DMotion - Animation framework and state machine based on DOTS

The [Bowuna New] column is UWA's aim to recommend novel, easy-to-use, and interesting open source projects for developers , helping everyone discover popular projects, cutting-edge technologies or amazing visual effects in the world, and explore Feasibility of applying it to your own projects. Many times, we don't know what we want until one day we meet it.

The project recommended today comes from the UWA open source library:
Latios Framework -- UWA Q&A | Open source library | Help developers find better solutions | Yuhu Technology

1. Introduction

Since Unity launched DOTS (Data-Oriented Technology Stack, data-oriented technology stack), its application has been receiving much attention. Although the performance improvement of DOTS is relatively obvious, it is still difficult for many developers to get started because of its relatively low threshold. Taking animation as an example, as of now the Entities 1.0 version still has no official Entities-based animation solution. The plug-in DMotion introduced in this article provides a DOTS-based animation framework and state machine, which can help developers use DOTS to make animations more conveniently .

2. Function overview

DMotion is based on the Kinemation part of another open source project, Latios-Framework. This project uses DOTS to establish a framework for some commonly used modules, including physics, audio, animation, etc., and is still being updated frequently. It can also be used as a reference for developers who want to learn and use DOTS. The link is as follows: Latios Framework --
UWA Q&A | Open source library | Help developers find better solutions |

Since Latios-Framework uses another animation compression scheme, that is, the plug-in Animation Compression Library is used. Although this plug-in can theoretically be used on the mobile side, it has not yet been adapted accordingly, so DMotion is currently only available on the PC platform. use on. The author mentioned that he will consider expanding to the mobile terminal in the future.

The main functions of DMotion are as follows:
Current Features (V0.3.4):

  • Fully Bursted Runtime
  • State Machine Visual Editor
  • Transitions: Boolean, Int, Enum And End Time
  • Simple API For Playing Clips Through Code (See Samples)
  • 1D Blend Tree
  • Animation Events
  • Root Motion (With Writegroup Support, If You Need To Override Default Behaviour)
  • Object Attachment
  • Support For Optimized And Non-Optimized Skeletons
  • State Machine Visual Debugging

Features that may be updated later:
Planned Features:

  • 2D Blend Tree (Cartesian/Freeform)
  • State Machine Override (A.K.A Animator Override Controller)
  • Substates
  • I Support
  • Multiple Layers
  • Skeleton Masks

Three, use

The latest version of Latios-Framework (currently 0.6.4) already supports Entities 1.0, but DMotion only supports Entities 0.51. Therefore, after installing the DMotion Package, you need to install the old version of Latios-Framework. It is recommended to use version 0.5.8.

The use of the DMotion plug-in is relatively simple on the whole, with a high degree of visualization. The author provides Sample and detailed guidance, and there are examples where you need to use the code. The documentation is linked here:
https://github.com/gamedev-pro/dmotion/wiki/1.1-Getting-Started:-The-Basics

Here are some simple introductions, such as playing an Animation Clip in the simplest way.

First you need to create a DMotion Clip.

Then set the Animation Clip to be used in the Inspector interface.

Then add the corresponding component to the object that needs to play the animation, make some settings in the component, add the Clip that needs to be used, and then the animation can be played.

Click Play to play the animation.

The animation state machine part has a high degree of visualization, which is very close to the usage method of Unity's own animation state machine.

First create an animation state machine.

Create a new state.

Add the corresponding Animation Clip.

Transition can be established between two animation states.

Transition can set some parameters and conditions.

These can all be found in the documentation, so I won't repeat them here.

4. Implementation principle

DMotion is a DOTS-based framework, here we start to analyze the animation code.

Inherit IConvertGameObjectToEntity to call Convert function to convert GameObject to Entity. Inheriting IRequestBlobAssets is to call RequestBlobAssets to convert Animation Clip into a format supported by DOTS. Here, the Kinemation part of the plug-in Latios-Framework is used, and it will eventually be converted into a BlobAsset, which is a binary data structure optimized for Streaming in DOTS.

The specific content of the Convert function converts the GameObject into an Entity and adds the corresponding Component.

Use RequestBlobAssets to convert Animation Clip into BlobAsset. At runtime, the code used by DMotion is compiled using Burst. The code in the System file is the part that processes the Component of Entities at runtime, which is the "S" in ECS. You can see that these codes are compiled using Burst and use the Job System.

It can be seen that DMotion makes full use of the DOTS system, and it can be predicted that its performance should be relatively excellent.

5. Performance

First, let me introduce why DOTS is faster than traditional methods. The DOTS launched by Unity mainly includes three aspects, namely ECS, Burst Complier and Job System. Entities are things in the game, or a collection of some data. Components organize the data related to Entity, and Systems is the logic that converts the data of Components from the current state to the next state. The figure below shows the organizational structure of ECS.

When the ECS architecture executes logic, it only operates the data that needs to be operated. When operating data, the System will only collect the Component data it cares about. When the CPU is running, it will load the entire memory into the cache, which reduces the number of Cache Misses, increases the cache hit rate, and improves the overall performance. program efficiency. In addition, the SIMD technique used in modern CPUs works extremely well with this data-intensive architecture and can further improve performance.

The ECS mode is more suitable for modern CPU architectures, because it can efficiently process data without storing redundant data fields in valuable caches, resulting in multiple Cache Misses. For example, manipulating the Position property of a Unity object will add all relevant data of the GameObject to the cache, wasting valuable cache space. However, under the ECS architecture, only the Position attribute will be put into memory, which saves cache space and reduces Cache Miss to a certain extent.

This data structure is well suited for parallel processing. Burst Complier is a compiler that uses LLVM to convert from IL/.NET bytecode to highly optimized native code. Together with the Job System, it generates code for multi-threaded parallel processing, making full use of SIMD, and multi-threaded operations give full play to the advantages of ECS. So Unity's DOTS tends to be faster than the traditional way.

Due to the characteristics of DOTS itself, the performance of DMotion is better than that of Animator. In the document, the author believes that the performance improvement can reach about 6 times, while our actual test results are about 3 times faster.

Test environment:
Platform: Windows 10 (10.0.19044) 64bit
Unity version: 2021.3.9f1c1
GPU: Intel(R) UHD Graphics 750/Direct3D 11.0
CPU: 3.6ghz/11th Gen Intel(R) Core(TM) I7-11700K @ 3.60ghz
test tool: UWA GOT Online

Test case:
The Model used is as follows, with 5770 vertices and 29 bones.

The animation used is a walking animation, which was tested using DMotion and Animator respectively.

Test content:
2500 models with animations were loaded and played, and the frame rate was tested.

The test results are as follows:
DMotion:
The average frame rate is 15.33 frames

Animator:
The average frame rate is 5.5 frames

It can be seen that DMotion has a certain improvement in performance compared to Animator, but it is a pity that it is not suitable for mobile platforms yet. Interested students can pay attention to the update of this project, or try to make further improvements on its basis.

Guess you like

Origin blog.csdn.net/UWA4D/article/details/129197493