Anim: hierarchical visibility for bone collections #116784

Manually merged
Sybren A. Stüvel merged 6 commits from dr.sybren/blender:anim/bone-collections-hierarchical-visibility into main 2024-01-05 15:35:37 +01:00

Bone collection visibility now respects their hierarchy.

A bone collection is only visible when it is marked as visible and all its ancestors (so parents, greatparents, etc.) are visible. Root bone
collections have no ancestors by definition, and only consider their own visibility.

image

The visibility 'eye' is dimmed when the bone collection is hidden because of its ancestors' visibility.

The effective ancestors' visibility is stored on each bone collection, in its BONE_COLLECTION_ANCESTORS_VISIBLE flag. This makes it possible to determine the effective visibility from just the flags of the bone collection itself.


Note for the reviewers: some function names (mostly is_visible_ancestors() and is_visible_effectively()) are IMO a bit awkward. I chose those so that all the is_visible… functions are sorted together. If you have suggestions for better names, let me know!

The BONE_COLLECTION_ANCESTORS_VISIBLE flag is now stored, with the other flags, in BoneCollection::flags. This means that it's stored in DNA, even though it's derived data and should actually be stored in a runtime struct. However, BoneCollection doesn't have any runtime struct yet, and I don't feel that the introduction of this flag is a good enough reason to introduce that just yet. Again, open to other opinions.

Bone collection visibility now respects their hierarchy. A bone collection is only visible when it is marked as visible and all its ancestors (so parents, greatparents, etc.) are visible. Root bone collections have no ancestors by definition, and only consider their own visibility. ![image](/attachments/6ae5096a-9d24-43d7-ac81-3fe2b740ea3d) The visibility 'eye' is dimmed when the bone collection is hidden because of its ancestors' visibility. The effective ancestors' visibility is stored on each bone collection, in its `BONE_COLLECTION_ANCESTORS_VISIBLE` flag. This makes it possible to determine the effective visibility from just the flags of the bone collection itself. -------------- Note for the reviewers: some function names (mostly `is_visible_ancestors()` and `is_visible_effectively()`) are IMO a bit awkward. I chose those so that all the `is_visible…` functions are sorted together. If you have suggestions for better names, let me know! The `BONE_COLLECTION_ANCESTORS_VISIBLE` flag is now stored, with the other flags, in `BoneCollection::flags`. This means that it's stored in DNA, even though it's derived data and should actually be stored in a runtime struct. However, `BoneCollection` doesn't have any runtime struct yet, and I don't feel that the introduction of this flag is a good enough reason to introduce that just yet. Again, open to other opinions.
Sybren A. Stüvel added 3 commits 2024-01-04 15:08:25 +01:00
d12fa306f7 Refactor: Anim, rename function to `ANIM_bone_in_visible_collection()`
Rename `ANIM_bonecoll_is_visible(armature, bone)` to
`ANIM_bone_in_visible_collection(armature, bone)`, as that reflects the
actual functionality.

No functional changes.
6874c87747 Cleanup: Anim, insert section start/end comments
Insert section comments `/* \{ */` and `/** \{ */` to `armature.cc`.

No functional changes.
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
d56b4f9b4f
Anim: hierarchical visibility for bone collections
Bone collection visibility now respects their hierarchy.

A bone collection is only visible when it is marked as visible and all
its ancestors (so parents, greatparents, etc.) are visible. Root bone
collections have no ancestors by definition, and only consider their own
visibility.

The effective ancestors' visibility is stored on each bone collection,
in its `BONE_COLLECTION_ANCESTORS_VISIBLE` flag. This makes it possible
to determine the effective visibility from just the flags of the bone
collection itself.
Sybren A. Stüvel requested review from Nathan Vegdahl 2024-01-04 15:20:47 +01:00
Sybren A. Stüvel requested review from Christoph Lendenfeld 2024-01-04 15:20:47 +01:00
Sybren A. Stüvel added the
Module
Animation & Rigging
label 2024-01-04 15:20:58 +01:00
Sybren A. Stüvel added this to the 4.1 milestone 2024-01-04 15:21:01 +01:00
Sybren A. Stüvel added this to the Animation & Rigging project 2024-01-04 15:21:04 +01:00
Author
Member

@blender-bot package

@blender-bot package
Member

Package build started. Download here when ready.

