Illuminating Wireframes with Three.js MeshPhongMaterial

While attempting to display a mesh with Phong shading along with wireframe on an ArrayBufferGeometry where the vertex colors are set to THREE.vertexColors, I encountered an issue where the lighting only affects one random face. However, when I switch to MeshBasicMaterial, the desired behavior is achieved. The Phong material looks good and is properly lit up when the wireframe is set to false:

 
geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3));
    geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
    geometry.computeFaceNormals();
    geometry.computeVertexNormals();

    console.log(geometry);
    var material = new THREE.MeshBasicMaterial({
        side: THREE.DoubleSide,
        wireframe: true,
        transparent: false,
        vertexColors: THREE.VertexColors, // CHANGED
        shininess: 100,
        //     color: 0xff0000,
        shading: THREE.SmoothShading
    });

    console.log(material);

    var terrainMesh = new THREE.Mesh(geometry, material);
    terrainMesh.name = 'GRD';
    terrainMesh.receiveShadow = true;
    terrainMesh.castShadow = true;
    console.log(terrainMesh);
    return terrainMesh;

Would recomputing the vertex normals after applying the material solve the issue? And is there a specific reason why the lighting seems to work for solid faces but not for wireframes?

Answer №1

After troubleshooting, it turned out that the issue was with the lighting.

My scene had different types of lights like AmbientLight, DirectionalLight for representing the sun, and a SpotLight that followed the camera target to highlight user focus areas. However, none of these lights were properly illuminating the wireframe. While referring to the MeshPhongMaterial example, I realized they used point lights instead. I mistakenly thought the only difference between a point light and a spot light was the direction and target, but using a point light solved the problem.

Furthermore, I discovered that the lighting from a point light onto the wireframe needed to be on the front side of the material, regardless of its initial orientation. Since my geometry faced downward due to an unconventional file format, I positioned the point light underneath the object to illuminate it correctly. Additionally, I added a reverse sun-type light using another PointLight to brighten the geometry from below.

Despite resolving the issue, I am still puzzled as to why only the PointLight successfully illuminated the wireframe and why it couldn't do so from the rear of a THREE.DoubleSide material.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a window.variable in a jQuery ajax callback using CoffeeScript

This particular project is built using rails and backbone-on-rails framework. Despite my efforts, I have been facing an issue with setting a global variable in a response callback function. Here's what I have attempted so far: 1) Initialization of t ...

Send your information without having to navigate away from the current

This is my form <form id="reservationForm" action="sendmail.php" method="post"> ... . . . . <input type="image" src="images/res-button.png" alt="Submit" class="submit" width="251" height="51px"> Here is my javascript $("#reservationForm").su ...

Learn the process of encoding a string in JavaScript or jQuery and then decoding it with PHP

I am facing an issue with updating a field in the database using Ajax and PHP. Everything runs smoothly except when there are special characters present, like this: اللهم اني اشكو اليك ضعف قوتي وقلة حيلتي وهواني عل ...

code snippet for callback function in javascript

Recently, I've been working on a project with angularjs and phonegap and stumbled upon this interesting code snippet. While I have a basic understanding of what it does, the inner workings are still a bit unclear to me. Since I'm still getting fa ...

Using Angular to pass arguments to the ng-show directive in order to bind to various JSON files

Check out my awesome AngularJS app on Plunker. Clicking the + next to My academic course opens a new panel with a list of courses to choose from. Selecting 'Academic' or 'Applied Sciences' displays more detailed information about each ...

Sending information from a rails controller to a react component

Wondering how to pass the example @post = Post.all from the controller to React component props while integrating Rails with React via Webpacker. Is it necessary to do this through an API or is there another way? ...

How can we retrieve the value from a textBox using JavaScript in Selenium WebDriver?

https://i.sstatic.net/6ni0f.pngTrying to extract text from an input tag that is missing in the HTML code, leading to the need for JavaScript to retrieve the value. Unfortunately, running the code in Eclipse returns null as the result. The HTML and Seleni ...

"Combining the power of JavaScript countdown with PHP date functionality

I have a JavaScript code that generates countdowns based on the user's PC date. I'm looking for a way to modify the script to use a specific timezone like: <?php date_default_timezone_set('Ireland/Dublin'); $date = date('m/d/Y ...

Loop through items in a list using Angular.js and display each item within an <

I am facing an issue where the model returned from the server contains html tags instead of plain text, such as b tag or i tag. When I use ng-repeat to create a list based on this model, the html is displayed as pure text. Is there a filter or directive av ...

Activate the jquery floatlabels plugin when the input is loaded

I'm currently experimenting with the jquery floatlabels plugin to implement inline labels for input fields in a form. The plugin works perfectly for fields without any text, but I need the label to display even if there is default text present. Upon ...

Tips for patiently awaiting the completion of a fadeout function

After a fadeOut function completes, I want to update a value. Here is the function I am using: const fadeOut = (duration: number = 300) => { Animated.timing( opacity, { toValue: 0, dura ...

Learn how to efficiently pre-load data using the prefetchQuery method in React-Query

Attempting to pre-fetch data using react-query with prefetchQuery. The network tab in browser DevTools shows the requested data coming from the back-end, but strangely, the data is not present in the react-query DevTools cache. Any ideas on what might be c ...

A specialized HTTP interceptor designed for individual APIs

Hey there, I am currently working with 3 different APIs that require unique auth tokens for authentication. My goal is to set up 3 separate HTTP interceptors, one for each API. While I'm familiar with creating a generic httpInterceptor for the entire ...

Embrace a variety of HTML template options when setting up a ReactJS component

Can someone help me understand how to render a component with template HTML data in ReactJS? class Options extends React.Component { render() { const othList = []; [1, 2, 3, 4, 5].forEach((t) => { othList.push(t); ...

Display the menu and submenus by making a request with $.get()

My menu with submenu is generated in JSON format, but I am facing issues displaying it on an HTML page using the provided code. Can someone please assist me in identifying what mistakes I might be making? let HandleClass = function() { ...

Utilizing a Material UI custom theme in React with Typescript: A step-by-step guide

Upon using the tool , I received a js file and a json file following the paths mentioned on the theme generator page: // src/ui/theme/index.js /* src/ui/theme/theme.json */ The files operate smoothly when left with the .js extension. However, when I attem ...

How can I use a specific condition to query for a particular element in an $in array in MongoDB?

Although I am skeptical that this is achievable, I will give it a shot here. Below are some examples of records in the database: { type: 'fruit', name: 'apple', quantity: 3 } { type: 'fruit', name: ' ...

Running into memory issues while constructing the heap

After attempting to build and deploy our React application, I encountered the following error: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory While I initially thought this was solely a JavaScript issue, I am uncert ...

Why does an async function fail to overwrite a module-scope variable?

The issue I am facing is that the module-scope variable "output" is not being overwritten by the async function "retrieveTextWrapper", and I can't seem to understand why. My goal is to display the text from StackOverFlow's homepage. The retrieval ...

PointLight in ThreeJS ceases to function properly following a modification in camera orientation

As a newcomer to Three, I have a very basic question regarding my code. I am trying to generate three objects: sun, earth, and mars. Everything was working fine until I made some changes to the camera position, sun size, earth size, and mars size. Now, I h ...