Dependent/Linked CustomData layers #97174

Closed
opened 2022-04-08 16:32:47 +02:00 by Martijn Versteegh · 15 comments

When moving from an AoS to an SoA paradigm and mving compound structs to separate CD_PROP_* generic attribute layers, there needs to be a system to tie the various layers that used to be combined into a single struct together.

I'll describe the problem with the CD_MLOOPUV datalayer as an example, but I think it would be nice to solve this in a generic way because other parts of blender will likely have the same need to store 'structs' of related information in attribute layers.

First I'll desribe the original situation:

 The CD_MLOOPUV datalayer  consists of an array of MLoopUV structs. The MLoopUV struct contains 4 parts of information. a float[2] vector and 3 booleans. 
 There can be multiple UV layers, distinguished by their name.

It is easy to access all the information elementwise. Accessing a single element gives you all information in an MLoopUV struct.

Now the new situation:

 The complete uv datalayer consists of 4 separate generic attribute layers: One CD_PROP_FLOAT2 layer for the actual uv imformation and 3 CD_PROP_BOOL layers containing the 3 bool flags.
 Now there is a naming problem. Those 4 layers can't have the same name, we need a way to get at them separately. Based on a sing;e 'UV layer name" and some sort of 'subname'. For example if we need to get at the vertsel or edgesel bools for a specific facecorner we need to get at those bool layers based on the name of the uvmap (or the active uv map) and an extra specifier.

Possible solutions (ideas welcome):
A) Just tag on the extra specifier to the name, using some sort of reserved coupling character.

  • Advantage: no changes to the datastructures
  • Disadvantage: needs extra care on renaming and deleting layers.
  • Disadvantage: the current maximum layername length is 64 chars. This is already quite a restriction (I've seen requests to make it larger for workflows with standardized layer names) tagging on extra stuff in the same space takes even more space away there.
    B) Add an extra list of dependent layers to the CustomDataLayer struct .
  • Advantage: No extra care needed on renaming. Still on deleting (also delete the depndent layers?)
  • Possible disadvantage: leads to a hierarchical structure, you need 1 main layer and various sub layers. (I don't think this really matters much, could even be an advantage)
  • Disadvantage: Needs changes to the CustomDataLayer struct. More complicated on saving.
  • Disadvantage layers can't have the same name, so sublayers still need some way of giving them a distinct name.

C) Add an extra sub-name field in the CustomDataLayer struct.

  • Advantage: simpler than B, doesn't take away space in the main layer name. Very similar to A
  • Disadvantage: need to save an extra name compared to A)

The prototype in D14365 more or less does A , but it doesn't handle renaming/deleteing.

