[Bf-blender-cvs] [940ee5d5871] soc-2021-adaptive-cloth: adaptive_cloth: AdaptiveMesh: force split for sewing

ishbosamiya noreply at git.blender.org
Mon Sep 6 11:47:39 CEST 2021


Commit: 940ee5d5871ae530365359ece2886da5e3ed31aa
Author: ishbosamiya
Date:   Tue Aug 31 21:17:59 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB940ee5d5871ae530365359ece2886da5e3ed31aa

adaptive_cloth: AdaptiveMesh: force split for sewing

Option to split the opposite edge even if it does not meet the size
criterion, with the option, it ensures that no sewing edge is missed
when an edge is split (it can be missed if the opposite edge doesn't
meet the size criterion).

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

M	source/blender/blenkernel/BKE_cloth_remesh.hh
M	source/blender/blenkernel/intern/cloth_remesh.cc
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_adaptive_remesh.cc

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

diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index 65a86d16441..ca0c3688952 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -157,6 +157,7 @@ template<typename END, typename ExtraData> struct AdaptiveRemeshParams {
 enum AdaptiveRemeshParamsFlags {
   /** Sewing is enabled */
   ADAPTIVE_REMESH_PARAMS_SEWING = 1 << 0,
+  ADAPTIVE_REMESH_PARAMS_FORCE_SPLIT_FOR_SEWING = 1 << 1,
 };
 
 /* `mesh` cannot be made const because function defined on `struct
diff --git a/source/blender/blenkernel/intern/cloth_remesh.cc b/source/blender/blenkernel/intern/cloth_remesh.cc
index f908328a70f..f34f7c75719 100644
--- a/source/blender/blenkernel/intern/cloth_remesh.cc
+++ b/source/blender/blenkernel/intern/cloth_remesh.cc
@@ -47,6 +47,7 @@
 #include <cmath>
 #include <cstddef>
 #include <functional>
+#include <iostream>
 #include <limits>
 #include <optional>
 
@@ -524,7 +525,7 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
    * Here "size" is determined by `Sizing` stores in `Vert`s of the
    * `Edge`, using the function `Sizing::get_edge_size_sq()`.
    */
-  void split_edges(bool sewing_enabled)
+  void split_edges(bool sewing_enabled, bool force_split_for_sewing)
   {
     auto splittable_edges_set = this->get_splittable_edge_indices_set();
     do {
@@ -534,7 +535,7 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
           continue;
         }
 
-        this->split_edge_adaptivemesh(edge_index, sewing_enabled);
+        this->split_edge_adaptivemesh(edge_index, sewing_enabled, force_split_for_sewing);
       }
 
       splittable_edges_set = this->get_splittable_edge_indices_set();
@@ -643,6 +644,7 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
     this->set_edge_sizes();
 
     bool sewing_enabled = params.flags & ADAPTIVE_REMESH_PARAMS_SEWING;
+    bool force_split_for_sewing = params.flags & ADAPTIVE_REMESH_PARAMS_FORCE_SPLIT_FOR_SEWING;
 
     /* Mark edges that are between sewing edges only if sewing is
      * enabled */
@@ -651,7 +653,7 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
     }
 
     /* Split the edges */
-    this->split_edges(sewing_enabled);
+    this->split_edges(sewing_enabled, force_split_for_sewing);
 
     /* Collapse the edges */
     this->collapse_edges();
