Anim: Change how names of Bindings work, and how Bindings are created/assigned #120941

Merged
Sybren A. Stüvel merged 8 commits from dr.sybren/blender:anim/baklava-binding-name-strip-2 into main 2024-04-30 15:51:59 +02:00

This cleans up some of the Animation/Binding API, and adds a distinction between a binding's "name" and its "display name".

An example file is attached below.

name
internal name that is unique within the Animation. As such, it is also the key into the anim.bindings collection.
  • To ensure the uniqueness, name is always prefxed with the ID identifier, like OBCube and CACamera.
  • A binding that was not created to animate a specific ID will be called XXBinding.
name_display
display name that strips the first two characters, so in the above examples would be Cube, Camera, and Binding.

RNA setter behaviour

name
always sets the name, emitting a warning when the name's prefix doesn't match the ID type of the Binding. This implicitly changes the display name (as they are two views into the same string).
name_display
sets name = prefix_for_ID_type + name_display. So even when the old name was QQSomethingWeird, setting binding.name_display = "NewName" would effectively set binding.name = "OBNewName" (assuming it was already bound to some object earlier).

Previously it was possible to "connect" a binding to an animated ID, which would (in pseudocode):

  1. Set id.adt.binding_hande = binding.handle
  2. Set binding.name = id.name and binding.idtype = GS(id.name).

This was confusing, as it doesn't actually assign the Animation itself, and thus would cause some semi-assigned state. This function is no longer available.

A nice aspect of this change is that all public C++ methods on the animrig::Binding class are now const.

Bindings now also always have a name. Previously it was possible to create bindings named "", but that's no longer possible.


Bindings used to be renamed automatically when they were first assigned, for example from XXBinding to OBCube. This behaviour has been removed, as it could potentially cause confusion.


A future UI will use the binding's ID type to draw the appropriate icon. This will make it possible to distinguish bindings by type, so that OBCamera and CACamera are still visually different.

This cleans up some of the Animation/Binding API, and adds a distinction between a binding's "name" and its "display name". An example file is attached below. `name` : internal name that is unique within the `Animation`. As such, it is also the key into the `anim.bindings` collection. - To ensure the uniqueness, `name` is always prefxed with the ID identifier, like `OBCube` and `CACamera`. - A binding that was not created to animate a specific ID will be called `XXBinding`. `name_display` : display name that strips the first two characters, so in the above examples would be `Cube`, `Camera`, and `Binding`. ### RNA setter behaviour `name` : always sets the name, emitting a warning when the name's prefix doesn't match the ID type of the Binding. This implicitly changes the display name (as they are two views into the same string). `name_display` : sets `name = prefix_for_ID_type + name_display`. So even when the old name was `QQSomethingWeird`, setting `binding.name_display = "NewName"` would effectively set `binding.name = "OBNewName"` (assuming it was already bound to some object earlier). ---------- Previously it was possible to "connect" a binding to an animated ID, which would (in pseudocode): 1. Set `id.adt.binding_hande = binding.handle` 2. Set `binding.name = id.name` and `binding.idtype = GS(id.name)`. This was confusing, as it doesn't actually assign the `Animation` itself, and thus would cause some semi-assigned state. This function is no longer available. A nice aspect of this change is that all public C++ methods on the `animrig::Binding` class are now `const`. Bindings now also **always have a name**. Previously it was possible to create bindings named `""`, but that's no longer possible. ----------- Bindings used to be **renamed automatically** when they were first assigned, for example from `XXBinding` to `OBCube`. This behaviour has been removed, as it could potentially cause confusion. ----------- A future UI will use the binding's ID type to draw the appropriate icon. This will make it possible to distinguish bindings by type, so that `OBCamera` and `CACamera` are still visually different.
Sybren A. Stüvel added the
Module
Animation & Rigging
label 2024-04-22 17:07:53 +02:00
Sybren A. Stüvel added 2 commits 2024-04-22 17:08:01 +02:00
9ace45daac Anim: make Binding.name skip the first two characters
Just like ID.name, the Binding.name starts with a two-letter ID code.
ef954ddc98 Change how bindings are connected to animated IDs
Basically there is no more way to "connect" a Binding to an ID without
assigning the Animation. What is possible, however, is to create a Binding
that's already named after the ID, and set up for that ID type.

