Deceleration graphics

Hi , I’ve a simple problem, I’m working on a game in first person and unfortunately I note that when I load too mach object like for example tree, the player movement suffer a deceleration and the movement is slow and with click … this ruin the gameplay :frowning:
In particular this is the code relative
[java]
@Override
public void simpleInitApp(){
//set up flycam
flyCam.setEnabled(true);
initPhysics();
// loadCharacter();
initSky();
initTerrain();
initLight();
initBULLETS();
setUpKeys();
// createSector();
initMaterial();
setUpKeys();
initCrossHairs();
managementPlayer();
loadTree();
// managementEnemy();
// startAi();
}

//method
public void loadTree(){
int x =-300;
int z = 300;
for(int i=0; i<100; i++){
ObjectStreet object = new ObjectStreet(assetManager, rootNode , bulletAppState, x,z);
// x+=10;
z-=10;
}
}

//class
public class ObjectStreet {
CharacterControl characterTree;
Spatial tree;
float x;
float z;

public ObjectStreet(AssetManager assetManager,Node rootNode, BulletAppState bullet,float x, float z){
     this.x= x;
     this.z= z;
     
     CapsuleCollisionShape capsule = new CapsuleCollisionShape(1.4f, 0.5f);
      //peso 
     characterTree = new CharacterControl(capsule,50f); 
     
     
         tree = (Spatial) assetManager.loadModel("Models/Tree/Tree.mesh.xml");
	     tree.setLocalScale(10,10,10);
	     tree.addControl(characterTree);
	     characterTree.setPhysicsLocation(new Vector3f(this.x, 0,this.z)  );
	          bullet.getPhysicsSpace().add(tree);
	          rootNode.attachChild(tree);
}

}

[/java]
Nothing of strange, there is something of graphics(for optimization) that escapse me?? How can remedy??
thanks in advance :slight_smile:

You should probably offload the entire asset loading process to a separate thread. Use a Future, when it’s complete, enqueue the rootNode.attachChild and physicsSpace.add

you are creating 100 separate tree objects, and giving them all a character control with a step height of 50 ;o. Are these trees supposed to move?

A couple optimizations are:

  • Batch all the trees with GeometryBatchFactory.optimize() (if they are static objects, use a BatchNode otherwise)
  • Either reuse a single collision shape (don’t create a new one for each tree) and create a separate RigidBodyControl for each tree or create a CompoundCollisionShape with all the trees in if they are within close promixity of each other.