The code that loads the mesh was shown in 3.1.6.
Now we are going to load the animation to the character. First we need
to get the animation data from the BCA file:
After that we need to get the four different animations out of it and
store them in the game attributes:
Now, we need an entity that knows how to keep an eye on the animations
of a mesh; this class is the BetaCell.Environment.Animation.BCAnimationController
and is constructed with
the following call:
controller = new
After that, we actually set the controller to the mesh:
evilMesh.controller = controller
Ok, we can update all the mesh's vertices in the update method with the
animation information; this requires performing a series of operations
per vertex in the CPU, but we know some one who can do that job in a
more efficient way; the GPU, so we need to add an effect part to the
mesh that handles the animation information.
First we create the animation feeder:
BCSkinnedMeshFeeder skinnedFeeder = new
Then we create the effect visitor:
BCDynamicEffectVisitor skinnedSetter =
Notice that the function used now is BCSkinnedMeshFeeder.SKINNED
the other function is used when the skinned mesh has a tangent space
which will be discussed later.
Also notice that the last parameter of the visitor's constructor is 0,
this means that the skinned mesh effect should be applied BEFORE ANY
COLOR AND LIGHTNING calculations; that's because the skinned mesh
algorithm transforms the normals of the mesh.
Then we apply the visitor:
This is the last visitor applied to the mesh.
Now we need to prepare for the sequence that we are going to be running
the tutorial. In it, the character stands idle for 5 seconds, after
that he starts running and runs for 5 seconds, finally he stops running
and the sequence starts again.
For that we need a BCAddSequenceListener
this class is responsible of giving the animation controller the
animation to play once the current animation finishes.
animationSequence = new
The setNext method receives two parameters, the first one is the
transition animation and the second one is the recurrent animation; the
way it works is:
- The controller is playing an animation
- The animation finishes
- The controler asks the BCAddSequenceListener
for the next animation to play
- If the transition animation isn't null, the BCAddSequenceListener
returns the transition animation and sets it (the transition animation)
- If the transition animation is null it returns the recurrent
Notice that this is a loop, after the recurrent animation is returned,
the controller starts playing it, when it's over, the BCAddSequenceListener
will return the recurrent
The result is that the transition is played once and the recurrent
keeps playing in a loop.
Now, we need to tell the controller that at first, he must run the idle
animation on the mesh and that once it finishes, it must ask the BCAddSequenceListener
for the next animation.
controller.addRecurrent(idle, animationSequence, 0);