Updating an Animated Scene CSE 3541/5541 Matt Boggus
Overview Unity script structure reminder Animation use-case Undo/redo use-case
Unity example script using UnityEngine; using System.Collections; public class SomeScript : MonoBehaviour { // fields void Start() { // code to run when start is pressed } void Update () { // code to run on repeat during execution } // other methods }
Animation terms frame time Scene/Hierarchy objects Initially 0, increases by 1 every time the scene is drawn time Initially 0, increases by dt (a.k.a. timestep, Δt) every update Units might be seconds, minutes, or days, etc. Unity Time and Framerate Management Scene/Hierarchy objects Geometric objects Lights Camera Note the use of your own dt value for controlling the speed of the animation vs. the Unity Time.deltatime which controls frame-rate for different hardware or run-time conditions
Animating objects P’(time+dt) = P(time) + Displacement(dt) Displacement(dt) is the change in position over the amount of time, dt, passing Can have similar equation for change in orientation How is Displacement(dt) calculated? Real-time user input Physics Behavior Key-frame data / Interpolation (Motion capture – save positions at each frame instead of computing displacement)
Time control or frame selection Braid (2008) Autodesk MotionBuilder Image from http://www.mobygames.com/game/xbox360/braid/screenshots/ Image from http://www.autodesk.com/products/motionbuilder/overview
Two approaches P(time-dt) = P’(time) - Displacement(dt) Save the cause (of the position change): Displacement(dt) Save the effect or result (of the position change) P’(time)
Timeline control – undo/redo of drawing shapes Ex: see MSPaint Removes the last drawn shape Replace removed shapes, unless a new one is drawn
Undo/Redo – two options Save the cause (the data to draw each shape) Which shape? Starting mouse (x, y) Ending mouse (x, y) Save the effect (the image after drawing the new shape) Image width * image height pixels Each pixel has a red, green, and blue value
Undo/Redo – two options Save the cause (of each drawn shape) Algorithm: to undo, clear the background and redraw shapes Storage cost: 5 ints per shape Save the effect (image after each shape is drawn) Algorithm: to undo, revert to previous image Storage cost: x * y * 3 ints per shape
Tie-in with hierarchical scenes in Unity Storing the result of a series of geometric transformations in an object’s transform is comparable to “saving the effect” Image from https://www.packtpub.com/books/content/unity-3-0-enter-third-dimension
Scene drawing options Input: 3D scene + camera Output: 2D image When to redraw? Camera change [1] Object in view moves [1] Every frame [2] Every xth frame [3] [1] if(flag_set){ draw(); flag_set = false; } [2] [3] counter = (counter + 1)%draw_rate; if(counter == 0)
Summary Unity script structure reminder Animation use-case Undo/redo use-case