From 59f9a5e6ac6f5bff914204ef299cba27bb5016eb Mon Sep 17 00:00:00 2001 From: Robert Sheldon Date: Thu, 15 Jul 2021 15:58:34 +0200 Subject: Fix T88188: Allow keyframing vertex mass in cloth sim Update vertex weights between simulation steps if they have changed. This allows for animated vertex weights in the cloth sim. Reviewed By: Sebastian Parborg Differential Revision: http://developer.blender.org/D11640 --- source/blender/blenkernel/intern/cloth.c | 9 ++++++++- source/blender/makesrna/intern/rna_cloth.c | 1 - source/blender/simulation/SIM_mass_spring.h | 2 ++ source/blender/simulation/intern/SIM_mass_spring.cpp | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 8678a659c0a..0fa58a74f2b 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -262,17 +262,19 @@ static bool do_init_cloth(Object *ob, ClothModifierData *clmd, Mesh *result, int static int do_step_cloth( Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, Mesh *result, int framenr) { + /* simulate 1 frame forward */ ClothVertex *verts = NULL; Cloth *cloth; ListBase *effectors = NULL; MVert *mvert; unsigned int i = 0; int ret = 0; + bool vert_mass_changed = false; - /* simulate 1 frame forward */ cloth = clmd->clothObject; verts = cloth->verts; mvert = result->mvert; + vert_mass_changed = verts->mass != clmd->sim_parms->mass; /* force any pinned verts to their constrained location. */ for (i = 0; i < clmd->clothObject->mvert_num; i++, verts++) { @@ -283,6 +285,11 @@ static int do_step_cloth( /* Get the current position. */ copy_v3_v3(verts->xconst, mvert[i].co); mul_m4_v3(ob->obmat, verts->xconst); + + if (vert_mass_changed) { + verts->mass = clmd->sim_parms->mass; + SIM_mass_spring_set_implicit_vertex_mass(cloth->implicit, i, verts->mass); + } } effectors = BKE_effectors_create(depsgraph, ob, NULL, clmd->sim_parms->effector_weights, false); diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c index 9e57368f8f9..2bc00dd5af5 100644 --- a/source/blender/makesrna/intern/rna_cloth.c +++ b/source/blender/makesrna/intern/rna_cloth.c @@ -652,7 +652,6 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna) prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_UNIT_MASS); RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_ui_text(prop, "Vertex Mass", "The mass of each vertex on the cloth material"); - RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, 0, "rna_cloth_update"); prop = RNA_def_property(srna, "vertex_group_mass", PROP_STRING, PROP_NONE); diff --git a/source/blender/simulation/SIM_mass_spring.h b/source/blender/simulation/SIM_mass_spring.h index 43de8b155cf..b3299258209 100644 --- a/source/blender/simulation/SIM_mass_spring.h +++ b/source/blender/simulation/SIM_mass_spring.h @@ -45,6 +45,8 @@ void SIM_mass_spring_solver_free(struct Implicit_Data *id); int SIM_mass_spring_solver_numvert(struct Implicit_Data *id); int SIM_cloth_solver_init(struct Object *ob, struct ClothModifierData *clmd); +void SIM_mass_spring_set_implicit_vertex_mass(struct Implicit_Data *data, int index, float mass); + void SIM_cloth_solver_free(struct ClothModifierData *clmd); int SIM_cloth_solve(struct Depsgraph *depsgraph, struct Object *ob, diff --git a/source/blender/simulation/intern/SIM_mass_spring.cpp b/source/blender/simulation/intern/SIM_mass_spring.cpp index cf654ebff07..ca01120eecb 100644 --- a/source/blender/simulation/intern/SIM_mass_spring.cpp +++ b/source/blender/simulation/intern/SIM_mass_spring.cpp @@ -203,7 +203,7 @@ int SIM_cloth_solver_init(Object *UNUSED(ob), ClothModifierData *clmd) cloth->implicit = id = SIM_mass_spring_solver_create(cloth->mvert_num, nondiag); for (i = 0; i < cloth->mvert_num; i++) { - SIM_mass_spring_set_vertex_mass(id, i, verts[i].mass); + SIM_mass_spring_set_implicit_vertex_mass(id, i, verts[i].mass); } for (i = 0; i < cloth->mvert_num; i++) { @@ -213,6 +213,10 @@ int SIM_cloth_solver_init(Object *UNUSED(ob), ClothModifierData *clmd) return 1; } +void SIM_mass_spring_set_implicit_vertex_mass(Implicit_Data *data, int index, float mass){ + SIM_mass_spring_set_vertex_mass(data, index, mass); +} + void SIM_cloth_solver_free(ClothModifierData *clmd) { Cloth *cloth = clmd->clothObject; -- cgit v1.2.3