Anim: Add channel type options to the Bake Action operator #111997

Merged
Nate Rupsis merged 9 commits from nrupsis/blender:anim-bake-components into main 2023-09-29 15:38:32 +02:00
Member

Helping land this patch for @cmbasnett & @BClark


Currently, we're limited to the type of Bake Data, without any control over the channels that get baked.

With this change, the user now has a fine degree of control as to which types of f-curve data will be written to the baked action (i.e., location, rotation, scale & b-bone channels).

action_bake_options.png

Recovered from: https://archive.blender.org/developer/D16481

Helping land this patch for @cmbasnett & @BClark --- Currently, we're limited to the type of Bake Data, without any control over the channels that get baked. With this change, the user now has a fine degree of control as to which types of f-curve data will be written to the baked action (i.e., location, rotation, scale & b-bone channels). ![action_bake_options.png](/attachments/47c163f4-8cc4-4e7f-8541-7995a88638a0) Recovered from: https://archive.blender.org/developer/D16481
Nate Rupsis added the
Module
Animation & Rigging
label 2023-09-05 22:08:59 +02:00
Nate Rupsis added 4 commits 2023-09-05 22:09:13 +02:00
Nate Rupsis requested review from Nathan Vegdahl 2023-09-05 22:10:45 +02:00
Nate Rupsis requested review from Brad Clark 2023-09-05 22:10:46 +02:00
Nate Rupsis requested review from Sybren A. Stüvel 2023-09-05 22:10:59 +02:00
Member

I'd like to re-raise my question from #110903: do we actually want separate options for location/rotation/scale, or should it just be a single "transforms" option?

To clarify:

  1. I agree that we need to add support for baking custom attributes. But I believe that's unrelated to whether transforms are a single option vs separate location/rotation/scale options.
  2. Further, I agree that it's useful to have fine-grained control over what gets baked, and I don't doubt there are use cases where you want to e.g. bake location and rotation but not scale. However, fully supporting fine-grained control over what gets baked cannot be done with a list of options like this—the list of options would get huge. Case in point: we could also have a full separate list of location/rotation/scale options for both object and pose. Basically, we can always just keep growing the number of options to support more use cases. But I think there needs to be a limit at some point, and an acknowledgement that to fully support fine-grained baking control we'll need to re-think how this works more broadly. Which we should definitely do, IMO, but the timeline for that is unclear.

So my question isn't whether splitting location/rotation/scale is useful or not. My question is where is that line where we stop adding more options and wait for a proper redesign. And the answer may well be that having separate loc/rot/scale options is sufficiently useful to justify adding them right now. But I just want to make sure we consider that in the larger context of option bloat.

I'd like to re-raise my question from #110903: do we actually want separate options for location/rotation/scale, or should it just be a single "transforms" option? To clarify: 1. I agree that we need to add support for baking custom attributes. But I believe that's unrelated to whether transforms are a single option vs separate location/rotation/scale options. 2. Further, I agree that it's useful to have fine-grained control over what gets baked, and I don't doubt there are use cases where you want to e.g. bake location and rotation but not scale. However, *fully* supporting fine-grained control over what gets baked cannot be done with a list of options like this—the list of options would get *huge*. Case in point: we could also have a full separate list of location/rotation/scale options for both object and pose. Basically, we can always just keep growing the number of options to support more use cases. But I think there needs to be a limit at some point, and an acknowledgement that to fully support fine-grained baking control we'll need to re-think how this works more broadly. Which we should definitely do, IMO, but the timeline for that is unclear. So my question isn't whether splitting location/rotation/scale is useful or not. My question is where is that line where we stop adding more options and wait for a proper redesign. And the answer may well be that having separate loc/rot/scale options is sufficiently useful to justify adding them right now. But I just want to make sure we consider that in the larger context of option bloat.
Sybren A. Stüvel requested changes 2023-09-11 11:12:53 +02:00
Sybren A. Stüvel left a comment
Member

I think the function argument count is getting out of hand. Better to do a cleanup pass first, moving the existing options into a class, like below, and pass that instead of the separate arguments.

@dataclass
class BakeOptions:
    only_selected: bool
    do_pose: bool
    do_object: bool
    do_visual_keying: bool
    do_constraint_clear: bool
    do_parents_clear: bool
    do_clean: bool

To keep in mind for that refactor: I don't think it makes much sense to have any default values specified in the bake_action_iter() parameters, as I don't think it's ever called without these arguments. There shouldn't be any need to sync up the UI defaults with this particular function (single responsibility principle: only one thing should be responsible for setting the defaults).

PS: please make sure that the PR description matches the Ingredients of a Pull Request.

