From 20abbc9ee7e85f32bad9233c2ae8305d7cd7f1bb Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Fri, 20 Sep 2019 13:53:34 -0700 Subject: [PATCH] add dynamic friction for deformable contact --- .../btDeformableContactProjection.cpp | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/BulletSoftBody/btDeformableContactProjection.cpp b/src/BulletSoftBody/btDeformableContactProjection.cpp index 3943e695f..e340a3fd5 100644 --- a/src/BulletSoftBody/btDeformableContactProjection.cpp +++ b/src/BulletSoftBody/btDeformableContactProjection.cpp @@ -387,14 +387,51 @@ void btDeformableContactProjection::applyDynamicFriction(TVStack& f) // it's ok to add the friction force generated by the entire impulse here because the normal component of the residual will be projected out anyway. for (int k = 0; k < 3; ++k) { - if (face->m_n[0]->index == i) + if (face->m_n[k]->index == i) { - f[i] += constraint->getDv(face->m_n[k])* (1./face->m_n[k]->m_im); + if (face->m_n[k]->m_im != 0) + { + f[i] += constraint->getDv(face->m_n[k])* (1./face->m_n[k]->m_im); + } break; } } } } + + if (m_deformableConstraints.find(i) != NULL) + { + btAlignedObjectArray& constraintsList = *m_deformableConstraints[i]; + for (int j = 0; j < constraintsList.size(); ++j) + { + const btDeformableFaceNodeContactConstraint* constraint = constraintsList[j]; + btSoftBody::Face* face = constraint->getContact()->m_face; + btSoftBody::Node* node = constraint->getContact()->m_node; + + // it's ok to add the friction force generated by the entire impulse here because the normal component of the residual will be projected out anyway. + if (node->index == i) + { + if (node->m_im != 0) + { + f[i] += constraint->getDv(node)*(1./node->m_im); + } + } + else + { + for (int k = 0; k < 3; ++k) + { + if (face->m_n[k]->index == i) + { + if (face->m_n[k]->m_im != 0) + { + f[i] += constraint->getDv(face->m_n[k])* (1./face->m_n[k]->m_im); + } + break; + } + } + } + } + } } }