Hi,
i try to add a collisionShape to a mesh, but a get an exception. Can somebody help me? My code:
Mesh mesh = new Mesh();
mesh.setMode(Mesh.Mode.Lines);
mesh.setBuffer(VertexBuffer.Type.Position, 3, new float[]{0, 0, 0, 100, 0, -200});
mesh.setBuffer(VertexBuffer.Type.Index, 2, new short[]{0, 1});
Geometry g = new Geometry(“line”, mesh);
g.setMaterial(borderMat);
MeshCollisionShape meshCollisionShape = new MeshCollisionShape(mesh);
mesh.updateBound();
mesh.updateCounts();
RigidBodyControl bodyControl = new RigidBodyControl(meshCollisionShape, 0f);
g.addControl(bodyControl);
rootNode.attachChild(g);
this.bulletAppState.getPhysicsSpace().add(g);
The Exception:
java.lang.IndexOutOfBoundsException
at java.nio.Buffer.checkIndex(Buffer.java:532)
at java.nio.DirectShortBufferU.get(DirectShortBufferU.java:253)
at com.jme3.scene.mesh.IndexShortBuffer.get(IndexShortBuffer.java:53)
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.<init>(MeshCollisionShape.java:65)
at mygame.Main.initRoad(Main.java:155)
at mygame.Main.simpleInitApp(Main.java:97)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:722)