Merge pull request #1046 from erwincoumans/master

enable --opengl2 fallback for example browser in 'physics server' mode too.
This commit is contained in:
erwincoumans 2017-03-28 08:20:46 -07:00 committed by GitHub
commit 993e98e37a
15 changed files with 638 additions and 93 deletions

View File

@ -495,10 +495,10 @@ static void saveCurrentSettings(int currentEntry,const char* startFileName)
{ {
fprintf(f,"--enable_experimental_opencl\n"); fprintf(f,"--enable_experimental_opencl\n");
} }
if (sUseOpenGL2 ) // if (sUseOpenGL2 )
{ // {
fprintf(f,"--opengl2\n"); // fprintf(f,"--opengl2\n");
} // }
fclose(f); fclose(f);
} }
@ -1237,8 +1237,8 @@ void OpenGLExampleBrowser::update(float deltaTime)
if (renderGrid) if (renderGrid)
{ {
BT_PROFILE("Draw Grid"); BT_PROFILE("Draw Grid");
glPolygonOffset(3.0, 3); //glPolygonOffset(3.0, 3);
glEnable(GL_POLYGON_OFFSET_FILL); //glEnable(GL_POLYGON_OFFSET_FILL);
s_app->drawGrid(dg); s_app->drawGrid(dg);
} }

View File

@ -10,8 +10,6 @@
#include "../OpenGLWindow/SimpleCamera.h" #include "../OpenGLWindow/SimpleCamera.h"
#include "../OpenGLWindow/GLInstanceGraphicsShape.h" #include "../OpenGLWindow/GLInstanceGraphicsShape.h"
//backwards compatibility
#include "GL_ShapeDrawer.h"
#define BT_LINE_BATCH_SIZE 512 #define BT_LINE_BATCH_SIZE 512
@ -147,7 +145,6 @@ struct OpenGLGuiHelperInternalData
{ {
struct CommonGraphicsApp* m_glApp; struct CommonGraphicsApp* m_glApp;
class MyDebugDrawer* m_debugDraw; class MyDebugDrawer* m_debugDraw;
GL_ShapeDrawer* m_gl2ShapeDrawer;
bool m_vrMode; bool m_vrMode;
int m_vrSkipShadowPass; int m_vrSkipShadowPass;
@ -178,19 +175,13 @@ OpenGLGuiHelper::OpenGLGuiHelper(CommonGraphicsApp* glApp, bool useOpenGL2)
m_data->m_glApp = glApp; m_data->m_glApp = glApp;
m_data->m_debugDraw = 0; m_data->m_debugDraw = 0;
m_data->m_gl2ShapeDrawer = 0;
if (useOpenGL2)
{
m_data->m_gl2ShapeDrawer = new GL_ShapeDrawer();
}
} }
OpenGLGuiHelper::~OpenGLGuiHelper() OpenGLGuiHelper::~OpenGLGuiHelper()
{ {
delete m_data->m_debugDraw; delete m_data->m_debugDraw;
delete m_data->m_gl2ShapeDrawer;
delete m_data; delete m_data;
} }
@ -337,13 +328,7 @@ void OpenGLGuiHelper::render(const btDiscreteDynamicsWorld* rbWorld)
m_data->m_glApp->m_renderer->renderScene(); m_data->m_glApp->m_renderer->renderScene();
} }
//backwards compatible OpenGL2 rendering
if (m_data->m_gl2ShapeDrawer && rbWorld)
{
m_data->m_gl2ShapeDrawer->enableTexture(true);
m_data->m_gl2ShapeDrawer->drawScene(rbWorld,true, m_data->m_glApp->getUpAxis());
}
} }
void OpenGLGuiHelper::createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld) void OpenGLGuiHelper::createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld)
{ {

View File

@ -1,13 +1,15 @@
#include "SimpleOpenGL2App.h" #include "SimpleOpenGL2App.h"
#define USE_OPENGL2 #define USE_OPENGL2
#include "OpenGLInclude.h" #include "OpenGLInclude.h"
#include "ShapeData.h"
#include "Bullet3Common/b3Logging.h"//b3Assert? #include "Bullet3Common/b3Logging.h"//b3Assert?
#include "Bullet3Common/b3Scalar.h" #include "Bullet3Common/b3Scalar.h"
#include "Bullet3Common/b3AlignedObjectArray.h" #include "Bullet3Common/b3AlignedObjectArray.h"
#include "Bullet3Common/b3Vector3.h" #include "Bullet3Common/b3Vector3.h"
#include "Bullet3Common/b3Quaternion.h"
#include "../CommonInterfaces/CommonRenderInterface.h" #include "../CommonInterfaces/CommonRenderInterface.h"
#include "../OpenGLWindow/GLPrimitiveRenderer.h" #include "../OpenGLWindow/GLPrimitiveRenderer.h"
#include "GLInstanceGraphicsShape.h"
#include "stdlib.h" #include "stdlib.h"
#include "TwFonts.h" #include "TwFonts.h"
#ifdef __APPLE__ #ifdef __APPLE__
@ -161,13 +163,13 @@ SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height)
b3Assert(glGetError() ==GL_NO_ERROR); b3Assert(glGetError() ==GL_NO_ERROR);
//m_instancingRenderer = new GLInstancingRenderer(128*1024,32*1024*1024); //m_renderer = new GLInstancingRenderer(128*1024,32*1024*1024);
//m_instancingRenderer->init(); //m_renderer->init();
//m_instancingRenderer->resize(width,height); //m_renderer->resize(width,height);
b3Assert(glGetError() ==GL_NO_ERROR); b3Assert(glGetError() ==GL_NO_ERROR);
//m_instancingRenderer->InitShaders(); //m_renderer->InitShaders();
m_window->setMouseMoveCallback(Simple2MouseMoveCallback); m_window->setMouseMoveCallback(Simple2MouseMoveCallback);
m_window->setMouseButtonCallback(Simple2MouseButtonCallback); m_window->setMouseButtonCallback(Simple2MouseButtonCallback);
@ -275,7 +277,7 @@ void SimpleOpenGL2App::drawGrid(DrawGridData data)
//we don't use drawPoints because all points would have the same color //we don't use drawPoints because all points would have the same color
// b3Vector3 points[3] = { b3MakeVector3(1, 0, 0), b3MakeVector3(0, 1, 0), b3MakeVector3(0, 0, 1) }; // b3Vector3 points[3] = { b3MakeVector3(1, 0, 0), b3MakeVector3(0, 1, 0), b3MakeVector3(0, 0, 1) };
// m_instancingRenderer->drawPoints(&points[0].x, b3MakeVector3(1, 0, 0), 3, sizeof(b3Vector3), 6); // m_renderer->drawPoints(&points[0].x, b3MakeVector3(1, 0, 0), 3, sizeof(b3Vector3), 6);
} }
void SimpleOpenGL2App::setUpAxis(int axis) void SimpleOpenGL2App::setUpAxis(int axis)
{ {
@ -466,8 +468,106 @@ void SimpleOpenGL2App::drawText3D( const char* txt, float worldPosX, float world
restoreOpenGLState(); restoreOpenGLState();
} }
void SimpleOpenGL2App::registerGrid(int xres, int yres, float color0[4], float color1[4])
void SimpleOpenGL2App::registerGrid(int cells_x, int cells_z, float color0[4], float color1[4])
{ {
b3Vector3 cubeExtents=b3MakeVector3(0.5,0.5,0.5);
cubeExtents[m_data->m_upAxis] = 0;
int cubeId = registerCubeShape(cubeExtents[0],cubeExtents[1],cubeExtents[2]);
b3Quaternion orn(0,0,0,1);
b3Vector3 center=b3MakeVector3(0,0,0,1);
b3Vector3 scaling=b3MakeVector3(1,1,1,1);
for ( int i = 0; i < cells_x; i++)
{
for (int j = 0; j < cells_z; j++)
{
float* color =0;
if ((i + j) % 2 == 0)
{
color = (float*)color0;
} else {
color = (float*)color1;
}
if (this->m_data->m_upAxis==1)
{
center =b3MakeVector3((i + 0.5f) - cells_x * 0.5f, 0.f, (j + 0.5f) - cells_z * 0.5f);
} else
{
center =b3MakeVector3((i + 0.5f) - cells_x * 0.5f, (j + 0.5f) - cells_z * 0.5f,0.f );
}
m_renderer->registerGraphicsInstance(cubeId,center,orn,color,scaling);
}
}
} }
int SimpleOpenGL2App::registerGraphicsUnitSphereShape(EnumSphereLevelOfDetail lod, int textureId)
{
int strideInBytes = 9*sizeof(float);
int graphicsShapeIndex = -1;
switch (lod)
{
case SPHERE_LOD_POINT_SPRITE:
{
int numVertices = sizeof(point_sphere_vertices)/strideInBytes;
int numIndices = sizeof(point_sphere_indices)/sizeof(int);
graphicsShapeIndex = m_renderer->registerShape(&point_sphere_vertices[0],numVertices,point_sphere_indices,numIndices,B3_GL_POINTS,textureId);
break;
}
case SPHERE_LOD_LOW:
{
int numVertices = sizeof(low_sphere_vertices)/strideInBytes;
int numIndices = sizeof(low_sphere_indices)/sizeof(int);
graphicsShapeIndex = m_renderer->registerShape(&low_sphere_vertices[0],numVertices,low_sphere_indices,numIndices,B3_GL_TRIANGLES,textureId);
break;
}
case SPHERE_LOD_MEDIUM:
{
int numVertices = sizeof(medium_sphere_vertices)/strideInBytes;
int numIndices = sizeof(medium_sphere_indices)/sizeof(int);
graphicsShapeIndex = m_renderer->registerShape(&medium_sphere_vertices[0],numVertices,medium_sphere_indices,numIndices,B3_GL_TRIANGLES,textureId);
break;
}
case SPHERE_LOD_HIGH:
default:
{
int numVertices = sizeof(detailed_sphere_vertices)/strideInBytes;
int numIndices = sizeof(detailed_sphere_indices)/sizeof(int);
graphicsShapeIndex = m_renderer->registerShape(&detailed_sphere_vertices[0],numVertices,detailed_sphere_indices,numIndices,B3_GL_TRIANGLES,textureId);
break;
}
};
return graphicsShapeIndex;
}
int SimpleOpenGL2App::registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ, int textureIndex, float textureScaling )
{
int strideInBytes = 9*sizeof(float);
int numVertices = sizeof(cube_vertices_textured)/strideInBytes;
int numIndices = sizeof(cube_indices)/sizeof(int);
b3AlignedObjectArray<GLInstanceVertex> verts;
verts.resize(numVertices);
for (int i=0;i<numVertices;i++)
{
verts[i].xyzw[0] = halfExtentsX*cube_vertices_textured[i*9];
verts[i].xyzw[1] = halfExtentsY*cube_vertices_textured[i*9+1];
verts[i].xyzw[2] = halfExtentsZ*cube_vertices_textured[i*9+2];
verts[i].xyzw[3] = cube_vertices_textured[i*9+3];
verts[i].normal[0] = cube_vertices_textured[i*9+4];
verts[i].normal[1]= cube_vertices_textured[i*9+5];
verts[i].normal[2] = cube_vertices_textured[i*9+6];
verts[i].uv[0] = cube_vertices_textured[i*9+7]*textureScaling;
verts[i].uv[1] = cube_vertices_textured[i*9+8]*textureScaling;
}
int shapeId = m_renderer->registerShape(&verts[0].xyzw[0],numVertices,cube_indices,numIndices,B3_GL_TRIANGLES,textureIndex);
return shapeId;
}

