org.critterai.nmgen
Class PolyMeshField

java.lang.Object
  extended by org.critterai.nmgen.BoundedField
      extended by org.critterai.nmgen.PolyMeshField

public final class PolyMeshField
extends BoundedField

Represents a set of related convex polygons within a bounded field.

The polygons are usually connected (share edges), but are expected to not intersect.

The data within this class is unprotected. So care must be taken.

See Also:
PolyMeshFieldBuilder

Field Summary
static int NULL_INDEX
          Represents an index value for a null (non-existent) vertex.
 int[] polyRegions
          Holds membership region data for each polygon in the form (regionID).
 int[] polys
          Holds flattened polygon index and neighbor information.
 int[] verts
          The vertices that make up the field in the form (x, y, z).
 
Constructor Summary
PolyMeshField(float[] gridBoundsMin, float[] gridBoundsMax, float cellSize, float cellHeight, int maxVertsPerPoly)
          Consructor
 
Method Summary
 int getPolyRegion(int polyIndex)
          Gets the region ID of the polygon.
 int[] getPolyVerts(int polyIndex)
          Gets an array containing the vertices of the polygon.
 int maxVertsPerPoly()
          The maximum vertices per polygon held within the polys array.
 int polyCount()
          The number of polygons in the polys array.
 int vertCount()
          The number of vertices in the verts array.
 
Methods inherited from class org.critterai.nmgen.BoundedField
boundsMax, boundsMin, cellHeight, cellSize, depth, getDirOffsetDepth, getDirOffsetWidth, gridIndex, isInBounds, overlaps, resetBounds, resetCellInfo, setBounds, setBounds, setBoundsMax, setBoundsMin, setCellHeight, setCellSize, width
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_INDEX

public static final int NULL_INDEX
Represents an index value for a null (non-existent) vertex.

This is required since polygons held within polys are variable in size. So all entries for polygons within polys that have fewer vertices than maxVertsPerPoly() are padded with this value. See polys for more information.

See Also:
Constant Field Values

verts

public int[] verts
The vertices that make up the field in the form (x, y, z). Value defaults to null.


polys

public int[] polys
Holds flattened polygon index and neighbor information. Value defaults to null.

Where mvpp = maxVertsPerPoly():

Example:

If mvpp = 6, the polygon has 4 vertices and 2 neighbor connections.
Then for (1, 3, 4, 8, NULL_INDEX, NULL_INDEX, 18, NULL_INDEX, 21, NULL_INDEX, NULL_INDEX, NULL_INDEX)
(1, 3, 4, 8) defines the polygon.
Polygon 18 shares edge 1->3.
Polygon 21 shares edge 4->8.
Edges 3->4 and 8->1 are border edges. (Not shared with any other polygon.)


polyRegions

public int[] polyRegions
Holds membership region data for each polygon in the form (regionID). Value defaults to null.

Constructor Detail

PolyMeshField

public PolyMeshField(float[] gridBoundsMin,
                     float[] gridBoundsMax,
                     float cellSize,
                     float cellHeight,
                     int maxVertsPerPoly)
              throws IllegalArgumentException
Consructor

Parameters:
gridBoundsMin - The minimum bounds of the field in the form (minX, minY, minZ).
gridBoundsMax - The maximum bounds of the field in the form (maxX, maxY, maxZ).
cellSize - The size of the cells. (The grid that forms the base of the field.)
cellHeight - The height increment of the field.
maxVertsPerPoly - The maximum vertices per polygon. Value will be auto-clamped to >=3.
Throws:
IllegalArgumentException - If the bounds are null or the wrong size.
Method Detail

getPolyRegion

public int getPolyRegion(int polyIndex)
Gets the region ID of the polygon.

Parameters:
polyIndex - The index of the polygon.
Returns:
The region ID of the polygon, or -1 if the polygon index is invalid.

getPolyVerts

public int[] getPolyVerts(int polyIndex)
Gets an array containing the vertices of the polygon.

This is a costly convenience operation.

Parameters:
polyIndex - The index of the polygon.
Returns:
An array containing the vertices of the polygon.

maxVertsPerPoly

public int maxVertsPerPoly()
The maximum vertices per polygon held within the polys array. (maxVertsPerPoly() * 2) represents the stride of the array.

This value is informational only. There is no enforcement.

Returns:
The maximum vertices per polygon held within the polys array.

polyCount

public int polyCount()
The number of polygons in the polys array.

Returns:
The number of vertices in the verts array.

vertCount

public int vertCount()
The number of vertices in the verts array.

Returns:
The number of vertices in the verts array.


Project Home and Source Code

Copyright 2010 Stephen Pratt. All rights reserved. Use is subject to license terms.