@webspatial/builder 0.0.9 → 0.0.11
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/dist/index.js +1 -1
- package/dist/lib/Cli.js +1 -1
- package/dist/lib/cmds/build.d.ts +1 -1
- package/dist/lib/cmds/build.js +1 -1
- package/dist/lib/cmds/check.js +1 -1
- package/dist/lib/cmds/help.js +1 -1
- package/dist/lib/cmds/version.js +1 -1
- package/dist/lib/pwa/config.js +1 -1
- package/dist/lib/pwa/index.js +1 -1
- package/dist/lib/pwa/validate.js +1 -1
- package/dist/lib/resource/file.js +1 -1
- package/dist/lib/resource/imageHelper.js +1 -1
- package/dist/lib/resource/index.d.ts +10 -3
- package/dist/lib/resource/index.js +1 -1
- package/dist/lib/resource/load.js +1 -1
- package/dist/lib/utils/CustomError.js +1 -1
- package/dist/lib/utils/FetchUtils-1.js +1 -1
- package/dist/lib/utils/Log.js +1 -1
- package/dist/lib/utils/fetch.js +1 -1
- package/dist/lib/utils/messages.js +1 -1
- package/dist/lib/utils/utils.d.ts +9 -0
- package/dist/lib/utils/utils.js +1 -1
- package/dist/lib/xcode/index.js +1 -1
- package/dist/lib/xcode/manifestSwiftTemplate.d.ts +1 -1
- package/dist/lib/xcode/manifestSwiftTemplate.js +1 -1
- package/dist/lib/xcode/xcodebuild.js +1 -1
- package/dist/lib/xcode/xcodeproject.js +1 -1
- package/dist/lib/xcode/xcrun.js +1 -1
- package/package.json +3 -2
- package/template/visionOSApp/Packages/RealityKitContent/.build/workspace-state.json +0 -7
- package/template/visionOSApp/Packages/RealityKitContent/.swiftpm/xcode/xcuserdata/bytedance.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/template/visionOSApp/Packages/RealityKitContent/Package.realitycomposerpro/ProjectData/main.json +0 -11
- package/template/visionOSApp/Packages/RealityKitContent/Package.realitycomposerpro/WorkspaceData/SceneMetadataList.json +0 -112
- package/template/visionOSApp/Packages/RealityKitContent/Package.realitycomposerpro/WorkspaceData/Settings.rcprojectdata +0 -17
- package/template/visionOSApp/Packages/RealityKitContent/Package.swift +0 -27
- package/template/visionOSApp/Packages/RealityKitContent/README.md +0 -3
- package/template/visionOSApp/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.rkassets/Immersive.usda +0 -50
- package/template/visionOSApp/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.rkassets/Materials/GridMaterial.usda +0 -216
- package/template/visionOSApp/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.rkassets/Scene.usda +0 -59
- package/template/visionOSApp/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift +0 -4
- package/template/visionOSApp/web-spatial/Assets.xcassets/AppIcon.solidimagestack/Back.solidimagestacklayer/Content.imageset/Contents.json +0 -12
- package/template/visionOSApp/web-spatial/Assets.xcassets/AppIcon.solidimagestack/Back.solidimagestacklayer/Contents.json +0 -6
- package/template/visionOSApp/web-spatial/Assets.xcassets/AppIcon.solidimagestack/Contents.json +0 -17
- package/template/visionOSApp/web-spatial/Assets.xcassets/AppIcon.solidimagestack/Front.solidimagestacklayer/Content.imageset/Contents.json +0 -12
- package/template/visionOSApp/web-spatial/Assets.xcassets/AppIcon.solidimagestack/Front.solidimagestacklayer/Contents.json +0 -6
- package/template/visionOSApp/web-spatial/Assets.xcassets/AppIcon.solidimagestack/Middle.solidimagestacklayer/Content.imageset/Contents.json +0 -12
- package/template/visionOSApp/web-spatial/Assets.xcassets/AppIcon.solidimagestack/Middle.solidimagestacklayer/Contents.json +0 -6
- package/template/visionOSApp/web-spatial/Assets.xcassets/Contents.json +0 -6
- package/template/visionOSApp/web-spatial/Info.plist +0 -33
- package/template/visionOSApp/web-spatial/Preview Content/Preview Assets.xcassets/Contents.json +0 -6
- package/template/visionOSApp/web-spatial/libs/EventEmitter.swift +0 -32
- package/template/visionOSApp/web-spatial/libs/SpatialComponent.swift +0 -31
- package/template/visionOSApp/web-spatial/libs/SpatialEntity.swift +0 -179
- package/template/visionOSApp/web-spatial/libs/SpatialInputComponent.swift +0 -26
- package/template/visionOSApp/web-spatial/libs/SpatialMeshResource.swift +0 -19
- package/template/visionOSApp/web-spatial/libs/SpatialModel3DComponent.swift +0 -51
- package/template/visionOSApp/web-spatial/libs/SpatialModelComponent.swift +0 -32
- package/template/visionOSApp/web-spatial/libs/SpatialObject.swift +0 -144
- package/template/visionOSApp/web-spatial/libs/SpatialPhysicallyBasedMaterial.swift +0 -19
- package/template/visionOSApp/web-spatial/libs/SpatialViewComponent.swift +0 -15
- package/template/visionOSApp/web-spatial/libs/SpatialWindowComponent.swift +0 -420
- package/template/visionOSApp/web-spatial/libs/SpatialWindowContainer.swift +0 -149
- package/template/visionOSApp/web-spatial/libs/Utils/CommandManager.swift +0 -800
- package/template/visionOSApp/web-spatial/libs/Utils/Logger.swift +0 -36
- package/template/visionOSApp/web-spatial/libs/Utils/SceneManager.swift +0 -108
- package/template/visionOSApp/web-spatial/libs/Utils/WindowContainerMgr.swift +0 -113
- package/template/visionOSApp/web-spatial/libs/json/JsonParser.swift +0 -52
- package/template/visionOSApp/web-spatial/libs/uiKitDelegate/Window.swift +0 -34
- package/template/visionOSApp/web-spatial/libs/webView/UpdateSystem.swift +0 -33
- package/template/visionOSApp/web-spatial/libs/webView/backend/NativeWebView.swift +0 -319
- package/template/visionOSApp/web-spatial/libs/webView/manifest.swift +0 -92
- package/template/visionOSApp/web-spatial/static-web/index.html +0 -9
- package/template/visionOSApp/web-spatial/views/HideViewModifier.swift +0 -17
- package/template/visionOSApp/web-spatial/views/ImmersiveView.swift +0 -24
- package/template/visionOSApp/web-spatial/views/LoadingView.swift +0 -25
- package/template/visionOSApp/web-spatial/views/MaterialWithBorderCornerModifier.swift +0 -82
- package/template/visionOSApp/web-spatial/views/OpenDismissHandlerUI.swift +0 -52
- package/template/visionOSApp/web-spatial/views/PlainWindowContainerView.swift +0 -84
- package/template/visionOSApp/web-spatial/views/SpatialModel3DView.swift +0 -193
- package/template/visionOSApp/web-spatial/views/SpatialViewUI.swift +0 -168
- package/template/visionOSApp/web-spatial/views/SpatialWebViewUI.swift +0 -186
- package/template/visionOSApp/web-spatial/views/VolumetricWindowContainerView.swift +0 -38
- package/template/visionOSApp/web-spatial/views/ui/NavView.swift +0 -125
- package/template/visionOSApp/web-spatial/web_spatialApp.swift +0 -158
- package/template/visionOSApp/web-spatial.xcodeproj/project.pbxproj +0 -686
- package/template/visionOSApp/web-spatial.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/template/visionOSApp/web-spatial.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/template/visionOSApp/web-spatial.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +0 -5
- package/template/visionOSApp/web-spatial.xcodeproj/project.xcworkspace/xcuserdata/bytedance.xcuserdatad/WorkspaceSettings.xcsettings +0 -14
- package/template/visionOSApp/web-spatial.xcodeproj/xcshareddata/xcschemes/web-spatial.xcscheme +0 -115
- package/template/visionOSApp/web-spatial.xcodeproj/xcuserdata/bytedance.xcuserdatad/xcschemes/xcschememanagement.plist +0 -27
- package/template/visionOSApp/web-spatialTests/web_spatialTests.swift +0 -34
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SpatialEntity.swift
|
|
3
|
-
// web-spatial
|
|
4
|
-
//
|
|
5
|
-
// Created by ByteDance on 9/10/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Combine
|
|
9
|
-
import Foundation
|
|
10
|
-
import RealityKit
|
|
11
|
-
import typealias RealityKit.Entity
|
|
12
|
-
|
|
13
|
-
enum CoordinateSpaceMode {
|
|
14
|
-
case
|
|
15
|
-
APP,
|
|
16
|
-
DOM,
|
|
17
|
-
ROOT
|
|
18
|
-
|
|
19
|
-
var description: String {
|
|
20
|
-
switch self {
|
|
21
|
-
case .APP:
|
|
22
|
-
return "APP"
|
|
23
|
-
case .DOM:
|
|
24
|
-
return "DOM"
|
|
25
|
-
case .ROOT:
|
|
26
|
-
return "ROOT"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// temp use SpatialBridgeComponent,
|
|
32
|
-
// will be replaced when modelEntity is removed from SpatialEntity
|
|
33
|
-
// then SpatialEntity have have a BridgeEntity instead
|
|
34
|
-
class SpatialBridgeComponent: Component {
|
|
35
|
-
let spatialEntity: SpatialEntity
|
|
36
|
-
|
|
37
|
-
init(_ spatialEntity: SpatialEntity) {
|
|
38
|
-
self.spatialEntity = spatialEntity
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Entity
|
|
43
|
-
@Observable
|
|
44
|
-
class SpatialEntity: SpatialObject {
|
|
45
|
-
var coordinateSpace = CoordinateSpaceMode.APP
|
|
46
|
-
let modelEntity = ModelEntity()
|
|
47
|
-
var zIndex: Double = 0
|
|
48
|
-
var visible = true
|
|
49
|
-
|
|
50
|
-
var forceUpdate = false
|
|
51
|
-
|
|
52
|
-
override init() {
|
|
53
|
-
super.init()
|
|
54
|
-
modelEntity.components.set(SpatialBridgeComponent(self))
|
|
55
|
-
modelEntity.model = ModelComponent(mesh: .generateBox(size: 0.0), materials: [])
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Entity can have a child/parent relationship
|
|
59
|
-
private var childEntities = [String: SpatialEntity]()
|
|
60
|
-
weak var parent: SpatialEntity? = nil
|
|
61
|
-
|
|
62
|
-
public func getEntities() -> [String: SpatialEntity] {
|
|
63
|
-
return childEntities
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Window container that this entity will be displayed in (not related to resource ownership)
|
|
67
|
-
weak var parentWindowContainer: SpatialWindowContainer?
|
|
68
|
-
public func setParentWindowContainer(wg: SpatialWindowContainer?) {
|
|
69
|
-
if let g = parentWindowContainer {
|
|
70
|
-
g.removeEntity(self)
|
|
71
|
-
parentWindowContainer = nil
|
|
72
|
-
}
|
|
73
|
-
parentWindowContainer = wg
|
|
74
|
-
if let g = parentWindowContainer {
|
|
75
|
-
g.addEntity(self)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// @Trevor: I add this code to process parent
|
|
79
|
-
// I think an entity can be either child of WindowContainer or SpatialEntity
|
|
80
|
-
parent?.childEntities.removeValue(forKey: id)
|
|
81
|
-
parent = nil
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public func addChild(child: SpatialEntity) {
|
|
85
|
-
child.setParent(parentEnt: self)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public func setParent(parentEnt: SpatialEntity?) {
|
|
89
|
-
// Remove parent window container
|
|
90
|
-
parentWindowContainer?.removeEntity(self)
|
|
91
|
-
parentWindowContainer = nil
|
|
92
|
-
|
|
93
|
-
// Remove from existing parent
|
|
94
|
-
parent?.childEntities.removeValue(forKey: id)
|
|
95
|
-
parentEnt?.modelEntity.removeChild(modelEntity)
|
|
96
|
-
|
|
97
|
-
// Set new parent
|
|
98
|
-
if let p = parentEnt {
|
|
99
|
-
parent = p
|
|
100
|
-
p.modelEntity.addChild(modelEntity)
|
|
101
|
-
p.childEntities[id] = self
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// components
|
|
106
|
-
private var components: [SpatialComponent] = []
|
|
107
|
-
|
|
108
|
-
public func addComponent(_ component: SpatialComponent) {
|
|
109
|
-
// first check component type
|
|
110
|
-
components.append(component)
|
|
111
|
-
component.entity = self
|
|
112
|
-
component.onAddToEntity()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public func removeComponent(_ component: SpatialComponent) {
|
|
116
|
-
if let index = components.firstIndex(of: component) {
|
|
117
|
-
components.remove(at: index)
|
|
118
|
-
component.entity = nil
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
public func getComponent<T: SpatialComponent>(_ type: T.Type) -> T? {
|
|
123
|
-
for component in components {
|
|
124
|
-
if let specificComponent = component as? T {
|
|
125
|
-
return specificComponent
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return nil
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public func hasComponent<T: SpatialComponent>(_ type: T.Type) -> Bool {
|
|
132
|
-
return getComponent(type) != nil
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
override func onDestroy() {
|
|
136
|
-
if let wg = parentWindowContainer {
|
|
137
|
-
wg.removeEntity(self)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// handle components destroy
|
|
141
|
-
components.forEach { $0.destroy() }
|
|
142
|
-
components = []
|
|
143
|
-
|
|
144
|
-
setParent(parentEnt: nil)
|
|
145
|
-
let keys = childEntities.map { $0.key }
|
|
146
|
-
for k in keys {
|
|
147
|
-
childEntities[k]!.setParent(parentEnt: nil)
|
|
148
|
-
}
|
|
149
|
-
childEntities = [String: SpatialEntity]()
|
|
150
|
-
|
|
151
|
-
modelEntity.removeFromParent()
|
|
152
|
-
modelEntity.components.removeAll()
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
override func inspect() -> [String: Any] {
|
|
156
|
-
let childEntitiesInfo = childEntities.mapValues { entity in
|
|
157
|
-
entity.inspect()
|
|
158
|
-
}
|
|
159
|
-
let componentsInfo = components.map { $0.inspect() }
|
|
160
|
-
|
|
161
|
-
var inspectInfo: [String: Any] = [
|
|
162
|
-
"position": modelEntity.position.description,
|
|
163
|
-
"scale": modelEntity.scale.description,
|
|
164
|
-
"zIndex": zIndex,
|
|
165
|
-
"visible": visible,
|
|
166
|
-
"childEntities": childEntitiesInfo,
|
|
167
|
-
"coordinateSpace": coordinateSpace.description,
|
|
168
|
-
"parent": parent != nil ? parent!.id : "null",
|
|
169
|
-
"parentWindowContainer": parentWindowContainer != nil ? parentWindowContainer!.id : "null",
|
|
170
|
-
"components": componentsInfo,
|
|
171
|
-
]
|
|
172
|
-
|
|
173
|
-
let baseInspectInfo = super.inspect()
|
|
174
|
-
for (key, value) in baseInspectInfo {
|
|
175
|
-
inspectInfo[key] = value
|
|
176
|
-
}
|
|
177
|
-
return inspectInfo
|
|
178
|
-
}
|
|
179
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SpatialInputComponent.swift
|
|
3
|
-
// web-spatial
|
|
4
|
-
//
|
|
5
|
-
// Created by ByteDance on 9/10/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Combine
|
|
9
|
-
import Foundation
|
|
10
|
-
import RealityKit
|
|
11
|
-
|
|
12
|
-
@Observable
|
|
13
|
-
class SpatialInputComponent: SpatialComponent {
|
|
14
|
-
// @todo: ref to wv is a bad desgin, should refactor later
|
|
15
|
-
weak var wv: SpatialWindowComponent?
|
|
16
|
-
var itc = InputTargetComponent()
|
|
17
|
-
|
|
18
|
-
var isDragging = false
|
|
19
|
-
var trackedPosition: SIMD3<Float> = .zero
|
|
20
|
-
|
|
21
|
-
override func onAddToEntity() {
|
|
22
|
-
let e = entity!
|
|
23
|
-
e.modelEntity.generateCollisionShapes(recursive: false)
|
|
24
|
-
e.modelEntity.components.set(itc)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SpatialMeshResource.swift
|
|
3
|
-
// web-spatial
|
|
4
|
-
//
|
|
5
|
-
// Created by ByteDance on 9/10/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
import RealityKit
|
|
10
|
-
|
|
11
|
-
@Observable
|
|
12
|
-
class SpatialMeshResource: SpatialObject {
|
|
13
|
-
let meshResource: MeshResource
|
|
14
|
-
|
|
15
|
-
init(_ meshResource: MeshResource) {
|
|
16
|
-
self.meshResource = meshResource
|
|
17
|
-
super.init()
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import SwiftUI
|
|
3
|
-
|
|
4
|
-
@Observable
|
|
5
|
-
class SpatialModel3DComponent: SpatialComponent {
|
|
6
|
-
var resolutionX: Double = 0
|
|
7
|
-
var resolutionY: Double = 0
|
|
8
|
-
var modelURL: String = ""
|
|
9
|
-
var opacity: Double = 1.0
|
|
10
|
-
var rotationAnchor: UnitPoint3D = .center
|
|
11
|
-
var scrollWithParent = true
|
|
12
|
-
var contentMode: ContentMode = .fit
|
|
13
|
-
var resizable: Bool = true
|
|
14
|
-
var aspectRatio: Double? = nil
|
|
15
|
-
|
|
16
|
-
var enableTapEvent = false
|
|
17
|
-
var enableDoubleTapEvent = false
|
|
18
|
-
var enableLongPressEvent = false
|
|
19
|
-
var enableDragEvent = false
|
|
20
|
-
|
|
21
|
-
// SpatialModel3DView should not have dependency on SpatialWindowComponent.
|
|
22
|
-
// It just need some JSB communication channel. This need to be refactor in future
|
|
23
|
-
weak var wv: SpatialWindowComponent?
|
|
24
|
-
|
|
25
|
-
public func setURL(_ url: String) {
|
|
26
|
-
modelURL = url
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
override func inspect() -> [String: Any] {
|
|
30
|
-
var inspectInfo: [String: Any] = [
|
|
31
|
-
"scrollWithParent": scrollWithParent,
|
|
32
|
-
"resolutionX": resolutionX,
|
|
33
|
-
"resolutionY": resolutionY,
|
|
34
|
-
"modelURL": modelURL,
|
|
35
|
-
"opacity": opacity,
|
|
36
|
-
"resizable": resizable,
|
|
37
|
-
"aspectRatio": aspectRatio != nil ? String(describing: aspectRatio!) : "nil",
|
|
38
|
-
"contentMode": contentMode == .fill ? "fill" : "fit",
|
|
39
|
-
"enableTapEvent": enableTapEvent,
|
|
40
|
-
"enableDoubleTapEvent": enableDoubleTapEvent,
|
|
41
|
-
"enableLongPressEvent": enableLongPressEvent,
|
|
42
|
-
"enableDragEvent": enableDragEvent,
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
let baseInspectInfo = super.inspect()
|
|
46
|
-
for (key, value) in baseInspectInfo {
|
|
47
|
-
inspectInfo[key] = value
|
|
48
|
-
}
|
|
49
|
-
return inspectInfo
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SpatialModelComponent.swift
|
|
3
|
-
// web-spatial
|
|
4
|
-
//
|
|
5
|
-
// Created by ByteDance on 9/10/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Combine
|
|
9
|
-
import Foundation
|
|
10
|
-
import RealityKit
|
|
11
|
-
|
|
12
|
-
@Observable
|
|
13
|
-
class SpatialModelComponent: SpatialComponent {
|
|
14
|
-
var modelComponent: ModelComponent
|
|
15
|
-
|
|
16
|
-
init(_ modelComponent: ModelComponent) {
|
|
17
|
-
self.modelComponent = modelComponent
|
|
18
|
-
|
|
19
|
-
super.init()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
override func onAddToEntity() {
|
|
23
|
-
entity?.modelEntity.model = modelComponent
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Since modelComponent is a struct instead of a class, we must sync it to the entity its attached to
|
|
27
|
-
func onUpdate() {
|
|
28
|
-
if entity != nil {
|
|
29
|
-
entity?.modelEntity.model = modelComponent
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SpatialObject.swift
|
|
3
|
-
// web-spatial
|
|
4
|
-
//
|
|
5
|
-
// Created by ByteDance on 9/10/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
|
|
10
|
-
struct SpatialObjectInfo: Codable {
|
|
11
|
-
var count: Int
|
|
12
|
-
var windowArray: [String]
|
|
13
|
-
var windowContainerArray: [String]
|
|
14
|
-
var entityArray: [String]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
struct SpatialObjectStatsInfo: Codable {
|
|
18
|
-
var backend = "AVP"
|
|
19
|
-
var objects: SpatialObjectInfo
|
|
20
|
-
var refObjects: SpatialObjectInfo
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class WeakReference<T: AnyObject> {
|
|
24
|
-
weak var value: T?
|
|
25
|
-
|
|
26
|
-
init(_ value: T) {
|
|
27
|
-
self.value = value
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
class SpatialObject: EventEmitter, Equatable {
|
|
32
|
-
static var objects = [String: SpatialObject]()
|
|
33
|
-
static var weakRefObjects = [String: WeakReference<SpatialObject>]()
|
|
34
|
-
static func get(_ id: String) -> SpatialObject? {
|
|
35
|
-
return objects[id]
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static func getRefObject(_ id: String) -> SpatialObject? {
|
|
39
|
-
return weakRefObjects[id]?.value
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// for debug
|
|
43
|
-
static func stats() -> SpatialObjectStatsInfo {
|
|
44
|
-
let webviews = objects.filter {
|
|
45
|
-
$0.value is SpatialWindowComponent
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let entities = objects.filter {
|
|
49
|
-
$0.value is SpatialEntity
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
let windowContainers = objects.filter {
|
|
53
|
-
$0.value is SpatialWindowContainer
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let weakRefWebviews = weakRefObjects.filter {
|
|
57
|
-
$0.value.value is SpatialWindowComponent
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let weakRefWindowContainers = weakRefObjects.filter {
|
|
61
|
-
$0.value.value is SpatialWindowContainer
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let weakRefEntities = weakRefObjects.filter {
|
|
65
|
-
$0.value.value is SpatialEntity
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return SpatialObjectStatsInfo(
|
|
69
|
-
objects: SpatialObjectInfo(
|
|
70
|
-
count: objects.count,
|
|
71
|
-
windowArray: Array(webviews.keys),
|
|
72
|
-
windowContainerArray: Array(windowContainers.keys),
|
|
73
|
-
entityArray: Array(entities.keys)
|
|
74
|
-
),
|
|
75
|
-
refObjects: SpatialObjectInfo(
|
|
76
|
-
count: weakRefObjects.count,
|
|
77
|
-
windowArray: Array(weakRefWebviews.keys),
|
|
78
|
-
windowContainerArray: Array(weakRefWindowContainers.keys),
|
|
79
|
-
entityArray: Array(weakRefEntities.keys)
|
|
80
|
-
)
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static func getWeakRef(_ id: String) -> SpatialObject? {
|
|
85
|
-
return weakRefObjects[id]?.value
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let id: String
|
|
89
|
-
var name: String = ""
|
|
90
|
-
|
|
91
|
-
private var _isDestroyed = false
|
|
92
|
-
|
|
93
|
-
var isDestroyed: Bool {
|
|
94
|
-
_isDestroyed
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
static func == (lhs: SpatialObject, rhs: SpatialObject) -> Bool {
|
|
98
|
-
return lhs.id == rhs.id
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
override init() {
|
|
102
|
-
id = UUID().uuidString
|
|
103
|
-
super.init()
|
|
104
|
-
SpatialObject.objects[id] = self
|
|
105
|
-
SpatialObject.weakRefObjects[id] = WeakReference(self)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
init(_ _id: String) {
|
|
109
|
-
id = _id
|
|
110
|
-
super.init()
|
|
111
|
-
SpatialObject.objects[id] = self
|
|
112
|
-
SpatialObject.weakRefObjects[id] = WeakReference(self)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
deinit {
|
|
116
|
-
SpatialObject.weakRefObjects.removeValue(forKey: id)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
enum Events: String {
|
|
120
|
-
case BeforeDestroyed = "SpatialObject::BeforeDestroyed"
|
|
121
|
-
case Destroyed = "SpatialObject::Destroyed"
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
func destroy() {
|
|
125
|
-
if _isDestroyed {
|
|
126
|
-
logger.warning("SpatialObject already destroyed \(self)")
|
|
127
|
-
return
|
|
128
|
-
}
|
|
129
|
-
emit(event: Events.BeforeDestroyed.rawValue, data: ["object": self])
|
|
130
|
-
onDestroy()
|
|
131
|
-
_isDestroyed = true
|
|
132
|
-
|
|
133
|
-
emit(event: Events.Destroyed.rawValue, data: ["object": self])
|
|
134
|
-
SpatialObject.objects.removeValue(forKey: id)
|
|
135
|
-
|
|
136
|
-
reset()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
func onDestroy() {}
|
|
140
|
-
|
|
141
|
-
func inspect() -> [String: Any] {
|
|
142
|
-
return ["id": id, "isDestroyed": isDestroyed, "name": name]
|
|
143
|
-
}
|
|
144
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SpatialPhysicallyBasedMaterial.swift
|
|
3
|
-
// web-spatial
|
|
4
|
-
//
|
|
5
|
-
// Created by ByteDance on 9/10/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
import RealityKit
|
|
10
|
-
|
|
11
|
-
@Observable
|
|
12
|
-
class SpatialPhysicallyBasedMaterial: SpatialObject {
|
|
13
|
-
var physicallyBasedMaterial: PhysicallyBasedMaterial
|
|
14
|
-
|
|
15
|
-
init(_ physicallyBasedMaterial: PhysicallyBasedMaterial) {
|
|
16
|
-
self.physicallyBasedMaterial = physicallyBasedMaterial
|
|
17
|
-
super.init()
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// SpatialViewComponent.swift
|
|
3
|
-
// web-spatial
|
|
4
|
-
//
|
|
5
|
-
// Created by ByteDance on 9/10/24.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
|
|
10
|
-
@Observable
|
|
11
|
-
class SpatialViewComponent: SpatialComponent {
|
|
12
|
-
var resolutionX: Double = 100
|
|
13
|
-
var resolutionY: Double = 100
|
|
14
|
-
var isPortal = false
|
|
15
|
-
}
|