Game Development Reference
In-Depth Information
The following code copies the generated UV coordinates to the
uvs
array of the
Geometry
class at the index 0. It is the index of the first material. Also our geometry
will use only one material:
uvs[0].push(uva[0]);
uvs[0].push(uva[1]);
uvs[0].push(uvb[0]);
uvs[0].push(uvb[1]);
uvs[0].push(uvc[0]);
uvs[0].push(uvc[1]);
uvs[0].push(uvd[0]);
uvs[0].push(uvd[1]);
In the following code, we create a
face
object and store the calculated indices in the
corresponding face properties (
a
,
b
,
d
). The normals of all vertices lie on the same
plane. Hence, the normals are cloned from the normal object (0, 0, 1) and copied to
the
vertexNormals
array of the
face
object:
var face = new Face();
face.a=a;
face.b=b;
face.c=d;
face.vertexNormals=[];
face.vertexNormals["a"]=vec3.clone(normal);
face.vertexNormals["b"]=vec3.clone(normal);
face.vertexNormals["c"]=vec3.clone( normal);
this.faces.push( face );
In the following code,
faceIndex
maintains the count of the number of face
objects stored in the
faces
array, and we store the UV indices at the corresponding
faceIndex
element in the
faceVertexUvs
array:
this.faceVertexUvs[0][faceIndex]=[];
this.faceVertexUvs[0][faceIndex]["a"]= faceUVIndex;
this.faceVertexUvs[0][faceIndex]["b"]= faceUVIndex+1;
this.faceVertexUvs[0][faceIndex]["c"]= faceUVIndex+3;
faceIndex=faceIndex+1;
In the following code, as there are two faces per segment, we repeat the process of
creating and adding the second face to the
faces
array and store their corresponding
UV indices in the
faceVertexUvs
array of the geometry:
face = new Face();
face.a=b;
face.b=c;
face.c=d;
face.vertexNormals=[];
face.vertexNormals["a"]=vec3.clone(normal);