"Motion Capture" for easily creating animations programmatically

Based on a user request, I created a utility class for easily creating animations in Panda via code. It lets you use actor.control_joint() to move the joints around, capture a frame, move the joints around, capture another frame, etc. and finally extracting the created animation in a form that can be loaded into an Actor. Kind of like doing a motion capture but in virtual space.

There is a test.py included, but you basically use it like this:

mocap = MotionCapture(actor)

head = actor.control_joint(None, "modelRoot", "head")
for h in range(-45, 45):
    head.set_h(h)
    mocap.capture_frame()
head.release_joint("modelRoot", "head")

# Save the created animation
anim_node = AnimBundleNode("shake", mocap.make_anim_bundle("shake", fps=48))
anim_path = NodePath(anim_node)
anim_path.write_bam_file("actor-shake.bam")

# Load the saved animation into the actor and play it
actor.load_anims({"shake": anim_path})
actor.loop("shake")

The full code is here:

Adding motion tweening is left as an exercise for the reader.

2 Likes

That is very cool! A nice addition indeed, I do think! :slight_smile:

It’s cool!

Let’s not talk about the original animation name, shall we?