Game Development Reference
In-Depth Information
Once both the mesh and animation files are loaded, we invoke
processMD5
. The
function basically invokes
MD5_converter.process_md5anim
and
MD5_converter.
process_md5mesh
and stores the JSON string in
meshData.string
and the
animation string in
meshData.stringAnimationOnly
. Then, we parse the string to
convert it to a JSON object using the jQuery function,
JSON.parse
. Then, we create a
RiggedMesh
object and invoke its
loadObject
function to load the JSON model.
function processMD5(mesh,animation) {
var animData = MD5_converter.process_md5anim( animation,
"boblampclean.md5anim" );
var meshData = MD5_converter.process_md5mesh( mesh,
"boblampclean.md5mesh" );
var model=JSON.parse(meshData.string);
var animationData=JSON.parse(meshData.stringAnimationOnly);
model.animation=animationData.animation;
model.metadata.sourceFile="boblampclean.md5mesh";
var stageObject=new RiggedMesh();
stageObject.loadObject(model);
loadTexture(stageObject,false);
addStageObject(stageObject,[0.0,40.0,-50.0],0.0,0.0,0.0);
}
Summary
This chapter was dedicated to loading and using skinned models. We covered the
basics to help us understand how skinning data is stored in a JSON model file.
We also explained the relation between the bones and the vertex transformations
and used this knowledge to write our vertex shader. We implemented the smooth
skinning algorithm to store our joint and skin data.
We then learned how animation data is encrypted in a JSON file. We evolved our
classes to load the animation data and learned how to animate a model on frame-
based animation principles.
This chapter used matrix transformations, quaternion mathematics and linear
interpolation to handle difficult concepts such as animating skinned models.
In the next chapter, we will cover concepts such as picking and post-processing
effects. Picking is the core concept used in all 3D editing software. Through picking,
we can select 3D objects on a 2D screen.
Post-processing helps us add effects to a scene. For example, we may want our game
user to feel as if he is viewing our game scene through night vision goggles.