When moving from an AoS to an SoA paradigm and mving compound structs to separate CD_PROP_* generic attribute layers, there needs to be a system to tie the various layers that used to be combined into a single struct together. I'll describe the problem with the CD_MLOOPUV datalayer as an example, but I think it would be nice to solve this in a generic way because other parts of blender will likely have the same need to store 'structs' of related information in attribute layers. First I'll desribe the original situation: ``` The CD_MLOOPUV datalayer consists of an array of MLoopUV structs. The MLoopUV struct contains 4 parts of information. a float[2] vector and 3 booleans. There can be multiple UV layers, distinguished by their name. ``` It is easy to access all the information elementwise. Accessing a single element gives you all information in an MLoopUV struct. Now the new situation: ``` The complete uv datalayer consists of 4 separate generic attribute layers: One CD_PROP_FLOAT2 layer for the actual uv imformation and 3 CD_PROP_BOOL layers containing the 3 bool flags. Now there is a naming problem. Those 4 layers can't have the same name, we need a way to get at them separately. Based on a sing;e 'UV layer name" and some sort of 'subname'. For example if we need to get at the vertsel or edgesel bools for a specific facecorner we need to get at those bool layers based on the name of the uvmap (or the active uv map) and an extra specifier. ``` Possible solutions (ideas welcome): A) Just tag on the extra specifier to the name, using some sort of reserved coupling character. - Advantage: no changes to the datastructures - Disadvantage: needs extra care on renaming and deleting layers. - Disadvantage: the current maximum layername length is 64 chars. This is already quite a restriction (I've seen requests to make it larger for workflows with standardized layer names) tagging on extra stuff in the same space takes even more space away there. B) Add an extra list of dependent layers to the CustomDataLayer struct . - Advantage: No extra care needed on renaming. Still on deleting (also delete the depndent layers?) - Possible disadvantage: leads to a hierarchical structure, you need 1 main layer and various sub layers. (I don't think this really matters much, could even be an advantage) - Disadvantage: Needs changes to the CustomDataLayer struct. More complicated on saving. - Disadvantage layers can't have the same name, so sublayers still need some way of giving them a distinct name. C) Add an extra sub-name field in the CustomDataLayer struct. - Advantage: simpler than B, doesn't take away space in the main layer name. Very similar to A - Disadvantage: need to save an extra name compared to A) The prototype in [D14365](https://archive.blender.org/developer/D14365) more or less does A , but it doesn't handle renaming/deleteing.
Author
Member

Added subscribers: @Baardaap, @HooglyBoogly

Added subscribers: @Baardaap, @HooglyBoogly
Member

I think some solution that maintains CustomData's flat array of layers would be preferable. Any sort of hierarchy is likely more complex and more costly to traverse, which I think is the case to optimize for rather than removal.

For the selection and pinning layers, my hunch is that some other sort of attribute identifier similar to AnonymousAttributeID would be helpful, since I see them more as UI data. On the other hand, I'm not sure we've decided explicitly that such UI data shouldn't show up somehow in the attributes list.
A seam layer seems more useful to control procedurally.

Here's another solution:

D) Add an array of "child/dependent attributes" to the parent custom data layer

  • Advantage: Users could edit the list, and it could potentially be used more generically in the future.
  • Advantage: Relatively simple to view the sub-attributes, while maintaining the flat list
  • Possible disadvantage: Still requires the "sub-attributes" to have unique names/identifiers
  • Disadvantage: Storing attribute names more than once unnecessarily

Maybe some combination of these ideas makes sense, we'll see.

I think some solution that maintains `CustomData`'s flat array of layers would be preferable. Any sort of hierarchy is likely more complex and more costly to traverse, which I think is the case to optimize for rather than removal. For the selection and pinning layers, my hunch is that some other sort of attribute identifier similar to `AnonymousAttributeID` would be helpful, since I see them more as UI data. On the other hand, I'm not sure we've decided explicitly that such UI data shouldn't show up somehow in the attributes list. A seam layer seems more useful to control procedurally. Here's another solution: D) Add an array of "child/dependent attributes" to the parent custom data layer * Advantage: Users could edit the list, and it could potentially be used more generically in the future. * Advantage: Relatively simple to view the sub-attributes, while maintaining the flat list * Possible disadvantage: Still requires the "sub-attributes" to have unique names/identifiers * Disadvantage: Storing attribute names more than once unnecessarily Maybe some combination of these ideas makes sense, we'll see.
Author
Member

To be clear: your D) is what I meant wit my B).

I wasn't talking about actually nesting layers. Just linking them via a list of dependent layers. Which conceptually creates a hierarchy (but still is stored as a a flat list).

If we make them anonymous layers that would make it easier I guess, as then the naming problem doesn't really exist.

To be clear: your D) is what I meant wit my B). I wasn't talking about actually nesting layers. Just linking them via a list of dependent layers. Which conceptually creates a hierarchy (but still is stored as a a flat list). If we make them anonymous layers that would make it easier I guess, as then the naming problem doesn't really exist.
Author
Member

About: https://hackmd.io/@II9-Bkl4TJifCqGL2jgbUw/BJkCE9BVq

In general I like the proposal a lot. Keep it simple.

How do you propose to handle this:

  • there can be multiple UV layers
  • each UV layer needs it's own set of dependent layers (>select_vertex, >uv_pinned, >select_edge )

Just append the name of the original UV layer?

How hard would it be (backwards compatibility-wise) to increase the max size of the layers names? With these sort of longish prefixes the 64char limit can get rather tight I think.

