2023 Spatial ComputingDeveloper Tools
WWDC23 · 21 min · Spatial Computing / Developer Tools
Meet RealityKit Trace
Discover how you can use RealityKit Trace to improve the performance of your spatial computing apps. Explore performance profiling guidelines for this platform and learn how the RealityKit Trace template can help you optimize rendering for your apps. We’ll also provide guidance on profiling various types of content in your app to help pinpoint performance issues.
Watch at developer.apple.com ↗Chapters
Code shown on screen · 5 snippets
SwiftUI View with High Offscreens
private struct Item: View {
var module: Module
// The corner radius of the item's hightlight when selected or hovering.
let cornerRadius = 20.0
var body: some View {
NavigationLink(value: module) {
VStack(alignment: .leading, spacing: 3) {
Text(module.eyebrow)
.font(.titleHeading)
.foregroundStyle(.secondary)
VStack(alignment: .leading, spacing: 7) {
Text(module.heading)
.font(.largeTitle)
Text(module.abstract)
}
}
.padding(.horizontal, 5)
.padding(.vertical, 20)
}
.buttonStyle(.bordered)
.shadow(radius: 10)
.buttonBorderShape(.roundedRectangle(radius: cornerRadius))
.frame(minWidth: 150, maxWidth: 280)
}
} EarthEntity Factory
class EarthEntity: Entity {
static func makeGlobe() -> EarthEntity {
EarthEntity(earthModel: Entity.makeModel(
name: "Earth",
filename: "Globe",
radius: 0.35,
color: .blue)
)
}
static func makeCloudyEarth() -> EarthEntity {
let earthModel = Entity()
earthModel.name = "Earth"
Task {
if let scene = await loadFromRealityComposerPro(
named: WorldAssets.rootNodeName,
fromSceneNamed: WorldAssets.sceneName
) {
earthModel.addChild(scene)
} else {
fatalError("Unable to load earth model")
}
}
return EarthEntity(earthModel: earthModel)
}
} Orbit SwiftUI View Body
struct Orbit: View {
private var model: ViewModel
var body: some View {
Earth(
world: EarthEntity.makeGlobe(),
earthConfiguration: model.orbitEarth,
satelliteConfiguration: [model.orbitSatellite],
moonConfiguration: model.orbitMoon,
showSun: true,
sunAngle: model.orbitSunAngle,
animateUpdates: true
)
.place(
initialPosition: Point3D([475, -1200.0, -1200.0]),
useCustomGesture: model.useCustomGesture,
handOffset: model.customGestureHandOffset,
isCustomGestureAnimated: model.isCustomGestureAnimated,
debugCustomGesture: model.debugCustomGesture,
scale: $model.orbitEarth.scale)
}
} SwiftUI ViewModel
class ViewModel: ObservableObject {
// MARK: - Navigation
var navigationPath: [Module] = []
var titleText: String = ""
var isTitleFinished: Bool = false
var finalTitle: String = "Hello World"
// MARK: - Globe
var globeEarthEntity: EarthEntity = .makeGlobe()
var isShowingGlobe: Bool = false
var globeEarth: EarthEntity.Configuration = .globeEarthDefault
var globeEarthOffset: SIMD3<Double> = [0, 0, 0]
var globePanelOffset: SIMD3<Double> = [0, -50, 30]
var showSatelliteButton: Bool = false
var isShowingSatellite: Bool = false
// MARK: - Orbit
var orbitEarthEntity: EarthEntity = .makeGlobe()
var useCustomGesture: Bool = true
var customGestureHandOffset: SIMD3<Float> = [0, 0.21, -0.07]
var isCustomGestureAnimated: Bool = false
var debugCustomGesture: Bool = false
var orbitSatelliteScale: Float = 0.9
var orbitMoonScale: Float = 0.9
var orbitTelescopeScale: Float = 0.8
var orbitSatelliteZOffset: Double = 100
var orbitMoonZOffset: Double = 100
var orbitTelescopeZOffset: Double = 100
var isShowingOrbit: Bool = false
var orbitImmersionStyle: ImmersionStyle = .mixed
var orbitEarth: EarthEntity.Configuration = .orbitEarthDefault
var orbitSatellite: SatelliteEntity.Configuration = .orbitSatelliteDefault
var orbitMoon: SatelliteEntity.Configuration = .orbitMoonDefault
var orbitSunAngle: Angle = .degrees(150)
var orbitSunAngleBinding: Binding<Float> {
Binding<Float>(
get: { Float(self.orbitSunAngle.degrees) },
set: { self.orbitSunAngle = .degrees(Double($0)) }
)
}
// MARK: - Solar System
var solarEarthEntity: EarthEntity = .makeCloudyEarth()
var isShowingSolar: Bool = false
var solarImmersionStyle: ImmersionStyle = .full
var solarEarth: EarthEntity.Configuration = .solarEarthDefault
var solarSatellite: SatelliteEntity.Configuration = .solarTelescopeDefault
var solarMoon: SatelliteEntity.Configuration = .solarMoonDefault
var solarSunDistance: Double = 700
var solarSunAngle: Angle = .degrees(280)
var solarSunSpotIntensity: Float = 10.5
var solarSunEmissionIntensity: Float = 10.5
var solarSunPosition: SIMD3<Float> {
[Float(solarSunDistance * sin(solarSunAngle.radians)),
0,
Float(solarSunDistance * cos(solarSunAngle.radians))]
}
} SwiftUI Orbit View Body
struct Orbit: View {
private var model: ViewModel
var body: some View {
Earth(
world: model.globeEarthEntity,
earthConfiguration: model.orbitEarth,
satelliteConfiguration: [model.orbitSatellite],
moonConfiguration: model.orbitMoon,
showSun: true,
sunAngle: model.orbitSunAngle,
animateUpdates: true
)
.place(
initialPosition: Point3D([475, -1200.0, -1200.0]),
useCustomGesture: model.useCustomGesture,
handOffset: model.customGestureHandOffset,
isCustomGestureAnimated: model.isCustomGestureAnimated,
debugCustomGesture: model.debugCustomGesture,
scale: $model.orbitEarth.scale)
}
} Resources
Related sessions
-
21 min -
29 min -
43 min -
32 min -
40 min