delete forces in exitPhysics

This commit is contained in:
Xuchen Han
2019-08-21 23:00:18 -07:00
parent b93c3c56ed
commit 3fbd7a7edd
5 changed files with 86 additions and 25 deletions

View File

@@ -49,6 +49,7 @@ static bool g_floatingBase = true;
static float friction = 1.; static float friction = 1.;
class DeformableMultibody : public CommonMultiBodyBase class DeformableMultibody : public CommonMultiBodyBase
{ {
btAlignedObjectArray<btDeformableLagrangianForce*> forces;
public: public:
DeformableMultibody(struct GUIHelperInterface* helper) DeformableMultibody(struct GUIHelperInterface* helper)
: CommonMultiBodyBase(helper) : CommonMultiBodyBase(helper)
@@ -122,7 +123,6 @@ void DeformableMultibody::initPhysics()
m_solver = sol; m_solver = sol;
m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver); m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver);
// deformableBodySolver->setWorld(getDeformableDynamicsWorld());
btVector3 gravity = btVector3(0, -10, 0); btVector3 gravity = btVector3(0, -10, 0);
m_dynamicsWorld->setGravity(gravity); m_dynamicsWorld->setGravity(gravity);
getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity; getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity;
@@ -224,8 +224,14 @@ void DeformableMultibody::initPhysics()
psb->m_cfg.kDF = .1; psb->m_cfg.kDF = .1;
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
getDeformableDynamicsWorld()->addSoftBody(psb); getDeformableDynamicsWorld()->addSoftBody(psb);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce(2, 0.01, false));
getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity)); btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(2, 0.01, false);
getDeformableDynamicsWorld()->addForce(psb, mass_spring);
forces.push_back(mass_spring);
btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity);
getDeformableDynamicsWorld()->addForce(psb, gravity_force);
forces.push_back(gravity_force);
} }
m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
@@ -248,7 +254,12 @@ void DeformableMultibody::exitPhysics()
m_dynamicsWorld->removeCollisionObject(obj); m_dynamicsWorld->removeCollisionObject(obj);
delete obj; delete obj;
} }
// delete forces
for (int j = 0; j < forces.size(); j++)
{
btDeformableLagrangianForce* force = forces[j];
delete force;
}
//delete collision shapes //delete collision shapes
for (int j = 0; j < m_collisionShapes.size(); j++) for (int j = 0; j < m_collisionShapes.size(); j++)
{ {

View File

@@ -44,6 +44,7 @@
///Generally it is best to leave the rolling friction coefficient zero (or close to zero). ///Generally it is best to leave the rolling friction coefficient zero (or close to zero).
class DeformableRigid : public CommonRigidBodyBase class DeformableRigid : public CommonRigidBodyBase
{ {
btAlignedObjectArray<btDeformableLagrangianForce*> forces;
public: public:
DeformableRigid(struct GUIHelperInterface* helper) DeformableRigid(struct GUIHelperInterface* helper)
: CommonRigidBodyBase(helper) : CommonRigidBodyBase(helper)
@@ -233,9 +234,14 @@ void DeformableRigid::initPhysics()
psb->m_cfg.kDF = 1; psb->m_cfg.kDF = 1;
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
getDeformableDynamicsWorld()->addSoftBody(psb); getDeformableDynamicsWorld()->addSoftBody(psb);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce(2, 0.01, false));
getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity));
btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(2,0.01, false);
getDeformableDynamicsWorld()->addForce(psb, mass_spring);
forces.push_back(mass_spring);
btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity);
getDeformableDynamicsWorld()->addForce(psb, gravity_force);
forces.push_back(gravity_force);
// add a few rigid bodies // add a few rigid bodies
Ctor_RbUpStack(1); Ctor_RbUpStack(1);
} }
@@ -259,7 +265,12 @@ void DeformableRigid::exitPhysics()
m_dynamicsWorld->removeCollisionObject(obj); m_dynamicsWorld->removeCollisionObject(obj);
delete obj; delete obj;
} }
// delete forces
for (int j = 0; j < forces.size(); j++)
{
btDeformableLagrangianForce* force = forces[j];
delete force;
}
//delete collision shapes //delete collision shapes
for (int j = 0; j < m_collisionShapes.size(); j++) for (int j = 0; j < m_collisionShapes.size(); j++)
{ {

View File

@@ -59,6 +59,7 @@ static bool supportsJointMotor(btMultiBody* mb, int mbLinkIndex)
class GraspDeformable : public CommonRigidBodyBase class GraspDeformable : public CommonRigidBodyBase
{ {
btAlignedObjectArray<btDeformableLagrangianForce*> forces;
public: public:
GraspDeformable(struct GUIHelperInterface* helper) GraspDeformable(struct GUIHelperInterface* helper)
: CommonRigidBodyBase(helper) : CommonRigidBodyBase(helper)
@@ -355,11 +356,17 @@ void GraspDeformable::initPhysics()
// getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity)); // getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity));
// getDeformableDynamicsWorld()->addForce(psb, new btDeformableCorotatedForce(0,6)); // getDeformableDynamicsWorld()->addForce(psb, new btDeformableCorotatedForce(0,6));
// linear damping btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(.5,0.04, true);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce(.5,0.04, true)); getDeformableDynamicsWorld()->addForce(psb, mass_spring);
// getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce(3,0.04, true)); forces.push_back(mass_spring);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity));
getDeformableDynamicsWorld()->addForce(psb, new btDeformableNeoHookeanForce(2,10)); btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity);
getDeformableDynamicsWorld()->addForce(psb, gravity_force);
forces.push_back(gravity_force);
btDeformableNeoHookeanForce* neohookean = new btDeformableNeoHookeanForce(2,10);
getDeformableDynamicsWorld()->addForce(psb, neohookean);
forces.push_back(neohookean);
} }
// // create a piece of cloth // // create a piece of cloth
@@ -431,7 +438,12 @@ void GraspDeformable::exitPhysics()
m_dynamicsWorld->removeCollisionObject(obj); m_dynamicsWorld->removeCollisionObject(obj);
delete obj; delete obj;
} }
// delete forces
for (int j = 0; j < forces.size(); j++)
{
btDeformableLagrangianForce* force = forces[j];
delete force;
}
//delete collision shapes //delete collision shapes
for (int j = 0; j < m_collisionShapes.size(); j++) for (int j = 0; j < m_collisionShapes.size(); j++)
{ {

View File

@@ -56,6 +56,7 @@ struct TetraBunny
class Pinch : public CommonRigidBodyBase class Pinch : public CommonRigidBodyBase
{ {
btAlignedObjectArray<btDeformableLagrangianForce*> forces;
public: public:
Pinch(struct GUIHelperInterface* helper) Pinch(struct GUIHelperInterface* helper)
: CommonRigidBodyBase(helper) : CommonRigidBodyBase(helper)
@@ -248,8 +249,6 @@ void Pinch::initPhysics()
m_solver = sol; m_solver = sol;
m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver); m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver);
// deformableBodySolver->setWorld(getDeformableDynamicsWorld());
// m_dynamicsWorld->getSolverInfo().m_singleAxisDeformableThreshold = 0.f;//faster but lower quality
btVector3 gravity = btVector3(0, -10, 0); btVector3 gravity = btVector3(0, -10, 0);
m_dynamicsWorld->setGravity(gravity); m_dynamicsWorld->setGravity(gravity);
getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity; getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity;
@@ -336,9 +335,18 @@ void Pinch::initPhysics()
psb->m_cfg.kDF = 2; psb->m_cfg.kDF = 2;
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
getDeformableDynamicsWorld()->addSoftBody(psb); getDeformableDynamicsWorld()->addSoftBody(psb);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce(1, 0.05));
getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity)); btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(1,0.05);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableNeoHookeanForce(.2,1)); getDeformableDynamicsWorld()->addForce(psb, mass_spring);
forces.push_back(mass_spring);
btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity);
getDeformableDynamicsWorld()->addForce(psb, gravity_force);
forces.push_back(gravity_force);
btDeformableNeoHookeanForce* neohookean = new btDeformableNeoHookeanForce(.2,1);
getDeformableDynamicsWorld()->addForce(psb, neohookean);
forces.push_back(neohookean);
// add a grippers // add a grippers
createGrip(); createGrip();
} }
@@ -362,7 +370,12 @@ void Pinch::exitPhysics()
m_dynamicsWorld->removeCollisionObject(obj); m_dynamicsWorld->removeCollisionObject(obj);
delete obj; delete obj;
} }
// delete forces
for (int j = 0; j < forces.size(); j++)
{
btDeformableLagrangianForce* force = forces[j];
delete force;
}
//delete collision shapes //delete collision shapes
for (int j = 0; j < m_collisionShapes.size(); j++) for (int j = 0; j < m_collisionShapes.size(); j++)
{ {

View File

@@ -51,6 +51,7 @@ struct TetraCube
class VolumetricDeformable : public CommonRigidBodyBase class VolumetricDeformable : public CommonRigidBodyBase
{ {
btAlignedObjectArray<btDeformableLagrangianForce*> forces;
public: public:
VolumetricDeformable(struct GUIHelperInterface* helper) VolumetricDeformable(struct GUIHelperInterface* helper)
: CommonRigidBodyBase(helper) : CommonRigidBodyBase(helper)
@@ -177,13 +178,10 @@ void VolumetricDeformable::initPhysics()
m_broadphase = new btDbvtBroadphase(); m_broadphase = new btDbvtBroadphase();
btDeformableBodySolver* deformableBodySolver = new btDeformableBodySolver(); btDeformableBodySolver* deformableBodySolver = new btDeformableBodySolver();
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btMultiBodyConstraintSolver* sol = new btMultiBodyConstraintSolver(); btMultiBodyConstraintSolver* sol = new btMultiBodyConstraintSolver();
m_solver = sol; m_solver = sol;
m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver); m_dynamicsWorld = new btDeformableMultiBodyDynamicsWorld(m_dispatcher, m_broadphase, sol, m_collisionConfiguration, deformableBodySolver);
// deformableBodySolver->setWorld(getDeformableDynamicsWorld());
// m_dynamicsWorld->getSolverInfo().m_singleAxisDeformableThreshold = 0.f;//faster but lower quality
btVector3 gravity = btVector3(0, -10, 0); btVector3 gravity = btVector3(0, -10, 0);
m_dynamicsWorld->setGravity(gravity); m_dynamicsWorld->setGravity(gravity);
getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity; getDeformableDynamicsWorld()->getWorldInfo().m_gravity = gravity;
@@ -236,9 +234,19 @@ void VolumetricDeformable::initPhysics()
psb->m_cfg.kCHR = 1; // collision hardness with rigid body psb->m_cfg.kCHR = 1; // collision hardness with rigid body
psb->m_cfg.kDF = 0.5; psb->m_cfg.kDF = 0.5;
psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD; psb->m_cfg.collisions = btSoftBody::fCollision::SDF_RD;
getDeformableDynamicsWorld()->addForce(psb, new btDeformableMassSpringForce(0,0.03));
getDeformableDynamicsWorld()->addForce(psb, new btDeformableGravityForce(gravity)); btDeformableMassSpringForce* mass_spring = new btDeformableMassSpringForce(0,0.03);
getDeformableDynamicsWorld()->addForce(psb, new btDeformableNeoHookeanForce(.5,2.5)); getDeformableDynamicsWorld()->addForce(psb, mass_spring);
forces.push_back(mass_spring);
btDeformableGravityForce* gravity_force = new btDeformableGravityForce(gravity);
getDeformableDynamicsWorld()->addForce(psb, gravity_force);
forces.push_back(gravity_force);
btDeformableNeoHookeanForce* neohookean = new btDeformableNeoHookeanForce(.5,2.5);
getDeformableDynamicsWorld()->addForce(psb, neohookean);
forces.push_back(neohookean);
} }
// add a few rigid bodies // add a few rigid bodies
Ctor_RbUpStack(4); Ctor_RbUpStack(4);
@@ -263,6 +271,12 @@ void VolumetricDeformable::exitPhysics()
m_dynamicsWorld->removeCollisionObject(obj); m_dynamicsWorld->removeCollisionObject(obj);
delete obj; delete obj;
} }
// delete forces
for (int j = 0; j < forces.size(); j++)
{
btDeformableLagrangianForce* force = forces[j];
delete force;
}
//delete collision shapes //delete collision shapes
for (int j = 0; j < m_collisionShapes.size(); j++) for (int j = 0; j < m_collisionShapes.size(); j++)