Rendering large numbers of identical objects efficients (SharedMesh?)

I’m trying to render a large number of identical objects which may move/be removed/added. However I’m experiencing very poor performance with large numbers of objects. My simplest code is below (obviously I don’t actually want to create one massive box out of many smaller ones, this is just an example).



From what I have read I need to change to using a sharedmesh, but I’ve not been able to find any example code using it. Additionally its import seems to have changed between jme2 and jme3, import com.jme3.scene.SharedMesh; doesn’t seem to work. Has SharedMesh been replaced by something else?



http://www.jmonkeyengine.com/doc/com/jme/scene/SharedMesh.html



[java]

import com.jme3.app.SimpleApplication;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.material.Material;

import com.jme3.scene.*;

import com.jme3.scene.shape.Box;





public class Simplest extends SimpleApplication{



public static void main(String[] args) {

Simplest app = new Simplest();

app.start();

}



public void simpleInitApp() {



viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));



cam.setLocation(new Vector3f(0f,0,50f));



setUpBlocks();

}



private void setUpBlocks(){



Material mat = new Material(assetManager,“Common/MatDefs/Misc/Unshaded.j3md”);

mat.setColor(“Color”, ColorRGBA.Blue);

Box b = new Box(Vector3f.ZERO, 1, 1, 1);



for(int i=0;i<30;i++){

for(int j=0;j<30;j++){

for(int k=0;k<30;k++){



Geometry geometry = new Geometry(“blue cube”, b);

geometry.setMaterial(mat);

Node translationNode=new Node();

translationNode.move(i,j,k);

translationNode.attachChild(geometry);

rootNode.attachChild(translationNode);

}

}

}





}

}[/java]



Thanks for any help you can offer

The object count is what is driving down the fps, not the meshes. use the GeometryBatchFactory or BatchNode depending on your needs. And please read the documentation, it contains lots of information like this.

Thanks for your very quick (and useful) reply. I had previously read the documentation on GeometryBatchFactory (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:intermediate:optimization#maintain_low_geometry_count) but had discounted it because it was stated that GeometryBatchFactory is only appropriate for static Geometry. However BatchNode sounds like exactly what I need and I will now try to incorperate that.

The fact that your making a lot of boxes, and then want to add/remove some of them, suggests to me that your trying to make some sort of “minecraft” clone (box world), if so search for voxels

And if you hover over “box world” above… you see the appropriate advice: “Box worlds are not made of boxes.”

Making a minecraft “clone” might be a bit beyond me at this point, but this voxel approach is certainly very interesting.



For anyone finding this on google this is an interesting page on voxels in jMonkey:

http://hub.jmonkeyengine.org/groups/free-announcements/forum/topic/simple-voxel-engine-starter-kit/