@needle-tools/engine 3.2.2-alpha → 3.2.3-alpha

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.
@@ -3240,7 +3240,7 @@ Please change to:
3240
3240
  ${C}? : AssetReference;
3241
3241
 
3242
3242
  in script ${i}.ts
3243
- <a href="https://docs.needle.tools/serializable" target="_blank">documentation</a>`),console.warn(i,C,I[C],I);continue}}}}function qO(I,A){for(const g of Object.keys(A)){const e=A[g];if(typeof e=="object"&&e!==null&&e!==void 0){const i=I[g];if(!i){MB&&console.log(g,"is undefined on",I);continue}for(const t of Object.keys(e))i[t]===void 0&&wU(e[t])&&!wU(i)&&(i[t]=e[t])}}}function wU(I){switch(typeof I){case"number":case"string":case"boolean":return!0}return!1}function yy(I,A,g,e,i){let t=typeof A=="function"&&A.prototype===void 0,C=A;if(t)try{if(C=A?.call(A,i),t=!1,C==null)return}catch(a){console.error("Error in callback",a,I)}if(g.type=C,!t&&i instanceof C)return i;if(i&&typeof i=="object"&&mO(i)){if(i.__concreteInstance)return i.__concreteInstance;const a=i;if(!a.$serializedTypes&&C.prototype.$serializedTypes&&(a.$serializedTypes=C.prototype.$serializedTypes),a.$serializedTypes&&wy(a,I,g),i&&C!==void 0)try{const n=new C;Ye&&console.log("Create concrete instance for persistent asset",i,"instance:",n),mB(n,i),i.__concreteInstance=n,i=n}catch(n){console.error("Error creating instance or creating values on instance",n,i,C)}return i}if(e||(e={serializer:ql.getSerializerForConstructor(C)}),Array.isArray(I)){const a=[];for(let n=0;n<I.length;n++){const r=I[n],E=yy(r,A,g,e,r);a.push(E)}return a}const o=e.serializer;if(o)return o.onDeserialize(I,g);let s;if(I&&(I.isMaterial||I.isTexture||I.isObject3D))s=I;else{if(I===void 0)return;if(I===null&&(C===fg||C===Ng||C===fA||C===mt))return null;s=new C(...bO(I))}const B=s;return B.$serializedTypes&&wy(B,I,g),s}function bO(I){if(bl.length=0,typeof I=="object"&&I!==null&&I!==void 0)for(const A of Object.keys(I))bl.push(I[A]);return bl}const Sy=Symbol("assigned component properties");function mB(I,A,g){var e;if(A==null||I==null)return;I[Sy]=!0;const i=((e=I.constructor)==null?void 0:e.name)??"unknown";g?.registerDefinedKeys(i,I);for(const t of Object.keys(A)){const C=LO(I,t);typeof C?.value!="function"&&(!C||C.writable===!0||C?.set!==void 0)&&(I[t]=A[t])}delete I[Sy]}function LO(I,A){let g;do g=Object.getOwnPropertyDescriptor(I,A);while(!g&&(I=Object.getPrototypeOf(I)));return g}const Rt=EA("debuginput");class ky{constructor(A){Q(this,"key"),Q(this,"keyType"),Q(this,"source"),this.key=A.key,this.keyType=A.type,this.source=A}}var XC=(I=>(I.PointerDown="pointerdown",I.PointerUp="pointerup",I.PointerMove="pointermove",I.KeyDown="keydown",I.KeyUp="keyup",I.KeyPressed="keypress",I))(XC||{});class vO extends EventTarget{constructor(A){super(),Q(this,"_doubleClickTimeThreshold",.2),Q(this,"_longPressTimeThreshold",1),Q(this,"_specialCursorTrigger",0),Q(this,"context"),Q(this,"_pointerDown",[!1]),Q(this,"_pointerUp",[!1]),Q(this,"_pointerClick",[!1]),Q(this,"_pointerDoubleClick",[!1]),Q(this,"_pointerPressed",[!1]),Q(this,"_pointerPositions",[new gA]),Q(this,"_pointerPositionsLastFrame",[new gA]),Q(this,"_pointerPositionsDelta",[new gA]),Q(this,"_pointerPositionsRC",[new gA]),Q(this,"_pointerPositionDown",[new gA]),Q(this,"_pointerDownTime",[]),Q(this,"_pointerUpTime",[]),Q(this,"_pointerUpTimestamp",[]),Q(this,"_pointerIds",[]),Q(this,"_pointerTypes",[""]),Q(this,"_mouseWheelChanged",[!1]),Q(this,"_mouseWheelDeltaY",[0]),Q(this,"_pointerEvent",[]),Q(this,"keysPressed",{}),this.context=A,this.context.post_render_callbacks.push(this.onEndOfFrame.bind(this)),window.addEventListener("touchstart",this.onTouchStart.bind(this),!1),window.addEventListener("touchmove",this.onTouchMove.bind(this),{passive:!0}),window.addEventListener("touchend",this.onTouchUp.bind(this),!1),window.addEventListener("mousedown",this.onMouseDown.bind(this),!1),window.addEventListener("mousemove",this.onMouseMove.bind(this),!1),window.addEventListener("mouseup",this.onMouseUp.bind(this),!1),window.addEventListener("wheel",this.onMouseWheel.bind(this),{passive:!0}),window.addEventListener("keydown",this.onKeyDown.bind(this),!1),window.addEventListener("keypress",this.onKeyPressed.bind(this),!1),window.addEventListener("keyup",this.onKeyUp.bind(this),!1),window.addEventListener("blur",this.onLostFocus.bind(this))}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")}getPointerPressedCount(){let A=0;for(let g=0;g<this._pointerPressed.length;g++)this._pointerPressed[g]&&A++;return A}getPointerPosition(A){return A>=this._pointerPositions.length?null:this._pointerPositions[A]}getPointerPositionLastFrame(A){return A>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[A]}getPointerPositionDelta(A){return A>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[A]}getPointerPositionRC(A){return A>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[A]}getPointerDown(A){return A>=this._pointerDown.length?!1:this._pointerDown[A]}getPointerUp(A){return A>=this._pointerUp.length?!1:this._pointerUp[A]}getPointerPressed(A){return A>=this._pointerPressed.length?!1:this._pointerPressed[A]}getPointerClicked(A){return A>=this._pointerClick.length?!1:this._pointerClick[A]}getPointerDoubleClicked(A){return A>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[A]}getPointerDownTime(A){return A>=this._pointerDownTime.length?-1:this._pointerDownTime[A]}getPointerUpTime(A){return A>=this._pointerUpTime.length?-1:this._pointerUpTime[A]}getPointerLongPress(A){return A>=this._pointerDownTime.length?!1:this.getPointerPressed(A)&&this.context.time.time-this._pointerDownTime[A]>this._longPressTimeThreshold}getIsMouse(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="mouse"}getIsTouch(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="touch"}getTouchesPressedCount(){let A=0;for(let g=0;g<this._pointerPressed.length;g++)this._pointerPressed[g]&&this.getIsTouch(g)&&A++;return A}getMouseWheelChanged(A=0){return A>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[A]}getMouseWheelDeltaY(A=0){return A>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[A]}getPointerEvent(A){if(!(A>=this._pointerEvent.length))return this._pointerEvent[A]??void 0}*foreachPointerId(A){for(let g=0;g<this._pointerTypes.length;g++)if(this._pointerIsActive(g)){if(A!==void 0){const e=this._pointerTypes[g];if(Array.isArray(A)){let i=!1;for(const t of A)if(e===t){i=!0;break}if(!i)continue}else if(A!==e)continue}yield g}}*foreachTouchId(){for(let A=0;A<this._pointerTypes.length;A++)this._pointerTypes[A]==="touch"&&this._pointerIsActive[A]&&(yield A)}_pointerIsActive(A){return A<0?!1:this._pointerPressed[A]||this._pointerDown[A]||this._pointerUp[A]}getKeyDown(){for(const A in this.keysPressed){const g=this.keysPressed[A];if(g.startFrame===this.context.time.frameCount)return g.key}return null}getKeyPressed(){for(const A in this.keysPressed){const g=this.keysPressed[A];if(g.pressed)return g.key}return null}isKeyDown(A){var g;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyDown(i))return!0;return!1}return this.context.application.isVisible&&this.context.application.hasFocus&&((g=this.keysPressed[A])==null?void 0:g.startFrame)===this.context.time.frameCount&&this.keysPressed[A].pressed}isKeyUp(A){var g;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyUp(i))return!0;return!1}return this.context.application.isVisible&&this.context.application.hasFocus&&((g=this.keysPressed[A])==null?void 0:g.frame)===this.context.time.frameCount&&!this.keysPressed[A].pressed}isKeyPressed(A){var g;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyPressed(i))return!0;return!1}return this.context.application.isVisible&&this.context.application.hasFocus&&((g=this.keysPressed[A])==null?void 0:g.pressed)}getCodeForCommonKeyName(A){if(A.length===1){if(A>="0"&&A<="9")return["Digit"+A];if(A>="a"&&A<="z")return["Key"+A.toUpperCase()];if(A==" ")return["Space"]}switch(A){case"Shift":return["ShiftLeft","ShiftRight"];case"Control":return["ControlLeft","ControlRight"];case"Alt":return["AltLeft","AltRight"]}return null}createPointerDown(A){Rt&&Ki("Create Pointer down"),this.onDown(A)}createPointerMove(A){Rt&&Ki("Create Pointer move"),this.onMove(A)}createPointerUp(A){Rt&&Ki("Create Pointer up"),this.onUp(A)}convertScreenspaceToRaycastSpace(A){A.x=(A.x-this.context.domX)/this.context.domWidth*2-1,A.y=-((A.y-this.context.domY)/this.context.domHeight)*2+1}onLostFocus(){for(const A in this.keysPressed)this.keysPressed[A].pressed=!1}onEndOfFrame(){for(let A=0;A<this._pointerUp.length;A++)this._pointerUp[A]=!1;for(let A=0;A<this._pointerDown.length;A++)this._pointerDown[A]=!1;for(let A=0;A<this._pointerClick.length;A++)this._pointerClick[A]=!1;for(let A=0;A<this._pointerDoubleClick.length;A++)this._pointerDoubleClick[A]=!1;for(const A of this._pointerPositionsDelta)A.set(0,0);for(let A=0;A<this._mouseWheelChanged.length;A++)this._mouseWheelChanged[A]=!1;for(let A=0;A<this._mouseWheelDeltaY.length;A++)this._mouseWheelDeltaY[A]=0}canReceiveInput(A){return A.target===this.context.renderer.domElement}onKeyDown(A){if(!this.context.application.hasFocus)return;const g=this.keysPressed[A.code];g&&g.pressed||(this.keysPressed[A.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:A.key,code:A.code},this.onDispatchEvent("keydown",new ky(A)))}onKeyPressed(A){if(!this.context.application.hasFocus)return;const g=this.keysPressed[A.code];g&&(g.pressed=!0,g.frame=this.context.time.frameCount+1,this.onDispatchEvent("keypress",new ky(A)))}onKeyUp(A){if(!this.context.application.hasFocus)return;const g=this.keysPressed[A.code];g&&(g.pressed=!1,g.frame=this.context.time.frameCount+1,this.onDispatchEvent("keyup",new ky(A)))}onMouseWheel(A){if(this.canReceiveInput(A)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const g=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=g+A.deltaY}onTouchStart(A){if(!(A.changedTouches.length<=0)&&this.canReceiveInput(A)!==!1)for(let g=0;g<A.changedTouches.length;g++){const e=A.changedTouches[g],i=this.getPointerIndex(e.identifier);Rt&&Ki(`touch start #${i}, identifier:${e.identifier}`);const t={button:i,clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:A};this.onDown(t)}}onTouchMove(A){if(!(A.changedTouches.length<=0))for(let g=0;g<A.changedTouches.length;g++){const e=A.changedTouches[g],i={button:this.getPointerIndex(e.identifier),clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:A};this.onMove(i)}}onTouchUp(A){if(!(A.changedTouches.length<=0))for(let g=0;g<A.changedTouches.length;g++){const e=A.changedTouches[g],i=this.getPointerIndex(e.identifier);if(!this.isNewEvent(A.timeStamp,i,this._pointerUpTimestamp))continue;Rt&&Ki(`touch up #${i}, identifier:${e.identifier}`);const t={button:i,clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:A};this.onUp(t)}}onMouseDown(A){if(A.defaultPrevented||this.canReceiveInput(A)===!1)return;let g=A.button;this.onDown({button:g,clientX:A.clientX,clientY:A.clientY,pointerType:"mouse",source:A})}onMouseMove(A){if(A.defaultPrevented)return;const g={button:A.button,clientX:A.clientX,clientY:A.clientY,pointerType:"mouse",source:A,movementX:A.movementX,movementY:A.movementY};this.onMove(g)}onMouseUp(A){if(A.defaultPrevented)return;let g=A.button;this.isNewEvent(A.timeStamp,g,this._pointerUpTimestamp)&&this.onUp({button:g,clientX:A.clientX,clientY:A.clientY,pointerType:"mouse",source:A})}isNewEvent(A,g,e){for(;e.length<=g;)e.push(-1);return A===e[g]?!1:(e[g]=A,!0)}isInRect(A){if(this.context.isInXR)return!0;const g=this.context.domElement.getBoundingClientRect(),e=A.clientX,i=A.clientY,t=e>=g.x&&e<=g.right&&i>=g.y&&i<=g.bottom;return Rt&&!t&&console.log("Not in rect",g,e,i),t}onDown(A){if(Rt&&console.log(A.pointerType,"DOWN",A.button),!!this.isInRect(A)){for(this.setPointerState(A.button,this._pointerPressed,!0),this.setPointerState(A.button,this._pointerDown,!0),this.setPointerStateT(A.button,this._pointerEvent,A.source);A.button>=this._pointerTypes.length;)this._pointerTypes.push(A.pointerType);for(this._pointerTypes[A.button]=A.pointerType;A.button>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new gA);for(this._pointerPositionDown[A.button].set(A.clientX,A.clientY);A.button>=this._pointerPositions.length;)this._pointerPositions.push(new gA);this._pointerPositions[A.button].set(A.clientX,A.clientY),A.button>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[A.button]=this.context.time.time,this.updatePointerPosition(A),this.onDispatchEvent("pointerdown",A)}}onMove(A){const g=this.getPointerPressed(A.button);g===!1&&!this.isInRect(A)||A.pointerType==="touch"&&!g||(Rt&&console.log(A.pointerType,"MOVE",A.button),this.updatePointerPosition(A),this.setPointerStateT(A.button,this._pointerEvent,A.source),this.onDispatchEvent("pointermove",A))}onUp(A){var g;if(((g=this._pointerIds)==null?void 0:g.length)>=A.button&&(this._pointerIds[A.button]=-1),!this._pointerPressed[A.button]){Rt&&console.log(A.pointerType,"UP",A.button,"was not down");return}if(Rt&&console.log(A.pointerType,"UP",A.button),this.setPointerState(A.button,this._pointerPressed,!1),this.setPointerStateT(A.button,this._pointerEvent,A.source),this.setPointerState(A.button,this._pointerUp,!0),this.updatePointerPosition(A),!this._pointerPositionDown[A.button]){Rt&&Ut("Received pointer up event without matching down event for button: "+A.button),console.warn("Received pointer up event without matching down event for button: "+A.button);return}const e=A.clientX-this._pointerPositionDown[A.button].x,i=A.clientY-this._pointerPositionDown[A.button].y;if(A.button>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(e)<5&&Math.abs(i)<5){this.setPointerState(A.button,this._pointerClick,!0);const t=this._pointerUpTime[A.button],C=this.context.time.time-t;C<this._doubleClickTimeThreshold&&C>0&&this.setPointerState(A.button,this._pointerDoubleClick,!0)}this._pointerUpTime[A.button]=this.context.time.time,this.onDispatchEvent("pointerup",A)}updatePointerPosition(A){for(;A.button>=this._pointerPositions.length;)this._pointerPositions.push(new gA);for(;A.button>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new gA);for(;A.button>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new gA);const g=this._pointerPositionsLastFrame[A.button];g.copy(this._pointerPositions[A.button]);const e=A.clientX-g.x,i=A.clientY-g.y;this._pointerPositionsDelta[A.button].set(e,i),this._pointerPositions[A.button].x=A.clientX,this._pointerPositions[A.button].y=A.clientY;const t=A.clientX,C=A.clientY;for(;A.button>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new gA);const o=this._pointerPositionsRC[A.button];o.set(t,C),this.convertScreenspaceToRaycastSpace(o)}getPointerIndex(A){const g=this._pointerIds;let e=-1;for(let i=0;i<g.length;i++){if(g[i]===A)return i;e===-1&&g[i]===-1&&(e=i)}return e!==-1?(g[e]=A,e):(g.push(A),g.length-1)}setPointerState(A,g,e){for(;g.length<=A;)g.push(!1);g[A]=e}setPointerStateT(A,g,e){for(;g.length<=A;)g.push(null);g[A]=e}onDispatchEvent(A,g){const e=Dg.Current;try{Dg.Current=this.context;const i=new Event(A);mB(i,g),this.dispatchEvent(i)}finally{Dg.Current=e}}}class xO{random(){return Math.random()}clamp(A,g,e){return A<g?g:A>e?e:A}clamp01(A){return this.clamp(A,0,1)}lerp(A,g,e){return e=e<0?0:e,e=e>1?1:e,A+(g-A)*e}inverseLerp(A,g,e){return(e-A)/(g-A)}remap(A,g,e,i,t){return i+(t-i)*(A-g)/(e-g)}moveTowards(A,g,e){return A+=e,(e<0&&A<g||e>0&&A>g)&&(A=g),A}toDegrees(A){return A*180/Math.PI}toRadians(A){return A*Math.PI/180}gammaToLinear(A){return Math.pow(A,2.2)}linearToGamma(A){return Math.pow(A,1/2.2)}}const $A=new xO;function YO(I,A,g){const e=I.length(),i=A.length(),t=$A.lerp(e,i,g);return I.lerp(A,g).normalize().multiplyScalar(t)}new RA().setFromAxisAngle(new M(0,1,0),Math.PI);const Gy=new Da(()=>new M,100);function wg(I,A=null,g=!0){const e=A??Gy.get();return I?I.parent?(g&&I.updateWorldMatrix(!0,!1),I.matrixWorldNeedsUpdate&&I.updateMatrixWorld(),e.setFromMatrixPosition(I.matrixWorld),e):e.copy(I.position):e.set(0,0,0)}function ye(I,A){if(!I)return;const g=Gy.get();A!==g&&g.copy(A),(I?.parent??I).worldToLocal(g),I.position.set(g.x,g.y,g.z)}function ur(I,A,g,e){const i=Gy.get();i.set(A,g,e),ye(I,i)}const UB=new RA,wr=new RA,fy=new RA;function Ji(I,A=null){if(!I)return wr.set(0,0,0,1);const g=A??wr;return I.parent?(I.getWorldQuaternion(g),g):g.copy(I.quaternion)}function Zt(I,A){if(!I)return;A!==UB&&UB.copy(A);const g=UB,e=I?.parent;e?.getWorldQuaternion(fy),fy.invert();const i=fy.multiply(g);I.quaternion.set(i.x,i.y,i.z,i.w)}function HO(I,A,g,e,i){UB.set(A,g,e,i),Zt(I,UB)}const Ll=new M;new M;function Qi(I,A=null){return I?I.parent?(I.getWorldScale(A??Ll),A??Ll):Ll.copy(I.scale):Ll.set(0,0,0)}new M;const yU=new $I,SU=new $I,TO=new M;function OO(I){return I.getWorldQuaternion(wr),SU.setFromQuaternion(wr),SU}function _O(I,A){Zt(I,wr.setFromEuler(A))}function kU(I){const A=OO(I),g=TO;return g.set(A.x,A.y,A.z),g.x=$A.toDegrees(g.x),g.y=$A.toDegrees(g.y),g.z=$A.toDegrees(g.z),g}function GU(I,A,g,e,i=!0){i&&(A=$A.toRadians(A),g=$A.toRadians(g),e=$A.toRadians(e)),yU.set(A,g,e),UB.setFromEuler(yU),Zt(I,UB)}function My(I,A=!0){I&&(A?function g(e){console.groupCollapsed((e.name?e.name:"(no name : "+e.type+")")+" %o",e),e.children.forEach(g),console.groupEnd()}(I):I.traverse(function(g){for(var e="|___",i=g;i.parent!==null;)e=" "+e,i=i.parent;console.log(e+g.name+" <"+g.type+">")}))}function PO(I){if(I){const A=I;return A.blendMode!==void 0&&A.clampWhenFinished!==void 0&&A.enabled!==void 0&&A.fadeIn!==void 0&&A.getClip!==void 0}return!1}const yr=class{static createBlitMaterial(I){return new xg({uniforms:{map:new GA(null)},vertexShader:this.vertex,fragmentShader:I})}static copyTexture(I,A){const g=A??this.blipMaterial;g.uniforms.map.value=I,g.needsUpdate=!0,g.uniformsNeedUpdate=!0;const e=this.mesh;e.material=g,e.frustumCulled=!1,this.scene.children.length=0,this.scene.add(e),this.renderer.setSize(I.image.width,I.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const i=new Ng(this.renderer.domElement);return i.name="Copy",i.needsUpdate=!0,i}static textureToCanvas(I,A){if(!I)return null;(A===!0||I.isCompressedTexture===!0)&&(I=jO(I));const g=I.image;if(WO(g)){const e=document.createElement("canvas");e.width=g.width,e.height=g.height;const i=e.getContext("2d");return i?(i.drawImage(g,0,0,g.width,g.height,0,0,e.width,e.height),e):(console.error("Failed getting canvas 2d context"),null)}return null}};let $C=yr;Q($C,"planeGeometry",new Je(2,2,1,1)),Q($C,"renderer",new Za({antialias:!1})),Q($C,"perspectiveCam",new Zg),Q($C,"scene",new et),Q($C,"vertex",`
3243
+ <a href="https://docs.needle.tools/serializable" target="_blank">documentation</a>`),console.warn(i,C,I[C],I);continue}}}}function qO(I,A){for(const g of Object.keys(A)){const e=A[g];if(typeof e=="object"&&e!==null&&e!==void 0){const i=I[g];if(!i){MB&&console.log(g,"is undefined on",I);continue}for(const t of Object.keys(e))i[t]===void 0&&wU(e[t])&&!wU(i)&&(i[t]=e[t])}}}function wU(I){switch(typeof I){case"number":case"string":case"boolean":return!0}return!1}function yy(I,A,g,e,i){let t=typeof A=="function"&&A.prototype===void 0,C=A;if(t)try{if(C=A?.call(A,i),t=!1,C==null)return}catch(a){console.error("Error in callback",a,I)}if(g.type=C,!t&&i instanceof C)return i;if(i&&typeof i=="object"&&mO(i)){if(i.__concreteInstance)return i.__concreteInstance;const a=i;if(!a.$serializedTypes&&C.prototype.$serializedTypes&&(a.$serializedTypes=C.prototype.$serializedTypes),a.$serializedTypes&&wy(a,I,g),i&&C!==void 0)try{const n=new C;Ye&&console.log("Create concrete instance for persistent asset",i,"instance:",n),mB(n,i),i.__concreteInstance=n,i=n}catch(n){console.error("Error creating instance or creating values on instance",n,i,C)}return i}if(e||(e={serializer:ql.getSerializerForConstructor(C)}),Array.isArray(I)){const a=[];for(let n=0;n<I.length;n++){const r=I[n],E=yy(r,A,g,e,r);a.push(E)}return a}const o=e.serializer;if(o)return o.onDeserialize(I,g);let s;if(I&&(I.isMaterial||I.isTexture||I.isObject3D))s=I;else{if(I===void 0)return;if(I===null&&(C===fg||C===Ng||C===fA||C===mt))return null;s=new C(...bO(I))}const B=s;return B.$serializedTypes&&wy(B,I,g),s}function bO(I){if(bl.length=0,typeof I=="object"&&I!==null&&I!==void 0)for(const A of Object.keys(I))bl.push(I[A]);return bl}const Sy=Symbol("assigned component properties");function mB(I,A,g){var e;if(A==null||I==null)return;I[Sy]=!0;const i=((e=I.constructor)==null?void 0:e.name)??"unknown";g?.registerDefinedKeys(i,I);for(const t of Object.keys(A)){const C=LO(I,t);typeof C?.value!="function"&&(!C||C.writable===!0||C?.set!==void 0)&&(I[t]=A[t])}delete I[Sy]}function LO(I,A){let g;do g=Object.getOwnPropertyDescriptor(I,A);while(!g&&(I=Object.getPrototypeOf(I)));return g}const Rt=EA("debuginput");class ky{constructor(A){Q(this,"key"),Q(this,"keyType"),Q(this,"source"),this.key=A.key,this.keyType=A.type,this.source=A}}var XC=(I=>(I.PointerDown="pointerdown",I.PointerUp="pointerup",I.PointerMove="pointermove",I.KeyDown="keydown",I.KeyUp="keyup",I.KeyPressed="keypress",I))(XC||{});class vO extends EventTarget{constructor(A){super(),Q(this,"_doubleClickTimeThreshold",.2),Q(this,"_longPressTimeThreshold",1),Q(this,"_specialCursorTrigger",0),Q(this,"context"),Q(this,"_pointerDown",[!1]),Q(this,"_pointerUp",[!1]),Q(this,"_pointerClick",[!1]),Q(this,"_pointerDoubleClick",[!1]),Q(this,"_pointerPressed",[!1]),Q(this,"_pointerPositions",[new gA]),Q(this,"_pointerPositionsLastFrame",[new gA]),Q(this,"_pointerPositionsDelta",[new gA]),Q(this,"_pointerPositionsRC",[new gA]),Q(this,"_pointerPositionDown",[new gA]),Q(this,"_pointerDownTime",[]),Q(this,"_pointerUpTime",[]),Q(this,"_pointerUpTimestamp",[]),Q(this,"_pointerIds",[]),Q(this,"_pointerTypes",[""]),Q(this,"_mouseWheelChanged",[!1]),Q(this,"_mouseWheelDeltaY",[0]),Q(this,"_pointerEvent",[]),Q(this,"keysPressed",{}),this.context=A,this.context.post_render_callbacks.push(this.onEndOfFrame.bind(this)),window.addEventListener("touchstart",this.onTouchStart.bind(this),!1),window.addEventListener("touchmove",this.onTouchMove.bind(this),{passive:!0}),window.addEventListener("touchend",this.onTouchUp.bind(this),!1),window.addEventListener("mousedown",this.onMouseDown.bind(this),!1),window.addEventListener("mousemove",this.onMouseMove.bind(this),!1),window.addEventListener("mouseup",this.onMouseUp.bind(this),!1),window.addEventListener("wheel",this.onMouseWheel.bind(this),{passive:!0}),window.addEventListener("keydown",this.onKeyDown.bind(this),!1),window.addEventListener("keypress",this.onKeyPressed.bind(this),!1),window.addEventListener("keyup",this.onKeyUp.bind(this),!1),window.addEventListener("blur",this.onLostFocus.bind(this))}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")}getPointerPressedCount(){let A=0;for(let g=0;g<this._pointerPressed.length;g++)this._pointerPressed[g]&&A++;return A}getPointerPosition(A){return A>=this._pointerPositions.length?null:this._pointerPositions[A]}getPointerPositionLastFrame(A){return A>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[A]}getPointerPositionDelta(A){return A>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[A]}getPointerPositionRC(A){return A>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[A]}getPointerDown(A){return A>=this._pointerDown.length?!1:this._pointerDown[A]}getPointerUp(A){return A>=this._pointerUp.length?!1:this._pointerUp[A]}getPointerPressed(A){return A>=this._pointerPressed.length?!1:this._pointerPressed[A]}getPointerClicked(A){return A>=this._pointerClick.length?!1:this._pointerClick[A]}getPointerDoubleClicked(A){return A>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[A]}getPointerDownTime(A){return A>=this._pointerDownTime.length?-1:this._pointerDownTime[A]}getPointerUpTime(A){return A>=this._pointerUpTime.length?-1:this._pointerUpTime[A]}getPointerLongPress(A){return A>=this._pointerDownTime.length?!1:this.getPointerPressed(A)&&this.context.time.time-this._pointerDownTime[A]>this._longPressTimeThreshold}getIsMouse(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="mouse"}getIsTouch(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="touch"}getTouchesPressedCount(){let A=0;for(let g=0;g<this._pointerPressed.length;g++)this._pointerPressed[g]&&this.getIsTouch(g)&&A++;return A}getMouseWheelChanged(A=0){return A>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[A]}getMouseWheelDeltaY(A=0){return A>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[A]}getPointerEvent(A){if(!(A>=this._pointerEvent.length))return this._pointerEvent[A]??void 0}*foreachPointerId(A){for(let g=0;g<this._pointerTypes.length;g++)if(this._pointerIsActive(g)){if(A!==void 0){const e=this._pointerTypes[g];if(Array.isArray(A)){let i=!1;for(const t of A)if(e===t){i=!0;break}if(!i)continue}else if(A!==e)continue}yield g}}*foreachTouchId(){for(let A=0;A<this._pointerTypes.length;A++)this._pointerTypes[A]==="touch"&&this._pointerIsActive[A]&&(yield A)}_pointerIsActive(A){return A<0?!1:this._pointerPressed[A]||this._pointerDown[A]||this._pointerUp[A]}getKeyDown(){for(const A in this.keysPressed){const g=this.keysPressed[A];if(g.startFrame===this.context.time.frameCount)return g.key}return null}getKeyPressed(){for(const A in this.keysPressed){const g=this.keysPressed[A];if(g.pressed)return g.key}return null}isKeyDown(A){var g;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyDown(i))return!0;return!1}return((g=this.keysPressed[A])==null?void 0:g.startFrame)===this.context.time.frameCount&&this.keysPressed[A].pressed}isKeyUp(A){var g;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyUp(i))return!0;return!1}return((g=this.keysPressed[A])==null?void 0:g.frame)===this.context.time.frameCount&&!this.keysPressed[A].pressed}isKeyPressed(A){var g;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyPressed(i))return!0;return!1}return(g=this.keysPressed[A])==null?void 0:g.pressed}getCodeForCommonKeyName(A){if(A.length===1){if(A>="0"&&A<="9")return["Digit"+A];if(A>="a"&&A<="z")return["Key"+A.toUpperCase()];if(A==" ")return["Space"]}switch(A){case"Shift":return["ShiftLeft","ShiftRight"];case"Control":return["ControlLeft","ControlRight"];case"Alt":return["AltLeft","AltRight"]}return null}createPointerDown(A){Rt&&Ki("Create Pointer down"),this.onDown(A)}createPointerMove(A){Rt&&Ki("Create Pointer move"),this.onMove(A)}createPointerUp(A){Rt&&Ki("Create Pointer up"),this.onUp(A)}convertScreenspaceToRaycastSpace(A){A.x=(A.x-this.context.domX)/this.context.domWidth*2-1,A.y=-((A.y-this.context.domY)/this.context.domHeight)*2+1}onLostFocus(){for(const A in this.keysPressed)this.keysPressed[A].pressed=!1}onEndOfFrame(){for(let A=0;A<this._pointerUp.length;A++)this._pointerUp[A]=!1;for(let A=0;A<this._pointerDown.length;A++)this._pointerDown[A]=!1;for(let A=0;A<this._pointerClick.length;A++)this._pointerClick[A]=!1;for(let A=0;A<this._pointerDoubleClick.length;A++)this._pointerDoubleClick[A]=!1;for(const A of this._pointerPositionsDelta)A.set(0,0);for(let A=0;A<this._mouseWheelChanged.length;A++)this._mouseWheelChanged[A]=!1;for(let A=0;A<this._mouseWheelDeltaY.length;A++)this._mouseWheelDeltaY[A]=0}canReceiveInput(A){return A.target===this.context.renderer.domElement}onKeyDown(A){if(!this.context.application.hasFocus)return;const g=this.keysPressed[A.code];g&&g.pressed||(this.keysPressed[A.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:A.key,code:A.code},this.onDispatchEvent("keydown",new ky(A)))}onKeyPressed(A){if(!this.context.application.hasFocus)return;const g=this.keysPressed[A.code];g&&(g.pressed=!0,g.frame=this.context.time.frameCount+1,this.onDispatchEvent("keypress",new ky(A)))}onKeyUp(A){if(!this.context.application.hasFocus)return;const g=this.keysPressed[A.code];g&&(g.pressed=!1,g.frame=this.context.time.frameCount+1,this.onDispatchEvent("keyup",new ky(A)))}onMouseWheel(A){if(this.canReceiveInput(A)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const g=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=g+A.deltaY}onTouchStart(A){if(!(A.changedTouches.length<=0)&&this.canReceiveInput(A)!==!1)for(let g=0;g<A.changedTouches.length;g++){const e=A.changedTouches[g],i=this.getPointerIndex(e.identifier);Rt&&Ki(`touch start #${i}, identifier:${e.identifier}`);const t={button:i,clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:A};this.onDown(t)}}onTouchMove(A){if(!(A.changedTouches.length<=0))for(let g=0;g<A.changedTouches.length;g++){const e=A.changedTouches[g],i={button:this.getPointerIndex(e.identifier),clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:A};this.onMove(i)}}onTouchUp(A){if(!(A.changedTouches.length<=0))for(let g=0;g<A.changedTouches.length;g++){const e=A.changedTouches[g],i=this.getPointerIndex(e.identifier);if(!this.isNewEvent(A.timeStamp,i,this._pointerUpTimestamp))continue;Rt&&Ki(`touch up #${i}, identifier:${e.identifier}`);const t={button:i,clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:A};this.onUp(t)}}onMouseDown(A){if(A.defaultPrevented||this.canReceiveInput(A)===!1)return;let g=A.button;this.onDown({button:g,clientX:A.clientX,clientY:A.clientY,pointerType:"mouse",source:A})}onMouseMove(A){if(A.defaultPrevented)return;const g={button:A.button,clientX:A.clientX,clientY:A.clientY,pointerType:"mouse",source:A,movementX:A.movementX,movementY:A.movementY};this.onMove(g)}onMouseUp(A){if(A.defaultPrevented)return;let g=A.button;this.isNewEvent(A.timeStamp,g,this._pointerUpTimestamp)&&this.onUp({button:g,clientX:A.clientX,clientY:A.clientY,pointerType:"mouse",source:A})}isNewEvent(A,g,e){for(;e.length<=g;)e.push(-1);return A===e[g]?!1:(e[g]=A,!0)}isInRect(A){if(this.context.isInXR)return!0;const g=this.context.domElement.getBoundingClientRect(),e=A.clientX,i=A.clientY,t=e>=g.x&&e<=g.right&&i>=g.y&&i<=g.bottom;return Rt&&!t&&console.log("Not in rect",g,e,i),t}onDown(A){if(Rt&&console.log(A.pointerType,"DOWN",A.button),!!this.isInRect(A)){for(this.setPointerState(A.button,this._pointerPressed,!0),this.setPointerState(A.button,this._pointerDown,!0),this.setPointerStateT(A.button,this._pointerEvent,A.source);A.button>=this._pointerTypes.length;)this._pointerTypes.push(A.pointerType);for(this._pointerTypes[A.button]=A.pointerType;A.button>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new gA);for(this._pointerPositionDown[A.button].set(A.clientX,A.clientY);A.button>=this._pointerPositions.length;)this._pointerPositions.push(new gA);this._pointerPositions[A.button].set(A.clientX,A.clientY),A.button>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[A.button]=this.context.time.time,this.updatePointerPosition(A),this.onDispatchEvent("pointerdown",A)}}onMove(A){const g=this.getPointerPressed(A.button);g===!1&&!this.isInRect(A)||A.pointerType==="touch"&&!g||(Rt&&console.log(A.pointerType,"MOVE",A.button),this.updatePointerPosition(A),this.setPointerStateT(A.button,this._pointerEvent,A.source),this.onDispatchEvent("pointermove",A))}onUp(A){var g;if(((g=this._pointerIds)==null?void 0:g.length)>=A.button&&(this._pointerIds[A.button]=-1),!this._pointerPressed[A.button]){Rt&&console.log(A.pointerType,"UP",A.button,"was not down");return}if(Rt&&console.log(A.pointerType,"UP",A.button),this.setPointerState(A.button,this._pointerPressed,!1),this.setPointerStateT(A.button,this._pointerEvent,A.source),this.setPointerState(A.button,this._pointerUp,!0),this.updatePointerPosition(A),!this._pointerPositionDown[A.button]){Rt&&Ut("Received pointer up event without matching down event for button: "+A.button),console.warn("Received pointer up event without matching down event for button: "+A.button);return}const e=A.clientX-this._pointerPositionDown[A.button].x,i=A.clientY-this._pointerPositionDown[A.button].y;if(A.button>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(e)<5&&Math.abs(i)<5){this.setPointerState(A.button,this._pointerClick,!0);const t=this._pointerUpTime[A.button],C=this.context.time.time-t;C<this._doubleClickTimeThreshold&&C>0&&this.setPointerState(A.button,this._pointerDoubleClick,!0)}this._pointerUpTime[A.button]=this.context.time.time,this.onDispatchEvent("pointerup",A)}updatePointerPosition(A){for(;A.button>=this._pointerPositions.length;)this._pointerPositions.push(new gA);for(;A.button>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new gA);for(;A.button>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new gA);const g=this._pointerPositionsLastFrame[A.button];g.copy(this._pointerPositions[A.button]);const e=A.clientX-g.x,i=A.clientY-g.y;this._pointerPositionsDelta[A.button].set(e,i),this._pointerPositions[A.button].x=A.clientX,this._pointerPositions[A.button].y=A.clientY;const t=A.clientX,C=A.clientY;for(;A.button>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new gA);const o=this._pointerPositionsRC[A.button];o.set(t,C),this.convertScreenspaceToRaycastSpace(o)}getPointerIndex(A){const g=this._pointerIds;let e=-1;for(let i=0;i<g.length;i++){if(g[i]===A)return i;e===-1&&g[i]===-1&&(e=i)}return e!==-1?(g[e]=A,e):(g.push(A),g.length-1)}setPointerState(A,g,e){for(;g.length<=A;)g.push(!1);g[A]=e}setPointerStateT(A,g,e){for(;g.length<=A;)g.push(null);g[A]=e}onDispatchEvent(A,g){const e=Dg.Current;try{Dg.Current=this.context;const i=new Event(A);mB(i,g),this.dispatchEvent(i)}finally{Dg.Current=e}}}class xO{random(){return Math.random()}clamp(A,g,e){return A<g?g:A>e?e:A}clamp01(A){return this.clamp(A,0,1)}lerp(A,g,e){return e=e<0?0:e,e=e>1?1:e,A+(g-A)*e}inverseLerp(A,g,e){return(e-A)/(g-A)}remap(A,g,e,i,t){return i+(t-i)*(A-g)/(e-g)}moveTowards(A,g,e){return A+=e,(e<0&&A<g||e>0&&A>g)&&(A=g),A}toDegrees(A){return A*180/Math.PI}toRadians(A){return A*Math.PI/180}gammaToLinear(A){return Math.pow(A,2.2)}linearToGamma(A){return Math.pow(A,1/2.2)}}const $A=new xO;function YO(I,A,g){const e=I.length(),i=A.length(),t=$A.lerp(e,i,g);return I.lerp(A,g).normalize().multiplyScalar(t)}new RA().setFromAxisAngle(new M(0,1,0),Math.PI);const Gy=new Da(()=>new M,100);function wg(I,A=null,g=!0){const e=A??Gy.get();return I?I.parent?(g&&I.updateWorldMatrix(!0,!1),I.matrixWorldNeedsUpdate&&I.updateMatrixWorld(),e.setFromMatrixPosition(I.matrixWorld),e):e.copy(I.position):e.set(0,0,0)}function ye(I,A){if(!I)return;const g=Gy.get();A!==g&&g.copy(A),(I?.parent??I).worldToLocal(g),I.position.set(g.x,g.y,g.z)}function ur(I,A,g,e){const i=Gy.get();i.set(A,g,e),ye(I,i)}const UB=new RA,wr=new RA,fy=new RA;function Ji(I,A=null){if(!I)return wr.set(0,0,0,1);const g=A??wr;return I.parent?(I.getWorldQuaternion(g),g):g.copy(I.quaternion)}function Zt(I,A){if(!I)return;A!==UB&&UB.copy(A);const g=UB,e=I?.parent;e?.getWorldQuaternion(fy),fy.invert();const i=fy.multiply(g);I.quaternion.set(i.x,i.y,i.z,i.w)}function HO(I,A,g,e,i){UB.set(A,g,e,i),Zt(I,UB)}const Ll=new M;new M;function Qi(I,A=null){return I?I.parent?(I.getWorldScale(A??Ll),A??Ll):Ll.copy(I.scale):Ll.set(0,0,0)}new M;const yU=new $I,SU=new $I,TO=new M;function OO(I){return I.getWorldQuaternion(wr),SU.setFromQuaternion(wr),SU}function _O(I,A){Zt(I,wr.setFromEuler(A))}function kU(I){const A=OO(I),g=TO;return g.set(A.x,A.y,A.z),g.x=$A.toDegrees(g.x),g.y=$A.toDegrees(g.y),g.z=$A.toDegrees(g.z),g}function GU(I,A,g,e,i=!0){i&&(A=$A.toRadians(A),g=$A.toRadians(g),e=$A.toRadians(e)),yU.set(A,g,e),UB.setFromEuler(yU),Zt(I,UB)}function My(I,A=!0){I&&(A?function g(e){console.groupCollapsed((e.name?e.name:"(no name : "+e.type+")")+" %o",e),e.children.forEach(g),console.groupEnd()}(I):I.traverse(function(g){for(var e="|___",i=g;i.parent!==null;)e=" "+e,i=i.parent;console.log(e+g.name+" <"+g.type+">")}))}function PO(I){if(I){const A=I;return A.blendMode!==void 0&&A.clampWhenFinished!==void 0&&A.enabled!==void 0&&A.fadeIn!==void 0&&A.getClip!==void 0}return!1}const yr=class{static createBlitMaterial(I){return new xg({uniforms:{map:new GA(null)},vertexShader:this.vertex,fragmentShader:I})}static copyTexture(I,A){const g=A??this.blipMaterial;g.uniforms.map.value=I,g.needsUpdate=!0,g.uniformsNeedUpdate=!0;const e=this.mesh;e.material=g,e.frustumCulled=!1,this.scene.children.length=0,this.scene.add(e),this.renderer.setSize(I.image.width,I.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const i=new Ng(this.renderer.domElement);return i.name="Copy",i.needsUpdate=!0,i}static textureToCanvas(I,A){if(!I)return null;(A===!0||I.isCompressedTexture===!0)&&(I=jO(I));const g=I.image;if(WO(g)){const e=document.createElement("canvas");e.width=g.width,e.height=g.height;const i=e.getContext("2d");return i?(i.drawImage(g,0,0,g.width,g.height,0,0,e.width,e.height),e):(console.error("Failed getting canvas 2d context"),null)}return null}};let $C=yr;Q($C,"planeGeometry",new Je(2,2,1,1)),Q($C,"renderer",new Za({antialias:!1})),Q($C,"perspectiveCam",new Zg),Q($C,"scene",new et),Q($C,"vertex",`
3244
3244
  varying vec2 vUv;
