[Bf-blender-cvs] [e3b5229da2] cloth-improvements: Add collision response quality control
Luca Rood
noreply at git.blender.org
Sat Feb 4 07:00:08 CET 2017
Commit: e3b5229da2f5d2338546d276a60b8fdf0fd7de62
Author: Luca Rood
Date: Fri Feb 3 19:57:58 2017 -0200
Branches: cloth-improvements
https://developer.blender.org/rBe3b5229da2f5d2338546d276a60b8fdf0fd7de62
Add collision response quality control
===================================================================
M release/scripts/startup/bl_ui/properties_physics_cloth.py
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/collision.c
M source/blender/makesdna/DNA_cloth_types.h
M source/blender/makesrna/intern/rna_cloth.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py b/release/scripts/startup/bl_ui/properties_physics_cloth.py
index f91bfdc08a..f12cc2374d 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -233,7 +233,14 @@ class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel):
col = layout.column()
- col.prop(cloth, "use_collision", text="Object Collision:")
+ split = col.split()
+
+ sub = split.column()
+ sub.prop(cloth, "use_collision", text="Object Collision:")
+
+ sub = split.column()
+ sub.active = cloth.use_collision
+ sub.prop(cloth, "collision_response_quality")
sub = col.column()
sub.active = cloth.use_collision
@@ -251,10 +258,11 @@ class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel):
sub = split.column()
sub.active = cloth.use_self_collision
- sub.prop(cloth, "self_friction", text="Friction")
+ sub.prop(cloth, "selfcollision_response_quality")
sub = col.column()
sub.active = cloth.use_self_collision
+ sub.prop(cloth, "self_friction", text="Friction")
sub.prop(cloth, "self_distance_min", slider=True, text="Distance")
sub.prop_search(cloth, "vertex_group_self_collisions", ob, "vertex_groups", text="Vertex Group")
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 86087abf3f..bcb979e656 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -134,6 +134,8 @@ void cloth_init(ClothModifierData *clmd )
clmd->coll_parms->collision_list = NULL;
clmd->coll_parms->selfepsilon = 0.015;
clmd->coll_parms->vgroup_selfcol = 0;
+ clmd->coll_parms->objcol_resp_iter = 2;
+ clmd->coll_parms->selfcol_resp_iter = 3;
/* These defaults are copied from softbody.c's
* softbody_calc_forces() function.
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index d3b7aa4323..55e33ec84a 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -1138,6 +1138,8 @@ static int cloth_bvh_objcollisions_resolve (ClothModifierData * clmd, Object **c
int i=0, j = 0, /*numfaces = 0, */ mvert_num = 0;
ClothVertex *verts = NULL;
ImpulseCluster **vert_imp_clusters;
+ int iter = clmd->coll_parms->objcol_resp_iter;
+ float influence = 1.0f / iter;
int ret = 0;
int result = 0;
@@ -1148,7 +1150,7 @@ static int cloth_bvh_objcollisions_resolve (ClothModifierData * clmd, Object **c
// process all collisions (calculate impulses, TODO: also repulses if distance too short)
result = 1;
- for ( j = 0; j < 2; j++ ) { /* 5 is just a value that ensures convergence */
+ for ( j = 0; j < iter; j++ ) { /* 5 is just a value that ensures convergence */
result = 0;
for (i = 0; i < numcollobj; i++) {
@@ -1169,8 +1171,8 @@ static int cloth_bvh_objcollisions_resolve (ClothModifierData * clmd, Object **c
free_impulse_clusters(vert_imp_clusters[i]);
vert_imp_clusters[i] = NULL;
- madd_v3_v3v3fl(verts[i].tv, verts[i].tv, verts[i].impulse, 0.5f);
- madd_v3_v3v3fl(verts[i].dcvel, verts[i].dcvel, verts[i].impulse, 0.5f);
+ madd_v3_v3v3fl(verts[i].tv, verts[i].tv, verts[i].impulse, influence);
+ madd_v3_v3v3fl(verts[i].dcvel, verts[i].dcvel, verts[i].impulse, influence);
zero_v3(verts[i].impulse);
verts[i].impulse_count = 0;
@@ -1194,6 +1196,8 @@ static int cloth_bvh_selfcollisions_resolve (ClothModifierData * clmd, CollPair
int i=0, j = 0, /*numfaces = 0, */ mvert_num = 0;
ClothVertex *verts = NULL;
ImpulseCluster **vert_imp_clusters;
+ int iter = clmd->coll_parms->selfcol_resp_iter;
+ float influence = 1.0f / iter;
int ret = 0;
int result = 0;
@@ -1202,7 +1206,7 @@ static int cloth_bvh_selfcollisions_resolve (ClothModifierData * clmd, CollPair
vert_imp_clusters = MEM_callocN(sizeof(*vert_imp_clusters) * mvert_num, "vert_impulse_clusters");
- for ( j = 0; j < 2; j++ ) { /* 5 is just a value that ensures convergence */
+ for ( j = 0; j < iter; j++ ) { /* 5 is just a value that ensures convergence */
result = 0;
result += cloth_selfcollision_response_static (clmd, collisions, collisions_index, vert_imp_clusters);
@@ -1216,8 +1220,8 @@ static int cloth_bvh_selfcollisions_resolve (ClothModifierData * clmd, CollPair
free_impulse_clusters(vert_imp_clusters[i]);
vert_imp_clusters[i] = NULL;
- madd_v3_v3v3fl(verts[i].tv, verts[i].tv, verts[i].impulse, 0.5f);
- madd_v3_v3v3fl(verts[i].dcvel, verts[i].dcvel, verts[i].impulse, 0.5f);
+ madd_v3_v3v3fl(verts[i].tv, verts[i].tv, verts[i].impulse, influence);
+ madd_v3_v3v3fl(verts[i].dcvel, verts[i].dcvel, verts[i].impulse, influence);
zero_v3(verts[i].impulse);
verts[i].impulse_count = 0;
diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h
index 72fe79d7cb..1d2ac6e6de 100644
--- a/source/blender/makesdna/DNA_cloth_types.h
+++ b/source/blender/makesdna/DNA_cloth_types.h
@@ -134,7 +134,9 @@ typedef struct ClothCollSettings {
short pad[3];
struct Group *group; /* Only use colliders from this group of objects */
short vgroup_selfcol; /* vgroup to paint which vertices are used for self collisions */
- short pad2[3];
+ short objcol_resp_iter; /* Iterations for object collision response */
+ short selfcol_resp_iter; /* Iterations for self collision response */
+ short pad2;
} ClothCollSettings;
diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c
index 5dd26d9916..e7a5956aff 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -892,7 +892,15 @@ static void rna_def_cloth_collision_settings(BlenderRNA *brna)
RNA_def_property_range(prop, 1, SHRT_MAX);
RNA_def_property_ui_range(prop, 1, 20, 1, -1);
RNA_def_property_ui_text(prop, "Collision Quality",
- "How many collision iterations should be done. (higher is better quality but slower)");
+ "How many collision iterations should be done. (higher is smoother quality but slower)");
+ RNA_def_property_update(prop, 0, "rna_cloth_update");
+
+ prop = RNA_def_property(srna, "collision_response_quality", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "objcol_resp_iter");
+ RNA_def_property_range(prop, 1, SHRT_MAX);
+ RNA_def_property_ui_range(prop, 1, 20, 1, -1);
+ RNA_def_property_ui_text(prop, "Response Quality",
+ "How many object collision response iterations should be done. (higher is smoother but slower)");
RNA_def_property_update(prop, 0, "rna_cloth_update");
/* self collision */
@@ -924,6 +932,14 @@ static void rna_def_cloth_collision_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Selfcollision Vertex Group",
"Vertex group to define vertices which are not used during self collisions");
RNA_def_property_update(prop, 0, "rna_cloth_update");
+
+ prop = RNA_def_property(srna, "selfcollision_response_quality", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "selfcol_resp_iter");
+ RNA_def_property_range(prop, 1, SHRT_MAX);
+ RNA_def_property_ui_range(prop, 1, 20, 1, -1);
+ RNA_def_property_ui_text(prop, "Response Quality",
+ "How many self collision response iterations should be done. (higher is better quality but slower)");
+ RNA_def_property_update(prop, 0, "rna_cloth_update");
}
void RNA_def_cloth(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list