Manipulating models with RealityKit
At a glance
| Item | Summary |
|---|---|
| Purpose | Interact with detailed 3D models using manipulation and clipping controls. |
| App architecture | A Swift sample with the source-visible chain ModelManipulatorApp → ClippingController → AppModel → ClippingTransformSyncSystem → RealityKit APIs. |
| Main patterns | View-controller organization |
| Project style | 27 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: async declaration or closure, @MainActor, Task closure isolated to MainActor, Task; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, @Observable. |
| Key frameworks/packages | SwiftUI, RealityKit, os, simd, Observation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── ModelManipulator/
├── ModelManipulatorApp.swift
├── Models/
│ ├── AppModel.swift
│ ├── ClippingController.swift
│ └── ClippingPlane.swift
├── Components/
│ ├── ClippingBoundsCacheComponent.swift
│ └── ClippingTransformSyncComponent.swift
├── Scenes/
│ └── ImmersiveScene.swift
├── Systems/
│ └── ClippingTransformSyncSystem.swift
└── Views/
├── ContentView.swift
├── EntityHierarchyView.swift
├── ImmersiveControlsView.swift
└── ImmersiveView.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 4 project/configuration file(s) and 29 source declaration(s).
Overall architecture
flowchart LR
N1["ModelManipulatorApp"]
N2["ClippingController"]
N3["AppModel"]
N4["ClippingTransformSyncSystem"]
N5["RealityKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
ModelManipulator/ModelManipulatorApp.swift:10 — architecture anchor
@main
struct ModelManipulatorApp: App {
@State private var appModel = AppModel()
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into RealityKit.
Ownership and state
classDiagram
ModelManipulatorApp *-- AppModel : appModel
AppModel o-- Entity : modelEntity
AppModel *-- URL : selectedModelURL
AppModel *-- Dictionary : clippingControllers
Ownership evidence
ModelManipulator/ModelManipulatorApp.swift:12 — stored dependency or nearest verified ownership anchor
@main
struct ModelManipulatorApp: App {
@State private var appModel = AppModel()
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ModelManipulatorApp |
AppModel (appModel) |
owns wrapper-managed state | Owning lexical scope |
AppModel |
Entity (modelEntity) |
stores or receives | App/module collaborators |
AppModel |
URL (selectedModelURL) |
owns value state | Owning type writes; wider scope can read |
AppModel |
Dictionary (clippingControllers) |
owns value state | Owning lexical scope |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | ModelManipulator/Entities/ClippingControlEntity.swift:21 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | ModelManipulator/ModelManipulatorApp.swift:24 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | ModelManipulator/ModelManipulatorApp.swift:24 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | ModelManipulator/ModelManipulatorApp.swift:24 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
ModelManipulator/Entities/ClippingControlEntity.swift:21 — representative execution boundary
static func makeEntity() async throws -> ClippingControlEntity {
let entity = ClippingControlEntity()
// ...
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | ModelManipulator/ModelManipulatorApp.swift:12 |
| State propagation | @Observable |
Observation macro publishes source-visible changes. | ModelManipulator/Models/AppModel.swift:14 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | ModelManipulator/Entities/ClippingControlEntity.swift:10 |
| Source import | RealityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | ModelManipulator/Components/ClippingBoundsCacheComponent.swift:8 |
| Source import | os |
The cited file imports this module; runtime use and architectural role are not inferred. | ModelManipulator/Entities/ClippingControlEntity.swift:8 |
| Source import | simd |
The cited file imports this module; runtime use and architectural role are not inferred. | ModelManipulator/Extensions/Axis+ModelManipulator.swift:8 |
| Source import | Observation |
The cited file imports this module; runtime use and architectural role are not inferred. | ModelManipulator/Models/AppModel.swift:8 |
| Source import | UniformTypeIdentifiers |
The cited file imports this module; runtime use and architectural role are not inferred. | ModelManipulator/Models/AppModel.swift:12 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
ModelManipulator/ModelManipulatorApp.swift:11 — representative type boundary
@main
struct ModelManipulatorApp: App {
@State private var appModel = AppModel()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
ModelManipulatorApp |
Application entry and top-level composition | App |
AppModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
ClippingController |
View lifecycle, callbacks, and feature coordination | Concrete collaborators/imported frameworks |
ClippingBoundsCacheComponent |
Stores entity-component data or behavior | Component |
ClippingTransformSyncComponent |
Stores entity-component data or behavior | Component |
ImmersiveScene |
Scene lifecycle or scene-level composition | Scene |
ClippingTransformSyncSystem |
Runs entity-component-system update logic | System |
ContentView |
User-interface presentation and input forwarding | View |
EntityHierarchyView |
User-interface presentation and input forwarding | View |
ImmersiveControlsView |
User-interface presentation and input forwarding | View |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
clippedEntity (ModelManipulator/Entities/ClippingControlEntity.swift:13) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
firstEventLocationInWorld (ModelManipulator/Entities/ClippingControlEntity.swift:14) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
mostRecentBounds (ModelManipulator/Entities/ClippingControlEntity.swift:15) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
planeLocationStartOfDragInWorld (ModelManipulator/Entities/ClippingControlEntity.swift:16) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
ModelManipulator/Entities/ClippingControlEntity.swift:13 — representative boundary
final class ClippingControlEntity: Entity {
private weak var clippedEntity: Entity?
// ...
}Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | ModelManipulatorApp |
The source’s App suffix makes this role explicit. |
| Stores entity-component data or behavior | ClippingBoundsCacheComponent, ClippingTransformSyncComponent |
The source’s Component suffix makes this role explicit. |
| View lifecycle, callbacks, and feature coordination | ClippingController |
The source’s Controller suffix makes this role explicit. |
| Feature data or observable state | AppModel |
The source’s Model suffix makes this role explicit. |
| Scene lifecycle or scene-level composition | ImmersiveScene |
The source’s Scene suffix makes this role explicit. |
| Runs entity-component-system update logic | ClippingTransformSyncSystem |
The source’s System suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, EntityHierarchyView, ImmersiveControlsView, ImmersiveView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | ModelManipulator/Models/ClippingController.swift:11 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
Naming conventions
- Types: App: ModelManipulatorApp; Component: ClippingBoundsCacheComponent, ClippingTransformSyncComponent; Controller: ClippingController; Model: AppModel; Scene: ImmersiveScene; System: ClippingTransformSyncSystem; View: ContentView, EntityHierarchyView, ImmersiveControlsView, ImmersiveView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
enterImmersivePresentation,exitImmersivePresentation,makeDefaultScenes,handleClippingStateChange,presentFileImporter,reset,selectDefaultModel,selectModel. - Files:
ModelManipulator/ModelManipulatorApp.swift,ModelManipulator/Models/AppModel.swift,ModelManipulator/Models/ClippingController.swift,ModelManipulator/Components/ClippingBoundsCacheComponent.swift,ModelManipulator/Components/ClippingTransformSyncComponent.swift,ModelManipulator/Scenes/ImmersiveScene.swift.
Architecture takeaways
ModelManipulatorAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, RealityKit, simd, UniformTypeIdentifiers through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
ModelManipulator/ModelManipulatorApp.swift |
Cited implementation, ModelManipulatorApp, @MainActor, Task closure isolated to MainActor, Task, SwiftUI state property wrapper |
ModelManipulator/Entities/ClippingControlEntity.swift |
Cited implementation, async declaration or closure, SwiftUI, os, ClippingControlEntity, ClippingControlError |
ModelManipulator/Models/ClippingController.swift |
ClippingController |
ModelManipulator/Models/AppModel.swift |
@Observable, Observation, UniformTypeIdentifiers, AppModel, ImmersiveSpaceState, ViewState |
ModelManipulator/Components/ClippingBoundsCacheComponent.swift |
RealityKit, ClippingBoundsCacheComponent, ClippingState |
ModelManipulator/Extensions/Axis+ModelManipulator.swift |
simd, Axis3D |
ModelManipulator/Components/ClippingTransformSyncComponent.swift |
ClippingTransformSyncComponent |
ModelManipulator/Scenes/ImmersiveScene.swift |
ImmersiveScene |
ModelManipulator/Systems/ClippingTransformSyncSystem.swift |
ClippingTransformSyncSystem |
ModelManipulator/Views/ContentView.swift |
ContentView |
ModelManipulator/Views/EntityHierarchyView.swift |
EntityHierarchyView |
ModelManipulator/Views/ImmersiveControlsView.swift |
ImmersiveControlsView |
ModelManipulator/Views/ImmersiveView.swift |
ImmersiveView |
ModelManipulator/Models/ClippingPlane.swift |
ClippingPlane |
ModelManipulator/Views/LoadingIndicatorSpatialOverlay.swift |
LoadingIndicatorSpatialOverlay, LoadingIndicatorOverlayModifier |
ModelManipulator/Entities/ClippingPlaneControlEntity.swift |
ClippingPlaneControlEntity |