I grouped a few meshes, but now i am trying to retrieve each mesh out of the group and change their textures, how do i do that ?
nvm : found it
for (var i = group.children.length - 1; i >= 0; i--) {
if (group.children[i].part === "sleeve") {
group.children[i].material.map.image.src = "http://localhost:8080/models/blue.jpg";
console.log(group.children[i].material.map.image.src);//http://localhost:8080/models/rainbow.jpg
}
}
You should use TextureLoader
in order to load your textures. If you directly change the image property, the renderer does not know when to upload the new data.
Okay, can i get a snippet because i am a bit confused would it be somthing like this :
var texloader = new THREE.TextureLoader();
texloader.load("second.jpg", function(tex) {
for (var i = group.children.length - 1; i >= 0; i--) {
if (group.children[i].part != "button") {
console.log(group.children[i].material.map.image.src);
group.children[i].material.map.image.src = tex;
//console.log(group.children[i].material.map.image.src);//http://localhost:8080/models/rainbow.jpg
}
}
});
Just do:
group.children[i].material.map = textureLoader.load( 'http://localhost:8080/models/blue.jpg' );
Create textureLoader
outside of the loop.