I\'m trying to swap image texture at runtime on a loaded three.js .obj. Here\'s the code straight from three.js examples with slight modification:
va
The problem here is that there are multiple child meshes in the object
variable. By having only one myMesh
global variable, you are storing only the last child mesh. Thus when you try to update the texture using this global variable, only one of the meshes gets a texture update, probably a small hidden part that is not clearly visible.
The solution would be to either:
myMeshes
array global variable and push myMesh
into it every time there is one. Then in your newTexture()
function, iterate through all items in this array and update their maps/materials.object
variable (the one returned from OBJLoader
's callback) into one single global variable. Then in your newTexture()
function, iterate through all the meshes like how it is done in the code (using traverse()
and if
statement), and update their maps/materials.Lastly, calling newTexture() somewhere in your code would also help ;)