diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 4c2d92e35..b3e1387ec 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -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; } diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index f1ab3460f..f28f89ea5 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -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) { diff --git a/src/BulletSoftBody/btSoftBody.h b/src/BulletSoftBody/btSoftBody.h index 954adf4d1..264d71279 100644 --- a/src/BulletSoftBody/btSoftBody.h +++ b/src/BulletSoftBody/btSoftBody.h @@ -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());