Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
CS248 Lecture 14
Zhenglin Geng
February 15th, 2018
CHARACTER AN IMAT ION AND PHYS I C S
Overview
Basics on character animationβͺ
Articulated rigid bodiesβͺ
Inverse kinematicsβͺ
Basics on Character Animation
3D Animation
Battlefield 3 Animation (Upright, Crouch, Prone)
3D Animation
Battlefield 4 Animation (Running)
Prepare your own character
Modeling Rigging Skinning
Retargeting
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
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
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
Importing Models
Model
βͺ 3D Model, such as a character, a building
or a piece of furniture
Importing Models
Rig
βͺ Animation type:
βΊ None
βΊ Legacy
βΊ Generic
βΊ Humanoid
Importing Models
Animation
Animation clipsβͺ
Demo
Review
Prepare your character animationβͺ
Modeling, rigging, skinningβΊ
RetargetingβΊ
Obtain humanoid models: βΊ Poser, MakeHuman, Mixamo
Animating charactersβΊ
Working with FBXβΊ
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β’
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
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
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β’
Demo
Review
βͺ Animation basics
βΊ Animator
βΊ Animator controller
βΊ Animation state
βΊ Animation transition
βΊ Animation parameter
Splitting Animation ClipsModels with unsplit animationsβ’
Walk animation β’ 1-33
Run animation β’ 41-57
Kick animation β’ 81-97
Looping Animation Clipsβ’ Loops can base on:
β’ Pose
β’ Rotation
β’ Position
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β
Demo
Review
βͺ Splitting animations
βͺ Looping animations
βΊ Pose
βΊ Rotation
βΊ Position
βͺ Root motion
βΊ Create a curve
βΊ Control by script
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
1D Blending
Blend typesβ’
β’ 1D
β’ 2D
Direct blendingβ’
Blending parameterβ’
Animation parameterβ’
Demo
Avatarβ’ Avatar
β’ Mapping between simplified bone structure understood by Unity
and the actual bones present in the skeleton
β’ Allow for retargeting and inverse kinematics
Configuring the AvatarAutomatic avatar configurationβ’
Manual inspection is always recommendedβ’
Needs to have similar bone structure (rigging)β’
Needs to be Tβ’ -pose (modeling)
Muscle Setupβ’ Muscle
β’ Control range of motion of different bones
β’ Prevent visual artifacts and self-overlaps
β’ Muscle group preview
β’ Per-Muscle Settings
Demo
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βΊ
Articulated Rigid Bodies
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β’
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
Configurable joint
Customizable joint, β’ 4 sections
Position and rotation configurationβ’
Limit and limit springsβ’
Target and drive forcesβ’
Projection β’
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
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βΊ
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
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β’
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)
Demo
Inverse Kinematics
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)
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)
π Γ π
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
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π‘
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
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
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
Eigen
β’ Matrix and Vector types
β’ Matrix access and assignment
β’ Initializing matrix
β’ Get block matrix: block(i,j,h,w)
β’ Matrix column and cross product
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
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β’