Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorishbosamiya <ishbosamiya@gmail.com>2021-09-02 12:13:54 +0300
committerishbosamiya <ishbosamiya@gmail.com>2021-09-02 12:13:54 +0300
commit48278754a715e28fc1e3f9f038e627d55354aa73 (patch)
treed68669de35d96bd8750a447b9a29c6f446365c40
parentffcc059abf65e8d3863371f5a6e38db51a586be4 (diff)
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.
-rw-r--r--release/scripts/startup/bl_ui/properties_physics_cloth.py3
-rw-r--r--source/blender/blenkernel/BKE_cloth_remesh.hh12
-rw-r--r--source/blender/blenkernel/intern/cloth_remesh.cc86
-rw-r--r--source/blender/makesdna/DNA_cloth_types.h14
-rw-r--r--source/blender/makesdna/DNA_modifier_defaults.h1
-rw-r--r--source/blender/makesdna/DNA_modifier_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_cloth.c13
-rw-r--r--source/blender/makesrna/intern/rna_modifier.c5
-rw-r--r--source/blender/modifiers/intern/MOD_adaptive_remesh.cc14
9 files changed, 133 insertions, 16 deletions
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;
+/**
+ * Type of remeshing for the cloth.
+ *
+ * ClothSimSettings.remeshing_type
+ */
+typedef enum {
+ CLOTH_REMESHING_STATIC = 0,
+ CLOTH_REMESHING_DYNAMIC = 1,
+} ClothRemeshingType;
+
typedef struct ClothCollSettings {
/** E.g. pointer to temp memory for collisions. */
struct LinkNode *collision_list;
diff --git a/source/blender/makesdna/DNA_modifier_defaults.h b/source/blender/makesdna/DNA_modifier_defaults.h
index af239e5584e..2758dc7ab84 100644
--- a/source/blender/makesdna/DNA_modifier_defaults.h
+++ b/source/blender/makesdna/DNA_modifier_defaults.h
@@ -174,6 +174,7 @@
.max_internal_tension = 15.0f, \
.max_internal_compression = 15.0f, \
/* TODO(ish): setup better remeshing defaults */ \
+ .remeshing_type = CLOTH_REMESHING_STATIC, \
.remeshing_size_min = 0.01f, \
}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 9cc84995ce7..38201cb8527 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -2373,6 +2373,7 @@ typedef enum AdaptiveRemeshMode {
ADAPTIVE_REMESH_COLLAPSE_EDGE = 1,
ADAPTIVE_REMESH_FLIP_EDGE = 2,
ADAPTIVE_REMESH_STATIC_REMESHING = 3,
+ ADAPTIVE_REMESH_DYNAMIC_REMESHING = 4,
} AdaptiveRemeshMode;
#ifdef __cplusplus
diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c
index fc92de9b1e2..f4987a43d77 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -579,6 +579,12 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL},
};
+ static const EnumPropertyItem prop_remeshing_type_items[] = {
+ {CLOTH_REMESHING_STATIC, "STATIC", 0, "Static", "Static remeshing applied to the cloth"},
+ {CLOTH_REMESHING_DYNAMIC, "DYNAMIC", 0, "Dynamic", "Dynamic remeshing applied to the cloth"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
srna = RNA_def_struct(brna, "ClothSettings", NULL);
RNA_def_struct_ui_text(srna, "Cloth Settings", "Cloth simulation settings for an object");
RNA_def_struct_sdna(srna, "ClothSimSettings");
@@ -1060,6 +1066,13 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, 0, "rna_cloth_update");
+ prop = RNA_def_property(srna, "remeshing_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "remeshing_type");
+ RNA_def_property_enum_items(prop, prop_remeshing_type_items);
+ RNA_def_property_ui_text(prop, "Remeshing Type", "Type of remeshing applied to the cloth");
+ RNA_def_property_update(prop, 0, "rna_cloth_update");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+
/* TODO(ish): remeshing paramters need proper text and doc */
prop = RNA_def_property(srna, "remeshing_size_min", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "remeshing_size_min");
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 92b841129ab..87b839b62c5 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -7245,6 +7245,11 @@ static void rna_def_modifier_adaptive_remesh(BlenderRNA *brna)
0,
"Static Remeshing",
"Static Remeshing"},
+ {ADAPTIVE_REMESH_DYNAMIC_REMESHING,
+ "DYNAMIC_REMESHING",
+ 0,
+ "Dynamic Remeshing",
+ "Dynamic Remeshing"},
{0, NULL, 0, NULL, NULL},
};
diff --git a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
index 5a7293b627c..c05f6c025ca 100644
--- a/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
+++ b/source/blender/modifiers/intern/MOD_adaptive_remesh.cc
@@ -60,7 +60,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
auto mode = armd->mode;
- if (mode == ADAPTIVE_REMESH_STATIC_REMESHING) {
+ if (mode == ADAPTIVE_REMESH_STATIC_REMESHING || mode == ADAPTIVE_REMESH_DYNAMIC_REMESHING) {
auto size_min = armd->size_min;
TempEmptyAdaptiveRemeshParams params;
@@ -72,6 +72,15 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
if (armd->flag & ADAPTIVE_REMESH_FORCE_SPLIT_FOR_SEWING) {
params.flags |= ADAPTIVE_REMESH_PARAMS_FORCE_SPLIT_FOR_SEWING;
}
+ if (mode == ADAPTIVE_REMESH_STATIC_REMESHING) {
+ params.type = ADAPTIVE_REMESH_PARAMS_STATIC_REMESH;
+ }
+ else if (mode == ADAPTIVE_REMESH_DYNAMIC_REMESHING) {
+ params.type = ADAPTIVE_REMESH_PARAMS_DYNAMIC_REMESH;
+ }
+ else {
+ BLI_assert_unreachable();
+ }
return __temp_empty_adaptive_remesh(params, mesh);
}
@@ -179,7 +188,8 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
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) {
+ else if (armd->mode == ADAPTIVE_REMESH_STATIC_REMESHING ||
+ armd->mode == ADAPTIVE_REMESH_DYNAMIC_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);