summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaarten Behn <maarten.behn@gmail.com>2022-12-19 15:31:21 +0100
committerMaarten Behn <maarten.behn@gmail.com>2022-12-19 15:31:21 +0100
commit9dd446609a7a9af8b5a586a67ab57019edbc2328 (patch)
tree7b7fa1099975061b9ae37010bb8bc3b022451439
parent60512c7872eb42a460920c8823f7692e00530e90 (diff)
downloadbullet3-9dd446609a7a9af8b5a586a67ab57019edbc2328.tar.gz
Adding getTetraMeshData()
-rw-r--r--examples/SharedMemory/PhysicsServerCommandProcessor.cpp53
-rw-r--r--examples/SharedMemory/PhysicsServerCommandProcessor.h1
-rw-r--r--examples/SharedMemory/SharedMemoryPublic.h5
3 files changed, 59 insertions, 0 deletions
diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp
index 376e833a6..081b6e204 100644
--- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp
+++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp
@@ -5718,6 +5718,54 @@ bool PhysicsServerCommandProcessor::processRequestMeshDataCommand(const struct S
return hasStatus;
}
+bool PhysicsServerCommandProcessor::processRequestTetraMeshDataCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes)
+{
+ bool hasStatus = true;
+ BT_PROFILE("CMD_REQUEST_MESH_DATA");
+ serverStatusOut.m_type = CMD_REQUEST_MESH_DATA_FAILED;
+ serverStatusOut.m_numDataStreamBytes = 0;
+ int sizeInBytes = 0;
+
+ InternalBodyHandle* bodyHandle = m_data->m_bodyHandles.getHandle(clientCmd.m_requestMeshDataArgs.m_bodyUniqueId);
+ if (bodyHandle)
+ {
+ int totalBytesPerTetra = sizeof(btVector3) * 4;
+ btVector3* verticesOut = (btVector3*)bufferServerToClient;
+ const btCollisionShape* colShape = 0;
+
+#ifndef SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD
+
+ if (bodyHandle->m_softBody)
+ {
+ btSoftBody* psb = bodyHandle->m_softBody;
+
+ int numTetra = psb->m_tetras.size();
+ int maxNumnumVertecies = bufferSizeInBytes / totalBytesPerTetra - 1;
+ int numVerticesRemaining = numTetra * 4 - clientCmd.m_requestMeshDataArgs.m_startingVertex;
+ int verticesCopied = btMin(maxNumnumVertecies, numVerticesRemaining);
+ for (int i = 0; i < verticesCopied; i += 4)
+ {
+ const btSoftBody::Tetra& n = psb->m_tetras[i / 4];
+
+ verticesOut[i].setValue(n.m_n[0].m_x.x(), n.m_n[0].m_x.y(), n.m_n[0].m_x.z());
+ verticesOut[i+1].setValue(n.m_n[1].m_x.x(), n.m_n[1].m_x.y(), n.m_n[1].m_x.z());
+ verticesOut[i+2].setValue(n.m_n[2].m_x.x(), n.m_n[2].m_x.y(), n.m_n[2].m_x.z());
+ verticesOut[i+3].setValue(n.m_n[3].m_x.x(), n.m_n[3].m_x.y(), n.m_n[3].m_x.z());
+ }
+ sizeInBytes = verticesCopied * sizeof(btVector3);
+ serverStatusOut.m_type = CMD_REQUEST_TETRA_MESH_DATA_COMPLETED;
+ serverStatusOut.m_sendMeshDataArgs.m_numVerticesCopied = verticesCopied;
+ serverStatusOut.m_sendMeshDataArgs.m_startingVertex = clientCmd.m_requestMeshDataArgs.m_startingVertex;
+ serverStatusOut.m_sendMeshDataArgs.m_numVerticesRemaining = numVerticesRemaining - verticesCopied;
+ }
+#endif //SKIP_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD
+ }
+
+ serverStatusOut.m_numDataStreamBytes = sizeInBytes;
+
+ return hasStatus;
+}
+
bool PhysicsServerCommandProcessor::processCreateVisualShapeCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes)
{
bool hasStatus = true;
@@ -15120,6 +15168,11 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
hasStatus = processRequestMeshDataCommand(clientCmd, serverStatusOut, bufferServerToClient, bufferSizeInBytes);
break;
}
+ case CMD_REQUEST_TETRA_MESH_DATA:
+ {
+ hasStatus = processRequestTetraMeshDataCommand(clientCmd, serverStatusOut, bufferServerToClient, bufferSizeInBytes);
+ break;
+ }
case CMD_RESET_MESH_DATA:
{
hasStatus = processResetMeshDataCommand(clientCmd, serverStatusOut, bufferServerToClient, bufferSizeInBytes);
diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.h b/examples/SharedMemory/PhysicsServerCommandProcessor.h
index fb23a1bb9..4035d7d0c 100644
--- a/examples/SharedMemory/PhysicsServerCommandProcessor.h
+++ b/examples/SharedMemory/PhysicsServerCommandProcessor.h
@@ -32,6 +32,7 @@ protected:
bool processCreateCollisionShapeCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
bool processCreateVisualShapeCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
bool processRequestMeshDataCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
+ bool processRequestTetraMeshDataCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
bool processResetMeshDataCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
bool processCustomCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
bool processUserDebugDrawCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
diff --git a/examples/SharedMemory/SharedMemoryPublic.h b/examples/SharedMemory/SharedMemoryPublic.h
index 7541ddb5a..c209d5bf4 100644
--- a/examples/SharedMemory/SharedMemoryPublic.h
+++ b/examples/SharedMemory/SharedMemoryPublic.h
@@ -118,6 +118,8 @@ enum EnumSharedMemoryClientCommand
CMD_PERFORM_COLLISION_DETECTION,
CMD_RESET_MESH_DATA,
+
+ CMD_REQUEST_TETRA_MESH_DATA,
//don't go beyond this command!
CMD_MAX_CLIENT_COMMANDS,
};
@@ -244,6 +246,9 @@ enum EnumSharedMemoryServerStatus
CMD_PERFORM_COLLISION_DETECTION_COMPLETED,
CMD_RESET_MESH_DATA_COMPLETED,
CMD_RESET_MESH_DATA_FAILED,
+
+ CMD_REQUEST_TETRA_MESH_DATA_COMPLETED,
+ CMD_REQUEST_TETRA_MESH_DATA_FAILED,
//don't go beyond 'CMD_MAX_SERVER_COMMANDS!
CMD_MAX_SERVER_COMMANDS
};