ARKit visionOS Developer
Description and Goals
This skill provides comprehensive guidance for implementing ARKit-powered features on visionOS. ARKit on visionOS uses ARKitSession with data providers to access world tracking, hand tracking, plane detection, scene reconstruction, and other spatial data, which can then be bridged into RealityKit content.
Goals
- - Enable developers to set up and manage ARKitSession on visionOS
- Guide proper authorization handling for ARKit data providers
- Help developers choose and configure appropriate data providers
- Support anchor processing and RealityKit integration
- Ensure proper lifecycle management of ARKit sessions
What This Skill Should Do
When implementing ARKit features on visionOS, this skill should:
- 1. Guide ARKitSession setup - Help you create and manage long-lived ARKitSession instances
- Handle authorization - Show how to request and check authorization for required data types
- Select data providers - Help you choose the right providers (world tracking, hand tracking, plane detection, etc.)
- Process anchors - Demonstrate how to consume anchor updates and map them to RealityKit entities
- Manage lifecycle - Ensure proper session start/stop and task cancellation
- Bridge to RealityKit - Show how to integrate ARKit anchors with RealityKit content
Load the appropriate reference file from the tables below for detailed usage, code examples, and best practices.
Quick Start Workflow
- 1. Add
NSWorldSensingUsageDescription, NSHandsTrackingUsageDescription, and NSMainCameraUsageDescription to Info.plist as needed for the providers you use. - Use the presentation style required by the selected providers. Some providers require immersive space, while others have more specific rules.
- Create a long-lived
ARKitSession and the data providers you need. - Request authorization for provider-required data types before running the session.
- Run the session with your providers and observe
anchorUpdates streams. - Map anchors to RealityKit entities and keep state in a model layer.
- Observe
ARKitSession.events for authorization changes and errors. - Stop the session and cancel tasks when leaving the immersive space.
Information About the Skill
Core Concepts
ARKitSession Lifecycle
- - Keep a strong reference to the session; call
run(_:) with providers, stop on teardown. - Sessions stop automatically on deinit, so maintain references throughout the immersive experience.
Authorization
- - Use
requestAuthorization(for:) or queryAuthorization(for:) and handle denied states gracefully. - Request authorization before running the session with providers that require it.
Data Providers
- - Choose providers for world tracking, plane detection, scene reconstruction, and hand tracking based on the feature set.
- Providers expose
anchorUpdates streams that you consume to process anchors.
Anchors and Updates
- - Consume provider
anchorUpdates and reconcile added, updated, and removed anchors. - Normalize anchor IDs to your own state model for reliable entity updates.
RealityKit Bridge
- - Use
ARKitAnchorComponent to inspect backing ARKit data on entities when needed. - Treat ARKit streams as authoritative and keep rendering logic in RealityKit.
Implementation Patterns
- - Prefer one session per immersive experience and reuse providers when possible.
- Normalize anchor IDs to your own state model for reliable entity updates.
- Treat ARKit streams as authoritative and keep rendering logic in RealityKit.
Provider References
When tracking hand poses and gestures for interaction. |
|
PlaneDetectionProvider | When detecting horizontal and vertical surfaces (floors, walls, tables). |
|
SceneReconstructionProvider | When creating detailed 3D mesh reconstructions of the environment. |
|
ImageTrackingProvider | When tracking known 2D images in the environment. |
|
ObjectTrackingProvider | When tracking 3D objects in the environment. |
|
RoomTrackingProvider | When tracking room boundaries and room-scale experiences. |
|
AccessoryTrackingProvider | When tracking Apple Vision Pro accessories. |
|
BarcodeDetectionProvider | When detecting and reading barcodes in the environment. |
|
CameraFrameProvider | When accessing raw camera frames for custom processing. |
|
CameraRegionProvider | When accessing camera frames from specific regions. |
|
EnvironmentLightEstimationProvider | When estimating ambient lighting conditions. |
|
SharedCoordinateSpaceProvider | When sharing coordinate spaces across multiple sessions. |
|
StereoPropertiesProvider | When accessing stereo camera properties. |
General ARKit Patterns
| Reference | When to Use |
|---|
REFERENCE.md | When implementing ARKit session setup, authorization, and general provider patterns. |
Pitfalls and Checks
- - In SwiftUI-first visionOS apps, prefer
RealityView for presentation and ARKitSession for tracking data; use ARView only when you specifically need its UIKit/AppKit-style view APIs. - Do not assume every ARKit provider has the same presentation requirements; check the provider-specific guidance before choosing Shared Space, a volumetric window, or an immersive space.
- Do not block the main actor while awaiting provider updates.
- Do not drop session references; ARKit stops sessions on deinit.
ARKit visionOS 开发者
描述与目标
此技能为在 visionOS 上实现基于 ARKit 的功能提供全面指导。visionOS 上的 ARKit 使用带有数据提供者的 ARKitSession 来访问世界追踪、手部追踪、平面检测、场景重建和其他空间数据,这些数据随后可以桥接到 RealityKit 内容中。
目标
- - 使开发者能够在 visionOS 上设置和管理 ARKitSession
- 指导 ARKit 数据提供者的正确授权处理
- 帮助开发者选择并配置合适的数据提供者
- 支持锚点处理和 RealityKit 集成
- 确保 ARKit 会话的生命周期管理正确
此技能应能做什么
在 visionOS 上实现 ARKit 功能时,此技能应:
- 1. 指导 ARKitSession 设置 - 帮助您创建和管理长期存在的 ARKitSession 实例
- 处理授权 - 展示如何请求和检查所需数据类型的授权
- 选择数据提供者 - 帮助您选择合适的提供者(世界追踪、手部追踪、平面检测等)
- 处理锚点 - 演示如何使用锚点更新并将其映射到 RealityKit 实体
- 管理生命周期 - 确保正确的会话启动/停止和任务取消
- 桥接到 RealityKit - 展示如何将 ARKit 锚点与 RealityKit 内容集成
从下表中加载相应的参考文件,以获取详细用法、代码示例和最佳实践。
快速入门工作流程
- 1. 根据您使用的提供者,在 Info.plist 中添加 NSWorldSensingUsageDescription、NSHandsTrackingUsageDescription 和 NSMainCameraUsageDescription。
- 使用所选提供者所需的呈现样式。某些提供者需要沉浸式空间,而其他提供者则有更具体的规则。
- 创建一个长期存在的 ARKitSession 以及您需要的数据提供者。
- 在运行会话之前,请求提供者所需数据类型的授权。
- 使用您的提供者运行会话,并观察 anchorUpdates 流。
- 将锚点映射到 RealityKit 实体,并在模型层中保持状态。
- 观察 ARKitSession.events 以获取授权更改和错误。
- 离开沉浸式空间时停止会话并取消任务。
关于此技能的信息
核心概念
ARKitSession 生命周期
- - 保持对会话的强引用;使用提供者调用 run(_:),在拆卸时停止。
- 会话在 deinit 时自动停止,因此在沉浸式体验期间保持引用。
授权
- - 使用 requestAuthorization(for:) 或 queryAuthorization(for:),并优雅地处理拒绝状态。
- 在运行需要授权的提供者之前请求授权。
数据提供者
- - 根据功能集选择用于世界追踪、平面检测、场景重建和手部追踪的提供者。
- 提供者公开 anchorUpdates 流,您可以通过消费这些流来处理锚点。
锚点和更新
- - 消费提供者的 anchorUpdates,并协调添加、更新和移除的锚点。
- 将锚点 ID 规范化到您自己的状态模型,以实现可靠的实体更新。
RealityKit 桥接
- - 在需要时使用 ARKitAnchorComponent 检查实体上的底层 ARKit 数据。
- 将 ARKit 流视为权威数据,并将渲染逻辑保留在 RealityKit 中。
实现模式
- - 每个沉浸式体验优先使用一个会话,并尽可能重用提供者。
- 将锚点 ID 规范化到您自己的状态模型,以实现可靠的实体更新。
- 将 ARKit 流视为权威数据,并将渲染逻辑保留在 RealityKit 中。
提供者参考
追踪手部姿势和手势以进行交互时。 |
|
PlaneDetectionProvider | 检测水平和垂直表面(地板、墙壁、桌子)时。 |
|
SceneReconstructionProvider | 创建环境的详细 3D 网格重建时。 |
|
ImageTrackingProvider | 追踪环境中已知的 2D 图像时。 |
|
ObjectTrackingProvider | 追踪环境中的 3D 对象时。 |
|
RoomTrackingProvider | 追踪房间边界和房间级体验时。 |
|
AccessoryTrackingProvider | 追踪 Apple Vision Pro 配件时。 |
|
BarcodeDetectionProvider | 检测和读取环境中的条形码时。 |
|
CameraFrameProvider | 访问原始相机帧进行自定义处理时。 |
|
CameraRegionProvider | 从特定区域访问相机帧时。 |
|
EnvironmentLightEstimationProvider | 估计环境光照条件时。 |
|
SharedCoordinateSpaceProvider | 在多个会话之间共享坐标空间时。 |
|
StereoPropertiesProvider | 访问立体相机属性时。 |
通用 ARKit 模式
陷阱与检查
- - 在以 SwiftUI 为主的 visionOS 应用中,优先使用 RealityView 进行呈现,使用 ARKitSession 进行追踪数据;仅在特别需要 UIKit/AppKit 风格视图 API 时使用 ARView。
- 不要假设每个 ARKit 提供者都有相同的呈现要求;在选择共享空间、体积窗口或沉浸式空间之前,请检查提供者特定的指导。
- 在等待提供者更新时,不要阻塞主参与者。
- 不要丢弃会话引用;ARKit 会在 deinit 时停止会话。