Refactor: Mesh Merge: deduplicate code, no interpolation for edges #109836
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#109836
Loading…
Reference in New Issue
No description provided.
Delete Branch "mano-wii/blender:weld_improvements"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
With
74772c6920
, the merge by distance code for meshes now supportsoptional interpolation of custom data for vertices.
As this can be advantageous for performance and memory, it seems
convenient to support the same for edges (and in the future polygons
and corners).
So this commit reworks the code that finds the edge groups to match the
same used for vertices and thus deduplicating and simplifying the code.
Conveniently the
edge_ctx_map
array is no longer needed and can beremoved to save memory.
However it was necessary to create another array (which is usually
smaller) called
double_edges
(to matchdouble_verts
).Results:
The profiling result depends on some factors such as:
The best case is when the customdata is not interpolated and the operation affects large portions of the mesh:
The worst case is when the customdata is not interpolated and the operation affects small portions of the mesh:
Other cases:
Customdata is interpolated and the operation affects large portions of the mesh:
Customdata is interpolated and the operation affects small portions of the mesh:
539ecefe59
to6191b04d8c
6191b04d8c
to696349bd9a
@ -90,3 +83,1 @@
Array<int> vert_group_map; /* Maps the vertex group offset from the target vert index. */
Array<int> vert_groups_offs;
Array<int> vert_groups_buffer;
Vector<int> double_verts;
Could you add a comment explaining what "double" means in this context, and what the indices refer to?
@ -164,3 +149,3 @@
}
}
BLI_assert(kills == supposed_kill_len);
BLI_assert(kills == expected_kill_len);
Probably needs a
UNUSED_VARS_NDEBUG
@ -446,3 +363,1 @@
if (we.vert_a == we.vert_b) {
we.flag = ELEM_COLLAPSED;
const int vert_a = (v_dest_1 != OUT_OF_CONTEXT) ? v_dest_1 : v1;
Can remove the double negative by switching
v_dest_1
and changing!=
to==
@ -478,2 +389,3 @@
* \return r_edge_double_kill_len: Number of edges to be destroyed by merging or collapsing.
*/
static void weld_edge_find_doubles(int remain_edge_ctx_len,
static void weld_edge_find_doubles(Span<WeldEdge> wedge,
Suggest
weld_edges
as a variable name.@ -620,3 +475,1 @@
r_edge_groups_verts[wgroups_len] = {we->vert_a, we->vert_b};
r_edge_groups_map[i] = wgroups_len;
wgroups_len++;
const WeldEdge &we_b = wedge[e_ctx_b];
Fully support changing pointers to references where possible, but the change makes the diff noisy, and makes it harder to see the larger changes. Maybe this could be committed separately?
@ -1449,0 +1274,4 @@
* \param double_elems: Affected elements in `dest_map` that will compose groups.
* Used for performance only.
*
* \return r_groups_map: Map that points out the group of elements that an element belongs to.
Probably worth specifying "source" or "result" whenever you use the word "element," that's the confusing part
@ -1449,0 +1282,4 @@
Span<int> double_elems,
Array<int> &r_groups_map,
Array<int> &r_groups_buffer,
Array<int> &r_groups_offs)
r_groups_offs
->r_groups_offets
The extra two letters really help :P
@ -1449,0 +1305,4 @@
}
/* Add +1 to allow calculation of the length of the last group. */
r_groups_offs.reinitialize(wgroups_len + 1);
"reinitialize and fill" can be replaced with
r_group_offs = Array<int>(wgroups_len + 1, 0);
That might be a bit faster in the future actually, since
Array
could usecalloc
in that case.But it's also just shorter.
@ -1449,0 +1308,4 @@
r_groups_offs.reinitialize(wgroups_len + 1);
r_groups_offs.fill(0);
for (const int elem_orig : double_elems) {
Reading this, I'm not sure. But could this be implemented with
array_utils::count_indices
? Nice to standardize these patterns where possible to make them more recognizable.@ -1449,0 +1315,4 @@
}
int offs = 0;
for (const int i : IndexRange(wgroups_len)) {
Use
offset_indices::accumulate_counts_to_offsets
@ -1449,0 +1324,4 @@
r_groups_buffer.reinitialize(offs);
BLI_assert(r_groups_buffer.size() == double_elems.size());
/* Use a reverse for loop to ensure that indexes are assigned in ascending order. */
indexes
->indices
@ -1544,0 +1434,4 @@
Span<int> double_elems,
const int dest_size,
const bool do_mix_data,
Array<int> &r_final_map)
It's confusing that the custom data merging process is also building the "final map". If those two processes could be separated, I think the whole process would be easier to understand. It's also worth simplifying custom data interpolation, since it's often a performance bottleneck, and if it's simpler it's easier to optimize.
@ -1544,0 +1476,4 @@
if (do_mix_data) {
const int grp_index = groups_map[i];
const int grp_buffer_offs = groups_offs[grp_index];
const int grp_buffer_len = groups_offs[grp_index + 1] - grp_buffer_offs;
Declare an
OffsetIndices
variable above to avoid repeating this boilerplate@ -1544,0 +1506,4 @@
}
if (finalize_map) {
for (int i : r_final_map.index_range()) {
int i
->const int i