@@ -762,7 +764,7 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
    * the set of verts that were added by the split operation only.
    */
   std::tuple<AdaptiveMeshDiff<END>, blender::Vector<VertIndex>> split_edge_adaptivemesh(
-      const EdgeIndex &edge_index, bool sewing_enabled)
+      const EdgeIndex &edge_index, bool sewing_enabled, bool force_split_for_sewing)
   {
     auto &edge = this->get_checked_edge(edge_index);
     auto mesh_diff = this->split_edge_triangulate(edge.get_self_index(), true, true);
@@ -785,7 +787,8 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
       BLI_assert(mesh_diff.get_added_nodes().size() == 1);
       std::cout << "mesh_diff.get_added_verts().size(): " << mesh_diff.get_added_verts().size()
                 << std::endl;
-      const auto sewing_mesh_diff = this->try_adding_sewing_edge(mesh_diff.get_added_verts()[0]);
+      const auto sewing_mesh_diff = this->try_adding_sewing_edge(mesh_diff.get_added_verts()[0],
+                                                                 force_split_for_sewing);
 
       /* Append `sewing_mesh_diff` to `mesh_diff` so that
        * `flip_edges()` operates on a valid MeshDiff */
@@ -829,7 +832,8 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
    * split and it has another loose edge adjacent to it which can loop
    * back the given vert via an edge.
    */
-  AdaptiveMeshDiff<END> try_adding_sewing_edge(const VertIndex &vert_index)
+  AdaptiveMeshDiff<END> try_adding_sewing_edge(const VertIndex &vert_index,
+                                               bool force_split_for_sewing)
   {
     /* vert: is the vert that is being tested.
      *
@@ -947,8 +951,10 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
       {
         const auto &opposite_edge = this->get_checked_edge(opposite_edge_index);
 
-        if (this->is_edge_splittable_adaptivemesh(opposite_edge) == false) {
-          continue;
+        if (force_split_for_sewing == false) {
+          if (this->is_edge_splittable_adaptivemesh(opposite_edge) == false) {
+            continue;
+          }
         }
 
         if (this->is_edge_between_sewing_edges(opposite_edge) == false) {
@@ -956,8 +962,8 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
         }
       }
 
-      const auto [mesh_diff, added_verts] = this->split_edge_adaptivemesh(opposite_edge_index,
-                                                                          true);
+      const auto [mesh_diff, added_verts] = this->split_edge_adaptivemesh(
+          opposite_edge_index, true, force_split_for_sewing);
       complete_mesh_diff.append(mesh_diff);
       complete_mesh_diff.remove_non_existing_elements(*this);
 
@@ -1902,10 +1908,7 @@ Mesh *__temp_empty_adaptive_remesh(const TempEmptyAdaptiveRemeshParams &input_pa
 
   AdaptiveRemeshParams<EmptyData, EmptyData> params;
   params.size_min = input_params.size_min;
-  params.flags = 0;
-  if (input_params.flags & ADAPTIVE_REMESH_PARAMS_SEWING) {
-    params.flags |= ADAPTIVE_REMESH_PARAMS_SEWING;
-  }
+  params.flags = input_params.flags;
   params.extra_data_to_end = [](const EmptyData &UNUSED(data), size_t UNUSED(index)) {
     return internal::EmptyExtraData();
   };
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 30a4a77be66..9cc84995ce7 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -2365,6 +2365,7 @@ typedef enum AdaptiveRemeshFlag {
   ADAPTIVE_REMESH_ACROSS_SEAMS = 1 << 0,
   ADAPTIVE_REMESH_VERTS_SWAPPED = 1 << 1,
   ADAPTIVE_REMESH_SEWING = 1 << 2,
+  ADAPTIVE_REMESH_FORCE_SPLIT_FOR_SEWING = 1 << 3,
 } AdaptiveRemeshFlag;
 
 typedef enum AdaptiveRemeshMode {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 5bb25d85e9c..92b841129ab 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -7281,6 +7281,11 @@ static void rna_def_modifier_adaptive_remesh(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Enable Sewing", "Enable sewing during remeshing");
   RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+  prop = RNA_def_property(srna, "force_split_for_sewing", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", ADAPTIVE_REMESH_FORCE_SPLIT_FOR_SEWING);
+  RNA_def_property_ui_text(prop, "Force Split for Sewing", "Force splitting of edge for sewing");
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
   prop = RNA_def_property(srna, "size_min", PROP_FLOAT, PROP_NONE);
   RNA_def_property_float_sdna(prop, NULL, "size_min");
   RNA_def_property_ui_range(prop, 0.0001f, 2.0f, 0.005f, 4);
diff --git a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
index 2d383dfca99..5a7293b627c 100644
--- a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
+++ b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
@@ -69,6 +69,9 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
     if (armd->flag & ADAPTIVE_REMESH_SEWING) {
       params.flags |= ADAPTIVE_REMESH_PARAMS_SEWING;
     }
+    if (armd->flag & ADAPTIVE_REMESH_FORCE_SPLIT_FOR_SEWING) {
+      params.flags |= ADAPTIVE_REMESH_PARAMS_FORCE_SPLIT_FOR_SEWING;
+    }
 
     return __temp_empty_adaptive_remesh(params, mesh);
   }
@@ -179,6 +182,7 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
   else if (armd->mode == ADAPTIVE_REMESH_STATIC_REMESHING) {
     uiItemR(layout, ptr, "size_min", 0, nullptr, ICON_NONE);
     uiItemR(layout, ptr, "enable_sewing", 0, nullptr, ICON_NONE);
+    uiItemR(layout, ptr, "force_split_for_sewing", 0, nullptr, ICON_NONE);
   }
   else {
     BLI_assert_unreachable();



More information about the Bf-blender-cvs mailing list