View motion_playback sample source code.
Extracting root motion is the process of capturing character motion (translation and rotation) from an animation. The purpose is to re-apply motion at runtime to drive the character and its collision capsule. This allows the capsule (responsible for physical collisions) to follow precisely the character, even if it moves during the animation. Furthermore it also allows to animate motion with a speed that matches with the animation (compared to the code driven approach).
Initializing WebGL
The sample uses animation and motion tracks converted using *2ozz tools, relying itself on ozz::animation::offline::MotionExtractor
. It uses animation.tracks.motion settings as described in the reference configuration.
The motion track for this sample is composed of:
Note also that *2ozz baked (ie: removed/extracted) the motion from the animation, so it can be re-applied at runtime.
At runtime, the position and rotation are sampled from the motion tracks each frame. They are accumulated to move the character transform (by delta motion each frame), allowing to continue moving when the animation loops.
The sample uses ozz::sample::MotionAccumulator
and ozz::sample::MotionSampler
utilities to help with the complexity of managing loops.
The sample allows to activate / deactivate usage of motion tracks. Deactivating motion tracks shows the baked animation only (animation with the motion extracted / removed).
The sample exposes ozz::sample::MotionAccumulator
capability of applying a rotation to the path.
Finally, different options allows to render the motion track/path, as well as character trace.
ozz::sample::MotionAccumulator
utility, which handles animation loops.