CSc 165 Lecture Notes 12 - Model Animation CSc 165 Computer Game Architecture Overview
• Approaches to Animation 12 - Animation • Skeletal Animation • Animation Transformations
• Keyframe Interpolation
• Keyframe Sequences
2
CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation Approaches to Animation Animation “Skeleton”
• Traditional or “Cel” animation pelvis o Developed (and still used) for cartooning
• Rigid Hierarchy LHip RHip LowerBack
• Per-Vertex Joint LKnee RKnee ... o Morph Targets LAnkle RAnkle • Skeletal Bone
3 4
CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation Skeletal Animation Process Defining a Skeleton
• Define model
o vertices/faces/groups
• Define skeleton
o Bones and Joints
• Associate model vertices with joints
o “Rigging” the model
• Create movement poses (keyframes)
o Move joints (vertices follow)
o Save skeleton position/orientation data as keyframes
Model credit: Essential Blender, Roland Hess, www.blender.org 5 6 CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation Rigging the Mesh KeyFraming
• Multiple model orientations (views, poses) Pose mode o A single view is called a “frame”
• Each pose represents a “key” view
• Display (render) key views in sequence
o Or, interpolate between keyframes
7 8
CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation
Keyframe Drawing KeyFrames
Keyframe: 0 1 2 3 4 5
• Animated model file stores each keyframe • Application code repeatedly: . Sets (specifies) “current frame” . Invokes model.draw() KeyFrame 1 KeyFrame 2 KeyFrame 3 KeyFrame 4 • draw() renders triangles using current frame (time = 0) (time = 15) (time = 30) (time = 45)
9 10
CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation Blender Keyframing Blender – export animation for RAGE
Graph File 3D View Editor
Export
RAGE addons
Dope Sheet Timeline If a model has multiple animations, each animation is exported separately
11 12 CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation
Models usually have multiple animations Loading Animated Models in RAGE
protected void setupScene(Engine eng, SceneManager sm) throws IOException examples: WoW Models { // load skeletal entity – in this case it is an avatar // parameters are: entity name, mesh file, skeleton file o Idle SkeletalEntity manSE = sm.createSkeletalEntity("manAv", "man.rkm", "man.rks"); o Walk // loading its texture in the standard way o Run Texture tex = sm.getTextureManager().getAssetByPath("man.jpg"); Crocodile TextureState tstate = (TextureState) sm.getRenderSystem() .createRenderState(RenderState.Type.TEXTURE); o Attack tstate.setTexture(tex); manSE.setRenderState(tstate); o Laugh // attach the skeletal entity to a scene node SceneNode manN = sm.getRootSceneNode().createChildSceneNode("manNode"); o Beg manN.attachObject(manSE);
o Die // load the model’s animations manSE.loadAnimation("walkAnimation", "walk.rka"); o … manSE.loadAnimation("waveAnimation", "wave.rka"); . . . Chimera } Female Goblin 13 14
CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation
Playing and Updating Animations in RAGE SkeletalEntity Class
Asset
private void doTheWave() { SkeletalEntity manSE = Entity (SkeletalEntity) engine.getSceneManager().getEntity("manAv"); Skeleton manSE.stopAnimation(); manSE.playAnimation("waveAnimation", 0.5f, LOOP, 0); name : String } boneNames: String[]
SkeletalEntity Mesh Mesh : mesh protected void update(Engine engine) Skeleton: skeleton { . . . animationList : Map
Animation * framesList : FloatBuffer[]
15 16
CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation Bone Hierarchy Vertex Transformations
BoneName Vertices must be “relocated” (transformed according to their Parent Bone attached bones’ transforms) before being drawn B1 (Li1, Ri1) Initial rotation o e.g., multiply each vertex by its joint’s “initial transformations” Rest location B2 o Vertices are in “global” (model) coordinates B0 (Li2 , Ri2) relative to parent joint; i.e., initial transform from parent o Bone transforms are in “local” (bone) space, and relative to parent bone (Li0 , Ri0 ) space to this joint’s space
B0 YM Initial states
B1 Vx,y,z
Vertex attached to B B1 B2 VY 1 B0
XM VZ VX ZM 17 18 CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation Bone (Model) Animation Animating a Vertex
o For each bone: . Select nearest keyframe based on current time ′ . Compute the bone’s animation transform from the associated v Bone’s v Bone’s bone’s keyframe transform values, applying parents’ transforms e Animation- e r From-Model- recursively up to the root bone = Relative-to- X X r t Space-to-Joint- t e Model-Space e o Gather the transformed bones to send to vertex shader Space transform x transform x
o In the vertex shader – for each vertex:
. Apply the assigned bone’s “animation transform” to vertex Concatenation of parent’s Animated vertex animRelativeToModelSpace Vertex in joint Original vertex (in . If vertex is attached to more than one bone, use a weighted sum transform with bone’s space model coordinates) animRelativeToParentSpace (assuming weight-painting was used) transform . Output transformed vertex.
19 20
CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation optional -- Keyframe Interpolation Keyframe Interpolation (cont.)
Need many keyframes to insure smooth animation • Find the “missing keyframe” time o possible overhead issues frameTime = frameNumber / FPS Solution: • Select nearest keyframes o reduce number of keyframes • Interpolate position and rotation o interpolation for intermediate frames
frameTime
Render frame 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
KF0 KF1 KF2 KF3 (Assume FPS=24) Time = 0.0 Time = 0.33 Time = 0.66 Time = 1.0 Time = 0.0 Time = 0.33 Time = 1.0 Rotations Rotations Rotations Rotations KF0 Rotations KF1 Rotations KF2 Rotations KF3 Translations Translations Translations Translations Translations Translations Translations
21 22
CSc 165 Lecture Notes CSc 165 Lecture Notes 12 - Model Animation 12 - Model Animation Linear Interpolation Problems Non-Linear Translation
Bouncing ball doesn’t “look right”: • Define desired path with (e.g.) cubic curve
KFn KF • Interpolate position by evaluating curve at n+2 time=t
Desired path KF Linearly-interpolated path n+1 Bezier curve KFn+1 control points
Position = P(t) Rotating character arm shortens: KFn
KFn KFn+1
Desired interpolated path Linearly-interpolated path Desired path Linearly-interpolated path
23 24 CSc 165 Lecture Notes 12 - Model Animation Keyframe Interpolation vs. Lots of Keyframes o Keyframe interpolation allows for a smaller model file o Having the DCC export more keyframes allows the animation to capture advanced DCC animation capabilities o RAGE export (.rks) files export a keyframe for each frame, to allow taking full advantage of Blender’s animation tools.
25