[Bf-blender-cvs] [da4bf06] hair_system: Enabled pinning constraints for hair roots.
Lukas Tönne
noreply at git.blender.org
Sun Oct 5 14:57:05 CEST 2014
Commit: da4bf06ea1390f7e18b10f1502cfdcfc83503d3b
Author: Lukas Tönne
Date: Sat Oct 4 14:28:25 2014 +0200
Branches: hair_system
https://developer.blender.org/rBda4bf06ea1390f7e18b10f1502cfdcfc83503d3b
Enabled pinning constraints for hair roots.
===================================================================
M source/blender/blenkernel/intern/object.c
M source/blender/physics/BPH_mass_spring.h
M source/blender/physics/intern/BPH_mass_spring.cpp
===================================================================
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 8c1f024..8a7cafb 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -3196,7 +3196,7 @@ void BKE_object_sim_pre_step(Scene *scene, Object *ob, float ctime)
BPH_hair_solver_set_externals(hmd->solver_data, scene, ob, dm, hsys->params.effector_weights);
- BPH_hair_solver_set_positions(hmd->solver_data, scene, ob, hmd->hairsys);
+ BPH_hair_solver_set_positions(hmd->solver_data, ob, hmd->hairsys);
if (!(hmd->debug_flag & MOD_HAIR_DEBUG_SHOW)) {
if (hmd->debug_data) {
@@ -3222,7 +3222,7 @@ void BKE_object_sim_tick(Scene *UNUSED(scene), Object *ob, float ctime, float ti
HairModifierData *hmd = (HairModifierData*) md;
HairSystem *hsys = hmd->hairsys;
- BPH_hair_solve(hmd->solver_data, &hsys->params, ctime, timestep, hmd->debug_data);
+ BPH_hair_solve(hmd->solver_data, ob, hsys, ctime, timestep, hmd->debug_data);
}
}
}
diff --git a/source/blender/physics/BPH_mass_spring.h b/source/blender/physics/BPH_mass_spring.h
index c5bf0c2..8db6433 100644
--- a/source/blender/physics/BPH_mass_spring.h
+++ b/source/blender/physics/BPH_mass_spring.h
@@ -64,8 +64,8 @@ void BPH_hair_solver_free(struct HairSolverData *data);
void BPH_hair_solver_set_externals(struct HairSolverData *data, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, struct EffectorWeights *effector_weights);
void BPH_hair_solver_clear_externals(struct HairSolverData *data);
-void BPH_hair_solver_set_positions(struct HairSolverData *data, struct Scene *scene, struct Object *ob, struct HairSystem *hsys);
-void BPH_hair_solve(struct HairSolverData *data, struct HairParams *params, float time, float timestep, struct SimDebugData *debug_data);
+void BPH_hair_solver_set_positions(struct HairSolverData *data, struct Object *ob, struct HairSystem *hsys);
+void BPH_hair_solve(struct HairSolverData *data, struct Object *ob, struct HairSystem *hsys, float time, float timestep, struct SimDebugData *debug_data);
void BPH_hair_solver_apply_positions(struct HairSolverData *data, struct Scene *scene, struct Object *ob, struct HairSystem *hsys);
bool implicit_hair_volume_get_texture_data(struct Object *UNUSED(ob), struct ClothModifierData *clmd, struct ListBase *UNUSED(effectors), struct VoxelData *vd);
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 645878a..36dfa39 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -820,7 +820,7 @@ void BPH_hair_solver_clear_externals(HairSolverData *data)
pdEndEffectors(&data->effectors);
}
-void BPH_hair_solver_set_positions(HairSolverData *data, Scene *scene, Object *ob, HairSystem *hsys)
+void BPH_hair_solver_set_positions(HairSolverData *data, Object *ob, HairSystem *hsys)
{
float obmat[4][4];
copy_m4_m4(obmat, ob->obmat);
@@ -917,8 +917,72 @@ static void hair_calc_force(HairSolverData *data, HairParams *params, float time
#endif
}
-void BPH_hair_solve(struct HairSolverData *data, HairParams *params, float time, float timestep, SimDebugData *debug_data)
+/* Init constraint matrix
+ * This is part of the modified CG method suggested by Baraff/Witkin in
+ * "Large Steps in Cloth Simulation" (Siggraph 1998)
+ */
+static void hair_setup_constraints(HairSolverData *data, Object *ob, HairSystem *hsys, ColliderContacts *contacts, int totcolliders, float dt)
+{
+ const float ZERO[3] = {0.0f, 0.0f, 0.0f};
+
+ int ktot = 0;
+ HairCurve *curve = hsys->curves;
+ for (int i = 0; i < hsys->totcurves; ++i, ++curve) {
+ if (curve->totpoints == 0)
+ continue;
+
+ /* hair root is always pinned in root space */
+ BPH_mass_spring_add_constraint_ndof0(data->id, ktot, ZERO);
+
+ ktot += curve->totpoints;
+ }
+
+#if 0
+ for (i = 0; i < totcolliders; ++i) {
+ ColliderContacts *ct = &contacts[i];
+ for (j = 0; j < ct->totcollisions; ++j) {
+ CollPair *collpair = &ct->collisions[j];
+// float restitution = (1.0f - clmd->coll_parms->damping) * (1.0f - ct->ob->pd->pdef_sbdamp);
+ float restitution = 0.0f;
+ int v = collpair->face1;
+ float impulse[3];
+
+ /* pinned verts handled separately */
+ if (verts[v].flags & CLOTH_VERT_FLAG_PINNED)
+ continue;
+
+ /* XXX cheap way of avoiding instability from multiple collisions in the same step
+ * this should eventually be supported ...
+ */
+ if (verts[v].impulse_count > 0)
+ continue;
+
+ /* calculate collision response */
+ if (!collision_response(clmd, ct->collmd, collpair, dt, restitution, impulse))
+ continue;
+
+ BPH_mass_spring_add_constraint_ndof2(data, v, collpair->normal, impulse);
+ ++verts[v].impulse_count;
+
+ BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pa, 0, 1, 0, "collision", hash_collpair(936, collpair));
+// BKE_sim_debug_data_add_dot(clmd->debug_data, collpair->pb, 1, 0, 0, "collision", hash_collpair(937, collpair));
+// BKE_sim_debug_data_add_line(clmd->debug_data, collpair->pa, collpair->pb, 0.7, 0.7, 0.7, "collision", hash_collpair(938, collpair));
+
+ { /* DEBUG */
+ float nor[3];
+ mul_v3_v3fl(nor, collpair->normal, -collpair->distance);
+ BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pa, nor, 1, 1, 0, "collision", hash_collpair(939, collpair));
+// BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pb, impulse, 1, 1, 0, "collision", hash_collpair(940, collpair));
+// BKE_sim_debug_data_add_vector(clmd->debug_data, collpair->pb, collpair->normal, 1, 1, 0, "collision", hash_collpair(941, collpair));
+ }
+ }
+ }
+#endif
+}
+
+void BPH_hair_solve(HairSolverData *data, Object *ob, HairSystem *hsys, float time, float timestep, SimDebugData *debug_data)
{
+ HairParams *params = &hsys->params;
float dt = timestep / (float)params->substeps;
int s;
ColliderContacts *contacts = NULL;
@@ -960,10 +1024,10 @@ void BPH_hair_solve(struct HairSolverData *data, HairParams *params, float time,
cloth_find_point_contacts(ob, clmd, 0.0f, tf, &contacts, &totcolliders);
}
}
+#endif
/* setup vertex constraints for pinned vertices and contacts */
- cloth_setup_constraints(clmd, contacts, totcolliders, dt);
-#endif
+ hair_setup_constraints(data, ob, hsys, contacts, totcolliders, dt);
// calculate forces
hair_calc_force(data, params, time, debug_data);
More information about the Bf-blender-cvs
mailing list