I am creating a scene with 200 spheres and was using the TestUtils.createSphere(float R, int divisions) method to generate the spheres. I set the divisions to 30 and was getting poor performance when animating the scene, around 8 fps.
I was interested to see if quadrics would increase performance and have implemented them in Xith3D and have noticed a substantial difference.
Quadrics use stacks and slices, and I’m not sure how these numbers compare to the divisions parameter, but with stacks = slices = 35, I get 18 fps. My OpenGL book says they should be set to 20 or more, and so with stacks=slices=20, I get 30 fps.
To get the same 30 fps with createSphere, I have to set divisions = 10, which is a much poorer quality sphere.
Therefore, I think Xith3D should support quadrics, although I don’t know exactly what the best way to do this would be, here is how I got them to work.
First I added a QuadricSphere class:
package com.xith3d.scenegraph;
import javax.vecmath.Tuple3f;
public class QuadricSphere extends Geometry{
public NodeComponent cloneNodeComponent(boolean forceDuplicate) {
return null;
}
public int getVertexCount() {
return 0;
}
public boolean getVertex(int i, Tuple3f pos) {
return false;
}
protected float radius;
protected int stacks = 20;
protected int slices = 20;
public int getStacks()
{
return stacks;
}
public int getSlices()
{
return slices;
}
public void setRadius(float r)
{
radius = r;
}
public float getRadius()
{
return radius;
}
public QuadricSphere(float r)
{
radius = r;
}
}
Next in the ShapeAtomPeer class I added a member variable:
GLUquadric sphereObject = null;
Then in the renderAtom(CanvasPeer, RenderAtom) method of ShapeAtomPeer I added the code:
if (((CanvasPeerImpl) canvas).isDebugFrame()) {
((CanvasPeerImpl) canvas).debugLog(
"Rendering a shape with geometry : " +
geometry.getClass().getName() + " : " + shape.getName());
OpenGlStateDebug.printState(canvas);
}
// Begin Quadric Code
if(geometry instanceof QuadricSphere)
{
QuadricSphere sphere = (QuadricSphere)geometry;
if(sphereObject == null)
{
sphereObject = glu.gluNewQuadric();
}
glu.gluQuadricNormals(sphereObject, GLU.GLU_SMOOTH);
glu.gluQuadricDrawStyle(sphereObject,GLU.GLU_FILL);
glu.gluQuadricOrientation(sphereObject, GLU.GLU_OUTSIDE);
glu.gluSphere(sphereObject, sphere.getRadius(), sphere.getSlices(), sphere.getStacks());
return;
}
// End Quadric Code
if (geometry instanceof GeometryArray) {
Then if you want to create a sphere you use:
Appearance a = new Appearance();
Shape3D atomShape = new Shape3D(new QuadricSphere(radius),a);
Spheres and cylinders are VERY important to my application, so I really appreciate any ideas for a better way to do this, and hope that Xith3D can have quadric support.
Thanks,
Jason

