PolygonFace.TurnInternalEdgeOffset
 
 
 

PolygonFace.TurnInternalEdgeOffset operator

Introduced

v8.0 (2010)

Description

Returns the current starting node used by the tesselator for this polygon face.

By default a polygon is triangulated using a triangle fan starting at vertex #0. So the triangulation is as follow: [0,1,2], [0,2,3], [0,3,4], ..., [0,N-2,N-1] where N is the number of nodes in the polygon. So for a quad the fan has only two triangles: [0,1,2] and [0,2,3].

You can apply the TurnEdgeOp operator to change the starting node of that triangle fan so that the triangulation becomes: [1,2,3], [1,3,4], ..., [1,N-1,0] (or [2,3,4], [2,4,5], ..., [2,0,1] the second time...). This is particularly useful for non-planar polygons where the "invisible" edges cause visible discontinuities in the shading.

Notice that for the case of concave polygons the tesselator might decide to ignore this offset in order to create a triangulation that doesn't create triangles outside of the polygon area.

C# Syntax

// get accessor
UInt32 rtn = PolygonFace.TurnInternalEdgeOffset;

Examples

JScript Example

/*
        This example demonstrates how to set and use the turn edge offset.
*/
NewScene( null, false );
CreatePrim("Grid", "MeshSurface", null, null);
SetValue("grid.polymsh.geom.subdivu", 2, null);
SetValue("grid.polymsh.geom.subdivv", 2, null);
var GridGeom = GetValue( "Grid" ).ActivePrimitive.Geometry;
var Polygons = GridGeom.Polygons;
var Polygon = Polygons.Item(3);
var PolygonVertices = Polygon.Vertices;
var TriangleSubIndices = Polygon.TriangleSubIndexArray.toArray();
Application.LogMessage( "Polygon #3 is defined with the following vertices: " + 
                                                PolygonVertices.Item(0).Index + ", " + 
                                                PolygonVertices.Item(1).Index + ", " + 
                                                PolygonVertices.Item(2).Index + ", " + 
                                                PolygonVertices.Item(3).Index );
Application.LogMessage( "Polygon #3 has the following two triangles before applying the TurnEdge operator: [" + 
                                                PolygonVertices.Item(TriangleSubIndices[0]).Index + ", " +
                                                PolygonVertices.Item(TriangleSubIndices[1]).Index + ", " +
                                                PolygonVertices.Item(TriangleSubIndices[2]).Index + "] and [" +
                                                PolygonVertices.Item(TriangleSubIndices[3]).Index + ", " +
                                                PolygonVertices.Item(TriangleSubIndices[4]).Index + ", " +
                                                PolygonVertices.Item(TriangleSubIndices[5]).Index + "]." );
ApplyOp("TurnEdgeOp", "grid.poly[LAST]", 3, siPersistentOperation, null, 0);
var GridGeom = GetValue( "Grid" ).ActivePrimitive.Geometry;
var Polygons = GridGeom.Polygons;
var Polygon = Polygons.Item(3);
var PolygonVertices = Polygon.Vertices;
var TriangleSubIndices = Polygon.TriangleSubIndexArray.toArray();
Application.LogMessage( "Polygon #3 has the following two triangles after applying the TurnEdge operator: [" + 
                                                PolygonVertices.Item(TriangleSubIndices[0]).Index + ", " +
                                                PolygonVertices.Item(TriangleSubIndices[1]).Index + ", " +
                                                PolygonVertices.Item(TriangleSubIndices[2]).Index + "] and [" +
                                                PolygonVertices.Item(TriangleSubIndices[3]).Index + ", " +
                                                PolygonVertices.Item(TriangleSubIndices[4]).Index + ", " +
                                                PolygonVertices.Item(TriangleSubIndices[5]).Index + "]" );
var offset = Polygon.TurnInternalEdgeOffset; // this should be 1 since with only turned the polygon edges once.
Application.LogMessage( "This triangulation is equivalent to that of a polygon defined using the following vertices: " + 
                                                PolygonVertices.Item( ( 0 + offset ) % 4 ).Index + ", " + 
                                                PolygonVertices.Item( ( 1 + offset ) % 4 ).Index + ", " + 
                                                PolygonVertices.Item( ( 2 + offset ) % 4 ).Index + ", " + 
                                                PolygonVertices.Item( ( 3 + offset ) % 4 ).Index );
// Expected results:
// INFO : Polygon #3 is defined with the following vertices: 4, 5, 8, 7
// INFO : Polygon #3 has the following two triangles before applying the TurnEdge operator: [4, 5, 8] and [4, 8, 7].
// INFO : Polygon #3 has the following two triangles after applying the TurnEdge operator: [5, 8, 7] and [5, 7, 4]
// INFO : This triangulation is equivalent to that of a polygon defined using the following vertices: 5, 8, 7, 4

See Also

PolygonFace.Vertices PolygonFace.Nodes