Game Development Reference
In-Depth Information
}
}
//
var nBones = this.bones.length;
this.boneMatrices = new Float32Array( 16 * nBones );
this.pose();
}
}
The loadObject function overrides the StageObject class' loadObject function.
It does everything that StageObject does, such as it invokes parseJSON and it
initializes materials. It also parses the skin and populates the geometry with the
skinIndices and skinWeights data.
Then, it iterates over the bones array and initializes a bone object for each element of
the array. It reads the position , quaternion and scale values from the bones array
element and adds the newly created bone object to the bones array.
Then, it creates the tree hierarchy. It iterates over all bone elements and if the value
of parent of the bone is -1 , it adds the bone as its child element; otherwise, it adds
the bone to the corresponding bone's parent, (this.bones[ gbone.parent ].add(
bone );) . The parent attribute of the bone element holds the indices of the bone.
Hence, we first retrieve the parent bone object by using the this.bones[ gbone.
parent] code and then add the bone to its parent.
It invokes the this.pose() function after initializing the bone objects, which in turn
invokes updateMatrixWorld , which creates the initial world space matrix for each
bone. The createBuffers function is defined as follows:
RiggedMesh.prototype.createBuffers=function(gl) {
...
this.skinIndexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.skinIndexBuffer);
gl.bufferData(gl.ARRAY_BUFFER,
new Float32Array(this.geometry.skinIndices), gl.STATIC_DRAW);
this.skinIndexBuffer.itemSize = 4;
this.skinIndexBuffer.numItems =
this.geometry.skinIndices.length/4;
this.skinWeightBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.skinWeightBuffer);
gl.bufferData(gl.ARRAY_BUFFER, new
Float32Array(this.geometry.skinWeights), gl.STATIC_DRAW);
this.skinWeightBuffer.itemSize = 4;
this.skinWeightBuffer.numItems =
this.geometry.skinWeights.length/4;
...
}
 
Search WWH ::




Custom Search