IndexedQuadArray in Xith3D

I am trying to refactor my J3D code to semi-match the Xith3D api.
I am trying to use the IndexedQuadArray node, but whenever I need to set my indicies ( setCoordinateIndices(0,indicies) in J3D), I have no equivalent in Xith3D…

Is there an alternate way of doing this?

Thanks

Zak Nixon

???

Use setIndex(int[] i) to set all of the indices.

Thanks for your reply, ewillis.
Is there also a way to set the color indicies as well?

So far, I can use a PointArray for my points and my geometry shows up (also QuadArray), but with the IndexedQuadArray, I am not seeing anything.

I have used the setIndex(int[] indicies) for the coordinates, and set my Shape3D’s coloring attributes.

Anyone have examples of working with the IndexedQuadArray?

Thanks :-/

Zak Nixon

I have tried adding a quad using the IndexedQuadArray and a triangle using the IndexedTriangleArray. The quad does not display, but the triangle will. Below is my code.

The quad:



      public Shape3D getGrid(){
            int numIndexes = 4;
            int[] indexes = new int[]{0,1,2,3};
            // Vector3f[] normals = new Vector3f[]{ new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f)};
            
            IndexedQuadArray a = new IndexedQuadArray(4,IndexedTriangleArray.COORDINATES,numIndexes);
            
            Point3f[] coords = new Point3f[]{ new Point3f(1.0f,1.0f,0.0f), new Point3f(-1.0f,1.0f,0.0f),new Point3f(-1.0f,-1.0f,0.0f),new Point3f(1.0f,-1.0f,0.0f)};
      
            a.setValidIndexCount(4);
            a.setCoordinates(0,coords);
            //a.setNormals(0,normals);
            a.setIndex(indexes);
            
            Appearance app = new Appearance();
          Material material = new Material();
          material.setAmbientColor(.6f,.6f,.6f);
          material.setLightingEnable(true);

            app.setColoringAttributes(new ColoringAttributes(new Color3f(1.0f,0.0f,0.0f),ColoringAttributes.FASTEST));
            app.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE,PolygonAttributes.CULL_NONE,0f));
            // app.setMaterial(material);
            
            Shape3D s = new Shape3D(a,app);
            return s;
      }

The triangle:



      public Shape3D getTriangle(){
            int numIndexes = 3;
            int[] indexes = new int[]{0,1,2};
            // Vector3f[] normals = new Vector3f[]{ new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f),new Vector3f(0.0f,0.0f,1.0f)};
            
            IndexedTriangleArray a = new IndexedTriangleArray(3,IndexedTriangleArray.COORDINATES,numIndexes);
            
            Point3f[] coords = new Point3f[]{ new Point3f(1.0f,1.0f,0.0f), new Point3f(-1.0f,1.0f,0.0f),new Point3f(-1.0f,-1.0f,0.0f)};
      
            a.setValidIndexCount(3);
            a.setCoordinates(0,coords);
            //a.setNormals(0,normals);
            a.setIndex(indexes);
            
            Appearance app = new Appearance();
          Material material = new Material();
          material.setAmbientColor(.6f,.6f,.6f);
          material.setLightingEnable(true);

            app.setColoringAttributes(new ColoringAttributes(new Color3f(1.0f,0.0f,0.0f),ColoringAttributes.FASTEST));
            app.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE,PolygonAttributes.CULL_NONE,0f));
            // app.setMaterial(material);
            
            Shape3D s = new Shape3D(a,app);
            return s;
      }


Any thing I am doing wrong?

Thanks
Zak

I suggest using com.xith3d.utility.geometry.XithGeometryInfo and com.xith3d.utility.geometry.GeometryCreator. GeometryCreator lets you specify geometries in an OpenGL manner, XithGeometryInfo allows you to create various GeometryArraysS from a GeometryCreator.

Well, unfourtunately, these classes do not support Quad geometry, just Triangle Strips.
There has to be a way to build simple quad geometry…

Any suggestions?

Zak

You can always represent a quad as two triangles. Is there a reason you really need to use a QuadArray?

I am trying to draw a wireframe model of a sphere, like lat/lon lines. I already have the geometry defined as Indexed Quads. I could define them as individual lines, but that changes all of my algorithms and data structs.

Just trying to find a one-to-one correspondance between J3D and Xith.

Zak

i guess there is no problem in ur code…the problem is with the one of the library class of Xith…go to the PACKAGE–com.xith3d.render.jogl…CLASS----ShapeAtomPeer…in this class go to the METHOD—private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray)… in this method actually some code is missing… i have made changes in this code…now the working code should be…

