Hi! I am trying to build a house in Three.js and load different textures on different parts of the house. I first load a complete GLTF model of the house, then traverse the children and add them into groups as the components of the house. However, when I try to load a texture onto a group, the previous group, which has already been given a texture, displays an overlap of the previous and the current texture. Can anyone help me with this? Here is my current code:
const groups = {
f: [],
r: [],
w: [],
v: [],
h: [],
t: [],
}
const modelLoader = new GLTFLoader();
modelLoader.load(houseURL, (gltf) => {
const model = gltf.scene;
//Loading Texture based on groups
model.children.forEach((child) => {
const cGroup = child.name[0];
groups[cGroup].push(child);
})
//Add 3d objects into groups
const walls = createGroup(groups.w, 'walls', wallTextureURL);
const roofs = createGroup(groups.r, 'roofs', roofTextureURL);
const verts = createGroup(groups.v, 'verts', beamsTextureURL);
const hors = createGroup(groups.h, 'hors', beamsTextureURL);
const tris = createGroup(groups.t, 'tris', beamsTextureURL);
const floor = createGroup(groups.f, 'floor', floorTextureURL);
}, undefined, (error) => console.log('Something is wrong!', error));
//Apply texture
const applyTexture = (model, textureURL) => {
const newTexture = new TextureLoader();
newTexture.load(textureURL, (textureS) => {
model.traverse((child) => {
// debugger;
if (child.isMesh || child.isPoint) {
textureS.wrapS = THREE.RepeatWrapping;
textureS.wrapT = THREE.RepeatWrapping;
textureS.repeat.set(API.xRepeat, API.yRepeat);
textureS.flipY = false;
child.material.map = textureS;
child.material.needsUpdate = true;
}
})
renderer.render( scene, camera );
}, undefined, (error) => console.log('something went wrong', error))
}
Thanks for looking!