Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Velocities synchronization fix in btDeformableMultiBodyConstraintSolver::writeToSolverBody #4667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/BulletDynamics/ConstraintSolver/btSolverBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ struct btSimdScalar
: m_vec128(v128)
{
}
union {
union
{
__m128 m_vec128;
float m_floats[4];
int m_ints[4];
Expand Down
36 changes: 24 additions & 12 deletions src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ btScalar btDeformableMultiBodyConstraintSolver::solveDeformableGroupIterations(b
// solver body velocity <- rigid body velocity
writeToSolverBody(bodies, numBodies, infoGlobal);


// std::cout << "------------Iteration " << iteration << "------------\n";
// std::cout << "m_leastSquaresResidual: " << m_leastSquaresResidual << "\n";

Expand All @@ -60,7 +59,7 @@ btScalar btDeformableMultiBodyConstraintSolver::solveDeformableGroupIterations(b
m_analyticsData.m_numBodies = numBodies;
m_analyticsData.m_numContactManifolds = numManifolds;
m_analyticsData.m_remainingLeastSquaresResidual = m_leastSquaresResidual;

m_deformableSolver->deformableBodyInternalWriteBack();
// std::cout << "[===================Next Step===================]\n";
break;
Expand Down Expand Up @@ -88,6 +87,21 @@ void btDeformableMultiBodyConstraintSolver::solveDeformableBodyGroup(btCollision
m_tmpNumMultiBodyConstraints = 0;
}

void btDeformableMultiBodyConstraintSolver::synchronizeSolverBodyWithRigidBody(btSolverBody* solverBody, btRigidBody* rigidBody)
{
// Compute the total velocity change
btVector3 totalDeltaLinearVelocity = rigidBody->getLinearVelocity() - (solverBody->m_linearVelocity + solverBody->m_deltaLinearVelocity);
btVector3 totalDeltaAngularVelocity = rigidBody->getAngularVelocity() - (solverBody->m_angularVelocity + solverBody->m_deltaAngularVelocity);

// Update the delta velocities
solverBody->m_deltaLinearVelocity += totalDeltaLinearVelocity;
solverBody->m_deltaAngularVelocity += totalDeltaAngularVelocity;

// Adjust the solver body's base velocities
solverBody->m_linearVelocity = rigidBody->getLinearVelocity() - solverBody->m_deltaLinearVelocity;
solverBody->m_angularVelocity = rigidBody->getAngularVelocity() - solverBody->m_deltaAngularVelocity;
}

void btDeformableMultiBodyConstraintSolver::writeToSolverBody(btCollisionObject** bodies, int numBodies, const btContactSolverInfo& infoGlobal)
{
// reduced soft body solver directly modifies the solver body
Expand All @@ -104,8 +118,7 @@ void btDeformableMultiBodyConstraintSolver::writeToSolverBody(btCollisionObject*
if (body && body->getInvMass())
{
btSolverBody& solverBody = m_tmpSolverBodyPool[bodyId];
solverBody.m_linearVelocity = body->getLinearVelocity() - solverBody.m_deltaLinearVelocity;
solverBody.m_angularVelocity = body->getAngularVelocity() - solverBody.m_deltaAngularVelocity;
synchronizeSolverBodyWithRigidBody(&solverBody, body);
}
}
}
Expand All @@ -129,7 +142,6 @@ void btDeformableMultiBodyConstraintSolver::solverBodyWriteBack(const btContactS
}
}


void btDeformableMultiBodyConstraintSolver::pairDeformableAndSolverBody(btCollisionObject** bodies, int numBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal)
{
if (!m_deformableSolver->isReducedSolver())
Expand All @@ -138,29 +150,29 @@ void btDeformableMultiBodyConstraintSolver::pairDeformableAndSolverBody(btCollis
}

btReducedDeformableBodySolver* solver = static_cast<btReducedDeformableBodySolver*>(m_deformableSolver);

for (int i = 0; i < numDeformableBodies; ++i)
{
for (int k = 0; k < solver->m_nodeRigidConstraints[i].size(); ++k)
{
btReducedDeformableNodeRigidContactConstraint& constraint = solver->m_nodeRigidConstraints[i][k];
{
btReducedDeformableNodeRigidContactConstraint& constraint = solver->m_nodeRigidConstraints[i][k];

if (!constraint.m_contact->m_cti.m_colObj->isStaticObject())
{
btCollisionObject& col_obj = const_cast<btCollisionObject&>(*constraint.m_contact->m_cti.m_colObj);

// object index in the solver body pool
int bodyId = getOrInitSolverBody(col_obj, infoGlobal.m_timeStep);

const btRigidBody* body = btRigidBody::upcast(bodies[bodyId]);
if (body && body->getInvMass())
{
// std::cout << "Node: " << constraint.m_node->index << ", body: " << bodyId << "\n";
// std::cout << "Node: " << constraint.m_node->index << ", body: " << bodyId << "\n";
btSolverBody& solverBody = m_tmpSolverBodyPool[bodyId];
constraint.setSolverBody(bodyId, solverBody);
}
}
}
}

// for (int j = 0; j < numBodies; j++)
// {
Expand All @@ -172,7 +184,7 @@ void btDeformableMultiBodyConstraintSolver::pairDeformableAndSolverBody(btCollis
// btSolverBody& solverBody = m_tmpSolverBodyPool[bodyId];
// m_deformableSolver->pairConstraintWithSolverBody(i, bodyId, solverBody);
// }
// }
// }
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ btDeformableMultiBodyConstraintSolver : public btMultiBodyConstraintSolver
// write the velocity of the the solver body to the underlying rigid body
void solverBodyWriteBack(const btContactSolverInfo& infoGlobal);

void synchronizeSolverBodyWithRigidBody(btSolverBody * solverBody, btRigidBody * rigidBody);

// write the velocity of the underlying rigid body to the the the solver body
void writeToSolverBody(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal);

// let each deformable body knows which solver body is in constact
void pairDeformableAndSolverBody(btCollisionObject** bodies, int numBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal);
void pairDeformableAndSolverBody(btCollisionObject * *bodies, int numBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal);

virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject * *bodies, int numBodies, btCollisionObject** deformableBodies, int numDeformableBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer);

Expand Down