implement pybullet.getContactPointData(), two optional object unique ids as filter
returns a pylist of contact points. Each point has the following data:
0 int m_contactFlags;//unused for now
1 int m_bodyUniqueIdA;
2 int m_bodyUniqueIdB;
3 int m_linkIndexA;
4 int m_linkIndexB;
5-6-7 double m_positionOnAInWS[3];//contact point location on object A, in world space coordinates
8-9-10 double m_positionOnBInWS[3];//contact point location on object A, in world space coordinates
11-12-13 double m_contactNormalOnBInWS[3];//the separating contact normal, pointing from object B towards object A
14 double m_contactDistance;//negative number is penetration, positive is distance.
15 double m_normalForce;
This commit is contained in:
@@ -39,6 +39,8 @@ struct PhysicsDirectInternalData
|
||||
btAlignedObjectArray<float> m_cachedCameraDepthBuffer;
|
||||
btAlignedObjectArray<int> m_cachedSegmentationMask;
|
||||
|
||||
btAlignedObjectArray<b3ContactPointData> m_cachedContactPoints;
|
||||
|
||||
|
||||
|
||||
PhysicsServerCommandProcessor* m_commandProcessor;
|
||||
@@ -193,6 +195,51 @@ bool PhysicsDirect::processDebugLines(const struct SharedMemoryCommand& orgComma
|
||||
return m_data->m_hasStatus;
|
||||
}
|
||||
|
||||
bool PhysicsDirect::processContactPointData(const struct SharedMemoryCommand& orgCommand)
|
||||
{
|
||||
SharedMemoryCommand command = orgCommand;
|
||||
|
||||
const SharedMemoryStatus& serverCmd = m_data->m_serverStatus;
|
||||
|
||||
do
|
||||
{
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(command,m_data->m_serverStatus,&m_data->m_bulletStreamDataServerToClient[0],SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
m_data->m_hasStatus = hasStatus;
|
||||
if (hasStatus)
|
||||
{
|
||||
if (m_data->m_verboseOutput)
|
||||
{
|
||||
b3Printf("Contact Point Information Request OK\n");
|
||||
}
|
||||
int startContactIndex = serverCmd.m_sendContactPointArgs.m_startingContactPointIndex;
|
||||
int numContactsCopied = serverCmd.m_sendContactPointArgs.m_numContactPointsCopied;
|
||||
|
||||
m_data->m_cachedContactPoints.resize(startContactIndex+numContactsCopied);
|
||||
|
||||
b3ContactPointData* contactData = (b3ContactPointData*)&m_data->m_bulletStreamDataServerToClient[0];
|
||||
|
||||
for (int i=0;i<numContactsCopied;i++)
|
||||
{
|
||||
m_data->m_cachedContactPoints[startContactIndex+i] = contactData[i];
|
||||
}
|
||||
|
||||
if (serverCmd.m_sendContactPointArgs.m_numRemainingContactPoints>0 && serverCmd.m_sendContactPointArgs.m_numContactPointsCopied)
|
||||
{
|
||||
command.m_type = CMD_REQUEST_CONTACT_POINT_INFORMATION;
|
||||
command.m_requestContactPointArguments.m_startingContactPointIndex = serverCmd.m_sendContactPointArgs.m_startingContactPointIndex+serverCmd.m_sendContactPointArgs.m_numContactPointsCopied;
|
||||
command.m_requestContactPointArguments.m_objectAIndexFilter = -1;
|
||||
command.m_requestContactPointArguments.m_objectBIndexFilter = -1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
} while (serverCmd.m_sendContactPointArgs.m_numRemainingContactPoints > 0 && serverCmd.m_sendContactPointArgs.m_numContactPointsCopied);
|
||||
|
||||
return m_data->m_hasStatus;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool PhysicsDirect::processCamera(const struct SharedMemoryCommand& orgCommand)
|
||||
{
|
||||
SharedMemoryCommand command = orgCommand;
|
||||
@@ -326,6 +373,10 @@ bool PhysicsDirect::submitClientCommand(const struct SharedMemoryCommand& comman
|
||||
{
|
||||
return processCamera(command);
|
||||
}
|
||||
if (command.m_type == CMD_REQUEST_CONTACT_POINT_INFORMATION)
|
||||
{
|
||||
return processContactPointData(command);
|
||||
}
|
||||
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(command,m_data->m_serverStatus,&m_data->m_bulletStreamDataServerToClient[0],SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
m_data->m_hasStatus = hasStatus;
|
||||
@@ -490,9 +541,8 @@ void PhysicsDirect::getCachedCameraImage(b3CameraImageData* cameraData)
|
||||
|
||||
void PhysicsDirect::getCachedContactPointInformation(struct b3ContactInformation* contactPointData)
|
||||
{
|
||||
if (contactPointData)
|
||||
{
|
||||
contactPointData->m_numContactPoints = 0;
|
||||
}
|
||||
contactPointData->m_numContactPoints = m_data->m_cachedContactPoints.size();
|
||||
contactPointData->m_contactPointData = contactPointData->m_numContactPoints? &m_data->m_cachedContactPoints[0] : 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user