Merge pull request #1637 from erwincoumans/master
PyBullet: add signed distance field support, with example/signedDista…
This commit is contained in:
@@ -410,6 +410,14 @@ void OpenGLExampleBrowserVisualizerFlagCallback(int flag, bool enable)
|
||||
if (flag == COV_ENABLE_WIREFRAME)
|
||||
{
|
||||
visualWireframe = enable;
|
||||
if (visualWireframe)
|
||||
{
|
||||
gDebugDrawFlags |= btIDebugDraw::DBG_DrawWireframe;
|
||||
}
|
||||
else
|
||||
{
|
||||
gDebugDrawFlags &= ~btIDebugDraw::DBG_DrawWireframe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -433,10 +433,14 @@ void OpenGLGuiHelper::createCollisionShapeGraphicsObject(btCollisionShape* colli
|
||||
if (collisionShape->getShapeType() == SOFTBODY_SHAPE_PROXYTYPE)
|
||||
{
|
||||
computeSoftBodyVertices(collisionShape, gfxVertices, indices);
|
||||
int shapeId = registerGraphicsShape(&gfxVertices[0].xyzw[0], gfxVertices.size(), &indices[0], indices.size(), B3_GL_TRIANGLES,
|
||||
m_data->m_checkedTexture);
|
||||
b3Assert(shapeId >= 0);
|
||||
collisionShape->setUserIndex(shapeId);
|
||||
if (gfxVertices.size() && indices.size())
|
||||
{
|
||||
int shapeId = registerGraphicsShape(&gfxVertices[0].xyzw[0], gfxVertices.size(), &indices[0], indices.size(), B3_GL_TRIANGLES,
|
||||
m_data->m_checkedTexture);
|
||||
|
||||
b3Assert(shapeId >= 0);
|
||||
collisionShape->setUserIndex(shapeId);
|
||||
}
|
||||
}
|
||||
if (collisionShape->getShapeType()==MULTI_SPHERE_SHAPE_PROXYTYPE)
|
||||
{
|
||||
@@ -1265,6 +1269,11 @@ void OpenGLGuiHelper::autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWor
|
||||
btCollisionObject* colObj = sortedObjects[i];
|
||||
//btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
//does this also work for btMultiBody/btMultiBodyLinkCollider?
|
||||
btSoftBody* sb = btSoftBody::upcast(colObj);
|
||||
if (sb)
|
||||
{
|
||||
colObj->getCollisionShape()->setUserPointer(sb);
|
||||
}
|
||||
createCollisionShapeGraphicsObject(colObj->getCollisionShape());
|
||||
int colorIndex = colObj->getBroadphaseHandle()->getUid() & 3;
|
||||
|
||||
@@ -1313,6 +1322,8 @@ void OpenGLGuiHelper::computeSoftBodyVertices(btCollisionShape* collisionShape,
|
||||
btAlignedObjectArray<GLInstanceVertex>& gfxVertices,
|
||||
btAlignedObjectArray<int>& indices)
|
||||
{
|
||||
if (collisionShape->getUserPointer()==0)
|
||||
return;
|
||||
b3Assert(collisionShape->getUserPointer());
|
||||
btSoftBody* psb = (btSoftBody*)collisionShape->getUserPointer();
|
||||
gfxVertices.resize(psb->m_faces.size() * 3);
|
||||
|
||||
@@ -21,6 +21,7 @@ subject to the following restrictions:
|
||||
#include "../ImportSTLDemo/LoadMeshFromSTL.h"
|
||||
#include "../ImportColladaDemo/LoadMeshFromCollada.h"
|
||||
#include "BulletCollision/CollisionShapes/btShapeHull.h"//to create a tesselation of a generic btConvexShape
|
||||
#include "BulletCollision/CollisionShapes/btSdfCollisionShape.h"
|
||||
#include "../../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||
#include "Bullet3Common/b3FileUtils.h"
|
||||
#include <string>
|
||||
@@ -509,6 +510,10 @@ bool findExistingMeshFile(
|
||||
{
|
||||
*out_type = UrdfGeometry::FILE_OBJ;
|
||||
}
|
||||
else if (ext == ".cdf")
|
||||
{
|
||||
*out_type = UrdfGeometry::FILE_CDF;
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Warning("%s: invalid mesh filename extension '%s'\n", error_message_prefix.c_str(), ext.c_str());
|
||||
@@ -662,7 +667,53 @@ btCollisionShape* BulletURDFImporter::convertURDFToCollisionShape(const UrdfColl
|
||||
shape ->setMargin(gUrdfDefaultCollisionMargin);
|
||||
break;
|
||||
}
|
||||
case URDF_GEOM_CDF:
|
||||
{
|
||||
|
||||
char relativeFileName[1024];
|
||||
char pathPrefix[1024];
|
||||
pathPrefix[0] = 0;
|
||||
if (b3ResourcePath::findResourcePath(collision->m_geometry.m_meshFileName.c_str(), relativeFileName, 1024))
|
||||
{
|
||||
b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024);
|
||||
|
||||
|
||||
btAlignedObjectArray<char> sdfData;
|
||||
{
|
||||
std::streampos fsize = 0;
|
||||
std::ifstream file(relativeFileName, std::ios::binary);
|
||||
if (file.good())
|
||||
{
|
||||
fsize = file.tellg();
|
||||
file.seekg(0, std::ios::end);
|
||||
fsize = file.tellg() - fsize;
|
||||
file.seekg(0, std::ios::beg);
|
||||
sdfData.resize(fsize);
|
||||
int bytesRead = file.rdbuf()->sgetn(&sdfData[0], fsize);
|
||||
btAssert(bytesRead == fsize);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (sdfData.size())
|
||||
{
|
||||
btSdfCollisionShape* sdfShape = new btSdfCollisionShape();
|
||||
bool valid = sdfShape->initializeSDF(&sdfData[0], sdfData.size());
|
||||
btAssert(valid);
|
||||
|
||||
if (valid)
|
||||
{
|
||||
shape = sdfShape;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete sdfShape;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case URDF_GEOM_MESH:
|
||||
{
|
||||
GLInstanceGraphicsShape* glmesh = 0;
|
||||
|
||||
@@ -436,9 +436,16 @@ bool UrdfParser::parseGeometry(UrdfGeometry& geom, XMLElement* g, ErrorLogger* l
|
||||
geom.m_capsuleHeight = m_urdfScaling * urdfLexicalCast<double>(shape->Attribute("length"));
|
||||
}
|
||||
}
|
||||
else if (type_name == "mesh")
|
||||
else if ((type_name == "mesh") || (type_name == "cdf"))
|
||||
{
|
||||
geom.m_type = URDF_GEOM_MESH;
|
||||
if ((type_name == "cdf"))
|
||||
{
|
||||
geom.m_type = URDF_GEOM_CDF;
|
||||
}
|
||||
else
|
||||
{
|
||||
geom.m_type = URDF_GEOM_MESH;
|
||||
}
|
||||
geom.m_meshScale.setValue(1,1,1);
|
||||
std::string fn;
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ enum UrdfGeomTypes
|
||||
URDF_GEOM_CYLINDER,
|
||||
URDF_GEOM_MESH,
|
||||
URDF_GEOM_PLANE,
|
||||
URDF_GEOM_CAPSULE, //non-standard URDF?
|
||||
URDF_GEOM_CAPSULE, //non-standard URDF
|
||||
URDF_GEOM_CDF,//signed-distance-field, non-standard URDF
|
||||
URDF_GEOM_UNKNOWN,
|
||||
};
|
||||
|
||||
@@ -79,6 +80,8 @@ struct UrdfGeometry
|
||||
FILE_STL =1,
|
||||
FILE_COLLADA =2,
|
||||
FILE_OBJ =3,
|
||||
FILE_CDF = 4,
|
||||
|
||||
};
|
||||
int m_meshFileType;
|
||||
std::string m_meshFileName;
|
||||
|
||||
@@ -295,7 +295,7 @@ static void printGLString(const char *name, GLenum s) {
|
||||
bool sOpenGLVerbose = true;
|
||||
|
||||
|
||||
SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, bool allowRetina)
|
||||
SimpleOpenGL3App::SimpleOpenGL3App(const char* title, int width, int height, bool allowRetina, int maxNumObjectCapacity, int maxShapeCapacityInBytes)
|
||||
{
|
||||
gApp = this;
|
||||
|
||||
@@ -369,7 +369,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo
|
||||
|
||||
b3Assert(glGetError() ==GL_NO_ERROR);
|
||||
|
||||
m_instancingRenderer = new GLInstancingRenderer(128*1024,128*1024*1024);
|
||||
m_instancingRenderer = new GLInstancingRenderer(maxNumObjectCapacity, maxShapeCapacityInBytes);
|
||||
|
||||
m_primRenderer = new GLPrimitiveRenderer(width,height);
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ struct SimpleOpenGL3App : public CommonGraphicsApp
|
||||
class GLInstancingRenderer* m_instancingRenderer;
|
||||
virtual void setBackgroundColor(float red, float green, float blue);
|
||||
|
||||
SimpleOpenGL3App(const char* title, int width,int height, bool allowRetina=true);
|
||||
SimpleOpenGL3App(const char* title, int width,int height, bool allowRetina=true, int maxNumObjectCapacity = 128 * 1024, int maxShapeCapacityInBytes = 128 * 1024 * 1024);
|
||||
|
||||
virtual ~SimpleOpenGL3App();
|
||||
|
||||
virtual int registerCubeShape(float halfExtentsX=1.f,float halfExtentsY=1.f, float halfExtentsZ = 1.f, int textureIndex = -1, float textureScaling = 1);
|
||||
|
||||
@@ -169,7 +169,7 @@ public:
|
||||
for ( int i=0;i<softWorld->getSoftBodyArray().size();i++)
|
||||
{
|
||||
btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i];
|
||||
if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe)))
|
||||
//if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe)))
|
||||
{
|
||||
btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer());
|
||||
btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags());
|
||||
|
||||
@@ -28,9 +28,12 @@
|
||||
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
int gSharedMemoryKey = -1;
|
||||
int gDebugDrawFlags = 0;
|
||||
bool gDisplayDistortion = false;
|
||||
bool gDisableDesktopGL = false;
|
||||
static int gDebugDrawFlags = 0;
|
||||
static bool gDisplayDistortion = false;
|
||||
static bool gDisableDesktopGL = false;
|
||||
|
||||
static int maxNumObjectCapacity = 128 * 1024;
|
||||
static int maxShapeCapacityInBytes = 128 * 1024 * 1024;
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -477,7 +480,8 @@ bool CMainApplication::BInit()
|
||||
SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
|
||||
|
||||
*/
|
||||
m_app = new SimpleOpenGL3App("SimpleOpenGL3App",m_nWindowWidth,m_nWindowHeight,true);
|
||||
|
||||
m_app = new SimpleOpenGL3App("SimpleOpenGL3App",m_nWindowWidth,m_nWindowHeight,true, maxNumObjectCapacity, maxShapeCapacityInBytes);
|
||||
|
||||
|
||||
sGuiPtr = new OpenGLGuiHelper(m_app,false);
|
||||
@@ -2354,7 +2358,10 @@ int main(int argc, char *argv[])
|
||||
b3ChromeUtilsEnableProfiling();
|
||||
}
|
||||
|
||||
|
||||
args.GetCmdLineArgument("max_num_object_capacity", maxNumObjectCapacity);
|
||||
args.GetCmdLineArgument("max_shape_capacity_in_bytes", maxShapeCapacityInBytes);
|
||||
args.GetCmdLineArgument("shared_memory_key", gSharedMemoryKey);
|
||||
|
||||
#ifdef BT_USE_CUSTOM_PROFILER
|
||||
b3SetCustomEnterProfileZoneFunc(dcEnter);
|
||||
b3SetCustomLeaveProfileZoneFunc(dcLeave);
|
||||
|
||||
15
examples/pybullet/examples/signedDistanceField.py
Normal file
15
examples/pybullet/examples/signedDistanceField.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pybullet as p
|
||||
import pybullet
|
||||
import time
|
||||
p.connect(p.GUI)
|
||||
p.loadURDF("toys/concave_box.urdf")
|
||||
p.setGravity(0,0,-10)
|
||||
for i in range (10):
|
||||
p.loadURDF("sphere_1cm.urdf",[i*0.02,0,0.5])
|
||||
p.loadURDF("duck_vhacd.urdf")
|
||||
timeStep = 1./240.
|
||||
p.setTimeStep(timeStep)
|
||||
while (1):
|
||||
p.stepSimulation()
|
||||
time.sleep(timeStep)
|
||||
|
||||
Reference in New Issue
Block a user