Contents

secondmouseau/occtswift

πŸ“– Documentation & cookbook: <https://secondmouseau.github.io/OCCTSwift/>

Quick Start

Installation

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/SecondMouseAU/OCCTSwift.git", from: "1.0.0")
]

The package ships a pre-built OCCT.xcframework as a release asset, so no source build of OCCT is required for end users.

Usage

import OCCTSwift

// Primitives
let box = Shape.box(width: 10, height: 5, depth: 3)
let cylinder = Shape.cylinder(radius: 2, height: 10)

// Boolean operations
let result = box - cylinder      // subtract
let combined = box + cylinder    // union
let common = box & cylinder      // intersect

// Modifications
let filleted = result.filleted(radius: 0.5)
let shelled = filleted.shelled(thickness: -0.3)

// Export
try Exporter.writeSTEP(shape: shelled, to: stepURL)
try Exporter.writeSTL(shape: shelled, to: stlURL, deflection: 0.05)

Ecosystem

OCCTSwift is the kernel of a layered family of packages, all SemVer-stable from v1.0.0 (OCCT 8.0.0 GA cohort, May 2026). See docs/ecosystem.md for an architecture map and "when to use which" guidance.

| Package | Role | |---------|------| | OCCTSwift (this repo) | Core Swift wrapper β€” shapes, curves, surfaces, OCAF, BRepGraph, drawing/projection, ML samplers. Bundles the OCCT 8.0.0p1 xcframework. | | OCCTSwiftIO | Headless CAD file I/O β€” STEP / IGES / STL / OBJ / BREP loaders + glTF / GLB / OBJ / PLY / STEP / BREP exporters. No Viewport dep. | | OCCTSwiftMesh | Mesh-domain algorithms β€” decimation, smoothing, repair (vendors meshoptimizer). | | OCCTSwiftViewport | Metal-based 3D viewport component (UIKit / AppKit / SwiftUI). | | OCCTSwiftTools | Bridge layer: converts kernel Shape to ViewportBody with picking metadata. | | OCCTSwiftAIS | High-level interactive services β€” selection, manipulator widgets, dimension annotations, scene objects. | | OCCTSwiftScripts | occtkit CLI + ScriptHarness β€” JSON-driven verbs for compose / reconstruct / drawing-export / metrics / mesh / render-preview / XCAF. | | OCCTMCP | MCP server exposing CAD modeling to AI tools via Model Context Protocol. | | simpleOCCTVP | Pure C API over OCCT for non-Swift consumers β€” shape I/O, healing, mesh extraction, offscreen rendering. |

What's Wrapped

OCCTSwift provides method-level coverage of all user-facing OCCT classes. Key areas:

