diff --git a/AJ-AR-F1/Readme.md b/AJ-AR-F1/Readme.md new file mode 100644 index 00000000..d3af9400 --- /dev/null +++ b/AJ-AR-F1/Readme.md @@ -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. + diff --git a/AJ-AR-F1/orientation_Ios.js b/AJ-AR-F1/orientation_Ios.js new file mode 100644 index 00000000..8a9a1909 --- /dev/null +++ b/AJ-AR-F1/orientation_Ios.js @@ -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; + } +}); diff --git a/three.js/src/index-arjs.js b/three.js/src/index-arjs.js index 78730e24..c9ae70f5 100644 --- a/three.js/src/index-arjs.js +++ b/three.js/src/index-arjs.js @@ -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, @@ -17,4 +17,5 @@ export { Context, Profile, Source, + isIOS, }; diff --git a/three.js/src/threex/arjs-profile.js b/three.js/src/threex/arjs-profile.js index 6bec9666..76ad5460 100644 --- a/three.js/src/threex/arjs-profile.js +++ b/three.js/src/threex/arjs-profile.js @@ -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) || diff --git a/three.js/src/threex/threejs-ios_Orientation.js b/three.js/src/threex/threejs-ios_Orientation.js new file mode 100644 index 00000000..91fc06fc --- /dev/null +++ b/three.js/src/threex/threejs-ios_Orientation.js @@ -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; + } +});