Mesh/Grids datalayer management #80609

Open
opened 2020-09-08 22:23:30 +02:00 by Pablo Dobarro · 2 comments
Member

This tasks is to design a plan to fix the issues related to having different datalayer for vertices and Multires data so we can use it to fix existing bugs and implement new features.

Currently, the data editable from Multires are coordinates, per element visibility, sculpt mask and face sets. Each one of these data as a different solution for this:

  • Coordinates are being applied to the base mesh from the grids manually by using the Apply Base operator. When modifying the base mesh, that changes the subdivision limit surface, updating the result as coordinates in grids are stored as displacement in the ##CD_MDISP## datalayer. This is not the standard design of a Multires sculpting software, but this approach works for all the expected use cases and it allows for some non-standard functionality (like sculpting the base mesh while previewing the displacement or sculpting in deformed meshes).
  • Element visibility is stored in the ##ME_HIDE## flag in ##MVerts->flag## for meshes and in a bitmap which is part of ##CD_MDISP## for grids. As far as I know, there is nothing that keeps this data in sync.
  • The Sculpt Mask is stored in the CD_PAINT_MASK for vertices and in the CD_GRID_PAINT_MASK for grids. The main sync point is in ##BKE_sculpt_mask_layers_ensure## were the current state of ##CD_PAINT_MASK## is copied into a new ##CD_GRID_PAINT_MASK## datalayer when grid mask data does not exist, and it is never updated again. When applying Multires with ##CD_GRID_PAINT_MASK##, the mask data is also not copied to the new base mesh.
  • Face Sets are stored in ##CD_SCULPT_FACE_SETS## for base mesh polys and Multires reads them directly based on the index of the face the grid is. This makes them to be always in sync, but they are not editable per element in Multires.

This is affecting future development in the following ways:

  • As the paint mask is not synced from grids to the base mesh, there is not possible to implement features like mask extract from Multires as there is no ##CD_PAINT_MASK## datalayer in the base mesh after applying the modifier to extract the new mesh.
  • The Sculpt Vertex Colors Multires implementation includes a ##CD_GRID_PROP_COLOR## datalayer and uses a similar approach as masks. If we replicate the same code to sync it with ##CD_PROP_COLOR##, were are going to have the same issues, but for this feature those are not acceptable. Vertex Colors should be always in sync between the base mesh and grids without requiring anything from the user. Also, there can be multiple ##CD_PROP_COLOR## datalayers, which is a feature that does not exist in the sculpt mask datalayer.
  • If we want to implement sculpt layers for displacement, that will require to add another datalayer to store them. I'm still not sure how they will be stored (coordinates, displacement relative to the layer 0...). Implementing this feature on top of the current design means dealing with the base mesh sync issue for multiple layers plus always running the Multires smooth propagation for all of them each time the base layer changes.
  • There are also some features that are trivial to implement (like PBR vertex painting using a datalayer that contains color + PBR values at the same time) that are also limited by not having mesh/multires data unified.

The mesh/grids datalayer management project should try to provide a common solution to all these problems. Ideally, it should be possible to use the same vertex datalayer transparently from the tools and the Multires code, having all these abstracted by another system that keeps the mesh and grids data always in sync.