Package build started. [Download here](https://builder.blender.org/download/patch/PR116784) when ready.
Nathan Vegdahl requested changes 2024-01-04 16:46:58 +01:00
Nathan Vegdahl left a comment
Member

Aside from a documentation nit and a couple minor spelling/naming issues, this looks great to me! Awesome work.

Also, just want to mention again how much I appreciate your code documentation! It's a lot easier to read/grok code when I know what the intended behavior is. :-)

Aside from a documentation nit and a couple minor spelling/naming issues, this looks great to me! Awesome work. Also, just want to mention again how much I appreciate your code documentation! It's a lot easier to read/grok code when I know what the intended behavior is. :-)
@ -219,0 +224,4 @@
/**
* Hide this bone collection.
*
* This marks the bone collection as 'hidden'. This also effectively hides its decendants,
Member

Spelling, throughout this PR: decendant -> descendant

(Don't feel bad: I almost didn't catch it myself, ha ha.)

Spelling, throughout this PR: decendant -> descendant (Don't feel bad: I almost didn't catch it myself, ha ha.)
dr.sybren marked this conversation as resolved
@ -219,0 +231,4 @@
/**
* Show or hide this bone collection.
*
* Do not use this with a hard-coded `is_visible` parameter, but use one of the
Member

Nit: IMO "Do not use..." gives the impression that the results will be incorrect if you do so. It's fairly obvious that that's not the case here, but it did give me minor cognitive dissonance for a moment.

Maybe something like this would be better:

"Calling this with a hard-coded is_visible parameter is equivalent to calling the dedicated show/hide functions. Prefer the dedicated functions for clarity."

Nit: IMO "Do not use..." gives the impression that the results will be incorrect if you do so. It's fairly obvious that that's not the case here, but it did give me minor cognitive dissonance for a moment. Maybe something like this would be better: "Calling this with a hard-coded `is_visible` parameter is equivalent to calling the dedicated show/hide functions. Prefer the dedicated functions for clarity."
dr.sybren marked this conversation as resolved
@ -716,0 +750,4 @@
}
/* Set/clear BONE_COLLECTION_ANCESTORS_VISIBLE on this bone collection and all its decendents. */
static void ancestors_visible_update(bArmature *armature,
Member

Just noting a possible alternative, rather than actually suggesting a change per se:

I was waffling back-and-forth on how I feel about the redundancy between this function and ancestors_visible_decendants_update() above.

I believe if we want to we could reduce both to a single function. Basically, we would effectively move the logic of ancestors_visible_decendants_update() into this function. Then at the top of this function, if (and only if) parent_bcoll is null we scan to find its parent (leaving it null if bcoll is a root).

That would make this function slower due to the additional linear scan at the initial call (but not subsequent recursive calls), and also because it would always update bcoll itself even when not strictly needed. But it would also reduce the API surface. So it's a trade-off.

I don't feel strongly either way, so I'm happy with the code as-is. But just wanted to mention the alternative.

Just noting a possible alternative, rather than actually suggesting a change per se: I was waffling back-and-forth on how I feel about the redundancy between this function and `ancestors_visible_decendants_update()` above. I believe if we want to we could reduce both to a single function. Basically, we would effectively move the logic of `ancestors_visible_decendants_update()` into this function. Then at the top of this function, if (and only if) `parent_bcoll` is null we scan to find its parent (leaving it null if `bcoll` is a root). That would make this function slower due to the additional linear scan at the initial call (but not subsequent recursive calls), and also because it would always update `bcoll` itself even when not strictly needed. But it would also reduce the API surface. So it's a trade-off. I don't feel strongly either way, so I'm happy with the code as-is. But just wanted to mention the alternative.
Author
Member

I've been pondering the same thing, and to me it was easier to comprehend what was going on with separate "update this bcoll and its descendents" vs. "make sure the descendents are in sync with their parent" functions.

Since these are static functions, and thus not part of any public API, I think I'd like to keep them smaller and more specific.

I've been pondering the same thing, and to me it was easier to comprehend what was going on with separate "update this bcoll and its descendents" vs. "make sure the descendents are in sync with their parent" functions. Since these are `static` functions, and thus not part of any public API, I think I'd like to keep them smaller and more specific.
nathanvegdahl marked this conversation as resolved
@ -456,0 +464,4 @@
BoneCollection *bcoll_r0_child0 = ANIM_armature_bonecoll_new(&arm, "r0_child0", root0_index);
BoneCollection *bcoll_r0_child1 = ANIM_armature_bonecoll_new(&arm, "r0_child1", root0_index);
const int child0_index = armature_bonecoll_find_index(&arm, bcoll_r0_child0);
BoneCollection *bcoll_c1_child0 = ANIM_armature_bonecoll_new(&arm, "c1_child0", child0_index);
Member

Not sure if this is a naming mistake or a choice-of-parent mistake. With the name c1_child0, I would expect its parent to be r0_child1, but in fact the parent is being set to r0_child0.

Not sure if this is a naming mistake or a choice-of-parent mistake. With the name `c1_child0`, I would expect its parent to be `r0_child1`, but in fact the parent is being set to `r0_child0`.
dr.sybren marked this conversation as resolved
Sybren A. Stüvel added 3 commits 2024-01-04 17:32:59 +01:00
Sybren A. Stüvel requested review from Nathan Vegdahl 2024-01-04 17:33:28 +01:00
Nathan Vegdahl approved these changes 2024-01-04 17:42:26 +01:00
Nathan Vegdahl left a comment
Member

Looks good to me!

Looks good to me!
Christoph Lendenfeld requested changes 2024-01-05 11:00:04 +01:00
Christoph Lendenfeld left a comment
Member

just some minor things
One thing I noticed is that there is no function to get the effective visibility from python. Or am I missing something?

just some minor things One thing I noticed is that there is no function to get the effective visibility from python. Or am I missing something?
@ -716,0 +749,4 @@
}
}
/* Set/clear BONE_COLLECTION_ANCESTORS_VISIBLE on this bone collection and all its decendents. */

