From c722630fc7a2dc5031fd033cb7ee0afcd29717cb Mon Sep 17 00:00:00 2001 From: Xuchen Han Date: Tue, 27 Aug 2019 10:17:00 -0700 Subject: [PATCH] bug fix in neohookean force --- examples/DeformableDemo/GraspDeformable.cpp | 2 +- src/BulletSoftBody/btDeformableNeoHookeanForce.h | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/DeformableDemo/GraspDeformable.cpp b/examples/DeformableDemo/GraspDeformable.cpp index b5cc66626..c97aa0d3c 100644 --- a/examples/DeformableDemo/GraspDeformable.cpp +++ b/examples/DeformableDemo/GraspDeformable.cpp @@ -357,7 +357,7 @@ void GraspDeformable::initPhysics() // getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity)); // getDeformableDynamicsWorld()->addForce(psb, new btDeformableCorotatedForce(0,6)); - btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(.5,0.04, true); + btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(.0,0.04, true); getDeformableDynamicsWorld()->addForce(psb, mass_spring); m_forces.push_back(mass_spring); diff --git a/src/BulletSoftBody/btDeformableNeoHookeanForce.h b/src/BulletSoftBody/btDeformableNeoHookeanForce.h index 9bc232e24..2431cd750 100644 --- a/src/BulletSoftBody/btDeformableNeoHookeanForce.h +++ b/src/BulletSoftBody/btDeformableNeoHookeanForce.h @@ -87,18 +87,20 @@ public: btMatrix3x3 C = F.transpose()*F; btScalar J = F.determinant(); btScalar trace = C[0].getX() + C[1].getY() + C[2].getZ(); - P = F * m_mu * ( 1. - 1. / (trace + 1.)) + F.adjoint() * (m_lambda * (J - 1) - 0.75 * m_mu); + P = F * m_mu * ( 1. - 1. / (trace + 1.)) + F.adjoint().transpose() * (m_lambda * (J - 1) - 0.75 * m_mu); } virtual void addScaledForceDifferential(btScalar scale, const TVStack& dv, TVStack& df) { } - void firstPiolaDifferential(const btMatrix3x3& F, const btMatrix3x3& G, btMatrix3x3& P) + void firstPiolaDifferential(const btMatrix3x3& F, const btMatrix3x3& dF, btMatrix3x3& dP) { btScalar J = F.determinant(); - addScaledCofactorMatrixDifferential(F, G, m_lambda*(J-1), P); - P += F.adjoint() * m_lambda * DotProduct(F.adjoint(), G); + addScaledCofactorMatrixDifferential(F, dF, m_lambda*(J-1) - 0.75*m_mu, dP); + dP += F.adjoint().transpose() * m_lambda * DotProduct(F.adjoint().transpose(), dF); + + //todo @xuchenhan: add the dP of the m_mu term. } btScalar DotProduct(const btMatrix3x3& A, const btMatrix3x3& B)