Performance issues

I’m using the capsule Collision Shape:
[java]
CapsuleCollisionShape capsule2 = new CapsuleCollisionShape(7f,7f,2);
elephantCharacter = new CharacterControl(capsule2, 0.5f);
elephantCharacter.setGravity(60);
elephantCharacter.setPhysicsLocation(new Vector3f(0,-5,0));
elephant = (Node) assetManager.loadModel(“Models/Elephant/Elephant.mesh.xml”);
elephant.scale(0.2f);
elephant.setLocalTranslation(30f,5f,10);
elephant.setShadowMode(ShadowMode.CastAndReceive);
elephant.addControl(elephantCharacter);
bulletAppState.getPhysicsSpace().add(elephantCharacter);
sceneNode.attachChild(elephant);
[/java]

I will try with the compunt shape.
How can I lnow if my terrain is static or dynamic?

system.out.println(terrainShape.getClass()) would be a simple solution

One question also, do you use the native or the jbullet version? And how many polygons does the terrain have?

I’m using the com.jme3.bullet.BulletAppState
I used the getTriangle() for the map, it has 532720 triangles.

You’re creating a mesh collision shape for the terrain, which is going to be massively slow. I just checked and the tutorial says to do this when it shouldn’t. Terrain uses a special physics shape (height field) for collision so it doesn’t have to collide with 1 million polygons every frame.

Do this instead:
[java]terrain.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().addAll(terrain);
[/java]

And take a look at TerrainTestCollision.java.

I will update the tutorial.

<cite>@Sploreg said:</cite> You're creating a mesh collision shape for the terrain, which is going to be massively slow. I just checked and the tutorial says to do this when it shouldn't. Terrain uses a special physics shape (height field) for collision so it doesn't have to collide with 1 million polygons every frame.

Do this instead:
[java]terrain.addControl(new RigidBodyControl(0));
bulletAppState.getPhysicsSpace().addAll(terrain);
[/java]

And take a look at TerrainTestCollision.java.

I will update the tutorial.

Sorry to say so, but please reread the bullet docu. While it needs quite some time for generation, it is only a one time cost, so it cannot be the issue here.
In fact the meshshape is faster as it has a acceleration tree in it, that can process different heights. (eg if the elephant is over a valley it does not much at all, while the hieghfield one would still check for the occluded area).
-> So assuming it is not recalculated every frame it is no the actual problem here.

The bullet app state can use native and jbullet, since you seem to not have changed anything i guess its defaulting to jbullet.

The collision shape for terrain is a heightfield that is significantly faster than mesh collision. When I did a performance test last year they weren’t even in the same ball park of speed: the heightfield won. Now if bullet has changed since then, it might be different and then I can change it.

I agree with Empire Phoenix, the problem dosn’t come from the terrain I tried both methods but it don’t change anything.
The problem comes from the elephant collision shape or physic.

Can you show me how to use the compound shape because I don’t understand it well in the tutorial.

Actually the capsule one should already work fine enough normally. The compound shape would be an alternative if you had used gimpact shapes.
I’m a little out of ideas here, can you test with any other objec than an elephant? Like a simple cube if it behaves different?

<cite>@Sploreg said:</cite> The collision shape for terrain is a heightfield that is significantly faster than mesh collision. When I did a performance test last year they weren't even in the same ball park of speed: the heightfield won. Now if bullet has changed since then, it might be different and then I can change it.

Well at least for the native one the mesh shape is faster, as i died test when creating my terrain rendering system, with meshshapes i was able to get around 2k spheres rolling on it at 60fps while with heighfield it started to lag quite hardly once they enterd the bounding box. (Also this gets far worse when useing larger objects, as the heighfield one has no real acceleration structure in it. (Test it shoot a nearly horizontal ray over a terrain that does not hit it. The heighfield one will peform really bad in such cases.)

I guess it really boils down to the type of map you are making then. Good to note.