I think that listening for group collisions is broken when using native bullet (using JME 3.1 alpha 2). Here’s a test case:
/*
* Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package test;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.PhysicsCollisionGroupListener;
import com.jme3.bullet.collision.PhysicsCollisionObject;
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import java.util.logging.Logger;
/**
*
* @author normenhansen
*/
public class TestCollisionGroups extends SimpleApplication implements PhysicsCollisionGroupListener{
private BulletAppState bulletAppState;
public static void main(String[] args) {
TestCollisionGroups app = new TestCollisionGroups();
app.start();
}
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(50);
Material debugMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
//debugMaterial.getAdditionalRenderState().setWireframe(true);
debugMaterial.setColor("Color", ColorRGBA.Brown);
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.setDebugEnabled(true);
bulletAppState.getPhysicsSpace().addCollisionGroupListener(this, PhysicsCollisionObject.COLLISION_GROUP_02);
// Add a physics sphere to the world
RigidBodyControl physicsSpherePhysics = new RigidBodyControl(new SphereCollisionShape(1), 1);
Geometry physicsSphere = new Geometry("Sphere", new Sphere(16, 16, 1));
physicsSphere.setMaterial(debugMaterial);
physicsSpherePhysics.setPhysicsLocation(new Vector3f(3, 6, 0));
physicsSphere.addControl(physicsSpherePhysics);
rootNode.attachChild(physicsSphere);
getPhysicsSpace().add(physicsSphere);
// Add a physics sphere to the world
RigidBodyControl physicsSpherePhysics2 = new RigidBodyControl(new SphereCollisionShape(1), 1);
Geometry physicsSphere2 = new Geometry("Sphere2", new Sphere(16, 16, 1));
physicsSphere2.setMaterial(debugMaterial);
physicsSphere2.addControl(physicsSpherePhysics2);
physicsSpherePhysics2.setPhysicsLocation(new Vector3f(4, 8, 0));
physicsSpherePhysics2.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
physicsSpherePhysics2.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_02);
rootNode.attachChild(physicsSphere2);
getPhysicsSpace().add(physicsSphere2);
// an obstacle mesh, does not move (mass=0)
RigidBodyControl node2Physics = new RigidBodyControl(new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
Geometry node2 = new Geometry("Sphere (collision group)", new Sphere(16, 16, 1.2f));
node2.setMaterial(debugMaterial);
node2.addControl(node2Physics);
node2Physics.setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
//node2Physics.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_01);
//node2Physics.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_01);
node2Physics.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
node2Physics.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_02);
rootNode.attachChild(node2);
getPhysicsSpace().add(node2);
// the floor, does not move (mass=0)
RigidBodyControl node3Physics = new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 100f, 0.2f, 100f)), 0);
Geometry node3 = new Geometry("Box", new Box(Vector3f.ZERO, 100f, 0.2f, 100f));
node3.setMaterial(debugMaterial);
node3.addControl(node3Physics);
node3Physics.setPhysicsLocation(new Vector3f(0f, -6, 0f));
rootNode.attachChild(node3);
getPhysicsSpace().add(node3);
}
private PhysicsSpace getPhysicsSpace() {
return bulletAppState.getPhysicsSpace();
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
@Override
public boolean collide(PhysicsCollisionObject nodeA, PhysicsCollisionObject nodeB){
//System.out.println("Collision");
Logger.getLogger(TestCollisionGroups.class.getName()).info("Collision");
return true;
}
}
In the test case, the two spheres that are in collision group 2 collide, which proves that group collisions work. Their should have also been a log of the collision printed in the console, but nothing is printed. This leads me to think that the group listener is broken. Can anyone confirm this behavior, or am I just missing something silly.