Bad Performance Issue

Hi,

I added a terrain and an object to my scene graph. When the object falls due to gravity, the fps rate goes down to 0 when the object is close to the terrain. Why is that?

Probably because you are not generating a height map collision shape for the terrain. Use the CollisionShapeFactory on the TerrainQuad directly, not on the rootNode above it. But that is just speculation, your post gives absolutely no information and your question is like “How long is the piece of string I am holding in my hand?”

http://www.mikeash.com/getting_answers.html

I have a class that extends Node and all objects in the game are added to this node. The class is then attached to rootNode. I modelled the terrain using the jmonkey platform and it is saved in a .j3o file.

[java]

// map

Spatial map = SinglePlayer.getInstance().getAssetManager().loadModel(ModelPaths.MAP1);

// set physics

CollisionShape sceneCollisionShape = CollisionShapeFactory.createMeshShape(map);

map_phy = new RigidBodyControl(sceneCollisionShape, 0);

map.addControl(map_phy);

bulletAppState.getPhysicsSpace().add(map_phy);

this.attachChild(map);



// add plane

Plane plane = new TestPlane(SinglePlayer.getInstance().getAssetManager().loadModel(ModelPaths.Plane));

this.attachChild(plane);

plane.setLocalTranslation(0, 20, -20);

// set physics

CollisionShape planeCollisionShape = CollisionShapeFactory.createDynamicMeshShape(plane.getModel());

plane_phy = new RigidBodyControl(planeCollisionShape, 2313.0f);

plane_phy.setGravity(new Vector3f(0, 100, 0));

plane.getModel().addControl(plane_phy);

bulletAppState.getPhysicsSpace().add(plane_phy);

[/java]

Plane is a class extending Node, which has the Spatial with the model of the plane attached to it and which also contains some other information about the object. (getModel() returns the Spatial)

The framerate goes down to 0 fps when the plane collides with the terrain.

Yeah. Its exactly what I said -.-

[java]

Node map = (Node)SinglePlayer.getInstance().getAssetManager().loadModel(ModelPaths.MAP1);

TerrainQuad terrain = (TerrainQuad)map.getChild(“terrain”);

// set physics

CollisionShape sceneCollisionShape = CollisionShapeFactory.createMeshShape(terrain);

[/java]



Edit: please don’t post “I get a NPE on creating the shape”, obviously you have to enter the correct name of the terrain

This makes it even worse, the framerate already goes down to 0 while the object is falling. I tried createBoxShape() for the plane instead of createDynamicMeshShape() because it should be significantly faster. It runs smoothly, but the plane now goes through the terrain.

have you tried what normen said? becouse i see that you DON’T -.-



do you have CollisionShape on terrainquad or it’s parentNode or rootNode or what?



edit: you certainly do somethin wrong. If you typed correct name of terrain / etc. Then it should work fast. You can also create testcase if you sure there is somethin wrong.

I DID do what he said:

[java]

Node map = (Node)SinglePlayer.getInstance().getAssetManager().loadModel(ModelPaths.MAP1);

TerrainQuad terrain = (TerrainQuad)map.getChild("terrain-Map1");

CollisionShape sceneCollisionShape = CollisionShapeFactory.createMeshShape(terrain);

[/java]

testcase would be helpful :wink:

The “dynamic mesh shape” will definitely produce such results btw, you are being warned about this in the javadoc. Anyway this is definitely no issue with the engine but with the usage.

I know, why does using the box shape in this case not work?

Probably because you do something wrong. Maybe because its way too heavy for its size if you did the same as with the plane shape (btw a movable plane shape is a bad idea anyway). Please don’t go back to asking those string questions again, how should I know what you mess up?