@@ -702,60 +702,15 @@ public static float4 Tessellate(Allocator allocator, NativeArray<float2> points,
702702 if ( points . Length < 3 || points . Length >= kMaxVertexCount )
703703 return ret ;
704704
705- // Ensure inputs form a proper PlanarGraph.
706- bool validGraph = false , handleEdgeCase = false ;
707- int pgEdgeCount = 0 , pgPointCount = 0 ;
708- NativeArray < int2 > pgEdges = new NativeArray < int2 > ( edges . Length * 8 , allocator ) ;
709- NativeArray < float2 > pgPoints = new NativeArray < float2 > ( points . Length * 4 , allocator ) ;
710-
711- // Valid Edges and Paths, correct the Planar Graph. If invalid create a simple convex hull rect.
712- if ( 0 != edges . Length )
713- {
714- validGraph = PlanarGraph . Validate ( allocator , points , points . Length , edges , edges . Length , ref pgPoints , ref pgPointCount , ref pgEdges , ref pgEdgeCount ) ;
715- }
716-
717- // Fallbacks are now handled by the Higher level packages. Enable if UTess needs to handle it.
718- // #if UTESS_QUAD_FALLBACK
719- // if (!validGraph)
720- // {
721- // pgPointCount = 0;
722- // handleEdgeCase = true;
723- // ModuleHandle.Copy(points, pgPoints, points.Length);
724- // GraphConditioner(points, ref pgPoints, ref pgPointCount, ref pgEdges, ref pgEdgeCount, false);
725- // }
726- // #else
727-
728- // If its not a valid Graph simply return back input Data without triangulation instead of going through UTess (pointless wasted cpu cycles).
729- if ( ! validGraph )
730- {
731- outEdgeCount = edges . Length ;
732- outVertexCount = points . Length ;
733- ModuleHandle . Copy ( edges , outEdges , edges . Length ) ;
734- ModuleHandle . Copy ( points , outVertices , points . Length ) ;
735- }
736-
737- // Do a proper Delaunay Triangulation if Inputs are valid.
738- if ( pgPointCount > 2 && pgEdgeCount > 2 )
739- {
740- // Tessellate does not add new points, only PG and SD does. Assuming each point creates a degenerate triangle, * 4 is more than enough.
741- NativeArray < int > tsIndices = new NativeArray < int > ( pgPointCount * 8 , allocator ) ;
742- NativeArray < float2 > tsVertices = new NativeArray < float2 > ( pgPointCount * 4 , allocator ) ;
743- int tsIndexCount = 0 , tsVertexCount = 0 ;
744- validGraph = Tessellator . Tessellate ( allocator , pgPoints , pgPointCount , pgEdges , pgEdgeCount , ref tsVertices , ref tsVertexCount , ref tsIndices , ref tsIndexCount ) ;
745- if ( validGraph )
746- {
747- // Copy Out
748- TransferOutput ( pgEdges , pgEdgeCount , ref outEdges , ref outEdgeCount , tsIndices , tsIndexCount , ref outIndices , ref outIndexCount , tsVertices , tsVertexCount , ref outVertices , ref outVertexCount ) ;
749- if ( handleEdgeCase == true )
750- outEdgeCount = 0 ;
751- }
752- tsVertices . Dispose ( ) ;
753- tsIndices . Dispose ( ) ;
754- }
755-
756- // Dispose Temp Memory.
757- pgPoints . Dispose ( ) ;
758- pgEdges . Dispose ( ) ;
705+ // Tessellate does not add new points, only PG and SD does. Assuming each point creates a degenerate triangle, * 4 is more than enough.
706+ NativeArray < int > tsIndices = new NativeArray < int > ( points . Length * 8 , allocator ) ;
707+ NativeArray < float2 > tsVertices = new NativeArray < float2 > ( points . Length * 4 , allocator ) ;
708+ int tsIndexCount = 0 , tsVertexCount = 0 ;
709+ var doneGeometry = Tessellator . Tessellate ( allocator , points , points . Length , edges , edges . Length , ref tsVertices , ref tsVertexCount , ref tsIndices , ref tsIndexCount ) ;
710+ if ( doneGeometry )
711+ TransferOutput ( edges , edges . Length , ref outEdges , ref outEdgeCount , tsIndices , tsIndexCount , ref outIndices , ref outIndexCount , tsVertices , tsVertexCount , ref outVertices , ref outVertexCount ) ;
712+ tsVertices . Dispose ( ) ;
713+ tsIndices . Dispose ( ) ;
759714 return ret ;
760715 }
761716 }
0 commit comments