Hey there! Just wanted to share that I was able to find a solution by using
mesh.material.map.image.src = texture;
Here was the original question:
I'm working on a ThreeJS project and I'm trying to change the texture on a mesh. Unfortunately, I'm having trouble getting Three to update to the new texture.
I've already tried everything mentioned in similar questions on Stack Overflow, but nothing seems to be working so far:
- three.js change texture on material
- How to update texture in ThreeJS with loaded image data?
- Three.js Update Texture image
- Changing texture and color on Three.js collada object
- and more...
The specific texture I'm trying to change is
scene.children[0].children[1].material.map.sourceFile
and the hierarchy looks like this:
- SCENE scene
- 3DOBJECT banner
- MESH flag
- MESHBASICMATERIAL flag_M
- TEXTURE flag_MT
- MESHBASICMATERIAL flag_M
- MESH flag
- 3DOBJECT banner
The texture I want to update is flag_MT
. Here are the methods I've attempted:
flag_M.needsUpdate = true;
flag_MT.needsUpdate = true;
where texture is a base64 data stringflag_MT = THREE.ImageUtils.loadTexture(texture);
- basically recreating the entire object and replacing it in the scene
Thank you for any help.
Edit: Here are some key parts of the code:
init()
// Code snippet here
app.setFlagTexture()
// Another code snippet here