Game Development Reference
In-Depth Information
clone: function () {
var face = new Face(this.a, this.b, this.c );
if(!(this.normal===undefined))
face.normal=vec3.clone(this.normal );
face.colorIndex= this.colorIndex;
face.materialIndex = this.materialIndex;
var i;
for ( i = 0; i < this.vertexNormals.length; ++i){
face.vertexNormals[ i ] = vec3.clone(this.vertexNormals
[ i ]);
}
for ( i = 0; i<this.vertexColors.length;++i ){
face.vertexColors[ i ] = this.vertexColors[ i ];
}
return face;
}
};
The class variables a , b , and c hold indexes to the vertices array defined in the
Geometry class. The vertexNormals array holds indices to the normal array defined
in the Geometry class for each vertex of that face, as shown in the following code:
face.vertexNormals["a"]=3;//3 is the index to the normal array in
the geometry class for the vertex "a" of the face.
Implementing Geometry.js
Open the Geomtery.js file from the primitive folder in your editor. The following
code is the constructor of the Geometry class. Note the faces array; it holds the
objects of the faces for that model:
Geometry = function () {
this.vertices = [];
this.colors = [];
this.normals = [];
this.indices=[];
this.faces = [];
this.materials=[];
};
 
Search WWH ::




Custom Search