mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-14 05:40:05 +00:00
Allow to remove soft body anchors, using pybullet.removeConstraint (untested).
Usage example: anchors = [] anchors.append(p.createSoftBodyAnchor(clothId ,0,-1,-1)) anchors.append(p.createSoftBodyAnchor(clothId ,3,boxId,-1, [0.5,-0.5,0])) for a in anchors: p.removeConstraint(a)
This commit is contained in:
parent
84cb577622
commit
e6a0206d47
@ -310,9 +310,16 @@ struct InteralUserConstraintData
|
||||
|
||||
b3UserConstraint m_userConstraintData;
|
||||
|
||||
int m_sbHandle;
|
||||
int m_sbNodeIndex;
|
||||
btScalar m_sbNodeMass;
|
||||
|
||||
InteralUserConstraintData()
|
||||
: m_rbConstraint(0),
|
||||
m_mbConstraint(0)
|
||||
m_mbConstraint(0),
|
||||
m_sbHandle(-1),
|
||||
m_sbNodeIndex(-1),
|
||||
m_sbNodeMass(-1)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -11226,8 +11233,13 @@ bool PhysicsServerCommandProcessor::processCreateUserConstraintCommand(const str
|
||||
if (bodyUniqueId<=0)
|
||||
{
|
||||
//fixed anchor (mass = 0)
|
||||
InteralUserConstraintData userConstraintData;
|
||||
userConstraintData.m_sbHandle = clientCmd.m_userConstraintArguments.m_parentBodyIndex;
|
||||
userConstraintData.m_sbNodeIndex = nodeIndex;
|
||||
userConstraintData.m_sbNodeMass = sbodyHandle->m_softBody->getMass(nodeIndex);
|
||||
sbodyHandle->m_softBody->setMass(nodeIndex,0.0);
|
||||
int uid = m_data->m_userConstraintUIDGenerator++;
|
||||
m_data->m_userConstraints.insert(uid, userConstraintData);
|
||||
serverCmd.m_userConstraintResultArgs.m_userConstraintUniqueId = uid;
|
||||
serverCmd.m_type = CMD_USER_CONSTRAINT_COMPLETED;
|
||||
} else
|
||||
@ -11278,6 +11290,10 @@ bool PhysicsServerCommandProcessor::processCreateUserConstraintCommand(const str
|
||||
}
|
||||
int uid = m_data->m_userConstraintUIDGenerator++;
|
||||
serverCmd.m_userConstraintResultArgs.m_userConstraintUniqueId = uid;
|
||||
InteralUserConstraintData userConstraintData;
|
||||
userConstraintData.m_sbHandle = clientCmd.m_userConstraintArguments.m_parentBodyIndex;
|
||||
userConstraintData.m_sbNodeIndex = nodeIndex;
|
||||
m_data->m_userConstraints.insert(uid, userConstraintData);
|
||||
serverCmd.m_type = CMD_USER_CONSTRAINT_COMPLETED;
|
||||
|
||||
}
|
||||
@ -11740,6 +11756,24 @@ bool PhysicsServerCommandProcessor::processCreateUserConstraintCommand(const str
|
||||
delete userConstraintPtr->m_rbConstraint;
|
||||
m_data->m_userConstraints.remove(userConstraintUidRemove);
|
||||
}
|
||||
if (userConstraintPtr->m_sbHandle >= 0)
|
||||
{
|
||||
InternalBodyHandle* sbodyHandle = m_data->m_bodyHandles.getHandle(clientCmd.m_userConstraintArguments.m_parentBodyIndex);
|
||||
if (sbodyHandle)
|
||||
{
|
||||
if (sbodyHandle->m_softBody)
|
||||
{
|
||||
if (userConstraintPtr->m_sbNodeMass >= 0)
|
||||
{
|
||||
sbodyHandle->m_softBody->setMass(userConstraintPtr->m_sbNodeIndex, userConstraintPtr->m_sbNodeMass);
|
||||
}
|
||||
else
|
||||
{
|
||||
sbodyHandle->m_softBody->removeAnchor(userConstraintPtr->m_sbNodeIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
serverCmd.m_userConstraintResultArgs.m_userConstraintUniqueId = userConstraintUidRemove;
|
||||
serverCmd.m_type = CMD_REMOVE_USER_CONSTRAINT_COMPLETED;
|
||||
}
|
||||
|
@ -558,6 +558,25 @@ void btSoftBody::appendDeformableAnchor(int node, btRigidBody* body)
|
||||
m_deformableAnchors.push_back(c);
|
||||
}
|
||||
|
||||
void btSoftBody::removeAnchor(int node)
|
||||
{
|
||||
const btSoftBody::Node& n = m_nodes[node];
|
||||
for (int i = 0; i < m_deformableAnchors.size(); )
|
||||
{
|
||||
const DeformableNodeRigidAnchor& c = m_deformableAnchors[i];
|
||||
if (c.m_node == &n)
|
||||
{
|
||||
m_deformableAnchors.removeAtIndex(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
void btSoftBody::appendDeformableAnchor(int node, btMultiBodyLinkCollider* link)
|
||||
{
|
||||
|
@ -927,6 +927,7 @@ public:
|
||||
void appendAnchor(int node,
|
||||
btRigidBody* body, bool disableCollisionBetweenLinkedBodies = false, btScalar influence = 1);
|
||||
void appendAnchor(int node, btRigidBody* body, const btVector3& localPivot, bool disableCollisionBetweenLinkedBodies = false, btScalar influence = 1);
|
||||
void removeAnchor(int node);
|
||||
/* Append linear joint */
|
||||
void appendLinearJoint(const LJoint::Specs& specs, Cluster* body0, Body body1);
|
||||
void appendLinearJoint(const LJoint::Specs& specs, Body body = Body());
|
||||
|
Loading…
Reference in New Issue
Block a user