three.js icon indicating copy to clipboard operation
three.js copied to clipboard

Changing material texture at run time throws an error

Open rohan-deshpande opened this issue 12 years ago • 8 comments

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?

rohan-deshpande avatar Oct 16 '14 06:10 rohan-deshpande

geometry.buffersNeedUpdate = true;
geometry.uvsNeedUpdate = true;

s9k avatar Oct 16 '14 06:10 s9k

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

rohan-deshpande avatar Oct 16 '14 06:10 rohan-deshpande

As stated in the guidelines, help requests should be directed to stackoverflow. This board is for bugs and feature requests.

WestLangley avatar Oct 16 '14 06:10 WestLangley

I'm trying to figure out if this is a bug or not...

rohan-deshpande avatar Oct 16 '14 06:10 rohan-deshpande

If you are not sure if it is a three.js bug, perhaps you can get clarification on stackoverflow.

WestLangley avatar Oct 16 '14 06:10 WestLangley

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...

rohan-deshpande avatar Oct 16 '14 06:10 rohan-deshpande

I've cross posted here http://stackoverflow.com/questions/26400058/changing-three-js-material-texture-at-run-time-throws-an-error

rohan-deshpande avatar Oct 16 '14 08:10 rohan-deshpande

Also, try with the version in the dev branch. Just in case.

mrdoob avatar Oct 17 '14 17:10 mrdoob