iwer 2.2.0 → 2.2.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 +159 -5
- package/build/iwer.min.js +12 -12
- package/build/iwer.module.js +158 -6
- package/build/iwer.module.min.js +12 -12
- package/lib/depth/XRDepthInformation.d.ts +38 -0
- package/lib/depth/XRDepthInformation.d.ts.map +1 -0
- package/lib/depth/XRDepthInformation.js +55 -0
- package/lib/depth/XRDepthInformation.js.map +1 -0
- package/lib/device/XRDevice.d.ts +3 -1
- package/lib/device/XRDevice.d.ts.map +1 -1
- package/lib/device/XRDevice.js.map +1 -1
- package/lib/frameloop/XRFrame.d.ts +4 -0
- package/lib/frameloop/XRFrame.d.ts.map +1 -1
- package/lib/frameloop/XRFrame.js +12 -1
- package/lib/frameloop/XRFrame.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/private.d.ts +1 -0
- package/lib/private.d.ts.map +1 -1
- package/lib/private.js +1 -0
- package/lib/private.js.map +1 -1
- package/lib/remote/RemoteControlInterface.d.ts.map +1 -1
- package/lib/remote/RemoteControlInterface.js +50 -4
- package/lib/remote/RemoteControlInterface.js.map +1 -1
- package/lib/session/XRSession.d.ts +7 -0
- package/lib/session/XRSession.d.ts.map +1 -1
- package/lib/session/XRSession.js +42 -0
- package/lib/session/XRSession.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/build/iwer.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).IWER={})}(this,function(e){"use strict";var t=1e-6,i="undefined"!=typeof Float32Array?Float32Array:Array;function r(){var e=new i(16);return i!=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 s(e){var t=new i(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function n(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 i=t[0],r=t[1],s=t[2],n=t[3],a=t[4],o=t[5],h=t[6],l=t[7],c=t[8],u=t[9],d=t[10],p=t[11],f=t[12],m=t[13],x=t[14],g=t[15],v=i*o-r*a,y=i*h-s*a,T=i*l-n*a,w=r*h-s*o,S=r*l-n*o,_=s*l-n*h,E=c*m-u*f,R=c*x-d*f,b=c*g-p*f,M=u*x-d*m,A=u*g-p*m,P=d*g-p*x,I=v*P-y*A+T*M+w*b-S*R+_*E;return I?(I=1/I,e[0]=(o*P-h*A+l*M)*I,e[1]=(s*A-r*P-n*M)*I,e[2]=(m*_-x*S+g*w)*I,e[3]=(d*S-u*_-p*w)*I,e[4]=(h*b-a*P-l*R)*I,e[5]=(i*P-s*b+n*R)*I,e[6]=(x*T-f*_-g*y)*I,e[7]=(c*_-d*T+p*y)*I,e[8]=(a*A-o*b+l*E)*I,e[9]=(r*b-i*A-n*E)*I,e[10]=(f*S-m*T+g*v)*I,e[11]=(u*T-c*S-p*v)*I,e[12]=(o*R-a*M-h*E)*I,e[13]=(i*M-r*R+s*E)*I,e[14]=(m*y-f*w-x*v)*I,e[15]=(c*w-u*y+d*v)*I,e):null}function o(e,t,i){var r=t[0],s=t[1],n=t[2],a=t[3],o=t[4],h=t[5],l=t[6],c=t[7],u=t[8],d=t[9],p=t[10],f=t[11],m=t[12],x=t[13],g=t[14],v=t[15],y=i[0],T=i[1],w=i[2],S=i[3];return e[0]=y*r+T*o+w*u+S*m,e[1]=y*s+T*h+w*d+S*x,e[2]=y*n+T*l+w*p+S*g,e[3]=y*a+T*c+w*f+S*v,y=i[4],T=i[5],w=i[6],S=i[7],e[4]=y*r+T*o+w*u+S*m,e[5]=y*s+T*h+w*d+S*x,e[6]=y*n+T*l+w*p+S*g,e[7]=y*a+T*c+w*f+S*v,y=i[8],T=i[9],w=i[10],S=i[11],e[8]=y*r+T*o+w*u+S*m,e[9]=y*s+T*h+w*d+S*x,e[10]=y*n+T*l+w*p+S*g,e[11]=y*a+T*c+w*f+S*v,y=i[12],T=i[13],w=i[14],S=i[15],e[12]=y*r+T*o+w*u+S*m,e[13]=y*s+T*h+w*d+S*x,e[14]=y*n+T*l+w*p+S*g,e[15]=y*a+T*c+w*f+S*v,e}function h(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 l(e,i,r){var s,n,a,o=r[0],h=r[1],l=r[2],c=Math.sqrt(o*o+h*h+l*l);return c<t?null:(o*=c=1/c,h*=c,l*=c,s=Math.sin(i),a=1-(n=Math.cos(i)),e[0]=o*o*a+n,e[1]=h*o*a+l*s,e[2]=l*o*a-h*s,e[3]=0,e[4]=o*h*a-l*s,e[5]=h*h*a+n,e[6]=l*h*a+o*s,e[7]=0,e[8]=o*l*a+h*s,e[9]=h*l*a-o*s,e[10]=l*l*a+n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)}function c(e,t,i){var r=t[0],s=t[1],n=t[2],a=t[3],o=r+r,h=s+s,l=n+n,c=r*o,u=r*h,d=r*l,p=s*h,f=s*l,m=n*l,x=a*o,g=a*h,v=a*l;return e[0]=1-(p+m),e[1]=u+v,e[2]=d-g,e[3]=0,e[4]=u-v,e[5]=1-(c+m),e[6]=f+x,e[7]=0,e[8]=d+g,e[9]=f-x,e[10]=1-(c+p),e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function u(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function d(e,t){var i=t[0],r=t[1],s=t[2],n=t[4],a=t[5],o=t[6],h=t[8],l=t[9],c=t[10];return e[0]=Math.sqrt(i*i+r*r+s*s),e[1]=Math.sqrt(n*n+a*a+o*o),e[2]=Math.sqrt(h*h+l*l+c*c),e}function p(e,t){var r=new i(3);d(r,t);var s=1/r[0],n=1/r[1],a=1/r[2],o=t[0]*s,h=t[1]*n,l=t[2]*a,c=t[4]*s,u=t[5]*n,p=t[6]*a,f=t[8]*s,m=t[9]*n,x=t[10]*a,g=o+u+x,v=0;return g>0?(v=2*Math.sqrt(g+1),e[3]=.25*v,e[0]=(p-m)/v,e[1]=(f-l)/v,e[2]=(h-c)/v):o>u&&o>x?(v=2*Math.sqrt(1+o-u-x),e[3]=(p-m)/v,e[0]=.25*v,e[1]=(h+c)/v,e[2]=(f+l)/v):u>x?(v=2*Math.sqrt(1+u-o-x),e[3]=(f-l)/v,e[0]=(h+c)/v,e[1]=.25*v,e[2]=(p+m)/v):(v=2*Math.sqrt(1+x-o-u),e[3]=(h-c)/v,e[0]=(f+l)/v,e[1]=(p+m)/v,e[2]=.25*v),e}var f=function(e,t,i,r,s){var n=1/Math.tan(t/2);if(e[0]=n/i,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=n,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 a=1/(r-s);e[10]=(s+r)*a,e[14]=2*s*r*a}else e[10]=-1,e[14]=-2*r;return e};function m(){var e=new i(3);return i!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function x(e,t,r){var s=new i(3);return s[0]=e,s[1]=t,s[2]=r,s}function g(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function v(e,t,i,r){return e[0]=t,e[1]=i,e[2]=r,e}function y(e,t){var i=t[0],r=t[1],s=t[2],n=i*i+r*r+s*s;return n>0&&(n=1/Math.sqrt(n)),e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e}function T(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function w(e,t,i){var r=t[0],s=t[1],n=t[2],a=i[0],o=i[1],h=i[2];return e[0]=s*h-n*o,e[1]=n*a-r*h,e[2]=r*o-s*a,e}function S(e,t,i,r){var s=t[0],n=t[1],a=t[2];return e[0]=s+r*(i[0]-s),e[1]=n+r*(i[1]-n),e[2]=a+r*(i[2]-a),e}function _(){var e=new i(4);return i!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function E(e,t,i,r,s){return e[0]=t,e[1]=i,e[2]=r,e[3]=s,e}function R(e,t,i){var r=t[0],s=t[1],n=t[2],a=t[3];return e[0]=i[0]*r+i[4]*s+i[8]*n+i[12]*a,e[1]=i[1]*r+i[5]*s+i[9]*n+i[13]*a,e[2]=i[2]*r+i[6]*s+i[10]*n+i[14]*a,e[3]=i[3]*r+i[7]*s+i[11]*n+i[15]*a,e}function b(){var e=new i(4);return i!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function M(e,t,i){i*=.5;var r=Math.sin(i);return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=Math.cos(i),e}function A(e,i,r,s){var n,a,o,h,l,c=i[0],u=i[1],d=i[2],p=i[3],f=r[0],m=r[1],x=r[2],g=r[3];return(a=c*f+u*m+d*x+p*g)<0&&(a=-a,f=-f,m=-m,x=-x,g=-g),1-a>t?(n=Math.acos(a),o=Math.sin(n),h=Math.sin((1-s)*n)/o,l=Math.sin(s*n)/o):(h=1-s,l=s),e[0]=h*c+l*f,e[1]=h*u+l*m,e[2]=h*d+l*x,e[3]=h*p+l*g,e}m(),function(){var e=_()}();var P,I=function(e,t,r,s){var n=new i(4);return n[0]=e,n[1]=t,n[2]=r,n[3]=s,n},F=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},L=E,C=function(e,t){var i=t[0],r=t[1],s=t[2],n=t[3],a=i*i+r*r+s*s+n*n;return a>0&&(a=1/Math.sqrt(a)),e[0]=i*a,e[1]=r*a,e[2]=s*a,e[3]=n*a,e};m(),x(1,0,0),x(0,1,0),b(),b(),P=new i(9),i!=Float32Array&&(P[1]=0,P[2]=0,P[3]=0,P[5]=0,P[6]=0,P[7]=0),P[0]=1,P[4]=1,P[8]=1;const D=Symbol("@iwer/action-player"),N=Symbol("@iwer/action-recorder"),O=Symbol("@iwer/xr-anchor"),V=Symbol("@iwer/xr-controller"),B=Symbol("@iwer/xr-device"),G=Symbol("@iwer/xr-hand-input"),U=Symbol("@iwer/xr-tracked-input"),X=Symbol("@iwer/xr-frame"),z=Symbol("@iwer/gamepad"),q=Symbol("@iwer/xr-system"),k=Symbol("@iwer/xr-input-source"),H=Symbol("@iwer/xr-webgl-layer"),j=Symbol("@iwer/xr-mesh"),W=Symbol("@iwer/xr-plane"),Y=Symbol("@iwer/xr-joint-pose"),Q=Symbol("@iwer/xr-pose"),$=Symbol("@iwer/xr-viewer-pose"),K=Symbol("@iwer/xr-rigid-transform"),J=Symbol("@iwer/xr-render-state"),Z=Symbol("@iwer/xr-session"),ee=Symbol("@iwer/xr-joint-space"),te=Symbol("@iwer/xr-reference-space"),ie=Symbol("@iwer/xr-space"),re=Symbol("@iwer/xr-view"),se=Symbol("@iwer/xr-viewport"),ne=Symbol("@iwer/xr-ray"),ae=Symbol("@iwer/xr-hit-test");class oe extends EventTarget{constructor(e,t){super(),this[ie]={parentSpace:e,offsetMatrix:t?s(t):r(),emulated:!0}}}class he extends oe{constructor(){super(void 0,r())}}class le{static updateOffsetPosition(e,t){h(e[ie].offsetMatrix,t)}static updateOffsetQuaternion(e,t){const i=e[ie].offsetMatrix,r=m();u(r,i),c(i,t,r)}static updateOffsetMatrix(e,t){n(e[ie].offsetMatrix,t)}static calculateGlobalOffsetMatrix(e,t=r()){return o(t,e[ie].parentSpace?le.calculateGlobalOffsetMatrix(e[ie].parentSpace):r(),e[ie].offsetMatrix),t}}class ce{constructor(e=0,t=0,i=0){this.vec3=x(e,t,i),this.tempVec3=m()}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,i){return v(this.vec3,e,t,i),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),y(this.vec3,this.tempVec3),this}add(e){return g(this.tempVec3,this.vec3),function(e,t,i){e[0]=t[0]+i[0],e[1]=t[1]+i[1],e[2]=t[2]+i[2]}(this.vec3,this.tempVec3,e.vec3),this}applyQuaternion(e){return g(this.tempVec3,this.vec3),function(e,t,i){var r=i[0],s=i[1],n=i[2],a=i[3],o=t[0],h=t[1],l=t[2],c=s*l-n*h,u=n*o-r*l,d=r*h-s*o;c+=c,u+=u,d+=d,e[0]=o+a*c+s*d-n*u,e[1]=h+a*u+n*c-r*d,e[2]=l+a*d+r*u-s*c}(this.vec3,this.tempVec3,e.quat),this}}class ue{constructor(e=0,t=0,i=0,r=1){this.quat=I(e,t,i,r),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,i,r){return L(this.quat,e,t,i,r),this}clone(){return new ue(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 F(this.tempQuat,this.quat),C(this.quat,this.tempQuat),this}invert(){return F(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 F(this.tempQuat,this.quat),function(e,t,i){var r=t[0],s=t[1],n=t[2],a=t[3],o=i[0],h=i[1],l=i[2],c=i[3];e[0]=r*c+a*o+s*l-n*h,e[1]=s*c+a*h+n*o-r*l,e[2]=n*c+a*l+r*h-s*o,e[3]=a*c-r*o-s*h-n*l}(this.quat,this.tempQuat,e.quat),this}setFromAxisAngle(e,t){return M(this.quat,e.vec3,t),this}}function de(e){return{x:e.x,y:e.y,z:e.z}}function pe(e){return{x:e.x,y:e.y,z:e.z,w:e.w}}function fe(e){const{x:t,y:i,z:r,w:s}=e,n=180/Math.PI,a=Math.max(-1,Math.min(1,2*(s*t-i*r)));let o;o=Math.abs(a)>=1?Math.sign(a)*Math.PI/2:Math.asin(a);const h=2*(s*i+t*r),l=1-2*(t*t+i*i),c=2*(s*r+t*i),u=1-2*(t*t+r*r);return{pitch:o*n,yaw:Math.atan2(h,l)*n,roll:Math.atan2(c,u)*n}}function me(e){var t,i,r;const s=Math.PI/180,n=(null!==(t=e.pitch)&&void 0!==t?t:0)*s,a=(null!==(i=e.yaw)&&void 0!==i?i:0)*s,o=(null!==(r=e.roll)&&void 0!==r?r:0)*s,h=Math.cos(.5*n),l=Math.sin(.5*n),c=Math.cos(.5*a),u=Math.sin(.5*a),d=Math.cos(.5*o),p=Math.sin(.5*o);return{w:h*c*d+l*u*p,x:l*c*d+h*u*p,y:h*u*d-l*c*p,z:h*c*p-l*u*d}}function xe(e,t){const i=t.x-e.x,r=t.y-e.y,s=t.z-e.z,n=Math.sqrt(i*i+r*r+s*s);return 0===n?{x:0,y:0,z:-1}:{x:i/n,y:r/n,z:s/n}}function ge(e,t={x:0,y:1,z:0}){const i=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(0===i)return{x:0,y:0,z:0,w:1};const r=e.x/i,s=e.y/i,n=e.z/i,a={x:s*t.z-n*t.y,y:n*t.x-r*t.z,z:r*t.y-s*t.x},o=Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z);if(0===o){const e={x:1,y:0,z:0};a.x=s*e.z-n*e.y,a.y=n*e.x-r*e.z,a.z=r*e.y-s*e.x;const t=Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z);a.x/=t,a.y/=t,a.z/=t}else a.x/=o,a.y/=o,a.z/=o;const h={x:a.y*n-a.z*s,y:a.z*r-a.x*n,z:a.x*s-a.y*r},l=a.x,c=h.x,u=-r,d=a.y,p=h.y,f=-s,m=a.z,x=h.z,g=-n,v=l+p+g;let y,T,w,S;if(v>0){const e=.5/Math.sqrt(v+1);y=.25/e,T=(x-f)*e,w=(u-m)*e,S=(d-c)*e}else if(l>p&&l>g){const e=2*Math.sqrt(1+l-p-g);y=(x-f)/e,T=.25*e,w=(c+d)/e,S=(u+m)/e}else if(p>g){const e=2*Math.sqrt(1+p-l-g);y=(u-m)/e,T=(c+d)/e,w=.25*e,S=(f+x)/e}else{const e=2*Math.sqrt(1+g-l-p);y=(d-c)/e,T=(u+m)/e,w=(f+x)/e,S=.25*e}const _=Math.sqrt(T*T+w*w+S*S+y*y);return _>0&&(T/=_,w/=_,S/=_,y/=_),{x:T,y:w,z:S,w:y}}function ve(e,t=5e3){return new Promise((i,r)=>{const s=Date.now(),n=()=>{e()?i():Date.now()-s>t?r(new Error("Timeout waiting for condition")):requestAnimationFrame(n)};n()})}function ye(e){return function(e){return"pitch"in e||"yaw"in e||"roll"in e}(e)?me(e):e}function Te(e,t,i){return e+(t-e)*i}class we{constructor(e){this.commandQueue=[],this._isCaptured=!1,this.releaseTimer=null,this.actionIdCounter=0,this.RELEASE_TIMEOUT_MS=3e4,this.device=e}generateActionId(){return"action_"+ ++this.actionIdCounter}get isCaptured(){return this._isCaptured}get queueLength(){return this.commandQueue.length}enqueueDiscrete(e,t){return new Promise((i,r)=>{const s={type:"discrete",id:this.generateActionId(),method:e,params:t,resolve:i,reject:r};this.commandQueue.push(s)})}enqueueDuration(e,t,i,r,s){return new Promise((n,a)=>{const o={type:"duration",id:this.generateActionId(),method:e,params:t,durationMs:i,elapsedMs:0,startState:r,targetState:s,resolve:n,reject:a};this.commandQueue.push(o)})}update(e){if(0!==this.commandQueue.length){for(this.cancelReleaseTimer(),this._isCaptured||(this._isCaptured=!0,this.device.controlMode="programmatic");this.commandQueue.length>0;){const t=this.commandQueue[0];if("discrete"===t.type){try{const e=this.executeDiscreteAction(t);t.resolve(e)}catch(e){t.reject(e)}this.commandQueue.shift()}else{if(t.elapsedMs+=e,!(t.elapsedMs>=t.durationMs)){const e=t.elapsedMs/t.durationMs;this.applyDurationLerpState(t,e);break}this.applyDurationFinalState(t),t.resolve(this.getDurationResult(t)),this.commandQueue.shift()}}this.device.notifyStateChange(),0===this.commandQueue.length&&this.startReleaseTimer()}}startReleaseTimer(){this.cancelReleaseTimer(),this.releaseTimer=setTimeout(()=>{this._isCaptured=!1,this.device.controlMode="manual",this.releaseTimer=null},this.RELEASE_TIMEOUT_MS)}cancelReleaseTimer(){null!==this.releaseTimer&&(clearTimeout(this.releaseTimer),this.releaseTimer=null)}getDeviceTransform(e){switch(e){case"headset":return{position:de(this.device.position),orientation:pe(this.device.quaternion)};case"controller-left":{const e=this.device.controllers.left;if(!e)throw new Error("Left controller not available");return{position:de(e.position),orientation:pe(e.quaternion)}}case"controller-right":{const e=this.device.controllers.right;if(!e)throw new Error("Right controller not available");return{position:de(e.position),orientation:pe(e.quaternion)}}case"hand-left":{const e=this.device.hands.left;if(!e)throw new Error("Left hand not available");return{position:de(e.position),orientation:pe(e.quaternion)}}case"hand-right":{const e=this.device.hands.right;if(!e)throw new Error("Right hand not available");return{position:de(e.position),orientation:pe(e.quaternion)}}default:throw new Error(`Unknown device: ${e}`)}}setDeviceTransform(e,t,i){switch(e){case"headset":t&&this.device.position.set(t.x,t.y,t.z),i&&this.device.quaternion.set(i.x,i.y,i.z,i.w);break;case"controller-left":{const e=this.device.controllers.left;if(!e)throw new Error("Left controller not available");t&&e.position.set(t.x,t.y,t.z),i&&e.quaternion.set(i.x,i.y,i.z,i.w);break}case"controller-right":{const e=this.device.controllers.right;if(!e)throw new Error("Right controller not available");t&&e.position.set(t.x,t.y,t.z),i&&e.quaternion.set(i.x,i.y,i.z,i.w);break}case"hand-left":{const e=this.device.hands.left;if(!e)throw new Error("Left hand not available");t&&e.position.set(t.x,t.y,t.z),i&&e.quaternion.set(i.x,i.y,i.z,i.w);break}case"hand-right":{const e=this.device.hands.right;if(!e)throw new Error("Right hand not available");t&&e.position.set(t.x,t.y,t.z),i&&e.quaternion.set(i.x,i.y,i.z,i.w);break}default:throw new Error(`Unknown device: ${e}`)}}transformXROriginToGlobal(e){var t,i;const r=this.device.activeSession;if(!r)return e;const s=null===(t=r[Z])||void 0===t?void 0:t.referenceSpaces;if(!s||0===s.length)return e;const n=null===(i=s[0][ie])||void 0===i?void 0:i.offsetMatrix;if(!n)return e;const a=x(e.x,e.y,e.z);return function(e,t,i){var r=t[0],s=t[1],n=t[2],a=i[3]*r+i[7]*s+i[11]*n+i[15];a=a||1,e[0]=(i[0]*r+i[4]*s+i[8]*n+i[12])/a,e[1]=(i[1]*r+i[5]*s+i[9]*n+i[13])/a,e[2]=(i[2]*r+i[6]*s+i[10]*n+i[14])/a}(a,a,n),{x:a[0],y:a[1],z:a[2]}}getDeviceSelectValue(e){var t,i,r,s,n,a,o,h;switch(e){case"controller-left":return null!==(i=null===(t=this.device.controllers.left)||void 0===t?void 0:t.getButtonValue("trigger"))&&void 0!==i?i:0;case"controller-right":return null!==(s=null===(r=this.device.controllers.right)||void 0===r?void 0:r.getButtonValue("trigger"))&&void 0!==s?s:0;case"hand-left":return null!==(a=null===(n=this.device.hands.left)||void 0===n?void 0:n.pinchValue)&&void 0!==a?a:0;case"hand-right":return null!==(h=null===(o=this.device.hands.right)||void 0===o?void 0:o.pinchValue)&&void 0!==h?h:0;default:throw new Error(`Unknown input device: ${e}`)}}setDeviceSelectValue(e,t){var i,r,s,n;switch(e){case"controller-left":null===(i=this.device.controllers.left)||void 0===i||i.updateButtonValue("trigger",t);break;case"controller-right":null===(r=this.device.controllers.right)||void 0===r||r.updateButtonValue("trigger",t);break;case"hand-left":null===(s=this.device.hands.left)||void 0===s||s.updatePinchValue(t);break;case"hand-right":null===(n=this.device.hands.right)||void 0===n||n.updatePinchValue(t);break;default:throw new Error(`Unknown input device: ${e}`)}}setDeviceConnected(e,t){switch(e){case"controller-left":this.device.controllers.left&&(this.device.controllers.left.connected=t);break;case"controller-right":this.device.controllers.right&&(this.device.controllers.right.connected=t);break;case"hand-left":this.device.hands.left&&(this.device.hands.left.connected=t);break;case"hand-right":this.device.hands.right&&(this.device.hands.right.connected=t);break;default:throw new Error(`Unknown input device: ${e}`)}}executeDiscreteAction(e){const{method:t,params:i}=e;switch(t){case"get_session_status":return this.executeGetSessionStatus();case"accept_session":return this.executeAcceptSession();case"end_session":return this.executeEndSession();case"get_transform":return this.executeGetTransform(i);case"set_transform":return this.executeSetTransform(i);case"look_at":return this.executeLookAt(i);case"set_input_mode":return this.executeSetInputMode(i);case"set_connected":return this.executeSetConnected(i);case"get_select_value":return this.executeGetSelectValue(i);case"set_select_value":return this.executeSetSelectValue(i);case"get_gamepad_state":return this.executeGetGamepadState(i);case"set_gamepad_state":return this.executeSetGamepadState(i);case"get_device_state":return this.executeGetDeviceState();case"set_device_state":return this.executeSetDeviceState(i);case"capture_canvas":return this.executeCaptureCanvas(i);case"_select_press":{const e=i.device;return void this.setDeviceSelectValue(e,1)}case"_select_release":{const e=i.device;return void this.setDeviceSelectValue(e,0)}default:throw new Error(`Unknown method: ${t}`)}}executeGetSessionStatus(){const e=this.device.activeSession;return{deviceName:this.device.name,isRuntimeInstalled:!0,sessionActive:!!e,sessionOffered:this.device.sessionOffered,sessionMode:e?e.mode:null,enabledFeatures:e?Array.from(e.enabledFeatures||[]):[],visibilityState:this.device.visibilityState}}executeAcceptSession(){if(!this.device.sessionOffered)throw new Error("No session has been offered");return this.device.grantOfferedSession(),{success:!0}}executeEndSession(){const e=this.device.activeSession;if(!e)throw new Error("No active session");return e.end(),{success:!0}}executeGetTransform(e){const{device:t}=e,i=this.getDeviceTransform(t);return{device:t,position:i.position,orientation:i.orientation,euler:fe(i.orientation)}}executeSetTransform(e){const{device:t,position:i,orientation:r}=e,s=r?ye(r):void 0;this.setDeviceTransform(t,i,s);const n=this.getDeviceTransform(t);return{device:t,position:n.position,orientation:n.orientation}}executeLookAt(e){const{device:t,target:i,moveToDistance:r}=e,s=this.getDeviceTransform(t),n=this.transformXROriginToGlobal(i),a=xe(s.position,n),o="headset"===t?function(e){const t=Math.sqrt(e.x*e.x+e.z*e.z);let i=0;t>1e-4&&(i=Math.atan2(-e.x,-e.z));const r=Math.atan2(e.y,t),s=180/Math.PI;return me({pitch:r*s,yaw:i*s,roll:0})}(a):ge(a);let h;void 0!==r&&(h={x:n.x-a.x*r,y:n.y-a.y*r,z:n.z-a.z*r}),this.setDeviceTransform(t,h,o);const l=this.getDeviceTransform(t);return{device:t,position:l.position,orientation:l.orientation}}executeSetInputMode(e){var t,i,r,s;const{mode:n}=e;this.device.primaryInputMode=n;const a=[];return"controller"===n?((null===(t=this.device.controllers.left)||void 0===t?void 0:t.connected)&&a.push("controller-left"),(null===(i=this.device.controllers.right)||void 0===i?void 0:i.connected)&&a.push("controller-right")):((null===(r=this.device.hands.left)||void 0===r?void 0:r.connected)&&a.push("hand-left"),(null===(s=this.device.hands.right)||void 0===s?void 0:s.connected)&&a.push("hand-right")),{mode:n,activeDevices:a}}executeSetConnected(e){const{device:t,connected:i}=e;return this.setDeviceConnected(t,i),{device:t,connected:i}}executeGetSelectValue(e){const{device:t}=e;return{device:t,value:this.getDeviceSelectValue(t)}}executeSetSelectValue(e){const{device:t,value:i}=e;return this.setDeviceSelectValue(t,i),{device:t,value:i}}executeGetGamepadState(e){const{device:t}=e,i="controller-left"===t?"left":"right",r=this.device.controllers[i];if(!r)throw new Error(`Controller ${i} not available`);const s=["trigger","squeeze","thumbstick","left"===i?"x-button":"a-button","left"===i?"y-button":"b-button","thumbrest"].map((e,t)=>({index:t,name:e.replace("x-button","x").replace("y-button","y").replace("a-button","a").replace("b-button","b"),value:r.getButtonValue(e),touched:r.getButtonTouched(e),pressed:r.getButtonValue(e)>.5})),n=r.getAxes(),a=[{index:0,name:"thumbstick-x",value:n.x},{index:1,name:"thumbstick-y",value:n.y}];return{device:t,connected:r.connected,buttons:s,axes:a}}executeSetGamepadState(e){const{device:t,buttons:i,axes:r}=e,s="controller-left"===t?"left":"right",n=this.device.controllers[s];if(!n)throw new Error(`Controller ${s} not available`);let a=0,o=0;const h=["trigger","squeeze","thumbstick","left"===s?"x-button":"a-button","left"===s?"y-button":"b-button","thumbrest"];if(i)for(const e of i){const t=h[e.index];t&&(n.updateButtonValue(t,e.value),void 0!==e.touched&&n.updateButtonTouch(t,e.touched),a++)}if(r){let e,t;for(const i of r)0===i.index?(e=i.value,o++):1===i.index&&(t=i.value,o++);if(void 0!==e||void 0!==t){const i=n.getAxes();n.updateAxes("thumbstick",null!=e?e:i.x,null!=t?t:i.y)}}return{device:t,buttonsSet:a,axesSet:o}}executeGetDeviceState(){var e,t,i,r,s,n,a,o,h,l,c,u,d,p,f,m,x,g,v,y,T,w,S,_;return{headset:{position:de(this.device.position),orientation:pe(this.device.quaternion)},inputMode:this.device.primaryInputMode,controllers:{left:{connected:null!==(t=null===(e=this.device.controllers.left)||void 0===e?void 0:e.connected)&&void 0!==t&&t,position:de(null!==(r=null===(i=this.device.controllers.left)||void 0===i?void 0:i.position)&&void 0!==r?r:{x:0,y:0,z:0}),orientation:pe(null!==(n=null===(s=this.device.controllers.left)||void 0===s?void 0:s.quaternion)&&void 0!==n?n:{x:0,y:0,z:0,w:1})},right:{connected:null!==(o=null===(a=this.device.controllers.right)||void 0===a?void 0:a.connected)&&void 0!==o&&o,position:de(null!==(l=null===(h=this.device.controllers.right)||void 0===h?void 0:h.position)&&void 0!==l?l:{x:0,y:0,z:0}),orientation:pe(null!==(u=null===(c=this.device.controllers.right)||void 0===c?void 0:c.quaternion)&&void 0!==u?u:{x:0,y:0,z:0,w:1})}},hands:{left:{connected:null!==(p=null===(d=this.device.hands.left)||void 0===d?void 0:d.connected)&&void 0!==p&&p,position:de(null!==(m=null===(f=this.device.hands.left)||void 0===f?void 0:f.position)&&void 0!==m?m:{x:0,y:0,z:0}),orientation:pe(null!==(g=null===(x=this.device.hands.left)||void 0===x?void 0:x.quaternion)&&void 0!==g?g:{x:0,y:0,z:0,w:1})},right:{connected:null!==(y=null===(v=this.device.hands.right)||void 0===v?void 0:v.connected)&&void 0!==y&&y,position:de(null!==(w=null===(T=this.device.hands.right)||void 0===T?void 0:T.position)&&void 0!==w?w:{x:0,y:0,z:0}),orientation:pe(null!==(_=null===(S=this.device.hands.right)||void 0===S?void 0:S.quaternion)&&void 0!==_?_:{x:0,y:0,z:0,w:1})}},stereoEnabled:this.device.stereoEnabled,fov:this.device.fovy*(180/Math.PI)}}executeSetDeviceState(e){const{state:t}=e;return t?(t.headset&&(t.headset.position&&this.device.position.set(t.headset.position.x,t.headset.position.y,t.headset.position.z),t.headset.orientation&&this.device.quaternion.set(t.headset.orientation.x,t.headset.orientation.y,t.headset.orientation.z,t.headset.orientation.w)),void 0!==t.inputMode&&(this.device.primaryInputMode=t.inputMode),void 0!==t.stereoEnabled&&(this.device.stereoEnabled=t.stereoEnabled),void 0!==t.fov&&(this.device.fovy=t.fov*(Math.PI/180)),t.controllers&&(this.applyInputState("controller-left",t.controllers.left),this.applyInputState("controller-right",t.controllers.right)),t.hands&&(this.applyInputState("hand-left",t.hands.left),this.applyInputState("hand-right",t.hands.right))):(this.device.position.set(0,1.6,0),this.device.quaternion.set(0,0,0,1),this.device.primaryInputMode="controller",this.device.stereoEnabled=!1,this.device.controllers.left&&(this.device.controllers.left.position.set(-.2,1.4,-.3),this.device.controllers.left.quaternion.set(0,0,0,1),this.device.controllers.left.connected=!0),this.device.controllers.right&&(this.device.controllers.right.position.set(.2,1.4,-.3),this.device.controllers.right.quaternion.set(0,0,0,1),this.device.controllers.right.connected=!0),this.device.hands.left&&(this.device.hands.left.position.set(-.15,1.3,-.4),this.device.hands.left.quaternion.set(0,0,0,1),this.device.hands.left.connected=!0),this.device.hands.right&&(this.device.hands.right.position.set(.15,1.3,-.4),this.device.hands.right.quaternion.set(0,0,0,1),this.device.hands.right.connected=!0)),{state:this.executeGetDeviceState()}}applyInputState(e,t){t&&(void 0!==t.connected&&this.setDeviceConnected(e,t.connected),(t.position||t.orientation)&&this.setDeviceTransform(e,t.position,t.orientation))}executeCaptureCanvas(e){const{maxWidth:t=800,format:i="png",quality:r=.92}=e;let s=this.device.appCanvas;if(!s){const e=document.querySelectorAll("canvas");if(1===e.length)s=e[0];else if(e.length>1){let t=null,i=0;e.forEach(e=>{const r=e.getBoundingClientRect(),s=r.width*r.height;s>i&&r.width>0&&r.height>0&&(i=s,t=e)}),s=t}}if(!s)throw new Error("No canvas available. Either start an XR session or ensure an app canvas is in the DOM.");const n=document.createElement("canvas"),a=n.getContext("2d");if(!a)throw new Error("Failed to create canvas context");const o=s.height/s.width,h=Math.min(s.width,t),l=Math.round(h*o);n.width=h,n.height=l,a.drawImage(s,0,0,h,l);const c=`image/${i}`;return{imageData:n.toDataURL(c,r).split(",")[1],width:h,height:l,format:i,timestamp:Date.now()}}applyDurationLerpState(e,t){const{startState:i,targetState:r,params:s}=e,n=s.device;let a,o;i.position&&r.position&&(a=function(e,t,i){return{x:Te(e.x,t.x,i),y:Te(e.y,t.y,i),z:Te(e.z,t.z,i)}}(i.position,r.position,t)),i.orientation&&r.orientation&&(o=function(e,t,i){let r=e.x*t.x+e.y*t.y+e.z*t.z+e.w*t.w,s=t.x,n=t.y,a=t.z,o=t.w;if(r<0&&(r=-r,s=-s,n=-n,a=-a,o=-o),r>.9995){const t={x:Te(e.x,s,i),y:Te(e.y,n,i),z:Te(e.z,a,i),w:Te(e.w,o,i)},r=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w);return{x:t.x/r,y:t.y/r,z:t.z/r,w:t.w/r}}const h=Math.acos(r),l=h*i,c=Math.sin(l),u=Math.sin(h),d=Math.cos(l)-r*c/u,p=c/u;return{x:d*e.x+p*s,y:d*e.y+p*n,z:d*e.z+p*a,w:d*e.w+p*o}}(i.orientation,r.orientation,t)),this.setDeviceTransform(n,a,o)}applyDurationFinalState(e){const{targetState:t,params:i}=e,r=i.device;this.setDeviceTransform(r,t.position,t.orientation)}getDurationResult(e){const{params:t,elapsedMs:i}=e,r=t.device,s=this.getDeviceTransform(r);return{device:r,position:s.position,orientation:s.orientation,actualDuration:i/1e3}}activateCaptureMode(){this._isCaptured||(this._isCaptured=!0,this.cancelReleaseTimer(),this.device.controlMode="programmatic"),this.startReleaseTimer()}async dispatch(e,t={}){var i;if(we.IMMEDIATE_METHODS.has(e))return we.ACTIVE_IMMEDIATE_METHODS.has(e)&&this.activateCaptureMode(),this.executeImmediateMethod(e,t);if(we.SESSION_REQUIRED_METHODS.has(e)&&!this.device.activeSession)throw new Error(`Cannot execute '${e}': No active XR session. Use 'get_session_status' to check session state, and 'accept_session' to start a session.`);if("animate_to"===e){const r=t,s=this.getDeviceTransform(r.device),n=1e3*(null!==(i=r.duration)&&void 0!==i?i:.5),a=r.orientation?ye(r.orientation):void 0,o=r.position?this.transformXROriginToGlobal(r.position):void 0;return this.enqueueDuration(e,t,n,{position:r.position?s.position:void 0,orientation:a?s.orientation:void 0},{position:o,orientation:a})}if("select"===e){const e=t;return this.executeSelectSequence(e)}return this.enqueueDiscrete(e,t)}executeImmediateMethod(e,t){switch(e){case"get_session_status":return this.executeGetSessionStatus();case"accept_session":return this.executeAcceptSession();case"end_session":return this.executeEndSession();case"get_transform":return this.executeGetTransform(t);case"get_select_value":return this.executeGetSelectValue(t);case"get_gamepad_state":return this.executeGetGamepadState(t);case"get_device_state":return this.executeGetDeviceState();case"capture_canvas":return this.executeCaptureCanvas(t);default:throw new Error(`Unknown immediate method: ${e}`)}}executeSelectSequence(e){const{device:t,duration:i=.15}=e;return new Promise((e,r)=>{let s=0;const n=()=>{s++,3===s&&e({device:t,duration:i})},a={type:"discrete",id:this.generateActionId(),method:"_select_press",params:{device:t},resolve:n,reject:r},o={type:"duration",id:this.generateActionId(),method:"_select_wait",params:{device:t},durationMs:1e3*i,elapsedMs:0,startState:{},targetState:{},resolve:n,reject:r},h={type:"discrete",id:this.generateActionId(),method:"_select_release",params:{device:t},resolve:n,reject:r};this.commandQueue.push(a,o,h)})}async acceptSession(){if(!this.device.sessionOffered)throw new Error("No session has been offered");return this.device.grantOfferedSession(),await ve(()=>!!this.device.activeSession,5e3),{success:!0}}forceRelease(){this.cancelReleaseTimer(),this._isCaptured=!1,this.device.controlMode="manual";for(const e of this.commandQueue)e.reject(new Error("Capture released"));this.commandQueue=[];for(const e of["left","right"]){const t=this.device.controllers[e];t&&(t.updateButtonValue("trigger",0),t.updateButtonValue("squeeze",0))}}}var Se,_e,Ee;we.IMMEDIATE_METHODS=new Set(["get_session_status","accept_session","end_session","get_transform","get_select_value","get_gamepad_state","get_device_state","capture_canvas"]),we.ACTIVE_IMMEDIATE_METHODS=new Set(["accept_session","end_session"]),we.SESSION_REQUIRED_METHODS=new Set(["set_transform","look_at","animate_to","set_input_mode","set_connected","set_select_value","select","set_gamepad_state","set_device_state"]),function(e){e.None="",e.Standard="standard",e.XRStandard="xr-standard"}(Se||(Se={}));class Re{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 be{constructor(){this.pressed=!1,this.touched=!1,this.value=0}}class Me{constructor(e,t="",i=-1){this[z]={id:t,index:i,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 Re(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 i=t.substring(0,t.length-6),r=t.substring(t.length-6);e.push("y-axis"===r?this[z].axesMap[i].y:this[z].axesMap[i].x)}}),e}get buttons(){return this[z].buttonsSequence.map(e=>null===e?new be: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"}(_e||(_e={})),function(e){e.Gaze="gaze",e.TrackedPointer="tracked-pointer",e.Screen="screen",e.TransientPointer="transient-pointer"}(Ee||(Ee={}));class Ae extends Array{}class Pe{constructor(e,t,i,r,s,n,a){this[k]={handedness:e,targetRayMode:t,targetRaySpace:r,gripSpace:n,profiles:i,gamepad:s,hand:a}}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 Ie 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 Fe={[_e.Left]:{position:new ce(-.25,1.5,-.4),quaternion:new ue},[_e.Right]:{position:new ce(.25,1.5,-.4),quaternion:new ue},[_e.None]:{position:new ce(.25,1.5,-.4),quaternion:new ue}};class Le{constructor(e){this[U]={inputSource:e,position:Fe[e.handedness].position.clone(),quaternion:Fe[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[z].connected=e}onFrameStart(e){c(this[U].inputSource.targetRaySpace[ie].offsetMatrix,this[U].quaternion.quat,this[U].position.vec3);const t=e.session;this[U].inputSource.gamepad.buttons.forEach(i=>{i instanceof Re&&(i[z].lastFrameValue=i[z].value,null!=i[z].pendingValue&&(i[z].value=i[z].pendingValue,i[z].pendingValue=null),null!=i[z].eventTrigger&&(0===i[z].lastFrameValue&&i[z].value>0?(t.dispatchEvent(new Ie(i[z].eventTrigger,{frame:e,inputSource:this[U].inputSource})),t.dispatchEvent(new Ie(i[z].eventTrigger+"start",{frame:e,inputSource:this[U].inputSource}))):i[z].lastFrameValue>0&&0===i[z].value&&t.dispatchEvent(new Ie(i[z].eventTrigger+"end",{frame:e,inputSource:this[U].inputSource}))))}),this[U].inputSourceChanged=this.connected!==this[U].lastFrameConnected,this[U].lastFrameConnected=this.connected}}class Ce extends Le{constructor(e,t,i){if(!e.layout[t])throw new DOMException("Handedness not supported","InvalidStateError");const r=new oe(i),s=e.layout[t].gripOffsetMatrix?new oe(r,e.layout[t].gripOffsetMatrix):void 0,n=[e.profileId,...e.fallbackProfileIds];super(new Pe(t,Ee.TrackedPointer,n,r,new Me(e.layout[t].gamepad),s)),this[V]={profileId:e.profileId,gamepadConfig:e.layout[t].gamepad}}get gamepadConfig(){return this[V].gamepadConfig}get profileId(){return this[V].profileId}updateButtonValue(e,t){if(t>1||t<0)return void console.warn(`Out-of-range value ${t} provided for button ${e}.`);const i=this[U].inputSource.gamepad[z].buttonsMap[e];if(i){if("binary"===i[z].type&&1!=t&&0!=t)return void console.warn(`Non-binary value ${t} provided for binary button ${e}.`);i[z].pendingValue=t}else console.warn(`Current controller does not have button ${e}.`)}setButtonValueImmediate(e,t){if(t>1||t<0)return void console.warn(`Out-of-range value ${t} provided for button ${e}.`);const i=this[U].inputSource.gamepad[z].buttonsMap[e];if(i){if("binary"===i[z].type&&1!=t&&0!=t)return void console.warn(`Non-binary value ${t} provided for binary button ${e}.`);i[z].value=t,i[z].pendingValue=t}else console.warn(`Current controller does not have button ${e}.`)}updateButtonTouch(e,t){const i=this[U].inputSource.gamepad[z].buttonsMap[e];i?i[z].touched=t:console.warn(`Current controller does not have button ${e}.`)}updateAxis(e,t,i){if(i>1||i<-1)return void console.warn(`Out-of-range value ${i} provided for ${e} axes.`);const r=this[U].inputSource.gamepad[z].axesMap[e];r?"x-axis"===t?r.x=i:"y-axis"===t&&(r.y=i):console.warn(`Current controller does not have ${e} axes.`)}updateAxes(e,t,i){if(t>1||t<-1||i>1||i<-1)return void console.warn(`Out-of-range value x:${t}, y:${i} provided for ${e} axes.`);const r=this[U].inputSource.gamepad[z].axesMap[e];r?(r.x=t,r.y=i):console.warn(`Current controller does not have ${e} axes.`)}getButtonValue(e){var t;const i=this[U].inputSource.gamepad[z].buttonsMap[e];return i?null!==(t=i[z].pendingValue)&&void 0!==t?t:i.value:0}getButtonTouched(e){const t=this[U].inputSource.gamepad[z].buttonsMap[e];return!!t&&t.touched}getAxes(e="thumbstick"){const t=this[U].inputSource.gamepad[z].axesMap[e];return t?{x:t.x,y:t.y}:{x:0,y:0}}}class De{constructor(e,t,i,r,s){this[j]={nativeMesh:e,frame:void 0,meshSpace:t,vertices:i,indices:r,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 Ne extends Set{}var Oe,Ve;e.XRSemanticLabels=void 0,(Oe=e.XRSemanticLabels||(e.XRSemanticLabels={})).Desk="desk",Oe.Couch="couch",Oe.Floor="floor",Oe.Ceiling="ceiling",Oe.Wall="wall",Oe.Door="door",Oe.Window="window",Oe.Table="table",Oe.Shelf="shelf",Oe.Bed="bed",Oe.Screen="screen",Oe.Lamp="lamp",Oe.Plant="plant",Oe.WallArt="wall art",Oe.GlobalMesh="global mesh",Oe.Other="other",function(e){e.Horizontal="horizontal",e.Vertical="vertical"}(Ve||(Ve={}));const Be={[e.XRSemanticLabels.Desk]:Ve.Horizontal,[e.XRSemanticLabels.Couch]:Ve.Horizontal,[e.XRSemanticLabels.Floor]:Ve.Horizontal,[e.XRSemanticLabels.Ceiling]:Ve.Horizontal,[e.XRSemanticLabels.Wall]:Ve.Vertical,[e.XRSemanticLabels.Door]:Ve.Vertical,[e.XRSemanticLabels.Window]:Ve.Vertical,[e.XRSemanticLabels.Table]:Ve.Horizontal,[e.XRSemanticLabels.Shelf]:Ve.Horizontal,[e.XRSemanticLabels.Bed]:Ve.Horizontal,[e.XRSemanticLabels.Screen]:Ve.Horizontal,[e.XRSemanticLabels.Lamp]:Ve.Horizontal,[e.XRSemanticLabels.Plant]:Ve.Horizontal,[e.XRSemanticLabels.WallArt]:Ve.Vertical};class Ge{constructor(e,t,i,r){this[W]={nativePlane:e,frame:void 0,planeSpace:t,polygon:i,lastChangedTime:performance.now(),semanticLabel:r,orientation:r?Be[r]:void 0}}get planeSpace(){return this[W].planeSpace}get polygon(){return this[W].polygon}get orientation(){return this[W].orientation}get lastChangedTime(){return this[W].lastChangedTime}get semanticLabel(){return this[W].semanticLabel}}class Ue extends Set{}class Xe{constructor(e,t){this[O]={anchorSpace:e,session:t,deleted:!1},t[Z].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[Z].persistentAnchors;for(const[i,r]of t.entries())if(r===this)return void e(i);const i=crypto.randomUUID();ke.createPersistentAnchor(this[O].session,this,i),e(i)}})}delete(){this[O].deleted||(this[O].anchorSpace=null,this[O].deleted=!0,this[O].session[Z].trackedAnchors.delete(this))}}class ze extends Set{}const qe="@immersive-web-emulation-runtime/persistent-anchors";class ke{static recoverPersistentAnchorsFromStorage(e){const t=JSON.parse(localStorage.getItem(qe)||"{}");Object.entries(t).forEach(([t,i])=>{const r=e[Z].device[B].globalSpace,s=new oe(r,i),n=new Xe(s,e);e[Z].persistentAnchors.set(t,n)})}static createPersistentAnchor(e,t,i){e[Z].trackedAnchors.add(t),e[Z].persistentAnchors.set(i,t);const r=JSON.parse(localStorage.getItem(qe)||"{}");r[i]=Array.from(t[O].anchorSpace[ie].offsetMatrix),localStorage.setItem(qe,JSON.stringify(r))}}class He{constructor(e,t){const i=x(0,0,0),s=b();this[K]={matrix:r(),position:e?x(e.x,e.y,e.z):i,orientation:t?C(b(),I(t.x,t.y,t.z,t.w)):s,inverse:null},this.updateMatrix()}updateMatrix(){c(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=m();u(t,e);let i=b();p(i,e),this[K].inverse=new He(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 je{constructor(e=0,t=0,i=0,r=1){this.x=e,this.y=t,this.z=i,this.w=r}}class We{constructor(e,t){const i={x:0,y:0,z:0,w:1},r={x:0,y:0,z:-1,w:0};if(e instanceof He){const t=e.matrix,s=E(_(),i.x,i.y,i.z,i.w),n=E(_(),r.x,r.y,r.z,r.w);R(s,s,t),R(n,n,t),i.x=s[0],i.y=s[1],i.z=s[2],i.w=s[3],r.x=n[0],r.y=n[1],r.z=n[2],r.w=n[3]}else if(e&&(i.x=e.x,i.y=e.y,i.z=e.z,i.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");r.x=t.x,r.y=t.y,r.z=t.z,r.w=t.w}const s=Math.sqrt(r.x*r.x+r.y*r.y+r.z*r.z)||1;r.x=r.x/s,r.y=r.y/s,r.z=r.z/s,this[ne]={origin:new je(i.x,i.y,i.z,i.w),direction:new je(r.x,r.y,r.z,r.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=v(m(),0,0,-1),t=v(m(),this[ne].origin.x,this[ne].origin.y,this[ne].origin.z),i=v(m(),this[ne].direction.x,this[ne].direction.y,this[ne].direction.z),s=w(m(),i,e),n=T(i,e),a=r();n>-1&&n<1?l(a,Math.acos(n),s):-1===n?l(a,Math.acos(n),v(m(),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}(a);const c=h(r(),t),u=o(r(),c,a);return this[ne].matrix=new Float32Array(u),this[ne].matrix}}class Ye{constructor(e,t){var i;this[ae]={session:e,space:t.space,offsetRay:null!==(i=t.offsetRay)&&void 0!==i?i:new We}}cancel(){this[ae].session[Z].hitTestSources.delete(this)}}class Qe{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 He,this[ae].offsetSpace)}}class $e 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 Ke,Je,Ze;!function(e){e.Viewer="viewer",e.Local="local",e.LocalFloor="local-floor",e.BoundedFloor="bounded-floor",e.Unbounded="unbounded"}(Je||(Je={}));class et extends oe{constructor(e,t,i){super(t,i),this[Ke]={type:null,onreset:()=>{}},this[te].type=e}get onreset(){var e;return null!==(e=this[te].onreset)&&void 0!==e?e:()=>{}}set onreset(e){this[te].onreset&&this.removeEventListener("reset",this[te].onreset),this[te].onreset=e,e&&this.addEventListener("reset",e)}getOffsetReferenceSpace(e){return new et(this[te].type,this,e)}}Ke=te;class tt{constructor(e={},t){this[J]={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[J].depthNear}get depthFar(){return this[J].depthFar}get inlineVerticalFieldOfView(){return this[J].inlineVerticalFieldOfView}get baseLayer(){return this[J].baseLayer}}class it 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"}(Ze||(Ze={}));class rt{constructor(e,t,i,r){this[re]={eye:e,projectionMatrix:t,transform:i,recommendedViewportScale:null,requestedViewportScale:1,session:r}}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 st{constructor(e,t=!1,i=void 0,r=void 0){this[Q]={transform:e,emulatedPosition:t,linearVelocity:i,angularVelocity:r}}get transform(){return this[Q].transform}get emulatedPosition(){return this[Q].emulatedPosition}get linearVelocity(){return this[Q].linearVelocity}get angularVelocity(){return this[Q].angularVelocity}}class nt extends st{constructor(e,t,i=!1,r=void 0,s=void 0){super(e,i,r,s),this[Y]={radius:t}}get radius(){return this[Y].radius}}class at extends st{constructor(e,t,i=!1,r=void 0,s=void 0){super(e,i,r,s),this[$]={views:Object.freeze(t)}}get views(){return this[$].views}}const ot=r(),ht=r(),lt=r(),ct=(e,t,i)=>{le.calculateGlobalOffsetMatrix(t,ot),le.calculateGlobalOffsetMatrix(i,ht),a(lt,ht),o(e,lt,ot)};class ut{constructor(e,t,i,s,n){this[X]={session:e,id:t,active:i,animationFrame:s,predictedDisplayTime:n,tempMat4:r(),detectedPlanes:new Ue,detectedMeshes:new Ne,trackedAnchors:e[Z].frameTrackedAnchors,hitTestResultsMap:new Map}}get session(){return this[X].session}get predictedDisplayTime(){return this[X].predictedDisplayTime}getPose(e,t){if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");ct(this[X].tempMat4,e,t);const i=m();u(i,this[X].tempMat4);const r=b();return p(r,this[X].tempMat4),new st(new He({x:i[0],y:i[1],z:i[2],w:1},{x:r[0],y:r[1],z:r[2],w:r[3]}),e[ie].emulated)}getViewerPose(e){if(!this[X].animationFrame)throw new DOMException("getViewerPose can only be called on XRFrame objects passed to XRSession.requestAnimationFrame callbacks.","InvalidStateError");const t=this[X].session,i=t[Z].device,r=this.getPose(i.viewerSpace,e),s="inline"===t[Z].mode?[Ze.None]:[Ze.Left,Ze.Right],n=[];return s.forEach(r=>{const s=i.viewSpaces[r],a=this.getPose(s,e),o=t[Z].getProjectionMatrix(r),h=new rt(r,new Float32Array(o),a.transform,t);n.push(h)}),new at(r.transform,n,!1)}getJointPose(e,t){const i=this.getPose(e,t),r=e[ee].radius;return new nt(i.transform,r,!1)}fillJointRadii(e,t){if(e=Array.from(e),!this[X].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 i=!0;for(let r=0;r<e.length;r++)e[r][ee].radius?t[r]=e[r][ee].radius:(t[r]=NaN,i=!1);return i}fillPoses(e,t,i){if(e=Array.from(e),!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");if(16*e.length>i.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,r)=>{ct(this[X].tempMat4,e,t);for(let e=0;e<16;e++)i[16*r+e]=this[X].tempMat4[e]}),!0}get detectedPlanes(){if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[X].detectedPlanes}get detectedMeshes(){if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[X].detectedMeshes}get trackedAnchors(){if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[X].trackedAnchors}createAnchor(e,t){return new Promise((i,r)=>{if(this[X].active){const s=this[X].session[Z].device[B].globalSpace,n=new oe(t,e.matrix),a=le.calculateGlobalOffsetMatrix(n),o=new oe(s,a),h=new Xe(o,this[X].session);this[X].session[Z].trackedAnchors.add(h),this[X].session[Z].newAnchors.set(h,{resolve:i,reject:r})}else r(new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError"))})}getHitTestResults(e){if(this[X].active){if(this[X].hitTestResultsMap.has(e))return[...this[X].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 dt,pt,ft;!function(e){e.Opaque="opaque",e.AlphaBlend="alpha-blend",e.Additive="additive"}(dt||(dt={})),function(e){e.ScreenSpace="screen-space",e.WorldSpace="world-space"}(pt||(pt={}));class mt extends EventTarget{constructor(e,t,i){super(),this[Z]={device:e,mode:t,renderState:new tt,pendingRenderState:null,enabledFeatures:i,isSystemKeyboardSupported:!1,ended:!1,projectionMatrices:{[Ze.Left]:r(),[Ze.Right]:r(),[Ze.None]:r()},getProjectionMatrix:e=>this[Z].projectionMatrices[e],referenceSpaceIsSupported:e=>{if(!this[Z].enabledFeatures.includes(e))return!1;switch(e){case Je.Viewer:return!0;case Je.Local:case Je.LocalFloor:case Je.BoundedFloor:case Je.Unbounded:return"inline"!=this[Z].mode}},frameHandle:0,frameCallbacks:[],currentFrameCallbacks:null,onDeviceFrame:()=>{if(this[Z].ended)return;this[Z].deviceFrameHandle=globalThis.requestAnimationFrame(this[Z].onDeviceFrame),null!=this[Z].pendingRenderState&&(this[Z].renderState=this[Z].pendingRenderState,this[Z].pendingRenderState=null,this[Z].device[B].onBaseLayerSet(this[Z].renderState.baseLayer));const e=this[Z].renderState.baseLayer;if(null===e)return;const t=e.context,i=t.canvas;if("inline"!=this[Z].mode){const e=t.getParameter(t.COLOR_CLEAR_VALUE),i=t.getParameter(t.DEPTH_CLEAR_VALUE),r=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(i),t.clearStencil(r)}const{depthNear:r,depthFar:s}=this[Z].renderState,{width:a,height:o}=i;if("inline"!==this[Z].mode){const e=a*(this[Z].device.stereoEnabled?.5:1)/o;f(this[Z].projectionMatrices[Ze.Left],this[Z].device.fovy,e,r,s),n(this[Z].projectionMatrices[Ze.Right],this[Z].projectionMatrices[Ze.Left])}else{const e=a/o;f(this[Z].projectionMatrices[Ze.None],this[Z].renderState.inlineVerticalFieldOfView,e,r,s)}const h=new ut(this,this[Z].frameHandle,!0,!0,performance.now()),l=performance.now(),c=this[Z].device[B].devui;if(c&&c.render(l),"immersive-ar"===this[Z].mode){const e=this[Z].device[B].sem;e&&e.render(l)}this[Z].enabledFeatures.includes("anchors")&&this[Z].updateTrackedAnchors(),this[Z].enabledFeatures.includes("plane-detection")&&this[Z].updateTrackedPlanes(h),this[Z].enabledFeatures.includes("mesh-detection")&&this[Z].updateTrackedMeshes(h),this[Z].enabledFeatures.includes("hit-test")&&this[Z].computeHitTestResults(h),this[Z].device[B].onFrameStart(h),this[Z].updateActiveInputSources();const u=this[Z].currentFrameCallbacks=this[Z].frameCallbacks;this[Z].frameCallbacks=[];const d=performance.now();for(let e=0;e<u.length;e++)try{u[e].cancelled||u[e].callback(d,h)}catch(e){console.error(e)}this[Z].currentFrameCallbacks=null,h[X].active=!1},nominalFrameRate:e.internalNominalFrameRate,referenceSpaces:[],inputSourceArray:[],activeInputSources:[],updateActiveInputSources:()=>{const e=this[Z].enabledFeatures.includes("hand-tracking"),t=this[Z].activeInputSources,i=this[Z].device.inputSources.filter(t=>!t.hand||e),r=i.filter(e=>!t.includes(e)),s=t.filter(e=>!i.includes(e));this[Z].activeInputSources=i,(r.length>0||s.length>0)&&this.dispatchEvent(new $e("inputsourceschange",{session:this,added:r,removed:s}))},trackedAnchors:new ze,persistentAnchors:new Map,newAnchors:new Map,frameTrackedAnchors:new ze,updateTrackedAnchors:()=>{this[Z].enabledFeatures.includes("anchors")&&(this[Z].frameTrackedAnchors.clear(),Array.from(this[Z].trackedAnchors).forEach(e=>{if(e[O].deleted){if(this[Z].trackedAnchors.delete(e),this[Z].newAnchors.has(e)){const{reject:t}=this[Z].newAnchors.get(e);t(new DOMException("Anchor is no longer tracked","InvalidStateError"))}}else if(this[Z].frameTrackedAnchors.add(e),this[Z].newAnchors.has(e)){const{resolve:t}=this[Z].newAnchors.get(e);t(e),this[Z].newAnchors.delete(e)}}))},trackedPlanes:new Map,updateTrackedPlanes:e=>{const t=this[Z].device[B].sem;if(!t)return;Array.from(this[Z].trackedPlanes.keys()).forEach(e=>{t.trackedPlanes.has(e)||this[Z].trackedPlanes.delete(e)}),t.trackedPlanes.forEach(t=>{let i=this[Z].trackedPlanes.get(t);if(!i){const e=new oe(this[Z].device[B].globalSpace,t.transform.matrix);i=new Ge(t,e,t.polygon,t.semanticLabel),this[Z].trackedPlanes.set(t,i)}i[W].lastChangedTime=e.predictedDisplayTime,i[W].frame=e,e[X].detectedPlanes.add(i)})},trackedMeshes:new Map,updateTrackedMeshes:e=>{const t=this[Z].device[B].sem;if(!t)return;Array.from(this[Z].trackedMeshes.keys()).forEach(e=>{t.trackedMeshes.has(e)||this[Z].trackedMeshes.delete(e)}),t.trackedMeshes.forEach(t=>{let i=this[Z].trackedMeshes.get(t);if(!i){const e=new oe(this[Z].device[B].globalSpace,t.transform.matrix);i=new De(t,e,t.vertices,t.indices,t.semanticLabel),this[Z].trackedMeshes.set(t,i)}i[j].lastChangedTime=e.predictedDisplayTime,i[j].frame=e,e[X].detectedMeshes.add(i)})},hitTestSources:new Set,computeHitTestResults:e=>{const t=this[Z].device[B].sem;if(!t)return;const i=this[Z].device[B].globalSpace;this[Z].hitTestSources.forEach(s=>{const n=s[ae].space,a=le.calculateGlobalOffsetMatrix(n),h=s[ae].offsetRay.matrix,l=r();o(l,a,h);const c=[];t.computeHitTestResults(l).forEach(t=>{const r=new oe(i,t),s=new Qe(e,r);c.push(s)}),e[X].hitTestResultsMap.set(s,c)})},onend:null,oninputsourceschange:null,onselect:null,onselectstart:null,onselectend:null,onsqueeze:null,onsqueezestart:null,onsqueezeend:null,onvisibilitychange:null,onframeratechange:null},ke.recoverPersistentAnchorsFromStorage(this),this[Z].onDeviceFrame()}get visibilityState(){return this[Z].device.visibilityState}get frameRate(){return this[Z].nominalFrameRate}get supportedFrameRates(){return new Float32Array(this[Z].device.supportedFrameRates)}get renderState(){return this[Z].renderState}get inputSources(){return this[Z].inputSourceArray.length=0,this[Z].ended||"inline"===this[Z].mode||this[Z].inputSourceArray.push(...this[Z].activeInputSources),this[Z].inputSourceArray}get enabledFeatures(){return this[Z].enabledFeatures}get isSystemKeyboardSupported(){return this[Z].isSystemKeyboardSupported}get environmentBlendMode(){var e;return null!==(e=this[Z].device[B].environmentBlendModes[this[Z].mode])&&void 0!==e?e:dt.Opaque}get interactionMode(){return this[Z].device[B].interactionMode}updateRenderState(e={}){var t,i,r,s;if(this[Z].ended)throw new DOMException("XRSession has already ended.","InvalidStateError");if(e.baseLayer&&e.baseLayer[H].session!==this)throw new DOMException("Base layer was created by a different XRSession","InvalidStateError");if(null!=e.inlineVerticalFieldOfView&&"inline"!==this[Z].mode)throw new DOMException("InlineVerticalFieldOfView must not be set for an immersive session","InvalidStateError");const n={baseLayer:e.baseLayer||(null===(t=this[Z].pendingRenderState)||void 0===t?void 0:t.baseLayer)||void 0,depthFar:e.depthFar||(null===(i=this[Z].pendingRenderState)||void 0===i?void 0:i.depthFar)||void 0,depthNear:e.depthNear||(null===(r=this[Z].pendingRenderState)||void 0===r?void 0:r.depthNear)||void 0,inlineVerticalFieldOfView:e.inlineVerticalFieldOfView||(null===(s=this[Z].pendingRenderState)||void 0===s?void 0:s.inlineVerticalFieldOfView)||void 0};this[Z].pendingRenderState=new tt(n,this[Z].renderState)}async updateTargetFrameRate(e){return new Promise((t,i)=>{this[Z].ended?i(new DOMException("XRSession has already ended.","InvalidStateError")):this[Z].device.supportedFrameRates.includes(e)?(this[Z].nominalFrameRate===e?console.log("Requested frame rate is the same as the current nominal frame rate, no update made"):(this[Z].nominalFrameRate=e,this.dispatchEvent(new it("frameratechange",{session:this})),console.log(`Nominal frame rate updated to ${e}`)),t()):i(new DOMException("Requested frame rate not supported.","InvalidStateError"))})}async requestReferenceSpace(e){return new Promise((t,i)=>{if(this[Z].ended||!this[Z].referenceSpaceIsSupported(e))return void i(new DOMException("The requested reference space type is not supported.","NotSupportedError"));let r;switch(e){case Je.Viewer:r=this[Z].device.viewerSpace;break;case Je.Local:r=new et(e,this[Z].device[B].globalSpace,this[Z].device.viewerSpace[ie].offsetMatrix);break;case Je.LocalFloor:case Je.BoundedFloor:case Je.Unbounded:r=new et(e,this[Z].device[B].globalSpace)}this[Z].referenceSpaces.push(r),t(r)})}requestAnimationFrame(e){if(this[Z].ended)return 0;const t=++this[Z].frameHandle;return this[Z].frameCallbacks.push({handle:t,callback:e,cancelled:!1}),t}cancelAnimationFrame(e){let t=this[Z].frameCallbacks,i=t.findIndex(t=>t&&t.handle===e);i>-1&&(t[i].cancelled=!0,t.splice(i,1)),t=this[Z].currentFrameCallbacks,t&&(i=t.findIndex(t=>t&&t.handle===e),i>-1&&(t[i].cancelled=!0))}async end(){return new Promise((e,t)=>{this[Z].ended||null===this[Z].deviceFrameHandle?t(new DOMException("XRSession has already ended.","InvalidStateError")):(globalThis.cancelAnimationFrame(this[Z].deviceFrameHandle),this[Z].device[B].onSessionEnd(),this.dispatchEvent(new it("end",{session:this})),e())})}get persistentAnchors(){return Array.from(this[Z].persistentAnchors.keys())}restorePersistentAnchor(e){return new Promise((t,i)=>{if(this[Z].persistentAnchors.has(e))if(this[Z].ended)i(new DOMException("XRSession has already ended.","InvalidStateError"));else{const r=this[Z].persistentAnchors.get(e);this[Z].newAnchors.has(r)?i(new DOMException(`Multiple concurrent attempts detected to restore the anchor with UUID: ${e}.`,"InvalidStateError")):(this[Z].trackedAnchors.add(r),this[Z].newAnchors.set(r,{resolve:t,reject:i}))}else i(new DOMException(`Persistent anchor with uuid ${e} not found.`,"InvalidStateError"))})}deletePersistentAnchor(e){return new Promise((t,i)=>{if(this[Z].persistentAnchors.has(e)){const i=this[Z].persistentAnchors.get(e);this[Z].persistentAnchors.delete(e),i.delete(),t(void 0)}else i(new DOMException(`Persistent anchor with uuid ${e} not found.`,"InvalidStateError"))})}requestHitTestSource(e){return new Promise((t,i)=>{if(this[Z].enabledFeatures.includes("hit-test"))if(this[Z].ended)i(new DOMException("XRSession has already ended.","InvalidStateError"));else if(this[Z].device[B].sem){const i=new Ye(this,e);this[Z].hitTestSources.add(i),t(i)}else i(new DOMException("Synthethic Environment Module required for emulating hit-test","OperationError"));else i(new DOMException('WebXR feature "hit-test" is not supported by current session',"NotSupportedError"))})}get onend(){var e;return null!==(e=this[Z].onend)&&void 0!==e?e:()=>{}}set onend(e){this[Z].onend&&this.removeEventListener("end",this[Z].onend),this[Z].onend=e,e&&this.addEventListener("end",e)}get oninputsourceschange(){var e;return null!==(e=this[Z].oninputsourceschange)&&void 0!==e?e:()=>{}}set oninputsourceschange(e){this[Z].oninputsourceschange&&this.removeEventListener("inputsourceschange",this[Z].oninputsourceschange),this[Z].oninputsourceschange=e,e&&this.addEventListener("inputsourceschange",e)}get onselect(){var e;return null!==(e=this[Z].onselect)&&void 0!==e?e:()=>{}}set onselect(e){this[Z].onselect&&this.removeEventListener("select",this[Z].onselect),this[Z].onselect=e,e&&this.addEventListener("select",e)}get onselectstart(){var e;return null!==(e=this[Z].onselectstart)&&void 0!==e?e:()=>{}}set onselectstart(e){this[Z].onselectstart&&this.removeEventListener("selectstart",this[Z].onselectstart),this[Z].onselectstart=e,e&&this.addEventListener("selectstart",e)}get onselectend(){var e;return null!==(e=this[Z].onselectend)&&void 0!==e?e:()=>{}}set onselectend(e){this[Z].onselectend&&this.removeEventListener("selectend",this[Z].onselectend),this[Z].onselectend=e,e&&this.addEventListener("selectend",e)}get onsqueeze(){var e;return null!==(e=this[Z].onsqueeze)&&void 0!==e?e:()=>{}}set onsqueeze(e){this[Z].onsqueeze&&this.removeEventListener("squeeze",this[Z].onsqueeze),this[Z].onsqueeze=e,e&&this.addEventListener("squeeze",e)}get onsqueezestart(){var e;return null!==(e=this[Z].onsqueezestart)&&void 0!==e?e:()=>{}}set onsqueezestart(e){this[Z].onsqueezestart&&this.removeEventListener("squeezestart",this[Z].onsqueezestart),this[Z].onsqueezestart=e,e&&this.addEventListener("squeezestart",e)}get onsqueezeend(){var e;return null!==(e=this[Z].onsqueezeend)&&void 0!==e?e:()=>{}}set onsqueezeend(e){this[Z].onsqueezeend&&this.removeEventListener("squeezeend",this[Z].onsqueezeend),this[Z].onsqueezeend=e,e&&this.addEventListener("squeezeend",e)}get onvisibilitychange(){var e;return null!==(e=this[Z].onvisibilitychange)&&void 0!==e?e:()=>{}}set onvisibilitychange(e){this[Z].onvisibilitychange&&this.removeEventListener("visibilitychange",this[Z].onvisibilitychange),this[Z].onvisibilitychange=e,e&&this.addEventListener("visibilitychange",e)}get onframeratechange(){var e;return null!==(e=this[Z].onframeratechange)&&void 0!==e?e:()=>{}}set onframeratechange(e){this[Z].onframeratechange&&this.removeEventListener("frameratechange",this[Z].onframeratechange),this[Z].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"}(ft||(ft={}));class xt extends Map{}class gt extends oe{constructor(e,t,i){super(t,i),this[ee]={jointName:e,radius:0}}get jointName(){return this[ee].jointName}}const vt={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]}}},yt={mapping:Se.None,buttons:[{id:"pinch",type:"analog",eventTrigger:"select"}],axes:[]},Tt=m(),wt=b(),St=m(),_t=m(),Et=b(),Rt=m(),bt=m(),Mt=b(),At=m(),Pt=(e,t,i,r)=>(u(Tt,t),p(wt,t),d(St,t),u(_t,i),p(Et,i),d(Rt,i),S(bt,Tt,_t,r),A(Mt,wt,Et,r),S(At,St,Rt,r),function(e,t,i,r){var s=t[0],n=t[1],a=t[2],o=t[3],h=s+s,l=n+n,c=a+a,u=s*h,d=s*l,p=s*c,f=n*l,m=n*c,x=a*c,g=o*h,v=o*l,y=o*c,T=r[0],w=r[1],S=r[2];e[0]=(1-(f+x))*T,e[1]=(d+y)*T,e[2]=(p-v)*T,e[3]=0,e[4]=(d-y)*w,e[5]=(1-(u+x))*w,e[6]=(m+g)*w,e[7]=0,e[8]=(p+v)*S,e[9]=(m-g)*S,e[10]=(1-(u+f))*S,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1}(e,Mt,bt,At),e),It=[1,-1,-1,0,-1,1,1,0,-1,1,1,0,-1,1,1,1];class Ft extends Le{constructor(e,t,i){if(t!==_e.Left&&t!==_e.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 r=new oe(i),s=new oe(r),n=[e.profileId,...e.fallbackProfileIds],a=new xt;Object.values(ft).forEach(e=>{a.set(e,new gt(e,r))});super(new Pe(t,Ee.TrackedPointer,n,r,new Me(yt),s,a)),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(ft).forEach(i=>{const r=e.jointTransforms[i].offsetMatrix,s=t.jointTransforms[i].offsetMatrix,n=this.inputSource.hand.get(i);Pt(n[ie].offsetMatrix,r,s,this.pinchValue),this.inputSource.handedness===_e.Right&&(e=>{for(let t=0;t<16;t++)e[t]*=It[t]})(n[ie].offsetMatrix),n[ee].radius=(1-this.pinchValue)*e.jointTransforms[i].radius+this.pinchValue*t.jointTransforms[i].radius}),e.gripOffsetMatrix&&t.gripOffsetMatrix&&Pt(this.inputSource.gripSpace[ie].offsetMatrix,e.gripOffsetMatrix,t.gripOffsetMatrix,this.pinchValue)}get pinchValue(){return this[U].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[U].inputSource.gamepad[z].buttonsMap.pinch[z].pendingValue=e}onFrameStart(e){super.onFrameStart(e),this.updateHandPose()}}class Lt extends EventTarget{}const Ct={antialias:!0,depth:!0,stencil:!1,alpha:!0,ignoreDepthValues:!1,framebufferScaleFactor:1};class Dt extends Lt{constructor(e,t,i={}){if(super(),e[Z].ended)throw new DOMException("Session has ended","InvalidStateError");const r={...Ct,...i};this[H]={session:e,context:t,antialias:r.antialias}}get context(){return this[H].context}get antialias(){return this[H].antialias}get ignoreDepthValues(){return!0}get framebuffer(){return null}get framebufferWidth(){return this[H].context.drawingBufferWidth}get framebufferHeight(){return this[H].context.drawingBufferHeight}getViewport(e){if(e[re].session!==this[H].session)throw new DOMException("View's session differs from Layer's session","InvalidStateError");return this[H].session[Z].device[B].getViewport(this,e)}static getNativeFramebufferScaleFactor(e){if(!(e instanceof mt))throw new TypeError("getNativeFramebufferScaleFactor must be passed a session.");return e[Z].ended?0:1}}class Nt{constructor(e,t,i){const{schema:r,frames:s}=t;if(!s||!r||0===s.length)throw new DOMException("wrong recording format","NotSupportedError");const n=new et(Je.Viewer,e),a={[Ze.Left]:new oe(n),[Ze.Right]:new oe(n),[Ze.None]:new oe(n)};this[D]={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:n,viewSpaces:a,vec3:m(),quat:b()},h(this[D].viewSpaces[Ze.Left][ie].offsetMatrix,x(-i/2,0,0)),h(this[D].viewSpaces[Ze.Right][ie].offsetMatrix,x(i/2,0,0)),r.forEach(t=>{const i=t[0],r=t[1];let s;if(r.hasGamepad){const e=[];for(let t=0;t<r.numButtons;t++)e.push({id:t.toString(),type:"manual"});const t=[];for(let e=0;e<r.numAxes;e++)t.push({id:e.toString(),type:"manual"});s=new Me({mapping:r.mapping,buttons:e,axes:t})}const n=new oe(e);let a;r.hasHand&&(a=new xt,Object.values(ft).forEach(e=>{a.set(e,new gt(e,n))}));const o=new Pe(r.handedness,r.targetRayMode,r.profiles,n,s,r.hasGrip?new oe(e):void 0,r.hasHand?a:void 0);this[D].inputSources.set(i,{active:!1,source:o}),this[D].inputSchemas.set(i,r)})}play(){this[D].recordedFramePointer=0,this[D].playbackTime=this[D].startingTimeStamp,this[D].playing=!0,this[D].actualTimeStamp=performance.now()}stop(){this[D].playing=!1}get playing(){return this[D].playing}get viewerSpace(){return this[D].viewerSpace}get viewSpaces(){return this[D].viewSpaces}get inputSources(){return Array.from(this[D].inputSources.values()).filter(e=>e.active).map(e=>e.source)}playFrame(){const e=performance.now(),t=e-this[D].actualTimeStamp;if(this[D].actualTimeStamp=e,this[D].playbackTime+=t,this[D].playbackTime>this[D].endingTimeStamp)return void this.stop();for(;this[D].frames[this[D].recordedFramePointer+1][0]<this[D].playbackTime;)this[D].recordedFramePointer++;const i=this[D].frames[this[D].recordedFramePointer],r=this[D].frames[this[D].recordedFramePointer+1],s=(this[D].playbackTime-i[0])/(r[0]-i[0]);this.updateXRSpaceFromMergedFrames(this[D].viewerSpace,i.slice(1,8),r.slice(1,8),s);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)}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)}this[D].inputSources.forEach(e=>{e.active=!1}),a.forEach((e,t)=>{this[D].inputSources.get(t).active=!0;const i=this[D].inputSources.get(t).source,r=this[D].inputSchemas.get(t);this.updateInputSource(i,r,n.has(t)?n.get(t):e,e,s)})}updateInputSource(e,t,i,r,s){if(this.updateXRSpaceFromMergedFrames(e.targetRaySpace,i.targetRayTransform,r.targetRayTransform,s),t.hasGrip&&this.updateXRSpaceFromMergedFrames(e.gripSpace,i.gripTransform,r.gripTransform,s),t.hasHand)for(let n=0;n<25;n++){const a=i.handTransforms.slice(8*n,8*n+7),o=r.handTransforms.slice(8*n,8*n+7),h=i.handTransforms[8*n+7],l=r.handTransforms[8*n+7],c=e.hand.get(t.jointSequence[n]);this.updateXRSpaceFromMergedFrames(c,a,o,s),c[ee].radius=(l-h)*s+h}if(t.hasGamepad){const t=e.gamepad;r.buttons.forEach((e,r)=>{const n=t.buttons[r];n[z].pressed=1===e[0],n[z].touched=1===e[1];const a=i.buttons[r][2],o=e[2];n[z].value=(o-a)*s+a}),r.axes.forEach((e,r)=>{const n=i.axes[r];t[z].axesMap[r.toString()].x=(e-n)*s+n})}}updateXRSpaceFromMergedFrames(e,t,i,r){const s=x(t[0],t[1],t[2]),n=I(t[3],t[4],t[5],t[6]),a=x(i[0],i[1],i[2]),o=I(i[3],i[4],i[5],i[6]);S(this[D].vec3,s,a,r),A(this[D].quat,n,o,r),c(e[ie].offsetMatrix,this[D].quat,this[D].vec3)}processRawInputData(e){const t=e[0],i=this[D].inputSchemas.get(t),r={targetRayTransform:e.slice(1,8)};let s=8;if(i.hasGrip&&(r.gripTransform=e[s++]),i.hasHand&&(r.handTransforms=e[s++]),i.hasGamepad){const t=e[s];r.buttons=t.slice(0,i.numButtons),r.axes=t.slice(i.numButtons)}return{index:t,inputData:r}}}const Ot="2.2.0";class Vt 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 Bt extends EventTarget{constructor(e){super(),this[q]={device:e,grantSession:({resolve:e,reject:t,mode:i,options:r})=>{if(this[q].activeSession)return void t(new DOMException("An active XRSession already exists.","InvalidStateError"));const{requiredFeatures:s=[],optionalFeatures:n=[]}=r,{supportedFeatures:a}=this[q].device;if(!s.every(e=>a.includes(e)))return void t(new Error("One or more required features are not supported by the device."));const o=n.filter(e=>a.includes(e)),h=Array.from(new Set([...s,...o,"viewer","local"])),l=new mt(this[q].device,i,h);this[q].activeSession=l,l.addEventListener("end",()=>{this[q].activeSession=void 0}),e(l)}}}isSessionSupported(e){return new Promise((t,i)=>{t("inline"===e||this[q].device.supportedSessionModes.includes(e))})}requestSession(e,t={}){return new Promise((i,r)=>{this.isSessionSupported(e).then(s=>{if(!s)return void r(new DOMException("The requested XRSession mode is not supported.","NotSupportedError"));const n={resolve:i,reject:r,mode:e,options:t};this[q].grantSession(n)}).catch(r)})}offerSession(e,t={}){return new Promise((i,r)=>{this.isSessionSupported(e).then(s=>{s?this[q].offeredSessionConfig={resolve:i,reject:r,mode:e,options:t}:r(new DOMException("The requested XRSession mode is not supported.","NotSupportedError"))}).catch(r)})}}class Gt{constructor(e,t,i,r){this[se]={x:e,y:t,width:i,height:r}}get x(){return this[se].x}get y(){return this[se].y}get width(){return this[se].width}get height(){return this[se].height}}
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).IWER={})}(this,function(e){"use strict";var t=1e-6,r="undefined"!=typeof Float32Array?Float32Array:Array;function i(){var e=new r(16);return r!=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 s(e){var t=new r(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function n(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],n=t[3],a=t[4],o=t[5],h=t[6],l=t[7],c=t[8],u=t[9],d=t[10],p=t[11],f=t[12],m=t[13],x=t[14],g=t[15],v=r*o-i*a,y=r*h-s*a,w=r*l-n*a,T=i*h-s*o,S=i*l-n*o,_=s*l-n*h,E=c*m-u*f,R=c*x-d*f,b=c*g-p*f,M=u*x-d*m,A=u*g-p*m,P=d*g-p*x,F=v*P-y*A+w*M+T*b-S*R+_*E;return F?(F=1/F,e[0]=(o*P-h*A+l*M)*F,e[1]=(s*A-i*P-n*M)*F,e[2]=(m*_-x*S+g*T)*F,e[3]=(d*S-u*_-p*T)*F,e[4]=(h*b-a*P-l*R)*F,e[5]=(r*P-s*b+n*R)*F,e[6]=(x*w-f*_-g*y)*F,e[7]=(c*_-d*w+p*y)*F,e[8]=(a*A-o*b+l*E)*F,e[9]=(i*b-r*A-n*E)*F,e[10]=(f*S-m*w+g*v)*F,e[11]=(u*w-c*S-p*v)*F,e[12]=(o*R-a*M-h*E)*F,e[13]=(r*M-i*R+s*E)*F,e[14]=(m*y-f*T-x*v)*F,e[15]=(c*T-u*y+d*v)*F,e):null}function o(e,t,r){var i=t[0],s=t[1],n=t[2],a=t[3],o=t[4],h=t[5],l=t[6],c=t[7],u=t[8],d=t[9],p=t[10],f=t[11],m=t[12],x=t[13],g=t[14],v=t[15],y=r[0],w=r[1],T=r[2],S=r[3];return e[0]=y*i+w*o+T*u+S*m,e[1]=y*s+w*h+T*d+S*x,e[2]=y*n+w*l+T*p+S*g,e[3]=y*a+w*c+T*f+S*v,y=r[4],w=r[5],T=r[6],S=r[7],e[4]=y*i+w*o+T*u+S*m,e[5]=y*s+w*h+T*d+S*x,e[6]=y*n+w*l+T*p+S*g,e[7]=y*a+w*c+T*f+S*v,y=r[8],w=r[9],T=r[10],S=r[11],e[8]=y*i+w*o+T*u+S*m,e[9]=y*s+w*h+T*d+S*x,e[10]=y*n+w*l+T*p+S*g,e[11]=y*a+w*c+T*f+S*v,y=r[12],w=r[13],T=r[14],S=r[15],e[12]=y*i+w*o+T*u+S*m,e[13]=y*s+w*h+T*d+S*x,e[14]=y*n+w*l+T*p+S*g,e[15]=y*a+w*c+T*f+S*v,e}function h(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 l(e,r,i){var s,n,a,o=i[0],h=i[1],l=i[2],c=Math.sqrt(o*o+h*h+l*l);return c<t?null:(o*=c=1/c,h*=c,l*=c,s=Math.sin(r),a=1-(n=Math.cos(r)),e[0]=o*o*a+n,e[1]=h*o*a+l*s,e[2]=l*o*a-h*s,e[3]=0,e[4]=o*h*a-l*s,e[5]=h*h*a+n,e[6]=l*h*a+o*s,e[7]=0,e[8]=o*l*a+h*s,e[9]=h*l*a-o*s,e[10]=l*l*a+n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e)}function c(e,t,r){var i=t[0],s=t[1],n=t[2],a=t[3],o=i+i,h=s+s,l=n+n,c=i*o,u=i*h,d=i*l,p=s*h,f=s*l,m=n*l,x=a*o,g=a*h,v=a*l;return e[0]=1-(p+m),e[1]=u+v,e[2]=d-g,e[3]=0,e[4]=u-v,e[5]=1-(c+m),e[6]=f+x,e[7]=0,e[8]=d+g,e[9]=f-x,e[10]=1-(c+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 d(e,t){var r=t[0],i=t[1],s=t[2],n=t[4],a=t[5],o=t[6],h=t[8],l=t[9],c=t[10];return e[0]=Math.sqrt(r*r+i*i+s*s),e[1]=Math.sqrt(n*n+a*a+o*o),e[2]=Math.sqrt(h*h+l*l+c*c),e}function p(e,t){var i=new r(3);d(i,t);var s=1/i[0],n=1/i[1],a=1/i[2],o=t[0]*s,h=t[1]*n,l=t[2]*a,c=t[4]*s,u=t[5]*n,p=t[6]*a,f=t[8]*s,m=t[9]*n,x=t[10]*a,g=o+u+x,v=0;return g>0?(v=2*Math.sqrt(g+1),e[3]=.25*v,e[0]=(p-m)/v,e[1]=(f-l)/v,e[2]=(h-c)/v):o>u&&o>x?(v=2*Math.sqrt(1+o-u-x),e[3]=(p-m)/v,e[0]=.25*v,e[1]=(h+c)/v,e[2]=(f+l)/v):u>x?(v=2*Math.sqrt(1+u-o-x),e[3]=(f-l)/v,e[0]=(h+c)/v,e[1]=.25*v,e[2]=(p+m)/v):(v=2*Math.sqrt(1+x-o-u),e[3]=(h-c)/v,e[0]=(f+l)/v,e[1]=(p+m)/v,e[2]=.25*v),e}var f=function(e,t,r,i,s){var n=1/Math.tan(t/2);if(e[0]=n/r,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=n,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 a=1/(i-s);e[10]=(s+i)*a,e[14]=2*s*i*a}else e[10]=-1,e[14]=-2*i;return e};function m(){var e=new r(3);return r!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function x(e,t,i){var s=new r(3);return s[0]=e,s[1]=t,s[2]=i,s}function g(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function v(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],n=r*r+i*i+s*s;return n>0&&(n=1/Math.sqrt(n)),e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e}function w(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],n=t[2],a=r[0],o=r[1],h=r[2];return e[0]=s*h-n*o,e[1]=n*a-i*h,e[2]=i*o-s*a,e}function S(e,t,r,i){var s=t[0],n=t[1],a=t[2];return e[0]=s+i*(r[0]-s),e[1]=n+i*(r[1]-n),e[2]=a+i*(r[2]-a),e}function _(){var e=new r(4);return r!=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],n=t[2],a=t[3];return e[0]=r[0]*i+r[4]*s+r[8]*n+r[12]*a,e[1]=r[1]*i+r[5]*s+r[9]*n+r[13]*a,e[2]=r[2]*i+r[6]*s+r[10]*n+r[14]*a,e[3]=r[3]*i+r[7]*s+r[11]*n+r[15]*a,e}function b(){var e=new r(4);return r!=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(e,r,i,s){var n,a,o,h,l,c=r[0],u=r[1],d=r[2],p=r[3],f=i[0],m=i[1],x=i[2],g=i[3];return(a=c*f+u*m+d*x+p*g)<0&&(a=-a,f=-f,m=-m,x=-x,g=-g),1-a>t?(n=Math.acos(a),o=Math.sin(n),h=Math.sin((1-s)*n)/o,l=Math.sin(s*n)/o):(h=1-s,l=s),e[0]=h*c+l*f,e[1]=h*u+l*m,e[2]=h*d+l*x,e[3]=h*p+l*g,e}m(),function(){var e=_()}();var P,F=function(e,t,i,s){var n=new r(4);return n[0]=e,n[1]=t,n[2]=i,n[3]=s,n},I=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},L=E,C=function(e,t){var r=t[0],i=t[1],s=t[2],n=t[3],a=r*r+i*i+s*s+n*n;return a>0&&(a=1/Math.sqrt(a)),e[0]=r*a,e[1]=i*a,e[2]=s*a,e[3]=n*a,e};m(),x(1,0,0),x(0,1,0),b(),b(),P=new r(9),r!=Float32Array&&(P[1]=0,P[2]=0,P[3]=0,P[5]=0,P[6]=0,P[7]=0),P[0]=1,P[4]=1,P[8]=1;const D=Symbol("@iwer/action-player"),N=Symbol("@iwer/action-recorder"),O=Symbol("@iwer/xr-anchor"),V=Symbol("@iwer/xr-controller"),B=Symbol("@iwer/xr-device"),U=Symbol("@iwer/xr-hand-input"),G=Symbol("@iwer/xr-tracked-input"),X=Symbol("@iwer/xr-frame"),z=Symbol("@iwer/gamepad"),q=Symbol("@iwer/xr-system"),k=Symbol("@iwer/xr-input-source"),H=Symbol("@iwer/xr-webgl-layer"),j=Symbol("@iwer/xr-mesh"),W=Symbol("@iwer/xr-plane"),Y=Symbol("@iwer/xr-joint-pose"),Q=Symbol("@iwer/xr-pose"),$=Symbol("@iwer/xr-viewer-pose"),K=Symbol("@iwer/xr-rigid-transform"),J=Symbol("@iwer/xr-render-state"),Z=Symbol("@iwer/xr-session"),ee=Symbol("@iwer/xr-joint-space"),te=Symbol("@iwer/xr-reference-space"),re=Symbol("@iwer/xr-space"),ie=Symbol("@iwer/xr-view"),se=Symbol("@iwer/xr-viewport"),ne=Symbol("@iwer/xr-ray"),ae=Symbol("@iwer/xr-depth-info"),oe=Symbol("@iwer/xr-hit-test");class he extends EventTarget{constructor(e,t){super(),this[re]={parentSpace:e,offsetMatrix:t?s(t):i(),emulated:!0}}}class le extends he{constructor(){super(void 0,i())}}class ce{static updateOffsetPosition(e,t){h(e[re].offsetMatrix,t)}static updateOffsetQuaternion(e,t){const r=e[re].offsetMatrix,i=m();u(i,r),c(r,t,i)}static updateOffsetMatrix(e,t){n(e[re].offsetMatrix,t)}static calculateGlobalOffsetMatrix(e,t=i()){return o(t,e[re].parentSpace?ce.calculateGlobalOffsetMatrix(e[re].parentSpace):i(),e[re].offsetMatrix),t}}class ue{constructor(e=0,t=0,r=0){this.vec3=x(e,t,r),this.tempVec3=m()}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 v(this.vec3,e,t,r),this}clone(){return new ue(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),y(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],n=r[2],a=r[3],o=t[0],h=t[1],l=t[2],c=s*l-n*h,u=n*o-i*l,d=i*h-s*o;c+=c,u+=u,d+=d,e[0]=o+a*c+s*d-n*u,e[1]=h+a*u+n*c-i*d,e[2]=l+a*d+i*u-s*c}(this.vec3,this.tempVec3,e.quat),this}}class de{constructor(e=0,t=0,r=0,i=1){this.quat=F(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],n=t[2],a=t[3],o=r[0],h=r[1],l=r[2],c=r[3];e[0]=i*c+a*o+s*l-n*h,e[1]=s*c+a*h+n*o-i*l,e[2]=n*c+a*l+i*h-s*o,e[3]=a*c-i*o-s*h-n*l}(this.quat,this.tempQuat,e.quat),this}setFromAxisAngle(e,t){return M(this.quat,e.vec3,t),this}}function pe(e){return{x:e.x,y:e.y,z:e.z}}function fe(e){return{x:e.x,y:e.y,z:e.z,w:e.w}}function me(e){const{x:t,y:r,z:i,w:s}=e,n=180/Math.PI,a=Math.max(-1,Math.min(1,2*(s*t-r*i)));let o;o=Math.abs(a)>=1?Math.sign(a)*Math.PI/2:Math.asin(a);const h=2*(s*r+t*i),l=1-2*(t*t+r*r),c=2*(s*i+t*r),u=1-2*(t*t+i*i);return{pitch:o*n,yaw:Math.atan2(h,l)*n,roll:Math.atan2(c,u)*n}}function xe(e){var t,r,i;const s=Math.PI/180,n=(null!==(t=e.pitch)&&void 0!==t?t:0)*s,a=(null!==(r=e.yaw)&&void 0!==r?r:0)*s,o=(null!==(i=e.roll)&&void 0!==i?i:0)*s,h=Math.cos(.5*n),l=Math.sin(.5*n),c=Math.cos(.5*a),u=Math.sin(.5*a),d=Math.cos(.5*o),p=Math.sin(.5*o);return{w:h*c*d+l*u*p,x:l*c*d+h*u*p,y:h*u*d-l*c*p,z:h*c*p-l*u*d}}function ge(e,t){const r=t.x-e.x,i=t.y-e.y,s=t.z-e.z,n=Math.sqrt(r*r+i*i+s*s);return 0===n?{x:0,y:0,z:-1}:{x:r/n,y:i/n,z:s/n}}function ve(e,t={x:0,y:1,z:0}){const r=Math.sqrt(e.x*e.x+e.y*e.y+e.z*e.z);if(0===r)return{x:0,y:0,z:0,w:1};const i=e.x/r,s=e.y/r,n=e.z/r,a={x:s*t.z-n*t.y,y:n*t.x-i*t.z,z:i*t.y-s*t.x},o=Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z);if(0===o){const e={x:1,y:0,z:0};a.x=s*e.z-n*e.y,a.y=n*e.x-i*e.z,a.z=i*e.y-s*e.x;const t=Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z);a.x/=t,a.y/=t,a.z/=t}else a.x/=o,a.y/=o,a.z/=o;const h={x:a.y*n-a.z*s,y:a.z*i-a.x*n,z:a.x*s-a.y*i},l=a.x,c=h.x,u=-i,d=a.y,p=h.y,f=-s,m=a.z,x=h.z,g=-n,v=l+p+g;let y,w,T,S;if(v>0){const e=.5/Math.sqrt(v+1);y=.25/e,w=(x-f)*e,T=(u-m)*e,S=(d-c)*e}else if(l>p&&l>g){const e=2*Math.sqrt(1+l-p-g);y=(x-f)/e,w=.25*e,T=(c+d)/e,S=(u+m)/e}else if(p>g){const e=2*Math.sqrt(1+p-l-g);y=(u-m)/e,w=(c+d)/e,T=.25*e,S=(f+x)/e}else{const e=2*Math.sqrt(1+g-l-p);y=(d-c)/e,w=(u+m)/e,T=(f+x)/e,S=.25*e}const _=Math.sqrt(w*w+T*T+S*S+y*y);return _>0&&(w/=_,T/=_,S/=_,y/=_),{x:w,y:T,z:S,w:y}}function ye(e,t=5e3){return new Promise((r,i)=>{const s=Date.now(),n=()=>{e()?r():Date.now()-s>t?i(new Error("Timeout waiting for condition")):requestAnimationFrame(n)};n()})}function we(e){return function(e){return"pitch"in e||"yaw"in e||"roll"in e}(e)?xe(e):e}function Te(e,t,r){return e+(t-e)*r}const Se={right:"controller-right",left:"controller-left","right-controller":"controller-right","left-controller":"controller-left","controllers.right":"controller-right","controllers.left":"controller-left",rightController:"controller-right",leftController:"controller-left","right-hand":"hand-right","left-hand":"hand-left","hands.right":"hand-right","hands.left":"hand-left",rightHand:"hand-right",leftHand:"hand-left"};class _e{constructor(e){this.commandQueue=[],this._isCaptured=!1,this.releaseTimer=null,this.actionIdCounter=0,this.RELEASE_TIMEOUT_MS=3e4,this.device=e}generateActionId(){return"action_"+ ++this.actionIdCounter}get isCaptured(){return this._isCaptured}get queueLength(){return this.commandQueue.length}enqueueDiscrete(e,t){return new Promise((r,i)=>{const s={type:"discrete",id:this.generateActionId(),method:e,params:t,resolve:r,reject:i};this.commandQueue.push(s)})}enqueueDuration(e,t,r,i,s){return new Promise((n,a)=>{const o={type:"duration",id:this.generateActionId(),method:e,params:t,durationMs:r,elapsedMs:0,startState:i,targetState:s,resolve:n,reject:a};this.commandQueue.push(o)})}update(e){if(0!==this.commandQueue.length){for(this.cancelReleaseTimer(),this._isCaptured||(this._isCaptured=!0,this.device.controlMode="programmatic");this.commandQueue.length>0;){const t=this.commandQueue[0];if("discrete"===t.type){try{const e=this.executeDiscreteAction(t);t.resolve(e)}catch(e){t.reject(e)}this.commandQueue.shift()}else{if(t.elapsedMs+=e,!(t.elapsedMs>=t.durationMs)){try{const e=t.elapsedMs/t.durationMs;this.applyDurationLerpState(t,e)}catch(e){t.reject(e),this.commandQueue.shift();continue}break}try{this.applyDurationFinalState(t),t.resolve(this.getDurationResult(t))}catch(e){t.reject(e)}this.commandQueue.shift()}}this.device.notifyStateChange(),0===this.commandQueue.length&&this.startReleaseTimer()}}startReleaseTimer(){this.cancelReleaseTimer(),this.releaseTimer=setTimeout(()=>{this._isCaptured=!1,this.device.controlMode="manual",this.releaseTimer=null},this.RELEASE_TIMEOUT_MS)}cancelReleaseTimer(){null!==this.releaseTimer&&(clearTimeout(this.releaseTimer),this.releaseTimer=null)}getDeviceTransform(e){switch(e){case"headset":return{position:pe(this.device.position),orientation:fe(this.device.quaternion)};case"controller-left":{const e=this.device.controllers.left;if(!e)throw new Error("Left controller not available");return{position:pe(e.position),orientation:fe(e.quaternion)}}case"controller-right":{const e=this.device.controllers.right;if(!e)throw new Error("Right controller not available");return{position:pe(e.position),orientation:fe(e.quaternion)}}case"hand-left":{const e=this.device.hands.left;if(!e)throw new Error("Left hand not available");return{position:pe(e.position),orientation:fe(e.quaternion)}}case"hand-right":{const e=this.device.hands.right;if(!e)throw new Error("Right hand not available");return{position:pe(e.position),orientation:fe(e.quaternion)}}default:throw new Error(`Unknown device: ${e}`)}}setDeviceTransform(e,t,r){switch(e){case"headset":t&&this.device.position.set(t.x,t.y,t.z),r&&this.device.quaternion.set(r.x,r.y,r.z,r.w);break;case"controller-left":{const e=this.device.controllers.left;if(!e)throw new Error("Left controller not available");t&&e.position.set(t.x,t.y,t.z),r&&e.quaternion.set(r.x,r.y,r.z,r.w);break}case"controller-right":{const e=this.device.controllers.right;if(!e)throw new Error("Right controller not available");t&&e.position.set(t.x,t.y,t.z),r&&e.quaternion.set(r.x,r.y,r.z,r.w);break}case"hand-left":{const e=this.device.hands.left;if(!e)throw new Error("Left hand not available");t&&e.position.set(t.x,t.y,t.z),r&&e.quaternion.set(r.x,r.y,r.z,r.w);break}case"hand-right":{const e=this.device.hands.right;if(!e)throw new Error("Right hand not available");t&&e.position.set(t.x,t.y,t.z),r&&e.quaternion.set(r.x,r.y,r.z,r.w);break}default:throw new Error(`Unknown device: ${e}`)}}transformXROriginToGlobal(e){var t,r;const i=this.device.activeSession;if(!i)return e;const s=null===(t=i[Z])||void 0===t?void 0:t.referenceSpaces;if(!s||0===s.length)return e;const n=null===(r=s[0][re])||void 0===r?void 0:r.offsetMatrix;if(!n)return e;const a=x(e.x,e.y,e.z);return function(e,t,r){var i=t[0],s=t[1],n=t[2],a=r[3]*i+r[7]*s+r[11]*n+r[15];a=a||1,e[0]=(r[0]*i+r[4]*s+r[8]*n+r[12])/a,e[1]=(r[1]*i+r[5]*s+r[9]*n+r[13])/a,e[2]=(r[2]*i+r[6]*s+r[10]*n+r[14])/a}(a,a,n),{x:a[0],y:a[1],z:a[2]}}getDeviceSelectValue(e){var t,r,i,s,n,a,o,h;switch(e){case"controller-left":return null!==(r=null===(t=this.device.controllers.left)||void 0===t?void 0:t.getButtonValue("trigger"))&&void 0!==r?r:0;case"controller-right":return null!==(s=null===(i=this.device.controllers.right)||void 0===i?void 0:i.getButtonValue("trigger"))&&void 0!==s?s:0;case"hand-left":return null!==(a=null===(n=this.device.hands.left)||void 0===n?void 0:n.pinchValue)&&void 0!==a?a:0;case"hand-right":return null!==(h=null===(o=this.device.hands.right)||void 0===o?void 0:o.pinchValue)&&void 0!==h?h:0;default:throw new Error(`Unknown input device: ${e}`)}}setDeviceSelectValue(e,t){var r,i,s,n;switch(e){case"controller-left":null===(r=this.device.controllers.left)||void 0===r||r.updateButtonValue("trigger",t);break;case"controller-right":null===(i=this.device.controllers.right)||void 0===i||i.updateButtonValue("trigger",t);break;case"hand-left":null===(s=this.device.hands.left)||void 0===s||s.updatePinchValue(t);break;case"hand-right":null===(n=this.device.hands.right)||void 0===n||n.updatePinchValue(t);break;default:throw new Error(`Unknown input device: ${e}`)}}setDeviceConnected(e,t){switch(e){case"controller-left":this.device.controllers.left&&(this.device.controllers.left.connected=t);break;case"controller-right":this.device.controllers.right&&(this.device.controllers.right.connected=t);break;case"hand-left":this.device.hands.left&&(this.device.hands.left.connected=t);break;case"hand-right":this.device.hands.right&&(this.device.hands.right.connected=t);break;default:throw new Error(`Unknown input device: ${e}`)}}executeDiscreteAction(e){const{method:t,params:r}=e;switch(t){case"get_session_status":return this.executeGetSessionStatus();case"accept_session":return this.executeAcceptSession();case"end_session":return this.executeEndSession();case"get_transform":return this.executeGetTransform(r);case"set_transform":return this.executeSetTransform(r);case"look_at":return this.executeLookAt(r);case"set_input_mode":return this.executeSetInputMode(r);case"set_connected":return this.executeSetConnected(r);case"get_select_value":return this.executeGetSelectValue(r);case"set_select_value":return this.executeSetSelectValue(r);case"get_gamepad_state":return this.executeGetGamepadState(r);case"set_gamepad_state":return this.executeSetGamepadState(r);case"get_device_state":return this.executeGetDeviceState();case"set_device_state":return this.executeSetDeviceState(r);case"capture_canvas":return this.executeCaptureCanvas(r);case"_select_press":{const e=r.device;return void this.setDeviceSelectValue(e,1)}case"_select_release":{const e=r.device;return void this.setDeviceSelectValue(e,0)}default:throw new Error(`Unknown method: ${t}`)}}executeGetSessionStatus(){const e=this.device.activeSession;return{deviceName:this.device.name,isRuntimeInstalled:!0,sessionActive:!!e,sessionOffered:this.device.sessionOffered,sessionMode:e?e.mode:null,enabledFeatures:e?Array.from(e.enabledFeatures||[]):[],visibilityState:this.device.visibilityState}}executeAcceptSession(){if(!this.device.sessionOffered)throw new Error("No session has been offered");return this.device.grantOfferedSession(),{success:!0}}executeEndSession(){const e=this.device.activeSession;if(!e)throw new Error("No active session");return e.end(),{success:!0}}executeGetTransform(e){const{device:t}=e,r=this.getDeviceTransform(t);return{device:t,position:r.position,orientation:r.orientation,euler:me(r.orientation)}}executeSetTransform(e){const{device:t,position:r,orientation:i}=e,s=i?we(i):void 0;this.setDeviceTransform(t,r,s);const n=this.getDeviceTransform(t);return{device:t,position:n.position,orientation:n.orientation}}executeLookAt(e){const{device:t,target:r,moveToDistance:i}=e,s=this.getDeviceTransform(t),n=this.transformXROriginToGlobal(r),a=ge(s.position,n),o="headset"===t?function(e){const t=Math.sqrt(e.x*e.x+e.z*e.z);let r=0;t>1e-4&&(r=Math.atan2(-e.x,-e.z));const i=Math.atan2(e.y,t),s=180/Math.PI;return xe({pitch:i*s,yaw:r*s,roll:0})}(a):ve(a);let h;void 0!==i&&(h={x:n.x-a.x*i,y:n.y-a.y*i,z:n.z-a.z*i}),this.setDeviceTransform(t,h,o);const l=this.getDeviceTransform(t);return{device:t,position:l.position,orientation:l.orientation}}executeSetInputMode(e){var t,r,i,s;const{mode:n}=e;this.device.primaryInputMode=n;const a=[];return"controller"===n?((null===(t=this.device.controllers.left)||void 0===t?void 0:t.connected)&&a.push("controller-left"),(null===(r=this.device.controllers.right)||void 0===r?void 0:r.connected)&&a.push("controller-right")):((null===(i=this.device.hands.left)||void 0===i?void 0:i.connected)&&a.push("hand-left"),(null===(s=this.device.hands.right)||void 0===s?void 0:s.connected)&&a.push("hand-right")),{mode:n,activeDevices:a}}executeSetConnected(e){const{device:t,connected:r}=e;return this.setDeviceConnected(t,r),{device:t,connected:r}}executeGetSelectValue(e){const{device:t}=e;return{device:t,value:this.getDeviceSelectValue(t)}}executeSetSelectValue(e){const{device:t,value:r}=e;return this.setDeviceSelectValue(t,r),{device:t,value:r}}executeGetGamepadState(e){const{device:t}=e,r="controller-left"===t?"left":"right",i=this.device.controllers[r];if(!i)throw new Error(`Controller ${r} not available`);const s=["trigger","squeeze","thumbstick","left"===r?"x-button":"a-button","left"===r?"y-button":"b-button","thumbrest"].map((e,t)=>({index:t,name:e.replace("x-button","x").replace("y-button","y").replace("a-button","a").replace("b-button","b"),value:i.getButtonValue(e),touched:i.getButtonTouched(e),pressed:i.getButtonValue(e)>.5})),n=i.getAxes(),a=[{index:0,name:"thumbstick-x",value:n.x},{index:1,name:"thumbstick-y",value:n.y}];return{device:t,connected:i.connected,buttons:s,axes:a}}executeSetGamepadState(e){const{device:t,buttons:r,axes:i}=e,s="controller-left"===t?"left":"right",n=this.device.controllers[s];if(!n)throw new Error(`Controller ${s} not available`);let a=0,o=0;const h=["trigger","squeeze","thumbstick","left"===s?"x-button":"a-button","left"===s?"y-button":"b-button","thumbrest"];if(r)for(const e of r){const t=h[e.index];t&&(n.updateButtonValue(t,e.value),void 0!==e.touched&&n.updateButtonTouch(t,e.touched),a++)}if(i){let e,t;for(const r of i)0===r.index?(e=r.value,o++):1===r.index&&(t=r.value,o++);if(void 0!==e||void 0!==t){const r=n.getAxes();n.updateAxes("thumbstick",null!=e?e:r.x,null!=t?t:r.y)}}return{device:t,buttonsSet:a,axesSet:o}}executeGetDeviceState(){var e,t,r,i,s,n,a,o,h,l,c,u,d,p,f,m,x,g,v,y,w,T,S,_;return{headset:{position:pe(this.device.position),orientation:fe(this.device.quaternion)},inputMode:this.device.primaryInputMode,controllers:{left:{connected:null!==(t=null===(e=this.device.controllers.left)||void 0===e?void 0:e.connected)&&void 0!==t&&t,position:pe(null!==(i=null===(r=this.device.controllers.left)||void 0===r?void 0:r.position)&&void 0!==i?i:{x:0,y:0,z:0}),orientation:fe(null!==(n=null===(s=this.device.controllers.left)||void 0===s?void 0:s.quaternion)&&void 0!==n?n:{x:0,y:0,z:0,w:1})},right:{connected:null!==(o=null===(a=this.device.controllers.right)||void 0===a?void 0:a.connected)&&void 0!==o&&o,position:pe(null!==(l=null===(h=this.device.controllers.right)||void 0===h?void 0:h.position)&&void 0!==l?l:{x:0,y:0,z:0}),orientation:fe(null!==(u=null===(c=this.device.controllers.right)||void 0===c?void 0:c.quaternion)&&void 0!==u?u:{x:0,y:0,z:0,w:1})}},hands:{left:{connected:null!==(p=null===(d=this.device.hands.left)||void 0===d?void 0:d.connected)&&void 0!==p&&p,position:pe(null!==(m=null===(f=this.device.hands.left)||void 0===f?void 0:f.position)&&void 0!==m?m:{x:0,y:0,z:0}),orientation:fe(null!==(g=null===(x=this.device.hands.left)||void 0===x?void 0:x.quaternion)&&void 0!==g?g:{x:0,y:0,z:0,w:1})},right:{connected:null!==(y=null===(v=this.device.hands.right)||void 0===v?void 0:v.connected)&&void 0!==y&&y,position:pe(null!==(T=null===(w=this.device.hands.right)||void 0===w?void 0:w.position)&&void 0!==T?T:{x:0,y:0,z:0}),orientation:fe(null!==(_=null===(S=this.device.hands.right)||void 0===S?void 0:S.quaternion)&&void 0!==_?_:{x:0,y:0,z:0,w:1})}},stereoEnabled:this.device.stereoEnabled,fov:this.device.fovy*(180/Math.PI)}}executeSetDeviceState(e){const{state:t}=e;return t?(t.headset&&(t.headset.position&&this.device.position.set(t.headset.position.x,t.headset.position.y,t.headset.position.z),t.headset.orientation&&this.device.quaternion.set(t.headset.orientation.x,t.headset.orientation.y,t.headset.orientation.z,t.headset.orientation.w)),void 0!==t.inputMode&&(this.device.primaryInputMode=t.inputMode),void 0!==t.stereoEnabled&&(this.device.stereoEnabled=t.stereoEnabled),void 0!==t.fov&&(this.device.fovy=t.fov*(Math.PI/180)),t.controllers&&(this.applyInputState("controller-left",t.controllers.left),this.applyInputState("controller-right",t.controllers.right)),t.hands&&(this.applyInputState("hand-left",t.hands.left),this.applyInputState("hand-right",t.hands.right))):(this.device.position.set(0,1.6,0),this.device.quaternion.set(0,0,0,1),this.device.primaryInputMode="controller",this.device.stereoEnabled=!1,this.device.controllers.left&&(this.device.controllers.left.position.set(-.2,1.4,-.3),this.device.controllers.left.quaternion.set(0,0,0,1),this.device.controllers.left.connected=!0),this.device.controllers.right&&(this.device.controllers.right.position.set(.2,1.4,-.3),this.device.controllers.right.quaternion.set(0,0,0,1),this.device.controllers.right.connected=!0),this.device.hands.left&&(this.device.hands.left.position.set(-.15,1.3,-.4),this.device.hands.left.quaternion.set(0,0,0,1),this.device.hands.left.connected=!0),this.device.hands.right&&(this.device.hands.right.position.set(.15,1.3,-.4),this.device.hands.right.quaternion.set(0,0,0,1),this.device.hands.right.connected=!0)),{state:this.executeGetDeviceState()}}applyInputState(e,t){t&&(void 0!==t.connected&&this.setDeviceConnected(e,t.connected),(t.position||t.orientation)&&this.setDeviceTransform(e,t.position,t.orientation))}executeCaptureCanvas(e){const{maxWidth:t=800,format:r="png",quality:i=.92}=e;let s=this.device.appCanvas;if(!s){const e=document.querySelectorAll("canvas");if(1===e.length)s=e[0];else if(e.length>1){let t=null,r=0;e.forEach(e=>{const i=e.getBoundingClientRect(),s=i.width*i.height;s>r&&i.width>0&&i.height>0&&(r=s,t=e)}),s=t}}if(!s)throw new Error("No canvas available. Either start an XR session or ensure an app canvas is in the DOM.");const n=document.createElement("canvas"),a=n.getContext("2d");if(!a)throw new Error("Failed to create canvas context");const o=s.height/s.width,h=Math.min(s.width,t),l=Math.round(h*o);n.width=h,n.height=l,a.drawImage(s,0,0,h,l);const c=`image/${r}`;return{imageData:n.toDataURL(c,i).split(",")[1],width:h,height:l,format:r,timestamp:Date.now()}}applyDurationLerpState(e,t){const{startState:r,targetState:i,params:s}=e,n=s.device;let a,o;r.position&&i.position&&(a=function(e,t,r){return{x:Te(e.x,t.x,r),y:Te(e.y,t.y,r),z:Te(e.z,t.z,r)}}(r.position,i.position,t)),r.orientation&&i.orientation&&(o=function(e,t,r){let i=e.x*t.x+e.y*t.y+e.z*t.z+e.w*t.w,s=t.x,n=t.y,a=t.z,o=t.w;if(i<0&&(i=-i,s=-s,n=-n,a=-a,o=-o),i>.9995){const t={x:Te(e.x,s,r),y:Te(e.y,n,r),z:Te(e.z,a,r),w:Te(e.w,o,r)},i=Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w);return{x:t.x/i,y:t.y/i,z:t.z/i,w:t.w/i}}const h=Math.acos(i),l=h*r,c=Math.sin(l),u=Math.sin(h),d=Math.cos(l)-i*c/u,p=c/u;return{x:d*e.x+p*s,y:d*e.y+p*n,z:d*e.z+p*a,w:d*e.w+p*o}}(r.orientation,i.orientation,t)),this.setDeviceTransform(n,a,o)}applyDurationFinalState(e){const{targetState:t,params:r}=e,i=r.device;this.setDeviceTransform(i,t.position,t.orientation)}getDurationResult(e){const{params:t,elapsedMs:r}=e,i=t.device,s=this.getDeviceTransform(i);return{device:i,position:s.position,orientation:s.orientation,actualDuration:r/1e3}}activateCaptureMode(){this._isCaptured||(this._isCaptured=!0,this.cancelReleaseTimer(),this.device.controlMode="programmatic"),this.startReleaseTimer()}async dispatch(e,t={}){var r;if("string"==typeof t.device&&(t.device=function(e){var t;return null!==(t=Se[e])&&void 0!==t?t:e}(t.device)),_e.IMMEDIATE_METHODS.has(e))return _e.ACTIVE_IMMEDIATE_METHODS.has(e)&&this.activateCaptureMode(),this.executeImmediateMethod(e,t);if(_e.SESSION_REQUIRED_METHODS.has(e)&&!this.device.activeSession)throw new Error(`Cannot execute '${e}': No active XR session. Use 'get_session_status' to check session state, and 'accept_session' to start a session.`);if("animate_to"===e){const i=t,s=this.getDeviceTransform(i.device),n=1e3*(null!==(r=i.duration)&&void 0!==r?r:.5),a=i.orientation?we(i.orientation):void 0,o=i.position?this.transformXROriginToGlobal(i.position):void 0;return this.enqueueDuration(e,t,n,{position:i.position?s.position:void 0,orientation:a?s.orientation:void 0},{position:o,orientation:a})}if("select"===e){const e=t;return this.executeSelectSequence(e)}return this.enqueueDiscrete(e,t)}executeImmediateMethod(e,t){switch(e){case"get_session_status":return this.executeGetSessionStatus();case"accept_session":return this.executeAcceptSession();case"end_session":return this.executeEndSession();case"get_transform":return this.executeGetTransform(t);case"get_select_value":return this.executeGetSelectValue(t);case"get_gamepad_state":return this.executeGetGamepadState(t);case"get_device_state":return this.executeGetDeviceState();case"capture_canvas":return this.executeCaptureCanvas(t);default:throw new Error(`Unknown immediate method: ${e}`)}}executeSelectSequence(e){const{device:t,duration:r=.15}=e;return this.getDeviceSelectValue(t),new Promise((e,i)=>{let s=0;const n=()=>{s++,3===s&&e({device:t,duration:r})},a={type:"discrete",id:this.generateActionId(),method:"_select_press",params:{device:t},resolve:n,reject:i},o={type:"duration",id:this.generateActionId(),method:"_select_wait",params:{device:t},durationMs:1e3*r,elapsedMs:0,startState:{},targetState:{},resolve:n,reject:i},h={type:"discrete",id:this.generateActionId(),method:"_select_release",params:{device:t},resolve:n,reject:i};this.commandQueue.push(a,o,h)})}async acceptSession(){if(!this.device.sessionOffered)throw new Error("No session has been offered");return this.device.grantOfferedSession(),await ye(()=>!!this.device.activeSession,5e3),{success:!0}}forceRelease(){this.cancelReleaseTimer(),this._isCaptured=!1,this.device.controlMode="manual";for(const e of this.commandQueue)e.reject(new Error("Capture released"));this.commandQueue=[];for(const e of["left","right"]){const t=this.device.controllers[e];t&&(t.updateButtonValue("trigger",0),t.updateButtonValue("squeeze",0))}}}var Ee,Re,be;_e.IMMEDIATE_METHODS=new Set(["get_session_status","accept_session","end_session","get_transform","get_select_value","get_gamepad_state","get_device_state","capture_canvas"]),_e.ACTIVE_IMMEDIATE_METHODS=new Set(["accept_session","end_session"]),_e.SESSION_REQUIRED_METHODS=new Set(["set_transform","look_at","animate_to","set_input_mode","set_connected","set_select_value","select","set_gamepad_state","set_device_state"]),function(e){e.None="",e.Standard="standard",e.XRStandard="xr-standard"}(Ee||(Ee={}));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 Ae{constructor(){this.pressed=!1,this.touched=!1,this.value=0}}class Pe{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 Ae: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"}(Re||(Re={})),function(e){e.Gaze="gaze",e.TrackedPointer="tracked-pointer",e.Screen="screen",e.TransientPointer="transient-pointer"}(be||(be={}));class Fe extends Array{}class Ie{constructor(e,t,r,i,s,n,a){this[k]={handedness:e,targetRayMode:t,targetRaySpace:i,gripSpace:n,profiles:r,gamepad:s,hand:a}}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 Le 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 Ce={[Re.Left]:{position:new ue(-.25,1.5,-.4),quaternion:new de},[Re.Right]:{position:new ue(.25,1.5,-.4),quaternion:new de},[Re.None]:{position:new ue(.25,1.5,-.4),quaternion:new de}};class De{constructor(e){this[G]={inputSource:e,position:Ce[e.handedness].position.clone(),quaternion:Ce[e.handedness].quaternion.clone(),connected:!0,lastFrameConnected:!1,inputSourceChanged:!0}}get position(){return this[G].position}get quaternion(){return this[G].quaternion}get inputSource(){return this[G].inputSource}get connected(){return this[G].connected}set connected(e){this[G].connected=e,this[G].inputSource.gamepad[z].connected=e}onFrameStart(e){c(this[G].inputSource.targetRaySpace[re].offsetMatrix,this[G].quaternion.quat,this[G].position.vec3);const t=e.session;this[G].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 Le(r[z].eventTrigger,{frame:e,inputSource:this[G].inputSource})),t.dispatchEvent(new Le(r[z].eventTrigger+"start",{frame:e,inputSource:this[G].inputSource}))):r[z].lastFrameValue>0&&0===r[z].value&&t.dispatchEvent(new Le(r[z].eventTrigger+"end",{frame:e,inputSource:this[G].inputSource}))))}),this[G].inputSourceChanged=this.connected!==this[G].lastFrameConnected,this[G].lastFrameConnected=this.connected}}class Ne extends De{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,n=[e.profileId,...e.fallbackProfileIds];super(new Ie(t,be.TrackedPointer,n,i,new Pe(e.layout[t].gamepad),s)),this[V]={profileId:e.profileId,gamepadConfig:e.layout[t].gamepad}}get gamepadConfig(){return this[V].gamepadConfig}get profileId(){return this[V].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[G].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}.`)}setButtonValueImmediate(e,t){if(t>1||t<0)return void console.warn(`Out-of-range value ${t} provided for button ${e}.`);const r=this[G].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].value=t,r[z].pendingValue=t}else console.warn(`Current controller does not have button ${e}.`)}updateButtonTouch(e,t){const r=this[G].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[G].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[G].inputSource.gamepad[z].axesMap[e];i?(i.x=t,i.y=r):console.warn(`Current controller does not have ${e} axes.`)}getButtonValue(e){var t;const r=this[G].inputSource.gamepad[z].buttonsMap[e];return r?null!==(t=r[z].pendingValue)&&void 0!==t?t:r.value:0}getButtonTouched(e){const t=this[G].inputSource.gamepad[z].buttonsMap[e];return!!t&&t.touched}getAxes(e="thumbstick"){const t=this[G].inputSource.gamepad[z].axesMap[e];return t?{x:t.x,y:t.y}:{x:0,y:0}}}class Oe{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 Ve extends Set{}var Be,Ue;e.XRSemanticLabels=void 0,(Be=e.XRSemanticLabels||(e.XRSemanticLabels={})).Desk="desk",Be.Couch="couch",Be.Floor="floor",Be.Ceiling="ceiling",Be.Wall="wall",Be.Door="door",Be.Window="window",Be.Table="table",Be.Shelf="shelf",Be.Bed="bed",Be.Screen="screen",Be.Lamp="lamp",Be.Plant="plant",Be.WallArt="wall art",Be.GlobalMesh="global mesh",Be.Other="other",function(e){e.Horizontal="horizontal",e.Vertical="vertical"}(Ue||(Ue={}));const Ge={[e.XRSemanticLabels.Desk]:Ue.Horizontal,[e.XRSemanticLabels.Couch]:Ue.Horizontal,[e.XRSemanticLabels.Floor]:Ue.Horizontal,[e.XRSemanticLabels.Ceiling]:Ue.Horizontal,[e.XRSemanticLabels.Wall]:Ue.Vertical,[e.XRSemanticLabels.Door]:Ue.Vertical,[e.XRSemanticLabels.Window]:Ue.Vertical,[e.XRSemanticLabels.Table]:Ue.Horizontal,[e.XRSemanticLabels.Shelf]:Ue.Horizontal,[e.XRSemanticLabels.Bed]:Ue.Horizontal,[e.XRSemanticLabels.Screen]:Ue.Horizontal,[e.XRSemanticLabels.Lamp]:Ue.Horizontal,[e.XRSemanticLabels.Plant]:Ue.Horizontal,[e.XRSemanticLabels.WallArt]:Ue.Vertical};class Xe{constructor(e,t,r,i){this[W]={nativePlane:e,frame:void 0,planeSpace:t,polygon:r,lastChangedTime:performance.now(),semanticLabel:i,orientation:i?Ge[i]:void 0}}get planeSpace(){return this[W].planeSpace}get polygon(){return this[W].polygon}get orientation(){return this[W].orientation}get lastChangedTime(){return this[W].lastChangedTime}get semanticLabel(){return this[W].semanticLabel}}class ze extends Set{}class qe{constructor(e,t,r,i,s,n){this[ae]={data:e,width:t,height:r,normDepthBufferFromNormView:i,rawValueToMeters:s,dataFormat:n}}get data(){return this[ae].data}get width(){return this[ae].width}get height(){return this[ae].height}get normDepthBufferFromNormView(){return this[ae].normDepthBufferFromNormView}get rawValueToMeters(){return this[ae].rawValueToMeters}getDepthInMeters(e,t){const{width:r,height:i,rawValueToMeters:s,data:n,dataFormat:a}=this[ae];if(e<0||e>=1||t<0||t>=1)throw new RangeError("Normalized coordinates must be in [0, 1) range.");const o=Math.floor(e*r),h=Math.floor(t*i);if("float32"===a){return new Float32Array(n)[h*r+o]*s}{const e=new Uint8Array(n),t=2*(h*r+o);return(e[t]+256*e[t+1])*s}}}class ke{constructor(e,t){this[O]={anchorSpace:e,session:t,deleted:!1},t[Z].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[Z].persistentAnchors;for(const[r,i]of t.entries())if(i===this)return void e(r);const r=crypto.randomUUID();We.createPersistentAnchor(this[O].session,this,r),e(r)}})}delete(){this[O].deleted||(this[O].anchorSpace=null,this[O].deleted=!0,this[O].session[Z].trackedAnchors.delete(this))}}class He extends Set{}const je="@immersive-web-emulation-runtime/persistent-anchors";class We{static recoverPersistentAnchorsFromStorage(e){const t=JSON.parse(localStorage.getItem(je)||"{}");Object.entries(t).forEach(([t,r])=>{const i=e[Z].device[B].globalSpace,s=new he(i,r),n=new ke(s,e);e[Z].persistentAnchors.set(t,n)})}static createPersistentAnchor(e,t,r){e[Z].trackedAnchors.add(t),e[Z].persistentAnchors.set(r,t);const i=JSON.parse(localStorage.getItem(je)||"{}");i[r]=Array.from(t[O].anchorSpace[re].offsetMatrix),localStorage.setItem(je,JSON.stringify(i))}}class Ye{constructor(e,t){const r=x(0,0,0),s=b();this[K]={matrix:i(),position:e?x(e.x,e.y,e.z):r,orientation:t?C(b(),F(t.x,t.y,t.z,t.w)):s,inverse:null},this.updateMatrix()}updateMatrix(){c(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=i();if(!a(e,this[K].matrix))throw new Error("Matrix is not invertible.");let t=m();u(t,e);let r=b();p(r,e),this[K].inverse=new Ye(new DOMPointReadOnly(t[0],t[1],t[2],1),new DOMPointReadOnly(r[0],r[1],r[2],r[3])),this[K].inverse[K].inverse=this}return this[K].inverse}}class Qe{constructor(e=0,t=0,r=0,i=1){this.x=e,this.y=t,this.z=r,this.w=i}}class $e{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 Ye){const t=e.matrix,s=E(_(),r.x,r.y,r.z,r.w),n=E(_(),i.x,i.y,i.z,i.w);R(s,s,t),R(n,n,t),r.x=s[0],r.y=s[1],r.z=s[2],r.w=s[3],i.x=n[0],i.y=n[1],i.z=n[2],i.w=n[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 Qe(r.x,r.y,r.z,r.w),direction:new Qe(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=v(m(),0,0,-1),t=v(m(),this[ne].origin.x,this[ne].origin.y,this[ne].origin.z),r=v(m(),this[ne].direction.x,this[ne].direction.y,this[ne].direction.z),s=T(m(),r,e),n=w(r,e),a=i();n>-1&&n<1?l(a,Math.acos(n),s):-1===n?l(a,Math.acos(n),v(m(),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}(a);const c=h(i(),t),u=o(i(),c,a);return this[ne].matrix=new Float32Array(u),this[ne].matrix}}class Ke{constructor(e,t){var r;this[oe]={session:e,space:t.space,offsetRay:null!==(r=t.offsetRay)&&void 0!==r?r:new $e}}cancel(){this[oe].session[Z].hitTestSources.delete(this)}}class Je{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 Ye,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 et,tt,rt;!function(e){e.Viewer="viewer",e.Local="local",e.LocalFloor="local-floor",e.BoundedFloor="bounded-floor",e.Unbounded="unbounded"}(tt||(tt={}));class it extends he{constructor(e,t,r){super(t,r),this[et]={type:null,onreset:()=>{}},this[te].type=e}get onreset(){var e;return null!==(e=this[te].onreset)&&void 0!==e?e:()=>{}}set onreset(e){this[te].onreset&&this.removeEventListener("reset",this[te].onreset),this[te].onreset=e,e&&this.addEventListener("reset",e)}getOffsetReferenceSpace(e){return new it(this[te].type,this,e)}}et=te;class st{constructor(e={},t){this[J]={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[J].depthNear}get depthFar(){return this[J].depthFar}get inlineVerticalFieldOfView(){return this[J].inlineVerticalFieldOfView}get baseLayer(){return this[J].baseLayer}}class nt 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"}(rt||(rt={}));class at{constructor(e,t,r,i){this[ie]={eye:e,projectionMatrix:t,transform:r,recommendedViewportScale:null,requestedViewportScale:1,session:i}}get eye(){return this[ie].eye}get projectionMatrix(){return this[ie].projectionMatrix}get transform(){return this[ie].transform}get recommendedViewportScale(){return this[ie].recommendedViewportScale}requestViewportScale(e){null===e||e<=0||e>1?console.warn("Invalid scale value. Scale must be > 0 and <= 1."):this[ie].requestedViewportScale=e}}class ot{constructor(e,t=!1,r=void 0,i=void 0){this[Q]={transform:e,emulatedPosition:t,linearVelocity:r,angularVelocity:i}}get transform(){return this[Q].transform}get emulatedPosition(){return this[Q].emulatedPosition}get linearVelocity(){return this[Q].linearVelocity}get angularVelocity(){return this[Q].angularVelocity}}class ht extends ot{constructor(e,t,r=!1,i=void 0,s=void 0){super(e,r,i,s),this[Y]={radius:t}}get radius(){return this[Y].radius}}class lt extends ot{constructor(e,t,r=!1,i=void 0,s=void 0){super(e,r,i,s),this[$]={views:Object.freeze(t)}}get views(){return this[$].views}}const ct=i(),ut=i(),dt=i(),pt=(e,t,r)=>{ce.calculateGlobalOffsetMatrix(t,ct),ce.calculateGlobalOffsetMatrix(r,ut),a(dt,ut),o(e,dt,ct)};class ft{constructor(e,t,r,s,n){this[X]={session:e,id:t,active:r,animationFrame:s,predictedDisplayTime:n,tempMat4:i(),detectedPlanes:new ze,detectedMeshes:new Ve,trackedAnchors:e[Z].frameTrackedAnchors,hitTestResultsMap:new Map,depthDataMap:new Map}}get session(){return this[X].session}get predictedDisplayTime(){return this[X].predictedDisplayTime}getPose(e,t){if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");pt(this[X].tempMat4,e,t);const r=m();u(r,this[X].tempMat4);const i=b();return p(i,this[X].tempMat4),new ot(new Ye({x:r[0],y:r[1],z:r[2],w:1},{x:i[0],y:i[1],z:i[2],w:i[3]}),e[re].emulated)}getViewerPose(e){if(!this[X].animationFrame)throw new DOMException("getViewerPose can only be called on XRFrame objects passed to XRSession.requestAnimationFrame callbacks.","InvalidStateError");const t=this[X].session,r=t[Z].device,i=this.getPose(r.viewerSpace,e),s="inline"===t[Z].mode?[rt.None]:[rt.Left,rt.Right],n=[];return s.forEach(i=>{const s=r.viewSpaces[i],a=this.getPose(s,e),o=t[Z].getProjectionMatrix(i),h=new at(i,new Float32Array(o),a.transform,t);n.push(h)}),new lt(i.transform,n,!1)}getJointPose(e,t){const r=this.getPose(e,t),i=e[ee].radius;return new ht(r.transform,i,!1)}fillJointRadii(e,t){if(e=Array.from(e),!this[X].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][ee].radius?t[i]=e[i][ee].radius:(t[i]=NaN,r=!1);return r}fillPoses(e,t,r){if(e=Array.from(e),!this[X].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)=>{pt(this[X].tempMat4,e,t);for(let e=0;e<16;e++)r[16*i+e]=this[X].tempMat4[e]}),!0}get detectedPlanes(){if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[X].detectedPlanes}get detectedMeshes(){if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[X].detectedMeshes}get trackedAnchors(){if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");return this[X].trackedAnchors}createAnchor(e,t){return new Promise((r,i)=>{if(this[X].active){const s=this[X].session[Z].device[B].globalSpace,n=new he(t,e.matrix),a=ce.calculateGlobalOffsetMatrix(n),o=new he(s,a),h=new ke(o,this[X].session);this[X].session[Z].trackedAnchors.add(h),this[X].session[Z].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[X].active){if(this[X].hitTestResultsMap.has(e))return[...this[X].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")}getDepthInformation(e){var t;if(!this[X].active)throw new DOMException("XRFrame access outside the callback that produced it is invalid.","InvalidStateError");if(!this[X].session[Z].enabledFeatures.includes("depth-sensing"))throw new DOMException("depth-sensing feature is not enabled on this session.","InvalidStateError");return null!==(t=this[X].depthDataMap.get(e[ie].eye))&&void 0!==t?t:null}}var mt,xt,gt;!function(e){e.Opaque="opaque",e.AlphaBlend="alpha-blend",e.Additive="additive"}(mt||(mt={})),function(e){e.ScreenSpace="screen-space",e.WorldSpace="world-space"}(xt||(xt={}));class vt extends EventTarget{constructor(e,t,r){super(),this[Z]={device:e,mode:t,renderState:new st,pendingRenderState:null,enabledFeatures:r,isSystemKeyboardSupported:!1,ended:!1,projectionMatrices:{[rt.Left]:i(),[rt.Right]:i(),[rt.None]:i()},getProjectionMatrix:e=>this[Z].projectionMatrices[e],referenceSpaceIsSupported:e=>{if(!this[Z].enabledFeatures.includes(e))return!1;switch(e){case tt.Viewer:return!0;case tt.Local:case tt.LocalFloor:case tt.BoundedFloor:case tt.Unbounded:return"inline"!=this[Z].mode}},frameHandle:0,frameCallbacks:[],currentFrameCallbacks:null,onDeviceFrame:()=>{if(this[Z].ended)return;this[Z].deviceFrameHandle=globalThis.requestAnimationFrame(this[Z].onDeviceFrame),null!=this[Z].pendingRenderState&&(this[Z].renderState=this[Z].pendingRenderState,this[Z].pendingRenderState=null,this[Z].device[B].onBaseLayerSet(this[Z].renderState.baseLayer));const e=this[Z].renderState.baseLayer;if(null===e)return;const t=e.context,r=t.canvas;if("inline"!=this[Z].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:s}=this[Z].renderState,{width:a,height:o}=r;if("inline"!==this[Z].mode){const e=a*(this[Z].device.stereoEnabled?.5:1)/o;f(this[Z].projectionMatrices[rt.Left],this[Z].device.fovy,e,i,s),n(this[Z].projectionMatrices[rt.Right],this[Z].projectionMatrices[rt.Left])}else{const e=a/o;f(this[Z].projectionMatrices[rt.None],this[Z].renderState.inlineVerticalFieldOfView,e,i,s)}const h=new ft(this,this[Z].frameHandle,!0,!0,performance.now()),l=performance.now(),c=this[Z].device[B].devui;if(c&&c.render(l),"immersive-ar"===this[Z].mode){const e=this[Z].device[B].sem;e&&e.render(l)}this[Z].enabledFeatures.includes("anchors")&&this[Z].updateTrackedAnchors(),this[Z].enabledFeatures.includes("plane-detection")&&this[Z].updateTrackedPlanes(h),this[Z].enabledFeatures.includes("mesh-detection")&&this[Z].updateTrackedMeshes(h),this[Z].enabledFeatures.includes("depth-sensing")&&this[Z].computeDepthSensing(h),this[Z].enabledFeatures.includes("hit-test")&&this[Z].computeHitTestResults(h),this[Z].device[B].onFrameStart(h),this[Z].updateActiveInputSources();const u=this[Z].currentFrameCallbacks=this[Z].frameCallbacks;this[Z].frameCallbacks=[];const d=performance.now();for(let e=0;e<u.length;e++)try{u[e].cancelled||u[e].callback(d,h)}catch(e){console.error(e)}this[Z].currentFrameCallbacks=null,h[X].active=!1},nominalFrameRate:e.internalNominalFrameRate,referenceSpaces:[],inputSourceArray:[],activeInputSources:[],updateActiveInputSources:()=>{const e=this[Z].enabledFeatures.includes("hand-tracking"),t=this[Z].activeInputSources,r=this[Z].device.inputSources.filter(t=>!t.hand||e),i=r.filter(e=>!t.includes(e)),s=t.filter(e=>!r.includes(e));this[Z].activeInputSources=r,(i.length>0||s.length>0)&&this.dispatchEvent(new Ze("inputsourceschange",{session:this,added:i,removed:s}))},trackedAnchors:new He,persistentAnchors:new Map,newAnchors:new Map,frameTrackedAnchors:new He,updateTrackedAnchors:()=>{this[Z].enabledFeatures.includes("anchors")&&(this[Z].frameTrackedAnchors.clear(),Array.from(this[Z].trackedAnchors).forEach(e=>{if(e[O].deleted){if(this[Z].trackedAnchors.delete(e),this[Z].newAnchors.has(e)){const{reject:t}=this[Z].newAnchors.get(e);t(new DOMException("Anchor is no longer tracked","InvalidStateError"))}}else if(this[Z].frameTrackedAnchors.add(e),this[Z].newAnchors.has(e)){const{resolve:t}=this[Z].newAnchors.get(e);t(e),this[Z].newAnchors.delete(e)}}))},trackedPlanes:new Map,updateTrackedPlanes:e=>{const t=this[Z].device[B].sem;if(!t)return;Array.from(this[Z].trackedPlanes.keys()).forEach(e=>{t.trackedPlanes.has(e)||this[Z].trackedPlanes.delete(e)}),t.trackedPlanes.forEach(t=>{let r=this[Z].trackedPlanes.get(t);if(!r){const e=new he(this[Z].device[B].globalSpace,t.transform.matrix);r=new Xe(t,e,t.polygon,t.semanticLabel),this[Z].trackedPlanes.set(t,r)}r[W].lastChangedTime=e.predictedDisplayTime,r[W].frame=e,e[X].detectedPlanes.add(r)})},trackedMeshes:new Map,updateTrackedMeshes:e=>{const t=this[Z].device[B].sem;if(!t)return;Array.from(this[Z].trackedMeshes.keys()).forEach(e=>{t.trackedMeshes.has(e)||this[Z].trackedMeshes.delete(e)}),t.trackedMeshes.forEach(t=>{let r=this[Z].trackedMeshes.get(t);if(!r){const e=new he(this[Z].device[B].globalSpace,t.transform.matrix);r=new Oe(t,e,t.vertices,t.indices,t.semanticLabel),this[Z].trackedMeshes.set(t,r)}r[j].lastChangedTime=e.predictedDisplayTime,r[j].frame=e,e[X].detectedMeshes.add(r)})},depthSensingUsage:"cpu-optimized",depthSensingDataFormat:"float32",computeDepthSensing:e=>{const t=this[Z].device[B].sem;if(!t)return;const{depthNear:r,depthFar:s}=this[Z].renderState,n=this[Z].renderState.baseLayer;if(!n)return;const o=n.context.canvas,h=Math.max(1,Math.floor(o.width/4)),l=Math.max(1,Math.floor(o.height/4)),c="inline"===this[Z].mode?[rt.None]:[rt.Left,rt.Right];for(const n of c){const o=this[Z].getProjectionMatrix(n),c=this[Z].device.viewSpaces[n],u=ce.calculateGlobalOffsetMatrix(c),d=i();a(d,u);const p=t.computeDepthBuffer(d,o,h,l,r,s);if(p){const t=new qe(p.data,p.width,p.height,new Ye,p.rawValueToMeters,this[Z].depthSensingDataFormat);e[X].depthDataMap.set(n,t)}}},hitTestSources:new Set,computeHitTestResults:e=>{const t=this[Z].device[B].sem;if(!t)return;const r=this[Z].device[B].globalSpace;this[Z].hitTestSources.forEach(s=>{const n=s[oe].space,a=ce.calculateGlobalOffsetMatrix(n),h=s[oe].offsetRay.matrix,l=i();o(l,a,h);const c=[];t.computeHitTestResults(l).forEach(t=>{const i=new he(r,t),s=new Je(e,i);c.push(s)}),e[X].hitTestResultsMap.set(s,c)})},onend:null,oninputsourceschange:null,onselect:null,onselectstart:null,onselectend:null,onsqueeze:null,onsqueezestart:null,onsqueezeend:null,onvisibilitychange:null,onframeratechange:null},We.recoverPersistentAnchorsFromStorage(this),this[Z].onDeviceFrame()}get visibilityState(){return this[Z].device.visibilityState}get frameRate(){return this[Z].nominalFrameRate}get supportedFrameRates(){return new Float32Array(this[Z].device.supportedFrameRates)}get renderState(){return this[Z].renderState}get inputSources(){return this[Z].inputSourceArray.length=0,this[Z].ended||"inline"===this[Z].mode||this[Z].inputSourceArray.push(...this[Z].activeInputSources),this[Z].inputSourceArray}get enabledFeatures(){return this[Z].enabledFeatures}get isSystemKeyboardSupported(){return this[Z].isSystemKeyboardSupported}get environmentBlendMode(){var e;return null!==(e=this[Z].device[B].environmentBlendModes[this[Z].mode])&&void 0!==e?e:mt.Opaque}get interactionMode(){return this[Z].device[B].interactionMode}get depthUsage(){return this[Z].depthSensingUsage}get depthDataFormat(){return this[Z].depthSensingDataFormat}updateRenderState(e={}){var t,r,i,s;if(this[Z].ended)throw new DOMException("XRSession has already ended.","InvalidStateError");if(e.baseLayer&&e.baseLayer[H].session!==this)throw new DOMException("Base layer was created by a different XRSession","InvalidStateError");if(null!=e.inlineVerticalFieldOfView&&"inline"!==this[Z].mode)throw new DOMException("InlineVerticalFieldOfView must not be set for an immersive session","InvalidStateError");const n={baseLayer:e.baseLayer||(null===(t=this[Z].pendingRenderState)||void 0===t?void 0:t.baseLayer)||void 0,depthFar:e.depthFar||(null===(r=this[Z].pendingRenderState)||void 0===r?void 0:r.depthFar)||void 0,depthNear:e.depthNear||(null===(i=this[Z].pendingRenderState)||void 0===i?void 0:i.depthNear)||void 0,inlineVerticalFieldOfView:e.inlineVerticalFieldOfView||(null===(s=this[Z].pendingRenderState)||void 0===s?void 0:s.inlineVerticalFieldOfView)||void 0};this[Z].pendingRenderState=new st(n,this[Z].renderState)}async updateTargetFrameRate(e){return new Promise((t,r)=>{this[Z].ended?r(new DOMException("XRSession has already ended.","InvalidStateError")):this[Z].device.supportedFrameRates.includes(e)?(this[Z].nominalFrameRate===e?console.log("Requested frame rate is the same as the current nominal frame rate, no update made"):(this[Z].nominalFrameRate=e,this.dispatchEvent(new nt("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[Z].ended||!this[Z].referenceSpaceIsSupported(e))return void r(new DOMException("The requested reference space type is not supported.","NotSupportedError"));let i;switch(e){case tt.Viewer:i=this[Z].device.viewerSpace;break;case tt.Local:i=new it(e,this[Z].device[B].globalSpace,this[Z].device.viewerSpace[re].offsetMatrix);break;case tt.LocalFloor:case tt.BoundedFloor:case tt.Unbounded:i=new it(e,this[Z].device[B].globalSpace)}this[Z].referenceSpaces.push(i),t(i)})}requestAnimationFrame(e){if(this[Z].ended)return 0;const t=++this[Z].frameHandle;return this[Z].frameCallbacks.push({handle:t,callback:e,cancelled:!1}),t}cancelAnimationFrame(e){let t=this[Z].frameCallbacks,r=t.findIndex(t=>t&&t.handle===e);r>-1&&(t[r].cancelled=!0,t.splice(r,1)),t=this[Z].currentFrameCallbacks,t&&(r=t.findIndex(t=>t&&t.handle===e),r>-1&&(t[r].cancelled=!0))}async end(){return new Promise((e,t)=>{this[Z].ended||null===this[Z].deviceFrameHandle?t(new DOMException("XRSession has already ended.","InvalidStateError")):(globalThis.cancelAnimationFrame(this[Z].deviceFrameHandle),this[Z].device[B].onSessionEnd(),this.dispatchEvent(new nt("end",{session:this})),e())})}get persistentAnchors(){return Array.from(this[Z].persistentAnchors.keys())}restorePersistentAnchor(e){return new Promise((t,r)=>{if(this[Z].persistentAnchors.has(e))if(this[Z].ended)r(new DOMException("XRSession has already ended.","InvalidStateError"));else{const i=this[Z].persistentAnchors.get(e);this[Z].newAnchors.has(i)?r(new DOMException(`Multiple concurrent attempts detected to restore the anchor with UUID: ${e}.`,"InvalidStateError")):(this[Z].trackedAnchors.add(i),this[Z].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[Z].persistentAnchors.has(e)){const r=this[Z].persistentAnchors.get(e);this[Z].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[Z].enabledFeatures.includes("hit-test"))if(this[Z].ended)r(new DOMException("XRSession has already ended.","InvalidStateError"));else if(this[Z].device[B].sem){const r=new Ke(this,e);this[Z].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[Z].onend)&&void 0!==e?e:()=>{}}set onend(e){this[Z].onend&&this.removeEventListener("end",this[Z].onend),this[Z].onend=e,e&&this.addEventListener("end",e)}get oninputsourceschange(){var e;return null!==(e=this[Z].oninputsourceschange)&&void 0!==e?e:()=>{}}set oninputsourceschange(e){this[Z].oninputsourceschange&&this.removeEventListener("inputsourceschange",this[Z].oninputsourceschange),this[Z].oninputsourceschange=e,e&&this.addEventListener("inputsourceschange",e)}get onselect(){var e;return null!==(e=this[Z].onselect)&&void 0!==e?e:()=>{}}set onselect(e){this[Z].onselect&&this.removeEventListener("select",this[Z].onselect),this[Z].onselect=e,e&&this.addEventListener("select",e)}get onselectstart(){var e;return null!==(e=this[Z].onselectstart)&&void 0!==e?e:()=>{}}set onselectstart(e){this[Z].onselectstart&&this.removeEventListener("selectstart",this[Z].onselectstart),this[Z].onselectstart=e,e&&this.addEventListener("selectstart",e)}get onselectend(){var e;return null!==(e=this[Z].onselectend)&&void 0!==e?e:()=>{}}set onselectend(e){this[Z].onselectend&&this.removeEventListener("selectend",this[Z].onselectend),this[Z].onselectend=e,e&&this.addEventListener("selectend",e)}get onsqueeze(){var e;return null!==(e=this[Z].onsqueeze)&&void 0!==e?e:()=>{}}set onsqueeze(e){this[Z].onsqueeze&&this.removeEventListener("squeeze",this[Z].onsqueeze),this[Z].onsqueeze=e,e&&this.addEventListener("squeeze",e)}get onsqueezestart(){var e;return null!==(e=this[Z].onsqueezestart)&&void 0!==e?e:()=>{}}set onsqueezestart(e){this[Z].onsqueezestart&&this.removeEventListener("squeezestart",this[Z].onsqueezestart),this[Z].onsqueezestart=e,e&&this.addEventListener("squeezestart",e)}get onsqueezeend(){var e;return null!==(e=this[Z].onsqueezeend)&&void 0!==e?e:()=>{}}set onsqueezeend(e){this[Z].onsqueezeend&&this.removeEventListener("squeezeend",this[Z].onsqueezeend),this[Z].onsqueezeend=e,e&&this.addEventListener("squeezeend",e)}get onvisibilitychange(){var e;return null!==(e=this[Z].onvisibilitychange)&&void 0!==e?e:()=>{}}set onvisibilitychange(e){this[Z].onvisibilitychange&&this.removeEventListener("visibilitychange",this[Z].onvisibilitychange),this[Z].onvisibilitychange=e,e&&this.addEventListener("visibilitychange",e)}get onframeratechange(){var e;return null!==(e=this[Z].onframeratechange)&&void 0!==e?e:()=>{}}set onframeratechange(e){this[Z].onframeratechange&&this.removeEventListener("frameratechange",this[Z].onframeratechange),this[Z].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"}(gt||(gt={}));class yt extends Map{}class wt extends he{constructor(e,t,r){super(t,r),this[ee]={jointName:e,radius:0}}get jointName(){return this[ee].jointName}}const Tt={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]}}},St={mapping:Ee.None,buttons:[{id:"pinch",type:"analog",eventTrigger:"select"}],axes:[]},_t=m(),Et=b(),Rt=m(),bt=m(),Mt=b(),At=m(),Pt=m(),Ft=b(),It=m(),Lt=(e,t,r,i)=>(u(_t,t),p(Et,t),d(Rt,t),u(bt,r),p(Mt,r),d(At,r),S(Pt,_t,bt,i),A(Ft,Et,Mt,i),S(It,Rt,At,i),function(e,t,r,i){var s=t[0],n=t[1],a=t[2],o=t[3],h=s+s,l=n+n,c=a+a,u=s*h,d=s*l,p=s*c,f=n*l,m=n*c,x=a*c,g=o*h,v=o*l,y=o*c,w=i[0],T=i[1],S=i[2];e[0]=(1-(f+x))*w,e[1]=(d+y)*w,e[2]=(p-v)*w,e[3]=0,e[4]=(d-y)*T,e[5]=(1-(u+x))*T,e[6]=(m+g)*T,e[7]=0,e[8]=(p+v)*S,e[9]=(m-g)*S,e[10]=(1-(u+f))*S,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1}(e,Ft,Pt,It),e),Ct=[1,-1,-1,0,-1,1,1,0,-1,1,1,0,-1,1,1,1];class Dt extends De{constructor(e,t,r){if(t!==Re.Left&&t!==Re.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),n=[e.profileId,...e.fallbackProfileIds],a=new yt;Object.values(gt).forEach(e=>{a.set(e,new wt(e,i))});super(new Ie(t,be.TrackedPointer,n,i,new Pe(St),s,a)),this[U]={poseId:"default",poses:e.poses},this.updateHandPose()}get poseId(){return this[U].poseId}set poseId(e){this[U].poses[e]?this[U].poseId=e:console.warn(`Pose config ${e} not found`)}updateHandPose(){const e=this[U].poses[this[U].poseId],t=this[U].poses.pinch;Object.values(gt).forEach(r=>{const i=e.jointTransforms[r].offsetMatrix,s=t.jointTransforms[r].offsetMatrix,n=this.inputSource.hand.get(r);Lt(n[re].offsetMatrix,i,s,this.pinchValue),this.inputSource.handedness===Re.Right&&(e=>{for(let t=0;t<16;t++)e[t]*=Ct[t]})(n[re].offsetMatrix),n[ee].radius=(1-this.pinchValue)*e.jointTransforms[r].radius+this.pinchValue*t.jointTransforms[r].radius}),e.gripOffsetMatrix&&t.gripOffsetMatrix&&Lt(this.inputSource.gripSpace[re].offsetMatrix,e.gripOffsetMatrix,t.gripOffsetMatrix,this.pinchValue)}get pinchValue(){return this[G].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[G].inputSource.gamepad[z].buttonsMap.pinch[z].pendingValue=e}onFrameStart(e){super.onFrameStart(e),this.updateHandPose()}}class Nt extends EventTarget{}const Ot={antialias:!0,depth:!0,stencil:!1,alpha:!0,ignoreDepthValues:!1,framebufferScaleFactor:1};class Vt extends Nt{constructor(e,t,r={}){if(super(),e[Z].ended)throw new DOMException("Session has ended","InvalidStateError");const i={...Ot,...r};this[H]={session:e,context:t,antialias:i.antialias}}get context(){return this[H].context}get antialias(){return this[H].antialias}get ignoreDepthValues(){return!0}get framebuffer(){return null}get framebufferWidth(){return this[H].context.drawingBufferWidth}get framebufferHeight(){return this[H].context.drawingBufferHeight}getViewport(e){if(e[ie].session!==this[H].session)throw new DOMException("View's session differs from Layer's session","InvalidStateError");return this[H].session[Z].device[B].getViewport(this,e)}static getNativeFramebufferScaleFactor(e){if(!(e instanceof vt))throw new TypeError("getNativeFramebufferScaleFactor must be passed a session.");return e[Z].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 n=new it(tt.Viewer,e),a={[rt.Left]:new he(n),[rt.Right]:new he(n),[rt.None]:new he(n)};this[D]={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:n,viewSpaces:a,vec3:m(),quat:b()},h(this[D].viewSpaces[rt.Left][re].offsetMatrix,x(-r/2,0,0)),h(this[D].viewSpaces[rt.Right][re].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 Pe({mapping:i.mapping,buttons:e,axes:t})}const n=new he(e);let a;i.hasHand&&(a=new yt,Object.values(gt).forEach(e=>{a.set(e,new wt(e,n))}));const o=new Ie(i.handedness,i.targetRayMode,i.profiles,n,s,i.hasGrip?new he(e):void 0,i.hasHand?a:void 0);this[D].inputSources.set(r,{active:!1,source:o}),this[D].inputSchemas.set(r,i)})}play(){this[D].recordedFramePointer=0,this[D].playbackTime=this[D].startingTimeStamp,this[D].playing=!0,this[D].actualTimeStamp=performance.now()}stop(){this[D].playing=!1}get playing(){return this[D].playing}get viewerSpace(){return this[D].viewerSpace}get viewSpaces(){return this[D].viewSpaces}get inputSources(){return Array.from(this[D].inputSources.values()).filter(e=>e.active).map(e=>e.source)}playFrame(){const e=performance.now(),t=e-this[D].actualTimeStamp;if(this[D].actualTimeStamp=e,this[D].playbackTime+=t,this[D].playbackTime>this[D].endingTimeStamp)return void this.stop();for(;this[D].frames[this[D].recordedFramePointer+1][0]<this[D].playbackTime;)this[D].recordedFramePointer++;const r=this[D].frames[this[D].recordedFramePointer],i=this[D].frames[this[D].recordedFramePointer+1],s=(this[D].playbackTime-r[0])/(i[0]-r[0]);this.updateXRSpaceFromMergedFrames(this[D].viewerSpace,r.slice(1,8),i.slice(1,8),s);const n=new Map;for(let e=8;e<r.length;e++){const{index:t,inputData:i}=this.processRawInputData(r[e]);n.set(t,i)}const a=new Map;for(let e=8;e<i.length;e++){const{index:t,inputData:r}=this.processRawInputData(i[e]);a.set(t,r)}this[D].inputSources.forEach(e=>{e.active=!1}),a.forEach((e,t)=>{this[D].inputSources.get(t).active=!0;const r=this[D].inputSources.get(t).source,i=this[D].inputSchemas.get(t);this.updateInputSource(r,i,n.has(t)?n.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 n=0;n<25;n++){const a=r.handTransforms.slice(8*n,8*n+7),o=i.handTransforms.slice(8*n,8*n+7),h=r.handTransforms[8*n+7],l=i.handTransforms[8*n+7],c=e.hand.get(t.jointSequence[n]);this.updateXRSpaceFromMergedFrames(c,a,o,s),c[ee].radius=(l-h)*s+h}if(t.hasGamepad){const t=e.gamepad;i.buttons.forEach((e,i)=>{const n=t.buttons[i];n[z].pressed=1===e[0],n[z].touched=1===e[1];const a=r.buttons[i][2],o=e[2];n[z].value=(o-a)*s+a}),i.axes.forEach((e,i)=>{const n=r.axes[i];t[z].axesMap[i.toString()].x=(e-n)*s+n})}}updateXRSpaceFromMergedFrames(e,t,r,i){const s=x(t[0],t[1],t[2]),n=F(t[3],t[4],t[5],t[6]),a=x(r[0],r[1],r[2]),o=F(r[3],r[4],r[5],r[6]);S(this[D].vec3,s,a,i),A(this[D].quat,n,o,i),c(e[re].offsetMatrix,this[D].quat,this[D].vec3)}processRawInputData(e){const t=e[0],r=this[D].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 Ut="2.2.1";class Gt 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 Xt 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:n=[]}=i,{supportedFeatures:a}=this[q].device;if(!s.every(e=>a.includes(e)))return void t(new Error("One or more required features are not supported by the device."));const o=n.filter(e=>a.includes(e)),h=Array.from(new Set([...s,...o,"viewer","local"])),l=new vt(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 n={resolve:r,reject:i,mode:e,options:t};this[q].grantSession(n)}).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 zt{constructor(e,t,r,i){this[se]={x:e,y:t,width:r,height:i}}get x(){return this[se].x}get y(){return this[se].y}get width(){return this[se].width}get height(){return this[se].height}}
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* webxr-layers-polyfill
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
40
40
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
41
41
|
* THE SOFTWARE.
|
|
42
|
-
*/var Ut,Xt;!function(e){e.texture="texture",e["texture-array"]="texture-array"}(Ut||(Ut={})),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"}(Xt||(Xt={}));const zt=e=>e&&"function"==typeof e.getOffsetReferenceSpace,qt=()=>"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},kt=(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 kt(e,e.DEPTH_COMPONENT24);case e.DEPTH_STENCIL:return kt(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 Ht{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,i){}dispatchEvent(e){return!1}removeEventListener(e,t,i){}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,i){if(!(t instanceof WebGL2RenderingContext)&&e===Ut["texture-array"])throw new TypeError;if(i===Xt.mono)return i;if(i===Xt.default){if(this.session.internalViews&&1===this.session.internalViews.length)return Xt.mono;if(e===Ut["texture-array"])return i}return i===Xt.default||i===Xt.stereo?Xt["stereo-left-right"]:i}isMediaLayer(){return null!==this._media}_deferredInitialize(){}initializeIfNeeded(){this._hasRunDeferredInitialize||(this._hasRunDeferredInitialize=!0,this._deferredInitialize())}_allocateColorTexturesInternal(e,t){let i=this.session.internalViews;if(i&&0!==i.length){if(this.initializeIfNeeded(),this.layout===Xt.mono){if(e===Ut["texture-array"]){const i=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[i],void(this._colorTextures=[i.texture])}{const i=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[i],void(this._colorTextures=[i.texture])}}if(this.layout===Xt.stereo){if(e===Ut["texture-array"]){const i=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat,2);return this._texturesMeta=[i],void(this._colorTextures=[i.texture])}{const i=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat),r=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[i,r],void(this._colorTextures=[i.texture,r.texture])}}if(this.layout===Xt["stereo-left-right"]){const i=this._createNewColorTexture(2*t.viewPixelWidth,t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[i],void(this._colorTextures=[i.texture])}if(this.layout===Xt["stereo-top-bottom"]){const i=this._createNewColorTexture(t.viewPixelWidth,2*t.viewPixelHeight,e,t.colorFormat);return this._texturesMeta=[i],void(this._colorTextures=[i.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===Xt.mono){if(e===Ut["texture-array"]){const i=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[i.texture])}{const i=this._createNewColorTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[i.texture])}}if(this.layout===Xt.stereo){if(e===Ut["texture-array"]){const i=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat,2);return void(this._depthStencilTextures=[i.texture])}{const i=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat),r=this._createNewDepthStencilTexture(t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[i.texture,r.texture])}}if(this.layout===Xt["stereo-left-right"]){const i=this._createNewDepthStencilTexture(2*t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[i.texture])}if(this.layout===Xt["stereo-top-bottom"]){const i=this._createNewDepthStencilTexture(t.viewPixelWidth,2*t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[i.texture])}}else this._depthStencilTextures=[]}_createNewColorTexture(e,t,i,r,s=1){return this._createGenericPolyfillTexture(i,e,t,r,0,s)}_createNewDepthStencilTexture(e,t,i,r,s=1){return this._createGenericPolyfillTexture(i,e,t,r,0,s)}_createGenericPolyfillTexture(e,t,i,r,s=0,n=1){if(e===Ut["texture-array"]&&n<=1&&console.warn("creating a texture array with a single layer..."),e===Ut["texture-array"]&&this.context instanceof WebGLRenderingContext)throw new Error("WebGL 1 does not support texture array");let a=this.context.createTexture(),o={width:t,height:i,layers:n,type:e,textureFormat:r,texture:a},h=r,l=this.context.UNSIGNED_BYTE;if(this.context instanceof WebGL2RenderingContext){const e=kt(this.context,r);h=e.internalFormat,r=e.textureFormat,l=e.type}else r===this.context.DEPTH_COMPONENT&&(l=this.context.UNSIGNED_INT),r===this.context.DEPTH_STENCIL&&(l=this.context.UNSIGNED_INT_24_8_WEBGL);if(e===Ut["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,a),this._getSupportedDepthFormats().indexOf(r)>=0?this.context.texStorage3D(this.context.TEXTURE_2D_ARRAY,1,h,t,i,n):this.context.texImage3D(this.context.TEXTURE_2D_ARRAY,0,h,t,i,n,0,r,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,a),this.context.texImage2D(this.context.TEXTURE_2D,0,h,t,i,0,r,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 jt={colorFormat:6408,mipLevels:1,layout:Xt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:Ut.texture,radius:2,centralAngle:.78539,aspectRatio:2},Wt={layout:Xt.mono,invertStereo:!1,space:null,radius:2,centralAngle:.78539};class Yt extends Ht{constructor(e,t){super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},Wt),e):this.init=Object.assign(Object.assign({},jt),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 i=qt();this.init.transform?this.transform=new i.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new i.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?Ut.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:Xt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:Ut.texture,radius:0,centralHorizontalAngle:6.28318,upperVerticalAngle:1.570795,lowerVerticalAngle:-1.570795},$t={space:null,layout:Xt.mono,invertStereo:!1,radius:0,centralHorizontalAngle:6.28318,upperVerticalAngle:1.570795,lowerVerticalAngle:-1.570795};class Kt extends Ht{constructor(e,t){if(super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},$t),e):this.init=Object.assign(Object.assign({},Qt),e),!zt(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 i=qt();e.transform?this.transform=new i.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new i.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?Ut.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 Jt={colorFormat:6408,mipLevels:1,layout:Xt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:Ut.texture,width:1,height:1},Zt={space:null,layout:Xt.mono,invertStereo:!1};class ei extends Ht{constructor(e,t){super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},Zt),e):this.init=Object.assign(Object.assign({},Jt),e),this.width=this.init.width,this.height=this.init.height,this.space=this.init.space,this.layout=this.init.layout;const i=qt();this.init.transform?this.transform=new i.XRRigidTransform(e.transform.position,e.transform.orientation):this.transform=new i.XRRigidTransform({x:0,y:0,z:0,w:1}),this.isMediaLayer()||(this.isStatic=e.isStatic)}getTextureType(){return this.isMediaLayer()?Ut.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 ti{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===Xt.default)throw new TypeError("Media Quad layer cannot be created with layout of default");let i=this.calculateAspectRatio(e,t.layout);void 0===t.width&&void 0===t.height&&(t.width=1),void 0===t.height&&(t.height=t.width/i),void 0===t.width&&(t.width=t.height/i);let r=new ei(t,e);return r.needsRedraw=!1,r.initialize(this.session),r}createCylinderLayer(e,t){if(this.session.ended)throw new Error("Session has ended");if(t.layout===Xt.default)throw new TypeError("Media Cylinder layer cannot be created with layout of default");let i=this.calculateAspectRatio(e,t.layout);void 0===t.aspectRatio&&(t.aspectRatio=i);let r=new Yt(t,e);return r.needsRedraw=!1,r.initialize(this.session),r}createEquirectLayer(e,t){if(this.session.ended)throw new Error("Session has ended");if(t.layout===Xt.default)throw new TypeError("Media Equirect layer cannot be created with layout of default");if(!zt(t.space))throw new Error("Media Equirect layer's space must be of type XRReferenceSpace");let i=new Kt(t,e);return i.needsRedraw=!1,i.initialize(this.session),i}calculateAspectRatio(e,t){let i=e.videoWidth,r=e.videoHeight;return t===Xt["stereo-left-right"]&&(i/=2),t===Xt["stereo-top-bottom"]&&(r/=2),i/r}}const ii={textureType:Ut.texture,colorFormat:6408,depthFormat:6402,scaleFactor:1};class ri extends Ht{constructor(e=ii){super(),this.init=Object.assign(Object.assign({},ii),e)}initialize(e,t){super.initialize(e,t),this.initializeIfNeeded();let i=e.getBaseLayer();this.textureWidth=i.framebufferWidth*this.init.scaleFactor,this.textureHeight=i.framebufferHeight*this.init.scaleFactor}_allocateProjectionColorTextures(){let e=[],t=[];const i=()=>{e=[];for(let i of t)e.push(i.texture)};let r=this.session,s=r.internalViews;if(!s||0===s.length)return void console.warn("We can't allocate color textures without views");let n=r.getBaseLayer(),a=s.length,o=n.framebufferWidth*this.init.scaleFactor/s.length,h=n.framebufferHeight*this.init.scaleFactor;if(this.layout===Xt.mono||this.layout===Xt.default){if(this.init.textureType===Ut["texture-array"]){let e=this._createNewColorTexture(o,h,Ut["texture-array"],this.init.colorFormat,a);t=[e]}else for(let e of s){let e=this._createNewColorTexture(o,h,Ut.texture,this.init.colorFormat);t.push(e)}return i(),this._colorTexturesMeta=t,void(this._colorTextures=e)}if(this.layout===Xt["stereo-left-right"]){let e=this._createNewColorTexture(o*a,h,this.init.textureType,this.init.colorFormat);t=[e]}else if(this.layout===Xt["stereo-top-bottom"]){let e=this._createNewColorTexture(o,h*a,this.init.textureType,this.init.colorFormat);t=[e]}i(),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 i=[],r=[];const s=()=>{i=[];for(let e of r)i.push(e.texture)};this.initializeIfNeeded();let n=e.getBaseLayer(),a=t.length,o=n.framebufferWidth*this.init.scaleFactor/t.length,h=n.framebufferHeight*this.init.scaleFactor;if(this.layout===Xt.mono||this.layout===Xt.default){if(this.init.textureType===Ut["texture-array"]){let e=this._createNewDepthStencilTexture(o,h,this.init.textureType,this.init.depthFormat,a);r=[e]}else for(let e of t){let e=this._createNewDepthStencilTexture(o,h,this.init.textureType,this.init.depthFormat);r.push(e)}return s(),void(this._depthStencilTextures=i)}if(this.layout===Xt["stereo-left-right"]){let e=this._createNewDepthStencilTexture(o*a,h,this.init.textureType,this.init.depthFormat);r=[e]}else if(this.layout===Xt["stereo-top-bottom"]){let e=this._createNewDepthStencilTexture(o,h*a,this.init.textureType,this.init.depthFormat);r=[e]}s(),this._depthStencilTextures=i}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,Xt.default);this.layout=e,this.needsRedraw=!0;let t=this.determineMaximumScaleFactor(),i=Math.min(this.init.scaleFactor,t);this.init.scaleFactor=i}determineMaximumScaleFactor(){let e=this.session.getBaseLayer(this.context),t=e.framebufferWidth,i=e.framebufferHeight;this.layout===Xt["stereo-left-right"]&&(t*=2),this.layout===Xt["stereo-top-bottom"]&&(i*=2);let r=Math.max(t,i);return this.context.getParameter(this.context.MAX_TEXTURE_SIZE)/r}}const si=(e,t,i,r,s)=>{let n=0,a=0,o=t.width,h=t.height;i===Xt["stereo-left-right"]?(n=t.width*r/s,o=t.width/s):i===Xt["stereo-top-bottom"]&&(a=t.height*r/s,h=t.height/s),e.x=n,e.y=a,e.width=o,e.height=h},ni=(e,t,i)=>{var r=e.createShader(i);if(e.shaderSource(r,t),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw"could not compile shader:"+e.getShaderInfoLog(r);return r},ai=(e,t,i)=>{const r=e.createProgram(),s=ni(e,t,e.VERTEX_SHADER),n=ni(e,i,e.FRAGMENT_SHADER);if(e.attachShader(r,s),e.attachShader(r,n),e.deleteShader(s),e.deleteShader(n),e.linkProgram(r),!e.getProgramParameter(r,e.LINK_STATUS))throw"program failed to link:"+e.getProgramInfoLog(r);return r},oi=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)}},hi=e=>e,li=hi`
|
|
42
|
+
*/var qt,kt;!function(e){e.texture="texture",e["texture-array"]="texture-array"}(qt||(qt={})),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"}(kt||(kt={}));const Ht=e=>e&&"function"==typeof e.getOffsetReferenceSpace,jt=()=>"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},Wt=(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 Wt(e,e.DEPTH_COMPONENT24);case e.DEPTH_STENCIL:return Wt(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 Yt{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===qt["texture-array"])throw new TypeError;if(r===kt.mono)return r;if(r===kt.default){if(this.session.internalViews&&1===this.session.internalViews.length)return kt.mono;if(e===qt["texture-array"])return r}return r===kt.default||r===kt.stereo?kt["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===kt.mono){if(e===qt["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===kt.stereo){if(e===qt["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===kt["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===kt["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===kt.mono){if(e===qt["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===kt.stereo){if(e===qt["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===kt["stereo-left-right"]){const r=this._createNewDepthStencilTexture(2*t.viewPixelWidth,t.viewPixelHeight,e,t.depthFormat);return void(this._depthStencilTextures=[r.texture])}if(this.layout===kt["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,n=1){if(e===qt["texture-array"]&&n<=1&&console.warn("creating a texture array with a single layer..."),e===qt["texture-array"]&&this.context instanceof WebGLRenderingContext)throw new Error("WebGL 1 does not support texture array");let a=this.context.createTexture(),o={width:t,height:r,layers:n,type:e,textureFormat:i,texture:a},h=i,l=this.context.UNSIGNED_BYTE;if(this.context instanceof WebGL2RenderingContext){const e=Wt(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===qt["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,a),this._getSupportedDepthFormats().indexOf(i)>=0?this.context.texStorage3D(this.context.TEXTURE_2D_ARRAY,1,h,t,r,n):this.context.texImage3D(this.context.TEXTURE_2D_ARRAY,0,h,t,r,n,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,a),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 Qt={colorFormat:6408,mipLevels:1,layout:kt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:qt.texture,radius:2,centralAngle:.78539,aspectRatio:2},$t={layout:kt.mono,invertStereo:!1,space:null,radius:2,centralAngle:.78539};class Kt extends Yt{constructor(e,t){super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},$t),e):this.init=Object.assign(Object.assign({},Qt),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=jt();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()?qt.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 Jt={colorFormat:6408,mipLevels:1,layout:kt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:qt.texture,radius:0,centralHorizontalAngle:6.28318,upperVerticalAngle:1.570795,lowerVerticalAngle:-1.570795},Zt={space:null,layout:kt.mono,invertStereo:!1,radius:0,centralHorizontalAngle:6.28318,upperVerticalAngle:1.570795,lowerVerticalAngle:-1.570795};class er extends Yt{constructor(e,t){if(super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},Zt),e):this.init=Object.assign(Object.assign({},Jt),e),!Ht(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=jt();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()?qt.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 tr={colorFormat:6408,mipLevels:1,layout:kt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0,textureType:qt.texture,width:1,height:1},rr={space:null,layout:kt.mono,invertStereo:!1};class ir extends Yt{constructor(e,t){super(),this._media=null!=t?t:null,this.isMediaLayer()?this.init=Object.assign(Object.assign({},rr),e):this.init=Object.assign(Object.assign({},tr),e),this.width=this.init.width,this.height=this.init.height,this.space=this.init.space,this.layout=this.init.layout;const r=jt();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()?qt.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 sr{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===kt.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 ir(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===kt.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 Kt(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===kt.default)throw new TypeError("Media Equirect layer cannot be created with layout of default");if(!Ht(t.space))throw new Error("Media Equirect layer's space must be of type XRReferenceSpace");let r=new er(t,e);return r.needsRedraw=!1,r.initialize(this.session),r}calculateAspectRatio(e,t){let r=e.videoWidth,i=e.videoHeight;return t===kt["stereo-left-right"]&&(r/=2),t===kt["stereo-top-bottom"]&&(i/=2),r/i}}const nr={textureType:qt.texture,colorFormat:6408,depthFormat:6402,scaleFactor:1};class ar extends Yt{constructor(e=nr){super(),this.init=Object.assign(Object.assign({},nr),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 n=i.getBaseLayer(),a=s.length,o=n.framebufferWidth*this.init.scaleFactor/s.length,h=n.framebufferHeight*this.init.scaleFactor;if(this.layout===kt.mono||this.layout===kt.default){if(this.init.textureType===qt["texture-array"]){let e=this._createNewColorTexture(o,h,qt["texture-array"],this.init.colorFormat,a);t=[e]}else for(let e of s){let e=this._createNewColorTexture(o,h,qt.texture,this.init.colorFormat);t.push(e)}return r(),this._colorTexturesMeta=t,void(this._colorTextures=e)}if(this.layout===kt["stereo-left-right"]){let e=this._createNewColorTexture(o*a,h,this.init.textureType,this.init.colorFormat);t=[e]}else if(this.layout===kt["stereo-top-bottom"]){let e=this._createNewColorTexture(o,h*a,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 n=e.getBaseLayer(),a=t.length,o=n.framebufferWidth*this.init.scaleFactor/t.length,h=n.framebufferHeight*this.init.scaleFactor;if(this.layout===kt.mono||this.layout===kt.default){if(this.init.textureType===qt["texture-array"]){let e=this._createNewDepthStencilTexture(o,h,this.init.textureType,this.init.depthFormat,a);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===kt["stereo-left-right"]){let e=this._createNewDepthStencilTexture(o*a,h,this.init.textureType,this.init.depthFormat);i=[e]}else if(this.layout===kt["stereo-top-bottom"]){let e=this._createNewDepthStencilTexture(o,h*a,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,kt.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===kt["stereo-left-right"]&&(t*=2),this.layout===kt["stereo-top-bottom"]&&(r*=2);let i=Math.max(t,r);return this.context.getParameter(this.context.MAX_TEXTURE_SIZE)/i}}const or=(e,t,r,i,s)=>{let n=0,a=0,o=t.width,h=t.height;r===kt["stereo-left-right"]?(n=t.width*i/s,o=t.width/s):r===kt["stereo-top-bottom"]&&(a=t.height*i/s,h=t.height/s),e.x=n,e.y=a,e.width=o,e.height=h},hr=(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},lr=(e,t,r)=>{const i=e.createProgram(),s=hr(e,t,e.VERTEX_SHADER),n=hr(e,r,e.FRAGMENT_SHADER);if(e.attachShader(i,s),e.attachShader(i,n),e.deleteShader(s),e.deleteShader(n),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw"program failed to link:"+e.getProgramInfoLog(i);return i},cr=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)}},ur=e=>e,dr=ur`
|
|
43
43
|
attribute vec2 a_position;
|
|
44
44
|
attribute vec2 a_texCoord;
|
|
45
45
|
|
|
@@ -61,7 +61,7 @@ void main() {
|
|
|
61
61
|
// The GPU will interpolate this value between points.
|
|
62
62
|
v_texCoord = a_texCoord;
|
|
63
63
|
}
|
|
64
|
-
`,
|
|
64
|
+
`,pr=ur`
|
|
65
65
|
precision mediump float;
|
|
66
66
|
|
|
67
67
|
// our texture
|
|
@@ -74,7 +74,7 @@ void main() {
|
|
|
74
74
|
vec4 tex = texture2D(u_image, v_texCoord);
|
|
75
75
|
gl_FragColor = vec4(tex.rgb, tex.a);
|
|
76
76
|
}
|
|
77
|
-
`;class
|
|
77
|
+
`;class fr{constructor(e,t){this.gl=t,this.layer=e,this.program=lr(this.gl,dr,pr),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),n=t.getParameter(t.ACTIVE_TEXTURE);if(i!==qt.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(n),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=cr(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 n=t,a=t+i,o=r,h=r+s;e.bufferData(e.ARRAY_BUFFER,new Float32Array([n,o,a,o,n,h,n,h,a,o,a,h]),e.DYNAMIC_DRAW)})(e,0,0,1,1);let r=e.FLOAT,i=!1;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,2,r,i,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,i,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=[],or(e,this.layer.colorTexturesMeta[0],this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e),or(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,n=r.width/e.width,a=r.height/e.height,o=[];for(let e=0;e<t.length;e+=2){let r=t[e]*n+i,h=t[e+1]*a+s;o[e]=r,o[e+1]=h}return new Float32Array(o)}_shouldUseStereoTexturePoints(){return this.layer.layout===kt["stereo-left-right"]||this.layer.layout===kt["stereo-top-bottom"]}}const mr=ur`#version 300 es
|
|
78
78
|
|
|
79
79
|
in vec2 a_position;
|
|
80
80
|
in vec2 a_texCoord;
|
|
@@ -97,7 +97,7 @@ void main() {
|
|
|
97
97
|
// The GPU will interpolate this value between points.
|
|
98
98
|
v_texCoord = a_texCoord;
|
|
99
99
|
}
|
|
100
|
-
`,
|
|
100
|
+
`,xr=ur`#version 300 es
|
|
101
101
|
precision mediump float;
|
|
102
102
|
precision mediump int;
|
|
103
103
|
precision mediump sampler2DArray;
|
|
@@ -114,7 +114,7 @@ void main() {
|
|
|
114
114
|
fragColor = vec4(tex.rgb, tex.a);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
`;class
|
|
117
|
+
`;class gr extends fr{constructor(e,t){super(e,t),this.program=lr(this.gl,mr,xr),this._createVAOs(),this.u_layerInfo=this.gl.getUniformLocation(this.program,"u_layer")}render(e){let t=this.gl;if(this.layer.getTextureType()===qt.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),n=r.getViewport(i);t.viewport(n.x,n.y,n.width,n.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 vr=(e,t)=>e.getTextureType()===qt["texture-array"]&&t instanceof WebGL2RenderingContext?new gr(e,t):new fr(e,t);var yr="undefined"!=typeof Float32Array?Float32Array:Array;function wr(){var e=new yr(16);return yr!=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 Tr(e,t,r){var i=t[0],s=t[1],n=t[2],a=t[3],o=t[4],h=t[5],l=t[6],c=t[7],u=t[8],d=t[9],p=t[10],f=t[11],m=t[12],x=t[13],g=t[14],v=t[15],y=r[0],w=r[1],T=r[2],S=r[3];return e[0]=y*i+w*o+T*u+S*m,e[1]=y*s+w*h+T*d+S*x,e[2]=y*n+w*l+T*p+S*g,e[3]=y*a+w*c+T*f+S*v,y=r[4],w=r[5],T=r[6],S=r[7],e[4]=y*i+w*o+T*u+S*m,e[5]=y*s+w*h+T*d+S*x,e[6]=y*n+w*l+T*p+S*g,e[7]=y*a+w*c+T*f+S*v,y=r[8],w=r[9],T=r[10],S=r[11],e[8]=y*i+w*o+T*u+S*m,e[9]=y*s+w*h+T*d+S*x,e[10]=y*n+w*l+T*p+S*g,e[11]=y*a+w*c+T*f+S*v,y=r[12],w=r[13],T=r[14],S=r[15],e[12]=y*i+w*o+T*u+S*m,e[13]=y*s+w*h+T*d+S*x,e[14]=y*n+w*l+T*p+S*g,e[15]=y*a+w*c+T*f+S*v,e}function Sr(e,t){var r=t[0],i=t[1],s=t[2],n=t[3],a=r+r,o=i+i,h=s+s,l=r*a,c=i*a,u=i*o,d=s*a,p=s*o,f=s*h,m=n*a,x=n*o,g=n*h;return e[0]=1-u-f,e[1]=c+g,e[2]=d-x,e[3]=0,e[4]=c-g,e[5]=1-l-f,e[6]=p+m,e[7]=0,e[8]=d+x,e[9]=p-m,e[10]=1-l-u,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function _r(){var e=new yr(2);return yr!=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=_r()}();const Er=e=>e,Rr=Er`
|
|
118
118
|
attribute vec4 a_position;
|
|
119
119
|
attribute vec2 a_texCoord;
|
|
120
120
|
|
|
@@ -131,7 +131,7 @@ void main() {
|
|
|
131
131
|
// The GPU will interpolate this value between points.
|
|
132
132
|
v_texCoord = a_texCoord;
|
|
133
133
|
}
|
|
134
|
-
`,
|
|
134
|
+
`,br=Er`
|
|
135
135
|
precision mediump float;
|
|
136
136
|
|
|
137
137
|
// our texture
|
|
@@ -145,7 +145,7 @@ void main() {
|
|
|
145
145
|
gl_FragColor = vec4(tex.rgb, tex.a);
|
|
146
146
|
// gl_FragColor = vec4(1.0, 0, 0, 1.0);
|
|
147
147
|
}
|
|
148
|
-
`,
|
|
148
|
+
`,Mr=Er`#version 300 es
|
|
149
149
|
|
|
150
150
|
in vec4 a_position;
|
|
151
151
|
in vec2 a_texCoord;
|
|
@@ -163,7 +163,7 @@ void main() {
|
|
|
163
163
|
// The GPU will interpolate this value between points.
|
|
164
164
|
v_texCoord = a_texCoord;
|
|
165
165
|
}
|
|
166
|
-
`,
|
|
166
|
+
`,Ar=Er`#version 300 es
|
|
167
167
|
precision mediump float;
|
|
168
168
|
precision mediump int;
|
|
169
169
|
precision mediump sampler2DArray;
|
|
@@ -180,7 +180,7 @@ void main() {
|
|
|
180
180
|
fragColor = vec4(tex.rgb, tex.a);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
`;class bi{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=gi(),t instanceof WebGL2RenderingContext&&this.layer.getTextureType()===Ut["texture-array"]&&(this.usesTextureArrayShaders=!0),this.usesTextureArrayShaders?this.program=ai(i,Ei,Ri):this.program=ai(i,Si,_i),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:Ut.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 i=this.gl,r=e.getBaseLayer(),s=t.getViewerPose(e.getReferenceSpace());const n=i.getParameter(i.ACTIVE_TEXTURE);for(let a of s.views){let s=r.getViewport(a);if(i.viewport(s.x,s.y,s.width,s.height),i.activeTexture(i.TEXTURE0),this.usesTextureArrayShaders){if(i 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 r=i.getParameter(i.TEXTURE_BINDING_2D_ARRAY);i.bindTexture(i.TEXTURE_2D_ARRAY,this.layer.colorTextures[0]),this.layer.isStatic?(!0===this.layer.needsRedraw&&i.generateMipmap(i.TEXTURE_2D_ARRAY),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MAG_FILTER,this.hasMipmap?i.LINEAR_MIPMAP_LINEAR:i.LINEAR),i.texParameteri(i.TEXTURE_2D_ARRAY,i.TEXTURE_MIN_FILTER,this.hasMipmap?i.LINEAR_MIPMAP_LINEAR:i.LINEAR);let s=0;if(this.layer.layout===Xt.stereo&&"right"===a.eye)s=1;this._shouldUseStereoTexturePoints()?this._renderInternalStereo(e,t,a,s):this._renderInternal(e,t,a,s),i.activeTexture(n),i.bindTexture(i.TEXTURE_2D_ARRAY,r)}else{const r=i.getParameter(i.TEXTURE_BINDING_2D);if(this.layer.isMediaLayer())i.bindTexture(i.TEXTURE_2D,this.mediaTexture),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0),i.texSubImage2D(i.TEXTURE_2D,0,0,0,this.layer.media.videoWidth,this.layer.media.videoHeight,i.RGBA,i.UNSIGNED_BYTE,this.layer.media);else if(this.layer.layout===Xt.stereo)if("right"===a.eye)i.bindTexture(i.TEXTURE_2D,this.layer.colorTextures[1]);else i.bindTexture(i.TEXTURE_2D,this.layer.colorTextures[0]);else i.bindTexture(i.TEXTURE_2D,this.layer.colorTextures[0]);this.layer.isStatic?(!0===this.layer.needsRedraw&&i.generateMipmap(i.TEXTURE_2D),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,this.hasMipmap?i.LINEAR_MIPMAP_LINEAR:i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,this.hasMipmap?i.LINEAR_MIPMAP_LINEAR:i.LINEAR),this._shouldUseStereoTexturePoints()?this._renderInternalStereo(e,t,a):this._renderInternal(e,t,a),i.activeTexture(n),i.bindTexture(i.TEXTURE_2D,r)}}this.restoreVaoState()}createPositionPoints(){return new Float32Array([])}createTextureUVs(){return new Float32Array([])}_offsetTextureUVsByRect(e,t,i){const r=(i=null!=i?i:{x:0,y:0,width:e.width,height:e.height}).x/e.width,s=i.y/e.height,n=i.width/e.width,a=i.height/e.height,o=[];for(let e=0;e<t.length;e+=2){let i=t[e]*n+r,h=t[e+1]*a+s;o[e]=i,o[e+1]=h}return new Float32Array(o)}_shouldUseStereoTexturePoints(){return this.layer.layout===Xt["stereo-left-right"]||this.layer.layout===Xt["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 i=t.FLOAT;t.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,2,i,!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 si(e,this.mediaTexturePolyfill,this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.mediaTexturePolyfill,this.texturePoints,e),si(e,this.mediaTexturePolyfill,this.layer.layout,1,2),this.stereoTexturePoints[1]=this._offsetTextureUVsByRect(this.mediaTexturePolyfill,this.texturePoints,e),void(this.layer.layout===Xt["stereo-top-bottom"]&&([this.stereoTexturePoints[0],this.stereoTexturePoints[1]]=[this.stereoTexturePoints[1],this.stereoTexturePoints[0]]));si(e,this.layer.colorTexturesMeta[0],this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e),si(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===Xt["stereo-top-bottom"]&&([this.stereoTexturePoints[0],this.stereoTexturePoints[1]]=[this.stereoTexturePoints[1],this.stereoTexturePoints[0]])}}_createVAOs(){this._recalculateVertices();let e=this.gl;this.vaoGl=oi(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 i=this.positionPoints;e.bufferData(e.ARRAY_BUFFER,i,e.STATIC_DRAW);var r=3,s=e.FLOAT,n=!1,a=0,o=0;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,r,s,n,a,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);r=2,s=e.FLOAT,n=!1,a=0,o=0;e.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,r,s,n,a,o),this.restoreVaoState()}_renderInternal(e,t,i,r){let s=this.gl;const n=s.getParameter(s.CURRENT_PROGRAM);s.useProgram(this.program),this.vaoGl.bindVertexArray(this.vao),this.usesTextureArrayShaders&&s.uniform1i(this.programInfo.uniformLocations.u_layer,r),this._setTransformMatrix(e,t,i),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix,!1,this.transformMatrix),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix,!1,i.projectionMatrix);var a=s.TRIANGLES,o=this.positionPoints.length/3;s.drawArrays(a,0,o),this.vaoGl.bindVertexArray(null),s.useProgram(n)}_renderInternalStereo(e,t,i,r){if("none"===i.eye)return this._renderInternal(e,t,i);let s=this.gl;this.vaoGl.bindVertexArray(this.vao);const n=s.getParameter(s.CURRENT_PROGRAM);s.useProgram(this.program),this._setStereoTextureBuffer("right"===i.eye?1:0),this.usesTextureArrayShaders&&s.uniform1i(this.programInfo.uniformLocations.u_layer,r),this._setTransformMatrix(e,t,i),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_matrix,!1,this.transformMatrix),s.uniformMatrix4fv(this.programInfo.uniformLocations.u_projectionMatrix,!1,i.projectionMatrix);var a=s.TRIANGLES,o=this.positionPoints.length/3;s.drawArrays(a,0,o),this.vaoGl.bindVertexArray(null),s.useProgram(n)}_setTransformMatrix(e,t,i){let r=t.getPose(this.layer.space,e.getReferenceSpace());vi(this.transformMatrix,r.transform.matrix,this.layer.transform.matrix),vi(this.transformMatrix,i.transform.inverse.matrix,this.transformMatrix)}}class Mi extends bi{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 Ai extends bi{constructor(e,t){super(e,t),this.segments=16,this.initialize()}createPositionPoints(){const e=[],t=this.layer.centralAngle,i=this.layer.height,r=this.layer.radius,s=t/this.segments,n=Math.PI/2-t/2,a=[],o=Ti();o[0]=r*Math.cos(n),o[1]=-r*Math.sin(n),a.push(o);for(let e=0;e<this.segments;e++){const t=Ti();t[0]=r*Math.cos(n+s*(e+1)),t[1]=-r*Math.sin(n+s*(e+1)),a.push(t)}a.reverse();for(let t=0;t<this.segments;t++){const r=a[t],s=a[t+1];e.push(r[0],-i/2,r[1]),e.push(s[0],-i/2,s[1]),e.push(r[0],i/2,r[1]),e.push(r[0],i/2,r[1]),e.push(s[0],-i/2,s[1]),e.push(s[0],i/2,s[1])}return new Float32Array(e)}createTextureUVs(){let e=[];const t=1/this.segments;for(let i=0;i<this.segments;i++){let r=t*i,s=t*(i+1);e.push(r,0),e.push(s,0),e.push(r,1),e.push(r,1),e.push(s,0),e.push(s,1)}return new Float32Array(e)}}class Pi extends bi{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 i=this.layer.centralHorizontalAngle,r=this.layer.upperVerticalAngle+Math.PI/2,s=this.layer.lowerVerticalAngle+Math.PI/2,n=Math.PI/2-i/2,a=n+i,o=s-r,h=a-n,l=[];for(let e=0;e<=this.segmentsPerAxis;e++)for(let i=0;i<=this.segmentsPerAxis;i++){let s=t,n=a-h*(i/this.segmentsPerAxis),c=o*(e/this.segmentsPerAxis)+r;const u=Math.cos(n)*Math.sin(c),d=Math.cos(c),p=-Math.sin(n)*Math.sin(c);l.push([s*u,s*d,s*p])}const c=this.segmentsPerAxis+1;for(let t=0;t<this.segmentsPerAxis;t++)for(let i=0;i<this.segmentsPerAxis;i++)e.push(...l[i*c+t]),e.push(...l[i*c+t+1]),e.push(...l[(i+1)*c+t]),e.push(...l[(i+1)*c+t]),e.push(...l[i*c+t+1]),e.push(...l[(i+1)*c+t+1]);return new Float32Array(e)}createTextureUVs(){const e=[],t=[];for(let e=0;e<=this.segmentsPerAxis;e++)for(let i=0;i<=this.segmentsPerAxis;i++){const r=i/this.segmentsPerAxis,s=e/this.segmentsPerAxis;t.push([r,s])}const i=this.segmentsPerAxis+1;for(let r=0;r<this.segmentsPerAxis;r++)for(let s=0;s<this.segmentsPerAxis;s++)e.push(...t[s*i+r]),e.push(...t[s*i+r+1]),e.push(...t[(s+1)*i+r]),e.push(...t[(s+1)*i+r]),e.push(...t[s*i+r+1]),e.push(...t[(s+1)*i+r+1]);return new Float32Array(e)}}const Ii={colorFormat:6408,mipLevels:1,layout:Xt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0};class Fi extends Ht{constructor(e=Ii){if(super(),!zt(e.space))throw new TypeError("XRCubeLayer's space needs to be an XRReferenceSpace");switch(this.init=Object.assign(Object.assign({},Ii),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 Xt.default:case Xt["stereo-left-right"]:case Xt["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===Xt.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===Xt.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:Ut.texture,textureFormat:this.init.colorFormat,texture:e};const i=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,i),t}_createCubeDepthTexture(){let e=this.context.createTexture(),t={width:this.init.viewPixelWidth,height:this.init.viewPixelHeight,layers:1,type:Ut.texture,textureFormat:this.init.depthFormat,texture:e};const i=this.context.getParameter(this.context.TEXTURE_BINDING_CUBE_MAP);this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,e);let r=this.init.depthFormat;this.context instanceof WebGL2RenderingContext&&(r===this.context.DEPTH_COMPONENT&&(r=this.context.DEPTH_COMPONENT24),r===this.context.DEPTH_STENCIL&&(r=this.context.DEPTH24_STENCIL8));for(let e=0;e<6;e++)this.context.texImage2D(this.context.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,r,t.width,t.height,0,t.textureFormat,this.context.UNSIGNED_INT,null);return this.context.bindTexture(this.context.TEXTURE_CUBE_MAP,i),t}getTextureType(){return Ut.texture}}const Li=e=>e,Ci=Li`
|
|
183
|
+
`;class Pr{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=wr(),t instanceof WebGL2RenderingContext&&this.layer.getTextureType()===qt["texture-array"]&&(this.usesTextureArrayShaders=!0),this.usesTextureArrayShaders?this.program=lr(r,Mr,Ar):this.program=lr(r,Rr,br),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:qt.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 n=r.getParameter(r.ACTIVE_TEXTURE);for(let a of s.views){let s=i.getViewport(a);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===kt.stereo&&"right"===a.eye)s=1;this._shouldUseStereoTexturePoints()?this._renderInternalStereo(e,t,a,s):this._renderInternal(e,t,a,s),r.activeTexture(n),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===kt.stereo)if("right"===a.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,a):this._renderInternal(e,t,a),r.activeTexture(n),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,n=r.width/e.width,a=r.height/e.height,o=[];for(let e=0;e<t.length;e+=2){let r=t[e]*n+i,h=t[e+1]*a+s;o[e]=r,o[e+1]=h}return new Float32Array(o)}_shouldUseStereoTexturePoints(){return this.layer.layout===kt["stereo-left-right"]||this.layer.layout===kt["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 or(e,this.mediaTexturePolyfill,this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.mediaTexturePolyfill,this.texturePoints,e),or(e,this.mediaTexturePolyfill,this.layer.layout,1,2),this.stereoTexturePoints[1]=this._offsetTextureUVsByRect(this.mediaTexturePolyfill,this.texturePoints,e),void(this.layer.layout===kt["stereo-top-bottom"]&&([this.stereoTexturePoints[0],this.stereoTexturePoints[1]]=[this.stereoTexturePoints[1],this.stereoTexturePoints[0]]));or(e,this.layer.colorTexturesMeta[0],this.layer.layout,0,2),this.stereoTexturePoints[0]=this._offsetTextureUVsByRect(this.layer.colorTexturesMeta[0],this.texturePoints,e),or(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===kt["stereo-top-bottom"]&&([this.stereoTexturePoints[0],this.stereoTexturePoints[1]]=[this.stereoTexturePoints[1],this.stereoTexturePoints[0]])}}_createVAOs(){this._recalculateVertices();let e=this.gl;this.vaoGl=cr(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,n=!1,a=0,o=0;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,i,s,n,a,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,n=!1,a=0,o=0;e.vertexAttribPointer(this.programInfo.attribLocations.a_texCoord,i,s,n,a,o),this.restoreVaoState()}_renderInternal(e,t,r,i){let s=this.gl;const n=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 a=s.TRIANGLES,o=this.positionPoints.length/3;s.drawArrays(a,0,o),this.vaoGl.bindVertexArray(null),s.useProgram(n)}_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 n=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 a=s.TRIANGLES,o=this.positionPoints.length/3;s.drawArrays(a,0,o),this.vaoGl.bindVertexArray(null),s.useProgram(n)}_setTransformMatrix(e,t,r){let i=t.getPose(this.layer.space,e.getReferenceSpace());Tr(this.transformMatrix,i.transform.matrix,this.layer.transform.matrix),Tr(this.transformMatrix,r.transform.inverse.matrix,this.transformMatrix)}}class Fr extends Pr{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 Ir extends Pr{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,n=Math.PI/2-t/2,a=[],o=_r();o[0]=i*Math.cos(n),o[1]=-i*Math.sin(n),a.push(o);for(let e=0;e<this.segments;e++){const t=_r();t[0]=i*Math.cos(n+s*(e+1)),t[1]=-i*Math.sin(n+s*(e+1)),a.push(t)}a.reverse();for(let t=0;t<this.segments;t++){const i=a[t],s=a[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 Lr extends Pr{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,n=Math.PI/2-r/2,a=n+r,o=s-i,h=a-n,l=[];for(let e=0;e<=this.segmentsPerAxis;e++)for(let r=0;r<=this.segmentsPerAxis;r++){let s=t,n=a-h*(r/this.segmentsPerAxis),c=o*(e/this.segmentsPerAxis)+i;const u=Math.cos(n)*Math.sin(c),d=Math.cos(c),p=-Math.sin(n)*Math.sin(c);l.push([s*u,s*d,s*p])}const c=this.segmentsPerAxis+1;for(let t=0;t<this.segmentsPerAxis;t++)for(let r=0;r<this.segmentsPerAxis;r++)e.push(...l[r*c+t]),e.push(...l[r*c+t+1]),e.push(...l[(r+1)*c+t]),e.push(...l[(r+1)*c+t]),e.push(...l[r*c+t+1]),e.push(...l[(r+1)*c+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 Cr={colorFormat:6408,mipLevels:1,layout:kt.mono,isStatic:!1,space:null,viewPixelHeight:0,viewPixelWidth:0};class Dr extends Yt{constructor(e=Cr){if(super(),!Ht(e.space))throw new TypeError("XRCubeLayer's space needs to be an XRReferenceSpace");switch(this.init=Object.assign(Object.assign({},Cr),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 kt.default:case kt["stereo-left-right"]:case kt["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===kt.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===kt.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:qt.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:qt.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 qt.texture}}const Nr=e=>e,Or=Nr`
|
|
184
184
|
attribute vec4 a_position;
|
|
185
185
|
uniform mat4 u_projectionMatrix;
|
|
186
186
|
uniform mat4 u_matrix;
|
|
@@ -191,7 +191,7 @@ void main() {
|
|
|
191
191
|
|
|
192
192
|
v_normal = normalize(a_position.xyz);
|
|
193
193
|
}
|
|
194
|
-
`,
|
|
194
|
+
`,Vr=Nr`
|
|
195
195
|
precision mediump float;
|
|
196
196
|
|
|
197
197
|
varying vec3 v_normal;
|
|
@@ -201,4 +201,4 @@ uniform samplerCube u_texture;
|
|
|
201
201
|
void main() {
|
|
202
202
|
gl_FragColor = textureCube(u_texture, normalize(v_normal));
|
|
203
203
|
}
|
|
204
|
-
`;class Ni{constructor(e,t){this.savedVaoState={vao:null,arrayBuffer:null},this.hasMipmap=!1,this.layer=e,this.gl=t,this.transformMatrix=gi(),this.program=ai(t,Ci,Di),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 i=this.gl,r=e.getBaseLayer(),s=t.getViewerPose(e.getReferenceSpace());const n=i.getParameter(i.ACTIVE_TEXTURE);for(let e of s.views){let t=r.getViewport(e);i.viewport(t.x,t.y,t.width,t.height),i.activeTexture(i.TEXTURE0);const s=i.getParameter(i.TEXTURE_BINDING_CUBE_MAP);if(this.layer.layout===Xt.stereo){const t="right"===e.eye?1:0;i.bindTexture(i.TEXTURE_CUBE_MAP,this.layer.colorTextures[t])}else i.bindTexture(i.TEXTURE_CUBE_MAP,this.layer.colorTextures[0]);this.layer.isStatic?(!0===this.layer.needsRedraw&&i.generateMipmap(i.TEXTURE_CUBE_MAP),this.hasMipmap=!0):this.hasMipmap=this.layer.mipLevels>0,i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MAG_FILTER,this.hasMipmap?i.LINEAR_MIPMAP_LINEAR:i.LINEAR),i.texParameteri(i.TEXTURE_CUBE_MAP,i.TEXTURE_MIN_FILTER,this.hasMipmap?i.LINEAR_MIPMAP_LINEAR:i.LINEAR),this._renderInternal(this.layer.orientation,e),i.activeTexture(n),i.bindTexture(i.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 r=i.getParameter(i.CURRENT_PROGRAM);i.useProgram(this.program),this.vaoGl.bindVertexArray(this.vao),yi(this.transformMatrix,[e.x,e.y,e.z,e.w]),this._poseOrientationMatrix||(this._poseOrientationMatrix=gi()),yi(this._poseOrientationMatrix,[t.transform.inverse.orientation.x,t.transform.inverse.orientation.y,t.transform.inverse.orientation.z,t.transform.inverse.orientation.w]),vi(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 s=i.TRIANGLES,n=this.positionPoints.length/3;i.drawArrays(s,0,n),this.vaoGl.bindVertexArray(null),i.useProgram(r)}_recalculateVertices(){this.positionPoints=this.createPositionPoints()}_createVAOs(){this._recalculateVertices();let e=this.gl;this.vaoGl=oi(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 i=this.positionPoints;e.bufferData(e.ARRAY_BUFFER,i,e.STATIC_DRAW);var r=e.FLOAT;e.vertexAttribPointer(this.programInfo.attribLocations.a_position,3,r,!1,0,0),this.restoreVaoState()}}class Oi{constructor(){this.mode="inline",this.layers=[],this.views=[],this.initializedViews=!1,this.isPolyfillActive=!1,this.taskQueue=[]}requestAnimationFrame(e){this.injectedFrameCallback||(this.injectedFrameCallback=(t,i)=>{let r=this.context;if(!this.initializedViews&&this.referenceSpace){let e=i.getViewerPose(this.referenceSpace);e&&(this.views=e.views,this.initializedViews=!0)}if(this.isPolyfillActive&&this.initializedViews){this.tempFramebuffer||(this.tempFramebuffer=r.createFramebuffer()),r.bindFramebuffer(r.FRAMEBUFFER,this.tempFramebuffer);const e=r.getParameter(r.COLOR_CLEAR_VALUE),t=r.getParameter(r.FRAMEBUFFER_BINDING);r.clearColor(0,0,0,0);for(let e of this.layers)if(e instanceof ri)for(let t=0;t<e.colorTextures.length;t++){e.colorTexturesMeta[t].type===Ut["texture-array"]||(r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,e.colorTextures[t],0),e.depthStencilTextures&&t<e.depthStencilTextures.length?r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,e.depthStencilTextures[t],0):r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,null,0),r.clear(r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT))}r.bindFramebuffer(r.FRAMEBUFFER,t),r.clearColor(e[0],e[1],e[2],e[3])}if(e(t,i),this.isPolyfillActive&&this.initializedViews){let e=r.isEnabled(r.BLEND),t=r.isEnabled(r.DEPTH_TEST),s=r.isEnabled(r.CULL_FACE);const n=r.getParameter(r.FRAMEBUFFER_BINDING),a=r.getParameter(r.COLOR_CLEAR_VALUE);r.bindFramebuffer(r.FRAMEBUFFER,this.getBaseLayer().framebuffer),r.clear(r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT),r.clearColor(a[0],a[1],a[2],a[3]),r.enable(r.BLEND),r.disable(r.DEPTH_TEST),r.disable(r.CULL_FACE);let o=r.getParameter(r.BLEND_SRC_RGB),h=r.getParameter(r.BLEND_SRC_ALPHA),l=r.getParameter(r.BLEND_DST_RGB),c=r.getParameter(r.BLEND_DST_ALPHA);r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA);for(let e of this.layers)if(this.renderers||(this.renderers=new WeakMap),e instanceof ri){this.renderers.has(e)||this.renderers.set(e,mi(e,this.context));this.renderers.get(e).render(this)}else if(e instanceof ei){this.renderers.has(e)||this.renderers.set(e,new Mi(e,this.context));this.renderers.get(e).render(this,i)}else if(e instanceof Yt){this.renderers.has(e)||this.renderers.set(e,new Ai(e,this.context));this.renderers.get(e).render(this,i)}else if(e instanceof Kt){this.renderers.has(e)||this.renderers.set(e,new Pi(e,this.context));this.renderers.get(e).render(this,i)}else if(e instanceof Fi){this.renderers.has(e)||this.renderers.set(e,new Ni(e,this.context));this.renderers.get(e).render(this,i)}else{const t=e;if(null===t.framebuffer)continue;r instanceof WebGL2RenderingContext?(r.bindFramebuffer(r.READ_FRAMEBUFFER,t.framebuffer),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,this.getBaseLayer().framebuffer),r.blitFramebuffer(0,0,t.framebufferWidth,t.framebufferHeight,0,0,this.getBaseLayer().framebufferWidth,this.getBaseLayer().framebufferHeight,r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT,r.LINEAR)):console.warn("GL blitFramebuffer is not supported on WebGL1, so XRWebGLLayers may not show up properly when polyfilled.")}for(e||r.disable(r.BLEND),t&&r.enable(r.DEPTH_TEST),s&&r.enable(r.CULL_FACE),r.blendFuncSeparate(o,l,h,c),r.bindFramebuffer(r.FRAMEBUFFER,n);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,i=Object.assign({},e);delete i.layers;for(let r of this.layers)if(r instanceof Ht){t=r.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 n(){t.canvas.width=t.canvas.clientWidth*window.devicePixelRatio,t.canvas.height=t.canvas.clientHeight*window.devicePixelRatio}document.body.appendChild(t.canvas),window.addEventListener("resize",n),n()}this.createInternalLayer(t),this.isPolyfillActive=!0,this._updateRenderState(Object.assign(Object.assign({},i),{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 i=this.views[t];if(e.eye===i.eye&&e.recommendedViewportScale===i.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=qt();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=qt();let t=Object.getOwnPropertyNames(e.XRRenderState.prototype);const i={};for(let e of t)i[e]=this._renderState[e];i.layers=[],this.activeRenderState=i}}class Vi{constructor(){this.viewport={x:0,y:0,width:0,height:0}}}class Bi{constructor(e,t){this.session=e,this.context=t,this.subImageCache=new Gi}createProjectionLayer(e=ii){const t=new ri(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=Jt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===Xt.default)throw new TypeError("Trying to create a quad layer with default layout");const t=new ei(e);return t.initialize(this.session,this.context),t}createCylinderLayer(e=jt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===Xt.default)throw new TypeError("Cylinder Layer cannot have a default layout");const t=new Yt(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===Xt.default)throw new TypeError("Equirect Layer cannot have a default layout");if(!zt(e.space))throw new TypeError("Equirect layer requires an XRReferenceSpace");let t=new Kt(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(!zt(e.space))throw new TypeError("XRCubeLayer requires a space of type XRReferenceSpace");let t=new Fi(e);return t.initialize(this.session,this.context),t}getSubImage(e,t,i="none"){if(e.isStatic&&!1===e.needsRedraw)throw new Error("Invalid state for subimage creation");let r=this.subImageCache.tryGetCachedSubImage(this.context,e,i);if(r)return r;let s=new Vi;if(e instanceof ri)throw new TypeError;if(e.layout===Xt.default)throw new TypeError;if(!this.validateStateofSubImageCreation(e,t))throw new Error("Invalid state for subimage creation");let n=0;if(e.layout===Xt.stereo){if("none"===i)throw new TypeError;"right"===i&&(n=1)}e.getTextureType()===Ut["texture-array"]?s.imageIndex=n:s.imageIndex=0;let a=0;e.getTextureType()===Ut.texture?(s.colorTexture=e.colorTextures[n],a=n):(s.colorTexture=e.colorTextures[0],a=0),e.depthStencilTextures&&e.depthStencilTextures.length?e.getTextureType()===Ut.texture?s.depthStencilTexture=e.depthStencilTextures[n]:s.depthStencilTexture=e.depthStencilTextures[0]:s.depthStencilTexture=null;const o=e.colorTexturesMeta[a];s.textureWidth=o.width,s.textureHeight=o.height;let h=1;return e.layout!==Xt["stereo-left-right"]&&e.layout!==Xt["stereo-top-bottom"]||(h=2),si(s.viewport,o,e.layout,n,h),this.session.queueTask(()=>{e.needsRedraw=!1}),this.subImageCache.cacheSubImage(s,this.context,e,i),s}getViewSubImage(e,t){let i=this.subImageCache.tryGetCachedViewSubImage(this.context,e,t);if(i)return i;let r=new Vi,s=this.session;if(!s.internalViews||!s.internalViews.length)return console.warn("Tried to get view sub image before we have any views"),r;let n=s.getViewIndex(t),a=0;return e.getTextureType()===Ut["texture-array"]?r.imageIndex=n:r.imageIndex=0,e.layout===Xt.default&&e.getTextureType()===Ut.texture?(r.colorTexture=e.colorTextures[n],a=n):(r.colorTexture=e.colorTextures[0],a=0),0===e.depthStencilTextures.length?r.depthStencilTexture=null:e.layout===Xt.default&&e.getTextureType()===Ut.texture?r.depthStencilTexture=e.depthStencilTextures[n]:r.depthStencilTexture=e.depthStencilTextures[0],r.textureWidth=e.colorTexturesMeta[a].width,r.textureHeight=e.colorTexturesMeta[a].height,si(r.viewport,e.colorTexturesMeta[a],e.layout,n,s.internalViews.length),e.needsRedraw=!1,this.subImageCache.cacheViewSubImage(r,this.context,e,t),r}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 Gi{constructor(){this.cache=new Map,this.viewCache=new Map}cacheSubImage(e,t,i,r){let s=new Map;s.set(r,e);let n=new Map;n.set(i,s),this.cache.set(t,n)}tryGetCachedSubImage(e,t,i){var r,s;return null===(s=null===(r=this.cache.get(e))||void 0===r?void 0:r.get(t))||void 0===s?void 0:s.get(i)}cacheViewSubImage(e,t,i,r){let s=new Map;s.set(r,e);let n=new Map;n.set(i,s),this.viewCache.set(t,n)}tryGetCachedViewSubImage(e,t,i){var r,s;return null===(s=null===(r=this.viewCache.get(e))||void 0===r?void 0:r.get(t))||void 0===s?void 0:s.get(i)}}class Ui{constructor(){this.injected=!1;const e=qt();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=Bi,e.XRMediaBinding=ti,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 i=Object.getOwnPropertyDescriptor(Oi.prototype,"renderState");Object.defineProperty(e.XRSession.prototype,"renderState",i);let r=Object.getOwnPropertyNames(Oi.prototype);for(let t of r){let i=Object.getOwnPropertyDescriptor(Oi.prototype,t);Object.defineProperty(e.XRSession.prototype,t,i)}}_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,i)=>{const r=(i,r)=>e.navigator.xr.requestSessionInternal(i,r).then(e=>{Object.assign(e,new Oi);let i=e;return i.initializeSession(t),Promise.resolve(i)});if("immersive-vr"!==t)return r(t,i);if(!i)return r(t,i);if(i.requiredFeatures&&i.requiredFeatures.indexOf("layers")>-1){const e=Object.assign({},i),s=[...i.requiredFeatures],n=s.indexOf("layers");return s.splice(n,1),e.requiredFeatures=s,r(t,e)}return r(t,i)}}}const Xi={ipd:.063,fovy:Math.PI/2,headsetPosition:new ce(0,1.6,0),headsetQuaternion:new ue,stereoEnabled:!1};const zi={mapping:Se.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"}]},qi={mapping:Se.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"}]},ki={profileId:"oculus-touch-v3",fallbackProfileIds:["oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:zi,gripOffsetMatrix:[.9925461411476135,2.0823669899527886e-8,-.12186937034130096,0,.08617465198040009,.7071067094802856,.701836109161377,0,.08617466688156128,-.7071067690849304,.7018360495567322,0,-.003979838453233242,-.015857907012104988,.04964181408286095,1],numHapticActuators:1},right:{gamepad:qi,gripOffsetMatrix:[.9925461411476135,-8.329467959811154e-8,.12186941504478455,0,-.08617465943098068,.7071066498756409,.7018361687660217,0,-.08617471158504486,-.7071068286895752,.7018359303474426,0,.003979798872023821,-.015857888385653496,.049641866236925125,1],numHapticActuators:1}}},Hi={profileId:"meta-quest-touch-pro",fallbackProfileIds:["oculus-touch-v2","oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:zi,gripOffsetMatrix:[.9925461411476135,-1.5779937356796836e-8,-.12186935544013977,0,.08617467433214188,.7071067094802856,.701836109161377,0,.0861746296286583,-.7071067690849304,.7018360495567322,0,-.003979836590588093,-.015857847407460213,.049641840159893036,1],numHapticActuators:3},right:{gamepad:qi,gripOffsetMatrix:[.9925461411476135,9267653311439972e-26,.12186937034130096,0,-.08617467433214188,.7071067094802856,.7018361687660217,0,-.08617464452981949,-.7071067690849304,.7018360495567322,0,.003979847766458988,-.01585782691836357,.04964186251163483,1],numHapticActuators:3}}},ji={profileId:"meta-quest-touch-plus",fallbackProfileIds:["oculus-touch-v3","oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:zi,gripOffsetMatrix:[.9925461411476135,1.0736208366779465e-8,-.12186933308839798,0,.08617459982633591,.70710688829422,.7018360495567322,0,.08617466688156128,-.7071067094802856,.7018362283706665,0,-.003979803062975407,-.015857873484492302,.04964187368750572,1],numHapticActuators:1},right:{gamepad:qi,gripOffsetMatrix:[.9925461411476135,-2.6238110351073374e-8,.12186934053897858,0,-.0861746147274971,.7071067690849304,.7018360495567322,0,-.08617465943098068,-.7071067094802856,.701836109161377,0,.003979838453233242,-.015857869759202003,.04964182525873184,1],numHapticActuators:1}}},Wi={name:"Oculus Quest 1",controllerConfig:{profileId:"oculus-touch-v2",fallbackProfileIds:["oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:zi,gripOffsetMatrix:[.9925461411476135,4.673031295254759e-9,-.12186938524246216,0,.08617470413446426,.7071065306663513,.7018362283706665,0,.0861746296286583,-.70710688829422,.7018358707427979,0,-.003979847766458988,-.01585787907242775,.04964185878634453,1],numHapticActuators:1},right:{gamepad:qi,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":dt.Opaque,"immersive-ar":dt.AlphaBlend},interactionMode:pt.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"},Yi={name:"Meta Quest 2",controllerConfig:ki,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":dt.Opaque,"immersive-ar":dt.AlphaBlend},interactionMode:pt.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"},Qi={name:"Meta Quest Pro",controllerConfig:Hi,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":dt.Opaque,"immersive-ar":dt.AlphaBlend},interactionMode:pt.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"},$i={name:"Meta Quest 3",controllerConfig:ji,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":dt.Opaque,"immersive-ar":dt.AlphaBlend},interactionMode:pt.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"},Ki=e=>{const t=[];return Array.from(e).forEach(e=>{t.push(parseFloat(e.toFixed(3)))}),t};e.ActionRecorder=class{constructor(e,t){this[N]={session:e,refSpace:t,inputMap:new Map,schemaMap:new Map,compressedFrames:[],jointRadii:new Float32Array(25),jointTransforms:new Float32Array(400)}}recordFrame(e){var t;const i=performance.now(),r=null===(t=e.getViewerPose(this[N].refSpace))||void 0===t?void 0:t.transform.matrix;if(!r)return;const s={timeStamp:i,position:u(m(),r),quaternion:p(b(),r),inputFrames:[]};this[N].session.inputSources.forEach(t=>{var i,r;if(!this[N].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 i=this[N].inputMap.size;this[N].inputMap.set(t,i),this[N].schemaMap.set(i,e)}const n=this[N].inputMap.get(t),a=this[N].schemaMap.get(n),o=null===(i=e.getPose(t.targetRaySpace,this[N].refSpace))||void 0===i?void 0:i.transform.matrix;if(o){const i={index:n,targetRayTransform:{position:u(m(),o),quaternion:p(b(),o)}};if(a.hasGrip){const s=null===(r=e.getPose(t.gripSpace,this[N].refSpace))||void 0===r?void 0:r.transform.matrix;if(s){const e=u(m(),s),t=p(b(),s);i.gripTransform={position:e,quaternion:t}}}if(a.hasHand){const r=Array.from(t.hand.values());let s=!0;if(s&&(s=e.fillPoses(r,t.targetRaySpace,this[N].jointTransforms)),s&&(s=e.fillJointRadii(r,this[N].jointRadii)),s){const e={};for(let t=0;t<25;t++){const i=this[N].jointTransforms.slice(16*t,16*(t+1)),s=this[N].jointRadii[t],n=u(m(),i),a=p(b(),i);e[r[t].jointName]={position:n,quaternion:a,radius:s}}i.hand=e}}if(a.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)};i.gamepad=e}s.inputFrames.push(i)}}),this[N].compressedFrames.push(this.compressActionFrame(s))}compressActionFrame(e){const t=[Math.round(10*e.timeStamp)/10,...Ki(e.position),...Ki(e.quaternion)];return e.inputFrames.forEach(e=>{const i=e.index,r=this[N].schemaMap.get(i),s=[i,...Ki(e.targetRayTransform.position),...Ki(e.targetRayTransform.quaternion)];if(r.hasGrip&&s.push([...Ki(e.gripTransform.position),...Ki(e.gripTransform.quaternion)]),r.hasHand){const t=[];Object.values(e.hand).forEach(({position:e,quaternion:i,radius:r})=>{t.push(...Ki(e),...Ki(i),parseFloat(r.toFixed(3)))}),s.push(t)}r.hasGamepad&&s.push([...e.gamepad.buttons,...e.gamepad.axes]),t.push(s)}),t}log(){const e={schema:Array.from(this[N].schemaMap.entries()),frames:this[N].compressedFrames};console.log(JSON.stringify(e))}},e.NativeMesh=class{constructor(e,t,i,r){this.transform=e,this.vertices=t,this.indices=i,this.semanticLabel=r}},e.NativePlane=class{constructor(e,t,i){this.transform=e,this.polygon=t,this.semanticLabel=i}},e.P_ACTION_PLAYER=D,e.P_ACTION_RECORDER=N,e.P_ANCHOR=O,e.P_CONTROLLER=V,e.P_DEVICE=B,e.P_FRAME=X,e.P_GAMEPAD=z,e.P_HAND_INPUT=G,e.P_HIT_TEST=ae,e.P_INPUT_SOURCE=k,e.P_JOINT_POSE=Y,e.P_JOINT_SPACE=ee,e.P_MESH=j,e.P_PLANE=W,e.P_POSE=Q,e.P_RAY=ne,e.P_REF_SPACE=te,e.P_RENDER_STATE=J,e.P_RIGID_TRANSFORM=K,e.P_SESSION=Z,e.P_SPACE=ie,e.P_SYSTEM=q,e.P_TRACKED_INPUT=U,e.P_VIEW=re,e.P_VIEWER_POSE=$,e.P_VIEWPORT=se,e.P_WEBGL_LAYER=H,e.RemoteControlInterface=we,e.XRAnchor=Xe,e.XRAnchorSet=ze,e.XRDevice=class{constructor(e,t={}){var i,s,n,a,o,l;this.version=Ot;const u=new he,d=new et(Je.Viewer,u),p={[Ze.Left]:new oe(d),[Ze.Right]:new oe(d),[Ze.None]:new oe(d)},f=e.controllerConfig,m={};f&&Object.values(_e).forEach(e=>{f.layout[e]&&(m[e]=new Ce(f,e,u))});const g={[_e.Left]:new Ft(vt,_e.Left,u),[_e.Right]:new Ft(vt,_e.Right,u)},v=null!==(i=t.canvasContainer)&&void 0!==i?i:document.createElement("div");v.dataset.webxr_runtime=`Immersive Web Emulation Runtime v${Ot}`,v.style.position="fixed",v.style.width="100%",v.style.height="100%",v.style.top="0",v.style.left="0",v.style.display="flex",v.style.justifyContent="center",v.style.alignItems="center",v.style.overflow="hidden",v.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:Xi.headsetPosition.clone(),quaternion:null!==(n=t.headsetQuaternion)&&void 0!==n?n:Xi.headsetQuaternion.clone(),stereoEnabled:null!==(a=t.stereoEnabled)&&void 0!==a?a:Xi.stereoEnabled,ipd:null!==(o=t.ipd)&&void 0!==o?o:Xi.ipd,fovy:null!==(l=t.fovy)&&void 0!==l?l:Xi.fovy,controllers:m,hands:g,primaryInputMode:"controller",pendingReferenceSpaceReset:!1,visibilityState:"visible",pendingVisibilityState:null,xrSystem:null,matrix:r(),globalSpace:u,viewerSpace:d,viewSpaces:p,canvasContainer:v,getViewport:(e,t)=>{const i=e.context.canvas,{width:r,height:s}=i;switch(t.eye){case Ze.None:return new Gt(0,0,r,s);case Ze.Left:return new Gt(0,0,this[B].stereoEnabled?r/2:r,s);case Ze.Right:return new Gt(r/2,0,this[B].stereoEnabled?r/2:0,s)}},updateViews:()=>{c(this[B].viewerSpace[ie].offsetMatrix,this[B].quaternion.quat,this[B].position.vec3),h(this[B].viewSpaces[Ze.Left][ie].offsetMatrix,x(-this[B].ipd/2,0,0)),h(this[B].viewSpaces[Ze.Right][ie].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:i}=e;t.style.zIndex=3..toString(),i.style.zIndex=4..toString(),this[B].canvasContainer.appendChild(e.devUICanvas),this[B].canvasContainer.appendChild(e.devUIContainer)}const i=this[B].sem;i&&(i.environmentCanvas.style.zIndex=1..toString(),this[B].canvasContainer.appendChild(i.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:i,height:r,zIndex:s}=this[B].canvasData;e.width=i,e.height=r,e.style.zIndex=s,t?t.appendChild(e):this[B].canvasContainer.removeChild(e);const n=this[B].devui;n&&(this[B].canvasContainer.removeChild(n.devUICanvas),this[B].canvasContainer.removeChild(n.devUIContainer));const a=this[B].sem;a&&this[B].canvasContainer.removeChild(a.environmentCanvas),document.body.removeChild(this[B].canvasContainer),this[B].canvasData=void 0,window.dispatchEvent(new Event("resize"))}},onFrameStart:e=>{var t;const i=performance.now(),r=this[B].lastFrameTime>0?i-this[B].lastFrameTime:16.67;if(this[B].lastFrameTime=i,this[B].remote&&this[B].remote.update(r),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 it("visibilitychange",{session:t}))),"visible"===this[B].visibilityState&&this.activeInputs.forEach(t=>{t.onFrameStart(e)}),this[B].pendingReferenceSpaceReset&&(t[Z].referenceSpaces.forEach(e=>{switch(e[te].type){case Je.Local:case Je.LocalFloor:case Je.BoundedFloor:case Je.Unbounded:e.dispatchEvent(new Vt("reset",{referenceSpace:e}))}}),this[B].pendingReferenceSpaceReset=!1)}this[B].updateViews()},controlMode:"manual",controlModeListeners:new Set,stateChangeListeners:new Set,remote:null,lastFrameTime:0},this[B].remote=new we(this),this[B].updateViews()}installRuntime(e){var t;const i=null!==(t=null==e?void 0:e.globalObject)&&void 0!==t?t:globalThis,r=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 Bt(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}),i.XRSystem=Bt,i.XRSession=mt,i.XRRenderState=tt,i.XRFrame=ut,i.XRSpace=oe,i.XRReferenceSpace=et,i.XRJointSpace=gt,i.XRView=rt,i.XRViewport=Gt,i.XRRigidTransform=He,i.XRPose=st,i.XRViewerPose=at,i.XRJointPose=nt,i.XRInputSource=Pe,i.XRInputSourceArray=Ae,i.XRHand=xt,i.XRLayer=Lt,i.XRWebGLLayer=Dt,i.XRSessionEvent=it,i.XRInputSourceEvent=Ie,i.XRInputSourcesChangeEvent=$e,i.XRReferenceSpaceEvent=Vt,r?new Ui:(i.XRMediaBinding=void 0,i.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 appCanvas(){var e;return null===(e=this[B].canvasData)||void 0===e?void 0:e.canvas}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:i,reject:r,mode:s,options:n}=t.offeredSessionConfig;t.offeredSessionConfig=void 0,e.requestSession(s,n).then(i).catch(r)}}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 i=Math.atan2(t.x,-t.z),r=(new ue).setFromAxisAngle(new ce(0,1,0),i);this.position.add(e),this.quaternion.multiply(r),[...Object.values(this[B].controllers),...Object.values(this[B].hands)].forEach(t=>{t.position.add(e),t.quaternion.multiply(r),t.position.applyQuaternion(r)}),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 Nt(e,t,this[B].ipd),this[B].actionPlayer}get devui(){return this[B].devui}get sem(){return this[B].sem}get remote(){return this[B].remote}get controlMode(){return this[B].controlMode}set controlMode(e){if("manual"!==e&&"programmatic"!==e)return void console.warn('control mode can only be "manual" or "programmatic"');this[B].controlMode!==e&&(this[B].controlMode=e,this[B].controlModeListeners.forEach(t=>t(e)))}onControlModeChange(e){return this[B].controlModeListeners.add(e),()=>{this[B].controlModeListeners.delete(e)}}onStateChange(e){return this[B].stateChangeListeners.add(e),()=>{this[B].stateChangeListeners.delete(e)}}notifyStateChange(){this[B].stateChangeListeners.forEach(e=>e())}},e.XRFrame=ut,e.XRHand=xt,e.XRInputSource=Pe,e.XRInputSourceArray=Ae,e.XRInputSourceEvent=Ie,e.XRInputSourcesChangeEvent=$e,e.XRJointPose=nt,e.XRJointSpace=gt,e.XRLayer=Lt,e.XRMesh=De,e.XRMeshSet=Ne,e.XRPlane=Ge,e.XRPlaneSet=Ue,e.XRPose=st,e.XRRay=We,e.XRReferenceSpace=et,e.XRReferenceSpaceEvent=Vt,e.XRRenderState=tt,e.XRRigidTransform=He,e.XRSession=mt,e.XRSessionEvent=it,e.XRSpace=oe,e.XRSystem=Bt,e.XRView=rt,e.XRViewerPose=at,e.XRViewport=Gt,e.XRWebGLLayer=Dt,e.directionTo=xe,e.eulerToQuat=me,e.lookRotation=ge,e.metaQuest2=Yi,e.metaQuest3=$i,e.metaQuestPro=Qi,e.oculusQuest1=Wi,e.quatToEuler=fe,e.quatToObj=pe,e.vec3ToObj=de,e.waitForCondition=ve,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
204
|
+
`;class Br{constructor(e,t){this.savedVaoState={vao:null,arrayBuffer:null},this.hasMipmap=!1,this.layer=e,this.gl=t,this.transformMatrix=wr(),this.program=lr(t,Or,Vr),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 n=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===kt.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(n),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),Sr(this.transformMatrix,[e.x,e.y,e.z,e.w]),this._poseOrientationMatrix||(this._poseOrientationMatrix=wr()),Sr(this._poseOrientationMatrix,[t.transform.inverse.orientation.x,t.transform.inverse.orientation.y,t.transform.inverse.orientation.z,t.transform.inverse.orientation.w]),Tr(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,n=this.positionPoints.length/3;r.drawArrays(s,0,n),this.vaoGl.bindVertexArray(null),r.useProgram(i)}_recalculateVertices(){this.positionPoints=this.createPositionPoints()}_createVAOs(){this._recalculateVertices();let e=this.gl;this.vaoGl=cr(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 Ur{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 ar)for(let t=0;t<e.colorTextures.length;t++){e.colorTexturesMeta[t].type===qt["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 n=i.getParameter(i.FRAMEBUFFER_BINDING),a=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(a[0],a[1],a[2],a[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),c=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 ar){this.renderers.has(e)||this.renderers.set(e,vr(e,this.context));this.renderers.get(e).render(this)}else if(e instanceof ir){this.renderers.has(e)||this.renderers.set(e,new Fr(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof Kt){this.renderers.has(e)||this.renderers.set(e,new Ir(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof er){this.renderers.has(e)||this.renderers.set(e,new Lr(e,this.context));this.renderers.get(e).render(this,r)}else if(e instanceof Dr){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,c),i.bindFramebuffer(i.FRAMEBUFFER,n);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 Yt){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 n(){t.canvas.width=t.canvas.clientWidth*window.devicePixelRatio,t.canvas.height=t.canvas.clientHeight*window.devicePixelRatio}document.body.appendChild(t.canvas),window.addEventListener("resize",n),n()}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=jt();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=jt();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 Gr{constructor(){this.viewport={x:0,y:0,width:0,height:0}}}class Xr{constructor(e,t){this.session=e,this.context=t,this.subImageCache=new zr}createProjectionLayer(e=nr){const t=new ar(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=tr){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===kt.default)throw new TypeError("Trying to create a quad layer with default layout");const t=new ir(e);return t.initialize(this.session,this.context),t}createCylinderLayer(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===kt.default)throw new TypeError("Cylinder Layer cannot have a default layout");const t=new Kt(e);return t.initialize(this.session,this.context),t}createEquirectLayer(e=Jt){if(this.session.ended)throw new Error("Session has ended");if(this.context.isContextLost())throw new Error("context is lost");if(e.layout===kt.default)throw new TypeError("Equirect Layer cannot have a default layout");if(!Ht(e.space))throw new TypeError("Equirect layer requires an XRReferenceSpace");let t=new er(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(!Ht(e.space))throw new TypeError("XRCubeLayer requires a space of type XRReferenceSpace");let t=new Dr(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 Gr;if(e instanceof ar)throw new TypeError;if(e.layout===kt.default)throw new TypeError;if(!this.validateStateofSubImageCreation(e,t))throw new Error("Invalid state for subimage creation");let n=0;if(e.layout===kt.stereo){if("none"===r)throw new TypeError;"right"===r&&(n=1)}e.getTextureType()===qt["texture-array"]?s.imageIndex=n:s.imageIndex=0;let a=0;e.getTextureType()===qt.texture?(s.colorTexture=e.colorTextures[n],a=n):(s.colorTexture=e.colorTextures[0],a=0),e.depthStencilTextures&&e.depthStencilTextures.length?e.getTextureType()===qt.texture?s.depthStencilTexture=e.depthStencilTextures[n]:s.depthStencilTexture=e.depthStencilTextures[0]:s.depthStencilTexture=null;const o=e.colorTexturesMeta[a];s.textureWidth=o.width,s.textureHeight=o.height;let h=1;return e.layout!==kt["stereo-left-right"]&&e.layout!==kt["stereo-top-bottom"]||(h=2),or(s.viewport,o,e.layout,n,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 Gr,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 n=s.getViewIndex(t),a=0;return e.getTextureType()===qt["texture-array"]?i.imageIndex=n:i.imageIndex=0,e.layout===kt.default&&e.getTextureType()===qt.texture?(i.colorTexture=e.colorTextures[n],a=n):(i.colorTexture=e.colorTextures[0],a=0),0===e.depthStencilTextures.length?i.depthStencilTexture=null:e.layout===kt.default&&e.getTextureType()===qt.texture?i.depthStencilTexture=e.depthStencilTextures[n]:i.depthStencilTexture=e.depthStencilTextures[0],i.textureWidth=e.colorTexturesMeta[a].width,i.textureHeight=e.colorTexturesMeta[a].height,or(i.viewport,e.colorTexturesMeta[a],e.layout,n,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 zr{constructor(){this.cache=new Map,this.viewCache=new Map}cacheSubImage(e,t,r,i){let s=new Map;s.set(i,e);let n=new Map;n.set(r,s),this.cache.set(t,n)}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 n=new Map;n.set(r,s),this.viewCache.set(t,n)}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 qr{constructor(){this.injected=!1;const e=jt();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=Xr,e.XRMediaBinding=sr,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(Ur.prototype,"renderState");Object.defineProperty(e.XRSession.prototype,"renderState",r);let i=Object.getOwnPropertyNames(Ur.prototype);for(let t of i){let r=Object.getOwnPropertyDescriptor(Ur.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 Ur);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],n=s.indexOf("layers");return s.splice(n,1),e.requiredFeatures=s,i(t,e)}return i(t,r)}}}const kr={ipd:.063,fovy:Math.PI/2,headsetPosition:new ue(0,1.6,0),headsetQuaternion:new de,stereoEnabled:!1};const Hr={mapping:Ee.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"}]},jr={mapping:Ee.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"}]},Wr={profileId:"oculus-touch-v3",fallbackProfileIds:["oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Hr,gripOffsetMatrix:[.9925461411476135,2.0823669899527886e-8,-.12186937034130096,0,.08617465198040009,.7071067094802856,.701836109161377,0,.08617466688156128,-.7071067690849304,.7018360495567322,0,-.003979838453233242,-.015857907012104988,.04964181408286095,1],numHapticActuators:1},right:{gamepad:jr,gripOffsetMatrix:[.9925461411476135,-8.329467959811154e-8,.12186941504478455,0,-.08617465943098068,.7071066498756409,.7018361687660217,0,-.08617471158504486,-.7071068286895752,.7018359303474426,0,.003979798872023821,-.015857888385653496,.049641866236925125,1],numHapticActuators:1}}},Yr={profileId:"meta-quest-touch-pro",fallbackProfileIds:["oculus-touch-v2","oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Hr,gripOffsetMatrix:[.9925461411476135,-1.5779937356796836e-8,-.12186935544013977,0,.08617467433214188,.7071067094802856,.701836109161377,0,.0861746296286583,-.7071067690849304,.7018360495567322,0,-.003979836590588093,-.015857847407460213,.049641840159893036,1],numHapticActuators:3},right:{gamepad:jr,gripOffsetMatrix:[.9925461411476135,9267653311439972e-26,.12186937034130096,0,-.08617467433214188,.7071067094802856,.7018361687660217,0,-.08617464452981949,-.7071067690849304,.7018360495567322,0,.003979847766458988,-.01585782691836357,.04964186251163483,1],numHapticActuators:3}}},Qr={profileId:"meta-quest-touch-plus",fallbackProfileIds:["oculus-touch-v3","oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Hr,gripOffsetMatrix:[.9925461411476135,1.0736208366779465e-8,-.12186933308839798,0,.08617459982633591,.70710688829422,.7018360495567322,0,.08617466688156128,-.7071067094802856,.7018362283706665,0,-.003979803062975407,-.015857873484492302,.04964187368750572,1],numHapticActuators:1},right:{gamepad:jr,gripOffsetMatrix:[.9925461411476135,-2.6238110351073374e-8,.12186934053897858,0,-.0861746147274971,.7071067690849304,.7018360495567322,0,-.08617465943098068,-.7071067094802856,.701836109161377,0,.003979838453233242,-.015857869759202003,.04964182525873184,1],numHapticActuators:1}}},$r={name:"Oculus Quest 1",controllerConfig:{profileId:"oculus-touch-v2",fallbackProfileIds:["oculus-touch","generic-trigger-squeeze-thumbstick"],layout:{left:{gamepad:Hr,gripOffsetMatrix:[.9925461411476135,4.673031295254759e-9,-.12186938524246216,0,.08617470413446426,.7071065306663513,.7018362283706665,0,.0861746296286583,-.70710688829422,.7018358707427979,0,-.003979847766458988,-.01585787907242775,.04964185878634453,1],numHapticActuators:1},right:{gamepad:jr,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":mt.Opaque,"immersive-ar":mt.AlphaBlend},interactionMode:xt.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"},Kr={name:"Meta Quest 2",controllerConfig:Wr,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":mt.Opaque,"immersive-ar":mt.AlphaBlend},interactionMode:xt.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"},Jr={name:"Meta Quest Pro",controllerConfig:Yr,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":mt.Opaque,"immersive-ar":mt.AlphaBlend},interactionMode:xt.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"},Zr={name:"Meta Quest 3",controllerConfig:Qr,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":mt.Opaque,"immersive-ar":mt.AlphaBlend},interactionMode:xt.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"},ei=e=>{const t=[];return Array.from(e).forEach(e=>{t.push(parseFloat(e.toFixed(3)))}),t};e.ActionRecorder=class{constructor(e,t){this[N]={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[N].refSpace))||void 0===t?void 0:t.transform.matrix;if(!i)return;const s={timeStamp:r,position:u(m(),i),quaternion:p(b(),i),inputFrames:[]};this[N].session.inputSources.forEach(t=>{var r,i;if(!this[N].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[N].inputMap.size;this[N].inputMap.set(t,r),this[N].schemaMap.set(r,e)}const n=this[N].inputMap.get(t),a=this[N].schemaMap.get(n),o=null===(r=e.getPose(t.targetRaySpace,this[N].refSpace))||void 0===r?void 0:r.transform.matrix;if(o){const r={index:n,targetRayTransform:{position:u(m(),o),quaternion:p(b(),o)}};if(a.hasGrip){const s=null===(i=e.getPose(t.gripSpace,this[N].refSpace))||void 0===i?void 0:i.transform.matrix;if(s){const e=u(m(),s),t=p(b(),s);r.gripTransform={position:e,quaternion:t}}}if(a.hasHand){const i=Array.from(t.hand.values());let s=!0;if(s&&(s=e.fillPoses(i,t.targetRaySpace,this[N].jointTransforms)),s&&(s=e.fillJointRadii(i,this[N].jointRadii)),s){const e={};for(let t=0;t<25;t++){const r=this[N].jointTransforms.slice(16*t,16*(t+1)),s=this[N].jointRadii[t],n=u(m(),r),a=p(b(),r);e[i[t].jointName]={position:n,quaternion:a,radius:s}}r.hand=e}}if(a.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[N].compressedFrames.push(this.compressActionFrame(s))}compressActionFrame(e){const t=[Math.round(10*e.timeStamp)/10,...ei(e.position),...ei(e.quaternion)];return e.inputFrames.forEach(e=>{const r=e.index,i=this[N].schemaMap.get(r),s=[r,...ei(e.targetRayTransform.position),...ei(e.targetRayTransform.quaternion)];if(i.hasGrip&&s.push([...ei(e.gripTransform.position),...ei(e.gripTransform.quaternion)]),i.hasHand){const t=[];Object.values(e.hand).forEach(({position:e,quaternion:r,radius:i})=>{t.push(...ei(e),...ei(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[N].schemaMap.entries()),frames:this[N].compressedFrames};console.log(JSON.stringify(e))}},e.NativeMesh=class{constructor(e,t,r,i){this.transform=e,this.vertices=t,this.indices=r,this.semanticLabel=i}},e.NativePlane=class{constructor(e,t,r){this.transform=e,this.polygon=t,this.semanticLabel=r}},e.P_ACTION_PLAYER=D,e.P_ACTION_RECORDER=N,e.P_ANCHOR=O,e.P_CONTROLLER=V,e.P_DEPTH_INFO=ae,e.P_DEVICE=B,e.P_FRAME=X,e.P_GAMEPAD=z,e.P_HAND_INPUT=U,e.P_HIT_TEST=oe,e.P_INPUT_SOURCE=k,e.P_JOINT_POSE=Y,e.P_JOINT_SPACE=ee,e.P_MESH=j,e.P_PLANE=W,e.P_POSE=Q,e.P_RAY=ne,e.P_REF_SPACE=te,e.P_RENDER_STATE=J,e.P_RIGID_TRANSFORM=K,e.P_SESSION=Z,e.P_SPACE=re,e.P_SYSTEM=q,e.P_TRACKED_INPUT=G,e.P_VIEW=ie,e.P_VIEWER_POSE=$,e.P_VIEWPORT=se,e.P_WEBGL_LAYER=H,e.RemoteControlInterface=_e,e.XRAnchor=ke,e.XRAnchorSet=He,e.XRCPUDepthInformation=qe,e.XRDevice=class{constructor(e,t={}){var r,s,n,a,o,l;this.version=Ut;const u=new le,d=new it(tt.Viewer,u),p={[rt.Left]:new he(d),[rt.Right]:new he(d),[rt.None]:new he(d)},f=e.controllerConfig,m={};f&&Object.values(Re).forEach(e=>{f.layout[e]&&(m[e]=new Ne(f,e,u))});const g={[Re.Left]:new Dt(Tt,Re.Left,u),[Re.Right]:new Dt(Tt,Re.Right,u)},v=null!==(r=t.canvasContainer)&&void 0!==r?r:document.createElement("div");v.dataset.webxr_runtime=`Immersive Web Emulation Runtime v${Ut}`,v.style.position="fixed",v.style.width="100%",v.style.height="100%",v.style.top="0",v.style.left="0",v.style.display="flex",v.style.justifyContent="center",v.style.alignItems="center",v.style.overflow="hidden",v.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:kr.headsetPosition.clone(),quaternion:null!==(n=t.headsetQuaternion)&&void 0!==n?n:kr.headsetQuaternion.clone(),stereoEnabled:null!==(a=t.stereoEnabled)&&void 0!==a?a:kr.stereoEnabled,ipd:null!==(o=t.ipd)&&void 0!==o?o:kr.ipd,fovy:null!==(l=t.fovy)&&void 0!==l?l:kr.fovy,controllers:m,hands:g,primaryInputMode:"controller",pendingReferenceSpaceReset:!1,visibilityState:"visible",pendingVisibilityState:null,xrSystem:null,matrix:i(),globalSpace:u,viewerSpace:d,viewSpaces:p,canvasContainer:v,getViewport:(e,t)=>{const r=e.context.canvas,{width:i,height:s}=r;switch(t.eye){case rt.None:return new zt(0,0,i,s);case rt.Left:return new zt(0,0,this[B].stereoEnabled?i/2:i,s);case rt.Right:return new zt(i/2,0,this[B].stereoEnabled?i/2:0,s)}},updateViews:()=>{c(this[B].viewerSpace[re].offsetMatrix,this[B].quaternion.quat,this[B].position.vec3),h(this[B].viewSpaces[rt.Left][re].offsetMatrix,x(-this[B].ipd/2,0,0)),h(this[B].viewSpaces[rt.Right][re].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 n=this[B].devui;n&&(this[B].canvasContainer.removeChild(n.devUICanvas),this[B].canvasContainer.removeChild(n.devUIContainer));const a=this[B].sem;a&&this[B].canvasContainer.removeChild(a.environmentCanvas),document.body.removeChild(this[B].canvasContainer),this[B].canvasData=void 0,window.dispatchEvent(new Event("resize"))}},onFrameStart:e=>{var t;const r=performance.now(),i=this[B].lastFrameTime>0?r-this[B].lastFrameTime:16.67;if(this[B].lastFrameTime=r,this[B].remote&&this[B].remote.update(i),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 nt("visibilitychange",{session:t}))),"visible"===this[B].visibilityState&&this.activeInputs.forEach(t=>{t.onFrameStart(e)}),this[B].pendingReferenceSpaceReset&&(t[Z].referenceSpaces.forEach(e=>{switch(e[te].type){case tt.Local:case tt.LocalFloor:case tt.BoundedFloor:case tt.Unbounded:e.dispatchEvent(new Gt("reset",{referenceSpace:e}))}}),this[B].pendingReferenceSpaceReset=!1)}this[B].updateViews()},controlMode:"manual",controlModeListeners:new Set,stateChangeListeners:new Set,remote:null,lastFrameTime:0},this[B].remote=new _e(this),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 Xt(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=Xt,r.XRSession=vt,r.XRRenderState=st,r.XRFrame=ft,r.XRSpace=he,r.XRReferenceSpace=it,r.XRJointSpace=wt,r.XRView=at,r.XRViewport=zt,r.XRRigidTransform=Ye,r.XRPose=ot,r.XRViewerPose=lt,r.XRJointPose=ht,r.XRInputSource=Ie,r.XRInputSourceArray=Fe,r.XRHand=yt,r.XRLayer=Nt,r.XRWebGLLayer=Vt,r.XRSessionEvent=nt,r.XRInputSourceEvent=Le,r.XRInputSourcesChangeEvent=Ze,r.XRReferenceSpaceEvent=Gt,i?new qr:(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 appCanvas(){var e;return null===(e=this[B].canvasData)||void 0===e?void 0:e.canvas}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:n}=t.offeredSessionConfig;t.offeredSessionConfig=void 0,e.requestSession(s,n).then(r).catch(i)}}recenter(){const e=new ue(-this.position.x,0,-this.position.z),t=new ue(0,0,-1).applyQuaternion(this.quaternion);t.y=0,t.normalize();const r=Math.atan2(t.x,-t.z),i=(new de).setFromAxisAngle(new ue(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}get remote(){return this[B].remote}get controlMode(){return this[B].controlMode}set controlMode(e){if("manual"!==e&&"programmatic"!==e)return void console.warn('control mode can only be "manual" or "programmatic"');this[B].controlMode!==e&&(this[B].controlMode=e,this[B].controlModeListeners.forEach(t=>t(e)))}onControlModeChange(e){return this[B].controlModeListeners.add(e),()=>{this[B].controlModeListeners.delete(e)}}onStateChange(e){return this[B].stateChangeListeners.add(e),()=>{this[B].stateChangeListeners.delete(e)}}notifyStateChange(){this[B].stateChangeListeners.forEach(e=>e())}},e.XRFrame=ft,e.XRHand=yt,e.XRInputSource=Ie,e.XRInputSourceArray=Fe,e.XRInputSourceEvent=Le,e.XRInputSourcesChangeEvent=Ze,e.XRJointPose=ht,e.XRJointSpace=wt,e.XRLayer=Nt,e.XRMesh=Oe,e.XRMeshSet=Ve,e.XRPlane=Xe,e.XRPlaneSet=ze,e.XRPose=ot,e.XRRay=$e,e.XRReferenceSpace=it,e.XRReferenceSpaceEvent=Gt,e.XRRenderState=st,e.XRRigidTransform=Ye,e.XRSession=vt,e.XRSessionEvent=nt,e.XRSpace=he,e.XRSystem=Xt,e.XRView=at,e.XRViewerPose=lt,e.XRViewport=zt,e.XRWebGLLayer=Vt,e.directionTo=ge,e.eulerToQuat=xe,e.lookRotation=ve,e.metaQuest2=Kr,e.metaQuest3=Zr,e.metaQuestPro=Jr,e.oculusQuest1=$r,e.quatToEuler=me,e.quatToObj=fe,e.vec3ToObj=pe,e.waitForCondition=ye,Object.defineProperty(e,"__esModule",{value:!0})});
|