@webspatial/core-sdk 0.1.5 → 0.1.7
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/CHANGELOG.md +8 -0
- package/dist/index.d.ts +712 -2
- package/dist/index.js +1500 -1
- package/dist/index.js.map +1 -0
- package/package.json +6 -5
- package/tsup.config.ts +23 -0
- package/dist/core/Spatial.d.ts +0 -27
- package/dist/core/Spatial.d.ts.map +0 -1
- package/dist/core/Spatial.js +0 -41
- package/dist/core/SpatialEntity.d.ts +0 -92
- package/dist/core/SpatialEntity.d.ts.map +0 -1
- package/dist/core/SpatialEntity.js +0 -122
- package/dist/core/SpatialHelper.d.ts +0 -39
- package/dist/core/SpatialHelper.d.ts.map +0 -1
- package/dist/core/SpatialHelper.js +0 -195
- package/dist/core/SpatialObject.d.ts +0 -20
- package/dist/core/SpatialObject.d.ts.map +0 -1
- package/dist/core/SpatialObject.js +0 -23
- package/dist/core/SpatialSession.d.ts +0 -164
- package/dist/core/SpatialSession.d.ts.map +0 -1
- package/dist/core/SpatialSession.js +0 -318
- package/dist/core/SpatialTransform.d.ts +0 -23
- package/dist/core/SpatialTransform.d.ts.map +0 -1
- package/dist/core/SpatialTransform.js +0 -31
- package/dist/core/SpatialWindowContainer.d.ts +0 -31
- package/dist/core/SpatialWindowContainer.d.ts.map +0 -1
- package/dist/core/SpatialWindowContainer.js +0 -48
- package/dist/core/component/EventSpatialComponent.d.ts +0 -22
- package/dist/core/component/EventSpatialComponent.d.ts.map +0 -1
- package/dist/core/component/EventSpatialComponent.js +0 -23
- package/dist/core/component/SpatialComponent.d.ts +0 -11
- package/dist/core/component/SpatialComponent.d.ts.map +0 -1
- package/dist/core/component/SpatialComponent.js +0 -23
- package/dist/core/component/SpatialInputComponent.d.ts +0 -22
- package/dist/core/component/SpatialInputComponent.d.ts.map +0 -1
- package/dist/core/component/SpatialInputComponent.js +0 -14
- package/dist/core/component/SpatialModel3DComponent.d.ts +0 -91
- package/dist/core/component/SpatialModel3DComponent.d.ts.map +0 -1
- package/dist/core/component/SpatialModel3DComponent.js +0 -185
- package/dist/core/component/SpatialModelComponent.d.ts +0 -22
- package/dist/core/component/SpatialModelComponent.d.ts.map +0 -1
- package/dist/core/component/SpatialModelComponent.js +0 -34
- package/dist/core/component/SpatialViewComponent.d.ts +0 -22
- package/dist/core/component/SpatialViewComponent.d.ts.map +0 -1
- package/dist/core/component/SpatialViewComponent.js +0 -30
- package/dist/core/component/SpatialWindowComponent.d.ts +0 -86
- package/dist/core/component/SpatialWindowComponent.d.ts.map +0 -1
- package/dist/core/component/SpatialWindowComponent.js +0 -114
- package/dist/core/component/index.d.ts +0 -7
- package/dist/core/component/index.d.ts.map +0 -1
- package/dist/core/component/index.js +0 -6
- package/dist/core/index.d.ts +0 -11
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -9
- package/dist/core/private/WebSpatial.d.ts +0 -46
- package/dist/core/private/WebSpatial.d.ts.map +0 -1
- package/dist/core/private/WebSpatial.js +0 -282
- package/dist/core/private/remote-command/RemoteCommand.d.ts +0 -8
- package/dist/core/private/remote-command/RemoteCommand.d.ts.map +0 -1
- package/dist/core/private/remote-command/RemoteCommand.js +0 -11
- package/dist/core/private/remote-command/index.d.ts +0 -2
- package/dist/core/private/remote-command/index.d.ts.map +0 -1
- package/dist/core/private/remote-command/index.js +0 -1
- package/dist/core/resource/SpatialMeshResource.d.ts +0 -7
- package/dist/core/resource/SpatialMeshResource.d.ts.map +0 -1
- package/dist/core/resource/SpatialMeshResource.js +0 -6
- package/dist/core/resource/SpatialPhysicallyBasedMaterialResource.d.ts +0 -37
- package/dist/core/resource/SpatialPhysicallyBasedMaterialResource.d.ts.map +0 -1
- package/dist/core/resource/SpatialPhysicallyBasedMaterialResource.js +0 -37
- package/dist/core/resource/index.d.ts +0 -3
- package/dist/core/resource/index.d.ts.map +0 -1
- package/dist/core/resource/index.js +0 -2
- package/dist/core/types.d.ts +0 -23
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -1
- package/dist/index.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1 +1,1500 @@
|
|
|
1
|
-
|
|
1
|
+
// src/core/private/remote-command/RemoteCommand.ts
|
|
2
|
+
var RemoteCommand = class _RemoteCommand {
|
|
3
|
+
static requestCounter = 0;
|
|
4
|
+
command;
|
|
5
|
+
data;
|
|
6
|
+
requestID;
|
|
7
|
+
constructor(cmd, data) {
|
|
8
|
+
this.command = cmd;
|
|
9
|
+
this.data = data;
|
|
10
|
+
this.requestID = ++_RemoteCommand.requestCounter;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/core/private/WebSpatial.ts
|
|
15
|
+
var WindowContainer = class {
|
|
16
|
+
id = "";
|
|
17
|
+
};
|
|
18
|
+
var WebSpatialResource = class {
|
|
19
|
+
id = "";
|
|
20
|
+
windowContainerId = "";
|
|
21
|
+
data = {};
|
|
22
|
+
receiveEvent() {
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var WebSpatial = class _WebSpatial {
|
|
26
|
+
static eventPromises = {};
|
|
27
|
+
static transactionStarted = false;
|
|
28
|
+
static transactionCommands = Array();
|
|
29
|
+
// store event receivers
|
|
30
|
+
static eventReceivers = {};
|
|
31
|
+
static registerEventReceiver(resourceId, callback) {
|
|
32
|
+
this.eventReceivers[resourceId] = callback;
|
|
33
|
+
}
|
|
34
|
+
static unregisterEventReceiver(resourceId) {
|
|
35
|
+
delete this.eventReceivers[resourceId];
|
|
36
|
+
}
|
|
37
|
+
static init() {
|
|
38
|
+
;
|
|
39
|
+
window.__SpatialWebEvent = (e) => {
|
|
40
|
+
if (e.resourceId) {
|
|
41
|
+
var callback = _WebSpatial.eventReceivers[e.resourceId];
|
|
42
|
+
callback(e.data);
|
|
43
|
+
} else {
|
|
44
|
+
var p = _WebSpatial.eventPromises[e.requestID];
|
|
45
|
+
if (p) {
|
|
46
|
+
if (e.success) {
|
|
47
|
+
p.res(e);
|
|
48
|
+
} else {
|
|
49
|
+
p.rej(e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
static startTransaction() {
|
|
56
|
+
_WebSpatial.transactionStarted = true;
|
|
57
|
+
_WebSpatial.transactionCommands = [];
|
|
58
|
+
}
|
|
59
|
+
static async sendTransaction() {
|
|
60
|
+
_WebSpatial.transactionStarted = false;
|
|
61
|
+
var cmd = new RemoteCommand("multiCommand", {
|
|
62
|
+
commandList: _WebSpatial.transactionCommands
|
|
63
|
+
});
|
|
64
|
+
var result = await new Promise((res, rej) => {
|
|
65
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res, rej };
|
|
66
|
+
_WebSpatial.sendCommand(cmd);
|
|
67
|
+
});
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
static getBackend() {
|
|
71
|
+
if (window.webkit) {
|
|
72
|
+
return "AVP";
|
|
73
|
+
} else {
|
|
74
|
+
return "UNKNOWN";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
static async sendCommand(cmd) {
|
|
78
|
+
if (window.__WebSpatialUnloaded) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (_WebSpatial.transactionStarted) {
|
|
82
|
+
_WebSpatial.transactionCommands.push(cmd);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
var msg = JSON.stringify(cmd);
|
|
86
|
+
if (_WebSpatial.getBackend() == "AVP") {
|
|
87
|
+
;
|
|
88
|
+
window.webkit.messageHandlers.bridge.postMessage(msg);
|
|
89
|
+
return;
|
|
90
|
+
} else {
|
|
91
|
+
;
|
|
92
|
+
window.bridge.nativeMessage(msg);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
static getImmersiveWindowContainer() {
|
|
97
|
+
var wg = new WindowContainer();
|
|
98
|
+
wg.id = "Immersive";
|
|
99
|
+
return wg;
|
|
100
|
+
}
|
|
101
|
+
static getCurrentWindowContainer() {
|
|
102
|
+
var wg = new WindowContainer();
|
|
103
|
+
wg.id = "current";
|
|
104
|
+
return wg;
|
|
105
|
+
}
|
|
106
|
+
static getCurrentWebPanel() {
|
|
107
|
+
var wg = new WebSpatialResource();
|
|
108
|
+
wg.id = "current";
|
|
109
|
+
wg.windowContainerId = _WebSpatial.getCurrentWindowContainer().id;
|
|
110
|
+
return wg;
|
|
111
|
+
}
|
|
112
|
+
static async createScene(style = "Plain", cfg) {
|
|
113
|
+
const { window: newWindow, ...sceneData } = cfg.sceneData;
|
|
114
|
+
const jsbSceneData = {
|
|
115
|
+
...sceneData,
|
|
116
|
+
windowID: newWindow._webSpatialID,
|
|
117
|
+
windowContainerID: newWindow._webSpatialGroupID
|
|
118
|
+
};
|
|
119
|
+
var cmd = new RemoteCommand("createScene", {
|
|
120
|
+
windowStyle: style,
|
|
121
|
+
sceneData: jsbSceneData,
|
|
122
|
+
windowContainerID: window._webSpatialParentGroupID
|
|
123
|
+
// parent WindowContainerID
|
|
124
|
+
});
|
|
125
|
+
try {
|
|
126
|
+
await new Promise((res, rej) => {
|
|
127
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res, rej };
|
|
128
|
+
_WebSpatial.sendCommand(cmd);
|
|
129
|
+
});
|
|
130
|
+
return true;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
static async createWindowContainer(style = "Plain", windowContainer, parentWebView) {
|
|
136
|
+
var cmd = new RemoteCommand("createWindowContainer", {
|
|
137
|
+
windowStyle: style,
|
|
138
|
+
windowContainerID: windowContainer ? windowContainer.id : void 0,
|
|
139
|
+
resourceID: parentWebView ? parentWebView.id : void 0
|
|
140
|
+
});
|
|
141
|
+
var result = await new Promise((res2, rej) => {
|
|
142
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res: res2, rej };
|
|
143
|
+
_WebSpatial.sendCommand(cmd);
|
|
144
|
+
});
|
|
145
|
+
var res = new WindowContainer();
|
|
146
|
+
res.id = result.data.createdID;
|
|
147
|
+
return res;
|
|
148
|
+
}
|
|
149
|
+
static async destroyResource(resource) {
|
|
150
|
+
const data = {};
|
|
151
|
+
var cmd = new RemoteCommand("destroyResource", {
|
|
152
|
+
windowContainerID: resource.windowContainerId,
|
|
153
|
+
resourceID: resource.id
|
|
154
|
+
});
|
|
155
|
+
_WebSpatial.sendCommand(cmd);
|
|
156
|
+
}
|
|
157
|
+
static async ping(msg) {
|
|
158
|
+
var cmd = new RemoteCommand("ping", {
|
|
159
|
+
windowContainerID: this.getCurrentWindowContainer().id,
|
|
160
|
+
resourceID: this.getCurrentWebPanel().id,
|
|
161
|
+
message: msg
|
|
162
|
+
});
|
|
163
|
+
if (_WebSpatial.transactionStarted) {
|
|
164
|
+
_WebSpatial.sendCommand(cmd);
|
|
165
|
+
return null;
|
|
166
|
+
} else {
|
|
167
|
+
var result = await new Promise((res, rej) => {
|
|
168
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res, rej };
|
|
169
|
+
_WebSpatial.sendCommand(cmd);
|
|
170
|
+
});
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
static async getStats() {
|
|
175
|
+
var cmd = new RemoteCommand("getStats", {
|
|
176
|
+
windowContainerID: this.getCurrentWindowContainer().id,
|
|
177
|
+
resourceID: this.getCurrentWebPanel().id
|
|
178
|
+
});
|
|
179
|
+
var result = await new Promise((res, rej) => {
|
|
180
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res, rej };
|
|
181
|
+
_WebSpatial.sendCommand(cmd);
|
|
182
|
+
});
|
|
183
|
+
return result.data;
|
|
184
|
+
}
|
|
185
|
+
static async inspect(spatialObjectId) {
|
|
186
|
+
var cmd = new RemoteCommand("inspect", {
|
|
187
|
+
resourceID: spatialObjectId
|
|
188
|
+
});
|
|
189
|
+
var result = await new Promise((res, rej) => {
|
|
190
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res, rej };
|
|
191
|
+
_WebSpatial.sendCommand(cmd);
|
|
192
|
+
});
|
|
193
|
+
return result.data;
|
|
194
|
+
}
|
|
195
|
+
static async inspectRootWindowContainer() {
|
|
196
|
+
return this.inspect("root");
|
|
197
|
+
}
|
|
198
|
+
static async setComponent(entity, resource) {
|
|
199
|
+
var cmd = new RemoteCommand("setComponent", {
|
|
200
|
+
windowContainerID: entity.windowContainerId,
|
|
201
|
+
resourceID: resource.id,
|
|
202
|
+
entityID: entity.id
|
|
203
|
+
});
|
|
204
|
+
_WebSpatial.sendCommand(cmd);
|
|
205
|
+
}
|
|
206
|
+
static async removeComponent(entity, resource) {
|
|
207
|
+
var cmd = new RemoteCommand("removeComponent", {
|
|
208
|
+
windowContainerID: entity.windowContainerId,
|
|
209
|
+
resourceID: resource.id,
|
|
210
|
+
entityID: entity.id
|
|
211
|
+
});
|
|
212
|
+
_WebSpatial.sendCommand(cmd);
|
|
213
|
+
}
|
|
214
|
+
// windowContainer is the group the resource will be tied to (if not provided it will use the current window grou)
|
|
215
|
+
// parentWebView is the SpatialWebView that the resource will be tied to (if not provided, resource will continue to exist even if this page is unloaded)
|
|
216
|
+
static async createResource(type, windowContainer, parentWebView, params = {}) {
|
|
217
|
+
var cmd = new RemoteCommand("createResource", {
|
|
218
|
+
windowContainerID: windowContainer ? windowContainer.id : void 0,
|
|
219
|
+
resourceID: parentWebView ? parentWebView.id : void 0,
|
|
220
|
+
type,
|
|
221
|
+
params
|
|
222
|
+
});
|
|
223
|
+
var result = await new Promise((res2, rej) => {
|
|
224
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res: res2, rej };
|
|
225
|
+
_WebSpatial.sendCommand(cmd);
|
|
226
|
+
});
|
|
227
|
+
var res = new WebSpatialResource();
|
|
228
|
+
res.id = result.data.createdID;
|
|
229
|
+
res.windowContainerId = cmd.data.windowContainerID;
|
|
230
|
+
return res;
|
|
231
|
+
}
|
|
232
|
+
static async updateWindowContainer(wg, data) {
|
|
233
|
+
var cmd = new RemoteCommand("updateWindowContainer", {
|
|
234
|
+
windowContainerID: wg.id,
|
|
235
|
+
update: data
|
|
236
|
+
});
|
|
237
|
+
var result = await new Promise((res, rej) => {
|
|
238
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res, rej };
|
|
239
|
+
_WebSpatial.sendCommand(cmd);
|
|
240
|
+
});
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
static async updateResource(resource, data = null) {
|
|
244
|
+
var cmd = new RemoteCommand("updateResource", {
|
|
245
|
+
windowContainerID: resource.windowContainerId,
|
|
246
|
+
resourceID: resource.id,
|
|
247
|
+
update: data || resource.data
|
|
248
|
+
});
|
|
249
|
+
var result = await new Promise((res, rej) => {
|
|
250
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res, rej };
|
|
251
|
+
_WebSpatial.sendCommand(cmd);
|
|
252
|
+
});
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
static async setLoading(method, style) {
|
|
256
|
+
var cmd = new RemoteCommand("setLoading", {
|
|
257
|
+
windowContainerID: window._webSpatialParentGroupID,
|
|
258
|
+
// parent WindowContainerID
|
|
259
|
+
loading: {
|
|
260
|
+
method,
|
|
261
|
+
style
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
var result = await new Promise((res, rej) => {
|
|
265
|
+
_WebSpatial.eventPromises[cmd.requestID] = { res, rej };
|
|
266
|
+
_WebSpatial.sendCommand(cmd);
|
|
267
|
+
});
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
static async openImmersiveSpace() {
|
|
271
|
+
var cmd = new RemoteCommand("openImmersiveSpace");
|
|
272
|
+
await _WebSpatial.sendCommand(cmd);
|
|
273
|
+
}
|
|
274
|
+
static async dismissImmersiveSpace() {
|
|
275
|
+
var cmd = new RemoteCommand("dismissImmersiveSpace");
|
|
276
|
+
await _WebSpatial.sendCommand(cmd);
|
|
277
|
+
}
|
|
278
|
+
static onFrame(fn) {
|
|
279
|
+
var dt = 0;
|
|
280
|
+
var loop = async () => {
|
|
281
|
+
var curTime = window.performance.now();
|
|
282
|
+
await fn(curTime);
|
|
283
|
+
var updateTime = window.performance.now() - curTime;
|
|
284
|
+
setTimeout(
|
|
285
|
+
() => {
|
|
286
|
+
loop();
|
|
287
|
+
},
|
|
288
|
+
Math.max(1e3 / 60 - updateTime, 0)
|
|
289
|
+
);
|
|
290
|
+
};
|
|
291
|
+
loop();
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
WebSpatial.init();
|
|
295
|
+
|
|
296
|
+
// src/core/SpatialObject.ts
|
|
297
|
+
var SpatialObject = class {
|
|
298
|
+
/** @hidden */
|
|
299
|
+
constructor(_resource) {
|
|
300
|
+
this._resource = _resource;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Marks resource to be released (it should no longer be used)
|
|
304
|
+
*/
|
|
305
|
+
async destroy() {
|
|
306
|
+
await WebSpatial.destroyResource(this._resource);
|
|
307
|
+
await this.onDestroy();
|
|
308
|
+
}
|
|
309
|
+
name = "";
|
|
310
|
+
async onDestroy() {
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// src/core/SpatialTransform.ts
|
|
315
|
+
var Vec3 = class {
|
|
316
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
317
|
+
this.x = x;
|
|
318
|
+
this.y = y;
|
|
319
|
+
this.z = z;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var Vec4 = class {
|
|
323
|
+
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
324
|
+
this.x = x;
|
|
325
|
+
this.y = y;
|
|
326
|
+
this.z = z;
|
|
327
|
+
this.w = w;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
var SpatialTransform = class {
|
|
331
|
+
position = new Vec3(0, 0, 0);
|
|
332
|
+
/** Quaternion value for x,y,z,w */
|
|
333
|
+
orientation = new Vec4(0, 0, 0, 1);
|
|
334
|
+
scale = new Vec3(1, 1, 1);
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// src/core/SpatialEntity.ts
|
|
338
|
+
var SpatialEntity = class extends SpatialObject {
|
|
339
|
+
/**
|
|
340
|
+
* Transform corresponding to the entity
|
|
341
|
+
* note: updateTransform must be called for transform to be synced to rendering
|
|
342
|
+
*/
|
|
343
|
+
transform = new SpatialTransform();
|
|
344
|
+
/** @hidden */
|
|
345
|
+
_destroyed = false;
|
|
346
|
+
/** @hidden */
|
|
347
|
+
get _entity() {
|
|
348
|
+
return this._resource;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Syncs the transform with the renderer, must be called to observe updates
|
|
352
|
+
*/
|
|
353
|
+
async updateTransform() {
|
|
354
|
+
await WebSpatial.updateResource(this._entity, this.transform);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Syncs the zIndex with the renderer
|
|
358
|
+
*/
|
|
359
|
+
async updateZIndex(zIndex) {
|
|
360
|
+
await WebSpatial.updateResource(this._entity, { zIndex });
|
|
361
|
+
}
|
|
362
|
+
components = /* @__PURE__ */ new Map();
|
|
363
|
+
/**
|
|
364
|
+
* Attaches a component to the entity to be displayed
|
|
365
|
+
* [TODO] review pass by value vs ref and ownership model for this
|
|
366
|
+
*/
|
|
367
|
+
async setComponent(component) {
|
|
368
|
+
await WebSpatial.setComponent(this._entity, component._resource);
|
|
369
|
+
this.components.set(component.constructor, component);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Removes a component from the entity
|
|
373
|
+
*/
|
|
374
|
+
async removeComponent(type) {
|
|
375
|
+
var c = this.getComponent(type);
|
|
376
|
+
if (c != void 0) {
|
|
377
|
+
await WebSpatial.removeComponent(this._entity, c._resource);
|
|
378
|
+
this.components.delete(c.constructor);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Gets a component from the entity
|
|
383
|
+
*/
|
|
384
|
+
getComponent(type) {
|
|
385
|
+
return this.components.get(type);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* @hidden
|
|
389
|
+
* Sets the window container that this entity should be rendered by (this does not effect resource ownership)
|
|
390
|
+
* @param wg the window container that should render this entity
|
|
391
|
+
*/
|
|
392
|
+
async _setParentWindowContainer(wg) {
|
|
393
|
+
await WebSpatial.updateResource(this._entity, {
|
|
394
|
+
setParentWindowContainerID: wg._wg.id
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Sets a parent entity, if that entity or its parents are attached to a window container, this entity will be displayed
|
|
399
|
+
* @param e parent entity or null to remove current parent
|
|
400
|
+
*/
|
|
401
|
+
async setParent(e) {
|
|
402
|
+
await WebSpatial.updateResource(this._entity, {
|
|
403
|
+
setParent: e ? e._entity.id : ""
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Sets the coordinate space of this entity (Default: App)
|
|
408
|
+
* "App" = game engine style coordinates in meters
|
|
409
|
+
* "Dom" = Windowing coordinates in dom units (eg. 0,0,0 is top left of window)
|
|
410
|
+
* "Root" = Coordinate space is ignored and content is displayed and updated as window container's root object, window containers can only have one root entity
|
|
411
|
+
* [TODO] review this api
|
|
412
|
+
* @param space coordinate space mode
|
|
413
|
+
*/
|
|
414
|
+
async setCoordinateSpace(space) {
|
|
415
|
+
await WebSpatial.updateResource(this._entity, { setCoordinateSpace: space });
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Query the 3d boudning box of the entity
|
|
419
|
+
* @returns The bounding box of the entity
|
|
420
|
+
*/
|
|
421
|
+
async getBoundingBox() {
|
|
422
|
+
var res = await WebSpatial.updateResource(this._entity, {
|
|
423
|
+
getBoundingBox: true
|
|
424
|
+
});
|
|
425
|
+
return res.data;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Sets if the entity should be visible (default: True)
|
|
429
|
+
* @param visible
|
|
430
|
+
*/
|
|
431
|
+
async setVisible(visible) {
|
|
432
|
+
await WebSpatial.updateResource(this._entity, { visible });
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Removes a reference to the entity by the renderer and this object should no longer be used. [TODO] Attached components will not be destroyed
|
|
436
|
+
*/
|
|
437
|
+
async destroy() {
|
|
438
|
+
this._destroyed = true;
|
|
439
|
+
await WebSpatial.destroyResource(this._entity);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Check if destroy has been called
|
|
443
|
+
*/
|
|
444
|
+
isDestroyed() {
|
|
445
|
+
return this._destroyed;
|
|
446
|
+
}
|
|
447
|
+
// Set Entity name. Currently for debugging only.
|
|
448
|
+
/** @hidden */
|
|
449
|
+
async _setName(name) {
|
|
450
|
+
this.name = name;
|
|
451
|
+
return WebSpatial.updateResource(this._entity, { name });
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// src/core/component/SpatialComponent.ts
|
|
456
|
+
var SpatialComponent = class extends SpatialObject {
|
|
457
|
+
/**
|
|
458
|
+
* Gets the entity this component is attached to
|
|
459
|
+
* @returns entity or null
|
|
460
|
+
*/
|
|
461
|
+
async getEntity() {
|
|
462
|
+
let reqResp = await WebSpatial.updateResource(
|
|
463
|
+
WebSpatial.getCurrentWebPanel(),
|
|
464
|
+
{ getEntityID: "" }
|
|
465
|
+
);
|
|
466
|
+
if (reqResp.data.parentID === "") {
|
|
467
|
+
return new Promise((res2, rej) => {
|
|
468
|
+
res2(null);
|
|
469
|
+
});
|
|
470
|
+
} else {
|
|
471
|
+
var res = new WebSpatialResource();
|
|
472
|
+
res.id = reqResp.data.parentID;
|
|
473
|
+
return new SpatialEntity(res);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// src/core/component/SpatialWindowComponent.ts
|
|
479
|
+
var SpatialWindowComponent = class extends SpatialComponent {
|
|
480
|
+
/**
|
|
481
|
+
* Loads a url page in the window
|
|
482
|
+
* @param url url to load
|
|
483
|
+
*/
|
|
484
|
+
async loadURL(url) {
|
|
485
|
+
await WebSpatial.updateResource(this._resource, { url });
|
|
486
|
+
}
|
|
487
|
+
async setFromWindow(window2) {
|
|
488
|
+
if (window2._webSpatialID) {
|
|
489
|
+
await WebSpatial.updateResource(this._resource, {
|
|
490
|
+
windowID: window2._webSpatialID
|
|
491
|
+
});
|
|
492
|
+
} else {
|
|
493
|
+
await console.warn(
|
|
494
|
+
"failed to call setFromWindow, window provided is not valid"
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Sets the resolution of the window, the resulting dimensions when rendered will be equal to 1/1360 units
|
|
500
|
+
* eg. if the resolution is set to 1360x1360 it will be a 1x1 plane
|
|
501
|
+
* See 1360 in spatialViewUI.swift for how this ratio works
|
|
502
|
+
* @param width width in pixels
|
|
503
|
+
* @param height height in pixels
|
|
504
|
+
*/
|
|
505
|
+
async setResolution(width, height) {
|
|
506
|
+
await WebSpatial.updateResource(this._resource, {
|
|
507
|
+
resolution: { x: width, y: height }
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* [Experimental] Sets the anchor which the entity this is attached to will rotate around
|
|
512
|
+
* @param rotationAnchor
|
|
513
|
+
*/
|
|
514
|
+
async setRotationAnchor(rotationAnchor) {
|
|
515
|
+
await WebSpatial.updateResource(this._resource, {
|
|
516
|
+
rotationAnchor
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* [Experimental] Sets the opacity of the window after apply material
|
|
521
|
+
* @param opacity
|
|
522
|
+
*/
|
|
523
|
+
async setOpacity(opacity) {
|
|
524
|
+
await WebSpatial.updateResource(this._resource, {
|
|
525
|
+
opacity
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Sets the style that should be applied to the window
|
|
530
|
+
* @param options style options
|
|
531
|
+
*/
|
|
532
|
+
async setStyle(styleParam) {
|
|
533
|
+
const { material, cornerRadius } = styleParam;
|
|
534
|
+
const options = {};
|
|
535
|
+
if (material?.type) {
|
|
536
|
+
options.backgroundMaterial = material.type;
|
|
537
|
+
}
|
|
538
|
+
if (cornerRadius !== void 0) {
|
|
539
|
+
if (typeof cornerRadius === "number") {
|
|
540
|
+
options.cornerRadius = {
|
|
541
|
+
topLeading: cornerRadius,
|
|
542
|
+
bottomLeading: cornerRadius,
|
|
543
|
+
topTrailing: cornerRadius,
|
|
544
|
+
bottomTrailing: cornerRadius
|
|
545
|
+
};
|
|
546
|
+
} else {
|
|
547
|
+
options.cornerRadius = { ...cornerRadius };
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (document && document.readyState == "loading") {
|
|
551
|
+
var encoded = encodeURIComponent(JSON.stringify(options));
|
|
552
|
+
var x = document.createElement("link");
|
|
553
|
+
x.rel = "stylesheet";
|
|
554
|
+
x.href = "forceStyle://mystyle.css?style=" + encoded;
|
|
555
|
+
document.head.appendChild(x);
|
|
556
|
+
}
|
|
557
|
+
await WebSpatial.updateResource(this._resource, { style: options });
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Modifies the amount the spatial window can be scrolled
|
|
561
|
+
* Should only be used internally
|
|
562
|
+
* See https://developer.apple.com/documentation/uikit/1624475-uiedgeinsetsmake?language=objc
|
|
563
|
+
* @param insets margin to modify scroll distances by
|
|
564
|
+
*/
|
|
565
|
+
async setScrollEdgeInsets(insets) {
|
|
566
|
+
await WebSpatial.updateResource(this._resource, {
|
|
567
|
+
setScrollEdgeInsets: insets
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Enable/Disable scrolling in the window (defaults to enabled), if disabled, scrolling will be applied to the root page
|
|
572
|
+
* @param enabled value to set
|
|
573
|
+
*/
|
|
574
|
+
async setScrollEnabled(enabled) {
|
|
575
|
+
await WebSpatial.updateResource(this._resource, { scrollEnabled: enabled });
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Defaults to false. If set to true, scrolling the parent page will also scroll this window with it like other dom elements
|
|
579
|
+
* @param scrollWithParent value to set
|
|
580
|
+
*/
|
|
581
|
+
async setScrollWithParent(scrollWithParent) {
|
|
582
|
+
await WebSpatial.updateResource(this._resource, {
|
|
583
|
+
scrollWithParent
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
// src/core/component/EventSpatialComponent.ts
|
|
589
|
+
var EventSpatialComponent = class extends SpatialComponent {
|
|
590
|
+
// Class implementation goes here
|
|
591
|
+
constructor(_resource) {
|
|
592
|
+
super(_resource);
|
|
593
|
+
WebSpatial.registerEventReceiver(_resource.id, (data) => {
|
|
594
|
+
this.onRecvEvent(data);
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
async onDestroy() {
|
|
598
|
+
WebSpatial.unregisterEventReceiver(this._resource.id);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
// src/core/component/SpatialInputComponent.ts
|
|
603
|
+
var SpatialInputComponent = class extends EventSpatialComponent {
|
|
604
|
+
onRecvEvent(data) {
|
|
605
|
+
this.onTranslate(data);
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Callback fired when a translate event occurs
|
|
609
|
+
* @param data translate event data
|
|
610
|
+
*/
|
|
611
|
+
onTranslate(data) {
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// src/core/component/SpatialModelComponent.ts
|
|
616
|
+
var SpatialModelComponent = class extends SpatialComponent {
|
|
617
|
+
cachedMaterials = new Array();
|
|
618
|
+
/**
|
|
619
|
+
* Sets the mesh to be displayed by the component
|
|
620
|
+
* @param mesh mesh to set
|
|
621
|
+
*/
|
|
622
|
+
async setMesh(mesh) {
|
|
623
|
+
await WebSpatial.updateResource(this._resource, {
|
|
624
|
+
meshResource: mesh._resource.id
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Sets the materials that should be applied to the mesh
|
|
629
|
+
* @param materials array of materials to set
|
|
630
|
+
*/
|
|
631
|
+
async setMaterials(materials) {
|
|
632
|
+
this.cachedMaterials = materials;
|
|
633
|
+
await WebSpatial.updateResource(this._resource, {
|
|
634
|
+
materials: materials.map((m) => {
|
|
635
|
+
m._addToComponent(this);
|
|
636
|
+
return m._resource.id;
|
|
637
|
+
})
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
/** @hidden */
|
|
641
|
+
async _syncMaterials() {
|
|
642
|
+
await this.setMaterials(this.cachedMaterials);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/core/component/SpatialViewComponent.ts
|
|
647
|
+
var SpatialViewComponent = class extends SpatialComponent {
|
|
648
|
+
/**
|
|
649
|
+
* Sets the resolution of the spatial view in dom pixels
|
|
650
|
+
*/
|
|
651
|
+
async setResolution(width, height) {
|
|
652
|
+
await WebSpatial.updateResource(this._resource, {
|
|
653
|
+
resolution: { x: width, y: height }
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Sets if content of the spatialView should be within a portal
|
|
658
|
+
* If true, volume will be behind the page, if false, it will be in front of the page
|
|
659
|
+
*/
|
|
660
|
+
async setIsPortal(isPortal) {
|
|
661
|
+
await WebSpatial.updateResource(this._resource, {
|
|
662
|
+
isPortal
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
|
|
667
|
+
// src/core/component/SpatialModel3DComponent.ts
|
|
668
|
+
var SpatialModel3DComponent = class extends EventSpatialComponent {
|
|
669
|
+
onRecvEvent(data) {
|
|
670
|
+
const { eventType, value, error } = data;
|
|
671
|
+
switch (eventType) {
|
|
672
|
+
case "phase":
|
|
673
|
+
if (value === "success") {
|
|
674
|
+
this.onSuccess?.();
|
|
675
|
+
} else {
|
|
676
|
+
this.onFailure?.(error);
|
|
677
|
+
}
|
|
678
|
+
break;
|
|
679
|
+
case "dragstart":
|
|
680
|
+
this._onDragStart?.(value);
|
|
681
|
+
break;
|
|
682
|
+
case "dragend":
|
|
683
|
+
this._onDragEnd?.(value);
|
|
684
|
+
break;
|
|
685
|
+
case "drag":
|
|
686
|
+
this._onDrag?.(value);
|
|
687
|
+
break;
|
|
688
|
+
case "tap":
|
|
689
|
+
this._onTap?.();
|
|
690
|
+
break;
|
|
691
|
+
case "doubletap":
|
|
692
|
+
this._onDoubleTap?.();
|
|
693
|
+
break;
|
|
694
|
+
case "longpress":
|
|
695
|
+
this._onLongPress?.();
|
|
696
|
+
break;
|
|
697
|
+
default:
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Sets the resolution of the spatial view in dom pixels
|
|
703
|
+
*/
|
|
704
|
+
async setResolution(width, height) {
|
|
705
|
+
await WebSpatial.updateResource(this._resource, {
|
|
706
|
+
resolution: { x: width, y: height }
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
async setRotationAnchor(rotationAnchor) {
|
|
710
|
+
await WebSpatial.updateResource(this._resource, {
|
|
711
|
+
rotationAnchor
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Sets the opacity of the model
|
|
716
|
+
* @param opacity
|
|
717
|
+
*/
|
|
718
|
+
async setOpacity(opacity) {
|
|
719
|
+
await WebSpatial.updateResource(this._resource, {
|
|
720
|
+
opacity
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Sets how the model fill the rect
|
|
725
|
+
* @param contentMode
|
|
726
|
+
*/
|
|
727
|
+
async setContentMode(contentMode) {
|
|
728
|
+
await WebSpatial.updateResource(this._resource, {
|
|
729
|
+
contentMode
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Constrains this model dimensions to the specified aspect ratio.
|
|
734
|
+
* with a value of 0, the model will use the original aspect ratio.
|
|
735
|
+
*
|
|
736
|
+
* @param aspectRatio number
|
|
737
|
+
*/
|
|
738
|
+
async setAspectRatio(aspectRatio) {
|
|
739
|
+
await WebSpatial.updateResource(this._resource, {
|
|
740
|
+
aspectRatio
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Defaults to false. If set to true, scrolling the parent page will also scroll this window with it like other dom elements
|
|
745
|
+
* @param scrollWithParent value to set
|
|
746
|
+
*/
|
|
747
|
+
async setScrollWithParent(scrollWithParent) {
|
|
748
|
+
await WebSpatial.updateResource(this._resource, {
|
|
749
|
+
scrollWithParent
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Sets whether the model appear in original size or fit the rect
|
|
754
|
+
* @param resizable
|
|
755
|
+
*/
|
|
756
|
+
async setResizable(resizable) {
|
|
757
|
+
await WebSpatial.updateResource(this._resource, {
|
|
758
|
+
resizable
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Callback fired when model load success
|
|
763
|
+
*/
|
|
764
|
+
onSuccess;
|
|
765
|
+
/**
|
|
766
|
+
* Callback fired when model load failure
|
|
767
|
+
* @param errorReason
|
|
768
|
+
*/
|
|
769
|
+
onFailure;
|
|
770
|
+
/**
|
|
771
|
+
* Callback fired when model was dragged at the beginning
|
|
772
|
+
* @param dragEvent
|
|
773
|
+
*/
|
|
774
|
+
_onDragStart;
|
|
775
|
+
set onDragStart(callback) {
|
|
776
|
+
if (this._onDragStart !== callback) {
|
|
777
|
+
this._onDragStart = callback;
|
|
778
|
+
WebSpatial.updateResource(this._resource, {
|
|
779
|
+
enableDragEvent: this.enableDragEvent
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Callback fired when model was dragged
|
|
785
|
+
* @param dragEvent
|
|
786
|
+
*/
|
|
787
|
+
_onDrag;
|
|
788
|
+
set onDrag(callback) {
|
|
789
|
+
if (this._onDrag !== callback) {
|
|
790
|
+
this._onDrag = callback;
|
|
791
|
+
WebSpatial.updateResource(this._resource, {
|
|
792
|
+
enableDragEvent: this.enableDragEvent
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Callback fired when model was dragged at the ending
|
|
798
|
+
* @param dragEvent
|
|
799
|
+
*/
|
|
800
|
+
_onDragEnd;
|
|
801
|
+
set onDragEnd(callback) {
|
|
802
|
+
if (this._onDragEnd !== callback) {
|
|
803
|
+
this._onDragEnd = callback;
|
|
804
|
+
WebSpatial.updateResource(this._resource, {
|
|
805
|
+
enableDragEvent: this.enableDragEvent
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
get enableDragEvent() {
|
|
810
|
+
return void 0 !== this._onDrag || void 0 !== this._onDragStart || void 0 !== this._onDragEnd;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Callback fired when model was tapped
|
|
814
|
+
*/
|
|
815
|
+
_onTap;
|
|
816
|
+
set onTap(callback) {
|
|
817
|
+
if (this._onTap !== callback) {
|
|
818
|
+
this._onTap = callback;
|
|
819
|
+
WebSpatial.updateResource(this._resource, {
|
|
820
|
+
enableTapEvent: void 0 !== callback
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
/** Callback fired when model was double tapped */
|
|
825
|
+
_onDoubleTap;
|
|
826
|
+
set onDoubleTap(callback) {
|
|
827
|
+
if (this._onDoubleTap !== callback) {
|
|
828
|
+
this._onDoubleTap = callback;
|
|
829
|
+
WebSpatial.updateResource(this._resource, {
|
|
830
|
+
enableDoubleTapEvent: void 0 !== callback
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
/** Callback fired when model was long pressed */
|
|
835
|
+
_onLongPress;
|
|
836
|
+
set onLongPress(callback) {
|
|
837
|
+
if (this._onLongPress !== callback) {
|
|
838
|
+
this._onLongPress = callback;
|
|
839
|
+
WebSpatial.updateResource(this._resource, {
|
|
840
|
+
enableLongPressEvent: void 0 !== callback
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
// src/core/resource/SpatialMeshResource.ts
|
|
847
|
+
var SpatialMeshResource = class extends SpatialObject {
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
// src/core/resource/SpatialPhysicallyBasedMaterialResource.ts
|
|
851
|
+
var SpatialPhysicallyBasedMaterialResource = class extends SpatialObject {
|
|
852
|
+
/**
|
|
853
|
+
* Base color of the material containing rgba between 0 and 1
|
|
854
|
+
*/
|
|
855
|
+
baseColor = { r: 0, g: 0.7, b: 0.7, a: 1 };
|
|
856
|
+
/**
|
|
857
|
+
* PBR metalic value between 0 and 1
|
|
858
|
+
*/
|
|
859
|
+
metallic = { value: 0.5 };
|
|
860
|
+
/**
|
|
861
|
+
* PBR roughness value between 0 and 1
|
|
862
|
+
*/
|
|
863
|
+
roughness = { value: 0.5 };
|
|
864
|
+
_modelComponentAttachedTo = {};
|
|
865
|
+
_addToComponent(c) {
|
|
866
|
+
this._modelComponentAttachedTo[c._resource.id] = c;
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Syncs state of color, metallic, roupghness to the renderer
|
|
870
|
+
*/
|
|
871
|
+
async update() {
|
|
872
|
+
await WebSpatial.updateResource(this._resource, {
|
|
873
|
+
baseColor: this.baseColor,
|
|
874
|
+
metallic: this.metallic,
|
|
875
|
+
roughness: this.roughness
|
|
876
|
+
});
|
|
877
|
+
for (var key in this._modelComponentAttachedTo) {
|
|
878
|
+
await this._modelComponentAttachedTo[key]._syncMaterials();
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
// src/core/SpatialWindowContainer.ts
|
|
884
|
+
var SpatialWindowContainer = class {
|
|
885
|
+
/** @hidden */
|
|
886
|
+
constructor(_wg) {
|
|
887
|
+
this._wg = _wg;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* @hidden
|
|
891
|
+
* Sets sets the open configuration for opening new window containers
|
|
892
|
+
* @param options style options
|
|
893
|
+
*/
|
|
894
|
+
async _setOpenSettings(options) {
|
|
895
|
+
await WebSpatial.updateWindowContainer(this._wg, {
|
|
896
|
+
nextOpenSettings: options
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Retrieves the root entity of the windowContainer
|
|
901
|
+
* @returns the root entity of the windowContainer if one exists
|
|
902
|
+
*/
|
|
903
|
+
async getRootEntity() {
|
|
904
|
+
let reqResp = await WebSpatial.updateWindowContainer(this._wg, {
|
|
905
|
+
getRootEntityID: ""
|
|
906
|
+
});
|
|
907
|
+
if (reqResp.data.rootEntId === "") {
|
|
908
|
+
return null;
|
|
909
|
+
} else {
|
|
910
|
+
var res = new WebSpatialResource();
|
|
911
|
+
res.id = reqResp.data.rootEntId;
|
|
912
|
+
return new SpatialEntity(res);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
/*
|
|
916
|
+
* Sets the root entity that this windowContainer will display (this does not effect resource ownership)
|
|
917
|
+
* @param entity to display
|
|
918
|
+
*/
|
|
919
|
+
async setRootEntity(entity) {
|
|
920
|
+
await entity._setParentWindowContainer(this);
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
// src/core/SpatialSession.ts
|
|
925
|
+
function _parseParentResources(options) {
|
|
926
|
+
var parentWindowContainer = null;
|
|
927
|
+
if (options?.windowContainer !== null) {
|
|
928
|
+
parentWindowContainer = options?.windowContainer ? options?.windowContainer._wg : WebSpatial.getCurrentWindowContainer();
|
|
929
|
+
}
|
|
930
|
+
var parentWindow = null;
|
|
931
|
+
if (options?.windowComponent !== null) {
|
|
932
|
+
parentWindow = options?.windowComponent ? options?.windowComponent._resource : WebSpatial.getCurrentWebPanel();
|
|
933
|
+
}
|
|
934
|
+
return [parentWindowContainer, parentWindow];
|
|
935
|
+
}
|
|
936
|
+
var SpatialSession = class _SpatialSession {
|
|
937
|
+
/** @hidden */
|
|
938
|
+
_engineUpdateListeners = Array();
|
|
939
|
+
/** @hidden */
|
|
940
|
+
_frameLoopStarted = false;
|
|
941
|
+
/**
|
|
942
|
+
* Add event listener callback to be called each frame
|
|
943
|
+
* @param callback callback to be called each update
|
|
944
|
+
*/
|
|
945
|
+
addOnEngineUpdateEventListener(callback) {
|
|
946
|
+
this._engineUpdateListeners.push(callback);
|
|
947
|
+
if (!this._frameLoopStarted) {
|
|
948
|
+
this._frameLoopStarted = true;
|
|
949
|
+
WebSpatial.onFrame(async (time) => {
|
|
950
|
+
await Promise.all(
|
|
951
|
+
this._engineUpdateListeners.map((cb) => {
|
|
952
|
+
return cb(time);
|
|
953
|
+
})
|
|
954
|
+
);
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Creates a Entity
|
|
960
|
+
* @returns Entity
|
|
961
|
+
*/
|
|
962
|
+
async createEntity(options) {
|
|
963
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
964
|
+
let entity = await WebSpatial.createResource(
|
|
965
|
+
"Entity",
|
|
966
|
+
parentWindowContainer,
|
|
967
|
+
parentWindow
|
|
968
|
+
);
|
|
969
|
+
return new SpatialEntity(entity);
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Creates a WindowComponent
|
|
973
|
+
* [TODO] should creation of components be moved to entity? and these made private?
|
|
974
|
+
* @returns WindowComponent
|
|
975
|
+
*/
|
|
976
|
+
async createWindowComponent(options) {
|
|
977
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
978
|
+
let entity = await WebSpatial.createResource(
|
|
979
|
+
"SpatialWebView",
|
|
980
|
+
parentWindowContainer,
|
|
981
|
+
parentWindow
|
|
982
|
+
);
|
|
983
|
+
return new SpatialWindowComponent(entity);
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Creates a ViewComponent used to display 3D content within the entity
|
|
987
|
+
* @returns SpatialViewComponent
|
|
988
|
+
*/
|
|
989
|
+
async createViewComponent(options) {
|
|
990
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
991
|
+
let entity = await WebSpatial.createResource(
|
|
992
|
+
"SpatialView",
|
|
993
|
+
parentWindowContainer,
|
|
994
|
+
parentWindow
|
|
995
|
+
);
|
|
996
|
+
return new SpatialViewComponent(entity);
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Creates a ModelComponent used to display geometry + material of a 3D model
|
|
1000
|
+
* @returns ModelComponent
|
|
1001
|
+
*/
|
|
1002
|
+
async createModelComponent(options) {
|
|
1003
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
1004
|
+
var opts = void 0;
|
|
1005
|
+
if (options) {
|
|
1006
|
+
opts = { modelURL: options.url };
|
|
1007
|
+
}
|
|
1008
|
+
let entity = await WebSpatial.createResource(
|
|
1009
|
+
"ModelComponent",
|
|
1010
|
+
parentWindowContainer,
|
|
1011
|
+
parentWindow,
|
|
1012
|
+
opts
|
|
1013
|
+
);
|
|
1014
|
+
return new SpatialModelComponent(entity);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Creates a Model3DComponent
|
|
1018
|
+
* @returns Model3DComponent
|
|
1019
|
+
*/
|
|
1020
|
+
async createModel3DComponent(options) {
|
|
1021
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
1022
|
+
var opts = void 0;
|
|
1023
|
+
if (options) {
|
|
1024
|
+
opts = { modelURL: options.url };
|
|
1025
|
+
}
|
|
1026
|
+
let entity = await WebSpatial.createResource(
|
|
1027
|
+
"Model3DComponent",
|
|
1028
|
+
parentWindowContainer,
|
|
1029
|
+
parentWindow,
|
|
1030
|
+
opts
|
|
1031
|
+
);
|
|
1032
|
+
return new SpatialModel3DComponent(entity);
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Creates a InputComponent
|
|
1036
|
+
* [Experimental] Creates a InputComponent used to handle click and drag events of the entity containing a model
|
|
1037
|
+
* @returns InputComponent
|
|
1038
|
+
*/
|
|
1039
|
+
async createInputComponent(options) {
|
|
1040
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
1041
|
+
let entity = await WebSpatial.createResource(
|
|
1042
|
+
"InputComponent",
|
|
1043
|
+
parentWindowContainer,
|
|
1044
|
+
parentWindow
|
|
1045
|
+
);
|
|
1046
|
+
return new SpatialInputComponent(entity);
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Creates a MeshResource containing geometry data
|
|
1050
|
+
* @returns MeshResource
|
|
1051
|
+
*/
|
|
1052
|
+
async createMeshResource(options) {
|
|
1053
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
1054
|
+
let entity = await WebSpatial.createResource(
|
|
1055
|
+
"MeshResource",
|
|
1056
|
+
parentWindowContainer,
|
|
1057
|
+
parentWindow,
|
|
1058
|
+
options
|
|
1059
|
+
);
|
|
1060
|
+
return new SpatialMeshResource(entity);
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Creates a PhysicallyBasedMaterial containing PBR material data
|
|
1064
|
+
* @returns PhysicallyBasedMaterial
|
|
1065
|
+
*/
|
|
1066
|
+
async createPhysicallyBasedMaterialResource(options) {
|
|
1067
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
1068
|
+
let entity = await WebSpatial.createResource(
|
|
1069
|
+
"PhysicallyBasedMaterial",
|
|
1070
|
+
parentWindowContainer,
|
|
1071
|
+
parentWindow,
|
|
1072
|
+
options
|
|
1073
|
+
);
|
|
1074
|
+
return new SpatialPhysicallyBasedMaterialResource(entity);
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Creates a WindowContainer
|
|
1078
|
+
* @returns SpatialWindowContainer
|
|
1079
|
+
* */
|
|
1080
|
+
async createWindowContainer(options) {
|
|
1081
|
+
var style = options?.style ? options?.style : "Plain";
|
|
1082
|
+
var [parentWindowContainer, parentWindow] = _parseParentResources(options);
|
|
1083
|
+
return new SpatialWindowContainer(
|
|
1084
|
+
await WebSpatial.createWindowContainer(
|
|
1085
|
+
style,
|
|
1086
|
+
parentWindowContainer,
|
|
1087
|
+
parentWindow
|
|
1088
|
+
)
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Creates a Scene to display content within an anchored area managed by the OS
|
|
1093
|
+
* @hidden
|
|
1094
|
+
* @param {WindowStyle} [style='Plain'] - The style of the Scene container to be created with. Defaults to 'Plain'.
|
|
1095
|
+
* @param {Object} [cfg={}] - Configuration object for the Scene.
|
|
1096
|
+
* @returns Boolean
|
|
1097
|
+
*/
|
|
1098
|
+
async _createScene(style = "Plain", cfg) {
|
|
1099
|
+
return await WebSpatial.createScene(style, cfg);
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Retrieves the window for this page
|
|
1103
|
+
* @returns the window component corresponding to the js running on this page
|
|
1104
|
+
* [TODO] discuss implications of this not being async
|
|
1105
|
+
*/
|
|
1106
|
+
getCurrentWindowComponent() {
|
|
1107
|
+
return new SpatialWindowComponent(WebSpatial.getCurrentWebPanel());
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Retrieves the parent window for this page or null if this is the root page
|
|
1111
|
+
* @returns the window component or null
|
|
1112
|
+
*/
|
|
1113
|
+
async getParentWindowComponent() {
|
|
1114
|
+
let parentResp = await WebSpatial.updateResource(
|
|
1115
|
+
WebSpatial.getCurrentWebPanel(),
|
|
1116
|
+
{ getParentID: "" }
|
|
1117
|
+
);
|
|
1118
|
+
if (parentResp.data.parentID === "") {
|
|
1119
|
+
return new Promise((res2, rej) => {
|
|
1120
|
+
res2(null);
|
|
1121
|
+
});
|
|
1122
|
+
} else {
|
|
1123
|
+
var res = new WebSpatialResource();
|
|
1124
|
+
res.id = parentResp.data.parentID;
|
|
1125
|
+
return new SpatialWindowComponent(res);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Logs a message to the native apps console
|
|
1130
|
+
* @param msg mesage to log
|
|
1131
|
+
*/
|
|
1132
|
+
async log(...msg) {
|
|
1133
|
+
await WebSpatial.sendCommand(
|
|
1134
|
+
new RemoteCommand("log", {
|
|
1135
|
+
logString: msg.map((x) => {
|
|
1136
|
+
return JSON.stringify(x);
|
|
1137
|
+
})
|
|
1138
|
+
})
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* @hidden
|
|
1143
|
+
* Debugging only, used to ping the native renderer
|
|
1144
|
+
*/
|
|
1145
|
+
async _ping(msg) {
|
|
1146
|
+
return await WebSpatial.ping(msg);
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* @hidden
|
|
1150
|
+
* Debugging to get internal state from native code
|
|
1151
|
+
* @returns data as a js object
|
|
1152
|
+
*/
|
|
1153
|
+
async _getStats() {
|
|
1154
|
+
return await WebSpatial.getStats();
|
|
1155
|
+
}
|
|
1156
|
+
/**
|
|
1157
|
+
* @hidden
|
|
1158
|
+
*/
|
|
1159
|
+
async _inspect(spatialObjectId = WebSpatial.getCurrentWebPanel().id) {
|
|
1160
|
+
return WebSpatial.inspect(spatialObjectId);
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* @hidden
|
|
1164
|
+
*/
|
|
1165
|
+
async _inspectRootWindowContainer() {
|
|
1166
|
+
return WebSpatial.inspectRootWindowContainer();
|
|
1167
|
+
}
|
|
1168
|
+
/** Opens the immersive space */
|
|
1169
|
+
async openImmersiveSpace() {
|
|
1170
|
+
return await WebSpatial.openImmersiveSpace();
|
|
1171
|
+
}
|
|
1172
|
+
/** Closes the immersive space */
|
|
1173
|
+
async dismissImmersiveSpace() {
|
|
1174
|
+
return await WebSpatial.dismissImmersiveSpace();
|
|
1175
|
+
}
|
|
1176
|
+
static _immersiveWindowContainer = null;
|
|
1177
|
+
/**
|
|
1178
|
+
* Retreives the window container corresponding to the Immersive space
|
|
1179
|
+
* @returns the immersive window container
|
|
1180
|
+
*/
|
|
1181
|
+
async getImmersiveWindowContainer() {
|
|
1182
|
+
if (_SpatialSession._immersiveWindowContainer) {
|
|
1183
|
+
return _SpatialSession._immersiveWindowContainer;
|
|
1184
|
+
} else {
|
|
1185
|
+
_SpatialSession._immersiveWindowContainer = new SpatialWindowContainer(
|
|
1186
|
+
WebSpatial.getImmersiveWindowContainer()
|
|
1187
|
+
);
|
|
1188
|
+
return _SpatialSession._immersiveWindowContainer;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
// Retreives the window container that is the parent to this spatial web page
|
|
1192
|
+
static _currentWindowContainer = null;
|
|
1193
|
+
/**
|
|
1194
|
+
* Gets the current window container for the window
|
|
1195
|
+
* [TODO] discuss what happens if it doesnt yet have a window container
|
|
1196
|
+
* @returns the current window container for the window
|
|
1197
|
+
*/
|
|
1198
|
+
getCurrentWindowContainer() {
|
|
1199
|
+
if (_SpatialSession._currentWindowContainer) {
|
|
1200
|
+
return _SpatialSession._currentWindowContainer;
|
|
1201
|
+
} else {
|
|
1202
|
+
_SpatialSession._currentWindowContainer = new SpatialWindowContainer(
|
|
1203
|
+
WebSpatial.getCurrentWindowContainer()
|
|
1204
|
+
);
|
|
1205
|
+
return _SpatialSession._currentWindowContainer;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
/**
|
|
1209
|
+
* Start a transaction that queues up commands to submit them all at once to reduce ipc overhead
|
|
1210
|
+
* @param fn function to be run, within this function, promises will not resolve
|
|
1211
|
+
* @returns promise for the entire transaction completion
|
|
1212
|
+
*/
|
|
1213
|
+
transaction(fn) {
|
|
1214
|
+
WebSpatial.startTransaction();
|
|
1215
|
+
fn();
|
|
1216
|
+
return WebSpatial.sendTransaction();
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Creates a window context object that is compatable with SpatialWindowComponent's setFromWindow API
|
|
1220
|
+
* @returns window context
|
|
1221
|
+
*/
|
|
1222
|
+
async createWindowContext() {
|
|
1223
|
+
let openedWindow = window.open("webspatial://createWindowContext");
|
|
1224
|
+
if (WebSpatial.getBackend() != "AVP") {
|
|
1225
|
+
var counter = 0;
|
|
1226
|
+
while (openedWindow.window.testAPI == null) {
|
|
1227
|
+
if (counter > 15) {
|
|
1228
|
+
openedWindow?.close();
|
|
1229
|
+
openedWindow = window.open("about:blank");
|
|
1230
|
+
counter = 0;
|
|
1231
|
+
this.log("unexpected error when trying to open new window, retrying.");
|
|
1232
|
+
}
|
|
1233
|
+
var locName = "about:blank?x" + counter;
|
|
1234
|
+
openedWindow.location.href = locName;
|
|
1235
|
+
counter++;
|
|
1236
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1237
|
+
}
|
|
1238
|
+
;
|
|
1239
|
+
openedWindow._webSpatialID = openedWindow.window.testAPI.getWindowID();
|
|
1240
|
+
} else {
|
|
1241
|
+
while (openedWindow.window._webSpatialID == void 0) {
|
|
1242
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
openedWindow.document.head.innerHTML = '<meta name="viewport" content="width=device-width, initial-scale=1">';
|
|
1246
|
+
return openedWindow;
|
|
1247
|
+
}
|
|
1248
|
+
// Get Entity by id. Currently for debugging only.
|
|
1249
|
+
/** @hidden */
|
|
1250
|
+
async _getEntity(id) {
|
|
1251
|
+
const entityInfo = await WebSpatial.inspect(id);
|
|
1252
|
+
const [_, x, y, z] = entityInfo.position.match(/(\d+\.?\d*)/g);
|
|
1253
|
+
const [__, sx, sy, sz] = entityInfo.scale.match(/(\d+\.?\d*)/g);
|
|
1254
|
+
var res = new WebSpatialResource();
|
|
1255
|
+
res.id = id;
|
|
1256
|
+
res.windowContainerId = WebSpatial.getCurrentWindowContainer().id;
|
|
1257
|
+
const entity = new SpatialEntity(res);
|
|
1258
|
+
entity.transform.position.x = parseFloat(x);
|
|
1259
|
+
entity.transform.position.y = parseFloat(y);
|
|
1260
|
+
entity.transform.position.z = parseFloat(z);
|
|
1261
|
+
entity.transform.scale.x = parseFloat(sx);
|
|
1262
|
+
entity.transform.scale.y = parseFloat(sy);
|
|
1263
|
+
entity.transform.scale.z = parseFloat(sz);
|
|
1264
|
+
return entity;
|
|
1265
|
+
}
|
|
1266
|
+
// set loading view.
|
|
1267
|
+
/** @hidden */
|
|
1268
|
+
async setLoading(method, style) {
|
|
1269
|
+
return WebSpatial.setLoading(method, style);
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
|
|
1273
|
+
// src/core/Spatial.ts
|
|
1274
|
+
var Spatial = class {
|
|
1275
|
+
/**
|
|
1276
|
+
* Requests a session object from the browser
|
|
1277
|
+
* @returns The session or null if not availible in the current browser
|
|
1278
|
+
* [TODO] discuss implications of this not being async
|
|
1279
|
+
*/
|
|
1280
|
+
requestSession() {
|
|
1281
|
+
if (this.isSupported() && this.getNativeVersion() === this.getClientVersion()) {
|
|
1282
|
+
return new SpatialSession();
|
|
1283
|
+
} else {
|
|
1284
|
+
return null;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* @returns true if web spatial is supported by this webpage
|
|
1289
|
+
*/
|
|
1290
|
+
isSupported() {
|
|
1291
|
+
return window.WebSpatailEnabled && this.getNativeVersion() === this.getClientVersion();
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Gets the native version, format is "x.x.x"
|
|
1295
|
+
* @returns native version string
|
|
1296
|
+
*/
|
|
1297
|
+
getNativeVersion() {
|
|
1298
|
+
return window.WebSpatailNativeVersion;
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Gets the client version, format is "x.x.x"
|
|
1302
|
+
* @returns client version string
|
|
1303
|
+
*/
|
|
1304
|
+
getClientVersion() {
|
|
1305
|
+
return "0.0.1";
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
|
|
1309
|
+
// src/core/SpatialHelper.ts
|
|
1310
|
+
var SpatialHelper = class _SpatialHelper {
|
|
1311
|
+
constructor(session) {
|
|
1312
|
+
this.session = session;
|
|
1313
|
+
}
|
|
1314
|
+
static _instance = null;
|
|
1315
|
+
static get instance() {
|
|
1316
|
+
if (this._instance) {
|
|
1317
|
+
return this._instance;
|
|
1318
|
+
} else {
|
|
1319
|
+
let spatial = new Spatial();
|
|
1320
|
+
if (spatial.isSupported()) {
|
|
1321
|
+
let session = spatial.requestSession();
|
|
1322
|
+
if (session) {
|
|
1323
|
+
this._instance = new _SpatialHelper(session);
|
|
1324
|
+
return this._instance;
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return null;
|
|
1329
|
+
}
|
|
1330
|
+
shape = {
|
|
1331
|
+
createShapeEntity: async (shape = "box") => {
|
|
1332
|
+
var box = await this.session.createMeshResource({ shape });
|
|
1333
|
+
var mat = await this.session.createPhysicallyBasedMaterialResource();
|
|
1334
|
+
await mat.update();
|
|
1335
|
+
var customModel = await this.session.createModelComponent();
|
|
1336
|
+
customModel.setMaterials([mat]);
|
|
1337
|
+
customModel.setMesh(box);
|
|
1338
|
+
var boxEntity = await this.session.createEntity();
|
|
1339
|
+
await boxEntity.setComponent(customModel);
|
|
1340
|
+
boxEntity.transform.position.z = 0;
|
|
1341
|
+
boxEntity.transform.scale = new Vec3(0.5, 0.5, 0.5);
|
|
1342
|
+
await boxEntity.updateTransform();
|
|
1343
|
+
return boxEntity;
|
|
1344
|
+
},
|
|
1345
|
+
createModelEntity: async (url) => {
|
|
1346
|
+
var customModel = await this.session.createModelComponent({ url });
|
|
1347
|
+
var boxEntity = await this.session.createEntity();
|
|
1348
|
+
await boxEntity.setComponent(customModel);
|
|
1349
|
+
await boxEntity.updateTransform();
|
|
1350
|
+
return boxEntity;
|
|
1351
|
+
},
|
|
1352
|
+
wrapInBoundingBoxEntity: async (entityToWrap) => {
|
|
1353
|
+
var bb = await entityToWrap.getBoundingBox();
|
|
1354
|
+
var targetSize = 1;
|
|
1355
|
+
var scale = targetSize / Math.max(bb.extents.x, bb.extents.y, bb.extents.z);
|
|
1356
|
+
entityToWrap.transform.scale.x = scale;
|
|
1357
|
+
entityToWrap.transform.scale.y = scale;
|
|
1358
|
+
entityToWrap.transform.scale.z = scale;
|
|
1359
|
+
entityToWrap.transform.position.x = -bb.center.x * scale;
|
|
1360
|
+
entityToWrap.transform.position.y = -bb.center.y * scale;
|
|
1361
|
+
entityToWrap.transform.position.z = -bb.center.z * scale;
|
|
1362
|
+
await entityToWrap.updateTransform();
|
|
1363
|
+
var boudningEntity = await _SpatialHelper.instance?.session.createEntity();
|
|
1364
|
+
await entityToWrap.setParent(boudningEntity);
|
|
1365
|
+
return boudningEntity;
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
navigation = {
|
|
1369
|
+
openPanel: async (url, options) => {
|
|
1370
|
+
if (options?.resolution) {
|
|
1371
|
+
await this.session.getCurrentWindowContainer()._setOpenSettings({ resolution: options.resolution });
|
|
1372
|
+
}
|
|
1373
|
+
var wg = await this.session.createWindowContainer({
|
|
1374
|
+
style: "Plain",
|
|
1375
|
+
windowComponent: null,
|
|
1376
|
+
windowContainer: null
|
|
1377
|
+
});
|
|
1378
|
+
var ent = await this.session.createEntity({
|
|
1379
|
+
windowComponent: null,
|
|
1380
|
+
windowContainer: wg
|
|
1381
|
+
});
|
|
1382
|
+
var i = await this.session.createWindowComponent({
|
|
1383
|
+
windowComponent: null,
|
|
1384
|
+
windowContainer: wg
|
|
1385
|
+
});
|
|
1386
|
+
await i.loadURL(url);
|
|
1387
|
+
await ent.setCoordinateSpace("Root");
|
|
1388
|
+
await ent.setComponent(i);
|
|
1389
|
+
await wg.setRootEntity(ent);
|
|
1390
|
+
await this.session.getCurrentWindowContainer()._setOpenSettings({ resolution: { width: 900, height: 700 } });
|
|
1391
|
+
},
|
|
1392
|
+
openVolume: async (url, options) => {
|
|
1393
|
+
var wg = await this.session.createWindowContainer({
|
|
1394
|
+
style: "Volumetric",
|
|
1395
|
+
windowComponent: null,
|
|
1396
|
+
windowContainer: null
|
|
1397
|
+
});
|
|
1398
|
+
var rootEnt = await this.session.createEntity({
|
|
1399
|
+
windowComponent: null,
|
|
1400
|
+
windowContainer: wg
|
|
1401
|
+
});
|
|
1402
|
+
await rootEnt.setComponent(
|
|
1403
|
+
await this.session.createViewComponent({
|
|
1404
|
+
windowComponent: null,
|
|
1405
|
+
windowContainer: wg
|
|
1406
|
+
})
|
|
1407
|
+
);
|
|
1408
|
+
await rootEnt.setCoordinateSpace("Root");
|
|
1409
|
+
await wg.setRootEntity(rootEnt);
|
|
1410
|
+
var ent = await this.session.createEntity({
|
|
1411
|
+
windowComponent: null,
|
|
1412
|
+
windowContainer: wg
|
|
1413
|
+
});
|
|
1414
|
+
var i = await this.session.createWindowComponent({
|
|
1415
|
+
windowComponent: null,
|
|
1416
|
+
windowContainer: wg
|
|
1417
|
+
});
|
|
1418
|
+
await i.loadURL(url);
|
|
1419
|
+
if (options?.resolution) {
|
|
1420
|
+
await i.setResolution(
|
|
1421
|
+
options.resolution.width,
|
|
1422
|
+
options.resolution.height
|
|
1423
|
+
);
|
|
1424
|
+
} else {
|
|
1425
|
+
await i.setResolution(1e3, 1e3);
|
|
1426
|
+
}
|
|
1427
|
+
ent.transform.position.z = -0.49;
|
|
1428
|
+
await ent.updateTransform();
|
|
1429
|
+
await ent.setCoordinateSpace("App");
|
|
1430
|
+
await ent.setComponent(i);
|
|
1431
|
+
await ent.setParent(rootEnt);
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
dom = {
|
|
1435
|
+
attachSpatialView: async (divOnPage) => {
|
|
1436
|
+
var viewEnt = await this.session.createEntity();
|
|
1437
|
+
await viewEnt.setCoordinateSpace("Dom");
|
|
1438
|
+
await viewEnt.setComponent(await this.session.createViewComponent());
|
|
1439
|
+
var wc = await this.session.getCurrentWindowComponent();
|
|
1440
|
+
var ent = await wc.getEntity();
|
|
1441
|
+
await viewEnt.setParent(ent);
|
|
1442
|
+
var update = () => {
|
|
1443
|
+
var rect = divOnPage.getBoundingClientRect();
|
|
1444
|
+
viewEnt.transform.position.x = rect.x + rect.width / 2;
|
|
1445
|
+
viewEnt.transform.position.y = rect.y + rect.height / 2 + window.scrollY;
|
|
1446
|
+
viewEnt.updateTransform();
|
|
1447
|
+
viewEnt.getComponent(SpatialViewComponent).setResolution(rect.width, rect.height);
|
|
1448
|
+
};
|
|
1449
|
+
var mo = new MutationObserver(update);
|
|
1450
|
+
mo.observe(divOnPage, { attributes: true });
|
|
1451
|
+
var ro = new ResizeObserver(update);
|
|
1452
|
+
ro.observe(divOnPage);
|
|
1453
|
+
const addRemoveObserver = new MutationObserver((mutations) => {
|
|
1454
|
+
mutations.forEach((mutation) => {
|
|
1455
|
+
mutation.removedNodes.forEach((node) => {
|
|
1456
|
+
if (node instanceof HTMLElement) {
|
|
1457
|
+
update();
|
|
1458
|
+
}
|
|
1459
|
+
});
|
|
1460
|
+
mutation.addedNodes.forEach((node) => {
|
|
1461
|
+
if (node instanceof HTMLElement) {
|
|
1462
|
+
update();
|
|
1463
|
+
}
|
|
1464
|
+
});
|
|
1465
|
+
});
|
|
1466
|
+
});
|
|
1467
|
+
addRemoveObserver.observe(document.body, {
|
|
1468
|
+
childList: true,
|
|
1469
|
+
subtree: true
|
|
1470
|
+
});
|
|
1471
|
+
update();
|
|
1472
|
+
return {
|
|
1473
|
+
entity: viewEnt
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
setBackgroundStyle = async (style, backgroundColor = "#00000000") => {
|
|
1478
|
+
document.documentElement.style.backgroundColor = backgroundColor;
|
|
1479
|
+
await this.session.getCurrentWindowComponent().setStyle(style);
|
|
1480
|
+
};
|
|
1481
|
+
};
|
|
1482
|
+
export {
|
|
1483
|
+
Spatial,
|
|
1484
|
+
SpatialComponent,
|
|
1485
|
+
SpatialEntity,
|
|
1486
|
+
SpatialHelper,
|
|
1487
|
+
SpatialInputComponent,
|
|
1488
|
+
SpatialMeshResource,
|
|
1489
|
+
SpatialModel3DComponent,
|
|
1490
|
+
SpatialModelComponent,
|
|
1491
|
+
SpatialPhysicallyBasedMaterialResource,
|
|
1492
|
+
SpatialSession,
|
|
1493
|
+
SpatialTransform,
|
|
1494
|
+
SpatialViewComponent,
|
|
1495
|
+
SpatialWindowComponent,
|
|
1496
|
+
SpatialWindowContainer,
|
|
1497
|
+
Vec3,
|
|
1498
|
+
Vec4
|
|
1499
|
+
};
|
|
1500
|
+
//# sourceMappingURL=index.js.map
|