View File

@ -20,14 +20,9 @@ public:
virtual void drawText( const char* txt, int posX, int posY, float size); virtual void drawText( const char* txt, int posX, int posY, float size);
virtual void drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA){}; virtual void drawTexturedRect(float x0, float y0, float x1, float y1, float color[4], float u0,float v0, float u1, float v1, int useRGBA){};
virtual void setBackgroundColor(float red, float green, float blue); virtual void setBackgroundColor(float red, float green, float blue);
virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ, int textureIndex = -1, float textureScaling = 1) virtual int registerCubeShape(float halfExtentsX,float halfExtentsY, float halfExtentsZ, int textureIndex = -1, float textureScaling = 1);
{
return 0; virtual int registerGraphicsUnitSphereShape(EnumSphereLevelOfDetail lod, int textureId=-1);
}
virtual int registerGraphicsUnitSphereShape(EnumSphereLevelOfDetail lod, int textureId=-1)
{
return 0;
}
virtual void drawText3D( const char* txt, float posX, float posZY, float posZ, float size); virtual void drawText3D( const char* txt, float posX, float posZY, float posZ, float size);
virtual void registerGrid(int xres, int yres, float color0[4], float color1[4]); virtual void registerGrid(int xres, int yres, float color0[4], float color1[4]);

View File

