diff options
author | Hans Goudey <h.goudey@me.com> | 2022-04-28 02:52:56 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-04-28 02:53:56 +0300 |
commit | 8399375098fa58d0201b861d035d4a1d56370baf (patch) | |
tree | 8a1647ad3699eb30e89362c18d1eec5f68d67f35 /source/blender/blenkernel/intern/mesh_boolean_convert.cc | |
parent | 52a5f68562680c0ccd6d4e525098bb5e2af7d0bd (diff) |
Cleanup: Reword comment, rename variables
Use "transform" instead of "obmat", because the meshes
don't necessarily come from objects.
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_boolean_convert.cc')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_boolean_convert.cc | 44 |
1 files changed, 25 insertions, 19 deletions
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 } |