Struct of Arrays Refactor for Mesh Edges #95966

Closed
opened 2022-02-22 20:27:22 +01:00 by Hans Goudey · 16 comments
Member

Currently, MEdge stores quite a bit of data:

typedef struct MEdge {
  unsigned int v1, v2;
  char crease, bweight;
  short flag;
} MEdge;

For the reasons described in #95965, this is an inefficient way to organize data.
This task describes how MEdge should be changed to only store the two vertex indices.
In the end, edges should just store two vertex index integers. Everything else should be optionally stored elsewhere.

Span<int2> edges;

Bevel Weight

In the longer term, this should be stored as an optional named generic float attribute (see #89054).
In the shorter term, this can be stored as CD_BWEIGHT. This means slightly increased memory usage when this data is used,
but it also gives increased precision, and it doesn't have to be allocated when it isn't used.

291c313f80

Flag

In the flag is:

  /*  SELECT = (1 << 0), */
  ME_EDGEDRAW = (1 << 1),
  ME_SEAM = (1 << 2),
  /*  ME_HIDE = (1 << 4), */
  ME_EDGERENDER = (1 << 5),
  ME_LOOSEEDGE = (1 << 7),
  ME_EDGE_TMP_TAG = (1 << 8),
  ME_SHARP = (1 << 9),

Selection 12becbf0df
It's not clear to me how selection interacts with mselect (MSelect), but perhaps it can be moved there.
It can also be moved to a separate boolean custom data layer with a name that keeps it from being displayed in the UI.

ME_SEAM cccf91ff83
Ideally this would move to a completely generic boolean attribute, since only having one seam layer is limiting.

ME_HIDE 2480b55f21
This can be moved to a separate boolean custom data layer, likely with a reserved name.

ME_EDGEDRAW 7ca651d182
ME_EDGERENDER 10131a6f62
As far as I can tell, these are always used together, like ME_EDGEDRAW | ME_EDGERENDER. It looks like they are only runtime data.
They should be stored in Mesh_Runtime as a bitmask or an array of booleans. This way they can only be allocated when they are actually needed,
like drawing a mesh after a subdivision surface modifier.

ME_LOOSEEDGE 1ea169d90e
This is also runtime data, so it should be stored in Mesh_Runtime, with some special API like mesh normals have now.

ME_EDGE_TMP_TAG 17567c235a
Can be easily removed, it's only used in one place.

ME_SHARP dd9e1eded0
Should be moved to a separate boolean layer and exposed as a builtin attribute.

Currently, `MEdge` stores quite a bit of data: ``` typedef struct MEdge { unsigned int v1, v2; char crease, bweight; short flag; } MEdge; ``` For the reasons described in #95965, this is an inefficient way to organize data. This task describes how `MEdge` should be changed to only store the two vertex indices. In the end, edges should just store two vertex index integers. Everything else should be optionally stored elsewhere. ``` Span<int2> edges; ``` ### Bevel Weight In the longer term, this should be stored as an optional named generic float attribute (see #89054). In the shorter term, this can be stored as `CD_BWEIGHT`. This means slightly increased memory usage when this data is used, but it also gives increased precision, and it doesn't have to be allocated when it isn't used. 291c313f80 ### Flag In the flag is: ``` /* SELECT = (1 << 0), */ ME_EDGEDRAW = (1 << 1), ME_SEAM = (1 << 2), /* ME_HIDE = (1 << 4), */ ME_EDGERENDER = (1 << 5), ME_LOOSEEDGE = (1 << 7), ME_EDGE_TMP_TAG = (1 << 8), ME_SHARP = (1 << 9), ``` **Selection** 12becbf0df It's not clear to me how selection interacts with `mselect` (`MSelect`), but perhaps it can be moved there. It can also be moved to a separate boolean custom data layer with a name that keeps it from being displayed in the UI. **ME_SEAM** cccf91ff832d119dbf048b0518a696b9aa83bce4 Ideally this would move to a completely generic boolean attribute, since only having one seam layer is limiting. **ME_HIDE** 2480b55f21 This can be moved to a separate boolean custom data layer, likely with a reserved name. **ME_EDGEDRAW** 7ca651d18274acacfe8e0ecb7bc6fdd3399ea01b **ME_EDGERENDER** 10131a6f62 As far as I can tell, these are always used together, like `ME_EDGEDRAW | ME_EDGERENDER`. It looks like they are only runtime data. They should be stored in `Mesh_Runtime` as a bitmask or an array of booleans. This way they can only be allocated when they are actually needed, like drawing a mesh after a subdivision surface modifier. **ME_LOOSEEDGE** 1ea169d90e This is also runtime data, so it should be stored in `Mesh_Runtime`, with some special API like mesh normals have now. **ME_EDGE_TMP_TAG** 17567c235a Can be easily removed, it's only used in one place. **ME_SHARP** dd9e1eded0 Should be moved to a separate boolean layer and exposed as a builtin attribute.
Author
Member

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Added subscriber: @ideasman42

Added subscriber: @ideasman42

edit replied to #95965.

*edit* replied to #95965.

This issue was referenced by 17567c235a

This issue was referenced by 17567c235ac62f6d0f7e3bf0cea50593633099da

This issue was referenced by 2480b55f21

This issue was referenced by 2480b55f216c31373a84bc5c5d2b0cc158497c44

This issue was referenced by 291c313f80

This issue was referenced by 291c313f80b4cccc8fcce3035584caeaa654844f

This issue was referenced by a8a454287a

This issue was referenced by a8a454287a27d408668f8adc6fe1b3aa988de1ac

This issue was referenced by 12becbf0df

This issue was referenced by 12becbf0dffe06b6f28c4cc444fe0312cf9249b9
Author
Member

ME_EDGEDRAW Flag

Currently the ME_EDGEDRAW flag is only ever set to false for the "optimal display" feature of the subdivision surface modifier.
When applying the modifier back to the original mesh this is turned off though.
Blender only produces original (in Main) meshes with every ME_EDGEDRAW flag set.

So, moving forward it makes sense to remove the BM_ELEM_DRAW flag from edges completely.
If that functionality is needed, disabling drawing of certain edges should be a viewport/overlay feature rather than being stored in the original mesh.
ME_EDGEDRAW should become runtime data-- a bitmap just like MeshRuntime::subsurf_face_dot_tags.

**ME_EDGEDRAW Flag** Currently the `ME_EDGEDRAW` flag is only ever set to false for the "optimal display" feature of the subdivision surface modifier. When applying the modifier back to the original mesh this is turned off though. Blender only produces original (in Main) meshes with every `ME_EDGEDRAW` flag set. So, moving forward it makes sense to remove the `BM_ELEM_DRAW` flag from edges completely. If that functionality is needed, disabling drawing of certain edges should be a viewport/overlay feature rather than being stored in the original mesh. `ME_EDGEDRAW` should become runtime data-- a bitmap just like `MeshRuntime::subsurf_face_dot_tags`.

This issue was referenced by 1ea169d90e

This issue was referenced by 1ea169d90e39647eac721cc1fee9927b0432bf97

Added subscriber: @JamellMoore

Added subscriber: @JamellMoore

@HooglyBoogly I' currently working with a patched build where I've exposed CD_BWEIGHT as a built-in named CD_PROP_FLOAT attribute (bevel_weight) as it allows controlling bevels using a bevel modifier. Would you welcome this in the short term?

The bevel node seems to be a community project that may take many releases to complete. This may be useful to other users until the node is complete or/and the bevel modifier allows generic attributes.

@HooglyBoogly I' currently working with a patched build where I've exposed CD_BWEIGHT as a built-in named CD_PROP_FLOAT attribute (bevel_weight) as it allows controlling bevels using a bevel modifier. Would you welcome this in the short term? The bevel node seems to be a community project that may take many releases to complete. This may be useful to other users until the node is complete or/and the bevel modifier allows generic attributes.
Author
Member

That is tempting, personally I don't think it's a great approach though. It's hard to add that sort of temporary feature, because people start to depend on it, and then it becomes somewhat permanent because we try hard to keep backwards compatibility for new releases. I would like to avoid that sort of temporary compromise becoming part of the permanent design.

It's not procedural, but would adding a "Bevel Weight" option to the convert attribute operator be helpful, so at least you could apply the modifier and convert an edge float attribute to bevel weights?

That is tempting, personally I don't think it's a great approach though. It's hard to add that sort of temporary feature, because people start to depend on it, and then it becomes somewhat permanent because we try hard to keep backwards compatibility for new releases. I would like to avoid that sort of temporary compromise becoming part of the permanent design. It's not procedural, but would adding a "Bevel Weight" option to the convert attribute operator be helpful, so at least you could apply the modifier and convert an edge float attribute to bevel weights?

I can't foresee any issues myself with regards to backwards compatibility other than ones you would have to deal with when transitioning to generic attributes, but that's fair enough though. I'm sure I've overseen something and it's better to be safer than cause issues down line.

Adding a "Bevel Weight" option to the Convert Attribute Operator wouldn't help for my use because I'm making procedural assets. It could be useful for other contexts though where the final output is non-procedural.

I can't foresee any issues myself with regards to backwards compatibility other than ones you would have to deal with when transitioning to generic attributes, but that's fair enough though. I'm sure I've overseen something and it's better to be safer than cause issues down line. Adding a "Bevel Weight" option to the Convert Attribute Operator wouldn't help for my use because I'm making procedural assets. It could be useful for other contexts though where the final output is non-procedural.

This issue was referenced by dd9e1eded0

This issue was referenced by dd9e1eded0d48e19a500233b20e8c5f18ed12a09
Hans Goudey added this to the 3.6 LTS milestone 2023-03-30 16:51:14 +02:00
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-04-17 13:49:36 +02:00
Sign in to join this conversation.
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 project
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#95966
No description provided.