minor, but this could also read "Set or clear" just like the function above

minor, but this could also read "Set or clear" just like the function above
Author
Member

I shortened it, as with "Set or clear" it will rewrap the line and put the closing */ on a line by itself. Now it juuuuust fits.

I shortened it, as with "Set or clear" it will rewrap the line and put the closing `*/` on a line by itself. Now it juuuuust fits.
@ -267,0 +297,4 @@
*
* \return true when this collection and all its ancestors are visible.
*
* \see is_visisble

typo in visisble vs visible

typo in `visisble` vs `visible`
dr.sybren marked this conversation as resolved
@ -267,0 +299,4 @@
*
* \see is_visisble
*/
bool is_visible_effectively() const;

I usually went for e.g. is_visible_in_hierarchy in such cases.
"effectively" doesn't tell me much tbh

There is also another way of doing it, where is_visible returns the effective visibility
and you have another function get_collection_visibility (or similar) to get the actual flag

I usually went for e.g. `is_visible_in_hierarchy` in such cases. "effectively" doesn't tell me much tbh There is also another way of doing it, where `is_visible` returns the effective visibility and you have another function `get_collection_visibility` (or similar) to get the actual flag
Author
Member

This is something I've been struggling with indeed, as there are now three "visibilities":

  1. the flag
  2. the effective visibility
  3. whether the bone collection can be seen in the tree view (i.e. its parents are expanded)

I don't think there's names without any downside; is_visible_in_hierarchy to me feels more like the 3rd option, because "the hierarchy" conjures the image of the tree structure.

I'll keep the naming as is, and double-check the documentation to ensure things are as clearly described as possible.

This is something I've been struggling with indeed, as there are now three "visibilities": 1. the flag 2. the effective visibility 3. whether the bone collection can be seen in the tree view (i.e. its parents are expanded) I don't think there's names without any downside; `is_visible_in_hierarchy` to me feels more like the 3rd option, because "the hierarchy" conjures the image of the tree structure. I'll keep the naming as is, and double-check the documentation to ensure things are as clearly described as possible.

hm, imo the bone collection shouldn't need to know if its expanded or not.
but this is an issue of blender in general where the core datastructure and the GUI are too closely connected.

hm, imo the bone collection shouldn't need to know if its expanded or not. but this is an issue of blender in general where the core datastructure and the GUI are too closely connected.
Author
Member

One thing I noticed is that there is no function to get the effective visibility from python. Or am I missing something?

Good point, the logic for which flags to combine to compute that should be in one place, and not replicated in Python as well. So I'll add a read-only property.

> One thing I noticed is that there is no function to get the effective visibility from python. Or am I missing something? Good point, the logic for which flags to combine to compute that should be in one place, and not replicated in Python as well. So I'll add a read-only property.
Sybren A. Stüvel added 2 commits 2024-01-05 14:39:05 +01:00
Sybren A. Stüvel requested review from Christoph Lendenfeld 2024-01-05 14:39:08 +01:00
Christoph Lendenfeld approved these changes 2024-01-05 15:04:09 +01:00
Christoph Lendenfeld left a comment
Member

lgtm

lgtm
Sybren A. Stüvel manually merged commit 6cfbf9ef2f into main 2024-01-05 15:35:37 +01:00
Author
Member

Landed in a9d9c3b116 with review comments addressed in d4ce5d6fc9 and a9d9c3b116.

Landed in a9d9c3b1163b1acacff8e0b0279fd363f505d855 with review comments addressed in d4ce5d6fc9e12a08094b01cf02189bafb38f8e95 and a9d9c3b1163b1acacff8e0b0279fd363f505d855.
Sybren A. Stüvel deleted branch anim/bone-collections-hierarchical-visibility 2024-01-05 15:36:27 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser Project (Legacy)
Interest
Asset System
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 Assignees
4 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#116784
No description provided.