[Bf-blender-cvs] [d6bee4bffd0] cloth-improvements: Implement weight keys for pinning
Luca Rood
noreply at git.blender.org
Tue Mar 14 06:52:51 CET 2017
Commit: d6bee4bffd037b31db8b17423a5fbf703527242c
Author: Luca Rood
Date: Wed Feb 15 01:03:30 2017 -0200
Branches: cloth-improvements
https://developer.blender.org/rBd6bee4bffd037b31db8b17423a5fbf703527242c
Implement weight keys for pinning
===================================================================
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/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 8a345ca99c0..46e39c03972 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -185,15 +185,23 @@ class PHYSICS_PT_cloth_shape(PhysicButtonsPanel, Panel):
layout.active = cloth_panel_enabled(md)
- split = layout.split(percentage=0.3, align=True)
+ col = layout.column()
+ split = col.split(percentage=0.3, align=True)
split.label("Pinning:")
- split.prop_search(cloth, "vertex_group_mass", ob, "vertex_groups", text="")
+ sub1 = split.row(align=True)
+ sub1.active = not cloth.use_combined_pin_cloth
- sub = split.row(align=True)
- sub.active = cloth.vertex_group_mass != ""
- sub.prop(cloth, "pin_stiffness", text="Stiffness")
+ sub1.prop_search(cloth, "vertex_group_mass", ob, "vertex_groups", text="")
+
+ sub2 = sub1.row(align=True)
+ sub2.active = cloth.vertex_group_mass != ""
+ sub2.prop(cloth, "pin_stiffness", text="Stiffness")
+
+ col.prop(cloth, "use_combined_pin_cloth")
+
+ layout.separator()
split = layout.split(percentage=0.3)
split.prop(cloth, "use_sewing_springs", text="Sewing:")
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 1651f317ec1..a25b1ad5e69 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -173,6 +173,7 @@ typedef enum {
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_COMB_GOAL = (1 << 5), // combined weights for goal
CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12), /* edit cache in editmode */
CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS = (1 << 13), /* don't allow spring compression */
CLOTH_SIMSETTINGS_FLAG_SEW = (1 << 14), /* pull ends of loose edges together */
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index fe6ea820e44..19a20071971 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -44,6 +44,7 @@
#include "BKE_cdderivedmesh.h"
#include "BKE_cloth.h"
#include "BKE_editmesh.h"
+#include "BKE_deform.h"
#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_modifier.h"
@@ -63,7 +64,7 @@ static void cloth_update_springs( ClothModifierData *clmd );
static void cloth_update_verts( Object *ob, ClothModifierData *clmd, DerivedMesh *dm );
static void cloth_update_spring_lengths( ClothModifierData *clmd, DerivedMesh *dm );
static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm );
-static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm );
+static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm, Object *ob );
typedef struct BendSpringRef {
int index, polys;
@@ -334,7 +335,7 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
cloth_update_verts ( ob, clmd, result );
/* Support for dynamic vertex groups, changing from frame to frame */
- cloth_apply_vgroup ( clmd, result );
+ cloth_apply_vgroup(clmd, result, ob);
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH) ||
(clmd->sim_parms->vgroup_shrink > 0) || (clmd->sim_parms->shrink > 0.0f))
@@ -652,7 +653,8 @@ int cloth_uses_vgroup(ClothModifierData *clmd)
(clmd->sim_parms->vgroup_struct>0)||
(clmd->sim_parms->vgroup_bend>0) ||
(clmd->sim_parms->vgroup_shrink>0) ||
- (clmd->sim_parms->vgroup_mass>0));
+ (clmd->sim_parms->vgroup_mass>0) ||
+ (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COMB_GOAL));
}
/**
@@ -660,7 +662,7 @@ int cloth_uses_vgroup(ClothModifierData *clmd)
*
**/
/* can be optimized to do all groups in one loop */
-static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
+static void cloth_apply_vgroup(ClothModifierData *clmd, DerivedMesh *dm, Object *ob)
{
int i = 0;
int j = 0;
@@ -695,9 +697,21 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
verts->flags &= ~CLOTH_VERT_FLAG_NOSELFCOLL;
dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT );
+
if ( dvert ) {
+ if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COMB_GOAL)
+ {
+ verts->goal = BKE_defvert_combined_weight(ob, dvert, DVERT_COMBINED_MODE_ADD);
+
+ verts->goal = pow4f(verts->goal);
+ if ( verts->goal >= SOFTGOALSNAP )
+ verts->flags |= CLOTH_VERT_FLAG_PINNED;
+ }
+
for ( j = 0; j < dvert->totweight; j++ ) {
- if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) {
+ if ((dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) &&
+ !(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COMB_GOAL))
+ {
verts->goal = dvert->dw [j].weight;
/* goalfac= 1.0f; */ /* UNUSED */
@@ -861,7 +875,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
// apply / set vertex groups
// has to be happen before springs are build!
- cloth_apply_vgroup (clmd, dm);
+ cloth_apply_vgroup(clmd, dm, ob);
if ( !cloth_build_springs ( clmd, dm ) ) {
cloth_free_modifier ( clmd );
diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c
index b6abce9baef..66b317004ab 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -568,6 +568,12 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
"(1.0 = no damping, 0.0 = fully dampened)");
RNA_def_property_update(prop, 0, "rna_cloth_update");
+ prop = RNA_def_property(srna, "use_combined_pin_cloth", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_SIMSETTINGS_FLAG_COMB_GOAL);
+ RNA_def_property_ui_text(prop, "Combined Weights", "Use combined interpolated weights for cloth pinning");
+ RNA_def_property_update(prop, 0, "rna_cloth_update");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+
prop = RNA_def_property(srna, "pin_stiffness", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "goalspring");
RNA_def_property_range(prop, 0.0f, 50.0);
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 35f9dcfe139..23e4149276e 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -1051,7 +1051,11 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
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 */
+ /* do goal and velocity stuff */
+ if ((clmd->sim_parms->vgroup_mass > 0) ||
+ (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COMB_GOAL) ||
+ init_vel)
+ {
for (i = 0; i < mvert_num; i++) {
// update velocities with constrained velocities from pinned verts
if ((verts[i].flags & CLOTH_VERT_FLAG_PINNED) || init_vel) {
@@ -1176,7 +1180,9 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
/* move pinned verts to correct position */
for (i = 0; i < mvert_num; i++) {
- if (clmd->sim_parms->vgroup_mass>0) {
+ if ((clmd->sim_parms->vgroup_mass > 0) ||
+ (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COMB_GOAL))
+ {
if (verts[i].flags & CLOTH_VERT_FLAG_PINNED) {
float x[3];
/* divide by time_scale to prevent pinned vertices' delta locations from being multiplied */
More information about the Bf-blender-cvs
mailing list