From 8399375098fa58d0201b861d035d4a1d56370baf Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 27 Apr 2022 18:52:56 -0500 Subject: Cleanup: Reword comment, rename variables Use "transform" instead of "obmat", because the meshes don't necessarily come from objects. --- .../blender/blenkernel/BKE_mesh_boolean_convert.hh | 20 +++++----- .../blenkernel/intern/mesh_boolean_convert.cc | 44 ++++++++++++---------- 2 files changed, 34 insertions(+), 30 deletions(-) (limited to 'source/blender/blenkernel') diff --git a/source/blender/blenkernel/BKE_mesh_boolean_convert.hh b/source/blender/blenkernel/BKE_mesh_boolean_convert.hh index 54209f1ccfc..abaf2ab0178 100644 --- a/source/blender/blenkernel/BKE_mesh_boolean_convert.hh +++ b/source/blender/blenkernel/BKE_mesh_boolean_convert.hh @@ -17,19 +17,17 @@ struct Mesh; namespace blender::meshintersect { /** - * Do a mesh boolean operation directly on meshes (without going back and forth to BMesh). - * \param meshes: An array of Mesh pointers. - * \param obmats: An array of pointers to the obmat matrices that transform local - * coordinates to global ones. It is allowed for the pointers to be null, meaning the - * transformation is the identity. - * \param material_remaps: An array of pointers to arrays of maps from material slot numbers in the - * corresponding mesh to the material slot in the first mesh. It is OK for material_remaps or any - * of its constituent arrays to be empty. + * Do a mesh boolean operation directly on meshes (without going back and forth from BMesh). + * \param transforms: An array of pointers to transform matrices used for each mesh's positions. + * It is allowed for the pointers to be null, meaning the transformation is the identity. + * \param material_remaps: An array of maps from material slot numbers in the corresponding mesh + * to the material slot in the first mesh. It is OK for material_remaps or any of its constituent + * arrays to be empty. */ -Mesh *direct_mesh_boolean(blender::Span meshes, - blender::Span obmats, +Mesh *direct_mesh_boolean(Span meshes, + Span transforms, const float4x4 &target_transform, - blender::Span> material_remaps, + Span> material_remaps, bool use_self, bool hole_tolerant, int boolean_mode); diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc index 3fcacb31b24..9e77b138359 100644 --- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc +++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc @@ -37,7 +37,7 @@ constexpr int estimated_max_facelen = 100; /* Used for initial size of some Vect * so this is a hack to clean up such matrices. * Would be better to change the transformation code itself. */ -static float4x4 clean_obmat(const float4x4 &mat) +static float4x4 clean_transform(const float4x4 &mat) { float4x4 cleaned; const float fuzz = 1e-6f; @@ -257,13 +257,13 @@ static IMesh meshes_to_imesh(Span meshes, const int estimate_num_outv = 3 * totvert; const int estimate_num_outf = 4 * totpoly; arena.reserve(estimate_num_outv, estimate_num_outf); - r_info->mesh_to_imesh_vert = Array(totvert); - r_info->mesh_to_imesh_face = Array(totpoly); - r_info->mesh_vert_offset = Array(nmeshes); - r_info->mesh_edge_offset = Array(nmeshes); - r_info->mesh_poly_offset = Array(nmeshes); - r_info->to_target_transform = Array(nmeshes); - r_info->has_negative_transform = Array(nmeshes); + r_info->mesh_to_imesh_vert.reinitialize(totvert); + r_info->mesh_to_imesh_face.reinitialize(totpoly); + r_info->mesh_vert_offset.reinitialize(nmeshes); + r_info->mesh_edge_offset.reinitialize(nmeshes); + r_info->mesh_poly_offset.reinitialize(nmeshes); + r_info->to_target_transform.reinitialize(nmeshes); + r_info->has_negative_transform.reinitialize(nmeshes); r_info->material_remaps = material_remaps; int v = 0; int e = 0; @@ -275,11 +275,11 @@ static IMesh meshes_to_imesh(Span meshes, Vector face_vert; Vector face_edge_orig; - /* To convert the coordinates of objects 1, 2, etc. into the local space - * of the target. We multiply each object's `obmat` by the inverse of the + /* To convert the coordinates of meshes 1, 2, etc. into the local space + * of the target, multiply each transform by the inverse of the * target matrix. Exact Boolean works better if these matrices are 'cleaned' - * -- see the comment for the `clean_obmat` function, above. */ - const float4x4 inv_target_mat = clean_obmat(target_transform).inverted(); + * -- see the comment for the `clean_transform` function, above. */ + const float4x4 inv_target_mat = clean_transform(target_transform).inverted(); /* For each input `Mesh`, make `Vert`s and `Face`s for the corresponding * `MVert`s and `MPoly`s, and keep track of the original indices (using the @@ -291,10 +291,10 @@ static IMesh meshes_to_imesh(Span meshes, r_info->mesh_vert_offset[mi] = v; r_info->mesh_edge_offset[mi] = e; r_info->mesh_poly_offset[mi] = f; - /* Get matrix that transforms a coordinate in objects[mi]'s local space + /* Get matrix that transforms a coordinate in meshes[mi]'s local space * to the target space. */ const float4x4 objn_mat = (obmats[mi] == nullptr) ? float4x4::identity() : - clean_obmat(*obmats[mi]); + clean_transform(*obmats[mi]); r_info->to_target_transform[mi] = inv_target_mat * objn_mat; r_info->has_negative_transform[mi] = objn_mat.is_negative(); @@ -419,6 +419,7 @@ static void copy_poly_attributes(Mesh *dest_mesh, } } } + mp->flag = orig_mp->flag; CustomData *target_cd = &dest_mesh->pdata; const CustomData *source_cd = &orig_me->pdata; @@ -791,7 +792,7 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim) #endif // WITH_GMP Mesh *direct_mesh_boolean(Span meshes, - Span obmats, + Span transforms, const float4x4 &target_transform, Span> material_remaps, const bool use_self, @@ -799,7 +800,7 @@ Mesh *direct_mesh_boolean(Span meshes, const int boolean_mode) { #ifdef WITH_GMP - BLI_assert(meshes.size() == obmats.size()); + BLI_assert(meshes.size() == transforms.size()); BLI_assert(material_remaps.size() == 0 || material_remaps.size() == meshes.size()); if (meshes.size() <= 0) { return nullptr; @@ -811,7 +812,7 @@ Mesh *direct_mesh_boolean(Span meshes, } MeshesToIMeshInfo mim; IMeshArena arena; - IMesh m_in = meshes_to_imesh(meshes, obmats, material_remaps, target_transform, arena, &mim); + IMesh m_in = meshes_to_imesh(meshes, transforms, material_remaps, target_transform, arena, &mim); std::function shape_fn = [&mim](int f) { for (int mi = 0; mi < mim.mesh_poly_offset.size() - 1; ++mi) { if (f < mim.mesh_poly_offset[mi + 1]) { @@ -835,8 +836,13 @@ Mesh *direct_mesh_boolean(Span meshes, return imesh_to_mesh(&m_out, mim); #else // WITH_GMP - UNUSED_VARS( - meshes, obmats, material_remaps, target_transform, use_self, hole_tolerant, boolean_mode); + UNUSED_VARS(meshes, + transforms, + material_remaps, + target_transform, + use_self, + hole_tolerant, + boolean_mode); return nullptr; #endif // WITH_GMP } -- cgit v1.2.3