threejs json装载机混合面和顶点

时间:2015-01-19 11:34:32

标签: json 3d three.js

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

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

编辑器验证正确的面和顶点数,但看起来面不是由正确的顶点组成。

以下是json文件的链接: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格式,但我显然没有正确导出数据。对于我可能做错的任何指示都将非常感激。对于更复杂的网格,甚至会丢失面。

1 个答案:

答案 0 :(得分:1)

  

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

在查看github存储库中的Geometry and Scene注释时,我遗憾地错过了这个文档。

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

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

感谢您指点我正确的方向。同样,这也开辟了我正在考虑的其他一些可能性。

相关问题