-
Notifications
You must be signed in to change notification settings - Fork 119
/
fakeXrDisplay.js
62 lines (51 loc) · 1.71 KB
/
fakeXrDisplay.js
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
(() => {
window._makeFakeXrDisplay = () => {
const fakeXrDisplay = new FakeXRDisplay();
fakeXrDisplay.enable();
fakeXrDisplay.enter = async ({renderer, animate, layers}) => {
const {domElement: canvas} = renderer;
if (navigator.xr) {
const session = await navigator.xr.requestSession({
exclusive: true,
});
await new Promise((accept, reject) => {
session.requestAnimationFrame((timestamp, frame) => {
session.layers = layers;
renderer.vr.enabled = true;
renderer.vr.setSession(session, {
frameOfReferenceType: 'stage',
});
renderer.vr.setAnimationLoop(animate);
const {views} = frame.getViewerPose();
const viewport = session.renderState.baseLayer.getViewport(views[0]);
const height = viewport.height;
const fullWidth = (() => {
let result = 0;
for (let i = 0; i < views.length; i++) {
result += session.renderState.baseLayer.getViewport(views[i]).width;
}
return result;
})();
renderer.setSize(fullWidth, height);
accept();
});
});
} else {
const displays = await navigator.getVRDisplays();
const display = displays[0];
await display.requestPresent([
{
source: canvas,
},
]);
display.layers = layers;
renderer.vr.enabled = true;
renderer.vr.setDevice(display);
renderer.vr.setAnimationLoop(animate);
// const {renderWidth: width, renderHeight: height} = display.getEyeParameters('left');
// renderer.setSize(width * 2, height);
}
};
return fakeXrDisplay;
};
})();