I'm working on loading multi-models with threejs and applying textures. But now, the multi-model is loaded with the code, but the texture is not applied to the loaded model, how do I fix it?
this is my github https://github.com/OKYOUNGBIN/Threejs_Web.git
please help me
function setMaterial(parent, type, mtl) {
parent.traverse((shadow) => {
if (shadow.isMesh && shadow.nameID != null) {
if (shadow.nameID == type) {
shadow.material = mtl;
}
}
})
}
const loader = new GLTFLoader;
loader.load(MODEL_PATH1, function (Top) {
console.log('success')
console.log(Top)
theModel = Top.scene;
theModel.traverse((Top) => {
if (Top.isMesh) {
Top.castShadow = true;
Top.receiveShadow = true;
}
});
theModel.scale.set(3, 2, 2);
theModel.position.y = -1;
for (let object of INITIAL_MAP) {
initColor(theModel, object.childID, object.mtl);
}
scene.add(theModel);
})
const INITIAL_MTL = new THREE.MeshPhongMaterial({ color: 0xf1f1f1, shininess: 10 });
const INITIAL_MAP = [
{ childID: "mesh_0", mtl: INITIAL_MTL },
{ childID: "mesh_0_1", mtl: INITIAL_MTL },
{ childID: "shelf_0301_t50_h600_w600_frame", mtl: INITIAL_MTL },
]
function initColor(parent, type, mtl) {
parent.traverse((shadow) => {
if (shadow.isMesh) {
if (shadow.name.includes(type)) {
shadow.material = mtl;
shadow.nameID = type;
}
}
})
}