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:
authorHans Goudey <h.goudey@me.com>2020-10-01 20:56:34 +0300
committerHans Goudey <h.goudey@me.com>2020-10-01 20:56:34 +0300
commitc3238bd50010e43ad97edb07ca1b2fe04ddf7f45 (patch)
treefa43f6fba52cde9fad9c4931c970861b675e7ae9
parent4c0ef4f788a1037888d5cb0a87ac23d6fe84573e (diff)
Cleanup: Use DNA defaults for cloth modifier
Followup for rB8398050695 This requires moving a few enum definitions to DNA instead of BKE, and adding default definitions for the two structs the cloth modifier where the cloth modifier stores its settings. The defaults are also reordered to be consistent with the order of each item in the struct.
-rw-r--r--source/blender/blenkernel/BKE_cloth.h42
-rw-r--r--source/blender/blenkernel/intern/cloth.c94
-rw-r--r--source/blender/makesdna/DNA_cloth_types.h41
-rw-r--r--source/blender/makesdna/DNA_modifier_defaults.h97
-rw-r--r--source/blender/makesdna/intern/dna_defaults.c9
-rw-r--r--source/blender/makesrna/intern/rna_cloth.c2
-rw-r--r--source/blender/modifiers/intern/MOD_cloth.c17
7 files changed, 158 insertions, 144 deletions
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 5af37829577..20e2122a195 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -193,47 +193,6 @@ typedef struct ClothSpring {
} \
((void)0)
-/* SIMULATION FLAGS: goal flags,.. */
-/* These are the bits used in SimSettings.flags. */
-typedef enum {
- /** Object is only collision object, no cloth simulation is done. */
- CLOTH_SIMSETTINGS_FLAG_COLLOBJ = (1 << 2),
- /** DEPRECATED, for versioning only. */
- CLOTH_SIMSETTINGS_FLAG_GOAL = (1 << 3),
- /** True if tearing is enabled. */
- CLOTH_SIMSETTINGS_FLAG_TEARING = (1 << 4),
- /** True if pressure sim is enabled. */
- CLOTH_SIMSETTINGS_FLAG_PRESSURE = (1 << 5),
- /** Use the user defined target volume. */
- CLOTH_SIMSETTINGS_FLAG_PRESSURE_VOL = (1 << 6),
- /** True if internal spring generation is enabled. */
- CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS = (1 << 7),
- /** DEPRECATED, for versioning only. */
- CLOTH_SIMSETTINGS_FLAG_SCALING = (1 << 8),
- /** Require internal springs to be created between points with opposite normals. */
- CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL = (1 << 9),
- /** Edit cache in edit-mode. */
- /* CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12), */ /* UNUSED */
- /** Don't allow spring compression. */
- CLOTH_SIMSETTINGS_FLAG_RESIST_SPRING_COMPRESS = (1 << 13),
- /** Pull ends of loose edges together. */
- CLOTH_SIMSETTINGS_FLAG_SEW = (1 << 14),
- /** Make simulation respect deformations in the base object. */
- CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH = (1 << 15),
-} CLOTH_SIMSETTINGS_FLAGS;
-
-/* ClothSimSettings.bending_model. */
-typedef enum {
- CLOTH_BENDING_LINEAR = 0,
- CLOTH_BENDING_ANGULAR = 1,
-} CLOTH_BENDING_MODEL;
-
-/* COLLISION FLAGS */
-typedef enum {
- CLOTH_COLLSETTINGS_FLAG_ENABLED = (1 << 1), /* enables cloth - object collisions */
- CLOTH_COLLSETTINGS_FLAG_SELF = (1 << 2), /* enables selfcollisions */
-} CLOTH_COLLISIONSETTINGS_FLAGS;
-
/* Spring types as defined in the paper.*/
typedef enum {
CLOTH_SPRING_TYPE_STRUCTURAL = (1 << 1),
@@ -281,7 +240,6 @@ int cloth_bvh_collision(struct Depsgraph *depsgraph,
// needed for modifier.c
void cloth_free_modifier_extern(struct ClothModifierData *clmd);
void cloth_free_modifier(struct ClothModifierData *clmd);
-void cloth_init(struct ClothModifierData *clmd);
void clothModifier_do(struct ClothModifierData *clmd,
struct Depsgraph *depsgraph,
struct Scene *scene,
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 770a9379e2d..3d5451125d9 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -75,100 +75,6 @@ typedef struct BendSpringRef {
* External interface called by modifier.c clothModifier functions.
*
******************************************************************************/
-/**
- * cloth_init - creates a new cloth simulation.
- *
- * 1. create object
- * 2. fill object with standard values or with the GUI settings if given
- */
-void cloth_init(ClothModifierData *clmd)
-{
- /* Initialize our new data structure to reasonable values. */
- clmd->sim_parms->gravity[0] = 0.0;
- clmd->sim_parms->gravity[1] = 0.0;
- clmd->sim_parms->gravity[2] = -9.81;
- clmd->sim_parms->tension = 15.0;
- clmd->sim_parms->max_tension = 15.0;
- clmd->sim_parms->compression = 15.0;
- clmd->sim_parms->max_compression = 15.0;
- clmd->sim_parms->shear = 5.0;
- clmd->sim_parms->max_shear = 5.0;
- clmd->sim_parms->bending = 0.5;
- clmd->sim_parms->max_bend = 0.5;
- clmd->sim_parms->tension_damp = 5.0;
- clmd->sim_parms->compression_damp = 5.0;
- clmd->sim_parms->shear_damp = 5.0;
- clmd->sim_parms->bending_damping = 0.5;
- clmd->sim_parms->Cvi = 1.0;
- clmd->sim_parms->mass = 0.3f;
- clmd->sim_parms->stepsPerFrame = 5;
- clmd->sim_parms->flags = 0;
- clmd->sim_parms->solver_type = 0;
- clmd->sim_parms->maxspringlen = 10;
- clmd->sim_parms->vgroup_mass = 0;
- clmd->sim_parms->vgroup_shrink = 0;
-
- /* Min amount the fabric will shrink by 0.0 = no shrinking, 1.0 = shrink to nothing. */
- clmd->sim_parms->shrink_min = 0.0f;
-
- clmd->sim_parms->avg_spring_len = 0.0;
- clmd->sim_parms->presets = 2; /* cotton as start setting */
- clmd->sim_parms->timescale = 1.0f; /* speed factor, describes how fast cloth moves */
- clmd->sim_parms->time_scale = 1.0f; /* multiplies cloth speed */
- clmd->sim_parms->reset = 0;
-
- clmd->coll_parms->self_friction = 5.0;
- clmd->coll_parms->friction = 5.0;
- clmd->coll_parms->loop_count = 2;
- clmd->coll_parms->epsilon = 0.015f;
- clmd->coll_parms->flags = CLOTH_COLLSETTINGS_FLAG_ENABLED;
- clmd->coll_parms->collision_list = NULL;
- clmd->coll_parms->selfepsilon = 0.015;
- clmd->coll_parms->vgroup_selfcol = 0;
-
- /* These defaults are copied from softbody.c's
- * softbody_calc_forces() function.
- */
- clmd->sim_parms->eff_force_scale = 1000.0;
- clmd->sim_parms->eff_wind_scale = 250.0;
-
- /* Internal spring settings */
- clmd->sim_parms->internal_spring_max_length = 0.0f;
- clmd->sim_parms->internal_spring_max_diversion = M_PI / 4.0f;
- clmd->sim_parms->internal_tension = 15.0f;
- clmd->sim_parms->max_internal_tension = 15.0f;
- clmd->sim_parms->internal_compression = 15.0f;
- clmd->sim_parms->max_internal_compression = 15.0f;
- clmd->sim_parms->vgroup_intern = 0;
- clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL;
-
- /* Pressure settings */
- clmd->sim_parms->uniform_pressure_force = 0.0f;
- clmd->sim_parms->target_volume = 0.0f;
- clmd->sim_parms->pressure_factor = 1.0f;
- clmd->sim_parms->fluid_density = 0.0f;
- clmd->sim_parms->vgroup_pressure = 0;
-
- // also from softbodies
- clmd->sim_parms->maxgoal = 1.0f;
- clmd->sim_parms->mingoal = 0.0f;
- clmd->sim_parms->defgoal = 0.0f;
- clmd->sim_parms->goalspring = 1.0f;
- clmd->sim_parms->goalfrict = 0.0f;
- clmd->sim_parms->velocity_smooth = 0.0f;
-
- clmd->sim_parms->voxel_cell_size = 0.1f;
-
- clmd->sim_parms->bending_model = CLOTH_BENDING_ANGULAR;
-
- if (!clmd->sim_parms->effector_weights) {
- clmd->sim_parms->effector_weights = BKE_effector_add_weights(NULL);
- }
-
- if (clmd->point_cache) {
- clmd->point_cache->step = 1;
- }
-}
static BVHTree *bvhtree_build_from_cloth(ClothModifierData *clmd, float epsilon)
{
diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h
index bc6991b3249..a4c0d9a4c40 100644
--- a/source/blender/makesdna/DNA_cloth_types.h
+++ b/source/blender/makesdna/DNA_cloth_types.h
@@ -177,6 +177,41 @@ typedef struct ClothSimSettings {
} ClothSimSettings;
+/* SIMULATION FLAGS: goal flags,.. */
+/* These are the bits used in SimSettings.flags. */
+typedef enum {
+ /** Object is only collision object, no cloth simulation is done. */
+ CLOTH_SIMSETTINGS_FLAG_COLLOBJ = (1 << 2),
+ /** DEPRECATED, for versioning only. */
+ CLOTH_SIMSETTINGS_FLAG_GOAL = (1 << 3),
+ /** True if tearing is enabled. */
+ CLOTH_SIMSETTINGS_FLAG_TEARING = (1 << 4),
+ /** True if pressure sim is enabled. */
+ CLOTH_SIMSETTINGS_FLAG_PRESSURE = (1 << 5),
+ /** Use the user defined target volume. */
+ CLOTH_SIMSETTINGS_FLAG_PRESSURE_VOL = (1 << 6),
+ /** True if internal spring generation is enabled. */
+ CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS = (1 << 7),
+ /** DEPRECATED, for versioning only. */
+ CLOTH_SIMSETTINGS_FLAG_SCALING = (1 << 8),
+ /** Require internal springs to be created between points with opposite normals. */
+ CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL = (1 << 9),
+ /** Edit cache in edit-mode. */
+ /* CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12), */ /* UNUSED */
+ /** Don't allow spring compression. */
+ CLOTH_SIMSETTINGS_FLAG_RESIST_SPRING_COMPRESS = (1 << 13),
+ /** Pull ends of loose edges together. */
+ CLOTH_SIMSETTINGS_FLAG_SEW = (1 << 14),
+ /** Make simulation respect deformations in the base object. */
+ CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH = (1 << 15),
+} CLOTH_SIMSETTINGS_FLAGS;
+
+/* ClothSimSettings.bending_model. */
+typedef enum {
+ CLOTH_BENDING_LINEAR = 0,
+ CLOTH_BENDING_ANGULAR = 1,
+} CLOTH_BENDING_MODEL;
+
typedef struct ClothCollSettings {
/** E.g. pointer to temp memory for collisions. */
struct LinkNode *collision_list;
@@ -209,3 +244,9 @@ typedef struct ClothCollSettings {
/** Impulse clamp for self collisions. */
float self_clamp;
} ClothCollSettings;
+
+/* COLLISION FLAGS */
+typedef enum {
+ CLOTH_COLLSETTINGS_FLAG_ENABLED = (1 << 1), /* enables cloth - object collisions */
+ CLOTH_COLLSETTINGS_FLAG_SELF = (1 << 2), /* enables selfcollisions */
+} CLOTH_COLLISIONSETTINGS_FLAGS;
diff --git a/source/blender/makesdna/DNA_modifier_defaults.h b/source/blender/makesdna/DNA_modifier_defaults.h
index 400e077e892..5f46d4f5cef 100644
--- a/source/blender/makesdna/DNA_modifier_defaults.h
+++ b/source/blender/makesdna/DNA_modifier_defaults.h
@@ -101,7 +101,102 @@
.type = MOD_CAST_TYPE_SPHERE, \
}
-/* Cloth modifier skipped for now. */
+#define _DNA_DEFAULT_ClothSimSettings \
+ { \
+ .cache = NULL, \
+ .mingoal = 0.0f, \
+ .Cvi = 1.0f, \
+ .gravity = {0.0f, 0.0f, -9.81f}, \
+ .dt = 0.0f, \
+ .mass = 0.3f, \
+ .shear = 5.0f, \
+ .bending = 0.5f, \
+ .max_bend = 0.5f, \
+ .max_shear = 5.0f, \
+ .max_sewing = 0.0f, \
+ .avg_spring_len = 0.0f, \
+ .timescale = 1.0f, \
+ .time_scale = 1.0f, \
+ .maxgoal = 1.0f, \
+ .eff_force_scale = 1000.0f, \
+ .eff_wind_scale = 250.0f, \
+ .sim_time_old = 0.0f, \
+ .defgoal = 0.0f, \
+ .goalspring = 1.0f, \
+ .goalfrict = 0.0f, \
+ .velocity_smooth = 0.0f, \
+ .density_target = 0.0f, \
+ .density_strength = 0.0f, \
+ .collider_friction = 0.0f, \
+ .shrink_min = 0.0f, \
+ .shrink_max = 0.0f, \
+ .uniform_pressure_force = 0.0f, \
+ .target_volume = 0.0f, \
+ .pressure_factor = 1.0f, \
+ .fluid_density = 0.0f, \
+ .vgroup_pressure = 0, \
+ .bending_damping = 0.5f, \
+ .voxel_cell_size = 0.1f, \
+ .stepsPerFrame = 5, \
+ .flags = CLOTH_SIMSETTINGS_FLAG_INTERNAL_SPRINGS_NORMAL, \
+ .maxspringlen = 10, \
+ .solver_type = 0, \
+ .vgroup_bend = 0, \
+ .vgroup_mass = 0, \
+ .vgroup_struct = 0, \
+ .vgroup_shrink = 0, \
+ .shapekey_rest = 0, \
+ .presets = 2, \
+ .reset = 0, \
+ .effector_weights = NULL, \
+ .bending_model = CLOTH_BENDING_ANGULAR, \
+ .vgroup_shear = 0, \
+ .tension = 15.0f , \
+ .compression = 15.0f, \
+ .max_tension = 15.0f, \
+ .max_compression = 15.0f, \
+ .tension_damp = 5.0f, \
+ .compression_damp = 5.0f, \
+ .shear_damp = 5.0f, \
+ .internal_spring_max_length = 0.0f, \
+ .internal_spring_max_diversion = M_PI / 4.0f, \
+ .vgroup_intern = 0, \
+ .internal_tension = 15.0f, \
+ .internal_compression = 15.0f, \
+ .max_internal_tension = 15.0f, \
+ .max_internal_compression = 15.0f, \
+ }
+
+#define _DNA_DEFAULT_ClothCollSettings \
+ { \
+ .collision_list = NULL, \
+ .epsilon = 0.015f, \
+ .self_friction = 5.0f, \
+ .friction = 5.0f, \
+ .damping = 0.0f, \
+ .selfepsilon = 0.015f, \
+ .flags = CLOTH_COLLSETTINGS_FLAG_ENABLED, \
+ .loop_count = 2, \
+ .group = NULL, \
+ .vgroup_selfcol = 0, \
+ .clamp = 0.0f, \
+ .self_clamp = 0.0f, \
+ }
+
+#define _DNA_DEFAULT_ClothModifierData \
+ { \
+ .clothObject = NULL, \
+ .sim_parms = NULL, \
+ .coll_parms = NULL, \
+ .point_cache = NULL, \
+ .ptcaches = {NULL, NULL}, \
+ .hairdata = NULL, \
+ .hair_grid_min = {0.0f, 0.0f, 0.0f}, \
+ .hair_grid_max = {0.0f, 0.0f, 0.0f}, \
+ .hair_grid_res = {0, 0, 0}, \
+ .hair_grid_cellsize = 0.0f, \
+ .solver_result = NULL, \
+ }
#define _DNA_DEFAULT_CollisionModifierData \
{ \
diff --git a/source/blender/makesdna/intern/dna_defaults.c b/source/blender/makesdna/intern/dna_defaults.c
index f2498325f3d..6fff2d33ac8 100644
--- a/source/blender/makesdna/intern/dna_defaults.c
+++ b/source/blender/makesdna/intern/dna_defaults.c
@@ -86,6 +86,7 @@
#include "DNA_brush_types.h"
#include "DNA_cachefile_types.h"
#include "DNA_camera_types.h"
+#include "DNA_cloth_types.h"
#include "DNA_curve_types.h"
#include "DNA_hair_types.h"
#include "DNA_image_types.h"
@@ -208,7 +209,9 @@ SDNA_DEFAULT_DECL_STRUCT(BevelModifierData);
SDNA_DEFAULT_DECL_STRUCT(BooleanModifierData);
SDNA_DEFAULT_DECL_STRUCT(BuildModifierData);
SDNA_DEFAULT_DECL_STRUCT(CastModifierData);
-/* Cloth modifier skipped for now. */
+SDNA_DEFAULT_DECL_STRUCT(ClothSimSettings);
+SDNA_DEFAULT_DECL_STRUCT(ClothCollSettings);
+SDNA_DEFAULT_DECL_STRUCT(ClothModifierData);
SDNA_DEFAULT_DECL_STRUCT(CollisionModifierData);
SDNA_DEFAULT_DECL_STRUCT(CorrectiveSmoothModifierData);
SDNA_DEFAULT_DECL_STRUCT(CurveModifierData);
@@ -389,7 +392,9 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = {
SDNA_DEFAULT_DECL(BooleanModifierData),
SDNA_DEFAULT_DECL(BuildModifierData),
SDNA_DEFAULT_DECL(CastModifierData),
- /* Cloth modifier skipped for now. */
+ SDNA_DEFAULT_DECL(ClothSimSettings),
+ SDNA_DEFAULT_DECL(ClothCollSettings),
+ SDNA_DEFAULT_DECL(ClothModifierData),
SDNA_DEFAULT_DECL(CollisionModifierData),
SDNA_DEFAULT_DECL(CorrectiveSmoothModifierData),
SDNA_DEFAULT_DECL(CurveModifierData),
diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c
index e99bd531c65..27318494428 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -711,7 +711,6 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
prop = RNA_def_property(srna, "voxel_cell_size", PROP_FLOAT, PROP_UNSIGNED);
RNA_def_property_float_sdna(prop, NULL, "voxel_cell_size");
RNA_def_property_range(prop, 0.0001f, 10000.0f);
- RNA_def_property_float_default(prop, 0.1f);
RNA_def_property_ui_text(
prop, "Voxel Grid Cell Size", "Size of the voxel grid cells for interaction effects");
RNA_def_property_update(prop, 0, "rna_cloth_update");
@@ -1005,7 +1004,6 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
prop = RNA_def_property(srna, "pressure_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "pressure_factor");
RNA_def_property_range(prop, 0.0f, 10000.0f);
- RNA_def_property_float_default(prop, 1.0f);
RNA_def_property_ui_text(prop,
"Pressure Scale",
"Ambient pressure (kPa) that balances out between the inside and "
diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c
index defba78c66c..2968bcda9b7 100644
--- a/source/blender/modifiers/intern/MOD_cloth.c
+++ b/source/blender/modifiers/intern/MOD_cloth.c
@@ -30,6 +30,7 @@
#include "BLT_translation.h"
#include "DNA_cloth_types.h"
+#include "DNA_defaults.h"
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
@@ -65,8 +66,12 @@ static void initData(ModifierData *md)
{
ClothModifierData *clmd = (ClothModifierData *)md;
- clmd->sim_parms = MEM_callocN(sizeof(ClothSimSettings), "cloth sim parms");
- clmd->coll_parms = MEM_callocN(sizeof(ClothCollSettings), "cloth coll parms");
+ BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(clmd, modifier));
+
+ MEMCPY_STRUCT_AFTER(clmd, DNA_struct_default_get(ClothModifierData), modifier);
+ clmd->sim_parms = DNA_struct_default_alloc(ClothSimSettings);
+ clmd->coll_parms = DNA_struct_default_alloc(ClothCollSettings);
+
clmd->point_cache = BKE_ptcache_add(&clmd->ptcaches);
/* check for alloc failing */
@@ -74,7 +79,13 @@ static void initData(ModifierData *md)
return;
}
- cloth_init(clmd);
+ if (!clmd->sim_parms->effector_weights) {
+ clmd->sim_parms->effector_weights = BKE_effector_add_weights(NULL);
+ }
+
+ if (clmd->point_cache) {
+ clmd->point_cache->step = 1;
+ }
}
static void deformVerts(ModifierData *md,