setDebugObjectColor

This commit is contained in:
erwincoumans
2016-11-21 07:42:11 -08:00
parent 1bc427df6b
commit 0d5dcb3cc5
11 changed files with 224 additions and 16 deletions

View File

@@ -1195,6 +1195,46 @@ int b3GetDebugItemUniqueId(b3SharedMemoryStatusHandle statusHandle)
return status->m_userDebugDrawArgs.m_debugItemUniqueId; 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. ///request an image from a simulated camera, using a software renderer.
b3SharedMemoryCommandHandle b3InitRequestCameraImage(b3PhysicsClientHandle physClient) b3SharedMemoryCommandHandle b3InitRequestCameraImage(b3PhysicsClientHandle physClient)
@@ -1244,6 +1284,17 @@ void b3RequestCameraImageSetLightDirection(b3SharedMemoryCommandHandle commandHa
command->m_updateFlags |= REQUEST_PIXEL_ARGS_SET_LIGHT_DIRECTION; 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]) void b3ComputeViewMatrixFromPositions(const float cameraPosition[3], const float cameraTargetPosition[3], const float cameraUp[3], float viewMatrix[16])
{ {

View File

@@ -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 b3InitUserDebugDrawAddText3D(b3PhysicsClientHandle physClient, const char* txt, double positionXYZ[3], double colorRGB[3], double textSize, double lifeTime);
b3SharedMemoryCommandHandle b3InitUserDebugDrawRemove(b3PhysicsClientHandle physClient, int debugItemUniqueId); b3SharedMemoryCommandHandle b3InitUserDebugDrawRemove(b3PhysicsClientHandle physClient, int debugItemUniqueId);
b3SharedMemoryCommandHandle b3InitUserDebugDrawRemoveAll(b3PhysicsClientHandle physClient); 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. ///All debug items unique Ids are positive: a negative unique Id means failure.
int b3GetDebugItemUniqueId(b3SharedMemoryStatusHandle statusHandle); int b3GetDebugItemUniqueId(b3SharedMemoryStatusHandle statusHandle);
///request an image from a simulated camera, using a software renderer. ///request an image from a simulated camera, using a software renderer.
b3SharedMemoryCommandHandle b3InitRequestCameraImage(b3PhysicsClientHandle physClient); b3SharedMemoryCommandHandle b3InitRequestCameraImage(b3PhysicsClientHandle physClient);
void b3RequestCameraImageSetCameraMatrices(b3SharedMemoryCommandHandle command, float viewMatrix[16], float projectionMatrix[16]); void b3RequestCameraImageSetCameraMatrices(b3SharedMemoryCommandHandle command, float viewMatrix[16], float projectionMatrix[16]);
void b3RequestCameraImageSetPixelResolution(b3SharedMemoryCommandHandle command, int width, int height ); void b3RequestCameraImageSetPixelResolution(b3SharedMemoryCommandHandle command, int width, int height );
void b3RequestCameraImageSetLightDirection(b3SharedMemoryCommandHandle commandHandle, const float lightDirection[3]); void b3RequestCameraImageSetLightDirection(b3SharedMemoryCommandHandle commandHandle, const float lightDirection[3]);
void b3RequestCameraImageSetLightColor(b3SharedMemoryCommandHandle commandHandle, const float lightColor[3]);
void b3RequestCameraImageSelectRenderer(b3SharedMemoryCommandHandle commandHandle, int renderer); void b3RequestCameraImageSelectRenderer(b3SharedMemoryCommandHandle commandHandle, int renderer);
void b3GetCameraImageData(b3PhysicsClientHandle physClient, struct b3CameraImageData* imageData); void b3GetCameraImageData(b3PhysicsClientHandle physClient, struct b3CameraImageData* imageData);

View File

@@ -3531,7 +3531,6 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
for( int i=0;i<numRb;i++) for( int i=0;i<numRb;i++)
{ {
btCollisionObject* colObj = importer->getRigidBodyByIndex(i); btCollisionObject* colObj = importer->getRigidBodyByIndex(i);
if (colObj) if (colObj)
{ {
btRigidBody* rb = btRigidBody::upcast(colObj); btRigidBody* rb = btRigidBody::upcast(colObj);
@@ -3594,7 +3593,54 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
SharedMemoryStatus& serverCmd = serverStatusOut; SharedMemoryStatus& serverCmd = serverStatusOut;
serverCmd.m_type = CMD_USER_DEBUG_DRAW_FAILED; serverCmd.m_type = CMD_USER_DEBUG_DRAW_FAILED;
hasStatus = true; 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) if (clientCmd.m_updateFlags & USER_DEBUG_HAS_TEXT)
{ {

View File

@@ -139,13 +139,15 @@ struct RequestPixelDataArgs
int m_pixelWidth; int m_pixelWidth;
int m_pixelHeight; int m_pixelHeight;
float m_lightDirection[3]; float m_lightDirection[3];
float m_lightColor[3];
}; };
enum EnumRequestPixelDataUpdateFlags enum EnumRequestPixelDataUpdateFlags
{ {
REQUEST_PIXEL_ARGS_HAS_CAMERA_MATRICES=1, REQUEST_PIXEL_ARGS_HAS_CAMERA_MATRICES=1,
REQUEST_PIXEL_ARGS_SET_PIXEL_WIDTH_HEIGHT=4, REQUEST_PIXEL_ARGS_SET_PIXEL_WIDTH_HEIGHT=2,
REQUEST_PIXEL_ARGS_SET_LIGHT_DIRECTION=8, 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 //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_LINE=1,
USER_DEBUG_HAS_TEXT=2, USER_DEBUG_HAS_TEXT=2,
USER_DEBUG_REMOVE_ONE_ITEM=4, 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 struct UserDebugDrawArgs
@@ -541,6 +546,10 @@ struct UserDebugDrawArgs
double m_textPositionXYZ[3]; double m_textPositionXYZ[3];
double m_textColorRGB[3]; double m_textColorRGB[3];
double m_textSize; double m_textSize;
double m_objectDebugColorRGB[3];
int m_objectUniqueId;
int m_linkIndex;
}; };

View File

@@ -75,6 +75,8 @@ struct TinyRendererVisualShapeConverterInternalData
b3AlignedObjectArray<int> m_segmentationMaskBuffer; b3AlignedObjectArray<int> m_segmentationMaskBuffer;
btVector3 m_lightDirection; btVector3 m_lightDirection;
bool m_hasLightDirection; bool m_hasLightDirection;
btVector3 m_lightColor;
bool m_hasLightColor;
SimpleCamera m_camera; SimpleCamera m_camera;
@@ -83,7 +85,8 @@ struct TinyRendererVisualShapeConverterInternalData
m_swWidth(START_WIDTH), m_swWidth(START_WIDTH),
m_swHeight(START_HEIGHT), m_swHeight(START_HEIGHT),
m_rgbColorBuffer(START_WIDTH,START_HEIGHT,TGAImage::RGB), 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_depthBuffer.resize(m_swWidth*m_swHeight);
m_segmentationMaskBuffer.resize(m_swWidth*m_swHeight,-1); 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; 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) 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(); 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()); // printf("num m_swRenderInstances = %d\n", m_data->m_swRenderInstances.size());
for (int i=0;i<m_data->m_swRenderInstances.size();i++) 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_viewMatrix[i][j] = viewMat[i+4*j];
renderObj->m_localScaling = colObj->getCollisionShape()->getLocalScaling(); renderObj->m_localScaling = colObj->getCollisionShape()->getLocalScaling();
renderObj->m_lightDirWorld = lightDirWorld; renderObj->m_lightDirWorld = lightDirWorld;
renderObj->m_lightColor = lightColor;
} }
} }
TinyRenderer::renderObject(*renderObj); TinyRenderer::renderObject(*renderObj);
@@ -900,4 +915,4 @@ int TinyRendererVisualShapeConverter::loadTextureFile(const char* filename)
return registerTexture(image, width, height); return registerTexture(image, width, height);
} }
return -1; return -1;
} }

