Anim: migrate Action assignments to the new API #128026

Merged
Sybren A. Stüvel merged 2 commits from dr.sybren/blender:anim/refactor-action-assignments into main 2024-09-23 15:53:48 +02:00

Instead of assigning Actions by direct pointer manipulation (and the
corresponding juggling of user counts), call animrig::assign_action()
and animrig::unassign_action().

These functions not only correctly handle user counts, but also ensure
that slot assignments & user tracking works. The former always happens,
the latter only when building with experimental features enabled.

Because (un)assigning slotted Actions need the animated ID (instead of
just the AnimData *), more functions now require an OwnedAnimData.

Note that there is still some user count juggling. This is caused by
BKE_id_new(), and by extension BKE_action_add, returning an ID with
user count = 1, even though that ID is not yet used. A todo task #128017
has been made to change BKE_action_add() so that the Action it returns
can be directly fed into animrig::assign_action().

This PR updates the following areas:

  • Creating a node group by grouping animated nodes, as this has to move
    the animation data. This PR just handles the assignment of a new
    Action.
  • Temporary Action creation for ungrouping node groups.
  • Versioning of pre-2.5 animation data.

No functional changes.

Ref: #123424


This PR sits on top of #128030, will rebase later.

Instead of assigning Actions by direct pointer manipulation (and the corresponding juggling of user counts), call `animrig::assign_action()` and `animrig::unassign_action()`. These functions not only correctly handle user counts, but also ensure that slot assignments & user tracking works. The former always happens, the latter only when building with experimental features enabled. Because (un)assigning slotted Actions need the animated ID (instead of just the `AnimData *`), more functions now require an `OwnedAnimData`. Note that there is still some user count juggling. This is caused by `BKE_id_new()`, and by extension `BKE_action_add`, returning an ID with user count = 1, even though that ID is not yet used. A todo task #128017 has been made to change `BKE_action_add()` so that the Action it returns can be directly fed into `animrig::assign_action()`. This PR updates the following areas: - Creating a node group by grouping animated nodes, as this has to move the animation data. This PR just handles the assignment of a new Action. - Temporary Action creation for ungrouping node groups. - Versioning of pre-2.5 animation data. No functional changes. Ref: #123424 ------- This PR sits on top of #128030, will rebase later.
Sybren A. Stüvel added the
Module
Animation & Rigging
label 2024-09-23 13:04:47 +02:00
Sybren A. Stüvel added 5 commits 2024-09-23 13:04:56 +02:00
The call was followed by `BKE_animdata_ensure_id(id)`, which already
returns any existing animdata.

No functional changes.
Make `BKE_animdata_action_ensure_idroot()` do the right thing when a
layered Action is passed in.
Instead of simply reassigning the `adt->action` and `adt->tmpact` pointers,
the code now uses the `animrig::assign_action()` and `assign_tmpaction()`.
This way the slot user maps should be properly updated.
The `animrig::assign_action(action, id)` function now takes a `bAction`
pointer (instead of its C++ wrapper `animrig::Action`). This makes it
easier to call from code that just deals with the DNA/C struct.

Also an override was added that takes an `OwnedAnimData` struct instead
of just the ID. This saves the lookup of the AnimData, to be used in cases
where the caller already has it.
Anim: correctly assign Action in id_action_ensure()
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
e6c2688e61
Fix two bugs by replacing direct assignment to `adt->action` with a call
to `animrig::assign_action()`:

- If a related Action was found, its user count was not incremented.
- If a new Action is created, its `idroot` was not properly set.
Author
Member

@blender-bot build

@blender-bot build
Sybren A. Stüvel force-pushed anim/refactor-action-assignments from bc57f6994d to 7c2fd9f964 2024-09-23 14:10:16 +02:00 Compare
Sybren A. Stüvel changed title from anim/refactor-action-assignments to Anim: migrate Action assignments to the new API 2024-09-23 14:10:36 +02:00
Sybren A. Stüvel requested review from Nathan Vegdahl 2024-09-23 14:13:34 +02:00
Nathan Vegdahl approved these changes 2024-09-23 15:25:39 +02:00
Nathan Vegdahl left a comment
Member

Just one place where I think the code could be clearer, which can be addressed while landing. Otherwise looks good, and kicking the tires a bit didn't reveal any issues.

Just one place where I think the code could be clearer, which can be addressed while landing. Otherwise looks good, and kicking the tires a bit didn't reveal any issues.
@ -746,3 +761,1 @@
id_us_min(&dstAdt->action->id);
dstAdt->action = BKE_action_add(bmain, dstAdt->action->id.name + 2);
BKE_animdata_action_ensure_idroot(dstID, dstAdt->action);
if (dstAdt->action) {
Member

If I understand correctly, what this is really saying is if (dstAdt->action == srcAdt->action). But you have to reason about the outer if's conditions to see that.

I think this can be refactored to be clearer by changing this to if (dstAdt->action == srcAdt->action) and moving it above the if (!dstAdt->action || dstAdt->action == srcAdt->action) block. And then also changing that to just if (!dstAdt->action).

In other words, the flow would then be:

  1. If dst action == src action, issue warning and unassign action from dst.
  2. If dst has no action assigned, create and assign one.
If I understand correctly, what this is really saying is `if (dstAdt->action == srcAdt->action)`. But you have to reason about the outer if's conditions to see that. I think this can be refactored to be clearer by changing this to `if (dstAdt->action == srcAdt->action)` and moving it above the `if (!dstAdt->action || dstAdt->action == srcAdt->action)` block. And then also changing *that* to just `if (!dstAdt->action)`. In other words, the flow would then be: 1. If dst action == src action, issue warning and unassign action from dst. 2. If dst has no action assigned, create and assign one.
dr.sybren marked this conversation as resolved
Sybren A. Stüvel force-pushed anim/refactor-action-assignments from 7c2fd9f964 to 77d51d1603 2024-09-23 15:49:56 +02:00 Compare
Sybren A. Stüvel added 1 commit 2024-09-23 15:53:03 +02:00
Sybren A. Stüvel merged commit 6115132998 into main 2024-09-23 15:53:48 +02:00
Sybren A. Stüvel deleted branch anim/refactor-action-assignments 2024-09-23 15:53:51 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
FBX
Interest
Freestyle
Interest
Geometry Nodes
Interest
glTF
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 & 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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
2 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#128026
No description provided.