make one of the cubes in two_cubes.sdf static (immovable) using the <static> tag in SDF
add an example using 'direct' fix the send-desired-state commands, to add flags for arguments set, using default values. Start exposing SDF loading in shared memory api, not fully implemented yet.
This commit is contained in:
@@ -33,6 +33,12 @@ struct PhysicsDirectInternalData
|
||||
|
||||
char m_bulletStreamDataServerToClient[SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE];
|
||||
|
||||
int m_cachedCameraPixelsWidth;
|
||||
int m_cachedCameraPixelsHeight;
|
||||
btAlignedObjectArray<unsigned char> m_cachedCameraPixelsRGBA;
|
||||
btAlignedObjectArray<float> m_cachedCameraDepthBuffer;
|
||||
|
||||
|
||||
PhysicsServerCommandProcessor* m_commandProcessor;
|
||||
|
||||
PhysicsDirectInternalData()
|
||||
@@ -167,6 +173,73 @@ bool PhysicsDirect::processDebugLines(const struct SharedMemoryCommand& orgComma
|
||||
return m_data->m_hasStatus;
|
||||
}
|
||||
|
||||
bool PhysicsDirect::processCamera(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)
|
||||
{
|
||||
btAssert(m_data->m_serverStatus.m_type == CMD_CAMERA_IMAGE_COMPLETED);
|
||||
|
||||
if (m_data->m_verboseOutput)
|
||||
{
|
||||
b3Printf("Camera image OK\n");
|
||||
}
|
||||
|
||||
int numBytesPerPixel = 4;//RGBA
|
||||
int numTotalPixels = serverCmd.m_sendPixelDataArguments.m_startingPixelIndex+
|
||||
serverCmd.m_sendPixelDataArguments.m_numPixelsCopied+
|
||||
serverCmd.m_sendPixelDataArguments.m_numRemainingPixels;
|
||||
|
||||
m_data->m_cachedCameraPixelsWidth = 0;
|
||||
m_data->m_cachedCameraPixelsHeight = 0;
|
||||
|
||||
int numPixels = serverCmd.m_sendPixelDataArguments.m_imageWidth*serverCmd.m_sendPixelDataArguments.m_imageHeight;
|
||||
|
||||
m_data->m_cachedCameraPixelsRGBA.reserve(numPixels*numBytesPerPixel);
|
||||
m_data->m_cachedCameraDepthBuffer.resize(numTotalPixels);
|
||||
m_data->m_cachedCameraPixelsRGBA.resize(numTotalPixels*numBytesPerPixel);
|
||||
|
||||
|
||||
unsigned char* rgbaPixelsReceived =
|
||||
(unsigned char*)&m_data->m_bulletStreamDataServerToClient[0];
|
||||
printf("pixel = %d\n", rgbaPixelsReceived[0]);
|
||||
|
||||
for (int i=0;i<serverCmd.m_sendPixelDataArguments.m_numPixelsCopied*numBytesPerPixel;i++)
|
||||
{
|
||||
m_data->m_cachedCameraPixelsRGBA[i + serverCmd.m_sendPixelDataArguments.m_startingPixelIndex*numBytesPerPixel]
|
||||
= rgbaPixelsReceived[i];
|
||||
}
|
||||
|
||||
if (serverCmd.m_sendPixelDataArguments.m_numRemainingPixels > 0)
|
||||
{
|
||||
|
||||
|
||||
// continue requesting remaining pixels
|
||||
command.m_type = CMD_REQUEST_CAMERA_IMAGE_DATA;
|
||||
command.m_requestPixelDataArguments.m_startPixelIndex =
|
||||
serverCmd.m_sendPixelDataArguments.m_startingPixelIndex +
|
||||
serverCmd.m_sendPixelDataArguments.m_numPixelsCopied;
|
||||
} else
|
||||
{
|
||||
m_data->m_cachedCameraPixelsWidth = serverCmd.m_sendPixelDataArguments.m_imageWidth;
|
||||
m_data->m_cachedCameraPixelsHeight = serverCmd.m_sendPixelDataArguments.m_imageHeight;
|
||||
}
|
||||
}
|
||||
} while (serverCmd.m_sendPixelDataArguments.m_numRemainingPixels > 0);
|
||||
|
||||
return m_data->m_hasStatus;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool PhysicsDirect::submitClientCommand(const struct SharedMemoryCommand& command)
|
||||
{
|
||||
if (command.m_type==CMD_REQUEST_DEBUG_LINES)
|
||||
@@ -174,6 +247,11 @@ bool PhysicsDirect::submitClientCommand(const struct SharedMemoryCommand& comman
|
||||
return processDebugLines(command);
|
||||
}
|
||||
|
||||
if (command.m_type==CMD_REQUEST_CAMERA_IMAGE_DATA)
|
||||
{
|
||||
return processCamera(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;
|
||||
if (hasStatus)
|
||||
@@ -333,9 +411,9 @@ void PhysicsDirect::getCachedCameraImage(b3CameraImageData* cameraData)
|
||||
{
|
||||
if (cameraData)
|
||||
{
|
||||
cameraData->m_pixelHeight = 0;
|
||||
cameraData->m_pixelWidth = 0;
|
||||
cameraData->m_depthValues = 0;
|
||||
cameraData->m_rgbColorData = 0;
|
||||
cameraData->m_pixelWidth = m_data->m_cachedCameraPixelsWidth;
|
||||
cameraData->m_pixelHeight = m_data->m_cachedCameraPixelsHeight;
|
||||
cameraData->m_depthValues = m_data->m_cachedCameraDepthBuffer.size() ? &m_data->m_cachedCameraDepthBuffer[0] : 0;
|
||||
cameraData->m_rgbColorData = m_data->m_cachedCameraPixelsRGBA.size() ? &m_data->m_cachedCameraPixelsRGBA[0] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user