Im currently loading a GLTF asset and using it multiple times in the scene.
I want to change material color of all meshes inside a targeted object which is a GLTF.
traverseMaterials(object, (material) => {
material.color.set(
object.info.model.color
);
});
This is working however it changes all other GLTF objects.
My goal is to change the targeted object and its children's mesh materials colors. ( Not all of them for all used GLTF's )
I tried this but nothing happens.
traverseMaterials(object, (material) => {
let clonedMaterial = material.clone();
material = clonedMaterial;
material.color.set(
object.info.model.color
);
});
Here is the traverseMaterials function for reference
function traverseMaterials (object, callback) {
object.traverse((node) => {
if (!node.isMesh) return;
const materials = Array.isArray(node.material)
? node.material
: [node.material];
materials.forEach(callback);
});
}