Game Development Reference
In-Depth Information
var textureIndices = this.faceVertexUvs[materialIndex][i]; //
Pick the corresponding vertexUV map
var aVertexIndices = ["a", "b", "c"];
for(var i=0; i<aVertexIndices.length; ++i) {
var aVertexIndex = aVertexIndices[i];
// For each vertex in face, copy the vertex to the vertex
redundant array.
redundantVertexVectors.push(face[aVertexIndex]);
// For each vertex in face, copy the vertexUV map to the uv
redundant array.
redundantUVs.push(textureIndices[aVertexIndex]);
}
}
for(var i=0; i<redundantVertexVectors.length; ++i) {
var vector=vertexVectors[redundantVertexVectors[i]];
// Copy X value of the vertex to vertices
this.vertices.push(vector[0]); // Copy Y value of the vertex
to vertices
this.vertices.push(vector[1]); // Copy Z value of the vertex
to vertices
this.vertices.push(vector[2]); // Copy s value from the UV
array. Since uv=[s0, t0, s1, t1, s2, t2 ]
this.uvs.push(uvs[redundantUVs[i]*2]);
this.uvs.push(uvs[redundantUVs[i]*2+1]);
this.indices.push(i+1); // indices=[1,2,3, 4,5,6, 7,8,9, ...]
}
}, */
However, while it is the simplest approach you could take, it's been commented
out and is there simply for our reference. It is not really the best approach as it is
inefficient. The first for loop iterates over non-redundant vertices information and
clubs triplets to create a single vector and pushes the vector on the vertexVectors
array. We do this because indices point to a coordinate and not its individual x , y , or
z components. The first for loop is shown as follows:
for(var i=0; i<vertices.length; i=i+3) {
var vector = vec3.fromValues(vertices[i], vertices[i+1],
vertices[i+2]);
vertexVectors.push(vector);
}
 
Search WWH ::




Custom Search