axiom-realitykit-ref
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRealityKit API Reference
RealityKit API参考
Complete API reference for RealityKit organized by category.
按类别整理的RealityKit完整API参考。
When to Use This Reference
何时使用本参考
Use this reference when:
- Looking up specific RealityKit API signatures or properties
- Checking which component types are available
- Finding the right anchor type for an AR experience
- Browsing material properties and options
- Setting up physics body parameters
- Looking up animation or audio API details
- Checking platform availability for specific APIs
在以下场景使用本参考:
- 查找特定RealityKit API签名或属性
- 查看可用的组件类型
- 为AR体验选择合适的锚点类型
- 浏览材质属性和选项
- 设置物理体参数
- 查找动画或音频API的详细信息
- 查看特定API的平台可用性
Part 1: Entity API
第一部分:实体API
Entity
实体
swift
// Creation
let entity = Entity()
let entity = Entity(components: [TransformComponent(), ModelComponent(...)])
// Async loading
let entity = try await Entity(named: "scene", in: .main)
let entity = try await Entity(contentsOf: url)
// Clone
let clone = entity.clone(recursive: true)swift
// Creation
let entity = Entity()
let entity = Entity(components: [TransformComponent(), ModelComponent(...)])
// Async loading
let entity = try await Entity(named: "scene", in: .main)
let entity = try await Entity(contentsOf: url)
// Clone
let clone = entity.clone(recursive: true)Entity Properties
实体属性
| Property | Type | Description |
|---|---|---|
| | Identifier for lookup |
| | Unique identity |
| | Local enabled state |
| | Effective enabled (considers parents) |
| | Entity is in an active scene |
| | Has anchoring or anchored ancestor |
| | Owning scene |
| | Parent entity |
| | Child entities |
| | All attached components |
| | Nearest anchoring ancestor |
| 属性 | 类型 | 描述 |
|---|---|---|
| | 用于查找的标识符 |
| | 唯一标识 |
| | 本地启用状态 |
| | 实际启用状态(考虑父实体) |
| | 实体处于活跃场景中 |
| | 具有锚定或已锚定的父实体 |
| | 所属场景 |
| | 父实体 |
| | 子实体 |
| | 所有附加组件 |
| | 最近的锚定父实体 |
Entity Hierarchy Methods
实体层级方法
swift
entity.addChild(child)
entity.addChild(child, preservingWorldTransform: true)
entity.removeChild(child)
entity.removeFromParent()
entity.findEntity(named: "name") // Recursive searchswift
entity.addChild(child)
entity.addChild(child, preservingWorldTransform: true)
entity.removeChild(child)
entity.removeFromParent()
entity.findEntity(named: "name") // Recursive searchEntity Subclasses
实体子类
| Class | Purpose | Key Component |
|---|---|---|
| Base container | Transform only |
| Renderable object | ModelComponent |
| AR anchor point | AnchoringComponent |
| Virtual camera | PerspectiveCameraComponent |
| Sun/directional | DirectionalLightComponent |
| Point light | PointLightComponent |
| Spot light | SpotLightComponent |
| Invisible collision zone | CollisionComponent |
| SwiftUI view in 3D | visionOS |
| Body-tracked entity | BodyTrackingComponent |
| 类 | 用途 | 核心组件 |
|---|---|---|
| 基础容器 | 仅包含Transform |
| 可渲染对象 | ModelComponent |
| AR锚点 | AnchoringComponent |
| 虚拟相机 | PerspectiveCameraComponent |
| 平行光/太阳光 | DirectionalLightComponent |
| 点光源 | PointLightComponent |
| 聚光灯 | SpotLightComponent |
| 不可见碰撞区域 | CollisionComponent |
| 3D空间中的SwiftUI视图 | visionOS |
| 身体追踪实体 | BodyTrackingComponent |
Part 2: Component Catalog
第二部分:组件目录
Transform
变换组件
swift
// Properties
entity.position // SIMD3<Float>, local
entity.orientation // simd_quatf
entity.scale // SIMD3<Float>
entity.transform // Transform struct
// World-space
entity.position(relativeTo: nil)
entity.orientation(relativeTo: nil)
entity.setPosition(pos, relativeTo: nil)
// Utilities
entity.look(at: target, from: position, relativeTo: nil)swift
// Properties
entity.position // SIMD3<Float>, local
entity.orientation // simd_quatf
entity.scale // SIMD3<Float>
entity.transform // Transform struct
// World-space
entity.position(relativeTo: nil)
entity.orientation(relativeTo: nil)
entity.setPosition(pos, relativeTo: nil)
// Utilities
entity.look(at: target, from: position, relativeTo: nil)ModelComponent
模型组件
swift
let component = ModelComponent(
mesh: MeshResource.generateBox(size: 0.1),
materials: [SimpleMaterial(color: .red, isMetallic: true)]
)
entity.components[ModelComponent.self] = componentswift
let component = ModelComponent(
mesh: MeshResource.generateBox(size: 0.1),
materials: [SimpleMaterial(color: .red, isMetallic: true)]
)
entity.components[ModelComponent.self] = componentMeshResource Built-in Generators
MeshResource内置生成器
| Method | Parameters |
|---|---|
| |
| Rounded box |
| |
| |
| Vertical plane |
| |
| |
| |
| 方法 | 参数 |
|---|---|
| |
| 圆角立方体 |
| |
| |
| 垂直平面 |
| |
| |
| |
CollisionComponent
碰撞组件
swift
let component = CollisionComponent(
shapes: [
.generateBox(size: SIMD3(0.1, 0.2, 0.1)),
.generateSphere(radius: 0.05),
.generateCapsule(height: 0.3, radius: 0.05),
.generateConvex(from: meshResource)
],
mode: .default, // .default or .trigger
filter: CollisionFilter(
group: CollisionGroup(rawValue: 1),
mask: .all
)
)swift
let component = CollisionComponent(
shapes: [
.generateBox(size: SIMD3(0.1, 0.2, 0.1)),
.generateSphere(radius: 0.05),
.generateCapsule(height: 0.3, radius: 0.05),
.generateConvex(from: meshResource)
],
mode: .default, // .default or .trigger
filter: CollisionFilter(
group: CollisionGroup(rawValue: 1),
mask: .all
)
)ShapeResource Types
ShapeResource类型
| Method | Description | Performance |
|---|---|---|
| Axis-aligned box | Fastest |
| Sphere | Fast |
| Capsule | Fast |
| Convex hull from mesh | Moderate |
| Exact mesh | Slowest (static only) |
| 方法 | 描述 | 性能 |
|---|---|---|
| 轴对齐立方体 | 最快 |
| 球体 | 快 |
| 胶囊体 | 快 |
| 基于网格的凸包 | 中等 |
| 精确网格 | 最慢(仅静态) |
PhysicsBodyComponent
物理体组件
swift
let component = PhysicsBodyComponent(
massProperties: .init(
mass: 1.0,
inertia: SIMD3(repeating: 0.1),
centerOfMass: .zero
),
material: .generate(
staticFriction: 0.5,
dynamicFriction: 0.3,
restitution: 0.4
),
mode: .dynamic // .dynamic, .static, .kinematic
)| Mode | Behavior |
|---|---|
| Physics simulation controls position |
| Immovable, participates in collisions |
| Code-controlled, affects dynamic bodies |
swift
let component = PhysicsBodyComponent(
massProperties: .init(
mass: 1.0,
inertia: SIMD3(repeating: 0.1),
centerOfMass: .zero
),
material: .generate(
staticFriction: 0.5,
dynamicFriction: 0.3,
restitution: 0.4
),
mode: .dynamic // .dynamic, .static, .kinematic
)| 模式 | 行为 |
|---|---|
| 物理模拟控制位置 |
| 不可移动,参与碰撞 |
| 代码控制,影响动态物体 |
PhysicsMotionComponent
物理运动组件
swift
var motion = PhysicsMotionComponent()
motion.linearVelocity = SIMD3(0, 5, 0)
motion.angularVelocity = SIMD3(0, .pi, 0)
entity.components[PhysicsMotionComponent.self] = motionswift
var motion = PhysicsMotionComponent()
motion.linearVelocity = SIMD3(0, 5, 0)
motion.angularVelocity = SIMD3(0, .pi, 0)
entity.components[PhysicsMotionComponent.self] = motionCharacterControllerComponent
角色控制器组件
swift
entity.components[CharacterControllerComponent.self] = CharacterControllerComponent(
radius: 0.3,
height: 1.8,
slopeLimit: .pi / 4,
stepLimit: 0.3
)
// Move character with gravity
entity.moveCharacter(
by: SIMD3(0.1, -0.01, 0),
deltaTime: Float(context.deltaTime),
relativeTo: nil
)swift
entity.components[CharacterControllerComponent.self] = CharacterControllerComponent(
radius: 0.3,
height: 1.8,
slopeLimit: .pi / 4,
stepLimit: 0.3
)
// Move character with gravity
entity.moveCharacter(
by: SIMD3(0.1, -0.01, 0),
deltaTime: Float(context.deltaTime),
relativeTo: nil
)AnchoringComponent
锚定组件
swift
// Plane detection
AnchoringComponent(.plane(.horizontal, classification: .table,
minimumBounds: SIMD2(0.2, 0.2)))
AnchoringComponent(.plane(.vertical, classification: .wall,
minimumBounds: SIMD2(0.5, 0.5)))
// World position
AnchoringComponent(.world(transform: float4x4(...)))
// Image anchor
AnchoringComponent(.image(group: "AR Resources", name: "poster"))
// Face tracking
AnchoringComponent(.face)
// Body tracking
AnchoringComponent(.body)swift
// Plane detection
AnchoringComponent(.plane(.horizontal, classification: .table,
minimumBounds: SIMD2(0.2, 0.2)))
AnchoringComponent(.plane(.vertical, classification: .wall,
minimumBounds: SIMD2(0.5, 0.5)))
// World position
AnchoringComponent(.world(transform: float4x4(...)))
// Image anchor
AnchoringComponent(.image(group: "AR Resources", name: "poster"))
// Face tracking
AnchoringComponent(.face)
// Body tracking
AnchoringComponent(.body)Plane Classification
平面分类
| Classification | Description |
|---|---|
| Horizontal table surface |
| Floor surface |
| Ceiling surface |
| Vertical wall |
| Door |
| Window |
| Chair/couch |
| 分类 | 描述 |
|---|---|
| 水平桌面表面 |
| 地面表面 |
| 天花板表面 |
| 垂直墙面 |
| 门 |
| 窗户 |
| 椅子/沙发 |
Light Components
光源组件
swift
// Directional
let light = DirectionalLightComponent(
color: .white,
intensity: 1000,
isRealWorldProxy: false
)
light.shadow = DirectionalLightComponent.Shadow(
maximumDistance: 10,
depthBias: 0.01
)
// Point
PointLightComponent(
color: .white,
intensity: 1000,
attenuationRadius: 5
)
// Spot
SpotLightComponent(
color: .white,
intensity: 1000,
innerAngleInDegrees: 30,
outerAngleInDegrees: 60,
attenuationRadius: 10
)swift
// Directional
let light = DirectionalLightComponent(
color: .white,
intensity: 1000,
isRealWorldProxy: false
)
light.shadow = DirectionalLightComponent.Shadow(
maximumDistance: 10,
depthBias: 0.01
)
// Point
PointLightComponent(
color: .white,
intensity: 1000,
attenuationRadius: 5
)
// Spot
SpotLightComponent(
color: .white,
intensity: 1000,
innerAngleInDegrees: 30,
outerAngleInDegrees: 60,
attenuationRadius: 10
)Accessibility
无障碍功能
swift
var accessibility = AccessibilityComponent()
accessibility.label = "Red cube"
accessibility.value = "Interactive 3D object"
accessibility.traits = .button
accessibility.isAccessibilityElement = true
entity.components[AccessibilityComponent.self] = accessibilityswift
var accessibility = AccessibilityComponent()
accessibility.label = "Red cube"
accessibility.value = "Interactive 3D object"
accessibility.traits = .button
accessibility.isAccessibilityElement = true
entity.components[AccessibilityComponent.self] = accessibilityAdditional Components
其他组件
| Component | Purpose | Platform |
|---|---|---|
| Fade entity in/out | All |
| Contact shadow beneath entity | All |
| Enable gesture input | visionOS |
| Highlight on gaze/hover | visionOS |
| Multiplayer entity sync | All |
| Custom environment lighting | All |
| Receive IBL from source | All |
| 组件 | 用途 | 平台 |
|---|---|---|
| 淡入/淡出实体 | 所有平台 |
| 实体下方的接触阴影 | 所有平台 |
| 启用手势输入 | visionOS |
| 凝视/悬停时高亮 | visionOS |
| 多玩家实体同步 | 所有平台 |
| 自定义环境光 | 所有平台 |
| 接收来自光源的IBL | 所有平台 |
Part 3: System API
第三部分:系统API
System Protocol
系统协议
swift
protocol System {
init(scene: RealityKit.Scene)
func update(context: SceneUpdateContext)
}swift
protocol System {
init(scene: RealityKit.Scene)
func update(context: SceneUpdateContext)
}SceneUpdateContext
场景更新上下文
| Property | Type | Description |
|---|---|---|
| | Time since last update |
| | The scene |
swift
// Query entities
context.entities(matching: query, updatingSystemWhen: .rendering)| 属性 | 类型 | 描述 |
|---|---|---|
| | 距上次更新的时间 |
| | 当前场景 |
swift
// Query entities
context.entities(matching: query, updatingSystemWhen: .rendering)EntityQuery
实体查询
swift
// Has specific component
EntityQuery(where: .has(HealthComponent.self))
// Has multiple components
EntityQuery(where: .has(HealthComponent.self) && .has(ModelComponent.self))
// Does not have component
EntityQuery(where: .has(EnemyComponent.self) && !.has(DeadComponent.self))swift
// Has specific component
EntityQuery(where: .has(HealthComponent.self))
// Has multiple components
EntityQuery(where: .has(HealthComponent.self) && .has(ModelComponent.self))
// Does not have component
EntityQuery(where: .has(EnemyComponent.self) && !.has(DeadComponent.self))Scene Events
场景事件
| Event | Trigger |
|---|---|
| Every frame |
| Entity added to scene |
| Entity removed from scene |
| Anchor tracking changes |
| Two entities start colliding |
| Collision continues |
| Collision ends |
| Animation finishes |
swift
scene.subscribe(to: CollisionEvents.Began.self, on: entity) { event in
// event.entityA, event.entityB, event.impulse
}| 事件 | 触发条件 |
|---|---|
| 每帧触发 |
| 实体添加到场景时 |
| 实体从场景移除时 |
| 锚定追踪状态变化时 |
| 两个实体开始碰撞时 |
| 碰撞持续时 |
| 碰撞结束时 |
| 动画播放完成时 |
swift
scene.subscribe(to: CollisionEvents.Began.self, on: entity) { event in
// event.entityA, event.entityB, event.impulse
}Part 4: RealityView API
第四部分:RealityView API
Initializers
初始化方法
swift
// Basic (iOS 18+, visionOS 1.0+)
RealityView { content in
// make: Add entities to content
}
// With update
RealityView { content in
// make
} update: { content in
// update: Called when SwiftUI state changes
}
// With placeholder
RealityView { content in
// make (async loading)
} placeholder: {
ProgressView()
}
// With attachments (visionOS)
RealityView { content, attachments in
// make
} update: { content, attachments in
// update
} attachments: {
Attachment(id: "label") { Text("Hello") }
}swift
// Basic (iOS 18+, visionOS 1.0+)
RealityView { content in
// make: Add entities to content
}
// With update
RealityView { content in
// make
} update: { content in
// update: Called when SwiftUI state changes
}
// With placeholder
RealityView { content in
// make (async loading)
} placeholder: {
ProgressView()
}
// With attachments (visionOS)
RealityView { content, attachments in
// make
} update: { content, attachments in
// update
} attachments: {
Attachment(id: "label") { Text("Hello") }
}RealityViewContent
RealityView内容
swift
content.add(entity)
content.remove(entity)
content.entities // EntityCollection
// iOS/macOS — camera content
content.camera // RealityViewCameraContent (non-visionOS)swift
content.add(entity)
content.remove(entity)
content.entities // EntityCollection
// iOS/macOS — camera content
content.camera // RealityViewCameraContent (non-visionOS)Gestures on RealityView
RealityView上的手势
swift
RealityView { content in ... }
.gesture(TapGesture().targetedToAnyEntity().onEnded { value in
let entity = value.entity
})
.gesture(DragGesture().targetedToAnyEntity().onChanged { value in
value.entity.position = value.convert(value.location3D,
from: .local, to: .scene)
})
.gesture(RotateGesture().targetedToAnyEntity().onChanged { value in
// Handle rotation
})
.gesture(MagnifyGesture().targetedToAnyEntity().onChanged { value in
// Handle scale
})swift
RealityView { content in ... }
.gesture(TapGesture().targetedToAnyEntity().onEnded { value in
let entity = value.entity
})
.gesture(DragGesture().targetedToAnyEntity().onChanged { value in
value.entity.position = value.convert(value.location3D,
from: .local, to: .scene)
})
.gesture(RotateGesture().targetedToAnyEntity().onChanged { value in
// Handle rotation
})
.gesture(MagnifyGesture().targetedToAnyEntity().onChanged { value in
// Handle scale
})Part 5: Model3D API
第五部分:Model3D API
swift
// Simple display
Model3D(named: "robot")
// With phases
Model3D(named: "robot") { phase in
switch phase {
case .empty:
ProgressView()
case .success(let model):
model.resizable().scaledToFit()
case .failure(let error):
Text("Failed: \(error.localizedDescription)")
@unknown default:
EmptyView()
}
}
// From URL
Model3D(url: modelURL)swift
// Simple display
Model3D(named: "robot")
// With phases
Model3D(named: "robot") { phase in
switch phase {
case .empty:
ProgressView()
case .success(let model):
model.resizable().scaledToFit()
case .failure(let error):
Text("Failed: \(error.localizedDescription)")
@unknown default:
EmptyView()
}
}
// From URL
Model3D(url: modelURL)Part 6: Material System
第六部分:材质系统
SimpleMaterial
简单材质
swift
var material = SimpleMaterial()
material.color = .init(tint: .blue)
material.metallic = .init(floatLiteral: 1.0)
material.roughness = .init(floatLiteral: 0.3)swift
var material = SimpleMaterial()
material.color = .init(tint: .blue)
material.metallic = .init(floatLiteral: 1.0)
material.roughness = .init(floatLiteral: 0.3)PhysicallyBasedMaterial
基于物理的材质
swift
var material = PhysicallyBasedMaterial()
material.baseColor = .init(tint: .white,
texture: .init(try .load(named: "albedo")))
material.metallic = .init(floatLiteral: 0.0)
material.roughness = .init(floatLiteral: 0.5)
material.normal = .init(texture: .init(try .load(named: "normal")))
material.ambientOcclusion = .init(texture: .init(try .load(named: "ao")))
material.emissiveColor = .init(color: .blue)
material.emissiveIntensity = 2.0
material.clearcoat = .init(floatLiteral: 0.8)
material.clearcoatRoughness = .init(floatLiteral: 0.1)
material.specular = .init(floatLiteral: 0.5)
material.sheen = .init(color: .white)
material.anisotropyLevel = .init(floatLiteral: 0.5)
material.blending = .transparent(opacity: .init(floatLiteral: 0.5))
material.faceCulling = .back // .none, .front, .backswift
var material = PhysicallyBasedMaterial()
material.baseColor = .init(tint: .white,
texture: .init(try .load(named: "albedo")))
material.metallic = .init(floatLiteral: 0.0)
material.roughness = .init(floatLiteral: 0.5)
material.normal = .init(texture: .init(try .load(named: "normal")))
material.ambientOcclusion = .init(texture: .init(try .load(named: "ao")))
material.emissiveColor = .init(color: .blue)
material.emissiveIntensity = 2.0
material.clearcoat = .init(floatLiteral: 0.8)
material.clearcoatRoughness = .init(floatLiteral: 0.1)
material.specular = .init(floatLiteral: 0.5)
material.sheen = .init(color: .white)
material.anisotropyLevel = .init(floatLiteral: 0.5)
material.blending = .transparent(opacity: .init(floatLiteral: 0.5))
material.faceCulling = .back // .none, .front, .backUnlitMaterial
无光照材质
swift
var material = UnlitMaterial()
material.color = .init(tint: .red,
texture: .init(try .load(named: "texture")))
material.blending = .transparent(opacity: .init(floatLiteral: 0.8))swift
var material = UnlitMaterial()
material.color = .init(tint: .red,
texture: .init(try .load(named: "texture")))
material.blending = .transparent(opacity: .init(floatLiteral: 0.8))Special Materials
特殊材质
swift
// Occlusion — invisible but hides content behind it
let occlusionMaterial = OcclusionMaterial()
// Video
let videoMaterial = VideoMaterial(avPlayer: avPlayer)swift
// Occlusion — invisible but hides content behind it
let occlusionMaterial = OcclusionMaterial()
// Video
let videoMaterial = VideoMaterial(avPlayer: avPlayer)TextureResource Loading
TextureResource加载
swift
// From bundle
let texture = try await TextureResource(named: "texture")
// From URL
let texture = try await TextureResource(contentsOf: url)
// With options
let texture = try await TextureResource(named: "texture",
options: .init(semantic: .color)) // .color, .raw, .normal, .hdrColorswift
// From bundle
let texture = try await TextureResource(named: "texture")
// From URL
let texture = try await TextureResource(contentsOf: url)
// With options
let texture = try await TextureResource(named: "texture",
options: .init(semantic: .color)) // .color, .raw, .normal, .hdrColorPart 7: Animation
第七部分:动画
Transform Animation
变换动画
swift
entity.move(
to: Transform(
scale: .one,
rotation: targetRotation,
translation: targetPosition
),
relativeTo: entity.parent,
duration: 1.5,
timingFunction: .easeInOut
)swift
entity.move(
to: Transform(
scale: .one,
rotation: targetRotation,
translation: targetPosition
),
relativeTo: entity.parent,
duration: 1.5,
timingFunction: .easeInOut
)Timing Functions
时间函数
| Function | Curve |
|---|---|
| System default |
| Constant speed |
| Slow start |
| Slow end |
| Slow start and end |
| 函数 | 曲线 |
|---|---|
| 系统默认 |
| 匀速 |
| 慢启动 |
| 慢结束 |
| 慢启动和慢结束 |
Playing Loaded Animations
播放加载的动画
swift
// All animations from USD
for animation in entity.availableAnimations {
let controller = entity.playAnimation(animation)
}
// With options
let controller = entity.playAnimation(
animation.repeat(count: 3),
transitionDuration: 0.3,
startsPaused: false
)swift
// All animations from USD
for animation in entity.availableAnimations {
let controller = entity.playAnimation(animation)
}
// With options
let controller = entity.playAnimation(
animation.repeat(count: 3),
transitionDuration: 0.3,
startsPaused: false
)AnimationPlaybackController
动画播放控制器
swift
let controller = entity.playAnimation(animation)
controller.pause()
controller.resume()
controller.stop()
controller.speed = 0.5 // Half speed
controller.blendFactor = 1.0 // Full blend
controller.isComplete // Check completionswift
let controller = entity.playAnimation(animation)
controller.pause()
controller.resume()
controller.stop()
controller.speed = 0.5 // Half speed
controller.blendFactor = 1.0 // Full blend
controller.isComplete // Check completionPart 8: Audio
第八部分:音频
AudioFileResource
音频文件资源
swift
// Load
let resource = try AudioFileResource.load(
named: "sound.wav",
configuration: .init(
shouldLoop: true,
shouldRandomizeStartTime: false,
mixGroupName: "effects"
)
)swift
// Load
let resource = try AudioFileResource.load(
named: "sound.wav",
configuration: .init(
shouldLoop: true,
shouldRandomizeStartTime: false,
mixGroupName: "effects"
)
)Audio Components
音频组件
swift
// Spatial (3D positional)
entity.components[SpatialAudioComponent.self] = SpatialAudioComponent(
directivity: .beam(focus: 0.5),
distanceAttenuation: .rolloff(factor: 1.0),
gain: 0 // dB
)
// Ambient (non-positional, uniform)
entity.components[AmbientAudioComponent.self] = AmbientAudioComponent(
gain: -6
)
// Channel (multi-channel output)
entity.components[ChannelAudioComponent.self] = ChannelAudioComponent(
gain: 0
)swift
// Spatial (3D positional)
entity.components[SpatialAudioComponent.self] = SpatialAudioComponent(
directivity: .beam(focus: 0.5),
distanceAttenuation: .rolloff(factor: 1.0),
gain: 0 // dB
)
// Ambient (non-positional, uniform)
entity.components[AmbientAudioComponent.self] = AmbientAudioComponent(
gain: -6
)
// Channel (multi-channel output)
entity.components[ChannelAudioComponent.self] = ChannelAudioComponent(
gain: 0
)Playback
播放控制
swift
let controller = entity.playAudio(resource)
controller.pause()
controller.stop()
controller.gain = -3 // Adjust volume (dB)
controller.speed = 1.5 // Pitch shift
entity.stopAllAudio()swift
let controller = entity.playAudio(resource)
controller.pause()
controller.stop()
controller.gain = -3 // Adjust volume (dB)
controller.speed = 1.5 // Pitch shift
entity.stopAllAudio()Part 9: RealityRenderer (Metal Integration)
第九部分:RealityRenderer(Metal集成)
swift
// Low-level Metal rendering of RealityKit content
let renderer = try RealityRenderer()
renderer.entities.append(entity)
// Render to Metal texture
let descriptor = RealityRenderer.CameraOutput.Descriptor(
colorFormat: .bgra8Unorm,
depthFormat: .depth32Float
)
try renderer.render(
viewMatrix: viewMatrix,
projectionMatrix: projectionMatrix,
size: size,
colorTexture: colorTexture,
depthTexture: depthTexture
)swift
// Low-level Metal rendering of RealityKit content
let renderer = try RealityRenderer()
renderer.entities.append(entity)
// Render to Metal texture
let descriptor = RealityRenderer.CameraOutput.Descriptor(
colorFormat: .bgra8Unorm,
depthFormat: .depth32Float
)
try renderer.render(
viewMatrix: viewMatrix,
projectionMatrix: projectionMatrix,
size: size,
colorTexture: colorTexture,
depthTexture: depthTexture
)Resources
资源
WWDC: 2019-603, 2019-605, 2021-10074, 2022-10074, 2023-10080, 2024-10103, 2024-10153
Docs: /realitykit, /realitykit/entity, /realitykit/component, /realitykit/system, /realitykit/realityview, /realitykit/model3d, /realitykit/modelentity, /realitykit/anchorentity, /realitykit/physicallybasedmaterial
Skills: axiom-realitykit, axiom-realitykit-diag, axiom-scenekit-ref
WWDC: 2019-603, 2019-605, 2021-10074, 2022-10074, 2023-10080, 2024-10103, 2024-10153
文档: /realitykit, /realitykit/entity, /realitykit/component, /realitykit/system, /realitykit/realityview, /realitykit/model3d, /realitykit/modelentity, /realitykit/anchorentity, /realitykit/physicallybasedmaterial
技能: axiom-realitykit, axiom-realitykit-diag, axiom-scenekit-ref