Panda Bullet

Return to Panda Features in Development

Panda Bullet

Postby enn0x » Sun Oct 24, 2010 3:48 pm

Integration of Bullet physics with Panda3D has been requested more than once. I have been working on this for some time now, and here is a PRELIMINARY solution:

http://enn0x.p3dp.com/libpandabullet-r17.zip (2011-04-22)

The .zip file contains the source code, a few samples, and binaries for Windows 32 and Ubuntu 10.10. The binaries are built using Panda3D-1.7.1 and Bullet r2388 (unpatched).

PRELIMINARY:
This is work in progress, and I am still searching for the best way to integrate Bullet with Panda3D. Don't expect the API to be stable yet!

OPEN ISSUES:
- Character controller nudges objects and is nudged by objects.

2011-05-20: We have moved this project to Panda3D's source code. Bullet support will be available starting with version 1.8.0, if there are not fundamental problems. For the latest binaries please download the current development snapshots.

2011-08-26: Most current samples for the Panda3D Bullet module:
http://enn0x.p3dp.com/samples.zip
Last edited by enn0x on Thu Aug 25, 2011 3:33 pm, edited 9 times in total.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Anon » Mon Oct 25, 2010 5:32 am

The dlls are missing.
Anon
 
Posts: 1556
Joined: Thu Oct 29, 2009 3:07 am

Postby enn0x » Mon Oct 25, 2010 5:55 am

What dlls? There are no dlls required, just the pyd.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Anon » Mon Oct 25, 2010 8:39 am

Misread it, I thought the "build" folder was empty because of it.

Anyway... Im gonna study the code now.

From the other thread, I dont know what you mean by Blender not supporting tetrahedra. Although I dont have any Bullet knowledge, but Blender supports softbodies and it uses Bullet for physics.
Anon
 
Posts: 1556
Joined: Thu Oct 29, 2009 3:07 am

Postby enn0x » Mon Oct 25, 2010 1:14 pm

I'm not an expert on Blender too, but from what see I assume that they do it the same way as in the soft body sample provided here: they use Bullet SoftBodyHelper to DERIVE a tetra mesh from a convex hull at RUNTIME.

In Blender this happens behind the scenes. Blender users never see the tetra mesh, and as far as I know there is no way of exporting it. And I don't know any file formats for storing a tetra mesh (besides "proprietary" or "custom" stuff like e.g. PhysX uses).

Sidenote: PhysX has a small application which is also deriving a tetra mesh from an arbitrary triangle mesh, and then saves the tetra mesh to a file (binary or ascii). Then a PhysX game just LOADS the saved file at runtime, which is obviously much faster, and allows better optimization of the tetra mesh.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Anon » Mon Oct 25, 2010 1:37 pm

So... generating one at realtime isnt fast.
The only option I see is make a small application that generates it at realtime from a 3d file, then dumps it to another file.
"egg2bullet" or something.

Though Ive heard about a .bullet format that has expoters for maya and blender. Maybe it supports such thing.
Anon
 
Posts: 1556
Joined: Thu Oct 29, 2009 3:07 am

Postby enn0x » Tue Oct 26, 2010 9:16 am

And how do we link the vertices of the "3D file" (.egg for example) with the vertices of the tetra mesh? Just having the softbody simulation is not enough - People want to see a visual proxy of the softbody, something that get's rendered, a triangle mesh. It's good practice to have a visual mesh at high resolution (looks good) and a tetra mesh at low resolution (fast simulation).

.bullet file format a binary format to serialize different Bullet objects (and ONLY Bullet object). It is quite new, and nowhere stable. I have added code to save/load single Bullet shapes around r4/r5, and by r7 the code has been broken again. No idea why.

Anyway, .bullet is not the right way to go. On the long run we need something independent from any particular physics engine, like .egg or .dae
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Anon » Tue Oct 26, 2010 10:03 am

I dont know. How do they usually do that?

If you think extending egg or dae is the only option, then I guess you will say its best to wait for complete Collada support in Panda. So I guess this is another feature to be added for 2.0
:x I hate waiting...
Anon
 
Posts: 1556
Joined: Thu Oct 29, 2009 3:07 am

Postby rdb » Tue Oct 26, 2010 10:17 am

.dae already supports physics.
rdb
 
Posts: 9418
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby Anon » Tue Oct 26, 2010 10:28 am

You mean Panda's importer too?
Anon
 
