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; + } + } + } + } + } } }