@ -2,13 +2,63 @@
#include "SimpleOpenGL2Renderer.h" #include "SimpleOpenGL2Renderer.h"
#include "OpenGL2Include.h" #include "OpenGL2Include.h"
#include "Bullet3Common/b3Vector3.h" #include "Bullet3Common/b3Vector3.h"
#include "Bullet3Common/b3AlignedObjectArray.h"
#include "GLInstanceGraphicsShape.h"
#include "Bullet3Common/b3Quaternion.h"
#include "Bullet3Common/b3Transform.h"
B3_ATTRIBUTE_ALIGNED16(struct) SimpleGL2Shape
{
B3_DECLARE_ALIGNED_ALLOCATOR();
int m_textureIndex;
int m_primitiveType;
b3AlignedObjectArray<int> m_indices;
b3AlignedObjectArray<GLInstanceVertex> m_vertices;
b3Vector3 m_scaling;
};
B3_ATTRIBUTE_ALIGNED16(struct) SimpleGL2Instance
{
B3_DECLARE_ALIGNED_ALLOCATOR();
int m_shapeIndex;
b3Vector3 m_position;
b3Quaternion orn;
b3Vector3 m_rgbColor;
b3Vector3 m_scaling;
};
struct InternalTextureHandle2
{
GLuint m_glTexture;
int m_width;
int m_height;
};
struct SimpleOpenGL2RendererInternalData
{
int m_width;
int m_height;
SimpleCamera m_camera;
b3AlignedObjectArray<SimpleGL2Shape*> m_shapes;
b3AlignedObjectArray<SimpleGL2Instance> m_graphicsInstances;
b3AlignedObjectArray<InternalTextureHandle2> m_textureHandles;
};
SimpleOpenGL2Renderer::SimpleOpenGL2Renderer(int width, int height) SimpleOpenGL2Renderer::SimpleOpenGL2Renderer(int width, int height)
:m_width(width),
m_height(height)
{ {
m_data = new SimpleOpenGL2RendererInternalData;
m_data->m_width = width;
m_data->m_height = height;
}
SimpleOpenGL2Renderer::~SimpleOpenGL2Renderer()
{
delete m_data;
} }
void SimpleOpenGL2Renderer::init() void SimpleOpenGL2Renderer::init()
@ -17,11 +67,11 @@ void SimpleOpenGL2Renderer::init()
const CommonCameraInterface* SimpleOpenGL2Renderer::getActiveCamera() const const CommonCameraInterface* SimpleOpenGL2Renderer::getActiveCamera() const
{ {
return &m_camera; return &m_data->m_camera;
} }
CommonCameraInterface* SimpleOpenGL2Renderer::getActiveCamera() CommonCameraInterface* SimpleOpenGL2Renderer::getActiveCamera()
{ {
return &m_camera; return &m_data->m_camera;
} }
void SimpleOpenGL2Renderer::setActiveCamera(CommonCameraInterface* cam) void SimpleOpenGL2Renderer::setActiveCamera(CommonCameraInterface* cam)
{ {
@ -32,11 +82,11 @@ void SimpleOpenGL2Renderer::updateCamera(int upAxis)
{ {
float projection[16]; float projection[16];
float view[16]; float view[16];
m_camera.setAspectRatio((float)m_width/(float)m_height); getActiveCamera()->setAspectRatio((float)m_data->m_width/(float)m_data->m_height);
m_camera.setCameraUpAxis(upAxis); getActiveCamera()->setCameraUpAxis(upAxis);
m_camera.update(); m_data->m_camera.update(); //??
m_camera.getCameraProjectionMatrix(projection); getActiveCamera()->getCameraProjectionMatrix(projection);
m_camera.getCameraViewMatrix(view); getActiveCamera()->getCameraViewMatrix(view);
GLfloat projMat[16]; GLfloat projMat[16];
GLfloat viewMat[16]; GLfloat viewMat[16];
for (int i=0;i<16;i++) for (int i=0;i<16;i++)
@ -55,6 +105,14 @@ void SimpleOpenGL2Renderer::updateCamera(int upAxis)
void SimpleOpenGL2Renderer::removeAllInstances() void SimpleOpenGL2Renderer::removeAllInstances()
{ {
for (int i=0;i<m_data->m_shapes.size();i++)
{
delete m_data->m_shapes[i];
}
m_data->m_shapes.clear();
m_data->m_graphicsInstances.clear();
//also destroy textures?
m_data->m_textureHandles.clear();
} }
@ -76,7 +134,7 @@ void SimpleOpenGL2Renderer::writeSingleInstanceScaleToCPU(double* scale, int src
int SimpleOpenGL2Renderer::getTotalNumInstances() const int SimpleOpenGL2Renderer::getTotalNumInstances() const
{ {
return 0; return m_data->m_graphicsInstances.size();
} }
void SimpleOpenGL2Renderer::getCameraViewMatrix(float viewMat[16]) const void SimpleOpenGL2Renderer::getCameraViewMatrix(float viewMat[16]) const
@ -90,21 +148,323 @@ void SimpleOpenGL2Renderer::getCameraProjectionMatrix(float projMat[16]) const
} }
void SimpleOpenGL2Renderer::drawOpenGL(int instanceIndex)
{
const SimpleGL2Instance& inst = m_data->m_graphicsInstances[instanceIndex];
const SimpleGL2Shape* shape = m_data->m_shapes[inst.m_shapeIndex];
glPushMatrix();
b3Transform tr;
tr.setOrigin(b3MakeVector3(inst.m_position[0],inst.m_position[1],inst.m_position[2]));
tr.setRotation(b3Quaternion(inst.orn[0],inst.orn[1],inst.orn[2],inst.orn[3]));
b3Scalar m[16];
tr.getOpenGLMatrix(m);
#ifdef B3_USE_DOUBLE_PRECISION
glMultMatrixd(m);
#else
glMultMatrixf(m);
#endif
#if 0
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(0.025f,0.025f,0.025f);
glMatrixMode(GL_MODELVIEW);
static const GLfloat planex[]={1,0,0,0};
// static const GLfloat planey[]={0,1,0,0};
static const GLfloat planez[]={0,0,1,0};
glTexGenfv(GL_S,GL_OBJECT_PLANE,planex);
glTexGenfv(GL_T,GL_OBJECT_PLANE,planez);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
m_textureinitialized=true;
#endif
//drawCoordSystem();
//glPushMatrix();
// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
// glMatrixMode(GL_TEXTURE);
// glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_COLOR_MATERIAL);
if(shape->m_textureIndex>=0)
{
glEnable(GL_TEXTURE_2D);
activateTexture(shape->m_textureIndex);
} else
{
glDisable(GL_TEXTURE_2D);
}
glColor3f(inst.m_rgbColor[0],inst.m_rgbColor[1], inst.m_rgbColor[2]);
glScalef(inst.m_scaling[0],inst.m_scaling[1],inst.m_scaling[2]);
glShadeModel(GL_SMOOTH);
glBegin (GL_TRIANGLES);
for (int i=0;i<shape->m_indices.size();i+=3)
{
for (int v=0;v<3;v++)
{
const GLInstanceVertex& vtx0 = shape->m_vertices[shape->m_indices[i+v]];
glNormal3f(vtx0.normal[0],vtx0.normal[1],vtx0.normal[2]);
glTexCoord2f(vtx0.uv[0],vtx0.uv[1]);
glVertex3f (vtx0.xyzw[0],vtx0.xyzw[1],vtx0.xyzw[2]);
}
}
glEnd();
glPopMatrix();
}
void SimpleOpenGL2Renderer::drawSceneInternal(int pass, int cameraUpAxis)
{
for (int i=0;i<m_data->m_graphicsInstances.size();i++)
{
drawOpenGL(i);
}
#if 0
b3Scalar m[16];
b3Matrix3x3 rot;rot.setIdentity();
const int numObjects=dynamicsWorld->getNumCollisionObjects();
btVector3 wireColor(1,0,0);
//glDisable(GL_CULL_FACE);
for(int i=0;i<numObjects;i++)
{
const btCollisionObject* colObj=dynamicsWorld->getCollisionObjectArray()[i];
const btRigidBody* body=btRigidBody::upcast(colObj);
if(body&&body->getMotionState())
{
btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);
rot=myMotionState->m_graphicsWorldTrans.getBasis();
}
else
{
colObj->getWorldTransform().getOpenGLMatrix(m);
rot=colObj->getWorldTransform().getBasis();
}
btVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation
if(i&1) wireColor=btVector3(0.f,0.0f,1.f);
///color differently for active, sleeping, wantsdeactivation states
if (colObj->getActivationState() == 1) //active
{
if (i & 1)
{
wireColor += btVector3 (1.f,0.f,0.f);
}
else
{
wireColor += btVector3 (.5f,0.f,0.f);
}
}
if(colObj->getActivationState()==2) //ISLAND_SLEEPING
{
if(i&1)
{
wireColor += btVector3 (0.f,1.f, 0.f);
}
else
{
wireColor += btVector3 (0.f,0.5f,0.f);
}
}
btVector3 aabbMin(0,0,0),aabbMax(0,0,0);
//m_dynamicsWorld->getBroadphase()->getBroadphaseAabb(aabbMin,aabbMax);
aabbMin-=btVector3(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
aabbMax+=btVector3(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
// printf("aabbMin=(%f,%f,%f)\n",aabbMin.getX(),aabbMin.getY(),aabbMin.getZ());
// printf("aabbMax=(%f,%f,%f)\n",aabbMax.getX(),aabbMax.getY(),aabbMax.getZ());
// m_dynamicsWorld->getDebugDrawer()->drawAabb(aabbMin,aabbMax,btVector3(1,1,1));
//switch(pass)
//if (!(getDebugMode()& btIDebugDraw::DBG_DrawWireframe))
int debugMode = 0;//getDebugMode()
//btVector3 m_sundirection(-1,-1,-1);
btVector3 m_sundirection(btVector3(1,-2,1)*1000);
if (cameraUpAxis==2)
{
m_sundirection = btVector3(1,1,-2)*1000;
}
switch(pass)
{
case 0: drawOpenGL(m,colObj->getCollisionShape(),wireColor,debugMode,aabbMin,aabbMax);break;
case 1: drawShadow(m,m_sundirection*rot,colObj->getCollisionShape(),aabbMin,aabbMax);break;
case 2: drawOpenGL(m,colObj->getCollisionShape(),wireColor*b3Scalar(0.3),0,aabbMin,aabbMax);break;
}
}
#endif
}
void SimpleOpenGL2Renderer::renderScene() void SimpleOpenGL2Renderer::renderScene()
{ {
GLfloat light_ambient[] = { b3Scalar(0.2), b3Scalar(0.2), b3Scalar(0.2), b3Scalar(1.0) };
GLfloat light_diffuse[] = { b3Scalar(1.0), b3Scalar(1.0), b3Scalar(1.0), b3Scalar(1.0) };
GLfloat light_specular[] = { b3Scalar(1.0), b3Scalar(1.0), b3Scalar(1.0), b3Scalar(1.0 )};
/* light_position is NOT default value */
GLfloat light_position0[] = { b3Scalar(1.0), b3Scalar(10.0), b3Scalar(1.0), b3Scalar(0.0 )};
GLfloat light_position1[] = { b3Scalar(-1.0), b3Scalar(-10.0), b3Scalar(-1.0), b3Scalar(0.0) };
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
drawSceneInternal(0,0);
} }
int SimpleOpenGL2Renderer::registerTexture(const unsigned char* texels, int width, int height)
{
b3Assert(glGetError() ==GL_NO_ERROR);
glActiveTexture(GL_TEXTURE0);
int textureIndex = m_data->m_textureHandles.size();
// const GLubyte* image= (const GLubyte*)texels;
GLuint textureHandle;
glGenTextures(1,(GLuint*)&textureHandle);
glBindTexture(GL_TEXTURE_2D,textureHandle);
b3Assert(glGetError() ==GL_NO_ERROR);
InternalTextureHandle2 h;
h.m_glTexture = textureHandle;
h.m_width = width;
h.m_height = height;
m_data->m_textureHandles.push_back(h);
updateTexture(textureIndex, texels);
return textureIndex;
}
void SimpleOpenGL2Renderer::updateTexture(int textureIndex, const unsigned char* texels)
{
if (textureIndex>=0)
{
glActiveTexture(GL_TEXTURE0);
b3Assert(glGetError() ==GL_NO_ERROR);
InternalTextureHandle2& h = m_data->m_textureHandles[textureIndex];
//textures need to be flipped for OpenGL...
b3AlignedObjectArray<unsigned char> flippedTexels;
flippedTexels.resize(h.m_width* h.m_height * 3);
for (int i = 0; i < h.m_width; i++)
{
for (int j = 0; j < h.m_height; j++)
{
flippedTexels[(i + j*h.m_width) * 3] = texels[(i + (h.m_height - 1 -j )*h.m_width) * 3];
flippedTexels[(i + j*h.m_width) * 3+1] = texels[(i + (h.m_height - 1 - j)*h.m_width) * 3+1];
flippedTexels[(i + j*h.m_width) * 3+2] = texels[(i + (h.m_height - 1 - j)*h.m_width) * 3+2];
}
}
glBindTexture(GL_TEXTURE_2D,h.m_glTexture);
b3Assert(glGetError() ==GL_NO_ERROR);
// const GLubyte* image= (const GLubyte*)texels;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, h.m_width,h.m_height,0,GL_RGB,GL_UNSIGNED_BYTE,&flippedTexels[0]);
b3Assert(glGetError() ==GL_NO_ERROR);
glGenerateMipmap(GL_TEXTURE_2D);
b3Assert(glGetError() ==GL_NO_ERROR);
}
}
void SimpleOpenGL2Renderer::activateTexture(int textureIndex)
{
glActiveTexture(GL_TEXTURE0);
if (textureIndex>=0)
{
glBindTexture(GL_TEXTURE_2D,m_data->m_textureHandles[textureIndex].m_glTexture);
} else
{
glBindTexture(GL_TEXTURE_2D,0);
}
}
int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling) int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling)
{ {
return 0; int sz = m_data->m_graphicsInstances.size();
SimpleGL2Instance& instance = m_data->m_graphicsInstances.expand();
instance.m_shapeIndex = shapeIndex;
instance.m_position[0] = position[0];
instance.m_position[1] = position[1];
instance.m_position[2] = position[2];
instance.orn[0] = quaternion[0];
instance.orn[1] = quaternion[1];
instance.orn[2] = quaternion[2];
instance.orn[3] = quaternion[3];
instance.m_rgbColor[0] = color[0];
instance.m_rgbColor[1] = color[1];
instance.m_rgbColor[2] = color[2];
instance.m_scaling[0] = scaling[0];
instance.m_scaling[1] = scaling[1];
instance.m_scaling[2] = scaling[2];
return sz;
} }
int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling) int SimpleOpenGL2Renderer::registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
{ {
return 0; int sz = m_data->m_graphicsInstances.size();
SimpleGL2Instance& instance = m_data->m_graphicsInstances.expand();
instance.m_shapeIndex = shapeIndex;
instance.m_position[0] = position[0];
instance.m_position[1] = position[1];
instance.m_position[2] = position[2];
instance.orn[0] = quaternion[0];
instance.orn[1] = quaternion[1];
instance.orn[2] = quaternion[2];
instance.orn[3] = quaternion[3];
instance.m_rgbColor[0] = color[0];
instance.m_rgbColor[1] = color[1];
instance.m_rgbColor[2] = color[2];
instance.m_scaling[0] = scaling[0];
instance.m_scaling[1] = scaling[1];
instance.m_scaling[2] = scaling[2];
return sz;
} }
void SimpleOpenGL2Renderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize) void SimpleOpenGL2Renderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float pointDrawSize)
@ -141,25 +501,91 @@ void SimpleOpenGL2Renderer::drawLine(const float from[4], const float to[4], con
glVertex3d(to[0],to[1],to[2]); glVertex3d(to[0],to[1],to[2]);
glEnd(); glEnd();
} }
int SimpleOpenGL2Renderer::registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureIndex) int SimpleOpenGL2Renderer::registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureIndex)
{ {
return 0;
SimpleGL2Shape* shape = new SimpleGL2Shape();
shape->m_textureIndex = textureIndex;
shape->m_indices.resize(numIndices);
for (int i=0;i<numIndices;i++)
{
shape->m_indices[i]=indices[i];
}
shape->m_vertices.resize(numvertices);
for (int v=0;v<numvertices;v++)
{
GLInstanceVertex& vtx = shape->m_vertices[v];
vtx.xyzw[0] = vertices[9*v+0];
vtx.xyzw[1] = vertices[9*v+1];
vtx.xyzw[2] = vertices[9*v+2];
vtx.xyzw[3] = vertices[9*v+3];
vtx.normal[0] = vertices[9*v+4];
vtx.normal[1] = vertices[9*v+5];
vtx.normal[2] = vertices[9*v+6];
vtx.uv[0] = vertices[9*v+7];
vtx.uv[1] = vertices[9*v+8];
}
int sz = m_data->m_shapes.size();
m_data->m_shapes.push_back(shape);
return sz;
} }
void SimpleOpenGL2Renderer::writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex) void SimpleOpenGL2Renderer::writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)
{ {
m_data->m_graphicsInstances[srcIndex].m_position[0] = position[0];
m_data->m_graphicsInstances[srcIndex].m_position[1] = position[1];
m_data->m_graphicsInstances[srcIndex].m_position[2] = position[2];
m_data->m_graphicsInstances[srcIndex].orn[0] = orientation[0];
m_data->m_graphicsInstances[srcIndex].orn[1] = orientation[1];
m_data->m_graphicsInstances[srcIndex].orn[2] = orientation[2];
m_data->m_graphicsInstances[srcIndex].orn[3] = orientation[3];
} }
void SimpleOpenGL2Renderer::writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex) void SimpleOpenGL2Renderer::writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)
{ {
m_data->m_graphicsInstances[srcIndex].m_position[0] = position[0];
m_data->m_graphicsInstances[srcIndex].m_position[1] = position[1];
m_data->m_graphicsInstances[srcIndex].m_position[2] = position[2];
m_data->m_graphicsInstances[srcIndex].orn[0] = orientation[0];
m_data->m_graphicsInstances[srcIndex].orn[1] = orientation[1];
m_data->m_graphicsInstances[srcIndex].orn[2] = orientation[2];
m_data->m_graphicsInstances[srcIndex].orn[3] = orientation[3];
} }
void SimpleOpenGL2Renderer::writeTransforms() void SimpleOpenGL2Renderer::writeTransforms()
{ {
} }
void SimpleOpenGL2Renderer::resize(int width, int height)
{
m_data->m_width = width;
m_data->m_height = height;
}
int SimpleOpenGL2Renderer::getScreenWidth()
{
return m_data->m_width;
}
int SimpleOpenGL2Renderer::getScreenHeight()
{
return m_data->m_height;
}
void SimpleOpenGL2Renderer::drawLine(const double from[4], const double to[4], const double color[4], double lineWidth) void SimpleOpenGL2Renderer::drawLine(const double from[4], const double to[4], const double color[4], double lineWidth)
{ {
glLineWidth(lineWidth);
glBegin(GL_LINES);
glColor3f(color[0],color[1],color[2]);
glVertex3d(from[0],from[1],from[2]);
glVertex3d(to[0],to[1],to[2]);
glEnd();
} }
void SimpleOpenGL2Renderer::drawPoint(const float* position, const float color[4], float pointDrawSize) void SimpleOpenGL2Renderer::drawPoint(const float* position, const float color[4], float pointDrawSize)
{ {
@ -170,6 +596,23 @@ void SimpleOpenGL2Renderer::drawPoint(const double* position, const double color
void SimpleOpenGL2Renderer::updateShape(int shapeIndex, const float* vertices) void SimpleOpenGL2Renderer::updateShape(int shapeIndex, const float* vertices)
{ {
SimpleGL2Shape* shape = m_data->m_shapes[shapeIndex];
int numvertices = shape->m_vertices.size();
for (int i=0;i<numvertices;i++)
{
shape->m_vertices[i].xyzw[0] = vertices[9*i+0];
shape->m_vertices[i].xyzw[1] = vertices[9*i+1];
shape->m_vertices[i].xyzw[2] = vertices[9*i+2];
shape->m_vertices[i].xyzw[3] = vertices[9*i+3];
shape->m_vertices[i].normal[0] = vertices[9*i+4];
shape->m_vertices[i].normal[1] = vertices[9*i+5];
shape->m_vertices[i].normal[2] = vertices[9*i+6];
shape->m_vertices[i].uv[0] = vertices[9*i+7];
shape->m_vertices[i].uv[1] = vertices[9*i+8];
}
} }
void SimpleOpenGL2Renderer::enableBlend(bool blend) void SimpleOpenGL2Renderer::enableBlend(bool blend)

View File

@ -5,13 +5,17 @@
#include "../CommonInterfaces/CommonRenderInterface.h" #include "../CommonInterfaces/CommonRenderInterface.h"
#include "SimpleCamera.h" #include "SimpleCamera.h"
struct SimpleOpenGL2Renderer : public CommonRenderInterface class SimpleOpenGL2Renderer : public CommonRenderInterface
{ {
int m_width; struct SimpleOpenGL2RendererInternalData* m_data;
int m_height;
SimpleCamera m_camera; void drawSceneInternal(int pass, int cameraUpAxis);
void drawOpenGL(int instanceIndex);
public:
SimpleOpenGL2Renderer(int width, int height); SimpleOpenGL2Renderer(int width, int height);
virtual ~SimpleOpenGL2Renderer();
virtual void init(); virtual void init();
@ -21,11 +25,7 @@ struct SimpleOpenGL2Renderer : public CommonRenderInterface
virtual CommonCameraInterface* getActiveCamera(); virtual CommonCameraInterface* getActiveCamera();
virtual void setActiveCamera(CommonCameraInterface* cam); virtual void setActiveCamera(CommonCameraInterface* cam);
virtual void resize(int width, int height) virtual void resize(int width, int height);
{
m_width = width;
m_height = height;
}
virtual void removeAllInstances(); virtual void removeAllInstances();
@ -40,20 +40,11 @@ struct SimpleOpenGL2Renderer : public CommonRenderInterface
virtual void renderScene(); virtual void renderScene();
virtual int getScreenWidth() virtual int getScreenWidth();
{ virtual int getScreenHeight();
return m_width; virtual int registerTexture(const unsigned char* texels, int width, int height);
} virtual void updateTexture(int textureIndex, const unsigned char* texels);
virtual int getScreenHeight() virtual void activateTexture(int textureIndex);
{
return m_height;
}
virtual int registerTexture(const unsigned char* texels, int width, int height)
{
return -1;
}
virtual void updateTexture(int textureIndex, const unsigned char* texels) {}
virtual void activateTexture(int textureIndex) {}
virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling); virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling);

View File

@ -260,6 +260,8 @@ int b3RobotSimulatorClientAPI::loadURDF(const std::string& fileName, const struc
//setting the initial position, orientation and other arguments are optional //setting the initial position, orientation and other arguments are optional
b3LoadUrdfCommandSetFlags(command,args.m_flags);
b3LoadUrdfCommandSetStartPosition(command, args.m_startPosition[0], b3LoadUrdfCommandSetStartPosition(command, args.m_startPosition[0],
args.m_startPosition[1], args.m_startPosition[1],
args.m_startPosition[2]); args.m_startPosition[2]);

View File

@ -15,12 +15,14 @@ struct b3RobotSimulatorLoadUrdfFileArgs
b3Quaternion m_startOrientation; b3Quaternion m_startOrientation;
bool m_forceOverrideFixedBase; bool m_forceOverrideFixedBase;
bool m_useMultiBody; bool m_useMultiBody;
int m_flags;
b3RobotSimulatorLoadUrdfFileArgs() b3RobotSimulatorLoadUrdfFileArgs()
: m_startPosition(b3MakeVector3(0, 0, 0)), : m_startPosition(b3MakeVector3(0, 0, 0)),
m_startOrientation(b3Quaternion(0, 0, 0, 1)), m_startOrientation(b3Quaternion(0, 0, 0, 1)),
m_forceOverrideFixedBase(false), m_forceOverrideFixedBase(false),
m_useMultiBody(true) m_useMultiBody(true),
m_flags(0)
{ {
} }
}; };

View File

@ -238,6 +238,19 @@ int b3LoadUrdfCommandSetUseFixedBase(b3SharedMemoryCommandHandle commandHandle,
return -1; return -1;
} }
int b3LoadUrdfCommandSetFlags(b3SharedMemoryCommandHandle commandHandle, int flags)
{
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*) commandHandle;
b3Assert(command);
b3Assert(command->m_type == CMD_LOAD_URDF);
if (command && (command->m_type == CMD_LOAD_URDF))
{
command->m_updateFlags |= URDF_ARGS_HAS_CUSTOM_URDF_FLAGS;
command->m_urdfArguments.m_urdfFlags = flags;
}
return 0;
}
int b3LoadUrdfCommandSetStartPosition(b3SharedMemoryCommandHandle commandHandle, double startPosX,double startPosY,double startPosZ) int b3LoadUrdfCommandSetStartPosition(b3SharedMemoryCommandHandle commandHandle, double startPosX,double startPosY,double startPosZ)
{ {
struct SharedMemoryCommand* command = (struct SharedMemoryCommand*) commandHandle; struct SharedMemoryCommand* command = (struct SharedMemoryCommand*) commandHandle;

View File

@ -217,6 +217,7 @@ int b3LoadUrdfCommandSetStartPosition(b3SharedMemoryCommandHandle commandHandle,
int b3LoadUrdfCommandSetStartOrientation(b3SharedMemoryCommandHandle commandHandle, double startOrnX,double startOrnY,double startOrnZ, double startOrnW); int b3LoadUrdfCommandSetStartOrientation(b3SharedMemoryCommandHandle commandHandle, double startOrnX,double startOrnY,double startOrnZ, double startOrnW);
int b3LoadUrdfCommandSetUseMultiBody(b3SharedMemoryCommandHandle commandHandle, int useMultiBody); int b3LoadUrdfCommandSetUseMultiBody(b3SharedMemoryCommandHandle commandHandle, int useMultiBody);
int b3LoadUrdfCommandSetUseFixedBase(b3SharedMemoryCommandHandle commandHandle, int useFixedBase); int b3LoadUrdfCommandSetUseFixedBase(b3SharedMemoryCommandHandle commandHandle, int useFixedBase);
int b3LoadUrdfCommandSetFlags(b3SharedMemoryCommandHandle commandHandle, int flags);
b3SharedMemoryCommandHandle b3LoadBulletCommandInit(b3PhysicsClientHandle physClient, const char* fileName); b3SharedMemoryCommandHandle b3LoadBulletCommandInit(b3PhysicsClientHandle physClient, const char* fileName);
b3SharedMemoryCommandHandle b3SaveBulletCommandInit(b3PhysicsClientHandle physClient, const char* fileName); b3SharedMemoryCommandHandle b3SaveBulletCommandInit(b3PhysicsClientHandle physClient, const char* fileName);

View File

@ -1539,7 +1539,7 @@ bool PhysicsServerCommandProcessor::loadSdf(const char* fileName, char* bufferSe
bool PhysicsServerCommandProcessor::loadUrdf(const char* fileName, const btVector3& pos, const btQuaternion& orn, bool PhysicsServerCommandProcessor::loadUrdf(const char* fileName, const btVector3& pos, const btQuaternion& orn,
bool useMultiBody, bool useFixedBase, int* bodyUniqueIdPtr, char* bufferServerToClient, int bufferSizeInBytes) bool useMultiBody, bool useFixedBase, int* bodyUniqueIdPtr, char* bufferServerToClient, int bufferSizeInBytes, int flags)
{ {
BT_PROFILE("loadURDF"); BT_PROFILE("loadURDF");
btAssert(m_data->m_dynamicsWorld); btAssert(m_data->m_dynamicsWorld);
@ -1597,7 +1597,7 @@ bool PhysicsServerCommandProcessor::loadUrdf(const char* fileName, const btVecto
// printf("urdf root link index = %d\n",rootLinkIndex); // printf("urdf root link index = %d\n",rootLinkIndex);
MyMultiBodyCreator creation(m_data->m_guiHelper); MyMultiBodyCreator creation(m_data->m_guiHelper);
ConvertURDF2Bullet(u2b,creation, tr,m_data->m_dynamicsWorld,useMultiBody,u2b.getPathPrefix()); ConvertURDF2Bullet(u2b,creation, tr,m_data->m_dynamicsWorld,useMultiBody,u2b.getPathPrefix(),flags);
for (int i=0;i<u2b.getNumAllocatedCollisionShapes();i++) for (int i=0;i<u2b.getNumAllocatedCollisionShapes();i++)
{ {
@ -2617,6 +2617,11 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
initialPos[1] = urdfArgs.m_initialPosition[1]; initialPos[1] = urdfArgs.m_initialPosition[1];
initialPos[2] = urdfArgs.m_initialPosition[2]; initialPos[2] = urdfArgs.m_initialPosition[2];
} }
int urdfFlags = 0;
if (clientCmd.m_updateFlags & URDF_ARGS_HAS_CUSTOM_URDF_FLAGS)
{
urdfFlags = urdfArgs.m_urdfFlags;
}
if (clientCmd.m_updateFlags & URDF_ARGS_INITIAL_ORIENTATION) if (clientCmd.m_updateFlags & URDF_ARGS_INITIAL_ORIENTATION)
{ {
initialOrn[0] = urdfArgs.m_initialOrientation[0]; initialOrn[0] = urdfArgs.m_initialOrientation[0];
@ -2630,8 +2635,7 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
//load the actual URDF and send a report: completed or failed //load the actual URDF and send a report: completed or failed
bool completedOk = loadUrdf(urdfArgs.m_urdfFileName, bool completedOk = loadUrdf(urdfArgs.m_urdfFileName,
initialPos,initialOrn, initialPos,initialOrn,
useMultiBody, useFixedBase,&bodyUniqueId, bufferServerToClient, bufferSizeInBytes); useMultiBody, useFixedBase,&bodyUniqueId, bufferServerToClient, bufferSizeInBytes, urdfFlags);
if (completedOk) if (completedOk)
{ {
@ -5399,7 +5403,7 @@ void PhysicsServerCommandProcessor::createDefaultRobotAssets()
btVector3 spawnDir = mat.getColumn(0); btVector3 spawnDir = mat.getColumn(0);
btVector3 shiftPos = spawnDir*spawnDistance; btVector3 shiftPos = spawnDir*spawnDistance;
btVector3 spawnPos = gVRGripperPos + shiftPos; btVector3 spawnPos = gVRGripperPos + shiftPos;
loadUrdf("sphere_small.urdf", spawnPos, gVRGripperOrn, true, false, &bodyId, &gBufferServerToClient[0], gBufferServerToClient.size()); loadUrdf("sphere_small.urdf", spawnPos, gVRGripperOrn, true, false, &bodyId, &gBufferServerToClient[0], gBufferServerToClient.size(),0);
//loadUrdf("lego/lego.urdf", spawnPos, gVRGripperOrn, true, false, &bodyId, &gBufferServerToClient[0], gBufferServerToClient.size()); //loadUrdf("lego/lego.urdf", spawnPos, gVRGripperOrn, true, false, &bodyId, &gBufferServerToClient[0], gBufferServerToClient.size());
m_data->m_sphereId = bodyId; m_data->m_sphereId = bodyId;
InteralBodyData* parentBody = m_data->getHandle(bodyId); InteralBodyData* parentBody = m_data->getHandle(bodyId);

View File

@ -35,7 +35,7 @@ protected:
bool loadSdf(const char* fileName, char* bufferServerToClient, int bufferSizeInBytes, bool useMultiBody, int flags); bool loadSdf(const char* fileName, char* bufferServerToClient, int bufferSizeInBytes, bool useMultiBody, int flags);
bool loadUrdf(const char* fileName, const class btVector3& pos, const class btQuaternion& orn, bool loadUrdf(const char* fileName, const class btVector3& pos, const class btQuaternion& orn,
bool useMultiBody, bool useFixedBase, int* bodyUniqueIdPtr, char* bufferServerToClient, int bufferSizeInBytes); bool useMultiBody, bool useFixedBase, int* bodyUniqueIdPtr, char* bufferServerToClient, int bufferSizeInBytes, int flags=0);
bool loadMjcf(const char* fileName, char* bufferServerToClient, int bufferSizeInBytes, bool useMultiBody, int flags); bool loadMjcf(const char* fileName, char* bufferServerToClient, int bufferSizeInBytes, bool useMultiBody, int flags);

View File

@ -79,6 +79,7 @@ enum EnumUrdfArgsUpdateFlags
URDF_ARGS_INITIAL_ORIENTATION=4, URDF_ARGS_INITIAL_ORIENTATION=4,
URDF_ARGS_USE_MULTIBODY=8, URDF_ARGS_USE_MULTIBODY=8,
URDF_ARGS_USE_FIXED_BASE=16, URDF_ARGS_USE_FIXED_BASE=16,
URDF_ARGS_HAS_CUSTOM_URDF_FLAGS = 32
}; };
@ -89,6 +90,7 @@ struct UrdfArgs
double m_initialOrientation[4]; double m_initialOrientation[4];
int m_useMultiBody; int m_useMultiBody;
int m_useFixedBase; int m_useFixedBase;
int m_urdfFlags;
}; };
struct MjcfArgs struct MjcfArgs

View File

@ -447,4 +447,9 @@ enum eCONNECT_METHOD {
eCONNECT_TCP = 5, eCONNECT_TCP = 5,
}; };
enum eURDF_Flags
{
URDF_USE_INERTIA_FROM_FILE=2,//sync with URDF2Bullet.h 'ConvertURDFFlags'
};
#endif//SHARED_MEMORY_PUBLIC_H #endif//SHARED_MEMORY_PUBLIC_H

View File

@ -693,8 +693,9 @@ static PyObject* pybullet_setPhysicsEngineParameter(PyObject* self, PyObject* ar
static PyObject* pybullet_loadURDF(PyObject* self, PyObject* args, PyObject* keywds) static PyObject* pybullet_loadURDF(PyObject* self, PyObject* args, PyObject* keywds)
{ {
int physicsClientId = 0; int physicsClientId = 0;
int flags = 0;
static char* kwlist[] = {"fileName", "basePosition", "baseOrientation", "useMaximalCoordinates", "useFixedBase", "physicsClientId", NULL}; static char* kwlist[] = {"fileName", "basePosition", "baseOrientation", "useMaximalCoordinates", "useFixedBase", "flags","physicsClientId", NULL};
static char* kwlistBackwardCompatible4[] = {"fileName", "startPosX", "startPosY", "startPosZ", NULL}; static char* kwlistBackwardCompatible4[] = {"fileName", "startPosX", "startPosY", "startPosZ", NULL};
static char* kwlistBackwardCompatible8[] = {"fileName", "startPosX", "startPosY", "startPosZ", "startOrnX", "startOrnY", "startOrnZ", "startOrnW", NULL}; static char* kwlistBackwardCompatible8[] = {"fileName", "startPosX", "startPosY", "startPosZ", "startOrnX", "startOrnY", "startOrnZ", "startOrnW", NULL};
@ -741,7 +742,7 @@ static PyObject* pybullet_loadURDF(PyObject* self, PyObject* args, PyObject* key
double basePos[3]; double basePos[3];
double baseOrn[4]; double baseOrn[4];
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|OOiii", kwlist, &urdfFileName, &basePosObj, &baseOrnObj, &useMaximalCoordinates, &useFixedBase, &physicsClientId)) if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|OOiiii", kwlist, &urdfFileName, &basePosObj, &baseOrnObj, &useMaximalCoordinates, &useFixedBase, &flags, &physicsClientId))
{ {
return NULL; return NULL;
} }
@ -790,6 +791,8 @@ static PyObject* pybullet_loadURDF(PyObject* self, PyObject* args, PyObject* key
b3SharedMemoryCommandHandle command = b3SharedMemoryCommandHandle command =
b3LoadUrdfCommandInit(sm, urdfFileName); b3LoadUrdfCommandInit(sm, urdfFileName);
b3LoadUrdfCommandSetFlags(command,flags);
// setting the initial position, orientation and other arguments are // setting the initial position, orientation and other arguments are
// optional // optional
b3LoadUrdfCommandSetStartPosition(command, startPosX, startPosY, startPosZ); b3LoadUrdfCommandSetStartPosition(command, startPosX, startPosY, startPosZ);
@ -3916,15 +3919,13 @@ static PyObject* pybullet_getCameraImage(PyObject* self, PyObject* args, PyObjec
b3RequestCameraImageSetLightDiffuseCoeff(command, lightDiffuseCoeff); b3RequestCameraImageSetLightDiffuseCoeff(command, lightDiffuseCoeff);
b3RequestCameraImageSetLightSpecularCoeff(command, lightSpecularCoeff); b3RequestCameraImageSetLightSpecularCoeff(command, lightSpecularCoeff);
b3RequestCameraImageSelectRenderer(command, renderer); b3RequestCameraImageSelectRenderer(command, renderer);//renderer could be ER_BULLET_HARDWARE_OPENGL
if (b3CanSubmitCommand(sm)) if (b3CanSubmitCommand(sm))
{ {
b3SharedMemoryStatusHandle statusHandle; b3SharedMemoryStatusHandle statusHandle;
int statusType; int statusType;
// b3RequestCameraImageSelectRenderer(command,ER_BULLET_HARDWARE_OPENGL);
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
statusType = b3GetStatusType(statusHandle); statusType = b3GetStatusType(statusHandle);
if (statusType == CMD_CAMERA_IMAGE_COMPLETED) if (statusType == CMD_CAMERA_IMAGE_COMPLETED)
@ -4349,7 +4350,6 @@ static PyObject* pybullet_renderImageObsolete(PyObject* self, PyObject* args)
b3SharedMemoryStatusHandle statusHandle; b3SharedMemoryStatusHandle statusHandle;
int statusType; int statusType;
// b3RequestCameraImageSelectRenderer(command,ER_BULLET_HARDWARE_OPENGL);
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
statusType = b3GetStatusType(statusHandle); statusType = b3GetStatusType(statusHandle);
@ -5422,6 +5422,8 @@ initpybullet(void)
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);
PyModule_AddIntConstant(m, "URDF_USE_INERTIA_FROM_FILE", URDF_USE_INERTIA_FROM_FILE);
PyModule_AddIntConstant(m, "B3G_F1", B3G_F1); PyModule_AddIntConstant(m, "B3G_F1", B3G_F1);
PyModule_AddIntConstant(m, "B3G_F2", B3G_F2); PyModule_AddIntConstant(m, "B3G_F2", B3G_F2);
PyModule_AddIntConstant(m, "B3G_F3", B3G_F3); PyModule_AddIntConstant(m, "B3G_F3", B3G_F3);