Game Development Reference
In-Depth Information
//If the new vertex corresponding to texture coordinate
points to same vertex as in redundant array or the
corresponding vertex is not defined in the redundant
array.
if (redundantVertexVectors[textureIndices[aVertexIndex]] ==
face[aVertexIndex] || redundantVertexVectors[
textureIndices[aVertexIndex]] === undefined) {
redundantVertexVectors[textureIndices[aVertexIndex]] =
face[aVertexIndex];
face[aVertexIndex] = textureIndices[aVertexIndex];
}
else {
// The texture coordinate holds the index of a
different vertex duplicate the uv coordinate
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;
}
}
}
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]);
}
this.uvs = uvs;
}
In the preceding code, we created a new vertex array ( redundantVertexVectors ) by
copying the index of the previous array at a new index location as per the UV index.
It is difficult to express the algorithm in words, so let's do a dry run for the custom
set of data.
 
Search WWH ::




Custom Search