@needle-tools/engine 3.10.1-beta → 3.10.2-beta

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.
@@ -3666,7 +3666,7 @@ Please change to:
3666
3666
  ${o}? : AssetReference;
3667
3667
 
3668
3668
  in script ${r}.ts
3669
- <a href="https://docs.needle.tools/serializable" target="_blank">documentation</a>`),console.warn(r,o,i[o],i);continue}}}}function Z8(i,e){for(const t of Object.keys(e)){const s=e[t];if(typeof s=="object"&&s!==null&&s!==void 0){const r=i[t];if(!r){wl&&console.log(t,"is undefined on",i);continue}for(const n of Object.keys(s))if(r[n]===void 0&&Xk(s[n])&&!Xk(r)){const o=$8(r,n);if(o&&(o?.writable===void 0||o?.writable===!1)&&o.set===void 0){wl&&console.warn('Property is not writable "'+n+'"',r,o,s[n],r[n]);continue}r[n]=s[n]}}}}function $8(i,e){for(;i;){const t=Object.getOwnPropertyDescriptor(i,e);if(t)return t;i=Object.getPrototypeOf(i)}}function Xk(i){switch(typeof i){case"number":case"string":case"boolean":return!0}return!1}function yC(i,e,t,s,r){let n=typeof e=="function"&&e.prototype===void 0,o=e;if(n)try{if(o=e?.call(e,r),n=!1,o==null)return}catch(h){console.error("Error in callback",h,i)}if(t.type=o,!n&&r instanceof o)return r;if(r&&typeof r=="object"&&W8(r)){if(r.__concreteInstance)return r.__concreteInstance;const h=r;if(!h.$serializedTypes&&o.prototype.$serializedTypes&&(h.$serializedTypes=o.prototype.$serializedTypes),h.$serializedTypes&&Ry(h,i,t),r&&o!==void 0)try{const d=new o;yr&&console.log("Create concrete instance for persistent asset",r,"instance:",d),wu(d,r),r.__concreteInstance=d,r=d}catch(d){console.error("Error creating instance or creating values on instance",d,r,o)}return r}if(s||(s={serializer:Ty.getSerializerForConstructor(o)}),Array.isArray(i)){const h=[];for(let d=0;d<i.length;d++){const p=i[d],f=yC(p,e,t,s,p);h.push(f)}return h}const a=s.serializer;if(a)return a.onDeserialize(i,t);let l;if(i&&(i.isMaterial||i.isTexture||i.isObject3D))l=i;else{if(i===void 0)return;if(i===null&&(o===It||o===Gt||o===xe||o===kn))return null;l=new o(...e9(i))}const c=l;return c.$serializedTypes&&Ry(c,i,t),l}function e9(i){if(Iy.length=0,typeof i=="object"&&i!==null&&i!==void 0)for(const e of Object.keys(i))Iy.push(i[e]);return Iy}const bC=Symbol("assigned component properties");function wu(i,e,t){var s;if(e==null||i==null)return;i[bC]=!0;const r=((s=i.constructor)==null?void 0:s.name)??"unknown";t?.registerDefinedKeys(r,i);for(const n of Object.keys(e)){const o=t9(i,n);typeof o?.value!="function"&&(!o||o.writable===!0||o?.set!==void 0)&&(i[n]=e[n])}delete i[bC]}function t9(i,e){let t;do t=Object.getOwnPropertyDescriptor(i,e);while(!t&&(i=Object.getPrototypeOf(i)));return t}const co=re("debuginput");class Py{constructor(e){u(this,"key"),u(this,"keyType"),u(this,"source"),this.key=e.key,this.keyType=e.type,this.source=e}}var Sa=(i=>(i.PointerDown="pointerdown",i.PointerUp="pointerup",i.PointerMove="pointermove",i.KeyDown="keydown",i.KeyUp="keyup",i.KeyPressed="keypress",i))(Sa||{}),Yk=(i=>(i.Mouse="mouse",i.Touch="touch",i))(Yk||{});class Jk extends EventTarget{constructor(e){super(),u(this,"_doubleClickTimeThreshold",.2),u(this,"_longPressTimeThreshold",1),u(this,"_specialCursorTrigger",0),u(this,"context"),u(this,"_pointerDown",[!1]),u(this,"_pointerUp",[!1]),u(this,"_pointerClick",[!1]),u(this,"_pointerDoubleClick",[!1]),u(this,"_pointerPressed",[!1]),u(this,"_pointerPositions",[new Y]),u(this,"_pointerPositionsLastFrame",[new Y]),u(this,"_pointerPositionsDelta",[new Y]),u(this,"_pointerPositionsRC",[new Y]),u(this,"_pointerPositionDown",[new Y]),u(this,"_pointerDownTime",[]),u(this,"_pointerUpTime",[]),u(this,"_pointerUpTimestamp",[]),u(this,"_pointerIds",[]),u(this,"_pointerTypes",[""]),u(this,"_mouseWheelChanged",[!1]),u(this,"_mouseWheelDeltaY",[0]),u(this,"_pointerEvent",[]),u(this,"_pointerUsed",[]),u(this,"onLostFocus",()=>{for(const t in this.keysPressed)this.keysPressed[t].pressed=!1}),u(this,"onEndOfFrame",()=>{for(let t=0;t<this._pointerUp.length;t++)this._pointerUp[t]=!1;for(let t=0;t<this._pointerDown.length;t++)this._pointerDown[t]=!1;for(let t=0;t<this._pointerClick.length;t++)this._pointerClick[t]=!1;for(let t=0;t<this._pointerDoubleClick.length;t++)this._pointerDoubleClick[t]=!1;for(const t of this._pointerPositionsDelta)t.set(0,0);for(let t=0;t<this._mouseWheelChanged.length;t++)this._mouseWheelChanged[t]=!1;for(let t=0;t<this._mouseWheelDeltaY.length;t++)this._mouseWheelDeltaY[t]=0}),u(this,"keysPressed",{}),u(this,"onKeyDown",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];s&&s.pressed||(this.keysPressed[t.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:t.key,code:t.code},this.onDispatchEvent("keydown",new Py(t)))}),u(this,"onKeyPressed",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];s&&(s.pressed=!0,s.frame=this.context.time.frameCount+1,this.onDispatchEvent("keypress",new Py(t)))}),u(this,"onKeyUp",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];s&&(s.pressed=!1,s.frame=this.context.time.frameCount+1,this.onDispatchEvent("keyup",new Py(t)))}),u(this,"onMouseWheel",t=>{if(this.canReceiveInput(t)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const s=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=s+t.deltaY}),u(this,"onTouchStart",t=>{if(!(t.changedTouches.length<=0)&&this.canReceiveInput(t)!==!1)for(let s=0;s<t.changedTouches.length;s++){const r=t.changedTouches[s],n=this.getPointerIndex(r.identifier);co&&cs(`touch start #${n}, identifier:${r.identifier}`);const o={button:n,clientX:r.clientX,clientY:r.clientY,pointerType:"touch",source:t};this.onDown(o)}}),u(this,"onTouchMove",t=>{if(!(t.changedTouches.length<=0))for(let s=0;s<t.changedTouches.length;s++){const r=t.changedTouches[s],n={button:this.getPointerIndex(r.identifier),clientX:r.clientX,clientY:r.clientY,pointerType:"touch",source:t};this.onMove(n)}}),u(this,"onTouchUp",t=>{if(!(t.changedTouches.length<=0))for(let s=0;s<t.changedTouches.length;s++){const r=t.changedTouches[s],n=this.getPointerIndex(r.identifier);if(!this.isNewEvent(t.timeStamp,n,this._pointerUpTimestamp))continue;co&&cs(`touch up #${n}, identifier:${r.identifier}`);const o={button:n,clientX:r.clientX,clientY:r.clientY,pointerType:"touch",source:t};this.onUp(o)}}),u(this,"onMouseDown",t=>{if(t.defaultPrevented||this.canReceiveInput(t)===!1)return;let s=t.button;this.onDown({button:s,clientX:t.clientX,clientY:t.clientY,pointerType:"mouse",source:t})}),u(this,"onMouseMove",t=>{if(t.defaultPrevented)return;const s={button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:"mouse",source:t,movementX:t.movementX,movementY:t.movementY};this.onMove(s)}),u(this,"onMouseUp",t=>{if(t.defaultPrevented)return;let s=t.button;this.isNewEvent(t.timeStamp,s,this._pointerUpTimestamp)&&this.onUp({button:s,clientX:t.clientX,clientY:t.clientY,pointerType:"mouse",source:t})}),this.context=e,this.context.post_render_callbacks.push(this.onEndOfFrame),window.addEventListener("touchstart",this.onTouchStart,!1),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchUp,!1),window.addEventListener("mousedown",this.onMouseDown,!1),window.addEventListener("mousemove",this.onMouseMove,!1),window.addEventListener("mouseup",this.onMouseUp,!1),window.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}setCursorPointer(){this._specialCursorTrigger+=1,this.context.domElement.style.cursor="pointer"}setCursorNormal(){this._specialCursorTrigger-=1,this._specialCursorTrigger=Math.max(0,this._specialCursorTrigger),this._specialCursorTrigger===0&&(this.context.domElement.style.cursor="default")}setPointerUsed(e,t=!0){if(e>=this._pointerUsed.length){if(e>=this._pointerIds.length)return;for(;this._pointerUsed.length<=e;)this._pointerUsed.push(!1)}this._pointerUsed[e]=t}getPointerUsed(e){return e>=this._pointerUsed.length?!1:this._pointerUsed[e]}getPointerPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&e++;return e}getPointerPosition(e){return e>=this._pointerPositions.length?null:this._pointerPositions[e]}getPointerPositionLastFrame(e){return e>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[e]}getPointerPositionDelta(e){return e>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[e]}getPointerPositionRC(e){return e>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[e]}getPointerDown(e){return e>=this._pointerDown.length?!1:this._pointerDown[e]}getPointerUp(e){return e>=this._pointerUp.length?!1:this._pointerUp[e]}getPointerPressed(e){return e>=this._pointerPressed.length?!1:this._pointerPressed[e]}getPointerClicked(e){return e>=this._pointerClick.length?!1:this._pointerClick[e]}getPointerDoubleClicked(e){return e>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[e]}getPointerDownTime(e){return e>=this._pointerDownTime.length?-1:this._pointerDownTime[e]}getPointerUpTime(e){return e>=this._pointerUpTime.length?-1:this._pointerUpTime[e]}getPointerLongPress(e){return e>=this._pointerDownTime.length?!1:this.getPointerPressed(e)&&this.context.time.time-this._pointerDownTime[e]>this._longPressTimeThreshold}getIsMouse(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="mouse"}getIsTouch(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="touch"}getTouchesPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&this.getIsTouch(t)&&e++;return e}getMouseWheelChanged(e=0){return e>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[e]}getMouseWheelDeltaY(e=0){return e>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[e]}getPointerEvent(e){if(!(e>=this._pointerEvent.length))return this._pointerEvent[e]??void 0}*foreachPointerId(e){for(let t=0;t<this._pointerTypes.length;t++)if(this._pointerIsActive(t)){if(e!==void 0){const s=this._pointerTypes[t];if(Array.isArray(e)){let r=!1;for(const n of e)if(s===n){r=!0;break}if(!r)continue}else if(e!==s)continue}yield t}}*foreachTouchId(){for(let e=0;e<this._pointerTypes.length;e++)this._pointerTypes[e]==="touch"&&this._pointerIsActive[e]&&(yield e)}_pointerIsActive(e){return e<0?!1:this._pointerPressed[e]||this._pointerDown[e]||this._pointerUp[e]}getKeyDown(){for(const e in this.keysPressed){const t=this.keysPressed[e];if(t.startFrame===this.context.time.frameCount)return t.key}return null}getKeyPressed(){for(const e in this.keysPressed){const t=this.keysPressed[e];if(t.pressed)return t.key}return null}isKeyDown(e){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const s=this.getCodeForCommonKeyName(e);if(s!==null){for(const r of s)if(this.isKeyDown(r))return!0;return!1}return((t=this.keysPressed[e])==null?void 0:t.startFrame)===this.context.time.frameCount&&this.keysPressed[e].pressed}isKeyUp(e){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const s=this.getCodeForCommonKeyName(e);if(s!==null){for(const r of s)if(this.isKeyUp(r))return!0;return!1}return((t=this.keysPressed[e])==null?void 0:t.frame)===this.context.time.frameCount&&!this.keysPressed[e].pressed}isKeyPressed(e){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const s=this.getCodeForCommonKeyName(e);if(s!==null){for(const r of s)if(this.isKeyPressed(r))return!0;return!1}return(t=this.keysPressed[e])==null?void 0:t.pressed}getCodeForCommonKeyName(e){if(e.length===1){if(e>="0"&&e<="9")return["Digit"+e];if(e>="a"&&e<="z")return["Key"+e.toUpperCase()];if(e==" ")return["Space"]}switch(e){case"Shift":return["ShiftLeft","ShiftRight"];case"Control":return["ControlLeft","ControlRight"];case"Alt":return["AltLeft","AltRight"]}return null}createPointerDown(e){co&&cs("Create Pointer down"),this.onDown(e)}createPointerMove(e){co&&cs("Create Pointer move"),this.onMove(e)}createPointerUp(e){co&&cs("Create Pointer up"),this.onUp(e)}convertScreenspaceToRaycastSpace(e){e.x=(e.x-this.context.domX)/this.context.domWidth*2-1,e.y=-((e.y-this.context.domY)/this.context.domHeight)*2+1}dispose(){const e=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);e>=0&&this.context.post_render_callbacks.splice(e,1),window.removeEventListener("touchstart",this.onTouchStart,!1),window.removeEventListener("touchmove",this.onTouchMove,!1),window.removeEventListener("touchend",this.onTouchUp,!1),window.removeEventListener("mousedown",this.onMouseDown,!1),window.removeEventListener("mousemove",this.onMouseMove,!1),window.removeEventListener("mouseup",this.onMouseUp,!1),window.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}canReceiveInput(e){return e.target===this.context.renderer.domElement||e.target===this.context.domElement}isNewEvent(e,t,s){for(;s.length<=t;)s.push(-1);return e===s[t]?!1:(s[t]=e,!0)}isInRect(e){if(this.context.isInXR)return!0;const t=this.context.domElement.getBoundingClientRect(),s=e.clientX,r=e.clientY,n=s>=t.x&&s<=t.right&&r>=t.y&&r<=t.bottom;return co&&!n&&console.log("Not in rect",t,s,r),n}onDown(e){var t;if(co&&console.log(e.pointerType,"DOWN",e.button),!!this.isInRect(e)){if(e.pointerType==="mouse"){const s=this._pointerUpTimestamp[e.button];if(s>0&&((t=e.source)==null?void 0:t.timeStamp)!==void 0){const r=s-e.source.timeStamp;if(r<30&&r>0){co&&console.log("Ignoring mouse.down for touch.up");return}}}for(this.setPointerState(e.button,this._pointerPressed,!0),this.setPointerState(e.button,this._pointerDown,!0),this.setPointerStateT(e.button,this._pointerEvent,e.source);e.button>=this._pointerTypes.length;)this._pointerTypes.push(e.pointerType);for(this._pointerTypes[e.button]=e.pointerType;e.button>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new Y);for(this._pointerPositionDown[e.button].set(e.clientX,e.clientY);e.button>=this._pointerPositions.length;)this._pointerPositions.push(new Y);this._pointerPositions[e.button].set(e.clientX,e.clientY),e.button>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[e.button]=this.context.time.time,this.updatePointerPosition(e),this.onDispatchEvent("pointerdown",e)}}onMove(e){const t=this.getPointerPressed(e.button);t===!1&&!this.isInRect(e)||e.pointerType==="touch"&&!t||(co&&console.log(e.pointerType,"MOVE",e.button),this.updatePointerPosition(e),this.setPointerStateT(e.button,this._pointerEvent,e.source),this.onDispatchEvent("pointermove",e))}onUp(e){var t;if(((t=this._pointerIds)==null?void 0:t.length)>=e.button&&(this._pointerIds[e.button]=-1),!this._pointerPressed[e.button]){co&&console.log(e.pointerType,"UP",e.button,"was not down");return}for(co&&console.log(e.pointerType,"UP",e.button),this.setPointerState(e.button,this._pointerPressed,!1),this.setPointerStateT(e.button,this._pointerEvent,e.source),this.setPointerState(e.button,this._pointerUp,!0);e.button>=this._pointerUsed.length;)this._pointerUsed.push(!1);if(this.setPointerState(e.button,this._pointerUsed,!1),this.updatePointerPosition(e),!this._pointerPositionDown[e.button]){co&&lo("Received pointer up event without matching down event for button: "+e.button),console.warn("Received pointer up event without matching down event for button: "+e.button);return}const s=e.clientX-this._pointerPositionDown[e.button].x,r=e.clientY-this._pointerPositionDown[e.button].y;if(e.button>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(s)<5&&Math.abs(r)<5){this.setPointerState(e.button,this._pointerClick,!0);const n=this._pointerUpTime[e.button],o=this.context.time.time-n;o<this._doubleClickTimeThreshold&&o>0&&this.setPointerState(e.button,this._pointerDoubleClick,!0)}this._pointerUpTime[e.button]=this.context.time.time,this.onDispatchEvent("pointerup",e)}updatePointerPosition(e){for(;e.button>=this._pointerPositions.length;)this._pointerPositions.push(new Y);for(;e.button>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new Y);for(;e.button>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new Y);const t=this._pointerPositionsLastFrame[e.button];t.copy(this._pointerPositions[e.button]);const s=this._pointerPositionsDelta[e.button],r=e.clientX-t.x,n=e.clientY-t.y;s.x+=r,s.y+=n,this._pointerPositions[e.button].x=e.clientX,this._pointerPositions[e.button].y=e.clientY;const o=e.clientX,a=e.clientY;for(;e.button>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new Y);const l=this._pointerPositionsRC[e.button];l.set(o,a),this.convertScreenspaceToRaycastSpace(l)}getPointerIndex(e){const t=this._pointerIds;let s=-1;for(let r=0;r<t.length;r++){if(t[r]===e)return r;s===-1&&t[r]===-1&&(s=r)}return s!==-1?(t[s]=e,s):(t.push(e),t.length-1)}setPointerState(e,t,s){for(;t.length<=e;)t.push(!1);t[e]=s}setPointerStateT(e,t,s){for(;t.length<=e;)t.push(null);t[e]=s}onDispatchEvent(e,t){const s=Lt.Current;try{Lt.Current=this.context;const r=new Event(e);wu(r,t),this.dispatchEvent(r)}finally{Lt.Current=s}}}class i9{constructor(){u(this,"Rad2Deg",180/Math.PI),u(this,"Deg2Rad",Math.PI/180),u(this,"Epsilon",1e-5)}random(){return Math.random()}clamp(e,t,s){return e<t?t:e>s?s:e}clamp01(e){return this.clamp(e,0,1)}lerp(e,t,s){return s=s<0?0:s,s=s>1?1:s,e+(t-e)*s}inverseLerp(e,t,s){return(s-e)/(t-e)}remap(e,t,s,r,n){return r+(n-r)*(e-t)/(s-t)}moveTowards(e,t,s){return e+=s,(s<0&&e<t||s>0&&e>t)&&(e=t),e}toDegrees(e){return e*180/Math.PI}toRadians(e){return e*Math.PI/180}tan(e){return Math.tan(e)}gammaToLinear(e){return Math.pow(e,2.2)}linearToGamma(e){return Math.pow(e,1/2.2)}}const et=new i9;function Kk(i,e,t){const s=i.length(),r=e.length(),n=et.lerp(s,r,t);return i.lerp(e,t).normalize().multiplyScalar(n)}const s9=new Ue().setFromAxisAngle(new S(0,1,0),Math.PI);function r9(i,e){i.lookAt(e),i.quaternion.multiply(s9)}const xC=new ga(()=>new S,100);function yt(i,e=null,t=!0){const s=e??xC.get();return i?i.parent?(t&&i.updateWorldMatrix(!0,!1),i.matrixWorldNeedsUpdate&&i.updateMatrixWorld(),s.setFromMatrixPosition(i.matrixWorld),s):s.copy(i.position):s.set(0,0,0)}function ts(i,e){if(!i)return;const t=xC.get();e!==t&&t.copy(e),(i?.parent??i).worldToLocal(t),i.position.set(t.x,t.y,t.z)}function vp(i,e,t,s){const r=xC.get();r.set(e,t,s),ts(i,r)}const By=new ga(()=>new Ue,100),Su=new Ue,_C=new Ue;function Rs(i,e=null){if(!i)return By.get().identity();const t=e??By.get();return i.parent?(i.getWorldQuaternion(t),t):t.copy(i.quaternion)}function ln(i,e){if(!i)return;e!==Su&&Su.copy(e);const t=Su,s=i?.parent;s?.getWorldQuaternion(_C),_C.invert();const r=_C.multiply(t);i.quaternion.set(r.x,r.y,r.z,r.w)}function Zk(i,e,t,s,r){Su.set(e,t,s,r),ln(i,Su)}const n9=new ga(()=>new S,100),o9=new S;function Ks(i,e=null){return e||(e=n9.get()),i?i.parent?(i.getWorldScale(e),e):e.copy(i.scale):e.set(0,0,0)}function wC(i,e){if(!i)return;if(!i.parent){i.scale.copy(e);return}const t=o9;i.parent.getWorldScale(t),i.scale.copy(e),i.scale.divide(t)}const a9=new S,$k=new Ue;function l9(i){return Rs(i,$k),a9.set(0,0,1).applyQuaternion($k)}const c9=new ga(()=>new S,100),eD=new Ue;function h9(i,e){return e||(e=c9.get().set(0,0,1)),Rs(i,eD),e.applyQuaternion(eD)}const tD=new Ys,iD=new Ys,u9=new S;function sD(i){const e=By.get();return i.getWorldQuaternion(e),iD.setFromQuaternion(e),iD}function rD(i,e){const t=By.get();ln(i,t.setFromEuler(e))}function ky(i){const e=sD(i),t=u9;return t.set(e.x,e.y,e.z),t.x=et.toDegrees(t.x),t.y=et.toDegrees(t.y),t.z=et.toDegrees(t.z),t}function nD(i,e){Dy(i,e.x,e.y,e.z,!0)}function Dy(i,e,t,s,r=!0){r&&(e=et.toRadians(e),t=et.toRadians(t),s=et.toRadians(s)),tD.set(e,t,s),Su.setFromEuler(tD),ln(i,Su)}function Oy(i,e=!0){i&&(e?function t(s){console.groupCollapsed((s.name?s.name:"(no name : "+s.type+")")+" %o",s),s.children.forEach(t),console.groupEnd()}(i):i.traverse(function(t){for(var s="|___",r=t;r.parent!==null;)s=" "+s,r=r.parent;console.log(s+t.name+" <"+t.type+">")}))}function oD(i){if(i){const e=i;return e.blendMode!==void 0&&e.clampWhenFinished!==void 0&&e.enabled!==void 0&&e.fadeIn!==void 0&&e.getClip!==void 0}return!1}const $m=class{static createBlitMaterial(i){return new kt({uniforms:{map:new Te(null)},vertexShader:this.vertex,fragmentShader:i})}static copyTexture(i,e){const t=e??this.blipMaterial;t.uniforms.map.value=i,t.needsUpdate=!0,t.uniformsNeedUpdate=!0;const s=this.mesh;s.material=t,s.frustumCulled=!1,this.scene.children.length=0,this.scene.add(s),this.renderer.setSize(i.image.width,i.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const r=new Gt(this.renderer.domElement);return r.name="Copy",r.needsUpdate=!0,r}static textureToCanvas(i,e){if(!i)return null;(e===!0||i.isCompressedTexture===!0)&&(i=aD(i));const t=i.image;if(p9(t)){const s=document.createElement("canvas");s.width=t.width,s.height=t.height;const r=s.getContext("2d");return r?(r.drawImage(t,0,0,t.width,t.height,0,0,s.width,s.height),s):(console.error("Failed getting canvas 2d context"),null)}return null}};let jo=$m;u(jo,"planeGeometry",new In(2,2,1,1)),u(jo,"renderer",new tp({antialias:!1})),u(jo,"perspectiveCam",new Xt),u(jo,"scene",new an),u(jo,"vertex",`
3669
+ <a href="https://docs.needle.tools/serializable" target="_blank">documentation</a>`),console.warn(r,o,i[o],i);continue}}}}function Z8(i,e){for(const t of Object.keys(e)){const s=e[t];if(typeof s=="object"&&s!==null&&s!==void 0){const r=i[t];if(!r){wl&&console.log(t,"is undefined on",i);continue}for(const n of Object.keys(s))if(r[n]===void 0&&Xk(s[n])&&!Xk(r)){const o=$8(r,n);if(o&&(o?.writable===void 0||o?.writable===!1)&&o.set===void 0){wl&&console.warn('Property is not writable "'+n+'"',r,o,s[n],r[n]);continue}r[n]=s[n]}}}}function $8(i,e){for(;i;){const t=Object.getOwnPropertyDescriptor(i,e);if(t)return t;i=Object.getPrototypeOf(i)}}function Xk(i){switch(typeof i){case"number":case"string":case"boolean":return!0}return!1}function yC(i,e,t,s,r){let n=typeof e=="function"&&e.prototype===void 0,o=e;if(n)try{if(o=e?.call(e,r),n=!1,o==null)return}catch(h){console.error("Error in callback",h,i)}if(t.type=o,!n&&r instanceof o)return r;if(r&&typeof r=="object"&&W8(r)){if(r.__concreteInstance)return r.__concreteInstance;const h=r;if(!h.$serializedTypes&&o.prototype.$serializedTypes&&(h.$serializedTypes=o.prototype.$serializedTypes),h.$serializedTypes&&Ry(h,i,t),r&&o!==void 0)try{const d=new o;yr&&console.log("Create concrete instance for persistent asset",r,"instance:",d),wu(d,r),r.__concreteInstance=d,r=d}catch(d){console.error("Error creating instance or creating values on instance",d,r,o)}return r}if(s||(s={serializer:Ty.getSerializerForConstructor(o)}),Array.isArray(i)){const h=[];for(let d=0;d<i.length;d++){const p=i[d],f=yC(p,e,t,s,p);h.push(f)}return h}const a=s.serializer;if(a)return a.onDeserialize(i,t);let l;if(i&&(i.isMaterial||i.isTexture||i.isObject3D))l=i;else{if(i===void 0)return;if(i===null&&(o===It||o===Gt||o===xe||o===kn))return null;l=new o(...e9(i))}const c=l;return c.$serializedTypes&&Ry(c,i,t),l}function e9(i){if(Iy.length=0,typeof i=="object"&&i!==null&&i!==void 0)for(const e of Object.keys(i))Iy.push(i[e]);return Iy}const bC=Symbol("assigned component properties");function wu(i,e,t){var s;if(e==null||i==null)return;i[bC]=!0;const r=((s=i.constructor)==null?void 0:s.name)??"unknown";t?.registerDefinedKeys(r,i);for(const n of Object.keys(e)){const o=t9(i,n);typeof o?.value!="function"&&(!o||o.writable===!0||o?.set!==void 0)&&(i[n]=e[n])}delete i[bC]}function t9(i,e){let t;do t=Object.getOwnPropertyDescriptor(i,e);while(!t&&(i=Object.getPrototypeOf(i)));return t}const co=re("debuginput");class Py{constructor(e){u(this,"key"),u(this,"keyType"),u(this,"source"),this.key=e.key,this.keyType=e.type,this.source=e}}var Sa=(i=>(i.PointerDown="pointerdown",i.PointerUp="pointerup",i.PointerMove="pointermove",i.KeyDown="keydown",i.KeyUp="keyup",i.KeyPressed="keypress",i))(Sa||{}),Yk=(i=>(i.Mouse="mouse",i.Touch="touch",i))(Yk||{});class Jk extends EventTarget{constructor(e){super(),u(this,"_doubleClickTimeThreshold",.2),u(this,"_longPressTimeThreshold",1),u(this,"_specialCursorTrigger",0),u(this,"context"),u(this,"_pointerDown",[!1]),u(this,"_pointerUp",[!1]),u(this,"_pointerClick",[!1]),u(this,"_pointerDoubleClick",[!1]),u(this,"_pointerPressed",[!1]),u(this,"_pointerPositions",[new Y]),u(this,"_pointerPositionsLastFrame",[new Y]),u(this,"_pointerPositionsDelta",[new Y]),u(this,"_pointerPositionsRC",[new Y]),u(this,"_pointerPositionDown",[new Y]),u(this,"_pointerDownTime",[]),u(this,"_pointerUpTime",[]),u(this,"_pointerUpTimestamp",[]),u(this,"_pointerIds",[]),u(this,"_pointerTypes",[""]),u(this,"_mouseWheelChanged",[!1]),u(this,"_mouseWheelDeltaY",[0]),u(this,"_pointerEvent",[]),u(this,"_pointerUsed",[]),u(this,"onLostFocus",()=>{for(const t in this.keysPressed)this.keysPressed[t].pressed=!1}),u(this,"onEndOfFrame",()=>{for(let t=0;t<this._pointerUp.length;t++)this._pointerUp[t]=!1;for(let t=0;t<this._pointerDown.length;t++)this._pointerDown[t]=!1;for(let t=0;t<this._pointerClick.length;t++)this._pointerClick[t]=!1;for(let t=0;t<this._pointerDoubleClick.length;t++)this._pointerDoubleClick[t]=!1;for(const t of this._pointerPositionsDelta)t.set(0,0);for(let t=0;t<this._mouseWheelChanged.length;t++)this._mouseWheelChanged[t]=!1;for(let t=0;t<this._mouseWheelDeltaY.length;t++)this._mouseWheelDeltaY[t]=0}),u(this,"keysPressed",{}),u(this,"onKeyDown",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];s&&s.pressed||(this.keysPressed[t.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:t.key,code:t.code},this.onDispatchEvent("keydown",new Py(t)))}),u(this,"onKeyPressed",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];s&&(s.pressed=!0,s.frame=this.context.time.frameCount+1,this.onDispatchEvent("keypress",new Py(t)))}),u(this,"onKeyUp",t=>{if(!this.context.application.hasFocus)return;const s=this.keysPressed[t.code];s&&(s.pressed=!1,s.frame=this.context.time.frameCount+1,this.onDispatchEvent("keyup",new Py(t)))}),u(this,"onMouseWheel",t=>{if(this.canReceiveInput(t)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const s=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=s+t.deltaY}),u(this,"onTouchStart",t=>{if(!(t.changedTouches.length<=0)&&this.canReceiveInput(t)!==!1)for(let s=0;s<t.changedTouches.length;s++){const r=t.changedTouches[s],n=this.getPointerIndex(r.identifier);co&&cs(`touch start #${n}, identifier:${r.identifier}`);const o={button:n,clientX:r.clientX,clientY:r.clientY,pointerType:"touch",source:t};this.onDown(o)}}),u(this,"onTouchMove",t=>{if(!(t.changedTouches.length<=0))for(let s=0;s<t.changedTouches.length;s++){const r=t.changedTouches[s],n={button:this.getPointerIndex(r.identifier),clientX:r.clientX,clientY:r.clientY,pointerType:"touch",source:t};this.onMove(n)}}),u(this,"onTouchUp",t=>{if(!(t.changedTouches.length<=0))for(let s=0;s<t.changedTouches.length;s++){const r=t.changedTouches[s],n=this.getPointerIndex(r.identifier);if(!this.isNewEvent(t.timeStamp,n,this._pointerUpTimestamp))continue;co&&cs(`touch up #${n}, identifier:${r.identifier}`);const o={button:n,clientX:r.clientX,clientY:r.clientY,pointerType:"touch",source:t};this.onUp(o)}}),u(this,"onMouseDown",t=>{if(t.defaultPrevented||this.canReceiveInput(t)===!1)return;let s=t.button;this.onDown({button:s,clientX:t.clientX,clientY:t.clientY,pointerType:"mouse",source:t})}),u(this,"onMouseMove",t=>{if(t.defaultPrevented)return;const s={button:t.button,clientX:t.clientX,clientY:t.clientY,pointerType:"mouse",source:t,movementX:t.movementX,movementY:t.movementY};this.onMove(s)}),u(this,"onMouseUp",t=>{if(t.defaultPrevented)return;let s=t.button;this.isNewEvent(t.timeStamp,s,this._pointerUpTimestamp)&&this.onUp({button:s,clientX:t.clientX,clientY:t.clientY,pointerType:"mouse",source:t})}),this.context=e,this.context.post_render_callbacks.push(this.onEndOfFrame),window.addEventListener("touchstart",this.onTouchStart,!1),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchUp,!1),window.addEventListener("mousedown",this.onMouseDown,!1),window.addEventListener("mousemove",this.onMouseMove,!1),window.addEventListener("mouseup",this.onMouseUp,!1),window.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}setCursorPointer(){this._specialCursorTrigger+=1,this.context.domElement.style.cursor="pointer"}setCursorNormal(){this._specialCursorTrigger-=1,this._specialCursorTrigger=Math.max(0,this._specialCursorTrigger),this._specialCursorTrigger===0&&(this.context.domElement.style.cursor="default")}setPointerUsed(e,t=!0){if(e>=this._pointerUsed.length){if(e>=this._pointerIds.length)return;for(;this._pointerUsed.length<=e;)this._pointerUsed.push(!1)}this._pointerUsed[e]=t}getPointerUsed(e){return e>=this._pointerUsed.length?!1:this._pointerUsed[e]}getPointerPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&e++;return e}getPointerPosition(e){return e>=this._pointerPositions.length?null:this._pointerPositions[e]}getPointerPositionLastFrame(e){return e>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[e]}getPointerPositionDelta(e){return e>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[e]}getPointerPositionRC(e){return e>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[e]}getPointerDown(e){return e>=this._pointerDown.length?!1:this._pointerDown[e]}getPointerUp(e){return e>=this._pointerUp.length?!1:this._pointerUp[e]}getPointerPressed(e){return e>=this._pointerPressed.length?!1:this._pointerPressed[e]}getPointerClicked(e){return e>=this._pointerClick.length?!1:this._pointerClick[e]}getPointerDoubleClicked(e){return e>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[e]}getPointerDownTime(e){return e>=this._pointerDownTime.length?-1:this._pointerDownTime[e]}getPointerUpTime(e){return e>=this._pointerUpTime.length?-1:this._pointerUpTime[e]}getPointerLongPress(e){return e>=this._pointerDownTime.length?!1:this.getPointerPressed(e)&&this.context.time.time-this._pointerDownTime[e]>this._longPressTimeThreshold}getIsMouse(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="mouse"}getIsTouch(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="touch"}getTouchesPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&this.getIsTouch(t)&&e++;return e}getMouseWheelChanged(e=0){return e>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[e]}getMouseWheelDeltaY(e=0){return e>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[e]}getPointerEvent(e){if(!(e>=this._pointerEvent.length))return this._pointerEvent[e]??void 0}*foreachPointerId(e){for(let t=0;t<this._pointerTypes.length;t++)if(this._pointerIsActive(t)){if(e!==void 0){const s=this._pointerTypes[t];if(Array.isArray(e)){let r=!1;for(const n of e)if(s===n){r=!0;break}if(!r)continue}else if(e!==s)continue}yield t}}*foreachTouchId(){for(let e=0;e<this._pointerTypes.length;e++)this._pointerTypes[e]==="touch"&&this._pointerIsActive[e]&&(yield e)}_pointerIsActive(e){return e<0?!1:this._pointerPressed[e]||this._pointerDown[e]||this._pointerUp[e]}getKeyDown(){for(const e in this.keysPressed){const t=this.keysPressed[e];if(t.startFrame===this.context.time.frameCount)return t.key}return null}getKeyPressed(){for(const e in this.keysPressed){const t=this.keysPressed[e];if(t.pressed)return t.key}return null}isKeyDown(e){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const s=this.getCodeForCommonKeyName(e);if(s!==null){for(const r of s)if(this.isKeyDown(r))return!0;return!1}return((t=this.keysPressed[e])==null?void 0:t.startFrame)===this.context.time.frameCount&&this.keysPressed[e].pressed}isKeyUp(e){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const s=this.getCodeForCommonKeyName(e);if(s!==null){for(const r of s)if(this.isKeyUp(r))return!0;return!1}return((t=this.keysPressed[e])==null?void 0:t.frame)===this.context.time.frameCount&&!this.keysPressed[e].pressed}isKeyPressed(e){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const s=this.getCodeForCommonKeyName(e);if(s!==null){for(const r of s)if(this.isKeyPressed(r))return!0;return!1}return(t=this.keysPressed[e])==null?void 0:t.pressed}getCodeForCommonKeyName(e){if(e.length===1){if(e>="0"&&e<="9")return["Digit"+e];if(e>="a"&&e<="z")return["Key"+e.toUpperCase()];if(e==" ")return["Space"]}switch(e){case"Shift":return["ShiftLeft","ShiftRight"];case"Control":return["ControlLeft","ControlRight"];case"Alt":return["AltLeft","AltRight"]}return null}createPointerDown(e){co&&cs("Create Pointer down"),this.onDown(e)}createPointerMove(e){co&&cs("Create Pointer move"),this.onMove(e)}createPointerUp(e){co&&cs("Create Pointer up"),this.onUp(e)}convertScreenspaceToRaycastSpace(e){e.x=(e.x-this.context.domX)/this.context.domWidth*2-1,e.y=-((e.y-this.context.domY)/this.context.domHeight)*2+1}dispose(){const e=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);e>=0&&this.context.post_render_callbacks.splice(e,1),window.removeEventListener("touchstart",this.onTouchStart,!1),window.removeEventListener("touchmove",this.onTouchMove,!1),window.removeEventListener("touchend",this.onTouchUp,!1),window.removeEventListener("mousedown",this.onMouseDown,!1),window.removeEventListener("mousemove",this.onMouseMove,!1),window.removeEventListener("mouseup",this.onMouseUp,!1),window.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}canReceiveInput(e){return e.target===this.context.renderer.domElement||e.target===this.context.domElement}isNewEvent(e,t,s){for(;s.length<=t;)s.push(-1);return e===s[t]?!1:(s[t]=e,!0)}isInRect(e){if(this.context.isInXR)return!0;const t=this.context.domElement.getBoundingClientRect(),s=e.clientX,r=e.clientY,n=s>=t.x&&s<=t.right&&r>=t.y&&r<=t.bottom;return co&&!n&&console.log("Not in rect",t,s,r),n}onDown(e){var t;if(co&&console.log(e.pointerType,"DOWN",e.button),!!this.isInRect(e)){if(e.pointerType==="mouse"){const s=this._pointerUpTimestamp[e.button];if(s>0&&((t=e.source)==null?void 0:t.timeStamp)!==void 0){const r=e.source.timeStamp-s;if(r<60&&r>=0){co&&console.log("Ignoring mouse.down for touch.up");return}}}for(this.setPointerState(e.button,this._pointerPressed,!0),this.setPointerState(e.button,this._pointerDown,!0),this.setPointerStateT(e.button,this._pointerEvent,e.source);e.button>=this._pointerTypes.length;)this._pointerTypes.push(e.pointerType);for(this._pointerTypes[e.button]=e.pointerType;e.button>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new Y);for(this._pointerPositionDown[e.button].set(e.clientX,e.clientY);e.button>=this._pointerPositions.length;)this._pointerPositions.push(new Y);this._pointerPositions[e.button].set(e.clientX,e.clientY),e.button>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[e.button]=this.context.time.time,this.updatePointerPosition(e),this.onDispatchEvent("pointerdown",e)}}onMove(e){const t=this.getPointerPressed(e.button);t===!1&&!this.isInRect(e)||e.pointerType==="touch"&&!t||(co&&console.log(e.pointerType,"MOVE",e.button),this.updatePointerPosition(e),this.setPointerStateT(e.button,this._pointerEvent,e.source),this.onDispatchEvent("pointermove",e))}onUp(e){var t;if(((t=this._pointerIds)==null?void 0:t.length)>=e.button&&(this._pointerIds[e.button]=-1),!this._pointerPressed[e.button]){co&&console.log(e.pointerType,"UP",e.button,"was not down");return}for(co&&console.log(e.pointerType,"UP",e.button),this.setPointerState(e.button,this._pointerPressed,!1),this.setPointerStateT(e.button,this._pointerEvent,e.source),this.setPointerState(e.button,this._pointerUp,!0);e.button>=this._pointerUsed.length;)this._pointerUsed.push(!1);if(this.setPointerState(e.button,this._pointerUsed,!1),this.updatePointerPosition(e),!this._pointerPositionDown[e.button]){co&&lo("Received pointer up event without matching down event for button: "+e.button),console.warn("Received pointer up event without matching down event for button: "+e.button);return}const s=e.clientX-this._pointerPositionDown[e.button].x,r=e.clientY-this._pointerPositionDown[e.button].y;if(e.button>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(s)<5&&Math.abs(r)<5){this.setPointerState(e.button,this._pointerClick,!0);const n=this._pointerUpTime[e.button],o=this.context.time.time-n;o<this._doubleClickTimeThreshold&&o>0&&this.setPointerState(e.button,this._pointerDoubleClick,!0)}this._pointerUpTime[e.button]=this.context.time.time,this.onDispatchEvent("pointerup",e)}updatePointerPosition(e){for(;e.button>=this._pointerPositions.length;)this._pointerPositions.push(new Y);for(;e.button>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new Y);for(;e.button>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new Y);const t=this._pointerPositionsLastFrame[e.button];t.copy(this._pointerPositions[e.button]);const s=this._pointerPositionsDelta[e.button],r=e.clientX-t.x,n=e.clientY-t.y;s.x+=r,s.y+=n,this._pointerPositions[e.button].x=e.clientX,this._pointerPositions[e.button].y=e.clientY;const o=e.clientX,a=e.clientY;for(;e.button>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new Y);const l=this._pointerPositionsRC[e.button];l.set(o,a),this.convertScreenspaceToRaycastSpace(l)}getPointerIndex(e){const t=this._pointerIds;let s=-1;for(let r=0;r<t.length;r++){if(t[r]===e)return r;s===-1&&t[r]===-1&&(s=r)}return s!==-1?(t[s]=e,s):(t.push(e),t.length-1)}setPointerState(e,t,s){for(;t.length<=e;)t.push(!1);t[e]=s}setPointerStateT(e,t,s){for(;t.length<=e;)t.push(null);t[e]=s}onDispatchEvent(e,t){const s=Lt.Current;try{Lt.Current=this.context;const r=new Event(e);wu(r,t),this.dispatchEvent(r)}finally{Lt.Current=s}}}class i9{constructor(){u(this,"Rad2Deg",180/Math.PI),u(this,"Deg2Rad",Math.PI/180),u(this,"Epsilon",1e-5)}random(){return Math.random()}clamp(e,t,s){return e<t?t:e>s?s:e}clamp01(e){return this.clamp(e,0,1)}lerp(e,t,s){return s=s<0?0:s,s=s>1?1:s,e+(t-e)*s}inverseLerp(e,t,s){return(s-e)/(t-e)}remap(e,t,s,r,n){return r+(n-r)*(e-t)/(s-t)}moveTowards(e,t,s){return e+=s,(s<0&&e<t||s>0&&e>t)&&(e=t),e}toDegrees(e){return e*180/Math.PI}toRadians(e){return e*Math.PI/180}tan(e){return Math.tan(e)}gammaToLinear(e){return Math.pow(e,2.2)}linearToGamma(e){return Math.pow(e,1/2.2)}}const et=new i9;function Kk(i,e,t){const s=i.length(),r=e.length(),n=et.lerp(s,r,t);return i.lerp(e,t).normalize().multiplyScalar(n)}const s9=new Ue().setFromAxisAngle(new S(0,1,0),Math.PI);function r9(i,e){i.lookAt(e),i.quaternion.multiply(s9)}const xC=new ga(()=>new S,100);function yt(i,e=null,t=!0){const s=e??xC.get();return i?i.parent?(t&&i.updateWorldMatrix(!0,!1),i.matrixWorldNeedsUpdate&&i.updateMatrixWorld(),s.setFromMatrixPosition(i.matrixWorld),s):s.copy(i.position):s.set(0,0,0)}function ts(i,e){if(!i)return;const t=xC.get();e!==t&&t.copy(e),(i?.parent??i).worldToLocal(t),i.position.set(t.x,t.y,t.z)}function vp(i,e,t,s){const r=xC.get();r.set(e,t,s),ts(i,r)}const By=new ga(()=>new Ue,100),Su=new Ue,_C=new Ue;function Rs(i,e=null){if(!i)return By.get().identity();const t=e??By.get();return i.parent?(i.getWorldQuaternion(t),t):t.copy(i.quaternion)}function ln(i,e){if(!i)return;e!==Su&&Su.copy(e);const t=Su,s=i?.parent;s?.getWorldQuaternion(_C),_C.invert();const r=_C.multiply(t);i.quaternion.set(r.x,r.y,r.z,r.w)}function Zk(i,e,t,s,r){Su.set(e,t,s,r),ln(i,Su)}const n9=new ga(()=>new S,100),o9=new S;function Ks(i,e=null){return e||(e=n9.get()),i?i.parent?(i.getWorldScale(e),e):e.copy(i.scale):e.set(0,0,0)}function wC(i,e){if(!i)return;if(!i.parent){i.scale.copy(e);return}const t=o9;i.parent.getWorldScale(t),i.scale.copy(e),i.scale.divide(t)}const a9=new S,$k=new Ue;function l9(i){return Rs(i,$k),a9.set(0,0,1).applyQuaternion($k)}const c9=new ga(()=>new S,100),eD=new Ue;function h9(i,e){return e||(e=c9.get().set(0,0,1)),Rs(i,eD),e.applyQuaternion(eD)}const tD=new Ys,iD=new Ys,u9=new S;function sD(i){const e=By.get();return i.getWorldQuaternion(e),iD.setFromQuaternion(e),iD}function rD(i,e){const t=By.get();ln(i,t.setFromEuler(e))}function ky(i){const e=sD(i),t=u9;return t.set(e.x,e.y,e.z),t.x=et.toDegrees(t.x),t.y=et.toDegrees(t.y),t.z=et.toDegrees(t.z),t}function nD(i,e){Dy(i,e.x,e.y,e.z,!0)}function Dy(i,e,t,s,r=!0){r&&(e=et.toRadians(e),t=et.toRadians(t),s=et.toRadians(s)),tD.set(e,t,s),Su.setFromEuler(tD),ln(i,Su)}function Oy(i,e=!0){i&&(e?function t(s){console.groupCollapsed((s.name?s.name:"(no name : "+s.type+")")+" %o",s),s.children.forEach(t),console.groupEnd()}(i):i.traverse(function(t){for(var s="|___",r=t;r.parent!==null;)s=" "+s,r=r.parent;console.log(s+t.name+" <"+t.type+">")}))}function oD(i){if(i){const e=i;return e.blendMode!==void 0&&e.clampWhenFinished!==void 0&&e.enabled!==void 0&&e.fadeIn!==void 0&&e.getClip!==void 0}return!1}const $m=class{static createBlitMaterial(i){return new kt({uniforms:{map:new Te(null)},vertexShader:this.vertex,fragmentShader:i})}static copyTexture(i,e){const t=e??this.blipMaterial;t.uniforms.map.value=i,t.needsUpdate=!0,t.uniformsNeedUpdate=!0;const s=this.mesh;s.material=t,s.frustumCulled=!1,this.scene.children.length=0,this.scene.add(s),this.renderer.setSize(i.image.width,i.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const r=new Gt(this.renderer.domElement);return r.name="Copy",r.needsUpdate=!0,r}static textureToCanvas(i,e){if(!i)return null;(e===!0||i.isCompressedTexture===!0)&&(i=aD(i));const t=i.image;if(p9(t)){const s=document.createElement("canvas");s.width=t.width,s.height=t.height;const r=s.getContext("2d");return r?(r.drawImage(t,0,0,t.width,t.height,0,0,s.width,s.height),s):(console.error("Failed getting canvas 2d context"),null)}return null}};let jo=$m;u(jo,"planeGeometry",new In(2,2,1,1)),u(jo,"renderer",new tp({antialias:!1})),u(jo,"perspectiveCam",new Xt),u(jo,"scene",new an),u(jo,"vertex",`
3670
3670
  varying vec2 vUv;
