Skip to content

Commit

Permalink
fix: PanoViewer is not working on iOS15
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodNeck authored Oct 12, 2021
1 parent 5769f82 commit 60a6d82
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ fabric.properties
_site/
.sass-cache/
.jekyll-metadata

cert.crt
cert.key

### SublimeText ###
# cache files for sublime text
Expand Down
40 changes: 20 additions & 20 deletions demo/common/js/PanoControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var PanoControls = (function() {

var vrButton = document.querySelector(".entervr")
vrButton && vrButton.addEventListener("click", function() {
panoViewer.enterVR().catch(e => {
panoViewer.enterVR().catch(function (e) {
Swal.fire({
title: "Can't enter VR mode!",
text: e.message || e,
Expand All @@ -115,7 +115,7 @@ var PanoControls = (function() {
});

// For iOS 13+
panoViewer.enableSensor().catch(() => {
panoViewer.enableSensor().catch(function () {
Swal.fire({
title: "Permission needed! (iOS13+)",
icon: "question",
Expand All @@ -124,10 +124,10 @@ var PanoControls = (function() {
reverseButtons: true,
confirmButtonText: "Allow",
cancelButtonText: "Deny"
}).then(result => {
}).then(function (result) {
if (result.value) {
// Granted
panoViewer.enableSensor().catch(() => {
panoViewer.enableSensor().catch(function () {
Swal.fire(
"You've denied a permission!",
"You have to completely close out your browser and reconnect this page to enable sensor again!",
Expand All @@ -140,7 +140,7 @@ var PanoControls = (function() {
});
});

const iOSVersion = (() => {
const iOSVersion = (function () {
if (/iP(hone|od|ad)/.test(navigator.platform)) {
// supports iOS 2.0 and later: <http://bit.ly/TJjs1V>
var v = navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
Expand All @@ -150,26 +150,26 @@ var PanoControls = (function() {

// For iOS 12.2 ~ 13
if (iOSVersion && iOSVersion[0] === 12 && iOSVersion[1] >= 2) {
PanoViewer.isGyroSensorAvailable(available => {
PanoViewer.isGyroSensorAvailable(function (available) {
if (!available) {
Swal.fire({
title: "Please enable the Motion Sensor! (iOS12.2~13)",
icon: "warning",
text: "This website requires a permission for your device motion sensor for the immersive experience.",
html: `
<div style="text-align: left;">
<div>
1. Open <img src="https://developer.apple.com/design/human-interface-guidelines/ios/images/icons/app_icons/Settings_2x.png" width="20" /> <b>Settings</b>
</div>
<div>
2. Select <img src="https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM26/en_US/safari-240.png" width="20" /> <b>Safari</b>
</div>
<div>
3. Enable <b>Motion & Orientation Access</b>
</div>
<div>4. Reload the page</div>
</div>
`
html: "\
<div style=\"text-align: left;\">\
<div>\
1. Open <img src=\"https://developer.apple.com/design/human-interface-guidelines/ios/images/icons/app_icons/Settings_2x.png\" width=\"20\" /> <b>Settings</b>\
</div>\
<div>\
2. Select <img src=\"https://km.support.apple.com/resources/sites/APPLE/content/live/IMAGES/0/IM26/en_US/safari-240.png\" width=\"20\" /> <b>Safari</b>\
</div>\
<div>\
3. Enable <b>Motion & Orientation Access</b>\
</div>\
<div>4. Reload the page</div>\
</div>\
"
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion demo/examples/panoviewer/etc/hotspot.html
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ <h2>Drag and rotate the photo. An anchor will follow.</h2>
});
}).on("viewChange", function (e) {
setHotspotOffsets(viewer);
}).on("error", e => {
}).on("error", function (e) {
console.error(e);
});

Expand Down
1 change: 0 additions & 1 deletion src/PanoImageRenderer/WebGLUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export default class WebGLUtils {
...{
preserveDrawingBuffer: false,
antialias: false,
xrCompatible: true,
}, ...userContextAttributes
};

Expand Down
4 changes: 2 additions & 2 deletions src/PanoImageRenderer/renderer/CubeRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ void main(void) {
const SHRINK_MULTIPLIER = 1 - trim * (2 / inputTextureSize);

const axisMultipliers = [0, 1, 2].map(axisIndex => {
const axisDir = Math.sign(faceCoords[0][axisIndex]);
const notSameDir = faceCoords.some(coord => Math.sign(coord[axisIndex]) !== axisDir);
const axisDir = mathUtil.sign(faceCoords[0][axisIndex]);
const notSameDir = faceCoords.some(coord => mathUtil.sign(coord[axisIndex]) !== axisDir);

return notSameDir;
}).map(notSameDir => notSameDir ? SHRINK_MULTIPLIER : 1);
Expand Down
4 changes: 2 additions & 2 deletions src/PanoImageRenderer/vr/XRManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ class XRManager {
this._xrSession?.removeEventListener("end", callback);
}

public requestPresent(canvas: HTMLCanvasElement, gl: WebGLRenderingContext) {
public async requestPresent(canvas: HTMLCanvasElement, gl: WebGLRenderingContext) {
const options = merge({
requiredFeatures: [XR_REFERENCE_SPACE],
}, this._options);

const attributes = gl.getContextAttributes();
if (attributes && (attributes as any).xrCompatible !== true) {
(gl as any).makeXRCompatible();
await (gl as any).makeXRCompatible();
}

return (navigator as any).xr.requestSession("immersive-vr", options).then(session => {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/math-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ util.yawOffsetBetween = (viewDir: number, targetDir: number) => {
return theta;
}

util.sign = (x: number) => Math.sign
? Math.sign(x)
: (Number(x > 0) - Number(x < 0)) || +x;

util.toDegree = toDegree;
util.getRotationDelta = getRotationDelta;
util.angleBetweenVec2 = angleBetweenVec2;
Expand Down

0 comments on commit 60a6d82

Please sign in to comment.