Is bullet or OgreBullet functional?

bharling

19-02-2009 10:05:33

Hi folks,

have been trying for a few days now to get anywhere with bullet physics in Python-Ogre, with very little success. test01.py and test02.py work for me, but everything fails when I try to do anything myself. I cant get the motionState stuff to work at all, and I'm getting some nasty crashes! Here's the code I cobbled together from the other demos if anyone can help

import sys, os
sys.path.insert(0,'..')
import PythonOgreConfig

if sys.platform == 'win32':
newpath = os.path.join ( os.path.abspath(os.path.dirname(__file__)), '../../plugins')
os.environ['PATH'] = newpath +';' + os.environ['PATH']

import ogre.renderer.OGRE as ogre
import ogre.physics.OgreBulletC as bulletC
import ogre.physics.bullet as bullet
import SampleFramework as sf

class BulletListener( sf.FrameListener ):
def __init__(self, rw, cam, world ):
sf.FrameListener.__init__(self, rw, cam)
self.world = world

def frameStarted(self, evt):
self.world.stepSimulation( evt.timeSinceLastFrame )
return sf.FrameListener.frameStarted( self, evt )

class OgreMotionState(bullet.btMotionState):
def __init__(self, initalPosition):
bullet.btMotionState.__init__(self)
self.Pos=initalPosition
self.Position=ogre.Vector3()
self.Quaternion=ogre.Quaternion()

def getWorldTransform(self, WorldTrans):
print WorldTrans
print WorldTrans.Rotation.x(),WorldTrans.Rotation.y(),WorldTrans.Rotation.z()
print self.Pos.getOrigin()
WorldTrans.setOrigin(self.Pos.getOrigin())
WorldTrans.setBasis(self.Pos.getBasis())

print WorldTrans.Rotation.x(),WorldTrans.Rotation.y(),WorldTrans.Rotation.z()
print WorldTrans
print "Pos", self.Pos
t=self.Pos
print "T", t
t.setOrigin(WorldTrans.getOrigin())
print "T1", t

def setWorldTransform(self, WorldTrans):
#print "setWorldTrans", WorldTrans
self.Position=ogre.Vector3(WorldTrans.getOrigin().x(),WorldTrans.getOrigin().y(),WorldTrans.getOrigin().z())
self.Quaternion=ogre.Quaternion(WorldTrans.getRotation().w(),WorldTrans.getRotation().x(),WorldTrans.getRotation().y(),WorldTrans.getRotation().z())
#print "setWorldTrans", WorldTrans



class BulletApplication( sf.Application ):
def _createScene( self ):
self.setupBullet()
self.createBoxes()

def __del__(self):
if self.world:
del self.world
#sf.Application.__del__(self)

def setupBullet( self ):
self.collisionConfiguration = bullet.btDefaultCollisionConfiguration()
self.dispatcher = bullet.btCollisionDispatcher (self.collisionConfiguration)
worldAabbMin = bullet.btVector3(-1000,-1000,-1000)
worldAabbMax = bullet.btVector3(1000,1000,1000)
maxProxies = 32766
self.broadphase = bullet.btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies)
self.solver = bullet.btSequentialImpulseConstraintSolver()
self.world = bullet.btDiscreteDynamicsWorld(self.dispatcher, self.broadphase , self.solver, self.collisionConfiguration)
self.world.stepSimulation(0.1)
self.world.stepSimulation(1)

def createBoxes( self ):
ent = self.sceneManager.createEntity( "box", "cube.mesh" )
node = self.sceneManager.getRootSceneNode().createChildSceneNode()
node.attachObject( ent )
ent.setMaterialName( "Examples/RustySteel")

mass = 10
fallInertia = bullet.btVector3(0, 0, 0)
shape=bullet.btSphereShape(1)
shape.calculateLocalInertia(mass, fallInertia)
print "Creating motionState"
motionState=OgreMotionState(bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), bullet.btVector3(0, 50, 0)))
print "creating construct"
construct = bullet.btRigidBody.btRigidBodyConstructionInfo(mass, motionState, shape, fallInertia)
print "creating object"
Object=bullet.btRigidBody(construct) # ...this should work in my eyes
print "adding rigidBody"
self.world.addRigidBody(Object)
print "completed"
self.world.stepSimulation(1)

def _createFrameListener( self ):
self.fl = BulletListener( self.renderWindow, self.camera, None )
self.fl.world = self.world
self.root.addFrameListener( self.fl )


if __name__=="__main__":
app = BulletApplication()
app.go()


