[Bf-blender-cvs] [48278754a71] soc-2021-adaptive-cloth: adaptive_cloth: Add dynamic remeshing selection to GUI

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


Commit: 48278754a715e28fc1e3f9f038e627d55354aa73
Author: ishbosamiya
Date:   Thu Sep 2 14:43:54 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB48278754a715e28fc1e3f9f038e627d55354aa73

adaptive_cloth: Add dynamic remeshing selection to GUI

Add remeshing type support to both the cloth modifier and the adaptive
remesh modifier.

The basic call for dynamic remesh is also setup, only need to work on
finding the vertex sizing dynamically.

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

M	release/scripts/startup/bl_ui/properties_physics_cloth.py
M	source/blender/blenkernel/BKE_cloth_remesh.hh
M	source/blender/blenkernel/intern/cloth_remesh.cc
M	source/blender/makesdna/DNA_cloth_types.h
M	source/blender/makesdna/DNA_modifier_defaults.h
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_cloth.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_adaptive_remesh.cc

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py b/release/scripts/startup/bl_ui/properties_physics_cloth.py
index b0d22294e73..ce12f0baf60 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -330,6 +330,9 @@ class PHYSICS_PT_cloth_remesh(PhysicButtonsPanel, Panel):
 
         flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True)
 
+        col = flow.column(align=True)
+        col.prop(cloth, "remeshing_type", text="Remeshing Type")
+
         # TODO(ish): setup better ui
         col = flow.column(align=True)
         col.prop(cloth, "remeshing_size_min", text="Remeshing Sizing Min")
