@webspatial/platform-visionos 1.0.3 → 1.0.5

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.
Files changed (74) hide show
  1. package/package.json +2 -2
  2. package/web-spatial/EventEmitter.swift +56 -0
  3. package/web-spatial/JSBCommand.swift +348 -0
  4. package/web-spatial/SpatialObject.swift +108 -0
  5. package/web-spatial/WebMsgCommand.swift +119 -0
  6. package/web-spatial/WebSpatialApp.swift +111 -0
  7. package/web-spatial/{libs/uiKitDelegate/Window.swift → Window.swift} +1 -0
  8. package/web-spatial/manager/Dynamic3DManager.swift +114 -0
  9. package/web-spatial/manager/JSBManager.swift +148 -0
  10. package/web-spatial/manager/WKWebViewManager.swift +39 -0
  11. package/web-spatial/{libs/webView/manifest.swift → manifest.swift} +16 -5
  12. package/web-spatial/model/SpatialApp.swift +190 -0
  13. package/web-spatial/model/SpatialScene.swift +1042 -0
  14. package/web-spatial/model/Spatialized2DElement.swift +128 -0
  15. package/web-spatial/model/SpatializedDynamic3DElement.swift +34 -0
  16. package/web-spatial/model/SpatializedElement.swift +95 -0
  17. package/web-spatial/model/SpatializedStatic3DElement.swift +19 -0
  18. package/web-spatial/model/dynamic3d/Geometry.swift +95 -0
  19. package/web-spatial/model/dynamic3d/SpatialComponent.swift +72 -0
  20. package/web-spatial/model/dynamic3d/SpatialEntity.swift +211 -0
  21. package/web-spatial/model/dynamic3d/SpatialMaterial.swift +39 -0
  22. package/web-spatial/model/dynamic3d/SpatialModelEntity.swift +39 -0
  23. package/web-spatial/model/dynamic3d/SpatialModelResource.swift +38 -0
  24. package/web-spatial/model/dynamic3d/SpatialTextureResource.swift +18 -0
  25. package/web-spatial/protocol/ScrollAbleSpatialElementContainer.swift +1 -0
  26. package/web-spatial/protocol/SpatialScrollAble.swift +8 -0
  27. package/web-spatial/protocol/SpatializedElementContainer.swift +8 -0
  28. package/web-spatial/protocol/WebMsgSender.swift +5 -0
  29. package/web-spatial/types/Vec2.swift +12 -0
  30. package/web-spatial/types/Vec3.swift +7 -0
  31. package/web-spatial/view/SceneHandlerUIView.swift +92 -0
  32. package/web-spatial/{views/ui/NavView.swift → view/SpatialNavView.swift} +149 -77
  33. package/web-spatial/view/SpatialSceneContentView.swift +218 -0
  34. package/web-spatial/view/SpatialSceneView.swift +53 -0
  35. package/web-spatial/view/Spatialized2DElementView.swift +96 -0
  36. package/web-spatial/view/SpatializedDynamic3DView.swift +104 -0
  37. package/web-spatial/view/SpatializedElementView.swift +178 -0
  38. package/web-spatial/view/SpatializedStatic3DView.swift +70 -0
  39. package/web-spatial/{views → view/view-modifier}/MaterialWithBorderCornerModifier.swift +28 -8
  40. package/web-spatial/webview/SpatialWebController.swift +300 -0
  41. package/web-spatial/webview/SpatialWebView.swift +34 -0
  42. package/web-spatial/webview/SpatialWebViewModel.swift +307 -0
  43. package/web-spatial.xcodeproj/project.pbxproj +126 -207
  44. package/web-spatial/libs/EventEmitter.swift +0 -25
  45. package/web-spatial/libs/SpatialComponent.swift +0 -24
  46. package/web-spatial/libs/SpatialEntity.swift +0 -172
  47. package/web-spatial/libs/SpatialInputComponent.swift +0 -19
  48. package/web-spatial/libs/SpatialMeshResource.swift +0 -12
  49. package/web-spatial/libs/SpatialModel3DComponent.swift +0 -51
  50. package/web-spatial/libs/SpatialModelComponent.swift +0 -25
  51. package/web-spatial/libs/SpatialObject.swift +0 -140
  52. package/web-spatial/libs/SpatialPhysicallyBasedMaterial.swift +0 -19
  53. package/web-spatial/libs/SpatialViewComponent.swift +0 -8
  54. package/web-spatial/libs/SpatialWindowComponent.swift +0 -454
  55. package/web-spatial/libs/SpatialWindowContainer.swift +0 -153
  56. package/web-spatial/libs/Utils/CommandManager.swift +0 -823
  57. package/web-spatial/libs/Utils/PerfClock.swift +0 -43
  58. package/web-spatial/libs/Utils/SceneManager.swift +0 -101
  59. package/web-spatial/libs/Utils/WindowContainerMgr.swift +0 -122
  60. package/web-spatial/libs/json/JsonParser.swift +0 -45
  61. package/web-spatial/libs/webView/UpdateSystem.swift +0 -26
  62. package/web-spatial/libs/webView/backend/NativeWebView.swift +0 -350
  63. package/web-spatial/views/ImmersiveView.swift +0 -17
  64. package/web-spatial/views/OpenDismissHandlerUI.swift +0 -45
  65. package/web-spatial/views/PlainWindowContainerView.swift +0 -132
  66. package/web-spatial/views/SpatialModel3DView.swift +0 -187
  67. package/web-spatial/views/SpatialViewUI.swift +0 -168
  68. package/web-spatial/views/SpatialWebViewUI.swift +0 -179
  69. package/web-spatial/views/VolumetricWindowContainerView.swift +0 -30
  70. package/web-spatial/web_spatialApp.swift +0 -141
  71. /package/web-spatial/{libs/Utils → Utils}/ColorExtension.swift +0 -0
  72. /package/web-spatial/{libs/Utils → Utils}/Logger.swift +0 -0
  73. /package/web-spatial/{views → view}/LoadingView.swift +0 -0
  74. /package/web-spatial/{views → view/view-modifier}/HideViewModifier.swift +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webspatial/platform-visionos",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Used to publish WebSpatial projects to Apple Vision Pro",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -19,7 +19,7 @@
