Game Development Reference
In-Depth Information
The RiggedMesh class has four new variables defined as follows:
this.bones[] : This array holds all the bone objects for that mesh.
this.boneMatrices[] : This array holds the transformation matrix of all
bones flattened into a common array. For example, elements 0 to 15 will
hold the transformation matrix of bone 0, elements 16 to 31 will hold the
transformation matrix of bone 1, and so on.
this.skinIndexBuffer : This variable holds the reference to the Vertex
Buffer Object, which stores the skinIndices data.
this.skinWeightBuffer : This variable holds the reference to the vertex
buffer object, which stores the skinWeights data.
The loadObject function of the RiggedMesh class is defined as follows:
RiggedMesh.prototype.loadObject= function (data) {
...
this.geometry=parseJSON(data);
parseSkin(data,this.geometry);
...
...
var b, bone, gbone, p, q, s;
if ( this.geometry && this.geometry.bones !== undefined ) {
for ( b = 0; b < this.geometry.bones.length; b ++ ) {
gbone = this.geometry.bones[ b ];
p = gbone.pos;
q = gbone.rotq;
s = gbone.scl;
bone = this.addBone();
bone.name = gbone.name;
bone.position=vec3.fromValues( p[0], p[1], p[2] );
bone.quaternion=quat.fromValues( q[0], q[1], q[2], q[3] );
if ( s !== undefined ) {
bone.scale=vec3.fromValues( s[0], s[1], s[2] );
} else {
bone.scale=vec3.fromValues( 1, 1, 1 );
}
}
for ( b = 0; b < this.bones.length; b ++ ) {
gbone = this.geometry.bones[ b ];
bone = this.bones[ b ];
if ( gbone.parent === -1 ) {
this.add( bone );
} else {
this.bones[ gbone.parent ].add( bone );
 
Search WWH ::




Custom Search