Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog
Main Page About Help FAQ Special pages Log in

ShiVa Character Animation

From ShiVa Wiki

Contents

Planning stage

Import into ShiVa

Model (UU3D workflow)

Animation (UU3D workflow)


Using Animations

Prerequisites

The ShiVa animation system

Basic Animation

animation.changeClip ( hObject, nBlendLayer, nClipIndex)
The hObject is the object which has the animBank you want to work with.
The nBlendLayer is the animation channel (Like a music channel) that we are going to use. 
   NOTE: there are only 8 channels available. if you need more, you have to dynamically remove
   unused clips form channels and replace them with you new ones.
The nClipIndex is the specific index number in the animBank of that object

Example:

animation.changeClip (hGameScorpionObject, 1, 0)

The above example says to Shiva, load the FIRST animation channel (technically 0 is the first channel, but for this example we are using 1 so that the reader does not get confused) with animClip 0 which is attached to the hGameScorpionObject's animBank.
So now in channel 1 we have this animation locked in place ready to be used.

API:

animation.setPlaybackKeyFrameBegin ( hObject, nBlendLayer, nKeyFrame )
animation.setPlaybackKeyFrameEnd ( hObject, nBlendLayer, nKeyFrame )
animation.getClipKeyFrameRangeMin ( hObject, nClipIndex )
animation.getClipKeyFrameRangeMax ( hObject, nClipIndex )
 

Example:

animation.setPlaybackKeyFrameBegin ( hGameScorpionObject, 1, animation.getClipKeyFrameRangeMin ( hGameScorpionObject, 0 ) )
animation.setPlaybackKeyFrameEnd ( hGameScorpionObject, 1, animation.getClipKeyFrameRangeMax ( hGameScorpionObject, 0 ) )

"The starting frame that I want the FIRST animation (animation clip 0) to start at is whatever Shiva finds is the BEGINNING FRAME of this animation." In this case, the beginning frame is 0. We could have alternatively also started the animation at frame 20 by doing the following:

Example:

animation.setPlaybackKeyFrameBegin ( hGameScorpionObject, 1, 20 )

In the previous example, we also said to Shiva, "The ending frame that I want the FIRST animation to END at (animation clip 0) is whatever Shiva finds is the ENDING FRAME of this animation." Similarly to Example 3 above, we could also set this frame manually if you know what it is as in the following example:

animation.setPlaybackKeyFrameEnd ( hGameScorpionObject, 1, 200 )

In most cases as you get many animations and objects, it becomes impractical to remember the final frames as you are changing animations or updating constantly so it is better to let Shiva figure out the frames and save you time in updating code rather than going to figure out exact frame numbers yourself.

Mixing animClips

Now we are going to create a second animation using a second clip and using the following code:

animation.changeClip (hGameScorpionObject, 2, 1)
animation.setPlaybackKeyFrameBegin ( hGameScorpionObject, 2, animation.getClipKeyFrameRangeMin ( hGameScorpionObject, 1 ) )
animation.setPlaybackKeyFrameEnd    ( hGameScorpionObject, 2, animation.getClipKeyFrameRangeMax ( hGameScorpionObject, 1 ) )

You just told Shiva to -> Place the second animation that is in the hGameScorpionObject's animBank (animClip 1) in the second animation channel (nBlendLayer 2) and make the animClip start at the beginning frame of the animation Clip and end at the final frame of the animation Clip.

Now we move from the setupAnimations() function to the updateAnimations() function. Here we are going to update on every frame (onEnterFrame handler in your AI model needs a call to this function, or it will not work).

Here we simply set the PLAYBACK level of the channels using the animation.setPlaybackLevel() command. The way it works is as follows:

animation.setPlaybackLevel ( hGameScorpionObject, 1, 0.5 )
animation.setPlaybackLevel ( hGameScorpionObject, 2, 0.5 )

What you are saying to Shiva is that you want Shiva to adjust the Animation Faders (Same concept as Mixer Faders in Audio, check the notes above to understand) to HALF strength each. This will MIX the 2 animations into 1 combined animation where both animations will play together. If I however just want the FIRST animation to play and not the second, I would do this:

animation.setPlaybackLevel ( hGameScorpionObject, 1, 1 )
animation.setPlaybackLevel ( hGameScorpionObject, 2, 0 )

In the above I now told Shiva that I want the Animation Fader for the first animation to be at FULL (Think of full volume in a mixer board) and the Animation Fader for the second animation to be off. This will play only the first animation in FULL.

The issue and confusion that comes in here is that when you are running an animation, usually you want to nicely have a FADE IN/FADE OUT from one animation to the other one. In order to do this, you need to have a variable for each fader (BlendLayer) that will be the "VOLUME" level.

Example: Let's say I want to play from animation 1 in the first animation channel and blend in to animation 2 from the second animation channel, well then I would have to slowly move the fader from the the first channel "down in volume" and the fader on the second channel "up in volume".

In the code I could accomplish something using variables:

animation.setPlaybackLevel ( hGameScorpionObject, 1, nCh1Volume )
animation.setPlaybackLevel ( hGameScorpionObject, 2, nCh2Volume )

where nCh1Volume and nCh2Volume are a maximum of 1.0 and a minimum of 0.0.

I could start out in my setupAnimations() and set the two channels as variables to 1.0 for nCh1Volume and 0.0 for nCh2Volume. Then I could do the following:

nCh1Volume = nCh1Volume - 0.1
nCh2Volume = nCh2Volume + 0.1

Put it all into IF statements to make sure that these values do not go below 0 or above 1.

Blending 2 animations without mixing unused channels

This method is useful for instance if you have an animation for the upper part of a character's body, but want fully independent control over the walking animation in the legs and hips.

this is possible if

setPlaybackIgnoreNotAnimatedChannels on the API page

Further reading

So that's it for animations, look at the provided examples in Shiva to learn how to do more advanced stuff, specifically look at the iPhone Character Control example in the Shiva samples. You will see all the code you need, but the concept is the hardest part to understand, however once you get it, it is VERY powerful and very useful :)

Credits

user gamescorpion and NiCoX

Retrieved from "http://www.stonetrip.com/developer/wiki/index.php?title=ShiVa_Character_Animation"

This page has been accessed 2,944 times. This page was last modified on 4 August 2011, at 12:14.