Simple Geometry Utils

Hi,

I require some simple geometry utility classes for generating planes, cylinders etc. (planes to beging with)
I’ve tried the TestUtils class but all it can generate is one big quad as the plane, this is messing with my lighting :frowning: so I need to tesselate the plane into sub-quads or triangles.

I’m tying to write a class, what is the best Geometry class to use for this sort of thing (QuadArray, TriangleArray or something else)?
Are there any docs on the format that QuadArray and Triangle array expect their data? ???

If something exists out there to already do this I’d gladly use that! I can’t be the first person to have required this…

Cheers,
Ben

Hi,

Creatin these primitives in Xith3D is very simple. Take a look at createSphere(float R, int divisions) in TestUtils and you will easily get the idea of how to do indexed triangle array.

Additionally, you can use GeometryCreator and XithGeometryInfo in utility/geometry package to create geometry in OpenGL glBegin/glEnd way and get it out as GPU-cache-optimized Xith3D Shape.

Here is a short example on how to use it:

            GeometryCreator gc = new GeometryCreator();
            for (int i = 0; i < indexedVertexes.length/3; i++)
            {
                  gc.addCoordinate(indexedVertexes[i*3],indexedVertexes[i*3+1],indexedVertexes[i*3+2]);
                  if (indexedNormals.length > 0)
                        gc.addNormal(indexedNormals[i*3],indexedNormals[i*3+1],indexedNormals[i*3+2]);
                  if (indexedTexCoords.length > 0)
                        gc.addTexCoord(indexedTexCoords[i*2],indexedTexCoords[i*2+1]);
            }
            for (int i = 0; i < indexes.length/3; i++)
            {
//                  System.out.println("Face " + indexes[i*3] + " " + indexes[i*3+1] + " " + indexes[i*3+2]);
                  gc.addCoordIndex(indexes[i*3]);
                  gc.addCoordIndex(indexes[i*3+1]);
                  gc.addCoordIndex(indexes[i*3+2]);
                  if (indexedNormals.length > 0)
                  {
                        gc.addNormalIndex(indexes[i*3]);
                        gc.addNormalIndex(indexes[i*3+1]);
                        gc.addNormalIndex(indexes[i*3+2]);
                  }
                  if (indexedTexCoords.length > 0)
                  {
                        gc.addTexIndex(indexes[i*3]);
                        gc.addTexIndex(indexes[i*3+1]);
                        gc.addTexIndex(indexes[i*3+2]);
                  }
                  gc.nextFace();
            }
            XithGeometryInfo xgi = new XithGeometryInfo();
            gc.fillGeometryInfo(xgi);
            xgi.weldVertices();
            xgi.optimizeTrianglesForCache();

            IndexedTriangleArray shapeGeom = xgi.createIndexedTriangleArray(geomFlags);

            shape.setGeometry(shapeGeom);

As of docs, you can take a look at Java3D docs - it uses similar format for data in GeometryArrays.

Yuri

Thanks, for the reply I’ve managed to write something now, that suits my needs. I just used QuadArray.

I had a look at GeometryCreator and I didn’t understand it, but I think I’ve got it now.

Here’s a link to my class, it creates planes in one of the three orientations and the planes can be subdivided into smaller quads.
http://cgi.bencoleman.plus.com/files/PlaneGenerator.java

Ben