I notice the world object seems very 'delicate', ie: you can't pass it as an argument to a framelistener otherwise it gets very upset!
with this code or slight variants thereof I either get a crash or 'pure virtual' error... nasty!

I'm guessing the wrapper for bullet is still in the embryonic stages at the moment.
many thanks,

jsgreenawalt

20-02-2009 00:49:33

Is bullet or OgreBullet functional?
I'm going to have to say "no" :-( At least I can't get it working.

The python wrappers for bullet won't compile using the "1-6" branch in svn and won't generate or compile using the trunk version. What I'd like to know is, where (what specific svn revision) is the code that was used to build/compile the bullet wrappers for the released 1.6.1 version of python-ogre? It would be nice if the releases were "tagged". Right now I'm going to assume that it was only compiled with some local hack that never even made it into svn, which makes me wonder...

andy

20-02-2009 03:29:54

What is the problem you are having building bullet and on what platform? As far as I know the trunk is building well on Windows against bullet 2.73

If you could post any building issues etc on the google mailing list as I have more regular access to that..

Thanks
Andy

jsgreenawalt

20-02-2009 04:51:36

Sorry andy, I posted the problems that I was having here:
http://www.ogre3d.org/addonforums/viewtopic.php?f=3&t=9285#p53786

I've also posted them to the mailing list just now after a fresh attempt (using the head revision of the v1-6 branch). I'm using windows XP. Let me know if there's any further info that you need. I'll write another post to the mailing list describing the issues building with the trunk head revision.

bharling

20-02-2009 09:22:33

I'm just using the windows binary release, and was really just trying to do a bullet demo to contribute to the project. Of course the problem could very well be that I dont really understand the engine well enough yet!

Morgg

26-03-2009 02:10:35

I use Python-Ogre Release 1.6.1r906 (latest), installed in binary form, and Python 2.5.4.

I have succesfully run the Basic Tutorial 1, but I can't run any bullet code in python-ogre, at all. I tried what I think is the port of the HelloWorld tutorial in bullet wiki, it makes python.exe crash (!?). This is my adapted code:
#!/usr/bin/env python
# This code is Public Domain.
"""Python-Ogre Basic Tutorial 01: The SceneNode, Entity, and SceneManager constructs."""

#import ogre.renderer.OGRE as ogre
from ogre.physics.bullet import *

if __name__ == '__main__':

maxProxies = 1024
worldAabbMin = btVector3(-10000,-10000,-10000)
worldAabbMax = btVector3(10000,10000,10000)
broadphase = btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies)

#Set up the collision configuration and dispatcher
collisionConfiguration = btDefaultCollisionConfiguration()
dispatcher = btCollisionDispatcher(collisionConfiguration)

#The actual physics solver
solver = btSequentialImpulseConstraintSolver()

#The world
dynamicsWorld = btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration)


Debugging with Eclipse+PyDev I found out Python crashes when executing the line dispatcher = btCollisionDispatcher(collisionConfiguration), with no errors in the console output.

Any idea about what could be happening? By the way, I couldn't run the bullet/ogrebullet demos icluded in the package either. Is bullet really working in Python-Ogre? Anyone can point me to some example code that works with the latest Python-Ogre version?

Thank you!

andy

26-03-2009 12:15:46

OgreBullet should be fine...

I've just taken another look at bullet and indeed there is a problem -- looks like a rather strange memory corruption issue related (currently) to btCollisionDispatcher and the CollisionConfiguration..

It works with some code and not with others -- I have a work around but need to understand what is really happening before I release a proper fix..

Regards

Andy

Morgg

26-03-2009 12:33:20

Thank you for the response and support. I look forward for the fix.

Regards.

andy

29-03-2009 13:05:38

Fixed the problem -- issue was the default windows build for bullet uses some advanced alignment functionality to maximise performance (basically it expects a number of data structures etc to be 8 or 16 byte aligned).. However when I built the wrapper module I used default alignment which is why the issues were "strange" and clearly all about memory corruption..

I've force the windows build to not use specific alignment(and disabled SSE code as this was also an issue) which makes the build the same as the Linux (and MAC) ones...

Along the way I've update my boost version so am doing a complete rebuild and will issue a new binary update over the next few days..

Andy

andy

04-04-2009 02:26:53

Try the new update and see if this fixes the Bullet issues...

http://www.ogre3d.org/addonforums/viewtopic.php?f=3&t=9376

Andy

Morgg

04-04-2009 13:18:09

Thank you Andy, this update seems to fix it. THe hello world tutorial and the test0x examples are working.