Newer
Older
AegisforEcosystem / next / AR.js-3.4.0 / aframe / build / aframe-ar-new-location-only.js
@KAOKA Daisuke KAOKA Daisuke on 31 May 2022 5 KB into AR.js
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("aframe"),require("three")):"function"==typeof define&&define.amd?define(["aframe","three"],t):"object"==typeof exports?exports.ARjs=t(require("aframe"),require("three")):e.ARjs=t(e.AFRAME,e.THREE)}(this,(function(e,t){return(()=>{"use strict";var i={223:t=>{t.exports=e},381:e=>{e.exports=t}},s={};function o(e){var t=s[e];if(void 0!==t)return t.exports;var n=s[e]={exports:{}};return i[e](n,n.exports,o),n.exports}o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n);var e=o(223),t=o(381);e.registerComponent("arjs-webcam-texture",{init:function(){this.scene=this.el.sceneEl,this.texCamera=new t.OrthographicCamera(-.5,.5,.5,-.5,0,10),this.texScene=new t.Scene,this.scene.renderer.autoClear=!1,this.video=document.createElement("video"),this.video.setAttribute("autoplay",!0),this.video.setAttribute("playsinline",!0),this.video.setAttribute("display","none"),document.body.appendChild(this.video),this.geom=new t.PlaneBufferGeometry,this.texture=new t.VideoTexture(this.video),this.material=new t.MeshBasicMaterial({map:this.texture});const e=new t.Mesh(this.geom,this.material);this.texScene.add(e)},play:function(){if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const e={video:{facingMode:"environment"}};navigator.mediaDevices.getUserMedia(e).then((e=>{this.video.srcObject=e,this.video.play()})).catch((e=>{this.el.sceneEl.systems.arjs._displayErrorPopup(`Webcam error: ${e}`)}))}else this.el.sceneEl.systems.arjs._displayErrorPopup("sorry - media devices API not supported")},tick:function(){this.scene.renderer.clear(),this.scene.renderer.render(this.texScene,this.texCamera),this.scene.renderer.clearDepth()},pause:function(){this.video.srcObject.getTracks().forEach((e=>{e.stop()}))},remove:function(){this.material.dispose(),this.texture.dispose(),this.geom.dispose()}}),e.registerComponent("gps-new-camera",{schema:{simulateLatitude:{type:"number",default:0},simulateLongitude:{type:"number",default:0},simulateAltitude:{type:"number",default:-Number.MAX_VALUE},gpsMinDistance:{type:"number",default:0},positionMinAccuracy:{type:"number",default:1e3}},init:function(){this._testForOrientationControls(),this.threeLoc=new THREEx.LocationBased(this.el.sceneEl.object3D,this.el.object3D),this.threeLoc.on("gpsupdate",(e=>{this._sendGpsUpdateEvent(e.coords.longitude,e.coords.latitude)})),this.threeLoc.on("gpserror",(e=>{e>=1&&e<=3?this._displayError(["User denied access to GPS.","GPS satellites not available.","Timeout communicating with GPS satellites - try moving to a more open area."][e-1]):this._displayError(`Unknown geolocation error code ${e}.`)}));const e=this._isMobile();this.el.setAttribute("look-controls-enabled",!e),e&&this.el.setAttribute("arjs-device-orientation-controls",!0),navigator.userAgent.match(/Version\/[\d.]+.*Safari/)&&this._setupSafariOrientationPermissions()},update:function(e){this.threeLoc.setGpsOptions({gpsMinAccuracy:this.data.positionMinAccuracy,gpsMinDistance:this.data.gpsMinDistance}),0===this.data.simulateLatitude&&0===this.data.simulateLongitude||this.data.simulateLatitude==e.simulateLatitude&&this.data.simulateLongitude==e.simulateLongitude||(this.threeLoc.fakeGps(this.data.simulateLongitude,this.data.simulateLatitude),this.data.simulateLatitude=0,this.data.simulateLongitude=0),this.data.simulateAltitude>-Number.MAX_VALUE&&this.threeLoc.setElevation(this.data.simulateAltitude+1.6)},play:function(){0===this.data.simulateLatitude&&0===this.data.simulateLongitude&&this.threeLoc.startGps()},pause:function(){this.threeLoc.stopGps()},_sendGpsUpdateEvent:function(e,t){this.el.emit("gps-camera-update-position",{position:{longitude:e,latitude:t}})},_testForOrientationControls:function(){this.el.components["arjs-device-orientation-controls"]||this.el.components["look-controls"]||this._displayError("WARNING - No orientation controls component, app will not respond to device rotation.")},_displayError:function(e){const t=this.el.sceneEl.systems.arjs;t?t._displayErrorPopup(msg):alert(msg)},_setupSafariOrientationPermissions:function(){if("function"==typeof DeviceOrientationEvent.requestPermission){var e=function(){console.log("Requesting device orientation permissions..."),DeviceOrientationEvent.requestPermission(),document.removeEventListener("touchend",e)};document.addEventListener("touchend",(function(){e()}),!1),this.el.sceneEl.systems.arjs._displayErrorPopup("After camera permission prompt, please tap the screen to activate geolocation.")}else{var t=setTimeout((function(){this.el.sceneEl.systems.arjs._displayErrorPopup("Please enable device orientation in Settings > Safari > Motion & Orientation Access.")}),750);window.addEventListener(eventName,(function(){clearTimeout(t)}))}},_isMobile:function(){return!!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}}),e.registerComponent("gps-new-entity-place",{schema:{longitude:{type:"number",default:0},latitude:{type:"number",default:0}},init:function(){const e=document.querySelector("[gps-new-camera]");e.components["gps-new-camera"]?this._cameraGps=e.components["gps-new-camera"]:console.error("gps-new-camera not initialised")},update:function(){const e=this._cameraGps.threeLoc.lonLatToWorldCoords(this.data.longitude,this.data.latitude);this.el.object3D.position.set(e[0],this.el.object3D.position.y,e[1])}}),e.registerComponent("arjs-device-orientation-controls",{schema:{smoothingFactor:{type:"number",default:1}},init:function(){this._orientationControls=new THREEx.DeviceOrientationControls(this.el.object3D)},update:function(){this._orientationControls.smoothingFactor=this.data.smoothingFactor},tick:function(){this._orientationControls.update()}})})(),n})()}));