Skip to content

Commit 77a8da1

Browse files
committed
fix: can't enter VR session with WebXR
1 parent 652964b commit 77a8da1

File tree

5 files changed

+38
-32
lines changed

5 files changed

+38
-32
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,5 @@ report/
206206
temp/
207207
demo/_data/version.yml
208208
demo/release/
209-
209+
dist/
210210
declaration/

demo/common/js/PanoControls.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ var PanoControls = (function() {
2424
var pieView = new PieView(pieEl);
2525
panoViewer.on({
2626
"ready": function () {
27-
var yawRange = panoViewer.getYawRange();
28-
pieView.setState(panoViewer.getYaw(), panoViewer._getHFov(), yawRange[1] - yawRange[0]);
27+
var yawRange = panoViewer.getYawRange();
28+
var hfov = (180 / Math.PI) * (2 * Math.atan(panoViewer._aspectRatio * Math.tan(panoViewer.getFov() * Math.PI / 360)));
29+
pieView.setState(panoViewer.getYaw(), hfov, yawRange[1] - yawRange[0]);
2930
showLoading(false);
3031
},
3132
"viewChange": function (e) {
32-
var hfov = panoViewer._getHFov();
33-
pieView.setState(e.yaw, hfov);
34-
// console.log("viewChange");
33+
var hfov = (180 / Math.PI) * (2 * Math.atan(panoViewer._aspectRatio * Math.tan(panoViewer.getFov() * Math.PI / 360)));
34+
pieView.setState(e.yaw, hfov);
35+
// console.log("viewChange");
3536
}
3637
});
3738

@@ -49,7 +50,7 @@ var PanoControls = (function() {
4950
panoViewer.updateViewportDimensions();
5051

5152
var yaw = panoViewer.getYaw();
52-
var hfov = panoViewer._getHFov();
53+
var hfov = (180 / Math.PI) * (2 * Math.atan(panoViewer._aspectRatio * Math.tan(panoViewer.getFov() * Math.PI / 360)));
5354
pieView.setState(yaw, hfov);
5455
}));
5556

src/PanoImageRenderer/PanoImageRenderer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ class PanoImageRenderer extends Component<{
154154

155155
this.canvas = this._initCanvas(width, height);
156156

157-
this.canvas.getContext("webgl", )
158157
this._setDefaultCanvasStyle();
159158
this._wrapper = null; // canvas wrapper
160159
this._wrapperOrigStyle = null;

src/PanoImageRenderer/vr/XRManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ class XRManager {
9999
requiredFeatures: [XR_REFERENCE_SPACE],
100100
}, this._options);
101101

102+
const attributes = gl.getContextAttributes();
103+
if (attributes && (attributes as any).xrCompatible !== true) {
104+
(gl as any).makeXRCompatible();
105+
}
106+
102107
return (navigator as any).xr.requestSession("immersive-vr", options).then(session => {
103108
const xrLayer = new (window as any).XRWebGLLayer(session, gl);
104109

test/manual/PanoViewer/Panorama.html

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<script src="../../../node_modules/@egjs/axes/dist/axes.js"></script>
1313
<script src="../../../dist/view360.js"></script>
1414
<!-- <script src="../../../dist/PanoViewer/view360.panoviewer.pkgd.min.js"></script> -->
15-
15+
1616
<script src="../lib/jquery-3.3.1.min.js"></script>
1717
<script src="../lib/screenfull.js"></script>
1818
<script src="../lib/util.js"></script>
@@ -68,25 +68,26 @@ <h2>Select your panorama picture taken on smartphone</h2>
6868
}
6969
).on({
7070
"ready": function () {
71-
var yawRange = panoViewer.getYawRange();
72-
pieView.setState(panoViewer.getYaw(), panoViewer._getHFov(), yawRange[1] - yawRange[0]);
71+
var yawRange = panoViewer.getYawRange();
72+
var hfov = (180 / Math.PI) * (2 * Math.atan(panoViewer._aspectRatio * Math.tan(panoViewer.getFov() * Math.PI / 360)));
73+
pieView.setState(panoViewer.getYaw(), hfov, yawRange[1] - yawRange[0]);
7374
},
7475
"viewChange": function (e) {
75-
var hfov = panoViewer._getHFov();
76-
pieView.setState(e.yaw, hfov);
76+
var hfov = (180 / Math.PI) * (2 * Math.atan(panoViewer._aspectRatio * Math.tan(panoViewer.getFov() * Math.PI / 360)));
77+
pieView.setState(e.yaw, hfov);
7778
},
7879
"error": function(e) {
79-
console.error(e);
80+
console.error(e);
8081
}
8182
});
8283

8384
// resize handler
8485
window.addEventListener("resize", debounce(function() {
85-
panoViewer.updateViewportDimensions();
86-
87-
var yaw = panoViewer.getYaw();
88-
var hfov = panoViewer._getHFov();
89-
pieView.setState(yaw, hfov);
86+
panoViewer.updateViewportDimensions();
87+
88+
var yaw = panoViewer.getYaw();
89+
var hfov = (180 / Math.PI) * (2 * Math.atan(panoViewer._aspectRatio * Math.tan(panoViewer.getFov() * Math.PI / 360)));
90+
pieView.setState(yaw, hfov);
9091
}));
9192

9293
// create file input
@@ -97,10 +98,10 @@ <h2>Select your panorama picture taken on smartphone</h2>
9798

9899
// inject an image with the src url
99100
reader.onload = function (event) {
100-
the_url = event.target.result;
101+
the_url = event.target.result;
101102

102-
panoViewer.setImage(the_url, { projectionType: "panorama" });
103-
panoViewer.updateViewportDimensions();
103+
panoViewer.setImage(the_url, { projectionType: "panorama" });
104+
panoViewer.updateViewportDimensions();
104105
}
105106

106107
// when the file is read it triggers the onload event above.
@@ -116,16 +117,16 @@ <h2>Select your panorama picture taken on smartphone</h2>
116117
var requestFullscreen;
117118

118119
if (screenfull.enabled) {
119-
requestFullscreen = screenfull.isFullscreen;
120+
requestFullscreen = screenfull.isFullscreen;
120121
} else {
121-
requestFullscreen = mode === "full";
122+
requestFullscreen = mode === "full";
122123
}
123-
124+
124125
if (requestFullscreen) {
125-
fullscreenContainer.appendChild(rootNode);
126+
fullscreenContainer.appendChild(rootNode);
126127
fullscreenContainer.style.display = "block";
127128
} else {
128-
originalContainer.appendChild(rootNode);
129+
originalContainer.appendChild(rootNode);
129130
fullscreenContainer.style.display = "none";
130131
}
131132

@@ -137,21 +138,21 @@ <h2>Select your panorama picture taken on smartphone</h2>
137138

138139
document.querySelector(".enterfs").addEventListener("click", function() {
139140
if (screenfull.enabled) {
140-
screenfull.request();
141+
screenfull.request();
141142
} else {
142-
changeMode("full");
143+
changeMode("full");
143144
}
144145
});
145146

146147
document.querySelector(".exitfs").addEventListener("click", function() {
147148
if (screenfull.enabled) {
148-
screenfull.exit();
149+
screenfull.exit();
149150
} else {
150-
changeMode("orignal");
151+
changeMode("orignal");
151152
}
152153
});
153154
</script>
154155

155156
</body>
156157

157-
</html>
158+
</html>

0 commit comments

Comments
 (0)