breakable constraints

Physics APIs, Physics file formats, Maya, Max, XSI, Cinema 4D, Lightwave, Blender, thinkingParticles™ and other simulation tools, exporters and importers
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

breakable constraints

Post by Erwin Coumans »

To trigger breaking chains, collapsing bridges etc. there is a new getAppliedImpulse to measure 'stress' on the constraints. A bridge can be build using 'hinge' constraint, or a bunch of point-to-point constraints.

The stress/appliedImpulse can be read out in the very latest RC3 preview43 build, see the included breaking_chain.blend.

Win32:
http://www.continuousphysics.com/ftp/pu ... indows.zip

Linux:
http://www.continuousphysics.com/ftp/pu ... view43.tgz

Code: Select all

#shows breaking constraints dependent on constraint 'appliedImpulse'
import PhysicsConstraints
import GameLogic
ob = GameLogic.getCurrentController().getOwner()
#ob.id points to the constraint id
imp1 = PhysicsConstraints.getAppliedImpulse(ob.id)
imp = imp1*imp1
print imp
breakingTreshold = 0.82
if imp>breakingTreshold:
    PhysicsConstraints.removeConstraint(ob.id)


Erwin
RJNelson68
Posts: 73
Joined: Tue Oct 06, 2009 3:19 pm

Re: breakable constraints

Post by RJNelson68 »

I realize this is an old post, but where could you detect the constraint's id? I am just looking for a place that this could be utilized becasue as far as I can tell the forces applied to the joints are not exposed to use something like this.
RJNelson68
Posts: 73
Joined: Tue Oct 06, 2009 3:19 pm

Re: breakable constraints

Post by RJNelson68 »

OK I have a nearly working system but I need to access the btDiscreteDynamicsWorld from btRigidBody to perform the removeConstraint function.

Code: Select all

void btRigidBody::checkToBreakConstraints()
{
	for (int i = 0; i < m_constraintRefs.size(); ++i)
	{
		btTypedConstraint* constraint = m_constraintRefs[i];
		if(constraint->getBreakable())
		{
			btScalar imp1 = constraint->getAppliedImpulse();
			btScalar imp = imp1 * imp1;
			if(imp > constraint->getBreakThreshold())
        }
	}
}
As you can tell I added a flag and a float to use for detecting if the joint is breakable and what the break threshold would be. Can someone tell me how to access the world so I can call the function?