About: https://hackmd.io/@II9-Bkl4TJifCqGL2jgbUw/BJkCE9BVq In general I like the proposal a lot. Keep it simple. How do you propose to handle this: - there can be multiple UV layers - each UV layer needs it's own set of dependent layers (>select_vertex, >uv_pinned, >select_edge ) Just append the name of the original UV layer? How hard would it be (backwards compatibility-wise) to increase the max size of the layers names? With these sort of longish prefixes the 64char limit can get rather tight I think.
Member

Yeah, that's the suggestion for handling those layers.
We talked about changing the layer name to char * instead of an array. Then arbitrary lengths could be supported.
DNA could detect that change and apply it automatically when loading a file (as another eReconstructStepType possibly).

Yeah, that's the suggestion for handling those layers. We talked about changing the layer name to `char *` instead of an array. Then arbitrary lengths could be supported. DNA could detect that change and apply it automatically when loading a file (as another `eReconstructStepType` possibly).
Author
Member

There's one piece of the puzzle still missing from this proposal. (Though maybe that's out of the scope of this specific proposal?)

Optional attributes.

For some attributes it would be very nice if they could return a default value when reading from a layer that doesn't exist. And it would be even nicer if the layer would be created on demand when trying to write to certain non-existent layers.

This way we could prevent uv_vertsel,uv_pinned and uv_edgesel layers being created for each and every FLOAT2 layer even though they never will get used.

The first property (reading giving a default value when the layer doesn't exists) could maybe be handled with a specialized BM_CD_ELEM_GET_*_OPTIONAL() macro which would return a default value if the base offset is -1.

For the writing I don't really see how it could be done directly from the access macros. But that's not too bad because writing happens way less than reading. It would be nice if there were a set of CustomData_get_or_add_named_layer_* () functions which would create the layer if it doesn't yet exists or return it when it does.

There's one piece of the puzzle still missing from this proposal. (Though maybe that's out of the scope of this specific proposal?) **Optional attributes.** For some attributes it would be very nice if they could return a default value when reading from a layer that doesn't exist. And it would be even nicer if the layer would be created on demand when trying to write to certain non-existent layers. This way we could prevent uv_vertsel,uv_pinned and uv_edgesel layers being created for each and every FLOAT2 layer even though they never will get used. The first property (reading giving a default value when the layer doesn't exists) could maybe be handled with a specialized BM_CD_ELEM_GET_*_OPTIONAL() macro which would return a default value if the base offset is -1. For the writing I don't really see how it could be done directly from the access macros. But that's not too bad because writing happens way less than reading. It would be nice if there were a set of CustomData_get_or_add_named_layer_* () functions which would create the layer if it doesn't yet exists or return it when it does.
Member

I think reading attributes with a default value should be handled by the reader of the attribute, so with a macro like you suggest for BMesh.
In the C++ attribute API we already support this, with an optional default value argument to functions like attribute_get_for_read.

Adding a CustomData function to add an attribute only if it doesn't exist sounds good.
Though for Mesh, I think we should move towards using the C++ attribute API rather than the CustomData API (that doesn't apply to BMesh).

I think reading attributes with a default value should be handled by the reader of the attribute, so with a macro like you suggest for BMesh. In the C++ attribute API we already support this, with an optional default value argument to functions like `attribute_get_for_read`. Adding a `CustomData` function to add an attribute only if it doesn't exist sounds good. Though for `Mesh`, I think we should move towards using the C++ attribute API rather than the `CustomData` API (that doesn't apply to BMesh).
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

I posted a proposal that solves this and a bunch of other problems: #97452.

I posted a proposal that solves this and a bunch of other problems: #97452.
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'
Member

What is the status of this? Superseeded by #97452?

What is the status of this? Superseeded by #97452?

This issue was referenced by 6c774feba2

This issue was referenced by 6c774feba2c9a1eb5834646f597a0f2c63177914
Author
Member

What was implemented in D14365 is more or less #97452 (option B)

What was implemented in [D14365](https://archive.blender.org/developer/D14365) is more or less #97452 (option B)
Member

Changed status from 'Needs Developer To Reproduce' to: 'Resolved'

Changed status from 'Needs Developer To Reproduce' to: 'Resolved'
Hans Goudey self-assigned this 2023-01-10 18:43:40 +01:00
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
5 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#97174
No description provided.