Game Development Reference
In-Depth Information
This
pose
function is invoked whenever the DOF value of any bone is modified.
It is invoked from animation handlers and initially invoked from the
RiggedMesh
constructor. The
normalizeSkinWeights
function is defined as follows:
RiggedMesh.prototype.normalizeSkinWeights = function () {
for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
var sw = this.geometry.skinWeights[ i ];
vec4.normalize(sw,sw);
}
};
This another very important function makes sure that the sum of all weights for
a vertex is equal to 1. If you open
model/obj/mrgreen.json
, you will notice
skinWeights=[1,1 …..]
. This simply means that vertex one in the
vertices
array
is equally affected by both the bones in the
skinIndices
array. However, we need
to normalize it before we pass them to the vertex shader. The
matrixWorld
matrix is
updated as follows:
RiggedMesh.prototype.update=function(steps){
this.updateMatrixWorld(true);
this.updateMatrix();
}
The preceding
update
function simply updates the
matrixWorld
. The final step of
cloning is done as follows:
RiggedMesh.prototype.clone = function ( object ) {
if ( object === undefined ) {
object = new RiggedMesh( this.geometry );
}
return object;
};
Loading the skinned model
Our base classes are ready. Now, let's move on to see them in action. We will need
to modify our shaders to compute the vertex transformations. Open
08-Loading-
Skinned-Models.html
in your favorite editor.
This vertex shader will now take four extra parameters, which are as follows:
•
useSkinning
: This is a
booluniform
value that determines whether the
passed vertex uses skinning or not.
•
boneGlobalMatrices
: This is a mat4
uniform
value that holds all the offset
matrices, passed as a flattened array from the main control code.