[Bf-blender-cvs] [358030554ac] soc-2021-adaptive-cloth: modifier: adaptive_remesh: UI for static remeshing of the mesh

ishbosamiya noreply at git.blender.org
Mon Jul 26 08:17:41 CEST 2021


Commit: 358030554ac75d2f84343701fa7c64e7d463814a
Author: ishbosamiya
Date:   Wed Jul 21 23:27:17 2021 +0530
Branches: soc-2021-adaptive-cloth
https://developer.blender.org/rB358030554ac75d2f84343701fa7c64e7d463814a

modifier: adaptive_remesh: UI for static remeshing of the mesh

Simple UI to allow `adaptive_remesh()` through the simple wrapper to
be called and controlled easily.

This should help with testing since the cloth simulator when applied
uses the (point) cached `Mesh` instead running the simulation which
will call `adaptive_remesh()` for us. This will need to be fixed later
but this is an easier approach to continue development the adaptive
remesher.

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

M	source/blender/makesdna/DNA_modifier_defaults.h
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/makesdna/DNA_modifier_defaults.h b/source/blender/makesdna/DNA_modifier_defaults.h
index adc68bcdb7d..af239e5584e 100644
--- a/source/blender/makesdna/DNA_modifier_defaults.h
+++ b/source/blender/makesdna/DNA_modifier_defaults.h
@@ -23,6 +23,14 @@
 /* Struct members on own line. */
 /* clang-format off */
 
+#define _DNA_DEFAULT_AdaptiveRemeshModifierData \
+  { \
+    .edge_index = 0, \
+    .flag = 0, \
+    .mode = 0, \
+    .size_min = 0.05 \
+  }
+
 #define _DNA_DEFAULT_ArmatureModifierData \
   { \
     .deformflag = ARM_DEF_VGROUP, \
@@ -49,13 +57,6 @@
     .uv_offset = {0.0f, 0.0f}, \
   }
 
-#define _DNA_DEFAULT_AdaptiveRemeshModifierData \
-  { \
-    .edge_index = 0, \
-    .flag = 0, \
-    .mode = 0, \
-  }
-
 #define _DNA_DEFAULT_BevelModifierData \
   { \
     .value = 0.1f, \
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index cc1e903e763..4cf74ad19d4 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -2355,8 +2355,9 @@ typedef struct AdaptiveRemeshModifierData {
   /* AdaptiveRemeshMode */
   uint32_t mode;
 
-  char _pad[4];
-
+  /* Needed for static remeshing and in the future dynamic remeshing
+   * as well */
+  float size_min;
 } AdaptiveRemeshModifierData;
 
 typedef enum AdaptiveRemeshFlag {
@@ -2368,6 +2369,7 @@ typedef enum AdaptiveRemeshMode {
   ADAPTIVE_REMESH_SPLIT_EDGE = 0,
   ADAPTIVE_REMESH_COLLAPSE_EDGE = 1,
   ADAPTIVE_REMESH_FLIP_EDGE = 2,
+  ADAPTIVE_REMESH_STATIC_REMESHING = 3,
 } AdaptiveRemeshMode;
 
 #ifdef __cplusplus
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index ac2414220dd..a958fed53d4 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -7240,6 +7240,11 @@ static void rna_def_modifier_adaptive_remesh(BlenderRNA *brna)
        "Collapse Edge",
        "Collapse edge of given index"},
       {ADAPTIVE_REMESH_FLIP_EDGE, "FLIP_EDGE", 0, "Flip Edge", "Flip edge of given index"},
+      {ADAPTIVE_REMESH_STATIC_REMESHING,
+       "STATIC_REMESHING",
+       0,
+       "Static Remeshing",
+       "Static Remeshing"},
       {0, NULL, 0, NULL, NULL},
   };
 
@@ -7271,6 +7276,12 @@ static void rna_def_modifier_adaptive_remesh(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Verts Swapped", "Swap verts during the operation");
   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);
+  RNA_def_property_ui_text(prop, "Remeshing Size Min", "");
+  RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
   RNA_define_lib_overridable(false);
 }
 
diff --git a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
index 1283ff4a520..d47720d8814 100644
--- a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
+++ b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
@@ -53,10 +53,20 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
 {
   AdaptiveRemeshModifierData *armd = (AdaptiveRemeshModifierData *)md;
 
+  auto mode = armd->mode;
+
+  if (mode == ADAPTIVE_REMESH_STATIC_REMESHING) {
+    auto size_min = armd->size_min;
+
+    TempEmptyAdaptiveRemeshParams params;
+    params.size_min = size_min;
+
+    return __temp_empty_adaptive_remesh(params, mesh);
+  }
+
   auto edge_i = armd->edge_index;
   auto across_seams = armd->flag & ADAPTIVE_REMESH_ACROSS_SEAMS;
   auto verts_swapped = armd->flag & ADAPTIVE_REMESH_VERTS_SWAPPED;
-  auto mode = armd->mode;
 
   internal::MeshIO reader;
   reader.read(mesh);
@@ -106,13 +116,23 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
 
   PointerRNA ob_ptr;
   PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
+  AdaptiveRemeshModifierData *armd = static_cast<AdaptiveRemeshModifierData *>(ptr->data);
 
   uiLayoutSetPropSep(layout, true);
 
   uiItemR(layout, ptr, "mode", 0, nullptr, ICON_NONE);
-  uiItemR(layout, ptr, "edge_index", 0, nullptr, ICON_NONE);
-  uiItemR(layout, ptr, "use_across_seams", 0, nullptr, ICON_NONE);
-  uiItemR(layout, ptr, "is_verts_swapped", 0, nullptr, ICON_NONE);
+  if (armd->mode == ADAPTIVE_REMESH_SPLIT_EDGE || armd->mode == ADAPTIVE_REMESH_COLLAPSE_EDGE ||
+      armd->mode == ADAPTIVE_REMESH_FLIP_EDGE) {
+    uiItemR(layout, ptr, "edge_index", 0, nullptr, ICON_NONE);
+    uiItemR(layout, ptr, "use_across_seams", 0, nullptr, ICON_NONE);
+    uiItemR(layout, ptr, "is_verts_swapped", 0, nullptr, ICON_NONE);
+  }
+  else if (armd->mode == ADAPTIVE_REMESH_STATIC_REMESHING) {
+    uiItemR(layout, ptr, "size_min", 0, nullptr, ICON_NONE);
+  }
+  else {
+    BLI_assert_unreachable();
+  }
 
   modifier_panel_end(layout, ptr);
 }



More information about the Bf-blender-cvs mailing list