19
19
  "package.json"
20
20
  ],
21
21
  "author": "",
22
- "license": "ISC",
22
+ "license": "MIT",
23
23
  "dependencies": {},
24
24
  "devDependencies": {},
25
25
  "publishConfig": {
@@ -0,0 +1,56 @@
1
+ class EventEmitter {
2
+ private var listeners: [String: [(_ object: Any, _ data: Any) -> Void]] = [:]
3
+
4
+ public func on(event: String, listener: @escaping (_ object: Any, _ data: Any) -> Void) {
5
+ if listeners[event] == nil {
6
+ listeners[event] = []
7
+ }
8
+ listeners[event]?.append(listener)
9
+ }
10
+
11
+ public func emit(event: String, data: Any) {
12
+ listeners[event]?.forEach { listener in
13
+ listener(self, data)
14
+ }
15
+ }
16
+
17
+ public func off(event: String, listener: @escaping (_ object: Any, _ data: Any) -> Void) {
18
+ listeners[event]?.removeAll(where: { $0 as AnyObject === listener as AnyObject })
19
+ }
20
+
21
+ public func reset(){
22
+ listeners = [:]
23
+ }
24
+ }
25
+
26
+ protocol EventEmitterProtocol{
27
+ var listeners: [String: [(_ object: Any, _ data: Any) -> Void]] {get set}
28
+
29
+ mutating func on(event: String, listener: @escaping (_ object: Any, _ data: Any) -> Void)
30
+ func emit(event: String, data: Any)
31
+ mutating func off(event: String, listener: @escaping (_ object: Any, _ data: Any) -> Void)
32
+ mutating func reset()
33
+ }
34
+
35
+ extension EventEmitterProtocol{
36
+ mutating func on(event: String, listener: @escaping (_ object: Any, _ data: Any) -> Void) {
37
+ if listeners[event] == nil {
38
+ listeners[event] = []
39
+ }
40
+ listeners[event]?.append(listener)
41
+ }
42
+
43
+ func emit(event: String, data: Any) {
44
+ listeners[event]?.forEach { listener in
45
+ listener(self, data)
46
+ }
47
+ }
48
+
49
+ mutating func off(event: String, listener: @escaping (_ object: Any, _ data: Any) -> Void) {
50
+ listeners[event]?.removeAll(where: { $0 as AnyObject === listener as AnyObject })
51
+ }
52
+
53
+ mutating func reset(){
54
+ listeners = [:]
55
+ }
56
+ }
@@ -0,0 +1,348 @@
1
+ import SwiftUI
2
+
3
+ struct UpdateSpatialSceneProperties: CommandDataProtocol {
4
+ static let commandType: String = "UpdateSpatialSceneProperties"
5
+ let cornerRadius: CornerRadius?
6
+ let material: BackgroundMaterial?
7
+ let opacity: Double?
8
+ }
9
+
10
+ struct AddSpatializedElementToSpatialScene: CommandDataProtocol {
11
+ static let commandType: String = "AddSpatializedElementToSpatialScene"
12
+ let spatializedElementId: String
13
+ }
14
+
15
+ struct CreateSpatializedStatic3DElement: CommandDataProtocol {
16
+ static let commandType: String = "CreateSpatializedStatic3DElement"
17
+ let modelURL: String
18
+ }
19
+
20
+ struct CreateSpatializedDynamic3DElement: CommandDataProtocol{
21
+ static let commandType: String = "CreateSpatializedDynamic3DElement"
22
+ let test: Bool
23
+ }
24
+
25
+ struct CreateSpatialEntity: CommandDataProtocol{
26
+ static let commandType: String = "CreateSpatialEntity"
27
+ let name: String?
28
+ }
29
+
30
+ struct CreateGeometryProperties: CommandDataProtocol{
31
+ static let commandType: String = "CreateGeometry"
32
+ let type: String
33
+ let width: Float?
34
+ let height: Float?
35
+ let depth: Float?
36
+ let cornerRadius: Float?
37
+ let splitFaces: Bool?
38
+ let radius: Float?
39
+ }
40
+
41
+ struct CreateUnlitMaterial: CommandDataProtocol{
42
+ static let commandType: String = "CreateUnlitMaterial"
43
+ let color: String?
44
+ let textureId: String?
45
+ let transparent: Bool?
46
+ let opacity: Float?
47
+ }
48
+
49
+ struct CreateTexture: CommandDataProtocol{
50
+ static let commandType: String = "CreateTexture"
51
+ let url: String
52
+ }
53
+
54
+ struct CreateModelAsset: CommandDataProtocol{
55
+ static let commandType: String = "CreateModelAsset"
56
+ let url: String
57
+ }
58
+
59
+ struct CreateSpatialModelEntity: CommandDataProtocol{
60
+ static let commandType: String = "CreateSpatialModelEntity"
61
+ let modelAssetId:String
62
+ let name:String?
63
+ }
64
+
65
+ struct CreateModelComponent: CommandDataProtocol{
66
+ static let commandType: String = "CreateModelComponent"
67
+ let geometryId: String
68
+ let materialIds: [String]
69
+ }
70
+
71
+ struct AddComponentToEntity: CommandDataProtocol{
72
+ static let commandType: String = "AddComponentToEntity"
73
+ let entityId: String
74
+ let componentId: String
75
+ }
76
+
77
+ struct AddEntityToDynamic3D: CommandDataProtocol{
78
+ static let commandType: String = "AddEntityToDynamic3D"
79
+ let dynamic3dId: String
80
+ let entityId: String
81
+ }
82
+
83
+ struct AddEntityToEntity: CommandDataProtocol{
84
+ static let commandType: String = "AddEntityToEntity"
85
+ let childId: String
86
+ let parentId: String
87
+ }
88
+
89
+ struct SetParentForEntity: CommandDataProtocol{
90
+ static let commandType: String = "SetParentToEntity"
91
+ let childId: String
92
+ let parentId: String?
93
+ }
94
+
95
+ struct RemoveEntityFromParent: CommandDataProtocol{
96
+ static let commandType: String = "RemoveEntityFromParent"
97
+ let entityId: String
98
+ }
99
+
100
+ struct UpdateEntityProperties: CommandDataProtocol{
101
+ static let commandType: String = "UpdateEntityProperties"
102
+ let entityId: String
103
+ let transform: [String:Float]
104
+ }
105
+
106
+ struct UpdateEntityEvent: CommandDataProtocol{
107
+ static let commandType: String = "UpdateEntityEvent"
108
+ let type: String
109
+ let entityId: String
110
+ let isEnable:Bool
111
+ }
112
+
113
+ struct ConvertFromEntityToEntity: CommandDataProtocol{
114
+ static let commandType: String = "ConvertFromEntityToEntity"
115
+ let fromEntityId: String
116
+ let toEntityId: String
117
+ let position:Vec3
118
+ }
119
+
120
+ struct ConvertFromEntityToScene: CommandDataProtocol{
121
+ static let commandType: String = "ConvertFromEntityToScene"
122
+ let fromEntityId: String
123
+ let position:Vec3
124
+ }
125
+
126
+ struct ConvertFromSceneToEntity: CommandDataProtocol{
127
+ static let commandType: String = "ConvertFromSceneToEntity"
128
+ let entityId: String
129
+ let position:Vec3
130
+ }
131
+
132
+ struct InspectCommand: CommandDataProtocol {
133
+ static let commandType: String = "Inspect"
134
+ var id: String?
135
+ }
136
+
137
+ protocol SpatialObjectCommand: CommandDataProtocol {
138
+ var id: String { get }
139
+ }
140
+
141
+ struct DestroyCommand: CommandDataProtocol {
142
+ static let commandType: String = "Destroy"
143
+ var id: String
144
+ }
145
+
146
+ protocol SpatializedElementProperties: SpatialObjectCommand {
147
+ var name: String? { get }
148
+ var clientX: Double? { get }
149
+ var clientY: Double? { get }
150
+ var width: Double? { get }
151
+ var height: Double? { get }
152
+ var depth: Double? { get }
153
+ var backOffset: Double? { get }
154
+ var rotationAnchor: Vec3? { get }
155
+ var opacity: Double? { get }
156
+ var visible: Bool? { get }
157
+ var scrollWithParent: Bool? { get }
158
+ var zIndex: Double? { get }
159
+
160
+ var enableDragStartGesture: Bool? { get }
161
+ var enableDragGesture: Bool? { get }
162
+ var enableDragEndGesture: Bool? { get }
163
+
164
+ var enableRotateStartGesture: Bool? { get }
165
+ var enableRotateGesture: Bool? { get }
166
+ var enableRotateEndGesture: Bool? { get }
167
+ var enableMagnifyStartGesture: Bool? { get }
168
+ var enableMagnifyGesture: Bool? { get }
169
+ var enableMagnifyEndGesture: Bool? { get }
170
+ var enableTapGesture: Bool? { get }
171
+ }
172
+
173
+ struct UpdateSpatialized2DElementProperties: SpatializedElementProperties {
174
+ static let commandType: String = "UpdateSpatialized2DElementProperties"
175
+ let id: String
176
+ let name: String?
177
+ var clientX: Double?
178
+ var clientY: Double?
179
+ let width: Double?
180
+ let height: Double?
181
+ let depth: Double?
182
+ let backOffset: Double?
183
+ let rotationAnchor: Vec3?
184
+ let opacity: Double?
185
+ let visible: Bool?
186
+ let scrollWithParent: Bool?
187
+ let zIndex: Double?
188
+
189
+ var enableDragStartGesture: Bool?
190
+ var enableDragGesture: Bool?
191
+ var enableDragEndGesture: Bool?
192
+ var enableRotateStartGesture: Bool?
193
+ var enableRotateGesture: Bool?
194
+ var enableRotateEndGesture: Bool?
195
+ var enableMagnifyStartGesture: Bool?
196
+ var enableMagnifyGesture: Bool?
197
+ var enableMagnifyEndGesture: Bool?
198
+ var enableTapGesture: Bool?
199
+
200
+ let scrollPageEnabled: Bool?
201
+ let material: BackgroundMaterial?
202
+ let cornerRadius: CornerRadius?
203
+
204
+ // this value is used by previous WebSpatial code, keep it here only for Compatibility consideration
205
+ // may delete it when we think it's not needed
206
+ let scrollEdgeInsetsMarginRight: Double?
207
+ }
208
+
209
+ struct UpdateSpatializedStatic3DElementProperties: SpatializedElementProperties {
210
+ static let commandType: String = "UpdateSpatializedStatic3DElementProperties"
211
+ let id: String
212
+ let name: String?
213
+ var clientX: Double?
214
+ var clientY: Double?
215
+ let width: Double?
216
+ let height: Double?
217
+ let depth: Double?
218
+ let backOffset: Double?
219
+ let rotationAnchor: Vec3?
220
+ let opacity: Double?
221
+ let visible: Bool?
222
+ let scrollWithParent: Bool?
223
+ let zIndex: Double?
224
+
225
+ var enableDragStartGesture: Bool?
226
+ let enableDragGesture: Bool?
227
+ let enableDragEndGesture: Bool?
228
+ var enableRotateStartGesture: Bool?
229
+ let enableRotateGesture: Bool?
230
+ let enableRotateEndGesture: Bool?
231
+ var enableMagnifyStartGesture: Bool?
232
+ let enableMagnifyGesture: Bool?
233
+ let enableMagnifyEndGesture: Bool?
234
+ let enableTapGesture: Bool?
235
+
236
+ let modelURL: String?
237
+ let modelTransform: [Double]?
238
+ }
239
+
240
+ struct UpdateSpatializedDynamic3DElementProperties: SpatializedElementProperties {
241
+ static let commandType: String = "UpdateSpatializedDynamic3DElementProperties"
242
+ let id: String
243
+ let name: String?
244
+ var clientX: Double?
245
+ var clientY: Double?
246
+ let width: Double?
247
+ let height: Double?
248
+ let depth: Double?
249
+ let backOffset: Double?
250
+ let rotationAnchor: Vec3?
251
+ let opacity: Double?
252
+ let visible: Bool?
253
+ let scrollWithParent: Bool?
254
+ let zIndex: Double?
255
+
256
+ var enableDragStartGesture: Bool?
257
+ let enableDragGesture: Bool?
258
+ let enableDragEndGesture: Bool?
259
+ var enableRotateStartGesture: Bool?
260
+ let enableRotateGesture: Bool?
261
+ let enableRotateEndGesture: Bool?
262
+ var enableMagnifyStartGesture: Bool?
263
+ let enableMagnifyGesture: Bool?
264
+ let enableMagnifyEndGesture: Bool?
265
+ let enableTapGesture: Bool?
266
+ }
267
+
268
+ struct UpdateSpatializedElementTransform: SpatialObjectCommand {
269
+ static let commandType: String = "UpdateSpatializedElementTransform"
270
+ let id: String
271
+ let matrix: [Double]
272
+ }
273
+
274
+ struct AddSpatializedElementToSpatialized2DElement: SpatialObjectCommand {
275
+ static let commandType: String = "AddSpatializedElementToSpatialized2DElement"
276
+ let id: String
277
+ let spatializedElementId: String
278
+ }
279
+
280
+ // incomming JSB data
281
+ struct XSceneOptionsJSB: Codable {
282
+ let defaultSize: Size?
283
+ let type: SpatialScene.WindowStyle?
284
+ let resizability: ResizeRange?
285
+ let worldScaling: WorldScalingJSB?
286
+ let worldAlignment: WorldAlignmentJSB?
287
+ let baseplateVisibility: BaseplateVisibilityJSB?
288
+ }
289
+
290
+ enum BaseplateVisibilityJSB: String, Codable {
291
+ case automatic
292
+ case visible
293
+ case hidden
294
+
295
+ var toSDK: Visibility {
296
+ switch self {
297
+ case .automatic: return .automatic
298
+ case .visible: return .visible
299
+ case .hidden: return .hidden
300
+ }
301
+ }
302
+ }
303
+
304
+ enum WorldScalingJSB: String, Codable {
305
+ case automatic
306
+ case dynamic
307
+
308
+ var toSDK: WorldScalingBehavior {
309
+ switch self {
310
+ case .automatic: return .automatic
311
+ case .dynamic: return .dynamic
312
+ }
313
+ }
314
+ }
315
+
316
+ enum WorldAlignmentJSB: String, Codable {
317
+ case adaptive
318
+ case automatic
319
+ case gravityAligned
320
+
321
+ var toSDK: WorldAlignmentBehavior {
322
+ switch self {
323
+ case .adaptive: return .adaptive
324
+ case .automatic: return .automatic
325
+ case .gravityAligned: return .gravityAligned
326
+ }
327
+ }
328
+ }
329
+
330
+ struct UpdateSceneConfigCommand: CommandDataProtocol {
331
+ static let commandType = "UpdateSceneConfig"
332
+ let config: XSceneOptionsJSB
333
+ init(_ data: XSceneOptionsJSB) {
334
+ config = data
335
+ }
336
+ }
337
+
338
+ struct FocusSceneCommand: CommandDataProtocol {
339
+ static let commandType = "FocusScene"
340
+ let id: String
341
+ init(_ id: String) {
342
+ self.id = id
343
+ }
344
+ }
345
+
346
+ struct GetSpatialSceneStateCommand: CommandDataProtocol {
347
+ static let commandType = "GetSpatialSceneState"
348
+ }
@@ -0,0 +1,108 @@
1
+ import Foundation
2
+
3
+ protocol SpatialObjectProtocol: Encodable, Equatable, EventEmitterProtocol {
4
+ var spatialId: String { get }
5
+ func destroy()
6
+ }
7
+
8
+ class WeakReference<T: AnyObject> {
9
+ weak var value: T?
10
+
11
+ init(_ value: T) {
12
+ self.value = value
13
+ }
14
+ }
15
+
16
+ class SpatialObjectWeakRefManager {
17
+ static var weakRefObjects = [String: WeakReference<AnyObject>]()
18
+
19
+ static func setWeakRef<T: AnyObject>(_ id: String, _ object: T) {
20
+ weakRefObjects[id] = WeakReference(object as AnyObject)
21
+ }
22
+
23
+ static func getWeakRef(_ id: String) -> AnyObject? {
24
+ return weakRefObjects[id]?.value
25
+ }
26
+
27
+ static func removeWeakRef(_ id: String) {
28
+ weakRefObjects.removeValue(forKey: id)
29
+ }
30
+ }
31
+
32
+ class SpatialObject: SpatialObjectProtocol {
33
+ internal var listeners: [String : [(Any, Any) -> Void]] = [:]
34
+ static var objects = [String: (any SpatialObjectProtocol)]()
35
+
36
+ static func get(_ id: String) -> (any SpatialObjectProtocol)? {
37
+ return objects[id]
38
+ }
39
+
40
+ static func getRefObject(_ id: String) -> SpatialObject? {
41
+ return SpatialObjectWeakRefManager.getWeakRef(id) as? SpatialObject
42
+ }
43
+
44
+ let spatialId: String
45
+ var name: String = ""
46
+ let id: String
47
+
48
+ private var _isDestroyed = false
49
+
50
+ var isDestroyed: Bool {
51
+ _isDestroyed
52
+ }
53
+
54
+ enum CodingKeys: String, CodingKey {
55
+ case id, name, isDestroyed
56
+ }
57
+
58
+ func encode(to encoder: any Encoder) throws {
59
+ var container = encoder.container(keyedBy: CodingKeys.self)
60
+ try container.encode(spatialId, forKey: .id)
61
+ try container.encode(name, forKey: .name)
62
+ try container.encode(isDestroyed, forKey: .isDestroyed)
63
+ }
64
+
65
+ static func == (lhs: SpatialObject, rhs: SpatialObject) -> Bool {
66
+ return lhs.spatialId == rhs.spatialId
67
+ }
68
+
69
+ init() {
70
+ spatialId = UUID().uuidString
71
+ id = spatialId
72
+ SpatialObject.objects[spatialId] = self
73
+ SpatialObjectWeakRefManager.setWeakRef(spatialId, self)
74
+ }
75
+
76
+ init(_ _id: String) {
77
+ spatialId = _id
78
+ id = spatialId
79
+ SpatialObject.objects[spatialId] = self
80
+ SpatialObjectWeakRefManager.setWeakRef(spatialId, self)
81
+ }
82
+
83
+ deinit {
84
+ SpatialObjectWeakRefManager.removeWeakRef(spatialId)
85
+ }
86
+
87
+ enum Events: String {
88
+ case BeforeDestroyed = "SpatialObject::BeforeDestroyed"
89
+ case Destroyed = "SpatialObject::Destroyed"
90
+ }
91
+
92
+ func destroy() {
93
+ if _isDestroyed {
94
+ logger.warning("SpatialObject already destroyed \(self)")
95
+ return
96
+ }
97
+ emit(event: Events.BeforeDestroyed.rawValue, data: ["object": self])
98
+ onDestroy()
99
+ _isDestroyed = true
100
+
101
+ emit(event: Events.Destroyed.rawValue, data: ["object": self])
102
+ SpatialObject.objects.removeValue(forKey: spatialId)
103
+
104
+ listeners = [:]
105
+ }
106
+
107
+ internal func onDestroy() {}
108
+ }
@@ -0,0 +1,119 @@
1
+ // All WebMsg have been listed here
2
+
3
+ import SwiftUI
4
+
5
+ enum WebSpatialGestureType: String, Encodable {
6
+ case spatialtap = "spatialtap"
7
+ case spatialdragstart = "spatialdragstart"
8
+ case spatialdrag = "spatialdrag"
9
+ case spatialdragend = "spatialdragend"
10
+ case spatialrotatestart = "spatialrotatestart"
11
+ case spatialrotate = "spatialrotate"
12
+ case spatialrotateend = "spatialrotateend"
13
+ case spatialmagnifystart = "spatialmagnifystart"
14
+ case spatialmagnify = "spatialmagnify"
15
+ case spatialmagnifyend = "spatialmagnifyend"
16
+ }
17
+
18
+ enum SpatialWebMsgType: String, Encodable {
19
+ case cubeInfo = "cubeInfo"
20
+ case transform = "transform"
21
+ case modelloaded = "modelloaded"
22
+ case modelloadfailed = "modelloadfailed"
23
+ case spatialtap = "spatialtap"
24
+ case spatialdrag = "spatialdrag"
25
+ case spatialdragend = "spatialdragend"
26
+ case spatialrotate = "spatialrotate"
27
+ case spatialrotateend = "spatialrotateend"
28
+ case spatialmagnify = "spatialmagnify"
29
+ case spatialmagnifyend = "spatialmagnifyend"
30
+
31
+ case objectdestroy = "objectdestroy"
32
+ }
33
+
34
+ // notify Spatialized3DElement Container Cube, used for ref.current.getBoundingClientCube()
35
+ struct SpatiaizedContainerClientCube: Encodable {
36
+ let type: SpatialWebMsgType = SpatialWebMsgType.cubeInfo
37
+ let origin: Point3D
38
+ let size: Size3D
39
+ }
40
+
41
+ // notify Spatialized3DElement Container Transform to SpatialScene, used for ref.current.convertToSpatialScene()
42
+ struct SpatiaizedContainerTransform: Encodable {
43
+ let type: SpatialWebMsgType = SpatialWebMsgType.transform
44
+ let detail: AffineTransform3D
45
+ }
46
+
47
+ struct WebSpatialTapGuestureEventDetail: Encodable {
48
+ let location3D: Point3D
49
+ }
50
+
51
+ // notify SpatializedElement/SpatialEntity tapped
52
+ struct WebSpatialTapGuestureEvent: Encodable {
53
+ let type: SpatialWebMsgType = SpatialWebMsgType.spatialtap
54
+ let detail: WebSpatialTapGuestureEventDetail
55
+ }
56
+
57
+ struct WebSpatialDragGuestureEventDetail: Encodable {
58
+ let location3D: Point3D
59
+ let startLocation3D: Point3D
60
+ let translation3D: Vector3D
61
+ let predictedEndTranslation3D: Vector3D
62
+ let predictedEndLocation3D: Point3D
63
+ let velocity: CGSize
64
+ }
65
+
66
+ struct WebSpatialDragGuestureEvent: Encodable {
67
+ let type: SpatialWebMsgType = SpatialWebMsgType.spatialdrag
68
+ let detail: WebSpatialDragGuestureEventDetail
69
+ }
70
+
71
+ struct WebSpatialDragEndGuestureEvent: Encodable {
72
+ let type: SpatialWebMsgType = SpatialWebMsgType.spatialdragend
73
+ let detail: WebSpatialDragGuestureEventDetail
74
+ }
75
+
76
+ struct WebSpatialRotateGuestureEventDetail: Encodable {
77
+ let rotation: Rotation3D
78
+ let startAnchor3D: UnitPoint3D
79
+ let startLocation3D: Point3D
80
+
81
+ }
82
+ struct WebSpatialRotateGuestureEvent: Encodable {
83
+ let type: SpatialWebMsgType = SpatialWebMsgType.spatialrotate
84
+ let detail: WebSpatialRotateGuestureEventDetail
85
+ }
86
+
87
+ struct WebSpatialRotateEndGuestureEvent: Encodable {
88
+ let type: SpatialWebMsgType = SpatialWebMsgType.spatialrotateend
89
+ let detail: WebSpatialRotateGuestureEventDetail
90
+ }
91
+
92
+ struct WebSpatialMagnifyGuestureEventDetail: Encodable {
93
+ let magnification: CGFloat
94
+ let velocity: CGFloat
95
+ let startLocation3D: Point3D
96
+ let startAnchor3D: UnitPoint3D
97
+ }
98
+
99
+ struct WebSpatialMagnifyGuestureEvent: Encodable {
100
+ let type: SpatialWebMsgType = SpatialWebMsgType.spatialmagnify
101
+ let detail: WebSpatialMagnifyGuestureEventDetail
102
+ }
103
+
104
+ struct WebSpatialMagnifyEndGuestureEvent: Encodable {
105
+ let type: SpatialWebMsgType = SpatialWebMsgType.spatialmagnifyend
106
+ let detail: WebSpatialMagnifyGuestureEventDetail
107
+ }
108
+
109
+ struct ModelLoadSuccess: Encodable {
110
+ let type: SpatialWebMsgType = SpatialWebMsgType.modelloaded
111
+ }
112
+
113
+ struct ModelLoadFailure: Encodable {
114
+ let type: SpatialWebMsgType = SpatialWebMsgType.modelloadfailed
115
+ }
116
+
117
+ struct SpatialObjectDestroiedEvent: Encodable {
118
+ let type: SpatialWebMsgType = SpatialWebMsgType.objectdestroy
119
+ }