Game Development Reference
In-Depth Information
nUvLayers = 0;
// Count the number of UV elements
for ( i = 0; i < data.uvs.length; i++ ) {
if ( data.uvs[ i ].length ) nUvLayers ++;
}
offset = 0;
zLength = faces.length;
while ( offset < zLength ) {
type = faces[ offset ++ ];
isQuad = isBitSet( type, 0 );
hasMaterial = isBitSet( type, 1 );
hasFaceUv = isBitSet( type, 2 );
hasFaceVertexUv = isBitSet( type, 3 );
hasFaceNormal = isBitSet( type, 4 );
hasFaceVertexNormal = isBitSet( type, 5 );
hasFaceColor = isBitSet( type, 6 );
hasFaceVertexColor = isBitSet( type, 7 );
The following code checks whether the first bit is 0 and then reads the next four
values. If it is a triangle, it reads the next three values. For each face definition in the
faces array, we create a JavaScript object. The object's predefined properties such as
vertices, materialIndex , and normalIndex are then initialized with the data from
the array:
if ( isQuad ) {
face = new Face();
face.a = faces[ offset++ ];
face.b = faces[ offset++ ];
face.c = faces[ offset++ ];
face.d=faces[ offset++ ];
nVertices = 4;
} else {
face = new Face();
face.a = faces[ offset++ ];
face.b = faces[ offset++ ];
face.c = faces[ offset++ ];
nVertices = 3;
}
The following code checks for the material and increments the offset:
if ( hasMaterial ) {
materialIndex = faces[ offset++ ];
face.materialIndex = materialIndex;
}
 
Search WWH ::




Custom Search