So i used terramonkey to make a basic scene containing nothing but a flat terrainQuad.
When I try to make a mesh exact control for it to add to the PhysicsSpace it crashes. Here is the stack trace:
Jul 22, 2011 9:00:02 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IndexOutOfBoundsException
at java.nio.Buffer.checkIndex(Buffer.java:514)
at java.nio.DirectIntBufferU.get(DirectIntBufferU.java:236)
at com.jme3.scene.mesh.IndexIntBuffer.get(IndexIntBuffer.java:52)
at com.jme3.bullet.util.Converter.convert(Converter.java:248)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:70)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.(MeshCollisionShape.java:65)
at com.jme3.bullet.util.CollisionShapeFactory.createSingleMeshShape(CollisionShapeFactory.java:174)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:65)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:62)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:62)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:62)
at com.jme3.bullet.util.CollisionShapeFactory.createCompoundShape(CollisionShapeFactory.java:85)
at com.jme3.bullet.util.CollisionShapeFactory.createMeshCompoundShape(CollisionShapeFactory.java:94)
at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:134)
at mygame.BattleField.(BattleField.java:50)
at mygame.Main.initMap(Main.java:85)
at mygame.Main.simpleInitApp(Main.java:52)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:218)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:138)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:206)
at java.lang.Thread.run(Thread.java:680)
Any idea why this is happening? Am I supposed to treat terrainQuads differently with respect to physics?
look at TerrainTestCollision
First I was looking at the TestTerrainCollision that comes in JMP which used PhysicsNodes, and I knew that wasn’t right.
So I took a look at the svn and found the newer version.
It uses:
[java]
terrain = new TerrainQuad(“terrain”, 65, 513, heightmap.getHeightMap());
TerrainLodControl control = new TerrainLodControl(terrain, getCamera());
terrain.addControl(control);
terrain.setMaterial(matRock);
terrain.setLocalScale(new Vector3f(2, 2, 2));
terrain.setLocked(false); // unlock it so we can edit the height
rootNode.attachChild(terrain);
/**
- Create PhysicsRigidBodyControl for collision
*/
terrain.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().addAll(terrain);
[/java]
The only way this differs from my code is that it is creating the TerrainQuad in code. I am trying to load it from a scene:
[java]
Node terrainScene = (Node) assetManager.loadModel(“Scenes/BattleFields/TerrainTest.j3o”);
TerrainQuad tQ = (TerrainQuad) terrainScene.getChild(0);
tQ.addControl(new RigidBodyControl(0));
physics.addAll(tQ);
[/java]
This was not the only way I tried. I tried adding the control while leaving the scene as a Spatial and casting it to a Node. I tried it on the object itself and on its children. I’m at a loss. Am I misunderstanding something about how scenes are structured? I assumed I could import them and treat them like any other Node or Spatial.
Thanks for the help!
Ok so I’ve found that this only happens when I change its location. I had dropped it down to (0,-20,0) in the scene editor and this was causing it. When I made it (0,0,0) it ran fine.
It also crashes if I try using setPhysicsLocation(0,-20,0) after everything has been added to the rootNodes and PhysicsSpace. So I guess the new question is, why does moving the terrain cause this error or how am I supposed to move it instead?
What error are you getting when you use setPhysicsLocation()?
TestCollisionGroups has examples of setPhysicsLocation.
I’m not on a machine with jme right now, and it might be a few days for me to get to one so I can look at this issue. Hang tight and bare with my absence
This is very strange, but when I went to recreate the error it worked fine. With both setPhysicsLocation and the scene editor setLocalTranslation. Thanks for the response lol. If I run into it again I’ll post here.