I have a cube where I have applied a texture on all sides. I want to apply different texture on different sides of the cube.
const textureLoader = new THREE.TextureLoader();
textureLoader.load(imagePath, (texture) => {
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.anisotropy = this.renderer.capabilities.getMaxAnisotropy();
texture.colorSpace = THREE.SRGBColorSpace;
if (this.mesh && this.mesh.material && this.mesh.material.map) {
this.mesh.material.map.dispose();
}
const newMaterial = new THREE.MeshPhongMaterial({ map: texture }); // Use MeshPhongMaterial for lighting.
const backMaterial = new THREE.MeshPhongMaterial({ map: textureLoader.load('/assets/outerSpace.jpg') });
//this.mesh.material = material;
const materials = [newMaterial, newMaterial, backMaterial, newMaterial, newMaterial, newMaterial];
this.mesh = new THREE.Mesh(this.geometry, materials); // If a single material is placed in the parameter instead of array, it works but when an array is placed, it gives error
this.scene.add(this.mesh);
this.animate(); // Start the animation loop after everything is set up.
This gives an error “test.component.ts:150 ERROR TypeError: Cannot read properties of undefined (reading ‘identity’)”.