diff --git a/index.html b/index.html new file mode 100644 index 0000000..d910ff8 --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + + + + + <--> + + + + + + +
+
+ + + + diff --git a/p5xr.js b/p5xr.js new file mode 100644 index 0000000..a7548a2 --- /dev/null +++ b/p5xr.js @@ -0,0 +1,96 @@ +(()=>{var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function t(e,t,i,r){Object.defineProperty(e,t,{get:i,set:r,enumerable:!0,configurable:!0})}var i,r={};i=r,Object.defineProperty(i,"__esModule",{value:!0,configurable:!0}),t(r,"default",(()=>dt)); +/** + * @license + * webxr-polyfill + * Copyright (c) 2017 Google + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @license + * cardboard-vr-display + * Copyright (c) 2015-2017 Google + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @license + * webvr-polyfill-dpdb + * Copyright (c) 2017 Google + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @license + * wglu-preserve-state + * Copyright (c) 2016, Brandon Jones. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +/** + * @license + * nosleep.js + * Copyright (c) 2017, Rich Tibbett + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +const n=void 0!==e?e:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},s=Symbol("@@webxr-polyfill/EventTarget");class a{constructor(){this[s]={listeners:new Map}}addEventListener(e,t){if("string"!=typeof e)throw new Error("`type` must be a string");if("function"!=typeof t)throw new Error("`listener` must be a function");const i=this[s].listeners.get(e)||[];i.push(t),this[s].listeners.set(e,i)}removeEventListener(e,t){if("string"!=typeof e)throw new Error("`type` must be a string");if("function"!=typeof t)throw new Error("`listener` must be a function");const i=this[s].listeners.get(e)||[];for(let e=i.length;e>=0;e--)i[e]===t&&i.pop()}dispatchEvent(e,t){const i=this[s].listeners.get(e)||[],r=[];for(let e=0;e0?(r=2*Math.sqrt(i+1),e[3]=.25*r,e[0]=(t[6]-t[9])/r,e[1]=(t[8]-t[2])/r,e[2]=(t[1]-t[4])/r):t[0]>t[5]&&t[0]>t[10]?(r=2*Math.sqrt(1+t[0]-t[5]-t[10]),e[3]=(t[6]-t[9])/r,e[0]=.25*r,e[1]=(t[1]+t[4])/r,e[2]=(t[8]+t[2])/r):t[5]>t[10]?(r=2*Math.sqrt(1+t[5]-t[0]-t[10]),e[3]=(t[8]-t[2])/r,e[0]=(t[1]+t[4])/r,e[1]=.25*r,e[2]=(t[6]+t[9])/r):(r=2*Math.sqrt(1+t[10]-t[0]-t[5]),e[3]=(t[1]-t[4])/r,e[0]=(t[8]+t[2])/r,e[1]=(t[6]+t[9])/r,e[2]=.25*r),e}function f(e,t,i,r,n){let s,a=1/Math.tan(t/2);return e[0]=a/i,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=a,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,null!=n&&n!==1/0?(s=1/(r-n),e[10]=(n+r)*s,e[14]=2*n*r*s):(e[10]=-1,e[14]=-2*r),e}function m(){let e=new o(3);return o!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function g(e){var t=new o(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function v(e,t,i){let r=new o(3);return r[0]=e,r[1]=t,r[2]=i,r}function w(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function y(e,t,i){return e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2],e}function b(e,t,i){return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e}function E(e,t){let i=t[0],r=t[1],n=t[2],s=i*i+r*r+n*n;return s>0&&(s=1/Math.sqrt(s),e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s),e}function x(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function M(e,t,i){let r=t[0],n=t[1],s=t[2],a=i[0],o=i[1],l=i[2];return e[0]=n*l-s*o,e[1]=s*a-r*l,e[2]=r*o-n*a,e}function S(e,t,i){let r=i[0],n=i[1],s=i[2],a=i[3],o=t[0],l=t[1],c=t[2],h=n*c-s*l,u=s*o-r*c,d=r*l-n*o,A=n*d-s*u,p=s*h-r*d,f=r*u-n*h,m=2*a;return h*=m,u*=m,d*=m,A*=2,p*=2,f*=2,e[0]=o+h+A,e[1]=l+u+p,e[2]=c+d+f,e}const _=function(e){let t=e[0],i=e[1],r=e[2];return Math.sqrt(t*t+i*i+r*r)};!function(){let e=m()}();!function(){let e=function(){let e=new o(4);return o!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}()}();function R(){let e=new o(4);return o!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function F(e,t,i){let r=t[0],n=t[1],s=t[2],a=t[3],o=i[0],l=i[1],c=i[2],h=i[3];return e[0]=r*h+a*o+n*c-s*l,e[1]=n*h+a*l+s*o-r*c,e[2]=s*h+a*c+r*l-n*o,e[3]=a*h-r*o-n*l-s*c,e}function T(e,t,i,r){let n,s,a,o,l,c=t[0],h=t[1],u=t[2],d=t[3],A=i[0],p=i[1],f=i[2],m=i[3];return s=c*A+h*p+u*f+d*m,s<0&&(s=-s,A=-A,p=-p,f=-f,m=-m),1-s>1e-6?(n=Math.acos(s),a=Math.sin(n),o=Math.sin((1-r)*n)/a,l=Math.sin(r*n)/a):(o=1-r,l=r),e[0]=o*c+l*A,e[1]=o*h+l*p,e[2]=o*u+l*f,e[3]=o*d+l*m,e}function P(e,t){let i=t[0],r=t[1],n=t[2],s=t[3],a=i*i+r*r+n*n+s*s,o=a?1/a:0;return e[0]=-i*o,e[1]=-r*o,e[2]=-n*o,e[3]=s*o,e}const C=function(e){let t=new o(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},B=function(e,t,i,r){let n=new o(4);return n[0]=e,n[1]=t,n[2]=i,n[3]=r,n},D=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},I=function(e,t){let i=t[0],r=t[1],n=t[2],s=t[3],a=i*i+r*r+n*n+s*s;return a>0&&(a=1/Math.sqrt(a),e[0]=i*a,e[1]=r*a,e[2]=n*a,e[3]=s*a),e},L=(function(){let e=m(),t=v(1,0,0),i=v(0,1,0)}(),function(){let e=R(),t=R()}(),function(){let e=function(){let e=new o(9);return o!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[5]=0,e[6]=0,e[7]=0),e[0]=1,e[4]=1,e[8]=1,e}()}(),Symbol("@@webxr-polyfill/XRRigidTransform"));class O{constructor(){if(this[L]={matrix:null,position:null,orientation:null,inverse:null},0===arguments.length)this[L].matrix=c(new Float32Array(16));else if(1===arguments.length)arguments[0]instanceof Float32Array?this[L].matrix=arguments[0]:(this[L].position=this._getPoint(arguments[0]),this[L].orientation=DOMPointReadOnly.fromPoint({x:0,y:0,z:0,w:1}));else{if(2!==arguments.length)throw new Error("Too many arguments!");this[L].position=this._getPoint(arguments[0]),this[L].orientation=this._getPoint(arguments[1])}if(this[L].matrix){let e=m();A(e,this[L].matrix),this[L].position=DOMPointReadOnly.fromPoint({x:e[0],y:e[1],z:e[2]});let t=R();p(t,this[L].matrix),this[L].orientation=DOMPointReadOnly.fromPoint({x:t[0],y:t[1],z:t[2],w:t[3]})}else this[L].matrix=c(new Float32Array(16)),d(this[L].matrix,B(this[L].orientation.x,this[L].orientation.y,this[L].orientation.z,this[L].orientation.w),v(this[L].position.x,this[L].position.y,this[L].position.z))}_getPoint(e){return e instanceof DOMPointReadOnly?e:DOMPointReadOnly.fromPoint(e)}get matrix(){return this[L].matrix}get position(){return this[L].position}get orientation(){return this[L].orientation}get inverse(){if(null===this[L].inverse){let e=c(new Float32Array(16));h(e,this[L].matrix),this[L].inverse=new O(e),this[L].inverse[L].inverse=this}return this[L].inverse}}const N=Symbol("@@webxr-polyfill/XRSpace");class G{constructor(e=null,t=null){this[N]={specialType:e,inputSource:t,baseMatrix:null,inverseBaseMatrix:null,lastFrameId:-1}}get _specialType(){return this[N].specialType}get _inputSource(){return this[N].inputSource}_ensurePoseUpdated(e,t){t!=this[N].lastFrameId&&(this[N].lastFrameId=t,this._onPoseUpdate(e))}_onPoseUpdate(e){"viewer"==this[N].specialType&&(this._baseMatrix=e.getBasePoseMatrix())}set _baseMatrix(e){this[N].baseMatrix=e,this[N].inverseBaseMatrix=null}get _baseMatrix(){return this[N].baseMatrix||this[N].inverseBaseMatrix&&(this[N].baseMatrix=new Float32Array(16),h(this[N].baseMatrix,this[N].inverseBaseMatrix)),this[N].baseMatrix}set _inverseBaseMatrix(e){this[N].inverseBaseMatrix=e,this[N].baseMatrix=null}get _inverseBaseMatrix(){return this[N].inverseBaseMatrix||this[N].baseMatrix&&(this[N].inverseBaseMatrix=new Float32Array(16),h(this[N].inverseBaseMatrix,this[N].baseMatrix)),this[N].inverseBaseMatrix}_getSpaceRelativeTransform(e){if(!this._inverseBaseMatrix||!e._baseMatrix)return null;let t=new Float32Array(16);return u(t,this._inverseBaseMatrix,e._baseMatrix),new O(t)}}const V=Symbol("@@webxr-polyfill/XRReferenceSpace"),k=["viewer","local","local-floor","bounded-floor","unbounded"];class z extends G{constructor(e,t=null){if(!k.includes(e))throw new Error(`XRReferenceSpaceType must be one of ${k}`);if(super(e),"bounded-floor"===e&&!t)throw new Error("XRReferenceSpace cannot use 'bounded-floor' type if the platform does not provide the floor level");(function(e){return"bounded-floor"===e||"local-floor"===e})(e)&&!t&&((t=c(new Float32Array(16)))[13]=1.6),this._inverseBaseMatrix=t||c(new Float32Array(16)),this[V]={type:e,transform:t,originOffset:c(new Float32Array(16))}}_transformBasePoseMatrix(e,t){u(e,this._inverseBaseMatrix,t)}_originOffsetMatrix(){return this[V].originOffset}_adjustForOriginOffset(e){let t=new Float32Array(16);h(t,this[V].originOffset),u(e,t,e)}_getSpaceRelativeTransform(e){let t=super._getSpaceRelativeTransform(e);return this._adjustForOriginOffset(t.matrix),new XRRigidTransform(t.matrix)}getOffsetReferenceSpace(e){let t=new z(this[V].type,this[V].transform,this[V].bounds);return u(t[V].originOffset,this[V].originOffset,e.matrix),t}}const Q=Symbol("@@webxr-polyfill/XR"),U=["inline","immersive-vr","immersive-ar"],X={inline:{requiredFeatures:["viewer"],optionalFeatures:[]},"immersive-vr":{requiredFeatures:["viewer","local"],optionalFeatures:[]},"immersive-ar":{requiredFeatures:["viewer","local"],optionalFeatures:[]}};let H;if("performance"in n==!1){let e=Date.now();H=()=>Date.now()-e}else H=()=>performance.now();var W=H;const q=Symbol("@@webxr-polyfill/XRPose");class j{constructor(e,t){this[q]={transform:e,emulatedPosition:t}}get transform(){return this[q].transform}get emulatedPosition(){return this[q].emulatedPosition}}const Y=Symbol("@@webxr-polyfill/XRViewerPose");class Z extends j{constructor(e,t,i=!1){super(e,i),this[Y]={views:t}}get views(){return this[Y].views}}const $=Symbol("@@webxr-polyfill/XRViewport");class K{constructor(e){this[$]={target:e}}get x(){return this[$].target.x}get y(){return this[$].target.y}get width(){return this[$].target.width}get height(){return this[$].target.height}}const J=["left","right","none"],ee=Symbol("@@webxr-polyfill/XRView");class te{constructor(e,t,i,r){if(!J.includes(i))throw new Error(`XREye must be one of: ${J}`);const n=Object.create(null),s=new K(n);this[ee]={device:e,eye:i,viewport:s,temp:n,sessionId:r,transform:t}}get eye(){return this[ee].eye}get projectionMatrix(){return this[ee].device.getProjectionMatrix(this.eye)}get transform(){return this[ee].transform}_getViewport(e){if(this[ee].device.getViewport(this[ee].sessionId,this.eye,e,this[ee].temp))return this[ee].viewport}}const ie=Symbol("@@webxr-polyfill/XRFrame"),re="XRFrame access outside the callback that produced it is invalid.";let ne=0;class se{constructor(e,t,i){this[ie]={id:++ne,active:!1,animationFrame:!1,device:e,session:t,sessionId:i}}get session(){return this[ie].session}getViewerPose(e){if(!this[ie].animationFrame)throw new DOMException("getViewerPose can only be called on XRFrame objects passed to XRSession.requestAnimationFrame callbacks.","InvalidStateError");if(!this[ie].active)throw new DOMException(re,"InvalidStateError");const t=this[ie].device,i=this[ie].session;i[we].viewerSpace._ensurePoseUpdated(t,this[ie].id),e._ensurePoseUpdated(t,this[ie].id);let r=e._getSpaceRelativeTransform(i[we].viewerSpace);const n=[];for(let r of i[we].viewSpaces){r._ensurePoseUpdated(t,this[ie].id);let i=e._getSpaceRelativeTransform(r),s=new te(t,i,r.eye,this[ie].sessionId);n.push(s)}return new Z(r,n,!1)}getPose(e,t){if(!this[ie].active)throw new DOMException(re,"InvalidStateError");const i=this[ie].device;if("target-ray"===e._specialType||"grip"===e._specialType)return i.getInputPose(e._inputSource,t,e._specialType);{e._ensurePoseUpdated(i,this[ie].id),t._ensurePoseUpdated(i,this[ie].id);let r=t._getSpaceRelativeTransform(e);return r?new XRPose(r,!1):null}}}const ae=Symbol("@@webxr-polyfill/XRRenderState"),oe=Object.freeze({depthNear:.1,depthFar:1e3,inlineVerticalFieldOfView:null,baseLayer:null});class le{constructor(e={}){const t=Object.assign({},oe,e);this[ae]={config:t}}get depthNear(){return this[ae].config.depthNear}get depthFar(){return this[ae].config.depthFar}get inlineVerticalFieldOfView(){return this[ae].config.inlineVerticalFieldOfView}get baseLayer(){return this[ae].config.baseLayer}}const ce=Symbol("@@webxr-polyfill/polyfilled-xr-compatible"),he=Symbol("@@webxr-polyfill/xr-compatible"),ue=Symbol("@@webxr-polyfill/XRWebGLLayer"),de=Object.freeze({antialias:!0,depth:!1,stencil:!1,alpha:!0,multiview:!1,ignoreDepthValues:!1,framebufferScaleFactor:1});const Ae=Symbol("@@webxr-polyfill/XRInputSourceEvent");class pe extends Event{constructor(e,t){super(e,t),this[Ae]={frame:t.frame,inputSource:t.inputSource},Object.setPrototypeOf(this,pe.prototype)}get frame(){return this[Ae].frame}get inputSource(){return this[Ae].inputSource}}const fe=Symbol("@@webxr-polyfill/XRSessionEvent");class me extends Event{constructor(e,t){super(e,t),this[fe]={session:t.session},Object.setPrototypeOf(this,me.prototype)}get session(){return this[fe].session}}const ge=Symbol("@@webxr-polyfill/XRInputSourcesChangeEvent");class ve extends Event{constructor(e,t){super(e,t),this[ge]={session:t.session,added:t.added,removed:t.removed},Object.setPrototypeOf(this,ve.prototype)}get session(){return this[ge].session}get added(){return this[ge].added}get removed(){return this[ge].removed}}const we=Symbol("@@webxr-polyfill/XRSession");class ye extends G{constructor(e){super(e)}get eye(){return this._specialType}_onPoseUpdate(e){this._inverseBaseMatrix=e.getBaseViewMatrix(this._specialType)}}class be extends a{constructor(e,t,i){super();let r="inline"!=t,n=new le({inlineVerticalFieldOfView:r?null:.5*Math.PI});this[we]={device:e,mode:t,immersive:r,ended:!1,suspended:!1,frameCallbacks:[],currentFrameCallbacks:null,frameHandle:0,deviceFrameHandle:null,id:i,activeRenderState:n,pendingRenderState:null,viewerSpace:new z("viewer"),viewSpaces:[],currentInputSources:[]},r?this[we].viewSpaces.push(new ye("left"),new ye("right")):this[we].viewSpaces.push(new ye("none")),this[we].onDeviceFrame=()=>{if(this[we].ended||this[we].suspended)return;if(this[we].deviceFrameHandle=null,this[we].startDeviceFrameLoop(),null!==this[we].pendingRenderState&&(this[we].activeRenderState=new le(this[we].pendingRenderState),this[we].pendingRenderState=null,this[we].activeRenderState.baseLayer&&this[we].device.onBaseLayerSet(this[we].id,this[we].activeRenderState.baseLayer)),null===this[we].activeRenderState.baseLayer)return;const t=new se(e,this,this[we].id),i=this[we].currentFrameCallbacks=this[we].frameCallbacks;this[we].frameCallbacks=[],t[ie].active=!0,t[ie].animationFrame=!0,this[we].device.onFrameStart(this[we].id,this[we].activeRenderState),this._checkInputSourcesChange();const r=W();for(let e=0;e{null===this[we].deviceFrameHandle&&(this[we].deviceFrameHandle=this[we].device.requestAnimationFrame(this[we].onDeviceFrame))},this[we].stopDeviceFrameLoop=()=>{const e=this[we].deviceFrameHandle;null!==e&&(this[we].device.cancelAnimationFrame(e),this[we].deviceFrameHandle=null)},this[we].onPresentationEnd=t=>{if(t!==this[we].id)return this[we].suspended=!1,this[we].startDeviceFrameLoop(),void this.dispatchEvent("focus",{session:this});this[we].ended=!0,this[we].stopDeviceFrameLoop(),e.removeEventListener("@@webxr-polyfill/vr-present-end",this[we].onPresentationEnd),e.removeEventListener("@@webxr-polyfill/vr-present-start",this[we].onPresentationStart),e.removeEventListener("@@webxr-polyfill/input-select-start",this[we].onSelectStart),e.removeEventListener("@@webxr-polyfill/input-select-end",this[we].onSelectEnd),this.dispatchEvent("end",new me("end",{session:this}))},e.addEventListener("@@webxr-polyfill/vr-present-end",this[we].onPresentationEnd),this[we].onPresentationStart=e=>{e!==this[we].id&&(this[we].suspended=!0,this[we].stopDeviceFrameLoop(),this.dispatchEvent("blur",{session:this}))},e.addEventListener("@@webxr-polyfill/vr-present-start",this[we].onPresentationStart),this[we].onSelectStart=e=>{e.sessionId===this[we].id&&this[we].dispatchInputSourceEvent("selectstart",e.inputSource)},e.addEventListener("@@webxr-polyfill/input-select-start",this[we].onSelectStart),this[we].onSelectEnd=e=>{e.sessionId===this[we].id&&(this[we].dispatchInputSourceEvent("selectend",e.inputSource),this[we].dispatchInputSourceEvent("select",e.inputSource))},e.addEventListener("@@webxr-polyfill/input-select-end",this[we].onSelectEnd),this[we].onSqueezeStart=e=>{e.sessionId===this[we].id&&this[we].dispatchInputSourceEvent("squeezestart",e.inputSource)},e.addEventListener("@@webxr-polyfill/input-squeeze-start",this[we].onSqueezeStart),this[we].onSqueezeEnd=e=>{e.sessionId===this[we].id&&(this[we].dispatchInputSourceEvent("squeezeend",e.inputSource),this[we].dispatchInputSourceEvent("squeeze",e.inputSource))},e.addEventListener("@@webxr-polyfill/input-squeeze-end",this[we].onSqueezeEnd),this[we].dispatchInputSourceEvent=(t,i)=>{const r=new se(e,this,this[we].id),n=new pe(t,{frame:r,inputSource:i});r[ie].active=!0,this.dispatchEvent(t,n),r[ie].active=!1},this[we].startDeviceFrameLoop(),this.onblur=void 0,this.onfocus=void 0,this.onresetpose=void 0,this.onend=void 0,this.onselect=void 0,this.onselectstart=void 0,this.onselectend=void 0}get renderState(){return this[we].activeRenderState}get environmentBlendMode(){return this[we].device.environmentBlendMode||"opaque"}async requestReferenceSpace(e){if(this[we].ended)return;if(!k.includes(e))throw new TypeError(`XRReferenceSpaceType must be one of ${k}`);if(!this[we].device.doesSessionSupportReferenceSpace(this[we].id,e))throw new DOMException(`The ${e} reference space is not supported by this session.`,"NotSupportedError");if("viewer"===e)return this[we].viewerSpace;let t=await this[we].device.requestFrameOfReferenceTransform(e);if("bounded-floor"===e){if(!t)throw new DOMException(`${e} XRReferenceSpace not supported by this device.`,"NotSupportedError");if(!this[we].device.requestStageBounds())throw new DOMException(`${e} XRReferenceSpace not supported by this device.`,"NotSupportedError");throw new DOMException(`The WebXR polyfill does not support the ${e} reference space yet.`,"NotSupportedError")}return new z(e,t)}requestAnimationFrame(e){if(this[we].ended)return;const t=++this[we].frameHandle;return this[we].frameCallbacks.push({handle:t,callback:e,cancelled:!1}),t}cancelAnimationFrame(e){let t=this[we].frameCallbacks,i=t.findIndex((t=>t&&t.handle===e));i>-1&&(t[i].cancelled=!0,t.splice(i,1)),t=this[we].currentFrameCallbacks,t&&(i=t.findIndex((t=>t&&t.handle===e)),i>-1&&(t[i].cancelled=!0))}get inputSources(){return this[we].device.getInputSources()}async end(){if(!this[we].ended)return this[we].immersive&&(this[we].ended=!0,this[we].device.removeEventListener("@@webxr-polyfill/vr-present-start",this[we].onPresentationStart),this[we].device.removeEventListener("@@webxr-polyfill/vr-present-end",this[we].onPresentationEnd),this[we].device.removeEventListener("@@webxr-polyfill/input-select-start",this[we].onSelectStart),this[we].device.removeEventListener("@@webxr-polyfill/input-select-end",this[we].onSelectEnd),this.dispatchEvent("end",new me("end",{session:this}))),this[we].stopDeviceFrameLoop(),this[we].device.endSession(this[we].id)}updateRenderState(e){if(this[we].ended){throw new Error("Can't call updateRenderState on an XRSession that has already ended.")}if(e.baseLayer&&e.baseLayer._session!==this){throw new Error("Called updateRenderState with a base layer that was created by a different session.")}if(null!==e.inlineVerticalFieldOfView&&void 0!==e.inlineVerticalFieldOfView){if(this[we].immersive){throw new Error("inlineVerticalFieldOfView must not be set for an XRRenderState passed to updateRenderState for an immersive session.")}e.inlineVerticalFieldOfView=Math.min(3.13,Math.max(.01,e.inlineVerticalFieldOfView))}if(null===this[we].pendingRenderState){const e=this[we].activeRenderState;this[we].pendingRenderState={depthNear:e.depthNear,depthFar:e.depthFar,inlineVerticalFieldOfView:e.inlineVerticalFieldOfView,baseLayer:e.baseLayer}}Object.assign(this[we].pendingRenderState,e)}_checkInputSourcesChange(){const e=[],t=[],i=this.inputSources,r=this[we].currentInputSources;for(const t of i)r.includes(t)||e.push(t);for(const e of r)i.includes(e)||t.push(e);(e.length>0||t.length>0)&&this.dispatchEvent("inputsourceschange",new ve("inputsourceschange",{session:this,added:e,removed:t})),this[we].currentInputSources.length=0;for(const e of i)this[we].currentInputSources.push(e)}}const Ee=Symbol("@@webxr-polyfill/XRInputSource");class xe{constructor(e){this[Ee]={impl:e,gripSpace:new G("grip",this),targetRaySpace:new G("target-ray",this)}}get handedness(){return this[Ee].impl.handedness}get targetRayMode(){return this[Ee].impl.targetRayMode}get gripSpace(){let e=this[Ee].impl.targetRayMode;return"gaze"===e||"screen"===e?null:this[Ee].gripSpace}get targetRaySpace(){return this[Ee].targetRaySpace}get profiles(){return this[Ee].impl.profiles}get gamepad(){return this[Ee].impl.gamepad}}const Me=Symbol("@@webxr-polyfill/XRReferenceSpaceEvent");class Se extends Event{constructor(e,t){super(e,t),this[Me]={referenceSpace:t.referenceSpace,transform:t.transform||null},Object.setPrototypeOf(this,Se.prototype)}get referenceSpace(){return this[Me].referenceSpace}get transform(){return this[Me].transform}}var _e={XRSystem:class extends a{constructor(e){super(),this[Q]={device:null,devicePromise:e,immersiveSession:null,inlineSessions:new Set},e.then((e=>{this[Q].device=e}))}async isSessionSupported(e){return this[Q].device||await this[Q].devicePromise,"inline"!=e?Promise.resolve(this[Q].device.isSessionSupported(e)):Promise.resolve(!0)}async requestSession(e,t){if(!this[Q].device){if("inline"!=e)throw new Error("Polyfill Error: Must call navigator.xr.isSessionSupported() with any XRSessionMode\nor navigator.xr.requestSession('inline') prior to requesting an immersive\nsession. This is a limitation specific to the WebXR Polyfill and does not apply\nto native implementations of the API.");await this[Q].devicePromise}if(!U.includes(e))throw new TypeError(`The provided value '${e}' is not a valid enum value of type XRSessionMode`);const i=X[e],r=i.requiredFeatures.concat(t&&t.requiredFeatures?t.requiredFeatures:[]),n=i.optionalFeatures.concat(t&&t.optionalFeatures?t.optionalFeatures:[]),s=new Set;let a=!1;for(let e of r)this[Q].device.isFeatureSupported(e)?s.add(e):(console.error(`The required feature '${e}' is not supported`),a=!0);if(a)throw new DOMException("Session does not support some required features","NotSupportedError");for(let e of n)this[Q].device.isFeatureSupported(e)?s.add(e):console.log(`The optional feature '${e}' is not supported`);const o=await this[Q].device.requestSession(e,s),l=new XRSession(this[Q].device,e,o);"inline"==e?this[Q].inlineSessions.add(l):this[Q].immersiveSession=l;const c=()=>{"inline"==e?this[Q].inlineSessions.delete(l):this[Q].immersiveSession=null,l.removeEventListener("end",c)};return l.addEventListener("end",c),l}},XRSession:be,XRSessionEvent:me,XRFrame:se,XRView:te,XRViewport:K,XRViewerPose:Z,XRWebGLLayer:class{constructor(e,t,i={}){const r=Object.assign({},de,i);if(!(e instanceof be))throw new Error("session must be a XRSession");if(e.ended)throw new Error("InvalidStateError");if(t[ce]&&!0!==t[he])throw new Error("InvalidStateError");const n=t.getParameter(t.FRAMEBUFFER_BINDING);this[ue]={context:t,config:r,framebuffer:n,session:e}}get context(){return this[ue].context}get antialias(){return this[ue].config.antialias}get ignoreDepthValues(){return!0}get framebuffer(){return this[ue].framebuffer}get framebufferWidth(){return this[ue].context.drawingBufferWidth}get framebufferHeight(){return this[ue].context.drawingBufferHeight}get _session(){return this[ue].session}getViewport(e){return e._getViewport(this)}static getNativeFramebufferScaleFactor(e){if(!e)throw new TypeError("getNativeFramebufferScaleFactor must be passed a session.");return e[we].ended?0:1}},XRSpace:G,XRReferenceSpace:z,XRReferenceSpaceEvent:Se,XRInputSource:xe,XRInputSourceEvent:pe,XRInputSourcesChangeEvent:ve,XRRenderState:le,XRRigidTransform:O,XRPose:j};const Re=e=>"function"!=typeof e.prototype.makeXRCompatible&&(e.prototype.makeXRCompatible=function(){return this[he]=!0,Promise.resolve()},!0),Fe=e=>{const t=e.prototype.getContext;e.prototype.getContext=function(e,i){const r=t.call(this,e,i);return r&&(r[ce]=!0,i&&"xrCompatible"in i&&(r[he]=i.xrCompatible)),r}};var Te="undefined"!=typeof window?window:void 0!==e?e:"undefined"!=typeof self?self:{};var Pe,Ce,Be,De=(Pe=function(e,t){e.exports=function(){var e,t,i,r,n,s,a,o,l=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},c=function(){function e(e,t){for(var i=0;id)},S=function(){return Math.max(window.screen.width,window.screen.height)*window.devicePixelRatio},_=function(){return Math.min(window.screen.width,window.screen.height)*window.devicePixelRatio},R=function(e){if(m())return!1;if(e.requestFullscreen)e.requestFullscreen();else if(e.webkitRequestFullscreen)e.webkitRequestFullscreen();else if(e.mozRequestFullScreen)e.mozRequestFullScreen();else{if(!e.msRequestFullscreen)return!1;e.msRequestFullscreen()}return!0},F=function(){if(document.exitFullscreen)document.exitFullscreen();else if(document.webkitExitFullscreen)document.webkitExitFullscreen();else if(document.mozCancelFullScreen)document.mozCancelFullScreen();else{if(!document.msExitFullscreen)return!1;document.msExitFullscreen()}return!0},T=function(){return document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement},P=function(e,t,i,r){var n=e.createShader(e.VERTEX_SHADER);e.shaderSource(n,t),e.compileShader(n);var s=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(s,i),e.compileShader(s);var a=e.createProgram();for(var o in e.attachShader(a,n),e.attachShader(a,s),r)e.bindAttribLocation(a,r[o],o);return e.linkProgram(a),e.deleteShader(n),e.deleteShader(s),a},C=function(e,t){for(var i={},r=e.getProgramParameter(t,e.ACTIVE_UNIFORMS),n="",s=0;s1?(console.warn("getQuaternionAngle: w > 1"),0):2*Math.acos(e.w)},k=(e={},function(t,i){void 0===e[t]&&(console.warn("webvr-polyfill: "+i),e[t]=!0)}),z=function(e,t){k(e,e+" has been deprecated. This may not work on native WebVR displays. "+(t?"Please use "+t+" instead.":""))};function Q(e,t,i){if(t){for(var r=[],n=null,s=0;se.TEXTURE31){console.error("TEXTURE_BINDING_2D or TEXTURE_BINDING_CUBE_MAP must be followed by a valid texture unit"),r.push(null,null);break}n||(n=e.getParameter(e.ACTIVE_TEXTURE)),e.activeTexture(l),r.push(e.getParameter(a),null);break;case e.ACTIVE_TEXTURE:n=e.getParameter(e.ACTIVE_TEXTURE),r.push(null);break;default:r.push(e.getParameter(a))}for(i(e),s=0;se.TEXTURE31)break;e.activeTexture(l),e.bindTexture(e.TEXTURE_2D,o);break;case e.TEXTURE_BINDING_CUBE_MAP:var l;if((l=t[++s])e.TEXTURE31)break;e.activeTexture(l),e.bindTexture(e.TEXTURE_CUBE_MAP,o);break;case e.VIEWPORT:e.viewport(o[0],o[1],o[2],o[3]);break;case e.BLEND:case e.CULL_FACE:case e.DEPTH_TEST:case e.SCISSOR_TEST:case e.STENCIL_TEST:o?e.enable(a):e.disable(a);break;default:console.log("No GL restore behavior for 0x"+a.toString(16))}n&&e.activeTexture(n)}}else i(e)}var U=Q,X=["attribute vec2 position;","attribute vec3 texCoord;","varying vec2 vTexCoord;","uniform vec4 viewportOffsetScale[2];","void main() {"," vec4 viewport = viewportOffsetScale[int(texCoord.z)];"," vTexCoord = (texCoord.xy * viewport.zw) + viewport.xy;"," gl_Position = vec4( position, 1.0, 1.0 );","}"].join("\n"),H=["precision mediump float;","uniform sampler2D diffuse;","varying vec2 vTexCoord;","void main() {"," gl_FragColor = texture2D(diffuse, vTexCoord);","}"].join("\n");function W(e,t,i,r){this.gl=e,this.cardboardUI=t,this.bufferScale=i,this.dirtySubmitFrameBindings=r,this.ctxAttribs=e.getContextAttributes(),this.instanceExt=e.getExtension("ANGLE_instanced_arrays"),this.meshWidth=20,this.meshHeight=20,this.bufferWidth=e.drawingBufferWidth,this.bufferHeight=e.drawingBufferHeight,this.realBindFramebuffer=e.bindFramebuffer,this.realEnable=e.enable,this.realDisable=e.disable,this.realColorMask=e.colorMask,this.realClearColor=e.clearColor,this.realViewport=e.viewport,f()||(this.realCanvasWidth=Object.getOwnPropertyDescriptor(e.canvas.__proto__,"width"),this.realCanvasHeight=Object.getOwnPropertyDescriptor(e.canvas.__proto__,"height")),this.isPatched=!1,this.lastBoundFramebuffer=null,this.cullFace=!1,this.depthTest=!1,this.blend=!1,this.scissorTest=!1,this.stencilTest=!1,this.viewport=[0,0,0,0],this.colorMask=[!0,!0,!0,!0],this.clearColor=[0,0,0,0],this.attribs={position:0,texCoord:1},this.program=P(e,X,H,this.attribs),this.uniforms=C(e,this.program),this.viewportOffsetScale=new Float32Array(8),this.setTextureBounds(),this.vertexBuffer=e.createBuffer(),this.indexBuffer=e.createBuffer(),this.indexCount=0,this.renderTarget=e.createTexture(),this.framebuffer=e.createFramebuffer(),this.depthStencilBuffer=null,this.depthBuffer=null,this.stencilBuffer=null,this.ctxAttribs.depth&&this.ctxAttribs.stencil?this.depthStencilBuffer=e.createRenderbuffer():this.ctxAttribs.depth?this.depthBuffer=e.createRenderbuffer():this.ctxAttribs.stencil&&(this.stencilBuffer=e.createRenderbuffer()),this.patch(),this.onResize()}W.prototype.destroy=function(){var e=this.gl;this.unpatch(),e.deleteProgram(this.program),e.deleteBuffer(this.vertexBuffer),e.deleteBuffer(this.indexBuffer),e.deleteTexture(this.renderTarget),e.deleteFramebuffer(this.framebuffer),this.depthStencilBuffer&&e.deleteRenderbuffer(this.depthStencilBuffer),this.depthBuffer&&e.deleteRenderbuffer(this.depthBuffer),this.stencilBuffer&&e.deleteRenderbuffer(this.stencilBuffer),this.cardboardUI&&this.cardboardUI.destroy()},W.prototype.onResize=function(){var e=this.gl,t=this,i=[e.RENDERBUFFER_BINDING,e.TEXTURE_BINDING_2D,e.TEXTURE0];U(e,i,(function(e){t.realBindFramebuffer.call(e,e.FRAMEBUFFER,null),t.scissorTest&&t.realDisable.call(e,e.SCISSOR_TEST),t.realColorMask.call(e,!0,!0,!0,!0),t.realViewport.call(e,0,0,e.drawingBufferWidth,e.drawingBufferHeight),t.realClearColor.call(e,0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.framebuffer),e.bindTexture(e.TEXTURE_2D,t.renderTarget),e.texImage2D(e.TEXTURE_2D,0,t.ctxAttribs.alpha?e.RGBA:e.RGB,t.bufferWidth,t.bufferHeight,0,t.ctxAttribs.alpha?e.RGBA:e.RGB,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t.renderTarget,0),t.ctxAttribs.depth&&t.ctxAttribs.stencil?(e.bindRenderbuffer(e.RENDERBUFFER,t.depthStencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,t.depthStencilBuffer)):t.ctxAttribs.depth?(e.bindRenderbuffer(e.RENDERBUFFER,t.depthBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,t.depthBuffer)):t.ctxAttribs.stencil&&(e.bindRenderbuffer(e.RENDERBUFFER,t.stencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.STENCIL_INDEX8,t.bufferWidth,t.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.STENCIL_ATTACHMENT,e.RENDERBUFFER,t.stencilBuffer)),!e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer incomplete!"),t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.lastBoundFramebuffer),t.scissorTest&&t.realEnable.call(e,e.SCISSOR_TEST),t.realColorMask.apply(e,t.colorMask),t.realViewport.apply(e,t.viewport),t.realClearColor.apply(e,t.clearColor)})),this.cardboardUI&&this.cardboardUI.onResize()},W.prototype.patch=function(){if(!this.isPatched){var e=this,t=this.gl.canvas,i=this.gl;f()||(t.width=S()*this.bufferScale,t.height=_()*this.bufferScale,Object.defineProperty(t,"width",{configurable:!0,enumerable:!0,get:function(){return e.bufferWidth},set:function(i){e.bufferWidth=i,e.realCanvasWidth.set.call(t,i),e.onResize()}}),Object.defineProperty(t,"height",{configurable:!0,enumerable:!0,get:function(){return e.bufferHeight},set:function(i){e.bufferHeight=i,e.realCanvasHeight.set.call(t,i),e.onResize()}})),this.lastBoundFramebuffer=i.getParameter(i.FRAMEBUFFER_BINDING),null==this.lastBoundFramebuffer&&(this.lastBoundFramebuffer=this.framebuffer,this.gl.bindFramebuffer(i.FRAMEBUFFER,this.framebuffer)),this.gl.bindFramebuffer=function(t,r){e.lastBoundFramebuffer=r||e.framebuffer,e.realBindFramebuffer.call(i,t,e.lastBoundFramebuffer)},this.cullFace=i.getParameter(i.CULL_FACE),this.depthTest=i.getParameter(i.DEPTH_TEST),this.blend=i.getParameter(i.BLEND),this.scissorTest=i.getParameter(i.SCISSOR_TEST),this.stencilTest=i.getParameter(i.STENCIL_TEST),i.enable=function(t){switch(t){case i.CULL_FACE:e.cullFace=!0;break;case i.DEPTH_TEST:e.depthTest=!0;break;case i.BLEND:e.blend=!0;break;case i.SCISSOR_TEST:e.scissorTest=!0;break;case i.STENCIL_TEST:e.stencilTest=!0}e.realEnable.call(i,t)},i.disable=function(t){switch(t){case i.CULL_FACE:e.cullFace=!1;break;case i.DEPTH_TEST:e.depthTest=!1;break;case i.BLEND:e.blend=!1;break;case i.SCISSOR_TEST:e.scissorTest=!1;break;case i.STENCIL_TEST:e.stencilTest=!1}e.realDisable.call(i,t)},this.colorMask=i.getParameter(i.COLOR_WRITEMASK),i.colorMask=function(t,r,n,s){e.colorMask[0]=t,e.colorMask[1]=r,e.colorMask[2]=n,e.colorMask[3]=s,e.realColorMask.call(i,t,r,n,s)},this.clearColor=i.getParameter(i.COLOR_CLEAR_VALUE),i.clearColor=function(t,r,n,s){e.clearColor[0]=t,e.clearColor[1]=r,e.clearColor[2]=n,e.clearColor[3]=s,e.realClearColor.call(i,t,r,n,s)},this.viewport=i.getParameter(i.VIEWPORT),i.viewport=function(t,r,n,s){e.viewport[0]=t,e.viewport[1]=r,e.viewport[2]=n,e.viewport[3]=s,e.realViewport.call(i,t,r,n,s)},this.isPatched=!0,L(t)}},W.prototype.unpatch=function(){if(this.isPatched){var e=this.gl,t=this.gl.canvas;f()||(Object.defineProperty(t,"width",this.realCanvasWidth),Object.defineProperty(t,"height",this.realCanvasHeight)),t.width=this.bufferWidth,t.height=this.bufferHeight,e.bindFramebuffer=this.realBindFramebuffer,e.enable=this.realEnable,e.disable=this.realDisable,e.colorMask=this.realColorMask,e.clearColor=this.realClearColor,e.viewport=this.realViewport,this.lastBoundFramebuffer==this.framebuffer&&e.bindFramebuffer(e.FRAMEBUFFER,null),this.isPatched=!1,setTimeout((function(){L(t)}),1)}},W.prototype.setTextureBounds=function(e,t){e||(e=[0,0,.5,1]),t||(t=[.5,0,.5,1]),this.viewportOffsetScale[0]=e[0],this.viewportOffsetScale[1]=e[1],this.viewportOffsetScale[2]=e[2],this.viewportOffsetScale[3]=e[3],this.viewportOffsetScale[4]=t[0],this.viewportOffsetScale[5]=t[1],this.viewportOffsetScale[6]=t[2],this.viewportOffsetScale[7]=t[3]},W.prototype.submitFrame=function(){var e=this.gl,t=this,i=[];if(this.dirtySubmitFrameBindings||i.push(e.CURRENT_PROGRAM,e.ARRAY_BUFFER_BINDING,e.ELEMENT_ARRAY_BUFFER_BINDING,e.TEXTURE_BINDING_2D,e.TEXTURE0),U(e,i,(function(e){t.realBindFramebuffer.call(e,e.FRAMEBUFFER,null);var i=0,r=0;t.instanceExt&&(i=e.getVertexAttrib(t.attribs.position,t.instanceExt.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE),r=e.getVertexAttrib(t.attribs.texCoord,t.instanceExt.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE)),t.cullFace&&t.realDisable.call(e,e.CULL_FACE),t.depthTest&&t.realDisable.call(e,e.DEPTH_TEST),t.blend&&t.realDisable.call(e,e.BLEND),t.scissorTest&&t.realDisable.call(e,e.SCISSOR_TEST),t.stencilTest&&t.realDisable.call(e,e.STENCIL_TEST),t.realColorMask.call(e,!0,!0,!0,!0),t.realViewport.call(e,0,0,e.drawingBufferWidth,e.drawingBufferHeight),(t.ctxAttribs.alpha||f())&&(t.realClearColor.call(e,0,0,0,1),e.clear(e.COLOR_BUFFER_BIT)),e.useProgram(t.program),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.indexBuffer),e.bindBuffer(e.ARRAY_BUFFER,t.vertexBuffer),e.enableVertexAttribArray(t.attribs.position),e.enableVertexAttribArray(t.attribs.texCoord),e.vertexAttribPointer(t.attribs.position,2,e.FLOAT,!1,20,0),e.vertexAttribPointer(t.attribs.texCoord,3,e.FLOAT,!1,20,8),t.instanceExt&&(0!=i&&t.instanceExt.vertexAttribDivisorANGLE(t.attribs.position,0),0!=r&&t.instanceExt.vertexAttribDivisorANGLE(t.attribs.texCoord,0)),e.activeTexture(e.TEXTURE0),e.uniform1i(t.uniforms.diffuse,0),e.bindTexture(e.TEXTURE_2D,t.renderTarget),e.uniform4fv(t.uniforms.viewportOffsetScale,t.viewportOffsetScale),e.drawElements(e.TRIANGLES,t.indexCount,e.UNSIGNED_SHORT,0),t.cardboardUI&&t.cardboardUI.renderNoState(),t.realBindFramebuffer.call(t.gl,e.FRAMEBUFFER,t.framebuffer),t.ctxAttribs.preserveDrawingBuffer||(t.realClearColor.call(e,0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)),t.dirtySubmitFrameBindings||t.realBindFramebuffer.call(e,e.FRAMEBUFFER,t.lastBoundFramebuffer),t.cullFace&&t.realEnable.call(e,e.CULL_FACE),t.depthTest&&t.realEnable.call(e,e.DEPTH_TEST),t.blend&&t.realEnable.call(e,e.BLEND),t.scissorTest&&t.realEnable.call(e,e.SCISSOR_TEST),t.stencilTest&&t.realEnable.call(e,e.STENCIL_TEST),t.realColorMask.apply(e,t.colorMask),t.realViewport.apply(e,t.viewport),!t.ctxAttribs.alpha&&t.ctxAttribs.preserveDrawingBuffer||t.realClearColor.apply(e,t.clearColor),t.instanceExt&&(0!=i&&t.instanceExt.vertexAttribDivisorANGLE(t.attribs.position,i),0!=r&&t.instanceExt.vertexAttribDivisorANGLE(t.attribs.texCoord,r))})),f()){var r=e.canvas;r.width==t.bufferWidth&&r.height==t.bufferHeight||(t.bufferWidth=r.width,t.bufferHeight=r.height,t.onResize())}},W.prototype.updateDeviceInfo=function(e){var t=this.gl,i=this,r=[t.ARRAY_BUFFER_BINDING,t.ELEMENT_ARRAY_BUFFER_BINDING];U(t,r,(function(t){var r=i.computeMeshVertices_(i.meshWidth,i.meshHeight,e);if(t.bindBuffer(t.ARRAY_BUFFER,i.vertexBuffer),t.bufferData(t.ARRAY_BUFFER,r,t.STATIC_DRAW),!i.indexCount){var n=i.computeMeshIndices_(i.meshWidth,i.meshHeight);t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,i.indexBuffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,n,t.STATIC_DRAW),i.indexCount=n.length}}))},W.prototype.computeMeshVertices_=function(e,t,i){for(var r=new Float32Array(2*e*t*5),n=i.getLeftEyeVisibleTanAngles(),s=i.getLeftEyeNoLensTanAngles(),a=i.getLeftEyeVisibleScreenRect(s),o=0,l=0;l<2;l++){for(var c=0;cn-s&&r.clientXi.clientHeight-s?e(r):r.clientX1e-4;){var n=e-this.distort(i),s=i-n*((i-t)/(n-r));t=i,i=s,r=n}return i},ae.prototype.distort=function(e){for(var t=e*e,i=0,r=0;r=1)return this.w=s,this.x=i,this.y=r,this.z=n,this;var o=Math.acos(a),l=Math.sqrt(1-a*a);if(Math.abs(l)<.001)return this.w=.5*(s+this.w),this.x=.5*(i+this.x),this.y=.5*(r+this.y),this.z=.5*(n+this.z),this;var c=Math.sin((1-t)*o)/l,h=Math.sin(t*o)/l;return this.w=s*c+this.w*h,this.x=i*c+this.x*h,this.y=r*c+this.y*h,this.z=n*c+this.z*h,this},setFromUnitVectors:(de=1e-6,function(e,t){return void 0===he&&(he=new ce),(ue=e.dot(t)+1)Math.abs(e.z)?he.set(-e.y,e.x,0):he.set(0,-e.z,e.y)):he.crossVectors(e,t),this.x=he.x,this.y=he.y,this.z=he.z,this.w=ue,this.normalize(),this})};var fe=new pe({widthMeters:.11,heightMeters:.062,bevelMeters:.004}),me=new pe({widthMeters:.1038,heightMeters:.0584,bevelMeters:.004}),ge={CardboardV1:new we({id:"CardboardV1",label:"Cardboard I/O 2014",fov:40,interLensDistance:.06,baselineLensDistance:.035,screenLensDistance:.042,distortionCoefficients:[.441,.156],inverseCoefficients:[-.4410035,.42756155,-.4804439,.5460139,-.58821183,.5733938,-.48303202,.33299083,-.17573841,.0651772,-.01488963,.001559834]}),CardboardV2:new we({id:"CardboardV2",label:"Cardboard I/O 2015",fov:60,interLensDistance:.064,baselineLensDistance:.035,screenLensDistance:.039,distortionCoefficients:[.34,.55],inverseCoefficients:[-.33836704,-.18162185,.862655,-1.2462051,1.0560602,-.58208317,.21609078,-.05444823,.009177956,-.0009904169,6183535e-11,-16981803e-13]})};function ve(e,t){this.viewer=ge.CardboardV2,this.updateDeviceParams(e),this.distortion=new ae(this.viewer.distortionCoefficients);for(var i=0;i=200&&i.status<=299?(r.dpdb=JSON.parse(i.response),r.recalculateDeviceParams_()):console.error("Error loading online DPDB!")})),i.send()}}function Ee(e){this.xdpi=e.xdpi,this.ydpi=e.ydpi,this.bevelMm=e.bevelMm}function xe(e,t){this.set(e,t)}function Me(e,t){this.kFilter=e,this.isDebug=t,this.currentAccelMeasurement=new xe,this.currentGyroMeasurement=new xe,this.previousGyroMeasurement=new xe,f()?this.filterQ=new Ae(-1,0,0,1):this.filterQ=new Ae(1,0,0,1),this.previousFilterQ=new Ae,this.previousFilterQ.copy(this.filterQ),this.accelQ=new Ae,this.isOrientationInitialized=!1,this.estimatedGravity=new ce,this.measuredGravity=new ce,this.gyroIntegralQ=new Ae}function Se(e,t){this.predictionTimeS=e,this.isDebug=t,this.previousQ=new Ae,this.previousTimestampS=null,this.deltaQ=new Ae,this.outQ=new Ae}function _e(e,t,i,r){this.yawOnly=i,this.accelerometer=new ce,this.gyroscope=new ce,this.filter=new Me(e,r),this.posePredictor=new Se(t,r),this.isFirefoxAndroid=v(),this.isIOS=f();var n=w();this.isDeviceMotionInRadians=!this.isIOS&&n&&n<66,this.isWithoutDeviceMotion=b()||y(),this.filterToWorldQ=new Ae,f()?this.filterToWorldQ.setFromAxisAngle(new ce(1,0,0),Math.PI/2):this.filterToWorldQ.setFromAxisAngle(new ce(1,0,0),-Math.PI/2),this.inverseWorldToScreenQ=new Ae,this.worldToScreenQ=new Ae,this.originalPoseAdjustQ=new Ae,this.originalPoseAdjustQ.setFromAxisAngle(new ce(0,0,1),-window.orientation*Math.PI/180),this.setScreenTransform_(),x()&&this.filterToWorldQ.multiply(this.inverseWorldToScreenQ),this.resetQ=new Ae,this.orientationOut_=new Float32Array(4),this.start()}be.prototype.getDeviceParams=function(){return this.deviceParams},be.prototype.recalculateDeviceParams_=function(){var e=this.calcDeviceParams_();e?(this.deviceParams=e,this.onDeviceParamsUpdated&&this.onDeviceParamsUpdated(this.deviceParams)):console.error("Failed to recalculate device parameters.")},be.prototype.calcDeviceParams_=function(){var e=this.dpdb;if(!e)return console.error("DPDB not available."),null;if(1!=e.format)return console.error("DPDB has unexpected format version."),null;if(!e.devices||!e.devices.length)return console.error("DPDB does not have a devices section."),null;var t=navigator.userAgent||navigator.vendor||window.opera,i=S(),r=_();if(!e.devices)return console.error("DPDB has no devices section."),null;for(var n=0;nd?(k("fusion-pose-sensor:invalid:outside-threshold","Invalid timestamps detected: Timestamp from devicemotion outside expected range."),void(this.previousTimestampS=r)):(this.accelerometer.set(-t.x,-t.y,-t.z),i&&(E()?this.gyroscope.set(-i.beta,i.alpha,i.gamma):this.gyroscope.set(i.alpha,i.beta,i.gamma),this.isDeviceMotionInRadians||this.gyroscope.multiplyScalar(Math.PI/180),this.filter.addGyroMeasurement(this.gyroscope,r)),this.filter.addAccelMeasurement(this.accelerometer,r),void(this.previousTimestampS=r))},_e.prototype.onOrientationChange_=function(e){this.setScreenTransform_()},_e.prototype.onMessage_=function(e){var t=e.data;t&&t.type&&"devicemotion"===t.type.toLowerCase()&&this.updateDeviceMotion_(t.deviceMotionEvent)},_e.prototype.setScreenTransform_=function(){switch(this.worldToScreenQ.set(0,0,0,1),window.orientation){case 0:break;case 90:this.worldToScreenQ.setFromAxisAngle(new ce(0,0,1),-Math.PI/2);break;case-90:this.worldToScreenQ.setFromAxisAngle(new ce(0,0,1),Math.PI/2)}this.inverseWorldToScreenQ.copy(this.worldToScreenQ),this.inverseWorldToScreenQ.inverse()},_e.prototype.start=function(){this.onDeviceMotionCallback_=this.onDeviceMotion_.bind(this),this.onOrientationChangeCallback_=this.onOrientationChange_.bind(this),this.onMessageCallback_=this.onMessage_.bind(this),this.onDeviceOrientationCallback_=this.onDeviceOrientation_.bind(this),f()&&N()&&window.addEventListener("message",this.onMessageCallback_),window.addEventListener("orientationchange",this.onOrientationChangeCallback_),this.isWithoutDeviceMotion?window.addEventListener("deviceorientation",this.onDeviceOrientationCallback_):window.addEventListener("devicemotion",this.onDeviceMotionCallback_)},_e.prototype.stop=function(){window.removeEventListener("devicemotion",this.onDeviceMotionCallback_),window.removeEventListener("deviceorientation",this.onDeviceOrientationCallback_),window.removeEventListener("orientationchange",this.onOrientationChangeCallback_),window.removeEventListener("message",this.onMessageCallback_)};var Re=60,Fe=new ce(1,0,0),Pe=new ce(0,0,1),Ce=new Ae;Ce.setFromAxisAngle(Fe,-Math.PI/2),Ce.multiply((new Ae).setFromAxisAngle(Pe,Math.PI/2));var Be=function(){function e(t){l(this,e),this.config=t,this.sensor=null,this.fusionSensor=null,this._out=new Float32Array(4),this.api=null,this.errors=[],this._sensorQ=new Ae,this._outQ=new Ae,this._onSensorRead=this._onSensorRead.bind(this),this._onSensorError=this._onSensorError.bind(this),this.init()}return c(e,[{key:"init",value:function(){var e=null;try{(e=new RelativeOrientationSensor({frequency:Re,referenceFrame:"screen"})).addEventListener("error",this._onSensorError)}catch(e){this.errors.push(e),"SecurityError"===e.name?(console.error("Cannot construct sensors due to the Feature Policy"),console.warn('Attempting to fall back using "devicemotion"; however this will fail in the future without correct permissions.'),this.useDeviceMotion()):"ReferenceError"===e.name?this.useDeviceMotion():console.error(e)}e&&(this.api="sensor",this.sensor=e,this.sensor.addEventListener("reading",this._onSensorRead),this.sensor.start())}},{key:"useDeviceMotion",value:function(){this.api="devicemotion",this.fusionSensor=new _e(this.config.K_FILTER,this.config.PREDICTION_TIME_S,this.config.YAW_ONLY,this.config.DEBUG),this.sensor&&(this.sensor.removeEventListener("reading",this._onSensorRead),this.sensor.removeEventListener("error",this._onSensorError),this.sensor=null)}},{key:"getOrientation",value:function(){if(this.fusionSensor)return this.fusionSensor.getOrientation();if(!this.sensor||!this.sensor.quaternion)return this._out[0]=this._out[1]=this._out[2]=0,this._out[3]=1,this._out;var e=this.sensor.quaternion;this._sensorQ.set(e[0],e[1],e[2],e[3]);var t=this._outQ;return t.copy(Ce),t.multiply(this._sensorQ),this.config.YAW_ONLY&&(t.x=t.z=0,t.normalize()),this._out[0]=t.x,this._out[1]=t.y,this._out[2]=t.z,this._out[3]=t.w,this._out}},{key:"_onSensorError",value:function(e){this.errors.push(e.error),"NotAllowedError"===e.error.name?console.error("Permission to access sensor was denied"):"NotReadableError"===e.error.name?console.error("Sensor could not be read"):console.error(e.error),this.useDeviceMotion()}},{key:"_onSensorRead",value:function(){}}]),e}(),De="";function Ie(){this.loadIcon_();var e=document.createElement("div");(s=e.style).position="fixed",s.top=0,s.right=0,s.bottom=0,s.left=0,s.backgroundColor="gray",s.fontFamily="sans-serif",s.zIndex=1e6;var t=document.createElement("img");t.src=this.icon,(s=t.style).marginLeft="25%",s.marginTop="25%",s.width="50%",e.appendChild(t);var i=document.createElement("div");(s=i.style).textAlign="center",s.fontSize="16px",s.lineHeight="24px",s.margin="24px 25%",s.width="50%",i.innerHTML="Place your phone into your Cardboard viewer.",e.appendChild(i);var r=document.createElement("div");(s=r.style).backgroundColor="#CFD8DC",s.position="fixed",s.bottom=0,s.width="100%",s.height="48px",s.padding="14px 24px",s.boxSizing="border-box",s.color="#656A6B",e.appendChild(r);var n=document.createElement("div");n.style.float="left",n.innerHTML="No Cardboard viewer?";var s,a=document.createElement("a");a.href="https://www.google.com/get/cardboard/get-cardboard/",a.innerHTML="get one",a.target="_blank",(s=a.style).float="right",s.fontWeight=600,s.textTransform="uppercase",s.borderLeft="1px solid gray",s.paddingLeft="24px",s.textDecoration="none",s.color="#656A6B",r.appendChild(n),r.appendChild(a),this.overlay=e,this.text=i,this.hide()}Ie.prototype.show=function(e){e||this.overlay.parentElement?e&&(this.overlay.parentElement&&this.overlay.parentElement!=e&&this.overlay.parentElement.removeChild(this.overlay),e.appendChild(this.overlay)):document.body.appendChild(this.overlay),this.overlay.style.display="block";var t=this.overlay.querySelector("img").style;x()?(t.width="20%",t.marginLeft="40%",t.marginTop="3%"):(t.width="50%",t.marginLeft="25%",t.marginTop="25%")},Ie.prototype.hide=function(){this.overlay.style.display="none"},Ie.prototype.showTemporarily=function(e,t){this.show(t),this.timer=setTimeout(this.hide.bind(this),e)},Ie.prototype.disableShowTemporarily=function(){clearTimeout(this.timer)},Ie.prototype.update=function(){this.disableShowTemporarily(),!x()&&D()?this.show():this.hide()},Ie.prototype.loadIcon_=function(){this.icon=A("image/svg+xml",De)};var Le="CardboardV1",Oe="WEBVR_CARDBOARD_VIEWER",Ne="webvr-polyfill-viewer-selector";function Ge(e){try{this.selectedKey=localStorage.getItem(Oe)}catch(e){console.error("Failed to load viewer profile: %s",e)}this.selectedKey||(this.selectedKey=e||Le),this.dialog=this.createDialog_(ve.Viewers),this.root=null,this.onChangeCallbacks_=[]}function Ve(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ke(e,t){return e(t={exports:{}},t.exports),t.exports}Ge.prototype.show=function(e){this.root=e,e.appendChild(this.dialog),this.dialog.querySelector("#"+this.selectedKey).checked=!0,this.dialog.style.display="block"},Ge.prototype.hide=function(){this.root&&this.root.contains(this.dialog)&&this.root.removeChild(this.dialog),this.dialog.style.display="none"},Ge.prototype.getCurrentViewer=function(){return ve.Viewers[this.selectedKey]},Ge.prototype.getSelectedKey_=function(){var e=this.dialog.querySelector("input[name=field]:checked");return e?e.id:null},Ge.prototype.onChange=function(e){this.onChangeCallbacks_.push(e)},Ge.prototype.fireOnChange_=function(e){for(var t=0;t.5&&(this.noSleepVideo.currentTime=Math.random())}.bind(this)))}return r(e,[{key:"enable",value:function(){a?(this.disable(),this.noSleepTimer=window.setInterval((function(){window.location.href="/",window.setTimeout(window.stop,0)}),15e3)):this.noSleepVideo.play()}},{key:"disable",value:function(){a?this.noSleepTimer&&(window.clearInterval(this.noSleepTimer),this.noSleepTimer=null):this.noSleepVideo.pause()}}]),e}();e.exports=o},function(e,t,i){e.exports="data:video/mp4;base64,AAAAIGZ0eXBtcDQyAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAACKBtZGF0AAAC8wYF///v3EXpvebZSLeWLNgg2SPu73gyNjQgLSBjb3JlIDE0MiByMjQ3OSBkZDc5YTYxIC0gSC4yNjQvTVBFRy00IEFWQyBjb2RlYyAtIENvcHlsZWZ0IDIwMDMtMjAxNCAtIGh0dHA6Ly93d3cudmlkZW9sYW4ub3JnL3gyNjQuaHRtbCAtIG9wdGlvbnM6IGNhYmFjPTEgcmVmPTEgZGVibG9jaz0xOjA6MCBhbmFseXNlPTB4MToweDExMSBtZT1oZXggc3VibWU9MiBwc3k9MSBwc3lfcmQ9MS4wMDowLjAwIG1peGVkX3JlZj0wIG1lX3JhbmdlPTE2IGNocm9tYV9tZT0xIHRyZWxsaXM9MCA4eDhkY3Q9MCBjcW09MCBkZWFkem9uZT0yMSwxMSBmYXN0X3Bza2lwPTEgY2hyb21hX3FwX29mZnNldD0wIHRocmVhZHM9NiBsb29rYWhlYWRfdGhyZWFkcz0xIHNsaWNlZF90aHJlYWRzPTAgbnI9MCBkZWNpbWF0ZT0xIGludGVybGFjZWQ9MCBibHVyYXlfY29tcGF0PTAgY29uc3RyYWluZWRfaW50cmE9MCBiZnJhbWVzPTMgYl9weXJhbWlkPTIgYl9hZGFwdD0xIGJfYmlhcz0wIGRpcmVjdD0xIHdlaWdodGI9MSBvcGVuX2dvcD0wIHdlaWdodHA9MSBrZXlpbnQ9MzAwIGtleWludF9taW49MzAgc2NlbmVjdXQ9NDAgaW50cmFfcmVmcmVzaD0wIHJjX2xvb2thaGVhZD0xMCByYz1jcmYgbWJ0cmVlPTEgY3JmPTIwLjAgcWNvbXA9MC42MCBxcG1pbj0wIHFwbWF4PTY5IHFwc3RlcD00IHZidl9tYXhyYXRlPTIwMDAwIHZidl9idWZzaXplPTI1MDAwIGNyZl9tYXg9MC4wIG5hbF9ocmQ9bm9uZSBmaWxsZXI9MCBpcF9yYXRpbz0xLjQwIGFxPTE6MS4wMACAAAAAOWWIhAA3//p+C7v8tDDSTjf97w55i3SbRPO4ZY+hkjD5hbkAkL3zpJ6h/LR1CAABzgB1kqqzUorlhQAAAAxBmiQYhn/+qZYADLgAAAAJQZ5CQhX/AAj5IQADQGgcIQADQGgcAAAACQGeYUQn/wALKCEAA0BoHAAAAAkBnmNEJ/8ACykhAANAaBwhAANAaBwAAAANQZpoNExDP/6plgAMuSEAA0BoHAAAAAtBnoZFESwr/wAI+SEAA0BoHCEAA0BoHAAAAAkBnqVEJ/8ACykhAANAaBwAAAAJAZ6nRCf/AAsoIQADQGgcIQADQGgcAAAADUGarDRMQz/+qZYADLghAANAaBwAAAALQZ7KRRUsK/8ACPkhAANAaBwAAAAJAZ7pRCf/AAsoIQADQGgcIQADQGgcAAAACQGe60Qn/wALKCEAA0BoHAAAAA1BmvA0TEM//qmWAAy5IQADQGgcIQADQGgcAAAAC0GfDkUVLCv/AAj5IQADQGgcAAAACQGfLUQn/wALKSEAA0BoHCEAA0BoHAAAAAkBny9EJ/8ACyghAANAaBwAAAANQZs0NExDP/6plgAMuCEAA0BoHAAAAAtBn1JFFSwr/wAI+SEAA0BoHCEAA0BoHAAAAAkBn3FEJ/8ACyghAANAaBwAAAAJAZ9zRCf/AAsoIQADQGgcIQADQGgcAAAADUGbeDRMQz/+qZYADLkhAANAaBwAAAALQZ+WRRUsK/8ACPghAANAaBwhAANAaBwAAAAJAZ+1RCf/AAspIQADQGgcAAAACQGft0Qn/wALKSEAA0BoHCEAA0BoHAAAAA1Bm7w0TEM//qmWAAy4IQADQGgcAAAAC0Gf2kUVLCv/AAj5IQADQGgcAAAACQGf+UQn/wALKCEAA0BoHCEAA0BoHAAAAAkBn/tEJ/8ACykhAANAaBwAAAANQZvgNExDP/6plgAMuSEAA0BoHCEAA0BoHAAAAAtBnh5FFSwr/wAI+CEAA0BoHAAAAAkBnj1EJ/8ACyghAANAaBwhAANAaBwAAAAJAZ4/RCf/AAspIQADQGgcAAAADUGaJDRMQz/+qZYADLghAANAaBwAAAALQZ5CRRUsK/8ACPkhAANAaBwhAANAaBwAAAAJAZ5hRCf/AAsoIQADQGgcAAAACQGeY0Qn/wALKSEAA0BoHCEAA0BoHAAAAA1Bmmg0TEM//qmWAAy5IQADQGgcAAAAC0GehkUVLCv/AAj5IQADQGgcIQADQGgcAAAACQGepUQn/wALKSEAA0BoHAAAAAkBnqdEJ/8ACyghAANAaBwAAAANQZqsNExDP/6plgAMuCEAA0BoHCEAA0BoHAAAAAtBnspFFSwr/wAI+SEAA0BoHAAAAAkBnulEJ/8ACyghAANAaBwhAANAaBwAAAAJAZ7rRCf/AAsoIQADQGgcAAAADUGa8DRMQz/+qZYADLkhAANAaBwhAANAaBwAAAALQZ8ORRUsK/8ACPkhAANAaBwAAAAJAZ8tRCf/AAspIQADQGgcIQADQGgcAAAACQGfL0Qn/wALKCEAA0BoHAAAAA1BmzQ0TEM//qmWAAy4IQADQGgcAAAAC0GfUkUVLCv/AAj5IQADQGgcIQADQGgcAAAACQGfcUQn/wALKCEAA0BoHAAAAAkBn3NEJ/8ACyghAANAaBwhAANAaBwAAAANQZt4NExC//6plgAMuSEAA0BoHAAAAAtBn5ZFFSwr/wAI+CEAA0BoHCEAA0BoHAAAAAkBn7VEJ/8ACykhAANAaBwAAAAJAZ+3RCf/AAspIQADQGgcAAAADUGbuzRMQn/+nhAAYsAhAANAaBwhAANAaBwAAAAJQZ/aQhP/AAspIQADQGgcAAAACQGf+UQn/wALKCEAA0BoHCEAA0BoHCEAA0BoHCEAA0BoHCEAA0BoHCEAA0BoHAAACiFtb292AAAAbG12aGQAAAAA1YCCX9WAgl8AAAPoAAAH/AABAAABAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAGGlvZHMAAAAAEICAgAcAT////v7/AAAF+XRyYWsAAABcdGtoZAAAAAPVgIJf1YCCXwAAAAEAAAAAAAAH0AAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAygAAAMoAAAAAACRlZHRzAAAAHGVsc3QAAAAAAAAAAQAAB9AAABdwAAEAAAAABXFtZGlhAAAAIG1kaGQAAAAA1YCCX9WAgl8AAV+QAAK/IFXEAAAAAAAtaGRscgAAAAAAAAAAdmlkZQAAAAAAAAAAAAAAAFZpZGVvSGFuZGxlcgAAAAUcbWluZgAAABR2bWhkAAAAAQAAAAAAAAAAAAAAJGRpbmYAAAAcZHJlZgAAAAAAAAABAAAADHVybCAAAAABAAAE3HN0YmwAAACYc3RzZAAAAAAAAAABAAAAiGF2YzEAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAygDKAEgAAABIAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY//8AAAAyYXZjQwFNQCj/4QAbZ01AKOyho3ySTUBAQFAAAAMAEAAr8gDxgxlgAQAEaO+G8gAAABhzdHRzAAAAAAAAAAEAAAA8AAALuAAAABRzdHNzAAAAAAAAAAEAAAABAAAB8GN0dHMAAAAAAAAAPAAAAAEAABdwAAAAAQAAOpgAAAABAAAXcAAAAAEAAAAAAAAAAQAAC7gAAAABAAA6mAAAAAEAABdwAAAAAQAAAAAAAAABAAALuAAAAAEAADqYAAAAAQAAF3AAAAABAAAAAAAAAAEAAAu4AAAAAQAAOpgAAAABAAAXcAAAAAEAAAAAAAAAAQAAC7gAAAABAAA6mAAAAAEAABdwAAAAAQAAAAAAAAABAAALuAAAAAEAADqYAAAAAQAAF3AAAAABAAAAAAAAAAEAAAu4AAAAAQAAOpgAAAABAAAXcAAAAAEAAAAAAAAAAQAAC7gAAAABAAA6mAAAAAEAABdwAAAAAQAAAAAAAAABAAALuAAAAAEAADqYAAAAAQAAF3AAAAABAAAAAAAAAAEAAAu4AAAAAQAAOpgAAAABAAAXcAAAAAEAAAAAAAAAAQAAC7gAAAABAAA6mAAAAAEAABdwAAAAAQAAAAAAAAABAAALuAAAAAEAADqYAAAAAQAAF3AAAAABAAAAAAAAAAEAAAu4AAAAAQAAOpgAAAABAAAXcAAAAAEAAAAAAAAAAQAAC7gAAAABAAA6mAAAAAEAABdwAAAAAQAAAAAAAAABAAALuAAAAAEAAC7gAAAAAQAAF3AAAAABAAAAAAAAABxzdHNjAAAAAAAAAAEAAAABAAAAAQAAAAEAAAEEc3RzegAAAAAAAAAAAAAAPAAAAzQAAAAQAAAADQAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAAPAAAADQAAAA0AAAARAAAADwAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAAPAAAADQAAAA0AAAARAAAADwAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAAPAAAADQAAAA0AAAARAAAADwAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAAPAAAADQAAAA0AAAARAAAADwAAAA0AAAANAAAAEQAAAA8AAAANAAAADQAAABEAAAANAAAADQAAAQBzdGNvAAAAAAAAADwAAAAwAAADZAAAA3QAAAONAAADoAAAA7kAAAPQAAAD6wAAA/4AAAQXAAAELgAABEMAAARcAAAEbwAABIwAAAShAAAEugAABM0AAATkAAAE/wAABRIAAAUrAAAFQgAABV0AAAVwAAAFiQAABaAAAAW1AAAFzgAABeEAAAX+AAAGEwAABiwAAAY/AAAGVgAABnEAAAaEAAAGnQAABrQAAAbPAAAG4gAABvUAAAcSAAAHJwAAB0AAAAdTAAAHcAAAB4UAAAeeAAAHsQAAB8gAAAfjAAAH9gAACA8AAAgmAAAIQQAACFQAAAhnAAAIhAAACJcAAAMsdHJhawAAAFx0a2hkAAAAA9WAgl/VgIJfAAAAAgAAAAAAAAf8AAAAAAAAAAAAAAABAQAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAACsm1kaWEAAAAgbWRoZAAAAADVgIJf1YCCXwAArEQAAWAAVcQAAAAAACdoZGxyAAAAAAAAAABzb3VuAAAAAAAAAAAAAAAAU3RlcmVvAAAAAmNtaW5mAAAAEHNtaGQAAAAAAAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAAAQAAAAx1cmwgAAAAAQAAAidzdGJsAAAAZ3N0c2QAAAAAAAAAAQAAAFdtcDRhAAAAAAAAAAEAAAAAAAAAAAACABAAAAAArEQAAAAAADNlc2RzAAAAAAOAgIAiAAIABICAgBRAFQAAAAADDUAAAAAABYCAgAISEAaAgIABAgAAABhzdHRzAAAAAAAAAAEAAABYAAAEAAAAABxzdHNjAAAAAAAAAAEAAAABAAAAAQAAAAEAAAAUc3RzegAAAAAAAAAGAAAAWAAAAXBzdGNvAAAAAAAAAFgAAAOBAAADhwAAA5oAAAOtAAADswAAA8oAAAPfAAAD5QAAA/gAAAQLAAAEEQAABCgAAAQ9AAAEUAAABFYAAARpAAAEgAAABIYAAASbAAAErgAABLQAAATHAAAE3gAABPMAAAT5AAAFDAAABR8AAAUlAAAFPAAABVEAAAVXAAAFagAABX0AAAWDAAAFmgAABa8AAAXCAAAFyAAABdsAAAXyAAAF+AAABg0AAAYgAAAGJgAABjkAAAZQAAAGZQAABmsAAAZ+AAAGkQAABpcAAAauAAAGwwAABskAAAbcAAAG7wAABwYAAAcMAAAHIQAABzQAAAc6AAAHTQAAB2QAAAdqAAAHfwAAB5IAAAeYAAAHqwAAB8IAAAfXAAAH3QAAB/AAAAgDAAAICQAACCAAAAg1AAAIOwAACE4AAAhhAAAIeAAACH4AAAiRAAAIpAAACKoAAAiwAAAItgAACLwAAAjCAAAAFnVkdGEAAAAObmFtZVN0ZXJlbwAAAHB1ZHRhAAAAaG1ldGEAAAAAAAAAIWhkbHIAAAAAAAAAAG1kaXJhcHBsAAAAAAAAAAAAAAAAO2lsc3QAAAAzqXRvbwAAACtkYXRhAAAAAQAAAABIYW5kQnJha2UgMC4xMC4yIDIwMTUwNjExMDA="}])}))})),Qe=Ve(ze),Ue=1e3,Xe=[0,0,.5,1],He=[.5,0,.5,1],We=window.requestAnimationFrame,qe=window.cancelAnimationFrame;function je(){this.leftProjectionMatrix=new Float32Array(16),this.leftViewMatrix=new Float32Array(16),this.rightProjectionMatrix=new Float32Array(16),this.rightViewMatrix=new Float32Array(16),this.pose=null}function Ye(e){Object.defineProperties(this,{hasPosition:{writable:!1,enumerable:!0,value:e.hasPosition},hasExternalDisplay:{writable:!1,enumerable:!0,value:e.hasExternalDisplay},canPresent:{writable:!1,enumerable:!0,value:e.canPresent},maxLayers:{writable:!1,enumerable:!0,value:e.maxLayers},hasOrientation:{enumerable:!0,get:function(){return z("VRDisplayCapabilities.prototype.hasOrientation","VRDisplay.prototype.getFrameData"),e.hasOrientation}}})}function Ze(e){var t=!("wakelock"in(e=e||{}))||e.wakelock;this.isPolyfilled=!0,this.displayId=Ue++,this.displayName="",this.depthNear=.01,this.depthFar=1e4,this.isPresenting=!1,Object.defineProperty(this,"isConnected",{get:function(){return z("VRDisplay.prototype.isConnected","VRDisplayCapabilities.prototype.hasExternalDisplay"),!1}}),this.capabilities=new Ye({hasPosition:!1,hasOrientation:!1,hasExternalDisplay:!1,canPresent:!1,maxLayers:1}),this.stageParameters=null,this.waitingForPresent_=!1,this.layer_=null,this.originalParent_=null,this.fullscreenElement_=null,this.fullscreenWrapper_=null,this.fullscreenElementCachedStyle_=null,this.fullscreenEventTarget_=null,this.fullscreenChangeHandler_=null,this.fullscreenErrorHandler_=null,t&&D()&&(this.wakelock_=new Qe)}Ze.prototype.getFrameData=function(e){return O(e,this._getPose(),this)},Ze.prototype.getPose=function(){return z("VRDisplay.prototype.getPose","VRDisplay.prototype.getFrameData"),this._getPose()},Ze.prototype.resetPose=function(){return z("VRDisplay.prototype.resetPose"),this._resetPose()},Ze.prototype.getImmediatePose=function(){return z("VRDisplay.prototype.getImmediatePose","VRDisplay.prototype.getFrameData"),this._getPose()},Ze.prototype.requestAnimationFrame=function(e){return We(e)},Ze.prototype.cancelAnimationFrame=function(e){return qe(e)},Ze.prototype.wrapForFullscreen=function(e){if(f())return e;if(!this.fullscreenWrapper_){this.fullscreenWrapper_=document.createElement("div");var t=["height: "+Math.min(screen.height,screen.width)+"px !important","top: 0 !important","left: 0 !important","right: 0 !important","border: 0","margin: 0","padding: 0","z-index: 999999 !important","position: fixed"];this.fullscreenWrapper_.setAttribute("style",t.join("; ")+";"),this.fullscreenWrapper_.classList.add("webvr-polyfill-fullscreen-wrapper")}if(this.fullscreenElement_==e)return this.fullscreenWrapper_;if(this.fullscreenElement_&&(this.originalParent_?this.originalParent_.appendChild(this.fullscreenElement_):this.fullscreenElement_.parentElement.removeChild(this.fullscreenElement_)),this.fullscreenElement_=e,this.originalParent_=e.parentElement,this.originalParent_||document.body.appendChild(e),!this.fullscreenWrapper_.parentElement){var i=this.fullscreenElement_.parentElement;i.insertBefore(this.fullscreenWrapper_,this.fullscreenElement_),i.removeChild(this.fullscreenElement_)}this.fullscreenWrapper_.insertBefore(this.fullscreenElement_,this.fullscreenWrapper_.firstChild),this.fullscreenElementCachedStyle_=this.fullscreenElement_.getAttribute("style");var r=this;function n(){if(r.fullscreenElement_){var e=["position: absolute","top: 0","left: 0","width: "+Math.max(screen.width,screen.height)+"px","height: "+Math.min(screen.height,screen.width)+"px","border: 0","margin: 0","padding: 0"];r.fullscreenElement_.setAttribute("style",e.join("; ")+";")}}return n(),this.fullscreenWrapper_},Ze.prototype.removeFullscreenWrapper=function(){if(this.fullscreenElement_){var e=this.fullscreenElement_;this.fullscreenElementCachedStyle_?e.setAttribute("style",this.fullscreenElementCachedStyle_):e.removeAttribute("style"),this.fullscreenElement_=null,this.fullscreenElementCachedStyle_=null;var t=this.fullscreenWrapper_.parentElement;return this.fullscreenWrapper_.removeChild(e),this.originalParent_===t?t.insertBefore(e,this.fullscreenWrapper_):this.originalParent_&&this.originalParent_.appendChild(e),t.removeChild(this.fullscreenWrapper_),e}},Ze.prototype.requestPresent=function(e){var t=this.isPresenting,i=this;return e instanceof Array||(z("VRDisplay.prototype.requestPresent with non-array argument","an array of VRLayers as the first argument"),e=[e]),new Promise((function(r,n){if(i.capabilities.canPresent)if(0==e.length||e.length>i.capabilities.maxLayers)n(new Error("Invalid number of layers."));else{var s=e[0];if(s.source){var a=s.leftBounds||Xe,o=s.rightBounds||He;if(t){var l=i.layer_;l.source!==s.source&&(l.source=s.source);for(var c=0;c<4;c++)l.leftBounds[c]=a[c],l.rightBounds[c]=o[c];return i.wrapForFullscreen(i.layer_.source),i.updatePresent_(),void r()}if(i.layer_={predistorted:s.predistorted,source:s.source,leftBounds:a.slice(0),rightBounds:o.slice(0)},i.waitingForPresent_=!1,i.layer_&&i.layer_.source){var h=i.wrapForFullscreen(i.layer_.source),u=function(){var e=T();i.isPresenting=h===e,i.isPresenting?(screen.orientation&&screen.orientation.lock&&screen.orientation.lock("landscape-primary").catch((function(e){console.error("screen.orientation.lock() failed due to",e.message)})),i.waitingForPresent_=!1,i.beginPresent_(),r()):(screen.orientation&&screen.orientation.unlock&&screen.orientation.unlock(),i.removeFullscreenWrapper(),i.disableWakeLock(),i.endPresent_(),i.removeFullscreenListeners_()),i.fireVRDisplayPresentChange_()},d=function(){i.waitingForPresent_&&(i.removeFullscreenWrapper(),i.removeFullscreenListeners_(),i.disableWakeLock(),i.waitingForPresent_=!1,i.isPresenting=!1,n(new Error("Unable to present.")))};i.addFullscreenListeners_(h,u,d),R(h)?(i.enableWakeLock(),i.waitingForPresent_=!0):(f()||m())&&(i.enableWakeLock(),i.isPresenting=!0,i.beginPresent_(),i.fireVRDisplayPresentChange_(),r())}i.waitingForPresent_||f()||(F(),n(new Error("Unable to present.")))}else r()}else n(new Error("VRDisplay is not capable of presenting."))}))},Ze.prototype.exitPresent=function(){var e=this.isPresenting,t=this;return this.isPresenting=!1,this.layer_=null,this.disableWakeLock(),new Promise((function(i,r){e?(!F()&&f()&&(t.endPresent_(),t.fireVRDisplayPresentChange_()),m()&&(t.removeFullscreenWrapper(),t.removeFullscreenListeners_(),t.endPresent_(),t.fireVRDisplayPresentChange_()),i()):r(new Error("Was not presenting to VRDisplay."))}))},Ze.prototype.getLayers=function(){return this.layer_?[this.layer_]:[]},Ze.prototype.fireVRDisplayPresentChange_=function(){var e=new CustomEvent("vrdisplaypresentchange",{detail:{display:this}});window.dispatchEvent(e)},Ze.prototype.fireVRDisplayConnect_=function(){var e=new CustomEvent("vrdisplayconnect",{detail:{display:this}});window.dispatchEvent(e)},Ze.prototype.addFullscreenListeners_=function(e,t,i){this.removeFullscreenListeners_(),this.fullscreenEventTarget_=e,this.fullscreenChangeHandler_=t,this.fullscreenErrorHandler_=i,t&&(document.fullscreenEnabled?e.addEventListener("fullscreenchange",t,!1):document.webkitFullscreenEnabled?e.addEventListener("webkitfullscreenchange",t,!1):document.mozFullScreenEnabled?document.addEventListener("mozfullscreenchange",t,!1):document.msFullscreenEnabled&&e.addEventListener("msfullscreenchange",t,!1)),i&&(document.fullscreenEnabled?e.addEventListener("fullscreenerror",i,!1):document.webkitFullscreenEnabled?e.addEventListener("webkitfullscreenerror",i,!1):document.mozFullScreenEnabled?document.addEventListener("mozfullscreenerror",i,!1):document.msFullscreenEnabled&&e.addEventListener("msfullscreenerror",i,!1))},Ze.prototype.removeFullscreenListeners_=function(){if(this.fullscreenEventTarget_){var e=this.fullscreenEventTarget_;if(this.fullscreenChangeHandler_){var t=this.fullscreenChangeHandler_;e.removeEventListener("fullscreenchange",t,!1),e.removeEventListener("webkitfullscreenchange",t,!1),document.removeEventListener("mozfullscreenchange",t,!1),e.removeEventListener("msfullscreenchange",t,!1)}if(this.fullscreenErrorHandler_){var i=this.fullscreenErrorHandler_;e.removeEventListener("fullscreenerror",i,!1),e.removeEventListener("webkitfullscreenerror",i,!1),document.removeEventListener("mozfullscreenerror",i,!1),e.removeEventListener("msfullscreenerror",i,!1)}this.fullscreenEventTarget_=null,this.fullscreenChangeHandler_=null,this.fullscreenErrorHandler_=null}},Ze.prototype.enableWakeLock=function(){this.wakelock_&&this.wakelock_.enable()},Ze.prototype.disableWakeLock=function(){this.wakelock_&&this.wakelock_.disable()},Ze.prototype.beginPresent_=function(){},Ze.prototype.endPresent_=function(){},Ze.prototype.submitFrame=function(e){},Ze.prototype.getEyeParameters=function(e){return null};var $e={ADDITIONAL_VIEWERS:[],DEFAULT_VIEWER:"",MOBILE_WAKE_LOCK:!0,DEBUG:!1,DPDB_URL:"https://dpdb.webvr.rocks/dpdb.json",K_FILTER:.98,PREDICTION_TIME_S:.04,CARDBOARD_UI_DISABLED:!1,ROTATE_INSTRUCTIONS_DISABLED:!1,YAW_ONLY:!1,BUFFER_SCALE:.5,DIRTY_SUBMIT_FRAME_BINDINGS:!1},Ke={LEFT:"left",RIGHT:"right"};function Je(e){var t=I({},$e);e=I(t,e||{}),Ze.call(this,{wakelock:e.MOBILE_WAKE_LOCK}),this.config=e,this.displayName="Cardboard VRDisplay",this.capabilities=new Ye({hasPosition:!1,hasOrientation:!0,hasExternalDisplay:!1,canPresent:!0,maxLayers:1}),this.stageParameters=null,this.bufferScale_=this.config.BUFFER_SCALE,this.poseSensor_=new Be(this.config),this.distorter_=null,this.cardboardUI_=null,this.dpdb_=new be(this.config.DPDB_URL,this.onDeviceParamsUpdated_.bind(this)),this.deviceInfo_=new ve(this.dpdb_.getDeviceParams(),e.ADDITIONAL_VIEWERS),this.viewerSelector_=new Ge(e.DEFAULT_VIEWER),this.viewerSelector_.onChange(this.onViewerChanged_.bind(this)),this.deviceInfo_.setViewer(this.viewerSelector_.getCurrentViewer()),this.config.ROTATE_INSTRUCTIONS_DISABLED||(this.rotateInstructions_=new Ie),f()&&window.addEventListener("resize",this.onResize_.bind(this))}return Je.prototype=Object.create(Ze.prototype),Je.prototype._getPose=function(){return{position:null,orientation:this.poseSensor_.getOrientation(),linearVelocity:null,linearAcceleration:null,angularVelocity:null,angularAcceleration:null}},Je.prototype._resetPose=function(){this.poseSensor_.resetPose&&this.poseSensor_.resetPose()},Je.prototype._getFieldOfView=function(e){var t;if(e==Ke.LEFT)t=this.deviceInfo_.getFieldOfViewLeftEye();else{if(e!=Ke.RIGHT)return console.error("Invalid eye provided: %s",e),null;t=this.deviceInfo_.getFieldOfViewRightEye()}return t},Je.prototype._getEyeOffset=function(e){var t;if(e==Ke.LEFT)t=[.5*-this.deviceInfo_.viewer.interLensDistance,0,0];else{if(e!=Ke.RIGHT)return console.error("Invalid eye provided: %s",e),null;t=[.5*this.deviceInfo_.viewer.interLensDistance,0,0]}return t},Je.prototype.getEyeParameters=function(e){var t=this._getEyeOffset(e),i=this._getFieldOfView(e),r={offset:t,renderWidth:.5*this.deviceInfo_.device.width*this.bufferScale_,renderHeight:this.deviceInfo_.device.height*this.bufferScale_};return Object.defineProperty(r,"fieldOfView",{enumerable:!0,get:function(){return z("VRFieldOfView","VRFrameData's projection matrices"),i}}),r},Je.prototype.onDeviceParamsUpdated_=function(e){this.config.DEBUG&&console.log("DPDB reported that device params were updated."),this.deviceInfo_.updateDeviceParams(e),this.distorter_&&this.distorter_.updateDeviceInfo(this.deviceInfo_)},Je.prototype.updateBounds_=function(){this.layer_&&this.distorter_&&(this.layer_.leftBounds||this.layer_.rightBounds)&&this.distorter_.setTextureBounds(this.layer_.leftBounds,this.layer_.rightBounds)},Je.prototype.beginPresent_=function(){var e=this.layer_.source.getContext("webgl");e||(e=this.layer_.source.getContext("experimental-webgl")),e||(e=this.layer_.source.getContext("webgl2")),e&&(this.layer_.predistorted?this.config.CARDBOARD_UI_DISABLED||(e.canvas.width=S()*this.bufferScale_,e.canvas.height=_()*this.bufferScale_,this.cardboardUI_=new se(e)):(this.config.CARDBOARD_UI_DISABLED||(this.cardboardUI_=new se(e)),this.distorter_=new W(e,this.cardboardUI_,this.config.BUFFER_SCALE,this.config.DIRTY_SUBMIT_FRAME_BINDINGS),this.distorter_.updateDeviceInfo(this.deviceInfo_)),this.cardboardUI_&&this.cardboardUI_.listen(function(e){this.viewerSelector_.show(this.layer_.source.parentElement),e.stopPropagation(),e.preventDefault()}.bind(this),function(e){this.exitPresent(),e.stopPropagation(),e.preventDefault()}.bind(this)),this.rotateInstructions_&&(x()&&D()?this.rotateInstructions_.showTemporarily(3e3,this.layer_.source.parentElement):this.rotateInstructions_.update()),this.orientationHandler=this.onOrientationChange_.bind(this),window.addEventListener("orientationchange",this.orientationHandler),this.vrdisplaypresentchangeHandler=this.updateBounds_.bind(this),window.addEventListener("vrdisplaypresentchange",this.vrdisplaypresentchangeHandler),this.fireVRDisplayDeviceParamsChange_())},Je.prototype.endPresent_=function(){this.distorter_&&(this.distorter_.destroy(),this.distorter_=null),this.cardboardUI_&&(this.cardboardUI_.destroy(),this.cardboardUI_=null),this.rotateInstructions_&&this.rotateInstructions_.hide(),this.viewerSelector_.hide(),window.removeEventListener("orientationchange",this.orientationHandler),window.removeEventListener("vrdisplaypresentchange",this.vrdisplaypresentchangeHandler)},Je.prototype.updatePresent_=function(){this.endPresent_(),this.beginPresent_()},Je.prototype.submitFrame=function(e){if(this.distorter_)this.updateBounds_(),this.distorter_.submitFrame();else if(this.cardboardUI_&&this.layer_){var t=this.layer_.source.getContext("webgl");t||(t=this.layer_.source.getContext("experimental-webgl")),t||(t=this.layer_.source.getContext("webgl2"));var i=t.canvas;i.width==this.lastWidth&&i.height==this.lastHeight||this.cardboardUI_.onResize(),this.lastWidth=i.width,this.lastHeight=i.height,this.cardboardUI_.render()}},Je.prototype.onOrientationChange_=function(e){this.viewerSelector_.hide(),this.rotateInstructions_&&this.rotateInstructions_.update(),this.onResize_()},Je.prototype.onResize_=function(e){if(this.layer_){var t=this.layer_.source.getContext("webgl");t||(t=this.layer_.source.getContext("experimental-webgl")),t||(t=this.layer_.source.getContext("webgl2"));var i=["position: absolute","top: 0","left: 0","width: 100vw","height: 100vh","border: 0","margin: 0","padding: 0px","box-sizing: content-box"];t.canvas.setAttribute("style",i.join("; ")+";"),L(t.canvas)}},Je.prototype.onViewerChanged_=function(e){this.deviceInfo_.setViewer(e),this.distorter_&&this.distorter_.updateDeviceInfo(this.deviceInfo_),this.fireVRDisplayDeviceParamsChange_()},Je.prototype.fireVRDisplayDeviceParamsChange_=function(){var e=new CustomEvent("vrdisplaydeviceparamschange",{detail:{vrdisplay:this,deviceInfo:this.deviceInfo_}});window.dispatchEvent(e)},Je.VRFrameData=je,Je.VRDisplay=Ze,Je}()},Pe(Ce={exports:{}},Ce.exports),Ce.exports),Ie=(Be=De)&&Be.__esModule&&Object.prototype.hasOwnProperty.call(Be,"default")?Be.default:Be;class Le extends a{constructor(e){super(),this.global=e,this.onWindowResize=this.onWindowResize.bind(this),this.global.window.addEventListener("resize",this.onWindowResize),this.environmentBlendMode="opaque"}onBaseLayerSet(e,t){throw new Error("Not implemented")}isSessionSupported(e){throw new Error("Not implemented")}isFeatureSupported(e){throw new Error("Not implemented")}async requestSession(e,t){throw new Error("Not implemented")}requestAnimationFrame(e){throw new Error("Not implemented")}onFrameStart(e){throw new Error("Not implemented")}onFrameEnd(e){throw new Error("Not implemented")}doesSessionSupportReferenceSpace(e,t){throw new Error("Not implemented")}requestStageBounds(){throw new Error("Not implemented")}async requestFrameOfReferenceTransform(e,t){}cancelAnimationFrame(e){throw new Error("Not implemented")}endSession(e){throw new Error("Not implemented")}getViewport(e,t,i,r){throw new Error("Not implemented")}getProjectionMatrix(e){throw new Error("Not implemented")}getBasePoseMatrix(){throw new Error("Not implemented")}getBaseViewMatrix(e){throw new Error("Not implemented")}getInputSources(){throw new Error("Not implemented")}getInputPose(e,t,i){throw new Error("Not implemented")}onWindowResize(){this.onWindowResize()}}let Oe={mapping:"xr-standard",profiles:["oculus-go","generic-trigger-touchpad"],buttons:{length:3,0:1,1:null,2:0},gripTransform:{orientation:[.11*Math.PI,0,0,1]}},Ne={mapping:"xr-standard",displayProfiles:{"Oculus Quest":["oculus-touch-v2","oculus-touch","generic-trigger-squeeze-thumbstick"]},profiles:["oculus-touch","generic-trigger-squeeze-thumbstick"],axes:{length:4,0:null,1:null,2:0,3:1},buttons:{length:7,0:1,1:2,2:null,3:0,4:3,5:4,6:null},gripTransform:{position:[0,-.02,.04,1],orientation:[.11*Math.PI,0,0,1]}},Ge={mapping:"xr-standard",profiles:["htc-vive","generic-trigger-squeeze-touchpad"],displayProfiles:{"HTC Vive":["htc-vive","generic-trigger-squeeze-touchpad"],"HTC Vive DVT":["htc-vive","generic-trigger-squeeze-touchpad"],"Valve Index":["valve-index","generic-trigger-squeeze-touchpad-thumbstick"]},buttons:{length:3,0:1,1:2,2:0},gripTransform:{position:[0,0,.05,1]},targetRayTransform:{orientation:[-.08*Math.PI,0,0,1]},userAgentOverrides:{Firefox:{axes:{invert:[1,3]}}}},Ve={mapping:"xr-standard",profiles:["samsung-gearvr","generic-trigger-touchpad"],buttons:{length:3,0:1,1:null,2:0},gripTransform:{orientation:[.11*Math.PI,0,0,1]}},ke={mapping:"xr-standard",profiles:["samsung-odyssey","microsoft-mixed-reality","generic-trigger-squeeze-touchpad-thumbstick"],buttons:{length:4,0:1,1:0,2:2,3:4},gripTransform:{position:[0,-.02,.04,1],orientation:[.11*Math.PI,0,0,1]}},ze={mapping:"xr-standard",profiles:["microsoft-mixed-reality","generic-trigger-squeeze-touchpad-thumbstick"],buttons:{length:4,0:1,1:0,2:2,3:4},gripTransform:{position:[0,-.02,.04,1],orientation:[.11*Math.PI,0,0,1]}},Qe={"Daydream Controller":{mapping:"",profiles:["google-daydream","generic-trigger-touchpad"],buttons:{length:3,0:null,1:null,2:0}},"Gear VR Controller":Ve,"HTC Vive Focus Controller":{mapping:"xr-standard",profiles:["htc-vive-focus","generic-trigger-touchpad"],buttons:{length:3,0:1,1:null,2:0}},"Oculus Go Controller":Oe,"Oculus Touch (Right)":Ne,"Oculus Touch (Left)":Ne,"OpenVR Gamepad":Ge,"Spatial Controller (Spatial Interaction Source) 045E-065A":ze,"Spatial Controller (Spatial Interaction Source) 045E-065D":ke,"Windows Mixed Reality (Right)":ze,"Windows Mixed Reality (Left)":ze};const Ue=v(.155,-.465,-.15),Xe=v(-.155,-.465,-.15),He=v(0,0,-.25),We=v(0,0,.05),qe=v(-.08,.14,.08),je=180/Math.PI;class Ye{constructor(){this.hand="right",this.headElbowOffset=Ue,this.controllerQ=R(),this.lastControllerQ=R(),this.headQ=R(),this.headPos=m(),this.elbowPos=m(),this.wristPos=m(),this.time=null,this.lastTime=null,this.rootQ=R(),this.position=m()}setHandedness(e){this.hand!=e&&(this.hand=e,"left"==this.hand?this.headElbowOffset=Xe:this.headElbowOffset=Ue)}update(e,t){this.time=W(),e&&(D(this.lastControllerQ,this.controllerQ),D(this.controllerQ,e)),t&&(A(this.headPos,t),p(this.headQ,t));let i=this.getHeadYawOrientation_(),r=this.quatAngle_(this.lastControllerQ,this.controllerQ);r/((this.time-this.lastTime)/1e3)>.61?T(this.rootQ,this.rootQ,i,Math.min(r/.175,1)):D(this.rootQ,i);let n=v(0,0,-1);S(n,n,this.controllerQ);let s=x(n,[0,1,0]),a=this.clamp_((s-.12)/.87,0,1),o=C(this.rootQ);P(o,o),F(o,o,this.controllerQ);let l=this.elbowPos;w(l,this.headPos),y(l,l,this.headElbowOffset);let c=g(qe);b(c,c,a),y(l,l,c);let h=this.quatAngle_(o,R())*je,u=(1-Math.pow(h/180,4))*(.4+.6*a*.4),d=R();T(d,d,o,u);let f=P(R(),d),m=C(o);F(m,m,f);let E=this.wristPos;w(E,We),S(E,E,d),y(E,E,He),S(E,E,m),y(E,E,l);let M=g(qe);b(M,M,a),y(this.position,this.wristPos,M),S(this.position,this.position,this.rootQ),this.lastTime=this.time}getPosition(){return this.position}getHeadYawOrientation_(){let e=m();!function(e,t,i){function r(e,t,i){return ei?i:e}var n=t[0]*t[0],s=t[1]*t[1],a=t[2]*t[2],o=t[3]*t[3];if("XYZ"===i)e[0]=Math.atan2(2*(t[0]*t[3]-t[1]*t[2]),o-n-s+a),e[1]=Math.asin(r(2*(t[0]*t[2]+t[1]*t[3]),-1,1)),e[2]=Math.atan2(2*(t[2]*t[3]-t[0]*t[1]),o+n-s-a);else if("YXZ"===i)e[0]=Math.asin(r(2*(t[0]*t[3]-t[1]*t[2]),-1,1)),e[1]=Math.atan2(2*(t[0]*t[2]+t[1]*t[3]),o-n-s+a),e[2]=Math.atan2(2*(t[0]*t[1]+t[2]*t[3]),o-n+s-a);else if("ZXY"===i)e[0]=Math.asin(r(2*(t[0]*t[3]+t[1]*t[2]),-1,1)),e[1]=Math.atan2(2*(t[1]*t[3]-t[2]*t[0]),o-n-s+a),e[2]=Math.atan2(2*(t[2]*t[3]-t[0]*t[1]),o-n+s-a);else if("ZYX"===i)e[0]=Math.atan2(2*(t[0]*t[3]+t[2]*t[1]),o-n-s+a),e[1]=Math.asin(r(2*(t[1]*t[3]-t[0]*t[2]),-1,1)),e[2]=Math.atan2(2*(t[0]*t[1]+t[2]*t[3]),o+n-s-a);else if("YZX"===i)e[0]=Math.atan2(2*(t[0]*t[3]-t[2]*t[1]),o-n+s-a),e[1]=Math.atan2(2*(t[1]*t[3]-t[0]*t[2]),o+n-s-a),e[2]=Math.asin(r(2*(t[0]*t[1]+t[2]*t[3]),-1,1));else{if("XZY"!==i)return void console.log("No order given for quaternion to euler conversion.");e[0]=Math.atan2(2*(t[0]*t[3]+t[1]*t[2]),o-n+s-a),e[1]=Math.atan2(2*(t[0]*t[2]+t[1]*t[3]),o+n-s-a),e[2]=Math.asin(r(2*(t[2]*t[3]-t[0]*t[1]),-1,1))}}(e,this.headQ,"YXZ");let t=function(e,t,i,r){let n=.5*Math.PI/180;t*=n,i*=n,r*=n;let s=Math.sin(t),a=Math.cos(t),o=Math.sin(i),l=Math.cos(i),c=Math.sin(r),h=Math.cos(r);return e[0]=s*l*h-a*o*c,e[1]=a*o*h+s*l*c,e[2]=a*l*c-s*o*h,e[3]=a*l*h+s*o*c,e}(R(),0,e[1]*je,0);return t}clamp_(e,t,i){return Math.min(Math.max(e,t),i)}quatAngle_(e,t){let i=[0,0,-1],r=[0,0,-1];return S(i,i,e),S(r,r,t),function(e,t){let i=v(e[0],e[1],e[2]),r=v(t[0],t[1],t[2]);E(i,i),E(r,r);let n=x(i,r);return n>1?0:n<-1?Math.PI:Math.acos(n)}(i,r)}}const Ze=Symbol("@@webxr-polyfill/XRRemappedGamepad"),$e={pressed:!1,touched:!1,value:0};Object.freeze($e);class Ke{constructor(e,t,i){if(i||(i={}),i.userAgentOverrides)for(let e in i.userAgentOverrides)if(navigator.userAgent.includes(e)){let t=i.userAgentOverrides[e];for(let e in t)e in i?Object.assign(i[e],t[e]):i[e]=t[e];break}let r=new Array(i.axes&&i.axes.length?i.axes.length:e.axes.length),n=new Array(i.buttons&&i.buttons.length?i.buttons.length:e.buttons.length),s=null;if(i.gripTransform){let e=i.gripTransform.orientation||[0,0,0,1];s=l(),d(s,I(e,e),i.gripTransform.position||[0,0,0])}let a=null;if(i.targetRayTransform){let e=i.targetRayTransform.orientation||[0,0,0,1];a=l(),d(a,I(e,e),i.targetRayTransform.position||[0,0,0])}let o=i.profiles;i.displayProfiles&&t.displayName in i.displayProfiles&&(o=i.displayProfiles[t.displayName]),this[Ze]={gamepad:e,map:i,profiles:o||[e.id],mapping:i.mapping||e.mapping,axes:r,buttons:n,gripTransform:s,targetRayTransform:a},this._update()}_update(){let e=this[Ze].gamepad,t=this[Ze].map,i=this[Ze].axes;for(let r=0;r!(!e.ImageBitmapRenderingContext||!e.createImageBitmap))(e)}get depthNear(){return this.display.depthNear}set depthNear(e){this.display.depthNear=e}get depthFar(){return this.display.depthFar}set depthFar(e){this.display.depthFar=e}onBaseLayerSet(e,t){const i=this.sessions.get(e),r=t.context.canvas;if(i.immersive){const e=this.display.getEyeParameters("left"),n=this.display.getEyeParameters("right");r.width=2*Math.max(e.renderWidth,n.renderWidth),r.height=Math.max(e.renderHeight,n.renderHeight),this.display.requestPresent([{source:r,attributes:et}]).then((()=>{this.global.document.body.contains(r)||(i.modifiedCanvasLayer=!0,this.global.document.body.appendChild(r),(e=>{e.style.display="block",e.style.position="absolute",e.style.width=e.style.height="1px",e.style.top=e.style.left="0px"})(r)),i.baseLayer=t}))}else i.baseLayer=t}isSessionSupported(e){return"immersive-ar"!=e&&("immersive-vr"!=e||!1!==this.canPresent)}isFeatureSupported(e){switch(e){case"viewer":case"local":case"local-floor":return!0;default:return!1}}async requestSession(e,t){if(!this.isSessionSupported(e))return Promise.reject();let i="immersive-vr"==e;if(i){const e=this.global.document.createElement("canvas");e.getContext("webgl");await this.display.requestPresent([{source:e,attributes:et}])}const r=new rt(e,t,{renderContextType:this.HAS_BITMAP_SUPPORT?"bitmaprenderer":"2d"});return this.sessions.set(r.id,r),i&&(this.immersiveSession=r,this.dispatchEvent("@@webxr-polyfill/vr-present-start",r.id)),Promise.resolve(r.id)}requestAnimationFrame(e){return this.display.requestAnimationFrame(e)}getPrimaryButtonIndex(e){let t=0,i=e.id.toLowerCase();for(let e in tt)if(i.includes(e)){t=tt[e];break}return Math.min(t,e.buttons.length-1)}onFrameStart(e,t){this.display.depthNear=t.depthNear,this.display.depthFar=t.depthFar,this.display.getFrameData(this.frame);const i=this.sessions.get(e);if(i.immersive&&this.CAN_USE_GAMEPAD){let e=this.gamepadInputSources;this.gamepadInputSources={};let t=this.global.navigator.getGamepads();for(let r=0;r0){let t=e[r];if(t||(t=new Je(this,this.display,this.getPrimaryButtonIndex(n))),t.updateFromGamepad(n),this.gamepadInputSources[r]=t,-1!=t.primaryButtonIndex){let e=n.buttons[t.primaryButtonIndex].pressed;e&&!t.primaryActionPressed?this.dispatchEvent("@@webxr-polyfill/input-select-start",{sessionId:i.id,inputSource:t.inputSource}):!e&&t.primaryActionPressed&&this.dispatchEvent("@@webxr-polyfill/input-select-end",{sessionId:i.id,inputSource:t.inputSource}),t.primaryActionPressed=e}if(-1!=t.primarySqueezeButtonIndex){let e=n.buttons[t.primarySqueezeButtonIndex].pressed;e&&!t.primarySqueezeActionPressed?this.dispatchEvent("@@webxr-polyfill/input-squeeze-start",{sessionId:i.id,inputSource:t.inputSource}):!e&&t.primarySqueezeActionPressed&&this.dispatchEvent("@@webxr-polyfill/input-squeeze-end",{sessionId:i.id,inputSource:t.inputSource}),t.primarySqueezeActionPressed=e}}}}if(!i.immersive&&i.baseLayer){const e=i.baseLayer.context.canvas;f(this.frame.leftProjectionMatrix,t.inlineVerticalFieldOfView,e.width/e.height,t.depthNear,t.depthFar)}}onFrameEnd(e){const t=this.sessions.get(e);if(!t.ended&&t.baseLayer){if(t.outputContext&&(!t.immersive||this.display.capabilities.hasExternalDisplay)){const e=t.immersive&&this.display.capabilities.hasExternalDisplay,i=t.baseLayer.context.canvas,r=e?i.width/2:i.width,n=i.height;{const e=t.outputContext.canvas,s=e.width,a=e.height,o=t.renderContext;this.HAS_BITMAP_SUPPORT?i.transferToImageBitmap?o.transferFromImageBitmap(i.transferToImageBitmap()):this.global.createImageBitmap(i,0,0,r,n,{resizeWidth:s,resizeHeight:a}).then((e=>o.transferFromImageBitmap(e))):o.drawImage(i,0,0,r,n,0,0,s,a)}}t.immersive&&t.baseLayer&&this.display.submitFrame()}}cancelAnimationFrame(e){this.display.cancelAnimationFrame(e)}async endSession(e){const t=this.sessions.get(e);if(!t.ended)return t.immersive?this.display.exitPresent():void(t.ended=!0)}doesSessionSupportReferenceSpace(e,t){const i=this.sessions.get(e);return!i.ended&&i.enabledFeatures.has(t)}requestStageBounds(){if(this.display.stageParameters){const e=this.display.stageParameters.sizeX,t=this.display.stageParameters.sizeZ,i=[];return i.push(-e/2),i.push(-t/2),i.push(e/2),i.push(-t/2),i.push(e/2),i.push(t/2),i.push(-e/2),i.push(t/2),i}return null}async requestFrameOfReferenceTransform(e,t){return("local-floor"===e||"bounded-floor"===e)&&this.display.stageParameters&&this.display.stageParameters.sittingToStandingTransform?this.display.stageParameters.sittingToStandingTransform:null}getProjectionMatrix(e){if("left"===e)return this.frame.leftProjectionMatrix;if("right"===e)return this.frame.rightProjectionMatrix;if("none"===e)return this.frame.leftProjectionMatrix;throw new Error("eye must be of type 'left' or 'right'")}getViewport(e,t,i,r){const n=this.sessions.get(e),{width:s,height:a}=i.context.canvas;if(!n.immersive)return r.x=r.y=0,r.width=s,r.height=a,!0;if("left"===t||"none"===t)r.x=0;else{if("right"!==t)return!1;r.x=s/2}return r.y=0,r.width=s/2,r.height=a,!0}getBasePoseMatrix(){let{position:e,orientation:t}=this.frame.pose;return e||t?(e||(e=this.tempVec3,e[0]=e[1]=e[2]=0),d(this.baseModelMatrix,t,e),this.baseModelMatrix):this.baseModelMatrix}getBaseViewMatrix(e){if("left"===e||"none"===e)return this.frame.leftViewMatrix;if("right"===e)return this.frame.rightViewMatrix;throw new Error("eye must be of type 'left' or 'right'")}getInputSources(){let e=[];for(let t in this.gamepadInputSources)e.push(this.gamepadInputSources[t].inputSource);return e}getInputPose(e,t,i){if(!t)return null;for(let r in this.gamepadInputSources){let n=this.gamepadInputSources[r];if(n.inputSource===e)return n.getXRPose(t,i)}return null}onWindowResize(){}onVRDisplayPresentChange(e){this.display.isPresenting||this.sessions.forEach((e=>{if(e.immersive&&!e.ended){if(e.modifiedCanvasLayer){const t=e.baseLayer.context.canvas;document.body.removeChild(t),t.setAttribute("style","")}this.immersiveSession===e&&(this.immersiveSession=null),this.dispatchEvent("@@webxr-polyfill/vr-present-end",e.id)}}))}}class st extends nt{constructor(e,t){const i=new Ie(t||{});super(e,i),this.display=i,this.frame={rightViewMatrix:new Float32Array(16),leftViewMatrix:new Float32Array(16),rightProjectionMatrix:new Float32Array(16),leftProjectionMatrix:new Float32Array(16),pose:null,timestamp:null}}}let at=0;class ot{constructor(e,t){this.mode=e,this.enabledFeatures=t,this.ended=null,this.baseLayer=null,this.id=++at}}class lt extends Le{constructor(e){super(e),this.sessions=new Map,this.projectionMatrix=l(),this.identityMatrix=l()}onBaseLayerSet(e,t){this.sessions.get(e).baseLayer=t}isSessionSupported(e){return"inline"==e}isFeatureSupported(e){return"viewer"===e}async requestSession(e,t){if(!this.isSessionSupported(e))return Promise.reject();const i=new ot(e,t);return this.sessions.set(i.id,i),Promise.resolve(i.id)}requestAnimationFrame(e){return window.requestAnimationFrame(e)}cancelAnimationFrame(e){window.cancelAnimationFrame(e)}onFrameStart(e,t){const i=this.sessions.get(e);if(i.baseLayer){const e=i.baseLayer.context.canvas;f(this.projectionMatrix,t.inlineVerticalFieldOfView,e.width/e.height,t.depthNear,t.depthFar)}}onFrameEnd(e){}async endSession(e){this.sessions.get(e).ended=!0}doesSessionSupportReferenceSpace(e,t){const i=this.sessions.get(e);return!i.ended&&i.enabledFeatures.has(t)}requestStageBounds(){return null}async requestFrameOfReferenceTransform(e,t){return null}getProjectionMatrix(e){return this.projectionMatrix}getViewport(e,t,i,r){this.sessions.get(e);const{width:n,height:s}=i.context.canvas;return r.x=r.y=0,r.width=n,r.height=s,!0}getBasePoseMatrix(){return this.identityMatrix}getBaseViewMatrix(e){return this.identityMatrix}getInputSources(){return[]}getInputPose(e,t,i){return null}onWindowResize(){}}const ct=async function(e,t){if(t.webvr){let t=await async function(e){let t=null;if("getVRDisplays"in e.navigator)try{const i=await e.navigator.getVRDisplays();i&&i.length&&(t=new nt(e,i[0]))}catch(e){}return t}(e);if(t)return t}let i=(e=>{var t=!1;return function(e){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0,4)))&&(t=!0)}(e.navigator.userAgent||e.navigator.vendor||e.opera),t})(e);return i&&t.cardboard||!i&&t.allowCardboardOnDesktop?(e.VRFrameData||(e.VRFrameData=function(){this.rightViewMatrix=new Float32Array(16),this.leftViewMatrix=new Float32Array(16),this.rightProjectionMatrix=new Float32Array(16),this.leftProjectionMatrix=new Float32Array(16),this.pose=null}),new st(e,t.cardboardConfig)):new lt(e)},ht={global:n,webvr:!0,cardboard:!0,cardboardConfig:null,allowCardboardOnDesktop:!1},ut=["navigator","HTMLCanvasElement","WebGLRenderingContext"];var dt=class{constructor(e={}){this.config=Object.freeze(Object.assign({},ht,e)),this.global=this.config.global,this.nativeWebXR="xr"in this.global.navigator,this.injected=!1,this.nativeWebXR?this._injectCompatibilityShims(this.global):this._injectPolyfill(this.global)}_injectPolyfill(e){if(!ut.every((t=>!!e[t])))throw new Error(`Global must have the following attributes : ${ut}`);for(const t of Object.keys(_e))void 0!==e[t]?console.warn(`${t} already defined on global.`):e[t]=_e[t];Re(e.WebGLRenderingContext)&&(Fe(e.HTMLCanvasElement),e.OffscreenCanvas&&Fe(e.OffscreenCanvas),e.WebGL2RenderingContext&&Re(e.WebGL2RenderingContext),window.isSecureContext||console.warn("WebXR Polyfill Warning:\nThis page is not running in a secure context (https:// or localhost)!\nThis means that although the page may be able to use the WebXR Polyfill it will\nnot be able to use native WebXR implementations, and as such will not be able to\naccess dedicated VR or AR hardware, and will not be able to take advantage of\nany performance improvements a native WebXR implementation may offer. Please\nhost this content on a secure origin for the best user experience.\n"));this.injected=!0,this._patchNavigatorXR()}_patchNavigatorXR(){let e=ct(this.global,this.config);this.xr=new _e.XRSystem(e),Object.defineProperty(this.global.navigator,"xr",{value:this.xr,configurable:!0})}_injectCompatibilityShims(e){if(!ut.every((t=>!!e[t])))throw new Error(`Global must have the following attributes : ${ut}`);if(e.navigator.xr&&"supportsSession"in e.navigator.xr&&!("isSessionSupported"in e.navigator.xr)){let t=e.navigator.xr.supportsSession;e.navigator.xr.isSessionSupported=function(e){return t.call(this,e).then((()=>!0)).catch((()=>!1))},e.navigator.xr.supportsSession=function(e){return console.warn("navigator.xr.supportsSession() is deprecated. Please call navigator.xr.isSessionSupported() instead and check the boolean value returned when the promise resolves."),t.call(this,e)}}}},At=on(r),pt={};Object.defineProperty(pt,"__esModule",{value:!0});var ft={};t(ft,"create",(()=>wt)),t(ft,"fromMat4",(()=>yt)),t(ft,"clone",(()=>bt)),t(ft,"copy",(()=>Et)),t(ft,"fromValues",(()=>xt)),t(ft,"set",(()=>Mt)),t(ft,"identity",(()=>St)),t(ft,"transpose",(()=>_t)),t(ft,"invert",(()=>Rt)),t(ft,"adjoint",(()=>Ft)),t(ft,"determinant",(()=>Tt)),t(ft,"multiply",(()=>Pt)),t(ft,"translate",(()=>Ct)),t(ft,"rotate",(()=>Bt)),t(ft,"scale",(()=>Dt)),t(ft,"fromTranslation",(()=>It)),t(ft,"fromRotation",(()=>Lt)),t(ft,"fromScaling",(()=>Ot)),t(ft,"fromMat2d",(()=>Nt)),t(ft,"fromQuat",(()=>Gt)),t(ft,"normalFromMat4",(()=>Vt)),t(ft,"projection",(()=>kt)),t(ft,"str",(()=>zt)),t(ft,"frob",(()=>Qt)),t(ft,"add",(()=>Ut)),t(ft,"subtract",(()=>Xt)),t(ft,"multiplyScalar",(()=>Ht)),t(ft,"multiplyScalarAndAdd",(()=>Wt)),t(ft,"exactEquals",(()=>qt)),t(ft,"equals",(()=>jt)),t(ft,"mul",(()=>Yt)),t(ft,"sub",(()=>Zt));var mt=1e-6,gt="undefined"!=typeof Float32Array?Float32Array:Array,vt=Math.random;Math.PI;function wt(){var e=new gt(9);return gt!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[5]=0,e[6]=0,e[7]=0),e[0]=1,e[4]=1,e[8]=1,e}function yt(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}function bt(e){var t=new gt(9);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t}function Et(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function xt(e,t,i,r,n,s,a,o,l){var c=new gt(9);return c[0]=e,c[1]=t,c[2]=i,c[3]=r,c[4]=n,c[5]=s,c[6]=a,c[7]=o,c[8]=l,c}function Mt(e,t,i,r,n,s,a,o,l,c){return e[0]=t,e[1]=i,e[2]=r,e[3]=n,e[4]=s,e[5]=a,e[6]=o,e[7]=l,e[8]=c,e}function St(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e}function _t(e,t){if(e===t){var i=t[1],r=t[2],n=t[5];e[1]=t[3],e[2]=t[6],e[3]=i,e[5]=t[7],e[6]=r,e[7]=n}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8];return e}function Rt(e,t){var i=t[0],r=t[1],n=t[2],s=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=h*a-o*c,d=-h*s+o*l,A=c*s-a*l,p=i*u+r*d+n*A;return p?(p=1/p,e[0]=u*p,e[1]=(-h*r+n*c)*p,e[2]=(o*r-n*a)*p,e[3]=d*p,e[4]=(h*i-n*l)*p,e[5]=(-o*i+n*s)*p,e[6]=A*p,e[7]=(-c*i+r*l)*p,e[8]=(a*i-r*s)*p,e):null}function Ft(e,t){var i=t[0],r=t[1],n=t[2],s=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8];return e[0]=a*h-o*c,e[1]=n*c-r*h,e[2]=r*o-n*a,e[3]=o*l-s*h,e[4]=i*h-n*l,e[5]=n*s-i*o,e[6]=s*c-a*l,e[7]=r*l-i*c,e[8]=i*a-r*s,e}function Tt(e){var t=e[0],i=e[1],r=e[2],n=e[3],s=e[4],a=e[5],o=e[6],l=e[7],c=e[8];return t*(c*s-a*l)+i*(-c*n+a*o)+r*(l*n-s*o)}function Pt(e,t,i){var r=t[0],n=t[1],s=t[2],a=t[3],o=t[4],l=t[5],c=t[6],h=t[7],u=t[8],d=i[0],A=i[1],p=i[2],f=i[3],m=i[4],g=i[5],v=i[6],w=i[7],y=i[8];return e[0]=d*r+A*a+p*c,e[1]=d*n+A*o+p*h,e[2]=d*s+A*l+p*u,e[3]=f*r+m*a+g*c,e[4]=f*n+m*o+g*h,e[5]=f*s+m*l+g*u,e[6]=v*r+w*a+y*c,e[7]=v*n+w*o+y*h,e[8]=v*s+w*l+y*u,e}function Ct(e,t,i){var r=t[0],n=t[1],s=t[2],a=t[3],o=t[4],l=t[5],c=t[6],h=t[7],u=t[8],d=i[0],A=i[1];return e[0]=r,e[1]=n,e[2]=s,e[3]=a,e[4]=o,e[5]=l,e[6]=d*r+A*a+c,e[7]=d*n+A*o+h,e[8]=d*s+A*l+u,e}function Bt(e,t,i){var r=t[0],n=t[1],s=t[2],a=t[3],o=t[4],l=t[5],c=t[6],h=t[7],u=t[8],d=Math.sin(i),A=Math.cos(i);return e[0]=A*r+d*a,e[1]=A*n+d*o,e[2]=A*s+d*l,e[3]=A*a-d*r,e[4]=A*o-d*n,e[5]=A*l-d*s,e[6]=c,e[7]=h,e[8]=u,e}function Dt(e,t,i){var r=i[0],n=i[1];return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=n*t[3],e[4]=n*t[4],e[5]=n*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e}function It(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=t[0],e[7]=t[1],e[8]=1,e}function Lt(e,t){var i=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=i,e[2]=0,e[3]=-i,e[4]=r,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e}function Ot(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=t[1],e[5]=0,e[6]=0,e[7]=0,e[8]=1,e}function Nt(e,t){return e[0]=t[0],e[1]=t[1],e[2]=0,e[3]=t[2],e[4]=t[3],e[5]=0,e[6]=t[4],e[7]=t[5],e[8]=1,e}function Gt(e,t){var i=t[0],r=t[1],n=t[2],s=t[3],a=i+i,o=r+r,l=n+n,c=i*a,h=r*a,u=r*o,d=n*a,A=n*o,p=n*l,f=s*a,m=s*o,g=s*l;return e[0]=1-u-p,e[3]=h-g,e[6]=d+m,e[1]=h+g,e[4]=1-c-p,e[7]=A-f,e[2]=d-m,e[5]=A+f,e[8]=1-c-u,e}function Vt(e,t){var i=t[0],r=t[1],n=t[2],s=t[3],a=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=t[9],d=t[10],A=t[11],p=t[12],f=t[13],m=t[14],g=t[15],v=i*o-r*a,w=i*l-n*a,y=i*c-s*a,b=r*l-n*o,E=r*c-s*o,x=n*c-s*l,M=h*f-u*p,S=h*m-d*p,_=h*g-A*p,R=u*m-d*f,F=u*g-A*f,T=d*g-A*m,P=v*T-w*F+y*R+b*_-E*S+x*M;return P?(P=1/P,e[0]=(o*T-l*F+c*R)*P,e[1]=(l*_-a*T-c*S)*P,e[2]=(a*F-o*_+c*M)*P,e[3]=(n*F-r*T-s*R)*P,e[4]=(i*T-n*_+s*S)*P,e[5]=(r*_-i*F-s*M)*P,e[6]=(f*x-m*E+g*b)*P,e[7]=(m*y-p*x-g*w)*P,e[8]=(p*E-f*y+g*v)*P,e):null}function kt(e,t,i){return e[0]=2/t,e[1]=0,e[2]=0,e[3]=0,e[4]=-2/i,e[5]=0,e[6]=-1,e[7]=1,e[8]=1,e}function zt(e){return"mat3("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+")"}function Qt(e){return Math.hypot(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8])}function Ut(e,t,i){return e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2],e[3]=t[3]+i[3],e[4]=t[4]+i[4],e[5]=t[5]+i[5],e[6]=t[6]+i[6],e[7]=t[7]+i[7],e[8]=t[8]+i[8],e}function Xt(e,t,i){return e[0]=t[0]-i[0],e[1]=t[1]-i[1],e[2]=t[2]-i[2],e[3]=t[3]-i[3],e[4]=t[4]-i[4],e[5]=t[5]-i[5],e[6]=t[6]-i[6],e[7]=t[7]-i[7],e[8]=t[8]-i[8],e}function Ht(e,t,i){return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*i,e[5]=t[5]*i,e[6]=t[6]*i,e[7]=t[7]*i,e[8]=t[8]*i,e}function Wt(e,t,i,r){return e[0]=t[0]+i[0]*r,e[1]=t[1]+i[1]*r,e[2]=t[2]+i[2]*r,e[3]=t[3]+i[3]*r,e[4]=t[4]+i[4]*r,e[5]=t[5]+i[5]*r,e[6]=t[6]+i[6]*r,e[7]=t[7]+i[7]*r,e[8]=t[8]+i[8]*r,e}function qt(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]}function jt(e,t){var i=e[0],r=e[1],n=e[2],s=e[3],a=e[4],o=e[5],l=e[6],c=e[7],h=e[8],u=t[0],d=t[1],A=t[2],p=t[3],f=t[4],m=t[5],g=t[6],v=t[7],w=t[8];return Math.abs(i-u)<=mt*Math.max(1,Math.abs(i),Math.abs(u))&&Math.abs(r-d)<=mt*Math.max(1,Math.abs(r),Math.abs(d))&&Math.abs(n-A)<=mt*Math.max(1,Math.abs(n),Math.abs(A))&&Math.abs(s-p)<=mt*Math.max(1,Math.abs(s),Math.abs(p))&&Math.abs(a-f)<=mt*Math.max(1,Math.abs(a),Math.abs(f))&&Math.abs(o-m)<=mt*Math.max(1,Math.abs(o),Math.abs(m))&&Math.abs(l-g)<=mt*Math.max(1,Math.abs(l),Math.abs(g))&&Math.abs(c-v)<=mt*Math.max(1,Math.abs(c),Math.abs(v))&&Math.abs(h-w)<=mt*Math.max(1,Math.abs(h),Math.abs(w))}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});var Yt=Pt,Zt=Xt,$t={};t($t,"create",(()=>Zi)),t($t,"identity",(()=>$i)),t($t,"setAxisAngle",(()=>Ki)),t($t,"getAxisAngle",(()=>Ji)),t($t,"getAngle",(()=>er)),t($t,"dot",(()=>Tr)),t($t,"multiply",(()=>tr)),t($t,"rotateX",(()=>ir)),t($t,"rotateY",(()=>rr)),t($t,"rotateZ",(()=>nr)),t($t,"calculateW",(()=>sr)),t($t,"exp",(()=>ar)),t($t,"ln",(()=>or)),t($t,"pow",(()=>lr)),t($t,"scale",(()=>Fr)),t($t,"slerp",(()=>cr)),t($t,"random",(()=>hr)),t($t,"invert",(()=>ur)),t($t,"conjugate",(()=>dr)),t($t,"fromMat3",(()=>Ar)),t($t,"fromEuler",(()=>pr)),t($t,"str",(()=>fr)),t($t,"clone",(()=>Er)),t($t,"fromValues",(()=>xr)),t($t,"copy",(()=>Mr)),t($t,"set",(()=>Sr)),t($t,"add",(()=>_r)),t($t,"mul",(()=>Rr)),t($t,"lerp",(()=>Pr)),t($t,"length",(()=>Cr)),t($t,"len",(()=>Br)),t($t,"squaredLength",(()=>Dr)),t($t,"sqrLen",(()=>Ir)),t($t,"normalize",(()=>Lr)),t($t,"exactEquals",(()=>Or)),t($t,"equals",(()=>Nr)),t($t,"rotationTo",(()=>Gr)),t($t,"sqlerp",(()=>Vr)),t($t,"setAxes",(()=>kr));var Kt={};function Jt(){var e=new gt(3);return gt!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function ei(e){var t=new gt(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function ti(e){var t=e[0],i=e[1],r=e[2];return Math.hypot(t,i,r)}function ii(e,t,i){var r=new gt(3);return r[0]=e,r[1]=t,r[2]=i,r}function ri(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function ni(e,t,i,r){return e[0]=t,e[1]=i,e[2]=r,e}function si(e,t,i){return e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2],e}function ai(e,t,i){return e[0]=t[0]-i[0],e[1]=t[1]-i[1],e[2]=t[2]-i[2],e}function oi(e,t,i){return e[0]=t[0]*i[0],e[1]=t[1]*i[1],e[2]=t[2]*i[2],e}function li(e,t,i){return e[0]=t[0]/i[0],e[1]=t[1]/i[1],e[2]=t[2]/i[2],e}function ci(e,t){return e[0]=Math.ceil(t[0]),e[1]=Math.ceil(t[1]),e[2]=Math.ceil(t[2]),e}function hi(e,t){return e[0]=Math.floor(t[0]),e[1]=Math.floor(t[1]),e[2]=Math.floor(t[2]),e}function ui(e,t,i){return e[0]=Math.min(t[0],i[0]),e[1]=Math.min(t[1],i[1]),e[2]=Math.min(t[2],i[2]),e}function di(e,t,i){return e[0]=Math.max(t[0],i[0]),e[1]=Math.max(t[1],i[1]),e[2]=Math.max(t[2],i[2]),e}function Ai(e,t){return e[0]=Math.round(t[0]),e[1]=Math.round(t[1]),e[2]=Math.round(t[2]),e}function pi(e,t,i){return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e}function fi(e,t,i,r){return e[0]=t[0]+i[0]*r,e[1]=t[1]+i[1]*r,e[2]=t[2]+i[2]*r,e}function mi(e,t){var i=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return Math.hypot(i,r,n)}function gi(e,t){var i=t[0]-e[0],r=t[1]-e[1],n=t[2]-e[2];return i*i+r*r+n*n}function vi(e){var t=e[0],i=e[1],r=e[2];return t*t+i*i+r*r}function wi(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e}function yi(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e}function bi(e,t){var i=t[0],r=t[1],n=t[2],s=i*i+r*r+n*n;return s>0&&(s=1/Math.sqrt(s)),e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}function Ei(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function xi(e,t,i){var r=t[0],n=t[1],s=t[2],a=i[0],o=i[1],l=i[2];return e[0]=n*l-s*o,e[1]=s*a-r*l,e[2]=r*o-n*a,e}function Mi(e,t,i,r){var n=t[0],s=t[1],a=t[2];return e[0]=n+r*(i[0]-n),e[1]=s+r*(i[1]-s),e[2]=a+r*(i[2]-a),e}function Si(e,t,i,r,n,s){var a=s*s,o=a*(2*s-3)+1,l=a*(s-2)+s,c=a*(s-1),h=a*(3-2*s);return e[0]=t[0]*o+i[0]*l+r[0]*c+n[0]*h,e[1]=t[1]*o+i[1]*l+r[1]*c+n[1]*h,e[2]=t[2]*o+i[2]*l+r[2]*c+n[2]*h,e}function _i(e,t,i,r,n,s){var a=1-s,o=a*a,l=s*s,c=o*a,h=3*s*o,u=3*l*a,d=l*s;return e[0]=t[0]*c+i[0]*h+r[0]*u+n[0]*d,e[1]=t[1]*c+i[1]*h+r[1]*u+n[1]*d,e[2]=t[2]*c+i[2]*h+r[2]*u+n[2]*d,e}function Ri(e,t){t=t||1;var i=2*vt()*Math.PI,r=2*vt()-1,n=Math.sqrt(1-r*r)*t;return e[0]=Math.cos(i)*n,e[1]=Math.sin(i)*n,e[2]=r*t,e}function Fi(e,t,i){var r=t[0],n=t[1],s=t[2],a=i[3]*r+i[7]*n+i[11]*s+i[15];return a=a||1,e[0]=(i[0]*r+i[4]*n+i[8]*s+i[12])/a,e[1]=(i[1]*r+i[5]*n+i[9]*s+i[13])/a,e[2]=(i[2]*r+i[6]*n+i[10]*s+i[14])/a,e}function Ti(e,t,i){var r=t[0],n=t[1],s=t[2];return e[0]=r*i[0]+n*i[3]+s*i[6],e[1]=r*i[1]+n*i[4]+s*i[7],e[2]=r*i[2]+n*i[5]+s*i[8],e}function Pi(e,t,i){var r=i[0],n=i[1],s=i[2],a=i[3],o=t[0],l=t[1],c=t[2],h=n*c-s*l,u=s*o-r*c,d=r*l-n*o,A=n*d-s*u,p=s*h-r*d,f=r*u-n*h,m=2*a;return h*=m,u*=m,d*=m,A*=2,p*=2,f*=2,e[0]=o+h+A,e[1]=l+u+p,e[2]=c+d+f,e}function Ci(e,t,i,r){var n=[],s=[];return n[0]=t[0]-i[0],n[1]=t[1]-i[1],n[2]=t[2]-i[2],s[0]=n[0],s[1]=n[1]*Math.cos(r)-n[2]*Math.sin(r),s[2]=n[1]*Math.sin(r)+n[2]*Math.cos(r),e[0]=s[0]+i[0],e[1]=s[1]+i[1],e[2]=s[2]+i[2],e}function Bi(e,t,i,r){var n=[],s=[];return n[0]=t[0]-i[0],n[1]=t[1]-i[1],n[2]=t[2]-i[2],s[0]=n[2]*Math.sin(r)+n[0]*Math.cos(r),s[1]=n[1],s[2]=n[2]*Math.cos(r)-n[0]*Math.sin(r),e[0]=s[0]+i[0],e[1]=s[1]+i[1],e[2]=s[2]+i[2],e}function Di(e,t,i,r){var n=[],s=[];return n[0]=t[0]-i[0],n[1]=t[1]-i[1],n[2]=t[2]-i[2],s[0]=n[0]*Math.cos(r)-n[1]*Math.sin(r),s[1]=n[0]*Math.sin(r)+n[1]*Math.cos(r),s[2]=n[2],e[0]=s[0]+i[0],e[1]=s[1]+i[1],e[2]=s[2]+i[2],e}function Ii(e,t){var i=e[0],r=e[1],n=e[2],s=t[0],a=t[1],o=t[2],l=Math.sqrt(i*i+r*r+n*n)*Math.sqrt(s*s+a*a+o*o),c=l&&Ei(e,t)/l;return Math.acos(Math.min(Math.max(c,-1),1))}function Li(e){return e[0]=0,e[1]=0,e[2]=0,e}function Oi(e){return"vec3("+e[0]+", "+e[1]+", "+e[2]+")"}function Ni(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]}function Gi(e,t){var i=e[0],r=e[1],n=e[2],s=t[0],a=t[1],o=t[2];return Math.abs(i-s)<=mt*Math.max(1,Math.abs(i),Math.abs(s))&&Math.abs(r-a)<=mt*Math.max(1,Math.abs(r),Math.abs(a))&&Math.abs(n-o)<=mt*Math.max(1,Math.abs(n),Math.abs(o))}t(Kt,"create",(()=>Jt)),t(Kt,"clone",(()=>ei)),t(Kt,"length",(()=>ti)),t(Kt,"fromValues",(()=>ii)),t(Kt,"copy",(()=>ri)),t(Kt,"set",(()=>ni)),t(Kt,"add",(()=>si)),t(Kt,"subtract",(()=>ai)),t(Kt,"multiply",(()=>oi)),t(Kt,"divide",(()=>li)),t(Kt,"ceil",(()=>ci)),t(Kt,"floor",(()=>hi)),t(Kt,"min",(()=>ui)),t(Kt,"max",(()=>di)),t(Kt,"round",(()=>Ai)),t(Kt,"scale",(()=>pi)),t(Kt,"scaleAndAdd",(()=>fi)),t(Kt,"distance",(()=>mi)),t(Kt,"squaredDistance",(()=>gi)),t(Kt,"squaredLength",(()=>vi)),t(Kt,"negate",(()=>wi)),t(Kt,"inverse",(()=>yi)),t(Kt,"normalize",(()=>bi)),t(Kt,"dot",(()=>Ei)),t(Kt,"cross",(()=>xi)),t(Kt,"lerp",(()=>Mi)),t(Kt,"hermite",(()=>Si)),t(Kt,"bezier",(()=>_i)),t(Kt,"random",(()=>Ri)),t(Kt,"transformMat4",(()=>Fi)),t(Kt,"transformMat3",(()=>Ti)),t(Kt,"transformQuat",(()=>Pi)),t(Kt,"rotateX",(()=>Ci)),t(Kt,"rotateY",(()=>Bi)),t(Kt,"rotateZ",(()=>Di)),t(Kt,"angle",(()=>Ii)),t(Kt,"zero",(()=>Li)),t(Kt,"str",(()=>Oi)),t(Kt,"exactEquals",(()=>Ni)),t(Kt,"equals",(()=>Gi)),t(Kt,"sub",(()=>ki)),t(Kt,"mul",(()=>zi)),t(Kt,"div",(()=>Qi)),t(Kt,"dist",(()=>Ui)),t(Kt,"sqrDist",(()=>Xi)),t(Kt,"len",(()=>Hi)),t(Kt,"sqrLen",(()=>Wi)),t(Kt,"forEach",(()=>qi));var Vi,ki=ai,zi=oi,Qi=li,Ui=mi,Xi=gi,Hi=ti,Wi=vi,qi=(Vi=Jt(),function(e,t,i,r,n,s){var a,o;for(t||(t=3),i||(i=0),o=r?Math.min(r*t+i,e.length):e.length,a=i;amt?(e[0]=t[0]/r,e[1]=t[1]/r,e[2]=t[2]/r):(e[0]=1,e[1]=0,e[2]=0),i}function er(e,t){var i=Tr(e,t);return Math.acos(2*i*i-1)}function tr(e,t,i){var r=t[0],n=t[1],s=t[2],a=t[3],o=i[0],l=i[1],c=i[2],h=i[3];return e[0]=r*h+a*o+n*c-s*l,e[1]=n*h+a*l+s*o-r*c,e[2]=s*h+a*c+r*l-n*o,e[3]=a*h-r*o-n*l-s*c,e}function ir(e,t,i){i*=.5;var r=t[0],n=t[1],s=t[2],a=t[3],o=Math.sin(i),l=Math.cos(i);return e[0]=r*l+a*o,e[1]=n*l+s*o,e[2]=s*l-n*o,e[3]=a*l-r*o,e}function rr(e,t,i){i*=.5;var r=t[0],n=t[1],s=t[2],a=t[3],o=Math.sin(i),l=Math.cos(i);return e[0]=r*l-s*o,e[1]=n*l+a*o,e[2]=s*l+r*o,e[3]=a*l-n*o,e}function nr(e,t,i){i*=.5;var r=t[0],n=t[1],s=t[2],a=t[3],o=Math.sin(i),l=Math.cos(i);return e[0]=r*l+n*o,e[1]=n*l-r*o,e[2]=s*l+a*o,e[3]=a*l-s*o,e}function sr(e,t){var i=t[0],r=t[1],n=t[2];return e[0]=i,e[1]=r,e[2]=n,e[3]=Math.sqrt(Math.abs(1-i*i-r*r-n*n)),e}function ar(e,t){var i=t[0],r=t[1],n=t[2],s=t[3],a=Math.sqrt(i*i+r*r+n*n),o=Math.exp(s),l=a>0?o*Math.sin(a)/a:0;return e[0]=i*l,e[1]=r*l,e[2]=n*l,e[3]=o*Math.cos(a),e}function or(e,t){var i=t[0],r=t[1],n=t[2],s=t[3],a=Math.sqrt(i*i+r*r+n*n),o=a>0?Math.atan2(a,s)/a:0;return e[0]=i*o,e[1]=r*o,e[2]=n*o,e[3]=.5*Math.log(i*i+r*r+n*n+s*s),e}function lr(e,t,i){return or(e,t),Fr(e,e,i),ar(e,e),e}function cr(e,t,i,r){var n,s,a,o,l,c=t[0],h=t[1],u=t[2],d=t[3],A=i[0],p=i[1],f=i[2],m=i[3];return(s=c*A+h*p+u*f+d*m)<0&&(s=-s,A=-A,p=-p,f=-f,m=-m),1-s>mt?(n=Math.acos(s),a=Math.sin(n),o=Math.sin((1-r)*n)/a,l=Math.sin(r*n)/a):(o=1-r,l=r),e[0]=o*c+l*A,e[1]=o*h+l*p,e[2]=o*u+l*f,e[3]=o*d+l*m,e}function hr(e){var t=vt(),i=vt(),r=vt(),n=Math.sqrt(1-t),s=Math.sqrt(t);return e[0]=n*Math.sin(2*Math.PI*i),e[1]=n*Math.cos(2*Math.PI*i),e[2]=s*Math.sin(2*Math.PI*r),e[3]=s*Math.cos(2*Math.PI*r),e}function ur(e,t){var i=t[0],r=t[1],n=t[2],s=t[3],a=i*i+r*r+n*n+s*s,o=a?1/a:0;return e[0]=-i*o,e[1]=-r*o,e[2]=-n*o,e[3]=s*o,e}function dr(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e}function Ar(e,t){var i,r=t[0]+t[4]+t[8];if(r>0)i=Math.sqrt(r+1),e[3]=.5*i,i=.5/i,e[0]=(t[5]-t[7])*i,e[1]=(t[6]-t[2])*i,e[2]=(t[1]-t[3])*i;else{var n=0;t[4]>t[0]&&(n=1),t[8]>t[3*n+n]&&(n=2);var s=(n+1)%3,a=(n+2)%3;i=Math.sqrt(t[3*n+n]-t[3*s+s]-t[3*a+a]+1),e[n]=.5*i,i=.5/i,e[3]=(t[3*s+a]-t[3*a+s])*i,e[s]=(t[3*s+n]+t[3*n+s])*i,e[a]=(t[3*a+n]+t[3*n+a])*i}return e}function pr(e,t,i,r){var n=.5*Math.PI/180;t*=n,i*=n,r*=n;var s=Math.sin(t),a=Math.cos(t),o=Math.sin(i),l=Math.cos(i),c=Math.sin(r),h=Math.cos(r);return e[0]=s*l*h-a*o*c,e[1]=a*o*h+s*l*c,e[2]=a*l*c-s*o*h,e[3]=a*l*h+s*o*c,e}function fr(e){return"quat("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"}var mr,gr,vr,wr,yr,br,Er=function(e){var t=new gt(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},xr=function(e,t,i,r){var n=new gt(4);return n[0]=e,n[1]=t,n[2]=i,n[3]=r,n},Mr=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},Sr=function(e,t,i,r,n){return e[0]=t,e[1]=i,e[2]=r,e[3]=n,e},_r=function(e,t,i){return e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2],e[3]=t[3]+i[3],e},Rr=tr,Fr=function(e,t,i){return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e},Tr=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},Pr=function(e,t,i,r){var n=t[0],s=t[1],a=t[2],o=t[3];return e[0]=n+r*(i[0]-n),e[1]=s+r*(i[1]-s),e[2]=a+r*(i[2]-a),e[3]=o+r*(i[3]-o),e},Cr=ji,Br=Cr,Dr=Yi,Ir=Dr,Lr=function(e,t){var i=t[0],r=t[1],n=t[2],s=t[3],a=i*i+r*r+n*n+s*s;return a>0&&(a=1/Math.sqrt(a)),e[0]=i*a,e[1]=r*a,e[2]=n*a,e[3]=s*a,e},Or=function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]},Nr=function(e,t){var i=e[0],r=e[1],n=e[2],s=e[3],a=t[0],o=t[1],l=t[2],c=t[3];return Math.abs(i-a)<=mt*Math.max(1,Math.abs(i),Math.abs(a))&&Math.abs(r-o)<=mt*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-l)<=mt*Math.max(1,Math.abs(n),Math.abs(l))&&Math.abs(s-c)<=mt*Math.max(1,Math.abs(s),Math.abs(c))},Gr=(mr=Jt(),gr=ii(1,0,0),vr=ii(0,1,0),function(e,t,i){var r=Ei(t,i);return r<-.999999?(xi(mr,gr,t),Hi(mr)<1e-6&&xi(mr,vr,t),bi(mr,mr),Ki(e,mr,Math.PI),e):r>.999999?(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e):(xi(mr,t,i),e[0]=mr[0],e[1]=mr[1],e[2]=mr[2],e[3]=1+r,Lr(e,e))}),Vr=(wr=Zi(),yr=Zi(),function(e,t,i,r,n,s){return cr(wr,t,n,s),cr(yr,i,r,s),cr(e,wr,yr,2*s*(1-s)),e}),kr=(br=wt(),function(e,t,i,r){return br[0]=i[0],br[3]=i[1],br[6]=i[2],br[1]=r[0],br[4]=r[1],br[7]=r[2],br[2]=-t[0],br[5]=-t[1],br[8]=-t[2],Lr(e,Ar(e,br))}),zr={};Object.defineProperty(zr,"__esModule",{value:!0});var Qr={};Object.defineProperty(Qr,"__esModule",{value:!0});Qr.default=class{constructor(){this._pose=null,this._view=null,this.poseMatrix=new p5.Matrix,this.initialMVMatrix=new p5.Matrix,this.leftPMatrix=new p5.Matrix,this.rightPMatrix=new p5.Matrix,this.position=new p5.Vector(0,0,0),this.setPosition=function(e,t,i){this.position.set(e,t,i),p5.instance._renderer.translate(-e,-t,-i)}}set pose(e){this._pose=e,this.poseMatrix.set(e.poseModelMatrix)}get pose(){return this._pose}set view(e){this._view=e,p5.instance._renderer.uMVMatrix.set(this._view.transform.inverse.matrix),p5.instance._renderer.uPMatrix.set(this._view.projectionMatrix),p5.instance._renderer._curCamera.cameraMatrix.set(p5.Matrix.identity().mult(this._view.transform.inverse.matrix)),"left"===e.eye?this.leftPMatrix.set(p5.instance._renderer.uPMatrix.copy()):this.rightPMatrix.set(p5.instance._renderer.uPMatrix.copy())}get view(){return this._view}},p5.prototype.setViewerPosition=function(e,t,i){const{viewer:r}=p5xr.instance;r.setPosition(e,t,i)},p5.prototype.sticky=function(e=!1){push(),p5xr.instance.viewer.drawOnTop=e,e&&p5.instance._renderer.GL.disable(p5.instance._renderer.GL.DEPTH_TEST),p5.instance._renderer.uMVMatrix.set(p5.Matrix.identity());const t=p5xr.instance.viewer.position;setViewerPosition(t.x,t.y,t.z)},p5.prototype.noSticky=function(){p5.instance._renderer.GL.enable(p5.instance._renderer.GL.DEPTH_TEST),pop()};var Ur=qr(Qr),Xr={};Object.defineProperty(Xr,"__esModule",{value:!0});Xr.default=class{constructor(e){this.options=e||{},this.options.color=e.color||"rgb(237, 34, 93)",this.options.background=e.background||!1,this.options.disabledOpacity=e.disabledOpacity||.5,this.options.height=e.height||window.innerWidth/5,this.options.corners=e.corners||"square",this.options.cssprefix=e.cssprefix||"webvr-ui",this.options.textEnterXRTitle=e.textEnterXRTitle||"ENTER XR",this.options.textXRNotFoundTitle=e.textXRNotFoundTitle||"XR NOT FOUND",this.options.textExitXRTitle=e.textExitXRTitle||"EXIT XR",this.options.onRequestSession=e.onRequestSession||function(){},this.options.onEndSession=e.onEndSession||function(){},this.options.injectCSS=!1!==e.injectCSS,this.options=e,this.device=null,this.session=null,this.logoScale=1.2,this._WEBXR_UI_CSS_INJECTED={},this.domElement=e.domElement||this.createDefaultView(e),this.__defaultDisplayStyle=this.domElement.style.display||"initial",this.domElement.addEventListener("click",(()=>this.__onXRButtonClick())),this.__forceDisabled=!1,this.__setDisabledAttribute(!0),this.setTitle(this.options.textXRNotFoundTitle)}generateInnerHTML(e,t){const i=t*this.logoScale;return``}createDefaultView(e){const t=e.height/3;e.injectCSS&&(this._WEBXR_UI_CSS_INJECTED[e.cssprefix]||(this.injectCSS(this.generateCSS(e,t)),this._WEBXR_UI_CSS_INJECTED[e.cssprefix]=!0));const i=document.createElement("div");return i.innerHTML=this.generateInnerHTML(e.cssprefix,t),i.firstChild}createXRIcon(e,t){const i=document.createElement("div");return i.innerHTML=generateXRIconString(e,t),i.firstChild}createNoXRIcon(e,t){const i=document.createElement("div");return i.innerHTML=generateNoXRIconString(e,t),i.firstChild}generateXRIconString(e,t){return`\n \n `}generateNoXRIconString(e,t){const i=28/18;return`\n \n \n \n `}setDevice(e){return this.device=e,this.__updateButtonState(),this}setSession(e){return this.session=e,this.__updateButtonState(),this}setTitle(e){return this.domElement.title=e,this.ifChild(this.domElement,this.options.cssprefix,"title",(t=>{e?(t.innerText=e,t.style.display="initial"):t.style.display="none"})),this}generateCSS(e,t=18){const{height:i}=e,r=e.background?e.background:e.color,n=e.cssprefix;let s;return s="round"==e.corners?e.height/2:"square"==e.corners?2:e.corners,`\n @font-face {\n font-family: 'Karla';\n font-style: normal;\n font-weight: 400;\n src: local('Karla'), local('Karla-Regular'),\n url(https://fonts.gstatic.com/s/karla/v5/31P4mP32i98D9CEnGyeX9Q.woff2) format('woff2');\n unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;\n }\n @font-face {\n font-family: 'Karla';\n font-style: normal;\n font-weight: 400;\n src: local('Karla'), local('Karla-Regular'),\n url(https://fonts.gstatic.com/s/karla/v5/Zi_e6rBgGqv33BWF8WTq8g.woff2) format('woff2');\n unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074,\n U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;\n }\n\n button.${n}-button {\n font-family: 'Karla', sans-serif;\n\n border: ${r} 2px solid;\n border-radius: ${s}px;\n box-sizing: border-box;\n background: ${e.background?e.background:"none"};\n\n height: ${i}px;\n min-width: ${9.6*t}px;\n display: inline-block;\n position: absolute;\n top: 5%;\n left: 15%;\n cursor: pointer;\n }\n\n button.${n}-button:focus {\n outline: none;\n }\n\n /*\n * Logo\n */\n\n .${n}-logo {\n width: ${i}px;\n height: ${i}px;\n position: absolute;\n top:0px;\n left:0px;\n width: ${i-4}px;\n height: ${i-4}px;\n }\n .${n}-svg {\n fill: ${e.color};\n margin-top: ${(i-t*this.logoScale)/2-2}px;\n margin-left: ${i/3}px;\n }\n .${n}-svg-error {\n fill: ${e.color};\n display:none;\n margin-top: ${(i-28/18*t*this.logoScale)/2-2}px;\n margin-left: ${i/3}px;\n }\n\n\n /*\n * Title\n */\n\n .${n}-title {\n color: ${e.color};\n position: relative;\n font-size: ${t}px;\n padding-left: ${1.05*i}px;\n padding-right: ${s-10<5?i/3:s-10}px;\n }\n\n /*\n * disabled\n */\n\n button.${n}-button[disabled=true] {\n opacity: ${e.disabledOpacity};\n }\n\n button.${n}-button[disabled=true] > .${n}-logo > .${n}-svg {\n display:none;\n }\n\n button.${n}-button[disabled=true] > .${n}-logo > .${n}-svg-error {\n display:initial;\n }\n `}injectCSS(e){const t=document.createElement("style");t.innerHTML=e;const i=document.getElementsByTagName("head")[0];i.insertBefore(t,i.firstChild)}ifChild(e,t,i,r){const n=e.querySelector(`.${t}-${i}`);n&&r(n)}setTooltip(e){return this.domElement.title=e,this}show(){return this.domElement.style.display=this.__defaultDisplayStyle,this}hide(){return this.domElement.style.display="none",this}enable(){return this.__setDisabledAttribute(!1),this.__forceDisabled=!1,this}disable(){return this.__setDisabledAttribute(!0),this.__forceDisabled=!0,this}remove(){this.domElement.parentElement&&this.domElement.parentElement.removeChild(this.domElement)}__setDisabledAttribute(e){e||this.__forceDisabled?this.domElement.setAttribute("disabled","true"):this.domElement.removeAttribute("disabled")}__onXRButtonClick(){this.session?this.options.onEndSession(this.session):this.device&&("undefined"!=typeof DeviceMotionEvent&&"function"==typeof DeviceMotionEvent.requestPermission&&DeviceMotionEvent.requestPermission().then((e=>{"granted"===e&&window.addEventListener("devicemotion",(()=>{}))})).catch(console.error),"undefined"!=typeof DeviceOrientationEvent&&"function"==typeof DeviceOrientationEvent.requestPermission&&DeviceOrientationEvent.requestPermission().then((e=>{"granted"===e&&window.addEventListener("deviceorientation",(()=>{}))})).catch(console.error),this.options.onRequestSession(this.device))}__updateButtonState(){this.session?(this.setTitle(this.options.textExitXRTitle),this.setTooltip("Exit XR presentation"),this.__setDisabledAttribute(!1)):this.device?(this.setTitle(this.options.textEnterXRTitle),this.setTooltip("Enter XR"),this.__setDisabledAttribute(!1)):(this.setTitle(this.options.textXRNotFoundTitle),this.setTooltip("No XR headset found."),this.__setDisabledAttribute(!0))}};var Hr=qr(Xr),Wr={};Object.defineProperty(Wr,"__esModule",{value:!0});function qr(e){return e&&e.__esModule?e:{default:e}}Wr.default=class{constructor(e,t,i){this._inputSource=e,this._targetRayPose=t.getPose(this._inputSource.targetRaySpace,i),this._pose,this.gamepad=e.gamepad,this._dir=Kt.create();const r=ft.create(),n=Kt.create();this._dir[2]=-1,this._targetRayPose&&(Kt.transformMat4(n,n,this._targetRayPose.transform.matrix),ft.fromMat4(r,this._targetRayPose.transform.matrix),Kt.transformMat3(this._dir,this._dir,r)),this.direction=this._dir}get direction(){return new p5.Vector(this._dir[0],this._dir[1],this._dir[2])}set direction(e){this._dir=Kt.copy(this._dir,e),Kt.normalize(this._dir,this._dir),this.inv_dir=Kt.fromValues(1/this._dir[0],1/this._dir[1],1/this._dir[2]),this.sign=[this.inv_dir[0]<0?1:0,this.inv_dir[1]<0?1:0,this.inv_dir[2]<0?1:0]}get pose(){return this.updatePose(),this._pose.transform.matrix}get position(){this.updatePose();const e=this._pose?.transform?.position;return new p5.Vector(e.x,e.y,e.z)}updatePose(){this._pose=window.p5xr.instance.frame.getPose(this._inputSource.gripSpace,window.p5xr.instance.xrRefSpace)}get trigger(){return this.updateGamepad(),this.gamepad?.buttons[0]}get grip(){return this.updateGamepad(),this.gamepad.buttons[1]}get touchpad(){return this.updateGamepad(),this.gamepad.buttons[2]}get thumbstick(){return this.updateGamepad(),this.gamepad.buttons[3]}get touchpad2D(){return this.updateGamepad(),new p5.Vector(this.gamepad.axes[0],this.gamepad.axes[1])}get thumbstick2D(){return this.updateGamepad(),new p5.Vector(this.gamepad.axes[2],this.gamepad.axes[3])}updateGamepad(){this.gamepad=this._inputSource.gamepad}};zr.default=class{constructor(){this.xrDevice=null,this.xrButton=null,this.isVR=null,this.xrSession=null,this.xrRefSpace=null,this.xrViewerSpace=null,this.xrHitTestSource=null,this.frame=null,this.gl=null,this.curClearColor=color(255,255,255),this.viewer=new Ur.default}removeLoadingElement(){const e=document.getElementById(window._loadingScreenId);e&&e.parentNode.removeChild(e)}updateXR(){const e=p5.instance._renderer;e.ambientLightColors.length=0,e.specularColors=[1,1,1],e.directionalLightDirections.length=0,e.directionalLightDiffuseColors.length=0,e.directionalLightSpecularColors.length=0,e.pointLightPositions.length=0,e.pointLightDiffuseColors.length=0,e.pointLightSpecularColors.length=0,e.spotLightPositions.length=0,e.spotLightDirections.length=0,e.spotLightDiffuseColors.length=0,e.spotLightSpecularColors.length=0,e.spotLightAngle.length=0,e.spotLightConc.length=0,e._enableLighting=!1,e._tint=[255,255,255,255]}setupCanvas(){createCanvas(windowWidth,windowHeight,WEBGL),p5.instance._setupDone=!0}createButton(){p5.instance._incrementPreload(),this.setupCanvas(),this.removeLoadingElement(),this.xrButton=new Hr.default({onRequestSession:this.onXRButtonClicked.bind(this),onEndSession:this.onSessionEnded.bind(this),textEnterXRTitle:this.isVR?"ENTER VR":"ENTER AR"});let e=document.querySelector("header");e||(e=document.createElement("header"),document.querySelector("body").appendChild(e)),e.appendChild(this.xrButton.domElement)}disableButton(){this.xrButton.setTitle("AR Unavailable"),this.xrButton.setTooltip("No XR headset found."),this.xrButton.__setDisabledAttribute(!0)}sessionCheck(){const e=window.injectedPolyfill?"with polyfill":"without polyfill";this.isVR?navigator.xr.isSessionSupported("immersive-vr").then((t=>{t?(console.log(`VR supported ${e}`),this.xrButton.setDevice(!0),this.isImmersive=!0):(console.log("This device does not support immersive VR sessions."),this.isImmersive=!1),this.xrButton.setDevice(!0)})).catch((e=>{console.log(e.message)})):navigator.xr.isSessionSupported("immersive-ar").then((t=>{t?(console.log(`AR supported ${e}`),this.xrButton.setDevice(!0)):this.disableButton()}))}onXRFrame(e,t){const i=this.xrSession=t.session;if(null===i||null===this.gl)return;i.requestAnimationFrame(this.onXRFrame.bind(this));let r=this.xrRefSpace;this.isVR&&!this.isImmersive&&(r=this.getAdjustedRefSpace(this.xrRefSpace));const n=t.getViewerPose(this.xrRefSpace),s=i.renderState.baseLayer;if(this.frame=t,n){this.viewer.pose=t.getViewerPose(r),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,s.framebuffer),this.isVR&&this.clearVR();let e=0;for(const t of this.viewer.pose.views){this.viewer.view=t;const i=this.isImmersive?1:pixelDensity(),r=s.getViewport(this.viewer.view);this.gl.viewport(r.x,r.y,r.width*i,r.height*i),this.updateViewport(r),this.drawEye(e),e++}}}updateViewport(e){p5.instance._renderer._viewport[0]=e.x,p5.instance._renderer._viewport[1]=e.y,p5.instance._renderer._viewport[2]=e.width,p5.instance._renderer._viewport[3]=e.height}drawEye(e){const t=window,i=t.setup,r=t.draw,n=t.calculate;if(this.isVR){if(0===e){"function"==typeof n&&n();const e=window.performance.now();p5.instance.deltaTime=e-p5.instance._lastFrameTime,p5.instance._frameRate=1e3/p5.instance.deltaTime,p5.instance._setProperty("deltaTime",p5.instance.deltaTime),p5.instance._lastFrameTime=e,t._setProperty("frameCount",t.frameCount+1)}}else scale(.01);if(p5.instance._renderer.isP3D){if("function"==typeof r){void 0===i&&t.scale(t._pixelDensity,t._pixelDensity),this.updateXR(),p5.instance._inUserDraw=!0;try{r()}finally{p5.instance._inUserDraw=!1}}}else console.error("Sketch does not have 3D Renderer")}getXRInput(e){let t;return this.xrSession.inputSources.forEach((i=>{i.handedness===e&&(t=new p5xrInput(i,this.frame,this.xrRefSpace))})),t}onSessionEnded(){this.isVR||(this.xrHitTestSource.cancel(),this.xrHitTestSource=null),this.xrSession&&(this.xrSession.end(),this.xrSession=null);const e=document.getElementsByClassName("p5Canvas");for(;e.length>0;)e[0].parentNode.removeChild(e[0]);this.xrButton.session=null,this.xrButton.setTitle(this.isVR?"ENTER VR":"ENTER AR"),this.gl=null}printUnsupportedMessage(){console.warn("Your browser/hardware does not work with AR Mode currently. This is undergoing heavy development currently.You may be able to fix this by enabling WebXR flags in Chrome.")}remove(){this.xrButton&&this.xrButton.remove(),window.p5xr.instance=null}get instance(){return window.p5xr.instance}set instance(e){return window.p5xr.instance=e,window.p5xr.instance}};var jr,Yr=(jr=zr)&&jr.__esModule?jr:{default:jr};class Zr extends Yr.default{constructor(){super(),this.isVR=!0,this.isImmersive=!0,this.lookYaw=0,this.lookPitch=0,this.LOOK_SPEED=.0025,this.primaryTouch=void 0,this.prevTouchX=void 0,this.prevTouchY=void 0}initVR(){this.createButton(),navigator.xr&&this.sessionCheck()}startSketch(e){this.xrSession=this.xrButton.session=e,this.canvas=p5.instance.canvas,this.canvas.style.visibility="visible",this.xrSession.addEventListener("end",this.onSessionEnded.bind(this)),"function"==typeof window.setup&&(window.setup(),p5.instance._millisStart=window.performance.now()),this.onRequestSession()}onXRButtonClicked(){this.isImmersive?(console.log("requesting session with mode: immersive-vr"),navigator.xr.requestSession("immersive-vr").then(this.startSketch.bind(this))):(console.log("requesting session with mode: non-immersive-vr"),this.xrButton.hide(),navigator.xr.requestSession("inline").then(this.startSketch.bind(this)))}onRequestSession(){this.xrButton.setTitle(this.isVR?"EXIT VR":"EXIT AR"),p5.instance._renderer._curCamera.cameraType="custom",this.gl=this.canvas.getContext("webgl",{xrCompatible:!0}),this.isImmersive?this.gl.makeXRCompatible().then((()=>{this.setupBaseLayer(),this.setupReferenceSpace()})).catch((e=>{console.log(e)})):(this.setupBaseLayer(),this.setupReferenceSpace(),this.xrSession.updateRenderState({inlineVerticalFieldOfView:Math.PI/180*70}),this.addInlineViewListeners(this.canvas)),this.xrSession.requestAnimationFrame(this.onXRFrame.bind(this))}setupBaseLayer(){this.baseLayer=new XRWebGLLayer(this.xrSession,this.gl),this.xrSession.updateRenderState({baseLayer:this.baseLayer})}setupReferenceSpace(){const e=this.isImmersive?"local":"viewer";this.xrSession.requestReferenceSpace(e).then((e=>{this.xrRefSpace=e}))}clearVR(){null!==this.curClearColor&&(p5.instance.background(this.curClearColor),this.gl.clear(this.gl.DEPTH_BUFFER_BIT))}getAdjustedRefSpace(e){const t=$t.create();$t.rotateX(t,t,-this.lookPitch),$t.rotateY(t,t,-this.lookYaw);const i=new XRRigidTransform({x:0,y:0,z:0},{x:t[0],y:t[1],z:t[2],w:t[3]});return e.getOffsetReferenceSpace(i)}rotateView(e,t){this.lookYaw+=e*this.LOOK_SPEED,this.lookPitch+=t*this.LOOK_SPEED,this.lookPitch<.5*-Math.PI&&(this.lookPitch=.5*-Math.PI),this.lookPitch>.5*Math.PI&&(this.lookPitch=.5*Math.PI)}addInlineViewListeners(e){this.canvas.addEventListener("mousemove",(e=>{e.buttons&&this.rotateView(e.movementX,e.movementY)})),this.canvas.addEventListener("touchstart",(e=>{if(void 0===this.primaryTouch){const t=e.changedTouches[0];this.primaryTouch=t.identifier,this.prevTouchX=t.pageX,this.prevTouchY=t.pageY}})),e.addEventListener("touchend",(e=>{for(const t of e.changedTouches)this.primaryTouch===t.identifier&&(this.primaryTouch=void 0,this.rotateView(t.pageX-this.prevTouchX,t.pageY-this.prevTouchY))})),e.addEventListener("touchcancel",(e=>{for(const t of e.changedTouches)this.primaryTouch===t.identifier&&(this.primaryTouch=void 0)})),e.addEventListener("touchmove",(e=>{for(const t of e.changedTouches)this.primaryTouch===t.identifier&&(this.rotateView(t.pageX-this.prevTouchX,t.pageY-this.prevTouchY),this.prevTouchX=t.pageX,this.prevTouchY=t.pageY)}))}}pt.default=Zr;var $r=on(pt),Kr={};Object.defineProperty(Kr,"__esModule",{value:!0});var Jr=rn(zr),en={};Object.defineProperty(en,"__esModule",{value:!0});en.default=class{constructor(e,t,i){this.position={x:100*e,y:100*t,z:100*i}}dispose(){}isTracking(){}isStopped(){}transform(){translate(this.position.x,this.position.y,this.position.z)}};var tn=rn(en);function rn(e){return e&&e.__esModule?e:{default:e}}class nn extends Jr.default{constructor(){super(),this.canvas=null}initAR(){this.createButton(),navigator.xr&&this.sessionCheck()}startSketch(e){this.xrSession=this.xrButton.session=e,this.xrSession.addEventListener("end",this.onSessionEnded),"function"==typeof touchStarted&&this.xrSession.addEventListener("select",touchStarted),this.canvas=p5.instance.canvas,p5.instance._renderer._curCamera.cameraType="custom",this.onRequestSession(),p5.instance._decrementPreload()}onSelect(e){const t=window.mousePressed;"function"==typeof t&&t()}detectHit(e){if(null==e)return console.warn("You must pass the touchStarted event to detectHit."),null;if(!this.xrSession)return null;e.clientY,window.innerHeight,e.clientX,window.innerWidth;if(this.xrHitTestSource&&this.viewer.pose&&this.frame){const e=this.frame.getHitTestResults(this.xrHitTestSource);if(e.length>0){const t=e[0].getPose(this.xrRefSpace);return createVector(t.transform.position.x,t.transform.position.y,t.transform.position.z)}}}createAnchor(e){return null==e?null:new tn.default(e.x,e.y,e.z)}onXRButtonClicked(e){window.injectedPolyfill?console.log("ARCORE mode is not supported with a polyfill. Try using a more recent browser version"):(navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,navigator.xr.requestSession("immersive-ar",{requiredFeatures:["local","hit-test"]}).then((e=>{this.startSketch(e)}),(e=>{console.log(`${e} unable to request an immersive-ar session.`)})))}onRequestSession(){this.gl=this.canvas.getContext("webgl",{xrCompatible:!0}),this.gl.makeXRCompatible().then((()=>{this.xrSession.updateRenderState({baseLayer:new XRWebGLLayer(this.xrSession,this.gl)})})),this.xrSession.requestReferenceSpace("viewer").then((e=>{this.xrViewerSpace=e,this.xrSession.requestHitTestSource({space:this.xrViewerSpace}).then((e=>{this.xrHitTestSource=e}))})),this.xrSession.requestReferenceSpace("local").then((e=>{this.xrRefSpace=e,this.xrSession.requestAnimationFrame(this.onXRFrame.bind(this))}))}}Kr.default=nn;var sn=on(Kr),an=function(e){return e&&e.__esModule?e:{default:e}}(Qr);function on(e){return e&&e.__esModule?e:{default:e}}an.default.prototype.getRayFromScreen=function(e,t){const i={origin:new p5.Vector(0,0,0),direction:new p5.Vector};let r=this.poseMatrix.copy();r.transpose(r),r=r.mat4,i.origin.x=r[3],i.origin.y=r[7],i.origin.z=r[11];let n=this.initialMVMatrix.copy();n.transpose(n),n=n.mat4;const s=i.origin.copy();i.origin.x=n[0]*s.x+n[1]*s.y+n[2]*s.z+n[3],i.origin.y=n[4]*s.x+n[5]*s.y+n[6]*s.z+n[7],i.origin.z=n[8]*s.x+n[9]*s.y+n[10]*s.z+n[11];const a=new p5.Vector(e,t,-1);let o=new p5.Matrix;o.invert(this.leftPMatrix.copy()),o.transpose(o),o=o.mat4;const l=a.copy();a.x=o[0]*l.x+o[1]*l.y+o[2]*l.z,a.y=o[4]*l.x+o[5]*l.y+o[6]*l.z,a.normalize();const c=new p5.Vector(e,t,-1);let h=new p5.Matrix;h.invert(this.rightPMatrix.copy()),h.transpose(h),h=h.mat4;const u=c.copy();return c.x=h[0]*u.x+h[1]*u.y+h[2]*u.z,c.y=h[4]*u.x+h[5]*u.y+h[6]*u.z,c.normalize(),i.direction=p5.Vector.add(a,c).normalize(),i},p5.prototype.intersectsSphere=function(){const e=arguments[0];let t={origin:null,direction:null};if(2===arguments.length&&arguments[1].hasOwnProperty("origin"))t.origin=arguments[1].origin.copy(),t.direction=arguments[1].direction.copy();else{const e=arguments[1]||0,i=arguments[2]||0;t=p5xr.instance.viewer.getRayFromScreen(e,i)}if(null===t)return!1;let i=p5.instance._renderer.uMVMatrix.copy();i.transpose(i),i=i.mat4;const r=new p5.Vector(0,0,0);if(r.x=i[3],r.y=i[7],r.z=i[11],p5.Vector.sub(t.origin,r).mag()<=e)return!0;if(p5.Vector.dot(p5.Vector.sub(r,t.origin),t.direction)<0)return!1;const n=p5.Vector.sub(t.origin,r),s=2*p5.Vector.dot(t.direction,n),a=p5.Vector.mag(n)*p5.Vector.mag(n)-e*e,o=s*s-4*a;return o>=0},p5.prototype.intersectsBox=function(){const e=arguments[0];let t,i,r={origin:null,direction:null};arguments[arguments.length-1].hasOwnProperty("origin")?(r.origin=arguments[arguments.length-1].origin.copy(),r.direction=arguments[arguments.length-1].direction.copy(),t=arguments.length>2?arguments[1]:e,i=arguments.length>3?arguments[2]:t):5===arguments.length?(r=p5xr.instance.viewer.getRayFromScreen(arguments[3],arguments[4]),t=arguments[1],i=arguments[2]):(r=p5xr.instance.viewer.getRayFromScreen(0,0),t=arguments.length>1?arguments[1]:e,i=arguments.length>2?arguments[2]:t);let n=p5.instance._renderer.uMVMatrix.copy();n.transpose(n),n.invert(n),n=n.mat4;const s=r.origin.copy();r.origin.x=n[0]*s.x+n[1]*s.y+n[2]*s.z+n[3],r.origin.y=n[4]*s.x+n[5]*s.y+n[6]*s.z+n[7],r.origin.z=n[8]*s.x+n[9]*s.y+n[10]*s.z+n[11];const a=r.direction.copy();r.direction.x=n[0]*a.x+n[1]*a.y+n[2]*a.z,r.direction.y=n[4]*a.x+n[5]*a.y+n[6]*a.z,r.direction.z=n[8]*a.x+n[9]*a.y+n[10]*a.z,r.direction.normalize();const o=new p5.Vector(-.5*e,-.5*t,-.5*i),l=new p5.Vector(.5*e,.5*t,.5*i),c=(o.x-r.origin.x)/r.direction.x,h=(l.x-r.origin.x)/r.direction.x,u=(o.y-r.origin.y)/r.direction.y,d=(l.y-r.origin.y)/r.direction.y,A=(o.z-r.origin.z)/r.direction.z,p=(l.z-r.origin.z)/r.direction.z,f=Math.max(Math.max(Math.min(c,h),Math.min(u,d)),Math.min(A,p)),m=Math.min(Math.min(Math.max(c,h),Math.max(u,d)),Math.max(A,p));return!(m<0||f>m)},p5.prototype.intersectsPlane=function(){let e={origin:null,direction:null};arguments[0].hasOwnProperty("origin")?(e.origin=arguments[0].origin.copy(),e.direction=arguments[0].direction.copy()):e=p5xr.instance.viewer.getRayFromScreen(arguments[0],arguments[1]);let t=p5.instance._renderer.uMVMatrix.copy();t.transpose(t),t.invert(t),t=t.mat4;const i=e.origin.copy();e.origin.x=t[0]*i.x+t[1]*i.y+t[2]*i.z+t[3],e.origin.y=t[4]*i.x+t[5]*i.y+t[6]*i.z+t[7],e.origin.z=t[8]*i.x+t[9]*i.y+t[10]*i.z+t[11];const r=e.direction.copy();e.direction.x=t[0]*r.x+t[1]*r.y+t[2]*r.z,e.direction.y=t[4]*r.x+t[5]*r.y+t[6]*r.z,e.direction.z=t[8]*r.x+t[9]*r.y+t[10]*r.z,e.direction.normalize();const n=new p5.Vector(0,0,1),s=new p5.Vector(0,0,0),a=p5.Vector.sub(s,e.origin),o=Math.abs(p5.Vector.dot(e.direction,n));if(0===o)return null;const l=Math.abs(p5.Vector.dot(a,n)/o),c=p5.Vector.add(e.origin,e.direction.copy().setMag(l));return createVector(c.x,c.y)},p5.prototype.generateRay=function(e,t,i,r,n,s){const a=new p5.Vector(e,t,i);let o=new p5.Vector(r,n,s);o=p5.Vector.sub(o,a),o.normalize();let l=p5.instance._renderer.uMVMatrix.copy();l.transpose(l),l=l.mat4;const c=a.copy();a.x=l[0]*c.x+l[1]*c.y+l[2]*c.z+l[3],a.y=l[4]*c.x+l[5]*c.y+l[6]*c.z+l[7],a.z=l[8]*c.x+l[9]*c.y+l[10]*c.z+l[11];const h=o.copy();return o.x=l[0]*h.x+l[1]*h.y+l[2]*h.z,o.y=l[4]*h.x+l[5]*h.y+l[6]*h.z,o.z=l[8]*h.x+l[9]*h.y+l[10]*h.z,o.normalize(),{origin:a,direction:o}},window.p5xr={instance:null},"xr"in navigator==0?(window.injectedPolyfill=!0,window.polyfill=new At.default):window.injectedPolyfill=!1,p5.prototype.createVRCanvas=function(){noLoop(),p5xr.instance=new $r.default,p5xr.instance.initVR()},p5.prototype.createARCanvas=function(){noLoop(),p5xr.instance=new sn.default,p5xr.instance.initAR()},p5.prototype.setVRBackgroundColor=function(e,t,i){p5xr.instance.curClearColor=color(e,t,i)},p5.prototype.surroundTexture=function(e){push(),texture(e),rotateX(PI),scale(-1,1,1),sphere(300,60,40),pop()},p5.prototype.createAnchor=function(e){if(!p5xr.instance.isVR)return p5xr.instance.createAnchor(e)},p5.prototype.detectHit=function(e){if(!p5xr.instance.isVR)return p5xr.instance.detectHit(e)},p5.prototype.getXRInput=function(e){if(0!==p5xr.instance.xrSession.inputSources.length)return p5xr.instance.getXRInput(e)}})(); \ No newline at end of file diff --git a/sketch.js b/sketch.js new file mode 100644 index 0000000..e58e6d2 --- /dev/null +++ b/sketch.js @@ -0,0 +1,108 @@ +let n = 0, randomX = [], randomY = [], randomS = []; +var rn; + + +let tree +let branchLength = 100 +let minimumWeight = 0.03 +let iteration = 15 + +function preload() { + createVRCanvas(); +} + +function setup() { + setVRBackgroundColor(200, 200, 200); + noStroke(); + for(let i=0; i=600){ + n=0; + setup(); + } + + + //rotateY(n/2); + + noStroke(); + rotateX(90); + fill(0, 160, 0); + plane(5000, 5000); + fill(128, 128, 0); + rotateX(-90) + + + for(let i = 0; i 10 ){ + for(var i=0;i<3;i++){ + rotateY(random(100,140)); + + push(); + + rotateZ(random(20,50)); + branch(len *0.7); + + + pop(); + } + } else { + + var r = 80 + random(-20,20) + var g = 120+ random(-20,20) + var b = 40+ random(-20,20) + + fill(r,g,b,200); + noStroke() + + translate(5,0,0) + + rotateZ(90) + + triangle(-5,-5,5,5,-5,5) + } + + +} diff --git a/style.css b/style.css new file mode 100644 index 0000000..fe3005f --- /dev/null +++ b/style.css @@ -0,0 +1,8 @@ +html, body { + margin: 0; + padding: 0; +} +canvas { + display: block; +} +