Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2014-09-16 22:44:25 +0400
committerLukas Tönne <lukas.toenne@gmail.com>2015-01-20 11:30:01 +0300
commit8876429edda44b542c8dc30ea6a9a7b9d88bc451 (patch)
treeb802dff5aa024aa424240440d89bca0b901c2799 /source/blender/physics/intern/BPH_mass_spring.cpp
parenta8cf092160d88df5f97514d8356b155a6820e22f (diff)
Added back the velocity smoothing implementation.
This is now also decoupled from the internal solver data. The grid is created as an opaque structure, filled with vertex or collider data (todo), and then forces can be calculated by interpolating the grid at random locations. These forces and derivatives are then fed into the solver.
Diffstat (limited to 'source/blender/physics/intern/BPH_mass_spring.cpp')
-rw-r--r--source/blender/physics/intern/BPH_mass_spring.cpp61
1 files changed, 59 insertions, 2 deletions
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 1c45e1ed1f8..568aea6abe3 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -386,6 +386,64 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
}
}
+static void hair_get_boundbox(ClothModifierData *clmd, float gmin[3], float gmax[3])
+{
+ Cloth *cloth = clmd->clothObject;
+ Implicit_Data *data = cloth->implicit;
+ unsigned int numverts = cloth->numverts;
+ int i;
+
+ INIT_MINMAX(gmin, gmax);
+ for (i = 0; i < numverts; i++) {
+ float x[3];
+ BPH_mass_spring_get_motion_state(data, i, x, NULL);
+ DO_MINMAX(x, gmin, gmax);
+ }
+}
+
+static void cloth_calc_volume_force(ClothModifierData *clmd)
+{
+ ClothSimSettings *parms = clmd->sim_parms;
+ Cloth *cloth = clmd->clothObject;
+ Implicit_Data *data = cloth->implicit;
+ int numverts = cloth->numverts;
+
+ /* 2.0f is an experimental value that seems to give good results */
+ float smoothfac = 2.0f * parms->velocity_smooth;
+ float collfac = 2.0f * parms->collider_friction;
+ float pressfac = parms->pressure;
+ float minpress = parms->pressure_threshold;
+ float gmin[3], gmax[3];
+ int i;
+
+ hair_get_boundbox(clmd, gmin, gmax);
+
+ /* gather velocities & density */
+ if (smoothfac > 0.0f || pressfac > 0.0f) {
+ HairVertexGrid *vertex_grid = BPH_hair_volume_create_vertex_grid(gmin, gmax);
+
+ for (i = 0; i < numverts; i++) {
+ float x[3], v[3];
+
+ BPH_mass_spring_get_motion_state(data, i, x, v);
+ BPH_hair_volume_add_vertex(vertex_grid, x, v);
+ }
+ BPH_hair_volume_normalize_vertex_grid(vertex_grid);
+
+ for (i = 0; i < numverts; i++) {
+ float x[3], v[3], f[3], dfdx[3][3], dfdv[3][3];
+
+ /* calculate volumetric forces */
+ BPH_mass_spring_get_motion_state(data, i, x, v);
+ BPH_hair_volume_vertex_grid_forces(vertex_grid, x, v, smoothfac, pressfac, minpress, f, dfdx, dfdv);
+ /* apply on hair data */
+ BPH_mass_spring_force_extern(data, i, f, dfdx, dfdv);
+ }
+
+ BPH_hair_volume_free_vertex_grid(vertex_grid);
+ }
+}
+
static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListBase *effectors, float time)
{
/* Collect forces and derivatives: F, dFdX, dFdV */
@@ -409,8 +467,7 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), ListB
BPH_mass_spring_force_gravity(data, gravity);
#endif
- // XXX TODO
-// hair_volume_forces(clmd, lF, lX, lV, numverts);
+ cloth_calc_volume_force(clmd);
#ifdef CLOTH_FORCE_DRAG
BPH_mass_spring_force_drag(data, drag);