[Bf-blender-cvs] [5ad6bdb021] cloth-improvements: Implement rest planarity factor scaling
Luca Rood
noreply at git.blender.org
Wed Mar 15 09:38:02 CET 2017
Commit: 5ad6bdb0216235934f32fdbbf084187c24bb9fc6
Author: Luca Rood
Date: Wed Mar 15 05:36:44 2017 -0300
Branches: cloth-improvements
https://developer.blender.org/rB5ad6bdb0216235934f32fdbbf084187c24bb9fc6
Implement rest planarity factor scaling
===================================================================
M release/scripts/startup/bl_ui/properties_physics_cloth.py
M source/blender/blenkernel/BKE_cloth.h
M source/blender/blenkernel/intern/cloth.c
M source/blender/makesdna/DNA_cloth_types.h
M source/blender/makesrna/intern/rna_cloth.c
M source/blender/physics/intern/BPH_mass_spring.cpp
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py b/release/scripts/startup/bl_ui/properties_physics_cloth.py
index 46e39c0397..8661aa41be 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -335,6 +335,14 @@ class PHYSICS_PT_cloth_scaling(PhysicButtonsPanel, Panel):
sub.active = cloth.vertex_group_shrink != ""
sub.prop(cloth, "shrinking_max", text="Max")
+ split = layout.split(percentage=0.25, align=True)
+ split.label("Flattening:")
+ split.prop_search(cloth, "vertex_group_planarity", ob, "vertex_groups", text="")
+
+ sub = split.row(align=True)
+ sub.active = cloth.vertex_group_planarity != ""
+ sub.prop(cloth, "planarity_factor_max", text="Max")
+
class PHYSICS_PT_cloth_adaptive_subframes(PhysicButtonsPanel, Panel):
bl_label = "Cloth Adaptive Subframes"
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index a25b1ad5e6..de738d13e9 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -122,6 +122,7 @@ typedef struct ClothVertex {
float struct_stiff;
float bend_stiff;
float shear_stiff;
+ float planarity;
int spring_count; /* how many springs attached? */
float shrink_factor; /* how much to shrink this cloth */
}
@@ -146,6 +147,7 @@ typedef struct ClothSpring {
int flags; /* defined in BKE_cloth.h, e.g. deactivated due to tearing */
float lin_stiffness; /* linear stiffness factor from the vertex groups */
float ang_stiffness; /* angular stiffness factor from the vertex groups */
+ float planarity;
/* angular bending spring target and derivatives */
float target[3];
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 19a2007197..aafc672c15 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -654,6 +654,7 @@ int cloth_uses_vgroup(ClothModifierData *clmd)
(clmd->sim_parms->vgroup_bend>0) ||
(clmd->sim_parms->vgroup_shrink>0) ||
(clmd->sim_parms->vgroup_mass>0) ||
+ (clmd->sim_parms->vgroup_planar>0) ||
(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COMB_GOAL));
}
@@ -736,6 +737,10 @@ static void cloth_apply_vgroup(ClothModifierData *clmd, DerivedMesh *dm, Object
verts->bend_stiff = dvert->dw [j].weight;
}
+ if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_planar - 1)) {
+ verts->planarity = dvert->dw[j].weight;
+ }
+
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF ) {
if ( dvert->dw[j].def_nr == (clmd->coll_parms->vgroup_selfcol-1)) {
if (dvert->dw [j].weight > 0.0f) {
@@ -1213,6 +1218,7 @@ static void cloth_update_springs( ClothModifierData *clmd )
if (spring->type & CLOTH_SPRING_TYPE_BENDING) {
spring->ang_stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f;
+ spring->planarity = (cloth->verts[spring->kl].planarity + cloth->verts[spring->ij].planarity) / 2.0f;
}
if (spring->type & CLOTH_SPRING_TYPE_STRUCTURAL) {
diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h
index cd83d8d542..42a3f76cd5 100644
--- a/source/blender/makesdna/DNA_cloth_types.h
+++ b/source/blender/makesdna/DNA_cloth_types.h
@@ -87,13 +87,13 @@ typedef struct ClothSimSettings {
float bend_plasticity; /* Factor of how much the rest angle will change after reaching yield point (0-1) */
float bend_yield_fact; /* How much angle has to change as a factor of a full circle before plastic behavior kicks in (0-1) */
float rest_planar_fact; /* Factor of how planar rest angles should be, 0 means the original angle, and 1 means totally flat */
+ float max_planarity;
/* XXX various hair stuff
* should really be separate, this struct is a horrible mess already
*/
float bending_damping; /* damping of bending springs */
float voxel_cell_size; /* size of voxel grid cells for continuum dynamics */
- int pad;
int stepsPerFrame; /* Number of time steps per frame. */
int flags; /* flags, see CSIMSETT_FLAGS enum above. */
@@ -105,11 +105,12 @@ typedef struct ClothSimSettings {
short vgroup_struct; /* vertex group for scaling structural stiffness */
short vgroup_shear; /* vertex group for scaling structural stiffness */
short vgroup_shrink; /* vertex group for shrinking cloth */
+ short vgroup_planar; /* vertex group for shrinking cloth */
short shapekey_rest; /* vertex group for scaling structural stiffness */
short presets; /* used for presets on GUI */
short reset;
- char pad0[6];
+ char pad0[4];
struct EffectorWeights *effector_weights;
/* Adaptive subframe stuff */
diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c
index 66b317004a..125969ac19 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -186,6 +186,28 @@ static void rna_ClothSettings_max_shrink_set(struct PointerRNA *ptr, float value
settings->max_shrink = value;
}
+static void rna_ClothSettings_planarity_set(struct PointerRNA *ptr, float value)
+{
+ ClothSimSettings *settings = (ClothSimSettings *)ptr->data;
+
+ settings->rest_planar_fact = value;
+
+ /* check for max clipping */
+ if (value > settings->max_planarity)
+ settings->max_planarity = value;
+}
+
+static void rna_ClothSettings_max_planarity_set(struct PointerRNA *ptr, float value)
+{
+ ClothSimSettings *settings = (ClothSimSettings *)ptr->data;
+
+ /* check for clipping */
+ if (value < settings->rest_planar_fact)
+ value = settings->rest_planar_fact;
+
+ settings->max_planarity = value;
+}
+
static void rna_ClothSettings_subframes_set(struct PointerRNA *ptr, float value)
{
ClothSimSettings *settings = (ClothSimSettings *)ptr->data;
@@ -298,6 +320,23 @@ static void rna_ClothSettings_bend_vgroup_set(PointerRNA *ptr, const char *value
rna_object_vgroup_name_index_set(ptr, value, &sim->vgroup_bend);
}
+static void rna_ClothSettings_planar_vgroup_get(PointerRNA *ptr, char *value)
+{
+ ClothSimSettings *sim = (ClothSimSettings *)ptr->data;
+ rna_object_vgroup_name_index_get(ptr, value, sim->vgroup_planar);
+}
+
+static int rna_ClothSettings_planar_vgroup_length(PointerRNA *ptr)
+{
+ ClothSimSettings *sim = (ClothSimSettings *)ptr->data;
+ return rna_object_vgroup_name_index_length(ptr, sim->vgroup_planar);
+}
+
+static void rna_ClothSettings_planar_vgroup_set(PointerRNA *ptr, const char *value)
+{
+ ClothSimSettings *sim = (ClothSimSettings *)ptr->data;
+ rna_object_vgroup_name_index_set(ptr, value, &sim->vgroup_planar);
+}
static void rna_CollSettings_selfcol_vgroup_get(PointerRNA *ptr, char *value)
{
@@ -758,9 +797,17 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
prop = RNA_def_property(srna, "rest_planarity_factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "rest_planar_fact");
RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_float_funcs(prop, NULL, "rna_ClothSettings_planarity_set", NULL);
RNA_def_property_ui_text(prop, "Rest Planarity Factor", "How planar the rest shape should be, 0 is the original shape, and 1 is totally flat");
RNA_def_property_update(prop, 0, "rna_cloth_update");
+ prop = RNA_def_property(srna, "planarity_factor_max", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "max_planarity");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_float_funcs(prop, NULL, "rna_ClothSettings_max_planarity_set", NULL);
+ RNA_def_property_ui_text(prop, "Rest Planarity Maximum", "Maximum rest planarity factor value");
+ RNA_def_property_update(prop, 0, "rna_cloth_update");
+
prop = RNA_def_property(srna, "sewing_force_max", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "max_sewing");
RNA_def_property_range(prop, 0.0f, 10000.0f);
@@ -817,6 +864,12 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
"Vertex group for fine control over bending stiffness");
RNA_def_property_update(prop, 0, "rna_cloth_update");
+ prop = RNA_def_property(srna, "vertex_group_planarity", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_ClothSettings_planar_vgroup_get", "rna_ClothSettings_planar_vgroup_length",
+ "rna_ClothSettings_planar_vgroup_set");
+ RNA_def_property_ui_text(prop, "Planarity Scaling Vertex Group", "Vertex group for fine control over rest planarity");
+ RNA_def_property_update(prop, 0, "rna_cloth_update");
+
prop = RNA_def_property(srna, "effector_weights", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "EffectorWeights");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 23e4149276..72c93ec1a3 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -347,15 +347,17 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
if (s->type & CLOTH_SPRING_TYPE_BENDING) { /* calculate force of bending springs */
#ifdef CLOTH_FORCE_SPRING_BEND
- float k, scaling;
+ float k, scaling, planarity;
s->flags |= CLOTH_SPRING_FLAG_NEEDED;
scaling = parms->bending + s->ang_stiffness * fabsf(parms->max_bend - parms->bending);
k = scaling * s->restlen * s->lenfact * 0.1f; /* multiplying by 0.1, just to scale the forces to more reasonable values */
+ planarity = parms->rest_planar_fact + s->planarity * fabsf(parms->max_planarity - parms->rest_planar_fact);
+
BPH_mass_spring_force_spring_angular(data, s->ij, s->kl, s->pa, s->pb, s->la, s->lb,
- s->restang * (1.0f - parms->rest_planar_fact), &s->angoffset, k,
+ s->restang * (1.0f - planarity), &s->angoffset, k,
parms->bending_damping, bend_plast, parms->bend_yield_fact, !collision_pass);
#endif
}
More information about the Bf-blender-cvs
mailing list