1
votes

I am trying to write an geometry translator from one CAD package to ThreeJS through JSON. I can use the JSONLoader to bring in the geometry I am writing to a js file, but it seems the vertex index do not match the original faces. Let me show you: http://i.imgur.com/oVCUynr.png

This is a simple cube on the left. I've added some number tags so you can see the face index as well as the vertex index of the underlying information which forms the cube. On the right, is how I see it in the ThreeJS Editor.

The editor verifies the correct number of faces and vertices, but it seems the faces are not composed of the correct vertices.

Here is a link to the json file:https://gist.github.com/fraguada/8ea243744961d72d61de

Essentially what I am doing is creating a list of vertex coordinates

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

similar for normals and faces

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

Am I not understanding the manner in which to construct the ThreeJS? I've referred to the JSON format for ThreeJS but I am obviously not exporting the data correctly. Any pointers for what I may be doing wrong would be greatly appreciated. With more complex meshes, there are even faces missing.

1
OK. I think that is exactly what I was looking for. Will verify tomorrow. Thanks.Luis E. Fraguada

1 Answers

1
votes

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

I unfortunately missed this documentation when looking at the Geometry and Scene notes in the github repository.

My issues is that I was not setting the proper bitmask for the face type:

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) 

From JSON-Model-format-3

Thanks for pointing me in the right direction. As well, this opens up a bunch of other possibilities that I was considering.