Panda Bullet

Hmmm, I should give a more concrete answer:

I usually don’t plan ahead very far. Implement something, see how it works, and then think about the next steps. So there is no 5 year plan. For the next few months I don’t plan to add any new “big” features, like particle fluids. I want to review the current state, maybe redesign here and there, fix bugs, and most important write documentation (both source and manual). My goal is to make libpandabullet more usable. Maybe add smaller things like setting up CCD properly and adding samples.

took a stab at building libpandabullet-r17 on Mac (OSX 10.6)
Modifications to wscript are indeed pretty straightforward, however i’m getting a lot of these when it comes to compiling:

In file included from ../src/bullet_composite.cxx:13:
../src/bulletConvexHullShape.cxx: In member function ‘void BulletConvexHullShape::add_array(const PTA_LVecBase3f&)’:
../src/bulletConvexHullShape.cxx:69: error: ambiguous overload for ‘operator[]’ in ‘points[i]’
../src/bulletConvexHullShape.cxx:69: note: candidates are: operator[](LVecBase3f*, long int) <built-in>
/Developer/Panda3D/include/pointerToArray.I:387: note:                 typename PointerToArray<Element>::reference PointerToArray<Element>::operator[](typename pvector<Element>::size_type) const [with Element = LVecBase3f]
/Developer/Panda3D/include/pointerToArray.I:405: note:                 typename PointerToArray<Element>::reference PointerToArray<Element>::operator[](int) const [with Element = LVecBase3f]

suspecting that perhaps this has something to do with compiler versions… maybe there’s a flag that is missing. I’m using g++ 4.2.1 (Do you recall which compiler you used to build on Linux?)
Will spend more time this weekend and post again, if i can sort it out.

Hmmm, can you please provide the comand line you used for compiling. You can see it if running waf with “-v” (verbose).

I think the gcc version is 4.4.4, but I have to check first (away for the weekend).

Here’s the command according to waf:

Build failed
 -> task failed (exit status 1): 
	{task 6401872: cxx bullet_composite.cxx -> bullet_composite.cxx.2.o}
['/usr/bin/g++', '-arch', 'i386', '-I/usr/include/python2.6', '-I/Developer/Panda3D/include', '-I/usr/local/include/bullet', '-I/Users/antonj/Downloads/libpandabullet-r17/built/src', '-I/Users/antonj/Downloads/libpandabullet-r17/src', '-DPYTHONDIR="/usr/local/lib/python2.6/site-packages"', '-DPYTHONARCHDIR="[\'/usr/local/lib/python2.6/site-packages\']"', '-DOSX', '-DHAVE_PYTHON', '-DBUILDING_PANDABULLET', '-DFORCE_INLINING', '../src/bullet_composite.cxx', '-c', '-o', 'src/bullet_composite.cxx.2.o']

Looking at makepanda.py I think the following flags could be missing:
-ftemplate-depth-30
-fPIC
-Wno-deprecated-declarations
-isysroot /Developer/SDKs/MacOSX10.6u.sdk
-mmacosx-version-min=10.6
But this is just a wild guess. To make sure we should compare with a command line created while building Panda3D from source code on OSX, e. g. using makepanda (again with verbose: --verbose). Maybe rdb can provide a logfile from a recent OSX build.

Sure thing, here you go:
panda3d.org:8010/builders/releas … stdio/text

As for the error; in that file, this line:

