I am trying to define material for cells loaded from OBJLoader using the following wrapper function:
function applyTexture(src){ var texture = new THREE.Texture(); var loader = new THREE.ImageLoader(); loader.addEventListener( 'load', function ( event ) { texture.image = event.content; texture.needsUpdate = true;
When the texture loads and it's time to apply the material to the grid, I begin to receive the following warning on the console:
.WebGLRenderingContext: GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 0
and the grid itself disappears.
what am i doing wrong here?
UPDATE
As @WestLangley pointed out the comments: Never try to apply texture / materials after things have been rendered. Create materials before rendering the object to the scene, and then modify them using:
obj.material.map = texture
source share