I’m new in three.js and I have a problem with my texture in my extruded shape.
I have a room in rectangle that i draw it by shape, and then i extrude it by ExtrudeGeometry. Now I want to add a texture on one side of this extrude shape. But if I add texture for side, it will append to four sides, each side is one image of the texture. I just want to append texture to one side, not in four sides. Is there any way to do it?!
This above picture is my extruded shape, I want to append texture on just one side, not four sides like in the picture.
You will need to use multi material here and assign respective materialIndex for the faces of the geometry. Just create an array with materials and it is a multi material
var multi_material = [new THREE.MeshPhongMaterial(),new THREE.MeshPhongMaterial()]
var mesh = new THREE.Mesh(new THREE.BoxGeometry(100,100,100),multi_material)
mesh.geometry.faces[0].materialIndex = 1;
mesh.geometry.faces[1].materialIndex = 1;
scene.add(mesh)
By Default every face has a materialIndex 0 so it takes multi_material[0] as its material
now the faces of the geometry have normals.
the face facing towards x direction will have normal (1,0,0)
with this you can know which face is what.
and this is also reliable if you rotate the mesh by changing mesh.rotation (dont rotate geometry), the normals will still be same in the local coordinates