Game Development Reference
In-Depth Information
Here, redundantVertexVectors[textureIndices[aVertexIndex]] ~
redundantVertexVectors[4] ~ 0 and faces[1]["c"] is equal to 3 which makes the
if condition false . Hence, in the else condition, the following code will be added:
uvs[materialIndex].push(uvs[materialIndex]
[textureIndices[aVertexIndex]*2]);
uvs[materialIndex].push(uvs[materialIndex]
[textureIndices[aVertexIndex]*2+1]);
var newIndex=Math.floor(uvs[materialIndex].length/2)-1;
redundantVertexVectors[newIndex] = face[aVertexIndex];
face[aVertexIndex] = newIndex;
textureIndices[aVertexIndex] = newIndex;
Here, uvs[0].push(uvs[0][4*2~8]) ~ uvs[0].push(s4) , uvs[0].push
(uvs[0][4*2+1~9]) ~ uvs[0].push(t4) , and var newIndex = Math.floor
(uvs[materialIndex].length/2)-1 ~ 7. The new length of the UV array minus
one, redundantVertexVectors[7] = 4 , face["c"] = 7 , and textureIndices
["c"]=7 . The resultant arrays are as follows:
uvs=[s0,t0, s1,t1, s2,t2, s3,t3, s4,t4, s5,t5, s6,t6, s4,t4]
faces=[[a=4,b=5,c=6],[a=4,b=6,c=7]........]
faceVertexUvs=[[[a=4,b=5,c=6],[a=4,b=6,c=7]…...]]
redundantVertexVectors=[,,,,0,1,2,4]
As you keep iterating through this function, you will realize which condition has the
minimum redundancy and you will have the following new arrays:
A new redundantVertexVectors array with indices to the original vector
array. We will use this array to create our new vertices array as follows:
for(var i=0; i<redundantVertexVectors.length; ++i) {
var vector=vertexVectors[redundantVertexVectors[i]];
this.vertices.push(vector[0]);
this.vertices.push(vector[1]);
this.vertices.push(vector[2]);
}
A new UV array with some redundant UV coordinates.
A faces array where each face element has indices of the new array for
each vertex.
Now, we can create our indices array like we did before, by using the
indicesFromFaces function of the Geometry class with new vertices and face
indexes. We will also use the calculateVertexNormals function of our Geometry
class to calculate normals for the new vertices and indices.
 
Search WWH ::




Custom Search