View File

@@ -33,6 +33,7 @@ struct TinyRendererVisualShapeConverter : public LinkVisualShapesConverter
void getWidthAndHeight(int& width, int& height); void getWidthAndHeight(int& width, int& height);
void setWidthAndHeight(int width, int height); void setWidthAndHeight(int width, int height);
void setLightDirection(float x, float y, float z); 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); void copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels,int* segmentationMaskBuffer, int segmentationMaskSizeInPixels, int startPixelIndex, int* widthPtr, int* heightPtr, int* numPixelsCopied);

View File

@@ -19,6 +19,7 @@ struct Shader : public IShader {
Model* m_model; Model* m_model;
Vec3f m_light_dir_local; Vec3f m_light_dir_local;
Vec3f m_light_color;
Matrix& m_modelMat; Matrix& m_modelMat;
Matrix m_invModelMat; Matrix m_invModelMat;
@@ -32,9 +33,10 @@ struct Shader : public IShader {
mat<3,3,float> varying_nrm; // normal per vertex to be interpolated by FS mat<3,3,float> varying_nrm; // normal per vertex to be interpolated by FS
//mat<3,3,float> ndc_tri; // triangle in normalized device coordinates //mat<3,3,float> ndc_tri; // triangle in normalized device coordinates
Shader(Model* model, Vec3f light_dir_local, Matrix& modelView, Matrix& projectionMatrix, Matrix& modelMat, Vec3f localScaling, const Vec4f& colorRGBA) Shader(Model* model, Vec3f light_dir_local, Vec3f light_color, Matrix& modelView, Matrix& projectionMatrix, Matrix& modelMat, Vec3f localScaling, const Vec4f& colorRGBA)
:m_model(model), :m_model(model),
m_light_dir_local(light_dir_local), m_light_dir_local(light_dir_local),
m_light_color(light_color),
m_modelView1(modelView), m_modelView1(modelView),
m_projectionMatrix(projectionMatrix), m_projectionMatrix(projectionMatrix),
m_modelMat(modelMat), m_modelMat(modelMat),
@@ -83,6 +85,10 @@ struct Shader : public IShader {
color.bgra[1] *= m_colorRGBA[1]; color.bgra[1] *= m_colorRGBA[1];
color.bgra[2] *= m_colorRGBA[2]; color.bgra[2] *= m_colorRGBA[2];
color.bgra[3] *= m_colorRGBA[3]; color.bgra[3] *= m_colorRGBA[3];
color.bgra[0] *= m_light_color[0];
color.bgra[1] *= m_light_color[1];
color.bgra[2] *= m_light_color[2];
return false; return false;
} }
@@ -260,6 +266,7 @@ void TinyRenderer::renderObject(TinyRenderObjectData& renderData)
int height = renderData.m_rgbColorBuffer.get_height(); int height = renderData.m_rgbColorBuffer.get_height();
Vec3f light_dir_local = Vec3f(renderData.m_lightDirWorld[0],renderData.m_lightDirWorld[1],renderData.m_lightDirWorld[2]); Vec3f light_dir_local = Vec3f(renderData.m_lightDirWorld[0],renderData.m_lightDirWorld[1],renderData.m_lightDirWorld[2]);
Vec3f light_color = Vec3f(renderData.m_lightColor[0],renderData.m_lightColor[1],renderData.m_lightColor[2]);
Model* model = renderData.m_model; Model* model = renderData.m_model;
if (0==model) if (0==model)
return; return;
@@ -278,7 +285,7 @@ void TinyRenderer::renderObject(TinyRenderObjectData& renderData)
{ {
Matrix modelViewMatrix = renderData.m_viewMatrix*renderData.m_modelMatrix; Matrix modelViewMatrix = renderData.m_viewMatrix*renderData.m_modelMatrix;
Vec3f localScaling(renderData.m_localScaling[0],renderData.m_localScaling[1],renderData.m_localScaling[2]); Vec3f localScaling(renderData.m_localScaling[0],renderData.m_localScaling[1],renderData.m_localScaling[2]);
Shader shader(model, light_dir_local, modelViewMatrix, renderData.m_projectionMatrix,renderData.m_modelMatrix, localScaling, model->getColorRGBA()); Shader shader(model, light_dir_local, light_color, modelViewMatrix, renderData.m_projectionMatrix,renderData.m_modelMatrix, localScaling, model->getColorRGBA());
//printf("Render %d triangles.\n",model->nfaces()); //printf("Render %d triangles.\n",model->nfaces());
for (int i=0; i<model->nfaces(); i++) for (int i=0; i<model->nfaces(); i++)

View File

@@ -18,6 +18,7 @@ struct TinyRenderObjectData
Matrix m_viewportMatrix; Matrix m_viewportMatrix;
btVector3 m_localScaling; btVector3 m_localScaling;
btVector3 m_lightDirWorld; btVector3 m_lightDirWorld;
btVector3 m_lightColor;
//Model (vertices, indices, textures, shader) //Model (vertices, indices, textures, shader)
Matrix m_modelMatrix; Matrix m_modelMatrix;

View File

@@ -1647,8 +1647,45 @@ static PyObject* pybullet_removeAllUserDebugItems(PyObject* self, PyObject* args
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject* pybullet_setDebugObjectColor(PyObject* self, PyObject* args, PyObject *keywds)
{
PyObject* objectColorRGBObj = 0;
double objectColorRGB[3];
int objectUniqueId = -1;
int linkIndex = -2;
static char *kwlist[] = { "objectUniqueId", "linkIndex","objectDebugColorRGB", NULL };
if (0 == sm) {
PyErr_SetString(SpamError, "Not connected to physics server.");
return NULL;
}
if (!PyArg_ParseTupleAndKeywords(args, keywds, "ii|O", kwlist,
&objectUniqueId, &linkIndex, &objectColorRGBObj))
return NULL;
if (objectColorRGBObj)
{
if (pybullet_internalSetVectord(objectColorRGBObj, objectColorRGB))
{
b3SharedMemoryCommandHandle commandHandle = b3InitDebugDrawingCommand(sm);
b3SetDebugObjectColor(commandHandle, objectUniqueId, linkIndex, objectColorRGB);
b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
}
}
else
{
b3SharedMemoryCommandHandle commandHandle = b3InitDebugDrawingCommand(sm);
b3RemoveDebugObjectColor(commandHandle, objectUniqueId, linkIndex);
b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject* pybullet_getVisualShapeData(PyObject* self, PyObject* args) static PyObject* pybullet_getVisualShapeData(PyObject* self, PyObject* args)
{ {
@@ -2237,17 +2274,18 @@ static PyObject* pybullet_getContactPointData(PyObject* self, PyObject* args, Py
/// Render an image from the current timestep of the simulation, width, height are required, other args are optional /// Render an image from the current timestep of the simulation, width, height are required, other args are optional
// getCameraImage(w, h, view[16], projection[16], lightpos[3]) // getCameraImage(w, h, view[16], projection[16], lightDir[3], lightColor[3])
static PyObject* pybullet_getCameraImage(PyObject* self, PyObject* args, PyObject *keywds) static PyObject* pybullet_getCameraImage(PyObject* self, PyObject* args, PyObject *keywds)
{ {
/// request an image from a simulated camera, using a software renderer. /// request an image from a simulated camera, using a software renderer.
struct b3CameraImageData imageData; struct b3CameraImageData imageData;
PyObject* objViewMat = 0, *objProjMat = 0, *lightDirObj = 0; PyObject* objViewMat = 0, *objProjMat = 0, *lightDirObj = 0, *lightColorObj = 0;
int width, height; int width, height;
int size = PySequence_Size(args); int size = PySequence_Size(args);
float viewMatrix[16]; float viewMatrix[16];
float projectionMatrix[16]; float projectionMatrix[16];
float lightDir[3]; float lightDir[3];
float lightColor[3];
// inialize cmd // inialize cmd
b3SharedMemoryCommandHandle command; b3SharedMemoryCommandHandle command;
@@ -2260,9 +2298,9 @@ static PyObject* pybullet_getCameraImage(PyObject* self, PyObject* args, PyObjec
command = b3InitRequestCameraImage(sm); command = b3InitRequestCameraImage(sm);
// set camera resolution, optionally view, projection matrix, light direction // set camera resolution, optionally view, projection matrix, light direction
static char *kwlist[] = { "width", "height", "viewMatrix", "projectionMatrix", "lightDirection",NULL }; static char *kwlist[] = { "width", "height", "viewMatrix", "projectionMatrix", "lightDirection", "lightColor", NULL };
if (!PyArg_ParseTupleAndKeywords(args, keywds, "ii|OOO", kwlist, &width, &height, &objViewMat, &objProjMat, &lightDirObj)) if (!PyArg_ParseTupleAndKeywords(args, keywds, "ii|OOOO", kwlist, &width, &height, &objViewMat, &objProjMat, &lightDirObj, &lightColorObj))
{ {
return NULL; return NULL;
} }
@@ -2273,11 +2311,16 @@ static PyObject* pybullet_getCameraImage(PyObject* self, PyObject* args, PyObjec
{ {
b3RequestCameraImageSetCameraMatrices(command, viewMatrix, projectionMatrix); b3RequestCameraImageSetCameraMatrices(command, viewMatrix, projectionMatrix);
} }
//set light pos only if function succeeds //set light direction only if function succeeds
if (pybullet_internalSetVector(lightDirObj, lightDir)) if (pybullet_internalSetVector(lightDirObj, lightDir))
{ {
b3RequestCameraImageSetLightDirection(command, lightDir); b3RequestCameraImageSetLightDirection(command, lightDir);
} }
//set light color only if function succeeds
if (pybullet_internalSetVector(lightColorObj, lightColor))
{
b3RequestCameraImageSetLightColor(command, lightColor);
}
if (b3CanSubmitCommand(sm)) if (b3CanSubmitCommand(sm))
@@ -3421,6 +3464,10 @@ static PyMethodDef SpamMethods[] = {
"remove all user debug draw items" "remove all user debug draw items"
}, },
{ "setDebugObjectColor", (PyCFunction)pybullet_setDebugObjectColor, METH_VARARGS | METH_KEYWORDS,
"Override the wireframe debug drawing color for a particular object unique id / link index."
"If you ommit the color, the custom color will be removed."
},
{"getVisualShapeData", pybullet_getVisualShapeData, METH_VARARGS, {"getVisualShapeData", pybullet_getVisualShapeData, METH_VARARGS,

View File

@@ -122,6 +122,7 @@ protected:
///internal update revision number. It will be increased when the object changes. This allows some subsystems to perform lazy evaluation. ///internal update revision number. It will be increased when the object changes. This allows some subsystems to perform lazy evaluation.
int m_updateRevision; int m_updateRevision;
btVector3 m_customDebugColorRGB;
public: public:
@@ -136,7 +137,8 @@ public:
CF_CHARACTER_OBJECT = 16, CF_CHARACTER_OBJECT = 16,
CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
CF_DISABLE_SPU_COLLISION_PROCESSING = 64,//disable parallel/SPU processing CF_DISABLE_SPU_COLLISION_PROCESSING = 64,//disable parallel/SPU processing
CF_HAS_CONTACT_STIFFNESS_DAMPING = 128 CF_HAS_CONTACT_STIFFNESS_DAMPING = 128,
CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR = 256,
}; };
enum CollisionObjectTypes enum CollisionObjectTypes
@@ -556,6 +558,26 @@ public:
return m_updateRevision; return m_updateRevision;
} }
void setCustomDebugColor(const btVector3& colorRGB)
{
m_customDebugColorRGB = colorRGB;
m_collisionFlags |= CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
}
void removeCustomDebugColor()
{
m_collisionFlags &= ~CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
}
bool getCustomDebugColor(btVector3& colorRGB) const
{
bool hasCustomColor = (0!=(m_collisionFlags&CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR));
if (hasCustomColor)
{
colorRGB = m_customDebugColorRGB;
}
return hasCustomColor;
}
inline bool checkCollideWith(const btCollisionObject* co) const inline bool checkCollideWith(const btCollisionObject* co) const
{ {

View File

@@ -1572,6 +1572,8 @@ void btCollisionWorld::debugDrawWorld()
} }
}; };
colObj->getCustomDebugColor(color);
debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color); debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
} }
if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb)) if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))