I think the function argument count is getting out of hand. Better to do a cleanup pass first, moving the existing options into a class, like below, and pass that instead of the separate arguments. ```python @dataclass class BakeOptions: only_selected: bool do_pose: bool do_object: bool do_visual_keying: bool do_constraint_clear: bool do_parents_clear: bool do_clean: bool ``` To keep in mind for that refactor: I don't think it makes much sense to have any default values specified in the `bake_action_iter()` parameters, as I don't think it's ever called without these arguments. There shouldn't be any need to sync up the UI defaults with this particular function (single responsibility principle: only one thing should be responsible for setting the defaults). PS: please make sure that the PR description matches the [Ingredients of a Pull Request](https://wiki.blender.org/wiki/Process/Contributing_Code#Ingredients_of_a_Pull_Request).
Author
Member

I think the function argument count is getting out of hand. Better to do a cleanup pass first, moving the existing options into a class, like below, and pass that instead of the separate arguments.

@dr.sybren for creating data classes (types), where should those live? Obviously we'd be using it anim_utils.py, but bake_action_objects is called from anim.py, and I'd assume we'd want to clean up bake_action_objects's parameters too?

> I think the function argument count is getting out of hand. Better to do a cleanup pass first, moving the existing options into a class, like below, and pass that instead of the separate arguments. @dr.sybren for creating data classes (types), where should those live? Obviously we'd be using it anim_utils.py, but `bake_action_objects` is called from `anim.py`, and I'd assume we'd want to clean up `bake_action_objects`'s parameters too?

anim.py imports anim_utils.py, so IMO the class(es) should be in anim_utils.py to avoid circular dependencies.

`anim.py` imports `anim_utils.py`, so IMO the class(es) should be in `anim_utils.py` to avoid circular dependencies.
Nate Rupsis added 4 commits 2023-09-20 00:02:40 +02:00
Nate Rupsis changed title from Animation: Add channel type options to the Bake Action operator to Anim: Add channel type options to the Bake Action operator 2023-09-20 00:06:02 +02:00
Sybren A. Stüvel requested changes 2023-09-21 17:30:34 +02:00
Sybren A. Stüvel left a comment
Member

Looking much better!

Too bad it doesn't work any more ;-)

Error: Python: Traceback (most recent call last):
  File "build_linux/bin/4.0/scripts/startup/bl_operators/anim.py", line 306, in execute
    actions = anim_utils.bake_action_objects(
  File "build_linux/bin/4.0/scripts/modules/bpy_extras/anim_utils.py", line 96, in bake_action_objects
    iter.send(None)
  File "build_linux/bin/4.0/scripts/modules/bpy_extras/anim_utils.py", line 120, in bake_action_objects_iter
    iter.send(None)
  File "build_linux/bin/4.0/scripts/modules/bpy_extras/anim_utils.py", line 256, in bake_action_iter
    if not (do_pose or bake_options.do_object):
UnboundLocalError: local variable 'do_pose' referenced before assignment

I think it's better to split apart the PR into a non-functional part (extraction of BakeOptions) and a functional part (the actual functional changes in this PR).

Looking much better! Too bad it doesn't work any more ;-) ``` Error: Python: Traceback (most recent call last): File "build_linux/bin/4.0/scripts/startup/bl_operators/anim.py", line 306, in execute actions = anim_utils.bake_action_objects( File "build_linux/bin/4.0/scripts/modules/bpy_extras/anim_utils.py", line 96, in bake_action_objects iter.send(None) File "build_linux/bin/4.0/scripts/modules/bpy_extras/anim_utils.py", line 120, in bake_action_objects_iter iter.send(None) File "build_linux/bin/4.0/scripts/modules/bpy_extras/anim_utils.py", line 256, in bake_action_iter if not (do_pose or bake_options.do_object): UnboundLocalError: local variable 'do_pose' referenced before assignment ``` I think it's better to split apart the PR into a non-functional part (extraction of `BakeOptions`) and a functional part (the actual functional changes in this PR).
@ -126,2 +138,2 @@
do_parents_clear=False,
do_clean=False
bake_options: BakeOptions
# only_selected=False,

If this is to be kept, please add a comment that explains why.

If this is to be kept, please add a comment that explains why.
nrupsis marked this conversation as resolved
@ -148,6 +170,14 @@ def bake_action_iter(
:type do_parents_clear: bool
:arg do_clean: Remove redundant keyframes after baking.
:type do_clean: bool
:arg do_location: Bake location channels.

These arguments no longer exist. Explanation of which option means what could go into BakeOptions.

These arguments no longer exist. Explanation of which option means what could go into `BakeOptions`.
nrupsis marked this conversation as resolved
@ -257,3 +269,4 @@
from bpy_extras import anim_utils
do_pose = 'POSE' in self.bake_types
do_object = 'OBJECT' in self.bake_types
do_location = 'LOCATION' in self.channel_types

Because these aren't used here directly, I think it's clearer to just have do_location='LOCATION' in self.channel_types in the anim_utils.BakeOptions(...) call.

Because these aren't used here directly, I think it's clearer to just have `do_location='LOCATION' in self.channel_types` in the `anim_utils.BakeOptions(...)` call.
nrupsis marked this conversation as resolved
Nate Rupsis added 1 commit 2023-09-29 03:12:27 +02:00
Nate Rupsis requested review from Sybren A. Stüvel 2023-09-29 03:13:21 +02:00
Sybren A. Stüvel approved these changes 2023-09-29 11:21:00 +02:00
Sybren A. Stüvel left a comment
Member

LGTM!

LGTM!
Nate Rupsis merged commit dd5b870d15 into main 2023-09-29 15:38:32 +02:00
Nate Rupsis deleted branch anim-bake-components 2023-09-29 15:38:33 +02:00

My question is where is that line where we stop adding more options and wait for a proper redesign.

I think this step is pretty reasonable. So let's consider this the last extension of the current code. It's been stretched far enough.

> My question is where is that line where we stop adding more options and wait for a proper redesign. I think this step is pretty reasonable. So let's consider this the last extension of the current code. It's been stretched far enough.
Sign in to join this conversation.
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
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#111997
No description provided.