private void drawGeometry(CanvasPeer canvas, GL gl, GeometryArray geoArray) {

    ProfileTimer.startProfile("drawGeometry");
    int numVertices = geoArray.getValidVertexCount();

//
if (numVertices == 0) {
if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Skipping because there are no valid vertices ");
ProfileTimer.endProfile();
return;
}

    // get the format of verticies
    int format = geoArray.getVertexFormat();

    int stripCount = 0;
    int[] stripVertexCounts = null;

    // if a strip array then get the above two values
    if (geoArray instanceof GeometryStripArray) {
        stripCount = ((GeometryStripArray) geoArray).getNumStrips();
        stripVertexCounts = ((GeometryStripArray) geoArray).
                getStripVertexCounts();
        if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a strip array " + stripCount + " strips");
    }

    // find out if color3f data was supplied and if it was use it


    int mode = 0;

    if ((geoArray instanceof IndexedGeometryArray)) {
        canvas.addTriangles( ((IndexedGeometryArray)geoArray).getValidIndexCount()/geoArray.getFaceSize());
       
    } else if (geoArray instanceof TriangleArray) {
        if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a triangle array with " + numVertices + " vertices");
        mode = GL.GL_TRIANGLES; // say that we want to draw trianlges
        canvas.addTriangles(numVertices/geoArray.getFaceSize());
    } else if (geoArray instanceof QuadArray) {
        if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Drawing a quad array with " + numVertices + " vertices");
        mode = GL.GL_QUADS; // say that we want to draw quads
        canvas.addTriangles(numVertices/geoArray.getFaceSize());
    } else if (geoArray instanceof PointArray) {
        mode = GL.GL_POINTS; // say that we want to draw points
        canvas.addTriangles(numVertices/geoArray.getFaceSize());
    } else if (geoArray instanceof LineArray) {
        mode = GL.GL_LINES; // say that we want to draw lines
    } else if (!(geoArray instanceof GeometryStripArray)) {
        if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Skipping unknown geometry : " + geoArray.getClass().getName());
       
        ProfileTimer.endProfile();
        return; // don't know how to draw this
    }

    // do the actual drawing genericly

    setupBuffers(canvas, gl, geoArray);
    if (geoArray instanceof GeometryStripArray) {

        //setPointers(gl);

        if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG, "Starting drawing strips for GeometryStripArray");
        // loop through the strips

        if (geoArray instanceof LineStripArray) {
            mode = GL.GL_LINE_STRIP; // say that we want to draw a line strip
        } else if (geoArray instanceof TriangleStripArray) {
            mode = GL.GL_TRIANGLE_STRIP; // say that we want to draw a triangle strip

// if (CanvasPeerImpl.debugGL) Log.print(LogType.DEBUG,“Drawing a triangle strip “+strip+” of “+stripCount+” strips and “+stripVertexCounts[strip]+” vertices”);
} else if (geoArray instanceof TriangleFanArray) {
mode = GL.GL_TRIANGLE_FAN; // say that we want to draw a triangle fan
}

        int start = 0;
        for (int strip = 0; strip < stripCount; strip++) {

            gl.glDrawArrays(mode, start, stripVertexCounts[strip]);
            start += stripVertexCounts[strip];

        }
    } else if (geoArray instanceof IndexedGeometryArray) {
       if (geoArray instanceof IndexedLineArray) {
            mode = GL.GL_LINES; // say that we want to draw points
            IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
            gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
        }
       
       if (geoArray instanceof IndexedQuadArray) {
             mode = GL.GL_QUADS; // say that we want to draw points
             IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
             gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
         }
        if (geoArray instanceof IndexedTriangleArray) {
            mode = GL.GL_TRIANGLES; // say that we want to draw points
            IndexedGeometryArray igeoArray = (IndexedGeometryArray) geoArray;
            gl.glDrawElements(mode, igeoArray.getValidIndexCount(), GL.GL_UNSIGNED_INT, igeoArray.getIndexData().getIntBuffer());
        } else if ( geoArray instanceof IndexedGeometryStripArray ) {
            if ( geoArray instanceof IndexedTriangleStripArray ) {
           mode = GL.GL_TRIANGLE_STRIP;
            IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
            int[] strips = igsa.getStripVertexCounts();
            int start = 0;
            for (int s = 0; s < strips.length; s++) {
                gl.glDrawElements(mode,strips[s],GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                start += strips[s];
            }
        }
            if ( geoArray instanceof IndexedLineStripArray ) {
               mode = GL.GL_LINE_STRIP;
                IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
                int[] strips = igsa.getStripVertexCounts();
                int start = 0;
                for (int s = 0; s < strips.length; s++) {
                    gl.glDrawElements(mode,strips[s],GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                    start += strips[s];
                }
            }
            if ( geoArray instanceof IndexedTriangleFanArray ) {
               mode = GL.GL_TRIANGLE_FAN;
                IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)geoArray;
                int[] strips = igsa.getStripVertexCounts();
                int start = 0;
                for (int s = 0; s < strips.length; s++) {
                    gl.glDrawElements(mode,strips[s],GL.GL_UNSIGNED_INT,((IntBuffer)igsa.getIndexData().getIntBuffer().position(start)).slice());
                    start += strips[s];
                }
            } 
        }
       
    } else {
        gl.glDrawArrays(mode, geoArray.getInitialVertexIndex(), geoArray.getValidVertexCount());
    }
    ProfileTimer.endProfile();
}

i guess replacing the previous code with this one,will solve ur problem…try this…All the best… n plzzz let me know if it works…