Commit: 00bb836e17de349b7e4f9478b1911f8de8e0b334
Author: Lukas Tönne
Date:   Fri Sep 19 16:53:35 2014 +0200
Branches: master
https://developer.blender.org/rB00bb836e17de349b7e4f9478b1911f8de8e0b334

Calculate bending targets based on the direction of previous segments.

This makes the bending a truely local effect. Eventually target
directions should be based in a local coordinate frame that gets
parallel transported along the curve. This will allow non-straight
rest shapes for hairs as well as supporting twist forces. However,
calculating locally transformed spring forces is more complicated.

===================================================================

M       source/blender/blenkernel/intern/cloth.c
M       source/blender/physics/intern/BPH_mass_spring.cpp
M       source/blender/physics/intern/implicit.h
M       source/blender/physics/intern/implicit_blender.c

===================================================================

diff --git a/source/blender/blenkernel/intern/cloth.c 
b/source/blender/blenkernel/intern/cloth.c
index 1b3b668..284107e 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -1302,9 +1302,9 @@ static int cloth_build_springs ( ClothModifierData *clmd, 
DerivedMesh *dm )
                                                return 0;
                                        }
                                        
-                                       spring->ij = tspring->kl;
+                                       spring->ij = tspring2->ij;
                                        spring->kl = tspring->ij;
-                                       spring->mn = tspring2->ij;
+                                       spring->mn = tspring->kl;
                                        spring->restlen = 
len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest);
                                        spring->type = 
CLOTH_SPRING_TYPE_BENDING_ANG;
                                        spring->stiffness = 
(cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 
2.0f;
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp 
b/source/blender/physics/intern/BPH_mass_spring.cpp
index 2700f4a..6a64e17 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -394,7 +394,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData 
*clmd, ClothSpring *s,
                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);
+               BPH_mass_spring_force_spring_bending_angular(data, s->ij, 
s->kl, s->mn, s->matrix_index, s->restlen, kb, cb, s->f, s->dfdx, s->dfdv);
 #endif
        }
 }
diff --git a/source/blender/physics/intern/implicit.h 
b/source/blender/physics/intern/implicit.h
index ac2c942..b11bc5d 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -144,7 +144,7 @@ bool BPH_mass_spring_force_spring_bending(struct 
Implicit_Data *data, int i, int
                                           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,
+bool BPH_mass_spring_force_spring_bending_angular(struct Implicit_Data *data, 
int i, int j, int k, 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 */
diff --git a/source/blender/physics/intern/implicit_blender.c 
b/source/blender/physics/intern/implicit_blender.c
index 84db552..425dcf9 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -1619,28 +1619,32 @@ 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,
+bool BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, 
int j, int k, 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], targetdir[3];
-       float extent[3], dir[3], length;
+       float extent[3], dir[3];
        float dist[3], vel[3];
        float f[3], dfdx[3][3], dfdv[3][3];
        
-       target[0] = 0.0f;
-       target[1] = 0.0f;
-       target[2] = restlen;
+       sub_v3_v3v3(targetdir, data->X[j], data->X[i]);
+       normalize_v3(targetdir);
+       mul_v3_v3fl(target, targetdir, restlen);
+       {
+               float x[3], d[3];
+               root_to_world_v3(data, j, x, data->X[j]);
+               root_to_world_v3(data, j, d, target);
+               BKE_sim_debug_data_add_vector(data->debug_data, x, d, 1, 0, 0, 
"spoint", hash_vertex(935, j));
+       }
        
        // 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 = normalize_v3_v3(dir, extent);
-       normalize_v3_v3(targetdir, target);
+       sub_v3_v3v3(extent, data->X[k], data->X[j]);
+       sub_v3_v3v3(vel, data->V[k], data->V[j]);
+       normalize_v3_v3(dir, extent);
        
        sub_v3_v3v3(dist, target, extent);
-       mul_v3_v3fl(f, dist, stiffness);
+       mul_v3_v3fl(f, dist, -stiffness);
        
        madd_v3_v3fl(vel, dir, -dot_v3v3(vel, dir));
        madd_v3_v3fl(f, vel, damping);
@@ -1648,13 +1652,7 @@ bool 
BPH_mass_spring_force_spring_bending_angular(Implicit_Data *data, int i, in
        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);
+       apply_spring(data, j, k, spring_index, f, dfdx, dfdv);
        
        if (r_f) copy_v3_v3(r_f, f);
        if (r_dfdx) copy_m3_m3(r_dfdx, dfdx);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to