jME performance having 20,000 Spheres

Hi,



I'm working in a 3D representation of 20,000 spheres in a x,y,z coordinates axis. I use this simple code to add spheres getting x,y,z position from database:



while (rs.next()) // loop through rows of result set
                {
                    Vector3f v = new Vector3f(rs.getFloat(1),rs.getFloat(1),rs.getFloat(1));
                    Sphere s = new Sphere("My sphere",v,30,30,((Double)0.02).floatValue());
                    rootNode.attachChild(s);
                }




Navigation in my scene is very slow, also testing it with a good video card (NVidia 8800). I wonder why I can perfectly run complicated 3D game scenes (also generated with jME), while I'm not capable of having a real-time navigation with 20,000 spheres.

Any suggestion?

Thanks a lot.

A well programmed game will not have 20.000 objects in the scene without any optimizations. Nor will it create unique geomety data for 20.000 objects that look the same. No reason to do this in jME either.



So in this case it's not so much about what engine you use, but how you use it.



However, even using this approach, you can still do a lot of optimizations with jME (eg sharing geomtry data using SharedMesh, locking with the lock* methods, organizing your spheres in a spatial tree so they're easier to cull)

Exactly what llama said, and I think your starting point is to work out a nice quad or oct tree for culling. Then think about what distance is viewable and for far off spheres whether a simple shared mesh or quad is satisfactory.



Think illusion not reality

Hi, I suggest using the Point class and write a shader that renders the points as spheres.



I run around 60000 “spheres” like this with pretty old graphics cards getting good frame rates.



You can run a webstartable demo here:



http://vikingmars.org/astrovis/



It starts in POINT_SPRITE mode. To see the sphere-shader, press the number key 3.



Detailed instructions are under the link.

Rik said:

Hi, I suggest using the Point class and write a shader that renders the points as spheres.

I run around 60000 "spheres" like this with pretty old graphics cards getting good frame rates.

You can run a webstartable demo here:

http://vikingmars.org/astrovis/

It starts in POINT_SPRITE mode. To see the sphere-shader, press the number key 3.

Detailed instructions are under the link.

You forgot something:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: [Lorg/lwjgl/opengl/DisplayMode;
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethod(Class.java:1935)
at java.awt.Component.isCoalesceEventsOverriden(Component.java:5726)
at java.awt.Component.access$100(Component.java:162)
at java.awt.Component$2.run(Component.java:5680)
at java.awt.Component$2.run(Component.java:5678)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Component.checkCoalescing(Component.java:5677)
at java.awt.Component.<init>(Component.java:5646)
at java.awt.Container.<init>(Container.java:245)
at java.awt.Window.<init>(Window.java:320)
at java.awt.Window.<init>(Window.java:466)
at java.awt.Dialog.<init>(Dialog.java:654)
at java.awt.Dialog.<init>(Dialog.java:398)
at javax.swing.JDialog.<init>(JDialog.java:259)
at javax.swing.JDialog.<init>(JDialog.java:193)
at javax.swing.JDialog.<init>(JDialog.java:141)
at com.jme.system.lwjgl.LWJGLPropertiesDialog.<init>(LWJGLPropertiesDialog.java:184)
at com.jme.app.AbstractGame$1.run(AbstractGame.java:215)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.opengl.DisplayMode
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... 28 more

What OS do you use? Linux?, Windows?, OS X?

20,000 spheres shouldn't be a problem if you do instancing or batch them in a couple of vbo's. As long as they don't use to many triangles.



Otherwise you could just use billboarding, no-one will see if it is a true sphere or a billboard.



For example look at this for some instance inspiration:

http://www.ozone3d.net/blogs/lab/?p=87

Thanks for responses,



I'm evaluating all options, however I'm a beginner in 3d visualization techniques and I'd like to see some guides or examples of:


  1. Using of quad or oct tree in jME (there's no info of usage in wiki user's guide).
  2. Using instancing in jME (really cool Haladri's example!).
  3. Using billboard: Haladria, you propose to use Point instead of Sphere?
  4. Write a shader to render point as sphere. (astrovis is very interesting and navigation is very fast!)



    Thanks a lot.
Rik said:

What OS do you use? Linux?, Windows?, OS X?

Mandriva Linux 2007. Sorry for the delay.