Anim: move ANIM_... bone collection functions into C++ style, such as the blender::animrig namespace #116938

Open
opened 2024-01-09 12:39:26 +01:00 by Sybren A. Stüvel · 2 comments

When bone collections were introduced, they replaced armature layers. The latter had an older C-style API, which translated into the bone collections following a similar approach. Now that much more of Blender's code has been moved to C++, a few refactors are in order:

Some of these are marked as 'OPTIONAL', as they need more discussion & better view of where we are going with the C++ style code.

  • OPTIONAL: Create a separate C++ wrapper for bone collections. This would follow the approach we have for the BoneColor struct, where there is an explicit distinction between the C DNA struct and its C++ wrapper class. Currently the DNA BoneCollection struct has some C++ methods on it, directly. Because of that, any alteration to its C++ interface requires recompiling everything that (indirectly) includes DNA_armature_types.h, which can get cumbersome during development. The downside is that there's then a difference between ::BoneCollection (DNA) and blender::animrig::BoneCollection (C++ wrapper).
  • Clean up some of the ANIM_… functions that were created during the transition from animation layers to bone collections. Now that the latter are more mature, we may not need all of those, or they could use some renaming to clarify their functionality.
  • Move some more querying functions into the C++ BoneCollection class. I think currently only bonecoll_has_children() could move to BoneCollection::has_children(), as the other functions all require access to the armature as well.
  • Wherever possible, move the ANIM_… functions to the blender::animrig namespace and drop their ANIM_ prefix.
  • Double-check that all functions that require the armature as well are named armature_bonecoll_….
  • OPTIONAL: Create a separate C++ wrapper for bArmature, which could then receive all the armature_bonecoll_… functions as bArmature::bonecoll_… methods.
When bone collections were introduced, they replaced armature layers. The latter had an older C-style API, which translated into the bone collections following a similar approach. Now that much more of Blender's code has been moved to C++, a few refactors are in order: Some of these are marked as 'OPTIONAL', as they need more discussion & better view of where we are going with the C++ style code. - [ ] OPTIONAL: Create a separate C++ wrapper for bone collections. This would follow the approach we have for the `BoneColor` struct, where there is an explicit distinction between the C DNA struct and its C++ wrapper class. Currently the DNA `BoneCollection` struct has some C++ methods on it, directly. Because of that, any alteration to its C++ interface requires recompiling everything that (indirectly) includes `DNA_armature_types.h`, which can get cumbersome during development. The downside is that there's then a difference between `::BoneCollection` (DNA) and `blender::animrig::BoneCollection` (C++ wrapper). - [ ] Clean up some of the `ANIM_…` functions that were created during the transition from animation layers to bone collections. Now that the latter are more mature, we may not need all of those, or they could use some renaming to clarify their functionality. - [ ] Move some more querying functions into the C++ `BoneCollection` class. I think currently only `bonecoll_has_children()` could move to `BoneCollection::has_children()`, as the other functions all require access to the armature as well. - [ ] Wherever possible, move the ` ANIM_…` functions to the `blender::animrig` namespace and drop their `ANIM_` prefix. - [ ] Double-check that all functions that require the armature as well are named `armature_bonecoll_…`. - [ ] OPTIONAL: Create a separate C++ wrapper for `bArmature`, which could then receive all the `armature_bonecoll_…` functions as `bArmature::bonecoll_…` methods.
Sybren A. Stüvel added the
Module
Animation & Rigging
Type
To Do
labels 2024-01-09 12:39:26 +01:00
Sybren A. Stüvel self-assigned this 2024-01-09 12:39:26 +01:00
Member

This all looks pretty sensible to me.

OPTIONAL: Create a separate C++ wrapper for bone collections.
[...]
OPTIONAL: Create a separate C++ wrapper for bArmature

I'm on the fence about the benefits of this. If a type has a single clear representation, that makes things simpler and easier to think about. But I do agree that the compile time hit of putting methods directly on the DNA types is obnoxious.

If C++ wrappers do end up being how we deal with this kind of thing in Blender, I think we should settle on one canonical way to do it across the whole code base with uniform naming schemes, and document that pattern so that it's clear to anyone diving into the code base.

(Side note that's beyond the scope of this issue: I doubt there's much disagreement here, but ideally I'd like to see some level of C++-ification of DNA itself. For example, being limited to C in DNA is why we had to essentially write our own duplicate Vector code for bone collections, rather than just using the existing BLI Vector implementation.)

This all looks pretty sensible to me. > OPTIONAL: Create a separate C++ wrapper for bone collections. > [...] > OPTIONAL: Create a separate C++ wrapper for bArmature I'm on the fence about the benefits of this. If a type has a single clear representation, that makes things simpler and easier to think about. But I do agree that the compile time hit of putting methods directly on the DNA types is obnoxious. If C++ wrappers do end up being how we deal with this kind of thing in Blender, I think we should settle on one canonical way to do it across the whole code base with uniform naming schemes, and document that pattern so that it's clear to anyone diving into the code base. (Side note that's beyond the scope of this issue: I doubt there's much disagreement here, but ideally I'd like to see some level of [C++-ification of DNA itself](https://devtalk.blender.org/t/dna-decentralization-and-c/30391). For example, being limited to C in DNA is why we had to essentially write our own duplicate Vector code for bone collections, rather than just using the existing BLI `Vector` implementation.)
Author
Member

If C++ wrappers do end up being how we deal with this kind of thing in Blender, I think we should settle on one canonical way to do it across the whole code base with uniform naming schemes, and document that pattern so that it's clear to anyone diving into the code base.

Of course. This discussion here is a direct result of that not having happened yet.

I discussed this face-to-face with Sergey, and he is in favour of having explicit C++ wrappers. They give a single, clear distinction between "the C/DNA world" and "the C++ world". So as far as I'm concerned that's settled, and we just go for these C++ wrappers (like already in place for BoneColor).

> If C++ wrappers do end up being how we deal with this kind of thing in Blender, I think we should settle on one canonical way to do it across the whole code base with uniform naming schemes, and document that pattern so that it's clear to anyone diving into the code base. Of course. This discussion here is a direct result of that not having happened yet. I discussed this face-to-face with Sergey, and he is in favour of having explicit C++ wrappers. They give a single, clear distinction between "the C/DNA world" and "the C++ world". So as far as I'm concerned that's settled, and we just go for these C++ wrappers (like already in place for `BoneColor`).
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
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#116938
No description provided.