diff options
author | Howard Trickey <howard.trickey@gmail.com> | 2021-02-22 01:57:03 +0300 |
---|---|---|
committer | Howard Trickey <howard.trickey@gmail.com> | 2021-02-22 01:57:03 +0300 |
commit | a3f091d7ceda77181422625135225e55afa612c8 (patch) | |
tree | e0529be5ae4da66a1d7fbc3e35162b925f519dc5 /source/blender/blenlib/intern | |
parent | 7883eb04ed3a3718a5a3b5e598c0e12eb9708d9f (diff) |
Change Exact Boolean modifier to skip round trip through BMesh.
The Exact modifier code had been written to avoid using BMesh but
in the initial release the modifier still converted all Meshes to
BMeshes, and then after running the boolean code on the BMeshes,
converted the result back to a Mesh.
This change skips that. Most of the work here is in getting the
Custom Data layers right. The approach taken is to merge default
layers from all operand meshes into the final result, and then
use the original verts, edges, polys, and loops to copy or interpolate
the appropriate custom data layers from all operands into the result.
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/mesh_boolean.cc | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index bfc1e4b01d3..defcb414c86 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -2605,6 +2605,26 @@ static int find_cdt_edge(const CDT_result<mpq_class> &cdt_out, int v1, int v2) return -1; } +/* Return the original edge id for the cdt output edge e_out, given that + * the only input to CDT was face f. Pick the first, if there are several. */ +static int orig_edge_for_cdt_edge(const CDT_result<mpq_class> &cdt_out, + int cdt_e_out, + const Face *f) +{ + for (int cdt_e_orig : cdt_out.edge_orig[cdt_e_out]) { + if (cdt_e_orig != NO_INDEX) { + BLI_assert(cdt_e_orig >= cdt_out.face_edge_offset); + int a = cdt_e_orig / cdt_out.face_edge_offset; + int b = cdt_e_orig % cdt_out.face_edge_offset; + /* It is the bth position within cdt input face a - 1. There is only one face, f. */ + BLI_assert(a == 1); + BLI_assert(b < f->size()); + return f->edge_orig[b]; + } + } + return NO_INDEX; +} + /** * Tessellate face f into triangles and return an array of `const Face *` * giving that triangulation. @@ -2660,13 +2680,7 @@ static Array<Face *> triangulate_poly(Face *f, IMeshArena *arena) for (int i = 0; i < 3; ++i) { int e_out = find_cdt_edge(cdt_out, i_v_out[i], i_v_out[(i + 1) % 3]); BLI_assert(e_out != -1); - eo[i] = NO_INDEX; - for (int orig : cdt_out.edge_orig[e_out]) { - if (orig != NO_INDEX) { - eo[i] = orig; - break; - } - } + eo[i] = orig_edge_for_cdt_edge(cdt_out, e_out, f); } if (rev) { ans[t] = arena->add_face( |