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-19 13:15:16 +0400
committerLukas Tönne <lukas.toenne@gmail.com>2015-01-20 11:30:02 +0300
commit7a7778d003d1a31fb4eb3411e1b0512981cc4614 (patch)
tree0488266c11cbaf505c02de1eb34bcaf42486e1d4 /source/blender/physics
parent86a4da1c5416c36d2e860720d474f394146ecc2d (diff)
Simple initial implementation of angular bending springs.
These are much better suited for creating stiff hair. The previous bending springs are based on "push" type spring along the hypothenuse of 3 hair vertices. This sort of spring requires a very large force in the direction of the spring for any angular effect, and is still unstable in the equilibrium. The new bending spring model is based on "target" vectors defined in a local hair frame, which generates a force perpendicular to the hair segment. For further details see "Artistic Simulation of Curly Hair" (Pixar technical memo #12-03a) or "A Mass Spring Model for Hair Simulation" (Selle, Lentine, Fedkiw 2008) Currently the implementation uses a single root frame that is not yet propagated along the hair, so the resulting rest shape is not very natural. Also damping and derivatives are still missing.
Diffstat (limited to 'source/blender/physics')
-rw-r--r--source/blender/physics/intern/BPH_mass_spring.cpp14
-rw-r--r--source/blender/physics/intern/implicit.h4
-rw-r--r--source/blender/physics/intern/implicit_blender.c44
3 files changed, 60 insertions, 2 deletions
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index db371997632..56de54e4192 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -373,7 +373,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
BPH_mass_spring_force_spring_goal(data, s->ij, s->matrix_index, goal_x, goal_v, k, parms->goalfrict * 0.01f, s->f, s->dfdx, s->dfdv);
#endif
}
- else { /* calculate force of bending springs */
+ else if (s->type & CLOTH_SPRING_TYPE_BENDING) { /* calculate force of bending springs */
#ifdef CLOTH_FORCE_SPRING_BEND
float kb, cb, scaling;
@@ -385,6 +385,18 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
BPH_mass_spring_force_spring_bending(data, s->ij, s->kl, s->matrix_index, s->restlen, kb, cb, s->f, s->dfdx, s->dfdv);
#endif
}
+ else if (s->type & CLOTH_SPRING_TYPE_BENDING_ANG) {
+#ifdef CLOTH_FORCE_SPRING_BEND
+ float kb, cb, scaling;
+
+ s->flags |= CLOTH_SPRING_FLAG_NEEDED;
+
+ scaling = parms->bending + s->stiffness * fabsf(parms->max_bend - parms->bending);
+ cb = kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
+
+ BPH_mass_spring_force_spring_bending_angular(data, s->ij, s->kl, s->matrix_index, s->restlen, kb, cb, s->f, s->dfdx, s->dfdv);
+#endif
+ }
}
static void hair_get_boundbox(ClothModifierData *clmd, float gmin[3], float gmax[3])
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 3743152cc79..ea9a5b8211a 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -140,6 +140,10 @@ bool BPH_mass_spring_force_spring_linear(struct Implicit_Data *data, int i, int
bool BPH_mass_spring_force_spring_bending(struct Implicit_Data *data, int i, int j, int spring_index, float restlen,
float kb, float cb,
float r_f[3], float r_dfdx[3][3], float r_dfdv[3][3]);
+/* Angular bending force based on local target vectors */
+bool BPH_mass_spring_force_spring_bending_angular(struct Implicit_Data *data, int i, int j, int spring_index, float restlen,
+ float stiffness, float damping,
+ float r_f[3], float r_dfdx[3][3], float r_dfdv[3][3]);
/* Global goal spring */
bool BPH_mass_spring_force_spring_goal(struct Implicit_Data *data, int i, int spring_index, const float goal_x[3], const float goal_v[3],
float stiffness, float damping,
diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c
index bad883d7af3..dd8cab6556f 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -1181,12 +1181,12 @@ int BPH_mass_spring_init_spring(Implicit_Data *data, int index, int v1, int v2)
{
int s = data->M[0].vcount + index; /* index from array start */
+ /* tfm and S don't have spring entries (diagonal blocks only) */
init_fmatrix(data->bigI + s, v1, v2);
init_fmatrix(data->M + s, v1, v2);
init_fmatrix(data->dFdX + s, v1, v2);
init_fmatrix(data->dFdV + s, v1, v2);
init_fmatrix(data->A + s, v1, v2);
-// init_fmatrix(data->S + s, v1, v2); // has no off-diagonal spring entries
init_fmatrix(data->P + s, v1, v2);
init_fmatrix(data->Pinv + s, v1, v2);
@@ -1609,6 +1609,48 @@ bool BPH_mass_spring_force_spring_bending(Implicit_Data *data, int i, int j, int
}
}
+/* Angular spring that pulls the vertex toward the local target
+ * See "Artistic Simulation of Curly Hair" (Pixar technical memo #12-03a)
+ */
+bool BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, int j, int spring_index, float restlen,
+ float stiffness, float damping,
+ float r_f[3], float r_dfdx[3][3], float r_dfdv[3][3])
+{
+ float target[3], dist[3], extent[3], length, dir[3], vel[3];
+ float f[3], dfdx[3][3], dfdv[3][3];
+
+ target[0] = 0.0f;
+ target[1] = 0.0f;
+ target[2] = restlen;
+
+ // calculate elonglation
+// spring_length(data, i, j, extent, dir, &length, vel);
+ sub_v3_v3v3(extent, data->X[j], data->X[i]);
+ sub_v3_v3v3(vel, data->V[j], data->V[i]);
+ length = len_v3(extent);
+
+ sub_v3_v3v3(dist, target, extent);
+ mul_v3_v3fl(f, dist, stiffness);
+// mul_v3_v3fl(f, dir, fbstar(length, restlen, kb, cb));
+
+ zero_m3(dfdx);
+ zero_m3(dfdv);
+
+// outerproduct(dfdx, dir, dir);
+// mul_m3_fl(dfdx, fbstar_jacobi(length, restlen, kb, cb));
+
+ /* XXX damping not supported */
+// zero_m3(dfdv);
+
+ apply_spring(data, i, j, spring_index, f, dfdx, dfdv);
+
+ if (r_f) copy_v3_v3(r_f, f);
+ if (r_dfdx) copy_m3_m3(r_dfdx, dfdx);
+ if (r_dfdv) copy_m3_m3(r_dfdv, dfdv);
+
+ return true;
+}
+
bool BPH_mass_spring_force_spring_goal(Implicit_Data *data, int i, int UNUSED(spring_index), const float goal_x[3], const float goal_v[3],
float stiffness, float damping,
float r_f[3], float r_dfdx[3][3], float r_dfdv[3][3])