Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS_Orientation_for_WebAR #520

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AJ-AR-F1/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IOS OREANTATION ISSUE of WebAR
1. To resolve orientation issues in iOS, you can use the orientation property of the window object to get the current orientation of the device and apply appropriate transformations to your AR content.
2. For non-iOS devices, we can use the screen.orientation API to get the current orientation of the device.

40 changes: 40 additions & 0 deletions AJ-AR-F1/orientation_Ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Practise _ ANIKET APRAJ_
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

function getDeviceOrientation() {
if (isIOS) {
switch (window.orientation) {
case 0:
return "portrait";
case 90:
return "landscape-left";
case -90:
return "landscape-right";
case 180:
return "portrait-upside-down";
}
} else {

return screen.orientation.type.split("-")[0];
}
}

// add event listener to detect orientation changes
window.addEventListener("orientationchange", () => {
const orientation = getDeviceOrientation();

switch (orientation) {
case "portrait":
// apply portrait transformations
break;
case "landscape-left":
// apply landscape-left transformations
break;
case "landscape-right":
// apply landscape-right transformations
break;
case "portrait-upside-down":
// apply portrait-upside-down transformations
break;
}
});
3 changes: 2 additions & 1 deletion three.js/src/index-arjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Utils from "./new-api/arjs-utils";
import Context from "./threex/arjs-context";
import Profile from "./threex/arjs-profile";
import Source from "./threex/arjs-source";

import isIOS from "./threex/threejs-ios_Orientation"
export {
Anchor,
HitTesting,
Expand All @@ -17,4 +17,5 @@ export {
Context,
Profile,
Source,
isIOS,
};
2 changes: 1 addition & 1 deletion three.js/src/threex/arjs-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Profile = function () {

this.performance("default");
};

// using oreantation_ios code we can fix the ios oreantation issue in webAR
Profile.prototype._guessPerformanceLabel = function () {
var isMobile =
navigator.userAgent.match(/Android/i) ||
Expand Down
41 changes: 41 additions & 0 deletions three.js/src/threex/threejs-ios_Orientation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// check if device is iOS
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

function getDeviceOrientation() {
if (isIOS) {
switch (window.orientation) {
case 0:
return "portrait";
case 90:
return "landscape-left";
case -90:
return "landscape-right";
case 180:
return "portrait-upside-down";
}
} else {

return screen.orientation.type.split("-")[0];
}
}

window.addEventListener("orientationchange", () => {
// get current orientation
const orientation = getDeviceOrientation();

// apply transformations to AR content based on orientation
switch (orientation) {
case "portrait":
// apply portrait transformations
break;
case "landscape-left":
// apply landscape-left transformations
break;
case "landscape-right":
// apply landscape-right transformations
break;
case "portrait-upside-down":
// apply portrait-upside-down transformations
break;
}
});