【问题标题】:threejs json loader mixed faces and verticesthreejs json loader 混合面和顶点
【发布时间】:2015-03-17 09:44:11
【问题描述】:

我正在尝试通过 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 格式,但我显然没有正确导出数据。对于我可能做错的任何指示将不胜感激。使用更复杂的网格,甚至会丢失面。

【问题讨论】:

标签: json 3d three.js


【解决方案1】:

参见 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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多