PBVH_BMESH Notes #87456

Open
opened 2021-04-13 09:33:11 +02:00 by Joseph Eagar · 9 comments
Member

Lately there's been interest in users (and some developers) in adding more topological workflows to sculptmode and/or refactoring editmode to use PBVH_BMESH. This will require much refactoring of the code, some of which has already happened as part of the DynTopo cleanup project (but not everything).

The purpose of this document is to set down some ideas for the future direction of PBVH_BMESH and how we might get there.

Current state of PBVH_BMESH

PBVH_BMESH Changes

  • Customdata interpolation is now supported for DynTopo.

  • PBVH drawing now sets GPU attributes (mostly) correctly (still need to support multiple UV layers properly).

  • Vertices now have a special MDynTopoVert customdata structure for storing original data.

  • PBVHNode->bm_unique_verts/bm_other_verts/bm_faces now use a special GSET wrapper that caches entries in a flat array for fast iteration.

  • Original data is no longer tied to the undo system (at all) for PBVH_BMESH.

  • Triangles are no longer cached in an ad-hoc way in node->bm_ortri and bm_orco.

  Instead using a new system (see below).
  • Face sets are supported.
  • The PBVH tree is now split during strokes, except for a few tools like draw sharp.

PBVH nodes are now joined together at the end of a stroke if they lose too much topology during dyntopo. This

  keeps the tree from entering a pathological state of lots of little nodes with few if any triangles.

There is an option to draw sculpt colors in flat cells instead of the usual vcol interpolation.

General PBVH Changes

The sculpt API now has a concept of sculpt vertex references (SculptVertRef) which are indices for PBVH_FACES/GRIDS and BMVert pointers for
PBVH_BMESH. You can convert between sculpt vert refs and mesh indices with BKE_vertex_index_to_table and BKE_table_index_to_vertex.
To prevent implicit casts to/from 32-bit ints, SculptVertRef is a structure:

struct SculptVertRef { intptr_t i}

The same idea is used for face references too with a similar SculptFaceRef structure.

Storing Triangulations In Nodes

We should cache triangles in PBVH nodes. I've roughed out a simple api for this in temp_multires_bmesh already (there were a few truly evil bugs that necessitated it). The new data structures are below.


typedef struct PBVHTri {
  int v[3];       // references into PBVHTriBuf->verts
  intptr_t l[3];  // loops
  int eflag;      // bitmask of which edges in the tri are real edges in the mesh

  float no[3];
  SculptFaceRef f;
} PBVHTri;

typedef struct PBVHTriBuf {
  PBVHTri *tris;
  SculptVertRef *verts;
  int *edges;
  int totvert, totedge, tottri;
  int verts_size, edges_size, tris_size;

  // private fields
  intptr_t *loops;
  int totloop, mat_nr;
  float min[3], max[3];
} PBVHTriBuf;

I've kept things as simple as possible (I was planning on doing this a lot later). Triangulations are generated lazily as with the old bm_ortri code, only instead
of flagging nodes as dirty by freeing the triangulation a new PBVH_UpdateTris flag is set in node->flag.

Some open questions are:

Should we use this for all PBVH types? If so, what should the related SCULPT_XXX api look like?

Future Steps

To make PBVH_BMESH usable outside of DynTopo (and even sculpt), the following needs to happen:

  • DONE. Remove triangle restriction from PBVH_BMESH. DynTopo should dynamically triangulate any non-triangle faces as it comes across them.
  • PARTIAL. Refactor DynTopo into it's own API separate from PBVH_BMESH.
  • DONE. Cache mesh triangulations inside PBVH nodes.
  • DONE. Use cached triangulations for drawing.
    • DONE. Support indexed drawing in PBVH draw code to save GPU bandwidth
    • Generate triangulations that are split by UV islands.

Add support for fragment shader based flat face shading to the draw system.

  This will help save GPU bandwidth for flat shaded meshes by not having to duplicate the vertex data for every single triangle.
