Changing material texture at run time throws an error
Okay so I have total access to a material, I can change it's colour at runtime, however trying to change the map texture gives an error.
For example
var materials = mesh.material.materials;
materials[index].color.setHex(0xb60430);
materials[index].needsUpdate = true;
scene.render();
this works totally fine, however in the same situation
var materials = mesh.material.materials;
var texture = new THREE.Texture(myPreloadedImageObject);
materials[index].map = texture;
materials[index].needsUpdate = true;
scene.render();
This throws an error (excuse if it's a bit weird I can't copy paste from the node-webkit console)
[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1
Note that I can also remove the material like this
materials[index] = 0;
scene.render();
And it also does not throw the error.
Any ideas?
geometry.buffersNeedUpdate = true;
geometry.uvsNeedUpdate = true;
Hey thanks for the quick response!
Hmm now it doesn't throw an error, but it just doesn't do anything...the material remains unchanged. Again if I try to set the colour, it works, but if I try to set the colour and the material, nothing happens.
Edit if I log the material after render, it does indeed have a map set as the texture, but for some reason it isn't being rendered I guess
As stated in the guidelines, help requests should be directed to stackoverflow. This board is for bugs and feature requests.
I'm trying to figure out if this is a bug or not...
If you are not sure if it is a three.js bug, perhaps you can get clarification on stackoverflow.
Okay I will cross post, but it's very slow to get answers over there, I've had questions up for weeks that no one answered...
I've cross posted here http://stackoverflow.com/questions/26400058/changing-three-js-material-texture-at-run-time-throws-an-error
Also, try with the version in the dev branch. Just in case.