# Skeletal Animation (Advanced Methods in Computer Graphics) Part 4

## Skinned Mesh Node

The SkinnedMesh class encapsulates data and related functions for loading a mesh file consisting of vertex and polygon lists, attaching a skeleton, and transforming the vertices using the joint angles associated with the bones of the skeleton (Listing 4.3).

As shown in Fig. 4.11, the SkinnedMesh class uses three vertex lists in the form of vectors to store the initial vertices of the mesh in bind pose, the intermediate set of vertices after the pre-processing phase, and the final set of vertices after applying joint angle transformations. The mesh definition file has a simple structure consisting of the list of vertices and polygons. Polygons are specified using vertex indices (three indices for triangles and four for quads). The vertex index starts from 1. Figure 4.19 gives the mesh definition for a rectangular prism.

Listing 4.1 Class definition for a single node of a skeleton

The framework described above also uses the Point3 and Matrix classes for various vertex and transformation related functions.

Listing 4.2 Class definition for a skeleton Fig. 4.18 Sample skeleton definition file

An example of a simple application using the skeleton animation framework is shown in Listing 4.4. At the initialization stage, both mesh and skeleton objects are created, corresponding data loaded from input files, the skeleton is attached to the mesh, and the preprocess() function is called on the mesh object. This function in turn passes the vertex data to the root node of the skeleton via the preprocessPhase() function and gets back the intermediate vertices. The display() function performs the animation of the mesh by defining joint angles for the bones. In the example, the function call skeleton->rotate(3,30,0,-75) is used to rotate the bone with index 3 by 30o about the x-axis and —751 about the z-axis. The sequence of rotations is

Listing 4.3 Class definition for a mesh pre-defined. The function call mesh ->render() is used inside the display loop to render the mesh with the transformed vertex coordinates.

## Summary

This topic addressed the problem of animating articulated character models. Character models are divided into two main categories: those constructed using individual component objects, and those modelled as a single mesh surface. The first category of objects requires blending of surfaces at the joints to avoid interpenetration of component objects and the appearance of gaps during animation.

Fig. 4.19 A sample mesh definition file

Listing 4.4 Example of an application using the vertex skinning algorithm

It was shown that Hermite polynomials and cubic Bezier polynomials could be effectively used for vertex blending.

This topic also presented the vertex skinning algorithm which is a well-known method used in skeletal animation. Various aspects of vertex skinning including the transformation of mesh vertices using skeletons, application of scene graphs in vertex skinning, and transformations using a combination of bone matrices have been discussed in detail. The process of keyframe interpolation has been outlined. This topic also demonstrated the implementation of the vertex skinning algorithm.

The next topic introduces the quaternion algebra and transformations that are used for interpolating between orientations in three-dimensional space. Quaternions have a very important role in animation sequences where generic rotational transformations are applied to objects.