mirror of
https://github.com/bulletphysics/bullet3
synced 2024-12-13 13:20:07 +00:00
Add pybullet.configureDebugVisualizer(rgbBackground=[red,green,blue]) (each component a float in the range [0,1])
This is an alternative to passing options="--background_color_red=red --background_color_green=green --background_color_blue=blue" in the connect method.
This commit is contained in:
parent
8e85dedaa9
commit
e952ac6f63
@ -52,6 +52,8 @@ struct GUIHelperInterface
|
||||
virtual int getShapeIndexFromInstance(int instanceUid) { return -1; }
|
||||
virtual void replaceTexture(int shapeIndex, int textureUid) {}
|
||||
virtual void removeTexture(int textureUid) {}
|
||||
virtual void setBackgroundColor(const double rgbBackground[3]) {}
|
||||
|
||||
|
||||
virtual Common2dCanvasInterface* get2dCanvasInterface() = 0;
|
||||
|
||||
|
@ -56,6 +56,8 @@ struct CommonRenderInterface
|
||||
|
||||
virtual void setLightPosition(const float lightPos[3]) = 0;
|
||||
virtual void setLightPosition(const double lightPos[3]) = 0;
|
||||
virtual void setBackgroundColor(const double rgbBackground[3]) = 0;
|
||||
|
||||
virtual void setShadowMapResolution(int shadowMapResolution) = 0;
|
||||
virtual void setShadowMapIntensity(double shadowMapIntensity) = 0;
|
||||
|
||||
|
@ -236,13 +236,19 @@ OpenGLGuiHelper::OpenGLGuiHelper(CommonGraphicsApp* glApp, bool useOpenGL2)
|
||||
m_data->m_debugDraw = 0;
|
||||
}
|
||||
|
||||
OpenGLGuiHelper::~OpenGLGuiHelper()
|
||||
|
||||
OpenGLGuiHelper::~OpenGLGuiHelper()
|
||||
{
|
||||
delete m_data->m_debugDraw;
|
||||
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
void OpenGLGuiHelper::setBackgroundColor(const double rgbBackground[3])
|
||||
{
|
||||
this->getRenderInterface()->setBackgroundColor(rgbBackground);
|
||||
}
|
||||
|
||||
struct CommonRenderInterface* OpenGLGuiHelper::getRenderInterface()
|
||||
{
|
||||
return m_data->m_glApp->m_renderer;
|
||||
|
@ -36,7 +36,7 @@ struct OpenGLGuiHelper : public GUIHelperInterface
|
||||
virtual int getShapeIndexFromInstance(int instanceUid);
|
||||
virtual void replaceTexture(int shapeIndex, int textureUid);
|
||||
virtual void updateShape(int shapeIndex, float* vertices, int numVertices);
|
||||
|
||||
virtual void setBackgroundColor(const double rgbBackground[3]);
|
||||
virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape);
|
||||
|
||||
virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld);
|
||||
|
@ -1522,6 +1522,11 @@ void GLInstancingRenderer::setLightPosition(const double lightPos[3])
|
||||
m_data->m_lightPos[2] = lightPos[2];
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::setBackgroundColor(const double rgbBackground[3])
|
||||
{
|
||||
glClearColor(rgbBackground[0], rgbBackground[1], rgbBackground[2], 1.f);
|
||||
}
|
||||
|
||||
void GLInstancingRenderer::setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16])
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
|
@ -127,7 +127,7 @@ public:
|
||||
void setLightSpecularIntensity(const float lightSpecularIntensity[3]);
|
||||
virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]);
|
||||
virtual void setProjectiveTexture(bool useProjectiveTexture);
|
||||
|
||||
virtual void setBackgroundColor(const double rgbBackground[3]);
|
||||
virtual void resize(int width, int height);
|
||||
virtual int getScreenWidth()
|
||||
{
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
virtual void setShadowMapIntensity(double shadowMapIntensity) {}
|
||||
virtual void setShadowMapWorldSize(float worldSize) {}
|
||||
virtual void resize(int width, int height);
|
||||
virtual void setBackgroundColor(const double rgbBackground[3]) {}
|
||||
|
||||
virtual void removeAllInstances();
|
||||
virtual void removeGraphicsInstance(int instanceUid);
|
||||
|
@ -6064,6 +6064,21 @@ B3_SHARED_API void b3ConfigureOpenGLVisualizerSetLightPosition(b3SharedMemoryCom
|
||||
}
|
||||
}
|
||||
|
||||
B3_SHARED_API void b3ConfigureOpenGLVisualizerSetLightRgbBackground(b3SharedMemoryCommandHandle commandHandle, const float rgbBackground[3])
|
||||
{
|
||||
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*)commandHandle;
|
||||
b3Assert(command);
|
||||
b3Assert(command->m_type == CMD_CONFIGURE_OPENGL_VISUALIZER);
|
||||
if (command->m_type == CMD_CONFIGURE_OPENGL_VISUALIZER)
|
||||
{
|
||||
command->m_updateFlags |= COV_SET_RGB_BACKGROUND;
|
||||
command->m_configureOpenGLVisualizerArguments.m_rgbBackground[0] = rgbBackground[0];
|
||||
command->m_configureOpenGLVisualizerArguments.m_rgbBackground[1] = rgbBackground[1];
|
||||
command->m_configureOpenGLVisualizerArguments.m_rgbBackground[2] = rgbBackground[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
B3_SHARED_API void b3ConfigureOpenGLVisualizerSetShadowMapResolution(b3SharedMemoryCommandHandle commandHandle, int shadowMapResolution)
|
||||
{
|
||||
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*)commandHandle;
|
||||
|
@ -218,7 +218,9 @@ extern "C"
|
||||
B3_SHARED_API void b3ConfigureOpenGLVisualizerSetLightPosition(b3SharedMemoryCommandHandle commandHandle, const float lightPosition[3]);
|
||||
B3_SHARED_API void b3ConfigureOpenGLVisualizerSetShadowMapResolution(b3SharedMemoryCommandHandle commandHandle, int shadowMapResolution);
|
||||
B3_SHARED_API void b3ConfigureOpenGLVisualizerSetShadowMapIntensity(b3SharedMemoryCommandHandle commandHandle, double shadowMapIntensity);
|
||||
B3_SHARED_API void b3ConfigureOpenGLVisualizerSetLightRgbBackground(b3SharedMemoryCommandHandle commandHandle, const float rgbBackground[3]);
|
||||
|
||||
|
||||
B3_SHARED_API void b3ConfigureOpenGLVisualizerSetShadowMapWorldSize(b3SharedMemoryCommandHandle commandHandle, int shadowMapWorldSize);
|
||||
B3_SHARED_API void b3ConfigureOpenGLVisualizerSetRemoteSyncTransformInterval(b3SharedMemoryCommandHandle commandHandle, double remoteSyncTransformInterval);
|
||||
|
||||
|
@ -11305,6 +11305,10 @@ bool PhysicsServerCommandProcessor::processConfigureOpenGLVisualizerCommand(cons
|
||||
{
|
||||
m_data->m_guiHelper->getRenderInterface()->setLightPosition(clientCmd.m_configureOpenGLVisualizerArguments.m_lightPosition);
|
||||
}
|
||||
if (clientCmd.m_updateFlags & COV_SET_RGB_BACKGROUND)
|
||||
{
|
||||
m_data->m_guiHelper->setBackgroundColor(clientCmd.m_configureOpenGLVisualizerArguments.m_rgbBackground);
|
||||
}
|
||||
if (clientCmd.m_updateFlags & COV_SET_SHADOWMAP_RESOLUTION)
|
||||
{
|
||||
m_data->m_guiHelper->getRenderInterface()->setShadowMapResolution(clientCmd.m_configureOpenGLVisualizerArguments.m_shadowMapResolution);
|
||||
|
@ -133,6 +133,7 @@ enum MultiThreadedGUIHelperCommunicationEnums
|
||||
eGUIUserDebugRemoveAllParameters,
|
||||
eGUIHelperResetCamera,
|
||||
eGUIHelperChangeGraphicsInstanceFlags,
|
||||
eGUIHelperSetRgbBackground,
|
||||
};
|
||||
|
||||
#include <stdio.h>
|
||||
@ -1058,7 +1059,17 @@ public:
|
||||
workerThreadWait();
|
||||
}
|
||||
|
||||
|
||||
double m_rgbBackground[3];
|
||||
virtual void setBackgroundColor(const double rgbBackground[3])
|
||||
{
|
||||
m_rgbBackground[0] = rgbBackground[0];
|
||||
m_rgbBackground[1] = rgbBackground[1];
|
||||
m_rgbBackground[2] = rgbBackground[2];
|
||||
m_cs->lock();
|
||||
m_cs->setSharedParam(1, eGUIHelperSetRgbBackground);
|
||||
workerThreadWait();
|
||||
this->getRenderInterface()->setBackgroundColor(rgbBackground);
|
||||
}
|
||||
|
||||
|
||||
int m_graphicsInstanceChangeScaling;
|
||||
@ -2267,6 +2278,13 @@ void PhysicsServerExample::updateGraphics()
|
||||
break;
|
||||
}
|
||||
|
||||
case eGUIHelperSetRgbBackground:
|
||||
{
|
||||
m_multiThreadedHelper->m_childGuiHelper->setBackgroundColor(m_multiThreadedHelper->m_rgbBackground);
|
||||
m_multiThreadedHelper->mainThreadRelease();
|
||||
break;
|
||||
}
|
||||
|
||||
case eGUIHelperChangeGraphicsInstanceScaling:
|
||||
{
|
||||
B3_PROFILE("eGUIHelperChangeGraphicsInstanceScaling");
|
||||
|
@ -962,6 +962,7 @@ enum InternalOpenGLVisualizerUpdateFlags
|
||||
COV_SET_SHADOWMAP_WORLD_SIZE = 16,
|
||||
COV_SET_REMOTE_SYNC_TRANSFORM_INTERVAL = 32,
|
||||
COV_SET_SHADOWMAP_INTENSITY = 64,
|
||||
COV_SET_RGB_BACKGROUND = 128,
|
||||
};
|
||||
|
||||
struct ConfigureOpenGLVisualizerRequest
|
||||
@ -977,6 +978,7 @@ struct ConfigureOpenGLVisualizerRequest
|
||||
int m_setFlag;
|
||||
int m_setEnabled;
|
||||
double m_shadowMapIntensity;
|
||||
double m_rgbBackground[3];
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -7450,11 +7450,12 @@ static PyObject* pybullet_configureDebugVisualizer(PyObject* self, PyObject* arg
|
||||
int physicsClientId = 0;
|
||||
double remoteSyncTransformInterval = -1;
|
||||
PyObject* pyLightPosition = 0;
|
||||
PyObject* pyRgbBackground = 0;
|
||||
b3PhysicsClientHandle sm = 0;
|
||||
static char* kwlist[] = {"flag", "enable", "lightPosition", "shadowMapResolution", "shadowMapWorldSize", "remoteSyncTransformInterval", "shadowMapIntensity", "physicsClientId", NULL};
|
||||
static char* kwlist[] = {"flag", "enable", "lightPosition", "shadowMapResolution", "shadowMapWorldSize", "remoteSyncTransformInterval", "shadowMapIntensity", "rgbBackground", "physicsClientId", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|iiOiiddi", kwlist,
|
||||
&flag, &enable, &pyLightPosition, &shadowMapResolution, &shadowMapWorldSize, &remoteSyncTransformInterval, &shadowMapIntensity, &physicsClientId))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|iiOiiddOi", kwlist,
|
||||
&flag, &enable, &pyLightPosition, &shadowMapResolution, &shadowMapWorldSize, &remoteSyncTransformInterval, &shadowMapIntensity, &pyRgbBackground, &physicsClientId))
|
||||
return NULL;
|
||||
|
||||
sm = getPhysicsClient(physicsClientId);
|
||||
@ -7478,6 +7479,14 @@ static PyObject* pybullet_configureDebugVisualizer(PyObject* self, PyObject* arg
|
||||
b3ConfigureOpenGLVisualizerSetLightPosition(commandHandle, lightPosition);
|
||||
}
|
||||
}
|
||||
if (pyRgbBackground)
|
||||
{
|
||||
float rgbBackground[3];
|
||||
if (pybullet_internalSetVector(pyRgbBackground, rgbBackground))
|
||||
{
|
||||
b3ConfigureOpenGLVisualizerSetLightRgbBackground(commandHandle, rgbBackground);
|
||||
}
|
||||
}
|
||||
if (shadowMapIntensity >= 0)
|
||||
{
|
||||
b3ConfigureOpenGLVisualizerSetShadowMapIntensity(commandHandle, shadowMapIntensity);
|
||||
|
Loading…
Reference in New Issue
Block a user