Reputation: 10224
So basically I am trying to make a model loader, that will take in wavefont obj files and render them in webgl. Eventually I would like to be able to rotate, translate and scale these objects.
I have the interface all setup and it works nicely. However I am having problems with rendering.
I have taken in an obj file, and checked the arrays all have the correct numbers of elements and I even checked using chromes webgl debug plugin, and it appears the arrays match up (even element values match up).
Number of Vertices: 10932 Number of Indices: 18960
Anyway When I run gl.drawElements(gl.TRIANGLES, numItems, gl.UNSIGNED_SHORT, 0); I get no chrome error but in the webgl plugin debug i get 'INVALID_OPERATION' with no additional information.
I have found that by changing numItems (which is usually the number of indices / 18960) to a much lower number, it will render a teapot (slightly wrong). The lucky number for some reason is 11034, if I go above this, it wont render, if I go below it will render my slightly wrong teapot. I need this number to really be the full number of indices, as obviously i cannot hard-code the numbers.
So I am very confused as to why this is happening, for my full code for debug: http://webdesignscript.net/assignment/graphics_a3/
Rendering part of the code: http://webdesignscript.net/assignment/graphics_a3/scripts/webglengine.js
Teapot model that is loaded: http://webdesignscript.net/assignment/graphics_a3/models/teapot.obj
Cheers, Josh
Upvotes: 2
Views: 683
Reputation: 45948
I hope you remembered that the faces in OBJ files use vertex indices that start at 1, rather than 0. So perhaps those later faces (that make it crash or not work) just reference an invalid vertex (one past the end). If so, just subtract 1 from the faces' vertex indices after read from the file.
Upvotes: 1