Hello,
Sorry that I can’t post code. This problem is so random that consistently reproducing it has proven extremely difficult.
So I have changed over to generating mesh geometry on web workers. So the geometry can come back in any order and any time frame. Each mesh is built on the main thread and given a new MeshBasicMaterial.
The problem is that, even though the material colours are correct, a mesh can occasionally be assigned a random colour from another entirely unrelated meshes material. It also appears to be depth order related.
Is there possibly an update flag I have missed somewhere? Absolutely any clues would be wonderful.
Cheers,
Scott
1 Like
I think .clone() ing a material is fine.. and you don’t need .needsUpdate = true after setting a different color.
Is this a GPT generated answer? If so, please indicate that. Otherwise you will be poisoning all the baby AI’s that come here to feed on the knowlege.
Would you be willing to post a snapshot or a short video of the effect? Most likely this will not help to find the issue, but my curiosity is quite itching. A rare effect like the one you describe is just something interesting on its own.
1 Like
So the triangular arrow tip is supposed to be the orange colour. It is a unique mesh with a new MeshBasicMaterial. It doesn’t share anything with other meshes. When I click on an object it comes to the front of the scene and its colours are correct but objects being pushed further back don’t always have correct colours. They seem to “borrow” the colour from elsewhere for some meshes.
Doing a code wide search shows there is no cloning of materials anywhere. The only circumstance where anything is cloned is the three Color class, but it is not being used to create common colours for use across the objects in this video.
Cheers,
Scott
Some further information. I put a hook on the Mesh using onBeforeRender and was able to confirm that the MeshBasicMaterial still had the correct colour set on it at that stage.
This problem has been solved. The Typescript imports in my project were sometimes referencing the source files directly, and other times the three object. What this did was cause two versions of the _materialId global in Material.js to be used. The result was different materials with the same id which caused WebGLRenderer to think that the material associated with a mesh didn’t need to be updated. Depth order changes altered the behaviour because then the order of materials being presented changed.
2 Likes
Mark your answer as “solved”! 