Search code examples
dictionarythree.jswebgltextures

threejs texture causes "GL ERROR :GL_INVALID_OPERATION : glDrawElements"


I'm trying to apply a texture to a geometry created at runtime, reading a binary asset from a remote server. I create the geometry assigning UVs (geometry.faceVertexUvs = uvs;), normals (face.vertexNormals.push(...)) and tangents (face.vertexTangents.push(...)).

If I try to create a mesh with a basic material, there are no problems, but when I create the mesh with that geometry and I try to apply my texture, webgl doesn't display any geometry and I get this warning:

[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1

Does anybody know what is going on? I think that my geometry has something wrong, because if I use a THREE.Sphere, I can actually apply the texture.

But everyone told me that in order to apply texture I need UVs, and I have'em.

I think that my faceVertexUvs is wrong.

The real question is: geometry.faceVertexUvs.length should be equal to geometry.vertices.length, or it should be equal to geometry.faces.length ?

Thank you very much.

PS: I've already read the following posts

WebGL drawElements out of range?

Three JS Map Material causes WebGL Warning

THREEjs can't use the material on the JSON Model when initializing. Gives me WebGL errors

Loading a texture for a custom geometry causes “GL_INVALID_OPERATION” error


Solution

  • problem solved!!

    @GuyGood: you're right when you say that every vertex need a UV-Vector2, but it's wrong to say that geometry.faceVertexUvs.length should be equal to geometry.vertices.length...

    it seems that facevertexUvs is a matrix, and not an array..well, it is an array of arrays..not properly a matrix..in fact I think it can be used to handle multi-mesh objects..if facevertexUvs.length == 3, we have 3 submeshes, so 3 arrays..each one of them has a length equal to the number of faces of a particular submesh..and every face knows the UV mapping about the 3 vertices defining that face..

    hope this is clear and helpful!!