Anyone tried python with bullet?

Gonsor

06-12-2008 19:15:51

Well I read some docs and worked through the demos of Bullet and I currently write my own wrapper module for bullet in python.
However, I'm stuck with the debugger but I think, it could be a very basic python mistake.
According to doxygen and all c++ samples I saw, you just need to create a class, which inherits from btIDebugDraw and must at least implement a "drawLine" method.

So this should work:

class DebugDrawer(bullet.btIDebugDraw):
def drawLine(self, lineFrom, lineTo, lineColor):
print "Draw debug line"


The debugger is then set to the world by calling "self.world.setDebugDrawer"
This works for me in C++.
However, if I do this in python, the updating method "self.world.stepSimulation" will always fail with a "TypeError: 'NoneType' object is not callable".

I tried adding it to the python-ogre bullet demo and it's the same result -
just add

class DebugDrawer(bullet.btIDebugDraw):
def drawLine(self, lineFrom, lineTo, lineColor):
print "Draw debug line"

debug = DebugDrawer()
world.setDebugDrawer(debug)

somewhere before the world.stepSimulation calls in python-ogre/demos/bullet/test01.py

Any ideas?

Best regards,
Gonsor

SiWi

07-12-2008 12:11:18

That NoneType error tells you that your self.world is set to None therefore not a BulletWorld class.
Check your basic bullet setup please.
Edit: Of course it does not has to be your world being set to to None, but then your error message should be more than that.

Gonsor

07-12-2008 15:41:59

Thanks for your answer. :)
That NoneType error tells you that your self.world is set to None therefore not a BulletWorld class.
Check your basic bullet setup please.
Edit: Of course it does not has to be your world being set to to None, but then your error message should be more than that.

Yes, and that is the weird thing. The world object should be fine - if I don't set a debugger, it updates the world perfectly, I got objects that fall down due to the gravity etc.
And printing it out shows
<ogre.physics.bullet._bullet_.btDiscreteDynamicsWorld object at 0xa5dacd4>
and not "None". The debugDrawer object is also not "None". That's why I absolutely have no idea what
File "/media/disk/home/daniel/Projekte/src/pyogrebullet.py", line 45, in update
self.world.stepSimulation(evt.timeSinceLastFrame)
TypeError: 'NoneType' object is not callable

means.
Because this call works without problems, when not setting a debugDrawer.
(You can check that with the code in my first post, when added to the demo)
Well, I guess it's connected with the way a debugDrawer class must be implemented; I don't see a mistake there though - maybe the bullet doxygen is inaccurate; so I'll continue trying -.-

Best regards,
Gonsor

Gonsor

07-12-2008 16:09:23

Ok, I got it working. So for all people, who want to go through hell like me and try pure bullet, here's the solution.
The doxygen description was indeed wrong; if you look at the method prototypes of the IDebugDraw interface, you'll notice that there are more than just the "drawLine" methods purely virtual and also set to 0, so they must be overwritten. I think, the "TypeError: None" exceptions are caused by non-implemented purely virtual methods. Never would have thought of that, when I read the message the first time.
So a valid debugger class has to look like this:
class DebugDrawer(bullet.btIDebugDraw):

def drawLine(self, lineFrom, lineTo, lineColor):
pass

def drawContactPoint(self, pointOnB, normalOnB, distance, lifeTime, color):
pass

def reportErrorWarning(self, warningString):
pass

def draw3dText(self, location, textString):
pass

def setDebugMode(self,debugMode):
pass

def getDebugMode(self):
return 0

It really is a shame, that there is nearly no documentation or tutorials for bullet available in the whole web; it's such a great physics library. And on top of that, even things that I would 100% trust like the doxygen is wrong because it's outdated. ;(
Maybe I'll write a tutorial for the python-ogre Wiki, when I'm more advanced in this topic and if there's interest.

Best Regards,
Gonsor

bharling

08-12-2008 13:49:52

I'd certainly be very interested in a tutorial, I was the same as you but gave up because I can't find any decent bullet tutorials anywhere.