Game Development Reference
In-Depth Information
"faces":
[2,1,0,4,0,2,1,4,5,0,2,5,6,2,0,2,5,2,1,0,2,6,7,3,0,2,6,
3,2,0,2,0,3,7,0,2,0,7,4,0,2,0,1,2,0,2,0,2,3,0,2,7,6,5,
0,2,7,5,4,0]
}
The JSON file contains the complete information of the object. It contains information
of the materials as well as the vertices and faces arrays. Each triad of elements
in the vertices array will form a face. Also note that it supplies information on
the number of materials used to render the object. In our case, it is ''materials''
: 1 in the metadata section. However, the "materials": [] object in the JSON file
is an array. In the preceding example, this array has a single element.
Understanding the faces array is pretty exciting. First, note that there are arrays
containing UV, color, and the normal information array as well. As the name
faces denotes, it stores information on the faces of the polygon. A face will have
information on its vertices and the primitive can be a quad or a triangle. The faces
array can hold information such as a normal index denoting the face normal, material
index, and color, as well as UV indices. All indices point to their corresponding
arrays. So, a typical face set would be something like the following code snippet:
v1,v2,v3,[v4],[material_index],[face_uv],[face_vertex_uv,
face_vertex_uv,face_vertex_uv,
face_vertex_uv],[face_normal],[face_vertex_normal,
face_vertex_normal,face_vertex_normal,
face_vertex_normal],[face_color],[face_vertex_color,
face_vertex_color,face_vertex_color, face_vertex_color],
The square brackets [] denote an optional element. Hence, from the preceding
string, we understand that a face information set may or may not have all this
information. So, how do we know whether our face set has all this information?
We learn about our face set after reading the first element of the array. The value
of the first element of the array will range from 1 to 255. We will first convert
this number to an octet. Each bit of the octet has information about the face. The
combination of bits helps us understand the number of elements we have to read to
get the information for that face, as demonstrated in the following code snippet:
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
 
Search WWH ::




Custom Search