IndexedQuadArray bug?

Hi all

I’ve just started to use Xith3D for a project, and I’ve encountered a problem using the IndexedQuadArray class. I’ve created an array of coordinates (coords), an array of normals (normals), and two int arrays specifying which coordinates and normals to use.

When creating the geometry using IndexedQuadArray I get no errors, but when I create a shape from the geometry and render it, nothing is shown. However, if I traverse the arrays myself, and then use QuadArray instead, everything works fine.

See the code attached below for details.


//Doesn't work:
            //IndexedQuadArray tube = new IndexedQuadArray(coords.length, IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, coordIndices.length);
            //tube.setCoordinateIndices(0, coordIndices);
            //tube.setNormals(0, normals);
            //tube.setNormalIndices(0, normalIndices);
            
            //Works fine:
            Point3f[] myCoords = new Point3f[coordIndices.length];
            Vector3f[] myNorms = new Vector3f[coordIndices.length];
            for (int i = 0; i < coordIndices.length; i++){
                  myCoords[i] = coords[coordIndices[i]];
                  myNorms[i] = normals[normalIndices[i]];
            }
            QuadArray tube = new QuadArray(myCoords.length, GeometryArray.COORDINATES | GeometryArray.NORMALS);
            tube.setCoordinates(0, myCoords);
            tube.setNormals(0, myNorms);


Edit: Saw the option to format the code :slight_smile:

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…