Fix for hair chain testing in the cloth modifier.

Bending springs are en-bloc and not interleaved with other springs, so
this can't be used as a test for hair roots. Use consecutive indices
instead.
This commit is contained in:
Lukas Tönne 2014-09-26 09:26:08 +02:00
parent 577150c635
commit d613c38171
2 changed files with 19 additions and 17 deletions

View File

@ -1104,10 +1104,9 @@ static void cloth_free_errorsprings(Cloth *cloth, LinkNode **edgelist)
static void cloth_update_bending_targets(ClothModifierData *clmd)
{
Cloth *cloth = clmd->clothObject;
ClothSpring *spring;
LinkNode *search = NULL;
float hair_frame[3][3], dir_old[3], dir_new[3];
bool is_root;
int prev_mn; /* to find hair chains */
/* XXX Note: we need to propagate frames from the root up,
* but structural hair springs are stored in reverse order.
@ -1117,13 +1116,13 @@ static void cloth_update_bending_targets(ClothModifierData *clmd)
* generated directly from a dedicated hair system.
*/
is_root = true;
prev_mn = -1;
for (search = cloth->springs; search; search = search->next) {
ClothSpring *spring = search->link;
ClothHairRoot *hair_ij, *hair_kl;
bool is_root = spring->kl != prev_mn;
spring = search->link;
if (spring->type != CLOTH_SPRING_TYPE_BENDING_ANG) {
is_root = true; /* next bending spring connects to root */
continue;
}
@ -1142,7 +1141,7 @@ static void cloth_update_bending_targets(ClothModifierData *clmd)
sub_v3_v3v3(dir_new, cloth->verts[spring->mn].x, cloth->verts[spring->kl].x);
normalize_v3(dir_new);
#if 1
#if 0
if (clmd->debug_data && (spring->ij == 0 || spring->ij == 1)) {
float a[3], b[3];
@ -1170,17 +1169,16 @@ static void cloth_update_bending_targets(ClothModifierData *clmd)
/* move frame to next hair segment */
cloth_parallel_transport_hair_frame(hair_frame, dir_old, dir_new);
is_root = false; /* next bending spring not connected to root */
prev_mn = spring->mn;
}
}
static void cloth_update_bending_rest_targets(ClothModifierData *clmd)
{
Cloth *cloth = clmd->clothObject;
ClothSpring *spring;
LinkNode *search = NULL;
float hair_frame[3][3], dir_old[3], dir_new[3];
bool is_root;
int prev_mn; /* to find hair roots */
/* XXX Note: we need to propagate frames from the root up,
* but structural hair springs are stored in reverse order.
@ -1190,13 +1188,13 @@ static void cloth_update_bending_rest_targets(ClothModifierData *clmd)
* generated directly from a dedicated hair system.
*/
is_root = true;
prev_mn = -1;
for (search = cloth->springs; search; search = search->next) {
ClothSpring *spring = search->link;
ClothHairRoot *hair_ij, *hair_kl;
bool is_root = spring->kl != prev_mn;
spring = search->link;
if (spring->type != CLOTH_SPRING_TYPE_BENDING_ANG) {
is_root = true; /* next bending spring connects to root */
continue;
}
@ -1222,7 +1220,7 @@ static void cloth_update_bending_rest_targets(ClothModifierData *clmd)
/* move frame to next hair segment */
cloth_parallel_transport_hair_frame(hair_frame, dir_old, dir_new);
is_root = false; /* next bending spring not connected to root */
prev_mn = spring->mn;
}
}

View File

@ -428,12 +428,16 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
BPH_mass_spring_force_spring_bending_angular(data, s->ij, s->kl, s->mn, s->matrix_ij_kl, s->matrix_kl_mn, s->matrix_ij_mn, s->target, kb, cb);
{
float x[3], v[3], d[3];
float x_kl[3], x_mn[3], v[3], d[3];
BPH_mass_spring_get_motion_state(data, s->kl, x, v);
BPH_mass_spring_get_motion_state(data, s->kl, x_kl, v);
BPH_mass_spring_get_motion_state(data, s->mn, x_mn, v);
BKE_sim_debug_data_add_dot(clmd->debug_data, x_kl, 0.9, 0.9, 0.9, "target", hash_vertex(7980, s->kl));
BKE_sim_debug_data_add_line(clmd->debug_data, x_kl, x_mn, 0.8, 0.8, 0.8, "target", hash_vertex(7981, s->kl));
copy_v3_v3(d, s->target);
BKE_sim_debug_data_add_vector(clmd->debug_data, x, d, 0.8, 0.8, 0.2, "target", hash_vertex(7982, s->kl));
BKE_sim_debug_data_add_vector(clmd->debug_data, x_kl, d, 0.8, 0.8, 0.2, "target", hash_vertex(7982, s->kl));
// copy_v3_v3(d, s->target_ij);
// BKE_sim_debug_data_add_vector(clmd->debug_data, x, d, 1, 0.4, 0.4, "target", hash_vertex(7983, s->kl));
@ -644,7 +648,7 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
if (clmd->debug_data) {
for (i = 0; i < numverts; i++) {
BKE_sim_debug_data_add_dot(clmd->debug_data, verts[i].x, 1.0f, 0.1f, 1.0f, "points", hash_vertex(583, i));
// BKE_sim_debug_data_add_dot(clmd->debug_data, verts[i].x, 1.0f, 0.1f, 1.0f, "points", hash_vertex(583, i));
}
}