iwer 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/iwer.js +412 -1291
- package/build/iwer.min.js +52 -11
- package/build/iwer.module.js +412 -1291
- package/build/iwer.module.min.js +52 -11
- package/lib/action/ActionPlayer.d.ts.map +1 -1
- package/lib/action/ActionPlayer.js.map +1 -1
- package/lib/action/ActionRecorder.d.ts.map +1 -1
- package/lib/action/ActionRecorder.js +1 -1
- package/lib/action/ActionRecorder.js.map +1 -1
- package/lib/anchors/XRAnchor.d.ts.map +1 -1
- package/lib/anchors/XRAnchor.js.map +1 -1
- package/lib/device/XRController.d.ts.map +1 -1
- package/lib/device/XRController.js.map +1 -1
- package/lib/device/XRDevice.d.ts +1 -1
- package/lib/device/XRDevice.d.ts.map +1 -1
- package/lib/device/XRDevice.js +8 -3
- package/lib/device/XRDevice.js.map +1 -1
- package/lib/device/XRHandInput.d.ts.map +1 -1
- package/lib/device/XRHandInput.js.map +1 -1
- package/lib/device/XRTrackedInput.d.ts.map +1 -1
- package/lib/device/XRTrackedInput.js.map +1 -1
- package/lib/device/configs/controller/meta.js.map +1 -1
- package/lib/device/configs/hand/pinch.js.map +1 -1
- package/lib/device/configs/hand/point.js.map +1 -1
- package/lib/device/configs/hand/relaxed.js.map +1 -1
- package/lib/device/configs/headset/meta.js.map +1 -1
- package/lib/events/XRInputSourceEvent.d.ts.map +1 -1
- package/lib/events/XRInputSourceEvent.js.map +1 -1
- package/lib/events/XRInputSourcesChangeEvent.d.ts.map +1 -1
- package/lib/events/XRInputSourcesChangeEvent.js.map +1 -1
- package/lib/events/XRReferenceSpaceEvent.d.ts.map +1 -1
- package/lib/events/XRReferenceSpaceEvent.js.map +1 -1
- package/lib/events/XRSessionEvent.d.ts.map +1 -1
- package/lib/events/XRSessionEvent.js.map +1 -1
- package/lib/frameloop/XRFrame.d.ts.map +1 -1
- package/lib/frameloop/XRFrame.js.map +1 -1
- package/lib/gamepad/Gamepad.d.ts.map +1 -1
- package/lib/gamepad/Gamepad.js.map +1 -1
- package/lib/hittest/XRHitTest.d.ts.map +1 -1
- package/lib/hittest/XRHitTest.js.map +1 -1
- package/lib/hittest/XRRay.d.ts.map +1 -1
- package/lib/hittest/XRRay.js.map +1 -1
- package/lib/initialization/XRSystem.d.ts.map +1 -1
- package/lib/initialization/XRSystem.js.map +1 -1
- package/lib/input/XRHand.d.ts.map +1 -1
- package/lib/input/XRHand.js.map +1 -1
- package/lib/input/XRInputSource.d.ts.map +1 -1
- package/lib/input/XRInputSource.js.map +1 -1
- package/lib/labels/labels.d.ts.map +1 -1
- package/lib/labels/labels.js.map +1 -1
- package/lib/layers/XRWebGLLayer.d.ts.map +1 -1
- package/lib/layers/XRWebGLLayer.js.map +1 -1
- package/lib/meshes/XRMesh.d.ts.map +1 -1
- package/lib/meshes/XRMesh.js.map +1 -1
- package/lib/planes/XRPlane.d.ts.map +1 -1
- package/lib/planes/XRPlane.js.map +1 -1
- package/lib/pose/XRJointPose.d.ts.map +1 -1
- package/lib/pose/XRJointPose.js.map +1 -1
- package/lib/pose/XRPose.d.ts.map +1 -1
- package/lib/pose/XRPose.js.map +1 -1
- package/lib/pose/XRViewerPose.d.ts.map +1 -1
- package/lib/pose/XRViewerPose.js.map +1 -1
- package/lib/primitives/XRRigidTransform.d.ts.map +1 -1
- package/lib/primitives/XRRigidTransform.js.map +1 -1
- package/lib/session/XRRenderState.d.ts.map +1 -1
- package/lib/session/XRRenderState.js.map +1 -1
- package/lib/session/XRSession.d.ts.map +1 -1
- package/lib/session/XRSession.js.map +1 -1
- package/lib/spaces/XRJointSpace.d.ts.map +1 -1
- package/lib/spaces/XRJointSpace.js.map +1 -1
- package/lib/spaces/XRReferenceSpace.d.ts.map +1 -1
- package/lib/spaces/XRReferenceSpace.js.map +1 -1
- package/lib/spaces/XRSpace.d.ts.map +1 -1
- package/lib/spaces/XRSpace.js.map +1 -1
- package/lib/utils/Math.d.ts.map +1 -1
- package/lib/utils/Math.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/views/XRView.d.ts.map +1 -1
- package/lib/views/XRView.js.map +1 -1
- package/lib/views/XRViewport.d.ts.map +1 -1
- package/lib/views/XRViewport.js.map +1 -1
- package/package.json +61 -61
package/build/iwer.module.min.js
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
|
-
var e=1e-6,t="undefined"!=typeof Float32Array?Float32Array:Array;function r(){var e=new t(16);return t!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function i(e){var r=new t(16);return r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=e[3],r[4]=e[4],r[5]=e[5],r[6]=e[6],r[7]=e[7],r[8]=e[8],r[9]=e[9],r[10]=e[10],r[11]=e[11],r[12]=e[12],r[13]=e[13],r[14]=e[14],r[15]=e[15],r}function s(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[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function a(e,t){var r=t[0],i=t[1],s=t[2],a=t[3],n=t[4],o=t[5],h=t[6],l=t[7],u=t[8],c=t[9],d=t[10],p=t[11],f=t[12],x=t[13],m=t[14],g=t[15],y=r*o-i*n,v=r*h-s*n,T=r*l-a*n,w=i*h-s*o,E=i*l-a*o,R=s*l-a*h,S=u*x-c*f,_=u*m-d*f,b=u*g-p*f,M=c*m-d*x,A=c*g-p*x,F=d*g-p*m,P=y*F-v*A+T*M+w*b-E*_+R*S;return P?(P=1/P,e[0]=(o*F-h*A+l*M)*P,e[1]=(s*A-i*F-a*M)*P,e[2]=(x*R-m*E+g*w)*P,e[3]=(d*E-c*R-p*w)*P,e[4]=(h*b-n*F-l*_)*P,e[5]=(r*F-s*b+a*_)*P,e[6]=(m*T-f*R-g*v)*P,e[7]=(u*R-d*T+p*v)*P,e[8]=(n*A-o*b+l*S)*P,e[9]=(i*b-r*A-a*S)*P,e[10]=(f*E-x*T+g*y)*P,e[11]=(c*T-u*E-p*y)*P,e[12]=(o*_-n*M-h*S)*P,e[13]=(r*M-i*_+s*S)*P,e[14]=(x*v-f*w-m*y)*P,e[15]=(u*w-c*v+d*y)*P,e):null}function n(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3],o=t[4],h=t[5],l=t[6],u=t[7],c=t[8],d=t[9],p=t[10],f=t[11],x=t[12],m=t[13],g=t[14],y=t[15],v=r[0],T=r[1],w=r[2],E=r[3];return e[0]=v*i+T*o+w*c+E*x,e[1]=v*s+T*h+w*d+E*m,e[2]=v*a+T*l+w*p+E*g,e[3]=v*n+T*u+w*f+E*y,v=r[4],T=r[5],w=r[6],E=r[7],e[4]=v*i+T*o+w*c+E*x,e[5]=v*s+T*h+w*d+E*m,e[6]=v*a+T*l+w*p+E*g,e[7]=v*n+T*u+w*f+E*y,v=r[8],T=r[9],w=r[10],E=r[11],e[8]=v*i+T*o+w*c+E*x,e[9]=v*s+T*h+w*d+E*m,e[10]=v*a+T*l+w*p+E*g,e[11]=v*n+T*u+w*f+E*y,v=r[12],T=r[13],w=r[14],E=r[15],e[12]=v*i+T*o+w*c+E*x,e[13]=v*s+T*h+w*d+E*m,e[14]=v*a+T*l+w*p+E*g,e[15]=v*n+T*u+w*f+E*y,e}function o(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function h(t,r,i){var s,a,n,o=i[0],h=i[1],l=i[2],u=Math.sqrt(o*o+h*h+l*l);return u<e?null:(o*=u=1/u,h*=u,l*=u,s=Math.sin(r),n=1-(a=Math.cos(r)),t[0]=o*o*n+a,t[1]=h*o*n+l*s,t[2]=l*o*n-h*s,t[3]=0,t[4]=o*h*n-l*s,t[5]=h*h*n+a,t[6]=l*h*n+o*s,t[7]=0,t[8]=o*l*n+h*s,t[9]=h*l*n-o*s,t[10]=l*l*n+a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function l(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3],o=i+i,h=s+s,l=a+a,u=i*o,c=i*h,d=i*l,p=s*h,f=s*l,x=a*l,m=n*o,g=n*h,y=n*l;return e[0]=1-(p+x),e[1]=c+y,e[2]=d-g,e[3]=0,e[4]=c-y,e[5]=1-(u+x),e[6]=f+m,e[7]=0,e[8]=d+g,e[9]=f-m,e[10]=1-(u+p),e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function u(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function c(e,t){var r=t[0],i=t[1],s=t[2],a=t[4],n=t[5],o=t[6],h=t[8],l=t[9],u=t[10];return e[0]=Math.sqrt(r*r+i*i+s*s),e[1]=Math.sqrt(a*a+n*n+o*o),e[2]=Math.sqrt(h*h+l*l+u*u),e}function d(e,r){var i=new t(3);c(i,r);var s=1/i[0],a=1/i[1],n=1/i[2],o=r[0]*s,h=r[1]*a,l=r[2]*n,u=r[4]*s,d=r[5]*a,p=r[6]*n,f=r[8]*s,x=r[9]*a,m=r[10]*n,g=o+d+m,y=0;return g>0?(y=2*Math.sqrt(g+1),e[3]=.25*y,e[0]=(p-x)/y,e[1]=(f-l)/y,e[2]=(h-u)/y):o>d&&o>m?(y=2*Math.sqrt(1+o-d-m),e[3]=(p-x)/y,e[0]=.25*y,e[1]=(h+u)/y,e[2]=(f+l)/y):d>m?(y=2*Math.sqrt(1+d-o-m),e[3]=(f-l)/y,e[0]=(h+u)/y,e[1]=.25*y,e[2]=(p+x)/y):(y=2*Math.sqrt(1+m-o-d),e[3]=(h-u)/y,e[0]=(f+l)/y,e[1]=(p+x)/y,e[2]=.25*y),e}function p(e,t){var r=t[0],i=t[1],s=t[2],a=t[3],n=r+r,o=i+i,h=s+s,l=r*n,u=i*n,c=i*o,d=s*n,p=s*o,f=s*h,x=a*n,m=a*o,g=a*h;return e[0]=1-c-f,e[1]=u+g,e[2]=d-m,e[3]=0,e[4]=u-g,e[5]=1-l-f,e[6]=p+x,e[7]=0,e[8]=d+m,e[9]=p-x,e[10]=1-l-c,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}var f=function(e,t,r,i,s){var a=1/Math.tan(t/2);if(e[0]=a/r,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!=s&&s!==1/0){var n=1/(i-s);e[10]=(s+i)*n,e[14]=2*s*i*n}else e[10]=-1,e[14]=-2*i;return e};function x(){var e=new t(3);return t!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function m(e,r,i){var s=new t(3);return s[0]=e,s[1]=r,s[2]=i,s}function g(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function y(e,t,r,i){return e[0]=t,e[1]=r,e[2]=i,e}function v(e,t){var r=t[0],i=t[1],s=t[2],a=r*r+i*i+s*s;return a>0&&(a=1/Math.sqrt(a)),e[0]=t[0]*a,e[1]=t[1]*a,e[2]=t[2]*a,e}function T(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function w(e,t,r){var i=t[0],s=t[1],a=t[2],n=r[0],o=r[1],h=r[2];return e[0]=s*h-a*o,e[1]=a*n-i*h,e[2]=i*o-s*n,e}function E(e,t,r,i){var s=t[0],a=t[1],n=t[2];return e[0]=s+i*(r[0]-s),e[1]=a+i*(r[1]-a),e[2]=n+i*(r[2]-n),e}function R(){var e=new t(4);return t!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function S(e,t,r,i,s){return e[0]=t,e[1]=r,e[2]=i,e[3]=s,e}function _(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3];return e[0]=r[0]*i+r[4]*s+r[8]*a+r[12]*n,e[1]=r[1]*i+r[5]*s+r[9]*a+r[13]*n,e[2]=r[2]*i+r[6]*s+r[10]*a+r[14]*n,e[3]=r[3]*i+r[7]*s+r[11]*a+r[15]*n,e}function b(){var e=new t(4);return t!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function M(e,t,r){r*=.5;var i=Math.sin(r);return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=Math.cos(r),e}function A(t,r,i,s){var a,n,o,h,l,u=r[0],c=r[1],d=r[2],p=r[3],f=i[0],x=i[1],m=i[2],g=i[3];return(n=u*f+c*x+d*m+p*g)<0&&(n=-n,f=-f,x=-x,m=-m,g=-g),1-n>e?(a=Math.acos(n),o=Math.sin(a),h=Math.sin((1-s)*a)/o,l=Math.sin(s*a)/o):(h=1-s,l=s),t[0]=h*u+l*f,t[1]=h*c+l*x,t[2]=h*d+l*m,t[3]=h*p+l*g,t}x(),function(){var e=R()}();var F,P=function(e,r,i,s){var a=new t(4);return a[0]=e,a[1]=r,a[2]=i,a[3]=s,a},I=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},L=S,C=function(e,t){var r=t[0],i=t[1],s=t[2],a=t[3],n=r*r+i*i+s*s+a*a;return n>0&&(n=1/Math.sqrt(n)),e[0]=r*n,e[1]=i*n,e[2]=s*n,e[3]=a*n,e};function D(){var e=new t(2);return t!=Float32Array&&(e[0]=0,e[1]=0),e}x(),m(1,0,0),m(0,1,0),b(),b(),F=new t(9),t!=Float32Array&&(F[1]=0,F[2]=0,F[3]=0,F[5]=0,F[6]=0,F[7]=0),F[0]=1,F[4]=1,F[8]=1,function(){var e=D()}();const N=Symbol("@iwer/action-player"),B=Symbol("@iwer/action-recorder"),O=Symbol("@iwer/xr-anchor"),U=Symbol("@iwer/xr-controller"),V=Symbol("@iwer/xr-device"),G=Symbol("@iwer/xr-hand-input"),X=Symbol("@iwer/xr-tracked-input"),q=Symbol("@iwer/xr-frame"),z=Symbol("@iwer/gamepad"),H=Symbol("@iwer/xr-system"),k=Symbol("@iwer/xr-input-source"),W=Symbol("@iwer/xr-webgl-layer"),j=Symbol("@iwer/xr-mesh"),Y=Symbol("@iwer/xr-plane"),Q=Symbol("@iwer/xr-joint-pose"),$=Symbol("@iwer/xr-pose"),K=Symbol("@iwer/xr-viewer-pose"),J=Symbol("@iwer/xr-rigid-transform"),Z=Symbol("@iwer/xr-render-state"),ee=Symbol("@iwer/xr-session"),te=Symbol("@iwer/xr-joint-space"),re=Symbol("@iwer/xr-reference-space"),ie=Symbol("@iwer/xr-space"),se=Symbol("@iwer/xr-view"),ae=Symbol("@iwer/xr-viewport"),ne=Symbol("@iwer/xr-ray"),oe=Symbol("@iwer/xr-hit-test");class he extends EventTarget{constructor(e,t){super(),this[ie]={parentSpace:e,offsetMatrix:t?i(t):r(),emulated:!0}}}class le extends he{constructor(){super(void 0,r())}}class ue{static updateOffsetPosition(e,t){o(e[ie].offsetMatrix,t)}static updateOffsetQuaternion(e,t){const r=e[ie].offsetMatrix,i=x();u(i,r),l(r,t,i)}static updateOffsetMatrix(e,t){s(e[ie].offsetMatrix,t)}static calculateGlobalOffsetMatrix(e,t=r()){return n(t,e[ie].parentSpace?ue.calculateGlobalOffsetMatrix(e[ie].parentSpace):r(),e[ie].offsetMatrix),t}}class ce{constructor(e=0,t=0,r=0){this.vec3=m(e,t,r),this.tempVec3=x()}get x(){return this.vec3[0]}set x(e){this.vec3[0]=e}get y(){return this.vec3[1]}set y(e){this.vec3[1]=e}get z(){return this.vec3[2]}set z(e){this.vec3[2]=e}set(e,t,r){return y(this.vec3,e,t,r),this}clone(){return new ce(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}normalize(){return g(this.tempVec3,this.vec3),v(this.vec3,this.tempVec3),this}add(e){return g(this.tempVec3,this.vec3),function(e,t,r){e[0]=t[0]+r[0],e[1]=t[1]+r[1],e[2]=t[2]+r[2]}(this.vec3,this.tempVec3,e.vec3),this}applyQuaternion(e){return g(this.tempVec3,this.vec3),function(e,t,r){var i=r[0],s=r[1],a=r[2],n=r[3],o=t[0],h=t[1],l=t[2],u=s*l-a*h,c=a*o-i*l,d=i*h-s*o;u+=u,c+=c,d+=d,e[0]=o+n*u+s*d-a*c,e[1]=h+n*c+a*u-i*d,e[2]=l+n*d+i*c-s*u}(this.vec3,this.tempVec3,e.quat),this}}class de{constructor(e=0,t=0,r=0,i=1){this.quat=P(e,t,r,i),this.tempQuat=b()}get x(){return this.quat[0]}set x(e){this.quat[0]=e}get y(){return this.quat[1]}set y(e){this.quat[1]=e}get z(){return this.quat[2]}set z(e){this.quat[2]=e}get w(){return this.quat[3]}set w(e){this.quat[3]=e}set(e,t,r,i){return L(this.quat,e,t,r,i),this}clone(){return new de(this.x,this.y,this.z,this.w)}copy(e){return L(this.quat,e.x,e.y,e.z,e.w),this}normalize(){return I(this.tempQuat,this.quat),C(this.quat,this.tempQuat),this}invert(){return I(this.tempQuat,this.quat),function(e,t){e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3]}(this.quat,this.tempQuat),this}multiply(e){return I(this.tempQuat,this.quat),function(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3],o=r[0],h=r[1],l=r[2],u=r[3];e[0]=i*u+n*o+s*l-a*h,e[1]=s*u+n*h+a*o-i*l,e[2]=a*u+n*l+i*h-s*o,e[3]=n*u-i*o-s*h-a*l}(this.quat,this.tempQuat,e.quat),this}setFromAxisAngle(e,t){return M(this.quat,e.vec3,t),this}}var pe,fe,xe;!function(e){e.None="",e.Standard="standard",e.XRStandard="xr-standard"}(pe||(pe={}));class me{constructor(e,t){this[z]={type:e,eventTrigger:t,pressed:!1,touched:!1,value:0,lastFrameValue:0,pendingValue:null}}get pressed(){return"manual"===this[z].type?this[z].pressed:this[z].value>0}get touched(){return"manual"===this[z].type?this[z].touched:this[z].touched||this.pressed}get value(){return this[z].value}}class ge{constructor(){this.pressed=!1,this.touched=!1,this.value=0}}class ye{constructor(e,t="",r=-1){this[z]={id:t,index:r,connected:!1,timestamp:performance.now(),mapping:e.mapping,buttonsMap:{},buttonsSequence:[],axesMap:{},axesSequence:[],hapticActuators:[]},e.buttons.forEach(e=>{var t;null===e?this[z].buttonsSequence.push(null):(this[z].buttonsSequence.push(e.id),this[z].buttonsMap[e.id]=new me(e.type,null!==(t=e.eventTrigger)&&void 0!==t?t:null))}),e.axes.forEach(e=>{null===e?this[z].axesSequence.push(null):(this[z].axesSequence.push(e.id+e.type),this[z].axesMap[e.id]||(this[z].axesMap[e.id]={x:0,y:0}))})}get id(){return this[z].id}get index(){return this[z].index}get connected(){return this[z].connected}get timestamp(){return this[z].timestamp}get mapping(){return this[z].mapping}get axes(){const e=[];return this[z].axesSequence.forEach(t=>{if(null===t)e.push(null);else{const r=t.substring(0,t.length-6),i=t.substring(t.length-6);e.push("y-axis"===i?this[z].axesMap[r].y:this[z].axesMap[r].x)}}),e}get buttons(){return this[z].buttonsSequence.map(e=>null===e?new ge:this[z].buttonsMap[e])}get hapticActuators(){return this[z].hapticActuators}get vibrationActuator(){return null}}!function(e){e.None="none",e.Left="left",e.Right="right"}(fe||(fe={})),function(e){e.Gaze="gaze",e.TrackedPointer="tracked-pointer",e.Screen="screen",e.TransientPointer="transient-pointer"}(xe||(xe={}));class ve extends Array{}class Te{constructor(e,t,r,i,s,a,n){this[k]={handedness:e,targetRayMode:t,targetRaySpace:i,gripSpace:a,profiles:r,gamepad:s,hand:n}}get handedness(){return this[k].handedness}get targetRayMode(){return this[k].targetRayMode}get targetRaySpace(){return this[k].targetRaySpace}get gripSpace(){return this[k].gripSpace}get profiles(){return this[k].profiles}get gamepad(){return this[k].gamepad}get hand(){return this[k].hand}}class we extends Event{constructor(e,t){if(super(e,t),!t.frame)throw new Error("XRInputSourceEventInit.frame is required");if(!t.inputSource)throw new Error("XRInputSourceEventInit.inputSource is required");this.frame=t.frame,this.inputSource=t.inputSource}}const Ee={[fe.Left]:{position:new ce(-.25,1.5,-.4),quaternion:new de},[fe.Right]:{position:new ce(.25,1.5,-.4),quaternion:new de},[fe.None]:{position:new ce(.25,1.5,-.4),quaternion:new de}};class Re{constructor(e){this[X]={inputSource:e,position:Ee[e.handedness].position.clone(),quaternion:Ee[e.handedness].quaternion.clone(),connected:!0,lastFrameConnected:!1,inputSourceChanged:!0}}get position(){return this[X].position}get quaternion(){return this[X].quaternion}get inputSource(){return this[X].inputSource}get connected(){return this[X].connected}set connected(e){this[X].connected=e,this[X].inputSource.gamepad[z].connected=e}onFrameStart(e){l(this[X].inputSource.targetRaySpace[ie].offsetMatrix,this[X].quaternion.quat,this[X].position.vec3);const t=e.session;this[X].inputSource.gamepad.buttons.forEach(r=>{r instanceof me&&(r[z].lastFrameValue=r[z].value,null!=r[z].pendingValue&&(r[z].value=r[z].pendingValue,r[z].pendingValue=null),null!=r[z].eventTrigger&&(0===r[z].lastFrameValue&&r[z].value>0?(t.dispatchEvent(new we(r[z].eventTrigger,{frame:e,inputSource:this[X].inputSource})),t.dispatchEvent(new we(r[z].eventTrigger+"start",{frame:e,inputSource:this[X].inputSource}))):r[z].lastFrameValue>0&&0===r[z].value&&t.dispatchEvent(new we(r[z].eventTrigger+"end",{frame:e,inputSource:this[X].inputSource}))))}),this[X].inputSourceChanged=this.connected!==this[X].lastFrameConnected,this[X].lastFrameConnected=this.connected}}class Se extends Re{constructor(e,t,r){if(!e.layout[t])throw new DOMException("Handedness not supported","InvalidStateError");const i=new he(r),s=e.layout[t].gripOffsetMatrix?new he(i,e.layout[t].gripOffsetMatrix):void 0,a=[e.profileId,...e.fallbackProfileIds];super(new Te(t,xe.TrackedPointer,a,i,new ye(e.layout[t].gamepad),s)),this[U]={profileId:e.profileId,gamepadConfig:e.layout[t].gamepad}}get gamepadConfig(){return this[U].gamepadConfig}get profileId(){return this[U].profileId}updateButtonValue(e,t){if(t>1||t<0)return void console.warn(`Out-of-range value ${t} provided for button ${e}.`);const r=this[X].inputSource.gamepad[z].buttonsMap[e];if(r){if("binary"===r[z].type&&1!=t&&0!=t)return void console.warn(`Non-binary value ${t} provided for binary button ${e}.`);r[z].pendingValue=t}else console.warn(`Current controller does not have button ${e}.`)}updateButtonTouch(e,t){const r=this[X].inputSource.gamepad[z].buttonsMap[e];r?r[z].touched=t:console.warn(`Current controller does not have button ${e}.`)}updateAxis(e,t,r){if(r>1||r<-1)return void console.warn(`Out-of-range value ${r} provided for ${e} axes.`);const i=this[X].inputSource.gamepad[z].axesMap[e];i?"x-axis"===t?i.x=r:"y-axis"===t&&(i.y=r):console.warn(`Current controller does not have ${e} axes.`)}updateAxes(e,t,r){if(t>1||t<-1||r>1||r<-1)return void console.warn(`Out-of-range value x:${t}, y:${r} provided for ${e} axes.`);const i=this[X].inputSource.gamepad[z].axesMap[e];i?(i.x=t,i.y=r):console.warn(`Current controller does not have ${e} axes.`)}}class _e{constructor(e,t,r,i,s){this[j]={nativeMesh:e,frame:void 0,meshSpace:t,vertices:r,indices:i,lastChangedTime:performance.now(),semanticLabel:s}}get meshSpace(){return this[j].meshSpace}get vertices(){return this[j].vertices}get indices(){return this[j].indices}get lastChangedTime(){return this[j].lastChangedTime}get semanticLabel(){return this[j].semanticLabel}}class be extends Set{}class Me{constructor(e,t,r,i){this.transform=e,this.vertices=t,this.indices=r,this.semanticLabel=i}}var Ae,Fe;!function(e){e.Desk="desk",e.Couch="couch",e.Floor="floor",e.Ceiling="ceiling",e.Wall="wall",e.Door="door",e.Window="window",e.Table="table",e.Shelf="shelf",e.Bed="bed",e.Screen="screen",e.Lamp="lamp",e.Plant="plant",e.WallArt="wall art",e.GlobalMesh="global mesh",e.Other="other"}(Ae||(Ae={})),function(e){e.Horizontal="horizontal",e.Vertical="vertical"}(Fe||(Fe={}));const Pe={[Ae.Desk]:Fe.Horizontal,[Ae.Couch]:Fe.Horizontal,[Ae.Floor]:Fe.Horizontal,[Ae.Ceiling]:Fe.Horizontal,[Ae.Wall]:Fe.Vertical,[Ae.Door]:Fe.Vertical,[Ae.Window]:Fe.Vertical,[Ae.Table]:Fe.Horizontal,[Ae.Shelf]:Fe.Horizontal,[Ae.Bed]:Fe.Horizontal,[Ae.Screen]:Fe.Horizontal,[Ae.Lamp]:Fe.Horizontal,[Ae.Plant]:Fe.Horizontal,[Ae.WallArt]:Fe.Vertical};class Ie{constructor(e,t,r,i){this[Y]={nativePlane:e,frame:void 0,planeSpace:t,polygon:r,lastChangedTime:performance.now(),semanticLabel:i,orientation:i?Pe[i]:void 0}}get planeSpace(){return this[Y].planeSpace}get polygon(){return this[Y].polygon}get orientation(){return this[Y].orientation}get lastChangedTime(){return this[Y].lastChangedTime}get semanticLabel(){return this[Y].semanticLabel}}class Le extends Set{}class Ce{constructor(e,t,r){this.transform=e,this.polygon=t,this.semanticLabel=r}}class De{constructor(e,t){this[O]={anchorSpace:e,session:t,deleted:!1},t[ee].trackedAnchors.add(this)}get anchorSpace(){if(this[O].deleted)throw new DOMException("XRAnchor has already been deleted.","InvalidStateError");return this[O].anchorSpace}requestPersistentHandle(){return new Promise((e,t)=>{if(this[O].deleted)t(new DOMException("XRAnchor has already been deleted.","InvalidStateError"));else{const t=this[O].session[ee].persistentAnchors;for(const[r,i]of t.entries())if(i===this)return void e(r);const r=crypto.randomUUID();Oe.createPersistentAnchor(this[O].session,this,r),e(r)}})}delete(){this[O].deleted||(this[O].anchorSpace=null,this[O].deleted=!0,this[O].session[ee].trackedAnchors.delete(this))}}class Ne extends Set{}const Be="@immersive-web-emulation-runtime/persistent-anchors";class Oe{static recoverPersistentAnchorsFromStorage(e){const t=JSON.parse(localStorage.getItem(Be)||"{}");Object.entries(t).forEach(([t,r])=>{const i=e[ee].device[V].globalSpace,s=new he(i,r),a=new De(s,e);e[ee].persistentAnchors.set(t,a)})}static createPersistentAnchor(e,t,r){e[ee].trackedAnchors.add(t),e[ee].persistentAnchors.set(r,t);const i=JSON.parse(localStorage.getItem(Be)||"{}");i[r]=Array.from(t[O].anchorSpace[ie].offsetMatrix),localStorage.setItem(Be,JSON.stringify(i))}}class Ue{constructor(e,t){const i=m(0,0,0),s=b();this[J]={matrix:r(),position:e?m(e.x,e.y,e.z):i,orientation:t?C(b(),P(t.x,t.y,t.z,t.w)):s,inverse:null},this.updateMatrix()}updateMatrix(){l(this[J].matrix,this[J].orientation,this[J].position)}get matrix(){return this[J].matrix}get position(){const e=this[J].position;return new DOMPointReadOnly(e[0],e[1],e[2],1)}get orientation(){const e=this[J].orientation;return new DOMPointReadOnly(e[0],e[1],e[2],e[3])}get inverse(){if(!this[J].inverse){const e=r();if(!a(e,this[J].matrix))throw new Error("Matrix is not invertible.");let t=x();u(t,e);let i=b();d(i,e),this[J].inverse=new Ue(new DOMPointReadOnly(t[0],t[1],t[2],1),new DOMPointReadOnly(i[0],i[1],i[2],i[3])),this[J].inverse[J].inverse=this}return this[J].inverse}}class Ve{constructor(e=0,t=0,r=0,i=1){this.x=e,this.y=t,this.z=r,this.w=i}}class Ge{constructor(e,t){const r={x:0,y:0,z:0,w:1},i={x:0,y:0,z:-1,w:0};if(e instanceof Ue){const t=e.matrix,s=S(R(),r.x,r.y,r.z,r.w),a=S(R(),i.x,i.y,i.z,i.w);_(s,s,t),_(a,a,t),r.x=s[0],r.y=s[1],r.z=s[2],r.w=s[3],i.x=a[0],i.y=a[1],i.z=a[2],i.w=a[3]}else if(e&&(r.x=e.x,r.y=e.y,r.z=e.z,r.w=e.w),t){if(0===t.x&&0===t.y&&0===t.z||0!==t.w)throw new DOMException("Invalid direction value to construct XRRay","TypeError");i.x=t.x,i.y=t.y,i.z=t.z,i.w=t.w}const s=Math.sqrt(i.x*i.x+i.y*i.y+i.z*i.z)||1;i.x=i.x/s,i.y=i.y/s,i.z=i.z/s,this[ne]={origin:new Ve(r.x,r.y,r.z,r.w),direction:new Ve(i.x,i.y,i.z,i.w),matrix:null}}get origin(){return this[ne].origin}get direction(){return this[ne].direction}get matrix(){if(this[ne].matrix)return this[ne].matrix;const e=y(x(),0,0,-1),t=y(x(),this[ne].origin.x,this[ne].origin.y,this[ne].origin.z),i=y(x(),this[ne].direction.x,this[ne].direction.y,this[ne].direction.z),s=w(x(),i,e),a=T(i,e),l=r();a>-1&&a<1?h(l,Math.acos(a),s):-1===a?h(l,Math.acos(a),y(x(),1,0,0)):function(e){e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1}(l);const u=o(r(),t),c=n(r(),u,l);return this[ne].matrix=new Float32Array(c),this[ne].matrix}}class Xe{constructor(e,t){var r;this[oe]={session:e,space:t.space,offsetRay:null!==(r=t.offsetRay)&&void 0!==r?r:new Ge}}cancel(){this[oe].session[ee].hitTestSources.delete(this)}}class qe{constructor(e,t){this[oe]={frame:e,offsetSpace:t}}getPose(e){return this[oe].frame.getPose(this[oe].offsetSpace,e)}createAnchor(){return this[oe].frame.createAnchor(new Ue,this[oe].offsetSpace)}}class ze extends Event{constructor(e,t){if(super(e,t),!t.session)throw new Error("XRInputSourcesChangeEventInit.session is required");if(!t.added)throw new Error("XRInputSourcesChangeEventInit.added is required");if(!t.removed)throw new Error("XRInputSourcesChangeEventInit.removed is required");this.session=t.session,this.added=t.added,this.removed=t.removed}}var He,ke,We;!function(e){e.Viewer="viewer",e.Local="local",e.LocalFloor="local-floor",e.BoundedFloor="bounded-floor",e.Unbounded="unbounded"}(ke||(ke={}));class je extends he{constructor(e,t,r){super(t,r),this[He]={type:null,onreset:()=>{}},this[re].type=e}get onreset(){var e;return null!==(e=this[re].onreset)&&void 0!==e?e:()=>{}}set onreset(e){this[re].onreset&&this.removeEventListener("reset",this[re].onreset),this[re].onreset=e,e&&this.addEventListener("reset",e)}getOffsetReferenceSpace(e){return new je(this[re].type,this,e)}}He=re;class Ye{constructor(e={},t){this[Z]={depthNear:e.depthNear||(null==t?void 0:t.depthNear)||.1,depthFar:e.depthFar||(null==t?void 0:t.depthFar)||1e3,inlineVerticalFieldOfView:e.inlineVerticalFieldOfView||(null==t?void 0:t.inlineVerticalFieldOfView)||null,baseLayer:e.baseLayer||(null==t?void 0:t.baseLayer)||null}}get depthNear(){return this[Z].depthNear}get depthFar(){return this[Z].depthFar}get inlineVerticalFieldOfView(){return this[Z].inlineVerticalFieldOfView}get baseLayer(){return this[Z].baseLayer}}class Qe extends Event{constructor(e,t){if(super(e,t),!t.session)throw new Error("XRSessionEventInit.session is required");this.session=t.session}}!function(e){e.None="none",e.Left="left",e.Right="right"}(We||(We={}));class $e{constructor(e,t,r,i){this[se]={eye:e,projectionMatrix:t,transform:r,recommendedViewportScale:null,requestedViewportScale:1,session:i}}get eye(){return this[se].eye}get projectionMatrix(){return this[se].projectionMatrix}get transform(){return this[se].transform}get recommendedViewportScale(){return this[se].recommendedViewportScale}requestViewportScale(e){null===e||e<=0||e>1?console.warn("Invalid scale value. Scale must be > 0 and <= 1."):this[se].requestedViewportScale=e}}class Ke{constructor(e,t=!1,r=void 0,i=void 0){this[$]={transform:e,emulatedPosition:t,linearVelocity:r,angularVelocity:i}}get transform(){return this[$].transform}get emulatedPosition(){return this[$].emulatedPosition}get linearVelocity(){return this[$].linearVelocity}get angularVelocity(){return this[$].angularVelocity}}class Je extends Ke{constructor(e,t,r=!1,i=void 0,s=void 0){super(e,r,i,s),this[Q]={radius:t}}get radius(){return this[Q].radius}}class Ze extends Ke{constructor(e,t,r=!1,i=void 0,s=void 0){super(e,r,i,s),this[K]={views:Object.freeze(t)}}get views(){return this[K].views}}const et=r(),tt=r(),rt=r(),it=(e,t,r)=>{ue.calculateGlobalOffsetMatrix(t,et),ue.calculateGlobalOffsetMatrix(r,tt),a(rt,tt),n(e,rt,et)};class st{constructor(e,t,i,s,a){this[q]={session:e,id:t,active:i,animationFrame:s,predictedDisplayTime:a,tempMat4:r(),detectedPlanes:new Le,detectedMeshes:new be,trackedAnchors:e[ee].frameTrackedAnchors,hitTestResultsMap:new Map}}get session(){return this[q].session}get predictedDisplayTime(){return this[q].predictedDisplayTime}getPose(e,t){if(!this[q].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");it(this[q].tempMat4,e,t);const r=x();u(r,this[q].tempMat4);const i=b();return d(i,this[q].tempMat4),new Ke(new Ue({x:r[0],y:r[1],z:r[2],w:1},{x:i[0],y:i[1],z:i[2],w:i[3]}),e[ie].emulated)}getViewerPose(e){if(!this[q].animationFrame)throw new DOMException("getViewerPose can only be called on XRFrame objects passed to XRSession.requestAnimationFrame callbacks.","InvalidStateError");const t=this[q].session,r=t[ee].device,i=this.getPose(r.viewerSpace,e),s="inline"===t[ee].mode?[We.None]:[We.Left,We.Right],a=[];return s.forEach(i=>{const s=r.viewSpaces[i],n=this.getPose(s,e),o=t[ee].getProjectionMatrix(i),h=new $e(i,new Float32Array(o),n.transform,t);a.push(h)}),new Ze(i.transform,a,!1)}getJointPose(e,t){const r=this.getPose(e,t),i=e[te].radius;return new Je(r.transform,i,!1)}fillJointRadii(e,t){if(e=Array.from(e),!this[q].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");if(e.length>t.length)throw new DOMException("The length of jointSpaces is larger than the number of elements in radii","TypeError");let r=!0;for(let i=0;i<e.length;i++)e[i][te].radius?t[i]=e[i][te].radius:(t[i]=NaN,r=!1);return r}fillPoses(e,t,r){if(e=Array.from(e),!this[q].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");if(16*e.length>r.length)throw new DOMException("The length of spaces multiplied by 16 is larger than the number of elements in transforms","TypeError");return e.forEach((e,i)=>{it(this[q].tempMat4,e,t);for(let e=0;e<16;e++)r[16*i+e]=this[q].tempMat4[e]}),!0}get detectedPlanes(){if(!this[q].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[q].detectedPlanes}get detectedMeshes(){if(!this[q].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[q].detectedMeshes}get trackedAnchors(){if(!this[q].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[q].trackedAnchors}createAnchor(e,t){return new Promise((r,i)=>{if(this[q].active){const s=this[q].session[ee].device[V].globalSpace,a=new he(t,e.matrix),n=ue.calculateGlobalOffsetMatrix(a),o=new he(s,n),h=new De(o,this[q].session);this[q].session[ee].trackedAnchors.add(h),this[q].session[ee].newAnchors.set(h,{resolve:r,reject:i})}else i(new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError"))})}getHitTestResults(e){if(this[q].active){if(this[q].hitTestResultsMap.has(e))return[...this[q].hitTestResultsMap.get(e)];throw new DOMException("Requested hit test results are not available for current frame.","InvalidStateError")}throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError")}}var at,nt,ot;!function(e){e.Opaque="opaque",e.AlphaBlend="alpha-blend",e.Additive="additive"}(at||(at={})),function(e){e.ScreenSpace="screen-space",e.WorldSpace="world-space"}(nt||(nt={}));class ht extends EventTarget{constructor(e,t,i){super(),this[ee]={device:e,mode:t,renderState:new Ye,pendingRenderState:null,enabledFeatures:i,isSystemKeyboardSupported:!1,ended:!1,projectionMatrices:{[We.Left]:r(),[We.Right]:r(),[We.None]:r()},getProjectionMatrix:e=>this[ee].projectionMatrices[e],referenceSpaceIsSupported:e=>{if(!this[ee].enabledFeatures.includes(e))return!1;switch(e){case ke.Viewer:return!0;case ke.Local:case ke.LocalFloor:case ke.BoundedFloor:case ke.Unbounded:return"inline"!=this[ee].mode}},frameHandle:0,frameCallbacks:[],currentFrameCallbacks:null,onDeviceFrame:()=>{if(this[ee].ended)return;this[ee].deviceFrameHandle=globalThis.requestAnimationFrame(this[ee].onDeviceFrame),null!=this[ee].pendingRenderState&&(this[ee].renderState=this[ee].pendingRenderState,this[ee].pendingRenderState=null,this[ee].device[V].onBaseLayerSet(this[ee].renderState.baseLayer));const e=this[ee].renderState.baseLayer;if(null===e)return;const t=e.context,r=t.canvas;if("inline"!=this[ee].mode){const e=t.getParameter(t.COLOR_CLEAR_VALUE),r=t.getParameter(t.DEPTH_CLEAR_VALUE),i=t.getParameter(t.STENCIL_CLEAR_VALUE);t.clearColor(0,0,0,0),t.clearDepth(1),t.clearStencil(0),t.clear(t.DEPTH_BUFFER_BIT|t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT),t.clearColor(e[0],e[1],e[2],e[3]),t.clearDepth(r),t.clearStencil(i)}const{depthNear:i,depthFar:a}=this[ee].renderState,{width:n,height:o}=r;if("inline"!==this[ee].mode){const e=n*(this[ee].device.stereoEnabled?.5:1)/o;f(this[ee].projectionMatrices[We.Left],this[ee].device.fovy,e,i,a),s(this[ee].projectionMatrices[We.Right],this[ee].projectionMatrices[We.Left])}else{const e=n/o;f(this[ee].projectionMatrices[We.None],this[ee].renderState.inlineVerticalFieldOfView,e,i,a)}const h=new st(this,this[ee].frameHandle,!0,!0,performance.now()),l=performance.now(),u=this[ee].device[V].devui;if(u&&u.render(l),"immersive-ar"===this[ee].mode){const e=this[ee].device[V].sem;e&&e.render(l)}this[ee].enabledFeatures.includes("anchors")&&this[ee].updateTrackedAnchors(),this[ee].enabledFeatures.includes("plane-detection")&&this[ee].updateTrackedPlanes(h),this[ee].enabledFeatures.includes("mesh-detection")&&this[ee].updateTrackedMeshes(h),this[ee].enabledFeatures.includes("hit-test")&&this[ee].computeHitTestResults(h),this[ee].device[V].onFrameStart(h),this[ee].updateActiveInputSources();const c=this[ee].currentFrameCallbacks=this[ee].frameCallbacks;this[ee].frameCallbacks=[];const d=performance.now();for(let e=0;e<c.length;e++)try{c[e].cancelled||c[e].callback(d,h)}catch(e){console.error(e)}this[ee].currentFrameCallbacks=null,h[q].active=!1},nominalFrameRate:e.internalNominalFrameRate,referenceSpaces:[],inputSourceArray:[],activeInputSources:[],updateActiveInputSources:()=>{const e=this[ee].enabledFeatures.includes("hand-tracking"),t=this[ee].activeInputSources,r=this[ee].device.inputSources.filter(t=>!t.hand||e),i=r.filter(e=>!t.includes(e)),s=t.filter(e=>!r.includes(e));this[ee].activeInputSources=r,(i.length>0||s.length>0)&&this.dispatchEvent(new ze("inputsourceschange",{session:this,added:i,removed:s}))},trackedAnchors:new Ne,persistentAnchors:new Map,newAnchors:new Map,frameTrackedAnchors:new Ne,updateTrackedAnchors:()=>{this[ee].enabledFeatures.includes("anchors")&&(this[ee].frameTrackedAnchors.clear(),Array.from(this[ee].trackedAnchors).forEach(e=>{if(e[O].deleted){if(this[ee].trackedAnchors.delete(e),this[ee].newAnchors.has(e)){const{reject:t}=this[ee].newAnchors.get(e);t(new DOMException("Anchor is no longer tracked","InvalidStateError"))}}else if(this[ee].frameTrackedAnchors.add(e),this[ee].newAnchors.has(e)){const{resolve:t}=this[ee].newAnchors.get(e);t(e),this[ee].newAnchors.delete(e)}}))},trackedPlanes:new Map,updateTrackedPlanes:e=>{const t=this[ee].device[V].sem;if(!t)return;Array.from(this[ee].trackedPlanes.keys()).forEach(e=>{t.trackedPlanes.has(e)||this[ee].trackedPlanes.delete(e)}),t.trackedPlanes.forEach(t=>{let r=this[ee].trackedPlanes.get(t);if(!r){const e=new he(this[ee].device[V].globalSpace,t.transform.matrix);r=new Ie(t,e,t.polygon,t.semanticLabel),this[ee].trackedPlanes.set(t,r)}r[Y].lastChangedTime=e.predictedDisplayTime,r[Y].frame=e,e[q].detectedPlanes.add(r)})},trackedMeshes:new Map,updateTrackedMeshes:e=>{const t=this[ee].device[V].sem;if(!t)return;Array.from(this[ee].trackedMeshes.keys()).forEach(e=>{t.trackedMeshes.has(e)||this[ee].trackedMeshes.delete(e)}),t.trackedMeshes.forEach(t=>{let r=this[ee].trackedMeshes.get(t);if(!r){const e=new he(this[ee].device[V].globalSpace,t.transform.matrix);r=new _e(t,e,t.vertices,t.indices,t.semanticLabel),this[ee].trackedMeshes.set(t,r)}r[j].lastChangedTime=e.predictedDisplayTime,r[j].frame=e,e[q].detectedMeshes.add(r)})},hitTestSources:new Set,computeHitTestResults:e=>{const t=this[ee].device[V].sem;if(!t)return;const i=this[ee].device[V].globalSpace;this[ee].hitTestSources.forEach(s=>{const a=s[oe].space,o=ue.calculateGlobalOffsetMatrix(a),h=s[oe].offsetRay.matrix,l=r();n(l,o,h);const u=[];t.computeHitTestResults(l).forEach(t=>{const r=new he(i,t),s=new qe(e,r);u.push(s)}),e[q].hitTestResultsMap.set(s,u)})},onend:null,oninputsourceschange:null,onselect:null,onselectstart:null,onselectend:null,onsqueeze:null,onsqueezestart:null,onsqueezeend:null,onvisibilitychange:null,onframeratechange:null},Oe.recoverPersistentAnchorsFromStorage(this),this[ee].onDeviceFrame()}get visibilityState(){return this[ee].device.visibilityState}get frameRate(){return this[ee].nominalFrameRate}get supportedFrameRates(){return new Float32Array(this[ee].device.supportedFrameRates)}get renderState(){return this[ee].renderState}get inputSources(){return this[ee].inputSourceArray.length=0,this[ee].ended||"inline"===this[ee].mode||this[ee].inputSourceArray.push(...this[ee].activeInputSources),this[ee].inputSourceArray}get enabledFeatures(){return this[ee].enabledFeatures}get isSystemKeyboardSupported(){return this[ee].isSystemKeyboardSupported}get environmentBlendMode(){var e;return null!==(e=this[ee].device[V].environmentBlendModes[this[ee].mode])&&void 0!==e?e:at.Opaque}get interactionMode(){return this[ee].device[V].interactionMode}updateRenderState(e={}){var t,r,i,s;if(this[ee].ended)throw new DOMException("XRSession has already ended.","InvalidStateError");if(e.baseLayer&&e.baseLayer[W].session!==this)throw new DOMException("Base layer was created by a different XRSession","InvalidStateError");if(null!=e.inlineVerticalFieldOfView&&"inline"!==this[ee].mode)throw new DOMException("InlineVerticalFieldOfView must not be set for an immersive session","InvalidStateError");const a={baseLayer:e.baseLayer||(null===(t=this[ee].pendingRenderState)||void 0===t?void 0:t.baseLayer)||void 0,depthFar:e.depthFar||(null===(r=this[ee].pendingRenderState)||void 0===r?void 0:r.depthFar)||void 0,depthNear:e.depthNear||(null===(i=this[ee].pendingRenderState)||void 0===i?void 0:i.depthNear)||void 0,inlineVerticalFieldOfView:e.inlineVerticalFieldOfView||(null===(s=this[ee].pendingRenderState)||void 0===s?void 0:s.inlineVerticalFieldOfView)||void 0};this[ee].pendingRenderState=new Ye(a,this[ee].renderState)}async updateTargetFrameRate(e){return new Promise((t,r)=>{this[ee].ended?r(new DOMException("XRSession has already ended.","InvalidStateError")):this[ee].device.supportedFrameRates.includes(e)?(this[ee].nominalFrameRate===e?console.log("Requested frame rate is the same as the current nominal frame rate, no update made"):(this[ee].nominalFrameRate=e,this.dispatchEvent(new Qe("frameratechange",{session:this})),console.log(`Nominal frame rate updated to ${e}`)),t()):r(new DOMException("Requested frame rate not supported.","InvalidStateError"))})}async requestReferenceSpace(e){return new Promise((t,r)=>{if(this[ee].ended||!this[ee].referenceSpaceIsSupported(e))return void r(new DOMException("The requested reference space type is not supported.","NotSupportedError"));let i;switch(e){case ke.Viewer:i=this[ee].device.viewerSpace;break;case ke.Local:i=new je(e,this[ee].device[V].globalSpace,this[ee].device.viewerSpace[ie].offsetMatrix);break;case ke.LocalFloor:case ke.BoundedFloor:case ke.Unbounded:i=new je(e,this[ee].device[V].globalSpace)}this[ee].referenceSpaces.push(i),t(i)})}requestAnimationFrame(e){if(this[ee].ended)return 0;const t=++this[ee].frameHandle;return this[ee].frameCallbacks.push({handle:t,callback:e,cancelled:!1}),t}cancelAnimationFrame(e){let t=this[ee].frameCallbacks,r=t.findIndex(t=>t&&t.handle===e);r>-1&&(t[r].cancelled=!0,t.splice(r,1)),t=this[ee].currentFrameCallbacks,t&&(r=t.findIndex(t=>t&&t.handle===e),r>-1&&(t[r].cancelled=!0))}async end(){return new Promise((e,t)=>{this[ee].ended||null===this[ee].deviceFrameHandle?t(new DOMException("XRSession has already ended.","InvalidStateError")):(globalThis.cancelAnimationFrame(this[ee].deviceFrameHandle),this[ee].device[V].onSessionEnd(),this.dispatchEvent(new Qe("end",{session:this})),e())})}get persistentAnchors(){return Array.from(this[ee].persistentAnchors.keys())}restorePersistentAnchor(e){return new Promise((t,r)=>{if(this[ee].persistentAnchors.has(e))if(this[ee].ended)r(new DOMException("XRSession has already ended.","InvalidStateError"));else{const i=this[ee].persistentAnchors.get(e);this[ee].newAnchors.has(i)?r(new DOMException(`Multiple concurrent attempts detected to restore the anchor with UUID: ${e}.`,"InvalidStateError")):(this[ee].trackedAnchors.add(i),this[ee].newAnchors.set(i,{resolve:t,reject:r}))}else r(new DOMException(`Persistent anchor with uuid ${e} not found.`,"InvalidStateError"))})}deletePersistentAnchor(e){return new Promise((t,r)=>{if(this[ee].persistentAnchors.has(e)){const r=this[ee].persistentAnchors.get(e);this[ee].persistentAnchors.delete(e),r.delete(),t(void 0)}else r(new DOMException(`Persistent anchor with uuid ${e} not found.`,"InvalidStateError"))})}requestHitTestSource(e){return new Promise((t,r)=>{if(this[ee].enabledFeatures.includes("hit-test"))if(this[ee].ended)r(new DOMException("XRSession has already ended.","InvalidStateError"));else if(this[ee].device[V].sem){const r=new Xe(this,e);this[ee].hitTestSources.add(r),t(r)}else r(new DOMException("Synthethic Environment Module required for emulating hit-test","OperationError"));else r(new DOMException('WebXR feature "hit-test" is not supported by current session',"NotSupportedError"))})}get onend(){var e;return null!==(e=this[ee].onend)&&void 0!==e?e:()=>{}}set onend(e){this[ee].onend&&this.removeEventListener("end",this[ee].onend),this[ee].onend=e,e&&this.addEventListener("end",e)}get oninputsourceschange(){var e;return null!==(e=this[ee].oninputsourceschange)&&void 0!==e?e:()=>{}}set oninputsourceschange(e){this[ee].oninputsourceschange&&this.removeEventListener("inputsourceschange",this[ee].oninputsourceschange),this[ee].oninputsourceschange=e,e&&this.addEventListener("inputsourceschange",e)}get onselect(){var e;return null!==(e=this[ee].onselect)&&void 0!==e?e:()=>{}}set onselect(e){this[ee].onselect&&this.removeEventListener("select",this[ee].onselect),this[ee].onselect=e,e&&this.addEventListener("select",e)}get onselectstart(){var e;return null!==(e=this[ee].onselectstart)&&void 0!==e?e:()=>{}}set onselectstart(e){this[ee].onselectstart&&this.removeEventListener("selectstart",this[ee].onselectstart),this[ee].onselectstart=e,e&&this.addEventListener("selectstart",e)}get onselectend(){var e;return null!==(e=this[ee].onselectend)&&void 0!==e?e:()=>{}}set onselectend(e){this[ee].onselectend&&this.removeEventListener("selectend",this[ee].onselectend),this[ee].onselectend=e,e&&this.addEventListener("selectend",e)}get onsqueeze(){var e;return null!==(e=this[ee].onsqueeze)&&void 0!==e?e:()=>{}}set onsqueeze(e){this[ee].onsqueeze&&this.removeEventListener("squeeze",this[ee].onsqueeze),this[ee].onsqueeze=e,e&&this.addEventListener("squeeze",e)}get onsqueezestart(){var e;return null!==(e=this[ee].onsqueezestart)&&void 0!==e?e:()=>{}}set onsqueezestart(e){this[ee].onsqueezestart&&this.removeEventListener("squeezestart",this[ee].onsqueezestart),this[ee].onsqueezestart=e,e&&this.addEventListener("squeezestart",e)}get onsqueezeend(){var e;return null!==(e=this[ee].onsqueezeend)&&void 0!==e?e:()=>{}}set onsqueezeend(e){this[ee].onsqueezeend&&this.removeEventListener("squeezeend",this[ee].onsqueezeend),this[ee].onsqueezeend=e,e&&this.addEventListener("squeezeend",e)}get onvisibilitychange(){var e;return null!==(e=this[ee].onvisibilitychange)&&void 0!==e?e:()=>{}}set onvisibilitychange(e){this[ee].onvisibilitychange&&this.removeEventListener("visibilitychange",this[ee].onvisibilitychange),this[ee].onvisibilitychange=e,e&&this.addEventListener("visibilitychange",e)}get onframeratechange(){var e;return null!==(e=this[ee].onframeratechange)&&void 0!==e?e:()=>{}}set onframeratechange(e){this[ee].onframeratechange&&this.removeEventListener("frameratechange",this[ee].onframeratechange),this[ee].onframeratechange=e,e&&this.addEventListener("frameratechange",e)}}!function(e){e.Wrist="wrist",e.ThumbMetacarpal="thumb-metacarpal",e.ThumbPhalanxProximal="thumb-phalanx-proximal",e.ThumbPhalanxDistal="thumb-phalanx-distal",e.ThumbTip="thumb-tip",e.IndexFingerMetacarpal="index-finger-metacarpal",e.IndexFingerPhalanxProximal="index-finger-phalanx-proximal",e.IndexFingerPhalanxIntermediate="index-finger-phalanx-intermediate",e.IndexFingerPhalanxDistal="index-finger-phalanx-distal",e.IndexFingerTip="index-finger-tip",e.MiddleFingerMetacarpal="middle-finger-metacarpal",e.MiddleFingerPhalanxProximal="middle-finger-phalanx-proximal",e.MiddleFingerPhalanxIntermediate="middle-finger-phalanx-intermediate",e.MiddleFingerPhalanxDistal="middle-finger-phalanx-distal",e.MiddleFingerTip="middle-finger-tip",e.RingFingerMetacarpal="ring-finger-metacarpal",e.RingFingerPhalanxProximal="ring-finger-phalanx-proximal",e.RingFingerPhalanxIntermediate="ring-finger-phalanx-intermediate",e.RingFingerPhalanxDistal="ring-finger-phalanx-distal",e.RingFingerTip="ring-finger-tip",e.PinkyFingerMetacarpal="pinky-finger-metacarpal",e.PinkyFingerPhalanxProximal="pinky-finger-phalanx-proximal",e.PinkyFingerPhalanxIntermediate="pinky-finger-phalanx-intermediate",e.PinkyFingerPhalanxDistal="pinky-finger-phalanx-distal",e.PinkyFingerTip="pinky-finger-tip"}(ot||(ot={}));class lt extends Map{}class ut extends he{constructor(e,t,r){super(t,r),this[te]={jointName:e,radius:0}}get jointName(){return this[te].jointName}}const ct={profileId:"oculus-hand",fallbackProfileIds:["generic-hand","generic-hand-select","generic-trigger"],poses:{default:{jointTransforms:{wrist:{offsetMatrix:[.9616971015930176,-.13805118203163147,.2368120402097702,0,.0005348679260350764,.8648636937141418,.5020061135292053,0,-.2741127610206604,-.48265108466148376,.8318111300468445,0,-.04913589730858803,.0021463718730956316,.11701996624469757,1],radius:.021460847929120064},"thumb-metacarpal":{offsetMatrix:[-.07536252588033676,-.9959676265716553,-.04867160692811012,0,.5877083539962769,-.08379616588354111,.8047218918800354,0,-.8055551648139954,.032041035592556,.5916536450386047,0,-.010643752291798592,.0006936835707165301,.08736639469861984,1],radius:.019382517784833908},"thumb-phalanx-proximal":{offsetMatrix:[.1374533325433731,-.9904957413673401,.004982374142855406,0,.5534393787384033,.08097179979085922,.8289443850517273,0,-.8214688897132874,-.11118389666080475,.559309184551239,0,.015547193586826324,-.0003480653394944966,.0681300163269043,1],radius:.01228295173496008},"thumb-phalanx-distal":{offsetMatrix:[-.04659227654337883,-.9974699020385742,-.05369402840733528,0,.6812446117401123,-.07104194164276123,.728600800037384,0,-.7305715084075928,-.002631746232509613,.6828309893608093,0,.04330715537071228,.003409178927540779,.0492292083799839,1],radius:.009768804535269737},"thumb-tip":{offsetMatrix:[-.04659227654337883,-.9974699020385742,-.05369402840733528,0,.6812446117401123,-.07104194164276123,.728600800037384,0,-.7305715084075928,-.002631746232509613,.6828309893608093,0,.062003348022699356,.004069602582603693,.03322213143110275,1],radius:.008768804371356964},"index-finger-metacarpal":{offsetMatrix:[.9616971015930176,-.13805118203163147,.2368120402097702,0,.0005348679260350764,.8648636937141418,.5020061135292053,0,-.2741127610206604,-.48265108466148376,.8318111300468445,0,-.02009812369942665,.008770795539021492,.08660387247800827,1],radius:.021228281781077385},"index-finger-phalanx-proximal":{offsetMatrix:[.9001791477203369,-.2598813474178314,.3494834005832672,0,.06073702871799469,.8695210218429565,.490146666765213,0,-.4312632381916046,-.41999316215515137,.7985095381736755,0,-.00017739279428496957,.03890012577176094,.039073407649993896,1],radius:.010295259766280651},"index-finger-phalanx-intermediate":{offsetMatrix:[.9082008600234985,-.20898112654685974,.36262574791908264,0,.11045389622449875,.9553793668746948,.27395179867744446,0,-.40369608998298645,-.20874978601932526,.8907597661018372,0,.01617925800383091,.05482936650514603,.008788082748651505,1],radius:.00853810179978609},"index-finger-phalanx-distal":{offsetMatrix:[.9309692978858948,-.16783711314201355,.32423174381256104,0,.1080828532576561,.9749603867530823,.1943446695804596,0,-.34873148798942566,-.14588497579097748,.9257990717887878,0,.02599053829908371,.059902746230363846,-.012860597111284733,1],radius:.007636196445673704},"index-finger-tip":{offsetMatrix:[.9309692978858948,-.16783711314201355,.32423174381256104,0,.1080828532576561,.9749603867530823,.1943446695804596,0,-.34873148798942566,-.14588497579097748,.9257990717887878,0,.03362493962049484,.06421422213315964,-.033461250364780426,1],radius:.006636196281760931},"middle-finger-metacarpal":{offsetMatrix:[.9616971015930176,-.13805118203163147,.2368120402097702,0,.0005348679260350764,.8648636937141418,.5020061135292053,0,-.2741127610206604,-.48265108466148376,.8318111300468445,0,-.03627845644950867,.011579737067222595,.08550142496824265,1],radius:.021231964230537415},"middle-finger-phalanx-proximal":{offsetMatrix:[.9876697659492493,-.06786545366048813,.1410750150680542,0,-.015095947310328484,.855663537979126,.5173118710517883,0,-.15582047402858734,-.5130629539489746,.8440889716148376,0,-.021259509027004242,.04587256908416748,.03659208118915558,1],radius:.01117393933236599},"middle-finger-phalanx-intermediate":{offsetMatrix:[.988391637802124,-.04354291781783104,.14555205404758453,0,.008894841186702251,.9729899168014526,.23067504167556763,0,-.15166506171226501,-.22670257091522217,.9620829224586487,0,-.014570588245987892,.06789684295654297,.0003578895702958107,1],radius:.008030958473682404},"middle-finger-phalanx-distal":{offsetMatrix:[.9853697419166565,.044260796159505844,.16458062827587128,0,-.0757969319820404,.9787378311157227,.19059516489505768,0,-.1526455283164978,-.20028135180473328,.9677740931510925,0,-.010392282158136368,.07414241135120392,-.026147106662392616,1],radius:.007629410829395056},"middle-finger-tip":{offsetMatrix:[.9853697419166565,.044260796159505844,.16458062827587128,0,-.0757969319820404,.9787378311157227,.19059516489505768,0,-.1526455283164978,-.20028135180473328,.9677740931510925,0,-.0069718430750072,.08024183660745621,-.05014154314994812,1],radius:.006629410665482283},"ring-finger-metacarpal":{offsetMatrix:[.9616971015930176,-.13805118203163147,.2368120402097702,0,.0005348679260350764,.8648636937141418,.5020061135292053,0,-.2741127610206604,-.48265108466148376,.8318111300468445,0,-.05402477830648422,.015797706320881844,.08152295649051666,1],radius:.019088275730609894},"ring-finger-phalanx-proximal":{offsetMatrix:[.9940828680992126,.05735103040933609,.09224652498960495,0,-.10022822767496109,.8116500377655029,.5754809379577637,0,-.041867565363645554,-.5813214182853699,.8125960826873779,0,-.041623555123806,.04171867296099663,.03582974523305893,1],radius:.00992213748395443},"ring-finger-phalanx-intermediate":{offsetMatrix:[.9843675494194031,.12044742703437805,.12850022315979004,0,-.15629759430885315,.9337108135223389,.3221098482608795,0,-.08118485659360886,-.3371586799621582,.937940776348114,0,-.039990875869989395,.06438793987035751,.004141641780734062,1],radius:.007611672393977642},"ring-finger-phalanx-distal":{offsetMatrix:[.9748351573944092,.11857274919748306,.18877571821212769,0,-.15575434267520905,.9681083559989929,.19623035192489624,0,-.15948788821697235,-.22069483995437622,.9622148275375366,0,-.03783353418111801,.07334739714860916,-.020782606676220894,1],radius:.007231088820844889},"ring-finger-tip":{offsetMatrix:[.9748351573944092,.11857274919748306,.18877571821212769,0,-.15575434267520905,.9681083559989929,.19623035192489624,0,-.15948788821697235,-.22069483995437622,.9622148275375366,0,-.03445569798350334,.0802423357963562,-.04392268508672714,1],radius:.0062310886569321156},"pinky-finger-metacarpal":{offsetMatrix:[.9181402921676636,.35625091195106506,.17350243031978607,0,-.39615097641944885,.8352503180503845,.38134080171585083,0,-.009065053425729275,-.41885748505592346,.9080066680908203,0,-.06191859766840935,.013620133511722088,.07850203663110733,1],radius:.01808827556669712},"pinky-finger-phalanx-proximal":{offsetMatrix:[.9714386463165283,.236698180437088,-.016745081171393394,0,-.18462024629116058,.7982627749443054,.5733163952827454,0,.14906984567642212,-.5538501739501953,.8191629648208618,0,-.061502378433942795,.032741155475378036,.03705105185508728,1],radius:.008483353070914745},"pinky-finger-phalanx-intermediate":{offsetMatrix:[.9337416291236877,.35620439052581787,-.03527557849884033,0,-.33203884959220886,.8987522721290588,.28634607791900635,0,.13370157778263092,-.2556603252887726,.9574766755104065,0,-.06608185172080994,.049755651503801346,.011886020191013813,1],radius:.0067641944624483585},"pinky-finger-phalanx-distal":{offsetMatrix:[.9419984817504883,.3303581774234772,.059175245463848114,0,-.33483216166496277,.9130291938781738,.23294763267040253,0,.02292730286717415,-.2392500638961792,.970687210559845,0,-.0687975287437439,.054948460310697556,-.007561664097011089,1],radius:.0064259846694767475},"pinky-finger-tip":{offsetMatrix:[.9419984817504883,.3303581774234772,.059175245463848114,0,-.33483216166496277,.9130291938781738,.23294763267040253,0,.02292730286717415,-.2392500638961792,.970687210559845,0,-.06947512179613113,.0613851435482502,-.028543535619974136,1],radius:.005425984505563974}},gripOffsetMatrix:[-.0005348679260350764,-.8648636937141418,-.5020061135292053,0,-.2741127908229828,-.48265108466148376,.8318111896514893,0,-.9616971015930176,.13805119693279266,-.2368120402097702,0,-.02878567762672901,.0017147823236882687,.04536811262369156,1]},pinch:{jointTransforms:{wrist:{offsetMatrix:[.9060805439949036,-.1844543218612671,.3807799518108368,0,-.08027800172567368,.8086723685264587,.5827555656433105,0,-.4154181182384491,-.5585917234420776,.7179155349731445,0,-.06867414712905884,-.009423808194696903,.10627774149179459,1],radius:.021460847929120064},"thumb-metacarpal":{offsetMatrix:[-.5012241005897522,-.8650535345077515,-.0213695727288723,0,.7415963411331177,-.4421543478965759,.5045139193534851,0,-.44587990641593933,.23702676594257355,.8631392121315002,0,-.032122574746608734,-.01196830440312624,.07194234430789948,1],radius:.019382517784833908},"thumb-phalanx-proximal":{offsetMatrix:[-.3175753057003021,-.9460570216178894,-.06419729441404343,0,.8958902955055237,-.32153913378715515,.30658137798309326,0,-.3106854259967804,.03984907269477844,.9496771097183228,0,-.017625702545046806,-.01967475935816765,.04387917369604111,1],radius:.01228295173496008},"thumb-phalanx-distal":{offsetMatrix:[-.4944636821746826,-.8691971898078918,.001086252392269671,0,.8307800889015198,-.4722411036491394,.2946045398712158,0,-.25555649399757385,.14657381176948547,.9556186199188232,0,-.007126678712666035,-.021021386608481407,.011786630377173424,1],radius:.009768804535269737},"thumb-tip":{offsetMatrix:[-.4944636821746826,-.8691971898078918,.001086252392269671,0,.8307800889015198,-.4722411036491394,.2946045398712158,0,-.25555649399757385,.14657381176948547,.9556186199188232,0,.0003423091256991029,-.024528030306100845,-.011410919018089771,1],radius:.008768804371356964},"index-finger-metacarpal":{offsetMatrix:[.9060805439949036,-.1844543218612671,.3807799518108368,0,-.08027800172567368,.8086723685264587,.5827555656433105,0,-.4154181182384491,-.5585917234420776,.7179155349731445,0,-.038037415593862534,-.0020236473064869642,.07626739144325256,1],radius:.021228281781077385},"index-finger-phalanx-proximal":{offsetMatrix:[.7986818552017212,-.35985732078552246,.48229536414146423,0,.538311243057251,.7854709625244141,-.30537736415863037,0,-.2689369022846222,.5035246014595032,.8210577368736267,0,-.006869405973702669,.033938243985176086,.04206443578004837,1],radius:.010295259766280651},"index-finger-phalanx-intermediate":{offsetMatrix:[.8285930156707764,-.32672837376594543,.4546217918395996,0,.5577570199966431,.4116027057170868,-.7207564115524292,0,.04836784675717354,.8507823944091797,.5232869386672974,0,.0033306588884443045,.014840902760624886,.010923954658210278,1],radius:.00853810179978609},"index-finger-phalanx-distal":{offsetMatrix:[.8412464261054993,-.35794928669929504,.4051857888698578,0,.5139996409416199,.29711154103279114,-.8046918511390686,0,.16765329241752625,.8852096796035767,.4339304566383362,0,.0021551470272243023,-.0058362227864563465,-.0017938464879989624,1],radius:.007636196445673704},"index-finger-tip":{offsetMatrix:[.8412464261054993,-.35794928669929504,.4051857888698578,0,.5139996409416199,.29711154103279114,-.8046918511390686,0,.16765329241752625,.8852096796035767,.4339304566383362,0,-.00131594471167773,-.025222131982445717,-.012442642822861671,1],radius:.006636196281760931},"middle-finger-metacarpal":{offsetMatrix:[.9060805439949036,-.1844543218612671,.3807799518108368,0,-.08027800172567368,.8086723685264587,.5827555656433105,0,-.4154181182384491,-.5585917234420776,.7179155349731445,0,-.05395089089870453,.003063359996303916,.07402937114238739,1],radius:.021231964230537415},"middle-finger-phalanx-proximal":{offsetMatrix:[.9187911748886108,-.1530158370733261,.36387869715690613,0,.038666240870952606,.9522662162780762,.302808940410614,0,-.3928440511226654,-.26414817571640015,.8808513283729553,0,-.02717282809317112,.04162866622209549,.03678669035434723,1],radius:.01117393933236599},"middle-finger-phalanx-intermediate":{offsetMatrix:[.9228746294975281,-.12856416404247284,.36300456523895264,0,.14524033665657043,.9892153143882751,-.01890045404434204,0,-.3566599190235138,.07016586512327194,.9315956234931946,0,-.01030921470373869,.05296773463487625,-.0010256498353555799,1],radius:.008030958473682404},"middle-finger-phalanx-distal":{offsetMatrix:[.9325166344642639,-.040404170751571655,.35885775089263916,0,.06836572289466858,.995502769947052,-.0655682161450386,0,-.3545948565006256,.08567725121974945,.9310863614082336,0,-.0004833847051486373,.05103470757603645,-.026690717786550522,1],radius:.007629410829395056},"middle-finger-tip":{offsetMatrix:[.9325166344642639,-.040404170751571655,.35885775089263916,0,.06836572289466858,.995502769947052,-.0655682161450386,0,-.3545948565006256,.08567725121974945,.9310863614082336,0,.008158999495208263,.05004044249653816,-.050120558589696884,1],radius:.006629410665482283},"ring-finger-metacarpal":{offsetMatrix:[.9060805439949036,-.1844543218612671,.3807799518108368,0,-.08027800172567368,.8086723685264587,.5827555656433105,0,-.4154181182384491,-.5585917234420776,.7179155349731445,0,-.06732909381389618,.007902119308710098,.07209732383489609,1],radius:.019088275730609894},"ring-finger-phalanx-proximal":{offsetMatrix:[.9391821026802063,-.027994679287075996,.34227466583251953,0,-.18282271921634674,.8029410243034363,.5673282742500305,0,-.2907087206840515,-.5954000353813171,.7489906549453735,0,-.047129884362220764,.03806127607822418,.032147664576768875,1],radius:.00992213748395443},"ring-finger-phalanx-intermediate":{offsetMatrix:[.9249380826950073,.03699534013867378,.3783116042613983,0,-.12898847460746765,.9667453765869141,.2208271026611328,0,-.3575615882873535,-.25304901599884033,.8989526629447937,0,-.03579339757561684,.06127955764532089,.002939916681498289,1],radius:.007611672393977642},"ring-finger-phalanx-distal":{offsetMatrix:[.9001164436340332,.03983335196971893,.4338230490684509,0,-.09662467986345291,.9892624020576477,.10964841395616531,0,-.4247973561286926,-.14061418175697327,.8943013548851013,0,-.026291755959391594,.06800390034914017,-.02094830758869648,1],radius:.007231088820844889},"ring-finger-tip":{offsetMatrix:[.9001164436340332,.03983335196971893,.4338230490684509,0,-.09662467986345291,.9892624020576477,.10964841395616531,0,-.4247973561286926,-.14061418175697327,.8943013548851013,0,-.016345610842108727,.07300511747598648,-.04263874143362045,1],radius:.0062310886569321156},"pinky-finger-metacarpal":{offsetMatrix:[.8769711852073669,.31462907791137695,.36322021484375,0,-.4506046175956726,.801031768321991,.39408499002456665,0,-.16696058213710785,-.5092697143554688,.8442559838294983,0,-.07460174709558487,.0062340241856873035,.06756893545389175,1],radius:.01808827556669712},"pinky-finger-phalanx-proximal":{offsetMatrix:[.9498357176780701,.1553308218717575,.2714462876319885,0,-.3019258379936218,.6817675232887268,.6663586497306824,0,-.08155745267868042,-.7148879170417786,.694466233253479,0,-.06697750836610794,.029482364654541016,.02902858518064022,1],radius:.008483353070914745},"pinky-finger-phalanx-intermediate":{offsetMatrix:[.9214097261428833,.27928245067596436,.2701927423477173,0,-.3670244514942169,.8538867831230164,.36901235580444336,0,-.12765564024448395,-.43917882442474365,.8892839550971985,0,-.06447203457355499,.05144399777054787,.0076942890882492065,1],radius:.0067641944624483585},"pinky-finger-phalanx-distal":{offsetMatrix:[.9038633704185486,.23618005216121674,.3567195236682892,0,-.3532794713973999,.8823202252388,.3109731376171112,0,-.24129553139209747,-.4070987403392792,.8809353709220886,0,-.06187915802001953,.060364335775375366,-.010368337854743004,1],radius:.0064259846694767475},"pinky-finger-tip":{offsetMatrix:[.9038633704185486,.23618005216121674,.3567195236682892,0,-.3532794713973999,.8823202252388,.3109731376171112,0,-.24129553139209747,-.4070987403392792,.8809353709220886,0,-.056796226650476456,.07042007893323898,-.02921444922685623,1],radius:.005425984505563974}},gripOffsetMatrix:[.08027800917625427,-.8086723685264587,-.5827556252479553,0,-.4154181480407715,-.5585916638374329,.7179154753684998,0,-.9060805439949036,.1844543218612671,-.3807799518108368,0,-.038054611533880234,-.002910431008785963,.03720742464065552,1]},point:{jointTransforms:{wrist:{offsetMatrix:[.9340395331382751,-.13936476409435272,.32885703444480896,0,-.005510995630174875,.914999783039093,.40341612696647644,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.05789132043719292,.01670890860259533,.11183350533246994,1],radius:.021460847929120064},"thumb-metacarpal":{offsetMatrix:[.02145560085773468,-.9978390336036682,.0621047280728817,0,.41311800479888916,.06541631370782852,.9083252549171448,0,-.9104245901107788,.006167683284729719,.4136286973953247,0,-.016488194465637207,.012708572670817375,.08862338215112686,1],radius:.019382517784833908},"thumb-phalanx-proximal":{offsetMatrix:[.21270370483398438,-.966137707233429,.14606566727161407,0,.49890995025634766,.2359165996313095,.8339261412620544,0,-.8401462435722351,-.10450579971075058,.5321959853172302,0,.013112368993461132,.012508046813309193,.07517509907484055,1],radius:.01228295173496008},"thumb-phalanx-distal":{offsetMatrix:[.01653280481696129,-.9986647963523865,.048943229019641876,0,.26313456892967224,.051570065319538116,.9633802771568298,0,-.9646173715591431,-.0030490627977997065,.26363563537597656,0,.04150351136922836,.016039609909057617,.05719054117798805,1],radius:.009768804535269737},"thumb-tip":{offsetMatrix:[.01653280481696129,-.9986647963523865,.048943229019641876,0,.26313456892967224,.051570065319538116,.9633802771568298,0,-.9646173715591431,-.0030490627977997065,.26363563537597656,0,.06548332422971725,.01683700829744339,.0516640841960907,1],radius:.008768804371356964},"index-finger-metacarpal":{offsetMatrix:[.9340395331382751,-.13936476409435272,.32885703444480896,0,-.005510995630174875,.914999783039093,.40341612696647644,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.02592567168176174,.019982583820819855,.08479326963424683,1],radius:.021228281781077385},"index-finger-phalanx-proximal":{offsetMatrix:[.9063700437545776,-.21756279468536377,.3621589243412018,0,.0970839336514473,.9415287375450134,.3226419687271118,0,-.41117796301841736,-.2572731077671051,.8744958639144897,0,-.0015709538711234927,.043078210204839706,.034657616168260574,1],radius:.010295259766280651},"index-finger-phalanx-intermediate":{offsetMatrix:[.9159826040267944,-.1651475727558136,.36565208435058594,0,.09755707532167435,.9756820797920227,.1962820291519165,0,-.3891757130622864,-.14411886036396027,.9098196625709534,0,.014023927971720695,.052835866808891296,.0014903299743309617,1],radius:.00853810179978609},"index-finger-phalanx-distal":{offsetMatrix:[.9378057718276978,-.12329639494419098,.3245268166065216,0,.032558172941207886,.9619227051734924,.2713746726512909,0,-.3456292748451233,-.2439306229352951,.9061115384101868,0,.023482320830225945,.05633850023150444,-.020621655508875847,1],radius:.007636196445673704},"index-finger-tip":{offsetMatrix:[.9378057718276978,-.12329639494419098,.3245268166065216,0,.032558172941207886,.9619227051734924,.2713746726512909,0,-.3456292748451233,-.2439306229352951,.9061115384101868,0,.03096788562834263,.06281610578298569,-.040703095495700836,1],radius:.006636196281760931},"middle-finger-metacarpal":{offsetMatrix:[.9340395331382751,-.13936476409435272,.32885703444480896,0,-.005510995630174875,.914999783039093,.40341612696647644,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.04184452444314957,.022474845871329308,.08177298307418823,1],radius:.021231964230537415},"middle-finger-phalanx-proximal":{offsetMatrix:[.9720265865325928,-.08313076198101044,.21966552734375,0,.20477405190467834,.7580050826072693,-.6192700862884521,0,-.11502730846405029,.6469289064407349,.7538246512413025,0,-.022107340395450592,.05035499855875969,.02970452979207039,1],radius:.01117393933236599},"middle-finger-phalanx-intermediate":{offsetMatrix:[.9779140949249268,-.07129573822021484,.19646917283535004,0,.1287083923816681,-.5352076292037964,-.8348574042320251,0,.1646735966205597,.8417060971260071,-.5142109394073486,0,-.017169542610645294,.022584279999136925,-.00265491777099669,1],radius:.008030958473682404},"middle-finger-phalanx-distal":{offsetMatrix:[.9774913787841797,-.19657190144062042,.07661263644695282,0,-.1924918293952942,-.9796126484870911,-.05749811604619026,0,.08635343611240387,.041456472128629684,-.995401918888092,0,-.02170622907578945,-.0006043742760084569,.011511396616697311,1],radius:.007629410829395056},"middle-finger-tip":{offsetMatrix:[.9774913787841797,-.19657190144062042,.07661263644695282,0,-.1924918293952942,-.9796126484870911,-.05749811604619026,0,.08635343611240387,.041456472128629684,-.995401918888092,0,-.02438267692923546,-.0026927536819130182,.03627248480916023,1],radius:.006629410665482283},"ring-finger-metacarpal":{offsetMatrix:[.9340395331382751,-.13936476409435272,.32885703444480896,0,-.005510995630174875,.914999783039093,.40341612696647644,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.05944233387708664,.0264605600386858,.07478221505880356,1],radius:.019088275730609894},"ring-finger-phalanx-proximal":{offsetMatrix:[.9842101335525513,.024470895528793335,.1753024309873581,0,.12200043350458145,.6237703561782837,-.7720272541046143,0,-.12824076414108276,.7812241315841675,.610936164855957,0,-.04249368980526924,.0467497780919075,.027722163125872612,1],radius:.00992213748395443},"ring-finger-phalanx-intermediate":{offsetMatrix:[.9941774606704712,.05949164181947708,.08983955532312393,0,.10504482686519623,-.7208291888237,-.6851072907447815,0,.024001073092222214,.6905553936958313,-.7228817939758301,0,-.0374927744269371,.016285063698887825,.0038980208337306976,1],radius:.007611672393977642},"ring-finger-phalanx-distal":{offsetMatrix:[.9995742440223694,.01638498157262802,.02412819117307663,0,.007813597097992897,-.9474818110466003,.31971633434295654,0,.028100071474909782,-.31939181685447693,-.9472070932388306,0,-.038130562752485275,-.0020653479732573032,.02310742810368538,1],radius:.007231088820844889},"ring-finger-tip":{offsetMatrix:[.9995742440223694,.01638498157262802,.02412819117307663,0,.007813597097992897,-.9474818110466003,.31971633434295654,0,.028100071474909782,-.31939181685447693,-.9472070932388306,0,-.0390593595802784,.004176302347332239,.0466572530567646,1],radius:.0062310886569321156},"pinky-finger-metacarpal":{offsetMatrix:[.9147363901138306,.3458845317363739,.20885537564754486,0,-.3923271894454956,.8839452862739563,.2544005811214447,0,-.09662359952926636,-.3146490156650543,.9442773461341858,0,-.06715242564678192,.024195827543735504,.07137546688318253,1],radius:.01808827556669712},"pinky-finger-phalanx-proximal":{offsetMatrix:[.9613109827041626,.22439135611057281,.15977802872657776,0,.01002211682498455,.5511574745178223,-.8343409299850464,0,-.27528178691864014,.8036624789237976,.5275853276252747,0,-.06273911893367767,.038559623062610626,.028268879279494286,1],radius:.008483353070914745},"pinky-finger-phalanx-intermediate":{offsetMatrix:[.9820972084999084,.18811029195785522,-.00995189044624567,0,.14063723385334015,-.7673450708389282,-.6256227493286133,0,-.12532226741313934,.6130226850509644,-.7800630927085876,0,-.05428232625126839,.013870777562260628,.012061242014169693,1],radius:.0067641944624483585},"pinky-finger-phalanx-distal":{offsetMatrix:[.9744614362716675,.20454788208007812,-.09265263378620148,0,.22429193556308746,-.9065253138542175,.35764020681381226,0,-.010836843401193619,-.3692878782749176,-.9292529225349426,0,-.05173685774207115,.0014194445684552193,.02790539152920246,1],radius:.0064259846694767475},"pinky-finger-tip":{offsetMatrix:[.9744614362716675,.20454788208007812,-.09265263378620148,0,.22429193556308746,-.9065253138542175,.35764020681381226,0,-.010836843401193619,-.3692878782749176,-.9292529225349426,0,-.05098633095622063,.008463085629045963,.048688892275094986,1],radius:.005425984505563974}},gripOffsetMatrix:[.005510995630174875,-.9149997234344482,-.40341615676879883,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.9340395331382751,.13936474919319153,-.32885703444480896,0,-.031803809106349945,.007837686687707901,.04313928261399269,1]}}},dt={mapping:pe.None,buttons:[{id:"pinch",type:"analog",eventTrigger:"select"}],axes:[]},pt=x(),ft=b(),xt=x(),mt=x(),gt=b(),yt=x(),vt=x(),Tt=b(),wt=x(),Et=(e,t,r,i)=>(u(pt,t),d(ft,t),c(xt,t),u(mt,r),d(gt,r),c(yt,r),E(vt,pt,mt,i),A(Tt,ft,gt,i),E(wt,xt,yt,i),function(e,t,r,i){var s=t[0],a=t[1],n=t[2],o=t[3],h=s+s,l=a+a,u=n+n,c=s*h,d=s*l,p=s*u,f=a*l,x=a*u,m=n*u,g=o*h,y=o*l,v=o*u,T=i[0],w=i[1],E=i[2];e[0]=(1-(f+m))*T,e[1]=(d+v)*T,e[2]=(p-y)*T,e[3]=0,e[4]=(d-v)*w,e[5]=(1-(c+m))*w,e[6]=(x+g)*w,e[7]=0,e[8]=(p+y)*E,e[9]=(x-g)*E,e[10]=(1-(c+f))*E,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1}(e,Tt,vt,wt),e),Rt=[1,-1,-1,0,-1,1,1,0,-1,1,1,0,-1,1,1,1];class St extends Re{constructor(e,t,r){if(t!==fe.Left&&t!==fe.Right)throw new DOMException('handedness for XRHandInput must be either "left" or "right"',"InvalidStateError");if(!e.poses.default||!e.poses.pinch)throw new DOMException('"default" and "pinch" hand pose configs are required',"InvalidStateError");const i=new he(r),s=new he(i),a=[e.profileId,...e.fallbackProfileIds],n=new lt;Object.values(ot).forEach(e=>{n.set(e,new ut(e,i))});super(new Te(t,xe.TrackedPointer,a,i,new ye(dt),s,n)),this[G]={poseId:"default",poses:e.poses},this.updateHandPose()}get poseId(){return this[G].poseId}set poseId(e){this[G].poses[e]?this[G].poseId=e:console.warn(`Pose config ${e} not found`)}updateHandPose(){const e=this[G].poses[this[G].poseId],t=this[G].poses.pinch;Object.values(ot).forEach(r=>{const i=e.jointTransforms[r].offsetMatrix,s=t.jointTransforms[r].offsetMatrix,a=this.inputSource.hand.get(r);Et(a[ie].offsetMatrix,i,s,this.pinchValue),this.inputSource.handedness===fe.Right&&(e=>{for(let t=0;t<16;t++)e[t]*=Rt[t]})(a[ie].offsetMatrix),a[te].radius=(1-this.pinchValue)*e.jointTransforms[r].radius+this.pinchValue*t.jointTransforms[r].radius}),e.gripOffsetMatrix&&t.gripOffsetMatrix&&Et(this.inputSource.gripSpace[ie].offsetMatrix,e.gripOffsetMatrix,t.gripOffsetMatrix,this.pinchValue)}get pinchValue(){return this[X].inputSource.gamepad[z].buttonsMap.pinch.value}updatePinchValue(e){if(e>1||e<0)return void console.warn(`Out-of-range value ${e} provided for pinch`);this[X].inputSource.gamepad[z].buttonsMap.pinch[z].pendingValue=e}onFrameStart(e){super.onFrameStart(e),this.updateHandPose()}}class _t extends EventTarget{}const bt={antialias:!0,depth:!0,stencil:!1,alpha:!0,ignoreDepthValues:!1,framebufferScaleFactor:1};class Mt extends _t{constructor(e,t,r={}){if(super(),e[ee].ended)throw new DOMException("Session has ended","InvalidStateError");const i={...bt,...r};this[W]={session:e,context:t,antialias:i.antialias}}get context(){return this[W].context}get antialias(){return this[W].antialias}get ignoreDepthValues(){return!0}get framebuffer(){return null}get framebufferWidth(){return this[W].context.drawingBufferWidth}get framebufferHeight(){return this[W].context.drawingBufferHeight}getViewport(e){if(e[se].session!==this[W].session)throw new DOMException("View's session differs from Layer's session","InvalidStateError");return this[W].session[ee].device[V].getViewport(this,e)}static getNativeFramebufferScaleFactor(e){if(!(e instanceof ht))throw new TypeError("getNativeFramebufferScaleFactor must be passed a session.");return e[ee].ended?0:1}}class At{constructor(e,t,r){const{schema:i,frames:s}=t;if(!s||!i||0===s.length)throw new DOMException("wrong recording format","NotSupportedError");const a=new je(ke.Viewer,e),n={[We.Left]:new he(a),[We.Right]:new he(a),[We.None]:new he(a)};this[N]={refSpace:e,inputSources:new Map,inputSchemas:new Map,frames:s,recordedFramePointer:0,startingTimeStamp:s[0][0],endingTimeStamp:s[s.length-1][0],playbackTime:s[0][0],playing:!1,viewerSpace:a,viewSpaces:n,vec3:x(),quat:b()},o(this[N].viewSpaces[We.Left][ie].offsetMatrix,m(-r/2,0,0)),o(this[N].viewSpaces[We.Right][ie].offsetMatrix,m(r/2,0,0)),i.forEach(t=>{const r=t[0],i=t[1];let s;if(i.hasGamepad){const e=[];for(let t=0;t<i.numButtons;t++)e.push({id:t.toString(),type:"manual"});const t=[];for(let e=0;e<i.numAxes;e++)t.push({id:e.toString(),type:"manual"});s=new ye({mapping:i.mapping,buttons:e,axes:t})}const a=new he(e);let n;i.hasHand&&(n=new lt,Object.values(ot).forEach(e=>{n.set(e,new ut(e,a))}));const o=new Te(i.handedness,i.targetRayMode,i.profiles,a,s,i.hasGrip?new he(e):void 0,i.hasHand?n:void 0);this[N].inputSources.set(r,{active:!1,source:o}),this[N].inputSchemas.set(r,i)})}play(){this[N].recordedFramePointer=0,this[N].playbackTime=this[N].startingTimeStamp,this[N].playing=!0,this[N].actualTimeStamp=performance.now()}stop(){this[N].playing=!1}get playing(){return this[N].playing}get viewerSpace(){return this[N].viewerSpace}get viewSpaces(){return this[N].viewSpaces}get inputSources(){return Array.from(this[N].inputSources.values()).filter(e=>e.active).map(e=>e.source)}playFrame(){const e=performance.now(),t=e-this[N].actualTimeStamp;if(this[N].actualTimeStamp=e,this[N].playbackTime+=t,this[N].playbackTime>this[N].endingTimeStamp)return void this.stop();for(;this[N].frames[this[N].recordedFramePointer+1][0]<this[N].playbackTime;)this[N].recordedFramePointer++;const r=this[N].frames[this[N].recordedFramePointer],i=this[N].frames[this[N].recordedFramePointer+1],s=(this[N].playbackTime-r[0])/(i[0]-r[0]);this.updateXRSpaceFromMergedFrames(this[N].viewerSpace,r.slice(1,8),i.slice(1,8),s);const a=new Map;for(let e=8;e<r.length;e++){const{index:t,inputData:i}=this.processRawInputData(r[e]);a.set(t,i)}const n=new Map;for(let e=8;e<i.length;e++){const{index:t,inputData:r}=this.processRawInputData(i[e]);n.set(t,r)}this[N].inputSources.forEach(e=>{e.active=!1}),n.forEach((e,t)=>{this[N].inputSources.get(t).active=!0;const r=this[N].inputSources.get(t).source,i=this[N].inputSchemas.get(t);this.updateInputSource(r,i,a.has(t)?a.get(t):e,e,s)})}updateInputSource(e,t,r,i,s){if(this.updateXRSpaceFromMergedFrames(e.targetRaySpace,r.targetRayTransform,i.targetRayTransform,s),t.hasGrip&&this.updateXRSpaceFromMergedFrames(e.gripSpace,r.gripTransform,i.gripTransform,s),t.hasHand)for(let a=0;a<25;a++){const n=r.handTransforms.slice(8*a,8*a+7),o=i.handTransforms.slice(8*a,8*a+7),h=r.handTransforms[8*a+7],l=i.handTransforms[8*a+7],u=e.hand.get(t.jointSequence[a]);this.updateXRSpaceFromMergedFrames(u,n,o,s),u[te].radius=(l-h)*s+h}if(t.hasGamepad){const t=e.gamepad;i.buttons.forEach((e,i)=>{const a=t.buttons[i];a[z].pressed=1===e[0],a[z].touched=1===e[1];const n=r.buttons[i][2],o=e[2];a[z].value=(o-n)*s+n}),i.axes.forEach((e,i)=>{const a=r.axes[i];t[z].axesMap[i.toString()].x=(e-a)*s+a})}}updateXRSpaceFromMergedFrames(e,t,r,i){const s=m(t[0],t[1],t[2]),a=P(t[3],t[4],t[5],t[6]),n=m(r[0],r[1],r[2]),o=P(r[3],r[4],r[5],r[6]);E(this[N].vec3,s,n,i),A(this[N].quat,a,o,i),l(e[ie].offsetMatrix,this[N].quat,this[N].vec3)}processRawInputData(e){const t=e[0],r=this[N].inputSchemas.get(t),i={targetRayTransform:e.slice(1,8)};let s=8;if(r.hasGrip&&(i.gripTransform=e[s++]),r.hasHand&&(i.handTransforms=e[s++]),r.hasGamepad){const t=e[s];i.buttons=t.slice(0,r.numButtons),i.axes=t.slice(r.numButtons)}return{index:t,inputData:i}}}const Ft="2.1.0";class Pt extends Event{constructor(e,t){if(super(e,t),!t.referenceSpace)throw new Error("XRReferenceSpaceEventInit.referenceSpace is required");this.referenceSpace=t.referenceSpace,this.transform=t.transform}}class It extends EventTarget{constructor(e){super(),this[H]={device:e,grantSession:({resolve:e,reject:t,mode:r,options:i})=>{if(this[H].activeSession)return void t(new DOMException("An active XRSession already exists.","InvalidStateError"));const{requiredFeatures:s=[],optionalFeatures:a=[]}=i,{supportedFeatures:n}=this[H].device;if(!s.every(e=>n.includes(e)))return void t(new Error("One or more required features are not supported by the device."));const o=a.filter(e=>n.includes(e)),h=Array.from(new Set([...s,...o,"viewer","local"])),l=new ht(this[H].device,r,h);this[H].activeSession=l,l.addEventListener("end",()=>{this[H].activeSession=void 0}),e(l)}}}isSessionSupported(e){return new Promise((t,r)=>{t("inline"===e||this[H].device.supportedSessionModes.includes(e))})}requestSession(e,t={}){return new Promise((r,i)=>{this.isSessionSupported(e).then(s=>{if(!s)return void i(new DOMException("The requested XRSession mode is not supported.","NotSupportedError"));const a={resolve:r,reject:i,mode:e,options:t};this[H].grantSession(a)}).catch(i)})}offerSession(e,t={}){return new Promise((r,i)=>{this.isSessionSupported(e).then(s=>{s?this[H].offeredSessionConfig={resolve:r,reject:i,mode:e,options:t}:i(new DOMException("The requested XRSession mode is not supported.","NotSupportedError"))}).catch(i)})}}class Lt{constructor(e,t,r,i){this[ae]={x:e,y:t,width:r,height:i}}get x(){return this[ae].x}get y(){return this[ae].y}get width(){return this[ae].width}get height(){return this[ae].height}}var Ct,Dt;!function(e){e.texture="texture",e["texture-array"]="texture-array"}(Ct||(Ct={})),function(e){e.default="default",e.mono="mono",e.stereo="stereo",e["stereo-left-right"]="stereo-left-right",e["stereo-top-bottom"]="stereo-top-bottom"}(Dt||(Dt={}));const Nt=e=>e&&"function"==typeof e.getOffsetReferenceSpace,Bt=()=>"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},Ot=(e,t)=>{switch(t){case e.RGBA8:case e.RGB5_A1:case e.RGBA4:case e.SRGB8_ALPHA8:return{internalFormat:t,textureFormat:e.RGBA,type:e.UNSIGNED_BYTE};case e.RGBA8_SNORM:return{internalFormat:t,textureFormat:e.RGBA,type:e.BYTE};case e.RGB10_A2:return{internalFormat:t,textureFormat:e.RGBA,type:e.UNSIGNED_INT_2_10_10_10_REV};case e.RGBA16F:return{internalFormat:t,textureFormat:e.RGBA,type:e.HALF_FLOAT};case e.RGBA32F:return{internalFormat:t,textureFormat:e.RGBA,type:e.FLOAT};case e.RGBA8UI:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.UNSIGNED_BYTE};case e.RGBA8I:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.BYTE};case e.RGBA16UI:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.UNSIGNED_SHORT};case e.RGBA16I:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.SHORT};case e.RGBA32UI:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.UNSIGNED_INT};case e.RGBA32I:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.INT};case e.RGB10_A2UI:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.UNSIGNED_INT_2_10_10_10_REV};case e.RGB8:case e.RGB565:case e.SRGB8:return{internalFormat:t,textureFormat:e.RGB,type:e.UNSIGNED_BYTE};case e.RGB8_SNORM:return{internalFormat:t,textureFormat:e.RGB,type:e.BYTE};case e.RGB16F:case e.R11F_G11F_B10F:case e.RGB9_E5:return{internalFormat:t,textureFormat:e.RGB,type:e.HALF_FLOAT};case e.RGB32F:return{internalFormat:t,textureFormat:e.RGB,type:e.FLOAT};case e.RGB8UI:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.UNSIGNED_BYTE};case e.RGB8I:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.BYTE};case e.RGB16UI:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.UNSIGNED_SHORT};case e.RGB16I:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.SHORT};case e.RGB32UI:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.UNSIGNED_INT};case e.RGB32I:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.INT};case e.DEPTH_COMPONENT16:return{internalFormat:t,textureFormat:e.DEPTH_COMPONENT,type:e.UNSIGNED_SHORT};case e.DEPTH_COMPONENT24:return{internalFormat:t,textureFormat:e.DEPTH_COMPONENT,type:e.UNSIGNED_INT};case e.DEPTH_COMPONENT32F:return{internalFormat:t,textureFormat:e.DEPTH_COMPONENT,type:e.FLOAT};case e.DEPTH24_STENCIL8:return{internalFormat:t,textureFormat:e.DEPTH_STENCIL,type:e.UNSIGNED_INT_24_8};case e.DEPTH32F_STENCIL8:return{internalFormat:t,textureFormat:e.DEPTH_STENCIL,type:e.FLOAT_32_UNSIGNED_INT_24_8_REV};case e.DEPTH_COMPONENT:return Ot(e,e.DEPTH_COMPONENT24);case e.DEPTH_STENCIL:return Ot(e,e.DEPTH24_STENCIL8);case e.RGBA:case e.RGB:case e.LUMINANCE_ALPHA:case e.LUMINANCE:case e.ALPHA:return{internalFormat:t,textureFormat:t,type:e.UNSIGNED_BYTE};default:throw new Error("Attempted to create polyfill with unsupported format.")}};class Ut{constructor(){this._hasRunDeferredInitialize=!1,this._media=null}initialize(e,t){this.session=e,t&&(this.context=t),this.blendTextureSourceAlpha=!0}destroy(){this._colorTextures=[],this._depthStencilTextures=[]}addEventListener(e,t,r){}dispatchEvent(e){return!1}removeEventListener(e,t,r){}getContext(){return this.context}getTextureType(){throw new Error("Unimplemented")}get colorTextures(){return this._colorTextures}get depthStencilTextures(){return this._depthStencilTextures}get colorTexturesMeta(){return this._texturesMeta}get media(){return this.isMediaLayer()||console.warn("Attempted to retrieve media from a non-media layer"),this._media}determineLayoutAttribute(e,t,r){if(!(t instanceof WebGL2RenderingContext)&&e===Ct["texture-array"])throw new TypeError;if(r===Dt.mono)return r;if(r===Dt.default){if(this.session.internalViews&&1===this.session.internalViews.length)return Dt.mono;if(e===Ct["texture-array"])return r}return r===Dt.default||r===Dt.stereo?Dt["stereo-left-right"]:r}isMediaLayer(){return null!==this._media}_deferredInitialize(){}initializeIfNeeded(){this._hasRunDeferredInitialize||(this._hasRunDeferredInitialize=!0,this._deferredInitialize())}_allocateColorTexturesInternal(e,t){let r=this.session.internalViews;if(r&&0!==r.length){if(this.initializeIfNeeded(),this.layout===Dt.mono){if(e===Ct["texture-array"]){const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}{const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}}if(this.layout===Dt.stereo){if(e===Ct["texture-array"]){const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat,2);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}{const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat),i=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r,i],void(this._colorTextures=[r.texture,i.texture])}}if(this.layout===Dt["stereo-left-right"]){const r=this._createNewColorTexture(2*t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}if(this.layout===Dt["stereo-top-bottom"]){const r=this._createNewColorTexture(t.viewPixelWidth,2*t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}}else console.warn("We can't allocate color textures without views")}_allocateDepthStencilTexturesInternal(e,t){if(t.depthFormat){if(this._getSupportedDepthFormats().indexOf(t.depthFormat)<0)throw new Error("Depth format provided is not supported in non-projection layers.");if(t.mipLevels<1)throw new Error("Invalid miplevel. Miplevel needs to be >= 1");if(this.layout===Dt.mono){if(e===Ct["texture-array"]){const r=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture])}{const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture])}}if(this.layout===Dt.stereo){if(e===Ct["texture-array"]){const r=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat,2);return void(this._depthStencilTextures=[r.texture])}{const r=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat),i=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture,i.texture])}}if(this.layout===Dt["stereo-left-right"]){const r=this._createNewDepthStencilTexture(2*t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture])}if(this.layout===Dt["stereo-top-bottom"]){const r=this._createNewDepthStencilTexture(t.viewPixelWidth,2*t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture])}}else this._depthStencilTextures=[]}_createNewColorTexture(e,t,r,i,s=1){return this._createGenericPolyfillTexture(r,e,t,i,0,s)}_createNewDepthStencilTexture(e,t,r,i,s=1){return this._createGenericPolyfillTexture(r,e,t,i,0,s)}_createGenericPolyfillTexture(e,t,r,i,s=0,a=1){if(e===Ct["texture-array"]&&a<=1&&console.warn("creating a texture array with a single layer..."),e===Ct["texture-array"]&&this.context instanceof WebGLRenderingContext)throw new Error("WebGL 1 does not support texture array");const n=this._getAutoSampleCount(),o=n>1;let h=this.context.createTexture(),l={width:t,height:r,layers:a,type:e,textureFormat:i,texture:h,_msaaFramebuffer:null,_resolveFramebuffer:null,_autoAntialiasing:o,_samples:n},u=i,c=this.context.UNSIGNED_BYTE;if(this.context instanceof WebGL2RenderingContext){const e=Ot(this.context,i);u=e.internalFormat,i=e.textureFormat,c=e.type}else i===this.context.DEPTH_COMPONENT&&(c=this.context.UNSIGNED_INT),i===this.context.DEPTH_STENCIL&&(c=this.context.UNSIGNED_INT_24_8_WEBGL);if(e===Ct["texture-array"]&&this.context instanceof WebGL2RenderingContext){console.warn("texture-array layers are supported...questionably in the polyfill at the moment. Use at your own risk.");const e=this.context.getParameter(this.context.TEXTURE_BINDING_2D_ARRAY);this.context.bindTexture(this.context.TEXTURE_2D_ARRAY,h),this._getSupportedDepthFormats().indexOf(i)>=0?this.context.texStorage3D(this.context.TEXTURE_2D_ARRAY,1,u,t,r,a):this.context.texImage3D(this.context.TEXTURE_2D_ARRAY,0,u,t,r,a,0,i,c,null),this.context.bindTexture(this.context.TEXTURE_2D_ARRAY,e)}else{const e=this.context.getParameter(this.context.TEXTURE_BINDING_2D);this.context.bindTexture(this.context.TEXTURE_2D,h),this.context.texImage2D(this.context.TEXTURE_2D,0,u,t,r,0,i,c,null),this.context.bindTexture(this.context.TEXTURE_2D,e)}if(o&&this.context instanceof WebGL2RenderingContext){if(!(this._getSupportedDepthFormats().indexOf(i)>=0))try{this._createAutoMSAAFramebuffers(l,t,r,u),console.log(`Auto-enabled ${n}x MSAA for layer texture (${t}x${r})`)}catch(e){console.warn("Failed to create MSAA framebuffers, falling back to non-AA:",e),l._autoAntialiasing=!1,l._samples=1}}return l}_getSupportedDepthFormats(){const e=[];return this.context instanceof WebGLRenderingContext&&!this.context.getExtension("WEBGL_depth_texture")||(e.push(this.context.DEPTH_COMPONENT,this.context.DEPTH_STENCIL),this.context instanceof WebGL2RenderingContext&&e.push(this.context.DEPTH_COMPONENT24,this.context.DEPTH24_STENCIL8)),e}_shouldAutoEnableAntialiasing(){if(void 0!==window.IWER)return!0;if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent))return!1;if(!(this.context instanceof WebGL2RenderingContext))return!1;return this.context.getParameter(this.context.MAX_SAMPLES)>1}_getAutoSampleCount(){if(!this._shouldAutoEnableAntialiasing())return 1;const e=this.context.getParameter(this.context.MAX_SAMPLES);return Math.min(e,4)}_createAutoMSAAFramebuffers(e,t,r,i,s){const a=this.context,n=a.createRenderbuffer();a.bindRenderbuffer(a.RENDERBUFFER,n),a.renderbufferStorageMultisample(a.RENDERBUFFER,e._samples,i,t,r);let o=null;s&&(o=a.createRenderbuffer(),a.bindRenderbuffer(a.RENDERBUFFER,o),a.renderbufferStorageMultisample(a.RENDERBUFFER,e._samples,s,t,r));const h=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,h),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.RENDERBUFFER,n),o&&a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,o);const l=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,l),e.type===Ct["texture-array"]?a.framebufferTextureLayer(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,e.texture,0,0):a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,e.texture,0),e._msaaFramebuffer=h,e._resolveFramebuffer=l,a.bindRenderbuffer(a.RENDERBUFFER,null),a.bindFramebuffer(a.FRAMEBUFFER,null)}}const Vt={colorFormat:6408,mipLevels:1,layout:Dt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:Ct.texture,radius:2,centralAngle:.78539,aspectRatio:2},Gt={layout:Dt.mono,invertStereo:!1,space:null,radius:2,centralAngle:.78539};class Xt extends Ut{constructor(e,t){super(),this._media=t??null,this.isMediaLayer()?this.init={...Gt,...e}:this.init={...Vt,...e},this.radius=this.init.radius,this.centralAngle=this.init.centralAngle,this.aspectRatio=this.init.aspectRatio,this.space=this.init.space,this.layout=this.init.layout;const r=Bt();this.init.transform?this.transform=new r.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new r.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?Ct.texture:this.init.textureType}_deferredInitialize(){let e=this.determineLayoutAttribute(this.init.textureType,this.context,this.init.layout);this.layout=e,this.needsRedraw=!0}get colorTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._colorTextures}get depthStencilTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._depthStencilTextures&&this._depthStencilTextures.length||this._allocateDepthStencilTexturesInternal(this.getTextureType(),this.init),this._depthStencilTextures}get colorTexturesMeta(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._texturesMeta}get width(){return 2*this.radius*Math.PI*(this.centralAngle/(2*Math.PI))}get height(){return this.width/this.aspectRatio}}const qt={colorFormat:6408,mipLevels:1,layout:Dt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:Ct.texture,radius:0,centralHorizontalAngle:6.28318,upperVerticalAngle:1.570795,lowerVerticalAngle:-1.570795},zt={space:null,layout:Dt.mono,invertStereo:!1,radius:0,centralHorizontalAngle:6.28318,upperVerticalAngle:1.570795,lowerVerticalAngle:-1.570795};class Ht extends Ut{constructor(e,t){if(super(),this._media=t??null,this.isMediaLayer()?this.init={...zt,...e}:this.init={...qt,...e},!Nt(this.init.space))throw new TypeError("Equirect layer's space needs to be an XRReferenceSpace");this.radius=this.init.radius,this.centralHorizontalAngle=this.init.centralHorizontalAngle,this.upperVerticalAngle=this.init.upperVerticalAngle,this.lowerVerticalAngle=this.init.lowerVerticalAngle,this.space=this.init.space,this.layout=this.init.layout;const r=Bt();e.transform?this.transform=new r.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new r.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?Ct.texture:this.init.textureType}_deferredInitialize(){let e=this.determineLayoutAttribute(this.init.textureType,this.context,this.init.layout);this.layout=e,this.needsRedraw=!0}get colorTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._colorTextures}get depthStencilTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._depthStencilTextures&&this._depthStencilTextures.length||this._allocateDepthStencilTexturesInternal(this.getTextureType(),this.init),this._depthStencilTextures}get colorTexturesMeta(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._texturesMeta}}const kt={colorFormat:6408,mipLevels:1,layout:Dt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:Ct.texture,width:1,height:1},Wt={space:null,layout:Dt.mono,invertStereo:!1};class jt extends Ut{constructor(e,t){super(),this._media=t??null,this.isMediaLayer()?this.init={...Wt,...e}:this.init={...kt,...e},this.width=this.init.width,this.height=this.init.height,this.space=this.init.space,this.layout=this.init.layout;const r=Bt();this.init.transform?this.transform=new r.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new r.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?Ct.texture:this.init.textureType}_deferredInitialize(){let e=this.determineLayoutAttribute(this.init.textureType,this.context,this.init.layout);this.layout=e,this.needsRedraw=!0}get colorTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._colorTextures}get depthStencilTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._depthStencilTextures&&this._depthStencilTextures.length||this._allocateDepthStencilTexturesInternal(this.getTextureType(),this.init),this._depthStencilTextures}get colorTexturesMeta(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._texturesMeta}}class Yt{constructor(e){if(this.session=e,this.session.ended)throw new Error("Session has ended")}createQuadLayer(e,t){if(this.session.ended)throw new Error("Session has ended");if(t.layout===Dt.default)throw new TypeError("Media Quad layer cannot be created with layout of default");let r=this.calculateAspectRatio(e,t.layout);void 0===t.width&&void 0===t.height&&(t.width=1),void 0===t.height&&(t.height=t.width/r),void 0===t.width&&(t.width=t.height/r);let i=new jt(t,e);return i.needsRedraw=!1,i.initialize(this.session),i}createCylinderLayer(e,t){if(this.session.ended)throw new Error("Session has ended");if(t.layout===Dt.default)throw new TypeError("Media Cylinder layer cannot be created with layout of default");let r=this.calculateAspectRatio(e,t.layout);void 0===t.aspectRatio&&(t.aspectRatio=r);let i=new Xt(t,e);return i.needsRedraw=!1,i.initialize(this.session),i}createEquirectLayer(e,t){if(this.session.ended)throw new Error("Session has ended");if(t.layout===Dt.default)throw new TypeError("Media Equirect layer cannot be created with layout of default");if(!Nt(t.space))throw new Error("Media Equirect layer's space must be of type XRReferenceSpace");let r=new Ht(t,e);return r.needsRedraw=!1,r.initialize(this.session),r}calculateAspectRatio(e,t){let r=e.videoWidth,i=e.videoHeight;return t===Dt["stereo-left-right"]&&(r/=2),t===Dt["stereo-top-bottom"]&&(i/=2),r/i}}const Qt={textureType:Ct.texture,colorFormat:6408,depthFormat:6402,scaleFactor:1.5};class $t extends Ut{constructor(e=Qt){super(),this.init={...Qt,...e}}initialize(e,t){super.initialize(e,t),this.initializeIfNeeded();let r=e.getBaseLayer();this.textureWidth=r.framebufferWidth*this.init.scaleFactor,this.textureHeight=r.framebufferHeight*this.init.scaleFactor}_allocateProjectionColorTextures(){let e=[],t=[];const r=()=>{e=[];for(let r of t)e.push(r.texture)};let i=this.session,s=i.internalViews;if(!s||0===s.length)return void console.warn("We can't allocate color textures without views");let a,n=i.getBaseLayer(),o=s.length,h=n.framebufferHeight*this.init.scaleFactor;if(a=this.init.textureType===Ct["texture-array"]?n.framebufferWidth*this.init.scaleFactor:n.framebufferWidth*this.init.scaleFactor/s.length,this.layout===Dt.mono||this.layout===Dt.default){if(this.init.textureType===Ct["texture-array"]){let e=this._createNewColorTexture(a,h,Ct["texture-array"],this.init.colorFormat,o);t=[e]}else for(let e of s){let e=this._createNewColorTexture(a,h,Ct.texture,this.init.colorFormat);t.push(e)}return r(),this._colorTexturesMeta=t,void(this._colorTextures=e)}if(this.layout===Dt["stereo-left-right"]){let e=this._createNewColorTexture(a*o,h,this.init.textureType,this.init.colorFormat);t=[e]}else if(this.layout===Dt["stereo-top-bottom"]){let e=this._createNewColorTexture(a,h*o,this.init.textureType,this.init.colorFormat);t=[e]}r(),this._colorTexturesMeta=t,this._colorTextures=e}_allocateProjectionDepthStencilTextures(){let e=this.session,t=e.internalViews;if(!t||0===t.length)return;if(0===this.init.depthFormat)return void(this._depthStencilTextures=[]);if(this.context instanceof WebGLRenderingContext){if(!this.context.getExtension("WEBGL_depth_texture"))return void(this._depthStencilTextures=[])}let r=[],i=[];const s=()=>{r=[];for(let e of i)r.push(e.texture)};this.initializeIfNeeded();let a,n=e.getBaseLayer(),o=t.length,h=n.framebufferHeight*this.init.scaleFactor;if(a=this.init.textureType===Ct["texture-array"]?n.framebufferWidth*this.init.scaleFactor:n.framebufferWidth*this.init.scaleFactor/t.length,this.layout===Dt.mono||this.layout===Dt.default){if(this.init.textureType===Ct["texture-array"]){let e=this._createNewDepthStencilTexture(a,h,this.init.textureType,this.init.depthFormat,o);i=[e]}else for(let e of t){let e=this._createNewDepthStencilTexture(a,h,this.init.textureType,this.init.depthFormat);i.push(e)}return s(),void(this._depthStencilTextures=r)}if(this.layout===Dt["stereo-left-right"]){let e=this._createNewDepthStencilTexture(a*o,h,this.init.textureType,this.init.depthFormat);i=[e]}else if(this.layout===Dt["stereo-top-bottom"]){let e=this._createNewDepthStencilTexture(a,h*o,this.init.textureType,this.init.depthFormat);i=[e]}s(),this._depthStencilTextures=r}get colorTextures(){return this._colorTextures&&this._colorTextures.length||this._allocateProjectionColorTextures(),this._colorTextures}get depthStencilTextures(){return void 0===this._depthStencilTextures&&this._allocateProjectionDepthStencilTextures(),this._depthStencilTextures||[]}get colorTexturesMeta(){return this._colorTextures&&this._colorTextures.length||this._allocateProjectionColorTextures(),this._colorTexturesMeta}getTextureType(){return this.init.textureType}_deferredInitialize(){this.isStatic=!1,this.ignoreDepthValues=!1,this.fixedFoveation=0;let e=this.determineLayoutAttribute(this.init.textureType,this.context,Dt.default);this.layout=e,this.needsRedraw=!0;let t=this.determineMaximumScaleFactor(),r=Math.min(this.init.scaleFactor,t);this.init.scaleFactor;let i=r;this.init.scaleFactor=i}determineMaximumScaleFactor(){let e=this.session.getBaseLayer(this.context),t=e.framebufferWidth,r=e.framebufferHeight;this.layout===Dt["stereo-left-right"]&&(t*=2),this.layout===Dt["stereo-top-bottom"]&&(r*=2);let i=Math.max(t,r);return this.context.getParameter(this.context.MAX_TEXTURE_SIZE)/i}}const Kt=(e,t,r,i,s)=>{let a=0,n=0,o=t.width,h=t.height;r===Dt["stereo-left-right"]?(a=t.width*i/s,o=t.width/s):r===Dt["stereo-top-bottom"]&&(n=t.height*i/s,h=t.height/s),e.x=a,e.y=n,e.width=o,e.height=h},Jt=(e,t,r)=>{var i=e.createShader(r);if(e.shaderSource(i,t),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw"could not compile shader:"+e.getShaderInfoLog(i);return i},Zt=(e,t,r)=>{const i=e.createProgram(),s=Jt(e,t,e.VERTEX_SHADER),a=Jt(e,r,e.FRAGMENT_SHADER);if(e.attachShader(i,s),e.attachShader(i,a),e.deleteShader(s),e.deleteShader(a),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw"program failed to link:"+e.getProgramInfoLog(i);return i},er=e=>{if(e instanceof WebGL2RenderingContext)return e;const t=e.getExtension("OES_vertex_array_object");if(!t)throw new Error("Cannot use VAOs.");return{VERTEX_ARRAY_BINDING:t.VERTEX_ARRAY_BINDING_OES,bindVertexArray:t.bindVertexArrayOES.bind(t),createVertexArray:t.createVertexArrayOES.bind(t),deleteVertexArray:t.deleteVertexArrayOES.bind(t),isVertexArray:t.isVertexArrayOES.bind(t)}},tr=e=>e,rr=tr`
|
|
1
|
+
var e=1e-6,t="undefined"!=typeof Float32Array?Float32Array:Array;function r(){var e=new t(16);return t!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function i(e){var r=new t(16);return r[0]=e[0],r[1]=e[1],r[2]=e[2],r[3]=e[3],r[4]=e[4],r[5]=e[5],r[6]=e[6],r[7]=e[7],r[8]=e[8],r[9]=e[9],r[10]=e[10],r[11]=e[11],r[12]=e[12],r[13]=e[13],r[14]=e[14],r[15]=e[15],r}function s(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[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function a(e,t){var r=t[0],i=t[1],s=t[2],a=t[3],n=t[4],o=t[5],h=t[6],l=t[7],u=t[8],c=t[9],d=t[10],p=t[11],f=t[12],x=t[13],m=t[14],g=t[15],y=r*o-i*n,v=r*h-s*n,T=r*l-a*n,w=i*h-s*o,S=i*l-a*o,E=s*l-a*h,R=u*x-c*f,_=u*m-d*f,b=u*g-p*f,M=c*m-d*x,A=c*g-p*x,F=d*g-p*m,P=y*F-v*A+T*M+w*b-S*_+E*R;return P?(P=1/P,e[0]=(o*F-h*A+l*M)*P,e[1]=(s*A-i*F-a*M)*P,e[2]=(x*E-m*S+g*w)*P,e[3]=(d*S-c*E-p*w)*P,e[4]=(h*b-n*F-l*_)*P,e[5]=(r*F-s*b+a*_)*P,e[6]=(m*T-f*E-g*v)*P,e[7]=(u*E-d*T+p*v)*P,e[8]=(n*A-o*b+l*R)*P,e[9]=(i*b-r*A-a*R)*P,e[10]=(f*S-x*T+g*y)*P,e[11]=(c*T-u*S-p*y)*P,e[12]=(o*_-n*M-h*R)*P,e[13]=(r*M-i*_+s*R)*P,e[14]=(x*v-f*w-m*y)*P,e[15]=(u*w-c*v+d*y)*P,e):null}function n(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3],o=t[4],h=t[5],l=t[6],u=t[7],c=t[8],d=t[9],p=t[10],f=t[11],x=t[12],m=t[13],g=t[14],y=t[15],v=r[0],T=r[1],w=r[2],S=r[3];return e[0]=v*i+T*o+w*c+S*x,e[1]=v*s+T*h+w*d+S*m,e[2]=v*a+T*l+w*p+S*g,e[3]=v*n+T*u+w*f+S*y,v=r[4],T=r[5],w=r[6],S=r[7],e[4]=v*i+T*o+w*c+S*x,e[5]=v*s+T*h+w*d+S*m,e[6]=v*a+T*l+w*p+S*g,e[7]=v*n+T*u+w*f+S*y,v=r[8],T=r[9],w=r[10],S=r[11],e[8]=v*i+T*o+w*c+S*x,e[9]=v*s+T*h+w*d+S*m,e[10]=v*a+T*l+w*p+S*g,e[11]=v*n+T*u+w*f+S*y,v=r[12],T=r[13],w=r[14],S=r[15],e[12]=v*i+T*o+w*c+S*x,e[13]=v*s+T*h+w*d+S*m,e[14]=v*a+T*l+w*p+S*g,e[15]=v*n+T*u+w*f+S*y,e}function o(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}function h(t,r,i){var s,a,n,o=i[0],h=i[1],l=i[2],u=Math.sqrt(o*o+h*h+l*l);return u<e?null:(o*=u=1/u,h*=u,l*=u,s=Math.sin(r),n=1-(a=Math.cos(r)),t[0]=o*o*n+a,t[1]=h*o*n+l*s,t[2]=l*o*n-h*s,t[3]=0,t[4]=o*h*n-l*s,t[5]=h*h*n+a,t[6]=l*h*n+o*s,t[7]=0,t[8]=o*l*n+h*s,t[9]=h*l*n-o*s,t[10]=l*l*n+a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function l(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3],o=i+i,h=s+s,l=a+a,u=i*o,c=i*h,d=i*l,p=s*h,f=s*l,x=a*l,m=n*o,g=n*h,y=n*l;return e[0]=1-(p+x),e[1]=c+y,e[2]=d-g,e[3]=0,e[4]=c-y,e[5]=1-(u+x),e[6]=f+m,e[7]=0,e[8]=d+g,e[9]=f-m,e[10]=1-(u+p),e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function u(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function c(e,t){var r=t[0],i=t[1],s=t[2],a=t[4],n=t[5],o=t[6],h=t[8],l=t[9],u=t[10];return e[0]=Math.sqrt(r*r+i*i+s*s),e[1]=Math.sqrt(a*a+n*n+o*o),e[2]=Math.sqrt(h*h+l*l+u*u),e}function d(e,r){var i=new t(3);c(i,r);var s=1/i[0],a=1/i[1],n=1/i[2],o=r[0]*s,h=r[1]*a,l=r[2]*n,u=r[4]*s,d=r[5]*a,p=r[6]*n,f=r[8]*s,x=r[9]*a,m=r[10]*n,g=o+d+m,y=0;return g>0?(y=2*Math.sqrt(g+1),e[3]=.25*y,e[0]=(p-x)/y,e[1]=(f-l)/y,e[2]=(h-u)/y):o>d&&o>m?(y=2*Math.sqrt(1+o-d-m),e[3]=(p-x)/y,e[0]=.25*y,e[1]=(h+u)/y,e[2]=(f+l)/y):d>m?(y=2*Math.sqrt(1+d-o-m),e[3]=(f-l)/y,e[0]=(h+u)/y,e[1]=.25*y,e[2]=(p+x)/y):(y=2*Math.sqrt(1+m-o-d),e[3]=(h-u)/y,e[0]=(f+l)/y,e[1]=(p+x)/y,e[2]=.25*y),e}var p=function(e,t,r,i,s){var a=1/Math.tan(t/2);if(e[0]=a/r,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!=s&&s!==1/0){var n=1/(i-s);e[10]=(s+i)*n,e[14]=2*s*i*n}else e[10]=-1,e[14]=-2*i;return e};function f(){var e=new t(3);return t!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function x(e,r,i){var s=new t(3);return s[0]=e,s[1]=r,s[2]=i,s}function m(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function g(e,t,r,i){return e[0]=t,e[1]=r,e[2]=i,e}function y(e,t){var r=t[0],i=t[1],s=t[2],a=r*r+i*i+s*s;return a>0&&(a=1/Math.sqrt(a)),e[0]=t[0]*a,e[1]=t[1]*a,e[2]=t[2]*a,e}function v(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function T(e,t,r){var i=t[0],s=t[1],a=t[2],n=r[0],o=r[1],h=r[2];return e[0]=s*h-a*o,e[1]=a*n-i*h,e[2]=i*o-s*n,e}function w(e,t,r,i){var s=t[0],a=t[1],n=t[2];return e[0]=s+i*(r[0]-s),e[1]=a+i*(r[1]-a),e[2]=n+i*(r[2]-n),e}function S(){var e=new t(4);return t!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function E(e,t,r,i,s){return e[0]=t,e[1]=r,e[2]=i,e[3]=s,e}function R(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3];return e[0]=r[0]*i+r[4]*s+r[8]*a+r[12]*n,e[1]=r[1]*i+r[5]*s+r[9]*a+r[13]*n,e[2]=r[2]*i+r[6]*s+r[10]*a+r[14]*n,e[3]=r[3]*i+r[7]*s+r[11]*a+r[15]*n,e}function _(){var e=new t(4);return t!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function b(e,t,r){r*=.5;var i=Math.sin(r);return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=Math.cos(r),e}function M(t,r,i,s){var a,n,o,h,l,u=r[0],c=r[1],d=r[2],p=r[3],f=i[0],x=i[1],m=i[2],g=i[3];return(n=u*f+c*x+d*m+p*g)<0&&(n=-n,f=-f,x=-x,m=-m,g=-g),1-n>e?(a=Math.acos(n),o=Math.sin(a),h=Math.sin((1-s)*a)/o,l=Math.sin(s*a)/o):(h=1-s,l=s),t[0]=h*u+l*f,t[1]=h*c+l*x,t[2]=h*d+l*m,t[3]=h*p+l*g,t}f(),function(){var e=S()}();var A,F=function(e,r,i,s){var a=new t(4);return a[0]=e,a[1]=r,a[2]=i,a[3]=s,a},P=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},I=E,L=function(e,t){var r=t[0],i=t[1],s=t[2],a=t[3],n=r*r+i*i+s*s+a*a;return n>0&&(n=1/Math.sqrt(n)),e[0]=r*n,e[1]=i*n,e[2]=s*n,e[3]=a*n,e};f(),x(1,0,0),x(0,1,0),_(),_(),A=new t(9),t!=Float32Array&&(A[1]=0,A[2]=0,A[3]=0,A[5]=0,A[6]=0,A[7]=0),A[0]=1,A[4]=1,A[8]=1;const C=Symbol("@iwer/action-player"),D=Symbol("@iwer/action-recorder"),N=Symbol("@iwer/xr-anchor"),O=Symbol("@iwer/xr-controller"),B=Symbol("@iwer/xr-device"),V=Symbol("@iwer/xr-hand-input"),U=Symbol("@iwer/xr-tracked-input"),G=Symbol("@iwer/xr-frame"),X=Symbol("@iwer/gamepad"),q=Symbol("@iwer/xr-system"),z=Symbol("@iwer/xr-input-source"),k=Symbol("@iwer/xr-webgl-layer"),H=Symbol("@iwer/xr-mesh"),j=Symbol("@iwer/xr-plane"),W=Symbol("@iwer/xr-joint-pose"),Y=Symbol("@iwer/xr-pose"),Q=Symbol("@iwer/xr-viewer-pose"),K=Symbol("@iwer/xr-rigid-transform"),$=Symbol("@iwer/xr-render-state"),J=Symbol("@iwer/xr-session"),Z=Symbol("@iwer/xr-joint-space"),ee=Symbol("@iwer/xr-reference-space"),te=Symbol("@iwer/xr-space"),re=Symbol("@iwer/xr-view"),ie=Symbol("@iwer/xr-viewport"),se=Symbol("@iwer/xr-ray"),ae=Symbol("@iwer/xr-hit-test");class ne extends EventTarget{constructor(e,t){super(),this[te]={parentSpace:e,offsetMatrix:t?i(t):r(),emulated:!0}}}class oe extends ne{constructor(){super(void 0,r())}}class he{static updateOffsetPosition(e,t){o(e[te].offsetMatrix,t)}static updateOffsetQuaternion(e,t){const r=e[te].offsetMatrix,i=f();u(i,r),l(r,t,i)}static updateOffsetMatrix(e,t){s(e[te].offsetMatrix,t)}static calculateGlobalOffsetMatrix(e,t=r()){return n(t,e[te].parentSpace?he.calculateGlobalOffsetMatrix(e[te].parentSpace):r(),e[te].offsetMatrix),t}}class le{constructor(e=0,t=0,r=0){this.vec3=x(e,t,r),this.tempVec3=f()}get x(){return this.vec3[0]}set x(e){this.vec3[0]=e}get y(){return this.vec3[1]}set y(e){this.vec3[1]=e}get z(){return this.vec3[2]}set z(e){this.vec3[2]=e}set(e,t,r){return g(this.vec3,e,t,r),this}clone(){return new le(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}normalize(){return m(this.tempVec3,this.vec3),y(this.vec3,this.tempVec3),this}add(e){return m(this.tempVec3,this.vec3),function(e,t,r){e[0]=t[0]+r[0],e[1]=t[1]+r[1],e[2]=t[2]+r[2]}(this.vec3,this.tempVec3,e.vec3),this}applyQuaternion(e){return m(this.tempVec3,this.vec3),function(e,t,r){var i=r[0],s=r[1],a=r[2],n=r[3],o=t[0],h=t[1],l=t[2],u=s*l-a*h,c=a*o-i*l,d=i*h-s*o;u+=u,c+=c,d+=d,e[0]=o+n*u+s*d-a*c,e[1]=h+n*c+a*u-i*d,e[2]=l+n*d+i*c-s*u}(this.vec3,this.tempVec3,e.quat),this}}class ue{constructor(e=0,t=0,r=0,i=1){this.quat=F(e,t,r,i),this.tempQuat=_()}get x(){return this.quat[0]}set x(e){this.quat[0]=e}get y(){return this.quat[1]}set y(e){this.quat[1]=e}get z(){return this.quat[2]}set z(e){this.quat[2]=e}get w(){return this.quat[3]}set w(e){this.quat[3]=e}set(e,t,r,i){return I(this.quat,e,t,r,i),this}clone(){return new ue(this.x,this.y,this.z,this.w)}copy(e){return I(this.quat,e.x,e.y,e.z,e.w),this}normalize(){return P(this.tempQuat,this.quat),L(this.quat,this.tempQuat),this}invert(){return P(this.tempQuat,this.quat),function(e,t){e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3]}(this.quat,this.tempQuat),this}multiply(e){return P(this.tempQuat,this.quat),function(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3],o=r[0],h=r[1],l=r[2],u=r[3];e[0]=i*u+n*o+s*l-a*h,e[1]=s*u+n*h+a*o-i*l,e[2]=a*u+n*l+i*h-s*o,e[3]=n*u-i*o-s*h-a*l}(this.quat,this.tempQuat,e.quat),this}setFromAxisAngle(e,t){return b(this.quat,e.vec3,t),this}}var ce,de,pe;!function(e){e.None="",e.Standard="standard",e.XRStandard="xr-standard"}(ce||(ce={}));class fe{constructor(e,t){this[X]={type:e,eventTrigger:t,pressed:!1,touched:!1,value:0,lastFrameValue:0,pendingValue:null}}get pressed(){return"manual"===this[X].type?this[X].pressed:this[X].value>0}get touched(){return"manual"===this[X].type?this[X].touched:this[X].touched||this.pressed}get value(){return this[X].value}}class xe{constructor(){this.pressed=!1,this.touched=!1,this.value=0}}class me{constructor(e,t="",r=-1){this[X]={id:t,index:r,connected:!1,timestamp:performance.now(),mapping:e.mapping,buttonsMap:{},buttonsSequence:[],axesMap:{},axesSequence:[],hapticActuators:[]},e.buttons.forEach((e=>{var t;null===e?this[X].buttonsSequence.push(null):(this[X].buttonsSequence.push(e.id),this[X].buttonsMap[e.id]=new fe(e.type,null!==(t=e.eventTrigger)&&void 0!==t?t:null))})),e.axes.forEach((e=>{null===e?this[X].axesSequence.push(null):(this[X].axesSequence.push(e.id+e.type),this[X].axesMap[e.id]||(this[X].axesMap[e.id]={x:0,y:0}))}))}get id(){return this[X].id}get index(){return this[X].index}get connected(){return this[X].connected}get timestamp(){return this[X].timestamp}get mapping(){return this[X].mapping}get axes(){const e=[];return this[X].axesSequence.forEach((t=>{if(null===t)e.push(null);else{const r=t.substring(0,t.length-6),i=t.substring(t.length-6);e.push("y-axis"===i?this[X].axesMap[r].y:this[X].axesMap[r].x)}})),e}get buttons(){return this[X].buttonsSequence.map((e=>null===e?new xe:this[X].buttonsMap[e]))}get hapticActuators(){return this[X].hapticActuators}get vibrationActuator(){return null}}!function(e){e.None="none",e.Left="left",e.Right="right"}(de||(de={})),function(e){e.Gaze="gaze",e.TrackedPointer="tracked-pointer",e.Screen="screen",e.TransientPointer="transient-pointer"}(pe||(pe={}));class ge extends Array{}class ye{constructor(e,t,r,i,s,a,n){this[z]={handedness:e,targetRayMode:t,targetRaySpace:i,gripSpace:a,profiles:r,gamepad:s,hand:n}}get handedness(){return this[z].handedness}get targetRayMode(){return this[z].targetRayMode}get targetRaySpace(){return this[z].targetRaySpace}get gripSpace(){return this[z].gripSpace}get profiles(){return this[z].profiles}get gamepad(){return this[z].gamepad}get hand(){return this[z].hand}}class ve extends Event{constructor(e,t){if(super(e,t),!t.frame)throw new Error("XRInputSourceEventInit.frame is required");if(!t.inputSource)throw new Error("XRInputSourceEventInit.inputSource is required");this.frame=t.frame,this.inputSource=t.inputSource}}const Te={[de.Left]:{position:new le(-.25,1.5,-.4),quaternion:new ue},[de.Right]:{position:new le(.25,1.5,-.4),quaternion:new ue},[de.None]:{position:new le(.25,1.5,-.4),quaternion:new ue}};class we{constructor(e){this[U]={inputSource:e,position:Te[e.handedness].position.clone(),quaternion:Te[e.handedness].quaternion.clone(),connected:!0,lastFrameConnected:!1,inputSourceChanged:!0}}get position(){return this[U].position}get quaternion(){return this[U].quaternion}get inputSource(){return this[U].inputSource}get connected(){return this[U].connected}set connected(e){this[U].connected=e,this[U].inputSource.gamepad[X].connected=e}onFrameStart(e){l(this[U].inputSource.targetRaySpace[te].offsetMatrix,this[U].quaternion.quat,this[U].position.vec3);const t=e.session;this[U].inputSource.gamepad.buttons.forEach((r=>{r instanceof fe&&(r[X].lastFrameValue=r[X].value,null!=r[X].pendingValue&&(r[X].value=r[X].pendingValue,r[X].pendingValue=null),null!=r[X].eventTrigger&&(0===r[X].lastFrameValue&&r[X].value>0?(t.dispatchEvent(new ve(r[X].eventTrigger,{frame:e,inputSource:this[U].inputSource})),t.dispatchEvent(new ve(r[X].eventTrigger+"start",{frame:e,inputSource:this[U].inputSource}))):r[X].lastFrameValue>0&&0===r[X].value&&t.dispatchEvent(new ve(r[X].eventTrigger+"end",{frame:e,inputSource:this[U].inputSource}))))})),this[U].inputSourceChanged=this.connected!==this[U].lastFrameConnected,this[U].lastFrameConnected=this.connected}}class Se extends we{constructor(e,t,r){if(!e.layout[t])throw new DOMException("Handedness not supported","InvalidStateError");const i=new ne(r),s=e.layout[t].gripOffsetMatrix?new ne(i,e.layout[t].gripOffsetMatrix):void 0,a=[e.profileId,...e.fallbackProfileIds];super(new ye(t,pe.TrackedPointer,a,i,new me(e.layout[t].gamepad),s)),this[O]={profileId:e.profileId,gamepadConfig:e.layout[t].gamepad}}get gamepadConfig(){return this[O].gamepadConfig}get profileId(){return this[O].profileId}updateButtonValue(e,t){if(t>1||t<0)return void console.warn(`Out-of-range value ${t} provided for button ${e}.`);const r=this[U].inputSource.gamepad[X].buttonsMap[e];if(r){if("binary"===r[X].type&&1!=t&&0!=t)return void console.warn(`Non-binary value ${t} provided for binary button ${e}.`);r[X].pendingValue=t}else console.warn(`Current controller does not have button ${e}.`)}updateButtonTouch(e,t){const r=this[U].inputSource.gamepad[X].buttonsMap[e];r?r[X].touched=t:console.warn(`Current controller does not have button ${e}.`)}updateAxis(e,t,r){if(r>1||r<-1)return void console.warn(`Out-of-range value ${r} provided for ${e} axes.`);const i=this[U].inputSource.gamepad[X].axesMap[e];i?"x-axis"===t?i.x=r:"y-axis"===t&&(i.y=r):console.warn(`Current controller does not have ${e} axes.`)}updateAxes(e,t,r){if(t>1||t<-1||r>1||r<-1)return void console.warn(`Out-of-range value x:${t}, y:${r} provided for ${e} axes.`);const i=this[U].inputSource.gamepad[X].axesMap[e];i?(i.x=t,i.y=r):console.warn(`Current controller does not have ${e} axes.`)}}class Ee{constructor(e,t,r,i,s){this[H]={nativeMesh:e,frame:void 0,meshSpace:t,vertices:r,indices:i,lastChangedTime:performance.now(),semanticLabel:s}}get meshSpace(){return this[H].meshSpace}get vertices(){return this[H].vertices}get indices(){return this[H].indices}get lastChangedTime(){return this[H].lastChangedTime}get semanticLabel(){return this[H].semanticLabel}}class Re extends Set{}class _e{constructor(e,t,r,i){this.transform=e,this.vertices=t,this.indices=r,this.semanticLabel=i}}var be,Me;!function(e){e.Desk="desk",e.Couch="couch",e.Floor="floor",e.Ceiling="ceiling",e.Wall="wall",e.Door="door",e.Window="window",e.Table="table",e.Shelf="shelf",e.Bed="bed",e.Screen="screen",e.Lamp="lamp",e.Plant="plant",e.WallArt="wall art",e.GlobalMesh="global mesh",e.Other="other"}(be||(be={})),function(e){e.Horizontal="horizontal",e.Vertical="vertical"}(Me||(Me={}));const Ae={[be.Desk]:Me.Horizontal,[be.Couch]:Me.Horizontal,[be.Floor]:Me.Horizontal,[be.Ceiling]:Me.Horizontal,[be.Wall]:Me.Vertical,[be.Door]:Me.Vertical,[be.Window]:Me.Vertical,[be.Table]:Me.Horizontal,[be.Shelf]:Me.Horizontal,[be.Bed]:Me.Horizontal,[be.Screen]:Me.Horizontal,[be.Lamp]:Me.Horizontal,[be.Plant]:Me.Horizontal,[be.WallArt]:Me.Vertical};class Fe{constructor(e,t,r,i){this[j]={nativePlane:e,frame:void 0,planeSpace:t,polygon:r,lastChangedTime:performance.now(),semanticLabel:i,orientation:i?Ae[i]:void 0}}get planeSpace(){return this[j].planeSpace}get polygon(){return this[j].polygon}get orientation(){return this[j].orientation}get lastChangedTime(){return this[j].lastChangedTime}get semanticLabel(){return this[j].semanticLabel}}class Pe extends Set{}class Ie{constructor(e,t,r){this.transform=e,this.polygon=t,this.semanticLabel=r}}class Le{constructor(e,t){this[N]={anchorSpace:e,session:t,deleted:!1},t[J].trackedAnchors.add(this)}get anchorSpace(){if(this[N].deleted)throw new DOMException("XRAnchor has already been deleted.","InvalidStateError");return this[N].anchorSpace}requestPersistentHandle(){return new Promise(((e,t)=>{if(this[N].deleted)t(new DOMException("XRAnchor has already been deleted.","InvalidStateError"));else{const t=this[N].session[J].persistentAnchors;for(const[r,i]of t.entries())if(i===this)return void e(r);const r=crypto.randomUUID();Ne.createPersistentAnchor(this[N].session,this,r),e(r)}}))}delete(){this[N].deleted||(this[N].anchorSpace=null,this[N].deleted=!0,this[N].session[J].trackedAnchors.delete(this))}}class Ce extends Set{}const De="@immersive-web-emulation-runtime/persistent-anchors";class Ne{static recoverPersistentAnchorsFromStorage(e){const t=JSON.parse(localStorage.getItem(De)||"{}");Object.entries(t).forEach((([t,r])=>{const i=e[J].device[B].globalSpace,s=new ne(i,r),a=new Le(s,e);e[J].persistentAnchors.set(t,a)}))}static createPersistentAnchor(e,t,r){e[J].trackedAnchors.add(t),e[J].persistentAnchors.set(r,t);const i=JSON.parse(localStorage.getItem(De)||"{}");i[r]=Array.from(t[N].anchorSpace[te].offsetMatrix),localStorage.setItem(De,JSON.stringify(i))}}class Oe{constructor(e,t){const i=x(0,0,0),s=_();this[K]={matrix:r(),position:e?x(e.x,e.y,e.z):i,orientation:t?L(_(),F(t.x,t.y,t.z,t.w)):s,inverse:null},this.updateMatrix()}updateMatrix(){l(this[K].matrix,this[K].orientation,this[K].position)}get matrix(){return this[K].matrix}get position(){const e=this[K].position;return new DOMPointReadOnly(e[0],e[1],e[2],1)}get orientation(){const e=this[K].orientation;return new DOMPointReadOnly(e[0],e[1],e[2],e[3])}get inverse(){if(!this[K].inverse){const e=r();if(!a(e,this[K].matrix))throw new Error("Matrix is not invertible.");let t=f();u(t,e);let i=_();d(i,e),this[K].inverse=new Oe(new DOMPointReadOnly(t[0],t[1],t[2],1),new DOMPointReadOnly(i[0],i[1],i[2],i[3])),this[K].inverse[K].inverse=this}return this[K].inverse}}class Be{constructor(e=0,t=0,r=0,i=1){this.x=e,this.y=t,this.z=r,this.w=i}}class Ve{constructor(e,t){const r={x:0,y:0,z:0,w:1},i={x:0,y:0,z:-1,w:0};if(e instanceof Oe){const t=e.matrix,s=E(S(),r.x,r.y,r.z,r.w),a=E(S(),i.x,i.y,i.z,i.w);R(s,s,t),R(a,a,t),r.x=s[0],r.y=s[1],r.z=s[2],r.w=s[3],i.x=a[0],i.y=a[1],i.z=a[2],i.w=a[3]}else if(e&&(r.x=e.x,r.y=e.y,r.z=e.z,r.w=e.w),t){if(0===t.x&&0===t.y&&0===t.z||0!==t.w)throw new DOMException("Invalid direction value to construct XRRay","TypeError");i.x=t.x,i.y=t.y,i.z=t.z,i.w=t.w}const s=Math.sqrt(i.x*i.x+i.y*i.y+i.z*i.z)||1;i.x=i.x/s,i.y=i.y/s,i.z=i.z/s,this[se]={origin:new Be(r.x,r.y,r.z,r.w),direction:new Be(i.x,i.y,i.z,i.w),matrix:null}}get origin(){return this[se].origin}get direction(){return this[se].direction}get matrix(){if(this[se].matrix)return this[se].matrix;const e=g(f(),0,0,-1),t=g(f(),this[se].origin.x,this[se].origin.y,this[se].origin.z),i=g(f(),this[se].direction.x,this[se].direction.y,this[se].direction.z),s=T(f(),i,e),a=v(i,e),l=r();a>-1&&a<1?h(l,Math.acos(a),s):-1===a?h(l,Math.acos(a),g(f(),1,0,0)):function(e){e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1}(l);const u=o(r(),t),c=n(r(),u,l);return this[se].matrix=new Float32Array(c),this[se].matrix}}class Ue{constructor(e,t){var r;this[ae]={session:e,space:t.space,offsetRay:null!==(r=t.offsetRay)&&void 0!==r?r:new Ve}}cancel(){this[ae].session[J].hitTestSources.delete(this)}}class Ge{constructor(e,t){this[ae]={frame:e,offsetSpace:t}}getPose(e){return this[ae].frame.getPose(this[ae].offsetSpace,e)}createAnchor(){return this[ae].frame.createAnchor(new Oe,this[ae].offsetSpace)}}class Xe extends Event{constructor(e,t){if(super(e,t),!t.session)throw new Error("XRInputSourcesChangeEventInit.session is required");if(!t.added)throw new Error("XRInputSourcesChangeEventInit.added is required");if(!t.removed)throw new Error("XRInputSourcesChangeEventInit.removed is required");this.session=t.session,this.added=t.added,this.removed=t.removed}}var qe,ze,ke;!function(e){e.Viewer="viewer",e.Local="local",e.LocalFloor="local-floor",e.BoundedFloor="bounded-floor",e.Unbounded="unbounded"}(ze||(ze={}));class He extends ne{constructor(e,t,r){super(t,r),this[qe]={type:null,onreset:()=>{}},this[ee].type=e}get onreset(){var e;return null!==(e=this[ee].onreset)&&void 0!==e?e:()=>{}}set onreset(e){this[ee].onreset&&this.removeEventListener("reset",this[ee].onreset),this[ee].onreset=e,e&&this.addEventListener("reset",e)}getOffsetReferenceSpace(e){return new He(this[ee].type,this,e)}}qe=ee;class je{constructor(e={},t){this[$]={depthNear:e.depthNear||(null==t?void 0:t.depthNear)||.1,depthFar:e.depthFar||(null==t?void 0:t.depthFar)||1e3,inlineVerticalFieldOfView:e.inlineVerticalFieldOfView||(null==t?void 0:t.inlineVerticalFieldOfView)||null,baseLayer:e.baseLayer||(null==t?void 0:t.baseLayer)||null}}get depthNear(){return this[$].depthNear}get depthFar(){return this[$].depthFar}get inlineVerticalFieldOfView(){return this[$].inlineVerticalFieldOfView}get baseLayer(){return this[$].baseLayer}}class We extends Event{constructor(e,t){if(super(e,t),!t.session)throw new Error("XRSessionEventInit.session is required");this.session=t.session}}!function(e){e.None="none",e.Left="left",e.Right="right"}(ke||(ke={}));class Ye{constructor(e,t,r,i){this[re]={eye:e,projectionMatrix:t,transform:r,recommendedViewportScale:null,requestedViewportScale:1,session:i}}get eye(){return this[re].eye}get projectionMatrix(){return this[re].projectionMatrix}get transform(){return this[re].transform}get recommendedViewportScale(){return this[re].recommendedViewportScale}requestViewportScale(e){null===e||e<=0||e>1?console.warn("Invalid scale value. Scale must be > 0 and <= 1."):this[re].requestedViewportScale=e}}class Qe{constructor(e,t=!1,r=void 0,i=void 0){this[Y]={transform:e,emulatedPosition:t,linearVelocity:r,angularVelocity:i}}get transform(){return this[Y].transform}get emulatedPosition(){return this[Y].emulatedPosition}get linearVelocity(){return this[Y].linearVelocity}get angularVelocity(){return this[Y].angularVelocity}}class Ke extends Qe{constructor(e,t,r=!1,i=void 0,s=void 0){super(e,r,i,s),this[W]={radius:t}}get radius(){return this[W].radius}}class $e extends Qe{constructor(e,t,r=!1,i=void 0,s=void 0){super(e,r,i,s),this[Q]={views:Object.freeze(t)}}get views(){return this[Q].views}}const Je=r(),Ze=r(),et=r(),tt=(e,t,r)=>{he.calculateGlobalOffsetMatrix(t,Je),he.calculateGlobalOffsetMatrix(r,Ze),a(et,Ze),n(e,et,Je)};class rt{constructor(e,t,i,s,a){this[G]={session:e,id:t,active:i,animationFrame:s,predictedDisplayTime:a,tempMat4:r(),detectedPlanes:new Pe,detectedMeshes:new Re,trackedAnchors:e[J].frameTrackedAnchors,hitTestResultsMap:new Map}}get session(){return this[G].session}get predictedDisplayTime(){return this[G].predictedDisplayTime}getPose(e,t){if(!this[G].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");tt(this[G].tempMat4,e,t);const r=f();u(r,this[G].tempMat4);const i=_();return d(i,this[G].tempMat4),new Qe(new Oe({x:r[0],y:r[1],z:r[2],w:1},{x:i[0],y:i[1],z:i[2],w:i[3]}),e[te].emulated)}getViewerPose(e){if(!this[G].animationFrame)throw new DOMException("getViewerPose can only be called on XRFrame objects passed to XRSession.requestAnimationFrame callbacks.","InvalidStateError");const t=this[G].session,r=t[J].device,i=this.getPose(r.viewerSpace,e),s="inline"===t[J].mode?[ke.None]:[ke.Left,ke.Right],a=[];return s.forEach((i=>{const s=r.viewSpaces[i],n=this.getPose(s,e),o=t[J].getProjectionMatrix(i),h=new Ye(i,new Float32Array(o),n.transform,t);a.push(h)})),new $e(i.transform,a,!1)}getJointPose(e,t){const r=this.getPose(e,t),i=e[Z].radius;return new Ke(r.transform,i,!1)}fillJointRadii(e,t){if(e=Array.from(e),!this[G].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");if(e.length>t.length)throw new DOMException("The length of jointSpaces is larger than the number of elements in radii","TypeError");let r=!0;for(let i=0;i<e.length;i++)e[i][Z].radius?t[i]=e[i][Z].radius:(t[i]=NaN,r=!1);return r}fillPoses(e,t,r){if(e=Array.from(e),!this[G].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");if(16*e.length>r.length)throw new DOMException("The length of spaces multiplied by 16 is larger than the number of elements in transforms","TypeError");return e.forEach(((e,i)=>{tt(this[G].tempMat4,e,t);for(let e=0;e<16;e++)r[16*i+e]=this[G].tempMat4[e]})),!0}get detectedPlanes(){if(!this[G].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[G].detectedPlanes}get detectedMeshes(){if(!this[G].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[G].detectedMeshes}get trackedAnchors(){if(!this[G].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[G].trackedAnchors}createAnchor(e,t){return new Promise(((r,i)=>{if(this[G].active){const s=this[G].session[J].device[B].globalSpace,a=new ne(t,e.matrix),n=he.calculateGlobalOffsetMatrix(a),o=new ne(s,n),h=new Le(o,this[G].session);this[G].session[J].trackedAnchors.add(h),this[G].session[J].newAnchors.set(h,{resolve:r,reject:i})}else i(new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError"))}))}getHitTestResults(e){if(this[G].active){if(this[G].hitTestResultsMap.has(e))return[...this[G].hitTestResultsMap.get(e)];throw new DOMException("Requested hit test results are not available for current frame.","InvalidStateError")}throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError")}}var it,st,at;!function(e){e.Opaque="opaque",e.AlphaBlend="alpha-blend",e.Additive="additive"}(it||(it={})),function(e){e.ScreenSpace="screen-space",e.WorldSpace="world-space"}(st||(st={}));class nt extends EventTarget{constructor(e,t,i){super(),this[J]={device:e,mode:t,renderState:new je,pendingRenderState:null,enabledFeatures:i,isSystemKeyboardSupported:!1,ended:!1,projectionMatrices:{[ke.Left]:r(),[ke.Right]:r(),[ke.None]:r()},getProjectionMatrix:e=>this[J].projectionMatrices[e],referenceSpaceIsSupported:e=>{if(!this[J].enabledFeatures.includes(e))return!1;switch(e){case ze.Viewer:return!0;case ze.Local:case ze.LocalFloor:case ze.BoundedFloor:case ze.Unbounded:return"inline"!=this[J].mode}},frameHandle:0,frameCallbacks:[],currentFrameCallbacks:null,onDeviceFrame:()=>{if(this[J].ended)return;this[J].deviceFrameHandle=globalThis.requestAnimationFrame(this[J].onDeviceFrame),null!=this[J].pendingRenderState&&(this[J].renderState=this[J].pendingRenderState,this[J].pendingRenderState=null,this[J].device[B].onBaseLayerSet(this[J].renderState.baseLayer));const e=this[J].renderState.baseLayer;if(null===e)return;const t=e.context,r=t.canvas;if("inline"!=this[J].mode){const e=t.getParameter(t.COLOR_CLEAR_VALUE),r=t.getParameter(t.DEPTH_CLEAR_VALUE),i=t.getParameter(t.STENCIL_CLEAR_VALUE);t.clearColor(0,0,0,0),t.clearDepth(1),t.clearStencil(0),t.clear(t.DEPTH_BUFFER_BIT|t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT),t.clearColor(e[0],e[1],e[2],e[3]),t.clearDepth(r),t.clearStencil(i)}const{depthNear:i,depthFar:a}=this[J].renderState,{width:n,height:o}=r;if("inline"!==this[J].mode){const e=n*(this[J].device.stereoEnabled?.5:1)/o;p(this[J].projectionMatrices[ke.Left],this[J].device.fovy,e,i,a),s(this[J].projectionMatrices[ke.Right],this[J].projectionMatrices[ke.Left])}else{const e=n/o;p(this[J].projectionMatrices[ke.None],this[J].renderState.inlineVerticalFieldOfView,e,i,a)}const h=new rt(this,this[J].frameHandle,!0,!0,performance.now()),l=performance.now(),u=this[J].device[B].devui;if(u&&u.render(l),"immersive-ar"===this[J].mode){const e=this[J].device[B].sem;e&&e.render(l)}this[J].enabledFeatures.includes("anchors")&&this[J].updateTrackedAnchors(),this[J].enabledFeatures.includes("plane-detection")&&this[J].updateTrackedPlanes(h),this[J].enabledFeatures.includes("mesh-detection")&&this[J].updateTrackedMeshes(h),this[J].enabledFeatures.includes("hit-test")&&this[J].computeHitTestResults(h),this[J].device[B].onFrameStart(h),this[J].updateActiveInputSources();const c=this[J].currentFrameCallbacks=this[J].frameCallbacks;this[J].frameCallbacks=[];const d=performance.now();for(let e=0;e<c.length;e++)try{c[e].cancelled||c[e].callback(d,h)}catch(e){console.error(e)}this[J].currentFrameCallbacks=null,h[G].active=!1},nominalFrameRate:e.internalNominalFrameRate,referenceSpaces:[],inputSourceArray:[],activeInputSources:[],updateActiveInputSources:()=>{const e=this[J].enabledFeatures.includes("hand-tracking"),t=this[J].activeInputSources,r=this[J].device.inputSources.filter((t=>!t.hand||e)),i=r.filter((e=>!t.includes(e))),s=t.filter((e=>!r.includes(e)));this[J].activeInputSources=r,(i.length>0||s.length>0)&&this.dispatchEvent(new Xe("inputsourceschange",{session:this,added:i,removed:s}))},trackedAnchors:new Ce,persistentAnchors:new Map,newAnchors:new Map,frameTrackedAnchors:new Ce,updateTrackedAnchors:()=>{this[J].enabledFeatures.includes("anchors")&&(this[J].frameTrackedAnchors.clear(),Array.from(this[J].trackedAnchors).forEach((e=>{if(e[N].deleted){if(this[J].trackedAnchors.delete(e),this[J].newAnchors.has(e)){const{reject:t}=this[J].newAnchors.get(e);t(new DOMException("Anchor is no longer tracked","InvalidStateError"))}}else if(this[J].frameTrackedAnchors.add(e),this[J].newAnchors.has(e)){const{resolve:t}=this[J].newAnchors.get(e);t(e),this[J].newAnchors.delete(e)}})))},trackedPlanes:new Map,updateTrackedPlanes:e=>{const t=this[J].device[B].sem;if(!t)return;Array.from(this[J].trackedPlanes.keys()).forEach((e=>{t.trackedPlanes.has(e)||this[J].trackedPlanes.delete(e)})),t.trackedPlanes.forEach((t=>{let r=this[J].trackedPlanes.get(t);if(!r){const e=new ne(this[J].device[B].globalSpace,t.transform.matrix);r=new Fe(t,e,t.polygon,t.semanticLabel),this[J].trackedPlanes.set(t,r)}r[j].lastChangedTime=e.predictedDisplayTime,r[j].frame=e,e[G].detectedPlanes.add(r)}))},trackedMeshes:new Map,updateTrackedMeshes:e=>{const t=this[J].device[B].sem;if(!t)return;Array.from(this[J].trackedMeshes.keys()).forEach((e=>{t.trackedMeshes.has(e)||this[J].trackedMeshes.delete(e)})),t.trackedMeshes.forEach((t=>{let r=this[J].trackedMeshes.get(t);if(!r){const e=new ne(this[J].device[B].globalSpace,t.transform.matrix);r=new Ee(t,e,t.vertices,t.indices,t.semanticLabel),this[J].trackedMeshes.set(t,r)}r[H].lastChangedTime=e.predictedDisplayTime,r[H].frame=e,e[G].detectedMeshes.add(r)}))},hitTestSources:new Set,computeHitTestResults:e=>{const t=this[J].device[B].sem;if(!t)return;const i=this[J].device[B].globalSpace;this[J].hitTestSources.forEach((s=>{const a=s[ae].space,o=he.calculateGlobalOffsetMatrix(a),h=s[ae].offsetRay.matrix,l=r();n(l,o,h);const u=[];t.computeHitTestResults(l).forEach((t=>{const r=new ne(i,t),s=new Ge(e,r);u.push(s)})),e[G].hitTestResultsMap.set(s,u)}))},onend:null,oninputsourceschange:null,onselect:null,onselectstart:null,onselectend:null,onsqueeze:null,onsqueezestart:null,onsqueezeend:null,onvisibilitychange:null,onframeratechange:null},Ne.recoverPersistentAnchorsFromStorage(this),this[J].onDeviceFrame()}get visibilityState(){return this[J].device.visibilityState}get frameRate(){return this[J].nominalFrameRate}get supportedFrameRates(){return new Float32Array(this[J].device.supportedFrameRates)}get renderState(){return this[J].renderState}get inputSources(){return this[J].inputSourceArray.length=0,this[J].ended||"inline"===this[J].mode||this[J].inputSourceArray.push(...this[J].activeInputSources),this[J].inputSourceArray}get enabledFeatures(){return this[J].enabledFeatures}get isSystemKeyboardSupported(){return this[J].isSystemKeyboardSupported}get environmentBlendMode(){var e;return null!==(e=this[J].device[B].environmentBlendModes[this[J].mode])&&void 0!==e?e:it.Opaque}get interactionMode(){return this[J].device[B].interactionMode}updateRenderState(e={}){var t,r,i,s;if(this[J].ended)throw new DOMException("XRSession has already ended.","InvalidStateError");if(e.baseLayer&&e.baseLayer[k].session!==this)throw new DOMException("Base layer was created by a different XRSession","InvalidStateError");if(null!=e.inlineVerticalFieldOfView&&"inline"!==this[J].mode)throw new DOMException("InlineVerticalFieldOfView must not be set for an immersive session","InvalidStateError");const a={baseLayer:e.baseLayer||(null===(t=this[J].pendingRenderState)||void 0===t?void 0:t.baseLayer)||void 0,depthFar:e.depthFar||(null===(r=this[J].pendingRenderState)||void 0===r?void 0:r.depthFar)||void 0,depthNear:e.depthNear||(null===(i=this[J].pendingRenderState)||void 0===i?void 0:i.depthNear)||void 0,inlineVerticalFieldOfView:e.inlineVerticalFieldOfView||(null===(s=this[J].pendingRenderState)||void 0===s?void 0:s.inlineVerticalFieldOfView)||void 0};this[J].pendingRenderState=new je(a,this[J].renderState)}async updateTargetFrameRate(e){return new Promise(((t,r)=>{this[J].ended?r(new DOMException("XRSession has already ended.","InvalidStateError")):this[J].device.supportedFrameRates.includes(e)?(this[J].nominalFrameRate===e?console.log("Requested frame rate is the same as the current nominal frame rate, no update made"):(this[J].nominalFrameRate=e,this.dispatchEvent(new We("frameratechange",{session:this})),console.log(`Nominal frame rate updated to ${e}`)),t()):r(new DOMException("Requested frame rate not supported.","InvalidStateError"))}))}async requestReferenceSpace(e){return new Promise(((t,r)=>{if(this[J].ended||!this[J].referenceSpaceIsSupported(e))return void r(new DOMException("The requested reference space type is not supported.","NotSupportedError"));let i;switch(e){case ze.Viewer:i=this[J].device.viewerSpace;break;case ze.Local:i=new He(e,this[J].device[B].globalSpace,this[J].device.viewerSpace[te].offsetMatrix);break;case ze.LocalFloor:case ze.BoundedFloor:case ze.Unbounded:i=new He(e,this[J].device[B].globalSpace)}this[J].referenceSpaces.push(i),t(i)}))}requestAnimationFrame(e){if(this[J].ended)return 0;const t=++this[J].frameHandle;return this[J].frameCallbacks.push({handle:t,callback:e,cancelled:!1}),t}cancelAnimationFrame(e){let t=this[J].frameCallbacks,r=t.findIndex((t=>t&&t.handle===e));r>-1&&(t[r].cancelled=!0,t.splice(r,1)),t=this[J].currentFrameCallbacks,t&&(r=t.findIndex((t=>t&&t.handle===e)),r>-1&&(t[r].cancelled=!0))}async end(){return new Promise(((e,t)=>{this[J].ended||null===this[J].deviceFrameHandle?t(new DOMException("XRSession has already ended.","InvalidStateError")):(globalThis.cancelAnimationFrame(this[J].deviceFrameHandle),this[J].device[B].onSessionEnd(),this.dispatchEvent(new We("end",{session:this})),e())}))}get persistentAnchors(){return Array.from(this[J].persistentAnchors.keys())}restorePersistentAnchor(e){return new Promise(((t,r)=>{if(this[J].persistentAnchors.has(e))if(this[J].ended)r(new DOMException("XRSession has already ended.","InvalidStateError"));else{const i=this[J].persistentAnchors.get(e);this[J].newAnchors.has(i)?r(new DOMException(`Multiple concurrent attempts detected to restore the anchor with UUID: ${e}.`,"InvalidStateError")):(this[J].trackedAnchors.add(i),this[J].newAnchors.set(i,{resolve:t,reject:r}))}else r(new DOMException(`Persistent anchor with uuid ${e} not found.`,"InvalidStateError"))}))}deletePersistentAnchor(e){return new Promise(((t,r)=>{if(this[J].persistentAnchors.has(e)){const r=this[J].persistentAnchors.get(e);this[J].persistentAnchors.delete(e),r.delete(),t(void 0)}else r(new DOMException(`Persistent anchor with uuid ${e} not found.`,"InvalidStateError"))}))}requestHitTestSource(e){return new Promise(((t,r)=>{if(this[J].enabledFeatures.includes("hit-test"))if(this[J].ended)r(new DOMException("XRSession has already ended.","InvalidStateError"));else if(this[J].device[B].sem){const r=new Ue(this,e);this[J].hitTestSources.add(r),t(r)}else r(new DOMException("Synthethic Environment Module required for emulating hit-test","OperationError"));else r(new DOMException('WebXR feature "hit-test" is not supported by current session',"NotSupportedError"))}))}get onend(){var e;return null!==(e=this[J].onend)&&void 0!==e?e:()=>{}}set onend(e){this[J].onend&&this.removeEventListener("end",this[J].onend),this[J].onend=e,e&&this.addEventListener("end",e)}get oninputsourceschange(){var e;return null!==(e=this[J].oninputsourceschange)&&void 0!==e?e:()=>{}}set oninputsourceschange(e){this[J].oninputsourceschange&&this.removeEventListener("inputsourceschange",this[J].oninputsourceschange),this[J].oninputsourceschange=e,e&&this.addEventListener("inputsourceschange",e)}get onselect(){var e;return null!==(e=this[J].onselect)&&void 0!==e?e:()=>{}}set onselect(e){this[J].onselect&&this.removeEventListener("select",this[J].onselect),this[J].onselect=e,e&&this.addEventListener("select",e)}get onselectstart(){var e;return null!==(e=this[J].onselectstart)&&void 0!==e?e:()=>{}}set onselectstart(e){this[J].onselectstart&&this.removeEventListener("selectstart",this[J].onselectstart),this[J].onselectstart=e,e&&this.addEventListener("selectstart",e)}get onselectend(){var e;return null!==(e=this[J].onselectend)&&void 0!==e?e:()=>{}}set onselectend(e){this[J].onselectend&&this.removeEventListener("selectend",this[J].onselectend),this[J].onselectend=e,e&&this.addEventListener("selectend",e)}get onsqueeze(){var e;return null!==(e=this[J].onsqueeze)&&void 0!==e?e:()=>{}}set onsqueeze(e){this[J].onsqueeze&&this.removeEventListener("squeeze",this[J].onsqueeze),this[J].onsqueeze=e,e&&this.addEventListener("squeeze",e)}get onsqueezestart(){var e;return null!==(e=this[J].onsqueezestart)&&void 0!==e?e:()=>{}}set onsqueezestart(e){this[J].onsqueezestart&&this.removeEventListener("squeezestart",this[J].onsqueezestart),this[J].onsqueezestart=e,e&&this.addEventListener("squeezestart",e)}get onsqueezeend(){var e;return null!==(e=this[J].onsqueezeend)&&void 0!==e?e:()=>{}}set onsqueezeend(e){this[J].onsqueezeend&&this.removeEventListener("squeezeend",this[J].onsqueezeend),this[J].onsqueezeend=e,e&&this.addEventListener("squeezeend",e)}get onvisibilitychange(){var e;return null!==(e=this[J].onvisibilitychange)&&void 0!==e?e:()=>{}}set onvisibilitychange(e){this[J].onvisibilitychange&&this.removeEventListener("visibilitychange",this[J].onvisibilitychange),this[J].onvisibilitychange=e,e&&this.addEventListener("visibilitychange",e)}get onframeratechange(){var e;return null!==(e=this[J].onframeratechange)&&void 0!==e?e:()=>{}}set onframeratechange(e){this[J].onframeratechange&&this.removeEventListener("frameratechange",this[J].onframeratechange),this[J].onframeratechange=e,e&&this.addEventListener("frameratechange",e)}}!function(e){e.Wrist="wrist",e.ThumbMetacarpal="thumb-metacarpal",e.ThumbPhalanxProximal="thumb-phalanx-proximal",e.ThumbPhalanxDistal="thumb-phalanx-distal",e.ThumbTip="thumb-tip",e.IndexFingerMetacarpal="index-finger-metacarpal",e.IndexFingerPhalanxProximal="index-finger-phalanx-proximal",e.IndexFingerPhalanxIntermediate="index-finger-phalanx-intermediate",e.IndexFingerPhalanxDistal="index-finger-phalanx-distal",e.IndexFingerTip="index-finger-tip",e.MiddleFingerMetacarpal="middle-finger-metacarpal",e.MiddleFingerPhalanxProximal="middle-finger-phalanx-proximal",e.MiddleFingerPhalanxIntermediate="middle-finger-phalanx-intermediate",e.MiddleFingerPhalanxDistal="middle-finger-phalanx-distal",e.MiddleFingerTip="middle-finger-tip",e.RingFingerMetacarpal="ring-finger-metacarpal",e.RingFingerPhalanxProximal="ring-finger-phalanx-proximal",e.RingFingerPhalanxIntermediate="ring-finger-phalanx-intermediate",e.RingFingerPhalanxDistal="ring-finger-phalanx-distal",e.RingFingerTip="ring-finger-tip",e.PinkyFingerMetacarpal="pinky-finger-metacarpal",e.PinkyFingerPhalanxProximal="pinky-finger-phalanx-proximal",e.PinkyFingerPhalanxIntermediate="pinky-finger-phalanx-intermediate",e.PinkyFingerPhalanxDistal="pinky-finger-phalanx-distal",e.PinkyFingerTip="pinky-finger-tip"}(at||(at={}));class ot extends Map{}class ht extends ne{constructor(e,t,r){super(t,r),this[Z]={jointName:e,radius:0}}get jointName(){return this[Z].jointName}}const lt={profileId:"oculus-hand",fallbackProfileIds:["generic-hand","generic-hand-select","generic-trigger"],poses:{default:{jointTransforms:{wrist:{offsetMatrix:[.9616971015930176,-.13805118203163147,.2368120402097702,0,.0005348679260350764,.8648636937141418,.5020061135292053,0,-.2741127610206604,-.48265108466148376,.8318111300468445,0,-.04913589730858803,.0021463718730956316,.11701996624469757,1],radius:.021460847929120064},"thumb-metacarpal":{offsetMatrix:[-.07536252588033676,-.9959676265716553,-.04867160692811012,0,.5877083539962769,-.08379616588354111,.8047218918800354,0,-.8055551648139954,.032041035592556,.5916536450386047,0,-.010643752291798592,.0006936835707165301,.08736639469861984,1],radius:.019382517784833908},"thumb-phalanx-proximal":{offsetMatrix:[.1374533325433731,-.9904957413673401,.004982374142855406,0,.5534393787384033,.08097179979085922,.8289443850517273,0,-.8214688897132874,-.11118389666080475,.559309184551239,0,.015547193586826324,-.0003480653394944966,.0681300163269043,1],radius:.01228295173496008},"thumb-phalanx-distal":{offsetMatrix:[-.04659227654337883,-.9974699020385742,-.05369402840733528,0,.6812446117401123,-.07104194164276123,.728600800037384,0,-.7305715084075928,-.002631746232509613,.6828309893608093,0,.04330715537071228,.003409178927540779,.0492292083799839,1],radius:.009768804535269737},"thumb-tip":{offsetMatrix:[-.04659227654337883,-.9974699020385742,-.05369402840733528,0,.6812446117401123,-.07104194164276123,.728600800037384,0,-.7305715084075928,-.002631746232509613,.6828309893608093,0,.062003348022699356,.004069602582603693,.03322213143110275,1],radius:.008768804371356964},"index-finger-metacarpal":{offsetMatrix:[.9616971015930176,-.13805118203163147,.2368120402097702,0,.0005348679260350764,.8648636937141418,.5020061135292053,0,-.2741127610206604,-.48265108466148376,.8318111300468445,0,-.02009812369942665,.008770795539021492,.08660387247800827,1],radius:.021228281781077385},"index-finger-phalanx-proximal":{offsetMatrix:[.9001791477203369,-.2598813474178314,.3494834005832672,0,.06073702871799469,.8695210218429565,.490146666765213,0,-.4312632381916046,-.41999316215515137,.7985095381736755,0,-.00017739279428496957,.03890012577176094,.039073407649993896,1],radius:.010295259766280651},"index-finger-phalanx-intermediate":{offsetMatrix:[.9082008600234985,-.20898112654685974,.36262574791908264,0,.11045389622449875,.9553793668746948,.27395179867744446,0,-.40369608998298645,-.20874978601932526,.8907597661018372,0,.01617925800383091,.05482936650514603,.008788082748651505,1],radius:.00853810179978609},"index-finger-phalanx-distal":{offsetMatrix:[.9309692978858948,-.16783711314201355,.32423174381256104,0,.1080828532576561,.9749603867530823,.1943446695804596,0,-.34873148798942566,-.14588497579097748,.9257990717887878,0,.02599053829908371,.059902746230363846,-.012860597111284733,1],radius:.007636196445673704},"index-finger-tip":{offsetMatrix:[.9309692978858948,-.16783711314201355,.32423174381256104,0,.1080828532576561,.9749603867530823,.1943446695804596,0,-.34873148798942566,-.14588497579097748,.9257990717887878,0,.03362493962049484,.06421422213315964,-.033461250364780426,1],radius:.006636196281760931},"middle-finger-metacarpal":{offsetMatrix:[.9616971015930176,-.13805118203163147,.2368120402097702,0,.0005348679260350764,.8648636937141418,.5020061135292053,0,-.2741127610206604,-.48265108466148376,.8318111300468445,0,-.03627845644950867,.011579737067222595,.08550142496824265,1],radius:.021231964230537415},"middle-finger-phalanx-proximal":{offsetMatrix:[.9876697659492493,-.06786545366048813,.1410750150680542,0,-.015095947310328484,.855663537979126,.5173118710517883,0,-.15582047402858734,-.5130629539489746,.8440889716148376,0,-.021259509027004242,.04587256908416748,.03659208118915558,1],radius:.01117393933236599},"middle-finger-phalanx-intermediate":{offsetMatrix:[.988391637802124,-.04354291781783104,.14555205404758453,0,.008894841186702251,.9729899168014526,.23067504167556763,0,-.15166506171226501,-.22670257091522217,.9620829224586487,0,-.014570588245987892,.06789684295654297,.0003578895702958107,1],radius:.008030958473682404},"middle-finger-phalanx-distal":{offsetMatrix:[.9853697419166565,.044260796159505844,.16458062827587128,0,-.0757969319820404,.9787378311157227,.19059516489505768,0,-.1526455283164978,-.20028135180473328,.9677740931510925,0,-.010392282158136368,.07414241135120392,-.026147106662392616,1],radius:.007629410829395056},"middle-finger-tip":{offsetMatrix:[.9853697419166565,.044260796159505844,.16458062827587128,0,-.0757969319820404,.9787378311157227,.19059516489505768,0,-.1526455283164978,-.20028135180473328,.9677740931510925,0,-.0069718430750072,.08024183660745621,-.05014154314994812,1],radius:.006629410665482283},"ring-finger-metacarpal":{offsetMatrix:[.9616971015930176,-.13805118203163147,.2368120402097702,0,.0005348679260350764,.8648636937141418,.5020061135292053,0,-.2741127610206604,-.48265108466148376,.8318111300468445,0,-.05402477830648422,.015797706320881844,.08152295649051666,1],radius:.019088275730609894},"ring-finger-phalanx-proximal":{offsetMatrix:[.9940828680992126,.05735103040933609,.09224652498960495,0,-.10022822767496109,.8116500377655029,.5754809379577637,0,-.041867565363645554,-.5813214182853699,.8125960826873779,0,-.041623555123806,.04171867296099663,.03582974523305893,1],radius:.00992213748395443},"ring-finger-phalanx-intermediate":{offsetMatrix:[.9843675494194031,.12044742703437805,.12850022315979004,0,-.15629759430885315,.9337108135223389,.3221098482608795,0,-.08118485659360886,-.3371586799621582,.937940776348114,0,-.039990875869989395,.06438793987035751,.004141641780734062,1],radius:.007611672393977642},"ring-finger-phalanx-distal":{offsetMatrix:[.9748351573944092,.11857274919748306,.18877571821212769,0,-.15575434267520905,.9681083559989929,.19623035192489624,0,-.15948788821697235,-.22069483995437622,.9622148275375366,0,-.03783353418111801,.07334739714860916,-.020782606676220894,1],radius:.007231088820844889},"ring-finger-tip":{offsetMatrix:[.9748351573944092,.11857274919748306,.18877571821212769,0,-.15575434267520905,.9681083559989929,.19623035192489624,0,-.15948788821697235,-.22069483995437622,.9622148275375366,0,-.03445569798350334,.0802423357963562,-.04392268508672714,1],radius:.0062310886569321156},"pinky-finger-metacarpal":{offsetMatrix:[.9181402921676636,.35625091195106506,.17350243031978607,0,-.39615097641944885,.8352503180503845,.38134080171585083,0,-.009065053425729275,-.41885748505592346,.9080066680908203,0,-.06191859766840935,.013620133511722088,.07850203663110733,1],radius:.01808827556669712},"pinky-finger-phalanx-proximal":{offsetMatrix:[.9714386463165283,.236698180437088,-.016745081171393394,0,-.18462024629116058,.7982627749443054,.5733163952827454,0,.14906984567642212,-.5538501739501953,.8191629648208618,0,-.061502378433942795,.032741155475378036,.03705105185508728,1],radius:.008483353070914745},"pinky-finger-phalanx-intermediate":{offsetMatrix:[.9337416291236877,.35620439052581787,-.03527557849884033,0,-.33203884959220886,.8987522721290588,.28634607791900635,0,.13370157778263092,-.2556603252887726,.9574766755104065,0,-.06608185172080994,.049755651503801346,.011886020191013813,1],radius:.0067641944624483585},"pinky-finger-phalanx-distal":{offsetMatrix:[.9419984817504883,.3303581774234772,.059175245463848114,0,-.33483216166496277,.9130291938781738,.23294763267040253,0,.02292730286717415,-.2392500638961792,.970687210559845,0,-.0687975287437439,.054948460310697556,-.007561664097011089,1],radius:.0064259846694767475},"pinky-finger-tip":{offsetMatrix:[.9419984817504883,.3303581774234772,.059175245463848114,0,-.33483216166496277,.9130291938781738,.23294763267040253,0,.02292730286717415,-.2392500638961792,.970687210559845,0,-.06947512179613113,.0613851435482502,-.028543535619974136,1],radius:.005425984505563974}},gripOffsetMatrix:[-.0005348679260350764,-.8648636937141418,-.5020061135292053,0,-.2741127908229828,-.48265108466148376,.8318111896514893,0,-.9616971015930176,.13805119693279266,-.2368120402097702,0,-.02878567762672901,.0017147823236882687,.04536811262369156,1]},pinch:{jointTransforms:{wrist:{offsetMatrix:[.9060805439949036,-.1844543218612671,.3807799518108368,0,-.08027800172567368,.8086723685264587,.5827555656433105,0,-.4154181182384491,-.5585917234420776,.7179155349731445,0,-.06867414712905884,-.009423808194696903,.10627774149179459,1],radius:.021460847929120064},"thumb-metacarpal":{offsetMatrix:[-.5012241005897522,-.8650535345077515,-.0213695727288723,0,.7415963411331177,-.4421543478965759,.5045139193534851,0,-.44587990641593933,.23702676594257355,.8631392121315002,0,-.032122574746608734,-.01196830440312624,.07194234430789948,1],radius:.019382517784833908},"thumb-phalanx-proximal":{offsetMatrix:[-.3175753057003021,-.9460570216178894,-.06419729441404343,0,.8958902955055237,-.32153913378715515,.30658137798309326,0,-.3106854259967804,.03984907269477844,.9496771097183228,0,-.017625702545046806,-.01967475935816765,.04387917369604111,1],radius:.01228295173496008},"thumb-phalanx-distal":{offsetMatrix:[-.4944636821746826,-.8691971898078918,.001086252392269671,0,.8307800889015198,-.4722411036491394,.2946045398712158,0,-.25555649399757385,.14657381176948547,.9556186199188232,0,-.007126678712666035,-.021021386608481407,.011786630377173424,1],radius:.009768804535269737},"thumb-tip":{offsetMatrix:[-.4944636821746826,-.8691971898078918,.001086252392269671,0,.8307800889015198,-.4722411036491394,.2946045398712158,0,-.25555649399757385,.14657381176948547,.9556186199188232,0,.0003423091256991029,-.024528030306100845,-.011410919018089771,1],radius:.008768804371356964},"index-finger-metacarpal":{offsetMatrix:[.9060805439949036,-.1844543218612671,.3807799518108368,0,-.08027800172567368,.8086723685264587,.5827555656433105,0,-.4154181182384491,-.5585917234420776,.7179155349731445,0,-.038037415593862534,-.0020236473064869642,.07626739144325256,1],radius:.021228281781077385},"index-finger-phalanx-proximal":{offsetMatrix:[.7986818552017212,-.35985732078552246,.48229536414146423,0,.538311243057251,.7854709625244141,-.30537736415863037,0,-.2689369022846222,.5035246014595032,.8210577368736267,0,-.006869405973702669,.033938243985176086,.04206443578004837,1],radius:.010295259766280651},"index-finger-phalanx-intermediate":{offsetMatrix:[.8285930156707764,-.32672837376594543,.4546217918395996,0,.5577570199966431,.4116027057170868,-.7207564115524292,0,.04836784675717354,.8507823944091797,.5232869386672974,0,.0033306588884443045,.014840902760624886,.010923954658210278,1],radius:.00853810179978609},"index-finger-phalanx-distal":{offsetMatrix:[.8412464261054993,-.35794928669929504,.4051857888698578,0,.5139996409416199,.29711154103279114,-.8046918511390686,0,.16765329241752625,.8852096796035767,.4339304566383362,0,.0021551470272243023,-.0058362227864563465,-.0017938464879989624,1],radius:.007636196445673704},"index-finger-tip":{offsetMatrix:[.8412464261054993,-.35794928669929504,.4051857888698578,0,.5139996409416199,.29711154103279114,-.8046918511390686,0,.16765329241752625,.8852096796035767,.4339304566383362,0,-.00131594471167773,-.025222131982445717,-.012442642822861671,1],radius:.006636196281760931},"middle-finger-metacarpal":{offsetMatrix:[.9060805439949036,-.1844543218612671,.3807799518108368,0,-.08027800172567368,.8086723685264587,.5827555656433105,0,-.4154181182384491,-.5585917234420776,.7179155349731445,0,-.05395089089870453,.003063359996303916,.07402937114238739,1],radius:.021231964230537415},"middle-finger-phalanx-proximal":{offsetMatrix:[.9187911748886108,-.1530158370733261,.36387869715690613,0,.038666240870952606,.9522662162780762,.302808940410614,0,-.3928440511226654,-.26414817571640015,.8808513283729553,0,-.02717282809317112,.04162866622209549,.03678669035434723,1],radius:.01117393933236599},"middle-finger-phalanx-intermediate":{offsetMatrix:[.9228746294975281,-.12856416404247284,.36300456523895264,0,.14524033665657043,.9892153143882751,-.01890045404434204,0,-.3566599190235138,.07016586512327194,.9315956234931946,0,-.01030921470373869,.05296773463487625,-.0010256498353555799,1],radius:.008030958473682404},"middle-finger-phalanx-distal":{offsetMatrix:[.9325166344642639,-.040404170751571655,.35885775089263916,0,.06836572289466858,.995502769947052,-.0655682161450386,0,-.3545948565006256,.08567725121974945,.9310863614082336,0,-.0004833847051486373,.05103470757603645,-.026690717786550522,1],radius:.007629410829395056},"middle-finger-tip":{offsetMatrix:[.9325166344642639,-.040404170751571655,.35885775089263916,0,.06836572289466858,.995502769947052,-.0655682161450386,0,-.3545948565006256,.08567725121974945,.9310863614082336,0,.008158999495208263,.05004044249653816,-.050120558589696884,1],radius:.006629410665482283},"ring-finger-metacarpal":{offsetMatrix:[.9060805439949036,-.1844543218612671,.3807799518108368,0,-.08027800172567368,.8086723685264587,.5827555656433105,0,-.4154181182384491,-.5585917234420776,.7179155349731445,0,-.06732909381389618,.007902119308710098,.07209732383489609,1],radius:.019088275730609894},"ring-finger-phalanx-proximal":{offsetMatrix:[.9391821026802063,-.027994679287075996,.34227466583251953,0,-.18282271921634674,.8029410243034363,.5673282742500305,0,-.2907087206840515,-.5954000353813171,.7489906549453735,0,-.047129884362220764,.03806127607822418,.032147664576768875,1],radius:.00992213748395443},"ring-finger-phalanx-intermediate":{offsetMatrix:[.9249380826950073,.03699534013867378,.3783116042613983,0,-.12898847460746765,.9667453765869141,.2208271026611328,0,-.3575615882873535,-.25304901599884033,.8989526629447937,0,-.03579339757561684,.06127955764532089,.002939916681498289,1],radius:.007611672393977642},"ring-finger-phalanx-distal":{offsetMatrix:[.9001164436340332,.03983335196971893,.4338230490684509,0,-.09662467986345291,.9892624020576477,.10964841395616531,0,-.4247973561286926,-.14061418175697327,.8943013548851013,0,-.026291755959391594,.06800390034914017,-.02094830758869648,1],radius:.007231088820844889},"ring-finger-tip":{offsetMatrix:[.9001164436340332,.03983335196971893,.4338230490684509,0,-.09662467986345291,.9892624020576477,.10964841395616531,0,-.4247973561286926,-.14061418175697327,.8943013548851013,0,-.016345610842108727,.07300511747598648,-.04263874143362045,1],radius:.0062310886569321156},"pinky-finger-metacarpal":{offsetMatrix:[.8769711852073669,.31462907791137695,.36322021484375,0,-.4506046175956726,.801031768321991,.39408499002456665,0,-.16696058213710785,-.5092697143554688,.8442559838294983,0,-.07460174709558487,.0062340241856873035,.06756893545389175,1],radius:.01808827556669712},"pinky-finger-phalanx-proximal":{offsetMatrix:[.9498357176780701,.1553308218717575,.2714462876319885,0,-.3019258379936218,.6817675232887268,.6663586497306824,0,-.08155745267868042,-.7148879170417786,.694466233253479,0,-.06697750836610794,.029482364654541016,.02902858518064022,1],radius:.008483353070914745},"pinky-finger-phalanx-intermediate":{offsetMatrix:[.9214097261428833,.27928245067596436,.2701927423477173,0,-.3670244514942169,.8538867831230164,.36901235580444336,0,-.12765564024448395,-.43917882442474365,.8892839550971985,0,-.06447203457355499,.05144399777054787,.0076942890882492065,1],radius:.0067641944624483585},"pinky-finger-phalanx-distal":{offsetMatrix:[.9038633704185486,.23618005216121674,.3567195236682892,0,-.3532794713973999,.8823202252388,.3109731376171112,0,-.24129553139209747,-.4070987403392792,.8809353709220886,0,-.06187915802001953,.060364335775375366,-.010368337854743004,1],radius:.0064259846694767475},"pinky-finger-tip":{offsetMatrix:[.9038633704185486,.23618005216121674,.3567195236682892,0,-.3532794713973999,.8823202252388,.3109731376171112,0,-.24129553139209747,-.4070987403392792,.8809353709220886,0,-.056796226650476456,.07042007893323898,-.02921444922685623,1],radius:.005425984505563974}},gripOffsetMatrix:[.08027800917625427,-.8086723685264587,-.5827556252479553,0,-.4154181480407715,-.5585916638374329,.7179154753684998,0,-.9060805439949036,.1844543218612671,-.3807799518108368,0,-.038054611533880234,-.002910431008785963,.03720742464065552,1]},point:{jointTransforms:{wrist:{offsetMatrix:[.9340395331382751,-.13936476409435272,.32885703444480896,0,-.005510995630174875,.914999783039093,.40341612696647644,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.05789132043719292,.01670890860259533,.11183350533246994,1],radius:.021460847929120064},"thumb-metacarpal":{offsetMatrix:[.02145560085773468,-.9978390336036682,.0621047280728817,0,.41311800479888916,.06541631370782852,.9083252549171448,0,-.9104245901107788,.006167683284729719,.4136286973953247,0,-.016488194465637207,.012708572670817375,.08862338215112686,1],radius:.019382517784833908},"thumb-phalanx-proximal":{offsetMatrix:[.21270370483398438,-.966137707233429,.14606566727161407,0,.49890995025634766,.2359165996313095,.8339261412620544,0,-.8401462435722351,-.10450579971075058,.5321959853172302,0,.013112368993461132,.012508046813309193,.07517509907484055,1],radius:.01228295173496008},"thumb-phalanx-distal":{offsetMatrix:[.01653280481696129,-.9986647963523865,.048943229019641876,0,.26313456892967224,.051570065319538116,.9633802771568298,0,-.9646173715591431,-.0030490627977997065,.26363563537597656,0,.04150351136922836,.016039609909057617,.05719054117798805,1],radius:.009768804535269737},"thumb-tip":{offsetMatrix:[.01653280481696129,-.9986647963523865,.048943229019641876,0,.26313456892967224,.051570065319538116,.9633802771568298,0,-.9646173715591431,-.0030490627977997065,.26363563537597656,0,.06548332422971725,.01683700829744339,.0516640841960907,1],radius:.008768804371356964},"index-finger-metacarpal":{offsetMatrix:[.9340395331382751,-.13936476409435272,.32885703444480896,0,-.005510995630174875,.914999783039093,.40341612696647644,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.02592567168176174,.019982583820819855,.08479326963424683,1],radius:.021228281781077385},"index-finger-phalanx-proximal":{offsetMatrix:[.9063700437545776,-.21756279468536377,.3621589243412018,0,.0970839336514473,.9415287375450134,.3226419687271118,0,-.41117796301841736,-.2572731077671051,.8744958639144897,0,-.0015709538711234927,.043078210204839706,.034657616168260574,1],radius:.010295259766280651},"index-finger-phalanx-intermediate":{offsetMatrix:[.9159826040267944,-.1651475727558136,.36565208435058594,0,.09755707532167435,.9756820797920227,.1962820291519165,0,-.3891757130622864,-.14411886036396027,.9098196625709534,0,.014023927971720695,.052835866808891296,.0014903299743309617,1],radius:.00853810179978609},"index-finger-phalanx-distal":{offsetMatrix:[.9378057718276978,-.12329639494419098,.3245268166065216,0,.032558172941207886,.9619227051734924,.2713746726512909,0,-.3456292748451233,-.2439306229352951,.9061115384101868,0,.023482320830225945,.05633850023150444,-.020621655508875847,1],radius:.007636196445673704},"index-finger-tip":{offsetMatrix:[.9378057718276978,-.12329639494419098,.3245268166065216,0,.032558172941207886,.9619227051734924,.2713746726512909,0,-.3456292748451233,-.2439306229352951,.9061115384101868,0,.03096788562834263,.06281610578298569,-.040703095495700836,1],radius:.006636196281760931},"middle-finger-metacarpal":{offsetMatrix:[.9340395331382751,-.13936476409435272,.32885703444480896,0,-.005510995630174875,.914999783039093,.40341612696647644,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.04184452444314957,.022474845871329308,.08177298307418823,1],radius:.021231964230537415},"middle-finger-phalanx-proximal":{offsetMatrix:[.9720265865325928,-.08313076198101044,.21966552734375,0,.20477405190467834,.7580050826072693,-.6192700862884521,0,-.11502730846405029,.6469289064407349,.7538246512413025,0,-.022107340395450592,.05035499855875969,.02970452979207039,1],radius:.01117393933236599},"middle-finger-phalanx-intermediate":{offsetMatrix:[.9779140949249268,-.07129573822021484,.19646917283535004,0,.1287083923816681,-.5352076292037964,-.8348574042320251,0,.1646735966205597,.8417060971260071,-.5142109394073486,0,-.017169542610645294,.022584279999136925,-.00265491777099669,1],radius:.008030958473682404},"middle-finger-phalanx-distal":{offsetMatrix:[.9774913787841797,-.19657190144062042,.07661263644695282,0,-.1924918293952942,-.9796126484870911,-.05749811604619026,0,.08635343611240387,.041456472128629684,-.995401918888092,0,-.02170622907578945,-.0006043742760084569,.011511396616697311,1],radius:.007629410829395056},"middle-finger-tip":{offsetMatrix:[.9774913787841797,-.19657190144062042,.07661263644695282,0,-.1924918293952942,-.9796126484870911,-.05749811604619026,0,.08635343611240387,.041456472128629684,-.995401918888092,0,-.02438267692923546,-.0026927536819130182,.03627248480916023,1],radius:.006629410665482283},"ring-finger-metacarpal":{offsetMatrix:[.9340395331382751,-.13936476409435272,.32885703444480896,0,-.005510995630174875,.914999783039093,.40341612696647644,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.05944233387708664,.0264605600386858,.07478221505880356,1],radius:.019088275730609894},"ring-finger-phalanx-proximal":{offsetMatrix:[.9842101335525513,.024470895528793335,.1753024309873581,0,.12200043350458145,.6237703561782837,-.7720272541046143,0,-.12824076414108276,.7812241315841675,.610936164855957,0,-.04249368980526924,.0467497780919075,.027722163125872612,1],radius:.00992213748395443},"ring-finger-phalanx-intermediate":{offsetMatrix:[.9941774606704712,.05949164181947708,.08983955532312393,0,.10504482686519623,-.7208291888237,-.6851072907447815,0,.024001073092222214,.6905553936958313,-.7228817939758301,0,-.0374927744269371,.016285063698887825,.0038980208337306976,1],radius:.007611672393977642},"ring-finger-phalanx-distal":{offsetMatrix:[.9995742440223694,.01638498157262802,.02412819117307663,0,.007813597097992897,-.9474818110466003,.31971633434295654,0,.028100071474909782,-.31939181685447693,-.9472070932388306,0,-.038130562752485275,-.0020653479732573032,.02310742810368538,1],radius:.007231088820844889},"ring-finger-tip":{offsetMatrix:[.9995742440223694,.01638498157262802,.02412819117307663,0,.007813597097992897,-.9474818110466003,.31971633434295654,0,.028100071474909782,-.31939181685447693,-.9472070932388306,0,-.0390593595802784,.004176302347332239,.0466572530567646,1],radius:.0062310886569321156},"pinky-finger-metacarpal":{offsetMatrix:[.9147363901138306,.3458845317363739,.20885537564754486,0,-.3923271894454956,.8839452862739563,.2544005811214447,0,-.09662359952926636,-.3146490156650543,.9442773461341858,0,-.06715242564678192,.024195827543735504,.07137546688318253,1],radius:.01808827556669712},"pinky-finger-phalanx-proximal":{offsetMatrix:[.9613109827041626,.22439135611057281,.15977802872657776,0,.01002211682498455,.5511574745178223,-.8343409299850464,0,-.27528178691864014,.8036624789237976,.5275853276252747,0,-.06273911893367767,.038559623062610626,.028268879279494286,1],radius:.008483353070914745},"pinky-finger-phalanx-intermediate":{offsetMatrix:[.9820972084999084,.18811029195785522,-.00995189044624567,0,.14063723385334015,-.7673450708389282,-.6256227493286133,0,-.12532226741313934,.6130226850509644,-.7800630927085876,0,-.05428232625126839,.013870777562260628,.012061242014169693,1],radius:.0067641944624483585},"pinky-finger-phalanx-distal":{offsetMatrix:[.9744614362716675,.20454788208007812,-.09265263378620148,0,.22429193556308746,-.9065253138542175,.35764020681381226,0,-.010836843401193619,-.3692878782749176,-.9292529225349426,0,-.05173685774207115,.0014194445684552193,.02790539152920246,1],radius:.0064259846694767475},"pinky-finger-tip":{offsetMatrix:[.9744614362716675,.20454788208007812,-.09265263378620148,0,.22429193556308746,-.9065253138542175,.35764020681381226,0,-.010836843401193619,-.3692878782749176,-.9292529225349426,0,-.05098633095622063,.008463085629045963,.048688892275094986,1],radius:.005425984505563974}},gripOffsetMatrix:[.005510995630174875,-.9149997234344482,-.40341615676879883,0,-.3571262061595917,-.37861889600753784,.8538784384727478,0,-.9340395331382751,.13936474919319153,-.32885703444480896,0,-.031803809106349945,.007837686687707901,.04313928261399269,1]}}},ut={mapping:ce.None,buttons:[{id:"pinch",type:"analog",eventTrigger:"select"}],axes:[]},ct=f(),dt=_(),pt=f(),ft=f(),xt=_(),mt=f(),gt=f(),yt=_(),vt=f(),Tt=(e,t,r,i)=>(u(ct,t),d(dt,t),c(pt,t),u(ft,r),d(xt,r),c(mt,r),w(gt,ct,ft,i),M(yt,dt,xt,i),w(vt,pt,mt,i),function(e,t,r,i){var s=t[0],a=t[1],n=t[2],o=t[3],h=s+s,l=a+a,u=n+n,c=s*h,d=s*l,p=s*u,f=a*l,x=a*u,m=n*u,g=o*h,y=o*l,v=o*u,T=i[0],w=i[1],S=i[2];e[0]=(1-(f+m))*T,e[1]=(d+v)*T,e[2]=(p-y)*T,e[3]=0,e[4]=(d-v)*w,e[5]=(1-(c+m))*w,e[6]=(x+g)*w,e[7]=0,e[8]=(p+y)*S,e[9]=(x-g)*S,e[10]=(1-(c+f))*S,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1}(e,yt,gt,vt),e),wt=[1,-1,-1,0,-1,1,1,0,-1,1,1,0,-1,1,1,1];class St extends we{constructor(e,t,r){if(t!==de.Left&&t!==de.Right)throw new DOMException('handedness for XRHandInput must be either "left" or "right"',"InvalidStateError");if(!e.poses.default||!e.poses.pinch)throw new DOMException('"default" and "pinch" hand pose configs are required',"InvalidStateError");const i=new ne(r),s=new ne(i),a=[e.profileId,...e.fallbackProfileIds],n=new ot;Object.values(at).forEach((e=>{n.set(e,new ht(e,i))}));super(new ye(t,pe.TrackedPointer,a,i,new me(ut),s,n)),this[V]={poseId:"default",poses:e.poses},this.updateHandPose()}get poseId(){return this[V].poseId}set poseId(e){this[V].poses[e]?this[V].poseId=e:console.warn(`Pose config ${e} not found`)}updateHandPose(){const e=this[V].poses[this[V].poseId],t=this[V].poses.pinch;Object.values(at).forEach((r=>{const i=e.jointTransforms[r].offsetMatrix,s=t.jointTransforms[r].offsetMatrix,a=this.inputSource.hand.get(r);Tt(a[te].offsetMatrix,i,s,this.pinchValue),this.inputSource.handedness===de.Right&&(e=>{for(let t=0;t<16;t++)e[t]*=wt[t]})(a[te].offsetMatrix),a[Z].radius=(1-this.pinchValue)*e.jointTransforms[r].radius+this.pinchValue*t.jointTransforms[r].radius})),e.gripOffsetMatrix&&t.gripOffsetMatrix&&Tt(this.inputSource.gripSpace[te].offsetMatrix,e.gripOffsetMatrix,t.gripOffsetMatrix,this.pinchValue)}get pinchValue(){return this[U].inputSource.gamepad[X].buttonsMap.pinch.value}updatePinchValue(e){if(e>1||e<0)return void console.warn(`Out-of-range value ${e} provided for pinch`);this[U].inputSource.gamepad[X].buttonsMap.pinch[X].pendingValue=e}onFrameStart(e){super.onFrameStart(e),this.updateHandPose()}}class Et extends EventTarget{}const Rt={antialias:!0,depth:!0,stencil:!1,alpha:!0,ignoreDepthValues:!1,framebufferScaleFactor:1};class _t extends Et{constructor(e,t,r={}){if(super(),e[J].ended)throw new DOMException("Session has ended","InvalidStateError");const i={...Rt,...r};this[k]={session:e,context:t,antialias:i.antialias}}get context(){return this[k].context}get antialias(){return this[k].antialias}get ignoreDepthValues(){return!0}get framebuffer(){return null}get framebufferWidth(){return this[k].context.drawingBufferWidth}get framebufferHeight(){return this[k].context.drawingBufferHeight}getViewport(e){if(e[re].session!==this[k].session)throw new DOMException("View's session differs from Layer's session","InvalidStateError");return this[k].session[J].device[B].getViewport(this,e)}static getNativeFramebufferScaleFactor(e){if(!(e instanceof nt))throw new TypeError("getNativeFramebufferScaleFactor must be passed a session.");return e[J].ended?0:1}}class bt{constructor(e,t,r){const{schema:i,frames:s}=t;if(!s||!i||0===s.length)throw new DOMException("wrong recording format","NotSupportedError");const a=new He(ze.Viewer,e),n={[ke.Left]:new ne(a),[ke.Right]:new ne(a),[ke.None]:new ne(a)};this[C]={refSpace:e,inputSources:new Map,inputSchemas:new Map,frames:s,recordedFramePointer:0,startingTimeStamp:s[0][0],endingTimeStamp:s[s.length-1][0],playbackTime:s[0][0],playing:!1,viewerSpace:a,viewSpaces:n,vec3:f(),quat:_()},o(this[C].viewSpaces[ke.Left][te].offsetMatrix,x(-r/2,0,0)),o(this[C].viewSpaces[ke.Right][te].offsetMatrix,x(r/2,0,0)),i.forEach((t=>{const r=t[0],i=t[1];let s;if(i.hasGamepad){const e=[];for(let t=0;t<i.numButtons;t++)e.push({id:t.toString(),type:"manual"});const t=[];for(let e=0;e<i.numAxes;e++)t.push({id:e.toString(),type:"manual"});s=new me({mapping:i.mapping,buttons:e,axes:t})}const a=new ne(e);let n;i.hasHand&&(n=new ot,Object.values(at).forEach((e=>{n.set(e,new ht(e,a))})));const o=new ye(i.handedness,i.targetRayMode,i.profiles,a,s,i.hasGrip?new ne(e):void 0,i.hasHand?n:void 0);this[C].inputSources.set(r,{active:!1,source:o}),this[C].inputSchemas.set(r,i)}))}play(){this[C].recordedFramePointer=0,this[C].playbackTime=this[C].startingTimeStamp,this[C].playing=!0,this[C].actualTimeStamp=performance.now()}stop(){this[C].playing=!1}get playing(){return this[C].playing}get viewerSpace(){return this[C].viewerSpace}get viewSpaces(){return this[C].viewSpaces}get inputSources(){return Array.from(this[C].inputSources.values()).filter((e=>e.active)).map((e=>e.source))}playFrame(){const e=performance.now(),t=e-this[C].actualTimeStamp;if(this[C].actualTimeStamp=e,this[C].playbackTime+=t,this[C].playbackTime>this[C].endingTimeStamp)return void this.stop();for(;this[C].frames[this[C].recordedFramePointer+1][0]<this[C].playbackTime;)this[C].recordedFramePointer++;const r=this[C].frames[this[C].recordedFramePointer],i=this[C].frames[this[C].recordedFramePointer+1],s=(this[C].playbackTime-r[0])/(i[0]-r[0]);this.updateXRSpaceFromMergedFrames(this[C].viewerSpace,r.slice(1,8),i.slice(1,8),s);const a=new Map;for(let e=8;e<r.length;e++){const{index:t,inputData:i}=this.processRawInputData(r[e]);a.set(t,i)}const n=new Map;for(let e=8;e<i.length;e++){const{index:t,inputData:r}=this.processRawInputData(i[e]);n.set(t,r)}this[C].inputSources.forEach((e=>{e.active=!1})),n.forEach(((e,t)=>{this[C].inputSources.get(t).active=!0;const r=this[C].inputSources.get(t).source,i=this[C].inputSchemas.get(t);this.updateInputSource(r,i,a.has(t)?a.get(t):e,e,s)}))}updateInputSource(e,t,r,i,s){if(this.updateXRSpaceFromMergedFrames(e.targetRaySpace,r.targetRayTransform,i.targetRayTransform,s),t.hasGrip&&this.updateXRSpaceFromMergedFrames(e.gripSpace,r.gripTransform,i.gripTransform,s),t.hasHand)for(let a=0;a<25;a++){const n=r.handTransforms.slice(8*a,8*a+7),o=i.handTransforms.slice(8*a,8*a+7),h=r.handTransforms[8*a+7],l=i.handTransforms[8*a+7],u=e.hand.get(t.jointSequence[a]);this.updateXRSpaceFromMergedFrames(u,n,o,s),u[Z].radius=(l-h)*s+h}if(t.hasGamepad){const t=e.gamepad;i.buttons.forEach(((e,i)=>{const a=t.buttons[i];a[X].pressed=1===e[0],a[X].touched=1===e[1];const n=r.buttons[i][2],o=e[2];a[X].value=(o-n)*s+n})),i.axes.forEach(((e,i)=>{const a=r.axes[i];t[X].axesMap[i.toString()].x=(e-a)*s+a}))}}updateXRSpaceFromMergedFrames(e,t,r,i){const s=x(t[0],t[1],t[2]),a=F(t[3],t[4],t[5],t[6]),n=x(r[0],r[1],r[2]),o=F(r[3],r[4],r[5],r[6]);w(this[C].vec3,s,n,i),M(this[C].quat,a,o,i),l(e[te].offsetMatrix,this[C].quat,this[C].vec3)}processRawInputData(e){const t=e[0],r=this[C].inputSchemas.get(t),i={targetRayTransform:e.slice(1,8)};let s=8;if(r.hasGrip&&(i.gripTransform=e[s++]),r.hasHand&&(i.handTransforms=e[s++]),r.hasGamepad){const t=e[s];i.buttons=t.slice(0,r.numButtons),i.axes=t.slice(r.numButtons)}return{index:t,inputData:i}}}const Mt="2.1.1";class At extends Event{constructor(e,t){if(super(e,t),!t.referenceSpace)throw new Error("XRReferenceSpaceEventInit.referenceSpace is required");this.referenceSpace=t.referenceSpace,this.transform=t.transform}}class Ft extends EventTarget{constructor(e){super(),this[q]={device:e,grantSession:({resolve:e,reject:t,mode:r,options:i})=>{if(this[q].activeSession)return void t(new DOMException("An active XRSession already exists.","InvalidStateError"));const{requiredFeatures:s=[],optionalFeatures:a=[]}=i,{supportedFeatures:n}=this[q].device;if(!s.every((e=>n.includes(e))))return void t(new Error("One or more required features are not supported by the device."));const o=a.filter((e=>n.includes(e))),h=Array.from(new Set([...s,...o,"viewer","local"])),l=new nt(this[q].device,r,h);this[q].activeSession=l,l.addEventListener("end",(()=>{this[q].activeSession=void 0})),e(l)}}}isSessionSupported(e){return new Promise(((t,r)=>{t("inline"===e||this[q].device.supportedSessionModes.includes(e))}))}requestSession(e,t={}){return new Promise(((r,i)=>{this.isSessionSupported(e).then((s=>{if(!s)return void i(new DOMException("The requested XRSession mode is not supported.","NotSupportedError"));const a={resolve:r,reject:i,mode:e,options:t};this[q].grantSession(a)})).catch(i)}))}offerSession(e,t={}){return new Promise(((r,i)=>{this.isSessionSupported(e).then((s=>{s?this[q].offeredSessionConfig={resolve:r,reject:i,mode:e,options:t}:i(new DOMException("The requested XRSession mode is not supported.","NotSupportedError"))})).catch(i)}))}}class Pt{constructor(e,t,r,i){this[ie]={x:e,y:t,width:r,height:i}}get x(){return this[ie].x}get y(){return this[ie].y}get width(){return this[ie].width}get height(){return this[ie].height}}
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* webxr-layers-polyfill
|
|
5
|
+
* Version 1.1.0
|
|
6
|
+
* Copyright (c) 2021 Facebook, Inc. and its affiliates.
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* @license
|
|
21
|
+
* gl-matrix
|
|
22
|
+
* Version 3.4.3
|
|
23
|
+
* Copyright (c) 2015-2021, Brandon Jones, Colin MacKenzie IV.
|
|
24
|
+
*
|
|
25
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
26
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
27
|
+
* in the Software without restriction, including without limitation the rights
|
|
28
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
29
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
30
|
+
* furnished to do so, subject to the following conditions:
|
|
31
|
+
*
|
|
32
|
+
* The above copyright notice and this permission notice shall be included in
|
|
33
|
+
* all copies or substantial portions of the Software.
|
|
34
|
+
*
|
|
35
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
36
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
37
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
38
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
39
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
40
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
41
|
+
* THE SOFTWARE.
|
|
42
|
+
*/var It,Lt;!function(e){e.texture="texture",e["texture-array"]="texture-array"}(It||(It={})),function(e){e.default="default",e.mono="mono",e.stereo="stereo",e["stereo-left-right"]="stereo-left-right",e["stereo-top-bottom"]="stereo-top-bottom"}(Lt||(Lt={}));const Ct=e=>e&&"function"==typeof e.getOffsetReferenceSpace,Dt=()=>"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},Nt=(e,t)=>{switch(t){case e.RGBA8:case e.RGB5_A1:case e.RGBA4:case e.SRGB8_ALPHA8:return{internalFormat:t,textureFormat:e.RGBA,type:e.UNSIGNED_BYTE};case e.RGBA8_SNORM:return{internalFormat:t,textureFormat:e.RGBA,type:e.BYTE};case e.RGB10_A2:return{internalFormat:t,textureFormat:e.RGBA,type:e.UNSIGNED_INT_2_10_10_10_REV};case e.RGBA16F:return{internalFormat:t,textureFormat:e.RGBA,type:e.HALF_FLOAT};case e.RGBA32F:return{internalFormat:t,textureFormat:e.RGBA,type:e.FLOAT};case e.RGBA8UI:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.UNSIGNED_BYTE};case e.RGBA8I:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.BYTE};case e.RGBA16UI:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.UNSIGNED_SHORT};case e.RGBA16I:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.SHORT};case e.RGBA32UI:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.UNSIGNED_INT};case e.RGBA32I:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.INT};case e.RGB10_A2UI:return{internalFormat:t,textureFormat:e.RGBA_INTEGER,type:e.UNSIGNED_INT_2_10_10_10_REV};case e.RGB8:case e.RGB565:case e.SRGB8:return{internalFormat:t,textureFormat:e.RGB,type:e.UNSIGNED_BYTE};case e.RGB8_SNORM:return{internalFormat:t,textureFormat:e.RGB,type:e.BYTE};case e.RGB16F:case e.R11F_G11F_B10F:case e.RGB9_E5:return{internalFormat:t,textureFormat:e.RGB,type:e.HALF_FLOAT};case e.RGB32F:return{internalFormat:t,textureFormat:e.RGB,type:e.FLOAT};case e.RGB8UI:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.UNSIGNED_BYTE};case e.RGB8I:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.BYTE};case e.RGB16UI:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.UNSIGNED_SHORT};case e.RGB16I:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.SHORT};case e.RGB32UI:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.UNSIGNED_INT};case e.RGB32I:return{internalFormat:t,textureFormat:e.RGB_INTEGER,type:e.INT};case e.DEPTH_COMPONENT16:return{internalFormat:t,textureFormat:e.DEPTH_COMPONENT,type:e.UNSIGNED_SHORT};case e.DEPTH_COMPONENT24:return{internalFormat:t,textureFormat:e.DEPTH_COMPONENT,type:e.UNSIGNED_INT};case e.DEPTH_COMPONENT32F:return{internalFormat:t,textureFormat:e.DEPTH_COMPONENT,type:e.FLOAT};case e.DEPTH24_STENCIL8:return{internalFormat:t,textureFormat:e.DEPTH_STENCIL,type:e.UNSIGNED_INT_24_8};case e.DEPTH32F_STENCIL8:return{internalFormat:t,textureFormat:e.DEPTH_STENCIL,type:e.FLOAT_32_UNSIGNED_INT_24_8_REV};case e.DEPTH_COMPONENT:return Nt(e,e.DEPTH_COMPONENT24);case e.DEPTH_STENCIL:return Nt(e,e.DEPTH24_STENCIL8);case e.RGBA:case e.RGB:case e.LUMINANCE_ALPHA:case e.LUMINANCE:case e.ALPHA:return{internalFormat:t,textureFormat:t,type:e.UNSIGNED_BYTE};default:throw new Error("Attempted to create polyfill with unsupported format.")}};class Ot{constructor(){this._hasRunDeferredInitialize=!1,this._media=null}initialize(e,t){this.session=e,t&&(this.context=t),this.blendTextureSourceAlpha=!0}destroy(){this._colorTextures=[],this._depthStencilTextures=[]}addEventListener(e,t,r){}dispatchEvent(e){return!1}removeEventListener(e,t,r){}getContext(){return this.context}getTextureType(){throw new Error("Unimplemented")}get colorTextures(){return this._colorTextures}get depthStencilTextures(){return this._depthStencilTextures}get colorTexturesMeta(){return this._texturesMeta}get media(){return this.isMediaLayer()||console.warn("Attempted to retrieve media from a non-media layer"),this._media}determineLayoutAttribute(e,t,r){if(!(t instanceof WebGL2RenderingContext)&&e===It["texture-array"])throw new TypeError;if(r===Lt.mono)return r;if(r===Lt.default){if(this.session.internalViews&&1===this.session.internalViews.length)return Lt.mono;if(e===It["texture-array"])return r}return r===Lt.default||r===Lt.stereo?Lt["stereo-left-right"]:r}isMediaLayer(){return null!==this._media}_deferredInitialize(){}initializeIfNeeded(){this._hasRunDeferredInitialize||(this._hasRunDeferredInitialize=!0,this._deferredInitialize())}_allocateColorTexturesInternal(e,t){let r=this.session.internalViews;if(r&&0!==r.length){if(this.initializeIfNeeded(),this.layout===Lt.mono){if(e===It["texture-array"]){const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}{const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}}if(this.layout===Lt.stereo){if(e===It["texture-array"]){const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat,2);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}{const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat),i=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r,i],void(this._colorTextures=[r.texture,i.texture])}}if(this.layout===Lt["stereo-left-right"]){const r=this._createNewColorTexture(2*t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}if(this.layout===Lt["stereo-top-bottom"]){const r=this._createNewColorTexture(t.viewPixelWidth,2*t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[r],void(this._colorTextures=[r.texture])}}else console.warn("We can't allocate color textures without views")}_allocateDepthStencilTexturesInternal(e,t){if(t.depthFormat){if(this._getSupportedDepthFormats().indexOf(t.depthFormat)<0)throw new Error("Depth format provided is not supported in non-projection layers.");if(t.mipLevels<1)throw new Error("Invalid miplevel. Miplevel needs to be >= 1");if(this.layout===Lt.mono){if(e===It["texture-array"]){const r=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture])}{const r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture])}}if(this.layout===Lt.stereo){if(e===It["texture-array"]){const r=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat,2);return void(this._depthStencilTextures=[r.texture])}{const r=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat),i=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture,i.texture])}}if(this.layout!==Lt["stereo-left-right"])if(this.layout!==Lt["stereo-top-bottom"]);else{const r=this._createNewDepthStencilTexture(t.viewPixelWidth,2*t.viewPixelHeight,e,t.depthFormat);this._depthStencilTextures=[r.texture]}else{const r=this._createNewDepthStencilTexture(2*t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);this._depthStencilTextures=[r.texture]}}else this._depthStencilTextures=[]}_createNewColorTexture(e,t,r,i,s=1){return this._createGenericPolyfillTexture(r,e,t,i,0,s)}_createNewDepthStencilTexture(e,t,r,i,s=1){return this._createGenericPolyfillTexture(r,e,t,i,0,s)}_createGenericPolyfillTexture(e,t,r,i,s=0,a=1){if(e===It["texture-array"]&&a<=1&&console.warn("creating a texture array with a single layer..."),e===It["texture-array"]&&this.context instanceof WebGLRenderingContext)throw new Error("WebGL 1 does not support texture array");let n=this.context.createTexture(),o={width:t,height:r,layers:a,type:e,textureFormat:i,texture:n},h=i,l=this.context.UNSIGNED_BYTE;if(this.context instanceof WebGL2RenderingContext){const e=Nt(this.context,i);h=e.internalFormat,i=e.textureFormat,l=e.type}else i===this.context.DEPTH_COMPONENT&&(l=this.context.UNSIGNED_INT),i===this.context.DEPTH_STENCIL&&(l=this.context.UNSIGNED_INT_24_8_WEBGL);if(e===It["texture-array"]&&this.context instanceof WebGL2RenderingContext){console.warn("texture-array layers are supported...questionably in the polyfill at the moment. Use at your own risk.");const e=this.context.getParameter(this.context.TEXTURE_BINDING_2D_ARRAY);this.context.bindTexture(this.context.TEXTURE_2D_ARRAY,n),this._getSupportedDepthFormats().indexOf(i)>=0?this.context.texStorage3D(this.context.TEXTURE_2D_ARRAY,1,h,t,r,a):this.context.texImage3D(this.context.TEXTURE_2D_ARRAY,0,h,t,r,a,0,i,l,null),this.context.bindTexture(this.context.TEXTURE_2D_ARRAY,e)}else{const e=this.context.getParameter(this.context.TEXTURE_BINDING_2D);this.context.bindTexture(this.context.TEXTURE_2D,n),this.context.texImage2D(this.context.TEXTURE_2D,0,h,t,r,0,i,l,null),this.context.bindTexture(this.context.TEXTURE_2D,e)}return o}_getSupportedDepthFormats(){const e=[];return this.context instanceof WebGLRenderingContext&&!this.context.getExtension("WEBGL_depth_texture")||(e.push(this.context.DEPTH_COMPONENT,this.context.DEPTH_STENCIL),this.context instanceof WebGL2RenderingContext&&e.push(this.context.DEPTH_COMPONENT24,this.context.DEPTH24_STENCIL8)),e}}const Bt={colorFormat:6408,mipLevels:1,layout:Lt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:It.texture,radius:2,centralAngle:.78539,aspectRatio:2},Vt={layout:Lt.mono,invertStereo:!1,space:null,radius:2,centralAngle:.78539};class Ut extends Ot{constructor(e,t){super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},Vt),e):this.init=Object.assign(Object.assign({},Bt),e),this.radius=this.init.radius,this.centralAngle=this.init.centralAngle,this.aspectRatio=this.init.aspectRatio,this.space=this.init.space,this.layout=this.init.layout;const r=Dt();this.init.transform?this.transform=new r.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new r.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?It.texture:this.init.textureType}_deferredInitialize(){let e=this.determineLayoutAttribute(this.init.textureType,this.context,this.init.layout);this.layout=e,this.needsRedraw=!0}get colorTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._colorTextures}get depthStencilTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._depthStencilTextures&&this._depthStencilTextures.length||this._allocateDepthStencilTexturesInternal(this.getTextureType(),this.init),this._depthStencilTextures}get colorTexturesMeta(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._texturesMeta}get width(){return 2*this.radius*Math.PI*(this.centralAngle/(2*Math.PI))}get height(){return this.width/this.aspectRatio}}const Gt={colorFormat:6408,mipLevels:1,layout:Lt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:It.texture,radius:0,centralHorizontalAngle:6.28318,upperVerticalAngle:1.570795,lowerVerticalAngle:-1.570795},Xt={space:null,layout:Lt.mono,invertStereo:!1,radius:0,centralHorizontalAngle:6.28318,upperVerticalAngle:1.570795,lowerVerticalAngle:-1.570795};class qt extends Ot{constructor(e,t){if(super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},Xt),e):this.init=Object.assign(Object.assign({},Gt),e),!Ct(this.init.space))throw new TypeError("Equirect layer's space needs to be an XRReferenceSpace");this.radius=this.init.radius,this.centralHorizontalAngle=this.init.centralHorizontalAngle,this.upperVerticalAngle=this.init.upperVerticalAngle,this.lowerVerticalAngle=this.init.lowerVerticalAngle,this.space=this.init.space,this.layout=this.init.layout;const r=Dt();e.transform?this.transform=new r.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new r.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?It.texture:this.init.textureType}_deferredInitialize(){let e=this.determineLayoutAttribute(this.init.textureType,this.context,this.init.layout);this.layout=e,this.needsRedraw=!0}get colorTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._colorTextures}get depthStencilTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._depthStencilTextures&&this._depthStencilTextures.length||this._allocateDepthStencilTexturesInternal(this.getTextureType(),this.init),this._depthStencilTextures}get colorTexturesMeta(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._texturesMeta}}const zt={colorFormat:6408,mipLevels:1,layout:Lt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:It.texture,width:1,height:1},kt={space:null,layout:Lt.mono,invertStereo:!1};class Ht extends Ot{constructor(e,t){super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},kt),e):this.init=Object.assign(Object.assign({},zt),e),this.width=this.init.width,this.height=this.init.height,this.space=this.init.space,this.layout=this.init.layout;const r=Dt();this.init.transform?this.transform=new r.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new r.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?It.texture:this.init.textureType}_deferredInitialize(){let e=this.determineLayoutAttribute(this.init.textureType,this.context,this.init.layout);this.layout=e,this.needsRedraw=!0}get colorTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._colorTextures}get depthStencilTextures(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._depthStencilTextures&&this._depthStencilTextures.length||this._allocateDepthStencilTexturesInternal(this.getTextureType(),this.init),this._depthStencilTextures}get colorTexturesMeta(){if(this.isMediaLayer())throw new Error("Media layers do not have associated textures");return this._colorTextures&&this._colorTextures.length||this._allocateColorTexturesInternal(this.getTextureType(),this.init),this._texturesMeta}}class jt{constructor(e){if(this.session=e,this.session.ended)throw new Error("Session has ended")}createQuadLayer(e,t){if(this.session.ended)throw new Error("Session has ended");if(t.layout===Lt.default)throw new TypeError("Media Quad layer cannot be created with layout of default");let r=this.calculateAspectRatio(e,t.layout);void 0===t.width&&void 0===t.height&&(t.width=1),void 0===t.height&&(t.height=t.width/r),void 0===t.width&&(t.width=t.height/r);let i=new Ht(t,e);return i.needsRedraw=!1,i.initialize(this.session),i}createCylinderLayer(e,t){if(this.session.ended)throw new Error("Session has ended");if(t.layout===Lt.default)throw new TypeError("Media Cylinder layer cannot be created with layout of default");let r=this.calculateAspectRatio(e,t.layout);void 0===t.aspectRatio&&(t.aspectRatio=r);let i=new Ut(t,e);return i.needsRedraw=!1,i.initialize(this.session),i}createEquirectLayer(e,t){if(this.session.ended)throw new Error("Session has ended");if(t.layout===Lt.default)throw new TypeError("Media Equirect layer cannot be created with layout of default");if(!Ct(t.space))throw new Error("Media Equirect layer's space must be of type XRReferenceSpace");let r=new qt(t,e);return r.needsRedraw=!1,r.initialize(this.session),r}calculateAspectRatio(e,t){let r=e.videoWidth,i=e.videoHeight;return t===Lt["stereo-left-right"]&&(r/=2),t===Lt["stereo-top-bottom"]&&(i/=2),r/i}}const Wt={textureType:It.texture,colorFormat:6408,depthFormat:6402,scaleFactor:1};class Yt extends Ot{constructor(e=Wt){super(),this.init=Object.assign(Object.assign({},Wt),e)}initialize(e,t){super.initialize(e,t),this.initializeIfNeeded();let r=e.getBaseLayer();this.textureWidth=r.framebufferWidth*this.init.scaleFactor,this.textureHeight=r.framebufferHeight*this.init.scaleFactor}_allocateProjectionColorTextures(){let e=[],t=[];const r=()=>{e=[];for(let r of t)e.push(r.texture)};let i=this.session,s=i.internalViews;if(!s||0===s.length)return void console.warn("We can't allocate color textures without views");let a=i.getBaseLayer(),n=s.length,o=a.framebufferWidth*this.init.scaleFactor/s.length,h=a.framebufferHeight*this.init.scaleFactor;if(this.layout===Lt.mono||this.layout===Lt.default){if(this.init.textureType===It["texture-array"]){let e=this._createNewColorTexture(o,h,It["texture-array"],this.init.colorFormat,n);t=[e]}else for(let e of s){let e=this._createNewColorTexture(o,h,It.texture,this.init.colorFormat);t.push(e)}return r(),this._colorTexturesMeta=t,void(this._colorTextures=e)}if(this.layout===Lt["stereo-left-right"]){let e=this._createNewColorTexture(o*n,h,this.init.textureType,this.init.colorFormat);t=[e]}else if(this.layout===Lt["stereo-top-bottom"]){let e=this._createNewColorTexture(o,h*n,this.init.textureType,this.init.colorFormat);t=[e]}r(),this._colorTexturesMeta=t,this._colorTextures=e}_allocateProjectionDepthStencilTextures(){let e=this.session,t=e.internalViews;if(!t||0===t.length)return;if(0===this.init.depthFormat)return void(this._depthStencilTextures=[]);if(this.context instanceof WebGLRenderingContext){if(!this.context.getExtension("WEBGL_depth_texture"))return void(this._depthStencilTextures=[])}let r=[],i=[];const s=()=>{r=[];for(let e of i)r.push(e.texture)};this.initializeIfNeeded();let a=e.getBaseLayer(),n=t.length,o=a.framebufferWidth*this.init.scaleFactor/t.length,h=a.framebufferHeight*this.init.scaleFactor;if(this.layout===Lt.mono||this.layout===Lt.default){if(this.init.textureType===It["texture-array"]){let e=this._createNewDepthStencilTexture(o,h,this.init.textureType,this.init.depthFormat,n);i=[e]}else for(let e of t){let e=this._createNewDepthStencilTexture(o,h,this.init.textureType,this.init.depthFormat);i.push(e)}return s(),void(this._depthStencilTextures=r)}if(this.layout===Lt["stereo-left-right"]){let e=this._createNewDepthStencilTexture(o*n,h,this.init.textureType,this.init.depthFormat);i=[e]}else if(this.layout===Lt["stereo-top-bottom"]){let e=this._createNewDepthStencilTexture(o,h*n,this.init.textureType,this.init.depthFormat);i=[e]}s(),this._depthStencilTextures=r}get colorTextures(){return this._colorTextures&&this._colorTextures.length||this._allocateProjectionColorTextures(),this._colorTextures}get depthStencilTextures(){return void 0===this._depthStencilTextures&&this._allocateProjectionDepthStencilTextures(),this._depthStencilTextures||[]}get colorTexturesMeta(){return this._colorTextures&&this._colorTextures.length||this._allocateProjectionColorTextures(),this._colorTexturesMeta}getTextureType(){return this.init.textureType}_deferredInitialize(){this.isStatic=!1,this.ignoreDepthValues=!1,this.fixedFoveation=0;let e=this.determineLayoutAttribute(this.init.textureType,this.context,Lt.default);this.layout=e,this.needsRedraw=!0;let t=this.determineMaximumScaleFactor(),r=Math.min(this.init.scaleFactor,t);this.init.scaleFactor=r}determineMaximumScaleFactor(){let e=this.session.getBaseLayer(this.context),t=e.framebufferWidth,r=e.framebufferHeight;this.layout===Lt["stereo-left-right"]&&(t*=2),this.layout===Lt["stereo-top-bottom"]&&(r*=2);let i=Math.max(t,r);return this.context.getParameter(this.context.MAX_TEXTURE_SIZE)/i}}const Qt=(e,t,r,i,s)=>{let a=0,n=0,o=t.width,h=t.height;r===Lt["stereo-left-right"]?(a=t.width*i/s,o=t.width/s):r===Lt["stereo-top-bottom"]&&(n=t.height*i/s,h=t.height/s),e.x=a,e.y=n,e.width=o,e.height=h},Kt=(e,t,r)=>{var i=e.createShader(r);if(e.shaderSource(i,t),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw"could not compile shader:"+e.getShaderInfoLog(i);return i},$t=(e,t,r)=>{const i=e.createProgram(),s=Kt(e,t,e.VERTEX_SHADER),a=Kt(e,r,e.FRAGMENT_SHADER);if(e.attachShader(i,s),e.attachShader(i,a),e.deleteShader(s),e.deleteShader(a),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw"program failed to link:"+e.getProgramInfoLog(i);return i},Jt=e=>{if(e instanceof WebGL2RenderingContext)return e;const t=e.getExtension("OES_vertex_array_object");if(!t)throw new Error("Cannot use VAOs.");return{VERTEX_ARRAY_BINDING:t.VERTEX_ARRAY_BINDING_OES,bindVertexArray:t.bindVertexArrayOES.bind(t),createVertexArray:t.createVertexArrayOES.bind(t),deleteVertexArray:t.deleteVertexArrayOES.bind(t),isVertexArray:t.isVertexArrayOES.bind(t)}},Zt=e=>e,er=Zt`
|
|
2
43
|
attribute vec2 a_position;
|
|
3
44
|
attribute vec2 a_texCoord;
|
|
4
45
|
|
|
@@ -20,7 +61,7 @@ void main() {
|
|
|
20
61
|
// The GPU will interpolate this value between points.
|
|
21
62
|
v_texCoord = a_texCoord;
|
|
22
63
|
}
|
|
23
|
-
`,
|
|
64
|
+
`,tr=Zt`
|
|
24
65
|
precision mediump float;
|
|
25
66
|
|
|
26
67
|
// our texture
|
|
@@ -33,7 +74,7 @@ void main() {
|
|
|
33
74
|
vec4 tex = texture2D(u_image, v_texCoord);
|
|
34
75
|
gl_FragColor = vec4(tex.rgb, tex.a);
|
|
35
76
|
}
|
|
36
|
-
`;class
|
|
77
|
+
`;class rr{constructor(e,t){this.gl=t,this.layer=e,this.program=$t(this.gl,er,tr),this.programInfo={attribLocations:{a_position:this.gl.getAttribLocation(this.program,"a_position"),a_texCoord:this.gl.getAttribLocation(this.program,"a_texCoord")}},this._createVAOs()}render(e){let t=this.gl,r=e.getBaseLayer();t.viewport(0,0,r.framebufferWidth,r.framebufferHeight);const i=this.layer.getTextureType(),s=t.getParameter(t.TEXTURE_BINDING_2D),a=t.getParameter(t.ACTIVE_TEXTURE);if(i!==It.texture)throw new Error("Created a texture projection renderer instead of a texture-array projection renderer for a texture-array layer.\nThis is probably an error with the polyfill itself; please file an issue on Github if you run into this.");t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.layer.colorTextures[0]),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let i of e.internalViews){let e=r.getViewport(i);t.viewport(e.x,e.y,e.width,e.height),this._shouldUseStereoTexturePoints()?this._renderInternalStereo(i):this._renderInternal()}t.activeTexture(a),t.bindTexture(t.TEXTURE_2D,s)}_renderInternal(){let e=this.gl;const t=e.getParameter(e.CURRENT_PROGRAM);e.useProgram(this.program),this.vaoGl.bindVertexArray(this.vao);var r=e.TRIANGLES;e.drawArrays(r,0,6),this.vaoGl.bindVertexArray(null),e.useProgram(t)}_renderInternalStereo(e){if("none"===e.eye)return this._renderInternal();let t=this.gl;this.vaoGl.bindVertexArray(this.vao);const r=t.getParameter(t.CURRENT_PROGRAM);t.useProgram(this.program),this._setStereoTextureBuffer("right"===e.eye?1:0);var i=t.TRIANGLES;t.drawArrays(i,0,6),this.vaoGl.bindVertexArray(null),t.useProgram(r)}_createVAOs(){this._createTextureUVs();let e=this.gl;this.vaoGl=Jt(e);let t=e.createBuffer();this.vao=this.vaoGl.createVertexArray(),this.vaoGl.bindVertexArray(this.vao),e.enableVertexAttribArray(this.programInfo.attribLocations.a_position),e.bindBuffer(e.ARRAY_BUFFER,t),((e,t,r,i,s)=>{var a=t,n=t+i,o=r,h=r+s;e.bufferData(e.ARRAY_BUFFER,new Float32Array([a,o,n,o,a,h,a,h,n,o,n,h]),e.DYNAMIC_DRAW)})(e,0,0,1,1);let r=e.FLOAT;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,2,r,false,0,0),this.texcoordBuffer=e.createBuffer(),e.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord),e.bindBuffer(e.ARRAY_BUFFER,this.texcoordBuffer),e.bufferData(e.ARRAY_BUFFER,this.texturePoints,e.DYNAMIC_DRAW),e.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,2,r,false,0,0),this.vaoGl.bindVertexArray(null),e.bindBuffer(e.ARRAY_BUFFER,null)}_setStereoTextureBuffer(e){let t=this.gl;t.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord),t.bindBuffer(t.ARRAY_BUFFER,this.texcoordBuffer),t.bufferData(t.ARRAY_BUFFER,this.stereoTexturePoints[e],t.STATIC_DRAW);var r=t.FLOAT;t.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,2,r,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,null)}_createTextureUVs(){this.texturePoints=new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]);const e={x:0,y:0,width:1,height:1};this._shouldUseStereoTexturePoints()&&(this.stereoTexturePoints=[],Qt(e,this.layer.colorTexturesMeta[0],this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e),Qt(e,this.layer.colorTexturesMeta[0],this.layer.layout,1,2),this.stereoTexturePoints[1]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e))}_offsetTextureUVsByRect(e,t,r){const i=(r=null!=r?r:{x:0,y:0,width:e.width,height:e.height}).x/e.width,s=r.y/e.height,a=r.width/e.width,n=r.height/e.height,o=[];for(let e=0;e<t.length;e+=2){let r=t[e]*a+i,h=t[e+1]*n+s;o[e]=r,o[e+1]=h}return new Float32Array(o)}_shouldUseStereoTexturePoints(){return this.layer.layout===Lt["stereo-left-right"]||this.layer.layout===Lt["stereo-top-bottom"]}}const ir=Zt`#version 300 es
|
|
37
78
|
|
|
38
79
|
in vec2 a_position;
|
|
39
80
|
in vec2 a_texCoord;
|
|
@@ -56,7 +97,7 @@ void main() {
|
|
|
56
97
|
// The GPU will interpolate this value between points.
|
|
57
98
|
v_texCoord = a_texCoord;
|
|
58
99
|
}
|
|
59
|
-
`,
|
|
100
|
+
`,sr=Zt`#version 300 es
|
|
60
101
|
precision mediump float;
|
|
61
102
|
precision mediump int;
|
|
62
103
|
precision mediump sampler2DArray;
|
|
@@ -73,7 +114,7 @@ void main() {
|
|
|
73
114
|
fragColor = vec4(tex.rgb, tex.a);
|
|
74
115
|
}
|
|
75
116
|
|
|
76
|
-
`;class
|
|
117
|
+
`;class ar extends rr{constructor(e,t){super(e,t),this.program=$t(this.gl,ir,sr),this._createVAOs(),this.u_layerInfo=this.gl.getUniformLocation(this.program,"u_layer")}render(e){let t=this.gl;if(this.layer.getTextureType()===It.texture)throw new Error("Using texture array projection renderer on a layer without texture array.");let r=e.getBaseLayer();const i=t.getParameter(t.TEXTURE_BINDING_2D_ARRAY);t.bindTexture(t.TEXTURE_2D_ARRAY,this.layer.colorTextures[0]),t.texParameteri(t.TEXTURE_2D_ARRAY,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D_ARRAY,t.TEXTURE_MIN_FILTER,t.LINEAR);for(let i of e.internalViews){let s=e.getViewIndex(i),a=r.getViewport(i);t.viewport(a.x,a.y,a.width,a.height),this._renderInternal(s)}t.bindTexture(t.TEXTURE_2D_ARRAY,i)}_renderInternal(e=0){let t=this.gl;const r=t.getParameter(t.CURRENT_PROGRAM);t.useProgram(this.program),t.bindVertexArray(this.vao),t.uniform1i(this.u_layerInfo,e);var i=t.TRIANGLES;t.drawArrays(i,0,6),t.bindVertexArray(null),t.useProgram(r)}}const nr=(e,t)=>e.getTextureType()===It["texture-array"]&&t instanceof WebGL2RenderingContext?new ar(e,t):new rr(e,t);var or="undefined"!=typeof Float32Array?Float32Array:Array;function hr(){var e=new or(16);return or!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function lr(e,t,r){var i=t[0],s=t[1],a=t[2],n=t[3],o=t[4],h=t[5],l=t[6],u=t[7],c=t[8],d=t[9],p=t[10],f=t[11],x=t[12],m=t[13],g=t[14],y=t[15],v=r[0],T=r[1],w=r[2],S=r[3];return e[0]=v*i+T*o+w*c+S*x,e[1]=v*s+T*h+w*d+S*m,e[2]=v*a+T*l+w*p+S*g,e[3]=v*n+T*u+w*f+S*y,v=r[4],T=r[5],w=r[6],S=r[7],e[4]=v*i+T*o+w*c+S*x,e[5]=v*s+T*h+w*d+S*m,e[6]=v*a+T*l+w*p+S*g,e[7]=v*n+T*u+w*f+S*y,v=r[8],T=r[9],w=r[10],S=r[11],e[8]=v*i+T*o+w*c+S*x,e[9]=v*s+T*h+w*d+S*m,e[10]=v*a+T*l+w*p+S*g,e[11]=v*n+T*u+w*f+S*y,v=r[12],T=r[13],w=r[14],S=r[15],e[12]=v*i+T*o+w*c+S*x,e[13]=v*s+T*h+w*d+S*m,e[14]=v*a+T*l+w*p+S*g,e[15]=v*n+T*u+w*f+S*y,e}function ur(e,t){var r=t[0],i=t[1],s=t[2],a=t[3],n=r+r,o=i+i,h=s+s,l=r*n,u=i*n,c=i*o,d=s*n,p=s*o,f=s*h,x=a*n,m=a*o,g=a*h;return e[0]=1-c-f,e[1]=u+g,e[2]=d-m,e[3]=0,e[4]=u-g,e[5]=1-l-f,e[6]=p+x,e[7]=0,e[8]=d+m,e[9]=p-x,e[10]=1-l-c,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function cr(){var e=new or(2);return or!=Float32Array&&(e[0]=0,e[1]=0),e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)}),function(){var e=cr()}();const dr=e=>e,pr=dr`
|
|
77
118
|
attribute vec4 a_position;
|
|
78
119
|
attribute vec2 a_texCoord;
|
|
79
120
|
|
|
@@ -90,7 +131,7 @@ void main() {
|
|
|
90
131
|
// The GPU will interpolate this value between points.
|
|
91
132
|
v_texCoord = a_texCoord;
|
|
92
133
|
}
|
|
93
|
-
`,
|
|
134
|
+
`,fr=dr`
|
|
94
135
|
precision mediump float;
|
|
95
136
|
|
|
96
137
|
// our texture
|
|
@@ -104,7 +145,7 @@ void main() {
|
|
|
104
145
|
gl_FragColor = vec4(tex.rgb, tex.a);
|
|
105
146
|
// gl_FragColor = vec4(1.0, 0, 0, 1.0);
|
|
106
147
|
}
|
|
107
|
-
`,dr
|
|
148
|
+
`,xr=dr`#version 300 es
|
|
108
149
|
|
|
109
150
|
in vec4 a_position;
|
|
110
151
|
in vec2 a_texCoord;
|
|
@@ -122,7 +163,7 @@ void main() {
|
|
|
122
163
|
// The GPU will interpolate this value between points.
|
|
123
164
|
v_texCoord = a_texCoord;
|
|
124
165
|
}
|
|
125
|
-
`,
|
|
166
|
+
`,mr=dr`#version 300 es
|
|
126
167
|
precision mediump float;
|
|
127
168
|
precision mediump int;
|
|
128
169
|
precision mediump sampler2DArray;
|
|
@@ -139,7 +180,7 @@ void main() {
|
|
|
139
180
|
fragColor = vec4(tex.rgb, tex.a);
|
|
140
181
|
}
|
|
141
182
|
|
|
142
|
-
`;class fr{constructor(e,t){this.usesTextureArrayShaders=!1,this.savedVaoState={vao:null,arrayBuffer:null},this.hasMipmap=!1,this.gl=t,this.layer=e;let i=this.gl;this.transformMatrix=r(),t instanceof WebGL2RenderingContext&&this.layer.getTextureType()===Ct["texture-array"]&&(this.usesTextureArrayShaders=!0),this.usesTextureArrayShaders?this.program=Zt(i,dr,pr):this.program=Zt(i,ur,cr),this.programInfo={attribLocations:{a_position:i.getAttribLocation(this.program,"a_position"),a_texCoord:i.getAttribLocation(this.program,"a_texCoord")},uniformLocations:{u_matrix:i.getUniformLocation(this.program,"u_matrix"),u_projectionMatrix:i.getUniformLocation(this.program,"u_projectionMatrix")}},this.usesTextureArrayShaders&&(this.programInfo.uniformLocations.u_layer=i.getUniformLocation(this.program,"u_layer"))}saveVaoState(){this.savedVaoState.vao=this.gl.getParameter(this.vaoGl.VERTEX_ARRAY_BINDING),this.savedVaoState.arrayBuffer=this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING)}restoreVaoState(){this.vaoGl.bindVertexArray(this.savedVaoState.vao),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.savedVaoState.arrayBuffer),this.savedVaoState.vao=this.savedVaoState.arrayBuffer=null}initialize(){let e=this.gl;if(this.layer.isMediaLayer()){this.mediaTexture=e.createTexture(),this.mediaTexturePolyfill={texture:this.mediaTexture,textureFormat:e.RGBA,width:this.layer.media.videoWidth,height:this.layer.media.videoHeight,type:Ct.texture};const t=e.getParameter(e.TEXTURE_BINDING_2D);e.bindTexture(e.TEXTURE_2D,this.mediaTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,this.layer.media.videoWidth,this.layer.media.videoHeight,0,e.RGBA,e.UNSIGNED_BYTE,null),e.bindTexture(e.TEXTURE_2D,t)}this._createVAOs()}render(e,t){this.saveVaoState();let r=this.gl,i=e.getBaseLayer(),s=t.getViewerPose(e.getReferenceSpace());const a=r.getParameter(r.ACTIVE_TEXTURE);for(let n of s.views){let s=i.getViewport(n);if(r.viewport(s.x,s.y,s.width,s.height),r.activeTexture(r.TEXTURE0),this.usesTextureArrayShaders){if(r instanceof WebGLRenderingContext)throw new Error("This should never happen; texture-arrays only supported on WebGL2.");if(this.layer.isMediaLayer())throw new Error("This should never happen. Media layers should never be created with texture-array");const i=r.getParameter(r.TEXTURE_BINDING_2D_ARRAY);r.bindTexture(r.TEXTURE_2D_ARRAY,this.layer.colorTextures[0]),this.layer.isStatic?(!0===this.layer.needsRedraw&&r.generateMipmap(r.TEXTURE_2D_ARRAY),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,r.texParameteri(r.TEXTURE_2D_ARRAY,r.TEXTURE_MAG_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),r.texParameteri(r.TEXTURE_2D_ARRAY,r.TEXTURE_MIN_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR);let s=0;if(this.layer.layout===Dt.stereo&&"right"===n.eye)s=1;this._shouldUseStereoTexturePoints()?this._renderInternalStereo(e,t,n,s):this._renderInternal(e,t,n,s),r.activeTexture(a),r.bindTexture(r.TEXTURE_2D_ARRAY,i)}else{const i=r.getParameter(r.TEXTURE_BINDING_2D);if(this.layer.isMediaLayer())r.bindTexture(r.TEXTURE_2D,this.mediaTexture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!0),r.texSubImage2D(r.TEXTURE_2D,0,0,0,this.layer.media.videoWidth,this.layer.media.videoHeight,r.RGBA,r.UNSIGNED_BYTE,this.layer.media);else if(this.layer.layout===Dt.stereo)if("right"===n.eye)r.bindTexture(r.TEXTURE_2D,this.layer.colorTextures[1]);else r.bindTexture(r.TEXTURE_2D,this.layer.colorTextures[0]);else r.bindTexture(r.TEXTURE_2D,this.layer.colorTextures[0]);this.layer.isStatic?(!0===this.layer.needsRedraw&&r.generateMipmap(r.TEXTURE_2D),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),this._shouldUseStereoTexturePoints()?this._renderInternalStereo(e,t,n):this._renderInternal(e,t,n),r.activeTexture(a),r.bindTexture(r.TEXTURE_2D,i)}}this.restoreVaoState()}createPositionPoints(){return new Float32Array([])}createTextureUVs(){return new Float32Array([])}_offsetTextureUVsByRect(e,t,r){const i=(r=r??{x:0,y:0,width:e.width,height:e.height}).x/e.width,s=r.y/e.height,a=r.width/e.width,n=r.height/e.height,o=[];for(let e=0;e<t.length;e+=2){let r=t[e]*a+i,h=t[e+1]*n+s;o[e]=r,o[e+1]=h}return new Float32Array(o)}_shouldUseStereoTexturePoints(){return this.layer.layout===Dt["stereo-left-right"]||this.layer.layout===Dt["stereo-top-bottom"]}_setStereoTextureBuffer(e){let t=this.gl;t.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord),t.bindBuffer(t.ARRAY_BUFFER,this.texcoordBuffer),t.bufferData(t.ARRAY_BUFFER,this.stereoTexturePoints[e],t.STATIC_DRAW);var r=t.FLOAT;t.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,2,r,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,null)}_recalculateVertices(){this.positionPoints=this.createPositionPoints(),this.texturePoints=this.createTextureUVs();const e={x:0,y:0,width:1,height:1};if(this._shouldUseStereoTexturePoints()){if(this.stereoTexturePoints=[],this.layer.isMediaLayer())return Kt(e,this.mediaTexturePolyfill,this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.mediaTexturePolyfill,this.texturePoints,e),Kt(e,this.mediaTexturePolyfill,this.layer.layout,1,2),this.stereoTexturePoints[1]=this._offsetTextureUVsByRect(this.mediaTexturePolyfill,this.texturePoints,e),void(this.layer.layout===Dt["stereo-top-bottom"]&&([this.stereoTexturePoints[0],this.stereoTexturePoints[1]]=[this.stereoTexturePoints[1],this.stereoTexturePoints[0]]));Kt(e,this.layer.colorTexturesMeta[0],this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e),Kt(e,this.layer.colorTexturesMeta[0],this.layer.layout,1,2),this.stereoTexturePoints[1]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e),this.layer.layout===Dt["stereo-top-bottom"]&&([this.stereoTexturePoints[0],this.stereoTexturePoints[1]]=[this.stereoTexturePoints[1],this.stereoTexturePoints[0]])}}_createVAOs(){this._recalculateVertices();let e=this.gl;this.vaoGl=er(e),this.saveVaoState();let t=e.createBuffer();this.vao=this.vaoGl.createVertexArray(),this.vaoGl.bindVertexArray(this.vao),e.enableVertexAttribArray(this.programInfo.attribLocations.a_position),e.bindBuffer(e.ARRAY_BUFFER,t);const r=this.positionPoints;e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW);var i=3,s=e.FLOAT,a=!1,n=0,o=0;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,i,s,a,n,o),e.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord),this.texcoordBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.texcoordBuffer),e.bufferData(e.ARRAY_BUFFER,this.texturePoints,e.STATIC_DRAW);i=2,s=e.FLOAT,a=!1,n=0,o=0;e.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,i,s,a,n,o),this.restoreVaoState()}_renderInternal(e,t,r,i){let s=this.gl;const a=s.getParameter(s.CURRENT_PROGRAM);s.useProgram(this.program),this.vaoGl.bindVertexArray(this.vao),this.usesTextureArrayShaders&&s.uniform1i(this.programInfo.uniformLocations.u_layer,i),this._setTransformMatrix(e,t,r),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix,!1,this.transformMatrix),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix,!1,r.projectionMatrix);var n=s.TRIANGLES,o=this.positionPoints.length/3;s.drawArrays(n,0,o),this.vaoGl.bindVertexArray(null),s.useProgram(a)}_renderInternalStereo(e,t,r,i){if("none"===r.eye)return this._renderInternal(e,t,r);let s=this.gl;this.vaoGl.bindVertexArray(this.vao);const a=s.getParameter(s.CURRENT_PROGRAM);s.useProgram(this.program),this._setStereoTextureBuffer("right"===r.eye?1:0),this.usesTextureArrayShaders&&s.uniform1i(this.programInfo.uniformLocations.u_layer,i),this._setTransformMatrix(e,t,r),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix,!1,this.transformMatrix),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix,!1,r.projectionMatrix);var n=s.TRIANGLES,o=this.positionPoints.length/3;s.drawArrays(n,0,o),this.vaoGl.bindVertexArray(null),s.useProgram(a)}_setTransformMatrix(e,t,r){let i=t.getPose(this.layer.space,e.getReferenceSpace());n(this.transformMatrix,i.transform.matrix,this.layer.transform.matrix),n(this.transformMatrix,r.transform.inverse.matrix,this.transformMatrix)}}class xr extends fr{constructor(e,t){super(e,t),this.initialize()}createPositionPoints(){const e=this.layer.width,t=this.layer.height;return new Float32Array([-e,-t,0,e,-t,0,-e,t,0,-e,t,0,e,-t,0,e,t,0])}createTextureUVs(){return new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1])}}class mr extends fr{constructor(e,t){super(e,t),this.segments=16,this.initialize()}createPositionPoints(){const e=[],t=this.layer.centralAngle,r=this.layer.height,i=this.layer.radius,s=t/this.segments,a=Math.PI/2-t/2,n=[],o=D();o[0]=i*Math.cos(a),o[1]=-i*Math.sin(a),n.push(o);for(let e=0;e<this.segments;e++){const t=D();t[0]=i*Math.cos(a+s*(e+1)),t[1]=-i*Math.sin(a+s*(e+1)),n.push(t)}n.reverse();for(let t=0;t<this.segments;t++){const i=n[t],s=n[t+1];e.push(i[0],-r/2,i[1]),e.push(s[0],-r/2,s[1]),e.push(i[0],r/2,i[1]),e.push(i[0],r/2,i[1]),e.push(s[0],-r/2,s[1]),e.push(s[0],r/2,s[1])}return new Float32Array(e)}createTextureUVs(){let e=[];const t=1/this.segments;for(let r=0;r<this.segments;r++){let i=t*r,s=t*(r+1);e.push(i,0),e.push(s,0),e.push(i,1),e.push(i,1),e.push(s,0),e.push(s,1)}return new Float32Array(e)}}class gr extends fr{constructor(e,t){super(e,t),this.segmentsPerAxis=40,this.initialize()}createPositionPoints(){const e=[];let t=this.layer.radius;0===t&&(t=25),t>25&&(t=25);const r=this.layer.centralHorizontalAngle,i=this.layer.upperVerticalAngle+Math.PI/2,s=this.layer.lowerVerticalAngle+Math.PI/2,a=Math.PI/2-r/2,n=a+r,o=s-i,h=n-a,l=[];for(let e=0;e<=this.segmentsPerAxis;e++)for(let r=0;r<=this.segmentsPerAxis;r++){let s=t,a=n-h*(r/this.segmentsPerAxis),u=o*(e/this.segmentsPerAxis)+i;const c=Math.cos(a)*Math.sin(u),d=Math.cos(u),p=-Math.sin(a)*Math.sin(u);l.push([s*c,s*d,s*p])}const u=this.segmentsPerAxis+1;for(let t=0;t<this.segmentsPerAxis;t++)for(let r=0;r<this.segmentsPerAxis;r++)e.push(...l[r*u+t]),e.push(...l[r*u+t+1]),e.push(...l[(r+1)*u+t]),e.push(...l[(r+1)*u+t]),e.push(...l[r*u+t+1]),e.push(...l[(r+1)*u+t+1]);return new Float32Array(e)}createTextureUVs(){const e=[],t=[];for(let e=0;e<=this.segmentsPerAxis;e++)for(let r=0;r<=this.segmentsPerAxis;r++){const i=r/this.segmentsPerAxis,s=e/this.segmentsPerAxis;t.push([i,s])}const r=this.segmentsPerAxis+1;for(let i=0;i<this.segmentsPerAxis;i++)for(let s=0;s<this.segmentsPerAxis;s++)e.push(...t[s*r+i]),e.push(...t[s*r+i+1]),e.push(...t[(s+1)*r+i]),e.push(...t[(s+1)*r+i]),e.push(...t[s*r+i+1]),e.push(...t[(s+1)*r+i+1]);return new Float32Array(e)}}const yr={colorFormat:6408,mipLevels:1,layout:Dt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0};class vr extends Ut{constructor(e=yr){if(super(),!Nt(e.space))throw new TypeError("XRCubeLayer's space needs to be an XRReferenceSpace");switch(this.init={...yr,...e},this.space=this.init.space,this.isStatic=this.init.isStatic,this.init.orientation?this.orientation=DOMPointReadOnly.fromPoint(this.init.orientation):this.orientation=new DOMPointReadOnly,this.init.layout){case Dt.default:case Dt["stereo-left-right"]:case Dt["stereo-top-bottom"]:throw new TypeError("Invalid layout format for XRCubeLayer")}this.layout=this.init.layout,this.needsRedraw=!0}initialize(e,t){super.initialize(e,t),this._allocateColorTexturesInternal(),this._allocateDepthStencilTexturesInternal()}_allocateColorTexturesInternal(){if(this._colorTextures=[],this._texturesMeta=[],this.layout===Dt.mono){const e=this._createCubeColorTexture();return this._texturesMeta.push(e),void this._colorTextures.push(e.texture)}{const e=this._createCubeColorTexture(),t=this._createCubeColorTexture();return this._texturesMeta.push(e,t),void this._colorTextures.push(e.texture,t.texture)}}_allocateDepthStencilTexturesInternal(){if(this._depthStencilTextures=[],this.init.depthFormat){if(this.context instanceof WebGLRenderingContext){if(!this.context.getExtension("WEBGL_depth_texture"))throw new TypeError("Depth textures not supported in the current context")}if(this.layout===Dt.mono){const e=this._createCubeDepthTexture();return void this._depthStencilTextures.push(e.texture)}{const e=this._createCubeDepthTexture(),t=this._createCubeDepthTexture();return void this._depthStencilTextures.push(e.texture,t.texture)}}}_createCubeColorTexture(){let e=this.context.createTexture(),t={width:this.init.viewPixelWidth,height:this.init.viewPixelHeight,layers:1,type:Ct.texture,textureFormat:this.init.colorFormat,texture:e};const r=this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,e);for(let e=0;e<6;e++)this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,t.textureFormat,t.width,t.height,0,t.textureFormat,this.context.UNSIGNED_BYTE,null);return this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,r),t}_createCubeDepthTexture(){let e=this.context.createTexture(),t={width:this.init.viewPixelWidth,height:this.init.viewPixelHeight,layers:1,type:Ct.texture,textureFormat:this.init.depthFormat,texture:e};const r=this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,e);let i=this.init.depthFormat;this.context instanceof WebGL2RenderingContext&&(i===this.context.DEPTH_COMPONENT&&(i=this.context.DEPTH_COMPONENT24),i===this.context.DEPTH_STENCIL&&(i=this.context.DEPTH24_STENCIL8));for(let e=0;e<6;e++)this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,i,t.width,t.height,0,t.textureFormat,this.context.UNSIGNED_INT,null);return this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,r),t}getTextureType(){return Ct.texture}}const Tr=e=>e,wr=Tr`
|
|
183
|
+
`;class gr{constructor(e,t){this.usesTextureArrayShaders=!1,this.savedVaoState={vao:null,arrayBuffer:null},this.hasMipmap=!1,this.gl=t,this.layer=e;let r=this.gl;this.transformMatrix=hr(),t instanceof WebGL2RenderingContext&&this.layer.getTextureType()===It["texture-array"]&&(this.usesTextureArrayShaders=!0),this.usesTextureArrayShaders?this.program=$t(r,xr,mr):this.program=$t(r,pr,fr),this.programInfo={attribLocations:{a_position:r.getAttribLocation(this.program,"a_position"),a_texCoord:r.getAttribLocation(this.program,"a_texCoord")},uniformLocations:{u_matrix:r.getUniformLocation(this.program,"u_matrix"),u_projectionMatrix:r.getUniformLocation(this.program,"u_projectionMatrix")}},this.usesTextureArrayShaders&&(this.programInfo.uniformLocations.u_layer=r.getUniformLocation(this.program,"u_layer"))}saveVaoState(){this.savedVaoState.vao=this.gl.getParameter(this.vaoGl.VERTEX_ARRAY_BINDING),this.savedVaoState.arrayBuffer=this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING)}restoreVaoState(){this.vaoGl.bindVertexArray(this.savedVaoState.vao),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.savedVaoState.arrayBuffer),this.savedVaoState.vao=this.savedVaoState.arrayBuffer=null}initialize(){let e=this.gl;if(this.layer.isMediaLayer()){this.mediaTexture=e.createTexture(),this.mediaTexturePolyfill={texture:this.mediaTexture,textureFormat:e.RGBA,width:this.layer.media.videoWidth,height:this.layer.media.videoHeight,type:It.texture};const t=e.getParameter(e.TEXTURE_BINDING_2D);e.bindTexture(e.TEXTURE_2D,this.mediaTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,this.layer.media.videoWidth,this.layer.media.videoHeight,0,e.RGBA,e.UNSIGNED_BYTE,null),e.bindTexture(e.TEXTURE_2D,t)}this._createVAOs()}render(e,t){this.saveVaoState();let r=this.gl,i=e.getBaseLayer(),s=t.getViewerPose(e.getReferenceSpace());const a=r.getParameter(r.ACTIVE_TEXTURE);for(let n of s.views){let s=i.getViewport(n);if(r.viewport(s.x,s.y,s.width,s.height),r.activeTexture(r.TEXTURE0),this.usesTextureArrayShaders){if(r instanceof WebGLRenderingContext)throw new Error("This should never happen; texture-arrays only supported on WebGL2.");if(this.layer.isMediaLayer())throw new Error("This should never happen. Media layers should never be created with texture-array");const i=r.getParameter(r.TEXTURE_BINDING_2D_ARRAY);r.bindTexture(r.TEXTURE_2D_ARRAY,this.layer.colorTextures[0]),this.layer.isStatic?(!0===this.layer.needsRedraw&&r.generateMipmap(r.TEXTURE_2D_ARRAY),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,r.texParameteri(r.TEXTURE_2D_ARRAY,r.TEXTURE_MAG_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),r.texParameteri(r.TEXTURE_2D_ARRAY,r.TEXTURE_MIN_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR);let s=0;if(this.layer.layout===Lt.stereo&&"right"===n.eye)s=1;this._shouldUseStereoTexturePoints()?this._renderInternalStereo(e,t,n,s):this._renderInternal(e,t,n,s),r.activeTexture(a),r.bindTexture(r.TEXTURE_2D_ARRAY,i)}else{const i=r.getParameter(r.TEXTURE_BINDING_2D);if(this.layer.isMediaLayer())r.bindTexture(r.TEXTURE_2D,this.mediaTexture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!0),r.texSubImage2D(r.TEXTURE_2D,0,0,0,this.layer.media.videoWidth,this.layer.media.videoHeight,r.RGBA,r.UNSIGNED_BYTE,this.layer.media);else if(this.layer.layout===Lt.stereo)if("right"===n.eye)r.bindTexture(r.TEXTURE_2D,this.layer.colorTextures[1]);else r.bindTexture(r.TEXTURE_2D,this.layer.colorTextures[0]);else r.bindTexture(r.TEXTURE_2D,this.layer.colorTextures[0]);this.layer.isStatic?(!0===this.layer.needsRedraw&&r.generateMipmap(r.TEXTURE_2D),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),this._shouldUseStereoTexturePoints()?this._renderInternalStereo(e,t,n):this._renderInternal(e,t,n),r.activeTexture(a),r.bindTexture(r.TEXTURE_2D,i)}}this.restoreVaoState()}createPositionPoints(){return new Float32Array([])}createTextureUVs(){return new Float32Array([])}_offsetTextureUVsByRect(e,t,r){const i=(r=null!=r?r:{x:0,y:0,width:e.width,height:e.height}).x/e.width,s=r.y/e.height,a=r.width/e.width,n=r.height/e.height,o=[];for(let e=0;e<t.length;e+=2){let r=t[e]*a+i,h=t[e+1]*n+s;o[e]=r,o[e+1]=h}return new Float32Array(o)}_shouldUseStereoTexturePoints(){return this.layer.layout===Lt["stereo-left-right"]||this.layer.layout===Lt["stereo-top-bottom"]}_setStereoTextureBuffer(e){let t=this.gl;t.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord),t.bindBuffer(t.ARRAY_BUFFER,this.texcoordBuffer),t.bufferData(t.ARRAY_BUFFER,this.stereoTexturePoints[e],t.STATIC_DRAW);var r=t.FLOAT;t.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,2,r,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,null)}_recalculateVertices(){this.positionPoints=this.createPositionPoints(),this.texturePoints=this.createTextureUVs();const e={x:0,y:0,width:1,height:1};if(this._shouldUseStereoTexturePoints()){if(this.stereoTexturePoints=[],this.layer.isMediaLayer())return Qt(e,this.mediaTexturePolyfill,this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.mediaTexturePolyfill,this.texturePoints,e),Qt(e,this.mediaTexturePolyfill,this.layer.layout,1,2),this.stereoTexturePoints[1]=this._offsetTextureUVsByRect(this.mediaTexturePolyfill,this.texturePoints,e),void(this.layer.layout===Lt["stereo-top-bottom"]&&([this.stereoTexturePoints[0],this.stereoTexturePoints[1]]=[this.stereoTexturePoints[1],this.stereoTexturePoints[0]]));Qt(e,this.layer.colorTexturesMeta[0],this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e),Qt(e,this.layer.colorTexturesMeta[0],this.layer.layout,1,2),this.stereoTexturePoints[1]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e),this.layer.layout===Lt["stereo-top-bottom"]&&([this.stereoTexturePoints[0],this.stereoTexturePoints[1]]=[this.stereoTexturePoints[1],this.stereoTexturePoints[0]])}}_createVAOs(){this._recalculateVertices();let e=this.gl;this.vaoGl=Jt(e),this.saveVaoState();let t=e.createBuffer();this.vao=this.vaoGl.createVertexArray(),this.vaoGl.bindVertexArray(this.vao),e.enableVertexAttribArray(this.programInfo.attribLocations.a_position),e.bindBuffer(e.ARRAY_BUFFER,t);const r=this.positionPoints;e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW);var i=3,s=e.FLOAT,a=!1,n=0,o=0;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,i,s,a,n,o),e.enableVertexAttribArray(this.programInfo.attribLocations.a_texCoord),this.texcoordBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.texcoordBuffer),e.bufferData(e.ARRAY_BUFFER,this.texturePoints,e.STATIC_DRAW);i=2,s=e.FLOAT,a=!1,n=0,o=0;e.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,i,s,a,n,o),this.restoreVaoState()}_renderInternal(e,t,r,i){let s=this.gl;const a=s.getParameter(s.CURRENT_PROGRAM);s.useProgram(this.program),this.vaoGl.bindVertexArray(this.vao),this.usesTextureArrayShaders&&s.uniform1i(this.programInfo.uniformLocations.u_layer,i),this._setTransformMatrix(e,t,r),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix,!1,this.transformMatrix),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix,!1,r.projectionMatrix);var n=s.TRIANGLES,o=this.positionPoints.length/3;s.drawArrays(n,0,o),this.vaoGl.bindVertexArray(null),s.useProgram(a)}_renderInternalStereo(e,t,r,i){if("none"===r.eye)return this._renderInternal(e,t,r);let s=this.gl;this.vaoGl.bindVertexArray(this.vao);const a=s.getParameter(s.CURRENT_PROGRAM);s.useProgram(this.program),this._setStereoTextureBuffer("right"===r.eye?1:0),this.usesTextureArrayShaders&&s.uniform1i(this.programInfo.uniformLocations.u_layer,i),this._setTransformMatrix(e,t,r),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix,!1,this.transformMatrix),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix,!1,r.projectionMatrix);var n=s.TRIANGLES,o=this.positionPoints.length/3;s.drawArrays(n,0,o),this.vaoGl.bindVertexArray(null),s.useProgram(a)}_setTransformMatrix(e,t,r){let i=t.getPose(this.layer.space,e.getReferenceSpace());lr(this.transformMatrix,i.transform.matrix,this.layer.transform.matrix),lr(this.transformMatrix,r.transform.inverse.matrix,this.transformMatrix)}}class yr extends gr{constructor(e,t){super(e,t),this.initialize()}createPositionPoints(){const e=this.layer.width,t=this.layer.height;return new Float32Array([-e,-t,0,e,-t,0,-e,t,0,-e,t,0,e,-t,0,e,t,0])}createTextureUVs(){return new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1])}}class vr extends gr{constructor(e,t){super(e,t),this.segments=16,this.initialize()}createPositionPoints(){const e=[],t=this.layer.centralAngle,r=this.layer.height,i=this.layer.radius,s=t/this.segments,a=Math.PI/2-t/2,n=[],o=cr();o[0]=i*Math.cos(a),o[1]=-i*Math.sin(a),n.push(o);for(let e=0;e<this.segments;e++){const t=cr();t[0]=i*Math.cos(a+s*(e+1)),t[1]=-i*Math.sin(a+s*(e+1)),n.push(t)}n.reverse();for(let t=0;t<this.segments;t++){const i=n[t],s=n[t+1];e.push(i[0],-r/2,i[1]),e.push(s[0],-r/2,s[1]),e.push(i[0],r/2,i[1]),e.push(i[0],r/2,i[1]),e.push(s[0],-r/2,s[1]),e.push(s[0],r/2,s[1])}return new Float32Array(e)}createTextureUVs(){let e=[];const t=1/this.segments;for(let r=0;r<this.segments;r++){let i=t*r,s=t*(r+1);e.push(i,0),e.push(s,0),e.push(i,1),e.push(i,1),e.push(s,0),e.push(s,1)}return new Float32Array(e)}}class Tr extends gr{constructor(e,t){super(e,t),this.segmentsPerAxis=40,this.initialize()}createPositionPoints(){const e=[];let t=this.layer.radius;0===t&&(t=25),t>25&&(t=25);const r=this.layer.centralHorizontalAngle,i=this.layer.upperVerticalAngle+Math.PI/2,s=this.layer.lowerVerticalAngle+Math.PI/2,a=Math.PI/2-r/2,n=a+r,o=s-i,h=n-a,l=[];for(let e=0;e<=this.segmentsPerAxis;e++)for(let r=0;r<=this.segmentsPerAxis;r++){let s=t,a=n-h*(r/this.segmentsPerAxis),u=o*(e/this.segmentsPerAxis)+i;const c=Math.cos(a)*Math.sin(u),d=Math.cos(u),p=-Math.sin(a)*Math.sin(u);l.push([s*c,s*d,s*p])}const u=this.segmentsPerAxis+1;for(let t=0;t<this.segmentsPerAxis;t++)for(let r=0;r<this.segmentsPerAxis;r++)e.push(...l[r*u+t]),e.push(...l[r*u+t+1]),e.push(...l[(r+1)*u+t]),e.push(...l[(r+1)*u+t]),e.push(...l[r*u+t+1]),e.push(...l[(r+1)*u+t+1]);return new Float32Array(e)}createTextureUVs(){const e=[],t=[];for(let e=0;e<=this.segmentsPerAxis;e++)for(let r=0;r<=this.segmentsPerAxis;r++){const i=r/this.segmentsPerAxis,s=e/this.segmentsPerAxis;t.push([i,s])}const r=this.segmentsPerAxis+1;for(let i=0;i<this.segmentsPerAxis;i++)for(let s=0;s<this.segmentsPerAxis;s++)e.push(...t[s*r+i]),e.push(...t[s*r+i+1]),e.push(...t[(s+1)*r+i]),e.push(...t[(s+1)*r+i]),e.push(...t[s*r+i+1]),e.push(...t[(s+1)*r+i+1]);return new Float32Array(e)}}const wr={colorFormat:6408,mipLevels:1,layout:Lt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0};class Sr extends Ot{constructor(e=wr){if(super(),!Ct(e.space))throw new TypeError("XRCubeLayer's space needs to be an XRReferenceSpace");switch(this.init=Object.assign(Object.assign({},wr),e),this.space=this.init.space,this.isStatic=this.init.isStatic,this.init.orientation?this.orientation=DOMPointReadOnly.fromPoint(this.init.orientation):this.orientation=new DOMPointReadOnly,this.init.layout){case Lt.default:case Lt["stereo-left-right"]:case Lt["stereo-top-bottom"]:throw new TypeError("Invalid layout format for XRCubeLayer")}this.layout=this.init.layout,this.needsRedraw=!0}initialize(e,t){super.initialize(e,t),this._allocateColorTexturesInternal(),this._allocateDepthStencilTexturesInternal()}_allocateColorTexturesInternal(){if(this._colorTextures=[],this._texturesMeta=[],this.layout===Lt.mono){const e=this._createCubeColorTexture();return this._texturesMeta.push(e),void this._colorTextures.push(e.texture)}{const e=this._createCubeColorTexture(),t=this._createCubeColorTexture();return this._texturesMeta.push(e,t),void this._colorTextures.push(e.texture,t.texture)}}_allocateDepthStencilTexturesInternal(){if(this._depthStencilTextures=[],this.init.depthFormat){if(this.context instanceof WebGLRenderingContext){if(!this.context.getExtension("WEBGL_depth_texture"))throw new TypeError("Depth textures not supported in the current context")}if(this.layout!==Lt.mono){const e=this._createCubeDepthTexture(),t=this._createCubeDepthTexture();return void this._depthStencilTextures.push(e.texture,t.texture)}{const e=this._createCubeDepthTexture();this._depthStencilTextures.push(e.texture)}}}_createCubeColorTexture(){let e=this.context.createTexture(),t={width:this.init.viewPixelWidth,height:this.init.viewPixelHeight,layers:1,type:It.texture,textureFormat:this.init.colorFormat,texture:e};const r=this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,e);for(let e=0;e<6;e++)this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,t.textureFormat,t.width,t.height,0,t.textureFormat,this.context.UNSIGNED_BYTE,null);return this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,r),t}_createCubeDepthTexture(){let e=this.context.createTexture(),t={width:this.init.viewPixelWidth,height:this.init.viewPixelHeight,layers:1,type:It.texture,textureFormat:this.init.depthFormat,texture:e};const r=this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,e);let i=this.init.depthFormat;this.context instanceof WebGL2RenderingContext&&(i===this.context.DEPTH_COMPONENT&&(i=this.context.DEPTH_COMPONENT24),i===this.context.DEPTH_STENCIL&&(i=this.context.DEPTH24_STENCIL8));for(let e=0;e<6;e++)this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,i,t.width,t.height,0,t.textureFormat,this.context.UNSIGNED_INT,null);return this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,r),t}getTextureType(){return It.texture}}const Er=e=>e,Rr=Er`
|
|
143
184
|
attribute vec4 a_position;
|
|
144
185
|
uniform mat4 u_projectionMatrix;
|
|
145
186
|
uniform mat4 u_matrix;
|
|
@@ -150,7 +191,7 @@ void main() {
|
|
|
150
191
|
|
|
151
192
|
v_normal = normalize(a_position.xyz);
|
|
152
193
|
}
|
|
153
|
-
`,Er
|
|
194
|
+
`,_r=Er`
|
|
154
195
|
precision mediump float;
|
|
155
196
|
|
|
156
197
|
varying vec3 v_normal;
|
|
@@ -160,4 +201,4 @@ uniform samplerCube u_texture;
|
|
|
160
201
|
void main() {
|
|
161
202
|
gl_FragColor = textureCube(u_texture, normalize(v_normal));
|
|
162
203
|
}
|
|
163
|
-
`;class Rr{constructor(e,t){this.savedVaoState={vao:null,arrayBuffer:null},this.hasMipmap=!1,this.layer=e,this.gl=t,this.transformMatrix=r(),this.program=Zt(t,wr,Er),this.programInfo={attribLocations:{a_position:t.getAttribLocation(this.program,"a_position")},uniformLocations:{u_matrix:t.getUniformLocation(this.program,"u_matrix"),u_texture:t.getUniformLocation(this.program,"u_texture"),u_projectionMatrix:t.getUniformLocation(this.program,"u_projectionMatrix")}},this._createVAOs()}saveVaoState(){this.savedVaoState.vao=this.gl.getParameter(this.vaoGl.VERTEX_ARRAY_BINDING),this.savedVaoState.arrayBuffer=this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING)}restoreVaoState(){this.vaoGl.bindVertexArray(this.savedVaoState.vao),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.savedVaoState.arrayBuffer),this.savedVaoState.vao=this.savedVaoState.arrayBuffer=null}render(e,t){this.saveVaoState();let r=this.gl,i=e.getBaseLayer(),s=t.getViewerPose(e.getReferenceSpace());const a=r.getParameter(r.ACTIVE_TEXTURE);for(let e of s.views){let t=i.getViewport(e);r.viewport(t.x,t.y,t.width,t.height),r.activeTexture(r.TEXTURE0);const s=r.getParameter(r.TEXTURE_BINDING_CUBE_MAP);if(this.layer.layout===Dt.stereo){const t="right"===e.eye?1:0;r.bindTexture(r.TEXTURE_CUBE_MAP,this.layer.colorTextures[t])}else r.bindTexture(r.TEXTURE_CUBE_MAP,this.layer.colorTextures[0]);this.layer.isStatic?(!0===this.layer.needsRedraw&&r.generateMipmap(r.TEXTURE_CUBE_MAP),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_MAG_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_MIN_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),this._renderInternal(this.layer.orientation,e),r.activeTexture(a),r.bindTexture(r.TEXTURE_CUBE_MAP,s)}this.restoreVaoState()}createPositionPoints(){const e=.5;return new Float32Array([-e,-e,-e,-e,e,-e,e,-e,-e,-e,e,-e,e,e,-e,e,-e,-e,-e,-e,e,e,-e,e,-e,e,e,-e,e,e,e,-e,e,e,e,e,-e,e,-e,-e,e,e,e,e,-e,-e,e,e,e,e,e,e,e,-e,-e,-e,-e,e,-e,-e,-e,-e,e,-e,-e,e,e,-e,-e,e,-e,e,-e,-e,-e,-e,-e,e,-e,e,-e,-e,-e,e,-e,e,e,-e,e,-e,e,-e,-e,e,e,-e,e,-e,e,e,-e,e,e,e,-e,e,e,e])}_renderInternal(e,t){let i=this.gl;const s=i.getParameter(i.CURRENT_PROGRAM);i.useProgram(this.program),this.vaoGl.bindVertexArray(this.vao),p(this.transformMatrix,[e.x,e.y,e.z,e.w]),this._poseOrientationMatrix||(this._poseOrientationMatrix=r()),p(this._poseOrientationMatrix,[t.transform.inverse.orientation.x,t.transform.inverse.orientation.y,t.transform.inverse.orientation.z,t.transform.inverse.orientation.w]),n(this.transformMatrix,this.transformMatrix,this._poseOrientationMatrix),i.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix,!1,this.transformMatrix),i.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix,!1,t.projectionMatrix),i.uniform1i(this.programInfo.uniformLocations.u_texture,0);var a=i.TRIANGLES,o=this.positionPoints.length/3;i.drawArrays(a,0,o),this.vaoGl.bindVertexArray(null),i.useProgram(s)}_recalculateVertices(){this.positionPoints=this.createPositionPoints()}_createVAOs(){this._recalculateVertices();let e=this.gl;this.vaoGl=er(e),this.saveVaoState();let t=e.createBuffer();this.vao=this.vaoGl.createVertexArray(),this.vaoGl.bindVertexArray(this.vao),e.enableVertexAttribArray(this.programInfo.attribLocations.a_position),e.bindBuffer(e.ARRAY_BUFFER,t);const r=this.positionPoints;e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW);var i=e.FLOAT;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,3,i,!1,0,0),this.restoreVaoState()}}class Sr{constructor(){this.mode="inline",this.layers=[],this.views=[],this.initializedViews=!1,this.isPolyfillActive=!1,this.taskQueue=[]}requestAnimationFrame(e){this.injectedFrameCallback||(this.injectedFrameCallback=(t,r)=>{let i=this.context;if(!this.initializedViews&&this.referenceSpace){let e=r.getViewerPose(this.referenceSpace);e&&(this.views=e.views,this.initializedViews=!0)}if(this.isPolyfillActive&&this.initializedViews){this.tempFramebuffer||(this.tempFramebuffer=i.createFramebuffer()),i.bindFramebuffer(i.FRAMEBUFFER,this.tempFramebuffer);const e=i.getParameter(i.COLOR_CLEAR_VALUE),t=i.getParameter(i.FRAMEBUFFER_BINDING);i.clearColor(0,0,0,0);for(let e of this.layers)if(e instanceof $t&&e.colorTextures&&e.colorTexturesMeta&&0!==e.colorTextures.length)for(let t=0;t<e.colorTextures.length;t++){let r=e.colorTexturesMeta[t].type,s=e.colorTexturesMeta[t];r===Ct["texture-array"]||(s._autoAntialiasing&&s._msaaFramebuffer?(i.bindFramebuffer(i.FRAMEBUFFER,s._msaaFramebuffer),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT)):(i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e.colorTextures[t],0),e.depthStencilTextures&&t<e.depthStencilTextures.length?i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,e.depthStencilTextures[t],0):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,null,0),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT)))}i.bindFramebuffer(i.FRAMEBUFFER,t),i.clearColor(e[0],e[1],e[2],e[3])}if(e(t,r),this.isPolyfillActive&&this.initializedViews&&this._autoResolveMSAAFramebuffers(),this.isPolyfillActive&&this.initializedViews){let e=i.isEnabled(i.BLEND),t=i.isEnabled(i.DEPTH_TEST),s=i.isEnabled(i.CULL_FACE);const a=i.getParameter(i.FRAMEBUFFER_BINDING),n=i.getParameter(i.COLOR_CLEAR_VALUE);i.bindFramebuffer(i.FRAMEBUFFER,this.getBaseLayer().framebuffer),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.clearColor(n[0],n[1],n[2],n[3]),i.enable(i.BLEND),i.disable(i.DEPTH_TEST),i.disable(i.CULL_FACE);let o=i.getParameter(i.BLEND_SRC_RGB),h=i.getParameter(i.BLEND_SRC_ALPHA),l=i.getParameter(i.BLEND_DST_RGB),u=i.getParameter(i.BLEND_DST_ALPHA);i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA);for(let e of this.layers)if(this.renderers||(this.renderers=new WeakMap),e instanceof $t){this.renderers.has(e)||this.renderers.set(e,hr(e,this.context));this.renderers.get(e).render(this)}else if(e instanceof jt){this.renderers.has(e)||this.renderers.set(e,new xr(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof Xt){this.renderers.has(e)||this.renderers.set(e,new mr(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof Ht){this.renderers.has(e)||this.renderers.set(e,new gr(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof vr){this.renderers.has(e)||this.renderers.set(e,new Rr(e,this.context));this.renderers.get(e).render(this,r)}else{const t=e;if(null===t.framebuffer)continue;i instanceof WebGL2RenderingContext?(i.bindFramebuffer(i.READ_FRAMEBUFFER,t.framebuffer),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,this.getBaseLayer().framebuffer),i.blitFramebuffer(0,0,t.framebufferWidth,t.framebufferHeight,0,0,this.getBaseLayer().framebufferWidth,this.getBaseLayer().framebufferHeight,i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT,i.LINEAR)):console.warn("GL blitFramebuffer is not supported on WebGL1, so XRWebGLLayers may not show up properly when polyfilled.")}for(e||i.disable(i.BLEND),t&&i.enable(i.DEPTH_TEST),s&&i.enable(i.CULL_FACE),i.blendFuncSeparate(o,l,h,u),i.bindFramebuffer(i.FRAMEBUFFER,a);this.taskQueue.length>0;){this.taskQueue.shift()()}}}),this._requestAnimationFrame(this.injectedFrameCallback)}updateRenderState(e){if(this.existingBaseLayer=e.baseLayer,e.layers&&(this.layers=e.layers),this.activeRenderState||this.createActiveRenderState(),this.activeRenderState={...this.activeRenderState,...e},!e.layers)return void this._updateRenderState(e);let t,r=Object.assign({},e);delete r.layers;for(let i of this.layers)if(i instanceof Ut){t=i.getContext();break}if(!t&&!this.context){console.log("No existing context! Have the session make one");const s=document.createElement("canvas");if(t=s.getContext("webgl2",{xrCompatible:!0}),t||(t=s.getContext("webgl",{xrCompatible:!0})),!t)throw new Error("No webGL support detected.");function a(){t.canvas.width=t.canvas.clientWidth*window.devicePixelRatio,t.canvas.height=t.canvas.clientHeight*window.devicePixelRatio}document.body.appendChild(t.canvas),window.addEventListener("resize",a),a()}this.createInternalLayer(t),this.isPolyfillActive=!0,this._updateRenderState({...r,baseLayer:this.internalLayer})}initializeSession(e){this.mode=e,this.requestReferenceSpace("local").then(e=>{this.referenceSpace=e}).catch(e=>{}),this.requestReferenceSpace("viewer").then(e=>{this.viewerSpace=e})}getBaseLayer(e){return this.internalLayer||this.existingBaseLayer||!e||this.createInternalLayer(e),this.internalLayer||this.existingBaseLayer}getReferenceSpace(){return this.referenceSpace?this.referenceSpace:this.viewerSpace}getViewerSpace(){return this.viewerSpace}queueTask(e){this.taskQueue.push(e)}get renderState(){return this.activeRenderState||this.createActiveRenderState(),this.activeRenderState}get internalViews(){return this.views}getViewIndex(e){for(let t=0;t<this.views.length;t++){let r=this.views[t];if(e.eye===r.eye&&e.recommendedViewportScale===r.recommendedViewportScale)return t}return-1}createInternalLayer(e){if(!e&&this.internalLayer)return this.internalLayer;if(e===this.context&&this.internalLayer)return this.internalLayer;const t=Bt();return this.internalLayer=new t.XRWebGLLayer(this,e),this.setContext(e),this.internalLayer}setContext(e){this.context=e,this.tempFramebuffer=e.createFramebuffer(),this.renderers=new WeakMap}createActiveRenderState(){const e=Bt();let t=Object.getOwnPropertyNames(e.XRRenderState.prototype);const r={};for(let e of t)r[e]=this._renderState[e];r.layers=[],this.activeRenderState=r}_autoResolveMSAAFramebuffers(){const e=this.context;if(e&&e instanceof WebGL2RenderingContext){for(let t of this.layers)if(t instanceof Ut&&t.colorTexturesMeta)for(let r of t.colorTexturesMeta)if(r._autoAntialiasing&&r._msaaFramebuffer&&r._resolveFramebuffer)try{e.bindFramebuffer(e.READ_FRAMEBUFFER,r._msaaFramebuffer),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,r._resolveFramebuffer),e.blitFramebuffer(0,0,r.width,r.height,0,0,r.width,r.height,e.COLOR_BUFFER_BIT,e.NEAREST)}catch(e){console.warn("Failed to resolve MSAA framebuffer:",e)}e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null)}}}class _r{constructor(){this.viewport={x:0,y:0,width:0,height:0}}}class br{constructor(e,t){this.session=e,this.context=t,this.subImageCache=new Mr}createProjectionLayer(e=Qt){const t=new $t(e);if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");return t.initialize(this.session,this.context),t}createQuadLayer(e=kt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===Dt.default)throw new TypeError("Trying to create a quad layer with default layout");const t=new jt(e);return t.initialize(this.session,this.context),t}createCylinderLayer(e=Vt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===Dt.default)throw new TypeError("Cylinder Layer cannot have a default layout");const t=new Xt(e);return t.initialize(this.session,this.context),t}createEquirectLayer(e=qt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===Dt.default)throw new TypeError("Equirect Layer cannot have a default layout");if(!Nt(e.space))throw new TypeError("Equirect layer requires an XRReferenceSpace");let t=new Ht(e);return t.initialize(this.session,this.context),t}createCubeLayer(e){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(!(this.context instanceof WebGL2RenderingContext))throw new Error("XRCubeLayer only work on WebGL2");if(!Nt(e.space))throw new TypeError("XRCubeLayer requires a space of type XRReferenceSpace");let t=new vr(e);return t.initialize(this.session,this.context),t}getSubImage(e,t,r="none"){if(e.isStatic&&!1===e.needsRedraw)throw new Error("Invalid state for subimage creation");let i=this.subImageCache.tryGetCachedSubImage(this.context,e,r);if(i)return i;let s=new _r;if(e instanceof $t)throw new TypeError;if(e.layout===Dt.default)throw new TypeError;if(!this.validateStateofSubImageCreation(e,t))throw new Error("Invalid state for subimage creation");let a=0;if(e.layout===Dt.stereo){if("none"===r)throw new TypeError;"right"===r&&(a=1)}e.getTextureType()===Ct["texture-array"]?s.imageIndex=a:s.imageIndex=0;let n=0;e.getTextureType()===Ct.texture?(s.colorTexture=e.colorTextures[a],n=a):(s.colorTexture=e.colorTextures[0],n=0),s.colorTexture&&"object"==typeof s.colorTexture&&(s.colorTexture.isWebGLMultiviewRenderTarget=e.getTextureType()===Ct["texture-array"]),e.depthStencilTextures&&e.depthStencilTextures.length?e.getTextureType()===Ct.texture?s.depthStencilTexture=e.depthStencilTextures[a]:s.depthStencilTexture=e.depthStencilTextures[0]:s.depthStencilTexture=null,s.depthStencilTexture&&"object"==typeof s.depthStencilTexture&&(s.depthStencilTexture.isWebGLMultiviewRenderTarget=e.getTextureType()===Ct["texture-array"]);const o=e.colorTexturesMeta[n];s.textureWidth=o.width,s.textureHeight=o.height;let h=1;return e.layout!==Dt["stereo-left-right"]&&e.layout!==Dt["stereo-top-bottom"]||(h=2),Kt(s.viewport,o,e.layout,a,h),this.session.queueTask(()=>{e.needsRedraw=!1}),this.subImageCache.cacheSubImage(s,this.context,e,r),s}getViewSubImage(e,t){let r=this.subImageCache.tryGetCachedViewSubImage(this.context,e,t);if(r)return r;let i=new _r,s=this.session;if(!s.internalViews||!s.internalViews.length){console.warn("getViewSubImage called before views are available, returning placeholder"),i.imageIndex=0;const e={isWebGLMultiviewRenderTarget:!1},t={isWebGLMultiviewRenderTarget:!1};return i.colorTexture=e,i.depthStencilTexture=t,i.textureWidth=1024,i.textureHeight=1024,i.viewport={x:0,y:0,width:1024,height:1024},i}let a=s.getViewIndex(t),n=0;e.getTextureType()===Ct["texture-array"]?i.imageIndex=a:i.imageIndex=0,e.layout===Dt.default&&e.getTextureType()===Ct.texture?(i.colorTexture=e.colorTextures[a],n=a):(i.colorTexture=e.colorTextures[0],n=0);const o=e.colorTexturesMeta[n];return o._autoAntialiasing&&o._msaaFramebuffer&&(i.framebuffer=o._msaaFramebuffer,i._needsResolve=!0,i._resolveFromFramebuffer=o._msaaFramebuffer,i._resolveToFramebuffer=o._resolveFramebuffer,i._textureMeta=o),i.colorTexture&&"object"==typeof i.colorTexture&&(i.colorTexture.isWebGLMultiviewRenderTarget=e.getTextureType()===Ct["texture-array"]),0===e.depthStencilTextures.length?i.depthStencilTexture=null:e.layout===Dt.default&&e.getTextureType()===Ct.texture?i.depthStencilTexture=e.depthStencilTextures[a]:i.depthStencilTexture=e.depthStencilTextures[0],i.depthStencilTexture&&"object"==typeof i.depthStencilTexture&&(i.depthStencilTexture.isWebGLMultiviewRenderTarget=e.getTextureType()===Ct["texture-array"]),i.textureWidth=e.colorTexturesMeta[n].width,i.textureHeight=e.colorTexturesMeta[n].height,Kt(i.viewport,e.colorTexturesMeta[n],e.layout,a,s.internalViews.length),e.needsRedraw=!1,this.subImageCache.cacheViewSubImage(i,this.context,e,t),i}validateStateofSubImageCreation(e,t){return t.session===e.session&&(this.session===e.session&&(this.context===e.context&&(!(!e.colorTextures||!e.colorTextures.length)&&(!e.isStatic||!1!==e.needsRedraw))))}}class Mr{constructor(){this.cache=new Map,this.viewCache=new Map}cacheSubImage(e,t,r,i){let s=new Map;s.set(i,e);let a=new Map;a.set(r,s),this.cache.set(t,a)}tryGetCachedSubImage(e,t,r){return this.cache.get(e)?.get(t)?.get(r)}cacheViewSubImage(e,t,r,i){let s=new Map;s.set(i,e);let a=new Map;a.set(r,s),this.viewCache.set(t,a)}tryGetCachedViewSubImage(e,t,r){return this.viewCache.get(e)?.get(t)?.get(r)}}let Ar=class{constructor(){this.injected=!1;const e=Bt();this._injectPolyfill(e)}_injectPolyfill(e){if(!("xr"in e.navigator))throw new Error("WebXR Layers polyfill requires WebXR support.");!0===this.injected&&console.warn("Polyfill has already been injected..."),(e=>!!e.navigator.xr&&!(!e.XRMediaBinding||!e.XRWebGLBinding))(e)||(this._polyfillRequiredLayersFeature(e),this._polyfillXRSession(e),e.XRWebGLBinding=br,e.XRMediaBinding=Yt,this.injected=!0,console.log("Injected Layers Polyfill"))}_polyfillXRSession(e){e.XRSession.prototype._updateRenderState=e.XRSession.prototype.updateRenderState,e.XRSession.prototype._requestAnimationFrame=e.XRSession.prototype.requestAnimationFrame;let t=Object.getOwnPropertyDescriptor(e.XRSession.prototype,"renderState");t&&Object.defineProperty(e.XRSession.prototype,"_renderState",t);let r=Object.getOwnPropertyDescriptor(Sr.prototype,"renderState");r&&Object.defineProperty(e.XRSession.prototype,"renderState",r);let i=Object.getOwnPropertyNames(Sr.prototype);for(let t of i){let r=Object.getOwnPropertyDescriptor(Sr.prototype,t);r&&Object.defineProperty(e.XRSession.prototype,t,r)}}_polyfillRequiredLayersFeature(e){const t=e.navigator.xr.requestSession;Object.defineProperty(e.navigator.xr,"requestSessionInternal",{writable:!0}),e.navigator.xr.requestSessionInternal=t;Object.defineProperty(e.navigator.xr,"requestSession",{writable:!0}),e.navigator.xr.requestSession=(t,r)=>{const i=(r,i)=>e.navigator.xr.requestSessionInternal(r,i).then(e=>{Object.assign(e,new Sr);let r=e;return r.initializeSession(t),Promise.resolve(r)});if("immersive-vr"!==t)return i(t,r);if(!r)return i(t,r);if(r.requiredFeatures&&r.requiredFeatures.indexOf("layers")>-1){const e={...r},s=[...r.requiredFeatures],a=s.indexOf("layers");return s.splice(a,1),e.requiredFeatures=s,i(t,e)}return i(t,r)}}};const Fr={ipd:.063,fovy:Math.PI/2,headsetPosition:new ce(0,1.6,0),headsetQuaternion:new de,stereoEnabled:!1};class Pr{constructor(e,t={}){var i,s,a,n,h,u;this.version=Ft;const c=new le,d=new je(ke.Viewer,c),p={[We.Left]:new he(d),[We.Right]:new he(d),[We.None]:new he(d)},f=e.controllerConfig,x={};f&&Object.values(fe).forEach(e=>{f.layout[e]&&(x[e]=new Se(f,e,c))});const g={[fe.Left]:new St(ct,fe.Left,c),[fe.Right]:new St(ct,fe.Right,c)},y=null!==(i=t.canvasContainer)&&void 0!==i?i:document.createElement("div");y.dataset.webxr_runtime=`Immersive Web Emulation Runtime v${Ft}`,y.style.position="fixed",y.style.width="100%",y.style.height="100%",y.style.top="0",y.style.left="0",y.style.display="flex",y.style.justifyContent="center",y.style.alignItems="center",y.style.overflow="hidden",y.style.zIndex="999",this[V]={name:e.name,supportedSessionModes:e.supportedSessionModes,supportedFeatures:e.supportedFeatures,supportedFrameRates:e.supportedFrameRates,isSystemKeyboardSupported:e.isSystemKeyboardSupported,internalNominalFrameRate:e.internalNominalFrameRate,environmentBlendModes:e.environmentBlendModes,interactionMode:e.interactionMode,userAgent:e.userAgent,position:null!==(s=t.headsetPosition)&&void 0!==s?s:Fr.headsetPosition.clone(),quaternion:null!==(a=t.headsetQuaternion)&&void 0!==a?a:Fr.headsetQuaternion.clone(),stereoEnabled:null!==(n=t.stereoEnabled)&&void 0!==n?n:Fr.stereoEnabled,ipd:null!==(h=t.ipd)&&void 0!==h?h:Fr.ipd,fovy:null!==(u=t.fovy)&&void 0!==u?u:Fr.fovy,controllers:x,hands:g,primaryInputMode:"controller",pendingReferenceSpaceReset:!1,visibilityState:"visible",pendingVisibilityState:null,xrSystem:null,matrix:r(),globalSpace:c,viewerSpace:d,viewSpaces:p,canvasContainer:y,getViewport:(e,t)=>{const r=e.context.canvas,{width:i,height:s}=r;switch(t.eye){case We.None:return new Lt(0,0,i,s);case We.Left:return new Lt(0,0,this[V].stereoEnabled?i/2:i,s);case We.Right:return new Lt(i/2,0,this[V].stereoEnabled?i/2:0,s)}},updateViews:()=>{l(this[V].viewerSpace[ie].offsetMatrix,this[V].quaternion.quat,this[V].position.vec3),o(this[V].viewSpaces[We.Left][ie].offsetMatrix,m(-this[V].ipd/2,0,0)),o(this[V].viewSpaces[We.Right][ie].offsetMatrix,m(this[V].ipd/2,0,0))},onBaseLayerSet:e=>{if(!e)return;const t=e.context.canvas;if(t.parentElement!==this[V].canvasContainer){const e=this[V].devui;if(e){const{devUICanvas:t,devUIContainer:r}=e;t.style.zIndex=3..toString(),r.style.zIndex=4..toString(),this[V].canvasContainer.appendChild(e.devUICanvas),this[V].canvasContainer.appendChild(e.devUIContainer)}const r=this[V].sem;r&&(r.environmentCanvas.style.zIndex=1..toString(),this[V].canvasContainer.appendChild(r.environmentCanvas)),this[V].canvasData={canvas:t,parent:t.parentElement,width:t.width,height:t.height,zIndex:t.style.zIndex},t.style.zIndex=2..toString(),this[V].canvasContainer.appendChild(t),document.body.appendChild(this[V].canvasContainer)}t.width=window.innerWidth,t.height=window.innerHeight},onSessionEnd:()=>{if(this[V].canvasData){const{canvas:e,parent:t,width:r,height:i,zIndex:s}=this[V].canvasData;e.width=r,e.height=i,e.style.zIndex=s,t?t.appendChild(e):this[V].canvasContainer.removeChild(e);const a=this[V].devui;a&&(this[V].canvasContainer.removeChild(a.devUICanvas),this[V].canvasContainer.removeChild(a.devUIContainer));const n=this[V].sem;n&&this[V].canvasContainer.removeChild(n.environmentCanvas),document.body.removeChild(this[V].canvasContainer),this[V].canvasData=void 0,window.dispatchEvent(new Event("resize"))}},onFrameStart:e=>{var t;if(null===(t=this[V].actionPlayer)||void 0===t?void 0:t.playing)this[V].actionPlayer.playFrame();else{const t=e.session;this[V].updateViews(),this[V].pendingVisibilityState&&(this[V].visibilityState=this[V].pendingVisibilityState,this[V].pendingVisibilityState=null,t.dispatchEvent(new Qe("visibilitychange",{session:t}))),"visible"===this[V].visibilityState&&this.activeInputs.forEach(t=>{t.onFrameStart(e)}),this[V].pendingReferenceSpaceReset&&(t[ee].referenceSpaces.forEach(e=>{switch(e[re].type){case ke.Local:case ke.LocalFloor:case ke.BoundedFloor:case ke.Unbounded:e.dispatchEvent(new Pt("reset",{referenceSpace:e}))}}),this[V].pendingReferenceSpaceReset=!1)}this[V].updateViews()}},this[V].updateViews()}installRuntime(e){var t;const r=null!==(t=null==e?void 0:e.globalObject)&&void 0!==t?t:globalThis,i=null==e?void 0:e.polyfillLayers;Object.defineProperty(WebGL2RenderingContext.prototype,"makeXRCompatible",{value:function(){return new Promise((e,t)=>{e(!0)})},configurable:!0}),this[V].xrSystem=new It(this),Object.defineProperty(globalThis.navigator,"xr",{value:this[V].xrSystem,configurable:!0}),Object.defineProperty(navigator,"userAgent",{value:this[V].userAgent,writable:!1,configurable:!1,enumerable:!0}),r.XRSystem=It,r.XRSession=ht,r.XRRenderState=Ye,r.XRFrame=st,r.XRSpace=he,r.XRReferenceSpace=je,r.XRJointSpace=ut,r.XRView=$e,r.XRViewport=Lt,r.XRRigidTransform=Ue,r.XRPose=Ke,r.XRViewerPose=Ze,r.XRJointPose=Je,r.XRInputSource=Te,r.XRInputSourceArray=ve,r.XRHand=lt,r.XRLayer=_t,r.XRWebGLLayer=Mt,r.XRSessionEvent=Qe,r.XRInputSourceEvent=we,r.XRInputSourcesChangeEvent=ze,r.XRReferenceSpaceEvent=Pt,i?new Ar:(r.XRMediaBinding=void 0,r.XRWebGLBinding=void 0)}installDevUI(e){this[V].devui=new e(this)}installSEM(e){this[V].sem=new e(this)}get supportedSessionModes(){return this[V].supportedSessionModes}get supportedFeatures(){return this[V].supportedFeatures}get supportedFrameRates(){return this[V].supportedFrameRates}get isSystemKeyboardSupported(){return this[V].isSystemKeyboardSupported}get internalNominalFrameRate(){return this[V].internalNominalFrameRate}get stereoEnabled(){return this[V].stereoEnabled}set stereoEnabled(e){this[V].stereoEnabled=e}get ipd(){return this[V].ipd}set ipd(e){this[V].ipd=e}get fovy(){return this[V].fovy}set fovy(e){this[V].fovy=e}get position(){return this[V].position}get quaternion(){return this[V].quaternion}get viewerSpace(){var e;return(null===(e=this[V].actionPlayer)||void 0===e?void 0:e.playing)?this[V].actionPlayer.viewerSpace:this[V].viewerSpace}get viewSpaces(){var e;return(null===(e=this[V].actionPlayer)||void 0===e?void 0:e.playing)?this[V].actionPlayer.viewSpaces:this[V].viewSpaces}get controllers(){return this[V].controllers}get hands(){return this[V].hands}get primaryInputMode(){return this[V].primaryInputMode}set primaryInputMode(e){"controller"===e||"hand"===e?this[V].primaryInputMode=e:console.warn('primary input mode can only be "controller" or "hand"')}get activeInputs(){if("visible"!==this[V].visibilityState)return[];return("controller"===this[V].primaryInputMode?Object.values(this[V].controllers):Object.values(this[V].hands)).filter(e=>e.connected)}get inputSources(){var e;return(null===(e=this[V].actionPlayer)||void 0===e?void 0:e.playing)?this[V].actionPlayer.inputSources:this.activeInputs.map(e=>e.inputSource)}get canvasContainer(){return this[V].canvasContainer}get canvasDimensions(){if(this[V].canvasData){const{width:e,height:t}=this[V].canvasData.canvas;return{width:e,height:t}}}get activeSession(){var e;return null===(e=this[V].xrSystem)||void 0===e?void 0:e[H].activeSession}get sessionOffered(){var e;return Boolean(null===(e=this[V].xrSystem)||void 0===e?void 0:e[H].offeredSessionConfig)}get name(){return this[V].name}grantOfferedSession(){var e;const t=null===(e=this[V].xrSystem)||void 0===e?void 0:e[H];t&&t.offeredSessionConfig&&(t.grantSession(t.offeredSessionConfig),t.offeredSessionConfig=void 0)}recenter(){const e=new ce(-this.position.x,0,-this.position.z),t=new ce(0,0,-1).applyQuaternion(this.quaternion);t.y=0,t.normalize();const r=Math.atan2(t.x,-t.z),i=(new de).setFromAxisAngle(new ce(0,1,0),r);this.position.add(e),this.quaternion.multiply(i),[...Object.values(this[V].controllers),...Object.values(this[V].hands)].forEach(t=>{t.position.add(e),t.quaternion.multiply(i),t.position.applyQuaternion(i)}),this[V].pendingReferenceSpaceReset=!0}get visibilityState(){return this[V].visibilityState}updateVisibilityState(e){if(!Object.values(["visible","visible-blurred","hidden"]).includes(e))throw new DOMException("Invalid XRVisibilityState value","NotSupportedError");e!==this[V].visibilityState&&(this[V].pendingVisibilityState=e)}createActionPlayer(e,t){return this[V].actionPlayer=new At(e,t,this[V].ipd),this[V].actionPlayer}get devui(){return this[V].devui}get sem(){return this[V].sem}}const Ir={mapping:pe.XRStandard,buttons:[{id:"trigger",type:"analog",eventTrigger:"select"},{id:"squeeze",type:"analog",eventTrigger:"squeeze"},null,{id:"thumbstick",type:"binary"},{id:"x-button",type:"binary"},{id:"y-button",type:"binary"},{id:"thumbrest",type:"binary"}],axes:[null,null,{id:"thumbstick",type:"x-axis"},{id:"thumbstick",type:"y-axis"}]},Lr={mapping:pe.XRStandard,buttons:[{id:"trigger",type:"analog",eventTrigger:"select"},{id:"squeeze",type:"analog",eventTrigger:"squeeze"},null,{id:"thumbstick",type:"binary"},{id:"a-button",type:"binary"},{id:"b-button",type:"binary"},{id:"thumbrest",type:"binary"}],axes:[null,null,{id:"thumbstick",type:"x-axis"},{id:"thumbstick",type:"y-axis"}]},Cr={profileId:"oculus-touch-v3",fallbackProfileIds:["oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Ir,gripOffsetMatrix:[.9925461411476135,2.0823669899527886e-8,-.12186937034130096,0,.08617465198040009,.7071067094802856,.701836109161377,0,.08617466688156128,-.7071067690849304,.7018360495567322,0,-.003979838453233242,-.015857907012104988,.04964181408286095,1],numHapticActuators:1},right:{gamepad:Lr,gripOffsetMatrix:[.9925461411476135,-8.329467959811154e-8,.12186941504478455,0,-.08617465943098068,.7071066498756409,.7018361687660217,0,-.08617471158504486,-.7071068286895752,.7018359303474426,0,.003979798872023821,-.015857888385653496,.049641866236925125,1],numHapticActuators:1}}},Dr={profileId:"meta-quest-touch-pro",fallbackProfileIds:["oculus-touch-v2","oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Ir,gripOffsetMatrix:[.9925461411476135,-1.5779937356796836e-8,-.12186935544013977,0,.08617467433214188,.7071067094802856,.701836109161377,0,.0861746296286583,-.7071067690849304,.7018360495567322,0,-.003979836590588093,-.015857847407460213,.049641840159893036,1],numHapticActuators:3},right:{gamepad:Lr,gripOffsetMatrix:[.9925461411476135,9267653311439972e-26,.12186937034130096,0,-.08617467433214188,.7071067094802856,.7018361687660217,0,-.08617464452981949,-.7071067690849304,.7018360495567322,0,.003979847766458988,-.01585782691836357,.04964186251163483,1],numHapticActuators:3}}},Nr={profileId:"meta-quest-touch-plus",fallbackProfileIds:["oculus-touch-v3","oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Ir,gripOffsetMatrix:[.9925461411476135,1.0736208366779465e-8,-.12186933308839798,0,.08617459982633591,.70710688829422,.7018360495567322,0,.08617466688156128,-.7071067094802856,.7018362283706665,0,-.003979803062975407,-.015857873484492302,.04964187368750572,1],numHapticActuators:1},right:{gamepad:Lr,gripOffsetMatrix:[.9925461411476135,-2.6238110351073374e-8,.12186934053897858,0,-.0861746147274971,.7071067690849304,.7018360495567322,0,-.08617465943098068,-.7071067094802856,.701836109161377,0,.003979838453233242,-.015857869759202003,.04964182525873184,1],numHapticActuators:1}}},Br={name:"Oculus Quest 1",controllerConfig:{profileId:"oculus-touch-v2",fallbackProfileIds:["oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Ir,gripOffsetMatrix:[.9925461411476135,4.673031295254759e-9,-.12186938524246216,0,.08617470413446426,.7071065306663513,.7018362283706665,0,.0861746296286583,-.70710688829422,.7018358707427979,0,-.003979847766458988,-.01585787907242775,.04964185878634453,1],numHapticActuators:1},right:{gamepad:Lr,gripOffsetMatrix:[.9925461411476135,3.688163374704345e-8,.12186937034130096,0,-.08617469668388367,.7071066498756409,.7018361687660217,0,-.0861746147274971,-.7071068286895752,.7018359899520874,0,.003979853354394436,-.01585787907242775,.04964182525873184,1],numHapticActuators:1}}},supportedSessionModes:["inline","immersive-vr","immersive-ar"],supportedFeatures:["viewer","local","local-floor","bounded-floor","unbounded","anchors","plane-detection","hand-tracking"],supportedFrameRates:[72,80,90],isSystemKeyboardSupported:!0,internalNominalFrameRate:72,environmentBlendModes:{"immersive-vr":at.Opaque,"immersive-ar":at.AlphaBlend},interactionMode:nt.WorldSpace,userAgent:"Mozilla/5.0 (X11; Linux x86_64; Quest 1) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36"},Or={name:"Meta Quest 2",controllerConfig:Cr,supportedSessionModes:["inline","immersive-vr","immersive-ar"],supportedFeatures:["viewer","local","local-floor","bounded-floor","unbounded","anchors","plane-detection","mesh-detection","hit-test","hand-tracking"],supportedFrameRates:[72,80,90,120],isSystemKeyboardSupported:!0,internalNominalFrameRate:72,environmentBlendModes:{"immersive-vr":at.Opaque,"immersive-ar":at.AlphaBlend},interactionMode:nt.WorldSpace,userAgent:"Mozilla/5.0 (X11; Linux x86_64; Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36"},Ur={name:"Meta Quest Pro",controllerConfig:Dr,supportedSessionModes:["inline","immersive-vr","immersive-ar"],supportedFeatures:["viewer","local","local-floor","bounded-floor","unbounded","anchors","plane-detection","mesh-detection","hit-test","hand-tracking"],supportedFrameRates:[72,80,90,120],isSystemKeyboardSupported:!0,internalNominalFrameRate:90,environmentBlendModes:{"immersive-vr":at.Opaque,"immersive-ar":at.AlphaBlend},interactionMode:nt.WorldSpace,userAgent:"Mozilla/5.0 (X11; Linux x86_64; Quest Pro) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36"},Vr={name:"Meta Quest 3",controllerConfig:Nr,supportedSessionModes:["inline","immersive-vr","immersive-ar"],supportedFeatures:["viewer","local","local-floor","bounded-floor","unbounded","anchors","plane-detection","mesh-detection","hit-test","hand-tracking","depth-sensing"],supportedFrameRates:[72,80,90,120],isSystemKeyboardSupported:!0,internalNominalFrameRate:90,environmentBlendModes:{"immersive-vr":at.Opaque,"immersive-ar":at.AlphaBlend},interactionMode:nt.WorldSpace,userAgent:"Mozilla/5.0 (X11; Linux x86_64; Quest 3) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36"},Gr=e=>{const t=[];return e.forEach(e=>{t.push(parseFloat(e.toFixed(3)))}),t};class Xr{constructor(e,t){this[B]={session:e,refSpace:t,inputMap:new Map,schemaMap:new Map,compressedFrames:[],jointRadii:new Float32Array(25),jointTransforms:new Float32Array(400)}}recordFrame(e){var t;const r=performance.now(),i=null===(t=e.getViewerPose(this[B].refSpace))||void 0===t?void 0:t.transform.matrix;if(!i)return;const s={timeStamp:r,position:u(x(),i),quaternion:d(b(),i),inputFrames:[]};this[B].session.inputSources.forEach(t=>{var r,i;if(!this[B].inputMap.has(t)){const e={handedness:t.handedness,targetRayMode:t.targetRayMode,profiles:t.profiles,hasGrip:null!=t.gripSpace,hasHand:null!=t.hand,hasGamepad:null!=t.gamepad};e.hasHand&&(e.jointSequence=Array.from(t.hand.values()).map(e=>e.jointName)),e.hasGamepad&&(e.mapping=t.gamepad.mapping,e.numButtons=t.gamepad.buttons.length,e.numAxes=t.gamepad.axes.length);const r=this[B].inputMap.size;this[B].inputMap.set(t,r),this[B].schemaMap.set(r,e)}const a=this[B].inputMap.get(t),n=this[B].schemaMap.get(a),o=null===(r=e.getPose(t.targetRaySpace,this[B].refSpace))||void 0===r?void 0:r.transform.matrix;if(o){const r={index:a,targetRayTransform:{position:u(x(),o),quaternion:d(b(),o)}};if(n.hasGrip){const s=null===(i=e.getPose(t.gripSpace,this[B].refSpace))||void 0===i?void 0:i.transform.matrix;if(s){const e=u(x(),s),t=d(b(),s);r.gripTransform={position:e,quaternion:t}}}if(n.hasHand){const i=Array.from(t.hand.values());let s=!0;if(s&&(s=e.fillPoses(i,t.targetRaySpace,this[B].jointTransforms)),s&&(s=e.fillJointRadii(i,this[B].jointRadii)),s){const e={};for(let t=0;t<25;t++){const r=this[B].jointTransforms.slice(16*t,16*(t+1)),s=this[B].jointRadii[t],a=u(x(),r),n=d(b(),r);e[i[t].jointName]={position:a,quaternion:n,radius:s}}r.hand=e}}if(n.hasGamepad){const e={buttons:t.gamepad.buttons.map(e=>e?[e.pressed?1:0,e.touched?1:0,e.value]:null),axes:Array.from(t.gamepad.axes)};r.gamepad=e}s.inputFrames.push(r)}}),this[B].compressedFrames.push(this.compressActionFrame(s))}compressActionFrame(e){const t=[Math.round(10*e.timeStamp)/10,...Gr(e.position),...Gr(e.quaternion)];return e.inputFrames.forEach(e=>{const r=e.index,i=this[B].schemaMap.get(r),s=[r,...Gr(e.targetRayTransform.position),...Gr(e.targetRayTransform.quaternion)];if(i.hasGrip&&s.push([...Gr(e.gripTransform.position),...Gr(e.gripTransform.quaternion)]),i.hasHand){const t=[];Object.values(e.hand).forEach(({position:e,quaternion:r,radius:i})=>{t.push(...Gr(e),...Gr(r),parseFloat(i.toFixed(3)))}),s.push(t)}i.hasGamepad&&s.push([...e.gamepad.buttons,...e.gamepad.axes]),t.push(s)}),t}log(){const e={schema:Array.from(this[B].schemaMap.entries()),frames:this[B].compressedFrames};console.log(JSON.stringify(e))}}export{Xr as ActionRecorder,Me as NativeMesh,Ce as NativePlane,N as P_ACTION_PLAYER,B as P_ACTION_RECORDER,O as P_ANCHOR,U as P_CONTROLLER,V as P_DEVICE,q as P_FRAME,z as P_GAMEPAD,G as P_HAND_INPUT,oe as P_HIT_TEST,k as P_INPUT_SOURCE,Q as P_JOINT_POSE,te as P_JOINT_SPACE,j as P_MESH,Y as P_PLANE,$ as P_POSE,ne as P_RAY,re as P_REF_SPACE,Z as P_RENDER_STATE,J as P_RIGID_TRANSFORM,ee as P_SESSION,ie as P_SPACE,H as P_SYSTEM,X as P_TRACKED_INPUT,se as P_VIEW,K as P_VIEWER_POSE,ae as P_VIEWPORT,W as P_WEBGL_LAYER,De as XRAnchor,Ne as XRAnchorSet,Pr as XRDevice,st as XRFrame,lt as XRHand,Te as XRInputSource,ve as XRInputSourceArray,we as XRInputSourceEvent,ze as XRInputSourcesChangeEvent,Je as XRJointPose,ut as XRJointSpace,_t as XRLayer,_e as XRMesh,be as XRMeshSet,Ie as XRPlane,Le as XRPlaneSet,Ke as XRPose,Ge as XRRay,je as XRReferenceSpace,Pt as XRReferenceSpaceEvent,Ye as XRRenderState,Ue as XRRigidTransform,Ae as XRSemanticLabels,ht as XRSession,Qe as XRSessionEvent,he as XRSpace,It as XRSystem,$e as XRView,Ze as XRViewerPose,Lt as XRViewport,Mt as XRWebGLLayer,Or as metaQuest2,Vr as metaQuest3,Ur as metaQuestPro,Br as oculusQuest1};
|
|
204
|
+
`;class br{constructor(e,t){this.savedVaoState={vao:null,arrayBuffer:null},this.hasMipmap=!1,this.layer=e,this.gl=t,this.transformMatrix=hr(),this.program=$t(t,Rr,_r),this.programInfo={attribLocations:{a_position:t.getAttribLocation(this.program,"a_position")},uniformLocations:{u_matrix:t.getUniformLocation(this.program,"u_matrix"),u_texture:t.getUniformLocation(this.program,"u_texture"),u_projectionMatrix:t.getUniformLocation(this.program,"u_projectionMatrix")}},this._createVAOs()}saveVaoState(){this.savedVaoState.vao=this.gl.getParameter(this.vaoGl.VERTEX_ARRAY_BINDING),this.savedVaoState.arrayBuffer=this.gl.getParameter(this.gl.ARRAY_BUFFER_BINDING)}restoreVaoState(){this.vaoGl.bindVertexArray(this.savedVaoState.vao),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.savedVaoState.arrayBuffer),this.savedVaoState.vao=this.savedVaoState.arrayBuffer=null}render(e,t){this.saveVaoState();let r=this.gl,i=e.getBaseLayer(),s=t.getViewerPose(e.getReferenceSpace());const a=r.getParameter(r.ACTIVE_TEXTURE);for(let e of s.views){let t=i.getViewport(e);r.viewport(t.x,t.y,t.width,t.height),r.activeTexture(r.TEXTURE0);const s=r.getParameter(r.TEXTURE_BINDING_CUBE_MAP);if(this.layer.layout===Lt.stereo){const t="right"===e.eye?1:0;r.bindTexture(r.TEXTURE_CUBE_MAP,this.layer.colorTextures[t])}else r.bindTexture(r.TEXTURE_CUBE_MAP,this.layer.colorTextures[0]);this.layer.isStatic?(!0===this.layer.needsRedraw&&r.generateMipmap(r.TEXTURE_CUBE_MAP),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_MAG_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),r.texParameteri(r.TEXTURE_CUBE_MAP,r.TEXTURE_MIN_FILTER,this.hasMipmap?r.LINEAR_MIPMAP_LINEAR:r.LINEAR),this._renderInternal(this.layer.orientation,e),r.activeTexture(a),r.bindTexture(r.TEXTURE_CUBE_MAP,s)}this.restoreVaoState()}createPositionPoints(){const e=.5;return new Float32Array([-e,-e,-e,-e,e,-e,e,-e,-e,-e,e,-e,e,e,-e,e,-e,-e,-e,-e,e,e,-e,e,-e,e,e,-e,e,e,e,-e,e,e,e,e,-e,e,-e,-e,e,e,e,e,-e,-e,e,e,e,e,e,e,e,-e,-e,-e,-e,e,-e,-e,-e,-e,e,-e,-e,e,e,-e,-e,e,-e,e,-e,-e,-e,-e,-e,e,-e,e,-e,-e,-e,e,-e,e,e,-e,e,-e,e,-e,-e,e,e,-e,e,-e,e,e,-e,e,e,e,-e,e,e,e])}_renderInternal(e,t){let r=this.gl;const i=r.getParameter(r.CURRENT_PROGRAM);r.useProgram(this.program),this.vaoGl.bindVertexArray(this.vao),ur(this.transformMatrix,[e.x,e.y,e.z,e.w]),this._poseOrientationMatrix||(this._poseOrientationMatrix=hr()),ur(this._poseOrientationMatrix,[t.transform.inverse.orientation.x,t.transform.inverse.orientation.y,t.transform.inverse.orientation.z,t.transform.inverse.orientation.w]),lr(this.transformMatrix,this.transformMatrix,this._poseOrientationMatrix),r.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix,!1,this.transformMatrix),r.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix,!1,t.projectionMatrix),r.uniform1i(this.programInfo.uniformLocations.u_texture,0);var s=r.TRIANGLES,a=this.positionPoints.length/3;r.drawArrays(s,0,a),this.vaoGl.bindVertexArray(null),r.useProgram(i)}_recalculateVertices(){this.positionPoints=this.createPositionPoints()}_createVAOs(){this._recalculateVertices();let e=this.gl;this.vaoGl=Jt(e),this.saveVaoState();let t=e.createBuffer();this.vao=this.vaoGl.createVertexArray(),this.vaoGl.bindVertexArray(this.vao),e.enableVertexAttribArray(this.programInfo.attribLocations.a_position),e.bindBuffer(e.ARRAY_BUFFER,t);const r=this.positionPoints;e.bufferData(e.ARRAY_BUFFER,r,e.STATIC_DRAW);var i=e.FLOAT;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,3,i,!1,0,0),this.restoreVaoState()}}class Mr{constructor(){this.mode="inline",this.layers=[],this.views=[],this.initializedViews=!1,this.isPolyfillActive=!1,this.taskQueue=[]}requestAnimationFrame(e){this.injectedFrameCallback||(this.injectedFrameCallback=(t,r)=>{let i=this.context;if(!this.initializedViews&&this.referenceSpace){let e=r.getViewerPose(this.referenceSpace);e&&(this.views=e.views,this.initializedViews=!0)}if(this.isPolyfillActive&&this.initializedViews){this.tempFramebuffer||(this.tempFramebuffer=i.createFramebuffer()),i.bindFramebuffer(i.FRAMEBUFFER,this.tempFramebuffer);const e=i.getParameter(i.COLOR_CLEAR_VALUE),t=i.getParameter(i.FRAMEBUFFER_BINDING);i.clearColor(0,0,0,0);for(let e of this.layers)if(e instanceof Yt)for(let t=0;t<e.colorTextures.length;t++){e.colorTexturesMeta[t].type===It["texture-array"]||(i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e.colorTextures[t],0),e.depthStencilTextures&&t<e.depthStencilTextures.length?i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,e.depthStencilTextures[t],0):i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,null,0),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT))}i.bindFramebuffer(i.FRAMEBUFFER,t),i.clearColor(e[0],e[1],e[2],e[3])}if(e(t,r),this.isPolyfillActive&&this.initializedViews){let e=i.isEnabled(i.BLEND),t=i.isEnabled(i.DEPTH_TEST),s=i.isEnabled(i.CULL_FACE);const a=i.getParameter(i.FRAMEBUFFER_BINDING),n=i.getParameter(i.COLOR_CLEAR_VALUE);i.bindFramebuffer(i.FRAMEBUFFER,this.getBaseLayer().framebuffer),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.clearColor(n[0],n[1],n[2],n[3]),i.enable(i.BLEND),i.disable(i.DEPTH_TEST),i.disable(i.CULL_FACE);let o=i.getParameter(i.BLEND_SRC_RGB),h=i.getParameter(i.BLEND_SRC_ALPHA),l=i.getParameter(i.BLEND_DST_RGB),u=i.getParameter(i.BLEND_DST_ALPHA);i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA);for(let e of this.layers)if(this.renderers||(this.renderers=new WeakMap),e instanceof Yt){this.renderers.has(e)||this.renderers.set(e,nr(e,this.context));this.renderers.get(e).render(this)}else if(e instanceof Ht){this.renderers.has(e)||this.renderers.set(e,new yr(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof Ut){this.renderers.has(e)||this.renderers.set(e,new vr(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof qt){this.renderers.has(e)||this.renderers.set(e,new Tr(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof Sr){this.renderers.has(e)||this.renderers.set(e,new br(e,this.context));this.renderers.get(e).render(this,r)}else{const t=e;if(null===t.framebuffer)continue;i instanceof WebGL2RenderingContext?(i.bindFramebuffer(i.READ_FRAMEBUFFER,t.framebuffer),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,this.getBaseLayer().framebuffer),i.blitFramebuffer(0,0,t.framebufferWidth,t.framebufferHeight,0,0,this.getBaseLayer().framebufferWidth,this.getBaseLayer().framebufferHeight,i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT,i.LINEAR)):console.warn("GL blitFramebuffer is not supported on WebGL1, so XRWebGLLayers may not show up properly when polyfilled.")}for(e||i.disable(i.BLEND),t&&i.enable(i.DEPTH_TEST),s&&i.enable(i.CULL_FACE),i.blendFuncSeparate(o,l,h,u),i.bindFramebuffer(i.FRAMEBUFFER,a);this.taskQueue.length>0;){this.taskQueue.shift()()}}}),this._requestAnimationFrame(this.injectedFrameCallback)}updateRenderState(e){if(this.existingBaseLayer=e.baseLayer,e.layers&&(this.layers=e.layers),this.activeRenderState||this.createActiveRenderState(),this.activeRenderState=Object.assign(Object.assign({},this.activeRenderState),e),!e.layers)return void this._updateRenderState(e);let t,r=Object.assign({},e);delete r.layers;for(let i of this.layers)if(i instanceof Ot){t=i.getContext();break}if(!t&&!this.context){console.log("No existing context! Have the session make one");const s=document.createElement("canvas");if(t=s.getContext("webgl2",{xrCompatible:!0}),t||(t=s.getContext("webgl",{xrCompatible:!0})),!t)throw new Error("No webGL support detected.");function a(){t.canvas.width=t.canvas.clientWidth*window.devicePixelRatio,t.canvas.height=t.canvas.clientHeight*window.devicePixelRatio}document.body.appendChild(t.canvas),window.addEventListener("resize",a),a()}this.createInternalLayer(t),this.isPolyfillActive=!0,this._updateRenderState(Object.assign(Object.assign({},r),{baseLayer:this.internalLayer}))}initializeSession(e){this.mode=e,this.requestReferenceSpace("local").then((e=>{this.referenceSpace=e})).catch((e=>{})),this.requestReferenceSpace("viewer").then((e=>{this.viewerSpace=e}))}getBaseLayer(e){return this.internalLayer||this.existingBaseLayer||!e||this.createInternalLayer(e),this.internalLayer||this.existingBaseLayer}getReferenceSpace(){return this.referenceSpace?this.referenceSpace:this.viewerSpace}getViewerSpace(){return this.viewerSpace}queueTask(e){this.taskQueue.push(e)}get renderState(){return this.activeRenderState||this.createActiveRenderState(),this.activeRenderState}get internalViews(){return this.views}getViewIndex(e){for(let t=0;t<this.views.length;t++){let r=this.views[t];if(e.eye===r.eye&&e.recommendedViewportScale===r.recommendedViewportScale)return t}return-1}createInternalLayer(e){if(!e&&this.internalLayer)return this.internalLayer;if(e===this.context&&this.internalLayer)return this.internalLayer;const t=Dt();return this.internalLayer=new t.XRWebGLLayer(this,e),this.setContext(e),this.internalLayer}setContext(e){this.context=e,this.tempFramebuffer=e.createFramebuffer(),this.renderers=new WeakMap}createActiveRenderState(){const e=Dt();let t=Object.getOwnPropertyNames(e.XRRenderState.prototype);const r={};for(let e of t)r[e]=this._renderState[e];r.layers=[],this.activeRenderState=r}}class Ar{constructor(){this.viewport={x:0,y:0,width:0,height:0}}}class Fr{constructor(e,t){this.session=e,this.context=t,this.subImageCache=new Pr}createProjectionLayer(e=Wt){const t=new Yt(e);if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");return t.initialize(this.session,this.context),t}createQuadLayer(e=zt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===Lt.default)throw new TypeError("Trying to create a quad layer with default layout");const t=new Ht(e);return t.initialize(this.session,this.context),t}createCylinderLayer(e=Bt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===Lt.default)throw new TypeError("Cylinder Layer cannot have a default layout");const t=new Ut(e);return t.initialize(this.session,this.context),t}createEquirectLayer(e=Gt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===Lt.default)throw new TypeError("Equirect Layer cannot have a default layout");if(!Ct(e.space))throw new TypeError("Equirect layer requires an XRReferenceSpace");let t=new qt(e);return t.initialize(this.session,this.context),t}createCubeLayer(e){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(!(this.context instanceof WebGL2RenderingContext))throw new Error("XRCubeLayer only work on WebGL2");if(!Ct(e.space))throw new TypeError("XRCubeLayer requires a space of type XRReferenceSpace");let t=new Sr(e);return t.initialize(this.session,this.context),t}getSubImage(e,t,r="none"){if(e.isStatic&&!1===e.needsRedraw)throw new Error("Invalid state for subimage creation");let i=this.subImageCache.tryGetCachedSubImage(this.context,e,r);if(i)return i;let s=new Ar;if(e instanceof Yt)throw new TypeError;if(e.layout===Lt.default)throw new TypeError;if(!this.validateStateofSubImageCreation(e,t))throw new Error("Invalid state for subimage creation");let a=0;if(e.layout===Lt.stereo){if("none"===r)throw new TypeError;"right"===r&&(a=1)}e.getTextureType()===It["texture-array"]?s.imageIndex=a:s.imageIndex=0;let n=0;e.getTextureType()===It.texture?(s.colorTexture=e.colorTextures[a],n=a):(s.colorTexture=e.colorTextures[0],n=0),e.depthStencilTextures&&e.depthStencilTextures.length?e.getTextureType()===It.texture?s.depthStencilTexture=e.depthStencilTextures[a]:s.depthStencilTexture=e.depthStencilTextures[0]:s.depthStencilTexture=null;const o=e.colorTexturesMeta[n];s.textureWidth=o.width,s.textureHeight=o.height;let h=1;return e.layout!==Lt["stereo-left-right"]&&e.layout!==Lt["stereo-top-bottom"]||(h=2),Qt(s.viewport,o,e.layout,a,h),this.session.queueTask((()=>{e.needsRedraw=!1})),this.subImageCache.cacheSubImage(s,this.context,e,r),s}getViewSubImage(e,t){let r=this.subImageCache.tryGetCachedViewSubImage(this.context,e,t);if(r)return r;let i=new Ar,s=this.session;if(!s.internalViews||!s.internalViews.length)return console.warn("Tried to get view sub image before we have any views"),i;let a=s.getViewIndex(t),n=0;return e.getTextureType()===It["texture-array"]?i.imageIndex=a:i.imageIndex=0,e.layout===Lt.default&&e.getTextureType()===It.texture?(i.colorTexture=e.colorTextures[a],n=a):(i.colorTexture=e.colorTextures[0],n=0),0===e.depthStencilTextures.length?i.depthStencilTexture=null:e.layout===Lt.default&&e.getTextureType()===It.texture?i.depthStencilTexture=e.depthStencilTextures[a]:i.depthStencilTexture=e.depthStencilTextures[0],i.textureWidth=e.colorTexturesMeta[n].width,i.textureHeight=e.colorTexturesMeta[n].height,Qt(i.viewport,e.colorTexturesMeta[n],e.layout,a,s.internalViews.length),e.needsRedraw=!1,this.subImageCache.cacheViewSubImage(i,this.context,e,t),i}validateStateofSubImageCreation(e,t){return t.session===e.session&&(this.session===e.session&&(this.context===e.context&&(!(!e.colorTextures||!e.colorTextures.length)&&(!e.isStatic||!1!==e.needsRedraw))))}}class Pr{constructor(){this.cache=new Map,this.viewCache=new Map}cacheSubImage(e,t,r,i){let s=new Map;s.set(i,e);let a=new Map;a.set(r,s),this.cache.set(t,a)}tryGetCachedSubImage(e,t,r){var i,s;return null===(s=null===(i=this.cache.get(e))||void 0===i?void 0:i.get(t))||void 0===s?void 0:s.get(r)}cacheViewSubImage(e,t,r,i){let s=new Map;s.set(i,e);let a=new Map;a.set(r,s),this.viewCache.set(t,a)}tryGetCachedViewSubImage(e,t,r){var i,s;return null===(s=null===(i=this.viewCache.get(e))||void 0===i?void 0:i.get(t))||void 0===s?void 0:s.get(r)}}class Ir{constructor(){this.injected=!1;const e=Dt();this._injectPolyfill(e)}_injectPolyfill(e){if(!("xr"in e.navigator))throw new Error("WebXR Layers polyfill requires WebXR support.");!0===this.injected&&console.warn("Polyfill has already been injected..."),(e=>!!e.navigator.xr&&!(!e.XRMediaBinding||!e.XRWebGLBinding))(e)||(this._polyfillRequiredLayersFeature(e),this._polyfillXRSession(e),e.XRWebGLBinding=Fr,e.XRMediaBinding=jt,this.injected=!0,console.log("Injected Layers Polyfill"))}_polyfillXRSession(e){e.XRSession.prototype._updateRenderState=e.XRSession.prototype.updateRenderState,e.XRSession.prototype._requestAnimationFrame=e.XRSession.prototype.requestAnimationFrame;let t=Object.getOwnPropertyDescriptor(e.XRSession.prototype,"renderState");Object.defineProperty(e.XRSession.prototype,"_renderState",t);let r=Object.getOwnPropertyDescriptor(Mr.prototype,"renderState");Object.defineProperty(e.XRSession.prototype,"renderState",r);let i=Object.getOwnPropertyNames(Mr.prototype);for(let t of i){let r=Object.getOwnPropertyDescriptor(Mr.prototype,t);Object.defineProperty(e.XRSession.prototype,t,r)}}_polyfillRequiredLayersFeature(e){const t=e.navigator.xr.requestSession;Object.defineProperty(e.navigator.xr,"requestSessionInternal",{writable:!0}),e.navigator.xr.requestSessionInternal=t;Object.defineProperty(e.navigator.xr,"requestSession",{writable:!0}),e.navigator.xr.requestSession=(t,r)=>{const i=(r,i)=>e.navigator.xr.requestSessionInternal(r,i).then((e=>{Object.assign(e,new Mr);let r=e;return r.initializeSession(t),Promise.resolve(r)}));if("immersive-vr"!==t)return i(t,r);if(!r)return i(t,r);if(r.requiredFeatures&&r.requiredFeatures.indexOf("layers")>-1){const e=Object.assign({},r),s=[...r.requiredFeatures],a=s.indexOf("layers");return s.splice(a,1),e.requiredFeatures=s,i(t,e)}return i(t,r)}}}const Lr={ipd:.063,fovy:Math.PI/2,headsetPosition:new le(0,1.6,0),headsetQuaternion:new ue,stereoEnabled:!1};class Cr{constructor(e,t={}){var i,s,a,n,h,u;this.version=Mt;const c=new oe,d=new He(ze.Viewer,c),p={[ke.Left]:new ne(d),[ke.Right]:new ne(d),[ke.None]:new ne(d)},f=e.controllerConfig,m={};f&&Object.values(de).forEach((e=>{f.layout[e]&&(m[e]=new Se(f,e,c))}));const g={[de.Left]:new St(lt,de.Left,c),[de.Right]:new St(lt,de.Right,c)},y=null!==(i=t.canvasContainer)&&void 0!==i?i:document.createElement("div");y.dataset.webxr_runtime=`Immersive Web Emulation Runtime v${Mt}`,y.style.position="fixed",y.style.width="100%",y.style.height="100%",y.style.top="0",y.style.left="0",y.style.display="flex",y.style.justifyContent="center",y.style.alignItems="center",y.style.overflow="hidden",y.style.zIndex="999",this[B]={name:e.name,supportedSessionModes:e.supportedSessionModes,supportedFeatures:e.supportedFeatures,supportedFrameRates:e.supportedFrameRates,isSystemKeyboardSupported:e.isSystemKeyboardSupported,internalNominalFrameRate:e.internalNominalFrameRate,environmentBlendModes:e.environmentBlendModes,interactionMode:e.interactionMode,userAgent:e.userAgent,position:null!==(s=t.headsetPosition)&&void 0!==s?s:Lr.headsetPosition.clone(),quaternion:null!==(a=t.headsetQuaternion)&&void 0!==a?a:Lr.headsetQuaternion.clone(),stereoEnabled:null!==(n=t.stereoEnabled)&&void 0!==n?n:Lr.stereoEnabled,ipd:null!==(h=t.ipd)&&void 0!==h?h:Lr.ipd,fovy:null!==(u=t.fovy)&&void 0!==u?u:Lr.fovy,controllers:m,hands:g,primaryInputMode:"controller",pendingReferenceSpaceReset:!1,visibilityState:"visible",pendingVisibilityState:null,xrSystem:null,matrix:r(),globalSpace:c,viewerSpace:d,viewSpaces:p,canvasContainer:y,getViewport:(e,t)=>{const r=e.context.canvas,{width:i,height:s}=r;switch(t.eye){case ke.None:return new Pt(0,0,i,s);case ke.Left:return new Pt(0,0,this[B].stereoEnabled?i/2:i,s);case ke.Right:return new Pt(i/2,0,this[B].stereoEnabled?i/2:0,s)}},updateViews:()=>{l(this[B].viewerSpace[te].offsetMatrix,this[B].quaternion.quat,this[B].position.vec3),o(this[B].viewSpaces[ke.Left][te].offsetMatrix,x(-this[B].ipd/2,0,0)),o(this[B].viewSpaces[ke.Right][te].offsetMatrix,x(this[B].ipd/2,0,0))},onBaseLayerSet:e=>{if(!e)return;const t=e.context.canvas;if(t.parentElement!==this[B].canvasContainer){const e=this[B].devui;if(e){const{devUICanvas:t,devUIContainer:r}=e;t.style.zIndex=3..toString(),r.style.zIndex=4..toString(),this[B].canvasContainer.appendChild(e.devUICanvas),this[B].canvasContainer.appendChild(e.devUIContainer)}const r=this[B].sem;r&&(r.environmentCanvas.style.zIndex=1..toString(),this[B].canvasContainer.appendChild(r.environmentCanvas)),this[B].canvasData={canvas:t,parent:t.parentElement,width:t.width,height:t.height,zIndex:t.style.zIndex},t.style.zIndex=2..toString(),this[B].canvasContainer.appendChild(t),document.body.appendChild(this[B].canvasContainer)}t.width=window.innerWidth,t.height=window.innerHeight},onSessionEnd:()=>{if(this[B].canvasData){const{canvas:e,parent:t,width:r,height:i,zIndex:s}=this[B].canvasData;e.width=r,e.height=i,e.style.zIndex=s,t?t.appendChild(e):this[B].canvasContainer.removeChild(e);const a=this[B].devui;a&&(this[B].canvasContainer.removeChild(a.devUICanvas),this[B].canvasContainer.removeChild(a.devUIContainer));const n=this[B].sem;n&&this[B].canvasContainer.removeChild(n.environmentCanvas),document.body.removeChild(this[B].canvasContainer),this[B].canvasData=void 0,window.dispatchEvent(new Event("resize"))}},onFrameStart:e=>{var t;if(null===(t=this[B].actionPlayer)||void 0===t?void 0:t.playing)this[B].actionPlayer.playFrame();else{const t=e.session;this[B].updateViews(),this[B].pendingVisibilityState&&(this[B].visibilityState=this[B].pendingVisibilityState,this[B].pendingVisibilityState=null,t.dispatchEvent(new We("visibilitychange",{session:t}))),"visible"===this[B].visibilityState&&this.activeInputs.forEach((t=>{t.onFrameStart(e)})),this[B].pendingReferenceSpaceReset&&(t[J].referenceSpaces.forEach((e=>{switch(e[ee].type){case ze.Local:case ze.LocalFloor:case ze.BoundedFloor:case ze.Unbounded:e.dispatchEvent(new At("reset",{referenceSpace:e}))}})),this[B].pendingReferenceSpaceReset=!1)}this[B].updateViews()}},this[B].updateViews()}installRuntime(e){var t;const r=null!==(t=null==e?void 0:e.globalObject)&&void 0!==t?t:globalThis,i=null==e?void 0:e.polyfillLayers;Object.defineProperty(WebGL2RenderingContext.prototype,"makeXRCompatible",{value:function(){return new Promise(((e,t)=>{e(!0)}))},configurable:!0}),this[B].xrSystem=new Ft(this),Object.defineProperty(globalThis.navigator,"xr",{value:this[B].xrSystem,configurable:!0}),Object.defineProperty(navigator,"userAgent",{value:this[B].userAgent,writable:!1,configurable:!1,enumerable:!0}),r.XRSystem=Ft,r.XRSession=nt,r.XRRenderState=je,r.XRFrame=rt,r.XRSpace=ne,r.XRReferenceSpace=He,r.XRJointSpace=ht,r.XRView=Ye,r.XRViewport=Pt,r.XRRigidTransform=Oe,r.XRPose=Qe,r.XRViewerPose=$e,r.XRJointPose=Ke,r.XRInputSource=ye,r.XRInputSourceArray=ge,r.XRHand=ot,r.XRLayer=Et,r.XRWebGLLayer=_t,r.XRSessionEvent=We,r.XRInputSourceEvent=ve,r.XRInputSourcesChangeEvent=Xe,r.XRReferenceSpaceEvent=At,i?new Ir:(r.XRMediaBinding=void 0,r.XRWebGLBinding=void 0)}installDevUI(e){this[B].devui=new e(this)}installSEM(e){this[B].sem=new e(this)}get supportedSessionModes(){return this[B].supportedSessionModes}get supportedFeatures(){return this[B].supportedFeatures}get supportedFrameRates(){return this[B].supportedFrameRates}get isSystemKeyboardSupported(){return this[B].isSystemKeyboardSupported}get internalNominalFrameRate(){return this[B].internalNominalFrameRate}get stereoEnabled(){return this[B].stereoEnabled}set stereoEnabled(e){this[B].stereoEnabled=e}get ipd(){return this[B].ipd}set ipd(e){this[B].ipd=e}get fovy(){return this[B].fovy}set fovy(e){this[B].fovy=e}get position(){return this[B].position}get quaternion(){return this[B].quaternion}get viewerSpace(){var e;return(null===(e=this[B].actionPlayer)||void 0===e?void 0:e.playing)?this[B].actionPlayer.viewerSpace:this[B].viewerSpace}get viewSpaces(){var e;return(null===(e=this[B].actionPlayer)||void 0===e?void 0:e.playing)?this[B].actionPlayer.viewSpaces:this[B].viewSpaces}get controllers(){return this[B].controllers}get hands(){return this[B].hands}get primaryInputMode(){return this[B].primaryInputMode}set primaryInputMode(e){"controller"===e||"hand"===e?this[B].primaryInputMode=e:console.warn('primary input mode can only be "controller" or "hand"')}get activeInputs(){if("visible"!==this[B].visibilityState)return[];return("controller"===this[B].primaryInputMode?Object.values(this[B].controllers):Object.values(this[B].hands)).filter((e=>e.connected))}get inputSources(){var e;return(null===(e=this[B].actionPlayer)||void 0===e?void 0:e.playing)?this[B].actionPlayer.inputSources:this.activeInputs.map((e=>e.inputSource))}get canvasContainer(){return this[B].canvasContainer}get canvasDimensions(){if(this[B].canvasData){const{width:e,height:t}=this[B].canvasData.canvas;return{width:e,height:t}}}get activeSession(){var e;return null===(e=this[B].xrSystem)||void 0===e?void 0:e[q].activeSession}get sessionOffered(){var e;return Boolean(null===(e=this[B].xrSystem)||void 0===e?void 0:e[q].offeredSessionConfig)}get name(){return this[B].name}grantOfferedSession(){const e=this[B].xrSystem,t=null==e?void 0:e[q];if(t&&t.offeredSessionConfig){const{resolve:r,reject:i,mode:s,options:a}=t.offeredSessionConfig;t.offeredSessionConfig=void 0,e.requestSession(s,a).then(r).catch(i)}}recenter(){const e=new le(-this.position.x,0,-this.position.z),t=new le(0,0,-1).applyQuaternion(this.quaternion);t.y=0,t.normalize();const r=Math.atan2(t.x,-t.z),i=(new ue).setFromAxisAngle(new le(0,1,0),r);this.position.add(e),this.quaternion.multiply(i),[...Object.values(this[B].controllers),...Object.values(this[B].hands)].forEach((t=>{t.position.add(e),t.quaternion.multiply(i),t.position.applyQuaternion(i)})),this[B].pendingReferenceSpaceReset=!0}get visibilityState(){return this[B].visibilityState}updateVisibilityState(e){if(!Object.values(["visible","visible-blurred","hidden"]).includes(e))throw new DOMException("Invalid XRVisibilityState value","NotSupportedError");e!==this[B].visibilityState&&(this[B].pendingVisibilityState=e)}createActionPlayer(e,t){return this[B].actionPlayer=new bt(e,t,this[B].ipd),this[B].actionPlayer}get devui(){return this[B].devui}get sem(){return this[B].sem}}const Dr={mapping:ce.XRStandard,buttons:[{id:"trigger",type:"analog",eventTrigger:"select"},{id:"squeeze",type:"analog",eventTrigger:"squeeze"},null,{id:"thumbstick",type:"binary"},{id:"x-button",type:"binary"},{id:"y-button",type:"binary"},{id:"thumbrest",type:"binary"}],axes:[null,null,{id:"thumbstick",type:"x-axis"},{id:"thumbstick",type:"y-axis"}]},Nr={mapping:ce.XRStandard,buttons:[{id:"trigger",type:"analog",eventTrigger:"select"},{id:"squeeze",type:"analog",eventTrigger:"squeeze"},null,{id:"thumbstick",type:"binary"},{id:"a-button",type:"binary"},{id:"b-button",type:"binary"},{id:"thumbrest",type:"binary"}],axes:[null,null,{id:"thumbstick",type:"x-axis"},{id:"thumbstick",type:"y-axis"}]},Or={profileId:"oculus-touch-v3",fallbackProfileIds:["oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Dr,gripOffsetMatrix:[.9925461411476135,2.0823669899527886e-8,-.12186937034130096,0,.08617465198040009,.7071067094802856,.701836109161377,0,.08617466688156128,-.7071067690849304,.7018360495567322,0,-.003979838453233242,-.015857907012104988,.04964181408286095,1],numHapticActuators:1},right:{gamepad:Nr,gripOffsetMatrix:[.9925461411476135,-8.329467959811154e-8,.12186941504478455,0,-.08617465943098068,.7071066498756409,.7018361687660217,0,-.08617471158504486,-.7071068286895752,.7018359303474426,0,.003979798872023821,-.015857888385653496,.049641866236925125,1],numHapticActuators:1}}},Br={profileId:"meta-quest-touch-pro",fallbackProfileIds:["oculus-touch-v2","oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Dr,gripOffsetMatrix:[.9925461411476135,-1.5779937356796836e-8,-.12186935544013977,0,.08617467433214188,.7071067094802856,.701836109161377,0,.0861746296286583,-.7071067690849304,.7018360495567322,0,-.003979836590588093,-.015857847407460213,.049641840159893036,1],numHapticActuators:3},right:{gamepad:Nr,gripOffsetMatrix:[.9925461411476135,9267653311439972e-26,.12186937034130096,0,-.08617467433214188,.7071067094802856,.7018361687660217,0,-.08617464452981949,-.7071067690849304,.7018360495567322,0,.003979847766458988,-.01585782691836357,.04964186251163483,1],numHapticActuators:3}}},Vr={profileId:"meta-quest-touch-plus",fallbackProfileIds:["oculus-touch-v3","oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Dr,gripOffsetMatrix:[.9925461411476135,1.0736208366779465e-8,-.12186933308839798,0,.08617459982633591,.70710688829422,.7018360495567322,0,.08617466688156128,-.7071067094802856,.7018362283706665,0,-.003979803062975407,-.015857873484492302,.04964187368750572,1],numHapticActuators:1},right:{gamepad:Nr,gripOffsetMatrix:[.9925461411476135,-2.6238110351073374e-8,.12186934053897858,0,-.0861746147274971,.7071067690849304,.7018360495567322,0,-.08617465943098068,-.7071067094802856,.701836109161377,0,.003979838453233242,-.015857869759202003,.04964182525873184,1],numHapticActuators:1}}},Ur={name:"Oculus Quest 1",controllerConfig:{profileId:"oculus-touch-v2",fallbackProfileIds:["oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Dr,gripOffsetMatrix:[.9925461411476135,4.673031295254759e-9,-.12186938524246216,0,.08617470413446426,.7071065306663513,.7018362283706665,0,.0861746296286583,-.70710688829422,.7018358707427979,0,-.003979847766458988,-.01585787907242775,.04964185878634453,1],numHapticActuators:1},right:{gamepad:Nr,gripOffsetMatrix:[.9925461411476135,3.688163374704345e-8,.12186937034130096,0,-.08617469668388367,.7071066498756409,.7018361687660217,0,-.0861746147274971,-.7071068286895752,.7018359899520874,0,.003979853354394436,-.01585787907242775,.04964182525873184,1],numHapticActuators:1}}},supportedSessionModes:["inline","immersive-vr","immersive-ar"],supportedFeatures:["viewer","local","local-floor","bounded-floor","unbounded","anchors","plane-detection","hand-tracking"],supportedFrameRates:[72,80,90],isSystemKeyboardSupported:!0,internalNominalFrameRate:72,environmentBlendModes:{"immersive-vr":it.Opaque,"immersive-ar":it.AlphaBlend},interactionMode:st.WorldSpace,userAgent:"Mozilla/5.0 (X11; Linux x86_64; Quest 1) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36"},Gr={name:"Meta Quest 2",controllerConfig:Or,supportedSessionModes:["inline","immersive-vr","immersive-ar"],supportedFeatures:["viewer","local","local-floor","bounded-floor","unbounded","anchors","plane-detection","mesh-detection","hit-test","hand-tracking"],supportedFrameRates:[72,80,90,120],isSystemKeyboardSupported:!0,internalNominalFrameRate:72,environmentBlendModes:{"immersive-vr":it.Opaque,"immersive-ar":it.AlphaBlend},interactionMode:st.WorldSpace,userAgent:"Mozilla/5.0 (X11; Linux x86_64; Quest 2) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36"},Xr={name:"Meta Quest Pro",controllerConfig:Br,supportedSessionModes:["inline","immersive-vr","immersive-ar"],supportedFeatures:["viewer","local","local-floor","bounded-floor","unbounded","anchors","plane-detection","mesh-detection","hit-test","hand-tracking"],supportedFrameRates:[72,80,90,120],isSystemKeyboardSupported:!0,internalNominalFrameRate:90,environmentBlendModes:{"immersive-vr":it.Opaque,"immersive-ar":it.AlphaBlend},interactionMode:st.WorldSpace,userAgent:"Mozilla/5.0 (X11; Linux x86_64; Quest Pro) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36"},qr={name:"Meta Quest 3",controllerConfig:Vr,supportedSessionModes:["inline","immersive-vr","immersive-ar"],supportedFeatures:["viewer","local","local-floor","bounded-floor","unbounded","anchors","plane-detection","mesh-detection","hit-test","hand-tracking","depth-sensing"],supportedFrameRates:[72,80,90,120],isSystemKeyboardSupported:!0,internalNominalFrameRate:90,environmentBlendModes:{"immersive-vr":it.Opaque,"immersive-ar":it.AlphaBlend},interactionMode:st.WorldSpace,userAgent:"Mozilla/5.0 (X11; Linux x86_64; Quest 3) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/33.0.0.x.x.x Chrome/126.0.6478.122 VR Safari/537.36"},zr=e=>{const t=[];return Array.from(e).forEach((e=>{t.push(parseFloat(e.toFixed(3)))})),t};class kr{constructor(e,t){this[D]={session:e,refSpace:t,inputMap:new Map,schemaMap:new Map,compressedFrames:[],jointRadii:new Float32Array(25),jointTransforms:new Float32Array(400)}}recordFrame(e){var t;const r=performance.now(),i=null===(t=e.getViewerPose(this[D].refSpace))||void 0===t?void 0:t.transform.matrix;if(!i)return;const s={timeStamp:r,position:u(f(),i),quaternion:d(_(),i),inputFrames:[]};this[D].session.inputSources.forEach((t=>{var r,i;if(!this[D].inputMap.has(t)){const e={handedness:t.handedness,targetRayMode:t.targetRayMode,profiles:t.profiles,hasGrip:null!=t.gripSpace,hasHand:null!=t.hand,hasGamepad:null!=t.gamepad};e.hasHand&&(e.jointSequence=Array.from(t.hand.values()).map((e=>e.jointName))),e.hasGamepad&&(e.mapping=t.gamepad.mapping,e.numButtons=t.gamepad.buttons.length,e.numAxes=t.gamepad.axes.length);const r=this[D].inputMap.size;this[D].inputMap.set(t,r),this[D].schemaMap.set(r,e)}const a=this[D].inputMap.get(t),n=this[D].schemaMap.get(a),o=null===(r=e.getPose(t.targetRaySpace,this[D].refSpace))||void 0===r?void 0:r.transform.matrix;if(o){const r={index:a,targetRayTransform:{position:u(f(),o),quaternion:d(_(),o)}};if(n.hasGrip){const s=null===(i=e.getPose(t.gripSpace,this[D].refSpace))||void 0===i?void 0:i.transform.matrix;if(s){const e=u(f(),s),t=d(_(),s);r.gripTransform={position:e,quaternion:t}}}if(n.hasHand){const i=Array.from(t.hand.values());let s=!0;if(s&&(s=e.fillPoses(i,t.targetRaySpace,this[D].jointTransforms)),s&&(s=e.fillJointRadii(i,this[D].jointRadii)),s){const e={};for(let t=0;t<25;t++){const r=this[D].jointTransforms.slice(16*t,16*(t+1)),s=this[D].jointRadii[t],a=u(f(),r),n=d(_(),r);e[i[t].jointName]={position:a,quaternion:n,radius:s}}r.hand=e}}if(n.hasGamepad){const e={buttons:t.gamepad.buttons.map((e=>e?[e.pressed?1:0,e.touched?1:0,e.value]:null)),axes:Array.from(t.gamepad.axes)};r.gamepad=e}s.inputFrames.push(r)}})),this[D].compressedFrames.push(this.compressActionFrame(s))}compressActionFrame(e){const t=[Math.round(10*e.timeStamp)/10,...zr(e.position),...zr(e.quaternion)];return e.inputFrames.forEach((e=>{const r=e.index,i=this[D].schemaMap.get(r),s=[r,...zr(e.targetRayTransform.position),...zr(e.targetRayTransform.quaternion)];if(i.hasGrip&&s.push([...zr(e.gripTransform.position),...zr(e.gripTransform.quaternion)]),i.hasHand){const t=[];Object.values(e.hand).forEach((({position:e,quaternion:r,radius:i})=>{t.push(...zr(e),...zr(r),parseFloat(i.toFixed(3)))})),s.push(t)}i.hasGamepad&&s.push([...e.gamepad.buttons,...e.gamepad.axes]),t.push(s)})),t}log(){const e={schema:Array.from(this[D].schemaMap.entries()),frames:this[D].compressedFrames};console.log(JSON.stringify(e))}}export{kr as ActionRecorder,_e as NativeMesh,Ie as NativePlane,C as P_ACTION_PLAYER,D as P_ACTION_RECORDER,N as P_ANCHOR,O as P_CONTROLLER,B as P_DEVICE,G as P_FRAME,X as P_GAMEPAD,V as P_HAND_INPUT,ae as P_HIT_TEST,z as P_INPUT_SOURCE,W as P_JOINT_POSE,Z as P_JOINT_SPACE,H as P_MESH,j as P_PLANE,Y as P_POSE,se as P_RAY,ee as P_REF_SPACE,$ as P_RENDER_STATE,K as P_RIGID_TRANSFORM,J as P_SESSION,te as P_SPACE,q as P_SYSTEM,U as P_TRACKED_INPUT,re as P_VIEW,Q as P_VIEWER_POSE,ie as P_VIEWPORT,k as P_WEBGL_LAYER,Le as XRAnchor,Ce as XRAnchorSet,Cr as XRDevice,rt as XRFrame,ot as XRHand,ye as XRInputSource,ge as XRInputSourceArray,ve as XRInputSourceEvent,Xe as XRInputSourcesChangeEvent,Ke as XRJointPose,ht as XRJointSpace,Et as XRLayer,Ee as XRMesh,Re as XRMeshSet,Fe as XRPlane,Pe as XRPlaneSet,Qe as XRPose,Ve as XRRay,He as XRReferenceSpace,At as XRReferenceSpaceEvent,je as XRRenderState,Oe as XRRigidTransform,be as XRSemanticLabels,nt as XRSession,We as XRSessionEvent,ne as XRSpace,Ft as XRSystem,Ye as XRView,$e as XRViewerPose,Pt as XRViewport,_t as XRWebGLLayer,Gr as metaQuest2,qr as metaQuest3,Xr as metaQuestPro,Ur as oculusQuest1};
|