for (unsigned int i=0; i < points.size(); i++) {

should probably be at least:

for (size_t i = 0; i < points.size(); ++i) {

(More ideally, you should probably use an iterator.)

Yep, already replaced the loop using the const iterator. I wonder why I did it this way. In other place, e. g. the BulletConvexPointCloudShape, I have been using the iterator from begining.

  PTA_LVecBase3f::const_iterator it;
  for (it=points.begin(); it!=points.end(); it++) {
    LVecBase3f v = *it;
    _shape->addPoint(LVecBase3f_to_btVector3(v));
  }

The problem with OSX and that I’ve had in linux seem to be related to 32bit vs 64bit issues.

I’ve had to change from unsigned int to size_t in several places in the source. I’ve also had to add -fPIC to the waf script when building on 64bit systems.

I’m still trying to fight a missing symbol issue now, as soon as I get it fully working, I’ll clean up my changes and make sure all’s right on 32bit still, and then I’ll post them here.

Actually, I decided to include the patch below, since it’s not that large.

I’m still struggling with a missing symbol when building, but I’ll get it sorted eventually.

diff -r -u libpandabullet-r17-orig/src/bulletConvexHullShape.cxx libpandabullet-r17/src/bulletConvexHullShape.cxx                                                                                             
--- libpandabullet-r17-orig/src/bulletConvexHullShape.cxx       2011-05-05 19:23:07.719358999 -0500
+++ libpandabullet-r17/src/bulletConvexHullShape.cxx    2011-05-03 21:47:59.079358998 -0500
@@ -65,8 +65,10 @@
   _shape = new btConvexHullShape(NULL, 0);
   _shape->setUserPointer(this);
 
-  for (unsigned int i=0; i < points.size(); i++) {
-    _shape->addPoint(LVecBase3f_to_btVector3(points[i]));
+  PTA_LVecBase3f::const_iterator it; 
+  for (it=points.begin(); it!=points.end(); it++) { 
+    LVecBase3f v = *it; 
+    _shape->addPoint(LVecBase3f_to_btVector3(v)); 
   }
 }
 
diff -r -u libpandabullet-r17-orig/src/bulletSoftBodyNode.cxx libpandabullet-r17/src/bulletSoftBodyNode.cxx                                                                                                   
--- libpandabullet-r17-orig/src/bulletSoftBodyNode.cxx  2011-05-05 19:23:07.729358999 -0500
+++ libpandabullet-r17/src/bulletSoftBodyNode.cxx       2011-05-03 21:57:20.389359003 -0500
@@ -694,7 +694,7 @@
 
   float eps = 1.0e-6f; // TODO make this a config option
 
-  for (unsigned int i=0; i<points.size(); i++) {
+  for (size_t i=0; i<points.size(); i++) {
     if (points[i].almost_equal(p, eps)) {
       return i; // Found
     }
@@ -804,7 +804,7 @@
 
   pmap<int, int> mapping;
 
-  for (unsigned int i=0; i<points.size(); i++) {
+  for (size_t i=0; i<points.size(); i++) {
     LVecBase3f p = points[i];
     int j = get_point_index(p, mapped_points);
     if (j < 0) {
@@ -816,7 +816,7 @@
     }
   }
 
-  for (unsigned int i=0; i<indices.size(); i++) {
+  for (size_t i=0; i<indices.size(); i++) {
     int idx = indices[i];
     int mapped_idx = mapping[idx];
     mapped_indices.push_back(mapped_idx);
@@ -830,14 +830,14 @@
   unsigned int num_triangles = indices.size() / 3;
 
   btScalar *vertices = new btScalar[num_vertices * 3];
-  for (unsigned int i=0; i < num_vertices; i++) {
+  for (size_t i=0; i < num_vertices; i++) {
     vertices[3*i]   = points[i].get_x();
     vertices[3*i+1] = points[i].get_y();
     vertices[3*i+2] = points[i].get_z();
   }
 
   int *triangles = new int[num_triangles * 3];
-  for (unsigned int i=0; i < num_triangles * 3; i++) {
+  for (size_t i=0; i < num_triangles * 3; i++) {
     triangles[i] = indices[i];
   }
 
@@ -914,7 +914,7 @@
   // Points
   btAlignedObjectArray<btVector3> pos;
   pos.resize(points.size());
-  for (unsigned int i=0; i<points.size(); i++) {
+  for (size_t i=0; i<points.size(); i++) {
     LVecBase3f point = points[i];
     pos[i] = LVecBase3f_to_btVector3(point);
   }
@@ -923,7 +923,7 @@
   btSoftBody* body = new btSoftBody(&info.get_info(), pos.size(), &pos[0], 0);
 
   // Indices
-  for (unsigned int i=0; i<indices.size() / 4; i++) {
+  for (size_t i=0; i<indices.size() / 4; i++) {
     int ni[4];
 
     ni[0] = indices[4*i];
diff -r -u libpandabullet-r17-orig/src/bulletTriangleMesh.cxx libpandabullet-r17/src/bulletTriangleMesh.cxx                                                                                                   
--- libpandabullet-r17-orig/src/bulletTriangleMesh.cxx  2011-05-05 19:23:07.729358999 -0500
+++ libpandabullet-r17/src/bulletTriangleMesh.cxx       2011-05-03 21:58:00.269358999 -0500
@@ -166,7 +166,7 @@
   }
 
   // Add triangles
-  unsigned int j = 0;
+  size_t j = 0;
   while (j+2 < indices.size()) {
 
     btVector3 v0 = vertices[indices[j++]];

Hello,
is there a way to disable gravity on a per-body basis? Currently BulletRigidBodyNode has no setGravity() method.

Not yet, but I have added support for this in the next release. You can get a preview here: http://enn0x.p3dp.com/libpandabullet-r18.zip

To disable gravity you have to call body.setGravity(Vec3(0,0,0)) AFTER you have added the body to the world.

New release (r18). The most important thing - besides a few minor changes - is probably that juce managed to compile libpandabullet on OSX (using Python 2.5 and 32bit). OSX support is still experimental. Many thanks to juce and morgul for attempting again and again to compile libpandabullet.

http://enn0x.p3dp.com/libpandabullet-r18.zip (Binaries are only contained for Windows/32bit and Linux/32bit)

New in libpandabullet-r18:

  • Using Bullet-r2395
  • Using Panda3D-1.7.2
  • New sample for continuous collision detection (CCD).
  • New config option bullet-solver-iterations.
  • Added setGravity & getGravity on BulletRigidBody
  • Buildscript has now a section for OSX

Hey,

My best friend recently downloaded r18, and is getting a strange error when trying to run one of the examples:

Traceback (most recent call last):
File "C:\Users\Exotath\Desktop\libpandabullet-r18\test\09_Character.py", line 23, in <module>
from panda3d.bullet import BulletWorld
File "C:\Panda3D-1.7.0\direct\ffi\panda3d.py", line 145, in _getattr_
mod = self.__manager__.libimport(self.__library__)
File "C:\Panda3D-1.7.0\direct\ffi\panda3d.py", line 126, in libimport
return cls.imp.load_dynamic(name, target)
ImportError: DLL load failed: The specified procedure could not be found.

Any ideas?

What Windows version is he using, is it 32bit or 64bit, and what Panda3D version is installed?

He is using 64bit, and 1.7.1 I think. He has the setup I have.

Looks like he’s using 1.7.0. It’s probably wise to upgrade to 1.7.2. We didn’t have ABI compatibility in 1.7.0, that was introduced in 1.7.1.

I am having a problem creating a collision shape from a simple mesh.

I am doing it like this:

self.geom = self.model.findAllMatches('**/+GeomNode').getPath(0).node().getGeom(0)
        self.mesh = BulletTriangleMesh()
        self.mesh.addGeom(self.geom)
        self.shape = BulletTriangleMeshShape(self.mesh,dynamic=True)

While the shape is correct, it is rotated on its side. (Y up)

How can I fix this?

I guess this is due to RigidBodyNode being attached to the wrong NodePath. When Panda loads a model, it creates a root NodePath, so the model returned by loader always has identity transform. If you then attach the model to your rigidbody’s nodepath, in general case your visible geometry would not match collision geometry.

Perhaps you need to do something like that:

VisibleGeometryNodePath = self.model.findAllMatches('**/+GeomNode').getPath(0)
self.geom = VisibleGeometryNodePath.node().getGeom(0)
self.mesh = BulletTriangleMesh()
self.mesh.addGeom(self.geom)
self.shape = BulletTriangleMeshShape(self.mesh,dynamic=True)
self.node = BulletRigidBodyNode("some name")
self.node.addShape(self.shape)
CollisionGeometryNodePath = render.attachNewNode(self.node)
VisibleGeometryNodePath.reparentTo(CollisionGeometryNodePath)

Is it possible that the GeomNode has a transform relative to self.model?

for geomNP in modelNP.findAllMatches('**/+GeomNode'):
  geomNode = geomNP.node()
  ts = geomNode.getTransform()

What you can do is to apply the same transform when adding the shape to the rigid body

ts = ... # the TransformState from above
body.addShape(shape, ts)