Tracking a handheld accessory as a virtual sculpting tool
At a glance
| Item | Summary |
|---|---|
| Purpose | Use a tracked accessory with Apple Vision Pro to create a virtual sculpture. |
| App architecture | A C/Objective-C header, Metal, Swift sample with the source-visible chain SpatialSculptingApp → ContentView → HapticsModel → ComputeDispatchSystem → ARKit APIs. |
| Main patterns | Protocol-oriented abstraction, Actor-isolated state |
| Project style | 25 scanned source file(s) across C/Objective-C header, Metal, Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── SpatialSculpting/
└── SpatialSculpting/
├── SpatialSculptingApp.swift
├── Compute/
│ └── ComputeSystem.swift
├── ECS/
│ └── SculptingToolComponent.swift
├── Document/
│ └── VolumeDocument.swift
├── ContentView.swift
├── ViewModel/
│ ├── HapticsModel.swift
│ ├── SculptingToolModel.swift
│ └── SculptingToolModel+GameController.swift
├── Mesh/
│ ├── MarchingCubesMesh.swift
│ ├── MarchingCubesParams.h
│ └── MeshVertex.h
└── Volume/
└── VoxelVolume.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: C/Objective-C header, Metal, Swift.
- The verified tree contains 4 project/configuration file(s) and 24 source declaration(s).
Overall architecture
flowchart LR
N1["SpatialSculptingApp"]
N2["ContentView"]
N3["HapticsModel"]
N4["ComputeDispatchSystem"]
N5["ARKit APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
SpatialSculpting/SpatialSculpting/SpatialSculptingApp.swift:10 — architecture anchor
@main
struct SpatialSculptingApp: App {
// ...
}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 ARKit.
Ownership and state
classDiagram
ComputeUpdateContext o-- SceneUpdateContext : sceneUpdateContext
ComputeUpdateContext o-- MTLCommandBuffer : commandBuffer
ComputeUpdateContext o-- MTLComputeCommandEncoder : _computeEncoder
ComputeUpdateContext o-- MTLBlitCommandEncoder : _blitEncoder
Ownership evidence
SpatialSculpting/SpatialSculpting/Compute/ComputeSystem.swift:14 — stored dependency or nearest verified ownership anchor
struct ComputeUpdateContext {
// ...
let sceneUpdateContext: SceneUpdateContext
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ComputeUpdateContext |
SceneUpdateContext (sceneUpdateContext) |
stores or receives | Initialized by the owner; the binding is immutable |
ComputeUpdateContext |
MTLCommandBuffer (commandBuffer) |
stores or receives | Initialized by the owner; the binding is immutable |
ComputeUpdateContext |
MTLComputeCommandEncoder (_computeEncoder) |
stores or receives | Owning lexical scope |
ComputeUpdateContext |
MTLBlitCommandEncoder (_blitEncoder) |
stores or receives | 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.
Class and protocol design
SpatialSculpting/SpatialSculpting/Compute/ComputeSystem.swift:55 — representative type boundary
protocol ComputeSystem {
@MainActor
func update(computeContext: inout ComputeUpdateContext)
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
SpatialSculptingApp |
Application entry and top-level composition | App |
ComputeSystem |
Defines a capability or collaboration contract | Concrete collaborators/imported frameworks |
ComputeSystemComponent |
Stores entity-component data or behavior | Component |
ComputeDispatchSystem |
Runs entity-component-system update logic | System |
SculptingToolComponent |
Stores entity-component data or behavior | Component |
SculptingToolSystem |
Runs entity-component-system update logic | ComputeSystem |
VolumeDocument |
Owns document data or lifecycle behavior | FileDocument |
ContentView |
User-interface presentation and input forwarding | View |
HapticsModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
SculptingToolModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
The source explicitly defines local protocol relationships: SculptingToolSystem → ComputeSystem.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
_computeEncoder (SpatialSculpting/SpatialSculpting/Compute/ComputeSystem.swift:49) |
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. |
_blitEncoder (SpatialSculpting/SpatialSculpting/Compute/ComputeSystem.swift:51) |
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. |
maxVertexCapacityPerMeshChunk (SpatialSculpting/SpatialSculpting/Mesh/MarchingCubesMesh.swift:21) |
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. |
maxVerticesPerVoxel (SpatialSculpting/SpatialSculpting/Mesh/MarchingCubesMesh.swift:22) |
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
SpatialSculpting/SpatialSculpting/Compute/ComputeSystem.swift:49 — representative boundary
struct ComputeUpdateContext {
// ...
private var _computeEncoder: MTLComputeCommandEncoder? = nil
// ...
}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 | SpatialSculptingApp |
The source’s App suffix makes this role explicit. |
| Stores entity-component data or behavior | ComputeSystemComponent, SculptingToolComponent |
The source’s Component suffix makes this role explicit. |
| Owns document data or lifecycle behavior | VolumeDocument |
The source’s Document suffix makes this role explicit. |
| Feature data or observable state | HapticsModel, SculptingToolModel |
The source’s Model suffix makes this role explicit. |
| Runs entity-component-system update logic | ComputeDispatchSystem, ComputeSystem, SculptingToolSystem |
The source’s System suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Protocol-oriented abstraction | SpatialSculpting/SpatialSculpting/ECS/SculptingToolComponent.swift:38 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Actor-isolated state | SpatialSculpting/SpatialSculpting/Compute/ComputeSystem.swift:56 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: SpatialSculptingApp; Component: ComputeSystemComponent, SculptingToolComponent; Document: VolumeDocument; Model: HapticsModel, SculptingToolModel; System: ComputeDispatchSystem, ComputeSystem, SculptingToolSystem; View: ContentView.
- Protocols:
ComputeSystem. - Methods:
computeEncoder,blitEncoder,endEncoding,update,loadFromURL,fileWrapper,createMeshChunkEntity,sculptingVolume. - Files:
SpatialSculpting/SpatialSculpting/SpatialSculptingApp.swift,SpatialSculpting/SpatialSculpting/Compute/ComputeSystem.swift,SpatialSculpting/SpatialSculpting/ECS/SculptingToolComponent.swift,SpatialSculpting/SpatialSculpting/Document/VolumeDocument.swift,SpatialSculpting/SpatialSculpting/ContentView.swift,SpatialSculpting/SpatialSculpting/ViewModel/HapticsModel.swift.
Architecture takeaways
SpatialSculptingAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches RealityKit, Metal, SwiftUI, ARKit 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.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
SpatialSculpting/SpatialSculpting/SpatialSculptingApp.swift |
SpatialSculptingApp |
SpatialSculpting/SpatialSculpting/Compute/ComputeSystem.swift |
ComputeUpdateContext, ComputeSystem, ComputeSystemComponent, ComputeDispatchSystem |
SpatialSculpting/SpatialSculpting/ECS/SculptingToolComponent.swift |
SculptingMode, SculptingToolComponent, SculptingToolSystem |
SpatialSculpting/SpatialSculpting/Document/VolumeDocument.swift |
VolumeDocumentError, VolumeDocument |
SpatialSculpting/SpatialSculpting/ContentView.swift |
ContentView |
SpatialSculpting/SpatialSculpting/ViewModel/HapticsModel.swift |
HapticsModel |
SpatialSculpting/SpatialSculpting/ViewModel/SculptingToolModel.swift |
SculptingToolModel |
SpatialSculpting/SpatialSculpting/Mesh/MarchingCubesMesh.swift |
MarchingCubesMeshChunk, MarchingCubesMesh, func |
SpatialSculpting/SpatialSculpting/ViewModel/SculptingToolModel+GameController.swift |
Feature implementation |
SpatialSculpting/SpatialSculpting/Volume/VoxelVolume.swift |
VoxelVolumeError, VoxelVolume |