54
CS248 Lecture 14 Zhenglin Geng February 15 th , 2018 C HARACTER A NIMATION AND P HYSICS

CS248 Lecture 14

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS248 Lecture 14

CS248 Lecture 14

Zhenglin Geng

February 15th, 2018

CHARACTER AN IMAT ION AND PHYS I C S

Page 2: CS248 Lecture 14

Overview

Basics on character animationβ–ͺ

Articulated rigid bodiesβ–ͺ

Inverse kinematicsβ–ͺ

Page 3: CS248 Lecture 14

Basics on Character Animation

Page 4: CS248 Lecture 14

3D Animation

Battlefield 3 Animation (Upright, Crouch, Prone)

Page 5: CS248 Lecture 14

3D Animation

Battlefield 4 Animation (Running)

Page 6: CS248 Lecture 14

Prepare your own character

Modeling Rigging Skinning

Retargeting

Page 7: CS248 Lecture 14

Prepare your own character

Modeling

Sensible topologyβ–ͺ

β–ͺ T-Pose

Rigging

HIPS β–ͺ - spine - chest -shoulders - arm -forearm - hand

HIPS β–ͺ - spine - chest -neck - head

HIPS β–ͺ - UpLeg - Leg -foot - toe - toe_end

Skinning

β–ͺ Use an automated process initially

β–ͺ Incrementally editing and refining

Page 8: CS248 Lecture 14

Animating Characters

Animation from external sources

Mocapβ–ͺ

β–ͺ 3DS Max, Maya or Blender

Unityβ–ͺ ’s asset store

Multiple clips cut and sliced from a single β–ͺ

imported timeline.

Animation created and edited within Unity

Position, rotation and scale of β–ͺ GameObjects

Use standard format FBX

Page 9: CS248 Lecture 14

Using Humanoid Characters

How to obtain humanoid models

β–ͺ Procedural character modeling or character generator such as Poser, MakeHuman or Mixamo

β–ͺ Unity assets store

β–ͺ Build from scratch

Page 10: CS248 Lecture 14

Importing Models

Model

β–ͺ 3D Model, such as a character, a building

or a piece of furniture

Page 11: CS248 Lecture 14

Importing Models

Rig

β–ͺ Animation type:

β€Ί None

β€Ί Legacy

β€Ί Generic

β€Ί Humanoid

Page 12: CS248 Lecture 14

Importing Models

Animation

Animation clipsβ–ͺ

Page 13: CS248 Lecture 14

Demo

Page 14: CS248 Lecture 14

Review

Prepare your character animationβ–ͺ

Modeling, rigging, skinningβ€Ί

Retargetingβ€Ί

Obtain humanoid models: β€Ί Poser, MakeHuman, Mixamo

Animating charactersβ€Ί

Working with FBXβ€Ί

Page 15: CS248 Lecture 14

Animator ControllersAnimator Controllerβ€’

arrange and maintain a set of Animation Clips and associated Animation Transitions for a β€’

character or object

Animation State Machineβ€’

β€’ a flow-chart of Animation Clips and Transitions

Statesβ€’ (animation clips)

State transitionβ€’

Page 16: CS248 Lecture 14

Animation Statesβ€’ Animation state

β€’ An individual animation sequence (or blend tree) which will play while the character is in

that state

β€’ Default state

β€’ The state that the machine will be in when it is first activated

β€’ Any state

β€’ Can be used to go to a specific state regardless of which state you are currently in

β€’ Cannot be the end point of a transition

Page 17: CS248 Lecture 14

Animation Transitionsβ€’ Animation transition

β€’ Switch or blend from one animation state to another

β€’ How to blend between states

β€’ Under what conditions they should activate (parameters)

β€’ Transition properties

β€’ Exit time: the exact time at which the transition can take effect

β€’ Interruption source: control the circumstances under which this transition may be interrupted.

Read this document for more details.

β€’ Transition graph

β€’ Duration in/out

β€’ Transition offset

Target StateCurrent State

Transition Duration

Transition Offset

Preview playback current timeDuration in

Duration out

Page 18: CS248 Lecture 14

Animation ParametersAnimation Parametersβ€’

Variables that can be accessed and assigned β€’

from scripts

Used to control or affect the flow of the state β€’

machine

Types:β€’

Intβ€’

Floatβ€’

Boolβ€’

Triggerβ€’

Page 19: CS248 Lecture 14

Demo

Page 20: CS248 Lecture 14

Review

β–ͺ Animation basics

β€Ί Animator

β€Ί Animator controller

β€Ί Animation state