| Category | Operations | Highlights | |----------|-----------|------------| | Primitives & Sweeps | 36 | box, cylinder, sphere, cone, torus, wedge, pipe, extrude, revolve, loft, thru-sections | | Booleans | 13 | union, subtract, intersect, section, split, cells builder, defeaturing | | Modifications | 33 | fillet (uniform/variable/evolving), chamfer, shell, offset, draft | | Wires & Edges | 56 | rectangle, circle, polygon, arc, BSpline, NURBS, helix, fillet2D, chamfer2D | | 2D Curves | 97 | full Geom2d β€” lines, conics, BSplines, Bezier, Gcc constraint solver, hatching | | 3D Curves | 84 | full Geom β€” lines, conics, BSplines, Bezier, interpolation, projection, evaluation | | Surfaces | 88 | analytic, swept, freeform, plate, NLPlate, curvature, projection, trimming (rectangular UV, UV-polygon, or 3D-wire bounded) | | Face / Edge Analysis | 54 | UV queries, normals, curvature, projection, classification, primary axis, surface type predicates | | Feature-Based | 36 | boss, pocket, drill, split, pattern, rib, revolution, draft prism | | Healing & Analysis | 69 | fix, unify, simplify, NURBS convert, sew, wire/face/shell repair | | Measurement | 38 | volume, area, distance, inertia, point classification, proximity, revolution/symmetry axes | | Import/Export | 19 | STEP, IGES, STL, OBJ, PLY, BREP, GLTF/GLB, DXF | | XDE/OCAF | 200+ | assembly, colors, materials, GD&T (32 dimension types + 16 tolerance types, read + write), annotations, transactions, undo/redo, STEP AP242 round-trip | | Math & Solvers | 50+ | root finding, BFGS, PSO, SVD, Gauss, Jacobi, constraint callbacks | | Colors & Materials | 63 | Quantity_Color, sRGB/Lab/HLS, PBR materials, named colors | | Geometry Factories | 90+ | GC/GCE2d/gce factories, convert to BSpline, analytical recognition | | Drawings & Dimensions | 32 | HLR projection, visible/hidden/outline edges, linear/radial/diameter/angular dimensions, centrelines, auto-centreline from revolution axes, DXF R12 writer | | Thread Features | 23 | ThreadForm (ISO-68/Unified), ThreadSpec parser (M5x0.8, 1/4-20 UNC), truncated 60Β° V-profile, multi-start, runout styles, Shape.threadedHole, Shape.threadedShaft (smooth direct build, single- & multi-start #213/#257; ThreadBuild .auto/.direct, .boolean deprecated #254), Shape.threadedRod (smooth worm/screw from a custom ThreadProfile, boolean-free) | | Sheet Metal | 3 | SheetMetal.Flange + Bend + Builder.build β€” declarative flange-and-bend composition via extrude + union + fillet |

For the full operation-by-operation mapping to OCCT classes, see docs/API_REFERENCE.md.

Examples

Sweep a Profile Along a Path

let profile = Wire.rectangle(width: 5, height: 3)
let path = Wire.arc(center: .zero, radius: 50, startAngle: 0, endAngle: .pi / 2)
let swept = Shape.sweep(profile: profile, along: path)

XDE Document with Assembly Structure

let doc = try Document.load(from: stepURL)

for node in doc.rootNodes {
    print("Part: \(node.name ?? "unnamed")")
    if let color = node.color {
        print("  Color: \(color.red), \(color.green), \(color.blue)")
    }
    if let shape = node.shape {
        let mesh = shape.mesh(linearDeflection: 0.1)
        // render with Metal, SceneKit, RealityKit...
    }
}

Parametric Curves for Metal Rendering

let curve = Curve3D.interpolate(points: [
    SIMD3(0, 0, 0), SIMD3(5, 10, 0), SIMD3(10, 0, 5)
])!
let points = curve.drawAdaptive(curvatureDeflection: 0.1)
// Feed to Metal vertex buffer

GLTF Export

try Exporter.writeGLTF(shape: model, to: gltfURL)
try Exporter.writeGLB(shape: model, to: glbURL)

Architecture

Sources/OCCTSwift/          Swift public API
Sources/OCCTBridge/include/ C function declarations (OCCTBridge.h)
Sources/OCCTBridge/src/     Objective-C++ implementations (OCCTBridge.mm)
Libraries/OCCT.xcframework  Pre-built OCCT 8.0.0p1 static library (arm64)
Tests/OCCT<Domain>Tests/    Per-domain Swift Testing targets (focused compile/run)

Three-layer design: Swift API -> C bridge (Objective-C++) -> OCCT C++

Each OCCT object is managed via opaque handle types with release-on-deinit. See docs/architecture/overview.md for details.

Requirements

  • Swift 6.1+ (verified clean on 6.1, 6.2, 6.3)
  • macOS 12.0+ (arm64) / iOS 15.0+ (arm64)
  • Xcode 16.0+

Supported Platforms

| Platform | Architecture | Status | |---|---|---| | macOS 12+ | arm64 (Apple Silicon) | Supported | | iOS 15+ device | arm64 | Supported | | iOS 15+ Simulator | arm64 (Apple Silicon host) | Supported | | visionOS 1+ | arm64 device + simulator | Supported (v0.167.0+) | | tvOS 15+ | arm64 device + simulator | Supported (v0.167.0+) | | watchOS | β€” | Out of scope (OCCT static lib too large for watch memory) | | macOS x86_64 (Intel) | β€” | Out of scope (Apple is winding down Intel macOS support) | | Linux / Windows / Android | β€” | Under review β€” see docs/platform-expansion.md |

Building OCCT from Source

The pre-built xcframework is included. To rebuild from source:

./Scripts/build-occt.sh

See docs/guides/building-occt.md for details.

Prebuilt OCCTBridge (opt-in)

The Objective-C++ bridge (16 files, ~62K lines) compiles from source by default. Consumers who don't need to edit it can opt into a prebuilt binary instead β€” set OCCTSWIFT_BRIDGE_PREBUILT=1. See docs/guides/prebuilt-bridge.md.

Documentation

| Document | Description | |----------|-------------| | Ecosystem | Map of the package family, dependency layering, when to use which | | SemVer Policy | Versioning rules for the cohort β€” what triggers MAJOR / MINOR / PATCH | | Architecture Overview | Three-layer design, memory management, conventions | | Adding Features | How to wrap new OCCT operations | | OCCT Concepts | B-Rep topology, handles, shapes primer | | Sharing the xcframework | Share one local copy across ecosystem repos + the Package.resolved pin footgun (#260) | | Prebuilt OCCTBridge | Opt-in prebuilt bridge binary (OCCTSWIFT_BRIDGE_PREBUILT=1) β€” skip compiling 62K lines of Obj-C++ per consumer rebuild (#339) | | API Reference (mapping) | Full operation-by-operation mapping to OCCT classes | | API Reference (detailed) | Per-type function reference β€” signatures, OCCT mapping, examples (built progressively) | | Thread Safety | OCCTSerial mutex, parallel execution notes | | Naming Conventions | Bridge and Swift naming patterns | | OCCT Upgrades | Breaking changes and migration for each OCCT version | | Wrapping Status | What's wrapped, what's not, and why | | WebAssembly Plan | Feasibility + phased plan for reusing the API in a SwiftWasm app | | Changelog | Release history |

License

LGPL-2.1. OpenCASCADE Technology is licensed under LGPL-2.1.

Acknowledgments

Package Metadata

Repository: secondmouseau/occtswift

Default branch: main

README: README.md