Page MenuHome

Animation: add function to apply a pose from an Action
ClosedPublic

Authored by Sybren A. Stüvel (sybren) on Mar 2 2021, 12:51 PM.

Details

Summary

Add BKE_pose_apply_action(object, action, evaluation_context) function to blenkernel, and expose in RNA as Pose.apply_action(action, evaluation_time).

This makes it possible to do the following:

  • Have a rig in pose mode.
  • Select a subset of the bones.
  • Have some Action loaded that contains the pose you want to apply.
  • Run C.object.pose.apply_pose_from_action(D.actions['PoseName'])
  • The selected bones are now posed as determined by the Action.

Just like Blender's current pose library, having no bones selected acts the same as having all bones selected.

Note that this doesn't completely implement all the work for T86159: Pose Library: non-modal apply pose operator; I want to get this code approved before building up from it.

The thing I'm mostly in doubt about is the place of the code. Currently it's exposed as function of the Pose, but it could just as easily be a function of the Action (so D.actions['PoseName'].apply_to(C.object)). The latter is more generic, but the fact that bone selection is relevant for the function indicates to me it's better to make it Pose-specific. We can always make a similar Action.apply_to(ID) function if necessary, that then ignores bone selection.

Another doubt is that this patch makes armature_update.c depend on the animation system. This is the only use of Actions and RNA pointers in that file. Maybe it's preferred to create a new file, blenkernel/intern/pose_library.c? Having such a new file would also make it possible to actually implement the internals as C++, using Set<char *> instead of GSet.

Manifest Task: T86159

Diff Detail

Repository
rB Blender
Branch
temp-apply-pose
Build Status
Buildable 13253
Build 13253: arc lint + arc unit

Event Timeline

Sybren A. Stüvel (sybren) requested review of this revision.Mar 2 2021, 12:51 PM
Sybren A. Stüvel (sybren) created this revision.
  • Rename function to apply_pose_from_action, so that it's clear that only a single pose is applied, and not all animation in the given Action.

Any reason to do this as function, not as an operator? Looking at the function, I don't see a reason to do it this way off hand.

Besides that, I can't speak for the animation specific code.
Re adding a new file - In general I think creating new files isn't an issue, maybe even good practice when there's some use for it. And personally, I'd also always use C++ for new files.

AFAIK operators aren't really meant for calling from Python, and are there for things like buttons, menu items, hotkeys, etc. This function is intended to be lower-level than that, as a building block for operators, and not for direct use by users.

  • Move code into armature_pose.cc and convert to C++

Again I can't speak for the animation code. Seems fine from my side.

This revision is now accepted and ready to land.Mar 5 2021, 4:14 PM