Contents

secondmouseau/occtswiftais

High-level Application Interactive Services for the OCCTSwift / OCCTSwiftViewport stack — selection-from-topology, manipulator widgets, dimension annotations, and standard scene objects, all in pure Swift.

What's in the box

  • Selection-from-topology — pick a body / face / edge / vertex; round-trip the GPU pick to a TopoDS_Face / Edge / Vertex handle on the source Shape. Body and face highlights composite via the renderer's per-triangle style buffer (no overlay-mesh flicker).
  • Manipulator widgets — translate and rotate gizmos with snapTranslate / snapRotateDeg, on the renderer's overlay layer (always-on-top), with native widget pick filtering. SwiftUI integration via .attachManipulator(_:).
  • DimensionsLinearDimension, AngularDimension, RadialDimension. Topology-aware anchors (vertex / edge midpoint / face bbox center / circular-edge center) feed into OCCTSwiftViewport's existing MeasurementOverlay for leader lines + billboarded label.
  • Standard scene objectsTrihedron, WorkPlane, Axis, PointCloudPresentation.
  • Durable selection identitySubShape carries a SubShapeRef (the resolved Shape plus a BRepGraph.GraphUID when a graph was in hand at pick time), not just a render-path ordinal. InteractiveContext.update(:to:absorbing:operationName:) absorbs a modelling operation's history into the object's living BRepGraph, and remap(:using:rebindingTo:) resolves a pre-mutation Selection forward through it — a face split by the operation expands to all its successors; a deleted one is reported via isDeleted(_:in:), never silently pointed at a coincidentally-adjacent neighbour.
  • Topology-aware selection filtersSurfaceTypeFilter, CurveTypeFilter, ShapeTypeFilter, composed with AllOfFilter / AnyOfFilter / NotFilter / PredicateFilter, installed via InteractiveContext.addFilter(_:) to restrict what's pickable/hoverable beyond selectionMode.
  • Rectangle and lasso area selectionInteractiveContext.selectRectangle(from:to:) / selectPolygon(:), honouring selectionMode and installed filters; .attachAreaSelection(:) wires up the drag gesture, a live rubber-band/lasso overlay, and camera-orbit passthrough when not actively marqueeing.

→ Getting started walks through wiring all of this into a SwiftUI app.

Installation

.package(url: "https://github.com/SecondMouseAU/OCCTSwiftAIS.git", from: "1.3.0"),

OCCTSwiftAIS transitively pulls OCCTSwiftTools, OCCTSwiftViewport, and OCCTSwift.

30-second example

import SwiftUI
import OCCTSwift
import OCCTSwiftViewport
import OCCTSwiftAIS

@MainActor
struct CADView: View {
    @StateObject private var ais = InteractiveContext(viewport: ViewportController())

    var body: some View {
        MetalViewportView(controller: ais.viewport, bodies: $ais.bodies)
            .onAppear {
                if let part = Shape.box(width: 10, height: 5, depth: 3) {
                    ais.display(part)
                }
                ais.selectionMode = [.face]
            }
            .onChange(of: ais.selection) { _, sel in
                for face in sel.faces {
                    print("selected face area:", face.area())
                }
            }
    }
}

Architecture

Application

OCCTSwiftAIS          this repo (selection / manipulator / dimensions)

OCCTSwiftTools        bridge: Shape  ViewportBody

OCCTSwift  OCCTSwiftViewport
(B-Rep)    (Metal)

OCCTSwiftAIS adds scene-management semantics an OCCT-style API expects (selection-on-topology, manipulators, dimensions) as a thin Swift layer on top of OCCTSwiftViewport's native Metal renderer. It is not a port of OCCT's TKV3d / TKService / TKOpenGl toolkits — see OCCTSwift/docs/visualization-research.md for why.

Supported platforms

| Platform | Status | |---|---| | macOS 15+ arm64 | Supported | | iOS 18+ device + simulator arm64 | Supported | | visionOS 1+ device + simulator arm64 | Supported | | tvOS 18+ device + simulator arm64 | Supported |

Same floor as OCCTSwiftViewport.

Documentation

  • Getting started — selection, manipulators, dimensions, standard objects in one walkthrough.
  • SPEC.md — design rationale and the v0.x → v1.0 trajectory.
  • docs/CHANGELOG.md — what shipped in each release.

Sibling repos: OCCTSwift (B-Rep kernel), OCCTSwiftViewport (Metal renderer), OCCTSwiftTools (Shape ↔ ViewportBody bridge).

License

LGPL 2.1 (matching OCCT). See LICENSE.

Package Metadata

Repository: secondmouseau/occtswiftais

Default branch: main

README: README.md