threejs json 加载器混合面和顶点

threejs json loader mixed faces and vertices

我正在尝试通过 JSON 编写一个从一个 CAD 包到 ThreeJS 的几何转换器。我可以使用 JSONLoader 将我正在写入 js 文件的几何体引入,但顶点索引似乎与原始面不匹配。我来给你展示: http://i.imgur.com/oVCUynr.png

左边是一个简单的立方体。我添加了一些数字标签,因此您可以看到面索引以及构成立方体的基础信息的顶点索引。右边是我在 ThreeJS 编辑器中看到的。

编辑器验证了正确的面数和顶点数,但似乎面数不是由正确的顶点组成。

这是 json 文件的 link:https://gist.github.com/fraguada/8ea243744961d72d61de

基本上我正在做的是创建一个顶点坐标列表

vertex[0].x,vertex[0].y,vertex[0].z, ...vertex[n].x,vertex[n].y,vertex[n].z....

法线和面部相似

faces[0].a,faces[0].b,faces[0].c,...faces[n].a,faces[n].b,faces[n].c,...

我是不是没看懂ThreeJS的构建方式?我已经提到了 ThreeJS 的 JSON 格式,但我显然没有正确导出数据。对于我可能做错了什么的任何指示将不胜感激。使用更复杂的网格,甚至缺少面。

See github.com/mrdoob/three.js/wiki/JSON-Model-format-3 – WestLangley

不幸的是,我在查看 github 存储库中的几何和场景注释时错过了该文档。

我的问题是我没有为面部类型设置正确的位掩码:

Type bitmask

00 00 00 00 = TRIANGLE
00 00 00 01 = QUAD
00 00 00 10 = FACE_MATERIAL
00 00 01 00 = FACE_UV
00 00 10 00 = FACE_VERTEX_UV
00 01 00 00 = FACE_NORMAL
00 10 00 00 = FACE_VERTEX_NORMAL
01 00 00 00 = FACE_COLOR
10 00 00 00 = FACE_VERTEX_COLOR

0: 0 = triangle (3 indices), 1 = quad (4 indices)
1: 0 = no face material, 1 = face material (1 index)
2: 0 = no face uvs, 1 = face uvs (1 index)
3: 0 = no face vertex uvs, 1 = face vertex uvs (3 indices or 4 indices)
4: 0 = no face normal, 1 = face normal (1 index)
5: 0 = no face vertex normals, 1 = face vertex normals (3 indices or 4 indices)
6: 0 = no face color, 1 = face color (1 index)
7: 0 = no face vertex colors, 1 = face vertex colors (3 indices or 4 indices) 

来自JSON-Model-format-3

感谢您为我指明了正确的方向。同样,这开启了我正在考虑的一系列其他可能性。