Page MenuHome

New animation add-on: Copy Global Transform
ClosedPublic

Authored by Sybren A. Stüvel (sybren) on Dec 14 2021, 1:13 PM.

Details

Summary

This add-on allows animators to copy the global transform of the active object or pose bone onto the clipboard. It can then be pasted in three different ways:

  • To the current transform of the selected object/pose bone (could be a different one than was used for the copying).
  • To selected keyframes.
  • Baking to all frames between the first and last selected keyframe (defaulting to preview range or scene range).

All three methods are compatible with auto-keying.

The latter two methods *require* auto-keying to be enabled, to give the animator control over which keying set to use, etc.

An earlier version of this add-on was used by the Blender Animation Studio during Sprite Fright. Since then the two paste-to-frame-range options were added, by request of the animators.

The add-on has been developed on GitHub before. That version on GitHub is identical to this one, except the COMMUNITY vs. OFFICIAL status. I fully intend to keep this add-on under my maintenance.

Developer aid

The copied matrix is put onto the clipboard as plain text. As such, it can be copied across other media, like Blender Chat. The paste function also understands the text format of Blender's print_m4() C function, to aid developers when debugging matrix manipulation.

Example

Example of baking, showing the counter-animation done to keep the active object at the desired global transform:

Diff Detail

Repository
rBA Blender Add-ons
Branch
copy-global-transform
Build Status
Buildable 19421
Build 19421: arc lint + arc unit

Event Timeline

Sybren A. Stüvel (sybren) requested review of this revision.Dec 14 2021, 1:13 PM
Sybren A. Stüvel (sybren) created this revision.
Sybren A. Stüvel (sybren) edited the summary of this revision. (Show Details)
  • Remove debug prints
  • Cleanup: Correct quoting style for enum values

Requesting minor changes but don't think an extra review iteration is needed, accepting.

copy_global_transform.py
51–66

This could be added to the Python API so scripts that insert key-frames don't need to duplicate this kind of logic. (more general TODO though).

197

bpy.utils.escape_identifier(bone.name) should be used in case the bone contains quotes in the name.

316

Using eval on external/untrusted data is worth avoiding if possible (we had some CVE's for this in the past).

In this case it's the literal can be parsed using the ast module.

mat = Matrix(ast.literal_eval(clipboard[6:]))
This revision is now accepted and ready to land.Dec 16 2021, 8:26 AM
Sybren A. Stüvel (sybren) marked 2 inline comments as done.
Sybren A. Stüvel (sybren) edited the summary of this revision. (Show Details)
  • Escape bone names
  • Use ast module for parsing
  • Remove some indentation from the matrix string on the clipboard (I added it for good reason, but neither documented nor remembered, so now it's back to "normal" indentation)
Sybren A. Stüvel (sybren) marked an inline comment as done.Dec 16 2021, 11:09 AM
Sybren A. Stüvel (sybren) added inline comments.
copy_global_transform.py
51–66

That's a good idea, but won't do it in this patch ;-)