Hey guys,
I’ve generated some terrain using cave3d’s ScalarFieldPolygonisator.java (http://code.google.com/p/cave3d/source/browse/trunk#trunk%2Fjme3%2Fcave3d). I want to make a physics mesh shape out of it, but I get this crash upon generation:
Exception in thread “Thread-5” java.lang.ArrayIndexOutOfBoundsException: 1
at com.bulletphysics.collision.shapes.QuantizedBvhNodes.setQuantizedAabbMax(QuantizedBvhNodes.java:170)
at com.bulletphysics.collision.shapes.QuantizedBvhNodes.setQuantizedAabbMax(QuantizedBvhNodes.java:143)
at com.bulletphysics.collision.shapes.OptimizedBvh.setInternalNodeAabbMax(OptimizedBvh.java:94)
at com.bulletphysics.collision.shapes.OptimizedBvh.buildTree(OptimizedBvh.java:507)
at com.bulletphysics.collision.shapes.OptimizedBvh.build(OptimizedBvh.java:318)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.(BvhTriangleMeshShape.java:80)
at com.bulletphysics.collision.shapes.BvhTriangleMeshShape.(BvhTriangleMeshShape.java:63)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createShape(MeshCollisionShape.java:122)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.createCollisionMesh(MeshCollisionShape.java:77)
at com.jme3.bullet.collision.shapes.MeshCollisionShape.(MeshCollisionShape.java:65)
at com.jme3.bullet.util.CollisionShapeFactory.createSingleMeshShape(CollisionShapeFactory.java:214)
at com.jme3.bullet.util.CollisionShapeFactory.createMeshShape(CollisionShapeFactory.java:171)
at Game.TerrainGeneration.TerrainGeometry.CreatePhysics(TerrainGeometry.java:46)
at Game.TerrainGeneration.PolygonizationThread.run(PolygonizationThread.java:147)
at java.lang.Thread.run(Thread.java:679)
Any suggestions?
Doesn’t seem to be a proper triangle mesh.
Hrm… the mesh does render OK, at least using the ShowNormals material definition. Here is how the mesh is generated:
[java] vertexBuffer = mesh.getFloatBuffer(Type.Position);
if( vertexBuffer == null ){
vertexBuffer = BufferUtils.createFloatBuffer( 16000 );
} else{
vertexBuffer.clear();
}
normalBuffer = mesh.getFloatBuffer(Type.Normal);
if( normalBuffer == null ){
normalBuffer = BufferUtils.createFloatBuffer( 16000 );
} else{
normalBuffer.clear();
}
if(doColors) {
colorBuffer = mesh.getFloatBuffer(Type.Color);
if( colorBuffer == null ){
colorBuffer = BufferUtils.createFloatBuffer( 16000 );
} else{
colorBuffer.clear();
}
}
if(doTexCoords) {
textureBuffer = mesh.getFloatBuffer(Type.TexCoord);
if( textureBuffer == null ){
textureBuffer = BufferUtils.createFloatBuffer( 16000 );
} else{
textureBuffer.clear();
}
}
IndexBuffer indBuf = mesh.getIndexBuffer();
if( indBuf == null ){
indexBuffer = BufferUtils.createIntBuffer( 16000 );
} else{
indexBuffer = (IntBuffer) indBuf.getBuffer();
indexBuffer.clear();
}
calculateCells( iso );
indexBuffer.flip();
//indexBuffer.compact();
mesh.setBuffer( Type.Index, 1, indexBuffer );
vertexBuffer.flip();
vertexBuffer.compact();
mesh.setBuffer(Type.Position, 3, vertexBuffer );
normalBuffer.flip();
normalBuffer.compact();
mesh.setBuffer(Type.Normal, 3, normalBuffer );
if(doColors) {
colorBuffer.flip();
colorBuffer.compact();
mesh.setBuffer(Type.Color, 4, colorBuffer );
}
//mesh.setTriangleCount( indexBuffer.limit() / 3 );
//mesh.setVertexCount( vertexBuffer.limit() / 3 );
if(doTexCoords) {
textureBuffer.flip();
textureBuffer.compact();
mesh.setBuffer(Type.TexCoord, 2, textureBuffer );
}
mesh.updateCounts();
if(doTexCoords && mesh.getTriangleCount() > 0){
TangentBinormalGenerator.generate(mesh);
}[/java]
See anything that would be throwing createMeshShape off?
Thank you for your help.
Looks like it is the .flip() calls on the buffer that is causing the crash, and .compact() is causing lots of lag and other problems. Is .flip() and .compact() really doing anything useful here (other than breaking the createMeshShape call)?
Looks like I’m still having lots of lag problems in createMeshShape() for generated terrain. Funny how it only seems to happen for some random terrain configurations and not others…
EDIT INSTEAD OF POST: Looks like some terrain “chunks” were being created with 0 mesh points (e.g. the sky), so createMeshShape() got confused with an empty mesh. Doh!
… so, no triangles
Correct!