[Bf-blender-cvs] [7fa9ab01d6e] cloth-improvements: Implement animated cloth velocity initialization
Luca Rood
noreply at git.blender.org
Mon Mar 13 05:34:16 CET 2017
Commit: 7fa9ab01d6e9deb434777d1635016b73d9835acc
Author: Luca Rood
Date: Mon Mar 13 01:31:10 2017 -0300
Branches: cloth-improvements
https://developer.blender.org/rB7fa9ab01d6e9deb434777d1635016b73d9835acc
Implement animated cloth velocity initialization
This allows the initial cloth velocity to be set by the vertex
velocities in the underlying animation.
===================================================================
M release/scripts/startup/bl_ui/properties_physics_cloth.py
M source/blender/blenkernel/BKE_cloth.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 0fa77b4de52..8a345ca99c0 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -146,6 +146,9 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, Panel):
row.prop(cloth, "bending_plasticity", text="")
row.prop(cloth, "bending_yield_factor", text="")
+ layout.separator()
+ layout.prop(cloth, "use_initial_velocity")
+
# 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 80860932b04..f86fd732947 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -171,6 +171,7 @@ typedef enum {
CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_SUBFRAMES_VEL = (1 << 0), /* use velocity based adaptive subframes*/
CLOTH_SIMSETTINGS_FLAG_ADAPTIVE_SUBFRAMES_IMP = (1 << 1), /* use velocity based adaptive subframes*/
CLOTH_SIMSETTINGS_FLAG_COLLOBJ = ( 1 << 2 ),// object is only collision object, no cloth simulation is done
+ CLOTH_SIMSETTINGS_FLAG_INIT_VEL = ( 1 << 3 ), /* initialize cloth velocity from animation */
CLOTH_SIMSETTINGS_FLAG_TEARING = ( 1 << 4 ),// true if tearing is enabled
CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12), /* edit cache in editmode */
CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS = (1 << 13), /* don't allow spring compression */
diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c
index c0c20726cdd..717dc88c2f6 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -853,6 +853,12 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Basemesh Valid", "True if the set basemesh is valid");
+ prop = RNA_def_property(srna, "use_initial_velocity", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_SIMSETTINGS_FLAG_INIT_VEL);
+ RNA_def_property_ui_text(prop, "Initialize Velocity", "Initialize velocity from animation");
+ RNA_def_property_update(prop, 0, "rna_cloth_update");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+
/* unused */
/* unused still */
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 6e64048708c..aa74e1b6979 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -1045,17 +1045,20 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
float max_impulse = 0.0f;
float tmp_vec[3];
float adapt_fact;
+ bool init_vel;
BKE_sim_debug_data_clear_category("collision");
if (!clmd->solver_result)
clmd->solver_result = (ClothSolverResult *)MEM_callocN(sizeof(ClothSolverResult), "cloth solver result");
cloth_clear_result(clmd);
-
- if (clmd->sim_parms->vgroup_mass>0) { /* do goal stuff */
+
+ init_vel = ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_INIT_VEL) && (frame == (clmd->point_cache->startframe + 1)));
+
+ if ((clmd->sim_parms->vgroup_mass > 0) || init_vel) { /* do goal and velocity stuff */
for (i = 0; i < mvert_num; i++) {
// update velocities with constrained velocities from pinned verts
- if (verts[i].flags & CLOTH_VERT_FLAG_PINNED) {
+ if ((verts[i].flags & CLOTH_VERT_FLAG_PINNED) || init_vel) {
float v[3];
sub_v3_v3v3(v, verts[i].xconst, verts[i].xold);
// mul_v3_fl(v, clmd->sim_parms->stepsPerFrame);
More information about the Bf-blender-cvs
mailing list