How to run the "Hello World" PyBullet example

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
8Observer8
Posts: 10
Joined: Sat Sep 20, 2014 6:07 am

How to run the "Hello World" PyBullet example

Post by 8Observer8 »

I try to run the first official example: https://github.com/dgym/pybullet/blob/m ... loworld.py

I installed PyBullet like this:

Code: Select all

pip install pybullet
When I try to run the example I get this error message:

Code: Select all

Traceback (most recent call last):
File "main.py", line 1, in <module>
from bullet.bullet import (ModuleNotFoundError: No module named 'bullet'
I think it is because the example is old (Mar 31, 2012) and PyBullet was updated. The module name is "pybullet". I renamed import like this:

Code: Select all

from pybullet import (
    Vector3, Transform,
    BoxShape,
    DefaultMotionState,
    RigidBody,
    DiscreteDynamicsWorld)
I have this error message:

Code: Select all

pybullet build time: Nov  3 2020 18:27:37
Traceback (most recent call last):
File "main.py", line 1, in <module>
from pybullet import (ImportError: cannot import name 'Vector3' from 'pybullet'
(C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\pybullet.cp37-win32.pyd)
Could you copy the official example above and try it you your machine? How I should to change the example to run it? I want to use PyBullet with OpenGL and PyQt5. I want to have GUI and 3D graphics with Physics in one window. Please, help me to run the simple PyBullet example above.
8Observer8
Posts: 10
Joined: Sat Sep 20, 2014 6:07 am

Re: How to run the "Hello World" PyBullet example

Post by 8Observer8 »

What version of PyBullet I must install to run the example above?
8Observer8
Posts: 10
Joined: Sat Sep 20, 2014 6:07 am

Re: How to run the "Hello World" PyBullet example

Post by 8Observer8 »

I use Bullet from C++. Could I use C++ Bullet library from Python without PyBullet? I really do not understand how to rewrite C++ code with OpenGL to PyBullet and OpenGL.
8Observer8
Posts: 10
Joined: Sat Sep 20, 2014 6:07 am

Re: How to run the "Hello World" PyBullet example

Post by 8Observer8 »

Please, write that it is impossible.
8Observer8
Posts: 10
Joined: Sat Sep 20, 2014 6:07 am

Re: How to run the "Hello World" PyBullet example

Post by 8Observer8 »

I found a solution. It is possible to use Python wrapper of Panda3D with my custom render in OpenGL.

To install Panda3D you need to write:
pip install Panda3D
main.py

Code: Select all

from panda3d.bullet import BulletWorld
from panda3d.core import TransformState, Vec3, Quat, Point3
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletRigidBodyNode

world = BulletWorld()
world.setGravity(Vec3(0, 0, -9.81))

shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
node = BulletRigidBodyNode('Box')
node.setMass(1.0)

p = Point3(1, 0, 0)
q = Quat.identQuat()
s = Vec3(2, 2, 2)

transform = TransformState.make_pos_quat_scale(p, q, s)
node.setTransform(transform)

node.addShape(shape)
world.attachRigidBody(node)

for i in range(10):
    world.doPhysics(0.016)
    print(node.getTransform())
Output:
T:(pos 1 0 0 scale 2)
T:(pos 1 0 -0.002507 scale 2)
T:(pos 1 0 -0.007521 scale 2)
T:(pos 1 0 -0.015042 scale 2)
T:(pos 1 0 -0.02507 scale 2)
T:(pos 1 0 -0.037605 scale 2)
T:(pos 1 0 -0.052647 scale 2)
T:(pos 1 0 -0.070196 scale 2)
T:(pos 1 0 -0.090252 scale 2)
T:(pos 1 0 -0.112815 scale 2)
8Observer8
Posts: 10
Joined: Sat Sep 20, 2014 6:07 am

Re: How to run the "Hello World" PyBullet example

Post by 8Observer8 »

I tried to use PyBullet but it is very complicated and I cannot understand haw to use it with OpenGL. The Panda3D Bullet wrapper is only one way that I found. And there is a very great manual: https://docs.panda3d.org/1.10/python/pr ... llet/index I hope I will not have unresolved problems with using the Panda3D Bullet wrapper with Qt and OpenGL.

I use:
  • the Panda3D Bullet wrapper for Physics
  • PyQt5 (and PySide2) for creating a window
  • OpenGL 3.3 for rendering
I created a textured cube with Blender and GIMP. I exported the cube to dae (COLLADA) and imported it to my program with built-in Qt XML parser.

Source:
textured_cubes_bullet_pyqt5.gif
textured_cubes_bullet_pyqt5.gif (105.18 KiB) Viewed 6616 times
Post Reply