Lately there's been interest in users (and some developers) in adding more topological workflows to sculptmode and/or refactoring editmode to use PBVH_BMESH. This will require much refactoring of the code, some of which has already happened as part of the DynTopo cleanup project (but not everything). The purpose of this document is to set down some ideas for the future direction of PBVH_BMESH and how we might get there. ## Current state of PBVH_BMESH **PBVH_BMESH Changes** - Customdata interpolation is now supported for DynTopo. - PBVH drawing now sets GPU attributes (mostly) correctly (still need to support multiple UV layers properly). - Vertices now have a special MDynTopoVert customdata structure for storing original data. - PBVHNode->bm_unique_verts/bm_other_verts/bm_faces now use a special GSET wrapper that caches entries in a flat array for fast iteration. - Original data is no longer tied to the undo system (at all) for PBVH_BMESH. - Triangles are no longer cached in an ad-hoc way in node->bm_ortri and bm_orco. ``` Instead using a new system (see below). ``` - Face sets are supported. - The PBVH tree is now split during strokes, except for a few tools like draw sharp. # PBVH nodes are now joined together at the end of a stroke if they lose too much topology during dyntopo. This ``` keeps the tree from entering a pathological state of lots of little nodes with few if any triangles. ``` # There is an option to draw sculpt colors in flat cells instead of the usual vcol interpolation. ### General PBVH Changes The sculpt API now has a concept of sculpt vertex references (SculptVertRef) which are indices for PBVH_FACES/GRIDS and BMVert pointers for PBVH_BMESH. You can convert between sculpt vert refs and mesh indices with BKE_vertex_index_to_table and BKE_table_index_to_vertex. To prevent implicit casts to/from 32-bit ints, SculptVertRef is a structure: ``` struct SculptVertRef { intptr_t i} ``` The same idea is used for face references too with a similar SculptFaceRef structure. **Storing Triangulations In Nodes** We should cache triangles in PBVH nodes. I've roughed out a simple api for this in temp_multires_bmesh already (there were a few truly evil bugs that necessitated it). The new data structures are below. ``` typedef struct PBVHTri { int v[3]; // references into PBVHTriBuf->verts intptr_t l[3]; // loops int eflag; // bitmask of which edges in the tri are real edges in the mesh float no[3]; SculptFaceRef f; } PBVHTri; typedef struct PBVHTriBuf { PBVHTri *tris; SculptVertRef *verts; int *edges; int totvert, totedge, tottri; int verts_size, edges_size, tris_size; // private fields intptr_t *loops; int totloop, mat_nr; float min[3], max[3]; } PBVHTriBuf; ``` I've kept things as simple as possible (I was planning on doing this a lot later). Triangulations are generated lazily as with the old bm_ortri code, only instead of flagging nodes as dirty by freeing the triangulation a new PBVH_UpdateTris flag is set in node->flag. Some open questions are: # Should we use this for all PBVH types? If so, what should the related SCULPT_XXX api look like? ## Future Steps To make PBVH_BMESH usable outside of DynTopo (and even sculpt), the following needs to happen: - DONE. Remove triangle restriction from PBVH_BMESH. DynTopo should dynamically triangulate any non-triangle faces as it comes across them. - PARTIAL. Refactor DynTopo into it's own API separate from PBVH_BMESH. - DONE. Cache mesh triangulations inside PBVH nodes. - DONE. Use cached triangulations for drawing. - DONE. Support indexed drawing in PBVH draw code to save GPU bandwidth - Generate triangulations that are split by UV islands. ## Add support for fragment shader based flat face shading to the draw system. ``` This will help save GPU bandwidth for flat shaded meshes by not having to duplicate the vertex data for every single triangle. ```
Author
Member

Added subscriber: @JosephEagar

Added subscriber: @JosephEagar
Contributor

Added subscriber: @IyadAhmed

Added subscriber: @IyadAhmed

Added subscriber: @MetinSeven-1

Added subscriber: @MetinSeven-1
Member

Added subscriber: @PabloDobarro

Added subscriber: @PabloDobarro

Added subscriber: @GeorgiaPacific

Added subscriber: @GeorgiaPacific

Added subscriber: @StephenSwaney

Added subscriber: @StephenSwaney
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123

Added subscriber: @Alchimista

Added subscriber: @Alchimista
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:11:58 +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 06:15:02 +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
9 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#87456
No description provided.