Hi. I try to travers trough all layers in a loaded glb file and give each layer a different material, but it’s not working. Any ideas where I do wrong?
function doorMaterial (setLayer) {
const assetPath = '../models/greenhouse/'; // model-folder
const loader = new THREE.GLTFLoader();
loader.setPath(assetPath);
loader.load('g-door.glb', function(object){
var i = 0;
object.scene.traverse(function(child){ // travers trough all the layers in the glb file
if (i == 0) {
doorMaterial1 = new THREE.MeshPhongMaterial ({color: 0x3333ff, opacity: 0.5, transparent: true, }); // denne funker
child.material = doorMaterial1;
}
if (i == 1) {
doorMaterial2 = new THREE.MeshPhongMaterial ({color: 0x339933, opacity: 0.5, transparent: true, });
child.material = doorMaterial2;
}
if (i == 2) {
doorMaterial3 = new THREE.MeshPhongMaterial ({color: 0x330033, opacity: 0.5, transparent: true, });
child.material = doorMaterial3;
}
child.layers.set(setLayer);
}
i ++;
});
scene.add(object.scene.children[1]);
model = new THREE.Object3D();
scene.add(model);
model.add(object.scene.children[0]); // skjønner ikke hvorfor man add'er [0], men scenen [1] ?
});
}