Skip to content

v0.1.0: Mesh.simplified(_:) via vendored meshoptimizer v1.1

Choose a tag to compare

@gsdali gsdali released this 29 Apr 09:58
· 9 commits to main since this release

v0.1.0 — Mesh.simplified(_:) via vendored meshoptimizer

Initial release. Quadric-error-metric (QEM) mesh decimation backed by meshoptimizer v1.1 (MIT, vendored under Sources/OCCTMeshOptimizer/src/meshoptimizer/).

import OCCTSwift
import OCCTSwiftMesh

let result = mesh.simplified(.init(targetTriangleCount: 5_000))
// → SimplifiedMesh(mesh:, beforeTriangleCount:, afterTriangleCount:, hausdorffDistance:)

Public API

  • Mesh.SimplifyOptions — exact targetTriangleCount or targetReduction ratio (mutually exclusive), optional maxHausdorffDistance cap, preserveBoundary for free-edge preservation.
  • Mesh.simplified(_ options:) -> SimplifiedMesh? — failable; returns nil for invalid options or empty inputs.
  • SimplifiedMesh — wraps the decimated Mesh with beforeTriangleCount, afterTriangleCount, and absolute hausdorffDistance in input mesh units.

Bridge ABI (OCCTMeshOptimizer.h)

C entry points exposed for any consumer that wants to operate on raw vertex/index buffers without the OCCTSwift Mesh wrap:

  • OCCTMeshSimplify — runs the QEM pass, compacts orphan vertices via meshopt_optimizeVertexFetchRemap + remap functions, reports absolute Hausdorff distance via meshopt_SimplifyErrorAbsolute.
  • OCCTMeshSimplifyFreeResult — releases caller-owned output buffers.
  • OCCTMeshSimplifyScale — bbox-diagonal scale factor for callers that work in relative-error units.

Requirements

  • OCCTSwift v0.156.2 or later — needed for the public Mesh(vertices:normals:indices:) initializer (OCCTSwift#94).
  • macOS 12+ / iOS 15+, Swift 6, C++17.

Algorithm details

See docs/algorithms/decimation.md for design notes: vertex compaction strategy, Hausdorff units, edge cases (preserveTopology, target overshoot, empty input), performance characteristics, and the vendored-version pin. Re-vendoring procedure in docs/VENDORING.md.

Tests

16 tests in 5 suites — input validation rejection, bridge end-to-end against a sphere mesh, scale function, public API integration (round-trips simplified arrays back through OCCTSwift.Mesh). swift build && swift test clean.

Closes #1.