Animation
GCubeSDK is using the same principles like threejs when it comes to
animation, by using AnimationClip. A
clip is a collection of KeyframeTracks. A track is a map of
time : value pairs for one certain
property, for example position.y or
Hips.quaternion.y. An AnimationMixer plays this clip on one
object. Call mixer->update every frame in order to play
the animation. The mixer is managing all the clips, tracks, and binds
them to the properties. Use one mixer per object. An object can store
several clips, such as walk and jump. Play one clip at a time.
Relevant Classes
| Class | Description |
|---|---|
| KeyframeTrack | Keyframes for one property, such as
Hips.quaternion.y. |
| Interpolant | The value between two keys. Discrete, linear, or smooth. |
| AnimationClip | One motion. A name, a duration, and its tracks. |
| AnimationAction | Playback state for one clip, including the current time in that clip. |
| AnimationMixer | Plays actions on one object. This is the object you update. |
| PropertyBinding | Finds the property a track name points at. The mixer creates it. |
| Bone | One joint of a character. |
| Skeleton | The bones, and the matrices used to deform the mesh. |
| SkinnedMesh | A mesh deformed by a skeleton. |
When using the GLTFLoader, things like bones and animation will be extracted and converted into clips, actions, interpolants etc..
Play an animation
Export GLTF or GLB. Put the file in data/. Details are
in Assets.
GLTFLoader creates the group, the skinned mesh, the skeleton, the bones, and the clips. You create the mixer and select a clip.
GLTFLoader* loader = new GLTFLoader();
Group* obj = loader->load("person.glb");
AnimationMixer* mixer = new AnimationMixer(obj);
scene->add(obj);
mixer->clipAction((AnimationClip*) obj->animations[0]);
while (1)
{
// ...
mixer->update(1.0f / 30.0f);
engine->render(scene, camera);
}animations[0] is the first clip stored in the file. DemoGLTFAnimation loads
the same model three times. Each copy has its own mixer, so each copy
can play on its own.
Interpolators
Each track is a list of keys. The interpolant is samples a value when the current time sits between two keys. The picture uses the same four keys for all three modes.
| Mode | Class | Between two keys |
|---|---|---|
| Discrete | DiscreteInterpolant | Keep the previous key until the next key. |
| Linear | LinearInterpolant | Straight line from one key to the next. |
| Smooth | CubicInterpolant | Curve, using the keys around the interval. |
DemoKeyframeTrack shows these three modes on cubes.
Other
The same mixer plays clips that did not come from a model. DemoAnimationMixer simulates a bounce once, stores the height and the squash as tracks, and plays that clip on each ball. The balls are a normal Mesh. They have no skeleton.