Link Search Menu Expand Document

OCCTSwiftViewport Cookbook

Task-oriented, example-rich guides for the OCCTSwiftViewport Swift API — one page per area, each a short bit of prose followed by runnable Swift snippets. The Swift-side counterpart to OCCTSwift’s own cookbook: make the viewport surface answerable by context7.

Conventions

  • Every example is runnable Swift in a ```swift block, using the real current API. Fallible factories and optionals are unwrapped with guard/if let, never force-unwrapped. Examples double as living docs; keep them compiling against the shipped API.
  • One canonical place per topic. These pages hold usage; the exhaustive per-member surface lives in the API Reference. Link, don’t duplicate.
  • SwiftUI-first. The viewport’s entry point is MetalViewportView (a SwiftUI View) driven by a ViewportController (@MainActor, ObservableObject). Examples assume a ViewportController instance named controller unless shown otherwise.

Figures

The viewport is the renderer, so figures on the visual pages are produced by its own headless OffscreenRenderer — the same path a host app would use for thumbnails or exports. They are committed under images/ and generated by the DocFigures example (Examples/DocFigures), so the picture and the documented API never drift. Rebuild them with:

cd Examples/DocFigures && swift run DocFigures ../../docs/guides/cookbook/images

Pages

  • Getting StartedMetalViewportView in SwiftUI, the ViewportController, and putting your first body on screen.
  • Display Modes — wireframe, shaded, shaded-with-edges, flat, and unlit/flat-colour for diagnostic renders.
  • Camera & Navigation — orbit / pan / zoom, the arcball / turntable / first-person rotation styles, standard views, fit-to-scene, and animated transitions.
  • ViewCube — the interactive orientation cube and navigation cube: click-to-snap faces / edges / corners, drag-to-orbit, and placement.
  • Lighting & MaterialsLightingConfiguration presets, per-body PBRMaterial / MaterialLibrary, and HDR image-based lighting.
  • Picking & Selection — GPU pick buffer, body / face / edge / vertex picks, SelectionFilter chains, ray-casting, and isPickable.
  • Loading Geometry — the ViewportBody container, interleaved vertex data, edges & analytic arcs, primitives, point clouds, per-body transform & colour, and bridging from OCCTSwift.
  • MeasurementsmeasurementMode, tap-to-measure, the MeasurementOverlay, and distance / angle / radius dimensions.
  • Clip Planes & SectionsClipPlane section views and capping.
  • Offscreen RenderingOffscreenRenderer / OffscreenRenderOptions for headless PNGs, display modes, lighting, and measurement compositing.
  • Gestures & InputGestureConfiguration presets (.default / .blender / .fusion360), the portable ViewportInputEvent model, and modifier keys.
  • HUD Overlays — the orientation gnomon and the scale bar.

Table of contents