Download presentation
Presentation is loading. Please wait.
Published byJade Walton Modified over 8 years ago
1
Procedural Animation and Physics Engine Yingcai Xiao
2
Outline What is it? How to design it in a game? How to design it in a game engine? How to implement it in Unity3D?
3
Yingcai Xiao Procedural Animation Dynamically generated by a procedure (function) at runtime. Flexible: can use any algorithms, can simulate real- world phenomenon (Good for building physics engines). Precise: no key frames, no lerping, can have smooth animation of any order in time and space.
4
Yingcai Xiao Procedural Animation of Dynamics
5
. Motion Dynamics Change of GO’s Geometry: location size orientation shape https://en.wikipedia.org/wiki/Procedural_animation Change of Camera: location orientation FOV (field of view) focal point
6
. Update Dynamics Change of GO’s Attributes: color texture lighting shading/reflection (via normal, material properties)
7
Yingcai Xiao Procedural Animation of Motion Dynamics (Wave Example)
8
. GO: Swimming Pool Animation: Wave Motion https://en.wikipedia.org/wiki/Procedural_animation Procedure: Physics Equations Data Structure: Elevation Grid
9
Data Structure Data Structure Design Criterion Compact (save space) Efficient (fast retrieval) Map-able (easy to convert) Minimal Coverage (small foot prints) Simple (easy to use)
10
Uniform Grid Commonly used in game engines as Elevation Grid for terrain data structure. Compact: No need to store x, z values,; they are calculated at runtime. Parametric space (i,j) x = i*d x + x 0; 0<= i < n x z = j*d z + z 0; 0<= j < n z Data array (i, j), loop i first, then j. Speedy retrieval of data in a 2D array. Simple Not flexible
11
Elevation Grid Elevation Grid is a special case of Uniform Grid. IK space x = i*d x + x 0; 0<= i < n x z = j*d z + z 0; 0<= j < n z Elevation values stored in as data at every grid note. The stored y value along with the computed x, z values define the coordinates of each grid note.
12
Yingcai Xiao Elevation Grid origin: 0,0 spacing: 2, 2 dimension: 3, 3 elevation: 10,20,30, 11,21,31, 21, 22, 33
13
Yingcai Xiao Physics of Waves
14
A snapshot of a decaying cosine wave V(r) = e -r cos(10r);
15
. 1D Cosine Wave: y = COS(x);
19
Yingcai Xiao Procedural Animation of Update Dynamics (Wave Example)
20
Change the shades to simulate waves Shades are produced by reflection. Reflection at each location depends on the surface normal at the location. If we change the normal by following the wave motion pattern, it could appear as a real wave.
21
Shading Shading: determining light reflection from objects at each pixel. Basic Reflection Model: Phong Reflection Model (most commonly used) I= k a I a + k d I d (l · n) + k s I s (v · r ) α I : reflected-light intensity
23
Procedural Animation in Unity3D Learn how to use scripts to change the geometry of game objects at run-time. Example: change the geometry of a plane to a simulate a wave.
24
Example in Unity3D To change the geometry of a plane to simulate a wave. Create a new project with Character Controller package. Add a plane (GameObject->CreateOhters->Plane) Scale it in the Inspector to 10X10 (in x and z). Uncheck the Mesh Collider (in the Inspector) Add a light (GameObject->CreateOhters->DirectionalLight) Add a FPC (Project->Assets->StandardAssets- >CharacterControllers->FirstPersonController, drag-and- drop it to Hierarchy.) Move it up. (Change its y position in the Inspector to 11). Add script to morph the plane (Plane->Inspector- >AddComponent->NewScript->JavaScript) name it Wave. Add the code on the next page to the Wave.js in Mono. Build->Build All in Mono to make sure there is no compilation errors.
25
Demo in Unity3D (Wave) #pragma strict function Start () { var mesh: Mesh = this.GetComponent(MeshFilter).mesh; var verts: Vector3[] = mesh.vertices; for (var v = 0; v < verts.Length; v++) { verts[v].y = Random.Range(0,10); } mesh.vertices = verts; mesh.RecalculateBounds(); mesh.RecalculateNormals(); this.gameObject.AddComponent(MeshCollider); } function Update () { }
26
Cosine Wave Formula y(r,t) = A e -r-at cos(2 π (r-Vt) / λ ); r = sqrt ((x-x 0 )*(x-x 0 )+ (z-z 0 )*(z-z 0 )) P 0 (x 0, y 0, z 0 ) : center of the wave A: amplitude of the wave V: velocity of the wave λ : wave length of the wave a: speed of decaying t = current time – time of impact (t 0 )
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.