Fixed jme2 Dome

The jme2 dome class didn't allow you to render only the inside of the dome with textures/colors.  I just copied that part of the Dome class from the jme1 version, then made the jme1 -> 2 changes.



Also, I don't know how to put things up on svn or wherever they're supposed to go, so if someone else could handle that, that would be great.



Replace senIndexData() method with

   private void setIndexData(boolean outsideView) {
       setTriangleQuantity((planes - 2) * radialSamples * 2 + radialSamples);
      setIndexBuffer(BufferUtils.createIntBuffer(3 * getTriangleCount()));

        // generate connectivity
        int index = 0;
        // Generate only for middle planes
        for (int plane = 1; plane < (planes - 1); plane++) {
            int bottomPlaneStart = (plane - 1) * (radialSamples + 1);
            int topPlaneStart = plane * (radialSamples + 1);
            for (int sample = 0; sample < radialSamples; sample++, index += 6) {
                if (!outsideView) {
                   getIndexBuffer().put(bottomPlaneStart + sample);
                   getIndexBuffer().put(bottomPlaneStart + sample + 1);
                   getIndexBuffer().put(topPlaneStart + sample);
                   getIndexBuffer().put(bottomPlaneStart + sample + 1);
                   getIndexBuffer().put(topPlaneStart + sample + 1);
                   getIndexBuffer().put(topPlaneStart + sample);
                } else // inside view
                {
                   getIndexBuffer().put(bottomPlaneStart + sample);
                   getIndexBuffer().put(topPlaneStart + sample);
                   getIndexBuffer().put(bottomPlaneStart + sample + 1);
                   getIndexBuffer().put(bottomPlaneStart + sample + 1);
                   getIndexBuffer().put(topPlaneStart + sample);
                   getIndexBuffer().put(topPlaneStart + sample + 1);
                }
            }
        }

        // pole triangles
        int bottomPlaneStart = (planes - 2) * (radialSamples + 1);
        for (int samples = 0; samples < radialSamples; samples++, index += 3) {
            if (!outsideView) {
               getIndexBuffer().put(bottomPlaneStart + samples);
               getIndexBuffer().put(bottomPlaneStart + samples + 1);
               getIndexBuffer().put(getVertexCount() - 1);
            } else // inside view
            {
               getIndexBuffer().put(bottomPlaneStart + samples);
               getIndexBuffer().put(getVertexCount() - 1);
                getIndexBuffer().put(bottomPlaneStart + samples + 1);
            }
        }
    }




and replace setData(Vector3f, int, int, float, boolean, boolean) method with

   public void setData(Vector3f center, int planes, int radialSamples,
            float radius, boolean updateBuffers, boolean outsideView) {
        if (center != null)
            this.center = center;
        else
            this.center = new Vector3f(0, 0, 0);
        this.planes = planes;
        this.radialSamples = radialSamples;
        this.radius = radius;

        if (updateBuffers) {
            setGeometryData(outsideView);
            setIndexData(outsideView);
        }
    }

People told me that it is better to provide a diff file here.

Whats the status of this? Any naysayers? I remember the last discussion about the dome was riddled with backwards compatibility arguements. Is this still the case?



Please provide a diff and I will see that this goes in.

Well, since it only changes the index buffer; ppls code won't 'break' but it could introduce some nasty problems if they are using (or have workarounds) for the current setup.



DIFF:

Index: Dome.java
--- Dome.java Base (BASE)
+++ Dome.java Locally Modified (Based On LOCAL)
@@ -178,7 +178,7 @@
 
         if (updateBuffers) {
             setGeometryData(outsideView);
-            setIndexData();
+            setIndexData( outsideView );
         }
     }
 
@@ -277,7 +277,7 @@
     /**
      * Generates the connections
      */
-    private void setIndexData() {
+    private void setIndexData( final boolean outsideView ) {
         // allocate connectivity
         setTriangleQuantity((planes - 2) * radialSamples * 2 + radialSamples);
         setIndexBuffer(BufferUtils.createIntBuffer(3 * getTriangleCount()));
@@ -301,11 +301,18 @@
         // pole triangles
         int bottomPlaneStart = (planes - 2) * (radialSamples + 1);
         for (int samples = 0; samples < radialSamples; samples++, index += 3) {
+            if (!outsideView) {
             getIndexBuffer().put(bottomPlaneStart + samples);
+               getIndexBuffer().put(bottomPlaneStart + samples + 1);
             getIndexBuffer().put(getVertexCount() - 1);
+               
+            } else {
+               getIndexBuffer().put(bottomPlaneStart + samples);
+               getIndexBuffer().put(getVertexCount() - 1);
             getIndexBuffer().put(bottomPlaneStart + samples + 1);
         }
     }
+    }
No newline at end of file
 
     public void write(JMEExporter e) throws IOException {
         super.write(e);



BUT, if its the proper way (and it might be) then is should be fixed...

(Wouldn't setting the triangle face winding to be CCW do the same thing?)
basixs said:
(Wouldn't setting the triangle face winding to be CCW do the same thing?)


Can you confirm this?

First, and this always gets me.  OpenGL uses CCW winding as its default, not CW.



Reply, yes this DOES work.  However, it is at the CullState setting; which means that a custom cull state still has to be applied (and either setting the FaceWinding.ClockWise or the CullFace to front will do the same thing).



SO, for simplicity sake (and a users standpoint), maybe we should incorporate the change (the only thing the OutsideView flag does right now is reverse the normals…)



Here’s a screeny of the test:



The blue dome is a normal dome, with standard front face culling.  The red dome has the outside view flag set and the front face cull state, BUT the cullstate is set to ClockWise winding.



So to sum up, without this patch a user is FORCED to set specific cull state on the DOME if they want to cull the outside but keep the inside (basically what inside view should do anyways…)  BBBUUTT, like I said earlier if ppl have workarounds in place (such as back face culling) and we simply reverse the polygon winding for inside views (which is what the patch does), it will result in the opposite cull function than they had previously.