-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelloWorldEarthOfVisionOs.swift
70 lines (61 loc) · 2.24 KB
/
HelloWorldEarthOfVisionOs.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
The model of the Earth.
*/
import SwiftUI
import RealityKit
import WorldAssets
/// The model of the Earth.
struct Earth: View {
var earthConfiguration: EarthEntity.Configuration = .init()
var satelliteConfiguration: [SatelliteEntity.Configuration] = []
var moonConfiguration: SatelliteEntity.Configuration? = nil
var animateUpdates: Bool = false
var axCustomActionHandler: ((_: AccessibilityEvents.CustomAction) -> Void)? = nil
/// The Earth entity that the view creates and stores for later updates.
@State private var earthEntity: EarthEntity?
var body: some View {
RealityView { content in
// Create an earth entity with tilt, rotation, a moon, and so on.
let earthEntity = await EarthEntity(
configuration: earthConfiguration,
satelliteConfiguration: satelliteConfiguration,
moonConfiguration: moonConfiguration)
content.add(earthEntity)
// Handle custom accessibility events.
if let axCustomActionHandler {
_ = content.subscribe(
to: AccessibilityEvents.CustomAction.self,
on: nil,
componentType: nil,
axCustomActionHandler)
}
// Store for later updates.
self.earthEntity = earthEntity
} update: { content in
// Reconfigure everything when any configuration changes.
earthEntity?.update(
configuration: earthConfiguration,
satelliteConfiguration: satelliteConfiguration,
moonConfiguration: moonConfiguration,
animateUpdates: animateUpdates)
}
}
}
#Preview {
Earth(
earthConfiguration: EarthEntity.Configuration.orbitEarthDefault,
satelliteConfiguration: [
SatelliteEntity.Configuration(
name: "Satellite",
isVisible: true,
inclination: .degrees(30),
speedRatio: 10,
scale: 1,
altitude: 0.4,
traceWidth: 400,
isTraceVisible: true)
]
)
}