Imported from cdcseacave/halfmesh (
src/AGENTS.md). Install upstream withnpx skills add cdcseacave/halfmesh --skill src. Copyright stays with the author.
AGENTS.md — src (implementation)
Implementation TUs for the public API. Namespace halfmesh::; file-local helpers go in
anonymous namespaces. See root AGENTS.md for conventions.
Numerics are load-bearing. Every formula, threshold and iteration count here is
covered by golden fixtures and quality bounds, so BY DEFAULT preserve them and don't
casually "improve" numerics. A deliberate change needs the same level of evidence the
current value has: golden fixtures regenerated with a reviewed delta report, plus the
quality/invariant bounds in tests/ (see tests/AGENTS.md).
TU map
The Mesh class is split across several TUs by concern:
HalfMesh.cpp— half-edge build/connectivity (flat open-addressing edge pairing), parity-agnosticConnectBorders,EnumerateHoles,ConnectedComponents, edge collapse (ERemove) + validity predicates, and the in-place face opsFAdd/FAddDisk/FRemoveBulk(undo-log rollback, pinch splitting).Mesh.cpp—Meshcore: the representation contract (InvalidateFaces/SyncFaces/Validate*/pipeline scope), normals, area, AABB, vertex/face adjacency,ListHalfEdges, edit primitives (RemoveFaces/RemoveUnreferencedVertices…).MeshIO.cpp— PLY/glTF load/save, texture & texcoord handling, seam export.MeshRepair.cpp— RemoveDuplicate/Degenerate faces, FixNonManifold, RemoveSmallComponents, RemoveSpuriousComponents, RemoveSpikes. Repair entry points that work on both representations dispatch to an*Arrays/*HalfEdgearm.MeshSimplify.cpp—Mesh::Simplify: QEM edge-collapse decimation (priority/exact mode and the fast threshold-sweep mode; setup is parallelized); the file has explanatory comments on the QEM math, the boundary discontinuity quadric, and the swap-with-last compaction.MeshRemesh.cpp—RemeshIsotropic(flip/collapse/relocate/refine + fairing); parallel tangential smoothing, surface queries run on the BVH. Shared helpers inMeshRemeshShared.{h,cpp}.MeshHoles.cpp—CloseHolesvia Liepa min-weight triangulation (O(n^3) DP) + refine + fairing, andRemoveVerticesAndFill(decimating variant, no refine); holes are filled in parallel and attached withHalfMesh::FAddDisk. Keep the Liepa / pmp-library algorithm attribution comment block at the top of the file.MeshSmooth.cpp—Mesh::SmoothHCLaplacian: HC (anti-shrink) Laplacian smoothing (Vollmer'99).Mesh::SmoothTaubin: Taubin'95 lambda|mu band-pass — smooths aggressively at ~zero shrinkage (needs more iterations).Mesh::Smooth(iterations, method): unified dispatcher over both smoothers (Taubin default), each run with its per-function default parameters.Parametrize.cpp— UV flattening: per chart (LSCM/Tutte init → SLIM/ARAP), parallelized in dependency-free waves.AtlasCharting.cpp— developable D-Charts chart segmentation (SegmentCharts) — cone-Lloyd relaxation + developable merge + flatten-and-bisect flip repair.AtlasPacking.cpp— uniform texel-density normalization + the two-tier (skyline min-waste head / shelf tail) first-fit multi-page packer, shared byPackAtlasand the mesh-independentPackRectanglesinRectPacking.h.TriangleKDTree.cpp— median-split KD-tree (build + nearest-point/ray queries with branch-and-bound pruning); commented.TriangleBVH.cpp— binned-SAH BVH build with a bounded traversal stack; nearest-point/ray queries take an optionalmax_distbound andNearestPointahint_facewarm start.ParallelFor.h— internal shared parallel-for pool helper (ParallelForPool) used by the parallel phases above.ChartFlattenCache.h— internal flip-repair→ParametrizeChartsflatten-artifact bridge (cache keyed by chart face-identity); consumed insideGenerateAtlas/Parametrizeonly.Version.cpp— version strings.GltfImageCodec.cpp/.h— the OpenCV-backedGltfLoadImageData/GltfWriteImageDatatinygltf callbacks (tinygltf is built withTINYGLTF_NO_STB_IMAGE[_WRITE], so it ships no codec of its own), plusSetGltfImageCodec(), which everytinygltf::TinyGLTFcontext must call before touching images (MeshIO.cppandtests/MeshIOTest.cppdo). This is also the single TU that#definesTINYGLTF_IMPLEMENTATION— the two are fused because the writer needs tinygltf helpers that exist only behind that macro.
Conventions specific to src/
- Include own headers as
#include <halfmesh/Xxx.h>. ASSERT(expr)for invariants (debug-only; no comparison-variant macros).- After edits, build + run the matching
tests/*Test.cpp; the algorithm files also have golden + quality coverage (seetests/AGENTS.md).