WIP: Make ComponentAttributeAccessor handle active/default_color_attribute #109083

Draft
Martijn Versteegh wants to merge 4 commits from Baardaap/blender:addremovetrigger into blender-v3.6-release

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

When Geometry Nodes created or deleted attributes it didn't handle
the active/default_color_attribute strings on Mesh. This lead to
Meshes with color attributes but without active/default_color_attribute
set, which is a regression from previous blender versions where newly
created color attributes are always set to active/default if they were the
first created color attribute.

When using GN to colorize point cloud data, for example, it's very
convenient if the created color_attribute is also used in solid mode attribute
coloring.

When Geometry Nodes created or deleted attributes it didn't handle the active/default_color_attribute strings on Mesh. This lead to Meshes with color attributes but without active/default_color_attribute set, which is a regression from previous blender versions where newly created color attributes are always set to active/default if they were the first created color attribute. When using GN to colorize point cloud data, for example, it's very convenient if the created color_attribute is also used in solid mode attribute coloring.
Martijn Versteegh added 1 commit 2023-06-17 18:08:46 +02:00
When Geometry Nodes created or deleted attributes it didn't handle
the active/default_color_attribute strings on Mesh. This lead to
Meshes with color attributes but without active/default_color_attribute
set, which is a regression from previous blender versions where newly
created color attributes are always set to active/default.
Author
Member

I think this is a better way to do what #109067 did as well.

I think this is a better way to do what #109067 did as well.
Martijn Versteegh added 1 commit 2023-06-17 18:11:27 +02:00
Martijn Versteegh added the
Module
Nodes & Physics
Interest
Geometry Nodes
labels 2023-06-17 18:17:18 +02:00
Author
Member

Iliya suggested (i the chat) to use 'handler' instead of 'trigger' for the function names. Which is better I agree.

