Anim: Action bake custom properties #113208
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#113208
Loading…
Reference in New Issue
No description provided.
Delete Branch "nrupsis/blender:Action-bake-custom-properties"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
With the new ability to select channel types while baking an action (#111997), we would like the ability to bake custom properties as well.
@BClark gives a good overview of the issue here, but in short, without the ability to bake down custom properties (IK/FK switching, etc), a custom rig is difficult to work with in the NLA.
This change adds custom properties as an option for baking an action:
For:
@blender-bot package
Package build started. Download here when ready.
@blender-bot package
Package build started. Download here when ready.
WIP: Action-bake-custom-propertiesto Anim: Action bake custom properties@blender-bot package
Package build started. Download here when ready.
👍 for the functionality!
About the implementation: the current approach, of calling
thing.id_properties_ensure().to_dict()
, modifies the data by ensuring there is an (empty)IDProperties
struct allocated. This means that it unnecessarily increases the memory usage & potentially even blendfile size (I don't expect these empty structs to be removed automatically). I think it's better to usedict(thing.items())
, as the.items()
function doesn't seem to do this allocation.It's probably better to move that to a separate function, though. That can then do some more checks on the data, to see if it's really worth baking at all. Dictionaries, lists, and ID pointers cannot, and thus could be skipped from the to-be-baked dictionary. Maybe calling
id_properties_ui(key)
is a nice way to check this, but also it could have a negative impact on baking performance if this has to be called for every key (and have a catch for theTypeError
it can throw).The calls to
pbone.keyframe_insert(f'[\"{key}\"]', ...
need some extra escaping, as the key itself can contain quotes. Usebpy.utils.escape_identifier(key)
for that.Also double quotes in single-quoted strings don't need escaping, so
f'["{escaped_key}"]'
should work.The code for applying the custom properties could be moved to a small function, as apart from the receiving end (
pbone
orobj
) it seems to do pretty much the same thing everywhere.@ -381,0 +409,4 @@
pbone[key] = value
pbone.keyframe_insert(f'[\"{key}\"]', index=-1, frame=f, group=name)
except TypeError:
# Non animatable properties (datablocks, etc) cannot be keyed.
The explanation is good, and also means that
pbone[key] = value
should be taken out of thetry
block. Same below.Here's an example file that fails because of quotes in the custom property name.
Gave that a try, but for non animatable properties, it still returns an obj. So not very useful.
@blender-bot package
Package build started. Download here when ready.
Just one point of confusion, but otherwise looks good to me.
@ -198,0 +210,4 @@
return clean_props
def bake_custom_properties(obj, custom_props={}, frame=None, name=""):
if (f is None or custom_props is None):
Where is
f
defined? Is this supposed to beframe
?Oops, looks like that was a miss on a refactoring pass. I'm surprised Python didn't complain about it 🤷♂️
Yeah, that's just something that happens sometimes in dynamic languages like Python. Glad I could help! :-)
@blender-bot package
Package build started. Download here when ready.
Took a quick look at the code again, and tested it out as well. Looks good to me!
But maybe @dr.sybren would like one more look before merging?
Just a few smaller things.
@ -198,0 +206,4 @@
def clean_custom_properties(obj):
clean_props = {}
for key, value in obj.items():
clean_props.update({key: rna_idprop_value_to_python(value)})
This can be written as dict comprehension:
which I think is easier to read in this case.
@ -198,0 +210,4 @@
return clean_props
def bake_custom_properties(obj, custom_props={}, frame=None, name=""):
if (frame is None or custom_props is None):
No parentheses, this isn't C ;)
Also, given that the for-loop doesn't do anything when
custom_props
is empty, you can reduce the condition to:Having said that, why does
frame
have a default value that causes the function to not run? That doesn't make much sense to me. The same goes forcustom_props
by the way; that default value makes the function a no-op too.If you want to force
frame
to be passed as keyword argument, this is not the way to do that. Instead, write:Finally, the
name
parameter is passed asgroup
tokeyframe_insert()
. It's probably better to rename the parameter togroup_name
so that it's clear what's getting named.But with a little more Syntactical structure, and type checking it could be 😄
That's a great question, and I wish I knew what last month me was thinking. I remember running into an edge case where the frame was
None
that caused an issues. Most likely a result of incoherent debugging sessions 🤷♂️@ -213,0 +243,4 @@
def armature_frame_info(obj):
custom_props = {}
if obj.type == 'ARMATURE':
I'd swap this around, and make this a proper precondition check:
LGTM!