Posts: 1556
Joined: Thu Oct 29, 2009 3:07 am

Postby rdb » Tue Oct 26, 2010 10:29 am

Not yet.
rdb
 
Posts: 9418
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby enn0x » Tue Oct 26, 2010 11:50 am

If you think extending egg or dae is the only option, then I guess you will say its best to wait for complete Collada support in Panda.


.dae already supports physics.


COLLADA (.dae) does support some physics, right, but only the very basics. For example soft body, fluid or character controllers are not yet part of COLLADA. I have been reading the COLLADA 1.5 specs more than once during the last weeks.

I have been tossing in .dae because I have been expecting this very discussion. Here is my point of view on .dae:
* pro: .dae is a standard. Ok, a new and emerging standard, but nevertheless a standard.
* contra: .dae covers only basic physics. We want a modern physics engine integrated in Panda3D which supports advanced features like e.g. softbody. Extending COLLADA by us is not possible, and waiting until the Cronos group has added those features to COLLADA (might be years) will take too long.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby enn0x » Tue Oct 26, 2010 12:09 pm

I should add one of the thoughts I have for Panda3D 2.0 & physics. It's about the collision system:

* Every physics engine uses it's own collision system. So the collision system is an integral part of physics, and it is not possible to have a "standard" P3D collision system but different physics engines.

* Panda3D already has a collision system (which is not used by any physics engine except the built-in physics). Lot's of code is written for this collision system, and replacing it by something completely different will break a lot (too much in my opinion, but this is just my opinion).

* .egg files can hold information about collision shapes. The .egg importer create CollisionSolids within the scene graph when loading a .egg file.

* COLLADA importer currently does not create CollisionSolids from COLLADA physics tags, but it COULD be extended to do so.

* Panda3D support for ODE or PhysX currently requires the user to create "collision objects" (and other, like bodies etc.) through code, and not by importing a model (.egg). ODE or PhysX can not make use of loaded CollisionSolids. They just clutter the scene graph if using ODE or PhysX.

How to improve things:

Way A: .egg loader and all other loaders which are able to load collision geometry create, depending on what physics system (built in, ODE, PhysX, ...) is used, collision objects for the physics engine used. Unfortunately ODE and PhysX collision objects are not part of the scene graph...

Way B: .egg loaders and all other loaders which ... always create CollisionSolids, and the physics system used should search for CollisionObjects when creating a new body, and use this information.

I'm in favor of way B, and would like to experiment with this way for the next level of Bullet integration. What is your opinion?
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby rdb » Tue Oct 26, 2010 1:04 pm

Way B does seem superior to way A, because way A would require that the COLLADA loader interfaces with every physics engine supported; or we'd need to have some kind of registering system, which would only complicate things.

If way B could work goodly (I assume this would mean that the Bullet integration uses the existing collision structures), then I'd say go for it.
rdb
 
Posts: 9418
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby enn0x » Tue Oct 26, 2010 2:31 pm

Way B does seem superior to way A, because way A would require that the COLLADA loader interfaces with every physics engine supported; or we'd need to have some kind of registering system, which would only complicate things.

I agree. Not only the COLLADA importer, but also the .egg importer and so on...

The registering system is something I have been pondering too, since it would be a step towards a engine-angostic physics API, but this would mean to remove the current CollisionSolids (and the whole collision system) too. Not my intention.

If way B could work goodly (I assume this would mean that the Bullet integration uses the existing collision structures), then I'd say go for it.

So far the here presented Bullet code has it's own collision objects, which get not loaded by Panda3D's importers. What I am talking about is the next level of Bullet integration. I don't want to give a date for a first release.

A downside of this is that I will have to add new CollisionSolids, e. g. for convex hulls, concave triangle meshes or heightfields. Not every physics/collision system will support every type of CollisionSolid. For example Bullet won't support the inverse sphere. Also we have to be careful about the "modifiers" like e. g. "trigger".

Other downsides are that ODE or PhysX won't automatically benefit from this way. The modules would have to be rewritten too. I'd say not to start on this until the experimental Bullet integration work's well.

Finally, the physics objects (rigid bodies) have to "query" the part of the scene graph below them for CollisionSolids, or state changes of CollisionSolids, since the CollisionSolids don't push such information to these objects.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Anon » Mon Nov 01, 2010 1:22 pm

I should have replied sooner.

I also think B is better in the long run.

