{"id":13415261,"url":"https://github.com/speps/LibTessDotNet","last_synced_at":"2025-03-14T22:33:04.286Z","repository":{"id":2686233,"uuid":"3678911","full_name":"speps/LibTessDotNet","owner":"speps","description":"C# port of the famous GLU Tessellator - prebuilt binaries now available in \"releases\" tab","archived":false,"fork":false,"pushed_at":"2022-04-12T10:06:56.000Z","size":1700,"stargazers_count":313,"open_issues_count":9,"forks_count":60,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-10-15T21:23:01.535Z","etag":null,"topics":["c-sharp","polygon","tessellation","triangulation","unity3d"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/LibTessDotNet","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/speps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-10T10:51:55.000Z","updated_at":"2024-09-27T14:30:04.000Z","dependencies_parsed_at":"2022-08-23T20:10:12.755Z","dependency_job_id":null,"html_url":"https://github.com/speps/LibTessDotNet","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speps%2FLibTessDotNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speps%2FLibTessDotNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speps%2FLibTessDotNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/speps%2FLibTessDotNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/speps","download_url":"https://codeload.github.com/speps/LibTessDotNet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243152862,"owners_count":20244662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","polygon","tessellation","triangulation","unity3d"],"created_at":"2024-07-30T21:00:46.160Z","updated_at":"2025-03-14T22:33:04.256Z","avatar_url":"https://github.com/speps.png","language":"C#","readme":"LibTessDotNet [![Build Status](https://ci.appveyor.com/api/projects/status/ypuw4wca67vr5k8u?svg=true)](https://ci.appveyor.com/project/speps/libtessdotnet)\n=============\n\n### Goal\n\nProvide a robust and fast tessellator (polygons with N vertices in the output) for .NET, also does triangulation.\n\n### Requirements\n\n* .NET Standard 2.0 (see [here](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) for more information)\n\n### Features\n\n* Tessellate arbitrary complex polygons\n    - self-intersecting (see \"star-intersect\" sample)\n    - with coincident vertices (see \"clipper\" sample)\n    - advanced winding rules : even/odd, non zero, positive, negative, |winding| \u003e= 2 (see \"redbook-winding\" sample)\n* Custom input\n    - Custom vertex attributes (eg. UV coordinates) with merging callback\n    - Force orientation of input contour (clockwise/counterclockwise, eg. for GIS systems, see \"force-winding\" sample)\n* Choice of output\n    - polygons with N vertices (with N \u003e= 3)\n    - connected polygons (didn't quite tried this yet, but should work)\n    - boundary only (to have a basic union of two contours)\n* Handles polygons computed with [Clipper](http://www.angusj.com/delphi/clipper.php) - an open source freeware polygon clipping library\n* Single/Double precision support\n\n### Screenshot\n\n![Redbook winding example](https://raw.github.com/speps/LibTessDotNet/master/TessBed/Misc/screenshot.png)\n\n### Comparison\n\n![Benchmarks](https://raw.github.com/speps/LibTessDotNet/master/TessBed/Misc/benchmarks.png)\n\n### Build\n\n```\ndotnet build\n```\n\n### Example\n\nFrom [TessExample/Program.cs](https://github.com/speps/LibTessDotNet/blob/master/TessExample/Program.cs)\n\n```csharp\nusing LibTessDotNet;\nusing System;\nusing System.Drawing;\n\nnamespace TessExample\n{\n    class Program\n    {\n        // The data array contains 4 values, it's the associated data of the vertices that resulted in an intersection.\n        private static object VertexCombine(LibTessDotNet.Vec3 position, object[] data, float[] weights)\n        {\n            // Fetch the vertex data.\n            var colors = new Color[] { (Color)data[0], (Color)data[1], (Color)data[2], (Color)data[3] };\n            // Interpolate with the 4 weights.\n            var rgba = new float[] {\n                (float)colors[0].R * weights[0] + (float)colors[1].R * weights[1] + (float)colors[2].R * weights[2] + (float)colors[3].R * weights[3],\n                (float)colors[0].G * weights[0] + (float)colors[1].G * weights[1] + (float)colors[2].G * weights[2] + (float)colors[3].G * weights[3],\n                (float)colors[0].B * weights[0] + (float)colors[1].B * weights[1] + (float)colors[2].B * weights[2] + (float)colors[3].B * weights[3],\n                (float)colors[0].A * weights[0] + (float)colors[1].A * weights[1] + (float)colors[2].A * weights[2] + (float)colors[3].A * weights[3]\n            };\n            // Return interpolated data for the new vertex.\n            return Color.FromArgb((int)rgba[3], (int)rgba[0], (int)rgba[1], (int)rgba[2]);\n        }\n\n        static void Main(string[] args)\n        {\n            // Example input data in the form of a star that intersects itself.\n            var inputData = new float[] { 0.0f, 3.0f, -1.0f, 0.0f, 1.6f, 1.9f, -1.6f, 1.9f, 1.0f, 0.0f };\n\n            // Create an instance of the tessellator. Can be reused.\n            var tess = new LibTessDotNet.Tess();\n\n            // Construct the contour from inputData.\n            // A polygon can be composed of multiple contours which are all tessellated at the same time.\n            int numPoints = inputData.Length / 2;\n            var contour = new LibTessDotNet.ContourVertex[numPoints];\n            for (int i = 0; i \u003c numPoints; i++)\n            {\n                // NOTE : Z is here for convenience if you want to keep a 3D vertex position throughout the tessellation process but only X and Y are important.\n                contour[i].Position = new LibTessDotNet.Vec3(inputData[i * 2], inputData[i * 2 + 1], 0);\n                // Data can contain any per-vertex data, here a constant color.\n                contour[i].Data = Color.Azure;\n            }\n            // Add the contour with a specific orientation, use \"Original\" if you want to keep the input orientation.\n            tess.AddContour(contour, LibTessDotNet.ContourOrientation.Clockwise);\n\n            // Tessellate!\n            // The winding rule determines how the different contours are combined together.\n            // See http://www.glprogramming.com/red/chapter11.html (section \"Winding Numbers and Winding Rules\") for more information.\n            // If you want triangles as output, you need to use \"Polygons\" type as output and 3 vertices per polygon.\n            tess.Tessellate(LibTessDotNet.WindingRule.EvenOdd, LibTessDotNet.ElementType.Polygons, 3, VertexCombine);\n\n            // Same call but the last callback is optional. Data will be null because no interpolated data would have been generated.\n            //tess.Tessellate(LibTessDotNet.WindingRule.EvenOdd, LibTessDotNet.ElementType.Polygons, 3); // Some vertices will have null Data in this case.\n\n            Console.WriteLine(\"Output triangles:\");\n            int numTriangles = tess.ElementCount;\n            for (int i = 0; i \u003c numTriangles; i++)\n            {\n                var v0 = tess.Vertices[tess.Elements[i * 3]].Position;\n                var v1 = tess.Vertices[tess.Elements[i * 3 + 1]].Position;\n                var v2 = tess.Vertices[tess.Elements[i * 3 + 2]].Position;\n                Console.WriteLine(\"#{0} ({1:F1},{2:F1}) ({3:F1},{4:F1}) ({5:F1},{6:F1})\", i, v0.X, v0.Y, v1.X, v1.Y, v2.X, v2.Y);\n            }\n            Console.ReadLine();\n        }\n    }\n}\n```\n\n### Notes\n\n* When using `ElementType.BoundaryContours`, `Tess.Elements` will contain a list of ranges `[startVertexIndex, vertexCount]`.\n  Those ranges are to used with `Tess.Vertices`.\n\n### TODO\n\n* No allocations with the same input twice, all coming from pool\n* Any suggestions are welcome ;)\n\n### License\n\nSGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)\nMore information in LICENSE.txt.\n\n### Links\n* [Reference implementation](http://oss.sgi.com/projects/ogl-sample) - the original SGI reference implementation\n* [libtess2](https://github.com/memononen/libtess2) - Mikko Mononen cleaned up the original GLU tesselator\n* [Poly2Tri](http://code.google.com/p/poly2tri/) - another triangulation library for .NET (other ports also available)\n    - Does not support polygons from Clipper, more specifically vertices with same coordinates (coincident)\n* [Clipper](http://www.angusj.com/delphi/clipper.php) - an open source freeware polygon clipping library\n","funding_links":[],"categories":["Graphics","图形","C#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspeps%2FLibTessDotNet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspeps%2FLibTessDotNet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspeps%2FLibTessDotNet/lists"}