Hi !

I'm trying to address the same kind of problem, managing to create holes
in polygons.

Doug Gehringer a �crit :
> 
> > From: "Yadav Khanal" <[EMAIL PROTECTED]>
> >
> > I would appreciate any one who can give me info about creating holes in
> > shape3D object.
> 
> The geometry utilities can be used to define a polygon with holes and then
> decompose the polygon into triangles (see the javadoc for the GeometryInfo
> class).

I tried this and created this code :

/*
 *  Testing program for making holes in polygon using java3d
 *  utilities
 *
 *  Mathieu Marache 24/02/99
 */

import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;

class Holes 
{
  public static void main(String args[])
  {
    /* 
      GeometryInfo(GeometryInfo.POLYGON_ARRAY)
                  
      The stripCounts array indicates how many vertices to use 
      for each contour, and the contourCounts array indicates 
      how many stripCounts entries to use for each polygon. 
      The first contour is the bounding polygon, and subsequent 
      contours are "holes." If contourCounts is left null, the 
      default is one contour per polygon.
    */
                
    GeometryInfo ginfo = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
                
    /*
      Example of usage (taken from the javadoc):
      Triangulator tr = new Triangulator();
      tr.triangulate(ginfo); // ginfo contains the geometry.
      shape.setGeometry(ginfo.getGeometryArray()); // shape is a
Shape3D.
    */
        
    float[] coordinates = 
    {
      // positive contour : a big square
      0, 0, 0,
      5, 0, 0,
      5, 5, 0,
      0, 5, 0,
      // hole : a small square inside the big one
      1, 1, 0,
      2, 1, 0,
      2, 2, 0,
      1, 2, 0
    };
                
    ginfo.setCoordinates(coordinates);
                
    int[] stripCounts = {4,4};
                
    ginfo.setStripCounts(stripCounts);
                
    Triangulator tr = new Triangulator();
    tr.triangulate(ginfo);
                
    if (ginfo.getPrimitive() == GeometryInfo.TRIANGLE_ARRAY) {
      IndexedGeometryArray igarray = ginfo.getIndexedGeometryArray();
      int vertexCount = igarray.getVertexCount();
      System.out.println("vertex  : " + vertexCount);
      int indexCount = igarray.getIndexCount();
      System.out.println("indexes : " + indexCount);

      for ( int i=0;i<indexCount; i+=3 )
      {
        System.out.println("facet " + i/3 + " : ");
        for (int j=i;j<i+3;j++) 
        {
          //double[] coordinates;
          igarray.getCoordinate(igarray.getCoordinateIndex(j),
coordinates);
          System.out.println(coordinates[0] + " , " +   
                             coordinates[1] + " , " +
                             coordinates[2] );
        }
      }
    } 
  }
}

But the result is just triangles corresponding to the two squares... Not
a big square with a hole in it. Am I using it wrong or is triangulator
not yet fully implemented ?


> More complex operations, such as boolean operations on solids, must be done in
> application code.

definetly...

Regards,
Mathieu
�����������������������
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to