β€Ί Animation transition

β€Ί Animation parameter

Page 21: CS248 Lecture 14

Splitting Animation ClipsModels with unsplit animationsβ€’

Walk animation β€’ 1-33

Run animation β€’ 41-57

Kick animation β€’ 81-97

Page 22: CS248 Lecture 14

Looping Animation Clipsβ€’ Loops can base on:

β€’ Pose

β€’ Rotation

β€’ Position

Page 23: CS248 Lecture 14

Root motionRoot motionβ€’

Body transformβ€’

Root transform (XZ plane)β€’

For animations comes as β€’ β€œin-place”

Create a curveβ€’

Create a parameterβ€’

Control by scriptβ€’

β€’ β€œHandle by script”

Page 24: CS248 Lecture 14

Demo

Page 25: CS248 Lecture 14

Review

β–ͺ Splitting animations

β–ͺ Looping animations

β€Ί Pose

β€Ί Rotation

β€Ί Position

β–ͺ Root motion

β€Ί Create a curve

β€Ί Control by script

Page 26: CS248 Lecture 14

Blend Treesβ€’ Blend trees

β€’ Allow multiple animations to be blended smoothly

β€’ A special type of state of Animation State Machine

β€’ Transitions

β€’ Transition from one animation state to another

β€’ Usually very quick

β€’ Using blend trees

β€’ Create state > From New Blend Tree

β€’ Add animation clips using β€˜+’ under motion

Page 27: CS248 Lecture 14

1D Blending

Blend typesβ€’

β€’ 1D

β€’ 2D

Direct blendingβ€’

Blending parameterβ€’

Animation parameterβ€’

Page 28: CS248 Lecture 14

Demo

Page 29: CS248 Lecture 14

Avatarβ€’ Avatar

β€’ Mapping between simplified bone structure understood by Unity

and the actual bones present in the skeleton

β€’ Allow for retargeting and inverse kinematics

Page 30: CS248 Lecture 14

Configuring the AvatarAutomatic avatar configurationβ€’

Manual inspection is always recommendedβ€’

Needs to have similar bone structure (rigging)β€’

Needs to be Tβ€’ -pose (modeling)

Page 31: CS248 Lecture 14

Muscle Setupβ€’ Muscle

β€’ Control range of motion of different bones

β€’ Prevent visual artifacts and self-overlaps

β€’ Muscle group preview

β€’ Per-Muscle Settings

Page 32: CS248 Lecture 14

Demo

Page 33: CS248 Lecture 14

Review

Blend treesβ–ͺ

Blend trees vs transitionsβ€Ί

Creating blend treesβ€Ί

Blending parametersβ€Ί

Blend types: β€Ί 1D, 2D, Direct

Avatarβ–ͺ

Mapping, allow for retargeting and inverse kinematicsβ€Ί

Configuring the avatarβ€Ί

Muscle: control range of motionβ€Ί

Page 34: CS248 Lecture 14

Articulated Rigid Bodies

Page 35: CS248 Lecture 14

Fixed Joint

Restrict an objectβ€’ ’s movement to be dependent on

another object

Fixed joint vs parentingβ€’

Implemented through physics rather than transform β€’

hierarchy

Can break apartβ€’

Page 36: CS248 Lecture 14

Spring Joint

β€’ Connect two rigid bodies through a spring

β€’ Anchor

β€’ Point in object’s local space at which the joint is

attached

β€’ Connected anchor

β€’ Point in the connected object’s local space at which

the joint is attached

β€’ Auto configure connected

β€’ Spring

β€’ Damper

Page 37: CS248 Lecture 14

Configurable joint

Customizable joint, β€’ 4 sections

Position and rotation configurationβ€’

Limit and limit springsβ€’

Target and drive forcesβ€’

Projection β€’

Page 38: CS248 Lecture 14

Configurable joint (1)

β€’ Anchor

β€’ Connected anchor

β€’ To define local coordinate frame of the joint

β€’ Axis

β€’ Secondary axis

β€’ X,Y,Z Motion

β€’ Free, locked, limited

β€’ Angular X,Y,Z Motion

β€’ Free, locked, limited

Page 39: CS248 Lecture 14

Configurable joint (2)

Linear limit springβ€’

Spring force applied to pull object back when it goes β€’

past the limit position

Linear limitβ€’

Limitβ€’

Distance in world unitsβ€’

Bouncinessβ€’

Bounce force applied to push is back when it β€’

reaches the limit distance

Contact distanceβ€Ί

Toleranceβ€’

