Upload
others
View
16
Download
0
Embed Size (px)
Citation preview
Sun-Jeong Kim
Mesh Hierarchy AnimationPart I – Rigid Meshes
7th Week, 2007
Game Programming II2
Objectives
To discover why mesh hierarchiesmesh hierarchies are important for object modeling
To understand the mathematics of mesh the mathematics of mesh hierarchy transformationshierarchy transformations
To become familiar with creating and traversing treetree--based mesh hierarchiesbased mesh hierarchies
To learn how to implement a robot arm and fictitious solar system using mesh hierarchies
To understand the basic idea of keyframeskeyframes and animation interpolation
Game Programming II3
Object Hierarchy (1)
Many objects are composed of parts, with a parent-child relationship
Hierarchy Transforms
Game Programming II4
Object Hierarchy (2)
A more complex hierarchy examplePelvis
Left Thigh
Left Calf
Left Foot
Right Thigh
Right Calf
Right Foot
Lower Spine
Upper Spine
Neck Left Clavicle
Left Upper Arm
Left Forearm
Left Hand
Right Clavicle
Right Upper Arm
Right Forearm
Right Hand
Game Programming II5
Robot Arm Demo
Game Programming II6
Mathematical Formulation (1)
A simple hierarchy
How do we correctly transform it to world space?Taking into consideration the transformations of its ancestors
Upper Arm(Bone 0)
Forearm(Bone 1)
Hand(Bone 2)
W
F0
F1 F2
Game Programming II7
Mathematical Formulation (2)
Matrix to transform the ith object in the arm hierarchy into world space
Ai: to-parent matrix to transform geometry from a child’s frame Fi into its parent frame Fi-1
W
F0
F1 F2
A0
A1
A2
A1A0
A2A1A0
011 AAAAM iii L−=
Game Programming II8
Bone Data Structure (1)
< Bone Mesh >
Game Programming II9
Bone Data Structure (2)
Game Programming II10
Building the Bone World Matrices
Game Programming II11
Animating the Bones
Game Programming II12
Rendering the Bones
Game Programming II13
Solar System Demo
Game Programming II14
Fictitious Solar System
Tree data structure for animated mesh hierarchy
0
1 2 3
4 5 6 7 8 9
[0] [1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
Game Programming II15
Solar Object Data Structure (1)
Game Programming II16
Solar Object Data Structure (2)
Game Programming II17
Solar Object Data Structure (3)
Game Programming II18
Solar Object Data Structure (4)
Game Programming II19
Building the Solar Object World Matrices
Game Programming II20
Animating the Solar System
Game Programming II21
Keyframes and Animation (1)
KeyframeKeyframe – significant posepose of an object in the mesh hierarchy at some instance in time
Animations are prerecorded by a 3D animator or recorded from a motion capture system
Key1 taken attime t0 = 0.0s
Key2 taken attime t1 = 2.5s
Key3 taken attime t2 = 5.0s Key1 . . . . . . Key2 . . . . . . Key3
t0 = 0.0s t1 = 2.5s t2 = 5.0s
Calculate intermediate frames/poses
Game Programming II22
Keyframes and Animation (2)
Each mesh in the hierarchy typically has several keyframes in an animation sequence
Pose is described by a rotation quaternion, scaling vector, and translation vector
Pose is described by a to-parent matrix
Keyframe interpolation
Key1 s = 0.0
Key2 s = 1.0
s = 0.167
s = 0.333
s = 0.50
s = 0.667
s = 0.833
Game Programming II23
Keyframes and Animation (3)
Keyframe interpolation (cont’)RST-values
The to-parent matrix of a bone is decomposed into its rotation, scaling, and translation components
They are interpolated independently and then recombined into the to-parent matrix after interpolation
D3DX functions perform these interpolation techniques: D3DXVec3Lerp (linear interpolation) and D3DXQuaternionSlerp(spherical interpolation)
Game Programming II24
Keyframes and Animation (4)
Pseudo codestruct Keyframe {
float time;D3DXQUATERNION R;D3DXVECTOR3 S;D3DXVECTOR3 T;
};
void interpolate( Keyframe &K0, Keyframe &K1, D3DXMATRIX &L ) {// Transform to [0, 1]float t0 = K0.time;float t1 = K1.time;float lerpTime = (t – t0) / (t1 – t0);
// Compute interpolated RST valuesD3DXVECTOR3 lerpedT;D3DXVECTOR3 lerpedS;D3DXQUATERNION lerpedR;
Game Programming II25
Keyframes and Animation (5)
Pseudo code (cont’)D3DVec3Lerp( &lerpedT, &K0.T, &K1.T, lerpTime );D3DVec3Lerp( &lerpedS, &K0.S, &K1.S, lerpTime );D3DQuaternionSlerp( &lerpedR, &K0.R, &K1.R, lerpTime );
// Build and return the interpolated to-parent matrixD3DXMATRIX T, S, R;D3DXMatrixTranlation( &T, lerpedT.x, lerpedT.y, lerpedT.z );D3DXMatrixScaling( &S, lerpedS.x, lerpedS.y, lerpedS.z );D3DXRotationQuaternion( &R, &lerpedQ );
L = R * S * T;}
Game Programming II26
Exercises
Modify the Robot Arm demo to draw the bone hierarchy shown in the following figure. Allow the user to animate the bones as follows: rotate bone 0 on the y-axis; rotate bones 1 and 2 on the z-axis; and rotate bones 3, 4, 5, and 6 on the x-axis.
0
1
4
2
3
6
5
01 2
3
4
5
6