This tasks is to design a plan to fix the issues related to having different datalayer for vertices and Multires data so we can use it to fix existing bugs and implement new features. Currently, the data editable from Multires are coordinates, per element visibility, sculpt mask and face sets. Each one of these data as a different solution for this: - Coordinates are being applied to the base mesh from the grids manually by using the Apply Base operator. When modifying the base mesh, that changes the subdivision limit surface, updating the result as coordinates in grids are stored as displacement in the ##CD_MDISP## datalayer. This is not the standard design of a Multires sculpting software, but this approach works for all the expected use cases and it allows for some non-standard functionality (like sculpting the base mesh while previewing the displacement or sculpting in deformed meshes). - Element visibility is stored in the ##ME_HIDE## flag in ##MVerts->flag## for meshes and in a bitmap which is part of ##CD_MDISP## for grids. As far as I know, there is nothing that keeps this data in sync. - The Sculpt Mask is stored in the CD_PAINT_MASK for vertices and in the CD_GRID_PAINT_MASK for grids. The main sync point is in ##BKE_sculpt_mask_layers_ensure## were the current state of ##CD_PAINT_MASK## is copied into a new ##CD_GRID_PAINT_MASK## datalayer when grid mask data does not exist, and it is never updated again. When applying Multires with ##CD_GRID_PAINT_MASK##, the mask data is also not copied to the new base mesh. - Face Sets are stored in ##CD_SCULPT_FACE_SETS## for base mesh polys and Multires reads them directly based on the index of the face the grid is. This makes them to be always in sync, but they are not editable per element in Multires. This is affecting future development in the following ways: - As the paint mask is not synced from grids to the base mesh, there is not possible to implement features like mask extract from Multires as there is no ##CD_PAINT_MASK## datalayer in the base mesh after applying the modifier to extract the new mesh. - The Sculpt Vertex Colors Multires implementation includes a ##CD_GRID_PROP_COLOR## datalayer and uses a similar approach as masks. If we replicate the same code to sync it with ##CD_PROP_COLOR##, were are going to have the same issues, but for this feature those are not acceptable. Vertex Colors should be always in sync between the base mesh and grids without requiring anything from the user. Also, there can be multiple ##CD_PROP_COLOR## datalayers, which is a feature that does not exist in the sculpt mask datalayer. - If we want to implement sculpt layers for displacement, that will require to add another datalayer to store them. I'm still not sure how they will be stored (coordinates, displacement relative to the layer 0...). Implementing this feature on top of the current design means dealing with the base mesh sync issue for multiple layers plus always running the Multires smooth propagation for all of them each time the base layer changes. - There are also some features that are trivial to implement (like PBR vertex painting using a datalayer that contains color + PBR values at the same time) that are also limited by not having mesh/multires data unified. The mesh/grids datalayer management project should try to provide a common solution to all these problems. Ideally, it should be possible to use the same vertex datalayer transparently from the tools and the Multires code, having all these abstracted by another system that keeps the mesh and grids data always in sync.
Member

We could have a new CustomData instance in meshes for multires grids, e.g. mesh->gdata or mesh->mdata. We could then allocate customdata layers as blocks in MDisps, similar to how bmesh does it. So, Mdisps might look something like:

struct MDisps {
  void *customdata; //array of customdata layer grids
  int totdisp;
  float (*disps)[3]; //convienent pointer
}

Then, accessing the grids would be like bmesh:


int offset = get_grid_layer_offset(&me->mdata, CD_WHATEVER);

//to get a grid from a loop. . .
MDisps *md = get_mdisps_from_loop(loop);
Whatever *grid = get_grid_layer(md, offset);

Per-MDisps allocation would be done with a memory pool, same as bmesh.

We could have a new CustomData instance in meshes for multires grids, e.g. mesh->gdata or mesh->mdata. We could then allocate customdata layers as blocks in MDisps, similar to how bmesh does it. So, Mdisps might look something like: ``` struct MDisps { void *customdata; //array of customdata layer grids int totdisp; float (*disps)[3]; //convienent pointer } ``` Then, accessing the grids would be like bmesh: ``` int offset = get_grid_layer_offset(&me->mdata, CD_WHATEVER); //to get a grid from a loop. . . MDisps *md = get_mdisps_from_loop(loop); Whatever *grid = get_grid_layer(md, offset); ``` Per-MDisps allocation would be done with a memory pool, same as bmesh.
Julien Kaspar added this to the Sculpt, Paint & Texture project 2023-02-08 10:20:48 +01:00
Philipp Oeser removed the
Interest
Sculpt, Paint & Texture
label 2023-02-10 09:12:19 +01:00
Member

I am removing the Needs Triage label. This is under the general rule that Design and TODO tasks should not have a status.

If you believe this task is no longer relevant, feel free to close it.

I am removing the `Needs Triage` label. This is under the general rule that Design and TODO tasks should not have a status. If you believe this task is no longer relevant, feel free to close it.
Alaska removed the
Status
Needs Triage
label 2024-04-07 05:51:35 +02: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 Assignees
3 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#80609
No description provided.