From a6244d714e673cb39ce214d6d4c888c6ce60c24d Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Fri, 25 Jan 2019 10:14:54 -0800 Subject: [PATCH] more PyBullet PhysX preliminary work. --- build3/premake4.lua | 10 +++- .../eglRendererVisualShapeConverter.cpp | 3 +- .../eglRendererVisualShapeConverter.h | 2 +- .../plugins/stablePDPlugin/Shape.cpp | 2 +- .../TinyRendererVisualShapeConverter.h | 2 +- .../pybullet/examples/otherPhysicsEngine.py | 32 +++--------- examples/pybullet/premake4.lua | 50 ++++++++++++++++++- 7 files changed, 70 insertions(+), 31 deletions(-) diff --git a/build3/premake4.lua b/build3/premake4.lua index 89936d8bf..b74f3f86a 100644 --- a/build3/premake4.lua +++ b/build3/premake4.lua @@ -59,7 +59,12 @@ trigger = "enable_static_vr_plugin", description = "Statically link vr plugin (in examples/SharedMemory/plugins/vrSyncPlugin)" } - + + newoption + { + trigger = "enable_physx", + description = "Allow optional PhysX backend for PyBullet, use pybullet.connect(pybullet.PhysX)." + } newoption { @@ -638,4 +643,7 @@ end include "../src/BulletDynamics" include "../src/BulletCollision" include "../src/LinearMath" + if _OPTIONS["enable_physx"] then + include "../src/physx" + end diff --git a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp index 5c8a3dcf1..05e24945b 100644 --- a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp +++ b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp @@ -250,6 +250,7 @@ static void SimpleResizeCallback(float widthf, float heightf) // gApp->m_primRenderer->setScreenSize(width, height); } +#if 0 static void SimpleKeyboardCallback(int key, int state) { if (key == B3G_ESCAPE) //&& gApp && gApp->m_window) @@ -261,7 +262,7 @@ static void SimpleKeyboardCallback(int key, int state) //gApp->defaultKeyboardCallback(key,state); } } - +#endif static void SimpleMouseButtonCallback(int button, int state, float x, float y) { if (gWindow) diff --git a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h index dfde7b22d..5fe8a5f08 100644 --- a/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h +++ b/examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h @@ -11,7 +11,7 @@ struct EGLRendererVisualShapeConverter : public UrdfRenderingInterface virtual ~EGLRendererVisualShapeConverter(); - virtual int convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfLink* linkPtr, const UrdfModel* model, int collisionObjectUniqueId, int bodyUniqueId, struct CommonFileIOInterface* fileIO); + virtual int convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfLink* linkPtr, const UrdfModel* model, int orgGraphicsUniqueId, int bodyUniqueId, struct CommonFileIOInterface* fileIO); virtual int getNumVisualShapes(int bodyUniqueId); diff --git a/examples/SharedMemory/plugins/stablePDPlugin/Shape.cpp b/examples/SharedMemory/plugins/stablePDPlugin/Shape.cpp index a8507257b..31b7fb04c 100644 --- a/examples/SharedMemory/plugins/stablePDPlugin/Shape.cpp +++ b/examples/SharedMemory/plugins/stablePDPlugin/Shape.cpp @@ -7,7 +7,7 @@ bool cShape::ParseShape(const std::string& str, eShape& out_shape) bool succ = true; if (str == "null") { - out_shape = eShapeNull; + out_shape = eShapeNull; } else if (str == "box") { diff --git a/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.h b/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.h index 5fec39cdd..6759395aa 100644 --- a/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.h +++ b/examples/SharedMemory/plugins/tinyRendererPlugin/TinyRendererVisualShapeConverter.h @@ -11,7 +11,7 @@ struct TinyRendererVisualShapeConverter : public UrdfRenderingInterface virtual ~TinyRendererVisualShapeConverter(); - virtual int convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfLink* linkPtr, const UrdfModel* model, int collisionObjectUniqueId, int bodyUniqueId, struct CommonFileIOInterface* fileIO); + virtual int convertVisualShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame, const UrdfLink* linkPtr, const UrdfModel* model, int unused, int bodyUniqueId, struct CommonFileIOInterface* fileIO); virtual int getNumVisualShapes(int bodyUniqueId); diff --git a/examples/pybullet/examples/otherPhysicsEngine.py b/examples/pybullet/examples/otherPhysicsEngine.py index 2786b1c66..dfd04352d 100644 --- a/examples/pybullet/examples/otherPhysicsEngine.py +++ b/examples/pybullet/examples/otherPhysicsEngine.py @@ -1,32 +1,14 @@ import pybullet as p import time -#p.connect(p.DIRECT) -#p.connect(p.DART) -p.connect(p.MuJoCo) +p.connect(p.PhysX) +p.loadPlugin("eglRendererPlugin") -#p.connect(p.GUI) -bodies = p.loadMJCF("mjcf/capsule.xml") -print("bodies=",bodies) - -numBodies = p.getNumBodies() -print("numBodies=",numBodies) -for i in range (numBodies): - print("bodyInfo[",i,"]=",p.getBodyInfo(i)) - +p.loadURDF("plane.urdf") +for i in range (50): + p.loadURDF("r2d2.urdf",[0,0,1+i*2]) p.setGravity(0,0,-10) -timeStep = 1./240. -p.setPhysicsEngineParameter(fixedTimeStep=timeStep) -#while (p.isConnected()): -for i in range (1000): +while (1): p.stepSimulation() - - for b in bodies: - pos,orn=p.getBasePositionAndOrientation(b) - print("pos[",b,"]=",pos) - print("orn[",b,"]=",orn) - linvel,angvel=p.getBaseVelocity(b) - print("linvel[",b,"]=",linvel) - print("angvel[",b,"]=",angvel) - time.sleep(timeStep) + time.sleep(1./240.) \ No newline at end of file diff --git a/examples/pybullet/premake4.lua b/examples/pybullet/premake4.lua index 81eb423ea..19d39558c 100644 --- a/examples/pybullet/premake4.lua +++ b/examples/pybullet/premake4.lua @@ -20,7 +20,7 @@ project ("pybullet") defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER"} hasCL = findOpenCL("clew") - links{"BulletExampleBrowserLib","gwen", "BulletFileLoader","BulletWorldImporter","OpenGL_Window","BulletSoftBody", "BulletInverseDynamicsUtils", "BulletInverseDynamics", "BulletDynamics","BulletCollision","LinearMath","BussIK", "Bullet3Common"} + links{ "BulletExampleBrowserLib","gwen", "BulletFileLoader","BulletWorldImporter","OpenGL_Window","BulletSoftBody", "BulletInverseDynamicsUtils", "BulletInverseDynamics", "BulletDynamics","BulletCollision","LinearMath","BussIK", "Bullet3Common"} initOpenGL() initGlew() @@ -171,7 +171,55 @@ if not _OPTIONS["no-enet"] then "../../examples/SharedMemory/plugins/pdControlPlugin/pdControlPlugin.cpp", "../../examples/SharedMemory/plugins/pdControlPlugin/pdControlPlugin.h", } + + if _OPTIONS["enable_physx"] then + defines {"BT_ENABLE_PHYSX","PX_PHYSX_STATIC_LIB", "PX_FOUNDATION_DLL=0"} + + configuration {"x64", "debug"} + defines {"_DEBUG"} + configuration {"x86", "debug"} + defines {"_DEBUG"} + configuration {"x64", "release"} + defines {"NDEBUG"} + configuration {"x86", "release"} + defines {"NDEBUG"} + configuration{} + + includedirs { + ".", + "../../src/PhysX/physx/include", + "../../src/PhysX/physx/include/characterkinematic", + "../../src/PhysX/physx/include/common", + "../../src/PhysX/physx/include/cooking", + "../../src/PhysX/physx/include/extensions", + "../../src/PhysX/physx/include/geometry", + "../../src/PhysX/physx/include/geomutils", + "../../src/PhysX/physx/include/vehicle", + "../../src/PhysX/pxshared/include", + } + links { + "PhysX", + } + files { + "../../examples/SharedMemory/plugins/eglPlugin/eglRendererPlugin.cpp", + "../../examples/SharedMemory/plugins/eglPlugin/eglRendererPlugin.h", + "../../examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.cpp", + "../../examples/SharedMemory/plugins/eglPlugin/eglRendererVisualShapeConverter.h", + "../../examples/SharedMemory/physx/PhysXC_API.cpp", + "../../examples/SharedMemory/physx/PhysXClient.cpp", + "../../examples/SharedMemory/physx/PhysXServerCommandProcessor.cpp", + "../../examples/SharedMemory/physx/PhysXUrdfImporter.cpp", + "../../examples/SharedMemory/physx/URDF2PhysX.cpp", + "../../examples/SharedMemory/physx/PhysXC_API.h", + "../../examples/SharedMemory/physx/PhysXClient.h", + "../../examples/SharedMemory/physx/PhysXServerCommandProcessor.h", + "../../examples/SharedMemory/physx/PhysXUrdfImporter.h", + "../../examples/SharedMemory/physx/URDF2PhysX.h", + "../../examples/SharedMemory/physx/PhysXUserData.h", + } + end + if (_OPTIONS["enable_static_vr_plugin"]) then files {"../../examples/SharedMemory/plugins/vrSyncPlugin/vrSyncPlugin.cpp"} end