-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
88 lines (79 loc) · 2.41 KB
/
app.js
File metadata and controls
88 lines (79 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* /!\ This file is auto-generated.
*
* This is the entry point of your standalone application.
*
* There are multiple tags used by the editor to inject code automatically:
* - `wle:auto-constants:start` and `wle:auto-constants:end`: The project's constants,
* such as the project's name, whether it should use the physx runtime, etc...
* - `wle:auto-benchmark:start` and `wle:auto-benchmark:end`: Append the benchmarking code
*/
import {loadRuntime} from "@wonderlandengine/api";
/* wle:auto-constants:start */
const Constants = {
ProjectName: 'viversecli.wlp',
RuntimeBaseName: 'WonderlandRuntime',
WebXRRequiredFeatures: ['local',],
WebXROptionalFeatures: ['local','local-floor','hand-tracking','hit-test',],
};
const RuntimeOptions = {
webgl2: true,
webgpu: false,
physx: false,
loader: true,
xrFramebufferScaleFactor: 1,
loadUncompressedImagesAsBitmap: false,
xrOfferSession: {
mode: 'auto',
features: Constants.WebXRRequiredFeatures,
optionalFeatures: Constants.WebXROptionalFeatures,
},
canvas: 'canvas',
};
/* wle:auto-constants:end */
const engine = await loadRuntime(Constants.RuntimeBaseName, RuntimeOptions);
engine.onLoadingScreenEnd.once(() => {
const el = document.getElementById("version");
if (el) setTimeout(() => el.remove(), 2000);
});
/* WebXR setup. */
function requestSession(mode) {
engine
.requestXRSession(
mode,
Constants.WebXRRequiredFeatures,
Constants.WebXROptionalFeatures,
)
.catch((e) => console.error(e));
}
function setupButtonsXR() {
/* Setup AR / VR buttons */
const arButton = document.getElementById("ar-button");
if (arButton) {
arButton.setAttribute("data-supported", engine.arSupported.toString());
arButton.addEventListener("click", () =>
requestSession("immersive-ar"),
);
}
const vrButton = document.getElementById("vr-button");
if (vrButton) {
vrButton.setAttribute("data-supported", engine.vrSupported.toString());
vrButton.addEventListener("click", () =>
requestSession("immersive-vr"),
);
}
}
if (document.readyState === "loading") {
window.addEventListener("load", setupButtonsXR);
} else {
setupButtonsXR();
}
/* Load main scene */
try {
await engine.loadMainScene(`${Constants.ProjectName}.bin`);
} catch (e) {
console.error(e);
window.alert(`Failed to load ${Constants.ProjectName}.bin:`, e);
}
/* wle:auto-benchmark:start */
/* wle:auto-benchmark:end */