fromContour method

Polygon fromContour(
  1. List<Vector3> points
)

Creates the polygon based on the given array of points in 3D space. The method assumes the contour (the sequence of points) is defined in CCW order.

Implementation

Polygon fromContour(List<Vector3> points ) {
	final edges = [];

	if ( points.length < 3 ) {
		yukaConsole.error( 'YUKA.Polygon: Unable to create polygon from contour. It needs at least three points.' );
		return this;
	}

	for ( int i = 0, l = points.length; i < l; i ++ ) {
		final edge = HalfEdge( points[ i ] );
		edges.add( edge );
	}

	// link edges
	for ( int i = 0, l = edges.length; i < l; i ++ ) {
		HalfEdge? current, prev, next;

		if ( i == 0 ) {
			current = edges[ i ];
			prev = edges[ l - 1 ];
		 	next = edges[ i + 1 ];
		}
      else if ( i == ( l - 1 ) ) {
			current = edges[ i ];
		 	prev = edges[ i - 1 ];
			next = edges[ 0 ];
		}
      else {
		 	current = edges[ i ];
			prev = edges[ i - 1 ];
			next = edges[ i + 1 ];
		}

		current?.prev = prev;
		current?.next = next;
		current?.polygon = this;
	}

	//
	edge = edges[ 0 ];

	//
	plane.fromCoplanarPoints( points[ 0 ], points[ 1 ], points[ 2 ] );

	return this;
}