Afternoon all,
I've come across some quirky behaviour using the MESH collision shape in jbullet-jme.
I'll start by describing the scenario, it's a simple game and a Spatial is loaded from a url to an XML file.
Spatial groundMesh = XmlModelLoader.loadModel( MeshFile.Ground.url );
That all works fine - it's standard JME stuff, next to create the physics bounds
CompoundCollisionShape composite = new CompoundCollisionShape();
composite.addChildShape( new MeshCollisionShape( (TriMesh) groundMesh ), new Vector3f( 0f, 0f, 0f ) );
PhysicsNode ground = new PhysicsNode( groundMesh, composite, 0f );
Creating a compound shape consisting of only a MeshCollisionShape works fine.
...However, when the physics node creation is done with the following line instead:
PhysicsNode ground = new PhysicsNode( groundMesh, CollisionShape.ShapeTypes.MESH, 0f );
or
PhysicsNode ground = new PhysicsNode( groundMesh, new MeshCollisionShape( (TriMesh) groundMesh ), 0f );
Despite the lines being semantically similar to the composite shape (chiefly, creating a mesh collision shape from the TriMesh) there is this problem when assertions are turned on:
SEVERE: Main game loop broken by uncaught exception
java.lang.AssertionError
at com.bulletphysics.collision.shapes.TriangleMeshShape.calculateLocalInertia(TriangleMeshShape.java:140)
at com.jmex.jbullet.collision.shapes.CollisionShape.calculateLocalInertia(CollisionShape.java:58)
at com.jmex.jbullet.nodes.PhysicsNode.preRebuild(PhysicsNode.java:232)
at com.jmex.jbullet.nodes.PhysicsNode.rebuildRigidBody(PhysicsNode.java:220)
at com.jmex.jbullet.nodes.PhysicsNode.createCollisionShape(PhysicsNode.java:746)
at com.jmex.jbullet.nodes.PhysicsNode.<init>(PhysicsNode.java:139)
Cause in jBullet, TriangleMeshShape line 140
@Override
public void calculateLocalInertia(float mass, Vector3f inertia) {
// moving concave objects not supported
assert (false);
inertia.set(0f, 0f, 0f);
}
Invoking method from jbullet-jme
public void calculateLocalInertia(float mass, javax.vecmath.Vector3f vector){
if(cShape==null) return;
cShape.calculateLocalInertia(mass, vector);
}
This is all fine, it looks like a precaution in jbullet to prevent the problem of having to apply forces to mesh shapes, which is understandable, as frankley they could look like anything