Converting OBJ file to VBO using JavaScript

2019-09-17 10:54发布

I am trying to convert an OBJ file to data that I can pass to a VBO, but I only managed to load simple models that do not have a lot of vertices. For now I am trying to load a model that has vertices and normals.

This is what I have: http://undefined.free.bg/Wavefront%20to%20JSON/

This reads the entire file and stores it in an array, then stores the lines with "v" in front of them in an array of vertices and the ones with "vn" in front in an array of normals. I use the faces to export them, duplicating all of the vertices (for example if blender exports a cube with 8 vertices, my output converts this to 36 vertices forming the triangles and no indices at all, since blender exports a normal per face and not a normal per vertex).

The problem is that the file gets too big and the for loop crashes if I load the blender monkey head, but if I load simple geometry like a cube or icosphere everything turns out okay.

Here is the code that is converting the OBJ file: http://undefined.free.bg/Wavefront%20to%20JSON/javascript/convert.js .

I tried to optimize the loop by waiting 100ms each time the loop loops for example 500 times, but it just gives the converter a few additional seconds before it crashes.

0条回答
登录 后发表回答