Also I have my doubts about the delete handler because:

  • it gets called for any deleted attribute regardless of type (the type isn't readily available)
  • it does unconditional strncmp for every deleted attribute, which is maybe too slow?
  • as it currently is there is no way to delete attributes from GN I think? So they only get deleted to just get recreated immediately.

But is does seem more 'correct' this way and I'm afraid not clearing those strings on attrib delete will come back to bite us in the ass later.

Now that I think of it... I'm not really sure the delete handler is even correct. As it uses the AttributeIDRef which points to the just deleted attribute. And it's name_ member probably points into the name of the deleted layer. Which could be the wrong layer name now that I think of it (because of the reordering of CD layers on remove). The delete handler would need to be called before deleting the layer, which is a bit more hard to integrate..

ok. back to the drawing board I guess. But I'd still very much appreciate some feedback on if this approach seems feasible and if it's something we want to have (setting the first created layer to active)

Iliya suggested (i the chat) to use 'handler' instead of 'trigger' for the function names. Which is better I agree. Also I have my doubts about the delete handler because: - it gets called for *any* deleted attribute regardless of type (the type isn't readily available) - it does unconditional strncmp for every deleted attribute, which is maybe too slow? - as it currently is there is no way to delete attributes from GN I think? So they only get deleted to just get recreated immediately. But is does seem more 'correct' this way and I'm afraid not clearing those strings on attrib delete will come back to bite us in the ass later. Now that I think of it... I'm not really sure the delete handler is even correct. As it uses the AttributeIDRef which points to the just deleted attribute. And it's name_ member probably points into the name of the deleted layer. Which could be the wrong layer name now that I think of it (because of the reordering of CD layers on remove). The delete handler would need to be called *before* deleting the layer, which is a bit more hard to integrate.. ok. back to the drawing board I guess. But I'd still very much appreciate some feedback on if this approach seems feasible and if it's something we want to have (setting the first created layer to active)
Martijn Versteegh added 1 commit 2023-06-17 21:03:43 +02:00
-call remove handler before removing the layer
Martijn Versteegh added 1 commit 2023-06-17 21:23:25 +02:00
Author
Member

I think I solved the issue with the remove handler being wrong.

I think I solved the issue with the remove handler being wrong.
Hans Goudey reviewed 2023-06-18 01:21:07 +02:00
@ -1082,6 +1082,38 @@ class VertexGroupsAttributeProvider final : public DynamicAttributesProvider {
*/
static ComponentAttributeProviders create_attribute_providers_for_mesh()
{
static AttributeAddHandler mesh_add_handler =
Member

To me the need for a concept like "Trigger" suggests the system is getting a bit too complex. Seems like it might fit a bit better in the existing CustomDataAttributeProvider::try_delete() function.

To me the need for a concept like "Trigger" suggests the system is getting a bit too complex. Seems like it might fit a bit better in the existing `CustomDataAttributeProvider::try_delete()` function.
Author
Member

I thought about that. But the problem is that the active/default is set on the mesh, and not on the CustomData level
I'll look at it again, but I think CustomDataAttributeProvider just links to the CustomDataLayer and has no easy way to get back to the owning mesh.

Furthermore CustomDataAttributeProvider is also used for Curves and PointClouds, but this functionality is only needed for Mesh.

I thought about that. But the problem is that the active/default is set on the mesh, and not on the CustomData level I'll look at it again, but I think CustomDataAttributeProvider just links to the CustomDataLayer and has no easy way to get back to the owning mesh. Furthermore CustomDataAttributeProvider is also used for Curves and PointClouds, but this functionality is only needed for Mesh.
@ -1085,0 +1087,4 @@
Mesh *mesh = static_cast<Mesh *>(owner);
if ((type == CD_PROP_COLOR || type == CD_PROP_BYTE_COLOR) && !attribute_id.is_anonymous()) {
if (mesh->active_color_attribute == nullptr) {
mesh->active_color_attribute = static_cast<char *>(
Member

Shouldn't need to cast this to char *, that's the return type.

Shouldn't need to cast this to `char *`, that's the return type.
@ -1085,0 +1100,4 @@
static AttributeRemoveHandler mesh_remove_handler =
[](void *owner, AttributeIDRef const &attribute_id) -> void {
Mesh *mesh = static_cast<Mesh *>(owner);
if (mesh->active_color_attribute && !strncmp(mesh->active_color_attribute,
Member

Looks much better as StringRef(mesh->active_color_attribute) == attribute_id.name() IMO

Looks much better as `StringRef(mesh->active_color_attribute) == attribute_id.name()` IMO
@ -1085,0 +1104,4 @@
attribute_id.name().data(),
attribute_id.name().size()))
{
MEM_SAFE_FREE(mesh->active_color_attribute);
Member

So far we've decided not to remove the active name when removing the corresponding attribute. The idea is that the name might not always match an attribute on the geometry, since they might be created/set at different times. I'm not totally tied to that, but it does seem reasonable to me too.

So far we've decided not to remove the active name when removing the corresponding attribute. The idea is that the name might not always match an attribute on the geometry, since they might be created/set at different times. I'm not totally tied to that, but it does seem reasonable to me too.
Author
Member

ok, that's good I could just remove the delete handler.

ok, that's good I could just remove the delete handler.
Member

The basic idea of setting the first created color attribute active seems somewhat reasonable I guess. But the alternative is to add a "Set Active Color Attribute" node, which is probably a bit more explicit (and therefore intuitive?). The remaining question we had about that when we discussed it is what name to use. But something like "active_color" might be fine Or it could be specified too.

as it currently is there is no way to delete attributes from GN I think?

There is the "Remove Named Attribute" node.


Also, as a high level design goal, personally I think the whole concept of an active color attribute in a procedural context is more of a crutch than a design goal. It just means connections are more implicit, and means you need to keep track of even more state. But it's the only way we have to create reusable materials that use color attributes, so we're sort of stuck with it for now.

The basic idea of setting the first created color attribute active seems somewhat reasonable I guess. But the alternative is to add a "Set Active Color Attribute" node, which is probably a bit more explicit (and therefore intuitive?). The remaining question we had about that when we discussed it is what name to use. But something like "active_color" might be fine Or it could be specified too. >as it currently is there is no way to delete attributes from GN I think? There is the "Remove Named Attribute" node. --- Also, as a high level design goal, personally I think the whole concept of an active color attribute in a procedural context is more of a crutch than a design goal. It just means connections are more implicit, and means you need to keep track of even more state. But it's the only way we have to create reusable materials that use color attributes, so we're sort of stuck with it for now.
Author
Member

Creating a an Active Color node might be better/more intuitive.

Though a bit strange that an 'Active Color' node would set the 'default_color_attribute' and not the 'active_color_attribute'.

I think the whole concept of an active color attribute in a procedural context is more of a crutch than a design goal.

I don't really disagree. But there are numerous bugreports because GN behaves differently in this respect than all other modifiers.
For backwards compatibility I think it would still be nice to always set a default, even if we have an explicit node as well.

Creating a an Active Color node might be better/more intuitive. Though a bit strange that an 'Active Color' node would set the 'default_color_attribute' and not the 'active_color_attribute'. > I think the whole concept of an active color attribute in a procedural context is more of a crutch than a design goal. I don't really disagree. But there are numerous bugreports because GN behaves differently in this respect than all other modifiers. For backwards compatibility I think it would still be nice to always set a default, even if we have an explicit node as well.
Hans Goudey added this to the Nodes & Physics project 2023-11-28 21:17:39 +01:00
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u addremovetrigger:Baardaap-addremovetrigger
git checkout Baardaap-addremovetrigger
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
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
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
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
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#109083
No description provided.