setDebugObjectColor
This commit is contained in:
@@ -1195,6 +1195,46 @@ int b3GetDebugItemUniqueId(b3SharedMemoryStatusHandle statusHandle)
|
||||
return status->m_userDebugDrawArgs.m_debugItemUniqueId;
|
||||
}
|
||||
|
||||
b3SharedMemoryCommandHandle b3InitDebugDrawingCommand(b3PhysicsClientHandle physClient)
|
||||
{
|
||||
PhysicsClient* cl = (PhysicsClient*)physClient;
|
||||
b3Assert(cl);
|
||||
b3Assert(cl->canSubmitCommand());
|
||||
struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand();
|
||||
b3Assert(command);
|
||||
command->m_type = CMD_USER_DEBUG_DRAW;
|
||||
command->m_updateFlags = 0;
|
||||
return (b3SharedMemoryCommandHandle)command;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void b3SetDebugObjectColor(b3SharedMemoryCommandHandle commandHandle, int objectUniqueId, int linkIndex, double objectColorRGB[3])
|
||||
{
|
||||
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*) commandHandle;
|
||||
b3Assert(command);
|
||||
b3Assert(command->m_type == CMD_USER_DEBUG_DRAW);
|
||||
command->m_updateFlags |= USER_DEBUG_SET_CUSTOM_OBJECT_COLOR;
|
||||
command->m_userDebugDrawArgs.m_objectUniqueId = objectUniqueId;
|
||||
command->m_userDebugDrawArgs.m_linkIndex = linkIndex;
|
||||
command->m_userDebugDrawArgs.m_objectDebugColorRGB[0] = objectColorRGB[0];
|
||||
command->m_userDebugDrawArgs.m_objectDebugColorRGB[1] = objectColorRGB[1];
|
||||
command->m_userDebugDrawArgs.m_objectDebugColorRGB[2] = objectColorRGB[2];
|
||||
}
|
||||
|
||||
void b3RemoveDebugObjectColor(b3SharedMemoryCommandHandle commandHandle, int objectUniqueId, int linkIndex)
|
||||
{
|
||||
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*) commandHandle;
|
||||
b3Assert(command);
|
||||
b3Assert(command->m_type == CMD_USER_DEBUG_DRAW);
|
||||
command->m_updateFlags |= USER_DEBUG_REMOVE_CUSTOM_OBJECT_COLOR;
|
||||
command->m_userDebugDrawArgs.m_objectUniqueId = objectUniqueId;
|
||||
command->m_userDebugDrawArgs.m_linkIndex = linkIndex;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///request an image from a simulated camera, using a software renderer.
|
||||
b3SharedMemoryCommandHandle b3InitRequestCameraImage(b3PhysicsClientHandle physClient)
|
||||
@@ -1244,6 +1284,17 @@ void b3RequestCameraImageSetLightDirection(b3SharedMemoryCommandHandle commandHa
|
||||
command->m_updateFlags |= REQUEST_PIXEL_ARGS_SET_LIGHT_DIRECTION;
|
||||
}
|
||||
|
||||
void b3RequestCameraImageSetLightColor(b3SharedMemoryCommandHandle commandHandle, const float lightColor[3])
|
||||
{
|
||||
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*) commandHandle;
|
||||
b3Assert(command);
|
||||
b3Assert(command->m_type == CMD_REQUEST_CAMERA_IMAGE_DATA);
|
||||
for (int i = 0; i<3; i++)
|
||||
{
|
||||
command->m_requestPixelDataArguments.m_lightColor[i] = lightColor[i];
|
||||
}
|
||||
command->m_updateFlags |= REQUEST_PIXEL_ARGS_SET_LIGHT_COLOR;
|
||||
}
|
||||
|
||||
void b3ComputeViewMatrixFromPositions(const float cameraPosition[3], const float cameraTargetPosition[3], const float cameraUp[3], float viewMatrix[16])
|
||||
{
|
||||
|
||||
@@ -89,14 +89,21 @@ b3SharedMemoryCommandHandle b3InitUserDebugDrawAddLine3D(b3PhysicsClientHandle p
|
||||
b3SharedMemoryCommandHandle b3InitUserDebugDrawAddText3D(b3PhysicsClientHandle physClient, const char* txt, double positionXYZ[3], double colorRGB[3], double textSize, double lifeTime);
|
||||
b3SharedMemoryCommandHandle b3InitUserDebugDrawRemove(b3PhysicsClientHandle physClient, int debugItemUniqueId);
|
||||
b3SharedMemoryCommandHandle b3InitUserDebugDrawRemoveAll(b3PhysicsClientHandle physClient);
|
||||
|
||||
b3SharedMemoryCommandHandle b3InitDebugDrawingCommand(b3PhysicsClientHandle physClient);
|
||||
void b3SetDebugObjectColor(b3SharedMemoryCommandHandle commandHandle, int objectUniqueId, int linkIndex, double objectColorRGB[3]);
|
||||
void b3RemoveDebugObjectColor(b3SharedMemoryCommandHandle commandHandle, int objectUniqueId, int linkIndex);
|
||||
|
||||
///All debug items unique Ids are positive: a negative unique Id means failure.
|
||||
int b3GetDebugItemUniqueId(b3SharedMemoryStatusHandle statusHandle);
|
||||
|
||||
|
||||
///request an image from a simulated camera, using a software renderer.
|
||||
b3SharedMemoryCommandHandle b3InitRequestCameraImage(b3PhysicsClientHandle physClient);
|
||||
void b3RequestCameraImageSetCameraMatrices(b3SharedMemoryCommandHandle command, float viewMatrix[16], float projectionMatrix[16]);
|
||||
void b3RequestCameraImageSetPixelResolution(b3SharedMemoryCommandHandle command, int width, int height );
|
||||
void b3RequestCameraImageSetLightDirection(b3SharedMemoryCommandHandle commandHandle, const float lightDirection[3]);
|
||||
void b3RequestCameraImageSetLightColor(b3SharedMemoryCommandHandle commandHandle, const float lightColor[3]);
|
||||
void b3RequestCameraImageSelectRenderer(b3SharedMemoryCommandHandle commandHandle, int renderer);
|
||||
void b3GetCameraImageData(b3PhysicsClientHandle physClient, struct b3CameraImageData* imageData);
|
||||
|
||||
|
||||
@@ -3531,7 +3531,6 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
||||
for( int i=0;i<numRb;i++)
|
||||
{
|
||||
btCollisionObject* colObj = importer->getRigidBodyByIndex(i);
|
||||
|
||||
if (colObj)
|
||||
{
|
||||
btRigidBody* rb = btRigidBody::upcast(colObj);
|
||||
@@ -3594,7 +3593,54 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
|
||||
SharedMemoryStatus& serverCmd = serverStatusOut;
|
||||
serverCmd.m_type = CMD_USER_DEBUG_DRAW_FAILED;
|
||||
hasStatus = true;
|
||||
|
||||
|
||||
if ((clientCmd.m_updateFlags & USER_DEBUG_SET_CUSTOM_OBJECT_COLOR) || (clientCmd.m_updateFlags & USER_DEBUG_REMOVE_CUSTOM_OBJECT_COLOR))
|
||||
{
|
||||
int bodyUniqueId = clientCmd.m_userDebugDrawArgs.m_objectUniqueId;
|
||||
InteralBodyData* body = m_data->getHandle(bodyUniqueId);
|
||||
if (body)
|
||||
{
|
||||
btCollisionObject* destColObj = 0;
|
||||
|
||||
if (body->m_multiBody)
|
||||
{
|
||||
if (clientCmd.m_userDebugDrawArgs.m_linkIndex == -1)
|
||||
{
|
||||
destColObj = body->m_multiBody->getBaseCollider();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (clientCmd.m_userDebugDrawArgs.m_linkIndex >= 0 && clientCmd.m_userDebugDrawArgs.m_linkIndex < body->m_multiBody->getNumLinks())
|
||||
{
|
||||
destColObj = body->m_multiBody->getLink(clientCmd.m_userDebugDrawArgs.m_linkIndex).m_collider;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (body->m_rigidBody)
|
||||
{
|
||||
destColObj = body->m_rigidBody;
|
||||
}
|
||||
|
||||
if (destColObj)
|
||||
{
|
||||
if (clientCmd.m_updateFlags & USER_DEBUG_REMOVE_CUSTOM_OBJECT_COLOR)
|
||||
{
|
||||
destColObj->removeCustomDebugColor();
|
||||
serverCmd.m_type = CMD_USER_DEBUG_DRAW_COMPLETED;
|
||||
}
|
||||
if (clientCmd.m_updateFlags & USER_DEBUG_SET_CUSTOM_OBJECT_COLOR)
|
||||
{
|
||||
btVector3 objectColorRGB;
|
||||
objectColorRGB.setValue(clientCmd.m_userDebugDrawArgs.m_objectDebugColorRGB[0],
|
||||
clientCmd.m_userDebugDrawArgs.m_objectDebugColorRGB[1],
|
||||
clientCmd.m_userDebugDrawArgs.m_objectDebugColorRGB[2]);
|
||||
destColObj->setCustomDebugColor(objectColorRGB);
|
||||
serverCmd.m_type = CMD_USER_DEBUG_DRAW_COMPLETED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (clientCmd.m_updateFlags & USER_DEBUG_HAS_TEXT)
|
||||
{
|
||||
|
||||
@@ -139,13 +139,15 @@ struct RequestPixelDataArgs
|
||||
int m_pixelWidth;
|
||||
int m_pixelHeight;
|
||||
float m_lightDirection[3];
|
||||
float m_lightColor[3];
|
||||
};
|
||||
|
||||
enum EnumRequestPixelDataUpdateFlags
|
||||
{
|
||||
REQUEST_PIXEL_ARGS_HAS_CAMERA_MATRICES=1,
|
||||
REQUEST_PIXEL_ARGS_SET_PIXEL_WIDTH_HEIGHT=4,
|
||||
REQUEST_PIXEL_ARGS_SET_LIGHT_DIRECTION=8,
|
||||
REQUEST_PIXEL_ARGS_SET_PIXEL_WIDTH_HEIGHT=2,
|
||||
REQUEST_PIXEL_ARGS_SET_LIGHT_DIRECTION=4,
|
||||
REQUEST_PIXEL_ARGS_SET_LIGHT_COLOR=8,
|
||||
//don't exceed (1<<15), because this enum is shared with EnumRenderer in SharedMemoryPublic.h
|
||||
|
||||
};
|
||||
@@ -524,7 +526,10 @@ enum EnumUserDebugDrawFlags
|
||||
USER_DEBUG_HAS_LINE=1,
|
||||
USER_DEBUG_HAS_TEXT=2,
|
||||
USER_DEBUG_REMOVE_ONE_ITEM=4,
|
||||
USER_DEBUG_REMOVE_ALL=8
|
||||
USER_DEBUG_REMOVE_ALL=8,
|
||||
USER_DEBUG_SET_CUSTOM_OBJECT_COLOR = 16,
|
||||
USER_DEBUG_REMOVE_CUSTOM_OBJECT_COLOR = 32,
|
||||
|
||||
};
|
||||
|
||||
struct UserDebugDrawArgs
|
||||
@@ -541,6 +546,10 @@ struct UserDebugDrawArgs
|
||||
double m_textPositionXYZ[3];
|
||||
double m_textColorRGB[3];
|
||||
double m_textSize;
|
||||
|
||||
double m_objectDebugColorRGB[3];
|
||||
int m_objectUniqueId;
|
||||
int m_linkIndex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -75,6 +75,8 @@ struct TinyRendererVisualShapeConverterInternalData
|
||||
b3AlignedObjectArray<int> m_segmentationMaskBuffer;
|
||||
btVector3 m_lightDirection;
|
||||
bool m_hasLightDirection;
|
||||
btVector3 m_lightColor;
|
||||
bool m_hasLightColor;
|
||||
SimpleCamera m_camera;
|
||||
|
||||
|
||||
@@ -83,7 +85,8 @@ struct TinyRendererVisualShapeConverterInternalData
|
||||
m_swWidth(START_WIDTH),
|
||||
m_swHeight(START_HEIGHT),
|
||||
m_rgbColorBuffer(START_WIDTH,START_HEIGHT,TGAImage::RGB),
|
||||
m_hasLightDirection(false)
|
||||
m_hasLightDirection(false),
|
||||
m_hasLightColor(false)
|
||||
{
|
||||
m_depthBuffer.resize(m_swWidth*m_swHeight);
|
||||
m_segmentationMaskBuffer.resize(m_swWidth*m_swHeight,-1);
|
||||
@@ -117,6 +120,11 @@ void TinyRendererVisualShapeConverter::setLightDirection(float x, float y, float
|
||||
m_data->m_hasLightDirection = true;
|
||||
}
|
||||
|
||||
void TinyRendererVisualShapeConverter::setLightColor(float x, float y, float z)
|
||||
{
|
||||
m_data->m_lightColor.setValue(x, y, z);
|
||||
m_data->m_hasLightColor = true;
|
||||
}
|
||||
|
||||
void convertURDFToVisualShape(const UrdfVisual* visual, const char* urdfPathPrefix, const btTransform& visualTransform, btAlignedObjectArray<GLInstanceVertex>& verticesOut, btAlignedObjectArray<int>& indicesOut, btAlignedObjectArray<MyTexture2>& texturesOut, b3VisualShapeData& visualShapeOut)
|
||||
{
|
||||
@@ -704,6 +712,12 @@ void TinyRendererVisualShapeConverter::render(const float viewMat[16], const flo
|
||||
|
||||
lightDirWorld.normalize();
|
||||
|
||||
btVector3 lightColor(1.0,1.0,1.0);
|
||||
if (m_data->m_hasLightColor)
|
||||
{
|
||||
lightColor = m_data->m_lightColor;
|
||||
}
|
||||
|
||||
// printf("num m_swRenderInstances = %d\n", m_data->m_swRenderInstances.size());
|
||||
for (int i=0;i<m_data->m_swRenderInstances.size();i++)
|
||||
{
|
||||
@@ -737,6 +751,7 @@ void TinyRendererVisualShapeConverter::render(const float viewMat[16], const flo
|
||||
renderObj->m_viewMatrix[i][j] = viewMat[i+4*j];
|
||||
renderObj->m_localScaling = colObj->getCollisionShape()->getLocalScaling();
|
||||
renderObj->m_lightDirWorld = lightDirWorld;
|
||||
renderObj->m_lightColor = lightColor;
|
||||
}
|
||||
}
|
||||
TinyRenderer::renderObject(*renderObj);
|
||||
@@ -900,4 +915,4 @@ int TinyRendererVisualShapeConverter::loadTextureFile(const char* filename)
|
||||
return registerTexture(image, width, height);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ struct TinyRendererVisualShapeConverter : public LinkVisualShapesConverter
|
||||
void getWidthAndHeight(int& width, int& height);
|
||||
void setWidthAndHeight(int width, int height);
|
||||
void setLightDirection(float x, float y, float z);
|
||||
void setLightColor(float x, float y, float z);
|
||||
|
||||
void copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels,int* segmentationMaskBuffer, int segmentationMaskSizeInPixels, int startPixelIndex, int* widthPtr, int* heightPtr, int* numPixelsCopied);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user