Tips for properly updating the shadow when modifying the vertices of custom geometry in A-Frame/three.js

I've developed a custom component in a-frame that generates a unique geometry. I'm using the tick function to animate the update of the geometry's vertices successfully. However, the shadow on the geometry doesn't seem to update accordingly.

In the example below, I switch between two states for a flat shape - folded and unfolded. When transitioning from folded to unfolded, the shadows remain as if it's still folded.

Check out the HTML code below, specifically look at <a-fold> which starts in the folded state (you can change it to 'unfolded' by modifying that attribute).

 // Insert HTML code here

and the JavaScript code as follows:

 // Insert JavaScript code here

Despite trying to set this.material.needsUpdate = true, this.mesh.castShadow = true, and this.mesh.receiveShadow = true within the component, the shadow issue persists.

Interestingly, when I animate the entire entity (e.g., a rotation), I notice the material reacting to light dynamically. However, this behavior is not observed when changing the shape by updating the vertices.

Please refer to the linked images below to better understand the problem:

https://i.sstatic.net/XRh0B.png

https://i.sstatic.net/JcuKz.png

The second image clearly shows that even though the plane appears flat, its shadows indicate a fold. This inconsistency also occurs in reverse (if starting unfolded, the correct shadow persists when folding).

Here is a link to a js fiddle for further reference: JS Fiddle Link

If you require additional information, please feel free to ask. Your assistance is greatly appreciated.

Answer №1

When it comes to calculating lighting, normal vectors play a crucial role. In your situation, modifying the mesh vertices without updating the normal vectors is why the lighting remains unchanged. Make sure to include geometry.computeVertexNormals(); in your tick function after manipulating the vertices.

In the realm of 3D graphics, shadows, shading, and lighting are distinct concepts. The issue you're encountering pertains to lighting specifically, rather than shadows. Adjusting properties like mesh.castShadow didn't give the anticipated results because it's not related to shadow casting.

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

Dimming the background of my page as the Loader makes its grand entrance

Currently, I am in the process of developing a filtering system for my content. The setup involves displaying a loader in the center of the screen whenever a filter option is clicked, followed by sorting and displaying the results using JQuery. I have a v ...

Utilizing setTimeout within every iteration is ineffective

A vast gallery containing around 400 pictures is featured on my website. I have implemented a button that allows users to delete all images from both the DOM and the server through an AJAX request for each file. While testing, I attempted to use the setTi ...

Avoid using single quotes in Postgres queries for a more secure Node.js application

Snippet from my node js code: var qry = 'INSERT INTO "sma"."RMD"("UserId","Favourite") VALUES (' + req.body.user + ',' + JSON.stringify(req.body.favourite) + ')' My problem is inserting single quotes before JSON.stringify(r ...

Disabling CSS transitions and attempting to alter the style of an HTML element using JavaScript may not consistently work as expected

Currently, I am in the process of creating an animated effect for a website that involves moving two elements' positions over time and resetting them to their original position. Only one element is displayed at a time, and the animation should run smo ...

Obtaining the final field with the $in operator in Mongoose

I need to retrieve all person records that fall within a time frame specified by start and end dates, and have a place ID of either 1 or 2. Below is the query I am using: Person.find({ time: { $gte: start, $lt: end ...

Save message in the callback function of the express app.listen method

I'm currently integrating winston logging into my application and aiming to switch all info or error level logs with winston's .info and .error. Everything seems to be working well except when trying to log an info message from within the app.lis ...

The attempt to compress the code in the file from './node_modules/num2persian' using num2persian was unsuccessful

I have been using the num2persian library to convert numbers into Persian characters. However, whenever I run the command npm run build, I encounter the following error: An error occurred while trying to minimize the code in this file: ./node_modules/num ...

Managing Numerous Ajax Calls

Dealing with Multiple Ajax Requests I have implemented several Like Buttons on a single PHP Page, which trigger the same Ajax function when clicked to update the corresponding text from Like to Unlike. The current code works well for individual Like Butt ...

Allow the words to seamlessly transition back and forth between columns in a continuous cycle

Currently, I am attempting to showcase a large text in a format similar to a book. Each "page" has designated width and height, with content displayed over two columns: left and right. In this layout, page 1 is on the left, page 2 on the right, page 3 on t ...

Update the HTML page when switching between tabs

Currently, I am experiencing an issue with tab navigation in HTML. Within my code, I have two tabs named #tab1 and #tab2, each containing a form. The problem arises when I input data into #tab1, switch to #tab2, and then return to #tab1 - the information I ...

Is there a way to activate and change the color of a Radio Button when it is clicked?

Is there a way to change the background-color of a clicked Radio Button so it appears highlighted? For example, when the first choice is clicked, I want it to stand out visually. This is the current UI displaying the choices: https://i.stack.imgur.com/a7 ...

Switch effortlessly between one animation and another with Angular.js

I have two animations named "prev" and "next". Upon clicking the prev button, the "prev" animation should play. Similarly, when you click on the "next" button, the "next" animation should be triggered. I am using ng-class to achieve this behavior. How can ...

What is the correct way to run javascript on a DOM element when ng-show is triggered?

For those who prefer shorter explanations, there's a TLDR at the end. Otherwise, here's a detailed breakdown. I have a form that consists of multiple inputs organized into different "pages" using ng-show. What I aim to achieve is when ng-show r ...

Transferring a list of files from Callback folder

I am struggling with a function that is supposed to retrieve and list all the files in a specific folder. However, I am facing issues when trying to push out these files through an array. Something seems to be going wrong in my code as I receive an error w ...

What factors determine when Angular automatically triggers a setTimeout function compared to another?

Sorry if this all seems a bit odd, but I'll do my best to explain the situation. We have been given access to a small service that provides a simple form UI which we collect results from using an event. We've successfully implemented this in two ...

Limit input to numbers only in Semantic UI React Form Field

I've developed a custom CurrencyInput React component for users to input numeric values. I set the input type to "number", but unfortunately, this only seems to function properly in Chrome (as Firefox still allows non-numeric entries). Here is the co ...

Cause: Trying to serialize an `object` that is not JSON serializable (such as a "[object Date]"). Ensure that only JSON serializable data types are returned

Currently, I am utilizing Prisma along with Next.js. My issue arises when attempting to retrieve content from Prisma within the getStaticProps function; while it successfully fetches the data, I encounter difficulties passing it on to the main component. e ...

Guide to creating a nested list using the jQuery :header selector

Here is the structure of my html: <h1 id="header1">H1</h1> <p>Lorem ipsum</p> <h2 id="header2">H2</h2> <p>lorem ipsum</p> <h2 id="header3">H2</h2> <p>lorem upsum</p ...

Switch to display only when selected

When I click on the details link, it will show all information. However, what I actually want is for it to toggle only the specific detail that I clicked on. Check out this example fiddle Here is the JavaScript code: $('.listt ul').hide(); $( ...

Sharing resources between different origins and the file:// protocol

I have been developing an HTML5 application that is collecting data from various sources using JSONP. So far, everything involving a GET request has been functioning perfectly. However, I have encountered a hurdle while attempting to make a POST request. T ...