diff --git a/docs/01-helloworld/index.html b/docs/01-helloworld/index.html index ecbd0b1..4f5cfee 100644 --- a/docs/01-helloworld/index.html +++ b/docs/01-helloworld/index.html @@ -2,8 +2,8 @@
0)return i;const r=e*t;let s=Ea[r];if(s===void 0&&(s=new Float32Array(r),Ea[r]=s),e!==0){n.toArray(s,0);for(let a=1,o=0;a!==e;++a)o+=t,i[a].toArray(s,o)}return s}function rt(i,e){if(i.length!==e.length)return!1;for(let t=0,n=i.length;t 0)return i;const r=e*t;let s=Ta[r];if(s===void 0&&(s=new Float32Array(r),Ta[r]=s),e!==0){n.toArray(s,0);for(let a=1,o=0;a!==e;++a)o+=t,i[a].toArray(s,o)}return s}function rt(i,e){if(i.length!==e.length)return!1;for(let t=0,n=i.length;t{this._gpsReceived(e)},e=>{this._eventHandlers.gpserror?this._eventHandlers.gpserror(e.code):alert(`GPS error: code ${e.code}`)},{enableHighAccuracy:!0}),!0):!1}stopGps(){return this._watchPositionId!==null?(navigator.geolocation.clearWatch(this._watchPositionId),this._watchPositionId=null,!0):!1}fakeGps(e,t,n=null,r=0){n!==null&&this.setElevation(n),this._gpsReceived({coords:{longitude:e,latitude:t,accuracy:r}})}lonLatToWorldCoords(e,t){const n=this._proj.project(e,t);if(this.initialPosition)n[0]-=this.initialPosition[0],n[1]-=this.initialPosition[1];else throw"No initial position determined";return[n[0],-n[1]]}add(e,t,n,r,s={}){e.properties=s,this.setWorldPosition(e,t,n,r),this._scene.add(e)}setWorldPosition(e,t,n,r){const s=this.lonLatToWorldCoords(t,n);r!==void 0&&(e.position.y=r),[e.position.x,e.position.z]=s}setElevation(e){this._camera.position.y=e}on(e,t){this._eventHandlers[e]=t}setWorldOrigin(e,t){this.initialPosition=this._proj.project(e,t)}_gpsReceived(e){let t=Number.MAX_VALUE;e.coords.accuracy<=this._gpsMinAccuracy&&(this._lastCoords===null?this._lastCoords={latitude:e.coords.latitude,longitude:e.coords.longitude}:t=this._haversineDist(this._lastCoords,e.coords),t>=this._gpsMinDistance&&(this._lastCoords.longitude=e.coords.longitude,this._lastCoords.latitude=e.coords.latitude,this.initialPosition||this.setWorldOrigin(e.coords.longitude,e.coords.latitude),this.setWorldPosition(this._camera,e.coords.longitude,e.coords.latitude),this._eventHandlers.gpsupdate&&this._eventHandlers.gpsupdate(e,t)))}_haversineDist(e,t){const n=sn.degToRad(t.longitude-e.longitude),r=sn.degToRad(t.latitude-e.latitude),s=Math.sin(r/2)*Math.sin(r/2)+Math.cos(sn.degToRad(e.latitude))*Math.cos(sn.degToRad(t.latitude))*(Math.sin(n/2)*Math.sin(n/2));return 2*Math.atan2(Math.sqrt(s),Math.sqrt(1-s))*6371e3}}class ep{constructor(e,t,n){this.renderer=e,this.renderer.autoClear=!1,this.sceneWebcam=new Wf;let r;t===void 0?(r=document.createElement("video"),r.setAttribute("autoplay",!0),r.setAttribute("playsinline",!0),r.style.display="none",document.body.appendChild(r)):r=document.querySelector(t),this.geom=new gi,this.texture=new Xf(r),this.material=new Ns({map:this.texture});const s=new Ft(this.geom,this.material);if(this.sceneWebcam.add(s),this.cameraWebcam=new _o(-.5,.5,.5,-.5,0,10),navigator.mediaDevices&&navigator.mediaDevices.getUserMedia){const a={video:{width:(n==null?void 0:n.width)||1280,height:(n==null?void 0:n.height)||720,facingMode:"environment"}};navigator.mediaDevices.getUserMedia(a).then(o=>{console.log("using the webcam successfully..."),r.srcObject=o,r.play()}).catch(o=>{setTimeout(()=>{this.createErrorPopup(`Webcam Error
+Name: `+o.name+`
+Message: `+o.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(e){if(!document.getElementById("error-popup")){var t=document.createElement("div");t.innerHTML=e,t.setAttribute("id","error-popup"),document.body.appendChild(t)}}}const Kf=new N(0,0,1),Va=new Bt,Zf=new hn,$f=new hn(-Math.sqrt(.5),0,0,Math.sqrt(.5)),jf={type:"change"};class tp extends wn{constructor(e){super(),window.isSecureContext===!1&&console.error("THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)");const t=this,n=1e-6,r=new hn;this.object=e,this.object.rotation.reorder("YXZ"),this.enabled=!0,this.deviceOrientation={},this.screenOrientation=0,this.alphaOffset=0,this.deviceOrientationEventName="ondeviceorientationabsolute"in window?"deviceorientationabsolute":"deviceorientation";const s=function(l){t.deviceOrientation=l},a=function(){t.screenOrientation=window.orientation||0},o=function(l,c,u,p,f){Va.set(u,c,-p,"YXZ"),l.setFromEuler(Va),l.multiply($f),l.multiply(Zf.setFromAxisAngle(Kf,-f))};this.connect=function(){a(),window.DeviceOrientationEvent!==void 0&&typeof window.DeviceOrientationEvent.requestPermission=="function"?window.DeviceOrientationEvent.requestPermission().then(function(l){l=="granted"&&(window.addEventListener("orientationchange",a),window.addEventListener(t.deviceOrientationEventName,s))}).catch(function(l){console.error("THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:",l)}):(window.addEventListener("orientationchange",a),window.addEventListener(t.deviceOrientationEventName,s)),t.enabled=!0},this.disconnect=function(){window.removeEventListener("orientationchange",a),window.removeEventListener(t.deviceOrientationEventName,s),t.enabled=!1},this.update=function(){if(t.enabled===!1)return;const l=t.deviceOrientation;if(l){const c=l.alpha?sn.degToRad(l.alpha)+t.alphaOffset:0,u=l.beta?sn.degToRad(l.beta):0,p=l.gamma?sn.degToRad(l.gamma):0,f=t.screenOrientation?sn.degToRad(t.screenOrientation):0;o(t.object.quaternion,c,u,p,f),8*(1-r.dot(t.object.quaternion))>n&&(r.copy(t.object.quaternion),t.dispatchEvent(jf))}},this.dispose=function(){t.disconnect()},this.connect()}}class np{constructor(e){this.raycaster=new qf,this.normalisedMousePosition=new Ye(null,null),e.domElement.addEventListener("click",t=>{this.normalisedMousePosition.set(t.clientX/e.domElement.clientWidth*2-1,-(t.clientY/e.domElement.clientHeight*2)+1)})}raycast(e,t){if(this.normalisedMousePosition.x!==null&&this.normalisedMousePosition.y!==null){this.raycaster.setFromCamera(this.normalisedMousePosition,e);const n=this.raycaster.intersectObjects(t.children,!1);return this.normalisedMousePosition.set(null,null),n}return[]}}export{_i as B,ep as E,Ft as M,Lt as P,Wf as S,Jf as W,Qf as _,Ns as a,tp as b,sn as c,np as y};
diff --git a/docs/index.html b/docs/index.html
index c9f946d..58bafe2 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -17,6 +17,7 @@ LocAR.js examples