Good / simple introduction example / docs for Bullet 3 GPU ?
-
- Posts: 11
- Joined: Sun Apr 08, 2012 10:01 am
Good / simple introduction example / docs for Bullet 3 GPU ?
Hello,
i am looking for a simple to follow introduction example on how to set up things to have a Bullet 3 world with OpenCL support.
There is a basic hello world example in the wiki, which explains how to create a world, add in rigidbodys, shapes and constraints
and step the simulation.
But is there somewhere an equivalent for Bullet 3 with OpenCL ? like a b3World with a b3Rigidbody and a b3Constraint... with automatic
OpenCL support in the back.
For example, blender includes bullet 2.83 and for this the "classic Bullet 2.x" helloworld example is applicable. Like use a btDynamicsWorld, how to build it
and stuff like that.
Ultimatively i want to port this over to Bullet 3 OpenCL or alternatively use CPU multithreading as fallback if opencl should be not available for some reason.
Because for larger simulations with 1000s of fracture shards and constraints the singlethreaded-ness becomes a serious bottleneck.
So is the potential performance gain worth all the effort to get used to a new API in Bullet3 and porting it all over ?
Another question... since the pybullet wrapper seems not exactly what i can use for the purpose of operating bullet via python, i also was looking into
Cython-izing parts of the Bullet 3 API.
So i hope the performance gain is greater (OpenCL vs CPU) than the potential loss using Cython. (Means, i get still a decent performance by using bullet as a wrapped
python module).
Any hints / clues / tips which could point me into the right direction ?
Greetings, scorpion81
i am looking for a simple to follow introduction example on how to set up things to have a Bullet 3 world with OpenCL support.
There is a basic hello world example in the wiki, which explains how to create a world, add in rigidbodys, shapes and constraints
and step the simulation.
But is there somewhere an equivalent for Bullet 3 with OpenCL ? like a b3World with a b3Rigidbody and a b3Constraint... with automatic
OpenCL support in the back.
For example, blender includes bullet 2.83 and for this the "classic Bullet 2.x" helloworld example is applicable. Like use a btDynamicsWorld, how to build it
and stuff like that.
Ultimatively i want to port this over to Bullet 3 OpenCL or alternatively use CPU multithreading as fallback if opencl should be not available for some reason.
Because for larger simulations with 1000s of fracture shards and constraints the singlethreaded-ness becomes a serious bottleneck.
So is the potential performance gain worth all the effort to get used to a new API in Bullet3 and porting it all over ?
Another question... since the pybullet wrapper seems not exactly what i can use for the purpose of operating bullet via python, i also was looking into
Cython-izing parts of the Bullet 3 API.
So i hope the performance gain is greater (OpenCL vs CPU) than the potential loss using Cython. (Means, i get still a decent performance by using bullet as a wrapped
python module).
Any hints / clues / tips which could point me into the right direction ?
Greetings, scorpion81
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Good / simple introduction example / docs for Bullet 3 G
Why not?Another question... since the pybullet wrapper seems not exactly what i can use for the purpose of operating bullet via python
pybullet and the underlying shared memory C-API will be the new Bullet 3.x API. I plan to create a backend so you can automatically select Bullet 2.x or Bullet 3.x (or other physics engines) under the hood. Those Bullet 3.x bindings will start happenening around PhysicsServerCommandProcessor.cpp...
-
- Posts: 11
- Joined: Sun Apr 08, 2012 10:01 am
Re: Good / simple introduction example / docs for Bullet 3 G
Ah ok, well i guess i did not understand yet how this new shared memory C-API works. Like... which commands in particular are necessary to replicate the basic HelloWorld example from the (old) wiki ?Erwin Coumans wrote:Why not?Another question... since the pybullet wrapper seems not exactly what i can use for the purpose of operating bullet via python
pybullet and the underlying shared memory C-API will be the new Bullet 3.x API. I plan to create a backend so you can automatically select Bullet 2.x or Bullet 3.x (or other physics engines) under the hood. Those Bullet 3.x bindings will start happenening around PhysicsServerCommandProcessor.cpp...
Like building a world, adding rigidbodies, setting shapes, adding constraints ?
Is there some documentation i might have overlooked ?
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Good / simple introduction example / docs for Bullet 3 G
Loading a URDF lets you specify collision shapes, mass, inertia, constraints etc.
It is work-in-progress, there is not much documentation for the new API yet, I would suggest try getting pybullet to run and give some feedback.
There are a few scripts in Bullet/examples/pybullet.
There will also be C++ access, using Bullet\examples\RoboticsLearning\b3RobotSimAPI.h. Once this is more complete, it will be rename b3PhysicsSimAPI.h...
You will be able to do your own graphics engine of course, and use the Bullet connect 'DIRECT' method (instead of GUI or SHARED_MEMORY).
It is work-in-progress, there is not much documentation for the new API yet, I would suggest try getting pybullet to run and give some feedback.
There are a few scripts in Bullet/examples/pybullet.
There will also be C++ access, using Bullet\examples\RoboticsLearning\b3RobotSimAPI.h. Once this is more complete, it will be rename b3PhysicsSimAPI.h...
You will be able to do your own graphics engine of course, and use the Bullet connect 'DIRECT' method (instead of GUI or SHARED_MEMORY).
-
- Posts: 11
- Joined: Sun Apr 08, 2012 10:01 am
Re: Good / simple introduction example / docs for Bullet 3 G
Ok, first attempt to get pybullet to be built on Linux Mint 17.3, x64 , GCC 4.8.4, Python 3.5.1....Erwin Coumans wrote:Loading a URDF lets you specify collision shapes, mass, inertia, constraints etc.
It is work-in-progress, there is not much documentation for the new API yet, I would suggest try getting pybullet to run and give some feedback.
There are a few scripts in Bullet/examples/pybullet.
There will also be C++ access, using Bullet\examples\RoboticsLearning\b3RobotSimAPI.h. Once this is more complete, it will be rename b3PhysicsSimAPI.h...
You will be able to do your own graphics engine of course, and use the Bullet connect 'DIRECT' method (instead of GUI or SHARED_MEMORY).
got a linker error, see below
and CFLAGS / CCFLAGS / CPPFLAGS = '-fPIC' before the premake4_linux64 or make command didnt have an effect
Input:
CPPFLAGS='-fPIC' ./premake4_linux64 --enable_pybullet --python_include_dir="/home/martin/BlenderSVN/build/bin/2.78/python/include/python3.5m"
--python_lib_dir="/home/martin/BlenderSVN/build/bin/2.78/python/lib/python3.5" gmake
and make in the gmake dir
Output...(snip)
...
==== Building BulletFileLoader (release64) ====
==== Building BulletWorldImporter (release64) ====
==== Building pybullet (release64) ====
Linking pybullet
/usr/bin/ld: ../../bin/libBulletExampleBrowserLib_gmake_x64_release.a(OpenGLExampleBrowser.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
../../bin/libBulletExampleBrowserLib_gmake_x64_release.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[1]: *** [../../bin/libpybullet_gmake_x64_release.so] Error 1
make: *** [pybullet] Error 2
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Good / simple introduction example / docs for Bullet 3 G
Use cmake to build pybullet on Linux and Mac, there are some issues building pybullet using premake.
In the Bullet root directory:
edit build_and_run_cmake.sh and turn BUILD_PYBULLET=ON
then run this script
./build_and_run_cmake.sh
This should build all of Bullet and launch the ExampleBrowser. Play with this a bit, and exit it using <ESC> key.
Then change directory to build_cmake/examples/pybullet. On Linux use
On Mac OSX use
Start python while in this directory, so it can find pybullet.so, and start your first script: (replace p.GUI with p.DIRECT or p.SHARED_MEMORY, -> shared memory will connect to example browser, while in 'experimental/physics server' mode)
The VR example only works on Windows at the moment (waiting for Valve/HTC Vive/Oculus Rift),
but you can see it using pybullet as follows:
There are also some example pybullet scripts in Bullet/examples/pybullet. At some stage I'll write some documentation.
Does that work for you?
In the Bullet root directory:
edit build_and_run_cmake.sh and turn BUILD_PYBULLET=ON
then run this script
./build_and_run_cmake.sh
This should build all of Bullet and launch the ExampleBrowser. Play with this a bit, and exit it using <ESC> key.
Then change directory to build_cmake/examples/pybullet. On Linux use
Code: Select all
ln -s libpybullet.so pybullet.so
Code: Select all
ln -s libpybullet.dylib pybullet.so
Code: Select all
import pybullet as p
p.connect(p.GUI)
p.loadURDF("plane.urdf")
p.loadURDF("sphere_small.urdf",0,0,2)
p.setSimulation()
but you can see it using pybullet as follows:
Code: Select all
import pybullet as p
p.connect(p.GUI)
p.setRealTimeSimulation(1)
Does that work for you?
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Good / simple introduction example / docs for Bullet 3 G
You can also try out pybullet to connect to a 'physics server' in the example browser:
First start the example browser, and select the 'Experiments/Physics Server' example, and leave it running. Before running the script below, your ExampleBrowser in 'Experiments/Physics Server' should look similar to this: In a new terminal, start python in the build_cmake/example/pybullet directory, start it (python) and then run the following script.
The p.setRealTimeSImulation(1) will add some hard-coded world/objects (used for the VR demo). You can also leave out the 'p.setRealTimeSimulation(1)' command. In that case, you have to manually 'step' the simulation by sending 'p.stepSimulation' commands and put objecs in the world by using loadUrdf/loadSdf.
After running above script, it should look similar to this:
First start the example browser, and select the 'Experiments/Physics Server' example, and leave it running. Before running the script below, your ExampleBrowser in 'Experiments/Physics Server' should look similar to this: In a new terminal, start python in the build_cmake/example/pybullet directory, start it (python) and then run the following script.
Code: Select all
import pybullet as p
p.connect(p.SHARED_MEMORY)
p.setRealTimeSimulation(1)
After running above script, it should look similar to this:
You do not have the required permissions to view the files attached to this post.
-
- Posts: 11
- Joined: Sun Apr 08, 2012 10:01 am
Re: Good / simple introduction example / docs for Bullet 3 G
Erwin Coumans wrote:You can also try out pybullet to connect to a 'physics server' in the example browser:
First start the example browser, and select the 'Experiments/Physics Server' example, and leave it running. Before running the script below, your ExampleBrowser in 'Experiments/Physics Server' should look similar to this: In a new terminal, start python in the build_cmake/example/pybullet directory, start it (python) and then run the following script.
The p.setRealTimeSImulation(1) will add some hard-coded world/objects (used for the VR demo). You can also leave out the 'p.setRealTimeSimulation(1)' command. In that case, you have to manually 'step' the simulation by sending 'p.stepSimulation' commands and put objecs in the world by using loadUrdf/loadSdf.Code: Select all
import pybullet as p p.connect(p.SHARED_MEMORY) p.setRealTimeSimulation(1)
After running above script, it should look similar to this:
Ok, i got the pybullet to run now. Had to recompile my static python 3.5 lib to a shared one, else i got the same linker error. (and i used Cmake and your instructions too)
Currently i am looking into pythons xml ElementTree on how to write urdf links (and joints later maybe) from the mesh shards as an XML file.
It would be even nicer if the Bullet C-API and thus pybullet would allow this in a more direct way, as you mentioned before
Will try your "hardcoded" example later.
Greetings, scorpion81
-
- Posts: 11
- Joined: Sun Apr 08, 2012 10:01 am
Re: Good / simple introduction example / docs for Bullet 3 G
Ok, and the hardcoded example works too.
Only thing what worries me a bit about loading from urdf is the short delay in loading time, even already in the example browser
Imagine i want to use dynamic voronoi fracturing. For this purpose in blender i let bullet fire contact callbacks to blender,
where the impact point and force is evaluated basically and a pointcloud for the next voronoi fracture of the existing
shards is generated. In the Fracture Modifier in blender this already works quite nicely. But if i constantly have to write and
read urdf files containing a new bigger set of shards, i expect this loading time to become slower and slower. This will be a serious
performance bottleneck and slow down the sim unnecessarily.
So i am looking forward on how to perhaps create rigidbodies and constraints too directly thru the C-API for Bullet 3.x.
scorpion81
Only thing what worries me a bit about loading from urdf is the short delay in loading time, even already in the example browser
Imagine i want to use dynamic voronoi fracturing. For this purpose in blender i let bullet fire contact callbacks to blender,
where the impact point and force is evaluated basically and a pointcloud for the next voronoi fracture of the existing
shards is generated. In the Fracture Modifier in blender this already works quite nicely. But if i constantly have to write and
read urdf files containing a new bigger set of shards, i expect this loading time to become slower and slower. This will be a serious
performance bottleneck and slow down the sim unnecessarily.
So i am looking forward on how to perhaps create rigidbodies and constraints too directly thru the C-API for Bullet 3.x.
scorpion81
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Good / simple introduction example / docs for Bullet 3 G
Yes, in your case (and when using pybullet in a content creation environment such as Blender etc) programmatically creating shapes, rigid bodies and constraints make more sense.
Also, note that the OpenCL GPGPU rigid body pipeline hasn't been developed for many year, so it will take some time to get it into good shape again, and them putting it behind the abstract API.
I'll look into all of this, as part of my work.
Also, note that the OpenCL GPGPU rigid body pipeline hasn't been developed for many year, so it will take some time to get it into good shape again, and them putting it behind the abstract API.
I'll look into all of this, as part of my work.
-
- Posts: 350
- Joined: Sat Jul 04, 2015 10:33 am
- Location: Bern, Switzerland
Re: Good / simple introduction example / docs for Bullet 3 G
@Erwin: In case this comes in handy, I started making a wiki page stub based on what you posted here. This might be nice for the earlyadopters such as scropion81, me and such.
Here it is:
http://bulletphysics.org/mediawiki-1.5. ... g_pybullet
Some early feedback:
Your step-by-step guide worked well on Linux Mint here, I can see the Example Browser with a plane and a ball. However, the p.setSimulation() command does not exist (anymore?). What is the intention of it?
Here it is:
http://bulletphysics.org/mediawiki-1.5. ... g_pybullet
Some early feedback:
Your step-by-step guide worked well on Linux Mint here, I can see the Example Browser with a plane and a ball. However, the p.setSimulation() command does not exist (anymore?). What is the intention of it?