Mesh: replace 'BKE_mesh_merge_verts' algorithm #105136

Merged
Germano Cavalcante merged 1 commits from mano-wii/blender:deduplicate_merge into main 2023-02-23 19:10:13 +01:00

Blender currently has 2 algorithms for merging vertices:

  • BKE_mesh_merge_verts;
  • blender::geometry::create_merged_mesh

BKE_mesh_merge_verts has a simplified algorithm to work with Array,
Mirror and Screw modifiers. It doesn't support merge results that would
create new faces. However it has shortcuts to be more efficient in
these modifiers.

blender::geometry::create_merged_mesh tries to predict all possible
outcomes. So it's a more complex. But it loses in performance to
BKE_mesh_merge_verts in some cases.

The performance comparison between these two depends on many factors.
blender::geometry::create_merged_mesh works with a context that has
only the affected geometry. Thus a smaller region of the mesh is read
for duplicate checking. Therefore, the smaller the affected geometry,
the more efficient the operation.

By my tests blender::geometry::create_merged_mesh beats
BKE_mesh_merge_verts when less than 20% of the geometry is affected
in worst case MESH_MERGE_VERTS_DUMP_IF_EQUAL or 17% in case of
MESH_MERGE_VERTS_DUMP_IF_MAPPED .

For cases where the entire geometry is affected, a 30% loss was noticed,
largely due to the creation of a context that represents the entire mesh.

Blender currently has 2 algorithms for merging vertices: - `BKE_mesh_merge_verts`; - `blender::geometry::create_merged_mesh` `BKE_mesh_merge_verts` has a simplified algorithm to work with Array, Mirror and Screw modifiers. It doesn't support merge results that would create new faces. However it has shortcuts to be more efficient in these modifiers. `blender::geometry::create_merged_mesh` tries to predict all possible outcomes. So it's a more complex. But it loses in performance to `BKE_mesh_merge_verts` in some cases. The performance comparison between these two depends on many factors. `blender::geometry::create_merged_mesh` works with a context that has only the affected geometry. Thus a smaller region of the mesh is read for duplicate checking. Therefore, the smaller the affected geometry, the more efficient the operation. By my tests `blender::geometry::create_merged_mesh` beats `BKE_mesh_merge_verts` when less than 20% of the geometry is affected in worst case `MESH_MERGE_VERTS_DUMP_IF_EQUAL` or 17% in case of `MESH_MERGE_VERTS_DUMP_IF_MAPPED` . For cases where the entire geometry is affected, a 30% loss was noticed, largely due to the creation of a context that represents the entire mesh.
Germano Cavalcante requested review from Hans Goudey 2023-02-23 16:35:05 +01:00
Hans Goudey approved these changes 2023-02-23 17:05:45 +01:00
Hans Goudey left a comment
Member

Thanks for working on this! My only constructive thought is that long term, it's a bit confusing to have vert_dest_map be passed as a mutable span rather than const (algorithms changing their inputs is often confusing). But that's not really changing here, so fine the way it is.

Thanks for working on this! My only constructive thought is that long term, it's a bit confusing to have `vert_dest_map` be passed as a mutable span rather than const (algorithms changing their inputs is often confusing). But that's not really changing here, so fine the way it is.
Member
/home/hans/blender-git/blender/source/blender/modifiers/intern/MOD_mirror.cc:71:45: warning: unused parameter ‘axis’ [-Wunused-parameter]
   71 |                                   const int axis,
      |                                   ~~~~~~~~~~^~~~
``` /home/hans/blender-git/blender/source/blender/modifiers/intern/MOD_mirror.cc:71:45: warning: unused parameter ‘axis’ [-Wunused-parameter] 71 | const int axis, | ~~~~~~~~~~^~~~
Germano Cavalcante force-pushed deduplicate_merge from 9b09023277 to a2f29efe9f 2023-02-23 19:08:18 +01:00 Compare
Germano Cavalcante merged commit 4369627e71 into main 2023-02-23 19:10:13 +01:00
Germano Cavalcante deleted branch deduplicate_merge 2023-02-23 19:10:14 +01:00
Sign in to join this conversation.
No reviewers
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
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#105136
No description provided.