Angular Xβ–ͺ

Limit spring, low limit, high limitβ€Ί

Angular YZβ–ͺ

Limit spring, low limit, high limitβ€Ί

Page 40: CS248 Lecture 14

Configurable joint (3)

β€’ Target position / velocity

β€’ Desired position / velocity

β€’ X Drive

β€’ Drive force that moved toward target position/velocity

along local X axis

β€’ Mode: disabled, position, velocity or both

β€’ Position spring, damper

β€’ Maximum force

β€’ Y Drive, Z Drive

β€’ Target rotation / angular velocity

β€’ Angular X Drive

β€’ Angular YZ Drive

β€’ Slerp drive

Page 41: CS248 Lecture 14

Configurable joint (4)

Projection mode β€’

(snap back when constraints unexpectedly violate)β€’

Noneβ€’

Position and rotationβ€’

Projection distance / angleβ€’

The distance/angle the joint must move beyond its β€’

constraints before the physics engine will attempt to

snap it back to an acceptable position/rotation

Configured in world spaceβ€’

Swap bodiesβ€’

Page 42: CS248 Lecture 14

Apply forces and torques

β€’ Checkout Rigidbody class

β€’ public void AddForce(Vector3 force, ForceMode mode = ForceMode.Force)

β€’ public void AddRelativeForce(Vector3 force, ForceMode mode = ForceMode.Force)

β€’ public void AddForceAtPosition(Vector3 force, Vector3 position, ForceMode mode =

ForceMode.Force)

β€’ public void AddTorque(Vector3 torque, ForceMode mode = ForceMode.Force)

Page 43: CS248 Lecture 14

Demo

Page 44: CS248 Lecture 14

Inverse Kinematics

Page 45: CS248 Lecture 14

Inverse Kinematics (Review)

β€’ Joints

β€’ Position: 𝑝𝑖‒ Angle: πœƒπ‘–

β€’ Lengths

β€’ 𝑙𝑖‒ End effector

β€’ 𝑠

β€’ Coordinate frames

β€’ π‘Šπ‘₯,π‘Šπ‘¦,π‘Šπ‘§ , 𝑖π‘₯, 𝑖𝑦, 𝑖𝑧

β€’ Where are the z-axis?

β€’ What is the coordinate of the end effector in frame 2?

β€’ What is the coordinate of 𝑝𝑖 in frame i-1?

𝑝0

𝑝1

𝑝2

End effector

Base

π‘Šπ‘₯

π‘Šπ‘¦

π‘Šπ‘₯0

π‘Šπ‘¦0

π‘Šπ‘₯1

π‘Šπ‘¦1

π‘Šπ‘₯2π‘Šπ‘¦2

𝑙0

𝑙1

𝑙2

𝑠

πœƒ0

πœƒ1

πœƒ2

(0,0,1)

(𝑙2, 0,0)

(π‘™π‘–βˆ’1, 0,0)

Page 46: CS248 Lecture 14

Inverse Kinematics (Review)

Forward kinematicsβ€’

Specify the base position/joint along with the β€’

other joint angles to prescribe motion

Given β€’ 𝑙𝑖 , πœƒπ‘–, find 𝑝𝑖 , 𝑠

Inverse kinematicsβ€’

Given the values for the end effectors in β€’

world space, compute the joint angles

Jacobian iterative methodβ€’

𝑠‒ = 𝐹(𝛉)

𝐉‒ =πœ•π‘ 

πœ•π›‰

𝑠‒ βˆ’ π‘ π‘‘π‘Žπ‘Ÿπ‘”π‘’π‘‘ β‰ˆ 𝐉 𝛉 βˆ’ π›‰π‘‘π‘Žπ‘Ÿπ‘”π‘’π‘‘

Given β€’ s, π‘ π‘‘π‘Žπ‘Ÿπ‘”π‘’π‘‘, 𝛉, find π›‰π‘‘π‘Žπ‘Ÿπ‘”π‘’π‘‘, iteratively

𝑠‒ ∈ 𝑅𝑛, πœƒ ∈ π‘…π‘š, what is the dimension of 𝐉?

𝑝0

𝑝1

𝑝2

End effector

Base

π‘Šπ‘₯

π‘Šπ‘¦

π‘Šπ‘₯0

π‘Šπ‘¦0

π‘Šπ‘₯1

π‘Šπ‘¦1

π‘Šπ‘₯2π‘Šπ‘¦2

𝑙0

𝑙1

𝑙2

𝑠

πœƒ0

πœƒ1

πœƒ2

(Taylor expansion)

