python wrapping of bullet (using ctypes)

Post Reply
pyalot
Posts: 5
Joined: Wed Sep 02, 2009 9:12 am

python wrapping of bullet (using ctypes)

Post by pyalot »

Archwyrm
Posts: 2
Joined: Fri Sep 04, 2009 8:10 am

Re: python wrapping of bullet (using ctypes)

Post by Archwyrm »

Wow, quite nice! I'll have to give this a try. :)
pyalot
Posts: 5
Joined: Wed Sep 02, 2009 9:12 am

more examples and functionality

Post by pyalot »

If you want to run the examples you will need pyglet: http://pyglet.org or http://hg.codeflow.org/pyglet and gletools, http://hg.codeflow.org/gletools
There's currently only support for Linux and the checked in pre-build is against x86 (not x86-64), though you can compile it for x86-64, see the README

N-Body gravity example: http://hg.codeflow.org/ctypes_bullet/fi ... gravity.py
Mesh collision: http://hg.codeflow.org/ctypes_bullet/fi ... ollison.py
User Interaction: http://hg.codeflow.org/ctypes_bullet/fi ... r_force.py and http://hg.codeflow.org/ctypes_bullet/fi ... impulse.py
Simplified hello world: http://hg.codeflow.org/ctypes_bullet/fi ... loworld.py
pyalot
Posts: 5
Joined: Wed Sep 02, 2009 9:12 am

Re: python wrapping of bullet (using ctypes)

Post by pyalot »

Just added osx x86 build
scaron
Posts: 2
Joined: Fri May 29, 2009 1:08 am

Re: python wrapping of bullet (using ctypes)

Post by scaron »

has anyone got this working in windows?
kirchou
Posts: 1
Joined: Sat Jun 19, 2010 6:18 am

Re: python wrapping of bullet (using ctypes)

Post by kirchou »

Yes!
I've done a quick (and dirty) windows port today, examples are working well.

Now I can start coding bullet apps with the power of python, for 64 bits linux and 32 bits windows.
The association of bullet and python seems to be more than the sum of the two :wink:

It's easy to do:
- compile bullet with visual studio 2008 as statics libs
- recompile le python wrapper as a win32 dll, exporting all the fonctions with __declspec(dllexport)
- modify the __init__.py wrapper to use the dll instead of the linux .so

I can post some files if anybody is interested.
But for the moment, I haven't made yet a clean, multiplatform installer.
pekuja
Posts: 2
Joined: Mon Jul 05, 2010 5:13 am

Re: python wrapping of bullet (using ctypes)

Post by pekuja »

I was looking for good Python bindings for Bullet, and while this wrapper seems fine albeit incomplete, what I would really like to do is to use the Bullet C-API and ctypes to create bindings that didn't require any compiled middle layer. Does anyone know if the C-API is mature enough that this could work?
pekuja
Posts: 2
Joined: Mon Jul 05, 2010 5:13 am

Re: python wrapping of bullet (using ctypes)

Post by pekuja »

Ok, so I decided to take the plunge and attempt to make Python bindings for the Bullet C-API. I believe I did succeed. I tried to get the BulletDino example ported to Python, which I did, but all I'm seeing is a blank screen so something is still wrong. I don't know if it's the Bullet bindings or the graphics rendering. I will be doing some more tests on the bindings to see if they actually work.

Now, after doing this, and looking back at pyalot's bindings, I can see that his approach is much more elegant than mine, which is basically to do a 1:1 wrapper for the C-API. And of course I still need an extra layer of C code to make a shared library since Bullet doesn't compile to a shared library by default. Maybe that's a fixable problem, but I definitely do like pyalot's design for the bindings much better than the direct C-API wrapper.

I think what I'll do is I'll do some experiments with my C-API wrapper and maybe see if I can make a patch for Bullet to compile the C-API into a shared library, but I think I will move my focus to improving pyalot's bindings. Now that I've twiddled with ctypes myself, I feel like I actually understand how pyalot's bindings work. :-)
spooky_paul
Posts: 3
Joined: Tue Mar 24, 2009 11:53 pm

Re: python wrapping of bullet (using ctypes)

Post by spooky_paul »

I have build the wrapper on windows x86 but when I try to test it (the hello world example) it throws an attribute error (With Matrix: AttributeError: __exit__) on line 52.

How can i fix it?

Thank you
holofermes
Posts: 1
Joined: Tue Jul 26, 2011 5:05 pm

Re: python wrapping of bullet (using ctypes)

Post by holofermes »

Hi!
I successfully got it working for windows 32, however it doesn't *fully* work on 64. I run the helloworld.py and this is what I get when it's running the add_box_body

# Error: exception: access violation reading 0x000007FE3945C000
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "<maya console>", line 5, in add_box
# File "C:\Python26\Lib\site-packages\bullet-0.1.0-py2.6.egg\bullet\__init__.py", line 225, in add_box_body
# return self.add_body(x, y, z, shape, mass)
# File "C:\Python26\Lib\site-packages\bullet-0.1.0-py2.6.egg\bullet\__init__.py", line 204, in add_body
# motion_state = MotionState(transform)
# File "C:\Python26\Lib\site-packages\bullet-0.1.0-py2.6.egg\bullet\__init__.py", line 303, in __init__
# BulletObject.__init__(self, transform.handle)
# File "C:\Python26\Lib\site-packages\bullet-0.1.0-py2.6.egg\bullet\__init__.py", line 13, in __init__
# self.handle = self.new(*args)
# WindowsError: exception: access violation reading 0x000007FE3945C000 #
# Exception AttributeError: "'MotionState' object has no attribute 'handle'" in <bound method MotionState.__del__ of <bullet.MotionState object at 0x0000000039493828>> ignored

So, I'm able to add the first object to the world, but no more after it.

Also, it fails when I simply do this:

import bullet as bullet
bullet.BulletObject()

# Error: 'BulletObject' object has no attribute 'new'
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# File "C:\Python26\Lib\site-packages\bullet-0.1.0-py2.6.egg\bullet\__init__.py", line 13, in __init__
# self.handle = self.new(*args)
# AttributeError: 'BulletObject' object has no attribute 'new' #
# Exception AttributeError: "'BulletObject' object has no attribute 'delete'" in <bound method BulletObject.__del__ of <bullet.BulletObject object at 0x00000000394936A0>> ignored

And I only have this problem under windows 64.

Any help, or suggestions would be appreciated.
Thanks..!.
Post Reply