@webspatial/platform-visionos 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/web-spatial/JSBCommand.swift +45 -53
- package/web-spatial/SpatialObject.swift +30 -14
- package/web-spatial/WebMsgCommand.swift +50 -66
- package/web-spatial/manager/Dynamic3DManager.swift +10 -12
- package/web-spatial/manager/FileCoordinator.swift +20 -0
- package/web-spatial/manager/WKWebViewManager.swift +9 -1
- package/web-spatial/manifest.swift +4 -1
- package/web-spatial/model/SpatialScene.swift +7 -13
- package/web-spatial/model/Spatialized2DElement.swift +2 -0
- package/web-spatial/model/SpatializedElement.swift +5 -6
- package/web-spatial/model/dynamic3d/SpatialEntity.swift +72 -69
- package/web-spatial/view/Spatialized2DElementView.swift +1 -1
- package/web-spatial/view/SpatializedDynamic3DView.swift +19 -79
- package/web-spatial/view/SpatializedElementView.swift +42 -46
- package/web-spatial.xcodeproj/project.pbxproj +1 -0
- package/web-spatial.xcodeproj/xcshareddata/xcschemes/web-spatial.xcscheme +2 -2
|
@@ -39,7 +39,7 @@ class SpatialScene: SpatialObject, ScrollAbleSpatialElementContainer, WebMsgSend
|
|
|
39
39
|
var parent: (any ScrollAbleSpatialElementContainer)?
|
|
40
40
|
|
|
41
41
|
// Enum
|
|
42
|
-
|
|
42
|
+
enum WindowStyle: String, Codable, CaseIterable {
|
|
43
43
|
case window
|
|
44
44
|
case volume
|
|
45
45
|
}
|
|
@@ -51,7 +51,7 @@ class SpatialScene: SpatialObject, ScrollAbleSpatialElementContainer, WebMsgSend
|
|
|
51
51
|
var setLoadingWindowData = PassthroughSubject<XLoadingViewData, Never>()
|
|
52
52
|
|
|
53
53
|
var url: String = "" // start_url
|
|
54
|
-
|
|
54
|
+
var windowStyle: WindowStyle {
|
|
55
55
|
didSet {
|
|
56
56
|
resetBackgroundMaterialOnWindowStyleChange(windowStyle)
|
|
57
57
|
}
|
|
@@ -224,9 +224,9 @@ class SpatialScene: SpatialObject, ScrollAbleSpatialElementContainer, WebMsgSend
|
|
|
224
224
|
SpatialApp.Instance.closeWindowGroup(self)
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
|
|
227
|
+
var sceneConfig: SceneOptions?
|
|
228
228
|
|
|
229
|
-
|
|
229
|
+
func moveToState(_ newState: SceneStateKind, _ sceneConfig: SceneOptions?) {
|
|
230
230
|
print(" moveToState \(state) to \(newState) ")
|
|
231
231
|
|
|
232
232
|
let oldState = state
|
|
@@ -248,7 +248,7 @@ class SpatialScene: SpatialObject, ScrollAbleSpatialElementContainer, WebMsgSend
|
|
|
248
248
|
|
|
249
249
|
} else if oldState == .idle, newState == .visible {
|
|
250
250
|
// SpatialApp opened SpatialScene
|
|
251
|
-
} else if oldState == .idle
|
|
251
|
+
} else if oldState == .idle, newState == .willVisible {
|
|
252
252
|
// window.open with scene config
|
|
253
253
|
SpatialApp.Instance.openWindowGroup(self, sceneConfig!)
|
|
254
254
|
}
|
|
@@ -328,7 +328,7 @@ class SpatialScene: SpatialObject, ScrollAbleSpatialElementContainer, WebMsgSend
|
|
|
328
328
|
])
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
-
|
|
331
|
+
var didFailLoad = false
|
|
332
332
|
|
|
333
333
|
private func setupWebViewStateListener() {
|
|
334
334
|
spatialWebViewModel.addStateListener(.didStartLoad) {
|
|
@@ -644,9 +644,7 @@ class SpatialScene: SpatialObject, ScrollAbleSpatialElementContainer, WebMsgSend
|
|
|
644
644
|
if let enableDragEndGesture = command.enableDragEndGesture {
|
|
645
645
|
spatializedElement.enableDragEndGesture = enableDragEndGesture
|
|
646
646
|
}
|
|
647
|
-
|
|
648
|
-
spatializedElement.enableRotateStartGesture = enableRotateStartGesture
|
|
649
|
-
}
|
|
647
|
+
|
|
650
648
|
if let enableRotateGesture = command.enableRotateGesture {
|
|
651
649
|
spatializedElement.enableRotateGesture = enableRotateGesture
|
|
652
650
|
}
|
|
@@ -654,10 +652,6 @@ class SpatialScene: SpatialObject, ScrollAbleSpatialElementContainer, WebMsgSend
|
|
|
654
652
|
spatializedElement.enableRotateEndGesture = enableRotateEndGesture
|
|
655
653
|
}
|
|
656
654
|
|
|
657
|
-
if let enableMagnifyStartGesture = command.enableMagnifyStartGesture {
|
|
658
|
-
spatializedElement.enableMagnifyStartGesture = enableMagnifyStartGesture
|
|
659
|
-
}
|
|
660
|
-
|
|
661
655
|
if let enableMagnifyGesture = command.enableMagnifyGesture {
|
|
662
656
|
spatializedElement.enableMagnifyGesture = enableMagnifyGesture
|
|
663
657
|
}
|
|
@@ -53,6 +53,8 @@ class Spatialized2DElement: SpatializedElement, ScrollAbleSpatialElementContaine
|
|
|
53
53
|
self._scrollOffset.y = point.y
|
|
54
54
|
}
|
|
55
55
|
spatialWebViewModel.scrollEnabled = false
|
|
56
|
+
|
|
57
|
+
defaultAlignment = .center
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
// Spatialized2DElement can hold a collection of SpatializedElement children
|
|
@@ -26,20 +26,20 @@ class SpatializedElement: SpatialObject {
|
|
|
26
26
|
var enableDragStartGesture: Bool = false
|
|
27
27
|
var enableDragGesture: Bool = false
|
|
28
28
|
var enableDragEndGesture: Bool = false
|
|
29
|
-
var enableRotateStartGesture: Bool = false
|
|
30
29
|
var enableRotateGesture: Bool = false
|
|
31
30
|
var enableRotateEndGesture: Bool = false
|
|
32
|
-
var enableMagnifyStartGesture: Bool = false
|
|
33
31
|
var enableMagnifyGesture: Bool = false
|
|
34
32
|
var enableMagnifyEndGesture: Bool = false
|
|
35
33
|
var enableTapGesture: Bool = false
|
|
36
34
|
|
|
35
|
+
var defaultAlignment: DepthAlignment = .back
|
|
36
|
+
|
|
37
37
|
var enableGesture: Bool {
|
|
38
|
-
return enableDragStartGesture || enableDragGesture || enableDragEndGesture ||
|
|
38
|
+
return enableDragStartGesture || enableDragGesture || enableDragEndGesture || enableRotateGesture || enableRotateEndGesture || enableMagnifyGesture || enableMagnifyEndGesture || enableTapGesture
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
enum CodingKeys: String, CodingKey {
|
|
42
|
-
case clientX, clientY, width, height, depth, backOffset, transform, rotationAnchor, opacity, visible, scrollWithParent, zIndex, parent, enableGesture, enableTapGesture, enableDragGesture, enableDragEndGesture,
|
|
42
|
+
case clientX, clientY, width, height, depth, backOffset, transform, rotationAnchor, opacity, visible, scrollWithParent, zIndex, parent, enableGesture, enableTapGesture, enableDragStartGesture, enableDragGesture, enableDragEndGesture, enableRotateGesture, enableRotateEndGesture, enableMagnifyGesture, enableMagnifyEndGesture
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
override func encode(to encoder: Encoder) throws {
|
|
@@ -60,12 +60,11 @@ class SpatializedElement: SpatialObject {
|
|
|
60
60
|
try container.encode(parent?.id, forKey: .parent)
|
|
61
61
|
try container.encode(enableGesture, forKey: .enableGesture)
|
|
62
62
|
try container.encode(enableTapGesture, forKey: .enableTapGesture)
|
|
63
|
+
try container.encode(enableDragStartGesture, forKey: .enableDragStartGesture)
|
|
63
64
|
try container.encode(enableDragGesture, forKey: .enableDragGesture)
|
|
64
65
|
try container.encode(enableDragEndGesture, forKey: .enableDragEndGesture)
|
|
65
|
-
try container.encode(enableRotateStartGesture, forKey: .enableRotateStartGesture)
|
|
66
66
|
try container.encode(enableRotateGesture, forKey: .enableRotateGesture)
|
|
67
67
|
try container.encode(enableRotateEndGesture, forKey: .enableRotateEndGesture)
|
|
68
|
-
try container.encode(enableMagnifyStartGesture, forKey: .enableMagnifyStartGesture)
|
|
69
68
|
try container.encode(enableMagnifyGesture, forKey: .enableMagnifyGesture)
|
|
70
69
|
try container.encode(enableMagnifyEndGesture, forKey: .enableMagnifyEndGesture)
|
|
71
70
|
}
|
|
@@ -1,118 +1,123 @@
|
|
|
1
|
-
import SwiftUI
|
|
2
1
|
import RealityKit
|
|
2
|
+
import SwiftUI
|
|
3
3
|
|
|
4
4
|
@Observable
|
|
5
5
|
class SpatialEntity: Entity, SpatialObjectProtocol {
|
|
6
6
|
let spatialId: String
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
private var _isDestroyed: Bool = false
|
|
9
9
|
var isDestroyed: Bool {
|
|
10
10
|
return _isDestroyed
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
var listeners: [String: [(_ object: Any, _ data: Any) -> Void]] = [:]
|
|
14
|
+
|
|
14
15
|
private var _enableTap: Bool = false
|
|
15
16
|
private var _enableRotate: Bool = false
|
|
16
|
-
private var _enableRotateStart: Bool = false
|
|
17
17
|
private var _enableRotateEnd: Bool = false
|
|
18
18
|
private var _enableDrag: Bool = false
|
|
19
19
|
private var _enableDragStart: Bool = false
|
|
20
20
|
private var _enableDragEnd: Bool = false
|
|
21
21
|
private var _enableMagnify: Bool = false
|
|
22
|
-
private var _enableMagnifyStart: Bool = false
|
|
23
22
|
private var _enableMagnifyEnd: Bool = false
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
|
|
24
|
+
var rotation: simd_quatd = .init()
|
|
25
|
+
var spatialChildren: [String: SpatialEntity] = [:]
|
|
26
|
+
var spatialComponents: [String: SpatialComponent] = [:]
|
|
27
|
+
|
|
29
28
|
var enableTap: Bool {
|
|
30
29
|
return _enableTap
|
|
31
30
|
}
|
|
31
|
+
|
|
32
32
|
var enableRotate: Bool {
|
|
33
|
-
return _enableRotate ||
|
|
33
|
+
return _enableRotate || _enableRotateEnd
|
|
34
34
|
}
|
|
35
|
+
|
|
35
36
|
var enableDrag: Bool {
|
|
36
|
-
return _enableDrag || _enableDragStart
|
|
37
|
+
return _enableDrag || _enableDragStart || _enableDragEnd
|
|
37
38
|
}
|
|
39
|
+
|
|
38
40
|
var enableMagnify: Bool {
|
|
39
|
-
return _enableMagnify ||
|
|
41
|
+
return _enableMagnify || _enableMagnifyEnd
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
|
|
42
44
|
var enableRotateEnd: Bool {
|
|
43
45
|
return _enableRotateEnd
|
|
44
46
|
}
|
|
47
|
+
|
|
45
48
|
var enableDragEnd: Bool {
|
|
46
49
|
return _enableDragEnd
|
|
47
50
|
}
|
|
51
|
+
|
|
48
52
|
var enableMagnifyEnd: Bool {
|
|
49
53
|
return _enableMagnifyEnd
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
|
|
52
56
|
var enableInteractive: Bool {
|
|
53
|
-
return enableTap || enableRotate || enableDrag || enableMagnify
|
|
57
|
+
return enableTap || enableRotate || enableDrag || enableMagnify
|
|
54
58
|
}
|
|
55
|
-
|
|
59
|
+
|
|
56
60
|
required init() {
|
|
57
|
-
|
|
61
|
+
spatialId = UUID().uuidString
|
|
58
62
|
super.init()
|
|
59
|
-
SpatialObject.
|
|
63
|
+
SpatialObject.serialQueue.sync {
|
|
64
|
+
SpatialObject.objects[spatialId] = self
|
|
65
|
+
}
|
|
60
66
|
SpatialObjectWeakRefManager.setWeakRef(spatialId, self)
|
|
61
67
|
}
|
|
62
|
-
|
|
63
|
-
init(_ _name:String){
|
|
64
|
-
|
|
68
|
+
|
|
69
|
+
init(_ _name: String) {
|
|
70
|
+
spatialId = UUID().uuidString
|
|
65
71
|
super.init()
|
|
66
|
-
|
|
67
|
-
SpatialObject.
|
|
72
|
+
name = _name
|
|
73
|
+
SpatialObject.serialQueue.sync {
|
|
74
|
+
SpatialObject.objects[spatialId] = self
|
|
75
|
+
}
|
|
68
76
|
SpatialObjectWeakRefManager.setWeakRef(spatialId, self)
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
func addChild(entity:SpatialEntity){
|
|
78
|
+
|
|
79
|
+
func addChild(entity: SpatialEntity) {
|
|
72
80
|
spatialChildren[entity.spatialId] = entity
|
|
73
81
|
super.addChild(entity)
|
|
74
82
|
}
|
|
75
|
-
|
|
76
|
-
func removeChild(id:String){
|
|
77
|
-
if let entity = spatialChildren[id]{
|
|
83
|
+
|
|
84
|
+
func removeChild(id: String) {
|
|
85
|
+
if let entity = spatialChildren[id] {
|
|
78
86
|
super.removeChild(entity)
|
|
79
87
|
spatialChildren.removeValue(forKey: id)
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
88
|
+
} else {
|
|
82
89
|
print("no child found")
|
|
83
90
|
}
|
|
84
91
|
}
|
|
85
|
-
|
|
86
|
-
func removeFromParent(){
|
|
87
|
-
if let parent = parent as? SpatialEntity{
|
|
92
|
+
|
|
93
|
+
func removeFromParent() {
|
|
94
|
+
if let parent = parent as? SpatialEntity {
|
|
88
95
|
parent.removeChild(self)
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
|
-
|
|
98
|
+
|
|
92
99
|
func addComponent(_ comp: SpatialComponent) {
|
|
93
100
|
spatialComponents[comp.type.rawValue] = comp
|
|
94
101
|
comp.addToEntity(entity: self)
|
|
95
102
|
}
|
|
96
|
-
|
|
103
|
+
|
|
97
104
|
func removeComponent(_ comp: SpatialComponent) {
|
|
98
105
|
if spatialComponents[comp.type.rawValue] != nil {
|
|
99
106
|
comp.removeFromEntity(entity: self)
|
|
100
107
|
spatialComponents.removeValue(forKey: comp.type.rawValue)
|
|
101
108
|
}
|
|
102
109
|
}
|
|
103
|
-
|
|
104
|
-
func updateTransform(_ matrix:[String:Float]){
|
|
110
|
+
|
|
111
|
+
func updateTransform(_ matrix: [String: Float]) {
|
|
105
112
|
transform.matrix = float4x4([matrix["0"]!, matrix["1"]!, matrix["2"]!, matrix["3"]!], [matrix["4"]!, matrix["5"]!, matrix["6"]!, matrix["7"]!], [matrix["8"]!, matrix["9"]!, matrix["10"]!, matrix["11"]!], [matrix["12"]!, matrix["13"]!, matrix["14"]!, matrix["15"]!])
|
|
106
113
|
}
|
|
107
|
-
|
|
108
|
-
func updateGesture(_ type:String, _ isEable:Bool){
|
|
109
|
-
switch WebSpatialGestureType(rawValue: type){
|
|
114
|
+
|
|
115
|
+
func updateGesture(_ type: String, _ isEable: Bool) {
|
|
116
|
+
switch WebSpatialGestureType(rawValue: type) {
|
|
110
117
|
case .spatialtap:
|
|
111
118
|
_enableTap = isEable
|
|
112
119
|
case .spatialrotate:
|
|
113
120
|
_enableRotate = isEable
|
|
114
|
-
case .spatialrotatestart:
|
|
115
|
-
_enableRotateStart = isEable
|
|
116
121
|
case .spatialrotateend:
|
|
117
122
|
_enableRotateEnd = isEable
|
|
118
123
|
case .spatialdrag:
|
|
@@ -123,46 +128,42 @@ class SpatialEntity: Entity, SpatialObjectProtocol {
|
|
|
123
128
|
_enableDragEnd = isEable
|
|
124
129
|
case .spatialmagnify:
|
|
125
130
|
_enableMagnify = isEable
|
|
126
|
-
case .spatialmagnifystart:
|
|
127
|
-
_enableMagnifyStart = isEable
|
|
128
131
|
case .spatialmagnifyend:
|
|
129
132
|
_enableMagnifyEnd = isEable
|
|
130
133
|
default:
|
|
131
134
|
return
|
|
132
135
|
}
|
|
133
|
-
|
|
136
|
+
|
|
134
137
|
if enableInteractive {
|
|
135
|
-
if !components.has(InputTargetComponent.self){
|
|
138
|
+
if !components.has(InputTargetComponent.self) {
|
|
136
139
|
components.set(InputTargetComponent())
|
|
137
140
|
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if components.has(InputTargetComponent.self){
|
|
141
|
+
} else {
|
|
142
|
+
if components.has(InputTargetComponent.self) {
|
|
141
143
|
components.remove(InputTargetComponent.self)
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
|
-
|
|
146
|
-
static func findNearestParent(entity: Entity) -> SpatialEntity?{
|
|
147
|
-
if let parent = entity.parent as? SpatialEntity{
|
|
147
|
+
|
|
148
|
+
static func findNearestParent(entity: Entity) -> SpatialEntity? {
|
|
149
|
+
if let parent = entity.parent as? SpatialEntity {
|
|
148
150
|
return parent
|
|
149
|
-
}
|
|
150
|
-
else if entity.parent != nil {
|
|
151
|
+
} else if entity.parent != nil {
|
|
151
152
|
return findNearestParent(entity: entity.parent!)
|
|
152
153
|
}
|
|
153
154
|
return nil
|
|
154
155
|
}
|
|
155
|
-
|
|
156
|
+
|
|
156
157
|
func setRotation(_ rotation: simd_quatd) {
|
|
157
158
|
self.rotation = rotation
|
|
158
|
-
|
|
159
|
+
transform.rotation = simd_quatf(ix: Float(rotation.imag.x), iy: Float(rotation.imag.y), iz: Float(rotation.imag.z), r: Float(rotation.real))
|
|
159
160
|
}
|
|
160
|
-
|
|
161
|
+
|
|
161
162
|
// Encodable
|
|
162
163
|
enum CodingKeys: String, CodingKey {
|
|
163
164
|
case id, name, isDestroyed, children, components
|
|
164
165
|
}
|
|
165
|
-
|
|
166
|
+
|
|
166
167
|
func encode(to encoder: any Encoder) throws {
|
|
167
168
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
168
169
|
try container.encode(spatialId, forKey: .id)
|
|
@@ -171,12 +172,12 @@ class SpatialEntity: Entity, SpatialObjectProtocol {
|
|
|
171
172
|
try container.encode(spatialChildren, forKey: .children)
|
|
172
173
|
try container.encode(spatialComponents, forKey: .components)
|
|
173
174
|
}
|
|
174
|
-
|
|
175
|
+
|
|
175
176
|
// Equatable
|
|
176
177
|
static func == (lhs: SpatialEntity, rhs: SpatialEntity) -> Bool {
|
|
177
178
|
return lhs.spatialId == rhs.spatialId
|
|
178
179
|
}
|
|
179
|
-
|
|
180
|
+
|
|
180
181
|
func destroy() {
|
|
181
182
|
if _isDestroyed {
|
|
182
183
|
return
|
|
@@ -187,24 +188,26 @@ class SpatialEntity: Entity, SpatialObjectProtocol {
|
|
|
187
188
|
|
|
188
189
|
emit(event: SpatialObject.Events.Destroyed.rawValue, data: ["object": self])
|
|
189
190
|
listeners = [:]
|
|
190
|
-
SpatialObject.
|
|
191
|
+
SpatialObject.serialQueue.sync {
|
|
192
|
+
SpatialObject.objects.removeValue(forKey: spatialId)
|
|
193
|
+
}
|
|
191
194
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if
|
|
195
|
+
|
|
196
|
+
func onDestroy() {
|
|
197
|
+
if parent != nil {
|
|
195
198
|
removeFromParent()
|
|
196
199
|
}
|
|
197
200
|
components.removeAll()
|
|
198
|
-
|
|
201
|
+
for (id, child) in spatialChildren {
|
|
199
202
|
child.destroy()
|
|
200
203
|
}
|
|
201
204
|
spatialChildren = [:]
|
|
202
|
-
|
|
205
|
+
for (id, components) in spatialComponents {
|
|
203
206
|
components.destroy()
|
|
204
207
|
}
|
|
205
208
|
spatialComponents = [:]
|
|
206
209
|
}
|
|
207
|
-
|
|
210
|
+
|
|
208
211
|
deinit {
|
|
209
212
|
SpatialObjectWeakRefManager.removeWeakRef(spatialId)
|
|
210
213
|
}
|
|
@@ -71,7 +71,7 @@ struct Spatialized2DElementView: View {
|
|
|
71
71
|
private var dragWebGesture: some Gesture {
|
|
72
72
|
DragGesture()
|
|
73
73
|
.onChanged { gesture in
|
|
74
|
-
print("\(spatialized2DElement.name) dragWebGesture")
|
|
74
|
+
// print("\(spatialized2DElement.name) dragWebGesture")
|
|
75
75
|
if spatialized2DElement.scrollPageEnabled {
|
|
76
76
|
if !gestureData.dragStarted {
|
|
77
77
|
gestureData.dragStarted = true
|
|
@@ -29,37 +29,22 @@ struct SpatializedDynamic3DView: View {
|
|
|
29
29
|
RotateGesture3D().targetedToAnyEntity().onChanged { value in
|
|
30
30
|
// Always forward rotate gesture events to JS
|
|
31
31
|
if let entity = value.entity as? SpatialEntity {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
spatialScene.sendWebMsg(entity.spatialId, startEvent)
|
|
41
|
-
isRotate = true
|
|
42
|
-
} else {
|
|
43
|
-
let gestureEvent = WebSpatialRotateGuestureEvent(
|
|
44
|
-
detail: .init(
|
|
45
|
-
rotation: value.rotation,
|
|
46
|
-
startAnchor3D: value.startAnchor3D,
|
|
47
|
-
startLocation3D: value.startLocation3D
|
|
32
|
+
let gestureEvent = WebSpatialRotateGuestureEvent(
|
|
33
|
+
detail: .init(
|
|
34
|
+
quaternion: Quaternion(
|
|
35
|
+
x: value.rotation.quaternion.imag.x,
|
|
36
|
+
y: value.rotation.quaternion.imag.y,
|
|
37
|
+
z: value.rotation.quaternion.imag.z,
|
|
38
|
+
w: value.rotation.quaternion.real
|
|
48
39
|
)
|
|
49
40
|
)
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
)
|
|
42
|
+
spatialScene.sendWebMsg(entity.spatialId, gestureEvent)
|
|
52
43
|
}
|
|
53
44
|
}.onEnded { value in
|
|
54
45
|
// Always forward rotate end event to JS
|
|
55
46
|
if let entity = value.entity as? SpatialEntity {
|
|
56
|
-
let gestureEvent = WebSpatialRotateEndGuestureEvent(
|
|
57
|
-
detail: .init(
|
|
58
|
-
rotation: value.rotation,
|
|
59
|
-
startAnchor3D: value.startAnchor3D,
|
|
60
|
-
startLocation3D: value.startLocation3D
|
|
61
|
-
)
|
|
62
|
-
)
|
|
47
|
+
let gestureEvent = WebSpatialRotateEndGuestureEvent()
|
|
63
48
|
spatialScene.sendWebMsg(entity.spatialId, gestureEvent)
|
|
64
49
|
}
|
|
65
50
|
isRotate = false
|
|
@@ -70,40 +55,16 @@ struct SpatializedDynamic3DView: View {
|
|
|
70
55
|
MagnifyGesture().targetedToAnyEntity().onChanged { value in
|
|
71
56
|
// Always forward magnify gesture events to JS
|
|
72
57
|
if let entity = value.entity as? SpatialEntity {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
startLocation3D: value.startLocation3D,
|
|
79
|
-
startAnchor3D: value.startAnchor3D
|
|
80
|
-
)
|
|
81
|
-
)
|
|
82
|
-
spatialScene.sendWebMsg(entity.spatialId, startEvent)
|
|
83
|
-
isScale = true
|
|
84
|
-
} else {
|
|
85
|
-
let gestureEvent = WebSpatialMagnifyGuestureEvent(
|
|
86
|
-
detail: .init(
|
|
87
|
-
magnification: value.magnification,
|
|
88
|
-
velocity: value.velocity,
|
|
89
|
-
startLocation3D: value.startLocation3D,
|
|
90
|
-
startAnchor3D: value.startAnchor3D
|
|
91
|
-
)
|
|
92
|
-
)
|
|
93
|
-
spatialScene.sendWebMsg(entity.spatialId, gestureEvent)
|
|
94
|
-
}
|
|
58
|
+
let detail = WebSpatialMagnifyGuestureEventDetail(magnification: value.magnification)
|
|
59
|
+
let gestureEvent = WebSpatialMagnifyGuestureEvent(
|
|
60
|
+
detail: detail
|
|
61
|
+
)
|
|
62
|
+
spatialScene.sendWebMsg(entity.spatialId, gestureEvent)
|
|
95
63
|
}
|
|
96
64
|
}.onEnded { value in
|
|
97
65
|
// Always forward magnify end event to JS
|
|
98
66
|
if let entity = value.entity as? SpatialEntity {
|
|
99
|
-
let gestureEvent = WebSpatialMagnifyEndGuestureEvent(
|
|
100
|
-
detail: .init(
|
|
101
|
-
magnification: value.magnification,
|
|
102
|
-
velocity: value.velocity,
|
|
103
|
-
startLocation3D: value.startLocation3D,
|
|
104
|
-
startAnchor3D: value.startAnchor3D
|
|
105
|
-
)
|
|
106
|
-
)
|
|
67
|
+
let gestureEvent = WebSpatialMagnifyEndGuestureEvent()
|
|
107
68
|
spatialScene.sendWebMsg(entity.spatialId, gestureEvent)
|
|
108
69
|
}
|
|
109
70
|
isScale = false
|
|
@@ -117,26 +78,14 @@ struct SpatializedDynamic3DView: View {
|
|
|
117
78
|
if !isDrag {
|
|
118
79
|
let startEvent = WebSpatialDragStartGuestureEvent(
|
|
119
80
|
detail: .init(
|
|
120
|
-
|
|
121
|
-
startLocation3D: value.startLocation3D,
|
|
122
|
-
translation3D: value.translation3D,
|
|
123
|
-
predictedEndTranslation3D: value.predictedEndTranslation3D,
|
|
124
|
-
predictedEndLocation3D: value.predictedEndLocation3D,
|
|
125
|
-
velocity: value.velocity
|
|
81
|
+
startLocation3D: value.startLocation3D
|
|
126
82
|
)
|
|
127
83
|
)
|
|
128
84
|
spatialScene.sendWebMsg(entity.spatialId, startEvent)
|
|
129
85
|
isDrag = true
|
|
130
86
|
} else {
|
|
131
87
|
let gestureEvent = WebSpatialDragGuestureEvent(
|
|
132
|
-
detail: .init(
|
|
133
|
-
location3D: value.location3D,
|
|
134
|
-
startLocation3D: value.startLocation3D,
|
|
135
|
-
translation3D: value.translation3D,
|
|
136
|
-
predictedEndTranslation3D: value.predictedEndTranslation3D,
|
|
137
|
-
predictedEndLocation3D: value.predictedEndLocation3D,
|
|
138
|
-
velocity: value.velocity
|
|
139
|
-
)
|
|
88
|
+
detail: .init(translation3D: value.translation3D)
|
|
140
89
|
)
|
|
141
90
|
spatialScene.sendWebMsg(entity.spatialId, gestureEvent)
|
|
142
91
|
}
|
|
@@ -144,16 +93,7 @@ struct SpatializedDynamic3DView: View {
|
|
|
144
93
|
}.onEnded { value in
|
|
145
94
|
// Always forward drag end event to JS
|
|
146
95
|
if let entity = value.entity as? SpatialEntity {
|
|
147
|
-
let gestureEvent = WebSpatialDragEndGuestureEvent(
|
|
148
|
-
detail: .init(
|
|
149
|
-
location3D: value.location3D,
|
|
150
|
-
startLocation3D: value.startLocation3D,
|
|
151
|
-
translation3D: value.translation3D,
|
|
152
|
-
predictedEndTranslation3D: value.predictedEndTranslation3D,
|
|
153
|
-
predictedEndLocation3D: value.predictedEndLocation3D,
|
|
154
|
-
velocity: value.velocity
|
|
155
|
-
)
|
|
156
|
-
)
|
|
96
|
+
let gestureEvent = WebSpatialDragEndGuestureEvent()
|
|
157
97
|
spatialScene.sendWebMsg(entity.spatialId, gestureEvent)
|
|
158
98
|
}
|
|
159
99
|
isDrag = false
|