[Bf-blender-cvs] [8399375098f] master: Cleanup: Reword comment, rename variables

Hans Goudey noreply at git.blender.org
Thu Apr 28 01:54:04 CEST 2022


Commit: 8399375098fa58d0201b861d035d4a1d56370baf
Author: Hans Goudey
Date:   Wed Apr 27 18:52:56 2022 -0500
Branches: master
https://developer.blender.org/rB8399375098fa58d0201b861d035d4a1d56370baf

Cleanup: Reword comment, rename variables

Use "transform" instead of "obmat", because the meshes
don't necessarily come from objects.

===================================================================

M	source/blender/blenkernel/BKE_mesh_boolean_convert.hh
M	source/blender/blenkernel/intern/mesh_boolean_convert.cc

===================================================================

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<const Mesh *> meshes,
-                          blender::Span<const float4x4 *> obmats,
+Mesh *direct_mesh_boolean(Span<const Mesh *> meshes,
+                          Span<const float4x4 *> transforms,
                           const float4x4 &target_transform,
-                          blender::Span<blender::Array<short>> material_remaps,
+                          Span<Array<short>> 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<const Mesh *> 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<const Vert *>(totvert);
-  r_info->mesh_to_imesh_face = Array<Face *>(totpoly);
-  r_info->mesh_vert_offset = Array<int>(nmeshes);
-  r_info->mesh_edge_offset = Array<int>(nmeshes);
-  r_info->mesh_poly_offset = Array<int>(nmeshes);
-  r_info->to_target_transform = Array<float4x4>(nmeshes);
-  r_info->has_negative_transform = Array<bool>(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<const Mesh *> meshes,
   Vector<const Vert *, estimated_max_facelen> face_vert;
   Vector<int, estimated_max_facelen> 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<const Mesh *> 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<const Mesh *> meshes,
-                          Span<const float4x4 *> obmats,
+                          Span<const float4x4 *> transforms,
                           const float4x4 &target_transform,
                           Span<Array<short>> material_remaps,
                           const bool use_self,
@@ -799,7 +800,7 @@ Mesh *direct_mesh_boolean(Span<const Mesh *> 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<const Mesh *> 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<int(int)> 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<const Mesh *> 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
 }



More information about the Bf-blender-cvs mailing list