Game Development Reference
In-Depth Information
The two algorithms that we just discussed to create new
vertices and indices arrays are not standard algorithms.
We can always write better algorithms to reduce the size
of the vertices array.
Rendering objects exported from Blender
If you have reached this far, you have learned the main recipe to fight mutated
Mr. Green. Understanding the JSON format and then recreating the vertices and
indices arrays is exciting and at the same time, is your biggest weapon to build the
most beautiful objects with textures. So let's quickly walk through the code to load
JSON objects.
Changes in our JSON parser
Open primitive/parseJSON.js in your editor. This file has two major changes. The
first change populates the faceUvs and faceVertexUVs arrays of the Geometry class
with the JSON data, as shown in the following code snippet:
fi = geometry.faces.length;
if ( hasFaceUv ) {
for ( i = 0; i < nUvLayers; i++ ) {
uvLayer = data.uvs[ i ];
uvIndex = faces[ offset ++ ];
geometry.faceUvs[ i ][ fi ] = uvIndex;
}
}
if ( hasFaceVertexUv ) {
for ( i = 0; i < nUvLayers; i++ ) {
uvLayer = data.uvs[ i ];
uvs = [];
var aVertexIndices=["a","b","c","d"];
for ( j = 0; j < nVertices; j ++ ) {
uvIndex = faces[ offset ++ ];
//u = uvLayer[ uvIndex * 2 ];
//v = uvLayer[ uvIndex * 2 + 1 ];
uvs[ aVertexIndices[j] ] = uvIndex;
}
geometry.faceVertexUvs[ i ][ fi ] = uvs;
}
}
 
Search WWH ::




Custom Search