This commit is contained in:
Erwin Coumans
2017-05-16 18:03:05 -07:00
28 changed files with 446 additions and 123 deletions

View File

@@ -51,6 +51,10 @@ public:
{ {
}
virtual ~MyDebugDrawer()
{
} }
virtual DefaultColors getDefaultColors() const virtual DefaultColors getDefaultColors() const
{ {
@@ -1179,11 +1183,11 @@ void OpenGLGuiHelper::autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWor
createCollisionShapeGraphicsObject(colObj->getCollisionShape()); createCollisionShapeGraphicsObject(colObj->getCollisionShape());
int colorIndex = colObj->getBroadphaseHandle()->getUid() & 3; int colorIndex = colObj->getBroadphaseHandle()->getUid() & 3;
btVector3 color; btVector4 color;
color = sColors[colorIndex]; color = sColors[colorIndex];
if (colObj->getCollisionShape()->getShapeType()==STATIC_PLANE_PROXYTYPE) if (colObj->getCollisionShape()->getShapeType()==STATIC_PLANE_PROXYTYPE)
{ {
color.setValue(1,1,1); color.setValue(1,1,1,1);
} }
createCollisionObjectGraphicsObject(colObj,color); createCollisionObjectGraphicsObject(colObj,color);

View File

@@ -87,7 +87,16 @@ struct UrdfGeometry
UrdfGeometry() UrdfGeometry()
:m_type(URDF_GEOM_UNKNOWN), :m_type(URDF_GEOM_UNKNOWN),
m_hasFromTo(false), m_sphereRadius(1),
m_boxSize(1,1,1),
m_capsuleRadius(1),
m_capsuleHeight(1),
m_hasFromTo(0),
m_capsuleFrom(0,1,0),
m_capsuleTo(1,0,0),
m_planeNormal(0,0,1),
m_meshFileType(0),
m_meshScale(1,1,1),
m_hasLocalMaterial(false) m_hasLocalMaterial(false)
{ {
} }

View File

@@ -893,17 +893,25 @@ int GLInstancingRenderer::registerShape(const float* vertices, int numvertices,
gfxObj->m_numVertices = numvertices; gfxObj->m_numVertices = numvertices;
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
int vertexStrideInBytes = 9*sizeof(float); int vertexStrideInBytes = 9*sizeof(float);
int sz = numvertices*vertexStrideInBytes; int sz = numvertices*vertexStrideInBytes;
int totalUsed = vertexStrideInBytes*gfxObj->m_vertexArrayOffset+sz;
b3Assert(totalUsed<m_data->m_maxShapeCapacityInBytes);
if (totalUsed>=m_data->m_maxShapeCapacityInBytes)
{
return -1;
}
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
#if 0 #if 0
char* dest= (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_WRITE_ONLY);//GL_WRITE_ONLY char* dest= (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_WRITE_ONLY);//GL_WRITE_ONLY
#ifdef B3_DEBUG #ifdef B3_DEBUG
int totalUsed = vertexStrideInBytes*gfxObj->m_vertexArrayOffset+sz;
b3Assert(totalUsed<m_data->m_maxShapeCapacityInBytes);
#endif//B3_DEBUG #endif//B3_DEBUG
memcpy(dest+vertexStrideInBytes*gfxObj->m_vertexArrayOffset,vertices,sz); memcpy(dest+vertexStrideInBytes*gfxObj->m_vertexArrayOffset,vertices,sz);
@@ -1613,6 +1621,11 @@ static void b3CreateLookAt(const b3Vector3& eye, const b3Vector3& center,cons
void GLInstancingRenderer::renderSceneInternal(int renderMode) void GLInstancingRenderer::renderSceneInternal(int renderMode)
{ {
if (!useShadowMap)
{
renderMode = B3_DEFAULT_RENDERMODE;
}
// glEnable(GL_DEPTH_TEST); // glEnable(GL_DEPTH_TEST);
GLint dims[4]; GLint dims[4];

View File

@@ -92,7 +92,7 @@ public:
m_robotSim.loadSDF("kiva_shelf/model.sdf",results); m_robotSim.loadSDF("kiva_shelf/model.sdf",results);
} }
{ {
m_robotSim.loadURDF("results"); m_robotSim.loadURDF("plane.urdf");
} }
m_robotSim.setGravity(b3MakeVector3(0,0,-10)); m_robotSim.setGravity(b3MakeVector3(0,0,-10));

View File

@@ -122,7 +122,8 @@ protected:
{ {
if (m_options == eCLIENTEXAMPLE_SERVER) if (m_options == eCLIENTEXAMPLE_SERVER)
{ {
m_physicsServer.renderScene(); int renderFlags = 0;
m_physicsServer.renderScene(renderFlags);
} }
b3DebugLines debugLines; b3DebugLines debugLines;

View File

@@ -226,7 +226,7 @@ bool TcpNetworkedPhysicsProcessor::receiveStatus(struct SharedMemoryStatus& serv
} }
void TcpNetworkedPhysicsProcessor::renderScene() void TcpNetworkedPhysicsProcessor::renderScene(int renderFlags)
{ {
} }

View File

@@ -24,7 +24,7 @@ public:
virtual bool receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes); virtual bool receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
virtual void renderScene(); virtual void renderScene(int renderFlags);
virtual void physicsDebugDraw(int debugDrawFlags); virtual void physicsDebugDraw(int debugDrawFlags);

View File

@@ -540,7 +540,7 @@ bool UdpNetworkedPhysicsProcessor::receiveStatus(struct SharedMemoryStatus& serv
} }
void UdpNetworkedPhysicsProcessor::renderScene() void UdpNetworkedPhysicsProcessor::renderScene(int renderFlags)
{ {
} }

View File

@@ -24,7 +24,7 @@ public:
virtual bool receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes); virtual bool receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
virtual void renderScene(); virtual void renderScene(int renderFlags);
virtual void physicsDebugDraw(int debugDrawFlags); virtual void physicsDebugDraw(int debugDrawFlags);

View File

@@ -1,6 +1,11 @@
#ifndef PHYSICS_COMMAND_PROCESSOR_INTERFACE_H #ifndef PHYSICS_COMMAND_PROCESSOR_INTERFACE_H
#define PHYSICS_COMMAND_PROCESSOR_INTERFACE_H #define PHYSICS_COMMAND_PROCESSOR_INTERFACE_H
enum PhysicsCOmmandRenderFlags
{
COV_DISABLE_SYNC_RENDERING=1
};
class PhysicsCommandProcessorInterface class PhysicsCommandProcessorInterface
{ {
@@ -17,7 +22,7 @@ public:
virtual bool receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes) = 0; virtual bool receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes) = 0;
virtual void renderScene() = 0; virtual void renderScene(int renderFlags) = 0;
virtual void physicsDebugDraw(int debugDrawFlags) = 0; virtual void physicsDebugDraw(int debugDrawFlags) = 0;
virtual void setGuiHelper(struct GUIHelperInterface* guiHelper) = 0; virtual void setGuiHelper(struct GUIHelperInterface* guiHelper) = 0;
virtual void setTimeOut(double timeOutInSeconds) = 0; virtual void setTimeOut(double timeOutInSeconds) = 0;

View File

@@ -171,7 +171,8 @@ bool PhysicsDirect::connect(struct GUIHelperInterface* guiHelper)
void PhysicsDirect::renderScene() void PhysicsDirect::renderScene()
{ {
m_data->m_commandProcessor->renderScene(); int renderFlags = 0;
m_data->m_commandProcessor->renderScene(renderFlags);
} }
void PhysicsDirect::debugDraw(int debugDrawMode) void PhysicsDirect::debugDraw(int debugDrawMode)

View File

@@ -33,7 +33,7 @@ public:
//and for physics visualization. The idea is that physicsDebugDraw can also send wireframe //and for physics visualization. The idea is that physicsDebugDraw can also send wireframe
//to a physics client, over shared memory //to a physics client, over shared memory
virtual void physicsDebugDraw(int debugDrawFlags)=0; virtual void physicsDebugDraw(int debugDrawFlags)=0;
virtual void renderScene()=0; virtual void renderScene(int renderFlags)=0;
virtual void enableCommandLogging(bool enable, const char* fileName)=0; virtual void enableCommandLogging(bool enable, const char* fileName)=0;
virtual void replayFromLogFile(const char* fileName)=0; virtual void replayFromLogFile(const char* fileName)=0;

View File

@@ -2181,7 +2181,7 @@ int PhysicsServerCommandProcessor::createBodyInfoStream(int bodyUniqueId, char*
//serialize the btMultiBody and send the data to the client. This is one way to get the link/joint names across the (shared memory) wire //serialize the btMultiBody and send the data to the client. This is one way to get the link/joint names across the (shared memory) wire
InternalBodyHandle* bodyHandle = m_data->m_bodyHandles.getHandle(bodyUniqueId); InternalBodyHandle* bodyHandle = m_data->m_bodyHandles.getHandle(bodyUniqueId);
btMultiBody* mb = bodyHandle->m_multiBody; btMultiBody* mb = bodyHandle? bodyHandle->m_multiBody:0;
if (mb) if (mb)
{ {
UrdfLinkNameMapUtil* util = new UrdfLinkNameMapUtil; UrdfLinkNameMapUtil* util = new UrdfLinkNameMapUtil;
@@ -2837,10 +2837,11 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
int actualNumBodies = 0; int actualNumBodies = 0;
for (int i=0;i<usedHandles.size();i++) for (int i=0;i<usedHandles.size();i++)
{ {
InteralBodyData* body = m_data->m_bodyHandles.getHandle(usedHandles[i]); int usedHandle = usedHandles[i];
InteralBodyData* body = m_data->m_bodyHandles.getHandle(usedHandle);
if (body && (body->m_multiBody || body->m_rigidBody)) if (body && (body->m_multiBody || body->m_rigidBody))
{ {
serverStatusOut.m_sdfLoadedArgs.m_bodyUniqueIds[actualNumBodies++] = i; serverStatusOut.m_sdfLoadedArgs.m_bodyUniqueIds[actualNumBodies++] = usedHandle;
} }
} }
serverStatusOut.m_sdfLoadedArgs.m_numBodies = actualNumBodies; serverStatusOut.m_sdfLoadedArgs.m_numBodies = actualNumBodies;
@@ -4216,10 +4217,12 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
case CMD_RESET_SIMULATION: case CMD_RESET_SIMULATION:
{ {
BT_PROFILE("CMD_RESET_SIMULATION"); BT_PROFILE("CMD_RESET_SIMULATION");
m_data->m_guiHelper->setVisualizerFlag(COV_ENABLE_SYNC_RENDERING_INTERNAL,0);
resetSimulation(); resetSimulation();
m_data->m_guiHelper->setVisualizerFlag(COV_ENABLE_SYNC_RENDERING_INTERNAL,1);
SharedMemoryStatus& serverCmd =serverStatusOut; SharedMemoryStatus& serverCmd =serverStatusOut;
serverCmd.m_type = CMD_RESET_SIMULATION_COMPLETED; serverCmd.m_type = CMD_RESET_SIMULATION_COMPLETED;
hasStatus = true; hasStatus = true;
@@ -5062,6 +5065,8 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
serverCmd.m_removeObjectArgs.m_numBodies = 0; serverCmd.m_removeObjectArgs.m_numBodies = 0;
serverCmd.m_removeObjectArgs.m_numUserConstraints = 0; serverCmd.m_removeObjectArgs.m_numUserConstraints = 0;
m_data->m_guiHelper->setVisualizerFlag(COV_ENABLE_SYNC_RENDERING_INTERNAL,0);
for (int i=0;i<clientCmd.m_removeObjectArgs.m_numBodies;i++) for (int i=0;i<clientCmd.m_removeObjectArgs.m_numBodies;i++)
{ {
int bodyUniqueId = clientCmd.m_removeObjectArgs.m_bodyUniqueIds[i]; int bodyUniqueId = clientCmd.m_removeObjectArgs.m_bodyUniqueIds[i];
@@ -5142,7 +5147,8 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
m_data->m_bodyHandles.freeHandle(bodyUniqueId); m_data->m_bodyHandles.freeHandle(bodyUniqueId);
} }
m_data->m_guiHelper->setVisualizerFlag(COV_ENABLE_SYNC_RENDERING_INTERNAL,1);
hasStatus = true; hasStatus = true;
break; break;
@@ -5929,11 +5935,14 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
//static int skip=1; //static int skip=1;
void PhysicsServerCommandProcessor::renderScene() void PhysicsServerCommandProcessor::renderScene(int renderFlags)
{ {
if (m_data->m_guiHelper) if (m_data->m_guiHelper)
{ {
m_data->m_guiHelper->syncPhysicsToGraphics(m_data->m_dynamicsWorld); if (0==(renderFlags&COV_DISABLE_SYNC_RENDERING))
{
m_data->m_guiHelper->syncPhysicsToGraphics(m_data->m_dynamicsWorld);
}
m_data->m_guiHelper->render(m_data->m_dynamicsWorld); m_data->m_guiHelper->render(m_data->m_dynamicsWorld);
} }
#ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD #ifdef USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD

View File

@@ -78,7 +78,7 @@ public:
return false; return false;
}; };
virtual void renderScene(); virtual void renderScene(int renderFlags);
virtual void physicsDebugDraw(int debugDrawFlags); virtual void physicsDebugDraw(int debugDrawFlags);
virtual void setGuiHelper(struct GUIHelperInterface* guiHelper); virtual void setGuiHelper(struct GUIHelperInterface* guiHelper);

View File

@@ -25,6 +25,11 @@
//@todo(erwincoumans) those globals are hacks for a VR demo, move this to Python/pybullet! //@todo(erwincoumans) those globals are hacks for a VR demo, move this to Python/pybullet!
extern btVector3 gLastPickPos; extern btVector3 gLastPickPos;
bool gEnablePicking=true;
bool gEnableTeleporting=true;
bool gEnableRendering= true;
bool gEnableSyncPhysicsRendering= true;
bool gEnableUpdateDebugDrawLines = true;
btVector3 gVRTeleportPosLocal(0,0,0); btVector3 gVRTeleportPosLocal(0,0,0);
btQuaternion gVRTeleportOrnLocal(0,0,0,1); btQuaternion gVRTeleportOrnLocal(0,0,0,1);
@@ -181,6 +186,7 @@ enum MultiThreadedGUIHelperCommunicationEnums
eGUIDumpFramesToVideo, eGUIDumpFramesToVideo,
eGUIHelperRemoveGraphicsInstance, eGUIHelperRemoveGraphicsInstance,
eGUIHelperChangeGraphicsInstanceRGBAColor, eGUIHelperChangeGraphicsInstanceRGBAColor,
eGUIHelperSetVisualizerFlag,
}; };
@@ -232,7 +238,8 @@ struct MyMouseCommand
struct MotionArgs struct MotionArgs
{ {
MotionArgs() MotionArgs()
:m_physicsServerPtr(0) :m_physicsServerPtr(0),
m_debugDrawFlags(0)
{ {
for (int i=0;i<MAX_VR_CONTROLLERS;i++) for (int i=0;i<MAX_VR_CONTROLLERS;i++)
{ {
@@ -254,6 +261,7 @@ struct MotionArgs
b3CriticalSection* m_cs3; b3CriticalSection* m_cs3;
b3CriticalSection* m_csGUI; b3CriticalSection* m_csGUI;
int m_debugDrawFlags;
btAlignedObjectArray<MyMouseCommand> m_mouseCommands; btAlignedObjectArray<MyMouseCommand> m_mouseCommands;
@@ -452,6 +460,15 @@ void MotionThreadFunc(void* userPtr,void* lsMemory)
{ {
args->m_physicsServerPtr->stepSimulationRealTime(deltaTimeInSeconds, args->m_sendVrControllerEvents,numSendVrControllers, keyEvents, args->m_sendKeyEvents.size()); args->m_physicsServerPtr->stepSimulationRealTime(deltaTimeInSeconds, args->m_sendVrControllerEvents,numSendVrControllers, keyEvents, args->m_sendKeyEvents.size());
} }
{
if (gEnableUpdateDebugDrawLines)
{
args->m_csGUI->lock();
args->m_physicsServerPtr->physicsDebugDraw(args->m_debugDrawFlags);
gEnableUpdateDebugDrawLines=false;
args->m_csGUI->unlock();
}
}
deltaTimeInSeconds = 0; deltaTimeInSeconds = 0;
} }
@@ -546,6 +563,138 @@ struct UserDebugText
}; };
struct LineSegment
{
btVector3 m_from;
btVector3 m_to;
};
struct ColorWidth
{
btVector3FloatData m_color;
int width;
int getHash() const
{
unsigned char r = (unsigned char) m_color.m_floats[0]*255;
unsigned char g = (unsigned char) m_color.m_floats[1]*255;
unsigned char b = (unsigned char) m_color.m_floats[2]*255;
unsigned char w = width;
return r+(256*g)+(256*256*b)+(256*256*256*w);
}
bool equals(const ColorWidth& other) const
{
bool same = ((width == other.width) && (m_color.m_floats[0] == other.m_color.m_floats[0]) &&
(m_color.m_floats[1] == other.m_color.m_floats[1]) &&
(m_color.m_floats[2] == other.m_color.m_floats[2]));
return same;
}
};
ATTRIBUTE_ALIGNED16( class )MultithreadedDebugDrawer : public btIDebugDraw
{
class GUIHelperInterface* m_guiHelper;
int m_debugMode;
btAlignedObjectArray< btAlignedObjectArray<unsigned int> > m_sortedIndices;
btAlignedObjectArray< btAlignedObjectArray<btVector3FloatData> > m_sortedLines;
btHashMap<ColorWidth,int> m_hashedLines;
public:
void drawDebugDrawerLines()
{
if (m_hashedLines.size())
{
for (int i=0;i<m_hashedLines.size();i++)
{
ColorWidth cw = m_hashedLines.getKeyAtIndex(i);
int index = *m_hashedLines.getAtIndex(i);
int stride = sizeof(btVector3FloatData);
const float* positions = &m_sortedLines[index][0].m_floats[0];
int numPoints = m_sortedLines[index].size();
const unsigned int* indices = &m_sortedIndices[index][0];
int numIndices = m_sortedIndices[index].size();
m_guiHelper->getRenderInterface()->drawLines(positions,cw.m_color.m_floats,numPoints, stride, indices,numIndices,cw.width);
}
}
}
MultithreadedDebugDrawer(GUIHelperInterface* guiHelper)
:m_guiHelper(guiHelper),
m_debugMode(0)
{
}
virtual ~MultithreadedDebugDrawer()
{
}
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
{
ColorWidth cw;
color.serializeFloat(cw.m_color);
cw.width = 1;
int index = -1;
int* indexPtr = m_hashedLines.find(cw);
if (indexPtr)
{
index = *indexPtr;
} else
{
index = m_sortedLines.size();
m_sortedLines.expand();
m_sortedIndices.expand();
m_hashedLines.insert(cw,index);
}
btAssert(index>=0);
if (index>=0)
{
btVector3FloatData from1,toX1;
m_sortedIndices[index].push_back(m_sortedLines[index].size());
from.serializeFloat(from1);
m_sortedLines[index].push_back(from1);
m_sortedIndices[index].push_back(m_sortedLines[index].size());
to.serializeFloat(toX1);
m_sortedLines[index].push_back(toX1);
}
}
}
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
{
drawLine(PointOnB,PointOnB+normalOnB*distance,color);
btVector3 ncolor(0, 0, 0);
drawLine(PointOnB, PointOnB + normalOnB*0.01, ncolor);
}
virtual void reportErrorWarning(const char* warningString)
{
}
virtual void draw3dText(const btVector3& location,const char* textString)
{
}
virtual void setDebugMode(int debugMode)
{
m_debugMode = debugMode;
}
virtual int getDebugMode() const
{
return m_debugMode;
}
virtual void clearLines()
{
m_hashedLines.clear();
m_sortedIndices.clear();
m_sortedLines.clear();
}
virtual void flushLines()
{
}
};
class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface
{ {
@@ -555,17 +704,19 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface
b3CriticalSection* m_cs2; b3CriticalSection* m_cs2;
b3CriticalSection* m_cs3; b3CriticalSection* m_cs3;
b3CriticalSection* m_csGUI; b3CriticalSection* m_csGUI;
public: public:
void setVisualizerFlag(int flag, int enable) MultithreadedDebugDrawer* m_debugDraw;
{ void drawDebugDrawerLines()
m_childGuiHelper->setVisualizerFlag(flag,enable); {
} if (m_debugDraw)
{
m_debugDraw->drawDebugDrawerLines();
}
}
GUIHelperInterface* m_childGuiHelper; GUIHelperInterface* m_childGuiHelper;
int m_uidGenerator; int m_uidGenerator;
@@ -626,6 +777,7 @@ public:
m_cs2(0), m_cs2(0),
m_cs3(0), m_cs3(0),
m_csGUI(0), m_csGUI(0),
m_debugDraw(0),
m_uidGenerator(0), m_uidGenerator(0),
m_texels(0), m_texels(0),
m_textureId(-1) m_textureId(-1)
@@ -727,7 +879,18 @@ public:
virtual void createPhysicsDebugDrawer( btDiscreteDynamicsWorld* rbWorld) virtual void createPhysicsDebugDrawer( btDiscreteDynamicsWorld* rbWorld)
{ {
m_childGuiHelper->createPhysicsDebugDrawer(rbWorld); btAssert(rbWorld);
if (m_debugDraw)
{
delete m_debugDraw;
m_debugDraw = 0;
}
m_debugDraw = new MultithreadedDebugDrawer(this);
rbWorld->setDebugDrawer(m_debugDraw );
//m_childGuiHelper->createPhysicsDebugDrawer(rbWorld);
} }
virtual int registerTexture(const unsigned char* texels, int width, int height) virtual int registerTexture(const unsigned char* texels, int width, int height)
@@ -759,6 +922,25 @@ public:
return m_shapeIndex; return m_shapeIndex;
} }
int m_visualizerFlag;
int m_visualizerEnable;
void setVisualizerFlag(int flag, int enable)
{
m_visualizerFlag = flag;
m_visualizerEnable = enable;
m_cs->lock();
m_cs->setSharedParam(1,eGUIHelperSetVisualizerFlag);
workerThreadWait();
}
void setVisualizerFlagCallback(VisualizerFlagCallback callback)
{
m_childGuiHelper->setVisualizerFlagCallback(callback);
}
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling) virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
{ {
m_shapeIndex = shapeIndex; m_shapeIndex = shapeIndex;
@@ -998,6 +1180,10 @@ public:
} }
const char* m_mp4FileName; const char* m_mp4FileName;
virtual void dumpFramesToVideo(const char* mp4FileName) virtual void dumpFramesToVideo(const char* mp4FileName)
{ {
@@ -1558,6 +1744,38 @@ void PhysicsServerExample::updateGraphics()
m_multiThreadedHelper->mainThreadRelease(); m_multiThreadedHelper->mainThreadRelease();
break; break;
} }
case eGUIHelperSetVisualizerFlag:
{
int flag = m_multiThreadedHelper->m_visualizerFlag;
int enable = m_multiThreadedHelper->m_visualizerEnable;
if (flag==COV_ENABLE_VR_TELEPORTING)
{
gEnableTeleporting = enable;
}
if (flag == COV_ENABLE_VR_PICKING)
{
gEnablePicking = enable;
}
if (flag ==COV_ENABLE_SYNC_RENDERING_INTERNAL)
{
gEnableSyncPhysicsRendering = enable;
}
if (flag == COV_ENABLE_RENDERING)
{
gEnableRendering = enable;
}
m_multiThreadedHelper->m_childGuiHelper->setVisualizerFlag(m_multiThreadedHelper->m_visualizerFlag,m_multiThreadedHelper->m_visualizerEnable);
m_multiThreadedHelper->mainThreadRelease();
break;
}
case eGUIHelperRegisterGraphicsInstance: case eGUIHelperRegisterGraphicsInstance:
{ {
m_multiThreadedHelper->m_instanceId = m_multiThreadedHelper->m_childGuiHelper->registerGraphicsInstance( m_multiThreadedHelper->m_instanceId = m_multiThreadedHelper->m_childGuiHelper->registerGraphicsInstance(
@@ -1761,32 +1979,6 @@ extern double gSubStep;
extern int gVRTrackingObjectUniqueId; extern int gVRTrackingObjectUniqueId;
extern btTransform gVRTrackingObjectTr; extern btTransform gVRTrackingObjectTr;
struct LineSegment
{
btVector3 m_from;
btVector3 m_to;
};
struct ColorWidth
{
btVector3FloatData m_color;
int width;
int getHash() const
{
unsigned char r = (unsigned char) m_color.m_floats[0]*255;
unsigned char g = (unsigned char) m_color.m_floats[1]*255;
unsigned char b = (unsigned char) m_color.m_floats[2]*255;
unsigned char w = width;
return r+(256*g)+(256*256*b)+(256*256*256*w);
}
bool equals(const ColorWidth& other) const
{
bool same = ((width == other.width) && (m_color.m_floats[0] == other.m_color.m_floats[0]) &&
(m_color.m_floats[1] == other.m_color.m_floats[1]) &&
(m_color.m_floats[2] == other.m_color.m_floats[2]));
return same;
}
};
void PhysicsServerExample::drawUserDebugLines() void PhysicsServerExample::drawUserDebugLines()
{ {
@@ -2013,30 +2205,41 @@ void PhysicsServerExample::renderScene()
m_multiThreadedHelper->m_childGuiHelper->getRenderInterface()-> m_multiThreadedHelper->m_childGuiHelper->getRenderInterface()->
getActiveCamera()->setVRCameraOffsetTransform(vrOffset); getActiveCamera()->setVRCameraOffsetTransform(vrOffset);
} }
m_physicsServer.renderScene(); if (gEnableRendering)
for (int i=0;i<MAX_VR_CONTROLLERS;i++)
{ {
if (m_args[0].m_isVrControllerPicking[i] || m_args[0].m_isVrControllerDragging[i]) int renderFlags = 0;
if (!gEnableSyncPhysicsRendering)
{ {
btVector3 from = m_args[0].m_vrControllerPos[i]; renderFlags|=1;//COV_DISABLE_SYNC_RENDERING;
btMatrix3x3 mat(m_args[0].m_vrControllerOrn[i]); }
m_physicsServer.renderScene(renderFlags);
}
btVector3 toX = from+mat.getColumn(0); if (gEnablePicking)
btVector3 toY = from+mat.getColumn(1); {
btVector3 toZ = from+mat.getColumn(2); for (int i=0;i<MAX_VR_CONTROLLERS;i++)
{
if (m_args[0].m_isVrControllerPicking[i] || m_args[0].m_isVrControllerDragging[i])
{
btVector3 from = m_args[0].m_vrControllerPos[i];
btMatrix3x3 mat(m_args[0].m_vrControllerOrn[i]);
int width = 2; btVector3 toX = from+mat.getColumn(0);
btVector3 toY = from+mat.getColumn(1);
btVector3 toZ = from+mat.getColumn(2);
int width = 2;
btVector4 color; btVector4 color;
color=btVector4(1,0,0,1); color=btVector4(1,0,0,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toX,color,width); m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toX,color,width);
color=btVector4(0,1,0,1); color=btVector4(0,1,0,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toY,color,width); m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toY,color,width);
color=btVector4(0,0,1,1); color=btVector4(0,0,1,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toZ,color,width); m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toZ,color,width);
}
} }
} }
@@ -2058,9 +2261,18 @@ void PhysicsServerExample::physicsDebugDraw(int debugDrawFlags)
{ {
drawUserDebugLines(); drawUserDebugLines();
///debug rendering if (gEnableRendering)
m_physicsServer.physicsDebugDraw(debugDrawFlags); {
///debug rendering
//m_physicsServer.physicsDebugDraw(debugDrawFlags);
m_args[0].m_csGUI->lock();
//draw stuff and flush?
this->m_multiThreadedHelper->m_debugDraw->drawDebugDrawerLines();
m_args[0].m_debugDrawFlags = debugDrawFlags;
gEnableUpdateDebugDrawLines = true;
m_args[0].m_csGUI->unlock();
}
} }
@@ -2132,10 +2344,12 @@ btVector3 PhysicsServerExample::getRayTo(int x,int y)
extern int gSharedMemoryKey; extern int gSharedMemoryKey;
class CommonExampleInterface* PhysicsServerCreateFunc(struct CommonExampleOptions& options) class CommonExampleInterface* PhysicsServerCreateFunc(struct CommonExampleOptions& options)
{ {
MultiThreadedOpenGLGuiHelper* guiHelperWrapper = new MultiThreadedOpenGLGuiHelper(options.m_guiHelper->getAppInterface(),options.m_guiHelper); MultiThreadedOpenGLGuiHelper* guiHelperWrapper = new MultiThreadedOpenGLGuiHelper(options.m_guiHelper->getAppInterface(),options.m_guiHelper);
PhysicsServerExample* example = new PhysicsServerExample(guiHelperWrapper, PhysicsServerExample* example = new PhysicsServerExample(guiHelperWrapper,
options.m_sharedMem, options.m_sharedMem,
@@ -2250,7 +2464,7 @@ void PhysicsServerExample::vrControllerButtonCallback(int controllerId, int butt
} }
if (button==1) if (button==1 && gEnableTeleporting)
{ {
m_args[0].m_isVrControllerTeleporting[controllerId] = true; m_args[0].m_isVrControllerTeleporting[controllerId] = true;
} }
@@ -2262,7 +2476,7 @@ void PhysicsServerExample::vrControllerButtonCallback(int controllerId, int butt
else else
{ {
if (button == 33) if (button == 33 && gEnablePicking)
{ {
m_args[0].m_isVrControllerPicking[controllerId] = (state != 0); m_args[0].m_isVrControllerPicking[controllerId] = (state != 0);
m_args[0].m_isVrControllerReleasing[controllerId] = (state == 0); m_args[0].m_isVrControllerReleasing[controllerId] = (state == 0);

View File

@@ -274,9 +274,9 @@ void PhysicsServerSharedMemory::processClientCommands()
} }
} }
void PhysicsServerSharedMemory::renderScene() void PhysicsServerSharedMemory::renderScene(int renderFlags)
{ {
m_data->m_commandProcessor->renderScene(); m_data->m_commandProcessor->renderScene(renderFlags);

View File

@@ -42,7 +42,7 @@ public:
//and for physics visualization. The idea is that physicsDebugDraw can also send wireframe //and for physics visualization. The idea is that physicsDebugDraw can also send wireframe
//to a physics client, over shared memory //to a physics client, over shared memory
void physicsDebugDraw(int debugDrawFlags); void physicsDebugDraw(int debugDrawFlags);
void renderScene(); void renderScene(int renderFlags);
void enableCommandLogging(bool enable, const char* fileName); void enableCommandLogging(bool enable, const char* fileName);
void replayFromLogFile(const char* fileName); void replayFromLogFile(const char* fileName);

View File

@@ -183,7 +183,7 @@ bool SharedMemoryCommandProcessor::receiveStatus(struct SharedMemoryStatus& serv
return false; return false;
} }
void SharedMemoryCommandProcessor::renderScene() void SharedMemoryCommandProcessor::renderScene(int renderFlags)
{ {
} }

View File

@@ -23,7 +23,7 @@ public:
virtual bool receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes); virtual bool receiveStatus(struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes);
virtual void renderScene(); virtual void renderScene(int renderFlags);
virtual void physicsDebugDraw(int debugDrawFlags); virtual void physicsDebugDraw(int debugDrawFlags);
virtual void setGuiHelper(struct GUIHelperInterface* guiHelper); virtual void setGuiHelper(struct GUIHelperInterface* guiHelper);

View File

@@ -225,11 +225,11 @@ int b3InProcessMouseButtonCallback(b3PhysicsClientHandle clientHandle, int butto
} }
b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(struct GUIHelperInterface* guiHelper) b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(void* guiHelperPtr)
{ {
GUIHelperInterface* guiHelper = (GUIHelperInterface*) guiHelperPtr;
InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper); InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper);
//InProcessPhysicsClientFromGuiHelper* cl = new InProcessPhysicsClientFromGuiHelper(guiHelper); //InProcessPhysicsClientFromGuiHelper* cl = new InProcessPhysicsClientFromGuiHelper(guiHelper);
cl->connect(); cl->connect();
return (b3PhysicsClientHandle ) cl; return (b3PhysicsClientHandle ) cl;
} }

View File

@@ -14,7 +14,7 @@ b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnect(int argc, char* a
b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThread(int argc, char* argv[]); b3PhysicsClientHandle b3CreateInProcessPhysicsServerAndConnectMainThread(int argc, char* argv[]);
b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(struct GUIHelperInterface* guiHelper); b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect(void* guiHelperPtr);
///ignore the following APIs, they are for internal use for example browser ///ignore the following APIs, they are for internal use for example browser
void b3InProcessRenderSceneInternal(b3PhysicsClientHandle clientHandle); void b3InProcessRenderSceneInternal(b3PhysicsClientHandle clientHandle);

View File

@@ -495,6 +495,11 @@ enum b3ConfigureDebugVisualizerEnum
COV_ENABLE_GUI=1, COV_ENABLE_GUI=1,
COV_ENABLE_SHADOWS, COV_ENABLE_SHADOWS,
COV_ENABLE_WIREFRAME, COV_ENABLE_WIREFRAME,
COV_ENABLE_VR_TELEPORTING,
COV_ENABLE_VR_PICKING,
COV_ENABLE_VR_RENDER_CONTROLLERS,
COV_ENABLE_RENDERING,
COV_ENABLE_SYNC_RENDERING_INTERNAL,
}; };
enum eCONNECT_METHOD { enum eCONNECT_METHOD {

View File

@@ -516,7 +516,6 @@ void TinyRendererVisualShapeConverter::convertVisualShapes(
btAssert(linkPtr); // TODO: remove if (not doing it now, because diff will be 50+ lines) btAssert(linkPtr); // TODO: remove if (not doing it now, because diff will be 50+ lines)
if (linkPtr) if (linkPtr)
{ {
const btArray<UrdfVisual>* shapeArray;
bool useVisual; bool useVisual;
int cnt = 0; int cnt = 0;
if (linkPtr->m_visualArray.size() > 0) if (linkPtr->m_visualArray.size() > 0)
@@ -1011,6 +1010,7 @@ void TinyRendererVisualShapeConverter::resetAll()
} }
m_data->m_swRenderInstances.clear(); m_data->m_swRenderInstances.clear();
m_data->m_visualShapes.clear();
} }
void TinyRendererVisualShapeConverter::activateShapeTexture(int shapeUniqueId, int textureUniqueId) void TinyRendererVisualShapeConverter::activateShapeTexture(int shapeUniqueId, int textureUniqueId)

View File

@@ -367,6 +367,49 @@ void MyKeyboardCallback(int key, int state)
prevKeyboardCallback(key,state); prevKeyboardCallback(key,state);
} }
#include "../SharedMemory/SharedMemoryPublic.h"
extern bool useShadowMap;
bool gEnableVRRenderControllers=true;
void VRPhysicsServerVisualizerFlagCallback(int flag, bool enable)
{
if (flag == COV_ENABLE_SHADOWS)
{
useShadowMap = enable;
}
if (flag == COV_ENABLE_GUI)
{
//there is no regular GUI here, but disable the
}
if (flag == COV_ENABLE_VR_RENDER_CONTROLLERS)
{
gEnableVRRenderControllers = enable;
}
if (flag == COV_ENABLE_WIREFRAME)
{
if (enable)
{
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
//gDebugDrawFlags |= btIDebugDraw::DBG_DrawWireframe;
} else
{
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
//gDebugDrawFlags &= ~btIDebugDraw::DBG_DrawWireframe;
}
}
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: // Purpose:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -418,6 +461,7 @@ bool CMainApplication::BInit()
sGuiPtr = new OpenGLGuiHelper(m_app,false); sGuiPtr = new OpenGLGuiHelper(m_app,false);
sGuiPtr->setVisualizerFlagCallback(VRPhysicsServerVisualizerFlagCallback);
sGuiPtr->setVRMode(true); sGuiPtr->setVRMode(true);
//sGuiPtr = new DummyGUIHelper; //sGuiPtr = new DummyGUIHelper;
@@ -773,6 +817,7 @@ bool CMainApplication::HandleInput()
if (button==2) if (button==2)
{ {
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
///todo(erwincoumans) can't use reguar debug drawer, because physics/graphics are not in sync ///todo(erwincoumans) can't use reguar debug drawer, because physics/graphics are not in sync
///so it can (and likely will) cause crashes ///so it can (and likely will) cause crashes
///add a special debug drawer that deals with this ///add a special debug drawer that deals with this
@@ -810,7 +855,6 @@ bool CMainApplication::HandleInput()
if (button==2) if (button==2)
{ {
gDebugDrawFlags = 0; gDebugDrawFlags = 0;
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
} }
sExample->vrControllerButtonCallback(unDevice, button, 0, pos, orn); sExample->vrControllerButtonCallback(unDevice, button, 0, pos, orn);
@@ -1379,6 +1423,8 @@ extern int gGraspingController;
void CMainApplication::DrawControllers() void CMainApplication::DrawControllers()
{ {
// don't draw controllers if somebody else has input focus // don't draw controllers if somebody else has input focus
if( m_pHMD->IsInputFocusCapturedByAnotherProcess() ) if( m_pHMD->IsInputFocusCapturedByAnotherProcess() )
return; return;
@@ -1866,39 +1912,42 @@ void CMainApplication::RenderScene( vr::Hmd_Eye nEye )
bool bIsInputCapturedByAnotherProcess = m_pHMD->IsInputFocusCapturedByAnotherProcess(); bool bIsInputCapturedByAnotherProcess = m_pHMD->IsInputFocusCapturedByAnotherProcess();
if( !bIsInputCapturedByAnotherProcess ) if (gEnableVRRenderControllers)
{ {
// draw the controller axis lines if( !bIsInputCapturedByAnotherProcess )
glUseProgram( m_unControllerTransformProgramID ); {
glUniformMatrix4fv( m_nControllerMatrixLocation, 1, GL_FALSE, GetCurrentViewProjectionMatrix( nEye ).get() ); // draw the controller axis lines
glBindVertexArray( m_unControllerVAO ); glUseProgram( m_unControllerTransformProgramID );
glDrawArrays( GL_LINES, 0, m_uiControllerVertcount ); glUniformMatrix4fv( m_nControllerMatrixLocation, 1, GL_FALSE, GetCurrentViewProjectionMatrix( nEye ).get() );
glBindVertexArray( 0 ); glBindVertexArray( m_unControllerVAO );
glDrawArrays( GL_LINES, 0, m_uiControllerVertcount );
glBindVertexArray( 0 );
}
// ----- Render Model rendering -----
glUseProgram( m_unRenderModelProgramID );
for( uint32_t unTrackedDevice = 0; unTrackedDevice < vr::k_unMaxTrackedDeviceCount; unTrackedDevice++ )
{
if( !m_rTrackedDeviceToRenderModel[ unTrackedDevice ] || !m_rbShowTrackedDevice[ unTrackedDevice ] )
continue;
const vr::TrackedDevicePose_t & pose = m_rTrackedDevicePose[ unTrackedDevice ];
if( !pose.bPoseIsValid )
continue;
if( bIsInputCapturedByAnotherProcess && m_pHMD->GetTrackedDeviceClass( unTrackedDevice ) == vr::TrackedDeviceClass_Controller )
continue;
const Matrix4 & matDeviceToTracking = m_rmat4DevicePose[ unTrackedDevice ];
Matrix4 matMVP = GetCurrentViewProjectionMatrix( nEye ) * matDeviceToTracking;
glUniformMatrix4fv( m_nRenderModelMatrixLocation, 1, GL_FALSE, matMVP.get() );
m_rTrackedDeviceToRenderModel[ unTrackedDevice ]->Draw();
}
} }
glUseProgram( 0 );
// ----- Render Model rendering -----
glUseProgram( m_unRenderModelProgramID );
for( uint32_t unTrackedDevice = 0; unTrackedDevice < vr::k_unMaxTrackedDeviceCount; unTrackedDevice++ )
{
if( !m_rTrackedDeviceToRenderModel[ unTrackedDevice ] || !m_rbShowTrackedDevice[ unTrackedDevice ] )
continue;
const vr::TrackedDevicePose_t & pose = m_rTrackedDevicePose[ unTrackedDevice ];
if( !pose.bPoseIsValid )
continue;
if( bIsInputCapturedByAnotherProcess && m_pHMD->GetTrackedDeviceClass( unTrackedDevice ) == vr::TrackedDeviceClass_Controller )
continue;
const Matrix4 & matDeviceToTracking = m_rmat4DevicePose[ unTrackedDevice ];
Matrix4 matMVP = GetCurrentViewProjectionMatrix( nEye ) * matDeviceToTracking;
glUniformMatrix4fv( m_nRenderModelMatrixLocation, 1, GL_FALSE, matMVP.get() );
m_rTrackedDeviceToRenderModel[ unTrackedDevice ]->Draw();
}
glUseProgram( 0 );
} }

View File

@@ -6346,6 +6346,11 @@ initpybullet(void)
PyModule_AddIntConstant(m, "COV_ENABLE_GUI", COV_ENABLE_GUI); PyModule_AddIntConstant(m, "COV_ENABLE_GUI", COV_ENABLE_GUI);
PyModule_AddIntConstant(m, "COV_ENABLE_SHADOWS", COV_ENABLE_SHADOWS); PyModule_AddIntConstant(m, "COV_ENABLE_SHADOWS", COV_ENABLE_SHADOWS);
PyModule_AddIntConstant(m, "COV_ENABLE_WIREFRAME", COV_ENABLE_WIREFRAME); PyModule_AddIntConstant(m, "COV_ENABLE_WIREFRAME", COV_ENABLE_WIREFRAME);
PyModule_AddIntConstant(m, "COV_ENABLE_VR_PICKING", COV_ENABLE_VR_PICKING);
PyModule_AddIntConstant(m, "COV_ENABLE_VR_TELEPORTING", COV_ENABLE_VR_TELEPORTING);
PyModule_AddIntConstant(m, "COV_ENABLE_RENDERING", COV_ENABLE_RENDERING);
PyModule_AddIntConstant(m, "COV_ENABLE_VR_RENDER_CONTROLLERS", COV_ENABLE_VR_RENDER_CONTROLLERS);
PyModule_AddIntConstant(m, "ER_TINY_RENDERER", ER_TINY_RENDERER); PyModule_AddIntConstant(m, "ER_TINY_RENDERER", ER_TINY_RENDERER);
PyModule_AddIntConstant(m, "ER_BULLET_HARDWARE_OPENGL", ER_BULLET_HARDWARE_OPENGL); PyModule_AddIntConstant(m, "ER_BULLET_HARDWARE_OPENGL", ER_BULLET_HARDWARE_OPENGL);

View File

@@ -1514,6 +1514,8 @@ void btCollisionWorld::debugDrawWorld()
{ {
if (getDebugDrawer()) if (getDebugDrawer())
{ {
getDebugDrawer()->clearLines();
btIDebugDraw::DefaultColors defaultColors = getDebugDrawer()->getDefaultColors(); btIDebugDraw::DefaultColors defaultColors = getDebugDrawer()->getDefaultColors();
if ( getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints) if ( getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)

View File

@@ -798,6 +798,8 @@ void btMultiBodyDynamicsWorld::debugDrawWorld()
{ {
BT_PROFILE("btMultiBodyDynamicsWorld debugDrawWorld"); BT_PROFILE("btMultiBodyDynamicsWorld debugDrawWorld");
btDiscreteDynamicsWorld::debugDrawWorld();
bool drawConstraints = false; bool drawConstraints = false;
if (getDebugDrawer()) if (getDebugDrawer())
{ {
@@ -867,7 +869,7 @@ void btMultiBodyDynamicsWorld::debugDrawWorld()
} }
} }
btDiscreteDynamicsWorld::debugDrawWorld();
} }

View File

@@ -469,6 +469,10 @@ class btIDebugDraw
drawLine(transform*pt2,transform*pt3,color); drawLine(transform*pt2,transform*pt3,color);
} }
virtual void clearLines()
{
}
virtual void flushLines() virtual void flushLines()
{ {
} }