mbrea-c / bevy_animation_graph

Animation graphs in Bevy!
Apache License 2.0
102 stars 5 forks source link

Global and character space poses #17

Closed mbrea-c closed 10 months ago

mbrea-c commented 10 months ago

Objective

Some features in the animation graph requires that poses are expressed in character (relative to animation player root) or global space. The motivating case is inverse kinematics: for two-bone inverse kinematics all bone transforms in a frame must be expressed w.r.t. a common reference frame (i.e. they must be in either character or global space).

Solution

Rather than having a single pose type, we differentiate statically between BonePoseFrame, CharacterPoseFrame and GlobalPoseFrame types. The pose pass then returns an Option<PoseFrame>, where PoseFrame contains an enum which wraps one of the three pose types listed above.

This brings our handling of poses more in line with what we already do for parameter values, which has worked well so far.

Space conversion nodes were added to convert from one kind of pose to another. Lastly, a ExtendSkeleton node was added to ensure that all skeleton bone transforms are in a pose (since the assumption is that if a bone is not contained in a pose then it remains as-is).

The ergonomics of this are subject to change (and feedback is welcome!) but it should be enough to get started with inverse kinematics.