Hey, i found a big problem with mesh collision shapes. I think it’s a bug…When i run my test code the following exception is threw :
[java]java.lang.NullPointerException
at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:119)
at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)
at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)
at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)
at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)
at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.cleanOverlappingPair(HashedOverlappingPairCache.java:219)
at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache$CleanPairCallback.processOverlap(HashedOverlappingPairCache.java:447)
at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.processAllOverlappingPairs(HashedOverlappingPairCache.java:190)
at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.cleanProxyFromPairs(HashedOverlappingPairCache.java:207)
at com.bulletphysics.collision.dispatch.CollisionWorld.removeCollisionObject(CollisionWorld.java:172)
at com.bulletphysics.dynamics.DiscreteDynamicsWorld.removeRigidBody(DiscreteDynamicsWorld.java:423)
at com.jme3.bullet.PhysicsSpace.removeNode(PhysicsSpace.java:608)
at com.jme3.bullet.PhysicsSpace.removeAll(PhysicsSpace.java:549)
at com.jme3.bullet.PhysicsSpace.removeAll(PhysicsSpace.java:573)
at mygame.test.OgreSceneTest.onAnalog(OgreSceneTest.java:122)
at com.jme3.input.InputManager.invokeAnalogs(InputManager.java:215)
at com.jme3.input.InputManager.invokeUpdateActions(InputManager.java:188)
at com.jme3.input.InputManager.update(InputManager.java:481)
at com.jme3.app.Application.update(Application.java:448)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:194)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:141)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)
at java.lang.Thread.run(Thread.java:662)[/java]
Then when i change the mesh collision shapes to other basics shapes it works fine.
It’s so difficult to explain, then is better you get the following test code and run in your machine :
[java]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package mygame.test;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CompoundCollisionShape;
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
import com.jme3.bullet.nodes.PhysicsNode;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
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.debug.Grid;
import com.jme3.scene.shape.Box;
/**
*
-
@author Glauco
*/
public class OgreSceneTest extends SimpleApplication implements
AnalogListener {
/**
-
@param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
OgreSceneTest test = new OgreSceneTest();
test.setShowSettings(false);
test.start();
}
@Override
public void simpleInitApp() {
//set the app’s title to “PhysicsEditor”
context.setTitle(“PhysicsEditor”);
//set the background color to gray
viewPort.setBackgroundColor(ColorRGBA.Gray);
//do the app to use physics
stateManager.attach(new BulletAppState());
//increase the camera’s move speed
flyCam.setMoveSpeed(100);
//remove all app’s view informations
guiNode.detachAllChildren();
//attach a green grid 9x9 to the root node
Grid grid = new Grid(18, 18, 1);
Geometry gridgeo = new Geometry(“grid”, grid);
Material mt = new Material(assetManager, “Common/MatDefs/Misc/WireColor.j3md”);
mt.setColor(“m_Color”, ColorRGBA.Green);
gridgeo.setMaterial(mt);
gridgeo.center();
rootNode.attachChild(gridgeo);
//configure the cam’s position and rotation
cam.getLocation().addLocal(0, 2, 0);
cam.lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 1, 0));
Box box = new Box(1, 1, 1);
Geometry geo = new Geometry(“geo”, box);
geo.setMaterial(mt);
Box box2 = new Box(1, 1, 1);
Geometry geo2 = new Geometry(“geo”, box);
geo2.setMaterial(mt);
Box box3 = new Box(1, 1, 1);
Geometry geo3 = new Geometry(“geo”, box);
geo3.setMaterial(mt);
CompoundCollisionShape c1 = new CompoundCollisionShape();
//c1.addChildShape(new MeshCollisionShape(geo.getMesh()), Vector3f.ZERO.clone());
c1.addChildShape(new BoxCollisionShape(Vector3f.UNIT_XYZ), Vector3f.ZERO.clone());
CompoundCollisionShape c2 = new CompoundCollisionShape();
//c2.addChildShape(new MeshCollisionShape(geo2.getMesh()), Vector3f.ZERO.clone());
c2.addChildShape(new BoxCollisionShape(Vector3f.UNIT_XYZ), Vector3f.ZERO.clone());
CompoundCollisionShape c3 = new CompoundCollisionShape();
//c3.addChildShape(new MeshCollisionShape(geo3.getMesh()), Vector3f.ZERO.clone());
c3.addChildShape(new BoxCollisionShape(Vector3f.UNIT_XYZ), Vector3f.ZERO.clone());
PhysicsNode phynode = new PhysicsNode(geo, c1, 1);
PhysicsNode phynode2 = new PhysicsNode(geo2, c2, 1);
PhysicsNode phynode3 = new PhysicsNode(geo3, c3, 1);
phynode.attachDebugShape(assetManager);
phynode2.attachDebugShape(assetManager);
phynode3.attachDebugShape(assetManager);
phynode.updateGeometricState();
phynode2.updateGeometricState();
phynode3.updateGeometricState();
rootNode.attachChild(phynode);
rootNode.updateGeometricState();
rootNode.attachChild(phynode2);
rootNode.updateGeometricState();
rootNode.attachChild(phynode3);
rootNode.updateGeometricState();
inputManager.addMapping(“start”, new KeyTrigger(keyInput.KEY_SPACE));
inputManager.addMapping(“pause”, new KeyTrigger(keyInput.KEY_RSHIFT));
inputManager.addListener(this, “start”, “pause”);
}
@Override
public void simpleRender(RenderManager rm) {
}
@Override
public void simpleUpdate(float tpf) {
}
public void onAnalog(String name, float value, float tpf) {
if (name.equals(“start”)) {
stateManager.getState(BulletAppState.class).getPhysicsSpace().addAll(rootNode);
}
if (name.equals(“pause”)) {
stateManager.getState(BulletAppState.class).getPhysicsSpace().removeAll(rootNode);
}
}
}
[/java]
I would like you run the test code testing the keys :
key_space ( add all physics nodes to physics space) and key_r_right ( remove all physics nodes from physics space).
perceive now it works fine…
Now comment the uncommented lines and uncomment the commented lines at following lines and run the test code again( to test with mesh collision shapes now) :
[java] //c1.addChildShape(new MeshCollisionShape(geo.getMesh()), Vector3f.ZERO.clone());
c1.addChildShape(new BoxCollisionShape(Vector3f.UNIT_XYZ), Vector3f.ZERO.clone());
//c2.addChildShape(new MeshCollisionShape(geo2.getMesh()), Vector3f.ZERO.clone());
c2.addChildShape(new BoxCollisionShape(Vector3f.UNIT_XYZ), Vector3f.ZERO.clone());
//c3.addChildShape(new MeshCollisionShape(geo3.getMesh()), Vector3f.ZERO.clone());
c3.addChildShape(new BoxCollisionShape(Vector3f.UNIT_XYZ), Vector3f.ZERO.clone());[/java]
perceibe now it doens’t works…