I am about to reduce the size and complexity of a scene to enhance performance. At the moment there are tons of objects that have unique materials applied but share same visual apperance. My plan is to break down the amount of materials and re-reference them back to all meshes that visually cohere - however I need the possibiliy of fading in and out.
does anyone know about the best practice of fading out an in individual meshes of a set of meshes with the same material applied/referenced?
As know, when I tween the material.opacity
from 1.0
to 0.0
it also affects other meshes in an unintended way. the object.property mesh.visible
is a boolean type and doesnt allow fading.
I have also tried to wrap all meshes dynamically into another object that has a new material, in which i could only change the opacity - without success.
Thanks in advance.
Assume you have 1000 objects all sharing the same material. You want to change the material of one of them, but keep the other 999 unchanged. If this is correct understanding of your problem, I have done something like this:
- Clone the material of the selected object, e.g.
obj.material = obj.material.clone();
- Then modify it as you want, it will not affect the material of the rest 999 objects
- Once a material is cloned, there is no need to clone it again, if you change the material again, so you might put cloning into
if( obj.material === globalMaterial) obj.material = obj.material.clone();
This would be useful if a relatively small number of objects differ from the rest. If all object are different, then you will end up with 1001 materials.
Another approach is to have N versions of the same material with various degrees of opacity. Then, instead of changing opacity, just pick the closest material. This relies on the fact that people might not distinguish small changes in opacity, especially if they happen fast.