Skip to content

Commit 1adc3fb

Browse files
pcwaltonmsvbg
authored andcommitted
Rework animation to be done in two phases. (bevyengine#11707)
# Objective Bevy's animation system currently does tree traversals based on `Name` that aren't necessary. Not only do they require in unsafe code because tree traversals are awkward with parallelism, but they are also somewhat slow, brittle, and complex, which manifested itself as way too many queries in bevyengine#11670. # Solution Divide animation into two phases: animation *advancement* and animation *evaluation*, which run after one another. *Advancement* operates on the `AnimationPlayer` and sets the current animation time to match the game time. *Evaluation* operates on all animation bones in the scene in parallel and sets the transforms and/or morph weights based on the time and the clip. To do this, we introduce a new component, `AnimationTarget`, which the asset loader places on every bone. It contains the ID of the entity containing the `AnimationPlayer`, as well as a UUID that identifies which bone in the animation the target corresponds to. In the case of glTF, the UUID is derived from the full path name to the bone. The rule that `AnimationTarget`s are descendants of the entity containing `AnimationPlayer` is now just a convention, not a requirement; this allows us to eliminate the unsafe code. # Migration guide * `AnimationClip` now uses UUIDs instead of hierarchical paths based on the `Name` component to refer to bones. This has several consequences: - A new component, `AnimationTarget`, should be placed on each bone that you wish to animate, in order to specify its UUID and the associated `AnimationPlayer`. The glTF loader automatically creates these components as necessary, so most uses of glTF rigs shouldn't need to change. - Moving a bone around the tree, or renaming it, no longer prevents an `AnimationPlayer` from affecting it. - Dynamically changing the `AnimationPlayer` component will likely require manual updating of the `AnimationTarget` components. * Entities with `AnimationPlayer` components may now possess descendants that also have `AnimationPlayer` components. They may not, however, animate the same bones. * As they aren't specific to `TypeId`s, `bevy_reflect::utility::NoOpTypeIdHash` and `bevy_reflect::utility::NoOpTypeIdHasher` have been renamed to `bevy_reflect::utility::NoOpHash` and `bevy_reflect::utility::NoOpHasher` respectively.
1 parent 057c7ad commit 1adc3fb

File tree

9 files changed

+753
-494
lines changed

9 files changed

+753
-494
lines changed

crates/bevy_animation/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords = ["bevy"]
1313
bevy_app = { path = "../bevy_app", version = "0.13.0" }
1414
bevy_asset = { path = "../bevy_asset", version = "0.13.0" }
1515
bevy_core = { path = "../bevy_core", version = "0.13.0" }
16+
bevy_log = { path = "../bevy_log", version = "0.13.0" }
1617
bevy_math = { path = "../bevy_math", version = "0.13.0" }
1718
bevy_reflect = { path = "../bevy_reflect", version = "0.13.0", features = [
1819
"bevy",
@@ -24,5 +25,9 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.13.0" }
2425
bevy_transform = { path = "../bevy_transform", version = "0.13.0" }
2526
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.13.0" }
2627

28+
# other
29+
sha1_smol = { version = "1.0" }
30+
uuid = { version = "1.7", features = ["v5"] }
31+
2732
[lints]
2833
workspace = true

0 commit comments

Comments
 (0)