I have a model with the material like [mat1, mat2].
then i duplicate the model
so i got two model, model1 and model2.
model1 === model2 // false
this is what i want,but
model1.material[0] === model2.material[0] // true
i want
model1.material[0] !== model2.material[0]
so how to do that?
model file is here.
C2.zip (30.6 KB)
calrk
2
If you are using the clone method, it does a shallow copy where it only clones the surface objects but keeps sharing the children objects. It sounds like you want a deep copy which isn’t a feature but is easily implemented.
This article explains the concept further: https://we-are.bookmyshow.com/understanding-deep-and-shallow-copy-in-javascript-13438bad941c
object1 = ...; // A Three object
object2 = object1.clone();
// iterate through all child objects
object2.traverse(function(child){
if(child.material){ // Might have to consider material arrays here?
child.material = child.material.clone();
}
if(child.geometry){
child.geometry = child.geometry.clone();
}
});
Is that what you were after?
1 Like