[Bf-blender-cvs] [87825084d57] cloth-improvements: Implement cloth trouble indication map
Luca Rood
noreply at git.blender.org
Fri Mar 31 11:17:07 CEST 2017
Commit: 87825084d57ec4a8ae246d8edb005a230e1a59e5
Author: Luca Rood
Date: Thu Mar 30 19:51:53 2017 +0200
Branches: cloth-improvements
https://developer.blender.org/rB87825084d57ec4a8ae246d8edb005a230e1a59e5
Implement cloth trouble indication map
This allows one to set a vertex group, to which "trouble" data is
written. This allows one to see where issues occured for instance in the
event of a cloth explosion.
===================================================================
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/BPH_mass_spring.h
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 a141e7e643e..3888b2e58aa 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -149,6 +149,9 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, Panel):
layout.separator()
layout.prop(cloth, "use_initial_velocity")
+ layout.separator()
+ layout.prop_search(cloth, "vertex_group_trouble", ob, "vertex_groups")
+
# Disabled for now
"""
if cloth.vertex_group_mass:
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 0668f54eb41..e9f629847fa 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -98,6 +98,7 @@ typedef struct Cloth {
struct Implicit_Data *implicit; /* our implicit solver connects to this pointer */
int last_frame;
float adapt_fact; /* Stability dt compensation factor */
+ float max_col_trouble;
} Cloth;
/**
@@ -126,6 +127,7 @@ typedef struct ClothVertex {
float planarity;
int spring_count; /* how many springs attached? */
float shrink_factor; /* how much to shrink this cloth */
+ float col_trouble;
}
ClothVertex;
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index ef89a3c86e5..e98f873fd60 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -349,7 +349,7 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
// TIMEIT_START(cloth_step)
/* call the solver. */
- ret = BPH_cloth_solve(ob, framenr, clmd, effectors);
+ ret = BPH_cloth_solve(ob, framenr, clmd, effectors, result);
// TIMEIT_END(cloth_step)
@@ -833,6 +833,12 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
// set initial values
for ( i = 0; i < dm->getNumVerts(dm); i++, verts++ ) {
+ if (clmd->sim_parms->vgroup_trouble > 0) {
+ MDeformVert *dvert = (MDeformVert *)dm->getVertData(dm, i, CD_MDEFORMVERT);
+ MDeformWeight *weight = defvert_verify_index(dvert, (clmd->sim_parms->vgroup_trouble - 1));
+ weight->weight = 0.0f;
+ }
+
if (first) {
copy_v3_v3(verts->x, mvert[i].co);
@@ -871,6 +877,8 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
verts->impulse_count = 0;
copy_v3_v3 ( verts->impulse, tnull );
+
+ verts->col_trouble = 0.0f;
}
// apply / set vertex groups
diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h
index d814763ac17..730a4323132 100644
--- a/source/blender/makesdna/DNA_cloth_types.h
+++ b/source/blender/makesdna/DNA_cloth_types.h
@@ -106,11 +106,12 @@ typedef struct ClothSimSettings {
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 vgroup_trouble; /* cloth trouble is written to this group */
short shapekey_rest; /* vertex group for scaling structural stiffness */
short presets; /* used for presets on GUI */
short reset;
- char pad0[4];
+ char pad0[2];
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 85995c2d406..1f049086ac3 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -338,6 +338,24 @@ static void rna_ClothSettings_planar_vgroup_set(PointerRNA *ptr, const char *val
rna_object_vgroup_name_index_set(ptr, value, &sim->vgroup_planar);
}
+static void rna_ClothSettings_trouble_vgroup_get(PointerRNA *ptr, char *value)
+{
+ ClothSimSettings *sim = (ClothSimSettings *)ptr->data;
+ rna_object_vgroup_name_index_get(ptr, value, sim->vgroup_trouble);
+}
+
+static int rna_ClothSettings_trouble_vgroup_length(PointerRNA *ptr)
+{
+ ClothSimSettings *sim = (ClothSimSettings *)ptr->data;
+ return rna_object_vgroup_name_index_length(ptr, sim->vgroup_trouble);
+}
+
+static void rna_ClothSettings_trouble_vgroup_set(PointerRNA *ptr, const char *value)
+{
+ ClothSimSettings *sim = (ClothSimSettings *)ptr->data;
+ rna_object_vgroup_name_index_set(ptr, value, &sim->vgroup_trouble);
+}
+
static void rna_CollSettings_selfcol_vgroup_get(PointerRNA *ptr, char *value)
{
ClothCollSettings *coll = (ClothCollSettings *)ptr->data;
@@ -870,6 +888,12 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
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, "vertex_group_trouble", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_ClothSettings_trouble_vgroup_get", "rna_ClothSettings_trouble_vgroup_length",
+ "rna_ClothSettings_trouble_vgroup_set");
+ RNA_def_property_ui_text(prop, "Trouble Vertex Group", "Vertex group to which troublesome things are written");
+ 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/BPH_mass_spring.h b/source/blender/physics/BPH_mass_spring.h
index c650d83c927..d9dda8ede0b 100644
--- a/source/blender/physics/BPH_mass_spring.h
+++ b/source/blender/physics/BPH_mass_spring.h
@@ -55,7 +55,7 @@ int BPH_mass_spring_solver_numvert(struct Implicit_Data *id);
int BPH_cloth_solver_init(struct Object *ob, struct ClothModifierData *clmd);
void BPH_cloth_solver_free(struct ClothModifierData *clmd);
-int BPH_cloth_solve(struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors);
+int BPH_cloth_solve(struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors, struct DerivedMesh *dm);
void BKE_cloth_solver_set_positions(struct ClothModifierData *clmd);
bool BPH_cloth_solver_get_texture_data(struct Object *ob, struct ClothModifierData *clmd, struct VoxelData *vd);
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 704570b5a9a..732d6264239 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -45,6 +45,8 @@ extern "C" {
#include "BKE_cloth.h"
#include "BKE_collision.h"
+#include "BKE_deform.h"
+#include "BKE_DerivedMesh.h"
#include "BKE_effect.h"
}
@@ -926,7 +928,7 @@ static void cloth_calc_volume_force(ClothModifierData *clmd)
}
#endif
-static float cloth_solve_collisions(Object *ob, ClothModifierData *clmd, float step, float dt)
+static float cloth_solve_collisions(Object *ob, ClothModifierData *clmd, float step, float dt, float *impulses)
{
Cloth *cloth = clmd->clothObject;
Implicit_Data *id = cloth->implicit;
@@ -964,6 +966,8 @@ static float cloth_solve_collisions(Object *ob, ClothModifierData *clmd, float s
continue;
impulse = len_v3(verts[i].dcvel);
+ impulses[i] = impulse;
+
if (impulse > max_impulse) {
max_impulse = impulse;
}
@@ -1022,7 +1026,7 @@ static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *r
sres->status |= result->status;
}
-int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors)
+int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors, DerivedMesh *dm)
{
/* Hair currently is a cloth sim in disguise ...
* Collision detection and volumetrics work differently then.
@@ -1044,6 +1048,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
float tmp_vec[3];
float adapt_fact;
bool init_vel;
+ float *impulses = (float *)MEM_mallocN(sizeof(*impulses) * mvert_num, "impulse_magnitude_array");
BKE_sim_debug_data_clear_category("collision");
@@ -1122,7 +1127,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
// calculate collision impulses
if (!is_hair) {
- max_impulse = cloth_solve_collisions(ob, clmd, step, dt);
+ max_impulse = cloth_solve_collisions(ob, clmd, step, dt, impulses);
}
// calculate forces
@@ -1139,6 +1144,18 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
BPH_mass_spring_solve_positions(id, dt);
for (i = 0; i < mvert_num; i++) {
+ if (clmd->sim_parms->vgroup_trouble > 0) {
+ cloth->max_col_trouble = max_ff(cloth->max_col_trouble, max_impulse);
+
+ MDeformVert *dvert = (MDeformVert *)dm->getVertData(dm, i, CD_MDEFORMVERT);
+ MDeformWeight *weight = defvert_verify_index(dvert, (clmd->sim_parms->vgroup_trouble - 1));
+ if (cloth->max_col_trouble > 0.0f) {
+ verts[i].col_trouble = max_ff(verts[i].col_trouble, impulses[i]);
+
+ weight->weight = verts[i].col_trouble / cloth->max_col_trouble;
+ }
+ }
+
BPH_mass_spring_get_new_position(id, i, tmp_vec);
vel = len_v3v3(tmp_vec, verts[i].txold);
max_vel = max_ff(max_vel, vel);
@@ -1245,7 +1262,9 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
step += dt;
}
-
+
+ MEM_freeN(impulses);
+
/* copy results back to cloth data */
for (i = 0; i < mvert_num; i++) {
BPH_mass_spring_get_motion_state(id, i, verts[i].x, verts[i].v);
More information about the Bf-blender-cvs
mailing list