do not apply deformable contact impulse to points and faces constrained in rigid/deformable solve

This commit is contained in:
Xuchen Han 2020-05-20 17:56:20 -07:00
parent 65978cb58b
commit d1d2dad2e6
3 changed files with 25 additions and 23 deletions

View File

@ -437,7 +437,7 @@ void btDeformableBodySolver::predictDeformableMotion(btSoftBody* psb, btScalar d
} }
n.m_q = n.m_x + n.m_v * dt; n.m_q = n.m_x + n.m_v * dt;
n.m_splitv.setZero(); n.m_splitv.setZero();
n.m_penetration = 0; n.m_constrained = false;
} }
/* Nodes */ /* Nodes */

View File

@ -221,7 +221,7 @@ void btDeformableContactProjection::setProjection()
for (int j = 0; j < m_staticConstraints[i].size(); ++j) for (int j = 0; j < m_staticConstraints[i].size(); ++j)
{ {
int index = m_staticConstraints[i][j].m_node->index; int index = m_staticConstraints[i][j].m_node->index;
m_staticConstraints[i][j].m_node->m_penetration = SIMD_INFINITY; m_staticConstraints[i][j].m_node->m_constrained = true;
if (m_projectionsDict.find(index) == NULL) if (m_projectionsDict.find(index) == NULL)
{ {
m_projectionsDict.insert(index, units); m_projectionsDict.insert(index, units);
@ -238,7 +238,7 @@ void btDeformableContactProjection::setProjection()
for (int j = 0; j < m_nodeAnchorConstraints[i].size(); ++j) for (int j = 0; j < m_nodeAnchorConstraints[i].size(); ++j)
{ {
int index = m_nodeAnchorConstraints[i][j].m_anchor->m_node->index; int index = m_nodeAnchorConstraints[i][j].m_anchor->m_node->index;
m_nodeAnchorConstraints[i][j].m_anchor->m_node->m_penetration = SIMD_INFINITY; m_nodeAnchorConstraints[i][j].m_anchor->m_node->m_constrained = true;
if (m_projectionsDict.find(index) == NULL) if (m_projectionsDict.find(index) == NULL)
{ {
m_projectionsDict.insert(index, units); m_projectionsDict.insert(index, units);
@ -255,7 +255,7 @@ void btDeformableContactProjection::setProjection()
for (int j = 0; j < m_nodeRigidConstraints[i].size(); ++j) for (int j = 0; j < m_nodeRigidConstraints[i].size(); ++j)
{ {
int index = m_nodeRigidConstraints[i][j].m_node->index; int index = m_nodeRigidConstraints[i][j].m_node->index;
m_nodeRigidConstraints[i][j].m_node->m_penetration = -m_nodeRigidConstraints[i][j].getContact()->m_cti.m_offset; m_nodeRigidConstraints[i][j].m_node->m_constrained = true;
if (m_nodeRigidConstraints[i][j].m_static) if (m_nodeRigidConstraints[i][j].m_static)
{ {
if (m_projectionsDict.find(index) == NULL) if (m_projectionsDict.find(index) == NULL)
@ -289,15 +289,16 @@ void btDeformableContactProjection::setProjection()
for (int j = 0; j < m_faceRigidConstraints[i].size(); ++j) for (int j = 0; j < m_faceRigidConstraints[i].size(); ++j)
{ {
const btSoftBody::Face* face = m_faceRigidConstraints[i][j].m_face; const btSoftBody::Face* face = m_faceRigidConstraints[i][j].m_face;
btScalar penetration = -m_faceRigidConstraints[i][j].getContact()->m_cti.m_offset; if (m_faceRigidConstraints[i][j].m_binding)
for (int k = 0; k < 3; ++k) {
{ for (int k = 0; k < 3; ++k)
face->m_n[k]->m_penetration = btMax(face->m_n[k]->m_penetration, penetration); {
} face->m_n[k]->m_constrained = true;
}
}
for (int k = 0; k < 3; ++k) for (int k = 0; k < 3; ++k)
{ {
btSoftBody::Node* node = face->m_n[k]; btSoftBody::Node* node = face->m_n[k];
node->m_penetration = true;
int index = node->index; int index = node->index;
if (m_faceRigidConstraints[i][j].m_static) if (m_faceRigidConstraints[i][j].m_static)
{ {
@ -469,7 +470,7 @@ void btDeformableContactProjection::setLagrangeMultiplier()
for (int j = 0; j < m_staticConstraints[i].size(); ++j) for (int j = 0; j < m_staticConstraints[i].size(); ++j)
{ {
int index = m_staticConstraints[i][j].m_node->index; int index = m_staticConstraints[i][j].m_node->index;
m_staticConstraints[i][j].m_node->m_penetration = SIMD_INFINITY; m_staticConstraints[i][j].m_node->m_constrained = true;
LagrangeMultiplier lm; LagrangeMultiplier lm;
lm.m_num_nodes = 1; lm.m_num_nodes = 1;
lm.m_indices[0] = index; lm.m_indices[0] = index;
@ -483,7 +484,7 @@ void btDeformableContactProjection::setLagrangeMultiplier()
for (int j = 0; j < m_nodeAnchorConstraints[i].size(); ++j) for (int j = 0; j < m_nodeAnchorConstraints[i].size(); ++j)
{ {
int index = m_nodeAnchorConstraints[i][j].m_anchor->m_node->index; int index = m_nodeAnchorConstraints[i][j].m_anchor->m_node->index;
m_nodeAnchorConstraints[i][j].m_anchor->m_node->m_penetration = SIMD_INFINITY; m_nodeAnchorConstraints[i][j].m_anchor->m_node->m_constrained = true;
LagrangeMultiplier lm; LagrangeMultiplier lm;
lm.m_num_nodes = 1; lm.m_num_nodes = 1;
lm.m_indices[0] = index; lm.m_indices[0] = index;
@ -501,7 +502,7 @@ void btDeformableContactProjection::setLagrangeMultiplier()
continue; continue;
} }
int index = m_nodeRigidConstraints[i][j].m_node->index; int index = m_nodeRigidConstraints[i][j].m_node->index;
m_nodeRigidConstraints[i][j].m_node->m_penetration = -m_nodeRigidConstraints[i][j].getContact()->m_cti.m_offset; m_nodeRigidConstraints[i][j].m_node->m_constrained = true;
LagrangeMultiplier lm; LagrangeMultiplier lm;
lm.m_num_nodes = 1; lm.m_num_nodes = 1;
lm.m_indices[0] = index; lm.m_indices[0] = index;
@ -529,12 +530,11 @@ void btDeformableContactProjection::setLagrangeMultiplier()
const btSoftBody::Face* face = m_faceRigidConstraints[i][j].m_face; const btSoftBody::Face* face = m_faceRigidConstraints[i][j].m_face;
btVector3 bary = m_faceRigidConstraints[i][j].getContact()->m_bary; btVector3 bary = m_faceRigidConstraints[i][j].getContact()->m_bary;
btScalar penetration = -m_faceRigidConstraints[i][j].getContact()->m_cti.m_offset;
LagrangeMultiplier lm; LagrangeMultiplier lm;
lm.m_num_nodes = 3; lm.m_num_nodes = 3;
for (int k = 0; k<3; ++k) for (int k = 0; k<3; ++k)
{ {
face->m_n[k]->m_penetration = btMax(face->m_n[k]->m_penetration, penetration); face->m_n[k]->m_constrained = true;
lm.m_indices[k] = face->m_n[k]->index; lm.m_indices[k] = face->m_n[k]->index;
lm.m_weights[k] = bary[k]; lm.m_weights[k] = bary[k];
} }

View File

@ -269,7 +269,7 @@ public:
btScalar m_im; // 1/mass btScalar m_im; // 1/mass
btScalar m_area; // Area btScalar m_area; // Area
btDbvtNode* m_leaf; // Leaf data btDbvtNode* m_leaf; // Leaf data
btScalar m_penetration; // depth of penetration int m_constrained; // depth of penetration
int m_battach : 1; // Attached int m_battach : 1; // Attached
int index; int index;
btVector3 m_splitv; // velocity associated with split impulse btVector3 m_splitv; // velocity associated with split impulse
@ -1313,20 +1313,22 @@ public:
I = -btMin(m_repulsionStiffness * timeStep * d, mass * (OVERLAP_REDUCTION_FACTOR * d / timeStep - vn)); I = -btMin(m_repulsionStiffness * timeStep * d, mass * (OVERLAP_REDUCTION_FACTOR * d / timeStep - vn));
if (vn < 0) if (vn < 0)
I += 0.5 * mass * vn; I += 0.5 * mass * vn;
btScalar face_penetration = 0, node_penetration = node->m_penetration; int face_penetration = 0, node_penetration = node->m_constrained;
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
face_penetration = btMax(face_penetration, face->m_n[i]->m_penetration); face_penetration |= face->m_n[i]->m_constrained;
btScalar I_tilde = .5 *I /(1.0+w.length2()); btScalar I_tilde = .5 *I /(1.0+w.length2());
// double the impulse if node or face is constrained. // double the impulse if node or face is constrained.
if (face_penetration > 0 || node_penetration > 0) if (face_penetration > 0 || node_penetration > 0)
I_tilde *= 2.0; {
if (face_penetration <= node_penetration) I_tilde *= 2.0;
}
if (face_penetration <= 0)
{ {
for (int j = 0; j < 3; ++j) for (int j = 0; j < 3; ++j)
face->m_n[j]->m_v += w[j]*n*I_tilde*node->m_im; face->m_n[j]->m_v += w[j]*n*I_tilde*node->m_im;
} }
if (face_penetration >= node_penetration) if (node_penetration <= 0)
{ {
node->m_v -= I_tilde*node->m_im*n; node->m_v -= I_tilde*node->m_im*n;
} }
@ -1344,12 +1346,12 @@ public:
// double the impulse if node or face is constrained. // double the impulse if node or face is constrained.
// if (face_penetration > 0 || node_penetration > 0) // if (face_penetration > 0 || node_penetration > 0)
// I_tilde *= 2.0; // I_tilde *= 2.0;
if (face_penetration <= node_penetration) if (face_penetration <= 0)
{ {
for (int j = 0; j < 3; ++j) for (int j = 0; j < 3; ++j)
face->m_n[j]->m_v += w[j] * vt * I_tilde * (face->m_n[j])->m_im; face->m_n[j]->m_v += w[j] * vt * I_tilde * (face->m_n[j])->m_im;
} }
if (face_penetration >= node_penetration) if (node_penetration <= 0)
{ {
node->m_v -= I_tilde * node->m_im * vt; node->m_v -= I_tilde * node->m_im * vt;
} }