This reduced the number of ways in which Animation data-blocks can be
assigned to animated IDs, nicely simplifying some things.
Sybren A. Stüvel added 1 commit 2024-04-29 11:07:17 +02:00
Sybren A. Stüvel added 2 commits 2024-04-29 14:35:45 +02:00
Sybren A. Stüvel force-pushed anim/baklava-binding-name-strip-2 from 72f7f97e78 to 4c841b6eba 2024-04-29 16:18:18 +02:00 Compare
Sybren A. Stüvel changed title from WIP: Anim: Change how names of Bindings work, and how Bindings are created/assigned to Anim: Change how names of Bindings work, and how Bindings are created/assigned 2024-04-29 16:30:29 +02:00
Sybren A. Stüvel requested review from Nathan Vegdahl 2024-04-29 16:30:40 +02:00
Author
Member

@blender-bot build

@blender-bot build
Author
Member

@blender-bot build

@blender-bot build
Sybren A. Stüvel added 1 commit 2024-04-29 17:46:07 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
ddd8826a96
Merge remote-tracking branch 'origin/main' into anim/baklava-binding-name-strip-2
Sybren A. Stüvel reviewed 2024-04-29 18:02:47 +02:00
@ -397,0 +429,4 @@
/* If the binding is not yet tied to a type, use the ID name to give its initial name. This
* makes it possible to have bindings named "Binding.047" when they are created, and named
* after whatever is using them when first assigned. */
if (!binding->has_idtype()) {
Author
Member

Change this to a comparison (without suffix) of the default name, and only rename the Binding then. That'll allow setting up an Animation data-block with its bindings, and then assigning it everywhere.

Change this to a comparison (without suffix) of the default name, and only rename the Binding then. That'll allow setting up an Animation data-block with its bindings, and then assigning it everywhere.
dr.sybren marked this conversation as resolved
Sybren A. Stüvel reviewed 2024-04-29 18:05:10 +02:00
@ -574,1 +603,4 @@
std::string Binding::name_prefix_for_idtype() const
{
if (this->idtype == 0) {
Author
Member

use has_idtype()

use `has_idtype()`
dr.sybren marked this conversation as resolved
Sybren A. Stüvel reviewed 2024-04-29 18:17:48 +02:00
@ -127,4 +128,3 @@
static AnimationBinding *rna_Animation_bindings_new(Animation *anim_id,
bContext *C,
ReportList *reports,
ID *animated_id)
Author
Member

rename animated_id to suitable_for, as that's the Python/RNA parameter name.

rename `animated_id` to `suitable_for`, as that's the Python/RNA parameter name.
Member

Reading through this in review, I actually found suitable_for_id to be a confusing name. It reads like a bool. Maybe rename both id_for_binding?

Reading through this in review, I actually found `suitable_for_id` to be a confusing name. It reads like a bool. Maybe rename both `id_for_binding`?
Author
Member

How about for_id? Because the call anim.bindings.new(for_id=C.object) looks kinda nice to me. anim.bindings.new(id_for_binding=C.object) seems a bit repetetive.

How about `for_id`? Because the call `anim.bindings.new(for_id=C.object)` looks kinda nice to me. `anim.bindings.new(id_for_binding=C.object)` seems a bit repetetive.
Author
Member

For those reading along: we discussed face-to-face that id_for_binding is clearest in the C++ code, and the parameter for Python will be for_id.

For those reading along: we discussed face-to-face that `id_for_binding` is clearest in the C++ code, and the parameter for Python will be `for_id`.
dr.sybren marked this conversation as resolved
Sybren A. Stüvel reviewed 2024-04-29 18:22:30 +02:00
@ -224,0 +244,4 @@
if (binding.has_idtype()) {
/* Check if the new name is going to be compatible with the already-established ID type. */
const StringRef name_ref(name);
const std::string old_prefix = binding.name_prefix_for_idtype();
Author
Member

old_prefix is not the right name, prefix_for_idtype would be better.

`old_prefix` is not the right name, `prefix_for_idtype` would be better.
dr.sybren marked this conversation as resolved
Sybren A. Stüvel added 3 commits 2024-04-30 11:50:11 +02:00
Nathan Vegdahl approved these changes 2024-04-30 14:30:54 +02:00
Nathan Vegdahl left a comment
Member

Looks good to me. Just some nits that can be addressed while landing (or ignored if you don't agree).

Looks good to me. Just some nits that can be addressed while landing (or ignored if you don't agree).
@ -122,0 +127,4 @@
/**
* Create a new, unused Binding.
*
* When calling `assign_id(returned_binding, animated_id)`, the binding will be renamed to that
Member

This behavior of assign_id() doesn't appear to be documented on assign_id() itself.

This behavior of `assign_id()` doesn't appear to be documented on `assign_id()` itself.
dr.sybren marked this conversation as resolved
@ -169,0 +199,4 @@
void binding_name_ensure_prefix(Binding &binding);
/**
* Set the binding's name and ID type to those of the animated ID.
Member

Document the behavior when the binding already has an ID type, since that's non-obvious without looking at the code right now.

It also appears (looking at the implementation) that the name is no longer assigned, aside from just ensuring it's not a duplicate.

Document the behavior when the binding already has an ID type, since that's non-obvious without looking at the code right now. It also appears (looking at the implementation) that the name is no longer assigned, aside from just ensuring it's not a duplicate.
dr.sybren marked this conversation as resolved
@ -383,3 +420,3 @@
if (adt->animation) {
if (adt->animation && adt->animation != this) {
/* Unassign the ID from its existing animation first, or use the top-level
Member

Nit: this phrasing reads as if it's a description of the code below, rather than a description of what should be done to avoid this case. Maybe just prepend "To avoid this case".

Nit: this phrasing reads as if it's a description of the code below, rather than a description of what should be done to avoid this case. Maybe just prepend "To avoid this case".
dr.sybren marked this conversation as resolved
@ -575,0 +635,4 @@
StringRefNull Binding::name_without_prefix() const
{
/* Avoid accessing an uninitialised part of the string accidentally. */
if (this->name[0] == '\0' || this->name[1] == '\0') {
Member

My initial reaction was that this shouldn't be possible, and should be turned into an assert. But since the user can directly set the whole name, that's what can cause this (if I'm understanding correctly).

Maybe make a short note of that, either here or where the name field is defined, since this departs from how name prefixes work in other parts of Blender (namely IDs).

My initial reaction was that this shouldn't be possible, and should be turned into an assert. But since the user can directly set the whole name, that's what can cause this (if I'm understanding correctly). Maybe make a short note of that, either here or where the name field is defined, since this departs from how name prefixes work in other parts of Blender (namely IDs).
Author
Member

The code should remain, as asserts are debug-only, and in release mode Blender should still be crash-free. But you have a good point, and I'll add some more asserts anyway + checks on the length in the RNA setters.

The code should remain, as asserts are debug-only, and in release mode Blender should still be crash-free. But you have a good point, and I'll add some more asserts anyway + checks on the length in the RNA setters.
dr.sybren marked this conversation as resolved
@ -258,0 +258,4 @@
WM_reportf(RPT_ERROR,
"Animation '%s' binding '%s' (%d) could not be assigned to %s",
anim->id.name + 2,
binding->name_without_prefix().c_str(),
Member

It might make sense to print the full name here instead, or at least also print the type prefix separately. If the Animation has both OBCube and MECube bindings, it may not be immediately obvious which one is being referred to, forcing the reader to do more thinking than needed to troubleshoot it.

It might make sense to print the full name here instead, or at least also print the type prefix separately. If the `Animation` has both `OBCube` and `MECube` bindings, it may not be immediately obvious which one is being referred to, forcing the reader to do more thinking than needed to troubleshoot it.
dr.sybren marked this conversation as resolved
Sybren A. Stüvel added 2 commits 2024-04-30 15:13:33 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
f7e293dd62
The rest of the feedback
Author
Member

@blender-bot build

@blender-bot build
Sybren A. Stüvel added 1 commit 2024-04-30 15:22:45 +02:00
Sybren A. Stüvel merged commit 0da53b5e62 into main 2024-04-30 15:51:59 +02:00
Sybren A. Stüvel deleted branch anim/baklava-binding-name-strip-2 2024-04-30 15:52:01 +02:00
Sign in to join this conversation.
No reviewers
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
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#120941
No description provided.