Unit CastleTriangulate

Classes, Interfaces, Objects and Records
Constants

Description

Triangulating a polygon.

Uses

Overview

Functions and Procedures

procedure TriangulateFace( FaceIndices: PLongintArray; Count: Integer; Vertices: PVector3Array; VerticesCount: Integer; TriangulatorProc: TTriangulatorProc; AddToIndices: Longint); overload;
procedure TriangulateFace( FaceIndices: PLongintArray; Count: Integer; Vertices: TGetVertexFromIndexFunc; TriangulatorProc: TTriangulatorProc; AddToIndices: Longint); overload;
procedure TriangulateConvexFace(Count: Integer; TriangulatorProc: TTriangulatorProc; AddToIndices: Longint);
function IndexedPolygonNormal( Indices: PLongintArray; IndicesCount: Integer; Vertices: PVector3Array; const VerticesCount: Integer; const ResultForIncorrectPoly: TVector3; const Convex: boolean): TVector3;

Types

TTriangulatorProc = procedure (const Tri: TVector3Integer) of object;

Variables

LogTriangulation: boolean;

Description

Functions and Procedures

procedure TriangulateFace( FaceIndices: PLongintArray; Count: Integer; Vertices: PVector3Array; VerticesCount: Integer; TriangulatorProc: TTriangulatorProc; AddToIndices: Longint); overload;

Triangulate potentially non-convex face.

FaceIndices[0]..FaceIndices[Count - 1] are indices to the Vertices array. They describe the outline of the polygon (face). You can pass FaceIndices = Nil, this is understood that indices are just 0..Count - 1 (in other words, it's equivalent to setting FaceIndices[0] = 0, FaceIndices[1] = 1 etc.).

For each resulting triangle we will call TriangulatorProc with Tri (first param of TriangulatorProc) containing indices to FaceIndices[] array. We return indices to FaceIndices (not ready vectors from Vertices, not even indices to Vertices[] array) to allow the caller to obtain all information about the triangle. In the simple case, you can just use Vertices[FaceIndices[Tri[0..2]]] to obtain your triangle, in the more sophisticated cases you have other options to e.g. extract other vertex information from whatever data you have (see e.g. VRML/X3D IndexedFaceSet renderer).

Generated triangles have the same orientation (normal from ccw etc.) as original polygon. This also means that if you're sure that your polygon is planar (and it should be — although we handle gracefully small deviations from planar, this procedure doesn't actually handle arbitrary (dis)located 3D data) then normal vector of all your triangles is the same.

Note that you generally shouldn't use this procedure if you know that your polygon is convex. Then using this is a waste of time, after all convex polygons can be triangulated much easier. You can use TriangulateConvexFace in this case, which has deliberately very similar interface to this procedure.

Parameters
TriangulatorProcData
Is just passed unmodified to every TriangulatorProc call (as the second parameter). This is standard method to pass whatever data to your callback.
AddToIndices
Indexes returned in Tri[0..2] are all incremented by AddToIndices (which may also be negative), this is useful if your FaceIndices is actually a pointer to the middle of some larger indexes array. Just pass 0 if you don't want this.
See also
TriangulateConvexFace
Triangulate convex polygon.
procedure TriangulateFace( FaceIndices: PLongintArray; Count: Integer; Vertices: TGetVertexFromIndexFunc; TriangulatorProc: TTriangulatorProc; AddToIndices: Longint); overload;
 
procedure TriangulateConvexFace(Count: Integer; TriangulatorProc: TTriangulatorProc; AddToIndices: Longint);

Triangulate convex polygon.

This performs very easy triangulation. It has deliberately similar interface to TriangulateFace, so it can be used as drop-in replacement for TriangulateFace, when you know that your face is convex.

Note that it doesn't even need to know FaceIndices or Vertices, it's enough to know Count.

This also guarantees consequent triangles orientation, like TriangulateFace.

See also
TriangulateFace
function IndexedPolygonNormal( Indices: PLongintArray; IndicesCount: Integer; Vertices: PVector3Array; const VerticesCount: Integer; const ResultForIncorrectPoly: TVector3; const Convex: boolean): TVector3;

Calculate normal vector of possibly concave polygon.

Types

TTriangulatorProc = procedure (const Tri: TVector3Integer) of object;
 

Variables

LogTriangulation: boolean;

Write to Log a lot of comments how the triangulation goes. Useful for examples/visualize_triangulation/ .


Generated by PasDoc 0.16.0.