I dont see why some physics engines not supporting some collision solids is a problem.

Off topic, have you guys heard about http://www.adrianboeing.com/pal/index.html ?
Anon
 
Posts: 1556
Joined: Thu Oct 29, 2009 3:07 am

Postby rdb » Mon Nov 01, 2010 2:09 pm

Yeah, we have.
rdb
 
Posts: 9418
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby enn0x » Tue Nov 02, 2010 6:42 pm

I have a look at the PAL source code quite often. It's a great library from a technical point of view, but not what Panda3D needs. At least in my opinion.

Anyway, thank you very much for pointing us to this library, Anon.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Sothh » Fri Nov 12, 2010 4:02 pm

How do I set my model to the position and rotation of the physical sim?

Some doctumentation would be great!
Sothh
 
Posts: 235
Joined: Sat Oct 24, 2009 10:33 am
Location: Virginia, USA

Postby enn0x » Fri Nov 12, 2010 4:44 pm

How do I set my model to the position and rotation of the physical sim?

You don't have to set it yourself. The BulletMotionNode instances do it for you. Simply reparent your (visual) model below a BulletMotionNode.

Have a look at the sample "01_basics.py". The movable box has a model which moves with the physical body.

Some doctumentation would be great!

I agree.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Sothh » Sat Nov 13, 2010 10:55 am

The problem is, if I reparent the model, I can't get its position and rotation for Panda uses.

How can I set the rotation of a physics body? I would like to make ramps and such.

I could help with some documentation, I have been looking over the C++ source, so I understand a bit of whats going on.
Sothh
 
Posts: 235
Joined: Sat Oct 24, 2009 10:33 am
Location: Virginia, USA

Postby enn0x » Sat Nov 13, 2010 2:09 pm

How can I set the rotation of a physics body? I would like to make ramps and such.

The same way you would do it with any PandaNode: using setHpr, setMat or setQuat on the NodePath, or setting the thransform state on the node itself. Please note that only translation and orientation are supported, not shear or scale. This is a common limitation of all physics engine.

The problem is, if I reparent the model, I can't get its position and rotation for Panda uses.

I don't understand you here. Can you please elaborate a bit more?

I could help with some documentation, I have been looking over the C++ source, so I understand a bit of whats going on.

Any help is certainly appreciated.