𝑛 Γ— π‘š

Page 47: CS248 Lecture 14

Inverse Kinematics (Review)

π‘Šβ€’ β„Žπ‘–π‘™π‘’ 𝑠 βˆ’ 𝑠𝑑 < π‘‘β„Žπ‘Ÿπ‘’π‘ β„Ž

Compute β€’ 𝐉

𝛿𝑠‒ = 𝑠𝑑 βˆ’ 𝑠

Solve β€’ 𝐉𝛿𝛉 = 𝛿𝑠 to find 𝛿𝛉

Update with a small step β€’ 𝛼: 𝛉 += 𝛼𝛿𝛉

Update end effectors β€’ 𝑠 = 𝐹(𝛉)

𝑝0

𝑝1

𝑝2

End effector

Base

π‘Šπ‘₯

π‘Šπ‘¦

π‘Šπ‘₯0

π‘Šπ‘¦0

π‘Šπ‘₯1

π‘Šπ‘¦1

π‘Šπ‘₯2π‘Šπ‘¦2

𝑙0

𝑙1

𝑙2

𝑠

πœƒ0

πœƒ1

πœƒ2

Page 48: CS248 Lecture 14

Coordinate Framesβ€’ Coordinate transfer (from frame 2 to frame 1)

β€’ 1𝑝 = 21𝑅 2𝑝 + 2

1𝑑

β€’ 1𝑝 is p in frame 1, 21𝑅 is the matrix rotating coordinates from frame 2 to frame 1, 2

1𝑑 is the translation vector from frame 1 to frame 2

β€’ Homogenous coordinate and transformation matrix

β€’ 1𝑃 =1𝑝

1, 21𝑇 = 2

1𝑅 21𝑑

0 1

β€’ 1𝑃 = 21𝑇 2𝑃

β€’ 1𝑃 is homogenous representation of 1𝑝, 21𝑇 is matrix transforming coordinates from frame 2 to frame 1

β€’ Multiple coordinate frames:

β€’ π‘Šπ‘ƒ = 0π‘Šπ‘‡ 1

0𝑇 21𝑇 2𝑃 = 0

π‘Šπ‘‡10𝑇2

1𝑇 2𝑃 = 2π‘Šπ‘‡ 2𝑃 (commutativity)

β€’ Origin of the ith coordinate frame in world space

β€’ π‘Šπ‘ƒπ‘– = 0π‘Šπ‘‡ 1

0𝑇 21𝑇 2𝑃 = 𝑖

π‘Šπ‘‡

0001

, (last column of transformation matrix)

β€’ 𝑝𝑖 = π‘–π‘Šπ‘‡14, 𝑖

π‘Šπ‘‡24, π‘–π‘Šπ‘‡24

𝑇

π‘₯1

𝑦1

𝑧1

1𝑧2

1π‘₯21𝑦2 𝑝

2𝑝

1𝑝 =?

21𝑅, 2

1𝑑

Page 49: CS248 Lecture 14

Forward KinematicsCalculate β€’ 0

π‘Šπ‘‡

β€’ 0π‘Šπ‘‡ =

cos πœƒ0 βˆ’sin πœƒ0 0 0sin πœƒ0 cos πœƒ0 0 00 0 1 00 0 0 1

Calculate β€’ π‘–π‘Šπ‘‡, for 𝑖 = 1,… ,π‘š βˆ’ 1

β€’ π‘–π‘–βˆ’1𝑇 =

cos πœƒπ‘– βˆ’sin πœƒπ‘– 0 π‘™π‘–βˆ’1sin πœƒπ‘– cos πœƒπ‘– 0 00 0 1 00 0 0 1

β€’ π‘–π‘Šπ‘‡ = π‘–βˆ’1

π‘Šπ‘‡ π‘–π‘–βˆ’1𝑇

Calculate end effector in world frameβ€’

𝑠‒ = π‘šβˆ’1π‘Šπ‘‡

π‘™π‘šβˆ’1

001

𝑝0

𝑝1

𝑝2

End effector

Base

π‘Šπ‘₯

π‘Šπ‘¦

π‘Šπ‘₯0

π‘Šπ‘¦0

π‘Šπ‘₯1

π‘Šπ‘¦1

π‘Šπ‘₯2π‘Šπ‘¦2

𝑙0

𝑙1

𝑙2

𝑠

πœƒ0

πœƒ1

πœƒ2

Page 50: CS248 Lecture 14

Jacobian Calculation

𝐉‒ =πœ•π‘ 

πœ•π›‰difficult to evaluate

