Having full control over a material, changing its color at runtime is seamless. However, attempting to change the map texture results in an error.
For instance:
var materials = mesh.material.materials;
materials[index].color.setHex(0xb60430);
materials[index].needsUpdate = true;
scene.render();
The aforementioned code works perfectly fine. But in a similar scenario:
var materials = mesh.material.materials;
var texture = new THREE.Texture(myPreloadedImageObject);
materials[index].map = texture;
materials[index].needsUpdate = true;
scene.render();
An error occurs (unable to copy from node-webkit console):
[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1
Note that removing the material like this also does not trigger any error:
materials[index] = 0;
scene.render();
s9k on the github issues section recommended:
geometry.buffersNeedUpdate = true;
geometry.uvsNeedUpdate = true;
Following this advice resolved the error, however, it did not change anything. When trying to set both color and material, no changes are applied even though the material appears to have the correct textures set upon inspection after rendering.
Any thoughts or suggestions? Could this be a bug?