Game Development Reference
In-Depth Information
Implementing parseJSON.js
We have only done a few changes in the parseJSON.js file present in the primitive
folder. Open it in your favorite editor. Earlier, this class returned the initialized
faces array from the parsed JSON, but now, it initializes the Geometry object that in
turn holds the faces array, as shown in the following code:
var geometry=new Geometry();
Now, instead of initializing individual data elements, we initialize variables of the
Geometry class. Also, before returning the Geometry object, we initialize its data
members by invoking the functions that we explained earlier. This is shown in the
following code:
geometry.vertices=vertices;
geometry.materials=data.materials;
geometry.indicesFromFaces();
//Normal information is present in JSON object then invoke
morphedVertexNormalsFromObj else invoke calculateVertexNormals.
if(data.normals.length>0){
geometry.morphedVertexNormalsFromObj();
}else{
geometry.calculateVertexNormals();
}
Implementing StageObject.js
The new class StageObject that we have added basically holds information to
render geometry on the stage or on our scene. We have used the word "Stage" for our
game space. The purpose of this class is to initialize a Geometry object and initialize
buffer objects for that Geometry class. Also, this class contains the location and
rotation of the object with respect to our scene. The following code is the constructor
of the StageObject class:
StageObject=function(){
this.name="";
this.geometry=new Geometry();
this.location=vec3.fromValues(0,0,0);
this.rotationX=0.0;
this.rotationY=0.0;
this.rotationZ=0.0;
this.ibo=null;//Index buffer object
this.vbo=null;//Buffer object for vertices
this.nbo=null;//Buffer Object for normals
this.diffuseColor=[1.0,1.0,1.0,1.0];
 
Search WWH ::




Custom Search