code clean up

This commit is contained in:
Xuchen Han 2019-08-10 12:00:48 -07:00
parent fa5741d07e
commit f7cd1edf4a
6 changed files with 9 additions and 50 deletions

View File

@ -232,7 +232,7 @@ void DeformableRigid::initPhysics()
psb->setDampingCoefficient(0.05);
psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects
psb->m_cfg.kCHR = 1; // collision hardness with rigid body
psb->m_cfg.kDF = 0;
psb->m_cfg.kDF = 1;
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
getDeformableDynamicsWorld()->addSoftBody(psb);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce());

View File

@ -331,10 +331,10 @@ void GraspDeformable::initPhysics()
psb->getCollisionShape()->setMargin(0.1);
psb->setTotalMass(1);
psb->setSpringStiffness(0);
psb->setDampingCoefficient(0.02);
psb->setDampingCoefficient(0.1);
psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects
psb->m_cfg.kCHR = 1; // collision hardness with rigid body
psb->m_cfg.kDF = 0;
psb->m_cfg.kDF = 2;
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
getDeformableDynamicsWorld()->addSoftBody(psb);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce());

View File

@ -234,7 +234,7 @@ void VolumetricDeformable::initPhysics()
psb->getCollisionShape()->setMargin(0.25);
// psb->generateBendingConstraints(2);
psb->setTotalMass(1);
psb->setSpringStiffness(1);
psb->setSpringStiffness(0);
psb->setDampingCoefficient(0.01);
psb->m_cfg.kKHR = 1; // collision hardness with kinematic objects
psb->m_cfg.kCHR = 1; // collision hardness with rigid body
@ -242,6 +242,7 @@ void VolumetricDeformable::initPhysics()
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce());
getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity));
getDeformableDynamicsWorld()->addForce(psb, new btDeformableCorotatedForce(.5,.5));
}
// add a few rigid bodies
Ctor_RbUpStack(4);

View File

@ -53,49 +53,6 @@ struct DeformableContactConstraint
}
};
struct DeformableFrictionConstraint
{
btAlignedObjectArray<bool> m_static; // whether the friction is static
btAlignedObjectArray<btScalar> m_impulse; // the impulse magnitude the node feels
btAlignedObjectArray<btScalar> m_dv; // the dv magnitude of the node
btAlignedObjectArray<btVector3> m_direction; // the direction of the friction for the node
btAlignedObjectArray<bool> m_static_prev;
btAlignedObjectArray<btScalar> m_impulse_prev;
btAlignedObjectArray<btScalar> m_dv_prev;
btAlignedObjectArray<btVector3> m_direction_prev;
btAlignedObjectArray<bool> m_released; // whether the contact is released
// the total impulse the node applied to the rb in the tangential direction in the cg solve
btAlignedObjectArray<btVector3> m_accumulated_tangent_impulse;
DeformableFrictionConstraint()
{
append();
}
void append()
{
m_static.push_back(false);
m_static_prev.push_back(false);
m_direction_prev.push_back(btVector3(0,0,0));
m_direction.push_back(btVector3(0,0,0));
m_impulse.push_back(0);
m_impulse_prev.push_back(0);
m_dv.push_back(0);
m_dv_prev.push_back(0);
m_accumulated_tangent_impulse.push_back(btVector3(0,0,0));
m_released.push_back(false);
}
};
class btCGProjection
{
public:
@ -104,7 +61,6 @@ public:
typedef btAlignedObjectArray<btAlignedObjectArray<btScalar> > TArrayStack;
btAlignedObjectArray<btSoftBody *>& m_softBodies;
btDeformableRigidDynamicsWorld* m_world;
// const btAlignedObjectArray<btSoftBody::Node*>* m_nodes;
const btScalar& m_dt;
btCGProjection(btAlignedObjectArray<btSoftBody *>& softBodies, const btScalar& dt)

View File

@ -19,6 +19,7 @@
btDeformableBodySolver::btDeformableBodySolver()
: m_numNodes(0)
, m_cg(10)
, m_contact_iterations(10)
{
m_objective = new btDeformableBackwardEulerObjective(m_softBodySet, m_backupVelocity);
}
@ -46,7 +47,7 @@ void btDeformableBodySolver::solveConstraints(float solverdt)
void btDeformableBodySolver::computeStep(TVStack& dv, const TVStack& residual)
{
btScalar tolerance = std::numeric_limits<float>::epsilon() * m_objective->computeNorm(residual);
btScalar tolerance = std::numeric_limits<float>::epsilon() * 1024 * m_objective->computeNorm(residual);
m_cg.solve(*m_objective, dv, residual, tolerance);
}
@ -76,7 +77,7 @@ void btDeformableBodySolver::setConstraints()
{
BT_PROFILE("setConstraint");
m_objective->setConstraints();
for (int i = 0; i < 10; ++i)
for (int i = 0; i < m_contact_iterations; ++i)
{
m_objective->projection.update();
m_objective->enforceConstraint(m_dv);

View File

@ -37,6 +37,7 @@ protected:
btAlignedObjectArray<btVector3> m_backupVelocity;
btScalar m_dt;
btScalar m_contact_iterations;
btConjugateGradient<btDeformableBackwardEulerObjective> m_cg;