Fixed for hair collision detection, old/new positions were swapped.
This commit is contained in:
parent
971419c27d
commit
93194eb0e9
|
@ -1072,17 +1072,6 @@ static bool cloth_points_collision_response_static(ClothModifierData *clmd, Coll
|
|||
return result;
|
||||
}
|
||||
|
||||
#if 0
|
||||
BLI_INLINE void face_normal(float co1[3], float co2[3], float co3[3], float nor[3])
|
||||
{
|
||||
float p[3], q[3];
|
||||
sub_v3_v3v3(p, co2, co1);
|
||||
sub_v3_v3v3(q, co3, co1);
|
||||
cross_v3_v3v3(nor, p, q);
|
||||
normalize_v3(nor);
|
||||
}
|
||||
#endif
|
||||
|
||||
BLI_INLINE bool cloth_point_face_collision_params(const float p1[3], const float p2[3], const float v0[3], const float v1[3], const float v2[3],
|
||||
float r_nor[3], float *r_lambda, float r_uv[2])
|
||||
{
|
||||
|
@ -1126,7 +1115,7 @@ BLI_INLINE bool cloth_point_face_collision_params(const float p1[3], const float
|
|||
}
|
||||
|
||||
static CollPair *cloth_point_collpair(float p1[3], float p2[3], MVert *mverts, int bp1, int bp2, int bp3,
|
||||
int index_cloth, int index_coll, float epsilon, CollPair *collpair)
|
||||
int index_cloth, int index_coll, float epsilon, CollPair *collpair, SimDebugData *debug_data)
|
||||
{
|
||||
float *co1 = mverts[bp1].co, *co2 = mverts[bp2].co, *co3 = mverts[bp3].co;
|
||||
float lambda, uv[2], distance1, distance2;
|
||||
|
@ -1140,6 +1129,7 @@ static CollPair *cloth_point_collpair(float p1[3], float p2[3], MVert *mverts, i
|
|||
distance1 = dot_v3v3(v1p1, facenor);
|
||||
sub_v3_v3v3(v1p2, p2, co1);
|
||||
distance2 = dot_v3v3(v1p2, facenor);
|
||||
BKE_sim_debug_data_add_line(debug_data, p1, p2, 0,1,1, "collision", hash_int_2d(98293, hash_int_2d(index_cloth, index_coll)));
|
||||
if (distance2 > epsilon || (distance1 < 0.0f && distance2 < 0.0f))
|
||||
return collpair;
|
||||
|
||||
|
@ -1185,9 +1175,9 @@ static CollPair* cloth_point_collision(ModifierData *md1, ModifierData *md2,
|
|||
vert = &clmd->clothObject->verts[overlap->indexA];
|
||||
face = &collmd->mfaces[overlap->indexB];
|
||||
|
||||
collpair = cloth_point_collpair(vert->x, vert->tx, mverts, face->v1, face->v2, face->v3, overlap->indexA, overlap->indexB, epsilon, collpair);
|
||||
collpair = cloth_point_collpair(vert->tx, vert->x, mverts, face->v1, face->v2, face->v3, overlap->indexA, overlap->indexB, epsilon, collpair, clmd->debug_data);
|
||||
if (face->v4)
|
||||
collpair = cloth_point_collpair(vert->x, vert->tx, mverts, face->v3, face->v4, face->v1, overlap->indexA, overlap->indexB, epsilon, collpair);
|
||||
collpair = cloth_point_collpair(vert->tx, vert->x, mverts, face->v3, face->v4, face->v1, overlap->indexA, overlap->indexB, epsilon, collpair, clmd->debug_data);
|
||||
|
||||
return collpair;
|
||||
}
|
||||
|
|
|
@ -137,6 +137,11 @@ static int hash_vertex(int type, int vertex)
|
|||
{
|
||||
return hash_int_2d((unsigned int)type, (unsigned int)vertex);
|
||||
}
|
||||
|
||||
static int hash_collpair(int type, CollPair *collpair)
|
||||
{
|
||||
return hash_int_2d((unsigned int)type, hash_int_2d((unsigned int)collpair->face1, (unsigned int)collpair->face2));
|
||||
}
|
||||
/* ================ */
|
||||
|
||||
/*
|
||||
|
@ -1752,7 +1757,7 @@ bool implicit_hair_volume_get_texture_data(Object *UNUSED(ob), ClothModifierData
|
|||
/* ================================ */
|
||||
|
||||
/* Init constraint matrix */
|
||||
static void setup_constraint_matrix(ClothVertex *verts, int numverts, ColliderContacts *contacts, int totcolliders, fmatrix3x3 *S)
|
||||
static void setup_constraint_matrix(ClothVertex *verts, int numverts, ColliderContacts *contacts, int totcolliders, fmatrix3x3 *S, SimDebugData *debug_data)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
|
@ -1784,6 +1789,15 @@ static void setup_constraint_matrix(ClothVertex *verts, int numverts, ColliderCo
|
|||
|
||||
mul_fvectorT_fvector(cmat, collpair->normal, collpair->normal);
|
||||
sub_m3_m3m3(S[v].m, I, cmat);
|
||||
|
||||
BKE_sim_debug_data_add_dot(debug_data, collpair->pa, 0, 1, 0, "collision", hash_collpair(936, collpair));
|
||||
BKE_sim_debug_data_add_dot(debug_data, collpair->pb, 1, 0, 0, "collision", hash_collpair(937, collpair));
|
||||
BKE_sim_debug_data_add_line(debug_data, collpair->pa, collpair->pb, 0.7, 0.7, 0.7, "collision", hash_collpair(938, collpair));
|
||||
{
|
||||
float nor[3];
|
||||
mul_v3_v3fl(nor, collpair->normal, collpair->distance);
|
||||
BKE_sim_debug_data_add_vector(debug_data, collpair->pb, nor, 1, 1, 0, "collision", hash_collpair(939, collpair));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2080,17 +2094,18 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase *
|
|||
}
|
||||
}
|
||||
|
||||
/* determine contact points */
|
||||
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) {
|
||||
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_POINTS) {
|
||||
cloth_find_point_contacts(ob, clmd, 0.0f, tf, &contacts, &totcolliders);
|
||||
}
|
||||
}
|
||||
|
||||
/* setup vertex constraints for pinned vertices and contacts */
|
||||
setup_constraint_matrix(verts, cloth->numverts, contacts, totcolliders, id->S);
|
||||
|
||||
while (step < tf) {
|
||||
|
||||
/* determine contact points */
|
||||
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) {
|
||||
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_POINTS) {
|
||||
cloth_find_point_contacts(ob, clmd, 0.0f, tf, &contacts, &totcolliders);
|
||||
}
|
||||
}
|
||||
|
||||
/* setup vertex constraints for pinned vertices and contacts */
|
||||
setup_constraint_matrix(verts, cloth->numverts, contacts, totcolliders, id->S, clmd->debug_data);
|
||||
|
||||
// damping velocity for artistic reasons
|
||||
mul_lfvectorS(id->V, id->V, clmd->sim_parms->vel_damping, numverts);
|
||||
|
||||
|
@ -2117,13 +2132,17 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase *
|
|||
|
||||
copy_v3_v3(verts[i].txold, id->X[i]);
|
||||
|
||||
// if (!(verts[i].flags & CLOTH_VERT_FLAG_PINNED) && i > 0)
|
||||
// BKE_sim_debug_data_add_line(clmd->debug_data, id->Xnew[i], id->Xnew[i-1], 1, 0.5, 0.5, "hair", hash_vertex(4892, i));
|
||||
// BKE_sim_debug_data_add_vector(clmd->debug_data, id->Xnew[i], id->Vnew[i], 0, 0, 1, "velocity", hash_vertex(3158, i));
|
||||
if (!(verts[i].flags & CLOTH_VERT_FLAG_PINNED) && i > 0)
|
||||
BKE_sim_debug_data_add_line(clmd->debug_data, id->X[i], id->X[i-1], 1, 0.5, 0.5, "hair", hash_vertex(4892, i));
|
||||
if (!(verts[i].flags & CLOTH_VERT_FLAG_PINNED) && i > 0) {
|
||||
BKE_sim_debug_data_add_line(clmd->debug_data, id->X[i], id->X[i-1], 0.6, 0.3, 0.3, "hair", hash_vertex(4892, i));
|
||||
BKE_sim_debug_data_add_line(clmd->debug_data, id->Xnew[i], id->Xnew[i-1], 1, 0.5, 0.5, "hair", hash_vertex(4893, i));
|
||||
}
|
||||
BKE_sim_debug_data_add_vector(clmd->debug_data, id->X[i], id->V[i], 0, 0, 1, "velocity", hash_vertex(3158, i));
|
||||
}
|
||||
|
||||
/* free contact points */
|
||||
if (contacts) {
|
||||
cloth_free_contacts(contacts, totcolliders);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) {
|
||||
|
@ -2221,11 +2240,6 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase *
|
|||
}
|
||||
}
|
||||
|
||||
/* free contact points */
|
||||
if (contacts) {
|
||||
cloth_free_contacts(contacts, totcolliders);
|
||||
}
|
||||
|
||||
/* unused */
|
||||
/*MEM_freeN(initial_cos);*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue