Game Development Reference
In-Depth Information
The following code checks whether it has face normals and then reads and stores the
index of the normal array. Every face will have a normal:
//Just iterating and moving offset index forward. UV not relevant to
this chapter.
if ( hasFaceUv ) {
for ( i = 0; i < nUvLayers; i++ ) {
uvIndex = faces[ offset++ ];
}
}
//Just iterating and moving offset index forward. UV not relevant to
this chapter.
if ( hasFaceVertexUv ) {
for ( i = 0; i < nUvLayers; i++ ) {
for ( j = 0; j < nVertices; j++ ) {
uvIndex = faces[ offset++ ];
}
}
}
if ( hasFaceNormal ) {
normalIndex = faces[ offset++ ] * 3;
normal = vec3.fromValues(normals[ normalIndex++ ],normals[
normalIndex++ ],normals[ normalIndex ]);
face.normal = normal;
}
The following code checks whether it has vertex normals and then reads and stores
the normal array indices for each vertex of the face. Every vertex of a face will
have a normal:
if ( hasFaceVertexNormal ) {
for ( i = 0; i < nVertices; i++ ) {
normalIndex = faces[ offset++ ] * 3;
normal = vec3.fromValues(normals[ normalIndex++ ],normals[
normalIndex++ ],normals[ normalIndex ]);
face.vertexNormals.push( normal );
}
}
 
Search WWH ::




Custom Search