< Zurück | Inhalt | Weiter >

15.2 Triangulator, normal vector generator, stripifier

Triangulation is a mechanism to convert arbitrary polygons to triangular surfaces for rendering. The com.sun.j3d.utils.geometry.Triangulator class can be used not only to convert an arbitrary n−sided polygon (which does not have to be planar) to triangul ar surfaces, but also to create holes in the generated composite surface. To use the Triangulator, put your vertex coordinates into a double or float

array. This coordinate array should first define the outer boundary of the polygon, using counterclockwi se winding.


Then define any polygons that are to be excluded from the generated composite triangular surface. This simple example in figure 15.1 defines two contours: the outer polygon and one hole. The stripCountArray is an array of integers that delineates one con tour from the next. In figure 15.1, the stripCountArray would be


int[] stripCountArray = {4,3};


image


Figure 15.1 Counterclockwise winding for defining a polygon and a hole for Triangulation


image


Figure 15.2 Output from TriangulatorTest: The surface generated rendered both as a solid (left) and as a wireframe (right)


The first contour (A,B,C,D) contains four vertices, and the hole (F,G,H) contains three vertices.


The Triangulator class is not very well documented, so the following example should illustrate the concepts of polygon triangulation using the Triangulator class. In particular, the contourCountArray element is misleadingly documented and should be set t o the number of contours (1

+ the number of holes). This is always the same as the length of the stripCountArray. Why the

contourCountArray is necessary is not clear.


 

From TriangulatorTest.java