@ma2yama/ar.js 3.4.9-beta.2 → 3.4.9-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ export class WebcamRenderer {
|
|
|
10
10
|
export class DeviceOrientationControls extends EventDispatcher {
|
|
11
11
|
constructor(object: Object3D);
|
|
12
12
|
enabled: boolean;
|
|
13
|
-
deviceOrientation: { alpha: number; beta: number; gamma: number; webkitCompassHeading?: number } | null;
|
|
13
|
+
deviceOrientation: { alpha: number; beta: number; gamma: number; webkitCompassHeading?: number; webkitCompassAccuracy?: number } | null;
|
|
14
14
|
screenOrientation: number;
|
|
15
15
|
alphaOffset: number;
|
|
16
16
|
initialOffset: boolean | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("three")):"function"==typeof define&&define.amd?define(["three"],e):"object"==typeof exports?exports.THREEx=e(require("three")):t.THREEx=e(t.THREE)}(this,(t=>(()=>{"use strict";var e={818:e=>{e.exports=t}},i={};function
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("three")):"function"==typeof define&&define.amd?define(["three"],e):"object"==typeof exports?exports.THREEx=e(require("three")):t.THREEx=e(t.THREE)}(this,(t=>(()=>{"use strict";var e={818:e=>{e.exports=t}},i={};function o(t){var n=i[t];if(void 0!==n)return n.exports;var s=i[t]={exports:{}};return e[t](s,s.exports,o),s.exports}o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};o.r(n),o.d(n,{DeviceOrientationControls:()=>m,LocationBased:()=>r,WebcamRenderer:()=>h});class s{constructor(){this.EARTH=40075016.68,this.HALF_EARTH=20037508.34}project(t,e){return[this.lonToSphMerc(t),this.latToSphMerc(e)]}unproject(t){return[this.sphMercToLon(t[0]),this.sphMercToLat(t[1])]}lonToSphMerc(t){return t/180*this.HALF_EARTH}latToSphMerc(t){return Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180)*this.HALF_EARTH/180}sphMercToLon(t){return t/this.HALF_EARTH*180}sphMercToLat(t){var e=t/this.HALF_EARTH*180;return 180/Math.PI*(2*Math.atan(Math.exp(e*Math.PI/180))-Math.PI/2)}getID(){return"epsg:3857"}}var a=o(818);class r{constructor(t,e,i={}){this._scene=t,this._camera=e,this._proj=new s,this._eventHandlers={},this._lastCoords=null,this._gpsMinDistance=0,this._gpsMinAccuracy=100,this._maximumAge=0,this._watchPositionId=null,this.setGpsOptions(i),this.initialPosition=null!=i.initialPosition?this._proj.project(i.initialPosition.longitude,i.initialPosition.latitude):null,this.initialPositionAsOrigin=null!=i.initialPosition||i.initialPositionAsOrigin||!1,this.useAltitude=i.useAltitude||!1,this.altitudeOffset=i.altitudeOffset||0}setProjection(t){this._proj=t}setGpsOptions(t={}){void 0!==t.gpsMinDistance&&(this._gpsMinDistance=t.gpsMinDistance),void 0!==t.gpsMinAccuracy&&(this._gpsMinAccuracy=t.gpsMinAccuracy),void 0!==t.maximumAge&&(this._maximumAge=t.maximumAge)}startGps(t=0){return null===this._watchPositionId&&(this._watchPositionId=navigator.geolocation.watchPosition((t=>{this._gpsReceived(t)}),(t=>{this._eventHandlers.gpserror?this._eventHandlers.gpserror(t.code):alert(`GPS error: code ${t.code}`)}),{enableHighAccuracy:!0,maximumAge:0!=t?t:this._maximumAge}),!0)}stopGps(){return null!==this._watchPositionId&&(navigator.geolocation.clearWatch(this._watchPositionId),this._watchPositionId=null,!0)}fakeGps(t,e,i=null,o=0){null!==i&&this.setElevation(i),this._gpsReceived({coords:{longitude:t,latitude:e,accuracy:o}})}lonLatToWorldCoords(t,e){const i=this._proj.project(t,e);if(this.initialPositionAsOrigin){if(!this.initialPosition)throw"Trying to use 'initial position as origin' mode with no initial position determined";i[0]-=this.initialPosition[0],i[1]-=this.initialPosition[1]}return[i[0],-i[1]]}add(t,e,i,o){this.setWorldPosition(t,e,i,o),this._scene.add(t)}setWorldPosition(t,e,i,o){const n=this.lonLatToWorldCoords(e,i);void 0!==o&&(t.position.y=o),[t.position.x,t.position.z]=n}setElevation(t){this._camera.position.y=t}on(t,e){this._eventHandlers[t]=e}setWorldOrigin(t,e){this.initialPosition=this._proj.project(t,e)}_gpsReceived(t){let e=Number.MAX_VALUE;t.coords.accuracy<=this._gpsMinAccuracy&&(null===this._lastCoords?this._lastCoords={latitude:t.coords.latitude,longitude:t.coords.longitude}:e=this._haversineDist(this._lastCoords,t.coords),e>=this._gpsMinDistance&&(this._lastCoords.longitude=t.coords.longitude,this._lastCoords.latitude=t.coords.latitude,this.initialPositionAsOrigin&&!this.initialPosition&&this.setWorldOrigin(t.coords.longitude,t.coords.latitude),this.setWorldPosition(this._camera,t.coords.longitude,t.coords.latitude,this.useAltitude&&null!=t.coords.altitude?t.coords.altitude+this.altitudeOffset:void 0),this._eventHandlers.gpsupdate&&this._eventHandlers.gpsupdate(t,e)))}_haversineDist(t,e){const i=a.MathUtils.degToRad(e.longitude-t.longitude),o=a.MathUtils.degToRad(e.latitude-t.latitude),n=Math.sin(o/2)*Math.sin(o/2)+Math.cos(a.MathUtils.degToRad(t.latitude))*Math.cos(a.MathUtils.degToRad(e.latitude))*(Math.sin(i/2)*Math.sin(i/2));return 2*Math.atan2(Math.sqrt(n),Math.sqrt(1-n))*6371e3}}class h{constructor(t,e){let i;this.renderer=t,this.renderer.autoClear=!1,this.sceneWebcam=new a.Scene,"string"==typeof e?i=document.querySelector(e):e instanceof HTMLVideoElement&&(i=e),void 0===i&&(i=document.createElement("video"),i.setAttribute("autoplay",!0),i.setAttribute("playsinline",!0),i.style.display="none",document.body.appendChild(i)),this.geom=new a.PlaneGeometry,this.texture=new a.VideoTexture(i),this.material=new a.MeshBasicMaterial({map:this.texture});const o=new a.Mesh(this.geom,this.material);if(this.sceneWebcam.add(o),this.cameraWebcam=new a.OrthographicCamera(-.5,.5,.5,-.5,0,10),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const t={video:{width:1280,height:720,facingMode:"environment"}};navigator.mediaDevices.getUserMedia(t).then((t=>{console.log("using the webcam successfully..."),i.srcObject=t,i.play()})).catch((t=>{setTimeout((()=>{this.createErrorPopup("Webcam Error\nName: "+t.name+"\nMessage: "+t.message)}),1e3)}))}else setTimeout((()=>{this.createErrorPopup("sorry - media devices API not supported")}),1e3)}update(){this.renderer.clear(),this.renderer.render(this.sceneWebcam,this.cameraWebcam),this.renderer.clearDepth()}dispose(){this.material.dispose(),this.texture.dispose(),this.geom.dispose()}createErrorPopup(t){if(!document.getElementById("error-popup")){var e=document.createElement("div");e.innerHTML=t,e.setAttribute("id","error-popup"),document.body.appendChild(e)}}}const c=navigator.userAgent.match(/iPhone|iPad|iPod/i)||/Macintosh/i.test(navigator.userAgent)&&null!=navigator.maxTouchPoints&&navigator.maxTouchPoints>1,d=new a.Vector3(0,0,1),l=new a.Euler,u=new a.Quaternion,p=new a.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),g={type:"change"};class m extends a.EventDispatcher{constructor(t){super(),!1===window.isSecureContext&&console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");const e=this,i=new a.Quaternion;this.object=t,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation=null,this.screenOrientation=0,this.alphaOffset=0,this.initialOffset=null,this.TWO_PI=2*Math.PI,this.HALF_PI=.5*Math.PI,this.orientationChangeEventName="ondeviceorientationabsolute"in window?"deviceorientationabsolute":"deviceorientation",this.smoothingFactor=1;const o=function({alpha:i,beta:o,gamma:n,webkitCompassHeading:s,webkitCompassAccuracy:r}){if(c){const t=360-s;e.alphaOffset=a.MathUtils.degToRad(t-i),e.deviceOrientation={alpha:i,beta:o,gamma:n,webkitCompassHeading:s,webkitCompassAccuracy:r}}else i<0&&(i+=360),e.deviceOrientation={alpha:i,beta:o,gamma:n};window.dispatchEvent(new CustomEvent("camera-rotation-change",{detail:{cameraRotation:t.rotation}}))},n=function(){e.screenOrientation=window.orientation||0},s=function(t,e,i,o,n){l.set(i,e,-o,"YXZ"),t.setFromEuler(l),t.multiply(p),t.multiply(u.setFromAxisAngle(d,-n))};this.connect=function(){n(),void 0!==window.DeviceOrientationEvent&&"function"==typeof window.DeviceOrientationEvent.requestPermission?window.DeviceOrientationEvent.requestPermission().then((t=>{"granted"===t&&(window.addEventListener("orientationchange",n),window.addEventListener(e.orientationChangeEventName,o))})).catch((function(t){console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",t)})):(window.addEventListener("orientationchange",n),window.addEventListener(e.orientationChangeEventName,o)),e.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",n),window.removeEventListener(e.orientationChangeEventName,o),e.enabled=!1,e.initialOffset=!1,e.deviceOrientation=null},this.update=function({theta:t=0}={theta:0}){if(!1===e.enabled)return;const o=e.deviceOrientation;if(o){let n=o.alpha?a.MathUtils.degToRad(o.alpha)+e.alphaOffset:0,r=o.beta?a.MathUtils.degToRad(o.beta):0,h=o.gamma?a.MathUtils.degToRad(o.gamma):0;const d=e.screenOrientation?a.MathUtils.degToRad(e.screenOrientation):0;if(c){const t=new a.Quaternion;s(t,n,r,h,d);const i=(new a.Euler).setFromQuaternion(t,"YXZ");i.y=a.MathUtils.degToRad(360-o.webkitCompassHeading),t.setFromEuler(i),e.object.quaternion.copy(t)}else{if(this.smoothingFactor<1){if(this.lastOrientation){const t=this.smoothingFactor;n=this._getSmoothedAngle(n,this.lastOrientation.alpha,t),r=this._getSmoothedAngle(r+Math.PI,this.lastOrientation.beta,t),h=this._getSmoothedAngle(h+this.HALF_PI,this.lastOrientation.gamma,t,Math.PI)}else r+=Math.PI,h+=this.HALF_PI;this.lastOrientation={alpha:n,beta:r,gamma:h}}s(e.object.quaternion,n+t,this.smoothingFactor<1?r-Math.PI:r,this.smoothingFactor<1?h-this.HALF_PI:h,d)}8*(1-i.dot(e.object.quaternion))>1e-6&&(i.copy(e.object.quaternion),e.dispatchEvent(g))}},this._orderAngle=function(t,e,i=this.TWO_PI){return e>t&&Math.abs(e-t)<i/2||t>e&&Math.abs(e-t)>i/2?{left:t,right:e}:{left:e,right:t}},this._getSmoothedAngle=function(t,e,i,o=this.TWO_PI){const n=this._orderAngle(t,e,o),s=n.left,a=n.right;n.left=0,n.right-=s,n.right<0&&(n.right+=o);let r=a==e?(1-i)*n.right+i*n.left:i*n.right+(1-i)*n.left;return r+=s,r>=o&&(r-=o),r},this.updateAlphaOffset=function(){e.initialOffset=!1},this.dispose=function(){e.disconnect()},this.getAlpha=function(){const{deviceOrientation:t}=e;return t&&t.alpha?a.MathUtils.degToRad(t.alpha)+e.alphaOffset:0},this.getBeta=function(){const{deviceOrientation:t}=e;return t&&t.beta?a.MathUtils.degToRad(t.beta):0},this.connect()}}return n})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as t from"three";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},i={};e.d(i,{nX:()=>m,n$:()=>r,hX:()=>h});class n{constructor(){this.EARTH=40075016.68,this.HALF_EARTH=20037508.34}project(t,e){return[this.lonToSphMerc(t),this.latToSphMerc(e)]}unproject(t){return[this.sphMercToLon(t[0]),this.sphMercToLat(t[1])]}lonToSphMerc(t){return t/180*this.HALF_EARTH}latToSphMerc(t){return Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180)*this.HALF_EARTH/180}sphMercToLon(t){return t/this.HALF_EARTH*180}sphMercToLat(t){var e=t/this.HALF_EARTH*180;return 180/Math.PI*(2*Math.atan(Math.exp(e*Math.PI/180))-Math.PI/2)}getID(){return"epsg:3857"}}const o=(s={Euler:()=>t.Euler,EventDispatcher:()=>t.EventDispatcher,MathUtils:()=>t.MathUtils,Mesh:()=>t.Mesh,MeshBasicMaterial:()=>t.MeshBasicMaterial,OrthographicCamera:()=>t.OrthographicCamera,PlaneGeometry:()=>t.PlaneGeometry,Quaternion:()=>t.Quaternion,Scene:()=>t.Scene,Vector3:()=>t.Vector3,VideoTexture:()=>t.VideoTexture},a={},e.d(a,s),a);var s,a;class r{constructor(t,e,i={}){this._scene=t,this._camera=e,this._proj=new n,this._eventHandlers={},this._lastCoords=null,this._gpsMinDistance=0,this._gpsMinAccuracy=100,this._maximumAge=0,this._watchPositionId=null,this.setGpsOptions(i),this.initialPosition=null!=i.initialPosition?this._proj.project(i.initialPosition.longitude,i.initialPosition.latitude):null,this.initialPositionAsOrigin=null!=i.initialPosition||i.initialPositionAsOrigin||!1,this.useAltitude=i.useAltitude||!1,this.altitudeOffset=i.altitudeOffset||0}setProjection(t){this._proj=t}setGpsOptions(t={}){void 0!==t.gpsMinDistance&&(this._gpsMinDistance=t.gpsMinDistance),void 0!==t.gpsMinAccuracy&&(this._gpsMinAccuracy=t.gpsMinAccuracy),void 0!==t.maximumAge&&(this._maximumAge=t.maximumAge)}startGps(t=0){return null===this._watchPositionId&&(this._watchPositionId=navigator.geolocation.watchPosition((t=>{this._gpsReceived(t)}),(t=>{this._eventHandlers.gpserror?this._eventHandlers.gpserror(t.code):alert(`GPS error: code ${t.code}`)}),{enableHighAccuracy:!0,maximumAge:0!=t?t:this._maximumAge}),!0)}stopGps(){return null!==this._watchPositionId&&(navigator.geolocation.clearWatch(this._watchPositionId),this._watchPositionId=null,!0)}fakeGps(t,e,i=null,n=0){null!==i&&this.setElevation(i),this._gpsReceived({coords:{longitude:t,latitude:e,accuracy:n}})}lonLatToWorldCoords(t,e){const i=this._proj.project(t,e);if(this.initialPositionAsOrigin){if(!this.initialPosition)throw"Trying to use 'initial position as origin' mode with no initial position determined";i[0]-=this.initialPosition[0],i[1]-=this.initialPosition[1]}return[i[0],-i[1]]}add(t,e,i,n){this.setWorldPosition(t,e,i,n),this._scene.add(t)}setWorldPosition(t,e,i,n){const o=this.lonLatToWorldCoords(e,i);void 0!==n&&(t.position.y=n),[t.position.x,t.position.z]=o}setElevation(t){this._camera.position.y=t}on(t,e){this._eventHandlers[t]=e}setWorldOrigin(t,e){this.initialPosition=this._proj.project(t,e)}_gpsReceived(t){let e=Number.MAX_VALUE;t.coords.accuracy<=this._gpsMinAccuracy&&(null===this._lastCoords?this._lastCoords={latitude:t.coords.latitude,longitude:t.coords.longitude}:e=this._haversineDist(this._lastCoords,t.coords),e>=this._gpsMinDistance&&(this._lastCoords.longitude=t.coords.longitude,this._lastCoords.latitude=t.coords.latitude,this.initialPositionAsOrigin&&!this.initialPosition&&this.setWorldOrigin(t.coords.longitude,t.coords.latitude),this.setWorldPosition(this._camera,t.coords.longitude,t.coords.latitude,this.useAltitude&&null!=t.coords.altitude?t.coords.altitude+this.altitudeOffset:void 0),this._eventHandlers.gpsupdate&&this._eventHandlers.gpsupdate(t,e)))}_haversineDist(t,e){const i=o.MathUtils.degToRad(e.longitude-t.longitude),n=o.MathUtils.degToRad(e.latitude-t.latitude),s=Math.sin(n/2)*Math.sin(n/2)+Math.cos(o.MathUtils.degToRad(t.latitude))*Math.cos(o.MathUtils.degToRad(e.latitude))*(Math.sin(i/2)*Math.sin(i/2));return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}}class h{constructor(t,e){let i;this.renderer=t,this.renderer.autoClear=!1,this.sceneWebcam=new o.Scene,"string"==typeof e?i=document.querySelector(e):e instanceof HTMLVideoElement&&(i=e),void 0===i&&(i=document.createElement("video"),i.setAttribute("autoplay",!0),i.setAttribute("playsinline",!0),i.style.display="none",document.body.appendChild(i)),this.geom=new o.PlaneGeometry,this.texture=new o.VideoTexture(i),this.material=new o.MeshBasicMaterial({map:this.texture});const n=new o.Mesh(this.geom,this.material);if(this.sceneWebcam.add(n),this.cameraWebcam=new o.OrthographicCamera(-.5,.5,.5,-.5,0,10),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const t={video:{width:1280,height:720,facingMode:"environment"}};navigator.mediaDevices.getUserMedia(t).then((t=>{console.log("using the webcam successfully..."),i.srcObject=t,i.play()})).catch((t=>{setTimeout((()=>{this.createErrorPopup("Webcam Error\nName: "+t.name+"\nMessage: "+t.message)}),1e3)}))}else setTimeout((()=>{this.createErrorPopup("sorry - media devices API not supported")}),1e3)}update(){this.renderer.clear(),this.renderer.render(this.sceneWebcam,this.cameraWebcam),this.renderer.clearDepth()}dispose(){this.material.dispose(),this.texture.dispose(),this.geom.dispose()}createErrorPopup(t){if(!document.getElementById("error-popup")){var e=document.createElement("div");e.innerHTML=t,e.setAttribute("id","error-popup"),document.body.appendChild(e)}}}const c=navigator.userAgent.match(/iPhone|iPad|iPod/i)||/Macintosh/i.test(navigator.userAgent)&&null!=navigator.maxTouchPoints&&navigator.maxTouchPoints>1,l=new o.Vector3(0,0,1),d=new o.Euler,u=new o.Quaternion,g=new o.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),p={type:"change"};class m extends o.EventDispatcher{constructor(t){super(),!1===window.isSecureContext&&console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");const e=this,i=new o.Quaternion;this.object=t,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation=null,this.screenOrientation=0,this.alphaOffset=0,this.initialOffset=null,this.TWO_PI=2*Math.PI,this.HALF_PI=.5*Math.PI,this.orientationChangeEventName="ondeviceorientationabsolute"in window?"deviceorientationabsolute":"deviceorientation",this.smoothingFactor=1;const n=function({alpha:i,beta:n,gamma:s,webkitCompassHeading:a}){if(c){const t=360-a;e.alphaOffset=o.MathUtils.degToRad(t-i),e.deviceOrientation={alpha:i,beta:n,gamma:s,webkitCompassHeading:a}}else i<0&&(i+=360),e.deviceOrientation={alpha:i,beta:n,gamma:s};window.dispatchEvent(new CustomEvent("camera-rotation-change",{detail:{cameraRotation:t.rotation}}))},s=function(){e.screenOrientation=window.orientation||0},a=function(t,e,i,n,o){d.set(i,e,-n,"YXZ"),t.setFromEuler(d),t.multiply(g),t.multiply(u.setFromAxisAngle(l,-o))};this.connect=function(){s(),void 0!==window.DeviceOrientationEvent&&"function"==typeof window.DeviceOrientationEvent.requestPermission?window.DeviceOrientationEvent.requestPermission().then((t=>{"granted"===t&&(window.addEventListener("orientationchange",s),window.addEventListener(e.orientationChangeEventName,n))})).catch((function(t){console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",t)})):(window.addEventListener("orientationchange",s),window.addEventListener(e.orientationChangeEventName,n)),e.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",s),window.removeEventListener(e.orientationChangeEventName,n),e.enabled=!1,e.initialOffset=!1,e.deviceOrientation=null},this.update=function({theta:t=0}={theta:0}){if(!1===e.enabled)return;const n=e.deviceOrientation;if(n){let s=n.alpha?o.MathUtils.degToRad(n.alpha)+e.alphaOffset:0,r=n.beta?o.MathUtils.degToRad(n.beta):0,h=n.gamma?o.MathUtils.degToRad(n.gamma):0;const l=e.screenOrientation?o.MathUtils.degToRad(e.screenOrientation):0;if(c){const t=new o.Quaternion;a(t,s,r,h,l);const i=(new o.Euler).setFromQuaternion(t,"YXZ");i.y=o.MathUtils.degToRad(360-n.webkitCompassHeading),t.setFromEuler(i),e.object.quaternion.copy(t)}else{if(this.smoothingFactor<1){if(this.lastOrientation){const t=this.smoothingFactor;s=this._getSmoothedAngle(s,this.lastOrientation.alpha,t),r=this._getSmoothedAngle(r+Math.PI,this.lastOrientation.beta,t),h=this._getSmoothedAngle(h+this.HALF_PI,this.lastOrientation.gamma,t,Math.PI)}else r+=Math.PI,h+=this.HALF_PI;this.lastOrientation={alpha:s,beta:r,gamma:h}}a(e.object.quaternion,s+t,this.smoothingFactor<1?r-Math.PI:r,this.smoothingFactor<1?h-this.HALF_PI:h,l)}8*(1-i.dot(e.object.quaternion))>1e-6&&(i.copy(e.object.quaternion),e.dispatchEvent(p))}},this._orderAngle=function(t,e,i=this.TWO_PI){return e>t&&Math.abs(e-t)<i/2||t>e&&Math.abs(e-t)>i/2?{left:t,right:e}:{left:e,right:t}},this._getSmoothedAngle=function(t,e,i,n=this.TWO_PI){const o=this._orderAngle(t,e,n),s=o.left,a=o.right;o.left=0,o.right-=s,o.right<0&&(o.right+=n);let r=a==e?(1-i)*o.right+i*o.left:i*o.right+(1-i)*o.left;return r+=s,r>=n&&(r-=n),r},this.updateAlphaOffset=function(){e.initialOffset=!1},this.dispose=function(){e.disconnect()},this.getAlpha=function(){const{deviceOrientation:t}=e;return t&&t.alpha?o.MathUtils.degToRad(t.alpha)+e.alphaOffset:0},this.getBeta=function(){const{deviceOrientation:t}=e;return t&&t.beta?o.MathUtils.degToRad(t.beta):0},this.connect()}}var v=i.nX,M=i.n$,f=i.hX;export{v as DeviceOrientationControls,M as LocationBased,f as WebcamRenderer};
|
|
1
|
+
import*as t from"three";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},i={};e.d(i,{nX:()=>m,n$:()=>r,hX:()=>h});class n{constructor(){this.EARTH=40075016.68,this.HALF_EARTH=20037508.34}project(t,e){return[this.lonToSphMerc(t),this.latToSphMerc(e)]}unproject(t){return[this.sphMercToLon(t[0]),this.sphMercToLat(t[1])]}lonToSphMerc(t){return t/180*this.HALF_EARTH}latToSphMerc(t){return Math.log(Math.tan((90+t)*Math.PI/360))/(Math.PI/180)*this.HALF_EARTH/180}sphMercToLon(t){return t/this.HALF_EARTH*180}sphMercToLat(t){var e=t/this.HALF_EARTH*180;return 180/Math.PI*(2*Math.atan(Math.exp(e*Math.PI/180))-Math.PI/2)}getID(){return"epsg:3857"}}const o=(s={Euler:()=>t.Euler,EventDispatcher:()=>t.EventDispatcher,MathUtils:()=>t.MathUtils,Mesh:()=>t.Mesh,MeshBasicMaterial:()=>t.MeshBasicMaterial,OrthographicCamera:()=>t.OrthographicCamera,PlaneGeometry:()=>t.PlaneGeometry,Quaternion:()=>t.Quaternion,Scene:()=>t.Scene,Vector3:()=>t.Vector3,VideoTexture:()=>t.VideoTexture},a={},e.d(a,s),a);var s,a;class r{constructor(t,e,i={}){this._scene=t,this._camera=e,this._proj=new n,this._eventHandlers={},this._lastCoords=null,this._gpsMinDistance=0,this._gpsMinAccuracy=100,this._maximumAge=0,this._watchPositionId=null,this.setGpsOptions(i),this.initialPosition=null!=i.initialPosition?this._proj.project(i.initialPosition.longitude,i.initialPosition.latitude):null,this.initialPositionAsOrigin=null!=i.initialPosition||i.initialPositionAsOrigin||!1,this.useAltitude=i.useAltitude||!1,this.altitudeOffset=i.altitudeOffset||0}setProjection(t){this._proj=t}setGpsOptions(t={}){void 0!==t.gpsMinDistance&&(this._gpsMinDistance=t.gpsMinDistance),void 0!==t.gpsMinAccuracy&&(this._gpsMinAccuracy=t.gpsMinAccuracy),void 0!==t.maximumAge&&(this._maximumAge=t.maximumAge)}startGps(t=0){return null===this._watchPositionId&&(this._watchPositionId=navigator.geolocation.watchPosition((t=>{this._gpsReceived(t)}),(t=>{this._eventHandlers.gpserror?this._eventHandlers.gpserror(t.code):alert(`GPS error: code ${t.code}`)}),{enableHighAccuracy:!0,maximumAge:0!=t?t:this._maximumAge}),!0)}stopGps(){return null!==this._watchPositionId&&(navigator.geolocation.clearWatch(this._watchPositionId),this._watchPositionId=null,!0)}fakeGps(t,e,i=null,n=0){null!==i&&this.setElevation(i),this._gpsReceived({coords:{longitude:t,latitude:e,accuracy:n}})}lonLatToWorldCoords(t,e){const i=this._proj.project(t,e);if(this.initialPositionAsOrigin){if(!this.initialPosition)throw"Trying to use 'initial position as origin' mode with no initial position determined";i[0]-=this.initialPosition[0],i[1]-=this.initialPosition[1]}return[i[0],-i[1]]}add(t,e,i,n){this.setWorldPosition(t,e,i,n),this._scene.add(t)}setWorldPosition(t,e,i,n){const o=this.lonLatToWorldCoords(e,i);void 0!==n&&(t.position.y=n),[t.position.x,t.position.z]=o}setElevation(t){this._camera.position.y=t}on(t,e){this._eventHandlers[t]=e}setWorldOrigin(t,e){this.initialPosition=this._proj.project(t,e)}_gpsReceived(t){let e=Number.MAX_VALUE;t.coords.accuracy<=this._gpsMinAccuracy&&(null===this._lastCoords?this._lastCoords={latitude:t.coords.latitude,longitude:t.coords.longitude}:e=this._haversineDist(this._lastCoords,t.coords),e>=this._gpsMinDistance&&(this._lastCoords.longitude=t.coords.longitude,this._lastCoords.latitude=t.coords.latitude,this.initialPositionAsOrigin&&!this.initialPosition&&this.setWorldOrigin(t.coords.longitude,t.coords.latitude),this.setWorldPosition(this._camera,t.coords.longitude,t.coords.latitude,this.useAltitude&&null!=t.coords.altitude?t.coords.altitude+this.altitudeOffset:void 0),this._eventHandlers.gpsupdate&&this._eventHandlers.gpsupdate(t,e)))}_haversineDist(t,e){const i=o.MathUtils.degToRad(e.longitude-t.longitude),n=o.MathUtils.degToRad(e.latitude-t.latitude),s=Math.sin(n/2)*Math.sin(n/2)+Math.cos(o.MathUtils.degToRad(t.latitude))*Math.cos(o.MathUtils.degToRad(e.latitude))*(Math.sin(i/2)*Math.sin(i/2));return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}}class h{constructor(t,e){let i;this.renderer=t,this.renderer.autoClear=!1,this.sceneWebcam=new o.Scene,"string"==typeof e?i=document.querySelector(e):e instanceof HTMLVideoElement&&(i=e),void 0===i&&(i=document.createElement("video"),i.setAttribute("autoplay",!0),i.setAttribute("playsinline",!0),i.style.display="none",document.body.appendChild(i)),this.geom=new o.PlaneGeometry,this.texture=new o.VideoTexture(i),this.material=new o.MeshBasicMaterial({map:this.texture});const n=new o.Mesh(this.geom,this.material);if(this.sceneWebcam.add(n),this.cameraWebcam=new o.OrthographicCamera(-.5,.5,.5,-.5,0,10),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const t={video:{width:1280,height:720,facingMode:"environment"}};navigator.mediaDevices.getUserMedia(t).then((t=>{console.log("using the webcam successfully..."),i.srcObject=t,i.play()})).catch((t=>{setTimeout((()=>{this.createErrorPopup("Webcam Error\nName: "+t.name+"\nMessage: "+t.message)}),1e3)}))}else setTimeout((()=>{this.createErrorPopup("sorry - media devices API not supported")}),1e3)}update(){this.renderer.clear(),this.renderer.render(this.sceneWebcam,this.cameraWebcam),this.renderer.clearDepth()}dispose(){this.material.dispose(),this.texture.dispose(),this.geom.dispose()}createErrorPopup(t){if(!document.getElementById("error-popup")){var e=document.createElement("div");e.innerHTML=t,e.setAttribute("id","error-popup"),document.body.appendChild(e)}}}const c=navigator.userAgent.match(/iPhone|iPad|iPod/i)||/Macintosh/i.test(navigator.userAgent)&&null!=navigator.maxTouchPoints&&navigator.maxTouchPoints>1,l=new o.Vector3(0,0,1),d=new o.Euler,u=new o.Quaternion,g=new o.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),p={type:"change"};class m extends o.EventDispatcher{constructor(t){super(),!1===window.isSecureContext&&console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");const e=this,i=new o.Quaternion;this.object=t,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation=null,this.screenOrientation=0,this.alphaOffset=0,this.initialOffset=null,this.TWO_PI=2*Math.PI,this.HALF_PI=.5*Math.PI,this.orientationChangeEventName="ondeviceorientationabsolute"in window?"deviceorientationabsolute":"deviceorientation",this.smoothingFactor=1;const n=function({alpha:i,beta:n,gamma:s,webkitCompassHeading:a,webkitCompassAccuracy:r}){if(c){const t=360-a;e.alphaOffset=o.MathUtils.degToRad(t-i),e.deviceOrientation={alpha:i,beta:n,gamma:s,webkitCompassHeading:a,webkitCompassAccuracy:r}}else i<0&&(i+=360),e.deviceOrientation={alpha:i,beta:n,gamma:s};window.dispatchEvent(new CustomEvent("camera-rotation-change",{detail:{cameraRotation:t.rotation}}))},s=function(){e.screenOrientation=window.orientation||0},a=function(t,e,i,n,o){d.set(i,e,-n,"YXZ"),t.setFromEuler(d),t.multiply(g),t.multiply(u.setFromAxisAngle(l,-o))};this.connect=function(){s(),void 0!==window.DeviceOrientationEvent&&"function"==typeof window.DeviceOrientationEvent.requestPermission?window.DeviceOrientationEvent.requestPermission().then((t=>{"granted"===t&&(window.addEventListener("orientationchange",s),window.addEventListener(e.orientationChangeEventName,n))})).catch((function(t){console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",t)})):(window.addEventListener("orientationchange",s),window.addEventListener(e.orientationChangeEventName,n)),e.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",s),window.removeEventListener(e.orientationChangeEventName,n),e.enabled=!1,e.initialOffset=!1,e.deviceOrientation=null},this.update=function({theta:t=0}={theta:0}){if(!1===e.enabled)return;const n=e.deviceOrientation;if(n){let s=n.alpha?o.MathUtils.degToRad(n.alpha)+e.alphaOffset:0,r=n.beta?o.MathUtils.degToRad(n.beta):0,h=n.gamma?o.MathUtils.degToRad(n.gamma):0;const l=e.screenOrientation?o.MathUtils.degToRad(e.screenOrientation):0;if(c){const t=new o.Quaternion;a(t,s,r,h,l);const i=(new o.Euler).setFromQuaternion(t,"YXZ");i.y=o.MathUtils.degToRad(360-n.webkitCompassHeading),t.setFromEuler(i),e.object.quaternion.copy(t)}else{if(this.smoothingFactor<1){if(this.lastOrientation){const t=this.smoothingFactor;s=this._getSmoothedAngle(s,this.lastOrientation.alpha,t),r=this._getSmoothedAngle(r+Math.PI,this.lastOrientation.beta,t),h=this._getSmoothedAngle(h+this.HALF_PI,this.lastOrientation.gamma,t,Math.PI)}else r+=Math.PI,h+=this.HALF_PI;this.lastOrientation={alpha:s,beta:r,gamma:h}}a(e.object.quaternion,s+t,this.smoothingFactor<1?r-Math.PI:r,this.smoothingFactor<1?h-this.HALF_PI:h,l)}8*(1-i.dot(e.object.quaternion))>1e-6&&(i.copy(e.object.quaternion),e.dispatchEvent(p))}},this._orderAngle=function(t,e,i=this.TWO_PI){return e>t&&Math.abs(e-t)<i/2||t>e&&Math.abs(e-t)>i/2?{left:t,right:e}:{left:e,right:t}},this._getSmoothedAngle=function(t,e,i,n=this.TWO_PI){const o=this._orderAngle(t,e,n),s=o.left,a=o.right;o.left=0,o.right-=s,o.right<0&&(o.right+=n);let r=a==e?(1-i)*o.right+i*o.left:i*o.right+(1-i)*o.left;return r+=s,r>=n&&(r-=n),r},this.updateAlphaOffset=function(){e.initialOffset=!1},this.dispose=function(){e.disconnect()},this.getAlpha=function(){const{deviceOrientation:t}=e;return t&&t.alpha?o.MathUtils.degToRad(t.alpha)+e.alphaOffset:0},this.getBeta=function(){const{deviceOrientation:t}=e;return t&&t.beta?o.MathUtils.degToRad(t.beta):0},this.connect()}}var v=i.nX,M=i.n$,f=i.hX;export{v as DeviceOrientationControls,M as LocationBased,f as WebcamRenderer};
|