Converting OBJ file to VBO using JavaScript

自作多情 提交于 2019-12-11 21:09:01

问题


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.

来源:https://stackoverflow.com/questions/24727786/converting-obj-file-to-vbo-using-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!