But I don't want you to get frustrated after some time. This is still work in progress, and the API will change; for example the next release won't have BulletMotionNode any longer (I want to make RigidBody a PandaNode), or the collision filtering will change (I want to make use of Panda3D's from/into masks, if possible).

Currently I think the best way people could help is by playing around, asking questions, and making suggestions about what could be done differently.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Sothh » Sun Nov 14, 2010 11:14 am

In the following code, if I try to rotate the np node, the visual model rotates, but the physics block does not.

Code: Select all
#Load a model:
        self.model = main.loader.loadModel("models/block.egg")

        self.tex = loader.loadTexture('gfx/'+str(Type)+'.jpg')
        self.model.setTexture(self.tex)


        #Reparent the model to render:
        self.model.reparentTo(render)

        #Physics:
        self.node = BulletMotionNode('box')
        self.node.setTransform(TransformState.makePos((x,y,z)))

        self.shape = BulletBoxShape(.4)

        self.body = BulletRigidBody(0,self.node,self.shape)
        physics.world.addRigidBody(self.body)

        self.np = render.attachNewNode(self.node)
        self.np.setHpr(h,p,r)
        self.model.reparentTo(self.np)


Another problem, I am trying to set the cameras X and Z to match that of a player model. (This is for a platformer.) I am using this code
Code: Select all
main.camera.setX(player.np.getX()
)

It works, but is very jittery. If I reparent the camera to the players np node, its smooth, but the camera rotates with the player (a rolling ball), so that is no good.

When do you think the next release will come out?

Thanks,

Sothh[/code]
Sothh
 
Posts: 235
Joined: Sat Oct 24, 2009 10:33 am
Location: Virginia, USA

Postby Sothh » Sun Nov 14, 2010 11:30 am

In the following code, if I try to rotate the np node, the visual model rotates, but the physics block does not.

Code: Select all
#Load a model:
        self.model = main.loader.loadModel("models/block.egg")

        self.tex = loader.loadTexture('gfx/'+str(Type)+'.jpg')
        self.model.setTexture(self.tex)


        #Reparent the model to render:
        self.model.reparentTo(render)

        #Physics:
        self.node = BulletMotionNode('box')
        self.node.setTransform(TransformState.makePos((x,y,z)))

        self.shape = BulletBoxShape(.4)

        self.body = BulletRigidBody(0,self.node,self.shape)
        physics.world.addRigidBody(self.body)

        self.np = render.attachNewNode(self.node)
        self.np.setHpr(h,p,r)
        self.model.reparentTo(self.np)


Another problem, I am trying to set the cameras X and Z to match that of a player model. (This is for a platformer.) I am using this code
Code: Select all
main.camera.setX(player.np.getX()
)

It works, but is very jittery. If I reparent the camera to the players np node, its smooth, but the camera rotates with the player (a rolling ball), so that is no good.

When do you think the next release will come out?

Thanks,

Sothh[/code]
Sothh
 
Posts: 235
Joined: Sat Oct 24, 2009 10:33 am
Location: Virginia, USA

Postby enn0x » Sun Nov 14, 2010 1:57 pm

I have been wrong. Setting pos and hpr on the motion node doesn't work, because I left away the PandaNode hooks. This is one reason why I want to make BulletRigidBody a PandaNode and remove BulletMotionNode.

So far you can change the body's position by using BulletRigidBody.translate(...). A method for changing the orientation is missing so far. I have added BulletRigidBody.setHrp(h, p, r) in the following release (no other changes, but using current Bullet version r2233):

http://enn0x.p3dp.com/libpandabullet-r9.zip
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Sothh » Sun Nov 14, 2010 2:36 pm

I thought that must be the case, since it was missing from the source code.

So it should work now? Thanks!
Sothh
 
Posts: 235
Joined: Sat Oct 24, 2009 10:33 am
Location: Virginia, USA

Postby Sothh » Mon Nov 15, 2010 2:31 pm

Okay, when I used body.setHpr, the visual model does not change its rotation, but the physics object rotates and seems to move to the position (0,0,0) which is a big problem.

Here is the code I tried:

Code: Select all
class Block():

    def __init__(self,Type,x,y,z,h,p,r):

        #Load a model:
        self.model = main.loader.loadModel("models/block.egg")

        self.tex = loader.loadTexture('gfx/'+str(Type)+'.jpg')
        self.model.setTexture(self.tex)

        #Reparent the model to render:
        self.model.reparentTo(render)

        #Physics:
        self.node = BulletMotionNode('box')
        self.node.setTransform(TransformState.makePos((x,y,z)))

        self.shape = BulletBoxShape(.4)

        self.body = BulletRigidBody(0,self.node,self.shape)
        physics.world.addRigidBody(self.body)


        self.np = render.attachNewNode(self.node)
        self.body.setHpr(0,0,0)
        self.model.reparentTo(self.np)
Sothh
 
Posts: 235
Joined: Sat Oct 24, 2009 10:33 am
Location: Virginia, USA

Postby enn0x » Mon Nov 15, 2010 3:37 pm

Yep, this is the problem with quickshots. Ok, I fixed it; The method setHpr is removed again, and replaces by setTransform(TransformState xform). For example:
Code: Select all
xform = TransformState.makePosHpr(Point3(0, 0, -5), Vec3(0, 0, 30))
body.setTransform(xform)


I updated libpandabullet-r9.zip, so the above download link can be used again.

Just for the record: your original problem can be solved by setting hpr BEFORE creating the body. Changing the position of a body AFTER creation is possible now, but it should be used with care. Sudden "explosions" might occur if objects penetrate each other after the change of transform.
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Sothh » Fri Nov 19, 2010 5:23 pm

I sent a game I made using this module to a friend, whom is running Panda 1.7.0, and he gets this error when he tries running the program:

Code: Select all
Traceback (most recent call last):
  File "C:\Users\Exotath\Desktop\Blox\Blox.py", line 26, in <module>
    from libpandabullet import *
ImportError: DLL load failed: The specified procedure could not be found.
Sothh
 
Posts: 235
Joined: Sat Oct 24, 2009 10:33 am
Location: Virginia, USA

Postby enn0x » Fri Nov 19, 2010 6:01 pm

Your friend is missing this module, since it can't be found. Forgot to pack libpandabullet.pyd, or maybe placed it in the wrong folder, or something like this...
enn0x
 
Posts: 1370
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Next

Return to Panda Features in Development

Who is online

Users browsing this forum: No registered users and 0 guests