Skip to content

Latest commit

 

History

History
66 lines (42 loc) · 6.56 KB

File metadata and controls

66 lines (42 loc) · 6.56 KB

Welcome

Disclaimer

These samples are intended to serve as a reference for the com.unity.animation package. The package is highly experimental, and should NOT be considered suitable for production. Because it is currently undergoing a great deal of regular changes, these samples are provided as-is, without any expectation of support for the time being.

General Structure

The samples are split into three folders depending on their level of complexity. The Introduction folder has examples that show some basic setups and graphs. The Advanced examples have more elaborated graphs and animation concepts. The StressTests folder has scenes that test the limits of some of the animation core functions.

Input

Some samples are interactive and use the horizontal and/or vertical inputs to modify the Entities data.

To do this, a GameObject with a script inheriting from the AnimationInputBase is put in the Scene (not the SubScene). This object keeps a list of Entities and sets their ISampleData Component value on the main thread in the Update function. The overriden function UpdateComponentData computes the new data used for the Entities Components, and you could use other inputs than Horizontal and Vertical axis if you want.

Bone Rendering

To use the bone rendering, the RigPrefab must have the script BoneRendererComponent attached to it. The BoneRendererConversion System will convert it. In addition to the rig Entity, the BoneRendererEntityBuilder will create two Entities: one with the data required to compute the world matrices of the bones, that will have a reference to the rig Entity, a buffer for the bones' world matrices and a size for the bones; the other entity will have components for the instanced rendering, that is the color and shape of the bones, and a reference to the bone renderer data entity.

In the BoneRendererSystemGroup, two systems will compute the matrices then and render the bones, each working on the Entities previsouly mentioned:

  1. The BoneRendererMatrixSystem is a JobComponentSystem and as such is executed on multiple threads. This System computes the bones's matrices using the position of the rig's joints and the scale of the bones. It then sets the value of the BoneWorldMatrix Component;
  2. The BoneRendererRenderingSystem is updated after the BoneRendererMatrixSystem System and is a ComponentSystem. It's necessary to work on the main thread here because the bones are drawn using UnityEngine.Graphics.DrawMeshInstanced. The buffer of BoneWorldMatrix, computed in the previous system, is memcopied into a Matrix4x4 array that is then used for GPU instanciation.

Note that currently the bone renderer uses a custom shader to render the bones, Runtime/BoneRenderer/Shaders/BoneRenderer.shader.

Samples

The samples are independent one from another and are here to illustrate one possible way of implementing some animation features.

Introduction Samples

  • Animated Attachment Shows how to attach an animated object to an animated rig.
  • Animation Curve Shows how to convert an animation curve and use it to move a cube.
  • Blendshapes Shows how to play an animation clip to animate blendshapes.
  • My FirstAnimation Clip Shows how to play an animation clip in a loop on an existing model in a scene.
  • Rotating Cube Shows how to play a simple clip on a cube.
  • Scorpion Animates a rig by writing to the Transform components of the entities from a post-animation system, using exposed transforms. No skinned mesh is used.
  • Socket Shows three ways to "attach" an object entity to a rig entity.

Advanced Samples

  • Animation Controller Uses directional input to control the speed and direction of a walking character. Also shows a hybrid implementation of a follow behaviour for the camera.
  • Animation Rig Remap Showcases 3 different ways to remap animation from a source to a destination rig.
  • BlendTree 1D Converts a 1D blend tree to control the direction of a character running.
  • BlendTree 2D Simple Direction Converts a 2D simple directional blend tree to control if a character moves forward/backward and to the left/right.
  • Configurable Clip Evaluates a clip at a certain time. You can configure the clip to use normalized time, to loop the time, to loop the transform and to use root motion. You can go forward and back in time for the evaluation using the right and left keys respectively.
  • Constraints Shows a character that plays a walking clip, while having a LookAt constraint for his head and a Two Bone IK Constraint for each of his hand. The IK targets are dynamic.
  • Feather Blend Shows how to blend two clips with different weights for different channels.
  • Inertial Motion Blending Shows how to blend two clips using inertial motion blending.
  • Phase Matching:
    • Synchronize Motion Shows how to blend between clips that are aligned in their motion.
    • Synchronize Tags Shows how to use tags to blend between clips that don't have synchronized motion.

Stress Tests

Requirements

This version of Animation is compatible with Unity 2020.1.0b15+.