Producing large numbers of identical geometry / different colour objects


I'm new to jME and want to render a large number of sphere with different sizes and colours. I see two potential problems with this:

  1. All the spheres will have the same basic geometry, but if I create 100,000+ Sphere objects that will surely consume a lot of resources?
  2. If all the spheres have slightly different colours, does this mean I need an expensive RenderState change to change the MaterialState? State sorting probably won't help much if I have 16 million colours…

    Any advice on how to implement this efficiently would be most welcome!


take a look at SharedMesh. it enables you to share the geometry information between meshes.

also take a look at TestSharedMesh if you want to know how to start using it.

Thanks Sfera, seems to work very well. I'm up at 1,000 meshes and 100,000 triangles at a pretty decent framerate which is about what I was after.

BTW, Is there any difference between using SharedMesh and SharedNode?

i don't really know what SharedNode is as i never used it. after a quick look it seems like it's intended to be used if you want to share a whole node hierarchy (not only geometry).  :slight_smile:

Well, if you want 100.000 object with 100.000 different properties, somewhere along the line you'll have to create 100.000 unique objects. But if you want to render 100.000 objects on screen it won't work anyway… (well, not in real time that is). So I doubt you'll need to create 100.000 seperate geometry objects (wether they're SharedMeshes or not).

Eg. you could limit the number of objects to the max. number of objects you'll expect on screen, or you could use the same object over and over (if you skip the renderqueue).