Conversation
- Add TINYOBJLOADER_TRIANGULATE_* constants for method selection - Add fan triangulation method (simple triangle fan from vertex 0) - Make earclip and mapbox earcut selectable at runtime via ObjReaderConfig - Add preserve_quads option to keep quad faces and only triangulate 5+ ngons - Refactor LoadObj internals via LoadObjEx for clean v2 API plumbing - Maintain full backward compatibility for v1 LoadObj API Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
|
@copilot Implement MWT_Greedy_Algorithm https://github.com/drmasifhabib/MWT_Greedy_Algorithm |
Add Minimum Weight Triangulation (MWT) greedy algorithm based on drmasifhabib/MWT_Greedy_Algorithm. The algorithm: - Finds shortest external edge and starts from there - For each window of 4 consecutive vertices, compares two possible diagonals and picks the shorter one to split off a triangle - Tries both winding directions and picks the result with lower total diagonal weight (directional optimization) Selectable via config.triangulation_method = "mwt" or "greedy". Adds TINYOBJLOADER_TRIANGULATE_MWT constant. Includes 5 new test cases covering quad, pentagon, hexagon, preserve_quads, and file-based loading. Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Implemented the MWT Greedy Algorithm from drmasifhabib/MWT_Greedy_Algorithm in commit d174bce. The algorithm is available as a new triangulation method via It implements the directional greedy approach:
Added |
|
@copilot make triangulation implementation separate file so that we can test the algorithm standalone manner before integrating to tinyobjloader. put files to sandbox/triangulation/ |
…n/ files Create self-contained header (triangulation.h) with fan, earclip, and MWT greedy algorithms that can be tested independently of tinyobjloader. Add standalone test program (main.cc) with 24 test cases covering all three algorithms, 3D vertices, edge cases, and weight optimization. Add Makefile for standalone build/test. Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Created
The algorithms match the implementations in |
|
@copilot Implement our own Sweep-Line and Earcut(with zcurve) algorithm and also make benchmark program to test each triangulation algorithm. |
…mark Implement two new triangulation algorithms in sandbox/triangulation/: - **Sweep-Line**: Monotone polygon decomposition via sweep-line event processing (vertex classification, status structure with helpers), recursive polygon splitting at diagonals, and stack-based monotone polygon triangulation. - **Earcut Z-Curve**: Enhanced ear clipping using Z-order curve (Morton code) spatial indexing. Doubly-linked circular list with Z-sorted auxiliary list for fast point-in-triangle rejection. Falls back to full scan when Z-filtered pass gets stuck. Also add: - benchmark.cc: Measures all 5 algorithms (fan, earclip, MWT, sweep-line, earcut-Z) across regular n-gons, random convex, and star-shaped concave polygons of 4 to 1024 vertices. - 14 new test cases for the two new algorithms. - Updated Makefile with `make bench` target. Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
Implemented in commits 2cd27a7 and 57156fa. Added to Sweep-Line (
Earcut Z-Curve (
Benchmark (
14 new test cases (38 total standalone tests), all passing. 0 CodeQL alerts. |
The
ObjReaderConfig::triangulation_methodfield was declared but never used. This PR makes it functional, adds apreserve_quadsoption for quad+triangle decomposition, implements the MWT (Minimum Weight Triangulation) greedy algorithm, and adds standalone sweep-line and earcut Z-curve triangulation algorithms with a benchmark program.API changes
triangulation_methodnow dispatches at runtime between:"fan"/"simple"— triangle fan from vertex 0 (fastest, naive)"earclip"— built-in ear clipping (default, robust)"earcut"/"mapbox"— mapbox earcut (requiresTINYOBJLOADER_USE_MAPBOX_EARCUT)"mwt"/"greedy"— Minimum Weight Triangulation greedy algorithm with directional optimization (near-optimal triangulation minimizing total diagonal length, based on drmasifhabib/MWT_Greedy_Algorithm)preserve_quads(bool, defaultfalse) — keep quad faces as-is, only triangulate 5+ ngons"simple"(unused) to"earclip"(matches actual default behavior)LoadObj(..., bool triangulate)API is unchanged;truemaps to earclipMWT Greedy Algorithm
The MWT greedy algorithm implements the directional greedy approach described in "A Linear-Time Greedy Algorithm with Directional Optimization for Near-Optimal Minimum Weight Triangulation of Convex Polygons":
Standalone triangulation sandbox
Five triangulation algorithms are extracted into standalone files under
sandbox/triangulation/for independent testing and evaluation without any tinyobjloader dependency:sandbox/triangulation/triangulation.h— self-contained header-only library with five algorithms:sandbox/triangulation/main.cc— 38 standalone test cases covering all five algorithms across triangles through octagons, concave polygons, 3D vertices, edge cases, and MWT weight optimization verificationsandbox/triangulation/benchmark.cc— benchmark program measuring all 5 algorithms across regular n-gons, random convex, and star-shaped concave polygons of 4 to 1024 vertices (make bench)sandbox/triangulation/Makefile— build withmake test(tests) ormake bench(benchmark)Internals
exportGroupsToShapeandLoadObjInternaltakeunsigned int tri_method, bool preserve_quadsinstead ofbool triangulateLoadObjExstatic helpers thread extended params from v2ObjReaderAPI without changing v1 signaturesparseTriangulationMethod()converts config string toTINYOBJLOADER_TRIANGULATE_*constant once per loadTINYOBJLOADER_TRIANGULATE_MWTconstant (value 4)Usage
Tests
15 new tinyobjloader test cases: fan/earclip/mwt on quads and pentagons, mwt on hexagons, preserve_quads with multiple methods, no-triangulation passthrough, default config values, string aliases, v1 API backward compat, and mwt file-based loading. Plus 38 standalone tests in
sandbox/triangulation/covering all five algorithms.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.