diff --git a/source/blender/blenkernel/BKE_cloth_remesh.hh b/source/blender/blenkernel/BKE_cloth_remesh.hh
index c69e78ad81d..516232ce8de 100644
--- a/source/blender/blenkernel/BKE_cloth_remesh.hh
+++ b/source/blender/blenkernel/BKE_cloth_remesh.hh
@@ -117,6 +117,8 @@ template<typename END, typename ExtraData> struct AdaptiveRemeshParams {
   float size_min;
   /* AdaptiveRemeshParamsFlags */
   uint32_t flags;
+  /* AdaptiveRemeshParamsType */
+  uint32_t type;
 
   /* For handling Extra Node Data */
   /**
@@ -160,6 +162,14 @@ enum AdaptiveRemeshParamsFlags {
   ADAPTIVE_REMESH_PARAMS_FORCE_SPLIT_FOR_SEWING = 1 << 1,
 };
 
+/**
+ * AdaptiveRemeshParams->type
+ */
+enum AdaptiveRemeshParamsType {
+  ADAPTIVE_REMESH_PARAMS_STATIC_REMESH = 0,
+  ADAPTIVE_REMESH_PARAMS_DYNAMIC_REMESH = 1,
+};
+
 /* `mesh` cannot be made const because function defined on `struct
  * Mesh` do not take `struct Mesh` as const even when they can be const */
 template<typename END, typename ExtraData>
@@ -3564,6 +3574,8 @@ struct TempEmptyAdaptiveRemeshParams {
   float size_min;
   /* AdaptiveRemeshParamsFlags */
   uint32_t flags;
+  /* AdaptiveRemeshParamsType */
+  uint32_t type;
 };
 
 Mesh *__temp_empty_adaptive_remesh(const TempEmptyAdaptiveRemeshParams &params, Mesh *mesh);
diff --git a/source/blender/blenkernel/intern/cloth_remesh.cc b/source/blender/blenkernel/intern/cloth_remesh.cc
index b8c6f6279ac..537ba7abce3 100644
--- a/source/blender/blenkernel/intern/cloth_remesh.cc
+++ b/source/blender/blenkernel/intern/cloth_remesh.cc
@@ -54,7 +54,7 @@
 #define SHOULD_REMESH_DUMP_FILE 1
 
 namespace blender::bke::internal {
-static FilenameGen static_remesh_name_gen("/tmp/static_remesh/remesh", ".mesh");
+static FilenameGen remesh_name_gen("/tmp/remesh/remesh", ".mesh");
 
 static std::string get_number_as_string(usize number)
 {
@@ -469,9 +469,9 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
 
 #if SHOULD_REMESH_DUMP_FILE
         auto after_flip_msgpack = this->serialize();
-        auto after_flip_filename = static_remesh_name_gen.get_curr(
+        auto after_flip_filename = remesh_name_gen.get_curr(
             "after_flip_" + get_number_as_string(std::get<0>(edge_index.get_raw())));
-        static_remesh_name_gen.gen_next();
+        remesh_name_gen.gen_next();
         dump_file(after_flip_filename, after_flip_msgpack);
 #endif
 
@@ -579,9 +579,9 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
           if (op_mesh_diff) {
 #if SHOULD_REMESH_DUMP_FILE
             auto after_flip_msgpack = this->serialize();
-            auto after_flip_filename = static_remesh_name_gen.get_curr(
+            auto after_flip_filename = remesh_name_gen.get_curr(
                 "after_collapse_" + get_number_as_string(std::get<0>(edge_index.get_raw())));
-            static_remesh_name_gen.gen_next();
+            remesh_name_gen.gen_next();
             dump_file(after_flip_filename, after_flip_msgpack);
 #endif
             const auto mesh_diff = op_mesh_diff.value();
@@ -612,8 +612,8 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
   {
 #if SHOULD_REMESH_DUMP_FILE
     auto static_remesh_start_msgpack = this->serialize();
-    auto static_remesh_start_filename = static_remesh_name_gen.get_curr("static_remesh_start");
-    static_remesh_name_gen.gen_next();
+    auto static_remesh_start_filename = remesh_name_gen.get_curr("static_remesh_start");
+    remesh_name_gen.gen_next();
     dump_file(static_remesh_start_filename, static_remesh_start_msgpack);
 #endif
     /* Set sizing for all verts */
@@ -648,12 +648,53 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
 
 #if SHOULD_REMESH_DUMP_FILE
     auto static_remesh_end_msgpack = this->serialize();
-    auto static_remesh_end_filename = static_remesh_name_gen.get_curr("static_remesh_end");
-    static_remesh_name_gen.gen_next();
+    auto static_remesh_end_filename = remesh_name_gen.get_curr("static_remesh_end");
+    remesh_name_gen.gen_next();
     dump_file(static_remesh_end_filename, static_remesh_end_msgpack);
 #endif
   }
 
+  template<typename ExtraData>
+  void dynamic_remesh(const AdaptiveRemeshParams<END, ExtraData> &params)
+  {
+    /* TODO(ish): merge static_remesh and dynamic_remesh functions
+     * since they differ only by a small part. Keeping it separate for
+     * now for testing purposes. */
+#if SHOULD_REMESH_DUMP_FILE
+    auto dynamic_remesh_start_msgpack = this->serialize();
+    auto dynamic_remesh_start_filename = remesh_name_gen.get_curr("dynamic_remesh_start");
+    remesh_name_gen.gen_next();
+    dump_file(dynamic_remesh_start_filename, dynamic_remesh_start_msgpack);
+#endif
+
+    /* TODO(ish): set vert sizing */
+
+    /* Set edge sizes */
+    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 */
+    if (sewing_enabled) {
+      this->mark_edges_between_sewing_edges();
+    }
+
+    /* Split the edges */
+    this->split_edges(sewing_enabled, force_split_for_sewing);
+
+    /* Collapse the edges */
+    this->collapse_edges();
+
+#if SHOULD_REMESH_DUMP_FILE
+    auto dynamic_remesh_end_msgpack = this->serialize();
+    auto dynamic_remesh_end_filename = remesh_name_gen.get_curr("dynamic_remesh_end");
+    remesh_name_gen.gen_next();
+    dump_file(dynamic_remesh_end_filename, dynamic_remesh_end_msgpack);
+#endif
+  }
+
  private:
   bool is_edge_splittable_adaptivemesh(const AdaptiveEdge &edge) const
   {
@@ -759,9 +800,9 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
 
 #if SHOULD_REMESH_DUMP_FILE
     auto after_split_msgpack = this->serialize();
-    auto after_split_filename = static_remesh_name_gen.get_curr(
+    auto after_split_filename = remesh_name_gen.get_curr(
         "after_split_" + get_number_as_string(std::get<0>(edge_index.get_raw())));
-    static_remesh_name_gen.gen_next();
+    remesh_name_gen.gen_next();
     dump_file(after_split_filename, after_split_msgpack);
 #endif
 
@@ -962,10 +1003,10 @@ class AdaptiveMesh : public Mesh<NodeData<END>, VertData, EdgeData, internal::Em
 
 #if SHOULD_REMESH_DUMP_FILE
       auto after_adding_loose_edge_msgpack = this->serialize();
-      auto after_adding_loose_edge_filename = static_remesh_name_gen.get_curr(
+      auto after_adding_loose_edge_filename = remesh_name_gen.get_curr(
           "after_adding_loose_edge_" + get_number_as_string(std::get<0>(vert_index.get_raw())) +
           "_" + get_number_as_string(std::get<0>(added_verts[0].get_raw())));
-      static_remesh_name_gen.gen_next();
+      remesh_name_gen.gen_next();
       dump_file(after_adding_loose_edge_filename, after_adding_loose_edge_msgpack);
 #endif
 
@@ -1705,13 +1746,19 @@ Mesh *adaptive_remesh(const AdaptiveRemeshParams<END, ExtraData> &params,
   adaptive_mesh.mark_verts_for_preserve(sewing_enabled);
 
   /* Actual Remeshing Part */
-  {
+  if (params.type == ADAPTIVE_REMESH_PARAMS_STATIC_REMESH) {
     float size_min = params.size_min;
     auto m = float2x2::identity();
     m = m * (1.0 / size_min);
     internal::Sizing vert_sizing(std::move(m));
     adaptive_mesh.static_remesh(vert_sizing, params);
   }
+  else if (params.type == ADAPTIVE_REMESH_PARAMS_DYNAMIC_REMESH) {
+    adaptive_mesh.dynamic_remesh(params);
+  }
+  else {
+    BLI_assert_unreachable();
+  }
 
   /* set back data from `AdaptiveMesh` to whatever needs it */
   {
@@ -1871,6 +1918,16 @@ Mesh *BKE_cloth_remesh(Object *ob, ClothModifierData *clmd, Mesh *mesh)
   if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SEW) {
     params.flags |= ADAPTIVE_REMESH_PARAMS_SEWING;
   }
+  if (clmd->sim_parms->remeshing_type == CLOTH_REMESHING_STATIC) {
+    params.type = ADAPTIVE_REMESH_PARAMS_STATIC_REMESH;
+  }
+  else if (clmd->sim_parms->remeshing_type == CLOTH_REMESHING_DYNAMIC) {
+    params.type = ADAPTIVE_REMESH_PARAMS_DYNAMIC_REMESH;
+  }
+  else {
+    BLI_assert_unreachable();
+  }
+
   params.extra_data_to_end = [](const Cloth &cloth, size_t index) {
     BLI_assert(index < cloth.mvert_num);
     BLI_assert(cloth.verts);
@@ -1924,6 +1981,7 @@ Mesh *__temp_empty_adaptive_remesh(const TempEmptyAdaptiveRemeshParams &input_pa
   AdaptiveRemeshParams<EmptyData, EmptyData> params;
   params.size_min = input_params.size_min;
   params.flags = input_params.flags;
+  params.type = input_params.type;
   params.extra_data_to_end = [](const EmptyData &UNUSED(data), size_t UNUSED(index)) {
     return internal::EmptyExtraData();
   };
diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h
index f28fd176330..c596bed8794 100644
--- a/source/blender/makesdna/DNA_cloth_types.h
+++ b/source/blender/makesdna/DNA_cloth_types.h
@@ -24,6 +24,7 @@
 #pragma once
 
 #include "DNA_defs.h"
+#include <stdint.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -182,8 +183,11 @@ typedef struct ClothSimSettings {
   float max_internal_compression;
 
   /* Remeshing parameters */
+  /** ClothRemeshingType */
+  uint32_t remeshing_type;
   /* TODO(ish): need to write docs for this */
   float remeshing_size_min;
+  char _pad2[4];
 
 } ClothSimSettings;
 
@@ -224,6 +228,16 @@ typedef enum {
   CLOTH_BENDING_ANGULAR = 1,
 } CLOTH_BENDING_MODEL;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list