3671
3671
  void main(){
3672
3672
  vUv = uv;
@@ -4408,7 +4408,7 @@ Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
4408
4408
  version 0.6.9
4409
4409
  */var JU=function(i){return URL.createObjectURL(new Blob([i],{type:"text/javascript"}))};try{URL.revokeObjectURL(JU(""))}catch{JU=function(i){return"data:application/javascript;charset=UTF-8,"+encodeURI(i)}}var ps=Uint8Array,Nr=Uint16Array,Up=Uint32Array,Bb=new ps([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),kb=new ps([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),jE=new ps([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),KU=function(i,e){for(var t=new Nr(31),s=0;s<31;++s)t[s]=e+=1<<i[s-1];for(var r=new Up(t[30]),s=1;s<30;++s)for(var n=t[s];n<t[s+1];++n)r[n]=n-t[s]<<5|s;return[t,r]},ZU=KU(Bb,2),$U=ZU[0],GE=ZU[1];$U[28]=258,GE[258]=28;for(var eF=KU(kb,0),CJ=eF[0],tF=eF[1],HE=new Nr(32768),Ti=0;Ti<32768;++Ti){var sh=(Ti&43690)>>>1|(Ti&21845)<<1;sh=(sh&52428)>>>2|(sh&13107)<<2,sh=(sh&61680)>>>4|(sh&3855)<<4,HE[Ti]=((sh&65280)>>>8|(sh&255)<<8)>>>1}for(var Ra=function(i,e,t){for(var s=i.length,r=0,n=new Nr(e);r<s;++r)++n[i[r]-1];var o=new Nr(e);for(r=0;r<e;++r)o[r]=o[r-1]+n[r-1]<<1;var a;if(t){a=new Nr(1<<e);var l=15-e;for(r=0;r<s;++r)if(i[r])for(var c=r<<4|i[r],h=e-i[r],d=o[i[r]-1]++<<h,p=d|(1<<h)-1;d<=p;++d)a[HE[d]>>>l]=c}else for(a=new Nr(s),r=0;r<s;++r)i[r]&&(a[r]=HE[o[i[r]-1]++]>>>15-i[r]);return a},rh=new ps(288),Ti=0;Ti<144;++Ti)rh[Ti]=8;for(var Ti=144;Ti<256;++Ti)rh[Ti]=9;for(var Ti=256;Ti<280;++Ti)rh[Ti]=7;for(var Ti=280;Ti<288;++Ti)rh[Ti]=8;for(var Dg=new ps(32),Ti=0;Ti<32;++Ti)Dg[Ti]=5;var EJ=Ra(rh,9,0),MJ=Ra(rh,9,1),TJ=Ra(Dg,5,0),IJ=Ra(Dg,5,1),VE=function(i){for(var e=i[0],t=1;t<i.length;++t)i[t]>e&&(e=i[t]);return e},Yo=function(i,e,t){var s=e/8|0;return(i[s]|i[s+1]<<8)>>(e&7)&t},WE=function(i,e){var t=e/8|0;return(i[t]|i[t+1]<<8|i[t+2]<<16)>>(e&7)},qE=function(i){return(i/8|0)+(i&7&&1)},XE=function(i,e,t){(e==null||e<0)&&(e=0),(t==null||t>i.length)&&(t=i.length);var s=new(i instanceof Nr?Nr:i instanceof Up?Up:ps)(t-e);return s.set(i.subarray(e,t)),s},RJ=function(i,e,t){var s=i.length;if(!s||t&&!t.l&&s<5)return e||new ps(0);var r=!e||t,n=!t||t.i;t||(t={}),e||(e=new ps(s*3));var o=function(ze){var $e=e.length;if(ze>$e){var Je=new ps(Math.max($e*2,ze));Je.set(e),e=Je}},a=t.f||0,l=t.p||0,c=t.b||0,h=t.l,d=t.d,p=t.m,f=t.n,m=s*8;do{if(!h){t.f=a=Yo(i,l,1);var v=Yo(i,l+1,3);if(l+=3,v)if(v==1)h=MJ,d=IJ,p=9,f=5;else if(v==2){var A=Yo(i,l,31)+257,g=Yo(i,l+10,15)+4,b=A+Yo(i,l+5,31)+1;l+=14;for(var y=new ps(b),x=new ps(19),_=0;_<g;++_)x[jE[_]]=Yo(i,l+_*3,7);l+=g*3;for(var E=VE(x),I=(1<<E)-1,P=Ra(x,E,1),_=0;_<b;){var M=P[Yo(i,l,I)];l+=M&15;var C=M>>>4;if(C<16)y[_++]=C;else{var U=0,G=0;for(C==16?(G=3+Yo(i,l,3),l+=2,U=y[_-1]):C==17?(G=3+Yo(i,l,7),l+=3):C==18&&(G=11+Yo(i,l,127),l+=7);G--;)y[_++]=U}}var F=y.subarray(0,A),z=y.subarray(A);p=VE(F),f=VE(z),h=Ra(F,p,1),d=Ra(z,f,1)}else throw"invalid block type";else{var C=qE(l)+4,q=i[C-4]|i[C-3]<<8,te=C+q;if(te>s){if(n)throw"unexpected EOF";break}r&&o(c+q),e.set(i.subarray(C,te),c),t.b=c+=q,t.p=l=te*8;continue}if(l>m){if(n)throw"unexpected EOF";break}}r&&o(c+131072);for(var Z=(1<<p)-1,$=(1<<f)-1,he=l;;he=l){var U=h[WE(i,l)&Z],le=U>>>4;if(l+=U&15,l>m){if(n)throw"unexpected EOF";break}if(!U)throw"invalid length/literal";if(le<256)e[c++]=le;else if(le==256){he=l,h=null;break}else{var X=le-254;if(le>264){var _=le-257,ne=Bb[_];X=Yo(i,l,(1<<ne)-1)+$U[_],l+=ne}var _e=d[WE(i,l)&$],Ee=_e>>>4;if(!_e)throw"invalid distance";l+=_e&15;var z=CJ[Ee];if(Ee>3){var ne=kb[Ee];z+=WE(i,l)&(1<<ne)-1,l+=ne}if(l>m){if(n)throw"unexpected EOF";break}r&&o(c+131072);for(var Oe=c+X;c<Oe;c+=4)e[c]=e[c-z],e[c+1]=e[c+1-z],e[c+2]=e[c+2-z],e[c+3]=e[c+3-z];c=Oe}}t.l=h,t.p=he,t.b=c,h&&(a=1,t.m=p,t.d=d,t.n=f)}while(!a);return c==e.length?e:XE(e,0,c)},Ol=function(i,e,t){t<<=e&7;var s=e/8|0;i[s]|=t,i[s+1]|=t>>>8},Og=function(i,e,t){t<<=e&7;var s=e/8|0;i[s]|=t,i[s+1]|=t>>>8,i[s+2]|=t>>>16},YE=function(i,e){for(var t=[],s=0;s<i.length;++s)i[s]&&t.push({s,f:i[s]});var r=t.length,n=t.slice();if(!r)return[KE,0];if(r==1){var o=new ps(t[0].s+1);return o[t[0].s]=1,[o,1]}t.sort(function(_,E){return _.f-E.f}),t.push({s:-1,f:25001});var a=t[0],l=t[1],c=0,h=1,d=2;for(t[0]={s:-1,f:a.f+l.f,l:a,r:l};h!=r-1;)a=t[t[c].f<t[d].f?c++:d++],l=t[c!=h&&t[c].f<t[d].f?c++:d++],t[h++]={s:-1,f:a.f+l.f,l:a,r:l};for(var p=n[0].s,s=1;s<r;++s)n[s].s>p&&(p=n[s].s);var f=new Nr(p+1),m=JE(t[h-1],f,0);if(m>e){var s=0,v=0,A=m-e,g=1<<A;for(n.sort(function(E,I){return f[I.s]-f[E.s]||E.f-I.f});s<r;++s){var b=n[s].s;if(f[b]>e)v+=g-(1<<m-f[b]),f[b]=e;else break}for(v>>>=A;v>0;){var y=n[s].s;f[y]<e?v-=1<<e-f[y]++-1:++s}for(;s>=0&&v;--s){var x=n[s].s;f[x]==e&&(--f[x],++v)}m=e}return[new ps(f),m]},JE=function(i,e,t){return i.s==-1?Math.max(JE(i.l,e,t+1),JE(i.r,e,t+1)):e[i.s]=t},iF=function(i){for(var e=i.length;e&&!i[--e];);for(var t=new Nr(++e),s=0,r=i[0],n=1,o=function(l){t[s++]=l},a=1;a<=e;++a)if(i[a]==r&&a!=e)++n;else{if(!r&&n>2){for(;n>138;n-=138)o(32754);n>2&&(o(n>10?n-11<<5|28690:n-3<<5|12305),n=0)}else if(n>3){for(o(r),--n;n>6;n-=6)o(8304);n>2&&(o(n-3<<5|8208),n=0)}for(;n--;)o(r);n=1,r=i[a]}return[t.subarray(0,s),e]},Lg=function(i,e){for(var t=0,s=0;s<e.length;++s)t+=i[s]*e[s];return t},Db=function(i,e,t){var s=t.length,r=qE(e+2);i[r]=s&255,i[r+1]=s>>>8,i[r+2]=i[r]^255,i[r+3]=i[r+1]^255;for(var n=0;n<s;++n)i[r+n+4]=t[n];return(r+4+s)*8},sF=function(i,e,t,s,r,n,o,a,l,c,h){Ol(e,h++,t),++r[256];for(var d=YE(r,15),p=d[0],f=d[1],m=YE(n,15),v=m[0],A=m[1],g=iF(p),b=g[0],y=g[1],x=iF(v),_=x[0],E=x[1],I=new Nr(19),P=0;P<b.length;++P)I[b[P]&31]++;for(var P=0;P<_.length;++P)I[_[P]&31]++;for(var M=YE(I,7),C=M[0],U=M[1],G=19;G>4&&!C[jE[G-1]];--G);var F=c+5<<3,z=Lg(r,rh)+Lg(n,Dg)+o,q=Lg(r,p)+Lg(n,v)+o+14+3*G+Lg(I,C)+(2*I[16]+3*I[17]+7*I[18]);if(F<=z&&F<=q)return Db(e,h,i.subarray(l,l+c));var te,Z,$,he;if(Ol(e,h,1+(q<z)),h+=2,q<z){te=Ra(p,f,0),Z=p,$=Ra(v,A,0),he=v;var le=Ra(C,U,0);Ol(e,h,y-257),Ol(e,h+5,E-1),Ol(e,h+10,G-4),h+=14;for(var P=0;P<G;++P)Ol(e,h+3*P,C[jE[P]]);h+=3*G;for(var X=[b,_],ne=0;ne<2;++ne)for(var _e=X[ne],P=0;P<_e.length;++P){var Ee=_e[P]&31;Ol(e,h,le[Ee]),h+=C[Ee],Ee>15&&(Ol(e,h,_e[P]>>>5&127),h+=_e[P]>>>12)}}else te=EJ,Z=rh,$=TJ,he=Dg;for(var P=0;P<a;++P)if(s[P]>255){var Ee=s[P]>>>18&31;Og(e,h,te[Ee+257]),h+=Z[Ee+257],Ee>7&&(Ol(e,h,s[P]>>>23&31),h+=Bb[Ee]);var Oe=s[P]&31;Og(e,h,$[Oe]),h+=he[Oe],Oe>3&&(Og(e,h,s[P]>>>5&8191),h+=kb[Oe])}else Og(e,h,te[s[P]]),h+=Z[s[P]];return Og(e,h,te[256]),h+Z[256]},PJ=new Up([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),KE=new ps(0),BJ=function(i,e,t,s,r,n){var o=i.length,a=new ps(s+o+5*(1+Math.ceil(o/7e3))+r),l=a.subarray(s,a.length-r),c=0;if(!e||o<8)for(var h=0;h<=o;h+=65535){var d=h+65535;d<o?c=Db(l,c,i.subarray(h,d)):(l[h]=n,c=Db(l,c,i.subarray(h,o)))}else{for(var p=PJ[e-1],f=p>>>13,m=p&8191,v=(1<<t)-1,A=new Nr(32768),g=new Nr(v+1),b=Math.ceil(t/3),y=2*b,x=function(ye){return(i[ye]^i[ye+1]<<b^i[ye+2]<<y)&v},_=new Up(25e3),E=new Nr(288),I=new Nr(32),P=0,M=0,h=0,C=0,U=0,G=0;h<o;++h){var F=x(h),z=h&32767,q=g[F];if(A[z]=q,g[F]=z,U<=h){var te=o-h;if((P>7e3||C>24576)&&te>423){c=sF(i,l,0,_,E,I,M,C,G,h-G,c),C=P=M=0,G=h;for(var Z=0;Z<286;++Z)E[Z]=0;for(var Z=0;Z<30;++Z)I[Z]=0}var $=2,he=0,le=m,X=z-q&32767;if(te>2&&F==x(h-X))for(var ne=Math.min(f,te)-1,_e=Math.min(32767,h),Ee=Math.min(258,te);X<=_e&&--le&&z!=q;){if(i[h+$]==i[h+$-X]){for(var Oe=0;Oe<Ee&&i[h+Oe]==i[h+Oe-X];++Oe);if(Oe>$){if($=Oe,he=X,Oe>ne)break;for(var ze=Math.min(X,Oe-2),$e=0,Z=0;Z<ze;++Z){var Je=h-X+Z+32768&32767,qe=A[Je],xt=Je-qe+32768&32767;xt>$e&&($e=xt,q=Je)}}}z=q,q=A[z],X+=z-q+32768&32767}if(he){_[C++]=268435456|GE[$]<<18|tF[he];var pe=GE[$]&31,H=tF[he]&31;M+=Bb[pe]+kb[H],++E[257+pe],++I[H],U=h+$,++P}else _[C++]=i[h],++E[i[h]]}}c=sF(i,l,n,_,E,I,M,C,G,h-G,c),!n&&c&7&&(c=Db(l,c+1,KE))}return XE(a,0,s+qE(c)+r)},kJ=function(){for(var i=new Up(256),e=0;e<256;++e){for(var t=e,s=9;--s;)t=(t&1&&3988292384)^t>>>1;i[e]=t}return i}(),DJ=function(){var i=-1;return{p:function(e){for(var t=i,s=0;s<e.length;++s)t=kJ[t&255^e[s]]^t>>>8;i=t},d:function(){return~i}}},OJ=function(i,e,t,s,r){return BJ(i,e.level==null?6:e.level,e.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(i.length)))*1.5):12+e.mem,t,s,!r)},rF=function(i,e){var t={};for(var s in i)t[s]=i[s];for(var s in e)t[s]=e[s];return t},ir=function(i,e,t){for(;t;++e)i[e]=t,t>>>=8},LJ=function(i){if((i[0]&15)!=8||i[0]>>>4>7||(i[0]<<8|i[1])%31)throw"invalid zlib data";if(i[1]&32)throw"invalid zlib data: preset dictionaries not supported"};function UJ(i,e){return OJ(i,e||{},0,0)}function Ob(i,e){return RJ((LJ(i),i.subarray(2,-4)),e)}var nF=function(i,e,t,s){for(var r in i){var n=i[r],o=e+r;n instanceof ps?t[o]=[n,s]:Array.isArray(n)?t[o]=[n[0],rF(s,n[1])]:nF(n,o+"/",t,s)}},oF=typeof TextEncoder<"u"&&new TextEncoder,FJ=typeof TextDecoder<"u"&&new TextDecoder,NJ=0;try{FJ.decode(KE,{stream:!0}),NJ=1}catch{}function Lb(i,e){if(e){for(var t=new ps(i.length),s=0;s<i.length;++s)t[s]=i.charCodeAt(s);return t}if(oF)return oF.encode(i);for(var r=i.length,n=new ps(i.length+(i.length>>1)),o=0,a=function(d){n[o++]=d},s=0;s<r;++s){if(o+5>n.length){var l=new ps(o+8+(r-s<<1));l.set(n),n=l}var c=i.charCodeAt(s);c<128||e?a(c):c<2048?(a(192|c>>6),a(128|c&63)):c>55295&&c<57344?(c=65536+(c&1047552)|i.charCodeAt(++s)&1023,a(240|c>>18),a(128|c>>12&63),a(128|c>>6&63),a(128|c&63)):(a(224|c>>12),a(128|c>>6&63),a(128|c&63))}return XE(n,0,o)}var ZE=function(i){var e=0;if(i)for(var t in i){var s=i[t].length;if(s>65535)throw"extra field too long";e+=s+4}return e},aF=function(i,e,t,s,r,n,o,a){var l=s.length,c=t.extra,h=a&&a.length,d=ZE(c);ir(i,e,o!=null?33639248:67324752),e+=4,o!=null&&(i[e++]=20,i[e++]=t.os),i[e]=20,e+=2,i[e++]=t.flag<<1|(n==null&&8),i[e++]=r&&8,i[e++]=t.compression&255,i[e++]=t.compression>>8;var p=new Date(t.mtime==null?Date.now():t.mtime),f=p.getFullYear()-1980;if(f<0||f>119)throw"date not in range 1980-2099";if(ir(i,e,f<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>>1),e+=4,n!=null&&(ir(i,e,t.crc),ir(i,e+4,n),ir(i,e+8,t.size)),ir(i,e+12,l),ir(i,e+14,d),e+=16,o!=null&&(ir(i,e,h),ir(i,e+6,t.attrs),ir(i,e+10,o),e+=14),i.set(s,e),e+=l,d)for(var m in c){var v=c[m],A=v.length;ir(i,e,+m),ir(i,e+2,A),i.set(v,e+4),e+=4+A}return h&&(i.set(a,e),e+=h),e},zJ=function(i,e,t,s,r){ir(i,e,101010256),ir(i,e+8,t),ir(i,e+10,t),ir(i,e+12,s),ir(i,e+16,r)};function QJ(i,e){e||(e={});var t={},s=[];nF(i,"",t,e);var r=0,n=0;for(var o in t){var a=t[o],l=a[0],c=a[1],h=c.level==0?0:8,d=Lb(o),p=d.length,f=c.comment,m=f&&Lb(f),v=m&&m.length,A=ZE(c.extra);if(p>65535)throw"filename too long";var g=h?UJ(l,c):l,b=g.length,y=DJ();y.p(l),s.push(rF(c,{size:l.length,crc:y.d(),c:g,f:d,m,u:p!=o.length||m&&f.length!=v,o:r,compression:h})),r+=30+p+A+b,n+=76+2*(p+A)+(v||0)+b}for(var x=new ps(n+22),_=r,E=n-r,I=0;I<s.length;++I){var d=s[I];aF(x,d.o,d,d.f,d.u,d.c.length);var P=30+d.f.length+ZE(d.extra);x.set(d.c,d.o+P),aF(x,r,d,d.f,d.u,d.c.length,d.o,d.m),r+=16+P+(d.m?d.m.length:0)}return zJ(x,r,s.length,E,_),x}class $E extends YS{constructor(e){super(e),this.type=as}parse(e){const t=Math.pow(2.7182818,2.2);function s(T,k){let R=0;for(let N=0;N<65536;++N)(N==0||T[N>>3]&1<<(N&7))&&(k[R++]=N);const j=R-1;for(;R<65536;)k[R++]=0;return j}function r(T){for(let k=0;k<16384;k++)T[k]={},T[k].len=0,T[k].lit=0,T[k].p=null}const n={l:0,c:0,lc:0};function o(T,k,R,j,N){for(;R<T;)k=k<<8|H(j,N),R+=8;R-=T,n.l=k>>R&(1<<T)-1,n.c=k,n.lc=R}const a=new Array(59);function l(T){for(let R=0;R<=58;++R)a[R]=0;for(let R=0;R<65537;++R)a[T[R]]+=1;let k=0;for(let R=58;R>0;--R){const j=k+a[R]>>1;a[R]=k,k=j}for(let R=0;R<65537;++R){const j=T[R];j>0&&(T[R]=j|a[j]++<<6)}}function c(T,k,R,j,N,W){const ie=k;let Ce=0,ke=0;for(;j<=N;j++){if(ie.value-k.value>R)return!1;o(6,Ce,ke,T,ie);const we=n.l;if(Ce=n.c,ke=n.lc,W[j]=we,we==63){if(ie.value-k.value>R)throw new Error("Something wrong with hufUnpackEncTable");o(8,Ce,ke,T,ie);let Fe=n.l+6;if(Ce=n.c,ke=n.lc,j+Fe>N+1)throw new Error("Something wrong with hufUnpackEncTable");for(;Fe--;)W[j++]=0;j--}else if(we>=59){let Fe=we-59+2;if(j+Fe>N+1)throw new Error("Something wrong with hufUnpackEncTable");for(;Fe--;)W[j++]=0;j--}}l(W)}function h(T){return T&63}function d(T){return T>>6}function p(T,k,R,j){for(;k<=R;k++){const N=d(T[k]),W=h(T[k]);if(N>>W)throw new Error("Invalid table entry");if(W>14){const ie=j[N>>W-14];if(ie.len)throw new Error("Invalid table entry");if(ie.lit++,ie.p){const Ce=ie.p;ie.p=new Array(ie.lit);for(let ke=0;ke<ie.lit-1;++ke)ie.p[ke]=Ce[ke]}else ie.p=new Array(1);ie.p[ie.lit-1]=k}else if(W){let ie=0;for(let Ce=1<<14-W;Ce>0;Ce--){const ke=j[(N<<14-W)+ie];if(ke.len||ke.p)throw new Error("Invalid table entry");ke.len=W,ke.lit=k,ie++}}}return!0}const f={c:0,lc:0};function m(T,k,R,j){T=T<<8|H(R,j),k+=8,f.c=T,f.lc=k}const v={c:0,lc:0};function A(T,k,R,j,N,W,ie,Ce,ke){if(T==k){j<8&&(m(R,j,N,W),R=f.c,j=f.lc),j-=8;let we=R>>j;if(we=new Uint8Array([we])[0],Ce.value+we>ke)return!1;const Fe=ie[Ce.value-1];for(;we-- >0;)ie[Ce.value++]=Fe}else if(Ce.value<ke)ie[Ce.value++]=T;else return!1;v.c=R,v.lc=j}function g(T){return T&65535}function b(T){const k=g(T);return k>32767?k-65536:k}const y={a:0,b:0};function x(T,k){const R=b(T),j=b(k),N=R+(j&1)+(j>>1),W=N,ie=N-j;y.a=W,y.b=ie}function _(T,k){const R=g(T),j=g(k),N=R-(j>>1)&65535,W=j+N-32768&65535;y.a=W,y.b=N}function E(T,k,R,j,N,W,ie){const Ce=ie<16384,ke=R>N?N:R;let we=1,Fe,Ge;for(;we<=ke;)we<<=1;for(we>>=1,Fe=we,we>>=1;we>=1;){Ge=0;const Ke=Ge+W*(N-Fe),ot=W*we,Rt=W*Fe,lt=j*we,dt=j*Fe;let Bt,wi,xi,mr;for(;Ge<=Ke;Ge+=Rt){let vi=Ge;const Kt=Ge+j*(R-Fe);for(;vi<=Kt;vi+=dt){const Yi=vi+lt,O=vi+ot,se=O+lt;Ce?(x(T[vi+k],T[O+k]),Bt=y.a,xi=y.b,x(T[Yi+k],T[se+k]),wi=y.a,mr=y.b,x(Bt,wi),T[vi+k]=y.a,T[Yi+k]=y.b,x(xi,mr),T[O+k]=y.a,T[se+k]=y.b):(_(T[vi+k],T[O+k]),Bt=y.a,xi=y.b,_(T[Yi+k],T[se+k]),wi=y.a,mr=y.b,_(Bt,wi),T[vi+k]=y.a,T[Yi+k]=y.b,_(xi,mr),T[O+k]=y.a,T[se+k]=y.b)}if(R&we){const Yi=vi+ot;Ce?x(T[vi+k],T[Yi+k]):_(T[vi+k],T[Yi+k]),Bt=y.a,T[Yi+k]=y.b,T[vi+k]=Bt}}if(N&we){let vi=Ge;const Kt=Ge+j*(R-Fe);for(;vi<=Kt;vi+=dt){const Yi=vi+lt;Ce?x(T[vi+k],T[Yi+k]):_(T[vi+k],T[Yi+k]),Bt=y.a,T[Yi+k]=y.b,T[vi+k]=Bt}}Fe=we,we>>=1}return Ge}function I(T,k,R,j,N,W,ie,Ce,ke){let we=0,Fe=0;const Ge=ie,Ke=Math.trunc(j.value+(N+7)/8);for(;j.value<Ke;)for(m(we,Fe,R,j),we=f.c,Fe=f.lc;Fe>=14;){const Rt=we>>Fe-14&16383,lt=k[Rt];if(lt.len)Fe-=lt.len,A(lt.lit,W,we,Fe,R,j,Ce,ke,Ge),we=v.c,Fe=v.lc;else{if(!lt.p)throw new Error("hufDecode issues");let dt;for(dt=0;dt<lt.lit;dt++){const Bt=h(T[lt.p[dt]]);for(;Fe<Bt&&j.value<Ke;)m(we,Fe,R,j),we=f.c,Fe=f.lc;if(Fe>=Bt&&d(T[lt.p[dt]])==(we>>Fe-Bt&(1<<Bt)-1)){Fe-=Bt,A(lt.p[dt],W,we,Fe,R,j,Ce,ke,Ge),we=v.c,Fe=v.lc;break}}if(dt==lt.lit)throw new Error("hufDecode issues")}}const ot=8-N&7;for(we>>=ot,Fe-=ot;Fe>0;){const Rt=k[we<<14-Fe&16383];if(Rt.len)Fe-=Rt.len,A(Rt.lit,W,we,Fe,R,j,Ce,ke,Ge),we=v.c,Fe=v.lc;else throw new Error("hufDecode issues")}return!0}function P(T,k,R,j,N,W){const ie={value:0},Ce=R.value,ke=pe(k,R),we=pe(k,R);R.value+=4;const Fe=pe(k,R);if(R.value+=4,ke<0||ke>=65537||we<0||we>=65537)throw new Error("Something wrong with HUF_ENCSIZE");const Ge=new Array(65537),Ke=new Array(16384);r(Ke);const ot=j-(R.value-Ce);if(c(T,R,ot,ke,we,Ge),Fe>8*(j-(R.value-Ce)))throw new Error("Something wrong with hufUncompress");p(Ge,ke,we,Ke),I(Ge,Ke,T,R,Fe,we,W,N,ie)}function M(T,k,R){for(let j=0;j<R;++j)k[j]=T[k[j]]}function C(T){for(let k=1;k<T.length;k++){const R=T[k-1]+T[k]-128;T[k]=R}}function U(T,k){let R=0,j=Math.floor((T.length+1)/2),N=0;const W=T.length-1;for(;!(N>W||(k[N++]=T[R++],N>W));)k[N++]=T[j++]}function G(T){let k=T.byteLength;const R=new Array;let j=0;const N=new DataView(T);for(;k>0;){const W=N.getInt8(j++);if(W<0){const ie=-W;k-=ie+1;for(let Ce=0;Ce<ie;Ce++)R.push(N.getUint8(j++))}else{const ie=W;k-=2;const Ce=N.getUint8(j++);for(let ke=0;ke<ie+1;ke++)R.push(Ce)}}return R}function F(T,k,R,j,N,W){let ie=new DataView(W.buffer);const Ce=R[T.idx[0]].width,ke=R[T.idx[0]].height,we=3,Fe=Math.floor(Ce/8),Ge=Math.ceil(Ce/8),Ke=Math.ceil(ke/8),ot=Ce-(Ge-1)*8,Rt=ke-(Ke-1)*8,lt={value:0},dt=new Array(we),Bt=new Array(we),wi=new Array(we),xi=new Array(we),mr=new Array(we);for(let Kt=0;Kt<we;++Kt)mr[Kt]=k[T.idx[Kt]],dt[Kt]=Kt<1?0:dt[Kt-1]+Ge*Ke,Bt[Kt]=new Float32Array(64),wi[Kt]=new Uint16Array(64),xi[Kt]=new Uint16Array(Ge*64);for(let Kt=0;Kt<Ke;++Kt){let Yi=8;Kt==Ke-1&&(Yi=Rt);let O=8;for(let oe=0;oe<Ge;++oe){oe==Ge-1&&(O=ot);for(let J=0;J<we;++J)wi[J].fill(0),wi[J][0]=N[dt[J]++],z(lt,j,wi[J]),q(wi[J],Bt[J]),te(Bt[J]);Z(Bt);for(let J=0;J<we;++J)$(Bt[J],xi[J],oe*64)}let se=0;for(let oe=0;oe<we;++oe){const J=R[T.idx[oe]].type;for(let fe=8*Kt;fe<8*Kt+Yi;++fe){se=mr[oe][fe];for(let He=0;He<Fe;++He){const ut=He*64+(fe&7)*8;ie.setUint16(se+0*2*J,xi[oe][ut+0],!0),ie.setUint16(se+1*2*J,xi[oe][ut+1],!0),ie.setUint16(se+2*2*J,xi[oe][ut+2],!0),ie.setUint16(se+3*2*J,xi[oe][ut+3],!0),ie.setUint16(se+4*2*J,xi[oe][ut+4],!0),ie.setUint16(se+5*2*J,xi[oe][ut+5],!0),ie.setUint16(se+6*2*J,xi[oe][ut+6],!0),ie.setUint16(se+7*2*J,xi[oe][ut+7],!0),se+=8*2*J}}if(Fe!=Ge)for(let fe=8*Kt;fe<8*Kt+Yi;++fe){const He=mr[oe][fe]+8*Fe*2*J,ut=Fe*64+(fe&7)*8;for(let _t=0;_t<O;++_t)ie.setUint16(He+_t*2*J,xi[oe][ut+_t],!0)}}}const vi=new Uint16Array(Ce);ie=new DataView(W.buffer);for(let Kt=0;Kt<we;++Kt){R[T.idx[Kt]].decoded=!0;const Yi=R[T.idx[Kt]].type;if(R[Kt].type==2)for(let O=0;O<ke;++O){const se=mr[Kt][O];for(let oe=0;oe<Ce;++oe)vi[oe]=ie.getUint16(se+oe*2*Yi,!0);for(let oe=0;oe<Ce;++oe)ie.setFloat32(se+oe*2*Yi,me(vi[oe]),!0)}}}function z(T,k,R){let j,N=1;for(;N<64;)j=k[T.value],j==65280?N=64:j>>8==255?N+=j&255:(R[N]=j,N++),T.value++}function q(T,k){k[0]=me(T[0]),k[1]=me(T[1]),k[2]=me(T[5]),k[3]=me(T[6]),k[4]=me(T[14]),k[5]=me(T[15]),k[6]=me(T[27]),k[7]=me(T[28]),k[8]=me(T[2]),k[9]=me(T[4]),k[10]=me(T[7]),k[11]=me(T[13]),k[12]=me(T[16]),k[13]=me(T[26]),k[14]=me(T[29]),k[15]=me(T[42]),k[16]=me(T[3]),k[17]=me(T[8]),k[18]=me(T[12]),k[19]=me(T[17]),k[20]=me(T[25]),k[21]=me(T[30]),k[22]=me(T[41]),k[23]=me(T[43]),k[24]=me(T[9]),k[25]=me(T[11]),k[26]=me(T[18]),k[27]=me(T[24]),k[28]=me(T[31]),k[29]=me(T[40]),k[30]=me(T[44]),k[31]=me(T[53]),k[32]=me(T[10]),k[33]=me(T[19]),k[34]=me(T[23]),k[35]=me(T[32]),k[36]=me(T[39]),k[37]=me(T[45]),k[38]=me(T[52]),k[39]=me(T[54]),k[40]=me(T[20]),k[41]=me(T[22]),k[42]=me(T[33]),k[43]=me(T[38]),k[44]=me(T[46]),k[45]=me(T[51]),k[46]=me(T[55]),k[47]=me(T[60]),k[48]=me(T[21]),k[49]=me(T[34]),k[50]=me(T[37]),k[51]=me(T[47]),k[52]=me(T[50]),k[53]=me(T[56]),k[54]=me(T[59]),k[55]=me(T[61]),k[56]=me(T[35]),k[57]=me(T[36]),k[58]=me(T[48]),k[59]=me(T[49]),k[60]=me(T[57]),k[61]=me(T[58]),k[62]=me(T[62]),k[63]=me(T[63])}function te(T){const k=.5*Math.cos(.7853975),R=.5*Math.cos(3.14159/16),j=.5*Math.cos(3.14159/8),N=.5*Math.cos(3*3.14159/16),W=.5*Math.cos(5*3.14159/16),ie=.5*Math.cos(3*3.14159/8),Ce=.5*Math.cos(7*3.14159/16),ke=new Array(4),we=new Array(4),Fe=new Array(4),Ge=new Array(4);for(let Ke=0;Ke<8;++Ke){const ot=Ke*8;ke[0]=j*T[ot+2],ke[1]=ie*T[ot+2],ke[2]=j*T[ot+6],ke[3]=ie*T[ot+6],we[0]=R*T[ot+1]+N*T[ot+3]+W*T[ot+5]+Ce*T[ot+7],we[1]=N*T[ot+1]-Ce*T[ot+3]-R*T[ot+5]-W*T[ot+7],we[2]=W*T[ot+1]-R*T[ot+3]+Ce*T[ot+5]+N*T[ot+7],we[3]=Ce*T[ot+1]-W*T[ot+3]+N*T[ot+5]-R*T[ot+7],Fe[0]=k*(T[ot+0]+T[ot+4]),Fe[3]=k*(T[ot+0]-T[ot+4]),Fe[1]=ke[0]+ke[3],Fe[2]=ke[1]-ke[2],Ge[0]=Fe[0]+Fe[1],Ge[1]=Fe[3]+Fe[2],Ge[2]=Fe[3]-Fe[2],Ge[3]=Fe[0]-Fe[1],T[ot+0]=Ge[0]+we[0],T[ot+1]=Ge[1]+we[1],T[ot+2]=Ge[2]+we[2],T[ot+3]=Ge[3]+we[3],T[ot+4]=Ge[3]-we[3],T[ot+5]=Ge[2]-we[2],T[ot+6]=Ge[1]-we[1],T[ot+7]=Ge[0]-we[0]}for(let Ke=0;Ke<8;++Ke)ke[0]=j*T[16+Ke],ke[1]=ie*T[16+Ke],ke[2]=j*T[48+Ke],ke[3]=ie*T[48+Ke],we[0]=R*T[8+Ke]+N*T[24+Ke]+W*T[40+Ke]+Ce*T[56+Ke],we[1]=N*T[8+Ke]-Ce*T[24+Ke]-R*T[40+Ke]-W*T[56+Ke],we[2]=W*T[8+Ke]-R*T[24+Ke]+Ce*T[40+Ke]+N*T[56+Ke],we[3]=Ce*T[8+Ke]-W*T[24+Ke]+N*T[40+Ke]-R*T[56+Ke],Fe[0]=k*(T[Ke]+T[32+Ke]),Fe[3]=k*(T[Ke]-T[32+Ke]),Fe[1]=ke[0]+ke[3],Fe[2]=ke[1]-ke[2],Ge[0]=Fe[0]+Fe[1],Ge[1]=Fe[3]+Fe[2],Ge[2]=Fe[3]-Fe[2],Ge[3]=Fe[0]-Fe[1],T[0+Ke]=Ge[0]+we[0],T[8+Ke]=Ge[1]+we[1],T[16+Ke]=Ge[2]+we[2],T[24+Ke]=Ge[3]+we[3],T[32+Ke]=Ge[3]-we[3],T[40+Ke]=Ge[2]-we[2],T[48+Ke]=Ge[1]-we[1],T[56+Ke]=Ge[0]-we[0]}function Z(T){for(let k=0;k<64;++k){const R=T[0][k],j=T[1][k],N=T[2][k];T[0][k]=R+1.5747*N,T[1][k]=R-.1873*j-.4682*N,T[2][k]=R+1.8556*j}}function $(T,k,R){for(let j=0;j<64;++j)k[R+j]=ou.toHalfFloat(he(T[j]))}function he(T){return T<=1?Math.sign(T)*Math.pow(Math.abs(T),2.2):Math.sign(T)*Math.pow(t,Math.abs(T)-1)}function le(T){return new DataView(T.array.buffer,T.offset.value,T.size)}function X(T){const k=T.viewer.buffer.slice(T.offset.value,T.offset.value+T.size),R=new Uint8Array(G(k)),j=new Uint8Array(R.length);return C(R),U(R,j),new DataView(j.buffer)}function ne(T){const k=T.array.slice(T.offset.value,T.offset.value+T.size),R=Ob(k),j=new Uint8Array(R.length);return C(R),U(R,j),new DataView(j.buffer)}function _e(T){const k=T.viewer,R={value:T.offset.value},j=new Uint16Array(T.width*T.scanlineBlockSize*(T.channels*T.type)),N=new Uint8Array(8192);let W=0;const ie=new Array(T.channels);for(let Rt=0;Rt<T.channels;Rt++)ie[Rt]={},ie[Rt].start=W,ie[Rt].end=ie[Rt].start,ie[Rt].nx=T.width,ie[Rt].ny=T.lines,ie[Rt].size=T.type,W+=ie[Rt].nx*ie[Rt].ny*ie[Rt].size;const Ce=Ye(k,R),ke=Ye(k,R);if(ke>=8192)throw new Error("Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(Ce<=ke)for(let Rt=0;Rt<ke-Ce+1;Rt++)N[Rt+Ce]=Le(k,R);const we=new Uint16Array(65536),Fe=s(N,we),Ge=pe(k,R);P(T.array,k,R,Ge,j,W);for(let Rt=0;Rt<T.channels;++Rt){const lt=ie[Rt];for(let dt=0;dt<ie[Rt].size;++dt)E(j,lt.start+dt,lt.nx,lt.size,lt.ny,lt.nx*lt.size,Fe)}M(we,j,W);let Ke=0;const ot=new Uint8Array(j.buffer.byteLength);for(let Rt=0;Rt<T.lines;Rt++)for(let lt=0;lt<T.channels;lt++){const dt=ie[lt],Bt=dt.nx*dt.size,wi=new Uint8Array(j.buffer,dt.end*2,Bt*2);ot.set(wi,Ke),Ke+=Bt*2,dt.end+=Bt}return new DataView(ot.buffer)}function Ee(T){const k=T.array.slice(T.offset.value,T.offset.value+T.size),R=Ob(k),j=T.lines*T.channels*T.width,N=T.type==1?new Uint16Array(j):new Uint32Array(j);let W=0,ie=0;const Ce=new Array(4);for(let ke=0;ke<T.lines;ke++)for(let we=0;we<T.channels;we++){let Fe=0;switch(T.type){case 1:Ce[0]=W,Ce[1]=Ce[0]+T.width,W=Ce[1]+T.width;for(let Ge=0;Ge<T.width;++Ge){const Ke=R[Ce[0]++]<<8|R[Ce[1]++];Fe+=Ke,N[ie]=Fe,ie++}break;case 2:Ce[0]=W,Ce[1]=Ce[0]+T.width,Ce[2]=Ce[1]+T.width,W=Ce[2]+T.width;for(let Ge=0;Ge<T.width;++Ge){const Ke=R[Ce[0]++]<<24|R[Ce[1]++]<<16|R[Ce[2]++]<<8;Fe+=Ke,N[ie]=Fe,ie++}break}}return new DataView(N.buffer)}function Oe(T){const k=T.viewer,R={value:T.offset.value},j=new Uint8Array(T.width*T.lines*(T.channels*T.type*2)),N={version:ye(k,R),unknownUncompressedSize:ye(k,R),unknownCompressedSize:ye(k,R),acCompressedSize:ye(k,R),dcCompressedSize:ye(k,R),rleCompressedSize:ye(k,R),rleUncompressedSize:ye(k,R),rleRawSize:ye(k,R),totalAcUncompressedCount:ye(k,R),totalDcUncompressedCount:ye(k,R),acCompression:ye(k,R)};if(N.version<2)throw new Error("EXRLoader.parse: "+Xe.compression+" version "+N.version+" is unsupported");const W=new Array;let ie=Ye(k,R)-2;for(;ie>0;){const lt=ze(k.buffer,R),dt=Le(k,R),Bt=dt>>2&3,wi=(dt>>4)-1,xi=new Int8Array([wi])[0],mr=Le(k,R);W.push({name:lt,index:xi,type:mr,compression:Bt}),ie-=lt.length+3}const Ce=Xe.channels,ke=new Array(T.channels);for(let lt=0;lt<T.channels;++lt){const dt=ke[lt]={},Bt=Ce[lt];dt.name=Bt.name,dt.compression=0,dt.decoded=!1,dt.type=Bt.pixelType,dt.pLinear=Bt.pLinear,dt.width=T.width,dt.height=T.lines}const we={idx:new Array(3)};for(let lt=0;lt<T.channels;++lt){const dt=ke[lt];for(let Bt=0;Bt<W.length;++Bt){const wi=W[Bt];dt.name==wi.name&&(dt.compression=wi.compression,wi.index>=0&&(we.idx[wi.index]=lt),dt.offset=lt)}}let Fe,Ge,Ke;if(N.acCompressedSize>0)switch(N.acCompression){case 0:Fe=new Uint16Array(N.totalAcUncompressedCount),P(T.array,k,R,N.acCompressedSize,Fe,N.totalAcUncompressedCount);break;case 1:const lt=T.array.slice(R.value,R.value+N.totalAcUncompressedCount),dt=Ob(lt);Fe=new Uint16Array(dt.buffer),R.value+=N.totalAcUncompressedCount;break}if(N.dcCompressedSize>0){const lt={array:T.array,offset:R,size:N.dcCompressedSize};Ge=new Uint16Array(ne(lt).buffer),R.value+=N.dcCompressedSize}if(N.rleRawSize>0){const lt=T.array.slice(R.value,R.value+N.rleCompressedSize),dt=Ob(lt);Ke=G(dt.buffer),R.value+=N.rleCompressedSize}let ot=0;const Rt=new Array(ke.length);for(let lt=0;lt<Rt.length;++lt)Rt[lt]=new Array;for(let lt=0;lt<T.lines;++lt)for(let dt=0;dt<ke.length;++dt)Rt[dt].push(ot),ot+=ke[dt].width*T.type*2;F(we,Rt,ke,Fe,Ge,j);for(let lt=0;lt<ke.length;++lt){const dt=ke[lt];if(!dt.decoded)switch(dt.compression){case 2:let Bt=0,wi=0;for(let xi=0;xi<T.lines;++xi){let mr=Rt[lt][Bt];for(let vi=0;vi<dt.width;++vi){for(let Kt=0;Kt<2*dt.type;++Kt)j[mr++]=Ke[wi+Kt*dt.width*dt.height];wi++}Bt++}break;case 1:default:throw new Error("EXRLoader.parse: unsupported channel compression")}}return new DataView(j.buffer)}function ze(T,k){const R=new Uint8Array(T);let j=0;for(;R[k.value+j]!=0;)j+=1;const N=new TextDecoder().decode(R.slice(k.value,k.value+j));return k.value=k.value+j+1,N}function $e(T,k,R){const j=new TextDecoder().decode(new Uint8Array(T).slice(k.value,k.value+R));return k.value=k.value+R,j}function Je(T,k){const R=xt(T,k),j=pe(T,k);return[R,j]}function qe(T,k){const R=pe(T,k),j=pe(T,k);return[R,j]}function xt(T,k){const R=T.getInt32(k.value,!0);return k.value=k.value+4,R}function pe(T,k){const R=T.getUint32(k.value,!0);return k.value=k.value+4,R}function H(T,k){const R=T[k.value];return k.value=k.value+1,R}function Le(T,k){const R=T.getUint8(k.value);return k.value=k.value+1,R}const ye=function(T,k){let R;return"getBigInt64"in DataView.prototype?R=Number(T.getBigInt64(k.value,!0)):R=T.getUint32(k.value+4,!0)+Number(T.getUint32(k.value,!0)<<32),k.value+=8,R};function ge(T,k){const R=T.getFloat32(k.value,!0);return k.value+=4,R}function Qe(T,k){return ou.toHalfFloat(ge(T,k))}function me(T){const k=(T&31744)>>10,R=T&1023;return(T>>15?-1:1)*(k?k===31?R?NaN:1/0:Math.pow(2,k-15)*(1+R/1024):6103515625e-14*(R/1024))}function Ye(T,k){const R=T.getUint16(k.value,!0);return k.value+=2,R}function it(T,k){return me(Ye(T,k))}function ht(T,k,R,j){const N=R.value,W=[];for(;R.value<N+j-1;){const ie=ze(k,R),Ce=xt(T,R),ke=Le(T,R);R.value+=3;const we=xt(T,R),Fe=xt(T,R);W.push({name:ie,pixelType:Ce,pLinear:ke,xSampling:we,ySampling:Fe})}return R.value+=1,W}function qt(T,k){const R=ge(T,k),j=ge(T,k),N=ge(T,k),W=ge(T,k),ie=ge(T,k),Ce=ge(T,k),ke=ge(T,k),we=ge(T,k);return{redX:R,redY:j,greenX:N,greenY:W,blueX:ie,blueY:Ce,whiteX:ke,whiteY:we}}function ti(T,k){const R=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],j=Le(T,k);return R[j]}function L(T,k){const R=pe(T,k),j=pe(T,k),N=pe(T,k),W=pe(T,k);return{xMin:R,yMin:j,xMax:N,yMax:W}}function D(T,k){const R=["INCREASING_Y"],j=Le(T,k);return R[j]}function ce(T,k){const R=ge(T,k),j=ge(T,k);return[R,j]}function Re(T,k){const R=ge(T,k),j=ge(T,k),N=ge(T,k);return[R,j,N]}function Pe(T,k,R,j,N){if(j==="string"||j==="stringvector"||j==="iccProfile")return $e(k,R,N);if(j==="chlist")return ht(T,k,R,N);if(j==="chromaticities")return qt(T,R);if(j==="compression")return ti(T,R);if(j==="box2i")return L(T,R);if(j==="lineOrder")return D(T,R);if(j==="float")return ge(T,R);if(j==="v2f")return ce(T,R);if(j==="v3f")return Re(T,R);if(j==="int")return xt(T,R);if(j==="rational")return Je(T,R);if(j==="timecode")return qe(T,R);if(j==="preview")return R.value+=N,"skipped";R.value+=N}function Q(T,k,R){const j={};if(T.getUint32(0,!0)!=20000630)throw new Error("THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.");j.version=T.getUint8(4);const N=T.getUint8(5);j.spec={singleTile:!!(N&2),longName:!!(N&4),deepFormat:!!(N&8),multiPart:!!(N&16)},R.value=8;let W=!0;for(;W;){const ie=ze(k,R);if(ie==0)W=!1;else{const Ce=ze(k,R),ke=pe(T,R),we=Pe(T,k,R,Ce,ke);we===void 0?console.warn(`EXRLoader.parse: skipped unknown header attribute type '${Ce}'.`):j[ie]=we}}if(N&-5)throw console.error("EXRHeader:",j),new Error("THREE.EXRLoader: provided file is currently unsupported.");return j}function ve(T,k,R,j,N){const W={size:0,viewer:k,array:R,offset:j,width:T.dataWindow.xMax-T.dataWindow.xMin+1,height:T.dataWindow.yMax-T.dataWindow.yMin+1,channels:T.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:T.channels[0].pixelType,uncompress:null,getter:null,format:null,colorSpace:Fs};switch(T.compression){case"NO_COMPRESSION":W.lines=1,W.uncompress=le;break;case"RLE_COMPRESSION":W.lines=1,W.uncompress=X;break;case"ZIPS_COMPRESSION":W.lines=1,W.uncompress=ne;break;case"ZIP_COMPRESSION":W.lines=16,W.uncompress=ne;break;case"PIZ_COMPRESSION":W.lines=32,W.uncompress=_e;break;case"PXR24_COMPRESSION":W.lines=16,W.uncompress=Ee;break;case"DWAA_COMPRESSION":W.lines=32,W.uncompress=Oe;break;case"DWAB_COMPRESSION":W.lines=256,W.uncompress=Oe;break;default:throw new Error("EXRLoader.parse: "+T.compression+" is unsupported")}if(W.scanlineBlockSize=W.lines,W.type==1)switch(N){case Hi:W.getter=it,W.inputSize=2;break;case as:W.getter=Ye,W.inputSize=2;break}else if(W.type==2)switch(N){case Hi:W.getter=ge,W.inputSize=4;break;case as:W.getter=Qe,W.inputSize=4}else throw new Error("EXRLoader.parse: unsupported pixelType "+W.type+" for "+T.compression+".");W.blockCount=(T.dataWindow.yMax+1)/W.scanlineBlockSize;for(let Ce=0;Ce<W.blockCount;Ce++)ye(k,j);W.outputChannels=W.channels==3?4:W.channels;const ie=W.width*W.height*W.outputChannels;switch(N){case Hi:W.byteArray=new Float32Array(ie),W.channels<W.outputChannels&&W.byteArray.fill(1,0,ie);break;case as:W.byteArray=new Uint16Array(ie),W.channels<W.outputChannels&&W.byteArray.fill(15360,0,ie);break;default:console.error("THREE.EXRLoader: unsupported type: ",N);break}return W.bytesPerLine=W.width*W.inputSize*W.channels,W.outputChannels==4?(W.format=Ci,W.colorSpace=Fs):(W.format=dl,W.colorSpace=nn),W}const Se=new DataView(e),ue=new Uint8Array(e),Ve={value:0},Xe=Q(Se,e,Ve),be=ve(Xe,Se,ue,Ve,this.type),tt={value:0},Ze={R:0,G:1,B:2,A:3,Y:0};for(let T=0;T<be.height/be.scanlineBlockSize;T++){const k=pe(Se,Ve);be.size=pe(Se,Ve),be.lines=k+be.scanlineBlockSize>be.height?be.height-k:be.scanlineBlockSize;const R=be.size<be.lines*be.bytesPerLine?be.uncompress(be):le(be);Ve.value+=be.size;for(let j=0;j<be.scanlineBlockSize;j++){const N=j+T*be.scanlineBlockSize;if(N>=be.height)break;for(let W=0;W<be.channels;W++){const ie=Ze[Xe.channels[W].name];for(let Ce=0;Ce<be.width;Ce++){tt.value=(j*(be.channels*be.width)+W*be.width+Ce)*be.inputSize;const ke=(be.height-1-N)*(be.width*be.outputChannels)+Ce*be.outputChannels+ie;be.byteArray[ke]=be.getter(R,tt)}}}}return{header:Xe,width:be.width,height:be.height,data:be.byteArray,format:be.format,colorSpace:be.colorSpace,type:this.type}}setDataType(e){return this.type=e,this}load(e,t,s,r){function n(o,a){o.colorSpace=a.colorSpace,o.minFilter=Tt,o.magFilter=Tt,o.generateMipmaps=!1,o.flipY=!1,t&&t(o,a)}return super.load(e,n,s,r)}}const eM=re("debugexr");class jJ{constructor(e){u(this,"parser"),u(this,"name"),this.parser=e,this.name="EXT_texture_exr",eM&&console.log(e)}loadTexture(e){const t=this.name,s=this.parser,r=s.json.textures[e];if(eM&&console.log("EXT_texture_exr.loadTexture",e,r),!r.extensions||!r.extensions[t])return null;const n=r.extensions[t],o=new $E(s.options.manager);return eM&&console.log("EXT_texture_exr.loadTexture",n,o),s.loadTextureImage(e,n.source,o)}}window.addEventListener("unhandledrejection",i=>{});const lF="NEEDLE_gameobject_data";class GJ{constructor(e){u(this,"parser"),this.parser=e}get name(){return lF}afterRoot(e){const t=[];for(let s=0;s<this.parser.json.nodes.length;s++){const r=this.parser.json.nodes[s];if(r&&r.extensions){const n=r.extensions[lF];if(n){const o=this.findAndApplyExtensionData(s,n);t.push(o)}}}return Promise.all(t).then(()=>{})}async findAndApplyExtensionData(e,t){const s=await this.parser.getDependency("node",e);s&&this.applyExtensionData(s,t)}applyExtensionData(e,t){t.layers===void 0&&(t.layers=0),e.userData.layer=t.layers,e.layers.disableAll(),e.layers.set(t.layers),e.userData.tag=t.tag??"none",e.userData.hideFlags=t.hideFlags??0,e.userData.static=t.static??!1,e.visible=t.activeSelf??!0,e.guid=t.guid}}const cF="NEEDLE_lighting_settings",Du=re("debugenvlight");class HJ{constructor(e,t,s){u(this,"parser"),u(this,"sourceId"),u(this,"context"),this.parser=e,this.sourceId=t,this.context=s}get name(){return cF}afterRoot(e){const t=this.parser.json.extensions;if(t){const s=t[cF];if(s){Du&&console.log('Loaded "'+this.name+'", src: "'+this.sourceId+'"',s);let r;if(e.scene.children.length===1){const n=e.scene.children[0];r=ee.addNewComponent(n,Ub,!1)}else{const n=new De;n.name="LightSettings "+this.sourceId,e.scene.add(n),r=ee.addNewComponent(n,Ub,!1)}r.sourceId=this.sourceId,r.ambientIntensity=s.ambientIntensity,r.ambientLight=new Ae().fromArray(s.ambientLight),Array.isArray(s.ambientTrilight)&&(r.ambientTrilight=s.ambientTrilight.map(n=>new Ae().fromArray(n))),r.ambientMode=s.ambientMode,r.environmentReflectionSource=s.environmentReflectionSource}}return null}}Ii.registerCallback(Pr.ContextCreated,i=>{const e=i.context,t=ee.findObjectOfType(Ub,e);t!=null&&t.sourceId&&(t.enabled=!0)});class Ub extends Me{constructor(){super(...arguments),u(this,"ambientMode",Tp.Skybox),u(this,"ambientLight"),u(this,"ambientTrilight"),u(this,"ambientIntensity",1),u(this,"environmentReflectionSource",Tb.Skybox),u(this,"_hasReflection",!1),u(this,"_ambientLightObj"),u(this,"_hemisphereLightObj"),u(this,"_lightProbeObj")}awake(){var e;if(this.sourceId){const s=this.environmentReflectionSource===Tb.Skybox?Kc.Skybox:Kc.Reflection,r=this.context.lightmaps.tryGet(this.sourceId,s,0);this._hasReflection=r!=null,r&&this.context.sceneLighting.internalRegisterReflection(this.sourceId,r)}this.enabled=!1,this.context.sceneLighting.internalRegisterSceneLightSettings(this),Du&&window.addEventListener("keydown",s=>{if(!this.destroyed)switch(s.key){case"l":this.enabled=!this.enabled;break}});const t=(e=this.gameObject.userData)==null?void 0:e.components;if(t){const s=t.indexOf(this);t.splice(s,1),t.push(this)}}onDestroy(){this.context.sceneLighting.internalUnregisterSceneLightSettings(this)}calculateIntensityFactor(e){const t=Math.max(e.r,e.g,e.b);return 2.2*et.lerp(0,1.33,t)}onEnable(){if(Du&&console.warn("\u{1F4A1}\u{1F7E1} >>> Enable lighting",this.sourceId,this.enabled,this),this.ambientMode==Tp.Flat){if(this.ambientLight&&!this._ambientLightObj){const e=this.calculateIntensityFactor(this.ambientLight);this._ambientLightObj=new eC(this.ambientLight,this.ambientIntensity*e),Du&&console.log("Created ambient light",this.sourceId,this._ambientLightObj,this.ambientIntensity,e)}this._ambientLightObj&&this.gameObject.add(this._ambientLightObj),this._lightProbeObj&&this._lightProbeObj.removeFromParent()}else if(this.ambientMode===Tp.Trilight){if(this.ambientTrilight){const e=this.ambientTrilight[0],t=this.ambientTrilight[this.ambientTrilight.length-1],s=this.calculateIntensityFactor(t);this._hemisphereLightObj=new JS(t,e,this.ambientIntensity*s),this.gameObject.add(this._hemisphereLightObj),Du&&console.log("Created hemisphere ambient light",this.sourceId,this._hemisphereLightObj,this.ambientIntensity,s)}}else this._ambientLightObj&&this._ambientLightObj.removeFromParent(),this._hemisphereLightObj&&this._hemisphereLightObj.removeFromParent(),this._lightProbeObj?this.enabled&&this.destroyed&&this._lightProbeObj&&this.gameObject.add(this._lightProbeObj):this.sourceId&&this.context.sceneLighting.internalGetSceneLightingData(this.sourceId).then(e=>{e&&(this._lightProbeObj=e.lightProbe,this.enabled&&!this.destroyed&&this._lightProbeObj&&(Du&&console.log("Add",this.sourceId,e),this.gameObject.add(this._lightProbeObj)))});this.sourceId&&this.context.sceneLighting.internalEnableReflection(this.sourceId)}onDisable(){Du&&console.warn("\u{1F4A1}\u26AB <<< Disable lighting:",this.sourceId,this),this._lightProbeObj&&this._lightProbeObj.removeFromParent(),this._ambientLightObj&&this._ambientLightObj.removeFromParent(),this._hemisphereLightObj&&this._hemisphereLightObj.removeFromParent(),this.sourceId&&this.context.sceneLighting.internalDisableReflection(this.sourceId)}}const tM=re("debugstencil");function VJ(i,e){return(i&1<<e.layer)!=0}const WJ=Symbol("stencils"),Fp=class{constructor(i,e){u(this,"parser"),u(this,"source"),this.parser=i,this.source=e}static applyStencil(i){if(!i)return;const e=i.sourceId;if(tM&&console.log(e,Fp.stencils),!e)return;const t=Fp.stencils[e];if(t)for(let s=t.length-1;s>=0;s--){const r=t[s];if(VJ(r.layer,i)){tM&&console.log(r),setTimeout(()=>{Rr()&&mb(i.gameObject)&&(lo("Stencil not supported on instanced objects"),console.warn("Stencil not supported on instanced objects",i))},500);for(let n=0;n<i.sharedMaterials.length;n++){let o=i.sharedMaterials[n];o&&(o=o.clone(),o[WJ]=!0,o.stencilWrite=!0,o.stencilWriteMask=255,o.stencilFuncMask=255,o.stencilRef=r.value,o.stencilFunc=r.compareFunc,o.stencilZPass=r.passOp,o.stencilFail=r.failOp,o.stencilZFail=r.zFailOp,i.sharedMaterials[n]=o)}i.gameObject.renderOrder=r.event*1e3+r.index*50;break}}}afterRoot(i){const e=this.parser.json.extensions;if(e){const t=e[XJ];if(t){tM&&console.log(t);const s=t.stencil;if(s&&Array.isArray(s))for(const r of s){const n={...r};n.compareFunc=qJ(n.compareFunc),n.passOp=sM(n.passOp),n.failOp=sM(n.failOp),n.zFailOp=sM(n.zFailOp),Fp.stencils[this.source]||(Fp.stencils[this.source]=[]),Fp.stencils[this.source].push(n)}}}return null}};let iM=Fp;u(iM,"stencils",{});function sM(i){switch(i){case 0:return Sm;case 1:return KP;case 2:return ZP;case 3:return $P;case 4:return eB;case 6:return tB;case 7:return iB;case 5:return sB}return 0}function qJ(i){switch(i){case 1:return z1;case 2:return rB;case 3:return nB;case 4:return oB;case 5:return aB;case 6:return lB;case 7:return cB;case 8:return Q1}return z1}const XJ="NEEDLE_render_objects",Fb="NEEDLE_progressive",Ps=re("debugprogressive"),rM=Symbol("needle-progressive-texture"),nM=new Map;let oM=!1;Ps&&window.addEventListener("keyup",i=>{i.key==="p"&&(nM.forEach((e,t)=>{Object.entries(e).forEach(([s,r])=>{oM?t[s]=r.lod0:t[s]=r.original,t.needsUpdate=!0})}),oM=!oM)});const Nb=class{constructor(i,e,t){u(this,"parser"),u(this,"sourceId"),u(this,"context"),this.parser=i,this.sourceId=e,this.context=t}static assignTextureLOD(i,e,t,s=0){if(!t)return Promise.resolve(null);const r=[];for(let n of Object.keys(t)){const o=t[n];if(o!=null&&o.isTexture){const a=this.assignTextureLODForSlot(i,e,t,s,n,o);r.push(a)}}if(t instanceof cy)for(let n of Object.keys(t.uniforms)){const o=t.uniforms[n].value;if(o!=null&&o.isTexture){const a=this.assignTextureLODForSlot(i,e,t,s,n,o);r.push(a)}}return r}static assignTextureLODForSlot(i,e,t,s,r,n){return n?.isTexture!==!0?Promise.resolve(null):(Ps&&console.log(`-----------
4410
4410
  `,"FIND",t.name,r,n?.name,n?.userData,n,t),Nb.getOrLoadTexture(i,e,t,r,n,s).then(o=>{if(o?.isTexture===!0){if(Ps&&console.log("Assign LOD",t.name,r,o.name,o.guid,t,"Prev:",n,"Now:",o,`
4411
- --------------`),t[r]=o,o.needsUpdate=!0,t.needsUpdate=!0,Ps){let a=nM.get(t);a||(a={},nM.set(t,a));let l=a[r];l||(l=a[r]={original:n,lod0:o}),l.lod0=o}return o}return null}))}get name(){return Fb}afterRoot(i){var e;return Ps&&console.log("AFTER",this.sourceId,i),(e=this.parser.json.textures)==null||e.forEach((t,s)=>{if(t!=null&&t.extensions){const r=t?.extensions[Fb];r&&this.parser.getDependency("texture",s).then(n=>{Ps&&console.log("> Progressive: register",n.name,n.uuid,r),n.source&&(n.source[rM]=r),Nb.cache.set(n.uuid,r)})}}),null}static async getOrLoadTexture(i,e,t,s,r,n){const o=r.uuid;let a;if(r.source&&r.source[rM]&&(a=r.source[rM]),a||(a=Nb.cache.get(o)),a){Ps&&console.log(o,a.uri,a.guid);const l=Sc(e,a.uri);if(l.endsWith(".glb")||l.endsWith(".gltf")){if(!a.guid)return console.warn("missing pointer for glb/gltf texture",a),null;const c=l+"_"+a.guid;if(this.resolved[c]){let d=this.resolved[c];if(d.image&&d.image.data)return Ps&&console.log("Texture has already been loaded: "+c,t.name,s,r.name,d),d=this.copySettings(r,d),d;d&&Ps&&console.log("Texture has been disposed, will load again: "+c,t.name,s,r.name,d)}const h=this.onProgressiveLoadStart(i,e,l,t,s);try{if(this.currentlyLoading[c]!==void 0){Ps&&console.log("Already loading:",t.name+"."+s,c);let f=await this.currentlyLoading[c];return f&&(f=this.copySettings(r,f)),f}const d=a,p=new Promise(async(f,m)=>{var v;const A=new Dp;Bg(A,i),Ps&&console.log("Load "+l,t.name,s,d.guid),Ps&&await dm(Math.random()*1e3);const g=await A.loadAsync(l),b=g.parser;Ps&&console.log("Loading finished "+l,t.name,s,d.guid);let y=-1,x=!1;if(!((v=g.parser.json)!=null&&v.textures))return Ps&&console.warn("No textures in glTF "+l+" - may be a bug",t.name,s,d.guid),f(null);for(const E of g.parser.json.textures)if(y++,E!=null&&E.extensions){const I=E?.extensions[Fb];if(I!=null&&I.guid&&I.guid===d.guid){x=!0;break}}if(!x)return f(null);let _=await b.getDependency("texture",y);_=this.copySettings(r,_),_&&(_.guid=d.guid),this.resolved[c]=_,Ps&&console.log(t.name,s,'change "'+r.name+'" \u2192 "'+_.name+'"',l,y,_,t,c),f(_)});return this.currentlyLoading[c]=p,await p}finally{delete this.currentlyLoading[c],this.onProgressiveLoadEnd(h)}}else{const c=this.onProgressiveLoadStart(i,e,l,t,s);try{Ps&&console.log("Load texture from uri: "+l);const h=await new jc().loadAsync(l);return h?(h.guid=a.guid,h.flipY=!1,h.needsUpdate=!0,h.encoding=r.encoding,Ps&&console.log(a,h)):Ps&&console.warn("failed loading",l),h}finally{this.onProgressiveLoadEnd(c)}}}else Ps&&console.warn("unknown texture",r.name,r.uuid,r);return null}static copySettings(i,e){const t=i.clone(),s=e.source,r=e.mipmaps;return t.copy(i),t.source=s,t.mipmaps=r,t}static beginListenStart(i,e){this._progressiveEventListeners.has(i)||this._progressiveEventListeners.set(i,new uF),this._progressiveEventListeners.get(i).start.push(e)}static stopListenStart(i,e){if(!this._progressiveEventListeners.has(i))return;const t=this._progressiveEventListeners.get(i).start,s=t.indexOf(e);s>=0&&t.splice(s,1)}static beginListenEnd(i,e){this._progressiveEventListeners.has(i)||this._progressiveEventListeners.set(i,new uF),this._progressiveEventListeners.get(i).end.push(e)}static stopListenEnd(i,e){if(!this._progressiveEventListeners.has(i))return;const t=this._progressiveEventListeners.get(i).end,s=t.indexOf(e);s>=0&&t.splice(s,1)}static onProgressiveLoadStart(i,e,t,s,r){this._currentProgressiveLoadingInfo.has(i)||this._currentProgressiveLoadingInfo.set(i,[]);const n=new hF(i,e,t,s,r),o=this._currentProgressiveLoadingInfo.get(i),a=this._progressiveEventListeners.get(i);return a&&a.onStart(n),o.push(n),n}static onProgressiveLoadEnd(i){if(!i)return;const e=i.context;if(!this._currentProgressiveLoadingInfo.has(e))return;const t=this._currentProgressiveLoadingInfo.get(e),s=t.indexOf(i);if(s<0)return;t.splice(s,1);const r=this._progressiveEventListeners.get(e);r&&r.onEnd(i)}};let Jo=Nb;u(Jo,"cache",new Map),u(Jo,"resolved",{}),u(Jo,"currentlyLoading",{}),u(Jo,"_progressiveEventListeners",new Map),u(Jo,"_currentProgressiveLoadingInfo",new Map);class hF{constructor(e,t,s,r,n){u(this,"context"),u(this,"source"),u(this,"uri"),u(this,"material"),u(this,"slot"),this.context=e,this.source=t,this.uri=s,this.material=r,this.slot=n}}class uF{constructor(){u(this,"start",[]),u(this,"end",[])}onStart(e){for(const t of this.start)t(e)}onEnd(e){for(const t of this.end)t(e)}}let zb;Promise.resolve().then(()=>Che).then(i=>(zb=i.GLTFAnimationPointerExtension,zb)).catch(i=>{console.warn("Failed to import GLTFLoaderAnimationPointer. Please use @needle-tools/three for full KHR_animation support",i)});const Ug=new Array;function YJ(i){Ug.includes(i)||Ug.push(i)}function JJ(i){const e=Ug.indexOf(i);e>=0&&Ug.splice(e,1)}function aM(i){const e=new YU;return i.register(t=>(e.parser=t,e)),e}class KJ{resolvePath(e){return e.includes("/extensions/builtin_components/")?e.replace("/extensions/builtin_components/","/userData/components/"):e.includes("extensions/builtin_components/")?e.replace("extensions/builtin_components/","/userData/components/"):e}}function dF(i,e,t){const s=t.lastIndexOf("?");s>=0&&(t=t.substring(0,s)),i.register(r=>new GJ(r)),i.register(r=>new q8(r)),i.register(r=>new oY(r,e.lightmaps,t)),i.register(r=>new HJ(r,t,e)),i.register(r=>new xJ(r,t)),i.register(r=>new iM(r,t)),i.register(r=>new Jo(r,t,e)),i.register(r=>new jJ(r)),aL()&&i.register(r=>new rL(r));for(const r of Ug)i.register(n=>new r(n));i.register(r=>{if(zb){const n=new zb(r);return n.setAnimationPointerResolver.bind(n)(new KJ),n}})}const lM=re("debuglightmaps");class Fg{constructor(e,t){u(this,"lightmapIndex",-1),u(this,"lightmapScaleOffset",new mt(1,1,0,0)),u(this,"context"),u(this,"gameObject"),u(this,"lightmapTexture",null),u(this,"lightmapScaleOffsetUniform",{value:new mt(1,1,0,0)}),u(this,"lightmapUniform",{value:null}),u(this,"onBeforeCompile",(s,r)=>{lM&&console.log("Lightmaps, before compile"),s.lightMapUv="uv1",this.lightmapScaleOffsetUniform.value=this.lightmapScaleOffset,this.lightmapUniform.value=this.lightmapTexture,s.uniforms.lightmap=this.lightmapUniform,s.uniforms.lightmapScaleOffset=this.lightmapScaleOffsetUniform}),this.gameObject=e,this.context=t}get lightmap(){return this.lightmapTexture}set lightmap(e){e!==this.lightmapTexture&&(this.lightmapTexture=e,this.applyLightmap())}init(e,t,s){console.assert(this.gameObject!==void 0&&this.gameObject!==null,"Missing gameobject",this),this.lightmapIndex=e,!(this.lightmapIndex<0)&&(this.lightmapScaleOffset=t,this.lightmapTexture=s,lM&&this.setLightmapDebugMaterial(),this.applyLightmap())}updateLightmapUniforms(e){const t=e.uniforms;t&&t.lightmap&&(this.lightmapScaleOffsetUniform.value=this.lightmapScaleOffset,this.lightmapUniform.value=this.lightmapTexture,t.lightmap=this.lightmapUniform,t.lightmapScaleOffset=this.lightmapScaleOffsetUniform)}applyLightmap(){if(this.gameObject.type==="Object3D"){lM&&console.warn("Can not add lightmap. Is this object missing a renderer?",this.gameObject.name);return}if(this.gameObject.type==="Group"){console.warn("Lightmap on multimaterial object is not supported yet... please open a feature request on https://github.com/needle-tools/needle-engine-support if your project requires it");return}console.assert(this.gameObject.type==="Mesh","Lightmap only works on meshes",this);const e=this.gameObject;if(e.geometry.getAttribute("uv1")||e.geometry.setAttribute("uv1",e.geometry.getAttribute("uv")),Array.isArray(this.gameObject.material)){const t=this.gameObject.material;for(let s=0;s<t.length;s++){const r=t[s].clone();t[s]=r,r.onBeforeCompile=this.onBeforeCompile}}else{const t=this.gameObject.material.clone();this.gameObject.material=t,this.gameObject.material.onBeforeCompile=this.onBeforeCompile}if(this.lightmapIndex>=0){const t=this.lightmapTexture,s=this.gameObject.material;s&&t&&(s.uniforms||(s.uniforms={}),s.lightMap=t,s.uniforms.lightmap={value:t})}}setLightmapDebugMaterial(){this.gameObject.material=new kt({vertexShader:`
4411
+ --------------`),t[r]=o,o.needsUpdate=!0,t.needsUpdate=!0,Ps){let a=nM.get(t);a||(a={},nM.set(t,a));let l=a[r];l||(l=a[r]={original:n,lod0:o}),l.lod0=o}return o}return null}))}get name(){return Fb}afterRoot(i){var e;return Ps&&console.log("AFTER",this.sourceId,i),(e=this.parser.json.textures)==null||e.forEach((t,s)=>{if(t!=null&&t.extensions){const r=t?.extensions[Fb];r&&this.parser.getDependency("texture",s).then(n=>{Ps&&console.log("> Progressive: register",n.name,n.uuid,r),n.source&&(n.source[rM]=r),Nb.cache.set(n.uuid,r)})}}),null}static async getOrLoadTexture(i,e,t,s,r,n){const o=r.uuid;let a;if(r.source&&r.source[rM]&&(a=r.source[rM]),a||(a=Nb.cache.get(o)),a){Ps&&console.log(o,a.uri,a.guid);const l=Sc(e,a.uri);if(l.endsWith(".glb")||l.endsWith(".gltf")){if(!a.guid)return console.warn("missing pointer for glb/gltf texture",a),null;const c=l+"_"+a.guid;if(this.resolved[c]){let d=this.resolved[c];if(d.image&&d.image.data)return Ps&&console.log("Texture has already been loaded: "+c,t.name,s,r.name,d),d=this.copySettings(r,d),d;d&&Ps&&console.log("Texture has been disposed, will load again: "+c,t.name,s,r.name,d)}const h=this.onProgressiveLoadStart(i,e,l,t,s);try{if(this.currentlyLoading[c]!==void 0){Ps&&console.log("Already loading:",t.name+"."+s,c);let f=await this.currentlyLoading[c];return f&&(f=this.copySettings(r,f)),f}const d=a,p=new Promise(async(f,m)=>{var v;const A=new Dp;Bg(A,i),Ps&&console.log("Load "+l,t.name,s,d.guid),Ps&&await dm(Math.random()*1e3);const g=await A.loadAsync(l),b=g.parser;Ps&&console.log("Loading finished "+l,t.name,s,d.guid);let y=-1,x=!1;if(!((v=g.parser.json)!=null&&v.textures))return Ps&&console.warn("No textures in glTF "+l+" - may be a bug",t.name,s,d.guid),f(null);for(const E of g.parser.json.textures)if(y++,E!=null&&E.extensions){const I=E?.extensions[Fb];if(I!=null&&I.guid&&I.guid===d.guid){x=!0;break}}if(!x)return f(null);let _=await b.getDependency("texture",y);_=this.copySettings(r,_),_&&(_.guid=d.guid),this.resolved[c]=_,Ps&&console.log(t.name,s,'change "'+r.name+'" \u2192 "'+_.name+'"',l,y,_,t,c),f(_)});return this.currentlyLoading[c]=p,await p}finally{delete this.currentlyLoading[c],this.onProgressiveLoadEnd(h)}}else{const c=this.onProgressiveLoadStart(i,e,l,t,s);try{Ps&&console.log("Load texture from uri: "+l);const h=await new jc().loadAsync(l);return h?(h.guid=a.guid,h.flipY=!1,h.needsUpdate=!0,h.encoding=r.encoding,Ps&&console.log(a,h)):Ps&&console.warn("failed loading",l),h}finally{this.onProgressiveLoadEnd(c)}}}else Ps&&console.warn("unknown texture",r.name,r.uuid,r);return null}static copySettings(i,e){const t=i.clone(),s=e.source,r=e.mipmaps;return t.copy(i),t.source=s,t.mipmaps=r,t}static beginListenStart(i,e){this._progressiveEventListeners.has(i)||this._progressiveEventListeners.set(i,new uF),this._progressiveEventListeners.get(i).start.push(e)}static stopListenStart(i,e){if(!this._progressiveEventListeners.has(i))return;const t=this._progressiveEventListeners.get(i).start,s=t.indexOf(e);s>=0&&t.splice(s,1)}static beginListenEnd(i,e){this._progressiveEventListeners.has(i)||this._progressiveEventListeners.set(i,new uF),this._progressiveEventListeners.get(i).end.push(e)}static stopListenEnd(i,e){if(!this._progressiveEventListeners.has(i))return;const t=this._progressiveEventListeners.get(i).end,s=t.indexOf(e);s>=0&&t.splice(s,1)}static onProgressiveLoadStart(i,e,t,s,r){this._currentProgressiveLoadingInfo.has(i)||this._currentProgressiveLoadingInfo.set(i,[]);const n=new hF(i,e,t,s,r),o=this._currentProgressiveLoadingInfo.get(i),a=this._progressiveEventListeners.get(i);return a&&a.onStart(n),o.push(n),n}static onProgressiveLoadEnd(i){if(!i)return;const e=i.context;if(!this._currentProgressiveLoadingInfo.has(e))return;const t=this._currentProgressiveLoadingInfo.get(e),s=t.indexOf(i);if(s<0)return;t.splice(s,1);const r=this._progressiveEventListeners.get(e);r&&r.onEnd(i)}};let Jo=Nb;u(Jo,"cache",new Map),u(Jo,"resolved",{}),u(Jo,"currentlyLoading",{}),u(Jo,"_progressiveEventListeners",new Map),u(Jo,"_currentProgressiveLoadingInfo",new Map);class hF{constructor(e,t,s,r,n){u(this,"context"),u(this,"source"),u(this,"uri"),u(this,"material"),u(this,"slot"),this.context=e,this.source=t,this.uri=s,this.material=r,this.slot=n}}class uF{constructor(){u(this,"start",[]),u(this,"end",[])}onStart(e){for(const t of this.start)t(e)}onEnd(e){for(const t of this.end)t(e)}}let zb;Promise.resolve().then(()=>Che).then(i=>(zb=i.GLTFAnimationPointerExtension,zb)).catch(i=>{console.warn("Failed to import GLTFLoaderAnimationPointer. Please use @needle-tools/three for full KHR_animation support",i)});const Ug=new Array;function YJ(i){Ug.includes(i)||Ug.push(i)}function JJ(i){const e=Ug.indexOf(i);e>=0&&Ug.splice(e,1)}function aM(i){const e=new YU;return i.register(t=>(e.parser=t,e)),e}class KJ{resolvePath(e){return e.includes("/extensions/builtin_components/")?e.replace("/extensions/builtin_components/","/userData/components/"):e.includes("extensions/builtin_components/")?e.replace("extensions/builtin_components/","/userData/components/"):e}}function dF(i,e,t){const s=t.lastIndexOf("?");s>=0&&(t=t.substring(0,s)),i.register(r=>new GJ(r)),i.register(r=>new q8(r)),i.register(r=>new oY(r,e.lightmaps,t)),i.register(r=>new HJ(r,t,e)),i.register(r=>new xJ(r,t)),i.register(r=>new iM(r,t)),i.register(r=>new Jo(r,t,e)),i.register(r=>new jJ(r)),aL()&&i.register(r=>new rL(r));for(const r of Ug)i.register(n=>new r(n));i.register(r=>{if(zb){const n=new zb(r);return n.setAnimationPointerResolver.bind(n)(new KJ),n}})}const lM=re("debuglightmaps");class Fg{constructor(e,t){u(this,"lightmapIndex",-1),u(this,"lightmapScaleOffset",new mt(1,1,0,0)),u(this,"context"),u(this,"gameObject"),u(this,"lightmapTexture",null),u(this,"lightmapScaleOffsetUniform",{value:new mt(1,1,0,0)}),u(this,"lightmapUniform",{value:null}),u(this,"onBeforeCompile",(s,r)=>{lM&&console.log("Lightmaps, before compile",s),s.lightMapUv="uv1",this.lightmapScaleOffsetUniform.value=this.lightmapScaleOffset,this.lightmapUniform.value=this.lightmapTexture,s.uniforms.lightmapScaleOffset=this.lightmapScaleOffsetUniform}),this.gameObject=e,this.context=t}get lightmap(){return this.lightmapTexture}set lightmap(e){e!==this.lightmapTexture&&(this.lightmapTexture=e,this.applyLightmap())}init(e,t,s){console.assert(this.gameObject!==void 0&&this.gameObject!==null,"Missing gameobject",this),this.lightmapIndex=e,!(this.lightmapIndex<0)&&(this.lightmapScaleOffset=t,this.lightmapTexture=s,lM&&this.setLightmapDebugMaterial(),this.applyLightmap())}updateLightmapUniforms(e){const t=e.uniforms;t&&t.lightmap&&(this.lightmapScaleOffsetUniform.value=this.lightmapScaleOffset,t.lightmapScaleOffset=this.lightmapScaleOffsetUniform)}applyLightmap(){if(this.gameObject.type==="Object3D"){lM&&console.warn("Can not add lightmap. Is this object missing a renderer?",this.gameObject.name);return}if(this.gameObject.type==="Group"){console.warn("Lightmap on multimaterial object is not supported yet... please open a feature request on https://github.com/needle-tools/needle-engine-support if your project requires it");return}console.assert(this.gameObject.type==="Mesh","Lightmap only works on meshes",this);const e=this.gameObject;if(e.geometry.getAttribute("uv1")||e.geometry.setAttribute("uv1",e.geometry.getAttribute("uv")),Array.isArray(this.gameObject.material)){const t=this.gameObject.material;for(let s=0;s<t.length;s++){const r=t[s].clone();t[s]=r,r.onBeforeCompile=this.onBeforeCompile}}else{const t=this.gameObject.material.clone();this.gameObject.material=t,this.gameObject.material.onBeforeCompile=this.onBeforeCompile}if(this.lightmapIndex>=0&&this.lightmapTexture){const t=this.gameObject.material;t&&(t.lightMap=this.lightmapTexture,t.needsUpdate=!0)}}setLightmapDebugMaterial(){this.gameObject.material=new kt({vertexShader:`
4412
4412
  varying vec2 vUv1;
4413
4413
  void main()
4414
4414
  {
@@ -4416,7 +4416,7 @@ version 0.6.9
4416
4416
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
4417
4417
  }
4418
4418
  `,fragmentShader:`
4419
- uniform sampler2D lightmap;
4419
+ uniform sampler2D lightMap;
4420
4420
  uniform float lightMapIntensity;
4421
4421
  uniform vec4 lightmapScaleOffset;
4422
4422
  varying vec2 vUv1;
@@ -4429,11 +4429,11 @@ version 0.6.9
4429
4429
  void main() {
4430
4430
  vec2 lUv = vUv1.xy * lightmapScaleOffset.xy + vec2(lightmapScaleOffset.z, (1. - (lightmapScaleOffset.y + lightmapScaleOffset.w)));
4431
4431
 
4432
- vec4 lightMapTexel = texture2D( lightmap, lUv);
4432
+ vec4 lightMapTexel = texture2D( lightMap, lUv);
4433
4433
  // The range of RGBM lightmaps goes from 0 to 34.49 (5^2.2) in linear space, and from 0 to 5 in gamma space.
4434
- //lightMapTexel.rgb *= lightMapTexel.a * 8.; // no idea where that "8" comes from... heuristically derived
4435
- //lightMapTexel.a = 1.;
4436
- //lightMapTexel = conv_sRGBToLinear(lightMapTexel);
4434
+ // lightMapTexel.rgb *= lightMapTexel.a * 8.; // no idea where that "8" comes from... heuristically derived
4435
+ // lightMapTexel.a = 1.;
4436
+ // lightMapTexel = conv_sRGBToLinear(lightMapTexel);
4437
4437
  // lightMapTexel.rgb = vec3(1.);
4438
4438
 
4439
4439
  // gl_FragColor = vec4(vUv1.xy, 0, 1);
@@ -5006,7 +5006,7 @@ void main() {
5006
5006
  `){super("lineBreak",e,!0),this._newLineBreakability=null}update(e,t){this._needsProcess=!0}process(e){const t=e._whiteSpace._newLineBreakability;if(e._inlines._value)for(let s=0;s<e._inlines._value.length;s++){const r=e._inlines._value[s],n=r.char;let o=null;n!==void 0&&(t!=="nowrap"&&(this._value.includes(n)||n.match(/\s/g))&&(o="possible"),n.match(/\n/g)&&(o=t)),r.lineBreak=o}}get value(){return this._value}}class _3 extends pi{constructor(){super("layouter",null,!1),this._value=null}update(e,t){this._value=e._parent.find(s=>s.isUI&&s.isText),this._needsProcess=!0}process(e){this._value&&(this._value._layouter._needsProcess=!0)}}class Zte extends Jg{constructor(e){super("backgroundColor",e,!1),this._allowsInherit=!1,this._input=0}computeOutputValue(e){this._input==="inherit"?this._value.set(this.getInheritedInput(e)):this._value.set(this._input)}}class w3 extends vN{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class S3 extends AN{constructor(){super()}computeOutputValue(e){this._value=BM(this.getInheritedInput(e))}}class C3 extends CN{constructor(){super("fontFamily","inherit",!0),this._input="inherit",this._needsUpdate=!0,this._allowsInherit=!1}computeOutputValue(e){let t=this._inheritedInput;if(t==="inherit"&&(t=this.getInheritedInput(e)),t instanceof fx)this._value=t,e._font._needsUpdate=!0;else if(typeof t=="string"){const s=Fu.getFontFamily(t);s?(this._value=s,e._font._needsUpdate=!0):console.warn(`(.style) fontFamily, the font '${t}' is not registered. Aborted.`)}else console.warn("(.style) fontFamily requires a registered fontFamily instance, or the id of a registered fontFamily."),console.warn("If you want to set a specific font, please use .font property instead.")}get value(){return this._value}}class mT extends MN{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited,this._whiteSpacedContent="",this._stringCollapser=this.emptyStrategyLogic,this._inlineCollapser=this.emptyStrategyLogic,this._inlineWrapper=this.emptyStrategyLogic}_computeFromInherited(e){switch(super._computeFromInherited(e),this._newLineBreakability=$te(this._value),this._value){case"nowrap":case"normal":this._stringCollapser=eie;break;case"pre-line":this._stringCollapser=M3;break;default:this._stringCollapser=tie}switch(this._value){case"pre-line":case"nowrap":case"normal":this._inlineCollapser=oie;break;case"pre-wrap":this._inlineCollapser=nie;break;default:this._inlineCollapser=aie}switch(this._value){case"pre-line":case"pre-wrap":case"normal":this._inlineWrapper=iie;break;case"pre":this._inlineWrapper=sie;break;default:this._inlineWrapper=rie}this._needsProcess=!0}process(e){e.isInline&&!e.isInlineBlock&&(this._whiteSpacedContent=this._stringCollapser(e._textContent._value),e._glyphs._needsProcess=!0)}}const E3={" ":" ","\n":`
5007
5007
  `,"\r":"\r"," ":" "},$te=function(i){switch(i){case"pre":case"pre-wrap":case"pre-line":return"mandatory"}return null};function eie(i){return M3(i.replace(/\n/g," "))}function M3(i){return i.replace(/[ ]{2,}/g," ")}function tie(i){return i}function iie(i,e,t,s){const r=i[e];if(r.lineBreak==="mandatory"||t+r.xadvance+r.xoffset+r.kerning>s.INNER_WIDTH)return!0;const n=R3(i,e,s);return lie(i[e-1],t,n,s)}function sie(i,e,t,s){return i[e].lineBreak==="mandatory"}function rie(){return!1}function nie(i){if(!i[0])return 0;const e=i[0],t=i[i.length-1];return e.char&&e.char===`
5008
5008
  `&&i.length>1&&I3([e],i[1]),t.char&&t.char===`
5009
- `&&i.length>1&&T3([t],i[i.length-2]),e.offsetX}function oie(i){if(!i[0])return 0;let e=[],t;for(let s=0;s<i.length;s++){const r=i[s];if(r.char&&E3[r.char]&&i.length>s){e.push(r),t=i[s+1];continue}break}I3(e,t),e=[],t=null;for(let s=i.length-1;s>0;s--){const r=i[s];if(r.char&&E3[r.char]&&s>0){e.push(r),t=i[s-1];continue}break}return T3(e,t),i[0].offsetX}function aie(i){return i[0]?i[0].offsetX:0}function T3(i,e){if(e)for(let t=0;t<i.length;t++){const s=i[t];s.fontFactor=0,s.offsetX=e.offsetX+e.cumulativeWidth,s.cumulativeWidth=0}}function I3(i,e){if(e)for(let t=0;t<i.length;t++){const s=i[t];s.fontFactor=0,s.offsetX=e.offsetX,s.cumulativeWidth=0}}function R3(i,e,t,s){if(s=s||0,!i[e])return s;const r=i[e];return r.lineBreak?s+r.xadvance:R3(i,e+1,t,s+r.xadvance+r.xoffset+r.kerning+t.LETTERSPACING)}function lie(i,e,t,s){return!i||!i.char||e+t<s.INNER_WIDTH?!1:s.BREAKON.indexOf(i.char)>-1}class P3 extends TN{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._fontSize._needsProcess=!0,e._layouter._needsProcess=!0}}class B3 extends Bi{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(e){this._value=this._inheritedInput,e._font._fontVariant&&(e._bounds._needsProcess=!0,e._layouter._needsProcess=!0)}process(e){if(!e._font._fontVariant||!e._font._fontVariant.isReady)return;const t=this._value/e._font._fontVariant.typographic.size,s=e._inlines._value;for(let r=0;r<s.length;r++){const n=s[r];n.resetOffsets(),n.fontSize=this._value,n.fontFactor=t}}get value(){return this._value}}class k3 extends IN{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(e,t){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(e)),e._layouter._needsUpdate=!0}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class cie extends k3{constructor(){super(),this._value="inherit"}}class hie extends gx{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._parent._value._layouter._needsProcess=!1}process(e){if(this._value!=="none"){const t=e._whiteSpace._whiteSpacedContent,s=e._inlines._value;for(let r=1;r<s.length;r++){const n=t[r-1]+t[r];s[r].kerning=e._font._fontVariant.getKerningAmount(n)}}}}class D3 extends pi{constructor(){super("children",null,!1),this._uis=[]}update(e,t){}process(e){}_compute(e){}dispose(){}}function uie(i,e=!1){const t=i[0].index!==null,s=new Set(Object.keys(i[0].attributes)),r=new Set(Object.keys(i[0].morphAttributes)),n={},o={},a=i[0].morphTargetsRelative,l=new je.BufferGeometry;let c=0;for(let h=0;h<i.length;++h){const d=i[h];let p=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in d.attributes){if(!s.has(f))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;n[f]===void 0&&(n[f]=[]),n[f].push(d.attributes[f]),p++}if(p!==s.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in d.morphAttributes){if(!r.has(f))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;o[f]===void 0&&(o[f]=[]),o[f].push(d.morphAttributes[f])}if(l.userData.mergedUserData=l.userData.mergedUserData||[],l.userData.mergedUserData.push(d.userData),e){let f;if(t)f=d.index.count;else if(d.attributes.position!==void 0)f=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(c,f,h),c+=f}}if(t){let h=0;const d=[];for(let p=0;p<i.length;++p){const f=i[p].index;for(let m=0;m<f.count;++m)d.push(f.getX(m)+h);h+=i[p].attributes.position.count}l.setIndex(d)}for(const h in n){const d=O3(n[h]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,d)}for(const h in o){const d=o[h][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let p=0;p<d;++p){const f=[];for(let v=0;v<o[h].length;++v)f.push(o[h][v][p]);const m=O3(f);if(!m)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(m)}}return l}function O3(i){let e,t,s,r=0;for(let a=0;a<i.length;++a){const l=i[a];if(l.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(e===void 0&&(e=l.array.constructor),e!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=l.itemSize),t!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(s===void 0&&(s=l.normalized),s!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;r+=l.array.length}const n=new e(r);let o=0;for(let a=0;a<i.length;++a)n.set(i[a].array,o),o+=i[a].array.length;return new je.BufferAttribute(n,t,s)}class die extends pi{constructor(){super("renderer")}render(e){if(!e._inlines._value||!e._inlines._value.length)return;const t=e._inlines._value.map(r=>e._font._fontVariant.getGeometricGlyph(r,e).translate(r.offsetX,r.offsetY,0)),s=uie(t);e.setFontMesh(new je.Mesh(s,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class pie extends OM{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class lm extends sv{constructor(e={}){const t={};lm.definePropertiesValues(t,e),super(t,e),u(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0}),lm.init(this)}add(e){const t=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(t.push(r),r.position.z=.005):console.warn("Block element can only contain Box elements.",r)}return super.add(...t)}set textContent(e){this._textContent.value=e}get textContent(){return this._textContent._value}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(e,t){e.children||(e.children=D3),e.textContent||(e.textContent=Xte),e.glyphs||(e.glyphs=Jte),e.inlines||(e.inlines=Yte),e.layouter||(e.layouter=_3),e.renderer||(e.renderer=die),e.fontFamily||(e.fontFamily=C3),e.fontWeight||(e.fontWeight=S3),e.fontStyle||(e.fontStyle=w3),e.fontSize||(e.fontSize=B3),e.color||(e.color=Kte),e.backgroundColor||(e.backgroundColor=Zte),e.lineBreak||(e.lineBreak=x3),e.letterSpacing||(e.letterSpacing=P3),e.whiteSpace||(e.whiteSpace=mT),e.segments||(e.segments=cie),e.textAlign||(e.textAlign=pie),e.fontKerning||(e.fontKerning=hie)}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class fie extends gN{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this._needsUpdate=!1;for(let s=e.children.length-1;s>=0;s--){const r=e.children[s];r.isUI&&(e.remove(r),r.clear())}e._children._uis=[],this._value&&e.add(new lm({name:"anonymousInline",textContent:this._value}))}}class mie extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class gie extends pi{constructor(){super("layouter",null,!1),this._value=null}update(e,t){}process(e){let t=e._width._value;e._width._auto?t=1/0:t=e._bounds._innerWidth;const s=e._lineHeight._value,r=new mie(new b3);let n=0;e._children._inlines.forEach(d=>{if(!d._inlines.value)return;this._resetInlines(d);const p=d._fontSize._value,f=d._letterSpacing._value*p,m=d._whiteSpace._value,v=d._lineBreak._value,A={WHITESPACE:m,LETTERSPACING:f,BREAKON:v,INNER_WIDTH:t},g=d._whiteSpace._inlineWrapper;n+=d._margin._value.w+d._padding._value.w,d._inlines.value.forEach((b,y,x)=>{const _=r[r.length-1];if(g(x,y,n,A)){if(r.push(new b3(b)),b.offsetX=b.xoffset,b.width===0){n=0;return}b.cumulativeWidth=b.xadvance+f,n=b.cumulativeWidth;return}r[r.length-1].push(b),b.offsetX=n+b.xoffset+b.kerning,b.cumulativeWidth=b.xadvance+b.kerning+f,n+=b.cumulativeWidth,_.length-1===1&&_[_.length-2].width===0&&(b.offsetX-=b.xoffset,n-=b.xoffset)}),n+=d._margin._value.y+d._padding._value.y});const o=e._whiteSpace._inlineCollapser;let a=0,l=0,c=0;r.forEach((d,p)=>{const f=o(d);let m=0,v=0;if(d.forEach(A=>{m=Math.max(m,A.lineHeight),v=Math.max(v,A.lineBase),A.offsetX-=f}),d.lineHeight=m,d.lineBase=v,p===0?c=-(m*s-m)*.5:c-=r[p-1].lineHeight*s,d.y=c,d.x=0,d.forEach(A=>{A.offsetY=c-A.anchor,A.lineHeight<d.lineHeight&&(A.offsetY-=d.lineBase-A.lineBase)}),l+=d.lineHeight*s,d.width=0,d[0]){const A=d[d.length-1];d.width=A.offsetX+A.cumulativeWidth+A.paddingRight+A.marginRight+d[0].offsetX,a=Math.max(a,d.width)}}),r.height=l,r.width=a,this._value=r,t===1/0&&e._bounds.setChildrenWidth(e,r.width),e._height._auto&&e._bounds.setChildrenHeight(e,r.height);const h=e._parent._value;h&&(h._autoSize._needsProcess=!0,h._flexDirection._needsProcess=!0),e._inlineJustificator._needsProcess=!0,e._textAlign._needsProcess=!0,e._overflow._needsUpdate=!0}_resetInlines(e){e._fontSize.process(e)}}class vie extends OM{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput,this._needsProcess=!0}process(e){Aie(e),e._renderer._needsRender=!0}}function Aie(i){const e=i._layouter._value,t=i._textAlign._value,s=i._bounds._innerWidth;for(let r=0;r<e.length;r++){const n=e[r],o=yie(i,n,r===e.length-1),a=i._padding._value,l=i._borderWidth._value,c=(-a.w+a.y)/2+(-l.w+l.y)/2;n.x+=o;for(let h=0;h<n.length;h++)n[h].offsetX+=o-c}if(t.indexOf("justify")===0)for(let r=0;r<e.length;r++){const n=e[r];if(t.indexOf("-")!==-1&&r===e.length-1)return;const o=s-n.width;if(o<=0)return;let a=0;for(let d=1;d<n.length-1;d++)a+=n[d].char===" "?1:0;const l=o/a;let c=1;t==="justify-right"&&(n.reverse(),c=-1);let h=0;for(let d=1;d<=n.length-1;d++){const p=n[d];p.offsetX+=h*c,h+=p.char===" "?l:0}t==="justify-right"&&n.reverse()}}function yie(i,e,t){switch(i._textAlign._value){case"justify-left":case"justify":case"left":return-i._bounds._innerWidth/2;case"justify-right":case"right":return-e.width+i._bounds._innerWidth/2;case"center":return-e.width/2;case"justify-center":return t?-e.width/2:-i._bounds._innerWidth/2;default:console.warn(`textAlign: '${i._textAlign._value}' is not valid`)}}class bie extends LM{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput}}class xie extends EN{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class _ie extends gx{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e)}}class wie extends g3{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class Sie extends pi{constructor(){super("children",null,!1),u(this,"_sortOrder",(e,t)=>e._order._value<t._order._value?-1:e._order._value>t._order._value?1:this._uis.indexOf(e)<this._uis.indexOf(t)?-1:1),this._uis=[],this._inlines=[],this._boxes=[]}update(e,t){this._compute(e),this._needsProcess=!0}process(e){this._compute(e),e._overflow._needsRender=!0}_compute(e){this._uis=e.children.filter(t=>t.visible&&t.isUI),this._inlines=this._uis.filter(t=>t.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class Cie extends pi{constructor(){super("autosize")}process(e){if(e._layouter._value&&e._layouter._value.length){const t=e._layouter._value,s=e._padding._value,r=e._borderWidth._value;e._width._auto&&e._bounds.setOffsetWidth(e,t.width+s.w+s.y+r.w+r.y),e._height._auto&&e._bounds.setOffsetHeight(e,t.height+s.x+s.z+r.x+r.z)}}}class Eie extends y3{constructor(){super("renderer"),this._needsUpdate=!1}render(e){super.render(e);for(const t of e._children._inlines)t._renderer.render(t);e.performAfterUpdate()}}class QA extends NA{constructor(e={},t={}){QA.definePropertiesValues(t,e),super(t,e),QA.init(this)}add(e){const t=[];let s=!1;for(let r=0;r<arguments.length;r++){const n=arguments[r];!n.isUI||n.isInline?(n.isInline&&(s=!0),t.push(n)):console.warn("Block element can only contain Box elements.",n)}return t.length>0&&super.add(...t),s&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(e){this._textContent.value=e}get textContent(){return super.textContent}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(e,t){e.flexDirection=bie,e.justifyContent=UM,e.alignItems=DM,e.bounds=wie,e.autoSize=Cie,e.renderer=Eie,e.children||(e.children=Sie),e.textContent||(e.textContent=fie),e.layouter||(e.layouter=gie),e.lineHeight||(e.lineHeight=xie),e.textAlign||(e.textAlign=vie),e.whiteSpace||(e.whiteSpace=mT),e.fontKerning||(e.fontKerning=_ie),e.segments||(e.segments=k3),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class Mie extends pi{constructor(){super("inlines",null,!1),this._value=[]}process(e){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}}class Tie extends pi{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new A3(e)),e._backgroundMesh.position.x=e._inlines._value[0].offsetX+e._inlines._value[0].width/2,e._backgroundMesh.position.y=e._inlines._value[0].offsetY+e._inlines._value[0].lineBase/2,e._bounds.render(e)}}class Iie extends pi{constructor(){super("bounds",null,!1),this._size=new je.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(e,t){this.output(t),this._needsProcess=!0}process(e){this._offsetWidth=this._innerWidth=e._inlines._value[0].width,this._offsetHeight=this._innerHeight=e._inlines._value[0].height,this._needsRender=!0,e._borderWidth._needsRender=!0,e._borderRadius._needsRender=!0}render(e){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(e){e.size=this._size}}class jA extends sv{constructor(e={}){const t={};jA.definePropertiesValues(t,e),super(t,e),jA.init(this)}clear(){for(const e of this._inlines._value)e.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new je.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];r.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",r):(t.push(r),r.position.z=.005)}return super.add(...t)}static definePropertiesValues(e,t){e.children||(e.children=D3),e.bounds||(e.bounds=Iie),e.inlines||(e.inlines=Mie),e.layouter||(e.layouter=_3),e.renderer||(e.renderer=Tie),e.fontFamily||(e.fontFamily=C3),e.fontWeight||(e.fontWeight=S3),e.fontStyle||(e.fontStyle=w3),e.fontSize||(e.fontSize=B3),e.backgroundColor||(e.backgroundColor=pN),e.lineBreak||(e.lineBreak=x3),e.letterSpacing||(e.letterSpacing=P3),e.whiteSpace||(e.whiteSpace=mT),e.fontKerning||(e.fontKerning=gx),t.backgroundSize||(t.backgroundSize="cover"),t.width||(t.width="100%"),t.height||(t.height="100%"),t.boxSizing||(t.boxSizing="border-box")}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),e._inlines._value=[new Rie(e)],e.backgroundMaterial=new m3,e._renderer.render(e)}}class Rie extends xN{constructor(e){super(),this._uiElement=e}get xadvance(){const e=this._uiElement._padding._value,t=this._uiElement._width;return t._relative?t._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.w+e.y+t.value}get width(){const e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get height(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get anchor(){return this.height}get lineHeight(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get lineBase(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}clear(){this._uiElement=null}}class L3{constructor(e){this._subject=e}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const U3=()=>Cx.update(),F3={BaseProperty:pi,Block:zA,Text:QA,Inline:lm,InlineBlock:jA,MeshUIBaseElement:sv,FontLibrary:Fu,update:U3,MSDFFontMaterialUtils:ko,ShaderChunkUI:f3,Behavior:L3,FontVariant:Yg};typeof global<"u"&&(global.ThreeMeshUI=F3);const Pie=F3;var Bie=gs.w8,N3=gs.cg,gT=gs.gO,kie=gs.wb,vT=gs.zV,Die=gs.HS,Oie=gs.Ec,Mx=gs.gF,Lie=gs.ol,Uie=gs.pz,Fie=gs.tx,Nie=gs.hj,zie=gs.FV,Qie=gs.sV,z3=gs.xv,jie=gs.mx,Gie=gs.gE,Hie=gs.ZP,Q3=gs.Vx;const AT=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:Bie,Behavior:N3,Block:gT,DefaultValues:kie,FontLibrary:vT,FontVariant:Die,InheritableProperty:Oie,Inline:Mx,InlineBlock:Lie,InlineGlyph:Uie,MSDFFontMaterialUtils:Fie,MaterialTransformers:Nie,MeshUIBaseElement:zie,ShaderChunkUI:Qie,Text:z3,TypographicFont:jie,TypographicGlyph:Gie,default:Hie,update:Q3},Symbol.toStringTag,{value:"Module"})),Vie=re("debugshadowcomponents");gT.prototype.interactable={get(){return this.interactive},set(i){this.interactable=i}};const Na=Symbol("shadowDomOwner");class pa extends Me{constructor(){super(...arguments),u(this,"shadowComponent",null),u(this,"_controlsChildLayout",!0),u(this,"_root"),u(this,"_parentComponent")}isRoot(){var e;return((e=this.Root)==null?void 0:e.gameObject)===this.gameObject}get canvas(){const e=this.Root;return e!=null&&e.isCanvas?e:null}markDirty(){Fn.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(e){this._controlsChildLayout=e,this.shadowComponent&&(this.shadowComponent.autoLayout=e)}get Root(){return this._root===void 0&&(this._root=ee.getComponentInParent(this.gameObject,rv)),this._root}get Canvas(){return this.canvas}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(e,t){var s;this.removeShadowComponent();const r=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=ee.getComponentInParent(r,pa),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}e.name=this.name+" ("+(this.constructor.name??"UI")+")",e.autoLayout=this._parentComponent.controlsChildLayout,e[Na]=this,this.setShadowComponentOwner(e);let n=!1;if(((s=this.Root)==null?void 0:s.gameObject)===this.gameObject)this.gameObject.add(e);else{let o=this._parentComponent.shadowComponent;o&&(o?.add(e),n=!0)}this.shadowComponent=e,t&&t.shadowComponent&&this.shadowComponent&&t.shadowComponent.add(this.shadowComponent),Zm&&e.add(new gp(.5)),this.onAfterAddedToScene(),n&&Q3(),Vie&&console.log(this.shadowComponent)}set(e){}setShadowComponentOwner(e){if(e&&(e[Na]===void 0||e[Na]===this)&&(e[Na]=this,e.children))for(const t of e.children)this.setShadowComponentOwner(t)}traverseOwnedShadowComponents(e,t,s){if(e&&e[Na]===t){s(e);for(const r of e.children)this.traverseOwnedShadowComponents(r,t,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(e){this.shadowComponent&&(this.shadowComponent.interactable=e)}}class rv extends pa{awake(){super.awake()}}class rf{static getObject(e){const t=e[Na];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const s=this.tryFindCanvasGroup(e);if(s?.isCanvasGroup===!0&&(t&&(t.canvasGroup=s),s.blocksRaycasts===!1||s.interactable===!1))return!1;const r=Iu(e,n=>{if(n.isGraphic===!0)return n},!1);return t&&r?.isGraphic===!0&&(t.graphic=r),!(r?.raycastTarget===!1||r?.layer===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=Iu(e,s=>{const r=s;if(r.blocksRaycasts!==void 0&&r.interactable!==void 0)return r},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}const nv=re("debugwebxrcontroller");var nf=(i=>(i[i.PhysicalDevice=0]="PhysicalDevice",i[i.Touch=1]="Touch",i))(nf||{}),ql=(i=>(i.SelectStart="select-start",i.SelectEnd="select-end",i.Update="update",i))(ql||{});class Tx extends Me{}const sr=class extends Me{constructor(){super(...arguments),u(this,"webXR"),u(this,"index",-1),u(this,"controllerModel"),u(this,"controller"),u(this,"controllerGrip"),u(this,"hand"),u(this,"handPointerModel"),u(this,"grabbed",null),u(this,"input",null),u(this,"type",0),u(this,"showRaycastLine",!0),u(this,"_wristQuaternion",null),u(this,"movementVector",new S),u(this,"worldRot",new Ue),u(this,"joystick",new Y),u(this,"didRotate",!1),u(this,"didTeleport",!1),u(this,"didChangeScale",!1),u(this,"lastHit",null),u(this,"raycastLine",null),u(this,"_raycastHitPoint",null),u(this,"_connnectedCallback",null),u(this,"_disconnectedCallback",null),u(this,"_selectStartEvt",null),u(this,"_selectEndEvt",null),u(this,"_selectionPressed",!1),u(this,"_selectionPressedLastFrame",!1),u(this,"_selectionStartTime",0),u(this,"_selectionEndTime",0),u(this,"_useSmoothing",!0),u(this,"_isConnected",!1),u(this,"rayRotation",new Ue),u(this,"_pinchStartTime"),u(this,"selectStartCallback",null),u(this,"lastSelectStartObject",null),u(this,"_didNotEndSelection",!1),u(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const i=new $i(this.geometry),e=i.material;return e.color=this.raycastColor,i.layers.set(2),i.name="line",i.scale.z=1,i}static CreateRaycastHitPoint(){const i=new Po(.5,22,22),e=new hi({color:this.raycastColor}),t=new xe(i,e);return t.visible=!1,t.layers.set(2),t}static Create(i,e,t,s){const r=t?ee.addNewComponent(t,sr,!1):new sr;r.webXR=i,r.index=e,r.type=s;const n=i.context;r.controller=n.renderer.xr.getController(e),r.controllerGrip=n.renderer.xr.getControllerGrip(e),r.controllerModel=this.Factory.createControllerModel(r.controller),r.controllerGrip.add(r.controllerModel),r.hand=n.renderer.xr.getHand(e);const o=new Dp;Bg(o,n),r.webXR.handModelPath&&r.webXR.handModelPath!==""?o.setPath(Sc(i.sourceId,r.webXR.handModelPath)):o.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const a=new fZ(r.hand,o);return r.hand.add(a),r.hand.traverse(l=>l.layers.set(2)),r.handPointerModel=new xZ(r.hand,r.controller),r.controller.addEventListener("connected",l=>{r.setControllerLayers(r.controllerModel,2),r.setControllerLayers(r.controllerGrip,2),r.setControllerLayers(r.hand,2),setTimeout(()=>{r.setControllerLayers(r.controllerModel,2),r.setControllerLayers(r.controllerGrip,2),r.setControllerLayers(r.hand,2)},1e3)}),r.hand.addEventListener("connected",l=>{var c;if(l.data.hand){i.Rig&&i.Rig.add(r.hand),r.type=0,r.handPointerModel.traverse(d=>d.layers.set(2)),(c=r.handPointerModel.pointerObject)==null||c.traverse(d=>d.layers.set(2));const h=r.hand.joints;if(h)for(const d of Object.keys(h)){const p=h[d];p.parent||r.hand.add(p)}}}),r}static addEventListener(i,e){const t=this.eventSubs[i]??[];t.push(e),this.eventSubs[i]=t}static removeEventListener(i,e){if(!e)return;const t=this.eventSubs[i]??[],s=t.indexOf(e);s>=0&&t.splice(s,1),this.eventSubs[i]=t}get isUsingHands(){var i;return((i=this.input)==null?void 0:i.hand)!=null}get wrist(){if(!this.hand)return null;const i=this.hand.joints;return i?i.wrist:null}getWristQuaternion(){const i=this.wrist;return i?(this._wristQuaternion||(this._wristQuaternion=new Ue),Rs(i).multiply(this._wristQuaternion.setFromEuler(new Ys(-Math.PI/4,0,0)))):null}get selectionDown(){return this._selectionPressed&&!this._selectionPressedLastFrame}get selectionUp(){return!this._selectionPressed&&this._selectionPressedLastFrame}get selectionPressed(){return this._selectionPressed}get selectionClick(){return this._selectionEndTime-this._selectionStartTime<.3}get raycastHitPoint(){return this._raycastHitPoint}get useSmoothing(){return this._useSmoothing}awake(){if(!this.controller){console.warn("Missing Controller!!!",this);return}this._connnectedCallback=this.onSourceConnected.bind(this),this._disconnectedCallback=this.onSourceDisconnected.bind(this),this._selectStartEvt=this.onSelectStart.bind(this),this._selectEndEvt=this.onSelectEnd.bind(this),this.type===1&&(this.controllerGrip.addEventListener("connected",this._connnectedCallback),this.controllerGrip.addEventListener("disconnected",this._disconnectedCallback),this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt))}onDestroy(){var i,e,t;this.type===1&&(this.controllerGrip.removeEventListener("connected",this._connnectedCallback),this.controllerGrip.removeEventListener("disconnected",this._disconnectedCallback),this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),(i=this.hand)==null||i.clear(),(e=this.controllerGrip)==null||e.clear(),(t=this.controller)==null||t.clear()}onEnable(){var i,e,t,s,r;this.hand&&(this.hand.name="Hand"),this.controllerGrip&&(this.controllerGrip.name="ControllerGrip"),this.controller&&(this.controller.name="Controller"),this.raycastLine&&(this.raycastLine.name="RaycastLine;"),this.webXR.Controllers.indexOf(this)<0&&this.webXR.Controllers.push(this),this.raycastLine||(this.raycastLine=sr.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=sr.CreateRaycastHitPoint()),(i=this.webXR.Rig)==null||i.add(this.hand),(e=this.webXR.Rig)==null||e.add(this.controllerGrip),(t=this.webXR.Rig)==null||t.add(this.controller),(s=this.webXR.Rig)==null||s.add(this.raycastLine),(r=this.raycastLine)==null||r.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),nv&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var i,e,t,s,r;(i=this.hand)==null||i.removeFromParent(),(e=this.controllerGrip)==null||e.removeFromParent(),(t=this.controller)==null||t.removeFromParent(),(s=this.raycastLine)==null||s.removeFromParent(),(r=this._raycastHitPoint)==null||r.removeFromParent();const n=this.webXR.Controllers.indexOf(this);n>=0&&this.webXR.Controllers.splice(n,1)}onSourceConnected(i){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,i);return}this._isConnected=!0,this.input=i.data,this.type===1&&(this.onSelectStart(),this.createPointerEvent("down"))}onSourceDisconnected(i){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",i);return}this._isConnected=!1,this.type===1&&(this.onSelectEnd(),this.createPointerEvent("up")),this.input=null}createPointerEvent(i){switch(i){case"down":this.context.input.createPointerDown({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break;case"move":break;case"up":this.context.input.createPointerUp({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break}}update(){this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const i=sr.eventSubs.update;if(i&&i.length>0)for(const s of i)s(this);let e=1;this.type===0?e=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(e=this.context.time.deltaTime/.3),this.rayRotation.slerp(Rs(this.controller),this.useSmoothing?e:1);const t=yt(this.controller);if(this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine){const s=this.showRaycastLine&&this.type!==1;if(this.type===1)this.raycastLine.visible=!1;else if(this.isUsingHands){this.raycastLine.visible=!this.grabbed&&s,ts(this.raycastLine,t);const r=this.hand.joints;if(r&&r.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const n=this.getWristQuaternion();n&&this.rayRotation.copy(n)}ln(this.raycastLine,this.rayRotation)}else this.raycastLine.visible=s,ln(this.raycastLine,this.rayRotation),ts(this.raycastLine,t)}this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(i){var e,t;if(this.lastHit=null,!i||i.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=i.inputSources[this.index]),!this.input)return;const s=this.webXR.Rig;if(!s)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const r=(t=(e=this.input)==null?void 0:e.gamepad)==null?void 0:t.buttons;switch(this.input.handedness){case"left":const n=3*sr.MovementSpeedFactor,o=2,a=et.clamp01(this.joystick.length()*2),l=this.joystick.x>0?1:-1;let c=Math.pow(this.joystick.x,o);c*=l,c*=a;const h=this.joystick.y>0?1:-1;let d=Math.pow(this.joystick.y,o);d*=h,c*=a,s.getWorldQuaternion(this.worldRot),this.movementVector.set(c,0,d),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(n*this.context.time.deltaTime),s.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(s,r);break;case"right":const p=this.joystick.x,f=Math.abs(p);if(f<.4)this.didRotate=!1;else if(f>.5&&!this.didRotate){const m=p>0?-1:1;s.rotateY(et.toRadians(30*m)),this.didRotate=!0}this.runTeleport(s,r);break}}runTeleport(i,e){var t,s,r;let n=-this.joystick.y;if((t=this.hand)!=null&&t.visible&&!this.grabbed){const c=this.handPointerModel.isPinched();c&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),c&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(n=this.handPointerModel.isPinched()?1:0),c||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;let o=n>.5&&this.webXR.IsInVR,a=this.webXR.Rig?((r=(s=this.webXR.Rig)==null?void 0:s.scale)==null?void 0:r.x)<.999:!1,l=null;if(e&&this.input&&!this.input.hand)for(let c=0;c<e.length;c++){const h=e[c];if(c===4)if(h.pressed&&!this.didChangeScale&&this.webXR.IsInVR){this.didChangeScale=!0;const d=this.webXR.Rig;if(d)if(a){a=!1,d.scale.set(1,1,1),l=1,sr.MovementSpeedFactor=1;const p=this.context.mainCamera;sr.PreviousCameraFarDistance&&(p.far=sr.PreviousCameraFarDistance)}else{a=!0,o=!0,l=.1,sr.MovementSpeedFactor=l*2;const p=this.context.mainCamera;sr.PreviousCameraFarDistance=p.far,p.far/=l}}else h.pressed||(this.didChangeScale=!1)}if(o){if(!this.didTeleport){const c=this.raycast();if(this.didTeleport=!0,c&&c.length>0){const h=c[0];if(a||this.isValidTeleportTarget(h.object)){const d=h.point;ts(i,d)}}}}else n<.1&&(this.didTeleport=!1);l!==null&&(i.scale.set(l,l,l),i.updateMatrixWorld())}isValidTeleportTarget(i){return ee.getComponentInParent(i,Tx)!=null}updateStick(i){var e;!i||!i.gamepad||((e=i.gamepad.axes)==null?void 0:e.length)<4||(this.joystick.x=i.gamepad.axes[2],this.joystick.y=i.gamepad.axes[3])}updateLastHit(){var i;const e=this.raycast(),t=e?e[0]:null;this.lastHit=t;let s=1;if(this.webXR.Rig&&(s/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=s*(((i=this.lastHit)==null?void 0:i.distance)??9999);const r=this.raycastLine.material;t!=null?r.color=sr.raycastColor:r.color=sr.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const r=et.clamp(this.lastHit.distance*.01*s,.015,.1);this._raycastHitPoint.scale.set(r,r,r)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return t}onSelectStart(){this.context.connection.allowEditing&&(this.selectStartCallback=()=>this.onHandleSelectStart())}onHandleSelectStart(){this.selectStartCallback=null,this._selectionPressed=!0,this._selectionStartTime=this.context.time.time,this._selectionEndTime=1e3;let i=null,e=!1;if(this.isUsingHands?(i=this.overlap(),i.length<=0?(i=this.raycast(),e=!1):e=!0):i=this.raycast(),nv&&console.log("onHandleSelectStart","close grab? "+e,"intersections",i),i&&i.length>0)for(const t of i){const s=t.object;this.lastSelectStartObject=s;const r={selected:s,grab:s},n=sr.eventSubs["select-start"];if(n&&n.length>0)for(const o of n)o(this,r);r.grab!==s&&nv&&console.log("Grabbed object changed","original",s,"new",r.grab),r.grab&&(this.grabbed=za.TryTake(this,r.grab,t,e));break}else{const t=sr.eventSubs["select-start"],s={selected:null,grab:null};if(t&&t.length>0)for(const r of t)r(this,s)}}onSelectEnd(){var i;if(this.isUsingHands&&this.handPointerModel.pinched){this._didNotEndSelection=!0;return}if(!this._selectionPressed)return;this.selectStartCallback=null,this._selectionPressed=!1,this._selectionEndTime=this.context.time.time;const e={grab:((i=this.grabbed)==null?void 0:i.selected)??this.lastSelectStartObject},t=sr.eventSubs["select-end"];if(t&&t.length>0)for(const s of t)s(this,e);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(i){return!(!i||ee.isActiveInHierarchy(i)===!1||rf.isInteractable(i)===!1)}setControllerLayers(i,e){var t,s;if(i&&(i.layers.set(e),i.children))for(const r of i.children)((t=this.grabbed)==null?void 0:t.selected)===r||((s=this.grabbed)==null?void 0:s.selectedMesh)===r||this.setControllerLayers(r,e)}getRay(){const i=new xa;return i.origin.copy(yt(this.controller)),i.direction.set(0,0,-1).applyQuaternion(this.rayRotation),i}overlap(){const i=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(nv&&(!this.closeGrabBoundingBoxHelper&&i&&(this.closeGrabBoundingBoxHelper=new Cy(i,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&i&&this.closeGrabBoundingBoxHelper.setFromObject(i)),!i)return new Array;const e=yt(i).clone();return this.context.physics.sphereOverlap(e,.02)}raycast(){const i=new Go;i.layerMask=new to,i.layerMask.enableAll(),i.layerMask.disable(2),i.ray=this.getRay();const e=this.context.physics.raycast(i);for(let t=0;t<e.length;t++){const s=e[t],r=s.object;if(!this.testIsVisible(r)){e.splice(t,1),t--;continue}s.object=rf.getObject(r);break}return e}};let vs=sr;u(vs,"Factory",new kZ),u(vs,"raycastColor",new Ae(.9,.3,.3)),u(vs,"raycastNoHitColor",new Ae(.6,.6,.6)),u(vs,"geometry",new At().setFromPoints([new S(0,0,0),new S(0,0,-1)])),u(vs,"handModels",{}),u(vs,"eventSubs",{}),u(vs,"PreviousCameraFarDistance"),u(vs,"MovementSpeedFactor",1);var Ix=(i=>(i.WillTake="WillTake",i.DidTake="DidTake",i.WillFree="WillFree",i.DidFree="DidFree",i))(Ix||{});const gn=class{constructor(){u(this,"sync",null),u(this,"selected",null),u(this,"selectedParent",null),u(this,"selectedMesh",null),u(this,"controller",null),u(this,"grabTime",0),u(this,"grabUUID",""),u(this,"isCloseGrab",!1),u(this,"originalMaterial",null),u(this,"usageMarker",null),u(this,"rigidbodies",null),u(this,"didReparent",!1),u(this,"grabDistance",0),u(this,"interactable",null),u(this,"positionSource",null),u(this,"grabPoint",new S),u(this,"localPositionOffsetToGrab",null),u(this,"localPositionOffsetToGrab_worldSpace",new S),u(this,"localQuaternionToGrab",new Ue(0,0,0,1)),u(this,"targetDir",null),u(this,"quaternionLerp",null),u(this,"controllerDir",new S),u(this,"controllerWorldPos",new S),u(this,"lastControllerWorldPos",new S),u(this,"controllerPosDelta",new S),u(this,"totalChangeAlongDirection",0),u(this,"rigPositionLastFrame",new S)}static AddEventListener(i,e){return gn.Events[i]||(gn.Events[i]=[]),gn.Events[i].push(e),e}static RemoveEventListener(i,e){if(!e||!gn.Events[i])return;const t=gn.Events[i].indexOf(e);t>=0&&gn.Events[i].splice(t,1)}static Register(i){this.Current.find(e=>e===i)||this.Current.push(i)}static Remove(i){const e=this.Current.indexOf(i);e>=0&&this.Current.splice(e,1)}static TryTake(i,e,t,s){const r=ee.getComponentInParent(e,Yp);if(r)e=r.gameObject;else return nv&&console.warn("Prevented taking object that is not interactable",e),null;let n=e;const o=ee.getComponentInParent(e,mh);o&&(o.requestOwnership(),n=o.gameObject);for(const l of this.Current)if(l.selected===n)return l.controller===i||(l.free(),l.Take(i,n,e,o,r,t,s)),l;const a=new gn;return a.Take(i,n,e,o,r,t,s),a}Take(i,e,t,s,r,n,o){var a,l;if(console.assert(e!==null,"Expected object to be taken but was",e),i.isUsingHands?this.positionSource=o?i.wrist:i.controller:this.positionSource=i.controller,!this.positionSource)return console.warn("No position source"),this;const c={controller:i,take:e,hit:t,sync:s,interactable:r};(a=gn.Events.WillTake)==null||a.forEach(m=>m(this,c));const h=t;h!=null&&h.material&&(this.originalMaterial=h.material,Array.isArray(h.material)||(h.material=h.material.clone(),h.material&&h.material.emissive&&(h.material.emissive.b=.2))),this.selected=e,this.selectedParent||(this.selectedParent=e.parent),this.selectedMesh=h,this.controller=i,this.interactable=r,this.isCloseGrab=o,this.didReparent=!1,this.sync=s,this.grabTime=i.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=ee.addNewComponent(this.selected,Jp),this.rigidbodies=ee.getComponentsInChildren(this.selected,ji),yt(this.positionSource,this.lastControllerWorldPos);const d=()=>o?this.lastControllerWorldPos.clone():n.point.clone();this.grabDistance=d().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(d());const p=i.isUsingHands&&o?this.controller.getWristQuaternion().clone():i.rayRotation.clone();Rs(this.selected,this.localQuaternionToGrab).premultiply(p.invert());const f=this.controller.webXR.Rig;return f&&this.rigPositionLastFrame.copy(yt(f)),Wr.Add(i.context,this.selected),gn.Register(this),this.sync&&(this.sync.fastMode=!0),(l=gn.Events.DidTake)==null||l.forEach(m=>m(this,c)),this}free(){var i,e,t,s;if(!this.selected)return;const r={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(i=gn.Events.WillFree)==null||i.forEach(a=>a(this,r)),Wr.Remove(this.controller.context,this.selected),gn.Remove(this),this.sync&&(this.sync.fastMode=!1);const n=this.selectedMesh;n&&this.originalMaterial&&n.material&&(n.material=this.originalMaterial);const o=this.selected;if(this.didReparent&&o.parent){const a=this.selectedParent;a?a.attach(o):(e=this.controller)==null||e.context.scene.attach(o)}if((t=this.usageMarker)==null||t.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const a of this.rigidbodies)a.wakeUp(),a.setVelocity(a.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(s=gn.Events.DidFree)==null||s.forEach(a=>a(this,r))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),yt(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const i=this.controller.webXR.Rig;if(i){const e=yt(i),t=this.rigPositionLastFrame.sub(e);this.controllerPosDelta.add(t),this.rigPositionLastFrame.copy(e)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var i;if(this.rigidbodies)for(const e of this.rigidbodies)e.resetVelocities();if(this.sync&&this.controller&&this.controller.context.connection.isInRoom&&this.controller.context.time.time-this.grabTime>3&&this.sync.hasOwnership()===!1&&(console.log("no ownership, will leave",this.sync.guid),this.free()),!(this.interactable&&!this.interactable.canGrab)){if(!this.didReparent&&this.selected&&this.controller){const e=((i=this.controller.webXR.Rig)==null?void 0:i.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let t=1;this.controller.type===0&&(t=Math.max(0,1+this.totalChangeAlongDirection*2/e),t=t*t*t),this.grabDistance/e<.8&&(t=1),this.targetDir||(this.targetDir=new S),this.targetDir.set(0,0,-this.grabDistance*t);const s=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),r=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=r.clone()),this.quaternionLerp.slerp(r,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),ln(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(s),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(yt(this.selected)),s.sub(this.localPositionOffsetToGrab_worldSpace)),ts(this.selected,s)}if(this.rigidbodies!=null)for(const e of this.rigidbodies)e.wakeUp();_n.markDirty(this.selected,!0)}}};let za=gn;u(za,"Events",{}),u(za,"Current",[]);var Wie=Object.defineProperty,qie=Object.getOwnPropertyDescriptor,yT=(i,e,t,s)=>{for(var r=s>1?void 0:s?qie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Wie(e,t,r),r};class zu extends Me{constructor(){super(...arguments),u(this,"objectBounds",!1),u(this,"color"),u(this,"isGizmo",!0),u(this,"_gizmoObject",null),u(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!Zm||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new Cy(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=bF(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),On.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){for(var e;this._boxHelper;)(e=this._boxHelper)==null||e.update(),yield}}yT([w()],zu.prototype,"objectBounds",2),yT([w(Ae)],zu.prototype,"color",2),yT([w()],zu.prototype,"isGizmo",2);const Xie=re("debugrig");class Rx extends Me{awake(){if(Xie){const e=new De;e.position.y+=.5,this.gameObject.add(e);const t=e.addNewComponent(zu);t&&(t.isGizmo=!1)}}}class of{constructor(){u(this,"bb",null),u(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}w(){return this.bb.readFloat32(this.bb_pos+12)}static sizeOf(){return 16}static createVec4(e,t,s,r,n){return e.prep(4,16),e.writeFloat32(n),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(t),e.offset()}}class Tr{constructor(){u(this,"bb",null),u(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsVrUserStateBuffer(e,t){return(t||new Tr).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsVrUserStateBuffer(e,t){return e.setPosition(e.position()+Hy),(t||new Tr).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}time(){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):this.bb.createLong(0,0)}avatarId(e){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__string(this.bb_pos+t,e):null}position(e){const t=this.bb.__offset(this.bb_pos,10);return t?(e||new Un).__init(this.bb_pos+t,this.bb):null}rotation(e){const t=this.bb.__offset(this.bb_pos,12);return t?(e||new of).__init(this.bb_pos+t,this.bb):null}scale(){const e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readFloat32(this.bb_pos+e):0}posLeftHand(e){const t=this.bb.__offset(this.bb_pos,16);return t?(e||new Un).__init(this.bb_pos+t,this.bb):null}posRightHand(e){const t=this.bb.__offset(this.bb_pos,18);return t?(e||new Un).__init(this.bb_pos+t,this.bb):null}rotLeftHand(e){const t=this.bb.__offset(this.bb_pos,20);return t?(e||new of).__init(this.bb_pos+t,this.bb):null}rotRightHand(e){const t=this.bb.__offset(this.bb_pos,22);return t?(e||new of).__init(this.bb_pos+t,this.bb):null}static startVrUserStateBuffer(e){e.startObject(10)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addTime(e,t){e.addFieldInt64(1,t,e.createLong(0,0))}static addAvatarId(e,t){e.addFieldOffset(2,t,0)}static addPosition(e,t){e.addFieldStruct(3,t,0)}static addRotation(e,t){e.addFieldStruct(4,t,0)}static addScale(e,t){e.addFieldFloat32(5,t,0)}static addPosLeftHand(e,t){e.addFieldStruct(6,t,0)}static addPosRightHand(e,t){e.addFieldStruct(7,t,0)}static addRotLeftHand(e,t){e.addFieldStruct(8,t,0)}static addRotRightHand(e,t){e.addFieldStruct(9,t,0)}static endVrUserStateBuffer(e){return e.endObject()}static finishVrUserStateBufferBuffer(e,t){e.finish(t)}static finishSizePrefixedVrUserStateBufferBuffer(e,t){e.finish(t,void 0,!0)}}const j3=re("debugxr"),ov=re("debugavatar"),bT="VRUS";TC(bT,Tr.getRootAsVrUserStateBuffer);function xT(){return new Date().getTime()}function Yie(i){let e=i&4294967295,t=i/Math.pow(2,32)&1048575;return sl.create(e,t)}const Px=class{constructor(i){u(this,"guid"),u(this,"time"),u(this,"avatarId"),u(this,"position",new S),u(this,"rotation",new mt),u(this,"scale",1),u(this,"posLeftHand",new S),u(this,"posRightHand",new S),u(this,"rotLeftHand",new Ue),u(this,"rotRightHand",new Ue),this.guid=i}update(i,e,t,s,r){var n,o,a,l,c,h;this.time=xT(),this.avatarId=r,this.position.set(e.x,e.y,e.z),i&&this.position.applyMatrix4(i.matrixWorld);let d=Px.quat0;const p=Px.quat1;d.set(t.x,t.y,t.z,t.w),d=d.multiplyQuaternions(d,Px.invertRotation),i&&(i.getWorldQuaternion(p),d.multiplyQuaternions(p,d)),this.rotation.set(d.x,d.y,d.z,d.w),this.scale=i.scale.x;const f=(n=s.LeftController)==null?void 0:n.controllerGrip;f&&(f.getWorldPosition(this.posLeftHand),f.getWorldQuaternion(this.rotLeftHand));const m=(o=s.RightController)==null?void 0:o.controllerGrip;if(m&&(m.getWorldPosition(this.posRightHand),m.getWorldQuaternion(this.rotRightHand)),(l=(a=s.LeftController)==null?void 0:a.hand)!=null&&l.visible){const v=s.LeftController.wrist;v&&(v.getWorldPosition(this.posLeftHand),v.getWorldQuaternion(this.rotLeftHand))}if((h=(c=s.RightController)==null?void 0:c.hand)!=null&&h.visible){const v=s.RightController.wrist;v&&(v.getWorldPosition(this.posRightHand),v.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(i,e){i.clear();const t=i.createString(this.guid),s=i.createString(this.avatarId);Tr.startVrUserStateBuffer(i),Tr.addGuid(i,t),Tr.addTime(i,Yie(this.time)),Tr.addAvatarId(i,s),Tr.addPosition(i,Un.createVec3(i,this.position.x,this.position.y,this.position.z)),Tr.addRotation(i,of.createVec4(i,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),Tr.addScale(i,this.scale),Tr.addPosLeftHand(i,Un.createVec3(i,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),Tr.addPosRightHand(i,Un.createVec3(i,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),Tr.addRotLeftHand(i,of.createVec4(i,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),Tr.addRotRightHand(i,of.createVec4(i,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const r=Tr.endVrUserStateBuffer(i);i.finish(r,bT);const n=i.asUint8Array();e.sendBinary(n)}setFromBuffer(i,e){if(!i)return;this.guid=i,this.time=e.time().toFloat64();const t=e.avatarId();t&&(this.avatarId=t);const s=e.position();s&&this.position.set(s.x(),s.y(),s.z());const r=e.rotation();r&&this.rotation.set(r.x(),r.y(),r.z(),r.w());const n=e.posLeftHand();n&&this.posLeftHand.set(n.x(),n.y(),n.z());const o=e.posRightHand();o&&this.posRightHand.set(o.x(),o.y(),o.z());const a=e.rotLeftHand();a&&this.rotLeftHand.set(a.x(),a.y(),a.z(),a.w());const l=e.rotRightHand();l&&this.rotRightHand.set(l.x(),l.y(),l.z(),l.w()),this.scale=e.scale()}};let Xl=Px;u(Xl,"invertRotation",new Ue().setFromAxisAngle(new S(0,1,0),Math.PI)),u(Xl,"quat0",new Ue),u(Xl,"quat1",new Ue);class av extends Me{constructor(){super(...arguments),u(this,"webXR",null),u(this,"debugAvatarUser",null),u(this,"voip",null),u(this,"tempState",new Xl("")),u(this,"_removeAvatarsList",[]),u(this,"eventSub_ConnectionEvent",null),u(this,"eventSub_WebXRStartEvent",null),u(this,"eventSub_WebXREndEvent",null),u(this,"eventSub_WebXRUpdateEvent",null),u(this,"avatars",{}),u(this,"localAvatar",null),u(this,"k_LocalAvatarNoNetworkingGuid","local"),u(this,"ownership",null),u(this,"xrState",null),u(this,"builder",new nm(1024))}async awake(){if(this.webXR||(this.webXR=ee.getComponent(this.gameObject,wt)),this.webXR||(this.webXR=ee.findObjectOfType(wt,this.context)),!this.webXR&&(console.log("Missing webxr component"),this.webXR=ee.findObjectOfType(wt,this.context),!this.webXR)){console.error("Could not find webxr component");return}if(this.voip||(this.voip=ee.findObjectOfType(yc,this.context)),ov){const e="debug-avatar-"+ov,t=new ph(this.context,e,this.webXR);if(this.debugAvatarUser=t,typeof ov=="string"&&ov.length>0)if(await t.setAvatarOverride(ov)){const s=new Xl(e);s.position.y+=1;const r=.5;s.posLeftHand.y+=r,s.posLeftHand.x+=r,s.posRightHand.y+=r,s.posRightHand.x-=r,t.tryUpdate(s,0)}else t.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=ee.getComponent(this.gameObject,wt),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),wt.addEventListener(_i.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),wt.addEventListener(_i.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),wt.addEventListener(_i.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen(qi.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",e=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",e=>{const t=e.id!==null&&e.id!==void 0;if(t&&(console.log("webxr user left evt"),t)){const s=this.avatars[e.id];s?.destroy(),this.avatars[e.id]=void 0}}),this.context.connection.beginListenBinary(bT,e=>{const t=e.guid();if(!t)return;const s=e.time().toFloat64(),r=this.tempState;r.setFromBuffer(t,e);const n=this.onTryGetAvatar(t,s);n?.tryUpdate(r,s)}),this.context.connection.beginListen("vr-session-update",e=>{const t=e.guid,s=e.time,r=this.onTryGetAvatar(t,s);r?.tryUpdate(e,s)})}onTryGetAvatar(e,t){if(e===this.context.connection.connectionId)return null;const s=new Date().getTime()-t;if(s>5e3)return j3&&console.log("old data",s,e),null;let r=this.avatars[e];if(r===void 0)try{console.log("create new avatar");const n=new ph(this.context,e,this.webXR);r=n,this.avatars[e]=n}catch(n){this.avatars[e]=null,console.error(n)}return r}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen(qi.JoinedRoom,this.eventSub_ConnectionEvent),wt.removeEventListener(_i.XRStarted,this.eventSub_WebXRStartEvent),wt.removeEventListener(_i.XRUpdate,this.eventSub_WebXRUpdateEvent),wt.removeEventListener(_i.XRStopped,this.eventSub_WebXREndEvent)}update(){const e=xT();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=e),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const t in this.avatars){const s=this.avatars[t];s&&s.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const e=xT();for(const t in this.avatars){const s=this.avatars[t];if(!s){this._removeAvatarsList.push(t);continue}e-s.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),s.destroy(),this.avatars[t]=void 0)}for(const t of this._removeAvatarsList)delete this.avatars[t];this._removeAvatarsList.length=0}buildLocalAvatar(){var e;if(this.localAvatar)return;const t=((e=this.context.connection)==null?void 0:e.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new ph(this.context,t,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var e,t,s;j3&&console.log("Hey you are connected as "+this.context.connection.connectionId),((e=this.localAvatar)==null?void 0:e.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null)}onXRSessionStart(e){var t,s,r;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null,this.avatars)for(const n in this.avatars)(r=this.avatars[n])==null||r.updateFlags()}onXRSessionEnded(e){var t;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(e){this.xrState??(this.xrState=new Xl(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new sb(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:t,xr:s,rig:r}=e,n=t.getViewerPose(s.getReferenceSpace());if(!n)return;const o=n?.transform,a=o.position,l=o.orientation;this.xrState.update(r,a,l,this.webXR,this.getAvatarId()),this.localAvatar&&(this.context.connection.connectionId&&(this.localAvatar.guid=this.context.connection.connectionId),this.localAvatar.tryUpdate(this.xrState,0)),!(this.ownership&&!this.ownership.hasOwnership&&this.context.connection.isConnected&&(this.context.time.frameCount%120===0&&this.ownership.requestOwnership(),!this.ownership.hasOwnership))&&(!this.context.connection.isConnected||!this.context.connection.connectionId||this.xrState.sendAsBuffer(this.builder,this.context.connection))}getAvatarId(){return re("avatar")??null}}var Jie=Object.defineProperty,Kie=Object.getOwnPropertyDescriptor,af=(i,e,t,s)=>{for(var r=s>1?void 0:s?Kie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Jie(e,t,r),r};const _T=re("debugwebxr");async function G3(){return qA()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function H3(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let lv=!1,cv=!1;G3().then(i=>lv=i),H3().then(i=>cv=i);var _i=(i=>(i.XRStarted="xrStarted",i.XRStopped="xrStopped",i.XRUpdate="xrUpdate",i.RequestVRSession="requestVRSession",i.ModifyAROptions="modify-ar-options",i))(_i||{}),lf;const ks=(lf=class extends Me{constructor(){super(...arguments),u(this,"enableVR",!0),u(this,"enableAR",!0),u(this,"defaultAvatar"),u(this,"handModelPath",""),u(this,"createVRButton",!0),u(this,"createARButton",!0),u(this,"controllers",[]),u(this,"rig"),u(this,"isInit",!1),u(this,"_requestedAR",!1),u(this,"_requestedVR",!1),u(this,"_isInAR",!1),u(this,"_isInVR",!1),u(this,"_arButton"),u(this,"_vrButton"),u(this,"webAR",null),u(this,"_transformOrientation",new Ue),u(this,"_currentHeadPose",null),u(this,"_originalCameraParent",null),u(this,"_originalCameraPosition",new S),u(this,"_originalCameraRotation",new Ue),u(this,"_originalXRRigParent",null),u(this,"_originalXRRigPosition",new S),u(this,"_originalXRRigRotation",new Ue),u(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(lv||cv)}static get IsARSupported(){return lv}static get IsVRSupported(){return cv}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(i,e){return this.events.addEventListener(i,e),e}static removeEventListener(i,e){return this.events.removeEventListener(i,e),e}static dispatchEvent(i,e){this.events.dispatchEvent({type:i,detail:e})}static createVRButton(i,e){ks.XRSupported?i.__internalAwake():console.warn("WebXR is not supported on this device");const t={optionalFeatures:ks.OptionalFeatures_VR},s=SM.createButton(i.context.renderer,t);return s.classList.add("webxr-ar-button"),s.classList.add("webxr-button"),this.resetButtonStyles(s),(e?.registerClick??!0)&&s.addEventListener("click",i.onClickedVRButton.bind(i)),s}static createARButton(i,e){var t;i.__internalAwake();const s=(t=i.webAR)==null?void 0:t.getAROverlayContainer(),r={optionalFeatures:[...this.OptionalFeatures_AR]};s?(r.domOverlay={root:s},r.optionalFeatures.push("dom-overlay"),r.optionalFeatures.push("hit-test")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const n=sZ.createButton(i.context.renderer,r,this.onModifyAROptions.bind(this));return n.classList.add("webxr-ar-button"),n.classList.add("webxr-button"),ks.resetButtonStyles(n),(e?.registerClick??!0)&&n.addEventListener("click",i.onClickedARButton.bind(i)),n}static onModifyAROptions(i){ks.dispatchEvent("modify-ar-options",i)}static resetButtonStyles(i){i&&(i.style.position="",i.style.bottom="",i.style.left="")}endSession(){const i=this.context.renderer.xr.getSession();i&&i.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var i,e;return this.controllers.length>0&&((i=this.controllers[0].input)==null?void 0:i.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((e=this.controllers[1].input)==null?void 0:e.handedness)==="left"?this.controllers[1]:null}get RightController(){var i,e;return this.controllers.length>0&&((i=this.controllers[0].input)==null?void 0:i.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((e=this.controllers[1].input)==null?void 0:e.handedness)==="right"?this.controllers[1]:null}get ARButton(){return this._arButton}get VRButton(){return this._vrButton}get IsInVR(){return this._isInVR}get IsInAR(){return this._isInAR}awake(){if(this.defaultAvatar&&typeof this.defaultAvatar=="string"&&(this.defaultAvatar=wr.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!ee.findObjectOfType(av,this.context)){const i=ee.addNewComponent(this.gameObject,av,!1);i.webXR=this}this.webAR=new uv(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(lo("WebXR only works on https"),console.warn("WebXR only works on https. https://engine.needle.tools/docs/xr.html"))}onEnable(){if(this.isInit||!this.enableAR&&!this.enableVR)return;this.isInit=!0,this.context.renderer.xr.enabled=!0,ks.XRSupported;let i,e;const t=document.createElement("div");t.classList.add("webxr-buttons"),t.style.cssText=`
5009
+ `&&i.length>1&&T3([t],i[i.length-2]),e.offsetX}function oie(i){if(!i[0])return 0;let e=[],t;for(let s=0;s<i.length;s++){const r=i[s];if(r.char&&E3[r.char]&&i.length>s){e.push(r),t=i[s+1];continue}break}I3(e,t),e=[],t=null;for(let s=i.length-1;s>0;s--){const r=i[s];if(r.char&&E3[r.char]&&s>0){e.push(r),t=i[s-1];continue}break}return T3(e,t),i[0].offsetX}function aie(i){return i[0]?i[0].offsetX:0}function T3(i,e){if(e)for(let t=0;t<i.length;t++){const s=i[t];s.fontFactor=0,s.offsetX=e.offsetX+e.cumulativeWidth,s.cumulativeWidth=0}}function I3(i,e){if(e)for(let t=0;t<i.length;t++){const s=i[t];s.fontFactor=0,s.offsetX=e.offsetX,s.cumulativeWidth=0}}function R3(i,e,t,s){if(s=s||0,!i[e])return s;const r=i[e];return r.lineBreak?s+r.xadvance:R3(i,e+1,t,s+r.xadvance+r.xoffset+r.kerning+t.LETTERSPACING)}function lie(i,e,t,s){return!i||!i.char||e+t<s.INNER_WIDTH?!1:s.BREAKON.indexOf(i.char)>-1}class P3 extends TN{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._fontSize._needsProcess=!0,e._layouter._needsProcess=!0}}class B3 extends Bi{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(e){this._value=this._inheritedInput,e._font._fontVariant&&(e._bounds._needsProcess=!0,e._layouter._needsProcess=!0)}process(e){if(!e._font._fontVariant||!e._font._fontVariant.isReady)return;const t=this._value/e._font._fontVariant.typographic.size,s=e._inlines._value;for(let r=0;r<s.length;r++){const n=s[r];n.resetOffsets(),n.fontSize=this._value,n.fontFactor=t}}get value(){return this._value}}class k3 extends IN{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(e,t){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(e)),e._layouter._needsUpdate=!0}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class cie extends k3{constructor(){super(),this._value="inherit"}}class hie extends gx{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._parent._value._layouter._needsProcess=!1}process(e){if(this._value!=="none"){const t=e._whiteSpace._whiteSpacedContent,s=e._inlines._value;for(let r=1;r<s.length;r++){const n=t[r-1]+t[r];s[r].kerning=e._font._fontVariant.getKerningAmount(n)}}}}class D3 extends pi{constructor(){super("children",null,!1),this._uis=[]}update(e,t){}process(e){}_compute(e){}dispose(){}}function uie(i,e=!1){const t=i[0].index!==null,s=new Set(Object.keys(i[0].attributes)),r=new Set(Object.keys(i[0].morphAttributes)),n={},o={},a=i[0].morphTargetsRelative,l=new je.BufferGeometry;let c=0;for(let h=0;h<i.length;++h){const d=i[h];let p=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in d.attributes){if(!s.has(f))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;n[f]===void 0&&(n[f]=[]),n[f].push(d.attributes[f]),p++}if(p!==s.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in d.morphAttributes){if(!r.has(f))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;o[f]===void 0&&(o[f]=[]),o[f].push(d.morphAttributes[f])}if(l.userData.mergedUserData=l.userData.mergedUserData||[],l.userData.mergedUserData.push(d.userData),e){let f;if(t)f=d.index.count;else if(d.attributes.position!==void 0)f=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(c,f,h),c+=f}}if(t){let h=0;const d=[];for(let p=0;p<i.length;++p){const f=i[p].index;for(let m=0;m<f.count;++m)d.push(f.getX(m)+h);h+=i[p].attributes.position.count}l.setIndex(d)}for(const h in n){const d=O3(n[h]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,d)}for(const h in o){const d=o[h][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let p=0;p<d;++p){const f=[];for(let v=0;v<o[h].length;++v)f.push(o[h][v][p]);const m=O3(f);if(!m)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(m)}}return l}function O3(i){let e,t,s,r=0;for(let a=0;a<i.length;++a){const l=i[a];if(l.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(e===void 0&&(e=l.array.constructor),e!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=l.itemSize),t!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(s===void 0&&(s=l.normalized),s!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;r+=l.array.length}const n=new e(r);let o=0;for(let a=0;a<i.length;++a)n.set(i[a].array,o),o+=i[a].array.length;return new je.BufferAttribute(n,t,s)}class die extends pi{constructor(){super("renderer")}render(e){if(!e._inlines._value||!e._inlines._value.length)return;const t=e._inlines._value.map(r=>e._font._fontVariant.getGeometricGlyph(r,e).translate(r.offsetX,r.offsetY,0)),s=uie(t);e.setFontMesh(new je.Mesh(s,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class pie extends OM{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class lm extends sv{constructor(e={}){const t={};lm.definePropertiesValues(t,e),super(t,e),u(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0}),lm.init(this)}add(e){const t=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(t.push(r),r.position.z=.005):console.warn("Block element can only contain Box elements.",r)}return super.add(...t)}set textContent(e){this._textContent.value=e}get textContent(){return this._textContent._value}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(e,t){e.children||(e.children=D3),e.textContent||(e.textContent=Xte),e.glyphs||(e.glyphs=Jte),e.inlines||(e.inlines=Yte),e.layouter||(e.layouter=_3),e.renderer||(e.renderer=die),e.fontFamily||(e.fontFamily=C3),e.fontWeight||(e.fontWeight=S3),e.fontStyle||(e.fontStyle=w3),e.fontSize||(e.fontSize=B3),e.color||(e.color=Kte),e.backgroundColor||(e.backgroundColor=Zte),e.lineBreak||(e.lineBreak=x3),e.letterSpacing||(e.letterSpacing=P3),e.whiteSpace||(e.whiteSpace=mT),e.segments||(e.segments=cie),e.textAlign||(e.textAlign=pie),e.fontKerning||(e.fontKerning=hie)}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class fie extends gN{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this._needsUpdate=!1;for(let s=e.children.length-1;s>=0;s--){const r=e.children[s];r.isUI&&(e.remove(r),r.clear())}e._children._uis=[],this._value&&e.add(new lm({name:"anonymousInline",textContent:this._value}))}}class mie extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class gie extends pi{constructor(){super("layouter",null,!1),this._value=null}update(e,t){}process(e){let t=e._width._value;e._width._auto?t=1/0:t=e._bounds._innerWidth;const s=e._lineHeight._value,r=new mie(new b3);let n=0;e._children._inlines.forEach(d=>{if(!d._inlines.value)return;this._resetInlines(d);const p=d._fontSize._value,f=d._letterSpacing._value*p,m=d._whiteSpace._value,v=d._lineBreak._value,A={WHITESPACE:m,LETTERSPACING:f,BREAKON:v,INNER_WIDTH:t},g=d._whiteSpace._inlineWrapper;n+=d._margin._value.w+d._padding._value.w,d._inlines.value.forEach((b,y,x)=>{const _=r[r.length-1];if(g(x,y,n,A)){if(r.push(new b3(b)),b.offsetX=b.xoffset,b.width===0){n=0;return}b.cumulativeWidth=b.xadvance+f,n=b.cumulativeWidth;return}r[r.length-1].push(b),b.offsetX=n+b.xoffset+b.kerning,b.cumulativeWidth=b.xadvance+b.kerning+f,n+=b.cumulativeWidth,_.length-1===1&&_[_.length-2].width===0&&(b.offsetX-=b.xoffset,n-=b.xoffset)}),n+=d._margin._value.y+d._padding._value.y});const o=e._whiteSpace._inlineCollapser;let a=0,l=0,c=0;r.forEach((d,p)=>{const f=o(d);let m=0,v=0;if(d.forEach(A=>{m=Math.max(m,A.lineHeight),v=Math.max(v,A.lineBase),A.offsetX-=f}),d.lineHeight=m,d.lineBase=v,p===0?c=-(m*s-m)*.5:c-=r[p-1].lineHeight*s,d.y=c,d.x=0,d.forEach(A=>{A.offsetY=c-A.anchor,A.lineHeight<d.lineHeight&&(A.offsetY-=d.lineBase-A.lineBase)}),l+=d.lineHeight*s,d.width=0,d[0]){const A=d[d.length-1];d.width=A.offsetX+A.cumulativeWidth+A.paddingRight+A.marginRight+d[0].offsetX,a=Math.max(a,d.width)}}),r.height=l,r.width=a,this._value=r,t===1/0&&e._bounds.setChildrenWidth(e,r.width),e._height._auto&&e._bounds.setChildrenHeight(e,r.height);const h=e._parent._value;h&&(h._autoSize._needsProcess=!0,h._flexDirection._needsProcess=!0),e._inlineJustificator._needsProcess=!0,e._textAlign._needsProcess=!0,e._overflow._needsUpdate=!0}_resetInlines(e){e._fontSize.process(e)}}class vie extends OM{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput,this._needsProcess=!0}process(e){Aie(e),e._renderer._needsRender=!0}}function Aie(i){const e=i._layouter._value,t=i._textAlign._value,s=i._bounds._innerWidth;for(let r=0;r<e.length;r++){const n=e[r],o=yie(i,n,r===e.length-1),a=i._padding._value,l=i._borderWidth._value,c=(-a.w+a.y)/2+(-l.w+l.y)/2;n.x+=o;for(let h=0;h<n.length;h++)n[h].offsetX+=o-c}if(t.indexOf("justify")===0)for(let r=0;r<e.length;r++){const n=e[r];if(t.indexOf("-")!==-1&&r===e.length-1)return;const o=s-n.width;if(o<=0)return;let a=0;for(let d=1;d<n.length-1;d++)a+=n[d].char===" "?1:0;const l=o/a;let c=1;t==="justify-right"&&(n.reverse(),c=-1);let h=0;for(let d=1;d<=n.length-1;d++){const p=n[d];p.offsetX+=h*c,h+=p.char===" "?l:0}t==="justify-right"&&n.reverse()}}function yie(i,e,t){switch(i._textAlign._value){case"justify-left":case"justify":case"left":return-i._bounds._innerWidth/2;case"justify-right":case"right":return-e.width+i._bounds._innerWidth/2;case"center":return-e.width/2;case"justify-center":return t?-e.width/2:-i._bounds._innerWidth/2;default:console.warn(`textAlign: '${i._textAlign._value}' is not valid`)}}class bie extends LM{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput}}class xie extends EN{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class _ie extends gx{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e)}}class wie extends g3{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class Sie extends pi{constructor(){super("children",null,!1),u(this,"_sortOrder",(e,t)=>e._order._value<t._order._value?-1:e._order._value>t._order._value?1:this._uis.indexOf(e)<this._uis.indexOf(t)?-1:1),this._uis=[],this._inlines=[],this._boxes=[]}update(e,t){this._compute(e),this._needsProcess=!0}process(e){this._compute(e),e._overflow._needsRender=!0}_compute(e){this._uis=e.children.filter(t=>t.visible&&t.isUI),this._inlines=this._uis.filter(t=>t.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class Cie extends pi{constructor(){super("autosize")}process(e){if(e._layouter._value&&e._layouter._value.length){const t=e._layouter._value,s=e._padding._value,r=e._borderWidth._value;e._width._auto&&e._bounds.setOffsetWidth(e,t.width+s.w+s.y+r.w+r.y),e._height._auto&&e._bounds.setOffsetHeight(e,t.height+s.x+s.z+r.x+r.z)}}}class Eie extends y3{constructor(){super("renderer"),this._needsUpdate=!1}render(e){super.render(e);for(const t of e._children._inlines)t._renderer.render(t);e.performAfterUpdate()}}class QA extends NA{constructor(e={},t={}){QA.definePropertiesValues(t,e),super(t,e),QA.init(this)}add(e){const t=[];let s=!1;for(let r=0;r<arguments.length;r++){const n=arguments[r];!n.isUI||n.isInline?(n.isInline&&(s=!0),t.push(n)):console.warn("Block element can only contain Box elements.",n)}return t.length>0&&super.add(...t),s&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(e){this._textContent.value=e}get textContent(){return super.textContent}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(e,t){e.flexDirection=bie,e.justifyContent=UM,e.alignItems=DM,e.bounds=wie,e.autoSize=Cie,e.renderer=Eie,e.children||(e.children=Sie),e.textContent||(e.textContent=fie),e.layouter||(e.layouter=gie),e.lineHeight||(e.lineHeight=xie),e.textAlign||(e.textAlign=vie),e.whiteSpace||(e.whiteSpace=mT),e.fontKerning||(e.fontKerning=_ie),e.segments||(e.segments=k3),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class Mie extends pi{constructor(){super("inlines",null,!1),this._value=[]}process(e){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}}class Tie extends pi{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new A3(e)),e._backgroundMesh.position.x=e._inlines._value[0].offsetX+e._inlines._value[0].width/2,e._backgroundMesh.position.y=e._inlines._value[0].offsetY+e._inlines._value[0].lineBase/2,e._bounds.render(e)}}class Iie extends pi{constructor(){super("bounds",null,!1),this._size=new je.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(e,t){this.output(t),this._needsProcess=!0}process(e){this._offsetWidth=this._innerWidth=e._inlines._value[0].width,this._offsetHeight=this._innerHeight=e._inlines._value[0].height,this._needsRender=!0,e._borderWidth._needsRender=!0,e._borderRadius._needsRender=!0}render(e){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(e){e.size=this._size}}class jA extends sv{constructor(e={}){const t={};jA.definePropertiesValues(t,e),super(t,e),jA.init(this)}clear(){for(const e of this._inlines._value)e.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new je.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];r.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",r):(t.push(r),r.position.z=.005)}return super.add(...t)}static definePropertiesValues(e,t){e.children||(e.children=D3),e.bounds||(e.bounds=Iie),e.inlines||(e.inlines=Mie),e.layouter||(e.layouter=_3),e.renderer||(e.renderer=Tie),e.fontFamily||(e.fontFamily=C3),e.fontWeight||(e.fontWeight=S3),e.fontStyle||(e.fontStyle=w3),e.fontSize||(e.fontSize=B3),e.backgroundColor||(e.backgroundColor=pN),e.lineBreak||(e.lineBreak=x3),e.letterSpacing||(e.letterSpacing=P3),e.whiteSpace||(e.whiteSpace=mT),e.fontKerning||(e.fontKerning=gx),t.backgroundSize||(t.backgroundSize="cover"),t.width||(t.width="100%"),t.height||(t.height="100%"),t.boxSizing||(t.boxSizing="border-box")}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),e._inlines._value=[new Rie(e)],e.backgroundMaterial=new m3,e._renderer.render(e)}}class Rie extends xN{constructor(e){super(),this._uiElement=e}get xadvance(){const e=this._uiElement._padding._value,t=this._uiElement._width;return t._relative?t._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.w+e.y+t.value}get width(){const e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get height(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get anchor(){return this.height}get lineHeight(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get lineBase(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}clear(){this._uiElement=null}}class L3{constructor(e){this._subject=e}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const U3=()=>Cx.update(),F3={BaseProperty:pi,Block:zA,Text:QA,Inline:lm,InlineBlock:jA,MeshUIBaseElement:sv,FontLibrary:Fu,update:U3,MSDFFontMaterialUtils:ko,ShaderChunkUI:f3,Behavior:L3,FontVariant:Yg};typeof global<"u"&&(global.ThreeMeshUI=F3);const Pie=F3;var Bie=gs.w8,N3=gs.cg,gT=gs.gO,kie=gs.wb,vT=gs.zV,Die=gs.HS,Oie=gs.Ec,Mx=gs.gF,Lie=gs.ol,Uie=gs.pz,Fie=gs.tx,Nie=gs.hj,zie=gs.FV,Qie=gs.sV,z3=gs.xv,jie=gs.mx,Gie=gs.gE,Hie=gs.ZP,Q3=gs.Vx;const AT=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:Bie,Behavior:N3,Block:gT,DefaultValues:kie,FontLibrary:vT,FontVariant:Die,InheritableProperty:Oie,Inline:Mx,InlineBlock:Lie,InlineGlyph:Uie,MSDFFontMaterialUtils:Fie,MaterialTransformers:Nie,MeshUIBaseElement:zie,ShaderChunkUI:Qie,Text:z3,TypographicFont:jie,TypographicGlyph:Gie,default:Hie,update:Q3},Symbol.toStringTag,{value:"Module"})),Vie=re("debugshadowcomponents");gT.prototype.interactable={get(){return this.interactive},set(i){this.interactable=i}};const Na=Symbol("shadowDomOwner");class pa extends Me{constructor(){super(...arguments),u(this,"shadowComponent",null),u(this,"_controlsChildLayout",!0),u(this,"_root"),u(this,"_parentComponent")}isRoot(){var e;return((e=this.Root)==null?void 0:e.gameObject)===this.gameObject}get canvas(){const e=this.Root;return e!=null&&e.isCanvas?e:null}markDirty(){Fn.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(e){this._controlsChildLayout=e,this.shadowComponent&&(this.shadowComponent.autoLayout=e)}get Root(){return this._root===void 0&&(this._root=ee.getComponentInParent(this.gameObject,rv)),this._root}get Canvas(){return this.canvas}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(e,t){var s;this.removeShadowComponent();const r=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=ee.getComponentInParent(r,pa),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}e.name=this.name+" ("+(this.constructor.name??"UI")+")",e.autoLayout=this._parentComponent.controlsChildLayout,e[Na]=this,this.setShadowComponentOwner(e);let n=!1;if(((s=this.Root)==null?void 0:s.gameObject)===this.gameObject)this.gameObject.add(e);else{let o=this._parentComponent.shadowComponent;o&&(o?.add(e),n=!0)}this.shadowComponent=e,t&&t.shadowComponent&&this.shadowComponent&&t.shadowComponent.add(this.shadowComponent),Zm&&e.add(new gp(.5)),this.onAfterAddedToScene(),n&&Q3(),Vie&&console.log(this.shadowComponent)}set(e){}setShadowComponentOwner(e){if(e&&(e[Na]===void 0||e[Na]===this)&&(e[Na]=this,e.children))for(const t of e.children)this.setShadowComponentOwner(t)}traverseOwnedShadowComponents(e,t,s){if(e&&e[Na]===t){s(e);for(const r of e.children)this.traverseOwnedShadowComponents(r,t,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(e){this.shadowComponent&&(this.shadowComponent.interactable=e)}}class rv extends pa{awake(){super.awake()}}class rf{static getObject(e){const t=e[Na];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const s=this.tryFindCanvasGroup(e);if(s?.isCanvasGroup===!0&&(t&&(t.canvasGroup=s),s.blocksRaycasts===!1||s.interactable===!1))return!1;const r=Iu(e,n=>{if(n.isGraphic===!0)return n},!1);return t&&r?.isGraphic===!0&&(t.graphic=r),!(r?.raycastTarget===!1||r?.layer===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=Iu(e,s=>{const r=s;if(r.blocksRaycasts!==void 0&&r.interactable!==void 0)return r},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}const nv=re("debugwebxrcontroller");var nf=(i=>(i[i.PhysicalDevice=0]="PhysicalDevice",i[i.Touch=1]="Touch",i))(nf||{}),ql=(i=>(i.SelectStart="select-start",i.SelectEnd="select-end",i.Update="update",i))(ql||{});class Tx extends Me{}const sr=class extends Me{constructor(){super(...arguments),u(this,"webXR"),u(this,"index",-1),u(this,"controllerModel"),u(this,"controller"),u(this,"controllerGrip"),u(this,"hand"),u(this,"handPointerModel"),u(this,"grabbed",null),u(this,"input",null),u(this,"type",0),u(this,"showRaycastLine",!0),u(this,"_wristQuaternion",null),u(this,"movementVector",new S),u(this,"worldRot",new Ue),u(this,"joystick",new Y),u(this,"didRotate",!1),u(this,"didTeleport",!1),u(this,"didChangeScale",!1),u(this,"lastHit",null),u(this,"raycastLine",null),u(this,"_raycastHitPoint",null),u(this,"_connnectedCallback",null),u(this,"_disconnectedCallback",null),u(this,"_selectStartEvt",null),u(this,"_selectEndEvt",null),u(this,"_selectionPressed",!1),u(this,"_selectionPressedLastFrame",!1),u(this,"_selectionStartTime",0),u(this,"_selectionEndTime",0),u(this,"_useSmoothing",!0),u(this,"_isConnected",!1),u(this,"rayRotation",new Ue),u(this,"_pinchStartTime"),u(this,"selectStartCallback",null),u(this,"lastSelectStartObject",null),u(this,"_didNotEndSelection",!1),u(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const i=new $i(this.geometry),e=i.material;return e.color=this.raycastColor,i.layers.set(2),i.name="line",i.scale.z=1,i}static CreateRaycastHitPoint(){const i=new Po(.5,22,22),e=new hi({color:this.raycastColor}),t=new xe(i,e);return t.visible=!1,t.layers.set(2),t}static Create(i,e,t,s){const r=t?ee.addNewComponent(t,sr,!1):new sr;r.webXR=i,r.index=e,r.type=s;const n=i.context;r.controller=n.renderer.xr.getController(e),r.controllerGrip=n.renderer.xr.getControllerGrip(e),r.controllerModel=this.Factory.createControllerModel(r.controller),r.controllerGrip.add(r.controllerModel),r.hand=n.renderer.xr.getHand(e);const o=new Dp;Bg(o,n),r.webXR.handModelPath&&r.webXR.handModelPath!==""?o.setPath(Sc(i.sourceId,r.webXR.handModelPath)):o.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const a=new fZ(r.hand,o);return r.hand.add(a),r.hand.traverse(l=>l.layers.set(2)),r.handPointerModel=new xZ(r.hand,r.controller),r.controller.addEventListener("connected",l=>{r.setControllerLayers(r.controllerModel,2),r.setControllerLayers(r.controllerGrip,2),r.setControllerLayers(r.hand,2),setTimeout(()=>{r.setControllerLayers(r.controllerModel,2),r.setControllerLayers(r.controllerGrip,2),r.setControllerLayers(r.hand,2)},1e3)}),r.hand.addEventListener("connected",l=>{var c;if(l.data.hand){i.Rig&&i.Rig.add(r.hand),r.type=0,r.handPointerModel.traverse(d=>d.layers.set(2)),(c=r.handPointerModel.pointerObject)==null||c.traverse(d=>d.layers.set(2));const h=r.hand.joints;if(h)for(const d of Object.keys(h)){const p=h[d];p.parent||r.hand.add(p)}}}),r}static addEventListener(i,e){const t=this.eventSubs[i]??[];t.push(e),this.eventSubs[i]=t}static removeEventListener(i,e){if(!e)return;const t=this.eventSubs[i]??[],s=t.indexOf(e);s>=0&&t.splice(s,1),this.eventSubs[i]=t}get isUsingHands(){var i;return((i=this.input)==null?void 0:i.hand)!=null}get wrist(){if(!this.hand)return null;const i=this.hand.joints;return i?i.wrist:null}getWristQuaternion(){const i=this.wrist;return i?(this._wristQuaternion||(this._wristQuaternion=new Ue),Rs(i).multiply(this._wristQuaternion.setFromEuler(new Ys(-Math.PI/4,0,0)))):null}get selectionDown(){return this._selectionPressed&&!this._selectionPressedLastFrame}get selectionUp(){return!this._selectionPressed&&this._selectionPressedLastFrame}get selectionPressed(){return this._selectionPressed}get selectionClick(){return this._selectionEndTime-this._selectionStartTime<.3}get raycastHitPoint(){return this._raycastHitPoint}get useSmoothing(){return this._useSmoothing}awake(){if(!this.controller){console.warn("Missing Controller!!!",this);return}this._connnectedCallback=this.onSourceConnected.bind(this),this._disconnectedCallback=this.onSourceDisconnected.bind(this),this._selectStartEvt=this.onSelectStart.bind(this),this._selectEndEvt=this.onSelectEnd.bind(this),this.type===1&&(this.controllerGrip.addEventListener("connected",this._connnectedCallback),this.controllerGrip.addEventListener("disconnected",this._disconnectedCallback),this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt))}onDestroy(){var i,e,t;this.type===1&&(this.controllerGrip.removeEventListener("connected",this._connnectedCallback),this.controllerGrip.removeEventListener("disconnected",this._disconnectedCallback),this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),(i=this.hand)==null||i.clear(),(e=this.controllerGrip)==null||e.clear(),(t=this.controller)==null||t.clear()}onEnable(){var i,e,t,s,r;this.hand&&(this.hand.name="Hand"),this.controllerGrip&&(this.controllerGrip.name="ControllerGrip"),this.controller&&(this.controller.name="Controller"),this.raycastLine&&(this.raycastLine.name="RaycastLine;"),this.webXR.Controllers.indexOf(this)<0&&this.webXR.Controllers.push(this),this.raycastLine||(this.raycastLine=sr.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=sr.CreateRaycastHitPoint()),(i=this.webXR.Rig)==null||i.add(this.hand),(e=this.webXR.Rig)==null||e.add(this.controllerGrip),(t=this.webXR.Rig)==null||t.add(this.controller),(s=this.webXR.Rig)==null||s.add(this.raycastLine),(r=this.raycastLine)==null||r.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),nv&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var i,e,t,s,r;(i=this.hand)==null||i.removeFromParent(),(e=this.controllerGrip)==null||e.removeFromParent(),(t=this.controller)==null||t.removeFromParent(),(s=this.raycastLine)==null||s.removeFromParent(),(r=this._raycastHitPoint)==null||r.removeFromParent();const n=this.webXR.Controllers.indexOf(this);n>=0&&this.webXR.Controllers.splice(n,1)}onSourceConnected(i){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,i);return}this._isConnected=!0,this.input=i.data,this.type===1&&(this.onSelectStart(),this.createPointerEvent("down"))}onSourceDisconnected(i){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",i);return}this._isConnected=!1,this.type===1&&(this.onSelectEnd(),this.createPointerEvent("up")),this.input=null}createPointerEvent(i){switch(i){case"down":this.context.input.createPointerDown({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break;case"move":break;case"up":this.context.input.createPointerUp({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break}}raycastUpdate(i,e){const t=this.showRaycastLine&&this.type!==1;if(this.type===1)i.visible=!1;else if(this.isUsingHands){i.visible=!this.grabbed&&t,ts(i,e);const s=this.hand.joints;if(s&&s.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const r=this.getWristQuaternion();r&&this.rayRotation.copy(r)}ln(i,this.rayRotation)}else i.visible=t,ln(i,this.rayRotation),ts(i,e)}update(){this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const i=sr.eventSubs.update;if(i&&i.length>0)for(const s of i)s(this);let e=1;this.type===0?e=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(e=this.context.time.deltaTime/.3),this.rayRotation.slerp(Rs(this.controller),this.useSmoothing?e:1);const t=yt(this.controller);this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine&&this.raycastUpdate(this.raycastLine,t),this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(i){var e,t;if(this.lastHit=null,!i||i.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=i.inputSources[this.index]),!this.input)return;const s=this.webXR.Rig;if(!s)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const r=(t=(e=this.input)==null?void 0:e.gamepad)==null?void 0:t.buttons;switch(this.input.handedness){case"left":this.movementUpdate(s,r);break;case"right":this.rotationUpdate(s,r);break}}movementUpdate(i,e){const t=3*sr.MovementSpeedFactor,s=2,r=et.clamp01(this.joystick.length()*2),n=this.joystick.x>0?1:-1;let o=Math.pow(this.joystick.x,s);o*=n,o*=r;const a=this.joystick.y>0?1:-1;let l=Math.pow(this.joystick.y,s);l*=a,o*=r,i.getWorldQuaternion(this.worldRot),this.movementVector.set(o,0,l),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(t*this.context.time.deltaTime),i.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(i,e)}rotationUpdate(i,e){const t=this.joystick.x,s=Math.abs(t);if(s<.4)this.didRotate=!1;else if(s>.5&&!this.didRotate){const r=t>0?-1:1;i.rotateY(et.toRadians(30*r)),this.didRotate=!0}this.runTeleport(i,e)}runTeleport(i,e){var t,s,r;let n=-this.joystick.y;if((t=this.hand)!=null&&t.visible&&!this.grabbed){const c=this.handPointerModel.isPinched();c&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),c&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(n=this.handPointerModel.isPinched()?1:0),c||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;let o=n>.5&&this.webXR.IsInVR,a=this.webXR.Rig?((r=(s=this.webXR.Rig)==null?void 0:s.scale)==null?void 0:r.x)<.999:!1,l=null;if(e&&this.input&&!this.input.hand)for(let c=0;c<e.length;c++){const h=e[c];if(c===4)if(h.pressed&&!this.didChangeScale&&this.webXR.IsInVR){this.didChangeScale=!0;const d=this.webXR.Rig;if(d){let p=this.switchScale(d,o,a,l);o=p.doTeleport,a=p.isInMiniatureMode,l=p.newRigScale}}else h.pressed||(this.didChangeScale=!1)}if(o){if(!this.didTeleport){const c=this.raycast();if(this.didTeleport=!0,c&&c.length>0){const h=c[0];if(a||this.isValidTeleportTarget(h.object)){const d=h.point;ts(i,d)}}}}else n<.1&&(this.didTeleport=!1);l!==null&&(i.scale.set(l,l,l),i.updateMatrixWorld())}isValidTeleportTarget(i){return ee.getComponentInParent(i,Tx)!=null}switchScale(i,e,t,s){if(t){t=!1,i.scale.set(1,1,1),s=1,sr.MovementSpeedFactor=1;const r=this.context.mainCamera;sr.PreviousCameraFarDistance&&(r.far=sr.PreviousCameraFarDistance)}else{t=!0,e=!0,s=.1,sr.MovementSpeedFactor=s*2;const r=this.context.mainCamera;sr.PreviousCameraFarDistance=r.far,r.far/=s}return{doTeleport:e,isInMiniatureMode:t,newRigScale:s}}updateStick(i){var e;!i||!i.gamepad||((e=i.gamepad.axes)==null?void 0:e.length)<4||(this.joystick.x=i.gamepad.axes[2],this.joystick.y=i.gamepad.axes[3])}updateLastHit(){var i;const e=this.raycast(),t=e?e[0]:null;this.lastHit=t;let s=1;if(this.webXR.Rig&&(s/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=s*(((i=this.lastHit)==null?void 0:i.distance)??9999);const r=this.raycastLine.material;t!=null?r.color=sr.raycastColor:r.color=sr.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const r=et.clamp(this.lastHit.distance*.01*s,.015,.1);this._raycastHitPoint.scale.set(r,r,r)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return t}onSelectStart(){this.context.connection.allowEditing&&(this.selectStartCallback=()=>this.onHandleSelectStart())}onHandleSelectStart(){this.selectStartCallback=null,this._selectionPressed=!0,this._selectionStartTime=this.context.time.time,this._selectionEndTime=1e3;let i=null,e=!1;if(this.isUsingHands?(i=this.overlap(),i.length<=0?(i=this.raycast(),e=!1):e=!0):i=this.raycast(),nv&&console.log("onHandleSelectStart","close grab? "+e,"intersections",i),i&&i.length>0)for(const t of i){const s=t.object;this.lastSelectStartObject=s;const r={selected:s,grab:s},n=sr.eventSubs["select-start"];if(n&&n.length>0)for(const o of n)o(this,r);r.grab!==s&&nv&&console.log("Grabbed object changed","original",s,"new",r.grab),r.grab&&(this.grabbed=za.TryTake(this,r.grab,t,e));break}else{const t=sr.eventSubs["select-start"],s={selected:null,grab:null};if(t&&t.length>0)for(const r of t)r(this,s)}}onSelectEnd(){var i;if(this.isUsingHands&&this.handPointerModel.pinched){this._didNotEndSelection=!0;return}if(!this._selectionPressed)return;this.selectStartCallback=null,this._selectionPressed=!1,this._selectionEndTime=this.context.time.time;const e={grab:((i=this.grabbed)==null?void 0:i.selected)??this.lastSelectStartObject},t=sr.eventSubs["select-end"];if(t&&t.length>0)for(const s of t)s(this,e);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(i){return!(!i||ee.isActiveInHierarchy(i)===!1||rf.isInteractable(i)===!1)}setControllerLayers(i,e){var t,s;if(i&&(i.layers.set(e),i.children))for(const r of i.children)((t=this.grabbed)==null?void 0:t.selected)===r||((s=this.grabbed)==null?void 0:s.selectedMesh)===r||this.setControllerLayers(r,e)}getRay(){const i=new xa;return i.origin.copy(yt(this.controller)),i.direction.set(0,0,-1).applyQuaternion(this.rayRotation),i}overlap(){const i=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(nv&&(!this.closeGrabBoundingBoxHelper&&i&&(this.closeGrabBoundingBoxHelper=new Cy(i,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&i&&this.closeGrabBoundingBoxHelper.setFromObject(i)),!i)return new Array;const e=yt(i).clone();return this.context.physics.sphereOverlap(e,.02)}raycast(){const i=new Go;i.layerMask=new to,i.layerMask.enableAll(),i.layerMask.disable(2),i.ray=this.getRay();const e=this.context.physics.raycast(i);for(let t=0;t<e.length;t++){const s=e[t],r=s.object;if(!this.testIsVisible(r)){e.splice(t,1),t--;continue}s.object=rf.getObject(r);break}return e}};let vs=sr;u(vs,"Factory",new kZ),u(vs,"raycastColor",new Ae(.9,.3,.3)),u(vs,"raycastNoHitColor",new Ae(.6,.6,.6)),u(vs,"geometry",new At().setFromPoints([new S(0,0,0),new S(0,0,-1)])),u(vs,"handModels",{}),u(vs,"eventSubs",{}),u(vs,"PreviousCameraFarDistance"),u(vs,"MovementSpeedFactor",1);var Ix=(i=>(i.WillTake="WillTake",i.DidTake="DidTake",i.WillFree="WillFree",i.DidFree="DidFree",i))(Ix||{});const gn=class{constructor(){u(this,"sync",null),u(this,"selected",null),u(this,"selectedParent",null),u(this,"selectedMesh",null),u(this,"controller",null),u(this,"grabTime",0),u(this,"grabUUID",""),u(this,"isCloseGrab",!1),u(this,"originalMaterial",null),u(this,"usageMarker",null),u(this,"rigidbodies",null),u(this,"didReparent",!1),u(this,"grabDistance",0),u(this,"interactable",null),u(this,"positionSource",null),u(this,"grabPoint",new S),u(this,"localPositionOffsetToGrab",null),u(this,"localPositionOffsetToGrab_worldSpace",new S),u(this,"localQuaternionToGrab",new Ue(0,0,0,1)),u(this,"targetDir",null),u(this,"quaternionLerp",null),u(this,"controllerDir",new S),u(this,"controllerWorldPos",new S),u(this,"lastControllerWorldPos",new S),u(this,"controllerPosDelta",new S),u(this,"totalChangeAlongDirection",0),u(this,"rigPositionLastFrame",new S)}static AddEventListener(i,e){return gn.Events[i]||(gn.Events[i]=[]),gn.Events[i].push(e),e}static RemoveEventListener(i,e){if(!e||!gn.Events[i])return;const t=gn.Events[i].indexOf(e);t>=0&&gn.Events[i].splice(t,1)}static Register(i){this.Current.find(e=>e===i)||this.Current.push(i)}static Remove(i){const e=this.Current.indexOf(i);e>=0&&this.Current.splice(e,1)}static TryTake(i,e,t,s){const r=ee.getComponentInParent(e,Yp);if(r)e=r.gameObject;else return nv&&console.warn("Prevented taking object that is not interactable",e),null;let n=e;const o=ee.getComponentInParent(e,mh);o&&(o.requestOwnership(),n=o.gameObject);for(const l of this.Current)if(l.selected===n)return l.controller===i||(l.free(),l.Take(i,n,e,o,r,t,s)),l;const a=new gn;return a.Take(i,n,e,o,r,t,s),a}Take(i,e,t,s,r,n,o){var a,l;if(console.assert(e!==null,"Expected object to be taken but was",e),i.isUsingHands?this.positionSource=o?i.wrist:i.controller:this.positionSource=i.controller,!this.positionSource)return console.warn("No position source"),this;const c={controller:i,take:e,hit:t,sync:s,interactable:r};(a=gn.Events.WillTake)==null||a.forEach(m=>m(this,c));const h=t;h!=null&&h.material&&(this.originalMaterial=h.material,Array.isArray(h.material)||(h.material=h.material.clone(),h.material&&h.material.emissive&&(h.material.emissive.b=.2))),this.selected=e,this.selectedParent||(this.selectedParent=e.parent),this.selectedMesh=h,this.controller=i,this.interactable=r,this.isCloseGrab=o,this.didReparent=!1,this.sync=s,this.grabTime=i.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=ee.addNewComponent(this.selected,Jp),this.rigidbodies=ee.getComponentsInChildren(this.selected,ji),yt(this.positionSource,this.lastControllerWorldPos);const d=()=>o?this.lastControllerWorldPos.clone():n.point.clone();this.grabDistance=d().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(d());const p=i.isUsingHands&&o?this.controller.getWristQuaternion().clone():i.rayRotation.clone();Rs(this.selected,this.localQuaternionToGrab).premultiply(p.invert());const f=this.controller.webXR.Rig;return f&&this.rigPositionLastFrame.copy(yt(f)),Wr.Add(i.context,this.selected),gn.Register(this),this.sync&&(this.sync.fastMode=!0),(l=gn.Events.DidTake)==null||l.forEach(m=>m(this,c)),this}free(){var i,e,t,s;if(!this.selected)return;const r={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(i=gn.Events.WillFree)==null||i.forEach(a=>a(this,r)),Wr.Remove(this.controller.context,this.selected),gn.Remove(this),this.sync&&(this.sync.fastMode=!1);const n=this.selectedMesh;n&&this.originalMaterial&&n.material&&(n.material=this.originalMaterial);const o=this.selected;if(this.didReparent&&o.parent){const a=this.selectedParent;a?a.attach(o):(e=this.controller)==null||e.context.scene.attach(o)}if((t=this.usageMarker)==null||t.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const a of this.rigidbodies)a.wakeUp(),a.setVelocity(a.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(s=gn.Events.DidFree)==null||s.forEach(a=>a(this,r))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),yt(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const i=this.controller.webXR.Rig;if(i){const e=yt(i),t=this.rigPositionLastFrame.sub(e);this.controllerPosDelta.add(t),this.rigPositionLastFrame.copy(e)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var i;if(this.rigidbodies)for(const e of this.rigidbodies)e.resetVelocities();if(this.sync&&this.controller&&this.controller.context.connection.isInRoom&&this.controller.context.time.time-this.grabTime>3&&this.sync.hasOwnership()===!1&&(console.log("no ownership, will leave",this.sync.guid),this.free()),!(this.interactable&&!this.interactable.canGrab)){if(!this.didReparent&&this.selected&&this.controller){const e=((i=this.controller.webXR.Rig)==null?void 0:i.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let t=1;this.controller.type===0&&(t=Math.max(0,1+this.totalChangeAlongDirection*2/e),t=t*t*t),this.grabDistance/e<.8&&(t=1),this.targetDir||(this.targetDir=new S),this.targetDir.set(0,0,-this.grabDistance*t);const s=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),r=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=r.clone()),this.quaternionLerp.slerp(r,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),ln(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(s),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(yt(this.selected)),s.sub(this.localPositionOffsetToGrab_worldSpace)),ts(this.selected,s)}if(this.rigidbodies!=null)for(const e of this.rigidbodies)e.wakeUp();_n.markDirty(this.selected,!0)}}};let za=gn;u(za,"Events",{}),u(za,"Current",[]);var Wie=Object.defineProperty,qie=Object.getOwnPropertyDescriptor,yT=(i,e,t,s)=>{for(var r=s>1?void 0:s?qie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Wie(e,t,r),r};class zu extends Me{constructor(){super(...arguments),u(this,"objectBounds",!1),u(this,"color"),u(this,"isGizmo",!0),u(this,"_gizmoObject",null),u(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!Zm||(this._gizmoObject||(this.objectBounds?this._gizmoObject=new Cy(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=bF(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),On.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){for(var e;this._boxHelper;)(e=this._boxHelper)==null||e.update(),yield}}yT([w()],zu.prototype,"objectBounds",2),yT([w(Ae)],zu.prototype,"color",2),yT([w()],zu.prototype,"isGizmo",2);const Xie=re("debugrig");class Rx extends Me{awake(){if(Xie){const e=new De;e.position.y+=.5,this.gameObject.add(e);const t=e.addNewComponent(zu);t&&(t.isGizmo=!1)}}}class of{constructor(){u(this,"bb",null),u(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}w(){return this.bb.readFloat32(this.bb_pos+12)}static sizeOf(){return 16}static createVec4(e,t,s,r,n){return e.prep(4,16),e.writeFloat32(n),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(t),e.offset()}}class Tr{constructor(){u(this,"bb",null),u(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsVrUserStateBuffer(e,t){return(t||new Tr).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsVrUserStateBuffer(e,t){return e.setPosition(e.position()+Hy),(t||new Tr).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}time(){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):this.bb.createLong(0,0)}avatarId(e){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__string(this.bb_pos+t,e):null}position(e){const t=this.bb.__offset(this.bb_pos,10);return t?(e||new Un).__init(this.bb_pos+t,this.bb):null}rotation(e){const t=this.bb.__offset(this.bb_pos,12);return t?(e||new of).__init(this.bb_pos+t,this.bb):null}scale(){const e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readFloat32(this.bb_pos+e):0}posLeftHand(e){const t=this.bb.__offset(this.bb_pos,16);return t?(e||new Un).__init(this.bb_pos+t,this.bb):null}posRightHand(e){const t=this.bb.__offset(this.bb_pos,18);return t?(e||new Un).__init(this.bb_pos+t,this.bb):null}rotLeftHand(e){const t=this.bb.__offset(this.bb_pos,20);return t?(e||new of).__init(this.bb_pos+t,this.bb):null}rotRightHand(e){const t=this.bb.__offset(this.bb_pos,22);return t?(e||new of).__init(this.bb_pos+t,this.bb):null}static startVrUserStateBuffer(e){e.startObject(10)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addTime(e,t){e.addFieldInt64(1,t,e.createLong(0,0))}static addAvatarId(e,t){e.addFieldOffset(2,t,0)}static addPosition(e,t){e.addFieldStruct(3,t,0)}static addRotation(e,t){e.addFieldStruct(4,t,0)}static addScale(e,t){e.addFieldFloat32(5,t,0)}static addPosLeftHand(e,t){e.addFieldStruct(6,t,0)}static addPosRightHand(e,t){e.addFieldStruct(7,t,0)}static addRotLeftHand(e,t){e.addFieldStruct(8,t,0)}static addRotRightHand(e,t){e.addFieldStruct(9,t,0)}static endVrUserStateBuffer(e){return e.endObject()}static finishVrUserStateBufferBuffer(e,t){e.finish(t)}static finishSizePrefixedVrUserStateBufferBuffer(e,t){e.finish(t,void 0,!0)}}const j3=re("debugxr"),ov=re("debugavatar"),bT="VRUS";TC(bT,Tr.getRootAsVrUserStateBuffer);function xT(){return new Date().getTime()}function Yie(i){let e=i&4294967295,t=i/Math.pow(2,32)&1048575;return sl.create(e,t)}const Px=class{constructor(i){u(this,"guid"),u(this,"time"),u(this,"avatarId"),u(this,"position",new S),u(this,"rotation",new mt),u(this,"scale",1),u(this,"posLeftHand",new S),u(this,"posRightHand",new S),u(this,"rotLeftHand",new Ue),u(this,"rotRightHand",new Ue),this.guid=i}update(i,e,t,s,r){var n,o,a,l,c,h;this.time=xT(),this.avatarId=r,this.position.set(e.x,e.y,e.z),i&&this.position.applyMatrix4(i.matrixWorld);let d=Px.quat0;const p=Px.quat1;d.set(t.x,t.y,t.z,t.w),d=d.multiplyQuaternions(d,Px.invertRotation),i&&(i.getWorldQuaternion(p),d.multiplyQuaternions(p,d)),this.rotation.set(d.x,d.y,d.z,d.w),this.scale=i.scale.x;const f=(n=s.LeftController)==null?void 0:n.controllerGrip;f&&(f.getWorldPosition(this.posLeftHand),f.getWorldQuaternion(this.rotLeftHand));const m=(o=s.RightController)==null?void 0:o.controllerGrip;if(m&&(m.getWorldPosition(this.posRightHand),m.getWorldQuaternion(this.rotRightHand)),(l=(a=s.LeftController)==null?void 0:a.hand)!=null&&l.visible){const v=s.LeftController.wrist;v&&(v.getWorldPosition(this.posLeftHand),v.getWorldQuaternion(this.rotLeftHand))}if((h=(c=s.RightController)==null?void 0:c.hand)!=null&&h.visible){const v=s.RightController.wrist;v&&(v.getWorldPosition(this.posRightHand),v.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(i,e){i.clear();const t=i.createString(this.guid),s=i.createString(this.avatarId);Tr.startVrUserStateBuffer(i),Tr.addGuid(i,t),Tr.addTime(i,Yie(this.time)),Tr.addAvatarId(i,s),Tr.addPosition(i,Un.createVec3(i,this.position.x,this.position.y,this.position.z)),Tr.addRotation(i,of.createVec4(i,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),Tr.addScale(i,this.scale),Tr.addPosLeftHand(i,Un.createVec3(i,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),Tr.addPosRightHand(i,Un.createVec3(i,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),Tr.addRotLeftHand(i,of.createVec4(i,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),Tr.addRotRightHand(i,of.createVec4(i,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const r=Tr.endVrUserStateBuffer(i);i.finish(r,bT);const n=i.asUint8Array();e.sendBinary(n)}setFromBuffer(i,e){if(!i)return;this.guid=i,this.time=e.time().toFloat64();const t=e.avatarId();t&&(this.avatarId=t);const s=e.position();s&&this.position.set(s.x(),s.y(),s.z());const r=e.rotation();r&&this.rotation.set(r.x(),r.y(),r.z(),r.w());const n=e.posLeftHand();n&&this.posLeftHand.set(n.x(),n.y(),n.z());const o=e.posRightHand();o&&this.posRightHand.set(o.x(),o.y(),o.z());const a=e.rotLeftHand();a&&this.rotLeftHand.set(a.x(),a.y(),a.z(),a.w());const l=e.rotRightHand();l&&this.rotRightHand.set(l.x(),l.y(),l.z(),l.w()),this.scale=e.scale()}};let Xl=Px;u(Xl,"invertRotation",new Ue().setFromAxisAngle(new S(0,1,0),Math.PI)),u(Xl,"quat0",new Ue),u(Xl,"quat1",new Ue);class av extends Me{constructor(){super(...arguments),u(this,"webXR",null),u(this,"debugAvatarUser",null),u(this,"voip",null),u(this,"tempState",new Xl("")),u(this,"_removeAvatarsList",[]),u(this,"eventSub_ConnectionEvent",null),u(this,"eventSub_WebXRStartEvent",null),u(this,"eventSub_WebXREndEvent",null),u(this,"eventSub_WebXRUpdateEvent",null),u(this,"avatars",{}),u(this,"localAvatar",null),u(this,"k_LocalAvatarNoNetworkingGuid","local"),u(this,"ownership",null),u(this,"xrState",null),u(this,"builder",new nm(1024))}async awake(){if(this.webXR||(this.webXR=ee.getComponent(this.gameObject,wt)),this.webXR||(this.webXR=ee.findObjectOfType(wt,this.context)),!this.webXR&&(console.log("Missing webxr component"),this.webXR=ee.findObjectOfType(wt,this.context),!this.webXR)){console.error("Could not find webxr component");return}if(this.voip||(this.voip=ee.findObjectOfType(yc,this.context)),ov){const e="debug-avatar-"+ov,t=new ph(this.context,e,this.webXR);if(this.debugAvatarUser=t,typeof ov=="string"&&ov.length>0)if(await t.setAvatarOverride(ov)){const s=new Xl(e);s.position.y+=1;const r=.5;s.posLeftHand.y+=r,s.posLeftHand.x+=r,s.posRightHand.y+=r,s.posRightHand.x-=r,t.tryUpdate(s,0)}else t.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=ee.getComponent(this.gameObject,wt),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),wt.addEventListener(_i.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),wt.addEventListener(_i.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),wt.addEventListener(_i.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen(qi.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",e=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",e=>{const t=e.id!==null&&e.id!==void 0;if(t&&(console.log("webxr user left evt"),t)){const s=this.avatars[e.id];s?.destroy(),this.avatars[e.id]=void 0}}),this.context.connection.beginListenBinary(bT,e=>{const t=e.guid();if(!t)return;const s=e.time().toFloat64(),r=this.tempState;r.setFromBuffer(t,e);const n=this.onTryGetAvatar(t,s);n?.tryUpdate(r,s)}),this.context.connection.beginListen("vr-session-update",e=>{const t=e.guid,s=e.time,r=this.onTryGetAvatar(t,s);r?.tryUpdate(e,s)})}onTryGetAvatar(e,t){if(e===this.context.connection.connectionId)return null;const s=new Date().getTime()-t;if(s>5e3)return j3&&console.log("old data",s,e),null;let r=this.avatars[e];if(r===void 0)try{console.log("create new avatar");const n=new ph(this.context,e,this.webXR);r=n,this.avatars[e]=n}catch(n){this.avatars[e]=null,console.error(n)}return r}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen(qi.JoinedRoom,this.eventSub_ConnectionEvent),wt.removeEventListener(_i.XRStarted,this.eventSub_WebXRStartEvent),wt.removeEventListener(_i.XRUpdate,this.eventSub_WebXRUpdateEvent),wt.removeEventListener(_i.XRStopped,this.eventSub_WebXREndEvent)}update(){const e=xT();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=e),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const t in this.avatars){const s=this.avatars[t];s&&s.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const e=xT();for(const t in this.avatars){const s=this.avatars[t];if(!s){this._removeAvatarsList.push(t);continue}e-s.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),s.destroy(),this.avatars[t]=void 0)}for(const t of this._removeAvatarsList)delete this.avatars[t];this._removeAvatarsList.length=0}buildLocalAvatar(){var e;if(this.localAvatar)return;const t=((e=this.context.connection)==null?void 0:e.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new ph(this.context,t,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var e,t,s;j3&&console.log("Hey you are connected as "+this.context.connection.connectionId),((e=this.localAvatar)==null?void 0:e.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null)}onXRSessionStart(e){var t,s,r;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null,this.avatars)for(const n in this.avatars)(r=this.avatars[n])==null||r.updateFlags()}onXRSessionEnded(e){var t;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((t=this.localAvatar)==null||t.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(e){this.xrState??(this.xrState=new Xl(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new sb(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:t,xr:s,rig:r}=e,n=t.getViewerPose(s.getReferenceSpace());if(!n)return;const o=n?.transform,a=o.position,l=o.orientation;this.xrState.update(r,a,l,this.webXR,this.getAvatarId()),this.localAvatar&&(this.context.connection.connectionId&&(this.localAvatar.guid=this.context.connection.connectionId),this.localAvatar.tryUpdate(this.xrState,0)),!(this.ownership&&!this.ownership.hasOwnership&&this.context.connection.isConnected&&(this.context.time.frameCount%120===0&&this.ownership.requestOwnership(),!this.ownership.hasOwnership))&&(!this.context.connection.isConnected||!this.context.connection.connectionId||this.xrState.sendAsBuffer(this.builder,this.context.connection))}getAvatarId(){return re("avatar")??null}}var Jie=Object.defineProperty,Kie=Object.getOwnPropertyDescriptor,af=(i,e,t,s)=>{for(var r=s>1?void 0:s?Kie(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&Jie(e,t,r),r};const _T=re("debugwebxr");async function G3(){return qA()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function H3(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let lv=!1,cv=!1;G3().then(i=>lv=i),H3().then(i=>cv=i);var _i=(i=>(i.XRStarted="xrStarted",i.XRStopped="xrStopped",i.XRUpdate="xrUpdate",i.RequestVRSession="requestVRSession",i.ModifyAROptions="modify-ar-options",i))(_i||{}),lf;const ks=(lf=class extends Me{constructor(){super(...arguments),u(this,"enableVR",!0),u(this,"enableAR",!0),u(this,"defaultAvatar"),u(this,"handModelPath",""),u(this,"createVRButton",!0),u(this,"createARButton",!0),u(this,"controllers",[]),u(this,"rig"),u(this,"isInit",!1),u(this,"_requestedAR",!1),u(this,"_requestedVR",!1),u(this,"_isInAR",!1),u(this,"_isInVR",!1),u(this,"_arButton"),u(this,"_vrButton"),u(this,"webAR",null),u(this,"_transformOrientation",new Ue),u(this,"_currentHeadPose",null),u(this,"_originalCameraParent",null),u(this,"_originalCameraPosition",new S),u(this,"_originalCameraRotation",new Ue),u(this,"_originalXRRigParent",null),u(this,"_originalXRRigPosition",new S),u(this,"_originalXRRigRotation",new Ue),u(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(lv||cv)}static get IsARSupported(){return lv}static get IsVRSupported(){return cv}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(i,e){return this.events.addEventListener(i,e),e}static removeEventListener(i,e){return this.events.removeEventListener(i,e),e}static dispatchEvent(i,e){this.events.dispatchEvent({type:i,detail:e})}static createVRButton(i,e){ks.XRSupported?i.__internalAwake():console.warn("WebXR is not supported on this device");const t={optionalFeatures:ks.OptionalFeatures_VR},s=SM.createButton(i.context.renderer,t);return s.classList.add("webxr-ar-button"),s.classList.add("webxr-button"),this.resetButtonStyles(s),(e?.registerClick??!0)&&s.addEventListener("click",i.onClickedVRButton.bind(i)),s}static createARButton(i,e){var t;i.__internalAwake();const s=(t=i.webAR)==null?void 0:t.getAROverlayContainer(),r={optionalFeatures:[...this.OptionalFeatures_AR]};s?(r.domOverlay={root:s},r.optionalFeatures.push("dom-overlay"),r.optionalFeatures.push("hit-test")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const n=sZ.createButton(i.context.renderer,r,this.onModifyAROptions.bind(this));return n.classList.add("webxr-ar-button"),n.classList.add("webxr-button"),ks.resetButtonStyles(n),(e?.registerClick??!0)&&n.addEventListener("click",i.onClickedARButton.bind(i)),n}static onModifyAROptions(i){ks.dispatchEvent("modify-ar-options",i)}static resetButtonStyles(i){i&&(i.style.position="",i.style.bottom="",i.style.left="")}endSession(){const i=this.context.renderer.xr.getSession();i&&i.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var i,e;return this.controllers.length>0&&((i=this.controllers[0].input)==null?void 0:i.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((e=this.controllers[1].input)==null?void 0:e.handedness)==="left"?this.controllers[1]:null}get RightController(){var i,e;return this.controllers.length>0&&((i=this.controllers[0].input)==null?void 0:i.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((e=this.controllers[1].input)==null?void 0:e.handedness)==="right"?this.controllers[1]:null}get ARButton(){return this._arButton}get VRButton(){return this._vrButton}get IsInVR(){return this._isInVR}get IsInAR(){return this._isInAR}awake(){if(this.defaultAvatar&&typeof this.defaultAvatar=="string"&&(this.defaultAvatar=wr.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!ee.findObjectOfType(av,this.context)){const i=ee.addNewComponent(this.gameObject,av,!1);i.webXR=this}this.webAR=new uv(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(lo("WebXR only works on https"),console.warn("WebXR only works on https. https://engine.needle.tools/docs/xr.html"))}onEnable(){if(this.isInit||!this.enableAR&&!this.enableVR)return;this.isInit=!0,this.context.renderer.xr.enabled=!0,ks.XRSupported;let i,e;const t=document.createElement("div");t.classList.add("webxr-buttons"),t.style.cssText=`
5010
5010
  position: fixed;
5011
5011
  bottom: 21px;
5012
5012
  left: 50%;