3245
3245
  void main(){
3246
3246
  vUv = uv;
@@ -4738,7 +4738,7 @@ void main() {
4738
4738
  `,i=function(n,r,E){r=r||1024;let h=n.pos,c=-1,D=0,d="",w=String.fromCharCode.apply(null,new Uint16Array(n.subarray(h,h+128)));for(;0>(c=w.indexOf(e))&&D<r&&h<n.byteLength;)d+=w,D+=w.length,h+=128,w+=String.fromCharCode.apply(null,new Uint16Array(n.subarray(h,h+128)));return-1<c?(E!==!1&&(n.pos+=D+c+1),d+w.slice(0,c)):!1},t=function(n){const r=/^#\?(\S+)/,E=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,h=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,c=/^\s*FORMAT=(\S+)\s*$/,D=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,d={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let w,l;if(n.pos>=n.byteLength||!(w=i(n)))return g(1,"no header found");if(!(l=w.match(r)))return g(3,"bad initial token");for(d.valid|=1,d.programtype=l[1],d.string+=w+`
4739
4739
  `;w=i(n),w!==!1;){if(d.string+=w+`
4740
4740
  `,w.charAt(0)==="#"){d.comments+=w+`
4741
- `;continue}if((l=w.match(E))&&(d.gamma=parseFloat(l[1])),(l=w.match(h))&&(d.exposure=parseFloat(l[1])),(l=w.match(c))&&(d.valid|=2,d.format=l[1]),(l=w.match(D))&&(d.valid|=4,d.height=parseInt(l[1],10),d.width=parseInt(l[2],10)),d.valid&2&&d.valid&4)break}return d.valid&2?d.valid&4?d:g(3,"missing image size specifier"):g(3,"missing format specifier")},C=function(n,r,E){const h=r;if(h<8||h>32767||n[0]!==2||n[1]!==2||n[2]&128)return new Uint8Array(n);if(h!==(n[2]<<8|n[3]))return g(3,"wrong scanline width");const c=new Uint8Array(4*r*E);if(!c.length)return g(4,"unable to allocate buffer space");let D=0,d=0;const w=4*h,l=new Uint8Array(4),p=new Uint8Array(w);let u=E;for(;u>0&&d<n.byteLength;){if(d+4>n.byteLength)return g(1);if(l[0]=n[d++],l[1]=n[d++],l[2]=n[d++],l[3]=n[d++],l[0]!=2||l[1]!=2||(l[2]<<8|l[3])!=h)return g(3,"bad rgbe scanline format");let y=0,k;for(;y<w&&d<n.byteLength;){k=n[d++];const G=k>128;if(G&&(k-=128),k===0||y+k>w)return g(3,"bad scanline data");if(G){const f=n[d++];for(let K=0;K<k;K++)p[y++]=f}else p.set(n.subarray(d,d+k),y),y+=k,d+=k}const S=h;for(let G=0;G<S;G++){let f=0;c[D]=p[G+f],f+=h,c[D+1]=p[G+f],f+=h,c[D+2]=p[G+f],f+=h,c[D+3]=p[G+f],D+=4}u--}return c},o=function(n,r,E,h){const c=n[r+3],D=Math.pow(2,c-128)/255;E[h+0]=n[r+0]*D,E[h+1]=n[r+1]*D,E[h+2]=n[r+2]*D,E[h+3]=1},s=function(n,r,E,h){const c=n[r+3],D=Math.pow(2,c-128)/255;E[h+0]=fB.toHalfFloat(Math.min(n[r+0]*D,65504)),E[h+1]=fB.toHalfFloat(Math.min(n[r+1]*D,65504)),E[h+2]=fB.toHalfFloat(Math.min(n[r+2]*D,65504)),E[h+3]=fB.toHalfFloat(1)},B=new Uint8Array(A);B.pos=0;const a=t(B);if(a!==-1){const n=a.width,r=a.height,E=C(B.subarray(B.pos),n,r);if(E!==-1){let h,c,D;switch(this.type){case HI:D=E.length/4;const d=new Float32Array(D*4);for(let l=0;l<D;l++)o(E,l*4,d,l*4);h=d,c=HI;break;case Ae:D=E.length/4;const w=new Uint16Array(D*4);for(let l=0;l<D;l++)s(E,l*4,w,l*4);h=w,c=Ae;break;default:console.error("THREE.RGBELoader: unsupported type: ",this.type);break}return{width:n,height:r,data:h,header:a.string,gamma:a.gamma,exposure:a.exposure,type:c}}}return null}setDataType(A){return this.type=A,this}load(A,g,e,i){function t(C,o){switch(C.type){case HI:case Ae:C.encoding=RI,C.minFilter=qg,C.magFilter=qg,C.generateMipmaps=!1,C.flipY=!0;break}g&&g(C,o)}return super.load(A,t,e,i)}}const Tq=EA("debugautosync"),nG=Symbol("syncerId");class u5{constructor(){Q(this,"_syncers",{})}getOrCreateSyncer(A){if(!A.guid)return null;if(this._syncers[A.guid])return this._syncers[A.guid];const g=new w5(A);return g[nG]=A.guid,this._syncers[g[nG]]=g,g}removeSyncer(A){delete this._syncers[A[nG]]}}const rG=new u5;class w5{constructor(A){Q(this,"comp"),Q(this,"hasChanges",!1),Q(this,"changedProperties",{}),Q(this,"data",{}),Q(this,"_boundEvent"),Q(this,"_handleReceivingMethod"),Q(this,"_isReceiving",!1),Q(this,"_isInit",!1),this.comp=A}get networkingKey(){return this.comp.constructor.name}init(A){if(this._isInit)return;this._isInit=!0,this.comp=A,this._boundEvent=this.onHandleSending.bind(this),this.comp.context.post_render_callbacks.push(this._boundEvent),this._handleReceivingMethod=this.onHandleReceiving.bind(this),this.comp.context.connection.beginListen(this.networkingKey,this._handleReceivingMethod);const g=this.comp.context.connection.tryGetState(this.comp.guid);g&&this.onHandleReceiving(g)}destroy(){this._isInit&&(this._boundEvent&&this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this._boundEvent),1),this._handleReceivingMethod&&this.comp.context.connection.stopListen(this.networkingKey,this._handleReceivingMethod),this.comp=null,this._isInit=!1)}notifyChanged(A,g){this._isReceiving||(this.hasChanges=!0,this.changedProperties[A]=g)}onHandleSending(){if(!this.hasChanges)return;this.hasChanges=!1;const A=this.comp.context.connection;if(!A||!A.isConnected){for(const g in this.changedProperties)delete this.changedProperties[g];return}for(const g in this.data)delete this.data[g];this.data.guid=this.comp.guid;for(const g in this.changedProperties){const e=this.changedProperties[g];delete this.changedProperties[g],this.data[g]=e}A.send(this.networkingKey,this.data)}onHandleReceiving(A){if(!this._isInit||!this.comp)return;const g=A.guid;if(!(g&&g!==this.comp.guid)){Tq&&console.log("RECEIVED",this.comp.name,this.comp.guid,A);try{this._isReceiving=!0;for(const e in A){if(e==="guid")continue;const i=A[e];this.comp[e]=i}}catch(e){console.error(e)}finally{this._isReceiving=!1}}}}function y5(I,A){let g=A!==I;if(!g&&I&&A){if(Array.isArray(I)&&Array.isArray(A))g=!0;else if(typeof I=="object"&&typeof A=="object"){for(const e of Object.keys(I))if(I[e]!==A[e]){g=!0;break}}}return g}const rh=Symbol("AutoSyncHandler");function S5(I){if(I[rh])return I[rh];const A=rG.getOrCreateSyncer(I);return A?.init(I),I[rh]=A,A}function k5(I){const A=I[rh];A&&(rG.removeSyncer(A),A.destroy(),delete I[rh])}const Oq=function(I){return function(A,g){let e=null,i;typeof I=="string"?i=A[I]:typeof I=="function"&&(i=I);const t=A,C=t.__internalAwake;Tq&&console.log(g);const o=Symbol(g);t.__internalAwake=function(){if(this[o]!==void 0)return;this[o]=this[g],C.call(this),e=rG.getOrCreateSyncer(this);const B=Object.getOwnPropertyDescriptor(this,g);B?.set===void 0&&Object.defineProperty(this,g,{set:function(a){var n;const r=this[o];this[o]=a,y5(a,r)&&i?.call(this,a,r)!==!1&&((n=S5(this))==null||n.notifyChanged(g,a))},get:function(){return this[o]},configurable:!0,enumerable:!0}),e?.init(this)};const s=t.__internalDestroy;t.__internalDestroy=function(){k5(this),s.call(this)}}};var G5=Object.defineProperty,f5=Object.getOwnPropertyDescriptor,Ep=(I,A,g,e)=>{for(var i=e>1?void 0:e?f5(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&G5(A,g,i),i};const Eh=EA("debugskybox");class Ba extends qA{constructor(){super(...arguments),Q(this,"url"),Q(this,"allowDrop",!0),Q(this,"background",!0),Q(this,"environment",!0),Q(this,"_loader"),Q(this,"_prevUrl"),Q(this,"_prevLoadedEnvironment"),Q(this,"_prevEnvironment",null),Q(this,"_prevBackground",null),Q(this,"dragOverEvent"),Q(this,"dropEvent")}onEnable(){this.setSkybox(this.url),this.registerDropEvents()}onDisable(){var A;this.context.scene.environment===this._prevLoadedEnvironment&&(this.context.scene.environment=this._prevEnvironment,SI.backgroundShouldBeTransparent(this.context)||(this.context.scene.background=this._prevBackground),this._prevLoadedEnvironment=void 0),this.unregisterDropEvents(),(A=this.context.mainCameraComponent)==null||A.applyClearFlags()}async setSkybox(A){var g;if(!A)return;if(!(A!=null&&A.endsWith(".hdr"))&&!A.endsWith(".exr")&&!A.endsWith(".jpg")&&!A.endsWith(".png")&&!A.endsWith(".jpeg")&&console.warn("Potentially invalid skybox url",this.url,"on",this.name),Eh&&console.log("Remote skybox url?: "+A),this._prevUrl===A&&this._prevLoadedEnvironment){this.applySkybox();return}else(g=this._prevLoadedEnvironment)==null||g.dispose(),this._prevLoadedEnvironment=void 0;this._prevUrl=A;const e=A.endsWith(".exr"),i=A.endsWith(".hdr");e?this._loader instanceof w0||(this._loader=new w0):i?this._loader instanceof Hq||(this._loader=new Hq):this._loader instanceof uB||(this._loader=new uB),Eh&&console.log("Loading skybox: "+A);const t=await this._loader.loadAsync(A);if(!t||!this.enabled)return;this.url=A;const C=A.lastIndexOf("/");t.name=A.substring(C>=0?C+1:0),this._loader instanceof uB&&(t.encoding=VA),this._prevLoadedEnvironment=t,this.applySkybox()}applySkybox(){var A;const g=this._prevLoadedEnvironment;g&&(g.mapping=Sa,g.needsUpdate=!0,this.context.scene.background!==g&&(this._prevBackground=this.context.scene.background),this.context.scene.environment!==g&&(this._prevEnvironment=this.context.scene.environment),Eh&&console.log("Set remote skybox",this.url),this.environment&&(this.context.scene.environment=g),this.background&&!SI.backgroundShouldBeTransparent(this.context)&&(this.context.scene.background=g),((A=this.context.mainCameraComponent)==null?void 0:A.backgroundBlurriness)!==void 0&&(this.context.scene.backgroundBlurriness=this.context.mainCameraComponent.backgroundBlurriness))}registerDropEvents(){this.dragOverEvent||(this.dragOverEvent=A=>{if(this.allowDrop&&A.dataTransfer)for(const g of A.dataTransfer.types)g==="text/uri-list"&&A.preventDefault()},this.dropEvent=A=>{var g,e,i,t;if(this.allowDrop&&(A.preventDefault(),!!A.dataTransfer)){for(const C of A.dataTransfer.types)if(C==="text/uri-list"){const o=A.dataTransfer.getData(C);Eh&&console.log(C,o);let s=(e=(g=new RegExp(/polyhaven.com\/asset_img\/.+?\/(?<name>.+)\.png/).exec(o))==null?void 0:g.groups)==null?void 0:e.name;if(s||(s=(t=(i=new RegExp(/polyhaven\.com\/a\/(?<name>.+)/).exec(o))==null?void 0:i.groups)==null?void 0:t.name),Eh&&console.log(s),s){const B="https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/"+s+"_1k.exr";this.setSkybox(B)}else console.warn("Could not resolve skybox name from dropped url",o)}}},this.context.domElement.addEventListener("dragover",this.dragOverEvent),this.context.domElement.addEventListener("drop",this.dropEvent))}unregisterDropEvents(){this.dragOverEvent&&(this.context.domElement.removeEventListener("dragover",this.dragOverEvent),this.context.domElement.removeEventListener("drop",this.dropEvent))}}Ep([Oq("setSkybox"),m(URL)],Ba.prototype,"url",2),Ep([m()],Ba.prototype,"allowDrop",2),Ep([m()],Ba.prototype,"background",2),Ep([m()],Ba.prototype,"environment",2);var M5=Object.defineProperty,m5=Object.getOwnPropertyDescriptor,ln=(I,A,g,e)=>{for(var i=e>1?void 0:e?m5(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&M5(A,g,i),i};const _q=EA("debugsceneswitcher"),hh="scene";Qe.registerCallback(pt.ContextRegistered,I=>{YG.observedAttributes.includes(hh)||YG.observedAttributes.push(hh)});const Dn=Promise.resolve(!1);class Mo extends qA{constructor(){super(...arguments),Q(this,"scenes"),Q(this,"queryParameterName","scene"),Q(this,"clamp",!0),Q(this,"useHistory",!0),Q(this,"useKeyboard",!0),Q(this,"useSwipe",!0),Q(this,"_currentIndex",-1),Q(this,"_currentScene"),Q(this,"_engineElementOverserver"),Q(this,"onPopState",async A=>{if(!this.useHistory)return;let g=this.useHistory;try{this.useHistory=!1,await this.tryLoadFromQueryParam()}finally{this.useHistory=g}}),Q(this,"normalizedSwipeThresholdX",.1),Q(this,"_didSwipe",!1),Q(this,"onPointerMove",A=>{if(!this._didSwipe&&A.button===0&&A.pointerType==="touch"&&this.context.input.getPointerPressedCount()===1){const g=this.context.input.getPointerPositionDelta(A.button);if(g){const e=g.x/this.context.domWidth;e>=this.normalizedSwipeThresholdX?(this._didSwipe=!0,this.selectPrev()):e<=-this.normalizedSwipeThresholdX&&(this._didSwipe=!0,this.selectNext())}}}),Q(this,"onPointerUp",A=>{A.button===0&&(this._didSwipe=!1)}),Q(this,"onKeyDown",A=>{if(!this.useKeyboard||!this.scenes)return;const g=A.key.toLowerCase();if(!g)return;const e=parseInt(g)-1;if(e>=0){this.trySelectSceneFromValue(e);return}switch(g){case"arrowright":case"d":this.selectNext();break;case"arrowleft":case"a":this.selectPrev();break}})}async start(){if(this._currentIndex===-1&&!await this.tryLoadFromQueryParam()){const A=this.context.domElement.getAttribute(hh);try{(A===null||!await this.trySelectSceneFromValue(A))&&this._currentIndex===-1&&this.select(0)}finally{}}}onEnable(){globalThis.addEventListener("popstate",this.onPopState),this.context.input.addEventListener(XC.KeyDown,this.onKeyDown),this.context.input.addEventListener(XC.PointerMove,this.onPointerMove),this.context.input.addEventListener(XC.PointerUp,this.onPointerUp),this._engineElementOverserver||(this._engineElementOverserver=new MutationObserver(A=>{for(const g of A)if(g.type==="attributes"&&g.attributeName===hh){const e=this.context.domElement.getAttribute(hh);e!==null&&this.trySelectSceneFromValue(e)}})),this._engineElementOverserver.observe(this.context.domElement,{attributes:!0})}onDisable(){globalThis.removeEventListener("popstate",this.onPopState),this.context.input.removeEventListener(XC.KeyDown,this.onKeyDown),this.context.input.removeEventListener(XC.PointerMove,this.onPointerMove),this.context.input.removeEventListener(XC.PointerUp,this.onPointerUp)}selectNext(){return this.select(this._currentIndex+1)}selectPrev(){return this.select(this._currentIndex-1)}select(A){var g;if(_q&&console.log("select",A),!((g=this.scenes)!=null&&g.length))return Dn;if(A<0){if(this.clamp)return Dn;A=this.scenes.length-1}else if(A>=this.scenes.length){if(this.clamp)return Dn;A=0}const e=this.scenes[A];return this.switchScene(e)}async switchScene(A){var g,e;if(A===this._currentScene)return!0;this._currentScene&&this._currentScene.unload();const i=this._currentIndex=((g=this.scenes)==null?void 0:g.indexOf(A))??-1;this._currentScene=A;try{if(await A.loadAssetAsync(),!A.asset)return _q&&console.warn("Failed loading scene:",A),!1;if(this._currentIndex===i)return iA.add(A.asset,this.gameObject),(e=this.queryParameterName)!=null&&e.length&&zG(this.queryParameterName,i.toString(),this.useHistory),!0}catch(t){console.error(t)}return!1}tryLoadFromQueryParam(){var A;if(!((A=this.queryParameterName)!=null&&A.length))return Dn;const g=EA(this.queryParameterName);return typeof g=="boolean"?Dn:this.trySelectSceneFromValue(g)}trySelectSceneFromValue(A){if(typeof A=="string"){const g=parseInt(A);if(g>=0&&g<this.scenes.length)return this.select(g);for(let e=0;e<this.scenes.length;e++)if(this.scenes[e].uri.toLowerCase().includes(A))return this.select(e)}else if(typeof A=="number"&&A>=0&&A<this.scenes.length)return this.select(A);return si()&&console.warn('Can not find scene: "'+A+'"',this),Dn}}ln([m(tC)],Mo.prototype,"scenes",2),ln([m()],Mo.prototype,"queryParameterName",2),ln([m()],Mo.prototype,"clamp",2),ln([m()],Mo.prototype,"useHistory",2),ln([m()],Mo.prototype,"useKeyboard",2),ln([m()],Mo.prototype,"useSwipe",2);function U5(){return new Promise((I,A)=>{let g=()=>{g!=null&&(document.removeEventListener("pointerdown",g),document.removeEventListener("click",g),document.removeEventListener("dragstart",g),document.removeEventListener("touchstart",g),I())};document.addEventListener("pointerdown",g),document.addEventListener("click",g),document.addEventListener("dragstart",g),document.addEventListener("touchstart",g)})}async function R5(I){await U5(),I()}var Pq=(I=>(I[I.Quad=0]="Quad",I))(Pq||{});class F5{static createPrimitive(A,g){let e;switch(A){case 0:const i=new Je(1,1,1,1),t=g?.material??new sI({color:16777215});e=new fA(i,t)}return g!=null&&g.name&&(e.name=g.name),e}}var N5=Object.defineProperty,K5=Object.getOwnPropertyDescriptor,Ht=(I,A,g,e)=>{for(var i=e>1?void 0:e?K5(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&N5(A,g,i),i};const ch=EA("debugvideo");var jq=(I=>(I[I.CameraFarPlane=0]="CameraFarPlane",I[I.CameraNearPlane=1]="CameraNearPlane",I[I.RenderTexture=2]="RenderTexture",I[I.MaterialOverride=3]="MaterialOverride",I))(jq||{});class Pe extends qA{constructor(){super(),Q(this,"renderer",null),Q(this,"playOnAwake",!0),Q(this,"aspectMode",0),Q(this,"clip",null),Q(this,"renderMode"),Q(this,"targetMaterialProperty"),Q(this,"targetMaterialRenderer"),Q(this,"targetTexture"),Q(this,"time",0),Q(this,"_playbackSpeed",1),Q(this,"_isLooping",!1),Q(this,"_muted",!1),Q(this,"playInBackground",!0),Q(this,"_crossOrigin","anonymous"),Q(this,"audioOutputMode",1),Q(this,"source"),Q(this,"url",null),Q(this,"_videoElement",null),Q(this,"_videoTexture",null),Q(this,"_videoMaterial",null),Q(this,"_isPlaying",!1),Q(this,"wasPlaying",!1),Q(this,"_receivedInput",!1),Q(this,"_overlay",null),Q(this,"_targetObjects"),Q(this,"_updateAspectRoutineId",-1),R5(()=>{this._receivedInput=!0,this.updateVideoElementSettings()}),this._targetObjects=[],EA("videoscreenspace")&&window.addEventListener("keydown",A=>{A.key==="f"&&(this.screenspace=!this.screenspace)})}get playbackSpeed(){var A;return((A=this._videoElement)==null?void 0:A.playbackRate)??this._playbackSpeed}set playbackSpeed(A){this._playbackSpeed=A,this._videoElement&&(this._videoElement.playbackRate=A)}get isLooping(){var A;return((A=this._videoElement)==null?void 0:A.loop)??this._isLooping}set isLooping(A){this._isLooping=A,this._videoElement&&(this._videoElement.loop=A)}get currentTime(){var A;return((A=this._videoElement)==null?void 0:A.currentTime)??this.time}set currentTime(A){this._videoElement?this._videoElement.currentTime=A:this.time=A}get isPlaying(){const A=this._videoElement;return!!(A&&(A.currentTime>0&&!A.paused&&!A.ended&&A.readyState>A.HAVE_CURRENT_DATA||A.srcObject&&A.srcObject.active))}get crossOrigin(){var A;return((A=this._videoElement)==null?void 0:A.crossOrigin)??this._crossOrigin}set crossOrigin(A){this._crossOrigin=A,this._videoElement&&(A!==null?this._videoElement.setAttribute("crossorigin",A):this._videoElement.removeAttribute("crossorigin"))}get videoMaterial(){return this._videoMaterial}get videoTexture(){return this._videoTexture}get videoElement(){return this._videoElement}get muted(){var A;return((A=this._videoElement)==null?void 0:A.muted)??this._muted}set muted(A){this._muted=A,this._videoElement&&(this._videoElement.muted=A)}setVideo(A){this.clip=A,this.source=0,this._videoElement?(this._videoElement.srcObject=A,this._isPlaying&&this.play(),this.updateAspect()):this.create(!0)}setClipURL(A){this.url!==A&&(this.url=A,this.source=1,ch&&console.log("set url",A),this._videoElement?(this._videoElement.src=A,this._isPlaying&&(this.stop(),this.play())):this.create(!0))}awake(){this.create(this.playOnAwake),window.addEventListener("visibilitychange",A=>{switch(document.visibilityState){case"hidden":this.playInBackground||(this.wasPlaying=this._isPlaying,this.pause());break;case"visible":this.wasPlaying&&!this._isPlaying&&this.play();break}})}onEnable(){var A,g;this.playOnAwake===!0&&this.handleBeginPlaying(!0),this.screenspace?(A=this._overlay)==null||A.start():(g=this._overlay)==null||g.stop()}onDisable(){this.pause()}onDestroy(){var A;this._videoElement&&((A=this._videoElement.parentElement)==null||A.removeChild(this._videoElement),this._videoElement=null),this._videoTexture&&(this._videoTexture.dispose(),this._videoTexture=null)}play(){var A,g,e;this._videoElement&&(this._isPlaying&&!((A=this._videoElement)!=null&&A.ended)&&!((g=this._videoElement)!=null&&g.paused)||(this._isPlaying=!0,this._receivedInput||(this._videoElement.muted=!0),this.updateVideoElementSettings(),(e=this._videoElement)==null||e.play().catch(i=>{var t;ch&&console.error("Error playing video",i,"CODE="+i.code,(t=this.videoElement)==null?void 0:t.src,this),setTimeout(()=>{this._isPlaying&&!this.destroyed&&this.activeAndEnabled&&this.play()},1e3)}),ch&&console.log("play",this._videoElement)))}stop(){this._isPlaying=!1,this._videoElement&&(this._videoElement.currentTime=0,this._videoElement.pause())}pause(){var A;this._isPlaying=!1,(A=this._videoElement)==null||A.pause()}create(A){var g,e;let i;switch(this.source){case 0:i=this.clip;break;case 1:i=this.url;break}if(i){if(this._videoElement||(this._videoElement=this.createVideoElement(),(g=this.context.domElement)==null||g.prepend(this._videoElement),this.updateVideoElementStyles()),typeof i=="string"){this._videoElement.src=i;const t=(e=this._videoElement.captureStream)==null?void 0:e.call(this._videoElement);this.clip=t}else this._videoElement.srcObject=i;this._videoTexture||(this._videoTexture=new Bm(this._videoElement)),this._videoTexture.flipY=!1,this._videoTexture.encoding=VA,this.handleBeginPlaying(A),ch&&console.log(this)}}updateAspect(){this.aspectMode!==0&&this.startCoroutine(this.updateAspectImpl())}get screenspace(){var A;return((A=this._overlay)==null?void 0:A.enabled)??!1}set screenspace(A){var g;if(A){if(!this._videoTexture)return;this._overlay||(this._overlay=new J5(this.context)),this._overlay.add(this._videoTexture)}else(g=this._overlay)==null||g.remove(this._videoTexture);this._overlay&&(this._overlay.enabled=A)}createVideoElement(){const A=document.createElement("video");return this._crossOrigin&&A.setAttribute("crossorigin",this._crossOrigin),ch&&console.log("create video elment",A),A}handleBeginPlaying(A){var g,e;if(!this.enabled||!this._videoElement)return;this._targetObjects.length=0;let i=this.gameObject;switch(this.renderMode){case 3:i=(g=this.targetMaterialRenderer)==null?void 0:g.gameObject,i||(i=(e=iA.getComponent(this.gameObject,Be))==null?void 0:e.gameObject);break;case 2:console.error("VideoPlayer renderTexture not implemented yet. Please use material override instead");return}if(!i){console.error("Missing target for video material renderer",this.name,jq[this.renderMode],this);return}const t=i.material;if(t)if(this._targetObjects.push(i),t!==this._videoMaterial&&(this._videoMaterial=t.clone(),i.material=this._videoMaterial),!this.targetMaterialProperty)this._videoMaterial.map=this._videoTexture;else switch(this.targetMaterialProperty){default:this._videoMaterial.map=this._videoTexture;break}else{console.warn("Can not play video, no material found, this might be a multimaterial case which is not supported yet");return}this.updateVideoElementSettings(),this.updateVideoElementStyles(),A&&this.play()}updateVideoElementSettings(){if(!this._videoElement)return;this._videoElement.loop=this._isLooping,this._videoElement.currentTime=this.currentTime,this._videoElement.playbackRate=this._playbackSpeed,this._videoElement.playsInline=!0;let A=!this._receivedInput&&this.audioOutputMode!==0;!A&&this._muted&&(A=!0),this._videoElement.muted=A,this.playOnAwake&&(this._videoElement.autoplay=!0)}updateVideoElementStyles(){this._videoElement&&(this._videoElement.style.userSelect="none",this._videoElement.style.visibility="hidden",this._videoElement.style.display="none",this.updateAspect())}*updateAspectImpl(){const A=++this._updateAspectRoutineId,g=void 0,e=this.clip;for(;A===this._updateAspectRoutineId&&this.aspectMode!==0&&this.clip&&e===this.clip&&this._isPlaying;){if(!e||typeof e=="string")return;let i;for(const t of e.getVideoTracks()){const C=t.getSettings();if(C&&C.width&&C.height){i=C.width/C.height;break}else i=this.context.renderer.domElement.clientWidth/this.context.renderer.domElement.clientHeight}if(i===void 0){for(let t=0;t<10;t++)yield;if(!this.isPlaying)break;continue}if(g===i){yield;continue}for(const t of this._targetObjects){let C=1;if(t.parent){const o=Qi(t.parent);C=o.x/o.y}switch(this.aspectMode){case 1:t.scale.y=1/i*t.scale.x*C;break;case 2:t.scale.x=i*t.scale.y*C;break}}for(let t=0;t<3;t++)yield}}}Ht([m(NA)],Pe.prototype,"renderer",2),Ht([m()],Pe.prototype,"playOnAwake",2),Ht([m()],Pe.prototype,"aspectMode",2),Ht([m(URL)],Pe.prototype,"clip",2),Ht([m()],Pe.prototype,"renderMode",2),Ht([m()],Pe.prototype,"targetMaterialProperty",2),Ht([m(Be)],Pe.prototype,"targetMaterialRenderer",2),Ht([m(Ng)],Pe.prototype,"targetTexture",2),Ht([m()],Pe.prototype,"time",2),Ht([m()],Pe.prototype,"playbackSpeed",1),Ht([m()],Pe.prototype,"isLooping",1);class J5{constructor(A){Q(this,"context"),Q(this,"_videos",[]),Q(this,"_screenspaceModeQuad"),Q(this,"_isInScreenspaceMode",!1),Q(this,"_input"),this.context=A,this._input=new q5(this)}get enabled(){return this._isInScreenspaceMode}set enabled(A){A?this.start():this.stop()}add(A){this._videos.indexOf(A)===-1&&this._videos.push(A)}remove(A){if(!A)return;const g=this._videos.indexOf(A);g>=0&&this._videos.splice(g,1)}start(){var A;if(this._isInScreenspaceMode||this._videos.length<0)return;const g=this._videos[this._videos.length-1];if(!g)return;if(this._isInScreenspaceMode=!0,!this._screenspaceModeQuad){if(this._screenspaceModeQuad=F5.createPrimitive(Pq.Quad,{material:new b5(g)}),!this._screenspaceModeQuad)return;this._screenspaceModeQuad.geometry.scale(2,2,2)}const e=this._screenspaceModeQuad;this.context.scene.add(e),this.updateScreenspaceMaterialUniforms();const i=e.material;i?.reset(),(A=this._input)==null||A.enable(i)}stop(){var A;this._isInScreenspaceMode=!1,this._screenspaceModeQuad&&((A=this._input)==null||A.disable(),this._screenspaceModeQuad.removeFromParent())}updateScreenspaceMaterialUniforms(){var A;const g=(A=this._screenspaceModeQuad)==null?void 0:A.material;g&&(g.screenAspect=this.context.domElement.clientWidth/this.context.domElement.clientHeight)}}class q5{constructor(A){Q(this,"_onResizeScreenFn"),Q(this,"_onKeyUpFn"),Q(this,"_onMouseWheelFn"),Q(this,"context"),Q(this,"overlay"),Q(this,"_material"),Q(this,"_isPinching",!1),Q(this,"_lastPinch",0),this.overlay=A,this.context=A.context}enable(A){this._material=A,window.addEventListener("resize",this._onResizeScreenFn=()=>{this.overlay.updateScreenspaceMaterialUniforms()}),window.addEventListener("keyup",this._onKeyUpFn=i=>{i.key==="Escape"&&this.overlay.stop()}),window.addEventListener("wheel",this._onMouseWheelFn=i=>{this.overlay.enabled&&(A.zoom+=i.deltaY*5e-4,i.preventDefault())},{passive:!1});const g=new gA;window.addEventListener("mousemove",i=>{if(this.overlay.enabled&&this.context.input.getPointerPressed(0)){const t=new gA(i.movementX,i.movementY);t.x/=this.context.domElement.clientWidth,t.y/=this.context.domElement.clientHeight,g.set(t.x,t.y),g.multiplyScalar(A.zoom/-this.context.time.deltaTime*.01),A.offset=A.offset.add(g)}}),window.addEventListener("pointermove",i=>{this.overlay.enabled&&this.context.input.getPointerPressed(0)&&this.context.input.getTouchesPressedCount()===1&&(g.set(i.movementX,i.movementY),g.multiplyScalar(A.zoom*-this.context.time.deltaTime*.05),A.offset=A.offset.add(g))});let e=0;window.addEventListener("touchstart",i=>{if(i.touches.length<2){this.context.time.time-e<.3&&this.overlay.stop(),e=this.context.time.time;return}this._isPinching=!0,this._lastPinch=0}),window.addEventListener("touchmove",i=>{if(!this._isPinching||!this._material)return;const t=i.touches[0],C=i.touches[1],o=t.clientX-C.clientX,s=t.clientY-C.clientY,B=Math.sqrt(o*o+s*s);if(this._lastPinch!==0){const a=B-this._lastPinch;this._material.zoom-=a*.004}this._lastPinch=B}),window.addEventListener("touchend",()=>{this._isPinching=!1})}disable(){this._onResizeScreenFn&&(window.removeEventListener("resize",this._onResizeScreenFn),this._onResizeScreenFn=void 0),this._onKeyUpFn&&(window.removeEventListener("keyup",this._onKeyUpFn),this._onKeyUpFn=void 0),this._onMouseWheelFn&&(window.removeEventListener("wheel",this._onMouseWheelFn),this._onMouseWheelFn=void 0)}}class b5 extends xg{constructor(A){super(),Q(this,"_offset",new gA),this.uniforms={map:{value:A},screenAspect:{value:1},offsetScale:{value:new ig(0,0,1,1)}},this.vertexShader=`
4741
+ `;continue}if((l=w.match(E))&&(d.gamma=parseFloat(l[1])),(l=w.match(h))&&(d.exposure=parseFloat(l[1])),(l=w.match(c))&&(d.valid|=2,d.format=l[1]),(l=w.match(D))&&(d.valid|=4,d.height=parseInt(l[1],10),d.width=parseInt(l[2],10)),d.valid&2&&d.valid&4)break}return d.valid&2?d.valid&4?d:g(3,"missing image size specifier"):g(3,"missing format specifier")},C=function(n,r,E){const h=r;if(h<8||h>32767||n[0]!==2||n[1]!==2||n[2]&128)return new Uint8Array(n);if(h!==(n[2]<<8|n[3]))return g(3,"wrong scanline width");const c=new Uint8Array(4*r*E);if(!c.length)return g(4,"unable to allocate buffer space");let D=0,d=0;const w=4*h,l=new Uint8Array(4),p=new Uint8Array(w);let u=E;for(;u>0&&d<n.byteLength;){if(d+4>n.byteLength)return g(1);if(l[0]=n[d++],l[1]=n[d++],l[2]=n[d++],l[3]=n[d++],l[0]!=2||l[1]!=2||(l[2]<<8|l[3])!=h)return g(3,"bad rgbe scanline format");let y=0,k;for(;y<w&&d<n.byteLength;){k=n[d++];const G=k>128;if(G&&(k-=128),k===0||y+k>w)return g(3,"bad scanline data");if(G){const f=n[d++];for(let K=0;K<k;K++)p[y++]=f}else p.set(n.subarray(d,d+k),y),y+=k,d+=k}const S=h;for(let G=0;G<S;G++){let f=0;c[D]=p[G+f],f+=h,c[D+1]=p[G+f],f+=h,c[D+2]=p[G+f],f+=h,c[D+3]=p[G+f],D+=4}u--}return c},o=function(n,r,E,h){const c=n[r+3],D=Math.pow(2,c-128)/255;E[h+0]=n[r+0]*D,E[h+1]=n[r+1]*D,E[h+2]=n[r+2]*D,E[h+3]=1},s=function(n,r,E,h){const c=n[r+3],D=Math.pow(2,c-128)/255;E[h+0]=fB.toHalfFloat(Math.min(n[r+0]*D,65504)),E[h+1]=fB.toHalfFloat(Math.min(n[r+1]*D,65504)),E[h+2]=fB.toHalfFloat(Math.min(n[r+2]*D,65504)),E[h+3]=fB.toHalfFloat(1)},B=new Uint8Array(A);B.pos=0;const a=t(B);if(a!==-1){const n=a.width,r=a.height,E=C(B.subarray(B.pos),n,r);if(E!==-1){let h,c,D;switch(this.type){case HI:D=E.length/4;const d=new Float32Array(D*4);for(let l=0;l<D;l++)o(E,l*4,d,l*4);h=d,c=HI;break;case Ae:D=E.length/4;const w=new Uint16Array(D*4);for(let l=0;l<D;l++)s(E,l*4,w,l*4);h=w,c=Ae;break;default:console.error("THREE.RGBELoader: unsupported type: ",this.type);break}return{width:n,height:r,data:h,header:a.string,gamma:a.gamma,exposure:a.exposure,type:c}}}return null}setDataType(A){return this.type=A,this}load(A,g,e,i){function t(C,o){switch(C.type){case HI:case Ae:C.encoding=RI,C.minFilter=qg,C.magFilter=qg,C.generateMipmaps=!1,C.flipY=!0;break}g&&g(C,o)}return super.load(A,t,e,i)}}const Tq=EA("debugautosync"),nG=Symbol("syncerId");class u5{constructor(){Q(this,"_syncers",{})}getOrCreateSyncer(A){if(!A.guid)return null;if(this._syncers[A.guid])return this._syncers[A.guid];const g=new w5(A);return g[nG]=A.guid,this._syncers[g[nG]]=g,g}removeSyncer(A){delete this._syncers[A[nG]]}}const rG=new u5;class w5{constructor(A){Q(this,"comp"),Q(this,"hasChanges",!1),Q(this,"changedProperties",{}),Q(this,"data",{}),Q(this,"_boundEvent"),Q(this,"_handleReceivingMethod"),Q(this,"_isReceiving",!1),Q(this,"_isInit",!1),this.comp=A}get networkingKey(){return this.comp.constructor.name}init(A){if(this._isInit)return;this._isInit=!0,this.comp=A,this._boundEvent=this.onHandleSending.bind(this),this.comp.context.post_render_callbacks.push(this._boundEvent),this._handleReceivingMethod=this.onHandleReceiving.bind(this),this.comp.context.connection.beginListen(this.networkingKey,this._handleReceivingMethod);const g=this.comp.context.connection.tryGetState(this.comp.guid);g&&this.onHandleReceiving(g)}destroy(){this._isInit&&(this._boundEvent&&this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this._boundEvent),1),this._handleReceivingMethod&&this.comp.context.connection.stopListen(this.networkingKey,this._handleReceivingMethod),this.comp=null,this._isInit=!1)}notifyChanged(A,g){this._isReceiving||(this.hasChanges=!0,this.changedProperties[A]=g)}onHandleSending(){if(!this.hasChanges)return;this.hasChanges=!1;const A=this.comp.context.connection;if(!A||!A.isConnected){for(const g in this.changedProperties)delete this.changedProperties[g];return}for(const g in this.data)delete this.data[g];this.data.guid=this.comp.guid;for(const g in this.changedProperties){const e=this.changedProperties[g];delete this.changedProperties[g],this.data[g]=e}A.send(this.networkingKey,this.data)}onHandleReceiving(A){if(!this._isInit||!this.comp)return;const g=A.guid;if(!(g&&g!==this.comp.guid)){Tq&&console.log("RECEIVED",this.comp.name,this.comp.guid,A);try{this._isReceiving=!0;for(const e in A){if(e==="guid")continue;const i=A[e];this.comp[e]=i}}catch(e){console.error(e)}finally{this._isReceiving=!1}}}}function y5(I,A){let g=A!==I;if(!g&&I&&A){if(Array.isArray(I)&&Array.isArray(A))g=!0;else if(typeof I=="object"&&typeof A=="object"){for(const e of Object.keys(I))if(I[e]!==A[e]){g=!0;break}}}return g}const rh=Symbol("AutoSyncHandler");function S5(I){if(I[rh])return I[rh];const A=rG.getOrCreateSyncer(I);return A?.init(I),I[rh]=A,A}function k5(I){const A=I[rh];A&&(rG.removeSyncer(A),A.destroy(),delete I[rh])}const Oq=function(I){return function(A,g){let e=null,i;typeof I=="string"?i=A[I]:typeof I=="function"&&(i=I);const t=A,C=t.__internalAwake;Tq&&console.log(g);const o=Symbol(g);t.__internalAwake=function(){if(this[o]!==void 0)return;this[o]=this[g],C.call(this),e=rG.getOrCreateSyncer(this);const B=Object.getOwnPropertyDescriptor(this,g);B?.set===void 0&&Object.defineProperty(this,g,{set:function(a){var n;const r=this[o];this[o]=a,y5(a,r)&&i?.call(this,a,r)!==!1&&((n=S5(this))==null||n.notifyChanged(g,a))},get:function(){return this[o]},configurable:!0,enumerable:!0}),e?.init(this)};const s=t.__internalDestroy;t.__internalDestroy=function(){k5(this),s.call(this)}}};var G5=Object.defineProperty,f5=Object.getOwnPropertyDescriptor,Ep=(I,A,g,e)=>{for(var i=e>1?void 0:e?f5(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&G5(A,g,i),i};const Eh=EA("debugskybox");class Ba extends qA{constructor(){super(...arguments),Q(this,"url"),Q(this,"allowDrop",!0),Q(this,"background",!0),Q(this,"environment",!0),Q(this,"_loader"),Q(this,"_prevUrl"),Q(this,"_prevLoadedEnvironment"),Q(this,"_prevEnvironment",null),Q(this,"_prevBackground",null),Q(this,"dragOverEvent"),Q(this,"dropEvent")}onEnable(){this.setSkybox(this.url),this.registerDropEvents()}onDisable(){var A;this.context.scene.environment===this._prevLoadedEnvironment&&(this.context.scene.environment=this._prevEnvironment,SI.backgroundShouldBeTransparent(this.context)||(this.context.scene.background=this._prevBackground),this._prevLoadedEnvironment=void 0),this.unregisterDropEvents(),(A=this.context.mainCameraComponent)==null||A.applyClearFlags()}async setSkybox(A){var g;if(!A)return;if(!(A!=null&&A.endsWith(".hdr"))&&!A.endsWith(".exr")&&!A.endsWith(".jpg")&&!A.endsWith(".png")&&!A.endsWith(".jpeg")&&console.warn("Potentially invalid skybox url",this.url,"on",this.name),Eh&&console.log("Remote skybox url?: "+A),this._prevUrl===A&&this._prevLoadedEnvironment){this.applySkybox();return}else(g=this._prevLoadedEnvironment)==null||g.dispose(),this._prevLoadedEnvironment=void 0;this._prevUrl=A;const e=A.endsWith(".exr"),i=A.endsWith(".hdr");e?this._loader instanceof w0||(this._loader=new w0):i?this._loader instanceof Hq||(this._loader=new Hq):this._loader instanceof uB||(this._loader=new uB),Eh&&console.log("Loading skybox: "+A);const t=await this._loader.loadAsync(A);if(!t||!this.enabled)return;this.url=A;const C=A.lastIndexOf("/");t.name=A.substring(C>=0?C+1:0),this._loader instanceof uB&&(t.encoding=VA),this._prevLoadedEnvironment=t,this.applySkybox()}applySkybox(){var A;const g=this._prevLoadedEnvironment;g&&(g.mapping=Sa,g.needsUpdate=!0,this.context.scene.background!==g&&(this._prevBackground=this.context.scene.background),this.context.scene.environment!==g&&(this._prevEnvironment=this.context.scene.environment),Eh&&console.log("Set remote skybox",this.url),this.environment&&(this.context.scene.environment=g),this.background&&!SI.backgroundShouldBeTransparent(this.context)&&(this.context.scene.background=g),((A=this.context.mainCameraComponent)==null?void 0:A.backgroundBlurriness)!==void 0&&(this.context.scene.backgroundBlurriness=this.context.mainCameraComponent.backgroundBlurriness))}registerDropEvents(){this.dragOverEvent||(this.dragOverEvent=A=>{if(this.allowDrop&&A.dataTransfer)for(const g of A.dataTransfer.types)g==="text/uri-list"&&A.preventDefault()},this.dropEvent=A=>{var g,e,i,t;if(this.allowDrop&&(A.preventDefault(),!!A.dataTransfer)){for(const C of A.dataTransfer.types)if(C==="text/uri-list"){const o=A.dataTransfer.getData(C);Eh&&console.log(C,o);let s=(e=(g=new RegExp(/polyhaven.com\/asset_img\/.+?\/(?<name>.+)\.png/).exec(o))==null?void 0:g.groups)==null?void 0:e.name;if(s||(s=(t=(i=new RegExp(/polyhaven\.com\/a\/(?<name>.+)/).exec(o))==null?void 0:i.groups)==null?void 0:t.name),Eh&&console.log(s),s){const B="https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/"+s+"_1k.exr";this.setSkybox(B)}else console.warn("Could not resolve skybox name from dropped url",o)}}},this.context.domElement.addEventListener("dragover",this.dragOverEvent),this.context.domElement.addEventListener("drop",this.dropEvent))}unregisterDropEvents(){this.dragOverEvent&&(this.context.domElement.removeEventListener("dragover",this.dragOverEvent),this.context.domElement.removeEventListener("drop",this.dropEvent))}}Ep([Oq("setSkybox"),m(URL)],Ba.prototype,"url",2),Ep([m()],Ba.prototype,"allowDrop",2),Ep([m()],Ba.prototype,"background",2),Ep([m()],Ba.prototype,"environment",2);var M5=Object.defineProperty,m5=Object.getOwnPropertyDescriptor,ln=(I,A,g,e)=>{for(var i=e>1?void 0:e?m5(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&M5(A,g,i),i};const _q=EA("debugsceneswitcher"),hh="scene";Qe.registerCallback(pt.ContextRegistered,I=>{YG.observedAttributes.includes(hh)||YG.observedAttributes.push(hh)});const Dn=Promise.resolve(!1);class Mo extends qA{constructor(){super(...arguments),Q(this,"scenes"),Q(this,"queryParameterName","scene"),Q(this,"clamp",!0),Q(this,"useHistory",!0),Q(this,"useKeyboard",!0),Q(this,"useSwipe",!0),Q(this,"_currentIndex",-1),Q(this,"_currentScene"),Q(this,"_engineElementOverserver"),Q(this,"onPopState",async A=>{if(!this.useHistory)return;let g=this.useHistory;try{this.useHistory=!1,await this.tryLoadFromQueryParam()}finally{this.useHistory=g}}),Q(this,"normalizedSwipeThresholdX",.1),Q(this,"_didSwipe",!1),Q(this,"onPointerMove",A=>{if(!this._didSwipe&&A.button===0&&A.pointerType==="touch"&&this.context.input.getPointerPressedCount()===1){const g=this.context.input.getPointerPositionDelta(A.button);if(g){const e=g.x/this.context.domWidth;e>=this.normalizedSwipeThresholdX?(this._didSwipe=!0,this.selectPrev()):e<=-this.normalizedSwipeThresholdX&&(this._didSwipe=!0,this.selectNext())}}}),Q(this,"onPointerUp",A=>{A.button===0&&(this._didSwipe=!1)}),Q(this,"onKeyDown",A=>{if(!this.useKeyboard||!this.scenes)return;const g=A.key.toLowerCase();if(!g)return;const e=parseInt(g)-1;if(e>=0){this.trySelectSceneFromValue(e);return}switch(g){case"arrowright":case"d":this.selectNext();break;case"arrowleft":case"a":this.selectPrev();break}})}async start(){if(this._currentIndex===-1&&!await this.tryLoadFromQueryParam()){const A=this.context.domElement.getAttribute(hh);try{(A===null||!await this.trySelectSceneFromValue(A))&&this._currentIndex===-1&&this.select(0)}finally{}}}onEnable(){globalThis.addEventListener("popstate",this.onPopState),this.context.input.addEventListener(XC.KeyDown,this.onKeyDown),this.context.input.addEventListener(XC.PointerMove,this.onPointerMove),this.context.input.addEventListener(XC.PointerUp,this.onPointerUp),this._engineElementOverserver||(this._engineElementOverserver=new MutationObserver(A=>{for(const g of A)if(g.type==="attributes"&&g.attributeName===hh){const e=this.context.domElement.getAttribute(hh);e!==null&&this.trySelectSceneFromValue(e)}})),this._engineElementOverserver.observe(this.context.domElement,{attributes:!0})}onDisable(){globalThis.removeEventListener("popstate",this.onPopState),this.context.input.removeEventListener(XC.KeyDown,this.onKeyDown),this.context.input.removeEventListener(XC.PointerMove,this.onPointerMove),this.context.input.removeEventListener(XC.PointerUp,this.onPointerUp)}selectNext(){return this.select(this._currentIndex+1)}selectPrev(){return this.select(this._currentIndex-1)}select(A){var g;if(_q&&console.log("select",A),!((g=this.scenes)!=null&&g.length))return Dn;if(A<0){if(this.clamp)return Dn;A=this.scenes.length-1}else if(A>=this.scenes.length){if(this.clamp)return Dn;A=0}const e=this.scenes[A];return this.switchScene(e)}async switchScene(A){var g,e;if(A===this._currentScene)return!0;this._currentScene&&this._currentScene.unload();const i=this._currentIndex=((g=this.scenes)==null?void 0:g.indexOf(A))??-1;this._currentScene=A;try{if(await A.loadAssetAsync(),!A.asset)return _q&&console.warn("Failed loading scene:",A),!1;if(this._currentIndex===i)return iA.add(A.asset,this.gameObject),(e=this.queryParameterName)!=null&&e.length&&zG(this.queryParameterName,i.toString(),this.useHistory),!0}catch(t){console.error(t)}return!1}tryLoadFromQueryParam(){var A;if(!((A=this.queryParameterName)!=null&&A.length))return Dn;const g=EA(this.queryParameterName);return typeof g=="boolean"?Dn:this.trySelectSceneFromValue(g)}trySelectSceneFromValue(A){if(typeof A=="string"){const g=parseInt(A);if(g>=0&&g<this.scenes.length)return this.select(g);for(let e=0;e<this.scenes.length;e++)if(this.scenes[e].uri.toLowerCase().includes(A))return this.select(e)}else if(typeof A=="number"&&A>=0&&A<this.scenes.length)return this.select(A);return si()&&console.warn('Can not find scene: "'+A+'"',this),Dn}}ln([m(tC)],Mo.prototype,"scenes",2),ln([m()],Mo.prototype,"queryParameterName",2),ln([m()],Mo.prototype,"clamp",2),ln([m()],Mo.prototype,"useHistory",2),ln([m()],Mo.prototype,"useKeyboard",2),ln([m()],Mo.prototype,"useSwipe",2);function U5(){return new Promise((I,A)=>{let g=()=>{g!=null&&(document.removeEventListener("pointerdown",g),document.removeEventListener("click",g),document.removeEventListener("dragstart",g),document.removeEventListener("touchstart",g),I())};document.addEventListener("pointerdown",g),document.addEventListener("click",g),document.addEventListener("dragstart",g),document.addEventListener("touchstart",g)})}async function R5(I){await U5(),I()}var Pq=(I=>(I[I.Quad=0]="Quad",I))(Pq||{});class F5{static createPrimitive(A,g){let e;switch(A){case 0:const i=new Je(1,1,1,1),t=g?.material??new sI({color:16777215});e=new fA(i,t)}return g!=null&&g.name&&(e.name=g.name),e}}var N5=Object.defineProperty,K5=Object.getOwnPropertyDescriptor,Ht=(I,A,g,e)=>{for(var i=e>1?void 0:e?K5(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&N5(A,g,i),i};const ch=EA("debugvideo");var jq=(I=>(I[I.CameraFarPlane=0]="CameraFarPlane",I[I.CameraNearPlane=1]="CameraNearPlane",I[I.RenderTexture=2]="RenderTexture",I[I.MaterialOverride=3]="MaterialOverride",I))(jq||{});class Pe extends qA{constructor(){super(),Q(this,"renderer",null),Q(this,"playOnAwake",!0),Q(this,"aspectMode",0),Q(this,"clip",null),Q(this,"renderMode"),Q(this,"targetMaterialProperty"),Q(this,"targetMaterialRenderer"),Q(this,"targetTexture"),Q(this,"time",0),Q(this,"_playbackSpeed",1),Q(this,"_isLooping",!1),Q(this,"_muted",!1),Q(this,"playInBackground",!0),Q(this,"_crossOrigin","anonymous"),Q(this,"audioOutputMode",1),Q(this,"source"),Q(this,"url",null),Q(this,"_videoElement",null),Q(this,"_videoTexture",null),Q(this,"_videoMaterial",null),Q(this,"_isPlaying",!1),Q(this,"wasPlaying",!1),Q(this,"_receivedInput",!1),Q(this,"_overlay",null),Q(this,"_targetObjects"),Q(this,"_updateAspectRoutineId",-1),R5(()=>{this._receivedInput=!0,this.updateVideoElementSettings()}),this._targetObjects=[],EA("videoscreenspace")&&window.addEventListener("keydown",A=>{A.key==="f"&&(this.screenspace=!this.screenspace)})}get playbackSpeed(){var A;return((A=this._videoElement)==null?void 0:A.playbackRate)??this._playbackSpeed}set playbackSpeed(A){this._playbackSpeed=A,this._videoElement&&(this._videoElement.playbackRate=A)}get isLooping(){var A;return((A=this._videoElement)==null?void 0:A.loop)??this._isLooping}set isLooping(A){this._isLooping=A,this._videoElement&&(this._videoElement.loop=A)}get currentTime(){var A;return((A=this._videoElement)==null?void 0:A.currentTime)??this.time}set currentTime(A){this._videoElement?this._videoElement.currentTime=A:this.time=A}get isPlaying(){const A=this._videoElement;return!!(A&&(A.currentTime>0&&!A.paused&&!A.ended&&A.readyState>A.HAVE_CURRENT_DATA||A.srcObject&&A.srcObject.active))}get crossOrigin(){var A;return((A=this._videoElement)==null?void 0:A.crossOrigin)??this._crossOrigin}set crossOrigin(A){this._crossOrigin=A,this._videoElement&&(A!==null?this._videoElement.setAttribute("crossorigin",A):this._videoElement.removeAttribute("crossorigin"))}get videoMaterial(){return this._videoMaterial}get videoTexture(){return this._videoTexture}get videoElement(){return this._videoElement}get muted(){var A;return((A=this._videoElement)==null?void 0:A.muted)??this._muted}set muted(A){this._muted=A,this._videoElement&&(this._videoElement.muted=A)}setVideo(A){this.clip=A,this.source=0,this._videoElement?(this._videoElement.srcObject=A,this._isPlaying&&this.play(),this.updateAspect()):this.create(!0)}setClipURL(A){this.url!==A&&(this.url=A,this.source=1,ch&&console.log("set url",A),this._videoElement?(this._videoElement.src=A,this._isPlaying&&(this.stop(),this.play())):this.create(!0))}awake(){this.create(this.playOnAwake),window.addEventListener("visibilitychange",A=>{switch(document.visibilityState){case"hidden":this.playInBackground||(this.wasPlaying=this._isPlaying,this.pause());break;case"visible":this.wasPlaying&&!this._isPlaying&&this.play();break}})}onEnable(){var A,g;this.playOnAwake===!0&&this.handleBeginPlaying(!0),this.screenspace?(A=this._overlay)==null||A.start():(g=this._overlay)==null||g.stop()}onDisable(){this.pause()}onDestroy(){var A;this._videoElement&&((A=this._videoElement.parentElement)==null||A.removeChild(this._videoElement),this._videoElement=null),this._videoTexture&&(this._videoTexture.dispose(),this._videoTexture=null)}play(){var A,g,e;this._videoElement&&(this._isPlaying&&!((A=this._videoElement)!=null&&A.ended)&&!((g=this._videoElement)!=null&&g.paused)||(this._isPlaying=!0,this._receivedInput||(this._videoElement.muted=!0),this.updateVideoElementSettings(),(e=this._videoElement)==null||e.play().catch(i=>{var t;ch&&console.error("Error playing video",i,"CODE="+i.code,(t=this.videoElement)==null?void 0:t.src,this),setTimeout(()=>{this._isPlaying&&!this.destroyed&&this.activeAndEnabled&&this.play()},1e3)}),ch&&console.log("play",this._videoElement)))}stop(){this._isPlaying=!1,this._videoElement&&(this._videoElement.currentTime=0,this._videoElement.pause())}pause(){var A;this._isPlaying=!1,(A=this._videoElement)==null||A.pause()}create(A){var g,e;let i;switch(this.source){case 0:i=this.clip;break;case 1:i=this.url;break}if(i){if(this._videoElement||(this._videoElement=this.createVideoElement(),(g=this.context.domElement)==null||g.prepend(this._videoElement),this.updateVideoElementStyles()),typeof i=="string"){this._videoElement.src=i;const t=(e=this._videoElement.captureStream)==null?void 0:e.call(this._videoElement);this.clip=t}else this._videoElement.srcObject=i;this._videoTexture||(this._videoTexture=new Bm(this._videoElement)),this._videoTexture.flipY=!1,this._videoTexture.encoding=VA,this.handleBeginPlaying(A),ch&&console.log(this)}}updateAspect(){this.aspectMode!==0&&this.startCoroutine(this.updateAspectImpl())}get screenspace(){var A;return((A=this._overlay)==null?void 0:A.enabled)??!1}set screenspace(A){var g;if(A){if(!this._videoTexture)return;this._overlay||(this._overlay=new J5(this.context)),this._overlay.add(this._videoTexture)}else(g=this._overlay)==null||g.remove(this._videoTexture);this._overlay&&(this._overlay.enabled=A)}createVideoElement(){const A=document.createElement("video");return this._crossOrigin&&A.setAttribute("crossorigin",this._crossOrigin),ch&&console.log("create video elment",A),A}handleBeginPlaying(A){var g,e;if(!this.enabled||!this._videoElement)return;this._targetObjects.length=0;let i=this.gameObject;switch(this.renderMode){case 3:i=(g=this.targetMaterialRenderer)==null?void 0:g.gameObject,i||(i=(e=iA.getComponent(this.gameObject,Be))==null?void 0:e.gameObject);break;case 2:console.error("VideoPlayer renderTexture not implemented yet. Please use material override instead");return}if(!i){console.error("Missing target for video material renderer",this.name,jq[this.renderMode],this);return}const t=i.material;if(t)if(this._targetObjects.push(i),t!==this._videoMaterial&&(this._videoMaterial=t.clone(),i.material=this._videoMaterial),!this.targetMaterialProperty)this._videoMaterial.map=this._videoTexture;else switch(this.targetMaterialProperty){default:this._videoMaterial.map=this._videoTexture;break}else{console.warn("Can not play video, no material found, this might be a multimaterial case which is not supported yet");return}this.updateVideoElementSettings(),this.updateVideoElementStyles(),A&&this.play()}updateVideoElementSettings(){if(!this._videoElement)return;this._videoElement.loop=this._isLooping,this._videoElement.currentTime=this.currentTime,this._videoElement.playbackRate=this._playbackSpeed,this._videoElement.playsInline=!0;let A=!this._receivedInput||this.audioOutputMode===0;!A&&this._muted&&(A=!0),this._videoElement.muted=A,this.playOnAwake&&(this._videoElement.autoplay=!0)}updateVideoElementStyles(){this._videoElement&&(this._videoElement.style.userSelect="none",this._videoElement.style.visibility="hidden",this._videoElement.style.display="none",this.updateAspect())}*updateAspectImpl(){const A=++this._updateAspectRoutineId,g=void 0,e=this.clip;for(;A===this._updateAspectRoutineId&&this.aspectMode!==0&&this.clip&&e===this.clip&&this._isPlaying;){if(!e||typeof e=="string")return;let i;for(const t of e.getVideoTracks()){const C=t.getSettings();if(C&&C.width&&C.height){i=C.width/C.height;break}else i=this.context.renderer.domElement.clientWidth/this.context.renderer.domElement.clientHeight}if(i===void 0){for(let t=0;t<10;t++)yield;if(!this.isPlaying)break;continue}if(g===i){yield;continue}for(const t of this._targetObjects){let C=1;if(t.parent){const o=Qi(t.parent);C=o.x/o.y}switch(this.aspectMode){case 1:t.scale.y=1/i*t.scale.x*C;break;case 2:t.scale.x=i*t.scale.y*C;break}}for(let t=0;t<3;t++)yield}}}Ht([m(NA)],Pe.prototype,"renderer",2),Ht([m()],Pe.prototype,"playOnAwake",2),Ht([m()],Pe.prototype,"aspectMode",2),Ht([m(URL)],Pe.prototype,"clip",2),Ht([m()],Pe.prototype,"renderMode",2),Ht([m()],Pe.prototype,"targetMaterialProperty",2),Ht([m(Be)],Pe.prototype,"targetMaterialRenderer",2),Ht([m(Ng)],Pe.prototype,"targetTexture",2),Ht([m()],Pe.prototype,"time",2),Ht([m()],Pe.prototype,"playbackSpeed",1),Ht([m()],Pe.prototype,"isLooping",1);class J5{constructor(A){Q(this,"context"),Q(this,"_videos",[]),Q(this,"_screenspaceModeQuad"),Q(this,"_isInScreenspaceMode",!1),Q(this,"_input"),this.context=A,this._input=new q5(this)}get enabled(){return this._isInScreenspaceMode}set enabled(A){A?this.start():this.stop()}add(A){this._videos.indexOf(A)===-1&&this._videos.push(A)}remove(A){if(!A)return;const g=this._videos.indexOf(A);g>=0&&this._videos.splice(g,1)}start(){var A;if(this._isInScreenspaceMode||this._videos.length<0)return;const g=this._videos[this._videos.length-1];if(!g)return;if(this._isInScreenspaceMode=!0,!this._screenspaceModeQuad){if(this._screenspaceModeQuad=F5.createPrimitive(Pq.Quad,{material:new b5(g)}),!this._screenspaceModeQuad)return;this._screenspaceModeQuad.geometry.scale(2,2,2)}const e=this._screenspaceModeQuad;this.context.scene.add(e),this.updateScreenspaceMaterialUniforms();const i=e.material;i?.reset(),(A=this._input)==null||A.enable(i)}stop(){var A;this._isInScreenspaceMode=!1,this._screenspaceModeQuad&&((A=this._input)==null||A.disable(),this._screenspaceModeQuad.removeFromParent())}updateScreenspaceMaterialUniforms(){var A;const g=(A=this._screenspaceModeQuad)==null?void 0:A.material;g&&(g.screenAspect=this.context.domElement.clientWidth/this.context.domElement.clientHeight)}}class q5{constructor(A){Q(this,"_onResizeScreenFn"),Q(this,"_onKeyUpFn"),Q(this,"_onMouseWheelFn"),Q(this,"context"),Q(this,"overlay"),Q(this,"_material"),Q(this,"_isPinching",!1),Q(this,"_lastPinch",0),this.overlay=A,this.context=A.context}enable(A){this._material=A,window.addEventListener("resize",this._onResizeScreenFn=()=>{this.overlay.updateScreenspaceMaterialUniforms()}),window.addEventListener("keyup",this._onKeyUpFn=i=>{i.key==="Escape"&&this.overlay.stop()}),window.addEventListener("wheel",this._onMouseWheelFn=i=>{this.overlay.enabled&&(A.zoom+=i.deltaY*5e-4,i.preventDefault())},{passive:!1});const g=new gA;window.addEventListener("mousemove",i=>{if(this.overlay.enabled&&this.context.input.getPointerPressed(0)){const t=new gA(i.movementX,i.movementY);t.x/=this.context.domElement.clientWidth,t.y/=this.context.domElement.clientHeight,g.set(t.x,t.y),g.multiplyScalar(A.zoom/-this.context.time.deltaTime*.01),A.offset=A.offset.add(g)}}),window.addEventListener("pointermove",i=>{this.overlay.enabled&&this.context.input.getPointerPressed(0)&&this.context.input.getTouchesPressedCount()===1&&(g.set(i.movementX,i.movementY),g.multiplyScalar(A.zoom*-this.context.time.deltaTime*.05),A.offset=A.offset.add(g))});let e=0;window.addEventListener("touchstart",i=>{if(i.touches.length<2){this.context.time.time-e<.3&&this.overlay.stop(),e=this.context.time.time;return}this._isPinching=!0,this._lastPinch=0}),window.addEventListener("touchmove",i=>{if(!this._isPinching||!this._material)return;const t=i.touches[0],C=i.touches[1],o=t.clientX-C.clientX,s=t.clientY-C.clientY,B=Math.sqrt(o*o+s*s);if(this._lastPinch!==0){const a=B-this._lastPinch;this._material.zoom-=a*.004}this._lastPinch=B}),window.addEventListener("touchend",()=>{this._isPinching=!1})}disable(){this._onResizeScreenFn&&(window.removeEventListener("resize",this._onResizeScreenFn),this._onResizeScreenFn=void 0),this._onKeyUpFn&&(window.removeEventListener("keyup",this._onKeyUpFn),this._onKeyUpFn=void 0),this._onMouseWheelFn&&(window.removeEventListener("wheel",this._onMouseWheelFn),this._onMouseWheelFn=void 0)}}class b5 extends xg{constructor(A){super(),Q(this,"_offset",new gA),this.uniforms={map:{value:A},screenAspect:{value:1},offsetScale:{value:new ig(0,0,1,1)}},this.vertexShader=`
4742
4742
  uniform sampler2D map;
4743
4743
  uniform float screenAspect;
4744
4744
  uniform vec4 offsetScale;
@@ -4798,7 +4798,7 @@ void main() {
4798
4798
  // be blended onto the scene.
4799
4799
  gl_FragColor = vec4(direct, max);
4800
4800
  return;
4801
- `)}}}applyShadowMaterial(){var A;const g=iA.getComponent(this.gameObject,Be);if(g)if(((A=g.sharedMaterial)==null?void 0:A.type)!=="ShadowMaterial"){const e=new Pw;e.color=this.shadowColor,e.opacity=this.shadowColor.alpha,this.applyMaterialOptions(e),g.sharedMaterial=e}else{const e=g.sharedMaterial;e.color=this.shadowColor,e.opacity=this.shadowColor.alpha,this.applyMaterialOptions(e)}}applyMaterialOptions(A){A&&(A.depthWrite=!1,A.stencilWrite=!1)}}Vq([m()],ph.prototype,"mode",2),Vq([m(QI)],ph.prototype,"shadowColor",2);var W5=Object.defineProperty,Z5=Object.getOwnPropertyDescriptor,cp=(I,A,g,e)=>{for(var i=e>1?void 0:e?Z5(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&W5(A,g,i),i},EG;const zq=(EG=class extends qA{constructor(){super(...arguments),Q(this,"target",null),Q(this,"followFactor",.1),Q(this,"rotateFactor",.1),Q(this,"positionAxes",Yr.All),Q(this,"flipForward",!1),Q(this,"_firstUpdate",!0)}onBeforeRender(){this.updateNow(!1)}updateNow(I){if(!(!this.target||this.target===this.gameObject)){if(this.followFactor>0){const A=wg(this.target),g=this._firstUpdate||I?1:$A.clamp01(this.context.time.deltaTime*this.followFactor),e=this.worldPosition;this.positionAxes&Yr.X&&(e.x=$A.lerp(e.x,A.x,g)),this.positionAxes&Yr.Y&&(e.y=$A.lerp(e.y,A.y,g)),this.positionAxes&Yr.Z&&(e.z=$A.lerp(e.z,A.z,g)),this.worldPosition=e}if(this.rotateFactor>0){const A=Ji(this.target);this.flipForward&&A.premultiply(zq._invertForward);const g=this._firstUpdate||I?1:$A.clamp01(this.context.time.deltaTime*this.rotateFactor);this.worldQuaternion=this.worldQuaternion.slerp(A,g)}this._firstUpdate=!1}}},Q(EG,"_invertForward",new RA().setFromAxisAngle(new M(0,1,0),Math.PI)),EG);let Ts=zq;cp([m(NA)],Ts.prototype,"target",2),cp([m()],Ts.prototype,"followFactor",2),cp([m()],Ts.prototype,"rotateFactor",2),cp([m()],Ts.prototype,"positionAxes",2);class V5 extends fA{constructor(A){const g=new z5(A),e=new Je(g.image.width*.001,g.image.height*.001),i=new sI({map:g,toneMapped:!1,transparent:!0});super(e,i);function t(C){i.map.dispatchDOMEvent(C)}this.addEventListener("mousedown",t),this.addEventListener("mousemove",t),this.addEventListener("mouseup",t),this.addEventListener("click",t),this.dispose=function(){e.dispose(),i.dispose(),i.map.dispose(),hG.delete(A),this.removeEventListener("mousedown",t),this.removeEventListener("mousemove",t),this.removeEventListener("mouseup",t),this.removeEventListener("click",t)}}}class z5 extends Fw{constructor(A){super(Xq(A)),this.dom=A,this.anisotropy=16,this.encoding=VA,this.minFilter=qg,this.magFilter=qg;const g=new MutationObserver(()=>{this.scheduleUpdate||(this.scheduleUpdate=setTimeout(()=>this.update(),16))}),e={attributes:!0,childList:!0,subtree:!0,characterData:!0};g.observe(A,e),this.observer=g}dispatchDOMEvent(A){A.data&&X5(this.dom,A.type,A.data.x,A.data.y)}update(){this.image=Xq(this.dom),this.needsUpdate=!0,this.scheduleUpdate=null}dispose(){this.observer&&this.observer.disconnect(),this.scheduleUpdate=clearTimeout(this.scheduleUpdate),super.dispose()}}const hG=new WeakMap;function Xq(I){const A=document.createRange(),g=new yA;function e(r){const E=[];let h=!1;function c(){if(h&&(h=!1,r.restore()),E.length===0)return;let D=-1/0,d=-1/0,w=1/0,l=1/0;for(let p=0;p<E.length;p++){const u=E[p];D=Math.max(D,u.x),d=Math.max(d,u.y),w=Math.min(w,u.x+u.width),l=Math.min(l,u.y+u.height)}r.save(),r.beginPath(),r.rect(D,d,w-D,l-d),r.clip(),h=!0}return{add:function(D){E.push(D),c()},remove:function(){E.pop(),c()}}}function i(r,E,h,c){c!==""&&(r.textTransform==="uppercase"&&(c=c.toUpperCase()),a.font=r.fontWeight+" "+r.fontSize+" "+r.fontFamily,a.textBaseline="top",a.fillStyle=r.color,a.fillText(c,E,h+parseFloat(r.fontSize)*.1))}function t(r,E,h,c,D){h<2*D&&(D=h/2),c<2*D&&(D=c/2),a.beginPath(),a.moveTo(r+D,E),a.arcTo(r+h,E,r+h,E+c,D),a.arcTo(r+h,E+c,r,E+c,D),a.arcTo(r,E+c,r,E,D),a.arcTo(r,E,r+h,E,D),a.closePath()}function C(r,E,h,c,D,d){const w=r[E+"Width"],l=r[E+"Style"],p=r[E+"Color"];w!=="0px"&&l!=="none"&&p!=="transparent"&&p!=="rgba(0, 0, 0, 0)"&&(a.strokeStyle=p,a.lineWidth=parseFloat(w),a.beginPath(),a.moveTo(h,c),a.lineTo(h+D,c+d),a.stroke())}function o(r,E){let h=0,c=0,D=0,d=0;if(r.nodeType===Node.TEXT_NODE){A.selectNode(r);const l=A.getBoundingClientRect();h=l.left-s.left-.5,c=l.top-s.top-.5,D=l.width,d=l.height,i(E,h,c,r.nodeValue.trim())}else{if(r.nodeType===Node.COMMENT_NODE)return;if(r instanceof HTMLCanvasElement){if(r.style.display==="none")return;a.save();const l=window.devicePixelRatio;a.scale(1/l,1/l),a.drawImage(r,0,0),a.restore()}else{if(r.style.display==="none")return;const l=r.getBoundingClientRect();h=l.left-s.left-.5,c=l.top-s.top-.5,D=l.width,d=l.height,E=window.getComputedStyle(r),t(h,c,D,d,parseFloat(E.borderRadius));const p=E.backgroundColor;p!=="transparent"&&p!=="rgba(0, 0, 0, 0)"&&(a.fillStyle=p,a.fill());const u=["borderTop","borderLeft","borderBottom","borderRight"];let y=!0,k=null;for(const S of u){if(k!==null&&(y=E[S+"Width"]===E[k+"Width"]&&E[S+"Color"]===E[k+"Color"]&&E[S+"Style"]===E[k+"Style"]),y===!1)break;k=S}if(y===!0){const S=parseFloat(E.borderTopWidth);E.borderTopWidth!=="0px"&&E.borderTopStyle!=="none"&&E.borderTopColor!=="transparent"&&E.borderTopColor!=="rgba(0, 0, 0, 0)"&&(a.strokeStyle=E.borderTopColor,a.lineWidth=S,a.stroke())}else C(E,"borderTop",h,c,D,0),C(E,"borderLeft",h,c,0,d),C(E,"borderBottom",h,c+d,D,0),C(E,"borderRight",h+D,c,0,d);if(r instanceof HTMLInputElement){let S=E.accentColor;(S===void 0||S==="auto")&&(S=E.color),g.set(S);const G=Math.sqrt(.299*g.r**2+.587*g.g**2+.114*g.b**2)<.5?"white":"#111111";if(r.type==="radio"&&(t(h,c,D,d,d),a.fillStyle="white",a.strokeStyle=S,a.lineWidth=1,a.fill(),a.stroke(),r.checked&&(t(h+2,c+2,D-4,d-4,d),a.fillStyle=S,a.strokeStyle=G,a.lineWidth=2,a.fill(),a.stroke())),r.type==="checkbox"&&(t(h,c,D,d,2),a.fillStyle=r.checked?S:"white",a.strokeStyle=r.checked?G:S,a.lineWidth=1,a.stroke(),a.fill(),r.checked)){const f=a.textAlign;a.textAlign="center";const K={color:G,fontFamily:E.fontFamily,fontSize:d+"px",fontWeight:"bold"};i(K,h+D/2,c,"\u2714"),a.textAlign=f}if(r.type==="range"){const[f,K,q]=["min","max","value"].map(J=>parseFloat(r[J])),F=(q-f)/(K-f)*(D-d);t(h,c+d/4,D,d/2,d/4),a.fillStyle=G,a.strokeStyle=S,a.lineWidth=1,a.fill(),a.stroke(),t(h,c+d/4,F+d/2,d/2,d/4),a.fillStyle=S,a.fill(),t(h+F,c,d,d,d/2),a.fillStyle=S,a.fill()}(r.type==="color"||r.type==="text"||r.type==="number")&&(n.add({x:h,y:c,width:D,height:d}),i(E,h+parseInt(E.paddingLeft),c+parseInt(E.paddingTop),r.value),n.remove())}}}const w=E.overflow==="auto"||E.overflow==="hidden";w&&n.add({x:h,y:c,width:D,height:d});for(let l=0;l<r.childNodes.length;l++)o(r.childNodes[l],E);w&&n.remove()}const s=I.getBoundingClientRect();let B=hG.get(I);B===void 0&&(B=document.createElement("canvas"),B.width=s.width,B.height=s.height,hG.set(I,B));const a=B.getContext("2d"),n=new e(a);return o(I),B}function X5(I,A,g,e){const i={clientX:g*I.offsetWidth+I.offsetLeft,clientY:e*I.offsetHeight+I.offsetTop,view:I.ownerDocument.defaultView};window.dispatchEvent(new MouseEvent(A,i));const t=I.getBoundingClientRect();g=g*t.width+t.left,e=e*t.height+t.top;function C(o){if(o.nodeType!==Node.TEXT_NODE&&o.nodeType!==Node.COMMENT_NODE){const s=o.getBoundingClientRect();if(g>s.left&&g<s.right&&e>s.top&&e<s.bottom&&(o.dispatchEvent(new MouseEvent(A,i)),o instanceof HTMLInputElement&&o.type==="range"&&(A==="mousedown"||A==="click"))){const[B,a]=["min","max"].map(E=>parseFloat(o[E])),n=s.width,r=(g-s.x)/n;o.value=B+(a-B)*r,o.dispatchEvent(new InputEvent("input",{bubbles:!0}))}for(let B=0;B<o.childNodes.length;B++)C(o.childNodes[B])}}C(I)}const lp=new gA,dn={type:"",data:lp};class $5 extends Gt{constructor(A,g){super();const e=this,i=new iQ,t=new PA,C=A.domElement;function o(r){r.stopPropagation();const E=A.domElement.getBoundingClientRect();lp.x=(r.clientX-E.left)/E.width*2-1,lp.y=-(r.clientY-E.top)/E.height*2+1,i.setFromCamera(lp,g);const h=i.intersectObjects(e.children,!1);if(h.length>0){const c=h[0],D=c.object,d=c.uv;dn.type=r.type,dn.data.set(d.x,1-d.y),D.dispatchEvent(dn)}}C.addEventListener("pointerdown",o),C.addEventListener("pointerup",o),C.addEventListener("pointermove",o),C.addEventListener("mousedown",o),C.addEventListener("mouseup",o),C.addEventListener("mousemove",o),C.addEventListener("click",o);const s={move:"mousemove",select:"click",selectstart:"mousedown",selectend:"mouseup"};function B(r){const E=r.target;t.identity().extractRotation(E.matrixWorld),i.ray.origin.setFromMatrixPosition(E.matrixWorld),i.ray.direction.set(0,0,-1).applyMatrix4(t);const h=i.intersectObjects(e.children,!1);if(h.length>0){const c=h[0],D=c.object,d=c.uv;dn.type=s[r.type],dn.data.set(d.x,1-d.y),D.dispatchEvent(dn)}}const a=A.xr.getController(0);a.addEventListener("move",B),a.addEventListener("select",B),a.addEventListener("selectstart",B),a.addEventListener("selectend",B);const n=A.xr.getController(1);n.addEventListener("move",B),n.addEventListener("select",B),n.addEventListener("selectstart",B),n.addEventListener("selectend",B)}}class cG extends qA{constructor(){super(...arguments),Q(this,"id",null),Q(this,"keepAspect",!1)}start(){if(!this.id||!this.context.mainCamera)return;const A=document.getElementById(this.id);if(!A){console.warn('Could not find element with id "'+this.id+'"');return}A.style.display="block",A.style.visibility="hidden";const g=new $5(this.context.renderer,this.context.mainCamera);this.gameObject.add(g);const e=new V5(A);g.add(e),e.visible=!1,console.log(e);const i=e.material;i.transparent=!0,setTimeout(()=>{e.visible=!0;const t=kU(this.gameObject).clone();GU(this.gameObject,0,0,0),this.gameObject.updateMatrixWorld();const C=new ve;C.setFromObject(g),this.setWorldRotation(t.x,t.y,t.z);const o=C.max.x-C.min.x,s=C.max.y-C.min.y;if(this.keepAspect){const a=o/s;o>s?e.scale.set(1/o,1/s/a,1):e.scale.set(1/o*a,1/s,1)}else e.scale.set(1/o,1/s,1);const B=this.gameObject.scale;e.scale.multiply(B)},1)}}var AX=Object.defineProperty,gX=Object.getOwnPropertyDescriptor,uh=(I,A,g,e)=>{for(var i=e>1?void 0:e?gX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&AX(A,g,i),i};const wh=EA("debugspatialtrigger"),$q=new At,Ab=new At;function IX(I,A){return $q.mask=I,Ab.mask=A,$q.test(Ab)}class yC extends qA{constructor(){super(...arguments),Q(this,"triggerMask",0),Q(this,"onEnter"),Q(this,"onStay"),Q(this,"onExit"),Q(this,"currentIntersected",[]),Q(this,"lastIntersected",[])}start(){wh&&console.log(this.name,this.triggerMask,this)}update(){this.currentIntersected.length=0;for(const A of yh.triggers)IX(A.triggerMask,this.triggerMask)&&A.test(this.gameObject)&&this.currentIntersected.push(A);for(let A=this.lastIntersected.length-1;A>=0;A--){const g=this.lastIntersected[A];this.currentIntersected.indexOf(g)<0&&(this.onExitTrigger(g),this.lastIntersected.splice(A,1))}for(const A of this.currentIntersected)this.lastIntersected.indexOf(A)<0&&this.onEnterTrigger(A),this.onStayTrigger(A);this.lastIntersected.length=0,this.lastIntersected.push(...this.currentIntersected)}onEnterTrigger(A){var g;wh&&console.log("ENTER TRIGGER",this.name,A.name,this,A),A.raiseOnEnterEvent(this),(g=this.onEnter)==null||g.invoke(this,A)}onExitTrigger(A){var g;wh&&console.log("EXIT TRIGGER",this.name,A.name,this,A),A.raiseOnExitEvent(this),(g=this.onExit)==null||g.invoke(this,A)}onStayTrigger(A){var g;A.raiseOnStayEvent(this),(g=this.onStay)==null||g.invoke(this,A)}}uh([m()],yC.prototype,"triggerMask",2),uh([m(di)],yC.prototype,"onEnter",2),uh([m(di)],yC.prototype,"onStay",2),uh([m(di)],yC.prototype,"onExit",2);var lG;const Dp=(lG=class extends qA{constructor(){super(...arguments),Q(this,"triggerMask"),Q(this,"boxHelper")}start(){wh&&console.log(this.name,this.triggerMask,this)}onEnable(){var I;Dp.triggers.push(this),this.boxHelper||(this.boxHelper=iA.addNewComponent(this.gameObject,lC),(I=this.boxHelper)==null||I.showHelper(null,wh))}onDisable(){Dp.triggers.splice(Dp.triggers.indexOf(this),1)}test(I){return this.boxHelper?this.boxHelper.isInBox(I)??!1:!1}raiseOnEnterEvent(I){iA.foreachComponent(this.gameObject,A=>{A!==I&&A instanceof yC&&A.onEnterTrigger(this)},!1)}raiseOnStayEvent(I){iA.foreachComponent(this.gameObject,A=>{A!==I&&A instanceof yC&&A.onStayTrigger(this)},!1)}raiseOnExitEvent(I){iA.foreachComponent(this.gameObject,A=>{A!==I&&A instanceof yC&&A.onExitTrigger(this)},!1)}},Q(lG,"triggers",[]),lG);let yh=Dp;uh([m()],yh.prototype,"triggerMask",2);var eX=Object.defineProperty,iX=Object.getOwnPropertyDescriptor,tX=(I,A,g,e)=>{for(var i=e>1?void 0:e?iX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&eX(A,g,i),i};const Wi=EA("debugspectator");class dp extends qA{constructor(){super(...arguments),Q(this,"cam",null),Q(this,"useKeys",!0),Q(this,"_mode",0),Q(this,"orbit",null),Q(this,"_handler"),Q(this,"eventSub_WebXRRequestStartEvent",null),Q(this,"eventSub_WebXRStartEvent",null),Q(this,"eventSub_WebXREndEvent",null),Q(this,"_debug"),Q(this,"_networking")}get mode(){return this._mode}set mode(A){this._mode=A}get isSpectating(){var A;return((A=this._handler)==null?void 0:A.currentTarget)!==void 0}isSpectatingUser(A){var g;return((g=this.target)==null?void 0:g.userId)===A}isFollowedBy(A){var g;return(g=this.followers)==null?void 0:g.includes(A)}get followers(){return this._networking.followers}stopSpectating(){if(this.context.isInXR){this.followSelf();return}this.target=void 0}get localId(){return this.context.connection.connectionId??"local"}set target(A){var g;if(this._handler){const e=(g=this._handler.currentTarget)==null?void 0:g.userId,i=this.context.players.getPlayerView(this.localId);A===void 0||this.context.isInXR===!1&&i?.currentObject===A.currentObject?this._handler.currentTarget!==void 0&&(this._handler.disable(),iA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),this._networking.onSpectatedObjectChanged(A,e)):this._handler.currentTarget!==A&&(this._handler.set(A),iA.setActive(this.gameObject,!0),this.orbit&&(this.orbit.enabled=!1),this._networking.onSpectatedObjectChanged(A,e))}}get target(){var A;return(A=this._handler)==null?void 0:A.currentTarget}requestAllFollowMe(){this._networking.onRequestFollowMe()}get isSpectatingSelf(){var A,g;return this.isSpectating&&((A=this.target)==null?void 0:A.currentObject)===((g=this.context.players.getPlayerView(this.localId))==null?void 0:g.currentObject)}awake(){if(this._debug=new sX(this.context,this),this._networking=new QX(this.context,this),this._networking.awake(),iA.setActive(this.gameObject,!1),this.cam=iA.getComponent(this.gameObject,SI),!this.cam){console.error("Spectator camera needs camera component",this);return}!this._handler&&this.cam&&(this._handler=new CX(this.context,this.cam,this)),this.eventSub_WebXRRequestStartEvent=this.onXRSessionRequestStart.bind(this),this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Ug.addEventListener(me.RequestVRSession,this.eventSub_WebXRRequestStartEvent),Ug.addEventListener(me.XRStarted,this.eventSub_WebXRStartEvent),Ug.addEventListener(me.XRStopped,this.eventSub_WebXREndEvent),this.orbit=iA.getComponent(this.context.mainCamera,Ks)}onDestroy(){var A;this.stopSpectating(),Ug.removeEventListener(me.RequestVRSession,this.eventSub_WebXRStartEvent),Ug.removeEventListener(me.XRStarted,this.eventSub_WebXRStartEvent),Ug.removeEventListener(me.XRStopped,this.eventSub_WebXREndEvent),(A=this._handler)==null||A.destroy(),this._networking.destroy()}isSupportedPlatform(){const A=window.navigator.userAgent,g=/Windows|MacOS/.test(A),e=/Windows NT/.test(A)&&/Edg/.test(A)&&!/Win64/.test(A);return g&&!e}onXRSessionRequestStart(A){this.isSupportedPlatform()&&iA.setActive(this.gameObject,!0)}onXRSessionStart(A){this.isSupportedPlatform()&&(Wi&&console.log(this.context.mainCamera),this.context.mainCamera&&this.followSelf())}onXRSessionEnded(A){var g,e;this.context.removeCamera(this.cam),iA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),(g=this._handler)==null||g.set(void 0),(e=this._handler)==null||e.disable(),this.isSpectatingSelf&&this.stopSpectating()}followSelf(){this.target=this.context.players.getPlayerView(this.context.connection.connectionId),this.target||(this.context.players.setPlayerView(this.localId,this.context.mainCamera,Co.Headset),this.target=this.context.players.getPlayerView(this.localId)),Wi&&console.log("Follow self",this.target)}onAfterRender(){var A,g,e;if(!this.cam)return;const i=this.context.renderer,t=i.xr.enabled;if(!i.xr.isPresenting&&!((A=this._handler)!=null&&A.currentTarget))return;(g=this._handler)==null||g.update(this._mode);const C=i.getRenderTarget();let o=null;if(!C){if(!i.state.bindFramebuffer||!i.state.bindXRFramebuffer)return;o=i._framebuffer,i.state.bindXRFramebuffer(null)}this.setAvatarFlagsBeforeRender();const s=this.context.mainCameraComponent;if(s){const n=s.backgroundColor;n&&i.setClearColor(n,n.alpha),this.cam.backgroundColor=n,this.cam.clearFlags=s.clearFlags,this.cam.nearClipPlane=s.nearClipPlane,this.cam.farClipPlane=s.farClipPlane}else i.setClearColor(new yA(1,1,1));i.setRenderTarget(null),i.xr.enabled=!1;const B=(e=this.cam)==null?void 0:e.cam;this.context.updateAspect(B);const a=i.xr.isPresenting;i.xr.isPresenting=!1,i.setSize(this.context.domWidth,this.context.domHeight),i.render(this.context.scene,B),i.xr.isPresenting=a,i.xr.enabled=t,C?i.setRenderTarget(C):i.state.bindXRFramebuffer(o),this.resetAvatarFlags()}setAvatarFlagsBeforeRender(){const A=this._mode===0;for(const g of Oe.instances)if(g.avatar&&"isLocalAvatar"in g.avatar){let e=oe.All;this.isSpectatingSelf&&(e=A&&g.avatar.isLocalAvatar?oe.FirstPerson:oe.ThirdPerson);const i=g.avatar.flags;if(!i)continue;for(const t of i)t.UpdateVisible(e)}}resetAvatarFlags(){var A;for(const g of Oe.instances)if(g.avatar&&"flags"in g.avatar){const e=g.avatar.flags;if(!e)continue;for(const i of e)(A=g.avatar)!=null&&A.isLocalAvatar?i.UpdateVisible(oe.FirstPerson):i.UpdateVisible(oe.ThirdPerson)}}}tX([m()],dp.prototype,"useKeys",2);class CX{constructor(A,g,e){Q(this,"context"),Q(this,"cam"),Q(this,"spectator"),Q(this,"follow"),Q(this,"target"),Q(this,"view"),Q(this,"currentObject"),this.context=A,this.cam=g,this.spectator=e}get currentTarget(){return this.view}set(A){const g=A?.currentObject;if(!g){this.spectator.stopSpectating();return}g!==this.currentObject&&(this.currentObject=g,this.view=A,this.follow||(this.follow=iA.addNewComponent(this.cam.gameObject,Ts)),this.target||(this.target=new NA),g.add(this.target),this.follow.enabled=!0,this.follow.target=this.target,Wi&&console.log("FOLLOW",g),this.context.isInXR?this.context.removeCamera(this.cam):this.context.setCurrentCamera(this.cam))}disable(){Wi&&console.log("STOP FOLLOW",this.currentObject),this.view=void 0,this.currentObject=void 0,this.context.removeCamera(this.cam),this.follow&&(this.follow.enabled=!1)}destroy(){var A;(A=this.target)==null||A.removeFromParent(),this.follow&&iA.destroy(this.follow)}update(A){var g,e,i,t,C,o;if(((g=this.currentTarget)==null?void 0:g.isConnected)===!1||((e=this.currentTarget)==null?void 0:e.removed)===!0){Wi&&console.log("Target disconnected or timeout",this.currentTarget),this.spectator.stopSpectating();return}this.currentTarget&&((i=this.currentTarget)==null?void 0:i.currentObject)!==this.currentObject&&(Wi&&console.log("Target changed",this.currentObject,"to",this.currentTarget.currentObject),this.set(this.currentTarget));const s=this.context.mainCamera;s&&(this.cam.cam.near!==s.near||this.cam.cam.far!==s.far)&&(this.cam.cam.near=s.near,this.cam.cam.far=s.far,this.cam.cam.updateProjectionMatrix());const B=(t=this.follow)==null?void 0:t.target;if(!(!B||!this.follow)){switch(A){case 0:((C=this.view)==null?void 0:C.viewDevice)!==Co.Browser?(this.follow.followFactor=5,this.follow.rotateFactor=5):(this.follow.followFactor=50,this.follow.rotateFactor=50),B.position.set(0,0,0);break;case 1:this.follow.followFactor=3,this.follow.rotateFactor=2,B.position.set(0,.5,1.5);break}this.follow.flipForward=!1,((o=this.view)==null?void 0:o.viewDevice)!==Co.Browser?B.quaternion.copy(oX):B.quaternion.identity()}}}const oX=new RA().setFromAxisAngle(new M(0,1,0),Math.PI);class sX{constructor(A,g){Q(this,"context"),Q(this,"spectator"),this.context=A,this.spectator=g,console.log("Click other avatars or cameras to follow them. Press ESC to exit spectator mode."),this.context.domElement.addEventListener("keydown",i=>{!this.spectator.useKeys||i.key==="Escape"&&this.spectator.stopSpectating()});let e=0;this.context.input.addEventListener(XC.PointerDown,i=>{e=this.context.time.time}),this.context.input.addEventListener(XC.PointerUp,i=>{const t=this.context.time.time-e;t>1?this.spectator.stopSpectating():this.context.input.getPointerClicked(0)&&t<.3&&this.trySelectObject()})}trySelectObject(){const A=new gC;A.setMask(16777215);const g=this.context.physics.raycast(A);if(Wi&&console.log(...g),g!=null&&g.length)for(const e of g){if(e.distance<.2)continue;const i=e.object,t=iA.getComponentInParent(i,Oe),C=t?.connectionId;if(C){const o=this.context.players.getPlayerView(C);this.spectator.target=o,Wi&&console.log("spectate",C,t);break}}}}class BX{constructor(A,g,e){Q(this,"guid"),Q(this,"dontSave",!0),Q(this,"targetUserId"),Q(this,"stoppedFollowing"),this.guid=A,this.targetUserId=g,this.stoppedFollowing=e}}class aX{constructor(A,g){Q(this,"guid"),Q(this,"userId"),this.guid=A.guid,this.userId=g}}class QX{constructor(A,g){Q(this,"followers",[]),Q(this,"context"),Q(this,"spectator"),Q(this,"_followerEventMethod"),Q(this,"_requestFollowMethod"),Q(this,"_joinedRoomMethod"),Q(this,"_lastRequestFollowUser"),Q(this,"_enforceFollowInterval"),this.context=A,this.spectator=g,this._followerEventMethod=this.onFollowerEvent.bind(this),this._requestFollowMethod=this.onRequestFollowEvent.bind(this),this._joinedRoomMethod=this.onUserJoinedRoom.bind(this)}awake(){this.context.connection.beginListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.beginListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.beginListen(qI.JoinedRoom,this._joinedRoomMethod),this.context.domElement.addEventListener("keydown",A=>{this.spectator.useKeys&&(A.key==="f"?this.onRequestFollowMe():A.key==="Escape"&&this.onRequestFollowMe(!0))})}destroy(){this.context.connection.stopListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.stopListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.stopListen(qI.JoinedRoom,this._joinedRoomMethod)}onSpectatedObjectChanged(A,g){if(Wi&&console.log(this.context.connection.connectionId,"onSpectatedObjectChanged",A,g),this.context.connection.connectionId){const e=A?.userId===void 0,i=e?g:A?.userId,t=new BX(this.context.connection.connectionId,i,e);this.context.connection.send("spectator-follower-changed",t)}}onRequestFollowMe(A=!1){if(Wi&&console.log("Request follow",this.context.connection.connectionId),this.context.connection.connectionId){this.spectator.stopSpectating();const g=A?void 0:this.context.connection.connectionId,e=new aX(this.spectator,g);this.context.connection.send("spectator-request-follow",e)}}onUserJoinedRoom(){EA("followme")&&this.onRequestFollowMe()}onFollowerEvent(A){const g=A.targetUserId,e=A.guid;if(Wi&&console.log(A),g===this.context.connection.connectionId)if(A.stoppedFollowing){const i=this.followers.indexOf(e);i!==-1&&(this.followers.splice(i,1),this.removeDisconnectedFollowers(),console.log(e,"unfollows you",this.followers.length))}else this.followers.includes(e)||(this.followers.push(e),this.removeDisconnectedFollowers(),console.log(e,"follows you",this.followers.length))}removeDisconnectedFollowers(){for(let A=this.followers.length-1;A>=0;A--){const g=this.followers[A];this.context.connection.userIsInRoom(g)===!1&&this.followers.splice(A,1)}}onRequestFollowEvent(A){if(this._lastRequestFollowUser=A,A.userId===this.context.connection.connectionId)this.spectator.stopSpectating();else if(A.userId===void 0)this.spectator.stopSpectating();else{const g=this.context.players.getPlayerView(A.userId);if(g)this.spectator.target=g;else return Wi&&console.warn("Could not find view",A.userId),this.enforceFollow(),!1}return!0}enforceFollow(){this._enforceFollowInterval||(this._enforceFollowInterval=setInterval(()=>{this._lastRequestFollowUser===void 0||this._lastRequestFollowUser.userId&&this.spectator.isFollowedBy(this._lastRequestFollowUser.userId)?(clearInterval(this._enforceFollowInterval),this._enforceFollowInterval=void 0):(Wi&&console.log("REQUEST FOLLOW AGAIN",this._lastRequestFollowUser.userId),this.onRequestFollowEvent(this._lastRequestFollowUser))},1e3))}}var nX=Object.defineProperty,rX=Object.getOwnPropertyDescriptor,ct=(I,A,g,e)=>{for(var i=e>1?void 0:e?rX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&nX(A,g,i),i};const DG=EA("debugspriterenderer"),EX=EA("wireframe"),dG=class{static getOrCreateGeometry(I){if(I._geometry)return I._geometry;if(I.guid&&dG.cache[I.guid])return DG&&console.log("Take cached geometry for sprite",I.guid),dG.cache[I.guid];const A=new lg;I._geometry=A;const g=new Float32Array(I.triangles.length*3),e=new Float32Array(I.triangles.length*2);for(let i=0;i<I.triangles.length;i+=1){const t=I.triangles[i];g[i*3]=-I.vertices[t].x,g[i*3+1]=I.vertices[t].y,g[i*3+2]=0;const C=I.uv[t];e[i*2]=C.x,e[i*2+1]=1-C.y}return A.setAttribute("position",new ag(g,3)),A.setAttribute("uv",new ag(e,2)),I.guid&&(this.cache[I.guid]=A),DG&&console.log("Built sprite geometry",I,A),A}};let pG=dG;Q(pG,"cache",{});class Uo{constructor(){Q(this,"guid"),Q(this,"texture"),Q(this,"triangles"),Q(this,"uv"),Q(this,"vertices"),Q(this,"_geometry")}}ct([m()],Uo.prototype,"guid",2),ct([m(Ng)],Uo.prototype,"texture",2),ct([pQ()],Uo.prototype,"triangles",2),ct([pQ()],Uo.prototype,"uv",2),ct([pQ()],Uo.prototype,"vertices",2);const uG=Symbol("spriteOwner");class Sh{constructor(){Q(this,"sprites")}}ct([m(Uo)],Sh.prototype,"sprites",2);class pn{constructor(){Q(this,"spriteSheet"),Q(this,"index",0)}update(){if(!this.spriteSheet)return;const A=this.index;if(A<0||A>=this.spriteSheet.sprites.length)return;const g=this.spriteSheet.sprites[A];let e=g?.texture;e&&(e.encoding=VA,e.minFilter==Wg&&e.magFilter==Wg&&(e.anisotropy=1),e.needsUpdate=!0)}}ct([m(Sh)],pn.prototype,"spriteSheet",2),ct([m()],pn.prototype,"index",2);class aa extends qA{constructor(){super(...arguments),Q(this,"drawMode",0),Q(this,"size",{x:1,y:1}),Q(this,"color"),Q(this,"sharedMaterial"),Q(this,"_spriteSheet"),Q(this,"_currentSprite")}get sprite(){return this._spriteSheet}set sprite(A){if(A!==this._spriteSheet)if(typeof A=="number"){const g=Math.floor(A);g===A&&(this.spriteIndex=g);return}else this._spriteSheet=A,this.updateSprite()}set spriteIndex(A){this._spriteSheet&&(this._spriteSheet.index=A,this.updateSprite())}get spriteIndex(){var A;return((A=this._spriteSheet)==null?void 0:A.index)??0}get spriteFrames(){var A,g;return((g=(A=this._spriteSheet)==null?void 0:A.spriteSheet)==null?void 0:g.sprites.length)??0}awake(){this._currentSprite=void 0,DG&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(){var A,g,e;if(!this.__didAwake||!((g=(A=this.sprite)==null?void 0:A.spriteSheet)!=null&&g.sprites))return;const i=this.sprite.spriteSheet.sprites[this.spriteIndex];if(this._currentSprite)this._currentSprite.geometry=pG.getOrCreateGeometry(i),this._currentSprite.material.map=i.texture;else{const t=new sI({color:16777215,side:nI});if(!t)return;if(EX&&(t.wireframe=!0),this.color&&(t.color||(t.color=new yA),t.color.copy(this.color),t.opacity=this.color.alpha),t.transparent=!0,i.texture&&!t.wireframe){let C=i.texture;C[uG]!==void 0&&C[uG]!==this&&this.spriteFrames>1&&(C=i.texture=C.clone()),C[uG]=this,t.map=C}this.sharedMaterial=t,this._currentSprite=new fA(pG.getOrCreateGeometry(i),t)}this._currentSprite.parent!==this.gameObject&&(this.drawMode===2&&this._currentSprite.scale.set(this.size.x,this.size.y,1),this.gameObject&&this.gameObject.add(this._currentSprite)),(e=this._spriteSheet)==null||e.update()}}ct([m()],aa.prototype,"drawMode",2),ct([m(QI)],aa.prototype,"color",2),ct([m(fg)],aa.prototype,"sharedMaterial",2),ct([m(pn)],aa.prototype,"sprite",1);class NC{constructor(){Q(this,"bb",null),Q(this,"bb_pos",0)}__init(A,g){return this.bb_pos=A,this.bb=g,this}static getRootAsSyncedCameraModel(A,g){return(g||new NC).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedCameraModel(A,g){return A.setPosition(A.position()+lD),(g||new NC).__init(A.readInt32(A.position())+A.position(),A)}userId(A){const g=this.bb.__offset(this.bb_pos,4);return g?this.bb.__string(this.bb_pos+g,A):null}guid(A){const g=this.bb.__offset(this.bb_pos,6);return g?this.bb.__string(this.bb_pos+g,A):null}dontSave(){const A=this.bb.__offset(this.bb_pos,8);return A?!!this.bb.readInt8(this.bb_pos+A):!1}pos(A){const g=this.bb.__offset(this.bb_pos,10);return g?(A||new Hi).__init(this.bb_pos+g,this.bb):null}rot(A){const g=this.bb.__offset(this.bb_pos,12);return g?(A||new Hi).__init(this.bb_pos+g,this.bb):null}static startSyncedCameraModel(A){A.startObject(5)}static addUserId(A,g){A.addFieldOffset(0,g,0)}static addGuid(A,g){A.addFieldOffset(1,g,0)}static addDontSave(A,g){A.addFieldInt8(2,+g,0)}static addPos(A,g){A.addFieldStruct(3,g,0)}static addRot(A,g){A.addFieldStruct(4,g,0)}static endSyncedCameraModel(A){return A.endObject()}static finishSyncedCameraModelBuffer(A,g){A.finish(g)}static finishSizePrefixedSyncedCameraModelBuffer(A,g){A.finish(g,void 0,!0)}}var hX=Object.defineProperty,cX=Object.getOwnPropertyDescriptor,lX=(I,A,g,e)=>{for(var i=e>1?void 0:e?cX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&hX(A,g,i),i};const pp="SCAM";DS(pp,NC.getRootAsSyncedCameraModel);const Zi=new Rn;class DX{constructor(A,g){Q(this,"userId"),Q(this,"guid"),this.guid=g,this.userId=A}send(A,g){if(A){Zi.clear();const e=Zi.createString(this.guid),i=Zi.createString(this.userId);NC.startSyncedCameraModel(Zi),NC.addGuid(Zi,e),NC.addUserId(Zi,i);const t=wg(A),C=kU(A);NC.addPos(Zi,Hi.createVec3(Zi,t.x,t.y,t.z)),NC.addRot(Zi,Hi.createVec3(Zi,C.x,C.y,C.z));const o=NC.endSyncedCameraModel(Zi);Zi.finish(o,pp),g.sendBinary(Zi.asUint8Array())}}}var wG;const yG=(wG=class extends qA{constructor(){super(...arguments),Q(this,"cameraPrefab",null),Q(this,"_lastWorldPosition"),Q(this,"_lastWorldQuaternion"),Q(this,"_model",null),Q(this,"_needsUpdate",!0),Q(this,"_lastUpdateTime",0),Q(this,"remoteCams",{}),Q(this,"userToCamMap",{}),Q(this,"_camTimeoutInSeconds",10),Q(this,"_receiveCallback",null)}getCameraObject(I){const A=this.userToCamMap[I];return A?this.remoteCams[A].obj:null}async awake(){this._lastWorldPosition=this.worldPosition.clone(),this._lastWorldQuaternion=this.worldQuaternion.clone(),this.cameraPrefab&&("uri"in this.cameraPrefab&&(this.cameraPrefab=await this.cameraPrefab.instantiate(this.gameObject)),this.cameraPrefab&&"isObject3D"in this.cameraPrefab&&(this.cameraPrefab.visible=!1))}onEnable(){this._receiveCallback=this.context.connection.beginListenBinary(pp,this.onReceivedRemoteCameraInfoBin.bind(this))}onDisable(){this.context.connection.stopListenBinary(pp,this._receiveCallback)}update(){for(const e in this.remoteCams){const i=this.remoteCams[e],t=this.context.time.realtimeSinceStartup-i.lastUpdate;if(!i||t>this._camTimeoutInSeconds){console.log("Remote cam timeout",i,t),i!=null&&i.obj&&iA.destroy(i.obj),delete this.remoteCams[e],i&&delete this.userToCamMap[i.userId],yG.instances.push(i),this.context.players.removePlayerView(i.userId,Co.Browser);continue}}if(Ug.IsInWebXR)return;const I=this.context.mainCamera;if(I===null){this.enabled=!1;return}if(!this.context.connection.isConnected||this.context.connection.connectionId===null)return;this._model===null&&(this._model=new DX(this.context.connection.connectionId,this.context.connection.connectionId+"_camera"));const A=wg(I),g=Ji(I);(A.distanceTo(this._lastWorldPosition)>.001||g.angleTo(this._lastWorldQuaternion)>.01)&&(this._needsUpdate=!0),this._lastWorldPosition.copy(A),this._lastWorldQuaternion.copy(g),!((!this._needsUpdate||this.context.time.frameCount%2!==0)&&!(this.context.time.realtimeSinceStartup-this._lastUpdateTime>this._camTimeoutInSeconds*.5))&&(this._lastUpdateTime=this.context.time.realtimeSinceStartup,this._needsUpdate=!1,this._model.send(I,this.context.connection),this.context.isInXR||this.context.players.setPlayerView(this.context.connection.connectionId,I,Co.Browser))}onReceivedRemoteCameraInfoBin(I){const A=I.guid();if(!A)return;const g=I.userId();if(!g||!this.context.connection.userIsInRoom(g)||!this.cameraPrefab)return;let e=this.remoteCams[A];if(!e)if("isObject3D"in this.cameraPrefab){const o=new Vt;o.context=this.context;const s=iA.instantiate(this.cameraPrefab,o);e=this.remoteCams[A]={obj:s,lastUpdate:this.context.time.realtimeSinceStartup,userId:g},e.obj.visible=!0,this.gameObject.add(s),this.userToCamMap[g]=A,yG.instances.push(e);const B=iA.getOrAddComponent(s,Oe);B.connectionId=g,B.avatar=s}else return;const i=e.obj;this.context.players.setPlayerView(g,i,Co.Browser),e.lastUpdate=this.context.time.realtimeSinceStartup,Si.markDirty(i);const t=I.pos();t&&ur(i,t.x(),t.y(),t.z());const C=I.rot();C&&GU(i,C.x(),C.y(),C.z())}},Q(wG,"instances",[]),wG);let up=yG;lX([m([NA,tC])],up.prototype,"cameraPrefab",2);var dX=Object.defineProperty,pX=Object.getOwnPropertyDescriptor,kh=(I,A,g,e)=>{for(var i=e>1?void 0:e?pX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&dX(A,g,i),i};const SG="view",wp=EA("debugsyncedroom");class Os extends qA{constructor(){super(...arguments),Q(this,"roomName"),Q(this,"urlParameterName","room"),Q(this,"joinRandomRoom",!0),Q(this,"requireRoomParameter",!1),Q(this,"autoRejoin",!0),Q(this,"_roomPrefix"),Q(this,"_lastPingTime",0),Q(this,"_lastRoomTime",-1)}get RoomPrefix(){return this._roomPrefix}awake(){wp&&console.log("Room",this.roomName,this.urlParameterName,this.joinRandomRoom,this.requireRoomParameter,this.autoRejoin),this._roomPrefix===void 0&&(this._roomPrefix=this.roomName,this.roomName="")}onEnable(){const A=EA(SG);if(A&&typeof A=="string"&&A.length>0){console.log("Join as viewer"),this.context.connection.joinRoom(A,!0);return}this.tryJoinRoom()}onDisable(){this.roomName&&this.roomName.length>0&&this.context.connection.leaveRoom(this.roomName)}tryJoinRoom(A=0){A===void 0&&(A=0);let g=!1;if(this.urlParameterName){const e=EA(this.urlParameterName);if(e&&typeof e=="string"){g=!0;const i=Nb(e);this.roomName=i}else if(this.joinRandomRoom&&(console.log("No room name found in url, generating random one"),this.setRandomRoomUrlParameter(),A<1))return this.tryJoinRoom(A+1)}else this.joinRandomRoom&&(this.roomName===null||this.roomName===void 0||this.roomName.length<=0)&&(console.log("generate room name"),this.roomName=this.generateRoomName());return this.requireRoomParameter&&!g?(wp&&console.log('No required room parameter "'+this.urlParameterName+'" in url - will not connect to networking backend.'),!1):!this.roomName||this.roomName.length<=0?(wp&&console.error('Missing room name on "'+this.name+'". Make sure this is correctly configured in Unity',this.context.connection.isDebugEnabled?this:""),!1):(this.context.connection.isConnected||this.context.connection.connect(),wp&&console.log("Join "+this.roomName),this._roomPrefix&&(this.roomName=this._roomPrefix+this.roomName),this.context.connection.joinRoom(this.roomName),!0)}update(){this.context.connection.isConnected&&(this.context.time.time-this._lastPingTime>3&&(this._lastPingTime=this.context.time.time,this.context.connection.sendPing()),this.context.connection.isInRoom&&(this._lastRoomTime=this.context.time.time)),this._lastRoomTime>0&&this.context.time.time-this._lastRoomTime>.3&&(this._lastRoomTime=-1,this.autoRejoin?(console.log("Disconnected from networking backend - attempt reconnecting now"),this.tryJoinRoom()):console.warn("You are not connected to a room anymore (possibly because the tab was inactive for too long and the server kicked you)"))}get currentRoomName(){return EA(SG)||EA(this.urlParameterName)}setRandomRoomUrlParameter(){const A=ic(),g=this.generateRoomName();EA(this.urlParameterName)?A.set(this.urlParameterName,g):A.append(this.urlParameterName,g),XG(g,A)}generateRoomName(){return Fb()+"_"+Rb(100,999)}getViewOnlyUrl(){if(this.context.connection.isConnected&&this.context.connection.currentRoomViewId){const A=window.location.search,g=new URLSearchParams(A);return g.has(this.urlParameterName)&&g.delete(this.urlParameterName),g.set(SG,this.context.connection.currentRoomViewId),window.location.origin+window.location.pathname+"?"+g.toString()}return null}}kh([m()],Os.prototype,"roomName",2),kh([m()],Os.prototype,"urlParameterName",2),kh([m()],Os.prototype,"joinRandomRoom",2),kh([m()],Os.prototype,"requireRoomParameter",2),kh([m()],Os.prototype,"autoRejoin",2);function uX(){const I=EA("testwindowcount")||0;I&&I>0&&wX(I)}function wX(I){if(EA("testwindow"))return null;const A=new URL(window.location.href);Kn(A.searchParams,zD,1),Kn(A.searchParams,"testwindow",1);const g=A.toString(),e=[];window.onbeforeunload=()=>{for(const s of e)s.close()};const i=.05,t=128;let C=0,o=0;for(let s=0;s<I;s++){C*t+t*.01>=window.innerWidth&&(o+=1,C=0);const B=C*(t*(1+i))+window.screenLeft,a=o*(t*(1+i))+window.screenTop+90+60*o;C+=1;const n=window.open(g,"test window "+s,`popup=yes width=${t} height=${t} top=${a} left=${B}`);if(!n){console.warn("Failed to open window");continue}e.push(n),n.onload=()=>{n.onbeforeunload=()=>{for(let r=0;r<e.length;r++){const E=e[r];E!==n&&E.close()}e.length=0}}}return e}class kG extends qA{awake(){uX()}}class GG extends qA{constructor(){super(...arguments),Q(this,"transformsPerFrame",10),Q(this,"interval",0),Q(this,"useFlatbuffers",!0),Q(this,"builder",null),Q(this,"models",null)}awake(){if(this.useFlatbuffers)this.context.connection.beginListenBinary(DE,A=>{});else{this.models=[];for(let A=0;A<this.transformsPerFrame;A++)this.models.push(new gb(this.context.connection.connectionId+"_simulatedTransform_"+A,this))}}update(){if(this.context.connection.isConnected){if(this.useFlatbuffers){if(!this.context.connection.connectionId||this.context.time.frameCount%this.interval!==0)return;this.builder===null&&(this.builder=new Rn(1024));const A=this.builder;for(let g=0;g<this.transformsPerFrame;g++){A.clear();const e=LK(this.context.connection.connectionId,this);this.context.connection.sendBinary(e)}}else if(this.models)for(let A=0;A<this.models.length;A++){const g=this.models[A];g.dontSave=!0,g.update(this,null),this.context.connection.send("TestSimulateUserData-"+A,g)}}}}class gb{constructor(A,g){Q(this,"guid"),Q(this,"fast",!1),Q(this,"position"),Q(this,"rotation"),Q(this,"velocity"),Q(this,"dontSave"),this.guid=A,this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0,w:0},this.update(g,null)}isValid(){return this.fast!==void 0||this.position!==void 0||this.rotation!==void 0||this.velocity!==void 0}update(A,g){const e=A.worldPosition;this.position.x=e.x,this.position.y=e.y,this.position.z=e.z;const i=A.worldQuaternion;if(this.rotation.x=i.x,this.rotation.y=i.y,this.rotation.z=i.z,this.rotation.w=i.w,this.fast=!1,g){const t=g.getVelocity();this.velocity===void 0&&(this.velocity={x:0,y:0,z:0}),this.velocity.x=t.x,this.velocity.y=t.y,this.velocity.z=t.z}}}Q(gb,"temp",new M);var yX=Object.defineProperty,SX=Object.getOwnPropertyDescriptor,un=(I,A,g,e)=>{for(var i=e>1?void 0:e?SX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&yX(A,g,i),i};class SC extends pi{constructor(){super(...arguments),Q(this,"offset"),Q(this,"rotation"),Q(this,"focusArea"),Q(this,"feather"),Q(this,"kernelSize"),Q(this,"resolutionScale")}get typeName(){return"TiltShiftEffect"}init(){this.offset.defaultValue=0,this.rotation.defaultValue=0,this.focusArea.defaultValue=.4,this.feather.defaultValue=.3,this.kernelSize.defaultValue=to.MEDIUM,this.resolutionScale.defaultValue=1/window.devicePixelRatio}onCreateEffect(){console.log(this);const A=new o3({kernelSize:to.VERY_LARGE});return this.offset.onValueChanged=g=>A.offset=g,this.rotation.onValueChanged=g=>A.rotation=g,this.focusArea.onValueChanged=g=>A.focusArea=g,this.feather.onValueChanged=g=>A.feather=g,this.kernelSize.onValueChanged=g=>A.blurPass.kernelSize=g,this.resolutionScale.onValueChanged=g=>A.resolution.scale=g/window.devicePixelRatio,A}}un([m(mg)],SC.prototype,"offset",2),un([m(mg)],SC.prototype,"rotation",2),un([m(mg)],SC.prototype,"focusArea",2),un([m(mg)],SC.prototype,"feather",2),un([m(mg)],SC.prototype,"kernelSize",2),un([m(mg)],SC.prototype,"resolutionScale",2),hC("TiltShiftEffect",SC);var kX=Object.defineProperty,GX=Object.getOwnPropertyDescriptor,fX=(I,A,g,e)=>{for(var i=e>1?void 0:e?GX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&kX(A,g,i),i};class Gh extends pi{constructor(){super(...arguments),Q(this,"mode")}get typeName(){return"ToneMapping"}get isToneMapping(){return!0}init(){this.mode.defaultValue=Ze}apply(){this.mode.onValueChanged=this._apply.bind(this),this._apply(this.mode.value)}unapply(){this.context.renderer.toneMapping=Ze}_apply(A){switch(A){case 0:this.context.renderer.toneMapping=Ln;break;case 1:this.context.renderer.toneMapping=lu;break;case 2:this.context.renderer.toneMapping=Du;break}}}fX([m(mg)],Gh.prototype,"mode",2),hC("Tonemapping",Gh);const Qa=new iQ,yi=new M,_s=new M,dI=new RA,Ib={X:new M(1,0,0),Y:new M(0,1,0),Z:new M(0,0,1)},fG={type:"change"},eb={type:"mouseDown"},ib={type:"mouseUp",mode:null},tb={type:"objectChange"};class MX extends NA{constructor(A,g){super(),g===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),g=document),this.isTransformControls=!0,this.visible=!1,this.domElement=g,this.domElement.style.touchAction="none";const e=new KX;this._gizmo=e,this.add(e);const i=new JX;this._plane=i,this.add(i);const t=this;function C(w,l){let p=l;Object.defineProperty(t,w,{get:function(){return p!==void 0?p:l},set:function(u){p!==u&&(p=u,i[w]=u,e[w]=u,t.dispatchEvent({type:w+"-changed",value:u}),t.dispatchEvent(fG))}}),t[w]=l,i[w]=l,e[w]=l}C("camera",A),C("object",void 0),C("enabled",!0),C("axis",null),C("mode","translate"),C("translationSnap",null),C("rotationSnap",null),C("scaleSnap",null),C("space","world"),C("size",1),C("dragging",!1),C("showX",!0),C("showY",!0),C("showZ",!0);const o=new M,s=new M,B=new RA,a=new RA,n=new M,r=new RA,E=new M,h=new M,c=new M,D=0,d=new M;C("worldPosition",o),C("worldPositionStart",s),C("worldQuaternion",B),C("worldQuaternionStart",a),C("cameraPosition",n),C("cameraQuaternion",r),C("pointStart",E),C("pointEnd",h),C("rotationAxis",c),C("rotationAngle",D),C("eye",d),this._offset=new M,this._startNorm=new M,this._endNorm=new M,this._cameraScale=new M,this._parentPosition=new M,this._parentQuaternion=new RA,this._parentQuaternionInv=new RA,this._parentScale=new M,this._worldScaleStart=new M,this._worldQuaternionInv=new RA,this._worldScale=new M,this._positionStart=new M,this._quaternionStart=new RA,this._scaleStart=new M,this._getPointer=mX.bind(this),this._onPointerDown=RX.bind(this),this._onPointerHover=UX.bind(this),this._onPointerMove=FX.bind(this),this._onPointerUp=NX.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(A){if(this.object===void 0||this.dragging===!0)return;Qa.setFromCamera(A,this.camera);const g=MG(this._gizmo.picker[this.mode],Qa);g?this.axis=g.object.name:this.axis=null}pointerDown(A){if(!(this.object===void 0||this.dragging===!0||A.button!==0)&&this.axis!==null){Qa.setFromCamera(A,this.camera);const g=MG(this._plane,Qa,!0);g&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(g.point).sub(this.worldPositionStart)),this.dragging=!0,eb.mode=this.mode,this.dispatchEvent(eb)}}pointerMove(A){const g=this.axis,e=this.mode,i=this.object;let t=this.space;if(e==="scale"?t="local":(g==="E"||g==="XYZE"||g==="XYZ")&&(t="world"),i===void 0||g===null||this.dragging===!1||A.button!==-1)return;Qa.setFromCamera(A,this.camera);const C=MG(this._plane,Qa,!0);if(C){if(this.pointEnd.copy(C.point).sub(this.worldPositionStart),e==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),t==="local"&&g!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),g.indexOf("X")===-1&&(this._offset.x=0),g.indexOf("Y")===-1&&(this._offset.y=0),g.indexOf("Z")===-1&&(this._offset.z=0),t==="local"&&g!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),i.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(t==="local"&&(i.position.applyQuaternion(dI.copy(this._quaternionStart).invert()),g.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),g.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),g.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.position.applyQuaternion(this._quaternionStart)),t==="world"&&(i.parent&&i.position.add(yi.setFromMatrixPosition(i.parent.matrixWorld)),g.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),g.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),g.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.parent&&i.position.sub(yi.setFromMatrixPosition(i.parent.matrixWorld))));else if(e==="scale"){if(g.search("XYZ")!==-1){let o=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(o*=-1),_s.set(o,o,o)}else yi.copy(this.pointStart),_s.copy(this.pointEnd),yi.applyQuaternion(this._worldQuaternionInv),_s.applyQuaternion(this._worldQuaternionInv),_s.divide(yi),g.search("X")===-1&&(_s.x=1),g.search("Y")===-1&&(_s.y=1),g.search("Z")===-1&&(_s.z=1);i.scale.copy(this._scaleStart).multiply(_s),this.scaleSnap&&(g.search("X")!==-1&&(i.scale.x=Math.round(i.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),g.search("Y")!==-1&&(i.scale.y=Math.round(i.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),g.search("Z")!==-1&&(i.scale.z=Math.round(i.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(e==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const o=20/this.worldPosition.distanceTo(yi.setFromMatrixPosition(this.camera.matrixWorld));g==="E"?(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1):g==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(yi.copy(this.rotationAxis).cross(this.eye))*o):(g==="X"||g==="Y"||g==="Z")&&(this.rotationAxis.copy(Ib[g]),yi.copy(Ib[g]),t==="local"&&yi.applyQuaternion(this.worldQuaternion),this.rotationAngle=this._offset.dot(yi.cross(this.eye).normalize())*o),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),t==="local"&&g!=="E"&&g!=="XYZE"?(i.quaternion.copy(this._quaternionStart),i.quaternion.multiply(dI.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),i.quaternion.copy(dI.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),i.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(fG),this.dispatchEvent(tb)}}pointerUp(A){A.button===0&&(this.dragging&&this.axis!==null&&(ib.mode=this.mode,this.dispatchEvent(ib)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(A){A.geometry&&A.geometry.dispose(),A.material&&A.material.dispose()})}attach(A){return this.object=A,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(fG),this.dispatchEvent(tb),this.pointStart.copy(this.pointEnd))}getRaycaster(){return Qa}getMode(){return this.mode}setMode(A){this.mode=A}setTranslationSnap(A){this.translationSnap=A}setRotationSnap(A){this.rotationSnap=A}setScaleSnap(A){this.scaleSnap=A}setSize(A){this.size=A}setSpace(A){this.space=A}}function mX(I){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:I.button};{const A=this.domElement.getBoundingClientRect();return{x:(I.clientX-A.left)/A.width*2-1,y:-(I.clientY-A.top)/A.height*2+1,button:I.button}}}function UX(I){if(this.enabled)switch(I.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(I));break}}function RX(I){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(I.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(I)),this.pointerDown(this._getPointer(I)))}function FX(I){this.enabled&&this.pointerMove(this._getPointer(I))}function NX(I){this.enabled&&(this.domElement.releasePointerCapture(I.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(I)))}function MG(I,A,g){const e=A.intersectObject(I,!0);for(let i=0;i<e.length;i++)if(e[i].object.visible||g)return e[i];return!1}const yp=new $I,aI=new M(0,1,0),Cb=new M(0,0,0),ob=new PA,Sp=new RA,kp=new RA,kC=new M,sb=new PA,fh=new M(1,0,0),na=new M(0,1,0),Mh=new M(0,0,1),Gp=new M,mh=new M,Uh=new M;class KX extends NA{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const A=new sI({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),g=new NI({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=A.clone();e.opacity=.15;const i=g.clone();i.opacity=.5;const t=A.clone();t.color.setHex(16711680);const C=A.clone();C.color.setHex(65280);const o=A.clone();o.color.setHex(255);const s=A.clone();s.color.setHex(16711680),s.opacity=.5;const B=A.clone();B.color.setHex(65280),B.opacity=.5;const a=A.clone();a.color.setHex(255),a.opacity=.5;const n=A.clone();n.opacity=.25;const r=A.clone();r.color.setHex(16776960),r.opacity=.25,A.clone().color.setHex(16776960);const E=A.clone();E.color.setHex(7895160);const h=new UI(0,.04,.1,12);h.translate(0,.05,0);const c=new tI(.08,.08,.08);c.translate(0,.04,0);const D=new lg;D.setAttribute("position",new Ig([0,0,0,1,0,0],3));const d=new UI(.0075,.0075,.5,3);d.translate(0,.25,0);function w(J,H){const O=new MC(J,.0075,3,64,H*Math.PI*2);return O.rotateY(Math.PI/2),O.rotateX(Math.PI/2),O}function l(){const J=new lg;return J.setAttribute("position",new Ig([0,0,0,1,1,1],3)),J}const p={X:[[new fA(h,t),[.5,0,0],[0,0,-Math.PI/2]],[new fA(h,t),[-.5,0,0],[0,0,Math.PI/2]],[new fA(d,t),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new fA(h,C),[0,.5,0]],[new fA(h,C),[0,-.5,0],[Math.PI,0,0]],[new fA(d,C)]],Z:[[new fA(h,o),[0,0,.5],[Math.PI/2,0,0]],[new fA(h,o),[0,0,-.5],[-Math.PI/2,0,0]],[new fA(d,o),null,[Math.PI/2,0,0]]],XYZ:[[new fA(new fC(.1,0),n.clone()),[0,0,0]]],XY:[[new fA(new tI(.15,.15,.01),a.clone()),[.15,.15,0]]],YZ:[[new fA(new tI(.15,.15,.01),s.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new fA(new tI(.15,.15,.01),B.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},u={X:[[new fA(new UI(.2,0,.6,4),e),[.3,0,0],[0,0,-Math.PI/2]],[new fA(new UI(.2,0,.6,4),e),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new fA(new UI(.2,0,.6,4),e),[0,.3,0]],[new fA(new UI(.2,0,.6,4),e),[0,-.3,0],[0,0,Math.PI]]],Z:[[new fA(new UI(.2,0,.6,4),e),[0,0,.3],[Math.PI/2,0,0]],[new fA(new UI(.2,0,.6,4),e),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new fA(new fC(.2,0),e)]],XY:[[new fA(new tI(.2,.2,.01),e),[.15,.15,0]]],YZ:[[new fA(new tI(.2,.2,.01),e),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new fA(new tI(.2,.2,.01),e),[.15,0,.15],[-Math.PI/2,0,0]]]},y={START:[[new fA(new fC(.01,2),i),null,null,null,"helper"]],END:[[new fA(new fC(.01,2),i),null,null,null,"helper"]],DELTA:[[new KI(l(),i),null,null,null,"helper"]],X:[[new KI(D,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new KI(D,i.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new KI(D,i.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},k={XYZE:[[new fA(w(.5,1),E),null,[0,Math.PI/2,0]]],X:[[new fA(w(.5,.5),t)]],Y:[[new fA(w(.5,.5),C),null,[0,0,-Math.PI/2]]],Z:[[new fA(w(.5,.5),o),null,[0,Math.PI/2,0]]],E:[[new fA(w(.75,1),r),null,[0,Math.PI/2,0]]]},S={AXIS:[[new KI(D,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},G={XYZE:[[new fA(new Dt(.25,10,8),e)]],X:[[new fA(new MC(.5,.1,4,24),e),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new fA(new MC(.5,.1,4,24),e),[0,0,0],[Math.PI/2,0,0]]],Z:[[new fA(new MC(.5,.1,4,24),e),[0,0,0],[0,0,-Math.PI/2]]],E:[[new fA(new MC(.75,.1,2,24),e)]]},f={X:[[new fA(c,t),[.5,0,0],[0,0,-Math.PI/2]],[new fA(d,t),[0,0,0],[0,0,-Math.PI/2]],[new fA(c,t),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new fA(c,C),[0,.5,0]],[new fA(d,C)],[new fA(c,C),[0,-.5,0],[0,0,Math.PI]]],Z:[[new fA(c,o),[0,0,.5],[Math.PI/2,0,0]],[new fA(d,o),[0,0,0],[Math.PI/2,0,0]],[new fA(c,o),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new fA(new tI(.15,.15,.01),a),[.15,.15,0]]],YZ:[[new fA(new tI(.15,.15,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new fA(new tI(.15,.15,.01),B),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new fA(new tI(.1,.1,.1),n.clone())]]},K={X:[[new fA(new UI(.2,0,.6,4),e),[.3,0,0],[0,0,-Math.PI/2]],[new fA(new UI(.2,0,.6,4),e),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new fA(new UI(.2,0,.6,4),e),[0,.3,0]],[new fA(new UI(.2,0,.6,4),e),[0,-.3,0],[0,0,Math.PI]]],Z:[[new fA(new UI(.2,0,.6,4),e),[0,0,.3],[Math.PI/2,0,0]],[new fA(new UI(.2,0,.6,4),e),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new fA(new tI(.2,.2,.01),e),[.15,.15,0]]],YZ:[[new fA(new tI(.2,.2,.01),e),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new fA(new tI(.2,.2,.01),e),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new fA(new tI(.2,.2,.2),e),[0,0,0]]]},q={X:[[new KI(D,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new KI(D,i.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new KI(D,i.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function F(J){const H=new NA;for(const O in J)for(let X=J[O].length;X--;){const W=J[O][X][0].clone(),BA=J[O][X][1],aA=J[O][X][2],DA=J[O][X][3],MA=J[O][X][4];W.name=O,W.tag=MA,BA&&W.position.set(BA[0],BA[1],BA[2]),aA&&W.rotation.set(aA[0],aA[1],aA[2]),DA&&W.scale.set(DA[0],DA[1],DA[2]),W.updateMatrix();const eA=W.geometry.clone();eA.applyMatrix4(W.matrix),W.geometry=eA,W.renderOrder=1/0,W.position.set(0,0,0),W.rotation.set(0,0,0),W.scale.set(1,1,1),H.add(W)}return H}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=F(p)),this.add(this.gizmo.rotate=F(k)),this.add(this.gizmo.scale=F(f)),this.add(this.picker.translate=F(u)),this.add(this.picker.rotate=F(G)),this.add(this.picker.scale=F(K)),this.add(this.helper.translate=F(y)),this.add(this.helper.rotate=F(S)),this.add(this.helper.scale=F(q)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(A){const g=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:kp;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let e=[];e=e.concat(this.picker[this.mode].children),e=e.concat(this.gizmo[this.mode].children),e=e.concat(this.helper[this.mode].children);for(let i=0;i<e.length;i++){const t=e[i];t.visible=!0,t.rotation.set(0,0,0),t.position.copy(this.worldPosition);let C;if(this.camera.isOrthographicCamera?C=(this.camera.top-this.camera.bottom)/this.camera.zoom:C=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),t.scale.set(1,1,1).multiplyScalar(C*this.size/4),t.tag==="helper"){t.visible=!1,t.name==="AXIS"?(t.position.copy(this.worldPositionStart),t.visible=!!this.axis,this.axis==="X"&&(dI.setFromEuler(yp.set(0,0,0)),t.quaternion.copy(g).multiply(dI),Math.abs(aI.copy(fh).applyQuaternion(g).dot(this.eye))>.9&&(t.visible=!1)),this.axis==="Y"&&(dI.setFromEuler(yp.set(0,0,Math.PI/2)),t.quaternion.copy(g).multiply(dI),Math.abs(aI.copy(na).applyQuaternion(g).dot(this.eye))>.9&&(t.visible=!1)),this.axis==="Z"&&(dI.setFromEuler(yp.set(0,Math.PI/2,0)),t.quaternion.copy(g).multiply(dI),Math.abs(aI.copy(Mh).applyQuaternion(g).dot(this.eye))>.9&&(t.visible=!1)),this.axis==="XYZE"&&(dI.setFromEuler(yp.set(0,Math.PI/2,0)),aI.copy(this.rotationAxis),t.quaternion.setFromRotationMatrix(ob.lookAt(Cb,aI,na)),t.quaternion.multiply(dI),t.visible=this.dragging),this.axis==="E"&&(t.visible=!1)):t.name==="START"?(t.position.copy(this.worldPositionStart),t.visible=this.dragging):t.name==="END"?(t.position.copy(this.worldPosition),t.visible=this.dragging):t.name==="DELTA"?(t.position.copy(this.worldPositionStart),t.quaternion.copy(this.worldQuaternionStart),yi.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),yi.applyQuaternion(this.worldQuaternionStart.clone().invert()),t.scale.copy(yi),t.visible=this.dragging):(t.quaternion.copy(g),this.dragging?t.position.copy(this.worldPositionStart):t.position.copy(this.worldPosition),this.axis&&(t.visible=this.axis.search(t.name)!==-1));continue}t.quaternion.copy(g),this.mode==="translate"||this.mode==="scale"?(t.name==="X"&&Math.abs(aI.copy(fh).applyQuaternion(g).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="Y"&&Math.abs(aI.copy(na).applyQuaternion(g).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="Z"&&Math.abs(aI.copy(Mh).applyQuaternion(g).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="XY"&&Math.abs(aI.copy(Mh).applyQuaternion(g).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="YZ"&&Math.abs(aI.copy(fh).applyQuaternion(g).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="XZ"&&Math.abs(aI.copy(na).applyQuaternion(g).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1)):this.mode==="rotate"&&(Sp.copy(g),aI.copy(this.eye).applyQuaternion(dI.copy(g).invert()),t.name.search("E")!==-1&&t.quaternion.setFromRotationMatrix(ob.lookAt(this.eye,Cb,na)),t.name==="X"&&(dI.setFromAxisAngle(fh,Math.atan2(-aI.y,aI.z)),dI.multiplyQuaternions(Sp,dI),t.quaternion.copy(dI)),t.name==="Y"&&(dI.setFromAxisAngle(na,Math.atan2(aI.x,aI.z)),dI.multiplyQuaternions(Sp,dI),t.quaternion.copy(dI)),t.name==="Z"&&(dI.setFromAxisAngle(Mh,Math.atan2(aI.y,aI.x)),dI.multiplyQuaternions(Sp,dI),t.quaternion.copy(dI))),t.visible=t.visible&&(t.name.indexOf("X")===-1||this.showX),t.visible=t.visible&&(t.name.indexOf("Y")===-1||this.showY),t.visible=t.visible&&(t.name.indexOf("Z")===-1||this.showZ),t.visible=t.visible&&(t.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),t.material._color=t.material._color||t.material.color.clone(),t.material._opacity=t.material._opacity||t.material.opacity,t.material.color.copy(t.material._color),t.material.opacity=t.material._opacity,this.enabled&&this.axis&&(t.name===this.axis||this.axis.split("").some(function(o){return t.name===o}))&&(t.material.color.setHex(16776960),t.material.opacity=1)}super.updateMatrixWorld(A)}}class JX extends fA{constructor(){super(new Je(1e5,1e5,2,2),new sI({visible:!1,wireframe:!0,side:nI,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(A){let g=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(g="local"),Gp.copy(fh).applyQuaternion(g==="local"?this.worldQuaternion:kp),mh.copy(na).applyQuaternion(g==="local"?this.worldQuaternion:kp),Uh.copy(Mh).applyQuaternion(g==="local"?this.worldQuaternion:kp),aI.copy(mh),this.mode){case"translate":case"scale":switch(this.axis){case"X":aI.copy(this.eye).cross(Gp),kC.copy(Gp).cross(aI);break;case"Y":aI.copy(this.eye).cross(mh),kC.copy(mh).cross(aI);break;case"Z":aI.copy(this.eye).cross(Uh),kC.copy(Uh).cross(aI);break;case"XY":kC.copy(Uh);break;case"YZ":kC.copy(Gp);break;case"XZ":aI.copy(Uh),kC.copy(mh);break;case"XYZ":case"E":kC.set(0,0,0);break}break;case"rotate":default:kC.set(0,0,0)}kC.length()===0?this.quaternion.copy(this.cameraQuaternion):(sb.lookAt(yi.set(0,0,0),kC,aI),this.quaternion.setFromRotationMatrix(sb)),super.updateMatrixWorld(A)}}var qX=Object.defineProperty,bX=Object.getOwnPropertyDescriptor,LX=(I,A,g,e)=>{for(var i=e>1?void 0:e?bX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&qX(A,g,i),i};class fp extends qA{constructor(){super(...arguments),Q(this,"isGizmo",!0),Q(this,"control"),Q(this,"orbit"),Q(this,"changeEventListener"),Q(this,"windowKeyDownListener"),Q(this,"windowKeyUpListener")}awake(){this.isGizmo&&!pr||this.context.mainCamera&&(this.control=new MX(this.context.mainCamera,this.context.renderer.domElement),this.control.visible=!0,this.control.enabled=!0,this.control.getRaycaster().layers.set(2),this.control.size=.6,this.control.traverse(A=>{const g=A;if(g.layers.set(2),g){const e=g.material;e&&(e.opacity=.3)}}))}start(){if(this.context.mainCamera){const A=iA.getComponentInParent(this.context.mainCamera,MK)??void 0;this.orbit=A}}onEnable(){var A;this.control&&(this.context.scene.add(this.control),this.control.attach(this.gameObject)),this.changeEventListener=this.onControlChangedEvent.bind(this),(A=this.control)==null||A.addEventListener("dragging-changed",this.changeEventListener),this.attachWindowEvents()}onDisable(){var A,g;(A=this.control)==null||A.removeFromParent(),this.changeEventListener&&((g=this.control)==null||g.removeEventListener("dragging-changed",this.changeEventListener))}onControlChangedEvent(A){const g=this.orbit;if(g&&(g.enabled=!A.value),A.value){const e=iA.getComponentInParent(this.gameObject,Rs);e&&e.requestOwnership()}}attachWindowEvents(){const A=this.control;A&&(this.windowKeyDownListener||(this.windowKeyDownListener=g=>{switch(g.keyCode){case 81:A.setSpace(A.space==="local"?"world":"local");break;case 16:A.setTranslationSnap(100),A.setRotationSnap(ai.degToRad(15)),A.setScaleSnap(.25);break;case 87:A.setMode("translate");break;case 69:A.setMode("rotate");break;case 82:A.setMode("scale");break;case 187:case 107:A.setSize(A.size+.1);break;case 189:case 109:A.setSize(Math.max(A.size-.1,.1));break;case 88:A.showX=!A.showX;break;case 89:A.showY=!A.showY;break;case 90:A.showZ=!A.showZ;break;case 32:A.enabled=!A.enabled;break}}),this.windowKeyUpListener||(this.windowKeyUpListener=g=>{switch(g.keyCode){case 16:A.setTranslationSnap(null),A.setRotationSnap(null),A.setScaleSnap(null);break}}),window.addEventListener("keydown",this.windowKeyDownListener),window.addEventListener("keyup",this.windowKeyUpListener))}}LX([m()],fp.prototype,"isGizmo",2);function vX(I){const A=I.domElement.querySelector("link[rel='ar']");if(A)return A;const g=document.createElement("div");g.classList.add("menu"),g.classList.add("quicklook-menu"),g.style.display="none",g.style.visibility="hidden";const e=document.createElement("button");e.id="open-in-ar",e.innerText="Open in QuickLook",g.appendChild(e);const i=document.createElement("a");i.id="needle-usdz-link",i.style.display="none",i.rel="ar",i.href="",g.appendChild(i);const t=document.createElement("img");return t.id="button",i.appendChild(t),I.domElement.appendChild(g),i}function xX(){var I=new Date;const A=I.getMonth()+1,g=I.getDate(),e=I.getHours(),i=I.getMinutes(),t=I.getSeconds(),C=(A<10?"0":"")+A,o=(g<10?"0":"")+g,s=(e<10?"0":"")+e,B=(i<10?"0":"")+i,a=(t<10?"0":"")+t;return I.getFullYear()+C+o+"-"+s+B+a}const Mp=EA("debugusdz");function YX(I,A){const g=[],e=iA.getComponentsInChildren(I,xi);let i=!1;Mp&&console.log(e);for(const t of e){if(!t||!t.runtimeAnimatorController)continue;Mp&&console.log(t);const C=[];for(const o of t.runtimeAnimatorController.enumerateActions()){Mp&&console.log(o);const s=o.getClip();if(!i&&s.tracks.length>0){i=!0;const B=s.tracks[0],a=B.name.substring(0,B.name.lastIndexOf(".")),n=new Ni(a+".position",[0,.01],[0,0,0,0,0,0]),r=new Ni(a+".quaternion",[0,.01],[0,0,0,1,0,0,0,1]);C.push(new mt("rest",.01,[n,r]))}C.includes(s)||C.push(s)}g.push({root:t.gameObject,clips:C})}Mp&&console.log(g);for(const t of g)for(const C of t.clips)A.registerAnimation(t.root,C)}var HX=Object.defineProperty,TX=Object.getOwnPropertyDescriptor,Bb=(I,A,g,e)=>{for(var i=e>1?void 0:e?TX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&HX(A,g,i),i};const Rh=EA("debugusdz");class Fh extends qA{constructor(){super(...arguments),Q(this,"objectToExport"),Q(this,"autoExportAnimations",!1),Q(this,"extensions",[]),Q(this,"link"),Q(this,"webxr"),Q(this,"webARSessionRoot"),Q(this,"lastCallback"),Q(this,"_arButton")}start(){var A;Rh&&(window.addEventListener("keydown",g=>{switch(g.key){case"t":this.exportAsync();break}}),pa()&&setTimeout(()=>{this.exportAsync()},2e3)),(A=document.getElementById("open-in-ar"))==null||A.addEventListener("click",g=>{g.preventDefault(),this.exportAsync()}),this.objectToExport||(this.objectToExport=this.gameObject)}onEnable(){const A=oc(),g=Iu();(Rh||A&&g)&&(this.createQuicklookButton(),this.webARSessionRoot=iA.findObjectOfType(fs)??void 0,this.lastCallback=this.quicklookCallback.bind(this),this.link=vX(this.context),this.link.addEventListener("message",this.lastCallback))}onDisable(){var A;(A=this.link)==null||A.removeEventListener("message",this.lastCallback)}async exportAsync(){if(!this.objectToExport)return;if(this.webARSessionRoot){const r=this.webARSessionRoot.gameObject,E=1/this.webARSessionRoot.arScale;r.matrix.makeScale(E,E,E),this.webARSessionRoot.invertForward&&r.matrix.multiply(new PA().makeRotationY(Math.PI))}const A=new Nj,g=[...this.extensions],e=new VD;g.push(e),this.autoExportAnimations&&YX(this.objectToExport,e);const i={self:this,exporter:A,extensions:g,object:this.objectToExport};this.dispatchEvent(new CustomEvent("before-export",{detail:i}));let t="needle";Rh&&(t+="-"+xX()),A.debug=Rh;const C=await A.parse(this.objectToExport,g),o=new Blob([C],{type:"application/octet-stream"});this.dispatchEvent(new CustomEvent("after-export",{detail:i}));const s=this.buildQuicklookOverlay(),B=s.callToAction?encodeURIComponent(s.callToAction):"",a=s.checkoutTitle?encodeURIComponent(s.checkoutTitle):"",n=s.checkoutSubtitle?encodeURIComponent(s.checkoutSubtitle):"";this.link.href=URL.createObjectURL(o)+`#callToAction=${B}&checkoutTitle=${a}&checkoutSubtitle=${n}&`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=t+".usdz",this.link.click()}quicklookCallback(A){A?.data=="_apple_ar_quicklook_button_tapped"&&(Rh&&Ut("Quicklook closed via call to action button"),this.dispatchEvent(new CustomEvent("quicklook-button-tapped",{detail:this})))}buildQuicklookOverlay(){const A={};return A.callToAction="Close",A.checkoutTitle="\u{1F335} Made with Needle",A.checkoutSubtitle="_",this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:A})),A}async createQuicklookButton(){var A,g;if(!this.webxr)if(await tc(1),this.webxr=iA.findObjectOfType(Ug)??void 0,this.webxr)if(this.webxr.VRButton&&((A=this.webxr.VRButton.parentElement)==null||A.removeChild(this.webxr.VRButton)),this.webxr.ARButton&&this._arButton!==this.webxr.ARButton){this._arButton=this.webxr.ARButton;const e=(g=this.webxr.ARButton.parentElement)==null?void 0:g.querySelector("a");e&&(e.href=""),this.webxr.ARButton.innerText="Open in Quicklook",this.webxr.ARButton.disabled=!1,this.webxr.ARButton.addEventListener("click",i=>{i.preventDefault(),this.exportAsync()}),this.webxr.ARButton.classList.add("quicklook-ar-button"),this.dispatchEvent(new CustomEvent("created-button",{detail:this.webxr.ARButton}))}else{this.webxr.createARButton=!1,this.webxr.createVRButton=!1;let e=window.document.querySelector(".webxr-buttons");e||(e=document.createElement("div"),e.classList.add("webxr-buttons"));const i=document.createElement("button");i.innerText="Open in Quicklook",i.addEventListener("click",()=>{this.exportAsync()}),i.classList.add("webxr-ar-button"),i.classList.add("webxr-button"),i.classList.add("quicklook-ar-button"),e.appendChild(i),this.dispatchEvent(new CustomEvent("created-button",{detail:i}))}else console.warn("Could not find WebXR component: will not create Quicklook button",Dg.Current)}resetStyles(A){A.style.position="",A.style.top="",A.style.left="",A.style.width="",A.style.height="",A.style.margin="",A.style.padding="",A.style.border="",A.style.background="",A.style.color="",A.style.font="",A.style.textAlign="",A.style.opacity="",A.style.zIndex=""}}Bb([m(NA)],Fh.prototype,"objectToExport",2),Bb([m()],Fh.prototype,"autoExportAnimations",2);var OX=Object.defineProperty,_X=Object.getOwnPropertyDescriptor,mG=(I,A,g,e)=>{for(var i=e>1?void 0:e?_X(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&OX(A,g,i),i};class ra extends pi{constructor(){super(...arguments),Q(this,"color"),Q(this,"intensity"),Q(this,"center")}get typeName(){return"Vignette"}init(){this.color.defaultValue={r:0,g:0,b:0,a:1},this.intensity.defaultValue=0,this.center.defaultValue={x:.5,y:.5}}onCreateEffect(){const A=new DF;return this.intensity.onValueChanged=g=>{A.offset=g,this.updateDarkness(A)},this.color.onValueChanged=g=>{this.updateDarkness(A)},A}updateDarkness(A){const g=this.intensity.value;A.darkness=g}}mG([m(mg)],ra.prototype,"color",2),mG([m(mg)],ra.prototype,"intensity",2),mG([m(mg)],ra.prototype,"center",2),hC("Vignette",ra);var PX=Object.defineProperty,jX=Object.getOwnPropertyDescriptor,WX=(I,A,g,e)=>{for(var i=e>1?void 0:e?jX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&PX(A,g,i),i};const UG=EA("debugpost");class mp extends qA{constructor(){super(...arguments),Q(this,"sharedProfile"),Q(this,"_postprocessing"),Q(this,"_effects",[]),Q(this,"_lastApplyTime"),Q(this,"_rapidApplyCount",0),Q(this,"_modificationQueue"),Q(this,"_recreateId",-1)}awake(){var A;(A=this.sharedProfile)==null||A.init(),UG&&(console.log(this),console.log("Press P to toggle post processing"),window.addEventListener("keydown",g=>{g.key==="p"&&(console.log("Toggle volume: "+this.name,!this.enabled),this.enabled=!this.enabled)}))}onDisable(){var A;(A=this._postprocessing)==null||A.unapply()}onBeforeRender(){if(!this.context.isInXR){if(this.context.composer&&!(this.context.composer instanceof GS))return;this.context.mainCamera&&(!this._postprocessing||!this._postprocessing.isActive)&&this.apply(),this.context.composer&&(this.context.composer.setRenderer(this.context.renderer),this.context.composer.setMainScene(this.context.scene),this.context.mainCamera&&this.context.composer.setMainCamera(this.context.mainCamera))}}onDestroy(){var A;(A=this._postprocessing)==null||A.dispose()}apply(){var A,g;UG&&console.log("Apply PostProcessing",this,(A=this.context.mainCamera)==null?void 0:A.name),CQ()&&(this._lastApplyTime!==void 0&&Date.now()-this._lastApplyTime<100&&(this._rapidApplyCount++,this._rapidApplyCount===5&&console.warn("Detected rapid post processing modifications - this might be a bug",this)),this._lastApplyTime=Date.now()),this.unapply(),this._effects.length=0,(g=this.sharedProfile)!=null&&g.components&&this._effects.push(...this.sharedProfile.components);const e=this.gameObject.getComponentsInChildren(pi);if(UG&&e!=null&&e.length&&console.log("Additional",e),e)for(const i of e)i.active&&this._effects.push(i);this._effects.length>0&&(this._postprocessing||(this._postprocessing=new rp(this.context)),this._postprocessing.apply(this._effects),this._applyPostQueue())}unapply(){var A;(A=this._postprocessing)==null||A.unapply()}_applyPostQueue(){if(this._modificationQueue){for(const A of this._modificationQueue.values())this.onEditorModification(A);this._modificationQueue.clear()}}onEditorModification(A){var g,e;if(A.propertyName.startsWith("postprocessing.")){if(!this._postprocessing)return this._modificationQueue||(this._modificationQueue=new Map),this._modificationQueue.set(A.propertyName,A),!0;if(!((g=this._effects)!=null&&g.length))return;const i=A.propertyName.split(".");if(i.length===3||i.length===4){const t=i[1],C=i[2];for(const o of this._effects)if(((e=o.typeName)==null?void 0:e.toLowerCase())===t.toLowerCase()){if(C==="active"){o.active=A.value,this.scheduleRecreate();return}if(!Up.has(t)){const s=new Array;Up.set(t,s);const B=Object.keys(o);for(const a of B)o[a]instanceof mg&&s.push(a)}if(Up.has(t)){const s=C.toLowerCase(),B=Up.get(t);for(const a of B)if(a.toLowerCase()===s){const n=o[a];n instanceof mg&&(i.length===4&&i[3]==="active"?(n.overrideState=A.value,this.scheduleRecreate()):n&&n.value!==void 0&&(n.value=A.value));return}}console.warn("Unknown modification",C);return}}return!0}return!1}scheduleRecreate(){const A=++this._recreateId;setTimeout(()=>{A===this._recreateId&&(this.onDisable(),this.onEnable())},200)}}WX([pQ(HE)],mp.prototype,"sharedProfile",2);const Up=new Map;var ZX=Object.defineProperty,VX=Object.getOwnPropertyDescriptor,zX=(I,A,g,e)=>{for(var i=e>1?void 0:e?VX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&ZX(A,g,i),i};class Rp extends qA{constructor(){super(...arguments),Q(this,"backgroundTint",new QI(1,1,1,1)),Q(this,"_preRender"),Q(this,"backgroundPlane"),Q(this,"threeTexture"),Q(this,"forceTextureInitialization",function(){const A=new sI,g=new Je,e=new et;e.add(new fA(g,A));const i=new Ya;return function(t,C){A.map=C,t.render(e,i)}}())}awake(){Ug.OptionalFeatures_AR.push("camera-access")}get background(){return this.backgroundPlane}onEnable(){this._preRender=this.preRender.bind(this),this.context.pre_render_callbacks.push(this._preRender),this.backgroundPlane&&(this.gameObject.add(this.backgroundPlane),this.backgroundPlane.visible=!1)}onDisable(){this.context.pre_render_callbacks=this.context.pre_render_callbacks.filter(A=>A!==this._preRender),this.backgroundPlane&&this.gameObject.remove(this.backgroundPlane)}preRender(){if(!this||!this.gameObject)return;const A=this.context.renderer.xr.getFrame();A&&(!this.threeTexture&&this.context.renderer&&(this.threeTexture=new Ng,this.forceTextureInitialization(this.context.renderer,this.threeTexture)),this.backgroundPlane===void 0&&(this.backgroundPlane=$X(this.backgroundTint),this.gameObject.add(this.backgroundPlane)),this.updateFromFrame(A))}onBeforeRender(A){this.updateFromFrame(A)}updateFromFrame(A){if(!A)return;const g=A.getViewerPose(this.context.renderer.xr.getReferenceSpace());if(g){for(const e of g.views)if("camera"in e&&e.camera){let i=this.context.renderer.xr.getBinding();if(i||(i=new XRWebGLBinding(A.session,this.context.renderer.getContext())),i){let t=null;if("getCameraImage"in i){t=i.getCameraImage(e.camera);const C=this.context.renderer.properties.get(this.threeTexture);C.__webglTexture=t,this.backgroundPlane&&(this.backgroundPlane.setTexture(this.threeTexture),this.backgroundPlane.visible=!0)}}}}}}zX([m()],Rp.prototype,"backgroundTint",2);let XX=`
4801
+ `)}}}applyShadowMaterial(){var A;const g=iA.getComponent(this.gameObject,Be);if(g)if(((A=g.sharedMaterial)==null?void 0:A.type)!=="ShadowMaterial"){const e=new Pw;e.color=this.shadowColor,e.opacity=this.shadowColor.alpha,this.applyMaterialOptions(e),g.sharedMaterial=e}else{const e=g.sharedMaterial;e.color=this.shadowColor,e.opacity=this.shadowColor.alpha,this.applyMaterialOptions(e)}}applyMaterialOptions(A){A&&(A.depthWrite=!1,A.stencilWrite=!1)}}Vq([m()],ph.prototype,"mode",2),Vq([m(QI)],ph.prototype,"shadowColor",2);var W5=Object.defineProperty,Z5=Object.getOwnPropertyDescriptor,cp=(I,A,g,e)=>{for(var i=e>1?void 0:e?Z5(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&W5(A,g,i),i},EG;const zq=(EG=class extends qA{constructor(){super(...arguments),Q(this,"target",null),Q(this,"followFactor",.1),Q(this,"rotateFactor",.1),Q(this,"positionAxes",Yr.All),Q(this,"flipForward",!1),Q(this,"_firstUpdate",!0)}onBeforeRender(){this.updateNow(!1)}updateNow(I){if(!(!this.target||this.target===this.gameObject)){if(this.followFactor>0){const A=wg(this.target),g=this._firstUpdate||I?1:$A.clamp01(this.context.time.deltaTime*this.followFactor),e=this.worldPosition;this.positionAxes&Yr.X&&(e.x=$A.lerp(e.x,A.x,g)),this.positionAxes&Yr.Y&&(e.y=$A.lerp(e.y,A.y,g)),this.positionAxes&Yr.Z&&(e.z=$A.lerp(e.z,A.z,g)),this.worldPosition=e}if(this.rotateFactor>0){const A=Ji(this.target);this.flipForward&&A.premultiply(zq._invertForward);const g=this._firstUpdate||I?1:$A.clamp01(this.context.time.deltaTime*this.rotateFactor);this.worldQuaternion=this.worldQuaternion.slerp(A,g)}this._firstUpdate=!1}}},Q(EG,"_invertForward",new RA().setFromAxisAngle(new M(0,1,0),Math.PI)),EG);let Ts=zq;cp([m(NA)],Ts.prototype,"target",2),cp([m()],Ts.prototype,"followFactor",2),cp([m()],Ts.prototype,"rotateFactor",2),cp([m()],Ts.prototype,"positionAxes",2);class V5 extends fA{constructor(A){const g=new z5(A),e=new Je(g.image.width*.001,g.image.height*.001),i=new sI({map:g,toneMapped:!1,transparent:!0});super(e,i);function t(C){i.map.dispatchDOMEvent(C)}this.addEventListener("mousedown",t),this.addEventListener("mousemove",t),this.addEventListener("mouseup",t),this.addEventListener("click",t),this.dispose=function(){e.dispose(),i.dispose(),i.map.dispose(),hG.delete(A),this.removeEventListener("mousedown",t),this.removeEventListener("mousemove",t),this.removeEventListener("mouseup",t),this.removeEventListener("click",t)}}}class z5 extends Fw{constructor(A){super(Xq(A)),this.dom=A,this.anisotropy=16,this.encoding=VA,this.minFilter=qg,this.magFilter=qg;const g=new MutationObserver(()=>{this.scheduleUpdate||(this.scheduleUpdate=setTimeout(()=>this.update(),16))}),e={attributes:!0,childList:!0,subtree:!0,characterData:!0};g.observe(A,e),this.observer=g}dispatchDOMEvent(A){A.data&&X5(this.dom,A.type,A.data.x,A.data.y)}update(){this.image=Xq(this.dom),this.needsUpdate=!0,this.scheduleUpdate=null}dispose(){this.observer&&this.observer.disconnect(),this.scheduleUpdate=clearTimeout(this.scheduleUpdate),super.dispose()}}const hG=new WeakMap;function Xq(I){const A=document.createRange(),g=new yA;function e(r){const E=[];let h=!1;function c(){if(h&&(h=!1,r.restore()),E.length===0)return;let D=-1/0,d=-1/0,w=1/0,l=1/0;for(let p=0;p<E.length;p++){const u=E[p];D=Math.max(D,u.x),d=Math.max(d,u.y),w=Math.min(w,u.x+u.width),l=Math.min(l,u.y+u.height)}r.save(),r.beginPath(),r.rect(D,d,w-D,l-d),r.clip(),h=!0}return{add:function(D){E.push(D),c()},remove:function(){E.pop(),c()}}}function i(r,E,h,c){c!==""&&(r.textTransform==="uppercase"&&(c=c.toUpperCase()),a.font=r.fontWeight+" "+r.fontSize+" "+r.fontFamily,a.textBaseline="top",a.fillStyle=r.color,a.fillText(c,E,h+parseFloat(r.fontSize)*.1))}function t(r,E,h,c,D){h<2*D&&(D=h/2),c<2*D&&(D=c/2),a.beginPath(),a.moveTo(r+D,E),a.arcTo(r+h,E,r+h,E+c,D),a.arcTo(r+h,E+c,r,E+c,D),a.arcTo(r,E+c,r,E,D),a.arcTo(r,E,r+h,E,D),a.closePath()}function C(r,E,h,c,D,d){const w=r[E+"Width"],l=r[E+"Style"],p=r[E+"Color"];w!=="0px"&&l!=="none"&&p!=="transparent"&&p!=="rgba(0, 0, 0, 0)"&&(a.strokeStyle=p,a.lineWidth=parseFloat(w),a.beginPath(),a.moveTo(h,c),a.lineTo(h+D,c+d),a.stroke())}function o(r,E){let h=0,c=0,D=0,d=0;if(r.nodeType===Node.TEXT_NODE){A.selectNode(r);const l=A.getBoundingClientRect();h=l.left-s.left-.5,c=l.top-s.top-.5,D=l.width,d=l.height,i(E,h,c,r.nodeValue.trim())}else{if(r.nodeType===Node.COMMENT_NODE)return;if(r instanceof HTMLCanvasElement){if(r.style.display==="none")return;a.save();const l=window.devicePixelRatio;a.scale(1/l,1/l),a.drawImage(r,0,0),a.restore()}else{if(r.style.display==="none")return;const l=r.getBoundingClientRect();h=l.left-s.left-.5,c=l.top-s.top-.5,D=l.width,d=l.height,E=window.getComputedStyle(r),t(h,c,D,d,parseFloat(E.borderRadius));const p=E.backgroundColor;p!=="transparent"&&p!=="rgba(0, 0, 0, 0)"&&(a.fillStyle=p,a.fill());const u=["borderTop","borderLeft","borderBottom","borderRight"];let y=!0,k=null;for(const S of u){if(k!==null&&(y=E[S+"Width"]===E[k+"Width"]&&E[S+"Color"]===E[k+"Color"]&&E[S+"Style"]===E[k+"Style"]),y===!1)break;k=S}if(y===!0){const S=parseFloat(E.borderTopWidth);E.borderTopWidth!=="0px"&&E.borderTopStyle!=="none"&&E.borderTopColor!=="transparent"&&E.borderTopColor!=="rgba(0, 0, 0, 0)"&&(a.strokeStyle=E.borderTopColor,a.lineWidth=S,a.stroke())}else C(E,"borderTop",h,c,D,0),C(E,"borderLeft",h,c,0,d),C(E,"borderBottom",h,c+d,D,0),C(E,"borderRight",h+D,c,0,d);if(r instanceof HTMLInputElement){let S=E.accentColor;(S===void 0||S==="auto")&&(S=E.color),g.set(S);const G=Math.sqrt(.299*g.r**2+.587*g.g**2+.114*g.b**2)<.5?"white":"#111111";if(r.type==="radio"&&(t(h,c,D,d,d),a.fillStyle="white",a.strokeStyle=S,a.lineWidth=1,a.fill(),a.stroke(),r.checked&&(t(h+2,c+2,D-4,d-4,d),a.fillStyle=S,a.strokeStyle=G,a.lineWidth=2,a.fill(),a.stroke())),r.type==="checkbox"&&(t(h,c,D,d,2),a.fillStyle=r.checked?S:"white",a.strokeStyle=r.checked?G:S,a.lineWidth=1,a.stroke(),a.fill(),r.checked)){const f=a.textAlign;a.textAlign="center";const K={color:G,fontFamily:E.fontFamily,fontSize:d+"px",fontWeight:"bold"};i(K,h+D/2,c,"\u2714"),a.textAlign=f}if(r.type==="range"){const[f,K,q]=["min","max","value"].map(J=>parseFloat(r[J])),F=(q-f)/(K-f)*(D-d);t(h,c+d/4,D,d/2,d/4),a.fillStyle=G,a.strokeStyle=S,a.lineWidth=1,a.fill(),a.stroke(),t(h,c+d/4,F+d/2,d/2,d/4),a.fillStyle=S,a.fill(),t(h+F,c,d,d,d/2),a.fillStyle=S,a.fill()}(r.type==="color"||r.type==="text"||r.type==="number")&&(n.add({x:h,y:c,width:D,height:d}),i(E,h+parseInt(E.paddingLeft),c+parseInt(E.paddingTop),r.value),n.remove())}}}const w=E.overflow==="auto"||E.overflow==="hidden";w&&n.add({x:h,y:c,width:D,height:d});for(let l=0;l<r.childNodes.length;l++)o(r.childNodes[l],E);w&&n.remove()}const s=I.getBoundingClientRect();let B=hG.get(I);B===void 0&&(B=document.createElement("canvas"),B.width=s.width,B.height=s.height,hG.set(I,B));const a=B.getContext("2d"),n=new e(a);return o(I),B}function X5(I,A,g,e){const i={clientX:g*I.offsetWidth+I.offsetLeft,clientY:e*I.offsetHeight+I.offsetTop,view:I.ownerDocument.defaultView};window.dispatchEvent(new MouseEvent(A,i));const t=I.getBoundingClientRect();g=g*t.width+t.left,e=e*t.height+t.top;function C(o){if(o.nodeType!==Node.TEXT_NODE&&o.nodeType!==Node.COMMENT_NODE){const s=o.getBoundingClientRect();if(g>s.left&&g<s.right&&e>s.top&&e<s.bottom&&(o.dispatchEvent(new MouseEvent(A,i)),o instanceof HTMLInputElement&&o.type==="range"&&(A==="mousedown"||A==="click"))){const[B,a]=["min","max"].map(E=>parseFloat(o[E])),n=s.width,r=(g-s.x)/n;o.value=B+(a-B)*r,o.dispatchEvent(new InputEvent("input",{bubbles:!0}))}for(let B=0;B<o.childNodes.length;B++)C(o.childNodes[B])}}C(I)}const lp=new gA,dn={type:"",data:lp};class $5 extends Gt{constructor(A,g){super();const e=this,i=new iQ,t=new PA,C=A.domElement;function o(r){r.stopPropagation();const E=A.domElement.getBoundingClientRect();lp.x=(r.clientX-E.left)/E.width*2-1,lp.y=-(r.clientY-E.top)/E.height*2+1,i.setFromCamera(lp,g);const h=i.intersectObjects(e.children,!1);if(h.length>0){const c=h[0],D=c.object,d=c.uv;dn.type=r.type,dn.data.set(d.x,1-d.y),D.dispatchEvent(dn)}}C.addEventListener("pointerdown",o),C.addEventListener("pointerup",o),C.addEventListener("pointermove",o),C.addEventListener("mousedown",o),C.addEventListener("mouseup",o),C.addEventListener("mousemove",o),C.addEventListener("click",o);const s={move:"mousemove",select:"click",selectstart:"mousedown",selectend:"mouseup"};function B(r){const E=r.target;t.identity().extractRotation(E.matrixWorld),i.ray.origin.setFromMatrixPosition(E.matrixWorld),i.ray.direction.set(0,0,-1).applyMatrix4(t);const h=i.intersectObjects(e.children,!1);if(h.length>0){const c=h[0],D=c.object,d=c.uv;dn.type=s[r.type],dn.data.set(d.x,1-d.y),D.dispatchEvent(dn)}}const a=A.xr.getController(0);a.addEventListener("move",B),a.addEventListener("select",B),a.addEventListener("selectstart",B),a.addEventListener("selectend",B);const n=A.xr.getController(1);n.addEventListener("move",B),n.addEventListener("select",B),n.addEventListener("selectstart",B),n.addEventListener("selectend",B)}}class cG extends qA{constructor(){super(...arguments),Q(this,"id",null),Q(this,"keepAspect",!1)}start(){if(!this.id||!this.context.mainCamera)return;const A=document.getElementById(this.id);if(!A){console.warn('Could not find element with id "'+this.id+'"');return}A.style.display="block",A.style.visibility="hidden";const g=new $5(this.context.renderer,this.context.mainCamera);this.gameObject.add(g);const e=new V5(A);g.add(e),e.visible=!1,console.log(e);const i=e.material;i.transparent=!0,setTimeout(()=>{e.visible=!0;const t=kU(this.gameObject).clone();GU(this.gameObject,0,0,0),this.gameObject.updateMatrixWorld();const C=new ve;C.setFromObject(g),this.setWorldRotation(t.x,t.y,t.z);const o=C.max.x-C.min.x,s=C.max.y-C.min.y;if(this.keepAspect){const a=o/s;o>s?e.scale.set(1/o,1/s/a,1):e.scale.set(1/o*a,1/s,1)}else e.scale.set(1/o,1/s,1);const B=this.gameObject.scale;e.scale.multiply(B)},1)}}var AX=Object.defineProperty,gX=Object.getOwnPropertyDescriptor,uh=(I,A,g,e)=>{for(var i=e>1?void 0:e?gX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&AX(A,g,i),i};const wh=EA("debugspatialtrigger"),$q=new At,Ab=new At;function IX(I,A){return $q.mask=I,Ab.mask=A,$q.test(Ab)}class yC extends qA{constructor(){super(...arguments),Q(this,"triggerMask",0),Q(this,"onEnter"),Q(this,"onStay"),Q(this,"onExit"),Q(this,"currentIntersected",[]),Q(this,"lastIntersected",[])}start(){wh&&console.log(this.name,this.triggerMask,this)}update(){this.currentIntersected.length=0;for(const A of yh.triggers)IX(A.triggerMask,this.triggerMask)&&A.test(this.gameObject)&&this.currentIntersected.push(A);for(let A=this.lastIntersected.length-1;A>=0;A--){const g=this.lastIntersected[A];this.currentIntersected.indexOf(g)<0&&(this.onExitTrigger(g),this.lastIntersected.splice(A,1))}for(const A of this.currentIntersected)this.lastIntersected.indexOf(A)<0&&this.onEnterTrigger(A),this.onStayTrigger(A);this.lastIntersected.length=0,this.lastIntersected.push(...this.currentIntersected)}onEnterTrigger(A){var g;wh&&console.log("ENTER TRIGGER",this.name,A.name,this,A),A.raiseOnEnterEvent(this),(g=this.onEnter)==null||g.invoke(this,A)}onExitTrigger(A){var g;wh&&console.log("EXIT TRIGGER",this.name,A.name,this,A),A.raiseOnExitEvent(this),(g=this.onExit)==null||g.invoke(this,A)}onStayTrigger(A){var g;A.raiseOnStayEvent(this),(g=this.onStay)==null||g.invoke(this,A)}}uh([m()],yC.prototype,"triggerMask",2),uh([m(di)],yC.prototype,"onEnter",2),uh([m(di)],yC.prototype,"onStay",2),uh([m(di)],yC.prototype,"onExit",2);var lG;const Dp=(lG=class extends qA{constructor(){super(...arguments),Q(this,"triggerMask"),Q(this,"boxHelper")}start(){wh&&console.log(this.name,this.triggerMask,this)}onEnable(){var I;Dp.triggers.push(this),this.boxHelper||(this.boxHelper=iA.addNewComponent(this.gameObject,lC),(I=this.boxHelper)==null||I.showHelper(null,wh))}onDisable(){Dp.triggers.splice(Dp.triggers.indexOf(this),1)}test(I){return this.boxHelper?this.boxHelper.isInBox(I)??!1:!1}raiseOnEnterEvent(I){iA.foreachComponent(this.gameObject,A=>{A!==I&&A instanceof yC&&A.onEnterTrigger(this)},!1)}raiseOnStayEvent(I){iA.foreachComponent(this.gameObject,A=>{A!==I&&A instanceof yC&&A.onStayTrigger(this)},!1)}raiseOnExitEvent(I){iA.foreachComponent(this.gameObject,A=>{A!==I&&A instanceof yC&&A.onExitTrigger(this)},!1)}},Q(lG,"triggers",[]),lG);let yh=Dp;uh([m()],yh.prototype,"triggerMask",2);var eX=Object.defineProperty,iX=Object.getOwnPropertyDescriptor,tX=(I,A,g,e)=>{for(var i=e>1?void 0:e?iX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&eX(A,g,i),i};const Wi=EA("debugspectator");class dp extends qA{constructor(){super(...arguments),Q(this,"cam",null),Q(this,"useKeys",!0),Q(this,"_mode",0),Q(this,"orbit",null),Q(this,"_handler"),Q(this,"eventSub_WebXRRequestStartEvent",null),Q(this,"eventSub_WebXRStartEvent",null),Q(this,"eventSub_WebXREndEvent",null),Q(this,"_debug"),Q(this,"_networking")}get mode(){return this._mode}set mode(A){this._mode=A}get isSpectating(){var A;return((A=this._handler)==null?void 0:A.currentTarget)!==void 0}isSpectatingUser(A){var g;return((g=this.target)==null?void 0:g.userId)===A}isFollowedBy(A){var g;return(g=this.followers)==null?void 0:g.includes(A)}get followers(){return this._networking.followers}stopSpectating(){if(this.context.isInXR){this.followSelf();return}this.target=void 0}get localId(){return this.context.connection.connectionId??"local"}set target(A){var g;if(this._handler){const e=(g=this._handler.currentTarget)==null?void 0:g.userId,i=this.context.players.getPlayerView(this.localId);A===void 0||this.context.isInXR===!1&&i?.currentObject===A.currentObject?this._handler.currentTarget!==void 0&&(this._handler.disable(),iA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),this._networking.onSpectatedObjectChanged(A,e)):this._handler.currentTarget!==A&&(this._handler.set(A),iA.setActive(this.gameObject,!0),this.orbit&&(this.orbit.enabled=!1),this._networking.onSpectatedObjectChanged(A,e))}}get target(){var A;return(A=this._handler)==null?void 0:A.currentTarget}requestAllFollowMe(){this._networking.onRequestFollowMe()}get isSpectatingSelf(){var A,g;return this.isSpectating&&((A=this.target)==null?void 0:A.currentObject)===((g=this.context.players.getPlayerView(this.localId))==null?void 0:g.currentObject)}awake(){if(this._debug=new sX(this.context,this),this._networking=new QX(this.context,this),this._networking.awake(),iA.setActive(this.gameObject,!1),this.cam=iA.getComponent(this.gameObject,SI),!this.cam){console.error("Spectator camera needs camera component",this);return}!this._handler&&this.cam&&(this._handler=new CX(this.context,this.cam,this)),this.eventSub_WebXRRequestStartEvent=this.onXRSessionRequestStart.bind(this),this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Ug.addEventListener(me.RequestVRSession,this.eventSub_WebXRRequestStartEvent),Ug.addEventListener(me.XRStarted,this.eventSub_WebXRStartEvent),Ug.addEventListener(me.XRStopped,this.eventSub_WebXREndEvent),this.orbit=iA.getComponent(this.context.mainCamera,Ks)}onDestroy(){var A;this.stopSpectating(),Ug.removeEventListener(me.RequestVRSession,this.eventSub_WebXRStartEvent),Ug.removeEventListener(me.XRStarted,this.eventSub_WebXRStartEvent),Ug.removeEventListener(me.XRStopped,this.eventSub_WebXREndEvent),(A=this._handler)==null||A.destroy(),this._networking.destroy()}isSupportedPlatform(){const A=window.navigator.userAgent,g=/Windows|MacOS/.test(A),e=/Windows NT/.test(A)&&/Edg/.test(A)&&!/Win64/.test(A);return g&&!e}onXRSessionRequestStart(A){this.isSupportedPlatform()&&iA.setActive(this.gameObject,!0)}onXRSessionStart(A){this.isSupportedPlatform()&&(Wi&&console.log(this.context.mainCamera),this.context.mainCamera&&this.followSelf())}onXRSessionEnded(A){var g,e;this.context.removeCamera(this.cam),iA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),(g=this._handler)==null||g.set(void 0),(e=this._handler)==null||e.disable(),this.isSpectatingSelf&&this.stopSpectating()}followSelf(){this.target=this.context.players.getPlayerView(this.context.connection.connectionId),this.target||(this.context.players.setPlayerView(this.localId,this.context.mainCamera,Co.Headset),this.target=this.context.players.getPlayerView(this.localId)),Wi&&console.log("Follow self",this.target)}onAfterRender(){var A,g,e;if(!this.cam)return;const i=this.context.renderer,t=i.xr.enabled;if(!i.xr.isPresenting&&!((A=this._handler)!=null&&A.currentTarget))return;(g=this._handler)==null||g.update(this._mode);const C=i.getRenderTarget();let o=null;if(!C){if(!i.state.bindFramebuffer||!i.state.bindXRFramebuffer)return;o=i._framebuffer,i.state.bindXRFramebuffer(null)}this.setAvatarFlagsBeforeRender();const s=this.context.mainCameraComponent;if(s){const n=s.backgroundColor;n&&i.setClearColor(n,n.alpha),this.cam.backgroundColor=n,this.cam.clearFlags=s.clearFlags,this.cam.nearClipPlane=s.nearClipPlane,this.cam.farClipPlane=s.farClipPlane}else i.setClearColor(new yA(1,1,1));i.setRenderTarget(null),i.xr.enabled=!1;const B=(e=this.cam)==null?void 0:e.cam;this.context.updateAspect(B);const a=i.xr.isPresenting;i.xr.isPresenting=!1,i.setSize(this.context.domWidth,this.context.domHeight),i.render(this.context.scene,B),i.xr.isPresenting=a,i.xr.enabled=t,C?i.setRenderTarget(C):i.state.bindXRFramebuffer(o),this.resetAvatarFlags()}setAvatarFlagsBeforeRender(){const A=this._mode===0;for(const g of Oe.instances)if(g.avatar&&"isLocalAvatar"in g.avatar){let e=oe.All;this.isSpectatingSelf&&(e=A&&g.avatar.isLocalAvatar?oe.FirstPerson:oe.ThirdPerson);const i=g.avatar.flags;if(!i)continue;for(const t of i)t.UpdateVisible(e)}}resetAvatarFlags(){var A;for(const g of Oe.instances)if(g.avatar&&"flags"in g.avatar){const e=g.avatar.flags;if(!e)continue;for(const i of e)(A=g.avatar)!=null&&A.isLocalAvatar?i.UpdateVisible(oe.FirstPerson):i.UpdateVisible(oe.ThirdPerson)}}}tX([m()],dp.prototype,"useKeys",2);class CX{constructor(A,g,e){Q(this,"context"),Q(this,"cam"),Q(this,"spectator"),Q(this,"follow"),Q(this,"target"),Q(this,"view"),Q(this,"currentObject"),this.context=A,this.cam=g,this.spectator=e}get currentTarget(){return this.view}set(A){const g=A?.currentObject;if(!g){this.spectator.stopSpectating();return}g!==this.currentObject&&(this.currentObject=g,this.view=A,this.follow||(this.follow=iA.addNewComponent(this.cam.gameObject,Ts)),this.target||(this.target=new NA),g.add(this.target),this.follow.enabled=!0,this.follow.target=this.target,Wi&&console.log("FOLLOW",g),this.context.isInXR?this.context.removeCamera(this.cam):this.context.setCurrentCamera(this.cam))}disable(){Wi&&console.log("STOP FOLLOW",this.currentObject),this.view=void 0,this.currentObject=void 0,this.context.removeCamera(this.cam),this.follow&&(this.follow.enabled=!1)}destroy(){var A;(A=this.target)==null||A.removeFromParent(),this.follow&&iA.destroy(this.follow)}update(A){var g,e,i,t,C,o;if(((g=this.currentTarget)==null?void 0:g.isConnected)===!1||((e=this.currentTarget)==null?void 0:e.removed)===!0){Wi&&console.log("Target disconnected or timeout",this.currentTarget),this.spectator.stopSpectating();return}this.currentTarget&&((i=this.currentTarget)==null?void 0:i.currentObject)!==this.currentObject&&(Wi&&console.log("Target changed",this.currentObject,"to",this.currentTarget.currentObject),this.set(this.currentTarget));const s=this.context.mainCamera;s&&(this.cam.cam.near!==s.near||this.cam.cam.far!==s.far)&&(this.cam.cam.near=s.near,this.cam.cam.far=s.far,this.cam.cam.updateProjectionMatrix());const B=(t=this.follow)==null?void 0:t.target;if(!(!B||!this.follow)){switch(A){case 0:((C=this.view)==null?void 0:C.viewDevice)!==Co.Browser?(this.follow.followFactor=5,this.follow.rotateFactor=5):(this.follow.followFactor=50,this.follow.rotateFactor=50),B.position.set(0,0,0);break;case 1:this.follow.followFactor=3,this.follow.rotateFactor=2,B.position.set(0,.5,1.5);break}this.follow.flipForward=!1,((o=this.view)==null?void 0:o.viewDevice)!==Co.Browser?B.quaternion.copy(oX):B.quaternion.identity()}}}const oX=new RA().setFromAxisAngle(new M(0,1,0),Math.PI);class sX{constructor(A,g){Q(this,"context"),Q(this,"spectator"),this.context=A,this.spectator=g,console.log("Click other avatars or cameras to follow them. Press ESC to exit spectator mode."),this.context.domElement.addEventListener("keydown",i=>{!this.spectator.useKeys||i.key==="Escape"&&this.spectator.stopSpectating()});let e=0;this.context.input.addEventListener(XC.PointerDown,i=>{e=this.context.time.time}),this.context.input.addEventListener(XC.PointerUp,i=>{const t=this.context.time.time-e;t>1?this.spectator.stopSpectating():this.context.input.getPointerClicked(0)&&t<.3&&this.trySelectObject()})}trySelectObject(){const A=new gC;A.setMask(16777215);const g=this.context.physics.raycast(A);if(Wi&&console.log(...g),g!=null&&g.length)for(const e of g){if(e.distance<.2)continue;const i=e.object,t=iA.getComponentInParent(i,Oe),C=t?.connectionId;if(C){const o=this.context.players.getPlayerView(C);this.spectator.target=o,Wi&&console.log("spectate",C,t);break}}}}class BX{constructor(A,g,e){Q(this,"guid"),Q(this,"dontSave",!0),Q(this,"targetUserId"),Q(this,"stoppedFollowing"),this.guid=A,this.targetUserId=g,this.stoppedFollowing=e}}class aX{constructor(A,g){Q(this,"guid"),Q(this,"userId"),this.guid=A.guid,this.userId=g}}class QX{constructor(A,g){Q(this,"followers",[]),Q(this,"context"),Q(this,"spectator"),Q(this,"_followerEventMethod"),Q(this,"_requestFollowMethod"),Q(this,"_joinedRoomMethod"),Q(this,"_lastRequestFollowUser"),Q(this,"_enforceFollowInterval"),this.context=A,this.spectator=g,this._followerEventMethod=this.onFollowerEvent.bind(this),this._requestFollowMethod=this.onRequestFollowEvent.bind(this),this._joinedRoomMethod=this.onUserJoinedRoom.bind(this)}awake(){this.context.connection.beginListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.beginListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.beginListen(qI.JoinedRoom,this._joinedRoomMethod),this.context.domElement.addEventListener("keydown",A=>{this.spectator.useKeys&&(A.key==="f"?this.onRequestFollowMe():A.key==="Escape"&&this.onRequestFollowMe(!0))})}destroy(){this.context.connection.stopListen("spectator-follower-changed",this._followerEventMethod),this.context.connection.stopListen("spectator-request-follow",this._requestFollowMethod),this.context.connection.stopListen(qI.JoinedRoom,this._joinedRoomMethod)}onSpectatedObjectChanged(A,g){if(Wi&&console.log(this.context.connection.connectionId,"onSpectatedObjectChanged",A,g),this.context.connection.connectionId){const e=A?.userId===void 0,i=e?g:A?.userId,t=new BX(this.context.connection.connectionId,i,e);this.context.connection.send("spectator-follower-changed",t)}}onRequestFollowMe(A=!1){if(Wi&&console.log("Request follow",this.context.connection.connectionId),this.context.connection.connectionId){this.spectator.stopSpectating();const g=A?void 0:this.context.connection.connectionId,e=new aX(this.spectator,g);this.context.connection.send("spectator-request-follow",e)}}onUserJoinedRoom(){EA("followme")&&this.onRequestFollowMe()}onFollowerEvent(A){const g=A.targetUserId,e=A.guid;if(Wi&&console.log(A),g===this.context.connection.connectionId)if(A.stoppedFollowing){const i=this.followers.indexOf(e);i!==-1&&(this.followers.splice(i,1),this.removeDisconnectedFollowers(),console.log(e,"unfollows you",this.followers.length))}else this.followers.includes(e)||(this.followers.push(e),this.removeDisconnectedFollowers(),console.log(e,"follows you",this.followers.length))}removeDisconnectedFollowers(){for(let A=this.followers.length-1;A>=0;A--){const g=this.followers[A];this.context.connection.userIsInRoom(g)===!1&&this.followers.splice(A,1)}}onRequestFollowEvent(A){if(this._lastRequestFollowUser=A,A.userId===this.context.connection.connectionId)this.spectator.stopSpectating();else if(A.userId===void 0)this.spectator.stopSpectating();else{const g=this.context.players.getPlayerView(A.userId);if(g)this.spectator.target=g;else return Wi&&console.warn("Could not find view",A.userId),this.enforceFollow(),!1}return!0}enforceFollow(){this._enforceFollowInterval||(this._enforceFollowInterval=setInterval(()=>{this._lastRequestFollowUser===void 0||this._lastRequestFollowUser.userId&&this.spectator.isFollowedBy(this._lastRequestFollowUser.userId)?(clearInterval(this._enforceFollowInterval),this._enforceFollowInterval=void 0):(Wi&&console.log("REQUEST FOLLOW AGAIN",this._lastRequestFollowUser.userId),this.onRequestFollowEvent(this._lastRequestFollowUser))},1e3))}}var nX=Object.defineProperty,rX=Object.getOwnPropertyDescriptor,ct=(I,A,g,e)=>{for(var i=e>1?void 0:e?rX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&nX(A,g,i),i};const DG=EA("debugspriterenderer"),EX=EA("wireframe"),dG=class{static getOrCreateGeometry(I){if(I._geometry)return I._geometry;if(I.guid&&dG.cache[I.guid])return DG&&console.log("Take cached geometry for sprite",I.guid),dG.cache[I.guid];const A=new lg;I._geometry=A;const g=new Float32Array(I.triangles.length*3),e=new Float32Array(I.triangles.length*2);for(let i=0;i<I.triangles.length;i+=1){const t=I.triangles[i];g[i*3]=-I.vertices[t].x,g[i*3+1]=I.vertices[t].y,g[i*3+2]=0;const C=I.uv[t];e[i*2]=C.x,e[i*2+1]=1-C.y}return A.setAttribute("position",new ag(g,3)),A.setAttribute("uv",new ag(e,2)),I.guid&&(this.cache[I.guid]=A),DG&&console.log("Built sprite geometry",I,A),A}};let pG=dG;Q(pG,"cache",{});class Uo{constructor(){Q(this,"guid"),Q(this,"texture"),Q(this,"triangles"),Q(this,"uv"),Q(this,"vertices"),Q(this,"_geometry")}}ct([m()],Uo.prototype,"guid",2),ct([m(Ng)],Uo.prototype,"texture",2),ct([pQ()],Uo.prototype,"triangles",2),ct([pQ()],Uo.prototype,"uv",2),ct([pQ()],Uo.prototype,"vertices",2);const uG=Symbol("spriteOwner");class Sh{constructor(){Q(this,"sprites")}}ct([m(Uo)],Sh.prototype,"sprites",2);class pn{constructor(){Q(this,"spriteSheet"),Q(this,"index",0)}update(){if(!this.spriteSheet)return;const A=this.index;if(A<0||A>=this.spriteSheet.sprites.length)return;const g=this.spriteSheet.sprites[A];let e=g?.texture;e&&(e.encoding=VA,e.minFilter==Wg&&e.magFilter==Wg&&(e.anisotropy=1),e.needsUpdate=!0)}}ct([m(Sh)],pn.prototype,"spriteSheet",2),ct([m()],pn.prototype,"index",2);class aa extends qA{constructor(){super(...arguments),Q(this,"drawMode",0),Q(this,"size",{x:1,y:1}),Q(this,"color"),Q(this,"sharedMaterial"),Q(this,"_spriteSheet"),Q(this,"_currentSprite")}get sprite(){return this._spriteSheet}set sprite(A){if(A!==this._spriteSheet)if(typeof A=="number"){const g=Math.floor(A);g===A&&(this.spriteIndex=g);return}else this._spriteSheet=A,this.updateSprite()}set spriteIndex(A){this._spriteSheet&&(this._spriteSheet.index=A,this.updateSprite())}get spriteIndex(){var A;return((A=this._spriteSheet)==null?void 0:A.index)??0}get spriteFrames(){var A,g;return((g=(A=this._spriteSheet)==null?void 0:A.spriteSheet)==null?void 0:g.sprites.length)??0}awake(){this._currentSprite=void 0,DG&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(){var A,g,e;if(!this.__didAwake||!((g=(A=this.sprite)==null?void 0:A.spriteSheet)!=null&&g.sprites))return;const i=this.sprite.spriteSheet.sprites[this.spriteIndex];if(this._currentSprite)this._currentSprite.geometry=pG.getOrCreateGeometry(i),this._currentSprite.material.map=i.texture;else{const t=new sI({color:16777215,side:nI});if(!t)return;if(EX&&(t.wireframe=!0),this.color&&(t.color||(t.color=new yA),t.color.copy(this.color),t.opacity=this.color.alpha),t.transparent=!0,i.texture&&!t.wireframe){let C=i.texture;C[uG]!==void 0&&C[uG]!==this&&this.spriteFrames>1&&(C=i.texture=C.clone()),C[uG]=this,t.map=C}this.sharedMaterial=t,this._currentSprite=new fA(pG.getOrCreateGeometry(i),t)}this._currentSprite.parent!==this.gameObject&&(this.drawMode===2&&this._currentSprite.scale.set(this.size.x,this.size.y,1),this.gameObject&&this.gameObject.add(this._currentSprite)),this._currentSprite&&this._currentSprite.layers.set(this.layer),(e=this._spriteSheet)==null||e.update()}}ct([m()],aa.prototype,"drawMode",2),ct([m(QI)],aa.prototype,"color",2),ct([m(fg)],aa.prototype,"sharedMaterial",2),ct([m(pn)],aa.prototype,"sprite",1);class NC{constructor(){Q(this,"bb",null),Q(this,"bb_pos",0)}__init(A,g){return this.bb_pos=A,this.bb=g,this}static getRootAsSyncedCameraModel(A,g){return(g||new NC).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedCameraModel(A,g){return A.setPosition(A.position()+lD),(g||new NC).__init(A.readInt32(A.position())+A.position(),A)}userId(A){const g=this.bb.__offset(this.bb_pos,4);return g?this.bb.__string(this.bb_pos+g,A):null}guid(A){const g=this.bb.__offset(this.bb_pos,6);return g?this.bb.__string(this.bb_pos+g,A):null}dontSave(){const A=this.bb.__offset(this.bb_pos,8);return A?!!this.bb.readInt8(this.bb_pos+A):!1}pos(A){const g=this.bb.__offset(this.bb_pos,10);return g?(A||new Hi).__init(this.bb_pos+g,this.bb):null}rot(A){const g=this.bb.__offset(this.bb_pos,12);return g?(A||new Hi).__init(this.bb_pos+g,this.bb):null}static startSyncedCameraModel(A){A.startObject(5)}static addUserId(A,g){A.addFieldOffset(0,g,0)}static addGuid(A,g){A.addFieldOffset(1,g,0)}static addDontSave(A,g){A.addFieldInt8(2,+g,0)}static addPos(A,g){A.addFieldStruct(3,g,0)}static addRot(A,g){A.addFieldStruct(4,g,0)}static endSyncedCameraModel(A){return A.endObject()}static finishSyncedCameraModelBuffer(A,g){A.finish(g)}static finishSizePrefixedSyncedCameraModelBuffer(A,g){A.finish(g,void 0,!0)}}var hX=Object.defineProperty,cX=Object.getOwnPropertyDescriptor,lX=(I,A,g,e)=>{for(var i=e>1?void 0:e?cX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&hX(A,g,i),i};const pp="SCAM";DS(pp,NC.getRootAsSyncedCameraModel);const Zi=new Rn;class DX{constructor(A,g){Q(this,"userId"),Q(this,"guid"),this.guid=g,this.userId=A}send(A,g){if(A){Zi.clear();const e=Zi.createString(this.guid),i=Zi.createString(this.userId);NC.startSyncedCameraModel(Zi),NC.addGuid(Zi,e),NC.addUserId(Zi,i);const t=wg(A),C=kU(A);NC.addPos(Zi,Hi.createVec3(Zi,t.x,t.y,t.z)),NC.addRot(Zi,Hi.createVec3(Zi,C.x,C.y,C.z));const o=NC.endSyncedCameraModel(Zi);Zi.finish(o,pp),g.sendBinary(Zi.asUint8Array())}}}var wG;const yG=(wG=class extends qA{constructor(){super(...arguments),Q(this,"cameraPrefab",null),Q(this,"_lastWorldPosition"),Q(this,"_lastWorldQuaternion"),Q(this,"_model",null),Q(this,"_needsUpdate",!0),Q(this,"_lastUpdateTime",0),Q(this,"remoteCams",{}),Q(this,"userToCamMap",{}),Q(this,"_camTimeoutInSeconds",10),Q(this,"_receiveCallback",null)}getCameraObject(I){const A=this.userToCamMap[I];return A?this.remoteCams[A].obj:null}async awake(){this._lastWorldPosition=this.worldPosition.clone(),this._lastWorldQuaternion=this.worldQuaternion.clone(),this.cameraPrefab&&("uri"in this.cameraPrefab&&(this.cameraPrefab=await this.cameraPrefab.instantiate(this.gameObject)),this.cameraPrefab&&"isObject3D"in this.cameraPrefab&&(this.cameraPrefab.visible=!1))}onEnable(){this._receiveCallback=this.context.connection.beginListenBinary(pp,this.onReceivedRemoteCameraInfoBin.bind(this))}onDisable(){this.context.connection.stopListenBinary(pp,this._receiveCallback)}update(){for(const e in this.remoteCams){const i=this.remoteCams[e],t=this.context.time.realtimeSinceStartup-i.lastUpdate;if(!i||t>this._camTimeoutInSeconds){console.log("Remote cam timeout",i,t),i!=null&&i.obj&&iA.destroy(i.obj),delete this.remoteCams[e],i&&delete this.userToCamMap[i.userId],yG.instances.push(i),this.context.players.removePlayerView(i.userId,Co.Browser);continue}}if(Ug.IsInWebXR)return;const I=this.context.mainCamera;if(I===null){this.enabled=!1;return}if(!this.context.connection.isConnected||this.context.connection.connectionId===null)return;this._model===null&&(this._model=new DX(this.context.connection.connectionId,this.context.connection.connectionId+"_camera"));const A=wg(I),g=Ji(I);(A.distanceTo(this._lastWorldPosition)>.001||g.angleTo(this._lastWorldQuaternion)>.01)&&(this._needsUpdate=!0),this._lastWorldPosition.copy(A),this._lastWorldQuaternion.copy(g),!((!this._needsUpdate||this.context.time.frameCount%2!==0)&&!(this.context.time.realtimeSinceStartup-this._lastUpdateTime>this._camTimeoutInSeconds*.5))&&(this._lastUpdateTime=this.context.time.realtimeSinceStartup,this._needsUpdate=!1,this._model.send(I,this.context.connection),this.context.isInXR||this.context.players.setPlayerView(this.context.connection.connectionId,I,Co.Browser))}onReceivedRemoteCameraInfoBin(I){const A=I.guid();if(!A)return;const g=I.userId();if(!g||!this.context.connection.userIsInRoom(g)||!this.cameraPrefab)return;let e=this.remoteCams[A];if(!e)if("isObject3D"in this.cameraPrefab){const o=new Vt;o.context=this.context;const s=iA.instantiate(this.cameraPrefab,o);e=this.remoteCams[A]={obj:s,lastUpdate:this.context.time.realtimeSinceStartup,userId:g},e.obj.visible=!0,this.gameObject.add(s),this.userToCamMap[g]=A,yG.instances.push(e);const B=iA.getOrAddComponent(s,Oe);B.connectionId=g,B.avatar=s}else return;const i=e.obj;this.context.players.setPlayerView(g,i,Co.Browser),e.lastUpdate=this.context.time.realtimeSinceStartup,Si.markDirty(i);const t=I.pos();t&&ur(i,t.x(),t.y(),t.z());const C=I.rot();C&&GU(i,C.x(),C.y(),C.z())}},Q(wG,"instances",[]),wG);let up=yG;lX([m([NA,tC])],up.prototype,"cameraPrefab",2);var dX=Object.defineProperty,pX=Object.getOwnPropertyDescriptor,kh=(I,A,g,e)=>{for(var i=e>1?void 0:e?pX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&dX(A,g,i),i};const SG="view",wp=EA("debugsyncedroom");class Os extends qA{constructor(){super(...arguments),Q(this,"roomName"),Q(this,"urlParameterName","room"),Q(this,"joinRandomRoom",!0),Q(this,"requireRoomParameter",!1),Q(this,"autoRejoin",!0),Q(this,"_roomPrefix"),Q(this,"_lastPingTime",0),Q(this,"_lastRoomTime",-1)}get RoomPrefix(){return this._roomPrefix}awake(){wp&&console.log("Room",this.roomName,this.urlParameterName,this.joinRandomRoom,this.requireRoomParameter,this.autoRejoin),this._roomPrefix===void 0&&(this._roomPrefix=this.roomName,this.roomName="")}onEnable(){const A=EA(SG);if(A&&typeof A=="string"&&A.length>0){console.log("Join as viewer"),this.context.connection.joinRoom(A,!0);return}this.tryJoinRoom()}onDisable(){this.roomName&&this.roomName.length>0&&this.context.connection.leaveRoom(this.roomName)}tryJoinRoom(A=0){A===void 0&&(A=0);let g=!1;if(this.urlParameterName){const e=EA(this.urlParameterName);if(e&&typeof e=="string"){g=!0;const i=Nb(e);this.roomName=i}else if(this.joinRandomRoom&&(console.log("No room name found in url, generating random one"),this.setRandomRoomUrlParameter(),A<1))return this.tryJoinRoom(A+1)}else this.joinRandomRoom&&(this.roomName===null||this.roomName===void 0||this.roomName.length<=0)&&(console.log("generate room name"),this.roomName=this.generateRoomName());return this.requireRoomParameter&&!g?(wp&&console.log('No required room parameter "'+this.urlParameterName+'" in url - will not connect to networking backend.'),!1):!this.roomName||this.roomName.length<=0?(wp&&console.error('Missing room name on "'+this.name+'". Make sure this is correctly configured in Unity',this.context.connection.isDebugEnabled?this:""),!1):(this.context.connection.isConnected||this.context.connection.connect(),wp&&console.log("Join "+this.roomName),this._roomPrefix&&(this.roomName=this._roomPrefix+this.roomName),this.context.connection.joinRoom(this.roomName),!0)}update(){this.context.connection.isConnected&&(this.context.time.time-this._lastPingTime>3&&(this._lastPingTime=this.context.time.time,this.context.connection.sendPing()),this.context.connection.isInRoom&&(this._lastRoomTime=this.context.time.time)),this._lastRoomTime>0&&this.context.time.time-this._lastRoomTime>.3&&(this._lastRoomTime=-1,this.autoRejoin?(console.log("Disconnected from networking backend - attempt reconnecting now"),this.tryJoinRoom()):console.warn("You are not connected to a room anymore (possibly because the tab was inactive for too long and the server kicked you)"))}get currentRoomName(){return EA(SG)||EA(this.urlParameterName)}setRandomRoomUrlParameter(){const A=ic(),g=this.generateRoomName();EA(this.urlParameterName)?A.set(this.urlParameterName,g):A.append(this.urlParameterName,g),XG(g,A)}generateRoomName(){return Fb()+"_"+Rb(100,999)}getViewOnlyUrl(){if(this.context.connection.isConnected&&this.context.connection.currentRoomViewId){const A=window.location.search,g=new URLSearchParams(A);return g.has(this.urlParameterName)&&g.delete(this.urlParameterName),g.set(SG,this.context.connection.currentRoomViewId),window.location.origin+window.location.pathname+"?"+g.toString()}return null}}kh([m()],Os.prototype,"roomName",2),kh([m()],Os.prototype,"urlParameterName",2),kh([m()],Os.prototype,"joinRandomRoom",2),kh([m()],Os.prototype,"requireRoomParameter",2),kh([m()],Os.prototype,"autoRejoin",2);function uX(){const I=EA("testwindowcount")||0;I&&I>0&&wX(I)}function wX(I){if(EA("testwindow"))return null;const A=new URL(window.location.href);Kn(A.searchParams,zD,1),Kn(A.searchParams,"testwindow",1);const g=A.toString(),e=[];window.onbeforeunload=()=>{for(const s of e)s.close()};const i=.05,t=128;let C=0,o=0;for(let s=0;s<I;s++){C*t+t*.01>=window.innerWidth&&(o+=1,C=0);const B=C*(t*(1+i))+window.screenLeft,a=o*(t*(1+i))+window.screenTop+90+60*o;C+=1;const n=window.open(g,"test window "+s,`popup=yes width=${t} height=${t} top=${a} left=${B}`);if(!n){console.warn("Failed to open window");continue}e.push(n),n.onload=()=>{n.onbeforeunload=()=>{for(let r=0;r<e.length;r++){const E=e[r];E!==n&&E.close()}e.length=0}}}return e}class kG extends qA{awake(){uX()}}class GG extends qA{constructor(){super(...arguments),Q(this,"transformsPerFrame",10),Q(this,"interval",0),Q(this,"useFlatbuffers",!0),Q(this,"builder",null),Q(this,"models",null)}awake(){if(this.useFlatbuffers)this.context.connection.beginListenBinary(DE,A=>{});else{this.models=[];for(let A=0;A<this.transformsPerFrame;A++)this.models.push(new gb(this.context.connection.connectionId+"_simulatedTransform_"+A,this))}}update(){if(this.context.connection.isConnected){if(this.useFlatbuffers){if(!this.context.connection.connectionId||this.context.time.frameCount%this.interval!==0)return;this.builder===null&&(this.builder=new Rn(1024));const A=this.builder;for(let g=0;g<this.transformsPerFrame;g++){A.clear();const e=LK(this.context.connection.connectionId,this);this.context.connection.sendBinary(e)}}else if(this.models)for(let A=0;A<this.models.length;A++){const g=this.models[A];g.dontSave=!0,g.update(this,null),this.context.connection.send("TestSimulateUserData-"+A,g)}}}}class gb{constructor(A,g){Q(this,"guid"),Q(this,"fast",!1),Q(this,"position"),Q(this,"rotation"),Q(this,"velocity"),Q(this,"dontSave"),this.guid=A,this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0,w:0},this.update(g,null)}isValid(){return this.fast!==void 0||this.position!==void 0||this.rotation!==void 0||this.velocity!==void 0}update(A,g){const e=A.worldPosition;this.position.x=e.x,this.position.y=e.y,this.position.z=e.z;const i=A.worldQuaternion;if(this.rotation.x=i.x,this.rotation.y=i.y,this.rotation.z=i.z,this.rotation.w=i.w,this.fast=!1,g){const t=g.getVelocity();this.velocity===void 0&&(this.velocity={x:0,y:0,z:0}),this.velocity.x=t.x,this.velocity.y=t.y,this.velocity.z=t.z}}}Q(gb,"temp",new M);var yX=Object.defineProperty,SX=Object.getOwnPropertyDescriptor,un=(I,A,g,e)=>{for(var i=e>1?void 0:e?SX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&yX(A,g,i),i};class SC extends pi{constructor(){super(...arguments),Q(this,"offset"),Q(this,"rotation"),Q(this,"focusArea"),Q(this,"feather"),Q(this,"kernelSize"),Q(this,"resolutionScale")}get typeName(){return"TiltShiftEffect"}init(){this.offset.defaultValue=0,this.rotation.defaultValue=0,this.focusArea.defaultValue=.4,this.feather.defaultValue=.3,this.kernelSize.defaultValue=to.MEDIUM,this.resolutionScale.defaultValue=1/window.devicePixelRatio}onCreateEffect(){console.log(this);const A=new o3({kernelSize:to.VERY_LARGE});return this.offset.onValueChanged=g=>A.offset=g,this.rotation.onValueChanged=g=>A.rotation=g,this.focusArea.onValueChanged=g=>A.focusArea=g,this.feather.onValueChanged=g=>A.feather=g,this.kernelSize.onValueChanged=g=>A.blurPass.kernelSize=g,this.resolutionScale.onValueChanged=g=>A.resolution.scale=g/window.devicePixelRatio,A}}un([m(mg)],SC.prototype,"offset",2),un([m(mg)],SC.prototype,"rotation",2),un([m(mg)],SC.prototype,"focusArea",2),un([m(mg)],SC.prototype,"feather",2),un([m(mg)],SC.prototype,"kernelSize",2),un([m(mg)],SC.prototype,"resolutionScale",2),hC("TiltShiftEffect",SC);var kX=Object.defineProperty,GX=Object.getOwnPropertyDescriptor,fX=(I,A,g,e)=>{for(var i=e>1?void 0:e?GX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&kX(A,g,i),i};class Gh extends pi{constructor(){super(...arguments),Q(this,"mode")}get typeName(){return"ToneMapping"}get isToneMapping(){return!0}init(){this.mode.defaultValue=Ze}apply(){this.mode.onValueChanged=this._apply.bind(this),this._apply(this.mode.value)}unapply(){this.context.renderer.toneMapping=Ze}_apply(A){switch(A){case 0:this.context.renderer.toneMapping=Ln;break;case 1:this.context.renderer.toneMapping=lu;break;case 2:this.context.renderer.toneMapping=Du;break}}}fX([m(mg)],Gh.prototype,"mode",2),hC("Tonemapping",Gh);const Qa=new iQ,yi=new M,_s=new M,dI=new RA,Ib={X:new M(1,0,0),Y:new M(0,1,0),Z:new M(0,0,1)},fG={type:"change"},eb={type:"mouseDown"},ib={type:"mouseUp",mode:null},tb={type:"objectChange"};class MX extends NA{constructor(A,g){super(),g===void 0&&(console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.'),g=document),this.isTransformControls=!0,this.visible=!1,this.domElement=g,this.domElement.style.touchAction="none";const e=new KX;this._gizmo=e,this.add(e);const i=new JX;this._plane=i,this.add(i);const t=this;function C(w,l){let p=l;Object.defineProperty(t,w,{get:function(){return p!==void 0?p:l},set:function(u){p!==u&&(p=u,i[w]=u,e[w]=u,t.dispatchEvent({type:w+"-changed",value:u}),t.dispatchEvent(fG))}}),t[w]=l,i[w]=l,e[w]=l}C("camera",A),C("object",void 0),C("enabled",!0),C("axis",null),C("mode","translate"),C("translationSnap",null),C("rotationSnap",null),C("scaleSnap",null),C("space","world"),C("size",1),C("dragging",!1),C("showX",!0),C("showY",!0),C("showZ",!0);const o=new M,s=new M,B=new RA,a=new RA,n=new M,r=new RA,E=new M,h=new M,c=new M,D=0,d=new M;C("worldPosition",o),C("worldPositionStart",s),C("worldQuaternion",B),C("worldQuaternionStart",a),C("cameraPosition",n),C("cameraQuaternion",r),C("pointStart",E),C("pointEnd",h),C("rotationAxis",c),C("rotationAngle",D),C("eye",d),this._offset=new M,this._startNorm=new M,this._endNorm=new M,this._cameraScale=new M,this._parentPosition=new M,this._parentQuaternion=new RA,this._parentQuaternionInv=new RA,this._parentScale=new M,this._worldScaleStart=new M,this._worldQuaternionInv=new RA,this._worldScale=new M,this._positionStart=new M,this._quaternionStart=new RA,this._scaleStart=new M,this._getPointer=mX.bind(this),this._onPointerDown=RX.bind(this),this._onPointerHover=UX.bind(this),this._onPointerMove=FX.bind(this),this._onPointerUp=NX.bind(this),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointermove",this._onPointerHover),this.domElement.addEventListener("pointerup",this._onPointerUp)}updateMatrixWorld(){this.object!==void 0&&(this.object.updateMatrixWorld(),this.object.parent===null?console.error("TransformControls: The attached 3D object must be a part of the scene graph."):this.object.parent.matrixWorld.decompose(this._parentPosition,this._parentQuaternion,this._parentScale),this.object.matrixWorld.decompose(this.worldPosition,this.worldQuaternion,this._worldScale),this._parentQuaternionInv.copy(this._parentQuaternion).invert(),this._worldQuaternionInv.copy(this.worldQuaternion).invert()),this.camera.updateMatrixWorld(),this.camera.matrixWorld.decompose(this.cameraPosition,this.cameraQuaternion,this._cameraScale),this.camera.isOrthographicCamera?this.camera.getWorldDirection(this.eye).negate():this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize(),super.updateMatrixWorld(this)}pointerHover(A){if(this.object===void 0||this.dragging===!0)return;Qa.setFromCamera(A,this.camera);const g=MG(this._gizmo.picker[this.mode],Qa);g?this.axis=g.object.name:this.axis=null}pointerDown(A){if(!(this.object===void 0||this.dragging===!0||A.button!==0)&&this.axis!==null){Qa.setFromCamera(A,this.camera);const g=MG(this._plane,Qa,!0);g&&(this.object.updateMatrixWorld(),this.object.parent.updateMatrixWorld(),this._positionStart.copy(this.object.position),this._quaternionStart.copy(this.object.quaternion),this._scaleStart.copy(this.object.scale),this.object.matrixWorld.decompose(this.worldPositionStart,this.worldQuaternionStart,this._worldScaleStart),this.pointStart.copy(g.point).sub(this.worldPositionStart)),this.dragging=!0,eb.mode=this.mode,this.dispatchEvent(eb)}}pointerMove(A){const g=this.axis,e=this.mode,i=this.object;let t=this.space;if(e==="scale"?t="local":(g==="E"||g==="XYZE"||g==="XYZ")&&(t="world"),i===void 0||g===null||this.dragging===!1||A.button!==-1)return;Qa.setFromCamera(A,this.camera);const C=MG(this._plane,Qa,!0);if(C){if(this.pointEnd.copy(C.point).sub(this.worldPositionStart),e==="translate")this._offset.copy(this.pointEnd).sub(this.pointStart),t==="local"&&g!=="XYZ"&&this._offset.applyQuaternion(this._worldQuaternionInv),g.indexOf("X")===-1&&(this._offset.x=0),g.indexOf("Y")===-1&&(this._offset.y=0),g.indexOf("Z")===-1&&(this._offset.z=0),t==="local"&&g!=="XYZ"?this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale):this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale),i.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(t==="local"&&(i.position.applyQuaternion(dI.copy(this._quaternionStart).invert()),g.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),g.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),g.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.position.applyQuaternion(this._quaternionStart)),t==="world"&&(i.parent&&i.position.add(yi.setFromMatrixPosition(i.parent.matrixWorld)),g.search("X")!==-1&&(i.position.x=Math.round(i.position.x/this.translationSnap)*this.translationSnap),g.search("Y")!==-1&&(i.position.y=Math.round(i.position.y/this.translationSnap)*this.translationSnap),g.search("Z")!==-1&&(i.position.z=Math.round(i.position.z/this.translationSnap)*this.translationSnap),i.parent&&i.position.sub(yi.setFromMatrixPosition(i.parent.matrixWorld))));else if(e==="scale"){if(g.search("XYZ")!==-1){let o=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(o*=-1),_s.set(o,o,o)}else yi.copy(this.pointStart),_s.copy(this.pointEnd),yi.applyQuaternion(this._worldQuaternionInv),_s.applyQuaternion(this._worldQuaternionInv),_s.divide(yi),g.search("X")===-1&&(_s.x=1),g.search("Y")===-1&&(_s.y=1),g.search("Z")===-1&&(_s.z=1);i.scale.copy(this._scaleStart).multiply(_s),this.scaleSnap&&(g.search("X")!==-1&&(i.scale.x=Math.round(i.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),g.search("Y")!==-1&&(i.scale.y=Math.round(i.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),g.search("Z")!==-1&&(i.scale.z=Math.round(i.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(e==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const o=20/this.worldPosition.distanceTo(yi.setFromMatrixPosition(this.camera.matrixWorld));g==="E"?(this.rotationAxis.copy(this.eye),this.rotationAngle=this.pointEnd.angleTo(this.pointStart),this._startNorm.copy(this.pointStart).normalize(),this._endNorm.copy(this.pointEnd).normalize(),this.rotationAngle*=this._endNorm.cross(this._startNorm).dot(this.eye)<0?1:-1):g==="XYZE"?(this.rotationAxis.copy(this._offset).cross(this.eye).normalize(),this.rotationAngle=this._offset.dot(yi.copy(this.rotationAxis).cross(this.eye))*o):(g==="X"||g==="Y"||g==="Z")&&(this.rotationAxis.copy(Ib[g]),yi.copy(Ib[g]),t==="local"&&yi.applyQuaternion(this.worldQuaternion),this.rotationAngle=this._offset.dot(yi.cross(this.eye).normalize())*o),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),t==="local"&&g!=="E"&&g!=="XYZE"?(i.quaternion.copy(this._quaternionStart),i.quaternion.multiply(dI.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),i.quaternion.copy(dI.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),i.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(fG),this.dispatchEvent(tb)}}pointerUp(A){A.button===0&&(this.dragging&&this.axis!==null&&(ib.mode=this.mode,this.dispatchEvent(ib)),this.dragging=!1,this.axis=null)}dispose(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerHover),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.traverse(function(A){A.geometry&&A.geometry.dispose(),A.material&&A.material.dispose()})}attach(A){return this.object=A,this.visible=!0,this}detach(){return this.object=void 0,this.visible=!1,this.axis=null,this}reset(){this.enabled&&this.dragging&&(this.object.position.copy(this._positionStart),this.object.quaternion.copy(this._quaternionStart),this.object.scale.copy(this._scaleStart),this.dispatchEvent(fG),this.dispatchEvent(tb),this.pointStart.copy(this.pointEnd))}getRaycaster(){return Qa}getMode(){return this.mode}setMode(A){this.mode=A}setTranslationSnap(A){this.translationSnap=A}setRotationSnap(A){this.rotationSnap=A}setScaleSnap(A){this.scaleSnap=A}setSize(A){this.size=A}setSpace(A){this.space=A}}function mX(I){if(this.domElement.ownerDocument.pointerLockElement)return{x:0,y:0,button:I.button};{const A=this.domElement.getBoundingClientRect();return{x:(I.clientX-A.left)/A.width*2-1,y:-(I.clientY-A.top)/A.height*2+1,button:I.button}}}function UX(I){if(this.enabled)switch(I.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(I));break}}function RX(I){this.enabled&&(document.pointerLockElement||this.domElement.setPointerCapture(I.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.pointerHover(this._getPointer(I)),this.pointerDown(this._getPointer(I)))}function FX(I){this.enabled&&this.pointerMove(this._getPointer(I))}function NX(I){this.enabled&&(this.domElement.releasePointerCapture(I.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(I)))}function MG(I,A,g){const e=A.intersectObject(I,!0);for(let i=0;i<e.length;i++)if(e[i].object.visible||g)return e[i];return!1}const yp=new $I,aI=new M(0,1,0),Cb=new M(0,0,0),ob=new PA,Sp=new RA,kp=new RA,kC=new M,sb=new PA,fh=new M(1,0,0),na=new M(0,1,0),Mh=new M(0,0,1),Gp=new M,mh=new M,Uh=new M;class KX extends NA{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const A=new sI({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),g=new NI({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),e=A.clone();e.opacity=.15;const i=g.clone();i.opacity=.5;const t=A.clone();t.color.setHex(16711680);const C=A.clone();C.color.setHex(65280);const o=A.clone();o.color.setHex(255);const s=A.clone();s.color.setHex(16711680),s.opacity=.5;const B=A.clone();B.color.setHex(65280),B.opacity=.5;const a=A.clone();a.color.setHex(255),a.opacity=.5;const n=A.clone();n.opacity=.25;const r=A.clone();r.color.setHex(16776960),r.opacity=.25,A.clone().color.setHex(16776960);const E=A.clone();E.color.setHex(7895160);const h=new UI(0,.04,.1,12);h.translate(0,.05,0);const c=new tI(.08,.08,.08);c.translate(0,.04,0);const D=new lg;D.setAttribute("position",new Ig([0,0,0,1,0,0],3));const d=new UI(.0075,.0075,.5,3);d.translate(0,.25,0);function w(J,H){const O=new MC(J,.0075,3,64,H*Math.PI*2);return O.rotateY(Math.PI/2),O.rotateX(Math.PI/2),O}function l(){const J=new lg;return J.setAttribute("position",new Ig([0,0,0,1,1,1],3)),J}const p={X:[[new fA(h,t),[.5,0,0],[0,0,-Math.PI/2]],[new fA(h,t),[-.5,0,0],[0,0,Math.PI/2]],[new fA(d,t),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new fA(h,C),[0,.5,0]],[new fA(h,C),[0,-.5,0],[Math.PI,0,0]],[new fA(d,C)]],Z:[[new fA(h,o),[0,0,.5],[Math.PI/2,0,0]],[new fA(h,o),[0,0,-.5],[-Math.PI/2,0,0]],[new fA(d,o),null,[Math.PI/2,0,0]]],XYZ:[[new fA(new fC(.1,0),n.clone()),[0,0,0]]],XY:[[new fA(new tI(.15,.15,.01),a.clone()),[.15,.15,0]]],YZ:[[new fA(new tI(.15,.15,.01),s.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new fA(new tI(.15,.15,.01),B.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},u={X:[[new fA(new UI(.2,0,.6,4),e),[.3,0,0],[0,0,-Math.PI/2]],[new fA(new UI(.2,0,.6,4),e),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new fA(new UI(.2,0,.6,4),e),[0,.3,0]],[new fA(new UI(.2,0,.6,4),e),[0,-.3,0],[0,0,Math.PI]]],Z:[[new fA(new UI(.2,0,.6,4),e),[0,0,.3],[Math.PI/2,0,0]],[new fA(new UI(.2,0,.6,4),e),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new fA(new fC(.2,0),e)]],XY:[[new fA(new tI(.2,.2,.01),e),[.15,.15,0]]],YZ:[[new fA(new tI(.2,.2,.01),e),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new fA(new tI(.2,.2,.01),e),[.15,0,.15],[-Math.PI/2,0,0]]]},y={START:[[new fA(new fC(.01,2),i),null,null,null,"helper"]],END:[[new fA(new fC(.01,2),i),null,null,null,"helper"]],DELTA:[[new KI(l(),i),null,null,null,"helper"]],X:[[new KI(D,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new KI(D,i.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new KI(D,i.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},k={XYZE:[[new fA(w(.5,1),E),null,[0,Math.PI/2,0]]],X:[[new fA(w(.5,.5),t)]],Y:[[new fA(w(.5,.5),C),null,[0,0,-Math.PI/2]]],Z:[[new fA(w(.5,.5),o),null,[0,Math.PI/2,0]]],E:[[new fA(w(.75,1),r),null,[0,Math.PI/2,0]]]},S={AXIS:[[new KI(D,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},G={XYZE:[[new fA(new Dt(.25,10,8),e)]],X:[[new fA(new MC(.5,.1,4,24),e),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new fA(new MC(.5,.1,4,24),e),[0,0,0],[Math.PI/2,0,0]]],Z:[[new fA(new MC(.5,.1,4,24),e),[0,0,0],[0,0,-Math.PI/2]]],E:[[new fA(new MC(.75,.1,2,24),e)]]},f={X:[[new fA(c,t),[.5,0,0],[0,0,-Math.PI/2]],[new fA(d,t),[0,0,0],[0,0,-Math.PI/2]],[new fA(c,t),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new fA(c,C),[0,.5,0]],[new fA(d,C)],[new fA(c,C),[0,-.5,0],[0,0,Math.PI]]],Z:[[new fA(c,o),[0,0,.5],[Math.PI/2,0,0]],[new fA(d,o),[0,0,0],[Math.PI/2,0,0]],[new fA(c,o),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new fA(new tI(.15,.15,.01),a),[.15,.15,0]]],YZ:[[new fA(new tI(.15,.15,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new fA(new tI(.15,.15,.01),B),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new fA(new tI(.1,.1,.1),n.clone())]]},K={X:[[new fA(new UI(.2,0,.6,4),e),[.3,0,0],[0,0,-Math.PI/2]],[new fA(new UI(.2,0,.6,4),e),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new fA(new UI(.2,0,.6,4),e),[0,.3,0]],[new fA(new UI(.2,0,.6,4),e),[0,-.3,0],[0,0,Math.PI]]],Z:[[new fA(new UI(.2,0,.6,4),e),[0,0,.3],[Math.PI/2,0,0]],[new fA(new UI(.2,0,.6,4),e),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new fA(new tI(.2,.2,.01),e),[.15,.15,0]]],YZ:[[new fA(new tI(.2,.2,.01),e),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new fA(new tI(.2,.2,.01),e),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new fA(new tI(.2,.2,.2),e),[0,0,0]]]},q={X:[[new KI(D,i.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new KI(D,i.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new KI(D,i.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function F(J){const H=new NA;for(const O in J)for(let X=J[O].length;X--;){const W=J[O][X][0].clone(),BA=J[O][X][1],aA=J[O][X][2],DA=J[O][X][3],MA=J[O][X][4];W.name=O,W.tag=MA,BA&&W.position.set(BA[0],BA[1],BA[2]),aA&&W.rotation.set(aA[0],aA[1],aA[2]),DA&&W.scale.set(DA[0],DA[1],DA[2]),W.updateMatrix();const eA=W.geometry.clone();eA.applyMatrix4(W.matrix),W.geometry=eA,W.renderOrder=1/0,W.position.set(0,0,0),W.rotation.set(0,0,0),W.scale.set(1,1,1),H.add(W)}return H}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=F(p)),this.add(this.gizmo.rotate=F(k)),this.add(this.gizmo.scale=F(f)),this.add(this.picker.translate=F(u)),this.add(this.picker.rotate=F(G)),this.add(this.picker.scale=F(K)),this.add(this.helper.translate=F(y)),this.add(this.helper.rotate=F(S)),this.add(this.helper.scale=F(q)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(A){const g=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:kp;this.gizmo.translate.visible=this.mode==="translate",this.gizmo.rotate.visible=this.mode==="rotate",this.gizmo.scale.visible=this.mode==="scale",this.helper.translate.visible=this.mode==="translate",this.helper.rotate.visible=this.mode==="rotate",this.helper.scale.visible=this.mode==="scale";let e=[];e=e.concat(this.picker[this.mode].children),e=e.concat(this.gizmo[this.mode].children),e=e.concat(this.helper[this.mode].children);for(let i=0;i<e.length;i++){const t=e[i];t.visible=!0,t.rotation.set(0,0,0),t.position.copy(this.worldPosition);let C;if(this.camera.isOrthographicCamera?C=(this.camera.top-this.camera.bottom)/this.camera.zoom:C=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),t.scale.set(1,1,1).multiplyScalar(C*this.size/4),t.tag==="helper"){t.visible=!1,t.name==="AXIS"?(t.position.copy(this.worldPositionStart),t.visible=!!this.axis,this.axis==="X"&&(dI.setFromEuler(yp.set(0,0,0)),t.quaternion.copy(g).multiply(dI),Math.abs(aI.copy(fh).applyQuaternion(g).dot(this.eye))>.9&&(t.visible=!1)),this.axis==="Y"&&(dI.setFromEuler(yp.set(0,0,Math.PI/2)),t.quaternion.copy(g).multiply(dI),Math.abs(aI.copy(na).applyQuaternion(g).dot(this.eye))>.9&&(t.visible=!1)),this.axis==="Z"&&(dI.setFromEuler(yp.set(0,Math.PI/2,0)),t.quaternion.copy(g).multiply(dI),Math.abs(aI.copy(Mh).applyQuaternion(g).dot(this.eye))>.9&&(t.visible=!1)),this.axis==="XYZE"&&(dI.setFromEuler(yp.set(0,Math.PI/2,0)),aI.copy(this.rotationAxis),t.quaternion.setFromRotationMatrix(ob.lookAt(Cb,aI,na)),t.quaternion.multiply(dI),t.visible=this.dragging),this.axis==="E"&&(t.visible=!1)):t.name==="START"?(t.position.copy(this.worldPositionStart),t.visible=this.dragging):t.name==="END"?(t.position.copy(this.worldPosition),t.visible=this.dragging):t.name==="DELTA"?(t.position.copy(this.worldPositionStart),t.quaternion.copy(this.worldQuaternionStart),yi.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),yi.applyQuaternion(this.worldQuaternionStart.clone().invert()),t.scale.copy(yi),t.visible=this.dragging):(t.quaternion.copy(g),this.dragging?t.position.copy(this.worldPositionStart):t.position.copy(this.worldPosition),this.axis&&(t.visible=this.axis.search(t.name)!==-1));continue}t.quaternion.copy(g),this.mode==="translate"||this.mode==="scale"?(t.name==="X"&&Math.abs(aI.copy(fh).applyQuaternion(g).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="Y"&&Math.abs(aI.copy(na).applyQuaternion(g).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="Z"&&Math.abs(aI.copy(Mh).applyQuaternion(g).dot(this.eye))>.99&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="XY"&&Math.abs(aI.copy(Mh).applyQuaternion(g).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="YZ"&&Math.abs(aI.copy(fh).applyQuaternion(g).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1),t.name==="XZ"&&Math.abs(aI.copy(na).applyQuaternion(g).dot(this.eye))<.2&&(t.scale.set(1e-10,1e-10,1e-10),t.visible=!1)):this.mode==="rotate"&&(Sp.copy(g),aI.copy(this.eye).applyQuaternion(dI.copy(g).invert()),t.name.search("E")!==-1&&t.quaternion.setFromRotationMatrix(ob.lookAt(this.eye,Cb,na)),t.name==="X"&&(dI.setFromAxisAngle(fh,Math.atan2(-aI.y,aI.z)),dI.multiplyQuaternions(Sp,dI),t.quaternion.copy(dI)),t.name==="Y"&&(dI.setFromAxisAngle(na,Math.atan2(aI.x,aI.z)),dI.multiplyQuaternions(Sp,dI),t.quaternion.copy(dI)),t.name==="Z"&&(dI.setFromAxisAngle(Mh,Math.atan2(aI.y,aI.x)),dI.multiplyQuaternions(Sp,dI),t.quaternion.copy(dI))),t.visible=t.visible&&(t.name.indexOf("X")===-1||this.showX),t.visible=t.visible&&(t.name.indexOf("Y")===-1||this.showY),t.visible=t.visible&&(t.name.indexOf("Z")===-1||this.showZ),t.visible=t.visible&&(t.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),t.material._color=t.material._color||t.material.color.clone(),t.material._opacity=t.material._opacity||t.material.opacity,t.material.color.copy(t.material._color),t.material.opacity=t.material._opacity,this.enabled&&this.axis&&(t.name===this.axis||this.axis.split("").some(function(o){return t.name===o}))&&(t.material.color.setHex(16776960),t.material.opacity=1)}super.updateMatrixWorld(A)}}class JX extends fA{constructor(){super(new Je(1e5,1e5,2,2),new sI({visible:!1,wireframe:!0,side:nI,transparent:!0,opacity:.1,toneMapped:!1})),this.isTransformControlsPlane=!0,this.type="TransformControlsPlane"}updateMatrixWorld(A){let g=this.space;switch(this.position.copy(this.worldPosition),this.mode==="scale"&&(g="local"),Gp.copy(fh).applyQuaternion(g==="local"?this.worldQuaternion:kp),mh.copy(na).applyQuaternion(g==="local"?this.worldQuaternion:kp),Uh.copy(Mh).applyQuaternion(g==="local"?this.worldQuaternion:kp),aI.copy(mh),this.mode){case"translate":case"scale":switch(this.axis){case"X":aI.copy(this.eye).cross(Gp),kC.copy(Gp).cross(aI);break;case"Y":aI.copy(this.eye).cross(mh),kC.copy(mh).cross(aI);break;case"Z":aI.copy(this.eye).cross(Uh),kC.copy(Uh).cross(aI);break;case"XY":kC.copy(Uh);break;case"YZ":kC.copy(Gp);break;case"XZ":aI.copy(Uh),kC.copy(mh);break;case"XYZ":case"E":kC.set(0,0,0);break}break;case"rotate":default:kC.set(0,0,0)}kC.length()===0?this.quaternion.copy(this.cameraQuaternion):(sb.lookAt(yi.set(0,0,0),kC,aI),this.quaternion.setFromRotationMatrix(sb)),super.updateMatrixWorld(A)}}var qX=Object.defineProperty,bX=Object.getOwnPropertyDescriptor,LX=(I,A,g,e)=>{for(var i=e>1?void 0:e?bX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&qX(A,g,i),i};class fp extends qA{constructor(){super(...arguments),Q(this,"isGizmo",!0),Q(this,"control"),Q(this,"orbit"),Q(this,"changeEventListener"),Q(this,"windowKeyDownListener"),Q(this,"windowKeyUpListener")}awake(){this.isGizmo&&!pr||this.context.mainCamera&&(this.control=new MX(this.context.mainCamera,this.context.renderer.domElement),this.control.visible=!0,this.control.enabled=!0,this.control.getRaycaster().layers.set(2),this.control.size=.6,this.control.traverse(A=>{const g=A;if(g.layers.set(2),g){const e=g.material;e&&(e.opacity=.3)}}))}start(){if(this.context.mainCamera){const A=iA.getComponentInParent(this.context.mainCamera,MK)??void 0;this.orbit=A}}onEnable(){var A;this.control&&(this.context.scene.add(this.control),this.control.attach(this.gameObject)),this.changeEventListener=this.onControlChangedEvent.bind(this),(A=this.control)==null||A.addEventListener("dragging-changed",this.changeEventListener),this.attachWindowEvents()}onDisable(){var A,g;(A=this.control)==null||A.removeFromParent(),this.changeEventListener&&((g=this.control)==null||g.removeEventListener("dragging-changed",this.changeEventListener))}onControlChangedEvent(A){const g=this.orbit;if(g&&(g.enabled=!A.value),A.value){const e=iA.getComponentInParent(this.gameObject,Rs);e&&e.requestOwnership()}}attachWindowEvents(){const A=this.control;A&&(this.windowKeyDownListener||(this.windowKeyDownListener=g=>{switch(g.keyCode){case 81:A.setSpace(A.space==="local"?"world":"local");break;case 16:A.setTranslationSnap(100),A.setRotationSnap(ai.degToRad(15)),A.setScaleSnap(.25);break;case 87:A.setMode("translate");break;case 69:A.setMode("rotate");break;case 82:A.setMode("scale");break;case 187:case 107:A.setSize(A.size+.1);break;case 189:case 109:A.setSize(Math.max(A.size-.1,.1));break;case 88:A.showX=!A.showX;break;case 89:A.showY=!A.showY;break;case 90:A.showZ=!A.showZ;break;case 32:A.enabled=!A.enabled;break}}),this.windowKeyUpListener||(this.windowKeyUpListener=g=>{switch(g.keyCode){case 16:A.setTranslationSnap(null),A.setRotationSnap(null),A.setScaleSnap(null);break}}),window.addEventListener("keydown",this.windowKeyDownListener),window.addEventListener("keyup",this.windowKeyUpListener))}}LX([m()],fp.prototype,"isGizmo",2);function vX(I){const A=I.domElement.querySelector("link[rel='ar']");if(A)return A;const g=document.createElement("div");g.classList.add("menu"),g.classList.add("quicklook-menu"),g.style.display="none",g.style.visibility="hidden";const e=document.createElement("button");e.id="open-in-ar",e.innerText="Open in QuickLook",g.appendChild(e);const i=document.createElement("a");i.id="needle-usdz-link",i.style.display="none",i.rel="ar",i.href="",g.appendChild(i);const t=document.createElement("img");return t.id="button",i.appendChild(t),I.domElement.appendChild(g),i}function xX(){var I=new Date;const A=I.getMonth()+1,g=I.getDate(),e=I.getHours(),i=I.getMinutes(),t=I.getSeconds(),C=(A<10?"0":"")+A,o=(g<10?"0":"")+g,s=(e<10?"0":"")+e,B=(i<10?"0":"")+i,a=(t<10?"0":"")+t;return I.getFullYear()+C+o+"-"+s+B+a}const Mp=EA("debugusdz");function YX(I,A){const g=[],e=iA.getComponentsInChildren(I,xi);let i=!1;Mp&&console.log(e);for(const t of e){if(!t||!t.runtimeAnimatorController)continue;Mp&&console.log(t);const C=[];for(const o of t.runtimeAnimatorController.enumerateActions()){Mp&&console.log(o);const s=o.getClip();if(!i&&s.tracks.length>0){i=!0;const B=s.tracks[0],a=B.name.substring(0,B.name.lastIndexOf(".")),n=new Ni(a+".position",[0,.01],[0,0,0,0,0,0]),r=new Ni(a+".quaternion",[0,.01],[0,0,0,1,0,0,0,1]);C.push(new mt("rest",.01,[n,r]))}C.includes(s)||C.push(s)}g.push({root:t.gameObject,clips:C})}Mp&&console.log(g);for(const t of g)for(const C of t.clips)A.registerAnimation(t.root,C)}var HX=Object.defineProperty,TX=Object.getOwnPropertyDescriptor,Bb=(I,A,g,e)=>{for(var i=e>1?void 0:e?TX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&HX(A,g,i),i};const Rh=EA("debugusdz");class Fh extends qA{constructor(){super(...arguments),Q(this,"objectToExport"),Q(this,"autoExportAnimations",!1),Q(this,"extensions",[]),Q(this,"link"),Q(this,"webxr"),Q(this,"webARSessionRoot"),Q(this,"lastCallback"),Q(this,"_arButton")}start(){var A;Rh&&(window.addEventListener("keydown",g=>{switch(g.key){case"t":this.exportAsync();break}}),pa()&&setTimeout(()=>{this.exportAsync()},2e3)),(A=document.getElementById("open-in-ar"))==null||A.addEventListener("click",g=>{g.preventDefault(),this.exportAsync()}),this.objectToExport||(this.objectToExport=this.gameObject)}onEnable(){const A=oc(),g=Iu();(Rh||A&&g)&&(this.createQuicklookButton(),this.webARSessionRoot=iA.findObjectOfType(fs)??void 0,this.lastCallback=this.quicklookCallback.bind(this),this.link=vX(this.context),this.link.addEventListener("message",this.lastCallback))}onDisable(){var A;(A=this.link)==null||A.removeEventListener("message",this.lastCallback)}async exportAsync(){if(!this.objectToExport)return;if(this.webARSessionRoot){const r=this.webARSessionRoot.gameObject,E=1/this.webARSessionRoot.arScale;r.matrix.makeScale(E,E,E),this.webARSessionRoot.invertForward&&r.matrix.multiply(new PA().makeRotationY(Math.PI))}const A=new Nj,g=[...this.extensions],e=new VD;g.push(e),this.autoExportAnimations&&YX(this.objectToExport,e);const i={self:this,exporter:A,extensions:g,object:this.objectToExport};this.dispatchEvent(new CustomEvent("before-export",{detail:i}));let t="needle";Rh&&(t+="-"+xX()),A.debug=Rh;const C=await A.parse(this.objectToExport,g),o=new Blob([C],{type:"application/octet-stream"});this.dispatchEvent(new CustomEvent("after-export",{detail:i}));const s=this.buildQuicklookOverlay(),B=s.callToAction?encodeURIComponent(s.callToAction):"",a=s.checkoutTitle?encodeURIComponent(s.checkoutTitle):"",n=s.checkoutSubtitle?encodeURIComponent(s.checkoutSubtitle):"";this.link.href=URL.createObjectURL(o)+`#callToAction=${B}&checkoutTitle=${a}&checkoutSubtitle=${n}&`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=t+".usdz",this.link.click()}quicklookCallback(A){A?.data=="_apple_ar_quicklook_button_tapped"&&(Rh&&Ut("Quicklook closed via call to action button"),this.dispatchEvent(new CustomEvent("quicklook-button-tapped",{detail:this})))}buildQuicklookOverlay(){const A={};return A.callToAction="Close",A.checkoutTitle="\u{1F335} Made with Needle",A.checkoutSubtitle="_",this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:A})),A}async createQuicklookButton(){var A,g;if(!this.webxr)if(await tc(1),this.webxr=iA.findObjectOfType(Ug)??void 0,this.webxr)if(this.webxr.VRButton&&((A=this.webxr.VRButton.parentElement)==null||A.removeChild(this.webxr.VRButton)),this.webxr.ARButton&&this._arButton!==this.webxr.ARButton){this._arButton=this.webxr.ARButton;const e=(g=this.webxr.ARButton.parentElement)==null?void 0:g.querySelector("a");e&&(e.href=""),this.webxr.ARButton.innerText="Open in Quicklook",this.webxr.ARButton.disabled=!1,this.webxr.ARButton.addEventListener("click",i=>{i.preventDefault(),this.exportAsync()}),this.webxr.ARButton.classList.add("quicklook-ar-button"),this.dispatchEvent(new CustomEvent("created-button",{detail:this.webxr.ARButton}))}else{this.webxr.createARButton=!1,this.webxr.createVRButton=!1;let e=window.document.querySelector(".webxr-buttons");e||(e=document.createElement("div"),e.classList.add("webxr-buttons"));const i=document.createElement("button");i.innerText="Open in Quicklook",i.addEventListener("click",()=>{this.exportAsync()}),i.classList.add("webxr-ar-button"),i.classList.add("webxr-button"),i.classList.add("quicklook-ar-button"),e.appendChild(i),this.dispatchEvent(new CustomEvent("created-button",{detail:i}))}else console.warn("Could not find WebXR component: will not create Quicklook button",Dg.Current)}resetStyles(A){A.style.position="",A.style.top="",A.style.left="",A.style.width="",A.style.height="",A.style.margin="",A.style.padding="",A.style.border="",A.style.background="",A.style.color="",A.style.font="",A.style.textAlign="",A.style.opacity="",A.style.zIndex=""}}Bb([m(NA)],Fh.prototype,"objectToExport",2),Bb([m()],Fh.prototype,"autoExportAnimations",2);var OX=Object.defineProperty,_X=Object.getOwnPropertyDescriptor,mG=(I,A,g,e)=>{for(var i=e>1?void 0:e?_X(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&OX(A,g,i),i};class ra extends pi{constructor(){super(...arguments),Q(this,"color"),Q(this,"intensity"),Q(this,"center")}get typeName(){return"Vignette"}init(){this.color.defaultValue={r:0,g:0,b:0,a:1},this.intensity.defaultValue=0,this.center.defaultValue={x:.5,y:.5}}onCreateEffect(){const A=new DF;return this.intensity.onValueChanged=g=>{A.offset=g,this.updateDarkness(A)},this.color.onValueChanged=g=>{this.updateDarkness(A)},A}updateDarkness(A){const g=this.intensity.value;A.darkness=g}}mG([m(mg)],ra.prototype,"color",2),mG([m(mg)],ra.prototype,"intensity",2),mG([m(mg)],ra.prototype,"center",2),hC("Vignette",ra);var PX=Object.defineProperty,jX=Object.getOwnPropertyDescriptor,WX=(I,A,g,e)=>{for(var i=e>1?void 0:e?jX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&PX(A,g,i),i};const UG=EA("debugpost");class mp extends qA{constructor(){super(...arguments),Q(this,"sharedProfile"),Q(this,"_postprocessing"),Q(this,"_effects",[]),Q(this,"_lastApplyTime"),Q(this,"_rapidApplyCount",0),Q(this,"_modificationQueue"),Q(this,"_recreateId",-1)}awake(){var A;(A=this.sharedProfile)==null||A.init(),UG&&(console.log(this),console.log("Press P to toggle post processing"),window.addEventListener("keydown",g=>{g.key==="p"&&(console.log("Toggle volume: "+this.name,!this.enabled),this.enabled=!this.enabled)}))}onDisable(){var A;(A=this._postprocessing)==null||A.unapply()}onBeforeRender(){if(!this.context.isInXR){if(this.context.composer&&!(this.context.composer instanceof GS))return;this.context.mainCamera&&(!this._postprocessing||!this._postprocessing.isActive)&&this.apply(),this.context.composer&&(this.context.composer.setRenderer(this.context.renderer),this.context.composer.setMainScene(this.context.scene),this.context.mainCamera&&this.context.composer.setMainCamera(this.context.mainCamera))}}onDestroy(){var A;(A=this._postprocessing)==null||A.dispose()}apply(){var A,g;UG&&console.log("Apply PostProcessing",this,(A=this.context.mainCamera)==null?void 0:A.name),CQ()&&(this._lastApplyTime!==void 0&&Date.now()-this._lastApplyTime<100&&(this._rapidApplyCount++,this._rapidApplyCount===5&&console.warn("Detected rapid post processing modifications - this might be a bug",this)),this._lastApplyTime=Date.now()),this.unapply(),this._effects.length=0,(g=this.sharedProfile)!=null&&g.components&&this._effects.push(...this.sharedProfile.components);const e=this.gameObject.getComponentsInChildren(pi);if(UG&&e!=null&&e.length&&console.log("Additional",e),e)for(const i of e)i.active&&this._effects.push(i);this._effects.length>0&&(this._postprocessing||(this._postprocessing=new rp(this.context)),this._postprocessing.apply(this._effects),this._applyPostQueue())}unapply(){var A;(A=this._postprocessing)==null||A.unapply()}_applyPostQueue(){if(this._modificationQueue){for(const A of this._modificationQueue.values())this.onEditorModification(A);this._modificationQueue.clear()}}onEditorModification(A){var g,e;if(A.propertyName.startsWith("postprocessing.")){if(!this._postprocessing)return this._modificationQueue||(this._modificationQueue=new Map),this._modificationQueue.set(A.propertyName,A),!0;if(!((g=this._effects)!=null&&g.length))return;const i=A.propertyName.split(".");if(i.length===3||i.length===4){const t=i[1],C=i[2];for(const o of this._effects)if(((e=o.typeName)==null?void 0:e.toLowerCase())===t.toLowerCase()){if(C==="active"){o.active=A.value,this.scheduleRecreate();return}if(!Up.has(t)){const s=new Array;Up.set(t,s);const B=Object.keys(o);for(const a of B)o[a]instanceof mg&&s.push(a)}if(Up.has(t)){const s=C.toLowerCase(),B=Up.get(t);for(const a of B)if(a.toLowerCase()===s){const n=o[a];n instanceof mg&&(i.length===4&&i[3]==="active"?(n.overrideState=A.value,this.scheduleRecreate()):n&&n.value!==void 0&&(n.value=A.value));return}}console.warn("Unknown modification",C);return}}return!0}return!1}scheduleRecreate(){const A=++this._recreateId;setTimeout(()=>{A===this._recreateId&&(this.onDisable(),this.onEnable())},200)}}WX([pQ(HE)],mp.prototype,"sharedProfile",2);const Up=new Map;var ZX=Object.defineProperty,VX=Object.getOwnPropertyDescriptor,zX=(I,A,g,e)=>{for(var i=e>1?void 0:e?VX(A,g):A,t=I.length-1,C;t>=0;t--)(C=I[t])&&(i=(e?C(A,g,i):C(i))||i);return e&&i&&ZX(A,g,i),i};class Rp extends qA{constructor(){super(...arguments),Q(this,"backgroundTint",new QI(1,1,1,1)),Q(this,"_preRender"),Q(this,"backgroundPlane"),Q(this,"threeTexture"),Q(this,"forceTextureInitialization",function(){const A=new sI,g=new Je,e=new et;e.add(new fA(g,A));const i=new Ya;return function(t,C){A.map=C,t.render(e,i)}}())}awake(){Ug.OptionalFeatures_AR.push("camera-access")}get background(){return this.backgroundPlane}onEnable(){this._preRender=this.preRender.bind(this),this.context.pre_render_callbacks.push(this._preRender),this.backgroundPlane&&(this.gameObject.add(this.backgroundPlane),this.backgroundPlane.visible=!1)}onDisable(){this.context.pre_render_callbacks=this.context.pre_render_callbacks.filter(A=>A!==this._preRender),this.backgroundPlane&&this.gameObject.remove(this.backgroundPlane)}preRender(){if(!this||!this.gameObject)return;const A=this.context.renderer.xr.getFrame();A&&(!this.threeTexture&&this.context.renderer&&(this.threeTexture=new Ng,this.forceTextureInitialization(this.context.renderer,this.threeTexture)),this.backgroundPlane===void 0&&(this.backgroundPlane=$X(this.backgroundTint),this.gameObject.add(this.backgroundPlane)),this.updateFromFrame(A))}onBeforeRender(A){this.updateFromFrame(A)}updateFromFrame(A){if(!A)return;const g=A.getViewerPose(this.context.renderer.xr.getReferenceSpace());if(g){for(const e of g.views)if("camera"in e&&e.camera){let i=this.context.renderer.xr.getBinding();if(i||(i=new XRWebGLBinding(A.session,this.context.renderer.getContext())),i){let t=null;if("getCameraImage"in i){t=i.getCameraImage(e.camera);const C=this.context.renderer.properties.get(this.threeTexture);C.__webglTexture=t,this.backgroundPlane&&(this.backgroundPlane.setTexture(this.threeTexture),this.backgroundPlane.visible=!0)}}}}}}zX([m()],Rp.prototype,"backgroundTint",2);let XX=`
4802
4802
  uniform sampler2D t2D;
4803
4803
 
4804
4804
  varying vec2 vUv;