β€’ αˆΆπ‘  = 𝐉 αˆΆπ›‰ = π‰πŸŽ π‰πŸ π‰πŸ

πœ”0

πœ”1πœ”2

(with respect to time)

β€’ 𝐉𝑖 is the ith row of Jacobian 𝐉

β€’ αˆΆπ‘  = σ𝑖=0π‘šβˆ’1 αˆΆπ‘ π‘– = σ𝑖=0

π‘šβˆ’1πŽπ‘– Γ— 𝑠 βˆ’ 𝑝𝑖

β€’ = σ𝑖=0π‘šβˆ’1 𝑣𝑖 Γ— 𝑠 βˆ’ 𝑝𝑖 πœ”π‘–

β€’ πŽπ‘– is angular velocity, 𝑣𝑖 is the rotation axis for

joint i, πœ”π‘– is the magnitude: πŽπ‘– = πœ”π‘–π‘£π‘–The β€’ ith column of Jacobian

β€’ 𝐉𝑖 = 𝑣𝑖 Γ— 𝑠 βˆ’ 𝑝𝑖

𝑝0

𝑝1

𝑝2

End effector

Base

π‘Šπ‘₯

π‘Šπ‘¦

π‘Šπ‘₯0

π‘Šπ‘¦0

π‘Šπ‘₯1

π‘Šπ‘¦1

π‘Šπ‘₯2π‘Šπ‘¦2

𝑙0

𝑙1

𝑙2

𝑠

πœƒ0

πœƒ1

πœƒ2

αˆΆπ‘ 1

𝑠 βˆ’ 𝑝1

Page 51: CS248 Lecture 14

Jacobian Calculation

Calculate β€’ 0π‘Šπ‘‡

β€’ 0π‘Šπ‘‡ =

cosπœƒ0 βˆ’sin πœƒ0 0 0sin πœƒ0 cos πœƒ0 0 00 0 1 00 0 0 1

Calculate β€’ π‘–π‘Šπ‘‡, 𝑝𝑖 and 𝐉𝑖 , for 𝑖 = 1,… ,π‘š βˆ’ 1

β€’ π‘–π‘–βˆ’1𝑇 =

cos πœƒπ‘– βˆ’sin πœƒπ‘– 0 π‘™π‘–βˆ’1sin πœƒπ‘– cos πœƒπ‘– 0 00 0 1 00 0 0 1

β€’ π‘–π‘Šπ‘‡ = π‘–βˆ’1

π‘Šπ‘‡ π‘–π‘–βˆ’1𝑇

β€’ 𝑝𝑖 is the first three entries in the last column of π‘–π‘Šπ‘‡

β€’ 𝐉𝑖 = 𝑣𝑖 Γ— 𝑠 βˆ’ 𝑝𝑖

𝑝0

𝑝1

𝑝2

End effector

Base

π‘Šπ‘₯

π‘Šπ‘¦

π‘Šπ‘₯0

π‘Šπ‘¦0

π‘Šπ‘₯1

π‘Šπ‘¦1

π‘Šπ‘₯2π‘Šπ‘¦2

𝑙0

𝑙1

𝑙2

𝑠

πœƒ0

πœƒ1

πœƒ2

Page 52: CS248 Lecture 14

Eigen

β€’ Matrix and Vector types

β€’ Matrix access and assignment

β€’ Initializing matrix

β€’ Get block matrix: block(i,j,h,w)

β€’ Matrix column and cross product

Page 53: CS248 Lecture 14

Visual Studio Problems

SAFESEH problemβ€’

Project Properties β€’ -> Linker -> Advanced -> Image Has Safe Exception Handlers, turn off

Glutβ€’ 32.dll not found

Copy glutβ€’ 32.dll from lib to the directory that has .sln file

Page 54: CS248 Lecture 14

Review

Basics on character animationβ€’

Prepare your model: modeling, rigging, skinning, (retargeting)β€’

Obtain your model: β€’ Mixamo, unity assets store

Import models: use FBXβ€’

Animator, animator controllers, animation state machine, animation states, animation β€’

transitions, animation parameters

Advanced materials on character animationβ€’

Splitting animation clips, looping animation clips, root motionβ€’

Blend trees, β€’ 1D blending, blending parameters

Avatar, avatar configuration, musclesβ€’

Articulated rigid bodiesβ€’

Fixed joint, spring jointβ€’

Configurable joint: limits and limit springs, targets and drive forces, projectionβ€’

Inverse kinematicsβ€’

Forward kinematics, Jacobian calculation, Eigenβ€’