@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 YO(i,A){for(const g of Object.keys(A)){const I=A[g];if(typeof I=="object"&&I!==null&&I!==void 0){const e=i[g];if(!e){Sn&&console.log(g,"is undefined on",i);continue}for(const t of Object.keys(I))e[t]===void 0&&bM(I[t])&&!bM(e)&&(e[t]=I[t])}}}function bM(i){switch(typeof i){case"number":case"string":case"boolean":return!0}return!1}function gy(i,A,g,I,e){let t=typeof A=="function"&&A.prototype===void 0,C=A;if(t)try{if(C=A==null?void 0:A.call(A,e),t=!1,C==null)return}catch(B){console.error("Error in callback",B,i)}if(g.type=C,!t&&e instanceof C)return e;if(e&&typeof e=="object"&&KO(e)){if(e.__concreteInstance)return e.__concreteInstance;const B=e;if(!B.$serializedTypes&&C.prototype.$serializedTypes&&(B.$serializedTypes=C.prototype.$serializedTypes),B.$serializedTypes&&Ay(B,i,g),e&&C!==void 0)try{const r=new C;$e&&console.log("Create concrete instance for persistent asset",e,"instance:",r),QB(r,e),e.__concreteInstance=r,e=r}catch(r){console.error("Error creating instance or creating values on instance",r,e,C)}return e}if(I||(I={serializer:Yd.getSerializerForConstructor(C)}),Array.isArray(i)){const B=[];for(let r=0;r<i.length;r++){const a=i[r],E=gy(a,A,g,I,a);B.push(E)}return B}const o=I.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===Lg||C===GA||C===gC))return null;s=new C(...HO(i))}const n=s;return n.$serializedTypes&&Ay(n,i,g),s}function HO(i){if(Ad.length=0,typeof i=="object"&&i!==null&&i!==void 0)for(const A of Object.keys(i))Ad.push(i[A]);return Ad}const Iy=Symbol("assigned component properties");function QB(i,A,g){var e;if(A==null||i==null)return;i[Iy]=!0;const I=((e=i.constructor)==null?void 0:e.name)??"unknown";g==null||g.registerDefinedKeys(I,i);for(const t of Object.keys(A)){const C=TO(i,t);typeof(C==null?void 0:C.value)!="function"&&(!C||C.writable===!0||(C==null?void 0:C.set)!==void 0)&&(i[t]=A[t])}delete i[Iy]}function TO(i,A){let g;do g=Object.getOwnPropertyDescriptor(i,A);while(!g&&(i=Object.getPrototypeOf(i)));return g}const xt=EA("debuginput");class nw{constructor(A){Q(this,"key");Q(this,"keyType");Q(this,"source");this.key=A.key,this.keyType=A.type,this.source=A}}var Eo=(i=>(i.PointerDown="pointerdown",i.PointerUp="pointerup",i.PointerMove="pointermove",i.KeyDown="keydown",i.KeyUp="keyup",i.KeyPressed="keypress",i))(Eo||{});class OO extends EventTarget{constructor(g){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 $]);Q(this,"_pointerPositionsLastFrame",[new $]);Q(this,"_pointerPositionsDelta",[new $]);Q(this,"_pointerPositionsRC",[new $]);Q(this,"_pointerPositionDown",[new $]);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=g,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 g=0;for(let I=0;I<this._pointerPressed.length;I++)this._pointerPressed[I]&&g++;return g}getPointerPosition(g){return g>=this._pointerPositions.length?null:this._pointerPositions[g]}getPointerPositionLastFrame(g){return g>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[g]}getPointerPositionDelta(g){return g>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[g]}getPointerPositionRC(g){return g>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[g]}getPointerDown(g){return g>=this._pointerDown.length?!1:this._pointerDown[g]}getPointerUp(g){return g>=this._pointerUp.length?!1:this._pointerUp[g]}getPointerPressed(g){return g>=this._pointerPressed.length?!1:this._pointerPressed[g]}getPointerClicked(g){return g>=this._pointerClick.length?!1:this._pointerClick[g]}getPointerDoubleClicked(g){return g>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[g]}getPointerDownTime(g){return g>=this._pointerDownTime.length?-1:this._pointerDownTime[g]}getPointerUpTime(g){return g>=this._pointerUpTime.length?-1:this._pointerUpTime[g]}getPointerLongPress(g){return g>=this._pointerDownTime.length?!1:this.getPointerPressed(g)&&this.context.time.time-this._pointerDownTime[g]>this._longPressTimeThreshold}getIsMouse(g){return g<0||g>=this._pointerTypes.length?!1:this._pointerTypes[g]==="mouse"}getIsTouch(g){return g<0||g>=this._pointerTypes.length?!1:this._pointerTypes[g]==="touch"}getTouchesPressedCount(){let g=0;for(let I=0;I<this._pointerPressed.length;I++)this._pointerPressed[I]&&this.getIsTouch(I)&&g++;return g}getMouseWheelChanged(g=0){return g>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[g]}getMouseWheelDeltaY(g=0){return g>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[g]}getPointerEvent(g){if(!(g>=this._pointerEvent.length))return this._pointerEvent[g]??void 0}*foreachPointerId(g){for(let I=0;I<this._pointerTypes.length;I++)if(this._pointerIsActive(I)){if(g!==void 0){const e=this._pointerTypes[I];if(Array.isArray(g)){let t=!1;for(const C of g)if(e===C){t=!0;break}if(!t)continue}else if(g!==e)continue}yield I}}*foreachTouchId(){for(let g=0;g<this._pointerTypes.length;g++)this._pointerTypes[g]==="touch"&&this._pointerIsActive[g]&&(yield g)}_pointerIsActive(g){return g<0?!1:this._pointerPressed[g]||this._pointerDown[g]||this._pointerUp[g]}getKeyDown(){for(const g in this.keysPressed){const I=this.keysPressed[g];if(I.startFrame===this.context.time.frameCount)return I.key}return null}getKeyPressed(){for(const g in this.keysPressed){const I=this.keysPressed[g];if(I.pressed)return I.key}return null}isKeyDown(g){var e;const I=this.getCodeForCommonKeyName(g);if(I!==null){for(const t of I)if(this.isKeyDown(t))return!0;return!1}return this.context.application.isVisible&&this.context.application.hasFocus&&((e=this.keysPressed[g])==null?void 0:e.startFrame)===this.context.time.frameCount&&this.keysPressed[g].pressed}isKeyUp(g){var e;const I=this.getCodeForCommonKeyName(g);if(I!==null){for(const t of I)if(this.isKeyUp(t))return!0;return!1}return this.context.application.isVisible&&this.context.application.hasFocus&&((e=this.keysPressed[g])==null?void 0:e.frame)===this.context.time.frameCount&&!this.keysPressed[g].pressed}isKeyPressed(g){var e;const I=this.getCodeForCommonKeyName(g);if(I!==null){for(const t of I)if(this.isKeyPressed(t))return!0;return!1}return this.context.application.isVisible&&this.context.application.hasFocus&&((e=this.keysPressed[g])==null?void 0:e.pressed)}getCodeForCommonKeyName(g){if(g.length===1){if(g>="0"&&g<="9")return["Digit"+g];if(g>="a"&&g<="z")return["Key"+g.toUpperCase()];if(g==" ")return["Space"]}switch(g){case"Shift":return["ShiftLeft","ShiftRight"];case"Control":return["ControlLeft","ControlRight"];case"Alt":return["AltLeft","AltRight"]}return null}createPointerDown(g){xt&&Pi("Create Pointer down"),this.onDown(g)}createPointerMove(g){xt&&Pi("Create Pointer move"),this.onMove(g)}createPointerUp(g){xt&&Pi("Create Pointer up"),this.onUp(g)}convertScreenspaceToRaycastSpace(g){g.x=(g.x-this.context.domX)/this.context.domWidth*2-1,g.y=-((g.y-this.context.domY)/this.context.domHeight)*2+1}onLostFocus(){for(const g in this.keysPressed)this.keysPressed[g].pressed=!1}onEndOfFrame(){for(let g=0;g<this._pointerUp.length;g++)this._pointerUp[g]=!1;for(let g=0;g<this._pointerDown.length;g++)this._pointerDown[g]=!1;for(let g=0;g<this._pointerClick.length;g++)this._pointerClick[g]=!1;for(let g=0;g<this._pointerDoubleClick.length;g++)this._pointerDoubleClick[g]=!1;for(const g of this._pointerPositionsDelta)g.set(0,0);for(let g=0;g<this._mouseWheelChanged.length;g++)this._mouseWheelChanged[g]=!1;for(let g=0;g<this._mouseWheelDeltaY.length;g++)this._mouseWheelDeltaY[g]=0}canReceiveInput(g){return g.target===this.context.renderer.domElement}onKeyDown(g){if(!this.context.application.hasFocus)return;const I=this.keysPressed[g.code];I&&I.pressed||(this.keysPressed[g.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:g.key,code:g.code},this.onDispatchEvent("keydown",new nw(g)))}onKeyPressed(g){if(!this.context.application.hasFocus)return;const I=this.keysPressed[g.code];I&&(I.pressed=!0,I.frame=this.context.time.frameCount+1,this.onDispatchEvent("keypress",new nw(g)))}onKeyUp(g){if(!this.context.application.hasFocus)return;const I=this.keysPressed[g.code];I&&(I.pressed=!1,I.frame=this.context.time.frameCount+1,this.onDispatchEvent("keyup",new nw(g)))}onMouseWheel(g){if(this.canReceiveInput(g)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const I=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=I+g.deltaY}onTouchStart(g){if(!(g.changedTouches.length<=0)&&this.canReceiveInput(g)!==!1)for(let I=0;I<g.changedTouches.length;I++){const e=g.changedTouches[I],t=this.getPointerIndex(e.identifier);xt&&Pi(`touch start #${t}, identifier:${e.identifier}`);const C={button:t,clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:g};this.onDown(C)}}onTouchMove(g){if(!(g.changedTouches.length<=0))for(let I=0;I<g.changedTouches.length;I++){const e=g.changedTouches[I],C={button:this.getPointerIndex(e.identifier),clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:g};this.onMove(C)}}onTouchUp(g){if(!(g.changedTouches.length<=0))for(let I=0;I<g.changedTouches.length;I++){const e=g.changedTouches[I],t=this.getPointerIndex(e.identifier);if(!this.isNewEvent(g.timeStamp,t,this._pointerUpTimestamp))continue;xt&&Pi(`touch up #${t}, identifier:${e.identifier}`);const C={button:t,clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:g};this.onUp(C)}}onMouseDown(g){if(g.defaultPrevented||this.canReceiveInput(g)===!1)return;let I=g.button;this.onDown({button:I,clientX:g.clientX,clientY:g.clientY,pointerType:"mouse",source:g})}onMouseMove(g){if(g.defaultPrevented)return;const e={button:g.button,clientX:g.clientX,clientY:g.clientY,pointerType:"mouse",source:g,movementX:g.movementX,movementY:g.movementY};this.onMove(e)}onMouseUp(g){if(g.defaultPrevented)return;let I=g.button;this.isNewEvent(g.timeStamp,I,this._pointerUpTimestamp)&&this.onUp({button:I,clientX:g.clientX,clientY:g.clientY,pointerType:"mouse",source:g})}isNewEvent(g,I,e){for(;e.length<=I;)e.push(-1);return g===e[I]?!1:(e[I]=g,!0)}isInRect(g){if(this.context.isInXR)return!0;const I=this.context.domElement.getBoundingClientRect(),e=g.clientX,t=g.clientY,C=e>=I.x&&e<=I.right&&t>=I.y&&t<=I.bottom;return xt&&!C&&console.log("Not in rect",I,e,t),C}onDown(g){if(xt&&console.log(g.pointerType,"DOWN",g.button),!!this.isInRect(g)){for(this.setPointerState(g.button,this._pointerPressed,!0),this.setPointerState(g.button,this._pointerDown,!0),this.setPointerStateT(g.button,this._pointerEvent,g.source);g.button>=this._pointerTypes.length;)this._pointerTypes.push(g.pointerType);for(this._pointerTypes[g.button]=g.pointerType;g.button>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new $);for(this._pointerPositionDown[g.button].set(g.clientX,g.clientY);g.button>=this._pointerPositions.length;)this._pointerPositions.push(new $);this._pointerPositions[g.button].set(g.clientX,g.clientY),g.button>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[g.button]=this.context.time.time,this.updatePointerPosition(g),this.onDispatchEvent("pointerdown",g)}}onMove(g){const I=this.getPointerPressed(g.button);I===!1&&!this.isInRect(g)||g.pointerType==="touch"&&!I||(xt&&console.log(g.pointerType,"MOVE",g.button),this.updatePointerPosition(g),this.setPointerStateT(g.button,this._pointerEvent,g.source),this.onDispatchEvent("pointermove",g))}onUp(g){var C;if(((C=this._pointerIds)==null?void 0:C.length)>=g.button&&(this._pointerIds[g.button]=-1),!this._pointerPressed[g.button]){xt&&console.log(g.pointerType,"UP",g.button,"was not down");return}if(xt&&console.log(g.pointerType,"UP",g.button),this.setPointerState(g.button,this._pointerPressed,!1),this.setPointerStateT(g.button,this._pointerEvent,g.source),this.setPointerState(g.button,this._pointerUp,!0),this.updatePointerPosition(g),!this._pointerPositionDown[g.button]){xt&&tC("Received pointer up event without matching down event for button: "+g.button),console.warn("Received pointer up event without matching down event for button: "+g.button);return}const e=g.clientX-this._pointerPositionDown[g.button].x,t=g.clientY-this._pointerPositionDown[g.button].y;if(g.button>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(e)<5&&Math.abs(t)<5){this.setPointerState(g.button,this._pointerClick,!0);const o=this._pointerUpTime[g.button],s=this.context.time.time-o;s<this._doubleClickTimeThreshold&&s>0&&this.setPointerState(g.button,this._pointerDoubleClick,!0)}this._pointerUpTime[g.button]=this.context.time.time,this.onDispatchEvent("pointerup",g)}updatePointerPosition(g){for(;g.button>=this._pointerPositions.length;)this._pointerPositions.push(new $);for(;g.button>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new $);for(;g.button>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new $);const I=this._pointerPositionsLastFrame[g.button];I.copy(this._pointerPositions[g.button]);const e=g.clientX-I.x,t=g.clientY-I.y;this._pointerPositionsDelta[g.button].set(e,t),this._pointerPositions[g.button].x=g.clientX,this._pointerPositions[g.button].y=g.clientY;const C=g.clientX,o=g.clientY;for(;g.button>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new $);const s=this._pointerPositionsRC[g.button];s.set(C,o),this.convertScreenspaceToRaycastSpace(s)}getPointerIndex(g){const I=this._pointerIds;let e=-1;for(let t=0;t<I.length;t++){if(I[t]===g)return t;e===-1&&I[t]===-1&&(e=t)}return e!==-1?(I[e]=g,e):(I.push(g),I.length-1)}setPointerState(g,I,e){for(;I.length<=g;)I.push(!1);I[g]=e}setPointerStateT(g,I,e){for(;I.length<=g;)I.push(null);I[g]=e}onDispatchEvent(g,I){const e=Dg.Current;try{Dg.Current=this.context;const t=new Event(g);QB(t,I),this.dispatchEvent(t)}finally{Dg.Current=e}}}class _O{random(){return Math.random()}clamp(A,g,I){return A<g?g:A>I?I:A}clamp01(A){return this.clamp(A,0,1)}lerp(A,g,I){return I=I<0?0:I,I=I>1?1:I,A+(g-A)*I}inverseLerp(A,g,I){return(I-A)/(g-A)}remap(A,g,I,e,t){return e+(t-e)*(A-g)/(I-g)}moveTowards(A,g,I){return A+=I,(I<0&&A<g||I>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 gg=new _O;function PO(i,A,g){const I=i.length(),e=A.length(),t=gg.lerp(I,e,g);return i.lerp(A,g).normalize().multiplyScalar(t)}new UA().setFromAxisAngle(new M(0,1,0),Math.PI);const I0=new Ha(()=>new M,100);function Sg(i,A=null,g=!0){const I=A??I0.get();return i?i.parent?(g&&i.updateWorldMatrix(!0,!1),i.matrixWorldNeedsUpdate&&i.updateMatrixWorld(),I.setFromMatrixPosition(i.matrixWorld),I):I.copy(i.position):I.set(0,0,0)}function xe(i,A){if(!i)return;const g=I0.get();A!==g&&g.copy(A),((i==null?void 0:i.parent)??i).worldToLocal(g),i.position.set(g.x,g.y,g.z)}function bE(i,A,g,I){const e=I0.get();e.set(A,g,I),xe(i,e)}const $n=new UA,vE=new UA,Bw=new UA;function Vi(i,A=null){if(!i)return vE.set(0,0,0,1);const g=A??vE;return i.parent?(i.getWorldQuaternion(g),g):g.copy(i.quaternion)}function JC(i,A){if(!i)return;A!==$n&&$n.copy(A);const g=$n,I=i==null?void 0:i.parent;I==null||I.getWorldQuaternion(Bw),Bw.invert();const e=Bw.multiply(g);i.quaternion.set(e.x,e.y,e.z,e.w)}function WO(i,A,g,I,e){$n.set(A,g,I,e),JC(i,$n)}const rl=new M;new M;function fi(i,A=null){return i?i.parent?(i.getWorldScale(A??rl),A??rl):rl.copy(i.scale):rl.set(0,0,0)}new M;const vM=new Ce,xM=new Ce,jO=new M;function ZO(i){return i.getWorldQuaternion(vE),xM.setFromQuaternion(vE),xM}function zO(i,A){JC(i,vE.setFromEuler(A))}function dN(i){const A=ZO(i),g=jO;return g.set(A.x,A.y,A.z),g.x=gg.toDegrees(g.x),g.y=gg.toDegrees(g.y),g.z=gg.toDegrees(g.z),g}function DN(i,A,g,I,e=!0){e&&(A=gg.toRadians(A),g=gg.toRadians(g),I=gg.toRadians(I)),vM.set(A,g,I),$n.setFromEuler(vM),JC(i,$n)}function ey(i,A=!0){i&&(A?function g(I){console.groupCollapsed((I.name?I.name:"(no name : "+I.type+")")+" %o",I),I.children.forEach(g),console.groupEnd()}(i):i.traverse(function(g){for(var I="|___",e=g;e.parent!==null;)I=" "+I,e=e.parent;console.log(I+g.name+" <"+g.type+">")}))}function VO(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 Ra=class{static createBlitMaterial(A){return new Og({uniforms:{map:new SA(null)},vertexShader:this.vertex,fragmentShader:A})}static copyTexture(A,g){const I=g??this.blipMaterial;I.uniforms.map.value=A,I.needsUpdate=!0,I.uniformsNeedUpdate=!0;const e=this.mesh;e.material=I,e.frustumCulled=!1,this.scene.children.length=0,this.scene.add(e),this.renderer.setSize(A.image.width,A.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const t=new Lg(this.renderer.domElement);return t.name="Copy",t.needsUpdate=!0,t}static textureToCanvas(A,g){if(!A)return null;(g===!0||A.isCompressedTexture===!0)&&(A=XO(A));const I=A.image;if($O(I)){const e=document.createElement("canvas");e.width=I.width,e.height=I.height;const t=e.getContext("2d");return t?(t.drawImage(I,0,0,I.width,I.height,0,0,e.width,e.height),e):(console.error("Failed getting canvas 2d context"),null)}return null}};let Yt=Ra;Q(Yt,"planeGeometry",new Oe(2,2,1,1)),Q(Yt,"renderer",new QQ({antialias:!1})),Q(Yt,"perspectiveCam",new zg),Q(Yt,"scene",new Rt),Q(Yt,"vertex",`
3243
+ <a href="https://docs.needle.tools/serializable" target="_blank">documentation</a>`),console.warn(I,C,i[C],i);continue}}}}function YO(i,A){for(const g of Object.keys(A)){const I=A[g];if(typeof I=="object"&&I!==null&&I!==void 0){const e=i[g];if(!e){Sn&&console.log(g,"is undefined on",i);continue}for(const t of Object.keys(I))e[t]===void 0&&bM(I[t])&&!bM(e)&&(e[t]=I[t])}}}function bM(i){switch(typeof i){case"number":case"string":case"boolean":return!0}return!1}function gy(i,A,g,I,e){let t=typeof A=="function"&&A.prototype===void 0,C=A;if(t)try{if(C=A==null?void 0:A.call(A,e),t=!1,C==null)return}catch(B){console.error("Error in callback",B,i)}if(g.type=C,!t&&e instanceof C)return e;if(e&&typeof e=="object"&&KO(e)){if(e.__concreteInstance)return e.__concreteInstance;const B=e;if(!B.$serializedTypes&&C.prototype.$serializedTypes&&(B.$serializedTypes=C.prototype.$serializedTypes),B.$serializedTypes&&Ay(B,i,g),e&&C!==void 0)try{const r=new C;$e&&console.log("Create concrete instance for persistent asset",e,"instance:",r),QB(r,e),e.__concreteInstance=r,e=r}catch(r){console.error("Error creating instance or creating values on instance",r,e,C)}return e}if(I||(I={serializer:Yd.getSerializerForConstructor(C)}),Array.isArray(i)){const B=[];for(let r=0;r<i.length;r++){const a=i[r],E=gy(a,A,g,I,a);B.push(E)}return B}const o=I.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===Lg||C===GA||C===gC))return null;s=new C(...HO(i))}const n=s;return n.$serializedTypes&&Ay(n,i,g),s}function HO(i){if(Ad.length=0,typeof i=="object"&&i!==null&&i!==void 0)for(const A of Object.keys(i))Ad.push(i[A]);return Ad}const Iy=Symbol("assigned component properties");function QB(i,A,g){var e;if(A==null||i==null)return;i[Iy]=!0;const I=((e=i.constructor)==null?void 0:e.name)??"unknown";g==null||g.registerDefinedKeys(I,i);for(const t of Object.keys(A)){const C=TO(i,t);typeof(C==null?void 0:C.value)!="function"&&(!C||C.writable===!0||(C==null?void 0:C.set)!==void 0)&&(i[t]=A[t])}delete i[Iy]}function TO(i,A){let g;do g=Object.getOwnPropertyDescriptor(i,A);while(!g&&(i=Object.getPrototypeOf(i)));return g}const xt=EA("debuginput");class nw{constructor(A){Q(this,"key");Q(this,"keyType");Q(this,"source");this.key=A.key,this.keyType=A.type,this.source=A}}var Eo=(i=>(i.PointerDown="pointerdown",i.PointerUp="pointerup",i.PointerMove="pointermove",i.KeyDown="keydown",i.KeyUp="keyup",i.KeyPressed="keypress",i))(Eo||{});class OO extends EventTarget{constructor(g){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 $]);Q(this,"_pointerPositionsLastFrame",[new $]);Q(this,"_pointerPositionsDelta",[new $]);Q(this,"_pointerPositionsRC",[new $]);Q(this,"_pointerPositionDown",[new $]);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=g,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 g=0;for(let I=0;I<this._pointerPressed.length;I++)this._pointerPressed[I]&&g++;return g}getPointerPosition(g){return g>=this._pointerPositions.length?null:this._pointerPositions[g]}getPointerPositionLastFrame(g){return g>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[g]}getPointerPositionDelta(g){return g>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[g]}getPointerPositionRC(g){return g>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[g]}getPointerDown(g){return g>=this._pointerDown.length?!1:this._pointerDown[g]}getPointerUp(g){return g>=this._pointerUp.length?!1:this._pointerUp[g]}getPointerPressed(g){return g>=this._pointerPressed.length?!1:this._pointerPressed[g]}getPointerClicked(g){return g>=this._pointerClick.length?!1:this._pointerClick[g]}getPointerDoubleClicked(g){return g>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[g]}getPointerDownTime(g){return g>=this._pointerDownTime.length?-1:this._pointerDownTime[g]}getPointerUpTime(g){return g>=this._pointerUpTime.length?-1:this._pointerUpTime[g]}getPointerLongPress(g){return g>=this._pointerDownTime.length?!1:this.getPointerPressed(g)&&this.context.time.time-this._pointerDownTime[g]>this._longPressTimeThreshold}getIsMouse(g){return g<0||g>=this._pointerTypes.length?!1:this._pointerTypes[g]==="mouse"}getIsTouch(g){return g<0||g>=this._pointerTypes.length?!1:this._pointerTypes[g]==="touch"}getTouchesPressedCount(){let g=0;for(let I=0;I<this._pointerPressed.length;I++)this._pointerPressed[I]&&this.getIsTouch(I)&&g++;return g}getMouseWheelChanged(g=0){return g>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[g]}getMouseWheelDeltaY(g=0){return g>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[g]}getPointerEvent(g){if(!(g>=this._pointerEvent.length))return this._pointerEvent[g]??void 0}*foreachPointerId(g){for(let I=0;I<this._pointerTypes.length;I++)if(this._pointerIsActive(I)){if(g!==void 0){const e=this._pointerTypes[I];if(Array.isArray(g)){let t=!1;for(const C of g)if(e===C){t=!0;break}if(!t)continue}else if(g!==e)continue}yield I}}*foreachTouchId(){for(let g=0;g<this._pointerTypes.length;g++)this._pointerTypes[g]==="touch"&&this._pointerIsActive[g]&&(yield g)}_pointerIsActive(g){return g<0?!1:this._pointerPressed[g]||this._pointerDown[g]||this._pointerUp[g]}getKeyDown(){for(const g in this.keysPressed){const I=this.keysPressed[g];if(I.startFrame===this.context.time.frameCount)return I.key}return null}getKeyPressed(){for(const g in this.keysPressed){const I=this.keysPressed[g];if(I.pressed)return I.key}return null}isKeyDown(g){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const I=this.getCodeForCommonKeyName(g);if(I!==null){for(const t of I)if(this.isKeyDown(t))return!0;return!1}return((e=this.keysPressed[g])==null?void 0:e.startFrame)===this.context.time.frameCount&&this.keysPressed[g].pressed}isKeyUp(g){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const I=this.getCodeForCommonKeyName(g);if(I!==null){for(const t of I)if(this.isKeyUp(t))return!0;return!1}return((e=this.keysPressed[g])==null?void 0:e.frame)===this.context.time.frameCount&&!this.keysPressed[g].pressed}isKeyPressed(g){var e;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const I=this.getCodeForCommonKeyName(g);if(I!==null){for(const t of I)if(this.isKeyPressed(t))return!0;return!1}return(e=this.keysPressed[g])==null?void 0:e.pressed}getCodeForCommonKeyName(g){if(g.length===1){if(g>="0"&&g<="9")return["Digit"+g];if(g>="a"&&g<="z")return["Key"+g.toUpperCase()];if(g==" ")return["Space"]}switch(g){case"Shift":return["ShiftLeft","ShiftRight"];case"Control":return["ControlLeft","ControlRight"];case"Alt":return["AltLeft","AltRight"]}return null}createPointerDown(g){xt&&Pi("Create Pointer down"),this.onDown(g)}createPointerMove(g){xt&&Pi("Create Pointer move"),this.onMove(g)}createPointerUp(g){xt&&Pi("Create Pointer up"),this.onUp(g)}convertScreenspaceToRaycastSpace(g){g.x=(g.x-this.context.domX)/this.context.domWidth*2-1,g.y=-((g.y-this.context.domY)/this.context.domHeight)*2+1}onLostFocus(){for(const g in this.keysPressed)this.keysPressed[g].pressed=!1}onEndOfFrame(){for(let g=0;g<this._pointerUp.length;g++)this._pointerUp[g]=!1;for(let g=0;g<this._pointerDown.length;g++)this._pointerDown[g]=!1;for(let g=0;g<this._pointerClick.length;g++)this._pointerClick[g]=!1;for(let g=0;g<this._pointerDoubleClick.length;g++)this._pointerDoubleClick[g]=!1;for(const g of this._pointerPositionsDelta)g.set(0,0);for(let g=0;g<this._mouseWheelChanged.length;g++)this._mouseWheelChanged[g]=!1;for(let g=0;g<this._mouseWheelDeltaY.length;g++)this._mouseWheelDeltaY[g]=0}canReceiveInput(g){return g.target===this.context.renderer.domElement}onKeyDown(g){if(!this.context.application.hasFocus)return;const I=this.keysPressed[g.code];I&&I.pressed||(this.keysPressed[g.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:g.key,code:g.code},this.onDispatchEvent("keydown",new nw(g)))}onKeyPressed(g){if(!this.context.application.hasFocus)return;const I=this.keysPressed[g.code];I&&(I.pressed=!0,I.frame=this.context.time.frameCount+1,this.onDispatchEvent("keypress",new nw(g)))}onKeyUp(g){if(!this.context.application.hasFocus)return;const I=this.keysPressed[g.code];I&&(I.pressed=!1,I.frame=this.context.time.frameCount+1,this.onDispatchEvent("keyup",new nw(g)))}onMouseWheel(g){if(this.canReceiveInput(g)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const I=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=I+g.deltaY}onTouchStart(g){if(!(g.changedTouches.length<=0)&&this.canReceiveInput(g)!==!1)for(let I=0;I<g.changedTouches.length;I++){const e=g.changedTouches[I],t=this.getPointerIndex(e.identifier);xt&&Pi(`touch start #${t}, identifier:${e.identifier}`);const C={button:t,clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:g};this.onDown(C)}}onTouchMove(g){if(!(g.changedTouches.length<=0))for(let I=0;I<g.changedTouches.length;I++){const e=g.changedTouches[I],C={button:this.getPointerIndex(e.identifier),clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:g};this.onMove(C)}}onTouchUp(g){if(!(g.changedTouches.length<=0))for(let I=0;I<g.changedTouches.length;I++){const e=g.changedTouches[I],t=this.getPointerIndex(e.identifier);if(!this.isNewEvent(g.timeStamp,t,this._pointerUpTimestamp))continue;xt&&Pi(`touch up #${t}, identifier:${e.identifier}`);const C={button:t,clientX:e.clientX,clientY:e.clientY,pointerType:"touch",source:g};this.onUp(C)}}onMouseDown(g){if(g.defaultPrevented||this.canReceiveInput(g)===!1)return;let I=g.button;this.onDown({button:I,clientX:g.clientX,clientY:g.clientY,pointerType:"mouse",source:g})}onMouseMove(g){if(g.defaultPrevented)return;const e={button:g.button,clientX:g.clientX,clientY:g.clientY,pointerType:"mouse",source:g,movementX:g.movementX,movementY:g.movementY};this.onMove(e)}onMouseUp(g){if(g.defaultPrevented)return;let I=g.button;this.isNewEvent(g.timeStamp,I,this._pointerUpTimestamp)&&this.onUp({button:I,clientX:g.clientX,clientY:g.clientY,pointerType:"mouse",source:g})}isNewEvent(g,I,e){for(;e.length<=I;)e.push(-1);return g===e[I]?!1:(e[I]=g,!0)}isInRect(g){if(this.context.isInXR)return!0;const I=this.context.domElement.getBoundingClientRect(),e=g.clientX,t=g.clientY,C=e>=I.x&&e<=I.right&&t>=I.y&&t<=I.bottom;return xt&&!C&&console.log("Not in rect",I,e,t),C}onDown(g){if(xt&&console.log(g.pointerType,"DOWN",g.button),!!this.isInRect(g)){for(this.setPointerState(g.button,this._pointerPressed,!0),this.setPointerState(g.button,this._pointerDown,!0),this.setPointerStateT(g.button,this._pointerEvent,g.source);g.button>=this._pointerTypes.length;)this._pointerTypes.push(g.pointerType);for(this._pointerTypes[g.button]=g.pointerType;g.button>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new $);for(this._pointerPositionDown[g.button].set(g.clientX,g.clientY);g.button>=this._pointerPositions.length;)this._pointerPositions.push(new $);this._pointerPositions[g.button].set(g.clientX,g.clientY),g.button>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[g.button]=this.context.time.time,this.updatePointerPosition(g),this.onDispatchEvent("pointerdown",g)}}onMove(g){const I=this.getPointerPressed(g.button);I===!1&&!this.isInRect(g)||g.pointerType==="touch"&&!I||(xt&&console.log(g.pointerType,"MOVE",g.button),this.updatePointerPosition(g),this.setPointerStateT(g.button,this._pointerEvent,g.source),this.onDispatchEvent("pointermove",g))}onUp(g){var C;if(((C=this._pointerIds)==null?void 0:C.length)>=g.button&&(this._pointerIds[g.button]=-1),!this._pointerPressed[g.button]){xt&&console.log(g.pointerType,"UP",g.button,"was not down");return}if(xt&&console.log(g.pointerType,"UP",g.button),this.setPointerState(g.button,this._pointerPressed,!1),this.setPointerStateT(g.button,this._pointerEvent,g.source),this.setPointerState(g.button,this._pointerUp,!0),this.updatePointerPosition(g),!this._pointerPositionDown[g.button]){xt&&tC("Received pointer up event without matching down event for button: "+g.button),console.warn("Received pointer up event without matching down event for button: "+g.button);return}const e=g.clientX-this._pointerPositionDown[g.button].x,t=g.clientY-this._pointerPositionDown[g.button].y;if(g.button>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(e)<5&&Math.abs(t)<5){this.setPointerState(g.button,this._pointerClick,!0);const o=this._pointerUpTime[g.button],s=this.context.time.time-o;s<this._doubleClickTimeThreshold&&s>0&&this.setPointerState(g.button,this._pointerDoubleClick,!0)}this._pointerUpTime[g.button]=this.context.time.time,this.onDispatchEvent("pointerup",g)}updatePointerPosition(g){for(;g.button>=this._pointerPositions.length;)this._pointerPositions.push(new $);for(;g.button>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new $);for(;g.button>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new $);const I=this._pointerPositionsLastFrame[g.button];I.copy(this._pointerPositions[g.button]);const e=g.clientX-I.x,t=g.clientY-I.y;this._pointerPositionsDelta[g.button].set(e,t),this._pointerPositions[g.button].x=g.clientX,this._pointerPositions[g.button].y=g.clientY;const C=g.clientX,o=g.clientY;for(;g.button>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new $);const s=this._pointerPositionsRC[g.button];s.set(C,o),this.convertScreenspaceToRaycastSpace(s)}getPointerIndex(g){const I=this._pointerIds;let e=-1;for(let t=0;t<I.length;t++){if(I[t]===g)return t;e===-1&&I[t]===-1&&(e=t)}return e!==-1?(I[e]=g,e):(I.push(g),I.length-1)}setPointerState(g,I,e){for(;I.length<=g;)I.push(!1);I[g]=e}setPointerStateT(g,I,e){for(;I.length<=g;)I.push(null);I[g]=e}onDispatchEvent(g,I){const e=Dg.Current;try{Dg.Current=this.context;const t=new Event(g);QB(t,I),this.dispatchEvent(t)}finally{Dg.Current=e}}}class _O{random(){return Math.random()}clamp(A,g,I){return A<g?g:A>I?I:A}clamp01(A){return this.clamp(A,0,1)}lerp(A,g,I){return I=I<0?0:I,I=I>1?1:I,A+(g-A)*I}inverseLerp(A,g,I){return(I-A)/(g-A)}remap(A,g,I,e,t){return e+(t-e)*(A-g)/(I-g)}moveTowards(A,g,I){return A+=I,(I<0&&A<g||I>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 gg=new _O;function PO(i,A,g){const I=i.length(),e=A.length(),t=gg.lerp(I,e,g);return i.lerp(A,g).normalize().multiplyScalar(t)}new UA().setFromAxisAngle(new M(0,1,0),Math.PI);const I0=new Ha(()=>new M,100);function Sg(i,A=null,g=!0){const I=A??I0.get();return i?i.parent?(g&&i.updateWorldMatrix(!0,!1),i.matrixWorldNeedsUpdate&&i.updateMatrixWorld(),I.setFromMatrixPosition(i.matrixWorld),I):I.copy(i.position):I.set(0,0,0)}function xe(i,A){if(!i)return;const g=I0.get();A!==g&&g.copy(A),((i==null?void 0:i.parent)??i).worldToLocal(g),i.position.set(g.x,g.y,g.z)}function bE(i,A,g,I){const e=I0.get();e.set(A,g,I),xe(i,e)}const $n=new UA,vE=new UA,Bw=new UA;function Vi(i,A=null){if(!i)return vE.set(0,0,0,1);const g=A??vE;return i.parent?(i.getWorldQuaternion(g),g):g.copy(i.quaternion)}function JC(i,A){if(!i)return;A!==$n&&$n.copy(A);const g=$n,I=i==null?void 0:i.parent;I==null||I.getWorldQuaternion(Bw),Bw.invert();const e=Bw.multiply(g);i.quaternion.set(e.x,e.y,e.z,e.w)}function WO(i,A,g,I,e){$n.set(A,g,I,e),JC(i,$n)}const rl=new M;new M;function fi(i,A=null){return i?i.parent?(i.getWorldScale(A??rl),A??rl):rl.copy(i.scale):rl.set(0,0,0)}new M;const vM=new Ce,xM=new Ce,jO=new M;function ZO(i){return i.getWorldQuaternion(vE),xM.setFromQuaternion(vE),xM}function zO(i,A){JC(i,vE.setFromEuler(A))}function dN(i){const A=ZO(i),g=jO;return g.set(A.x,A.y,A.z),g.x=gg.toDegrees(g.x),g.y=gg.toDegrees(g.y),g.z=gg.toDegrees(g.z),g}function DN(i,A,g,I,e=!0){e&&(A=gg.toRadians(A),g=gg.toRadians(g),I=gg.toRadians(I)),vM.set(A,g,I),$n.setFromEuler(vM),JC(i,$n)}function ey(i,A=!0){i&&(A?function g(I){console.groupCollapsed((I.name?I.name:"(no name : "+I.type+")")+" %o",I),I.children.forEach(g),console.groupEnd()}(i):i.traverse(function(g){for(var I="|___",e=g;e.parent!==null;)I=" "+I,e=e.parent;console.log(I+g.name+" <"+g.type+">")}))}function VO(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 Ra=class{static createBlitMaterial(A){return new Og({uniforms:{map:new SA(null)},vertexShader:this.vertex,fragmentShader:A})}static copyTexture(A,g){const I=g??this.blipMaterial;I.uniforms.map.value=A,I.needsUpdate=!0,I.uniformsNeedUpdate=!0;const e=this.mesh;e.material=I,e.frustumCulled=!1,this.scene.children.length=0,this.scene.add(e),this.renderer.setSize(A.image.width,A.image.height),this.renderer.clear(),this.renderer.render(this.scene,this.perspectiveCam);const t=new Lg(this.renderer.domElement);return t.name="Copy",t.needsUpdate=!0,t}static textureToCanvas(A,g){if(!A)return null;(g===!0||A.isCompressedTexture===!0)&&(A=XO(A));const I=A.image;if($O(I)){const e=document.createElement("canvas");e.width=I.width,e.height=I.height;const t=e.getContext("2d");return t?(t.drawImage(I,0,0,I.width,I.height,0,0,e.width,e.height),e):(console.error("Failed getting canvas 2d context"),null)}return null}};let Yt=Ra;Q(Yt,"planeGeometry",new Oe(2,2,1,1)),Q(Yt,"renderer",new QQ({antialias:!1})),Q(Yt,"perspectiveCam",new zg),Q(Yt,"scene",new Rt),Q(Yt,"vertex",`
3244
3244
  varying vec2 vUv;
3245
3245
  void main(){
3246
3246
  vUv = uv;
@@ -4738,7 +4738,7 @@ void main() {
4738
4738
  `,a=function(d,D,p){D=D||1024;let S=d.pos,y=-1,G=0,k="",N=String.fromCharCode.apply(null,new Uint16Array(d.subarray(S,S+128)));for(;0>(y=N.indexOf(r))&&G<D&&S<d.byteLength;)k+=N,G+=N.length,S+=128,N+=String.fromCharCode.apply(null,new Uint16Array(d.subarray(S,S+128)));return-1<y?(p!==!1&&(d.pos+=G+y+1),k+N.slice(0,y)):!1},E=function(d){const D=/^#\?(\S+)/,p=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,f=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,S=/^\s*FORMAT=(\S+)\s*$/,y=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,G={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let k,N;if(d.pos>=d.byteLength||!(k=a(d)))return o(1,"no header found");if(!(N=k.match(D)))return o(3,"bad initial token");for(G.valid|=1,G.programtype=N[1],G.string+=k+`
4739
4739
  `;k=a(d),k!==!1;){if(G.string+=k+`
4740
4740
  `,k.charAt(0)==="#"){G.comments+=k+`
4741
- `;continue}if((N=k.match(p))&&(G.gamma=parseFloat(N[1])),(N=k.match(f))&&(G.exposure=parseFloat(N[1])),(N=k.match(S))&&(G.valid|=2,G.format=N[1]),(N=k.match(y))&&(G.valid|=4,G.height=parseInt(N[1],10),G.width=parseInt(N[2],10)),G.valid&2&&G.valid&4)break}return G.valid&2?G.valid&4?G:o(3,"missing image size specifier"):o(3,"missing format specifier")},c=function(d,D,p){const f=D;if(f<8||f>32767||d[0]!==2||d[1]!==2||d[2]&128)return new Uint8Array(d);if(f!==(d[2]<<8|d[3]))return o(3,"wrong scanline width");const S=new Uint8Array(4*D*p);if(!S.length)return o(4,"unable to allocate buffer space");let y=0,G=0;const k=4*f,N=new Uint8Array(4),J=new Uint8Array(k);let F=p;for(;F>0&&G<d.byteLength;){if(G+4>d.byteLength)return o(1);if(N[0]=d[G++],N[1]=d[G++],N[2]=d[G++],N[3]=d[G++],N[0]!=2||N[1]!=2||(N[2]<<8|N[3])!=f)return o(3,"bad rgbe scanline format");let K=0,x;for(;K<k&&G<d.byteLength;){x=d[G++];const O=x>128;if(O&&(x-=128),x===0||K+x>k)return o(3,"bad scanline data");if(O){const _=d[G++];for(let gA=0;gA<x;gA++)J[K++]=_}else J.set(d.subarray(G,G+x),K),K+=x,G+=x}const T=f;for(let O=0;O<T;O++){let _=0;S[y]=J[O+_],_+=f,S[y+1]=J[O+_],_+=f,S[y+2]=J[O+_],_+=f,S[y+3]=J[O+_],y+=4}F--}return S},h=function(d,D,p,f){const S=d[D+3],y=Math.pow(2,S-128)/255;p[f+0]=d[D+0]*y,p[f+1]=d[D+1]*y,p[f+2]=d[D+2]*y,p[f+3]=1},l=function(d,D,p,f){const S=d[D+3],y=Math.pow(2,S-128)/255;p[f+0]=Tn.toHalfFloat(Math.min(d[D+0]*y,65504)),p[f+1]=Tn.toHalfFloat(Math.min(d[D+1]*y,65504)),p[f+2]=Tn.toHalfFloat(Math.min(d[D+2]*y,65504)),p[f+3]=Tn.toHalfFloat(1)},u=new Uint8Array(A);u.pos=0;const w=E(u);if(w!==-1){const d=w.width,D=w.height,p=c(u.subarray(u.pos),d,D);if(p!==-1){let f,S,y;switch(this.type){case ie:y=p.length/4;const G=new Float32Array(y*4);for(let N=0;N<y;N++)h(p,N*4,G,N*4);f=G,S=ie;break;case Ee:y=p.length/4;const k=new Uint16Array(y*4);for(let N=0;N<y;N++)l(p,N*4,k,N*4);f=k,S=Ee;break;default:console.error("THREE.RGBELoader: unsupported type: ",this.type);break}return{width:d,height:D,data:f,header:w.string,gamma:w.gamma,exposure:w.exposure,type:S}}}return null}setDataType(A){return this.type=A,this}load(A,g,I,e){function t(C,o){switch(C.type){case ie:case Ee:C.encoding=ZI,C.minFilter=vg,C.magFilter=vg,C.generateMipmaps=!1,C.flipY=!0;break}g&&g(C,o)}return super.load(A,t,I,e)}}const aL=EA("debugautosync"),ef=Symbol("syncerId");class G5{constructor(){Q(this,"_syncers",{})}getOrCreateSyncer(A){if(!A.guid)return null;if(this._syncers[A.guid])return this._syncers[A.guid];const g=new k5(A);return g[ef]=A.guid,this._syncers[g[ef]]=g,g}removeSyncer(A){delete this._syncers[A[ef]]}}const zG=new G5;class k5{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 I=this.changedProperties[g];delete this.changedProperties[g],this.data[g]=I}A.send(this.networkingKey,this.data)}onHandleReceiving(A){if(!this._isInit||!this.comp)return;const g=A.guid;if(!(g&&g!==this.comp.guid)){aL&&console.log("RECEIVED",this.comp.name,this.comp.guid,A);try{this._isReceiving=!0;for(const I in A){if(I==="guid")continue;const e=A[I];this.comp[I]=e}}catch(I){console.error(I)}finally{this._isReceiving=!1}}}}function M5(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 I of Object.keys(i))if(i[I]!==A[I]){g=!0;break}}}return g}const cE=Symbol("AutoSyncHandler");function U5(i){if(i[cE])return i[cE];const A=zG.getOrCreateSyncer(i);return A==null||A.init(i),i[cE]=A,A}function R5(i){const A=i[cE];A&&(zG.removeSyncer(A),A.destroy(),delete i[cE])}const QL=function(i){return function(A,g){let I=null,e;typeof i=="string"?e=A[i]:typeof i=="function"&&(e=i);const t=A,C=t.__internalAwake;aL&&console.log(g);const o=Symbol(g);t.__internalAwake=function(){if(this[o]!==void 0)return;this[o]=this[g],C.call(this),I=zG.getOrCreateSyncer(this);const n=Object.getOwnPropertyDescriptor(this,g);(n==null?void 0:n.set)===void 0&&Object.defineProperty(this,g,{set:function(B){var a;const r=this[o];this[o]=B,M5(B,r)&&(e==null?void 0:e.call(this,B,r))!==!1&&((a=U5(this))==null||a.notifyChanged(g,B))},get:function(){return this[o]},configurable:!0,enumerable:!0}),I==null||I.init(this)};const s=t.__internalDestroy;t.__internalDestroy=function(){R5(this),s.call(this)}}};var m5=Object.defineProperty,F5=Object.getOwnPropertyDescriptor,Bp=(i,A,g,I)=>{for(var e=I>1?void 0:I?F5(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&m5(A,g,e),e};const Sr=EA("debugskybox");class JB extends xA{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 g;this.context.scene.environment===this._prevLoadedEnvironment&&(this.context.scene.environment=this._prevEnvironment,mI.backgroundShouldBeTransparent(this.context)||(this.context.scene.background=this._prevBackground),this._prevLoadedEnvironment=void 0),this.unregisterDropEvents(),(g=this.context.mainCameraComponent)==null||g.applyClearFlags()}async setSkybox(g){var o;if(!g)return;if(!(g!=null&&g.endsWith(".hdr"))&&!g.endsWith(".exr")&&!g.endsWith(".jpg")&&!g.endsWith(".png")&&!g.endsWith(".jpeg")&&console.warn("Potentially invalid skybox url",this.url,"on",this.name),Sr&&console.log("Remote skybox url?: "+g),this._prevUrl===g&&this._prevLoadedEnvironment){this.applySkybox();return}else(o=this._prevLoadedEnvironment)==null||o.dispose(),this._prevLoadedEnvironment=void 0;this._prevUrl=g;const I=g.endsWith(".exr"),e=g.endsWith(".hdr");I?this._loader instanceof Ny||(this._loader=new Ny):e?this._loader instanceof om||(this._loader=new om):this._loader instanceof Xn||(this._loader=new Xn),Sr&&console.log("Loading skybox: "+g);const t=await this._loader.loadAsync(g);if(!t||!this.enabled)return;this.url=g;const C=g.lastIndexOf("/");t.name=g.substring(C>=0?C+1:0),this._loader instanceof Xn&&(t.encoding=Ag),this._prevLoadedEnvironment=t,this.applySkybox()}applySkybox(){var I;const g=this._prevLoadedEnvironment;g&&(g.mapping=Pa,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),Sr&&console.log("Set remote skybox",this.url),this.environment&&(this.context.scene.environment=g),this.background&&!mI.backgroundShouldBeTransparent(this.context)&&(this.context.scene.background=g),((I=this.context.mainCameraComponent)==null?void 0:I.backgroundBlurriness)!==void 0&&(this.context.scene.backgroundBlurriness=this.context.mainCameraComponent.backgroundBlurriness))}registerDropEvents(){this.dragOverEvent||(this.dragOverEvent=g=>{if(this.allowDrop&&g.dataTransfer)for(const I of g.dataTransfer.types)I==="text/uri-list"&&g.preventDefault()},this.dropEvent=g=>{var I,e,t,C;if(this.allowDrop&&(g.preventDefault(),!!g.dataTransfer)){for(const o of g.dataTransfer.types)if(o==="text/uri-list"){const s=g.dataTransfer.getData(o);Sr&&console.log(o,s);let n=(e=(I=new RegExp(/polyhaven.com\/asset_img\/.+?\/(?<name>.+)\.png/).exec(s))==null?void 0:I.groups)==null?void 0:e.name;if(n||(n=(C=(t=new RegExp(/polyhaven\.com\/a\/(?<name>.+)/).exec(s))==null?void 0:t.groups)==null?void 0:C.name),Sr&&console.log(n),n){const B="https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/"+n+"_1k.exr";this.setSkybox(B)}else console.warn("Could not resolve skybox name from dropped url",s)}}},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))}}Bp([QL("setSkybox"),U(URL)],JB.prototype,"url",2);Bp([U()],JB.prototype,"allowDrop",2);Bp([U()],JB.prototype,"background",2);Bp([U()],JB.prototype,"environment",2);var N5=Object.defineProperty,K5=Object.getOwnPropertyDescriptor,$Q=(i,A,g,I)=>{for(var e=I>1?void 0:I?K5(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&N5(A,g,e),e};const sm=EA("debugsceneswitcher"),hE="scene";Se.registerCallback(Xt.ContextRegistered,i=>{AS.observedAttributes.includes(hE)||AS.observedAttributes.push(hE)});const aa=Promise.resolve(!1);class Zo extends xA{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 g=>{if(!this.useHistory)return;let I=this.useHistory;try{this.useHistory=!1,await this.tryLoadFromQueryParam()}finally{this.useHistory=I}});Q(this,"normalizedSwipeThresholdX",.1);Q(this,"_didSwipe",!1);Q(this,"onPointerMove",g=>{if(!this._didSwipe&&g.button===0&&g.pointerType==="touch"&&this.context.input.getPointerPressedCount()===1){const I=this.context.input.getPointerPositionDelta(g.button);if(I){const e=I.x/this.context.domWidth;e>=this.normalizedSwipeThresholdX?(this._didSwipe=!0,this.selectPrev()):e<=-this.normalizedSwipeThresholdX&&(this._didSwipe=!0,this.selectNext())}}});Q(this,"onPointerUp",g=>{g.button===0&&(this._didSwipe=!1)});Q(this,"onKeyDown",g=>{if(!this.useKeyboard||!this.scenes)return;const I=g.key.toLowerCase();if(!I)return;const e=parseInt(I)-1;if(e>=0){this.trySelectSceneFromValue(e);return}switch(I){case"arrowright":case"d":this.selectNext();break;case"arrowleft":case"a":this.selectPrev();break}})}async start(){if(this._currentIndex===-1&&!await this.tryLoadFromQueryParam()){const g=this.context.domElement.getAttribute(hE);try{(g===null||!await this.trySelectSceneFromValue(g))&&this._currentIndex===-1&&this.select(0)}finally{}}}onEnable(){globalThis.addEventListener("popstate",this.onPopState),this.context.input.addEventListener(Eo.KeyDown,this.onKeyDown),this.context.input.addEventListener(Eo.PointerMove,this.onPointerMove),this.context.input.addEventListener(Eo.PointerUp,this.onPointerUp),this._engineElementOverserver||(this._engineElementOverserver=new MutationObserver(g=>{for(const I of g)if(I.type==="attributes"&&I.attributeName===hE){const e=this.context.domElement.getAttribute(hE);e!==null&&this.trySelectSceneFromValue(e)}})),this._engineElementOverserver.observe(this.context.domElement,{attributes:!0})}onDisable(){globalThis.removeEventListener("popstate",this.onPopState),this.context.input.removeEventListener(Eo.KeyDown,this.onKeyDown),this.context.input.removeEventListener(Eo.PointerMove,this.onPointerMove),this.context.input.removeEventListener(Eo.PointerUp,this.onPointerUp)}selectNext(){return this.select(this._currentIndex+1)}selectPrev(){return this.select(this._currentIndex-1)}select(g){var e;if(sm&&console.log("select",g),!((e=this.scenes)!=null&&e.length))return aa;if(g<0){if(this.clamp)return aa;g=this.scenes.length-1}else if(g>=this.scenes.length){if(this.clamp)return aa;g=0}const I=this.scenes[g];return this.switchScene(I)}async switchScene(g){var e,t;if(g===this._currentScene)return!0;this._currentScene&&this._currentScene.unload();const I=this._currentIndex=((e=this.scenes)==null?void 0:e.indexOf(g))??-1;this._currentScene=g;try{if(await g.loadAssetAsync(),!g.asset)return sm&&console.warn("Failed loading scene:",g),!1;if(this._currentIndex===I)return CA.add(g.asset,this.gameObject),(t=this.queryParameterName)!=null&&t.length&&um(this.queryParameterName,I.toString(),this.useHistory),!0}catch(C){console.error(C)}return!1}tryLoadFromQueryParam(){var I;if(!((I=this.queryParameterName)!=null&&I.length))return aa;const g=EA(this.queryParameterName);return typeof g=="boolean"?aa:this.trySelectSceneFromValue(g)}trySelectSceneFromValue(g){if(typeof g=="string"){const I=parseInt(g);if(I>=0&&I<this.scenes.length)return this.select(I);for(let e=0;e<this.scenes.length;e++)if(this.scenes[e].uri.toLowerCase().includes(g))return this.select(e)}else if(typeof g=="number"&&g>=0&&g<this.scenes.length)return this.select(g);return Ui()&&console.warn('Can not find scene: "'+g+'"',this),aa}}$Q([U(St)],Zo.prototype,"scenes",2);$Q([U()],Zo.prototype,"queryParameterName",2);$Q([U()],Zo.prototype,"clamp",2);$Q([U()],Zo.prototype,"useHistory",2);$Q([U()],Zo.prototype,"useKeyboard",2);$Q([U()],Zo.prototype,"useSwipe",2);function J5(){return new Promise((i,A)=>{let I=()=>{I!=null&&(document.removeEventListener("pointerdown",I),document.removeEventListener("click",I),document.removeEventListener("dragstart",I),document.removeEventListener("touchstart",I),i())};document.addEventListener("pointerdown",I),document.addEventListener("click",I),document.addEventListener("dragstart",I),document.addEventListener("touchstart",I)})}async function q5(i){await J5(),i()}var rL=(i=>(i[i.Quad=0]="Quad",i))(rL||{});class L5{static createPrimitive(A,g){let I;switch(A){case 0:const e=new Oe(1,1,1,1),t=(g==null?void 0:g.material)??new rI({color:16777215});I=new GA(e,t)}return g!=null&&g.name&&(I.name=g.name),I}}var b5=Object.defineProperty,v5=Object.getOwnPropertyDescriptor,nC=(i,A,g,I)=>{for(var e=I>1?void 0:I?v5(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&b5(A,g,e),e};const Gr=EA("debugvideo");var EL=(i=>(i[i.CameraFarPlane=0]="CameraFarPlane",i[i.CameraNearPlane=1]="CameraNearPlane",i[i.RenderTexture=2]="RenderTexture",i[i.MaterialOverride=3]="MaterialOverride",i))(EL||{});class ei extends xA{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);q5(()=>{this._receivedInput=!0,this.updateVideoElementSettings()}),this._targetObjects=[],EA("videoscreenspace")&&window.addEventListener("keydown",g=>{g.key==="f"&&(this.screenspace=!this.screenspace)})}get playbackSpeed(){var g;return((g=this._videoElement)==null?void 0:g.playbackRate)??this._playbackSpeed}set playbackSpeed(g){this._playbackSpeed=g,this._videoElement&&(this._videoElement.playbackRate=g)}get isLooping(){var g;return((g=this._videoElement)==null?void 0:g.loop)??this._isLooping}set isLooping(g){this._isLooping=g,this._videoElement&&(this._videoElement.loop=g)}get currentTime(){var g;return((g=this._videoElement)==null?void 0:g.currentTime)??this.time}set currentTime(g){this._videoElement?this._videoElement.currentTime=g:this.time=g}get isPlaying(){const g=this._videoElement;if(g){if(g.currentTime>0&&!g.paused&&!g.ended&&g.readyState>g.HAVE_CURRENT_DATA)return!0;if(g.srcObject&&g.srcObject.active)return!0}return!1}get crossOrigin(){var g;return((g=this._videoElement)==null?void 0:g.crossOrigin)??this._crossOrigin}set crossOrigin(g){this._crossOrigin=g,this._videoElement&&(g!==null?this._videoElement.setAttribute("crossorigin",g):this._videoElement.removeAttribute("crossorigin"))}get videoMaterial(){return this._videoMaterial}get videoTexture(){return this._videoTexture}get videoElement(){return this._videoElement}get muted(){var g;return((g=this._videoElement)==null?void 0:g.muted)??this._muted}set muted(g){this._muted=g,this._videoElement&&(this._videoElement.muted=g)}setVideo(g){this.clip=g,this.source=0,this._videoElement?(this._videoElement.srcObject=g,this._isPlaying&&this.play(),this.updateAspect()):this.create(!0)}setClipURL(g){this.url!==g&&(this.url=g,this.source=1,Gr&&console.log("set url",g),this._videoElement?(this._videoElement.src=g,this._isPlaying&&(this.stop(),this.play())):this.create(!0))}awake(){this.create(this.playOnAwake),window.addEventListener("visibilitychange",g=>{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 g,I;this.playOnAwake===!0&&this.handleBeginPlaying(!0),this.screenspace?(g=this._overlay)==null||g.start():(I=this._overlay)==null||I.stop()}onDisable(){this.pause()}onDestroy(){var g;this._videoElement&&((g=this._videoElement.parentElement)==null||g.removeChild(this._videoElement),this._videoElement=null),this._videoTexture&&(this._videoTexture.dispose(),this._videoTexture=null)}play(){var g,I,e;this._videoElement&&(this._isPlaying&&!((g=this._videoElement)!=null&&g.ended)&&!((I=this._videoElement)!=null&&I.paused)||(this._isPlaying=!0,this._receivedInput||(this._videoElement.muted=!0),this.updateVideoElementSettings(),(e=this._videoElement)==null||e.play().catch(t=>{var C;Gr&&console.error("Error playing video",t,"CODE="+t.code,(C=this.videoElement)==null?void 0:C.src,this),setTimeout(()=>{this._isPlaying&&!this.destroyed&&this.activeAndEnabled&&this.play()},1e3)}),Gr&&console.log("play",this._videoElement)))}stop(){this._isPlaying=!1,this._videoElement&&(this._videoElement.currentTime=0,this._videoElement.pause())}pause(){var g;this._isPlaying=!1,(g=this._videoElement)==null||g.pause()}create(g){var e,t;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(),(e=this.context.domElement)==null||e.prepend(this._videoElement),this.updateVideoElementStyles()),typeof I=="string"){this._videoElement.src=I;const C=(t=this._videoElement.captureStream)==null?void 0:t.call(this._videoElement);this.clip=C}else this._videoElement.srcObject=I;this._videoTexture||(this._videoTexture=new NF(this._videoElement)),this._videoTexture.flipY=!1,this._videoTexture.encoding=Ag,this.handleBeginPlaying(g),Gr&&console.log(this)}}updateAspect(){this.aspectMode!==0&&this.startCoroutine(this.updateAspectImpl())}get screenspace(){var g;return((g=this._overlay)==null?void 0:g.enabled)??!1}set screenspace(g){var I;if(g){if(!this._videoTexture)return;this._overlay||(this._overlay=new x5(this.context)),this._overlay.add(this._videoTexture)}else(I=this._overlay)==null||I.remove(this._videoTexture);this._overlay&&(this._overlay.enabled=g)}createVideoElement(){const g=document.createElement("video");return this._crossOrigin&&g.setAttribute("crossorigin",this._crossOrigin),Gr&&console.log("create video elment",g),g}handleBeginPlaying(g){var t,C;if(!this.enabled||!this._videoElement)return;this._targetObjects.length=0;let I=this.gameObject;switch(this.renderMode){case 3:I=(t=this.targetMaterialRenderer)==null?void 0:t.gameObject,I||(I=(C=CA.getComponent(this.gameObject,de))==null?void 0:C.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,EL[this.renderMode],this);return}const e=I.material;if(e)if(this._targetObjects.push(I),e!==this._videoMaterial&&(this._videoMaterial=e.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(),g&&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 g=!this._receivedInput&&this.audioOutputMode!==0;!g&&this._muted&&(g=!0),this._videoElement.muted=g,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 g=++this._updateAspectRoutineId,I=void 0,e=this.clip;for(;g===this._updateAspectRoutineId&&this.aspectMode!==0&&this.clip&&e===this.clip&&this._isPlaying;){if(!e||typeof e=="string")return;let t;for(const C of e.getVideoTracks()){const o=C.getSettings();if(o&&o.width&&o.height){t=o.width/o.height;break}else t=this.context.renderer.domElement.clientWidth/this.context.renderer.domElement.clientHeight}if(t===void 0){for(let C=0;C<10;C++)yield;if(!this.isPlaying)break;continue}if(I===t){yield;continue}for(const C of this._targetObjects){let o=1;if(C.parent){const s=fi(C.parent);o=s.x/s.y}switch(this.aspectMode){case 1:C.scale.y=1/t*C.scale.x*o;break;case 2:C.scale.x=t*C.scale.y*o;break}}for(let C=0;C<3;C++)yield}}}nC([U(qA)],ei.prototype,"renderer",2);nC([U()],ei.prototype,"playOnAwake",2);nC([U()],ei.prototype,"aspectMode",2);nC([U(URL)],ei.prototype,"clip",2);nC([U()],ei.prototype,"renderMode",2);nC([U()],ei.prototype,"targetMaterialProperty",2);nC([U(de)],ei.prototype,"targetMaterialRenderer",2);nC([U(Lg)],ei.prototype,"targetTexture",2);nC([U()],ei.prototype,"time",2);nC([U()],ei.prototype,"playbackSpeed",1);nC([U()],ei.prototype,"isLooping",1);class x5{constructor(A){Q(this,"context");Q(this,"_videos",[]);Q(this,"_screenspaceModeQuad");Q(this,"_isInScreenspaceMode",!1);Q(this,"_input");this.context=A,this._input=new Y5(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 e;if(this._isInScreenspaceMode||this._videos.length<0)return;const A=this._videos[this._videos.length-1];if(!A)return;if(this._isInScreenspaceMode=!0,!this._screenspaceModeQuad){if(this._screenspaceModeQuad=L5.createPrimitive(rL.Quad,{material:new H5(A)}),!this._screenspaceModeQuad)return;this._screenspaceModeQuad.geometry.scale(2,2,2)}const g=this._screenspaceModeQuad;this.context.scene.add(g),this.updateScreenspaceMaterialUniforms();const I=g.material;I==null||I.reset(),(e=this._input)==null||e.enable(I)}stop(){var A;this._isInScreenspaceMode=!1,this._screenspaceModeQuad&&((A=this._input)==null||A.disable(),this._screenspaceModeQuad.removeFromParent())}updateScreenspaceMaterialUniforms(){var g;const A=(g=this._screenspaceModeQuad)==null?void 0:g.material;A&&(A.screenAspect=this.context.domElement.clientWidth/this.context.domElement.clientHeight)}}class Y5{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=e=>{e.key==="Escape"&&this.overlay.stop()}),window.addEventListener("wheel",this._onMouseWheelFn=e=>{this.overlay.enabled&&(A.zoom+=e.deltaY*5e-4,e.preventDefault())},{passive:!1});const g=new $;window.addEventListener("mousemove",e=>{if(this.overlay.enabled&&this.context.input.getPointerPressed(0)){const t=new $(e.movementX,e.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",e=>{this.overlay.enabled&&this.context.input.getPointerPressed(0)&&this.context.input.getTouchesPressedCount()===1&&(g.set(e.movementX,e.movementY),g.multiplyScalar(A.zoom*-this.context.time.deltaTime*.05),A.offset=A.offset.add(g))});let I=0;window.addEventListener("touchstart",e=>{if(e.touches.length<2){this.context.time.time-I<.3&&this.overlay.stop(),I=this.context.time.time;return}this._isPinching=!0,this._lastPinch=0}),window.addEventListener("touchmove",e=>{if(!this._isPinching||!this._material)return;const t=e.touches[0],C=e.touches[1],o=t.clientX-C.clientX,s=t.clientY-C.clientY,n=Math.sqrt(o*o+s*s);if(this._lastPinch!==0){const B=n-this._lastPinch;this._material.zoom-=B*.004}this._lastPinch=n}),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 H5 extends Og{constructor(g){super();Q(this,"_offset",new $);this.uniforms={map:{value:g},screenAspect:{value:1},offsetScale:{value:new ng(0,0,1,1)}},this.vertexShader=`
4741
+ `;continue}if((N=k.match(p))&&(G.gamma=parseFloat(N[1])),(N=k.match(f))&&(G.exposure=parseFloat(N[1])),(N=k.match(S))&&(G.valid|=2,G.format=N[1]),(N=k.match(y))&&(G.valid|=4,G.height=parseInt(N[1],10),G.width=parseInt(N[2],10)),G.valid&2&&G.valid&4)break}return G.valid&2?G.valid&4?G:o(3,"missing image size specifier"):o(3,"missing format specifier")},c=function(d,D,p){const f=D;if(f<8||f>32767||d[0]!==2||d[1]!==2||d[2]&128)return new Uint8Array(d);if(f!==(d[2]<<8|d[3]))return o(3,"wrong scanline width");const S=new Uint8Array(4*D*p);if(!S.length)return o(4,"unable to allocate buffer space");let y=0,G=0;const k=4*f,N=new Uint8Array(4),J=new Uint8Array(k);let F=p;for(;F>0&&G<d.byteLength;){if(G+4>d.byteLength)return o(1);if(N[0]=d[G++],N[1]=d[G++],N[2]=d[G++],N[3]=d[G++],N[0]!=2||N[1]!=2||(N[2]<<8|N[3])!=f)return o(3,"bad rgbe scanline format");let K=0,x;for(;K<k&&G<d.byteLength;){x=d[G++];const O=x>128;if(O&&(x-=128),x===0||K+x>k)return o(3,"bad scanline data");if(O){const _=d[G++];for(let gA=0;gA<x;gA++)J[K++]=_}else J.set(d.subarray(G,G+x),K),K+=x,G+=x}const T=f;for(let O=0;O<T;O++){let _=0;S[y]=J[O+_],_+=f,S[y+1]=J[O+_],_+=f,S[y+2]=J[O+_],_+=f,S[y+3]=J[O+_],y+=4}F--}return S},h=function(d,D,p,f){const S=d[D+3],y=Math.pow(2,S-128)/255;p[f+0]=d[D+0]*y,p[f+1]=d[D+1]*y,p[f+2]=d[D+2]*y,p[f+3]=1},l=function(d,D,p,f){const S=d[D+3],y=Math.pow(2,S-128)/255;p[f+0]=Tn.toHalfFloat(Math.min(d[D+0]*y,65504)),p[f+1]=Tn.toHalfFloat(Math.min(d[D+1]*y,65504)),p[f+2]=Tn.toHalfFloat(Math.min(d[D+2]*y,65504)),p[f+3]=Tn.toHalfFloat(1)},u=new Uint8Array(A);u.pos=0;const w=E(u);if(w!==-1){const d=w.width,D=w.height,p=c(u.subarray(u.pos),d,D);if(p!==-1){let f,S,y;switch(this.type){case ie:y=p.length/4;const G=new Float32Array(y*4);for(let N=0;N<y;N++)h(p,N*4,G,N*4);f=G,S=ie;break;case Ee:y=p.length/4;const k=new Uint16Array(y*4);for(let N=0;N<y;N++)l(p,N*4,k,N*4);f=k,S=Ee;break;default:console.error("THREE.RGBELoader: unsupported type: ",this.type);break}return{width:d,height:D,data:f,header:w.string,gamma:w.gamma,exposure:w.exposure,type:S}}}return null}setDataType(A){return this.type=A,this}load(A,g,I,e){function t(C,o){switch(C.type){case ie:case Ee:C.encoding=ZI,C.minFilter=vg,C.magFilter=vg,C.generateMipmaps=!1,C.flipY=!0;break}g&&g(C,o)}return super.load(A,t,I,e)}}const aL=EA("debugautosync"),ef=Symbol("syncerId");class G5{constructor(){Q(this,"_syncers",{})}getOrCreateSyncer(A){if(!A.guid)return null;if(this._syncers[A.guid])return this._syncers[A.guid];const g=new k5(A);return g[ef]=A.guid,this._syncers[g[ef]]=g,g}removeSyncer(A){delete this._syncers[A[ef]]}}const zG=new G5;class k5{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 I=this.changedProperties[g];delete this.changedProperties[g],this.data[g]=I}A.send(this.networkingKey,this.data)}onHandleReceiving(A){if(!this._isInit||!this.comp)return;const g=A.guid;if(!(g&&g!==this.comp.guid)){aL&&console.log("RECEIVED",this.comp.name,this.comp.guid,A);try{this._isReceiving=!0;for(const I in A){if(I==="guid")continue;const e=A[I];this.comp[I]=e}}catch(I){console.error(I)}finally{this._isReceiving=!1}}}}function M5(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 I of Object.keys(i))if(i[I]!==A[I]){g=!0;break}}}return g}const cE=Symbol("AutoSyncHandler");function U5(i){if(i[cE])return i[cE];const A=zG.getOrCreateSyncer(i);return A==null||A.init(i),i[cE]=A,A}function R5(i){const A=i[cE];A&&(zG.removeSyncer(A),A.destroy(),delete i[cE])}const QL=function(i){return function(A,g){let I=null,e;typeof i=="string"?e=A[i]:typeof i=="function"&&(e=i);const t=A,C=t.__internalAwake;aL&&console.log(g);const o=Symbol(g);t.__internalAwake=function(){if(this[o]!==void 0)return;this[o]=this[g],C.call(this),I=zG.getOrCreateSyncer(this);const n=Object.getOwnPropertyDescriptor(this,g);(n==null?void 0:n.set)===void 0&&Object.defineProperty(this,g,{set:function(B){var a;const r=this[o];this[o]=B,M5(B,r)&&(e==null?void 0:e.call(this,B,r))!==!1&&((a=U5(this))==null||a.notifyChanged(g,B))},get:function(){return this[o]},configurable:!0,enumerable:!0}),I==null||I.init(this)};const s=t.__internalDestroy;t.__internalDestroy=function(){R5(this),s.call(this)}}};var m5=Object.defineProperty,F5=Object.getOwnPropertyDescriptor,Bp=(i,A,g,I)=>{for(var e=I>1?void 0:I?F5(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&m5(A,g,e),e};const Sr=EA("debugskybox");class JB extends xA{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 g;this.context.scene.environment===this._prevLoadedEnvironment&&(this.context.scene.environment=this._prevEnvironment,mI.backgroundShouldBeTransparent(this.context)||(this.context.scene.background=this._prevBackground),this._prevLoadedEnvironment=void 0),this.unregisterDropEvents(),(g=this.context.mainCameraComponent)==null||g.applyClearFlags()}async setSkybox(g){var o;if(!g)return;if(!(g!=null&&g.endsWith(".hdr"))&&!g.endsWith(".exr")&&!g.endsWith(".jpg")&&!g.endsWith(".png")&&!g.endsWith(".jpeg")&&console.warn("Potentially invalid skybox url",this.url,"on",this.name),Sr&&console.log("Remote skybox url?: "+g),this._prevUrl===g&&this._prevLoadedEnvironment){this.applySkybox();return}else(o=this._prevLoadedEnvironment)==null||o.dispose(),this._prevLoadedEnvironment=void 0;this._prevUrl=g;const I=g.endsWith(".exr"),e=g.endsWith(".hdr");I?this._loader instanceof Ny||(this._loader=new Ny):e?this._loader instanceof om||(this._loader=new om):this._loader instanceof Xn||(this._loader=new Xn),Sr&&console.log("Loading skybox: "+g);const t=await this._loader.loadAsync(g);if(!t||!this.enabled)return;this.url=g;const C=g.lastIndexOf("/");t.name=g.substring(C>=0?C+1:0),this._loader instanceof Xn&&(t.encoding=Ag),this._prevLoadedEnvironment=t,this.applySkybox()}applySkybox(){var I;const g=this._prevLoadedEnvironment;g&&(g.mapping=Pa,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),Sr&&console.log("Set remote skybox",this.url),this.environment&&(this.context.scene.environment=g),this.background&&!mI.backgroundShouldBeTransparent(this.context)&&(this.context.scene.background=g),((I=this.context.mainCameraComponent)==null?void 0:I.backgroundBlurriness)!==void 0&&(this.context.scene.backgroundBlurriness=this.context.mainCameraComponent.backgroundBlurriness))}registerDropEvents(){this.dragOverEvent||(this.dragOverEvent=g=>{if(this.allowDrop&&g.dataTransfer)for(const I of g.dataTransfer.types)I==="text/uri-list"&&g.preventDefault()},this.dropEvent=g=>{var I,e,t,C;if(this.allowDrop&&(g.preventDefault(),!!g.dataTransfer)){for(const o of g.dataTransfer.types)if(o==="text/uri-list"){const s=g.dataTransfer.getData(o);Sr&&console.log(o,s);let n=(e=(I=new RegExp(/polyhaven.com\/asset_img\/.+?\/(?<name>.+)\.png/).exec(s))==null?void 0:I.groups)==null?void 0:e.name;if(n||(n=(C=(t=new RegExp(/polyhaven\.com\/a\/(?<name>.+)/).exec(s))==null?void 0:t.groups)==null?void 0:C.name),Sr&&console.log(n),n){const B="https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/"+n+"_1k.exr";this.setSkybox(B)}else console.warn("Could not resolve skybox name from dropped url",s)}}},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))}}Bp([QL("setSkybox"),U(URL)],JB.prototype,"url",2);Bp([U()],JB.prototype,"allowDrop",2);Bp([U()],JB.prototype,"background",2);Bp([U()],JB.prototype,"environment",2);var N5=Object.defineProperty,K5=Object.getOwnPropertyDescriptor,$Q=(i,A,g,I)=>{for(var e=I>1?void 0:I?K5(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&N5(A,g,e),e};const sm=EA("debugsceneswitcher"),hE="scene";Se.registerCallback(Xt.ContextRegistered,i=>{AS.observedAttributes.includes(hE)||AS.observedAttributes.push(hE)});const aa=Promise.resolve(!1);class Zo extends xA{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 g=>{if(!this.useHistory)return;let I=this.useHistory;try{this.useHistory=!1,await this.tryLoadFromQueryParam()}finally{this.useHistory=I}});Q(this,"normalizedSwipeThresholdX",.1);Q(this,"_didSwipe",!1);Q(this,"onPointerMove",g=>{if(!this._didSwipe&&g.button===0&&g.pointerType==="touch"&&this.context.input.getPointerPressedCount()===1){const I=this.context.input.getPointerPositionDelta(g.button);if(I){const e=I.x/this.context.domWidth;e>=this.normalizedSwipeThresholdX?(this._didSwipe=!0,this.selectPrev()):e<=-this.normalizedSwipeThresholdX&&(this._didSwipe=!0,this.selectNext())}}});Q(this,"onPointerUp",g=>{g.button===0&&(this._didSwipe=!1)});Q(this,"onKeyDown",g=>{if(!this.useKeyboard||!this.scenes)return;const I=g.key.toLowerCase();if(!I)return;const e=parseInt(I)-1;if(e>=0){this.trySelectSceneFromValue(e);return}switch(I){case"arrowright":case"d":this.selectNext();break;case"arrowleft":case"a":this.selectPrev();break}})}async start(){if(this._currentIndex===-1&&!await this.tryLoadFromQueryParam()){const g=this.context.domElement.getAttribute(hE);try{(g===null||!await this.trySelectSceneFromValue(g))&&this._currentIndex===-1&&this.select(0)}finally{}}}onEnable(){globalThis.addEventListener("popstate",this.onPopState),this.context.input.addEventListener(Eo.KeyDown,this.onKeyDown),this.context.input.addEventListener(Eo.PointerMove,this.onPointerMove),this.context.input.addEventListener(Eo.PointerUp,this.onPointerUp),this._engineElementOverserver||(this._engineElementOverserver=new MutationObserver(g=>{for(const I of g)if(I.type==="attributes"&&I.attributeName===hE){const e=this.context.domElement.getAttribute(hE);e!==null&&this.trySelectSceneFromValue(e)}})),this._engineElementOverserver.observe(this.context.domElement,{attributes:!0})}onDisable(){globalThis.removeEventListener("popstate",this.onPopState),this.context.input.removeEventListener(Eo.KeyDown,this.onKeyDown),this.context.input.removeEventListener(Eo.PointerMove,this.onPointerMove),this.context.input.removeEventListener(Eo.PointerUp,this.onPointerUp)}selectNext(){return this.select(this._currentIndex+1)}selectPrev(){return this.select(this._currentIndex-1)}select(g){var e;if(sm&&console.log("select",g),!((e=this.scenes)!=null&&e.length))return aa;if(g<0){if(this.clamp)return aa;g=this.scenes.length-1}else if(g>=this.scenes.length){if(this.clamp)return aa;g=0}const I=this.scenes[g];return this.switchScene(I)}async switchScene(g){var e,t;if(g===this._currentScene)return!0;this._currentScene&&this._currentScene.unload();const I=this._currentIndex=((e=this.scenes)==null?void 0:e.indexOf(g))??-1;this._currentScene=g;try{if(await g.loadAssetAsync(),!g.asset)return sm&&console.warn("Failed loading scene:",g),!1;if(this._currentIndex===I)return CA.add(g.asset,this.gameObject),(t=this.queryParameterName)!=null&&t.length&&um(this.queryParameterName,I.toString(),this.useHistory),!0}catch(C){console.error(C)}return!1}tryLoadFromQueryParam(){var I;if(!((I=this.queryParameterName)!=null&&I.length))return aa;const g=EA(this.queryParameterName);return typeof g=="boolean"?aa:this.trySelectSceneFromValue(g)}trySelectSceneFromValue(g){if(typeof g=="string"){const I=parseInt(g);if(I>=0&&I<this.scenes.length)return this.select(I);for(let e=0;e<this.scenes.length;e++)if(this.scenes[e].uri.toLowerCase().includes(g))return this.select(e)}else if(typeof g=="number"&&g>=0&&g<this.scenes.length)return this.select(g);return Ui()&&console.warn('Can not find scene: "'+g+'"',this),aa}}$Q([U(St)],Zo.prototype,"scenes",2);$Q([U()],Zo.prototype,"queryParameterName",2);$Q([U()],Zo.prototype,"clamp",2);$Q([U()],Zo.prototype,"useHistory",2);$Q([U()],Zo.prototype,"useKeyboard",2);$Q([U()],Zo.prototype,"useSwipe",2);function J5(){return new Promise((i,A)=>{let I=()=>{I!=null&&(document.removeEventListener("pointerdown",I),document.removeEventListener("click",I),document.removeEventListener("dragstart",I),document.removeEventListener("touchstart",I),i())};document.addEventListener("pointerdown",I),document.addEventListener("click",I),document.addEventListener("dragstart",I),document.addEventListener("touchstart",I)})}async function q5(i){await J5(),i()}var rL=(i=>(i[i.Quad=0]="Quad",i))(rL||{});class L5{static createPrimitive(A,g){let I;switch(A){case 0:const e=new Oe(1,1,1,1),t=(g==null?void 0:g.material)??new rI({color:16777215});I=new GA(e,t)}return g!=null&&g.name&&(I.name=g.name),I}}var b5=Object.defineProperty,v5=Object.getOwnPropertyDescriptor,nC=(i,A,g,I)=>{for(var e=I>1?void 0:I?v5(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&b5(A,g,e),e};const Gr=EA("debugvideo");var EL=(i=>(i[i.CameraFarPlane=0]="CameraFarPlane",i[i.CameraNearPlane=1]="CameraNearPlane",i[i.RenderTexture=2]="RenderTexture",i[i.MaterialOverride=3]="MaterialOverride",i))(EL||{});class ei extends xA{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);q5(()=>{this._receivedInput=!0,this.updateVideoElementSettings()}),this._targetObjects=[],EA("videoscreenspace")&&window.addEventListener("keydown",g=>{g.key==="f"&&(this.screenspace=!this.screenspace)})}get playbackSpeed(){var g;return((g=this._videoElement)==null?void 0:g.playbackRate)??this._playbackSpeed}set playbackSpeed(g){this._playbackSpeed=g,this._videoElement&&(this._videoElement.playbackRate=g)}get isLooping(){var g;return((g=this._videoElement)==null?void 0:g.loop)??this._isLooping}set isLooping(g){this._isLooping=g,this._videoElement&&(this._videoElement.loop=g)}get currentTime(){var g;return((g=this._videoElement)==null?void 0:g.currentTime)??this.time}set currentTime(g){this._videoElement?this._videoElement.currentTime=g:this.time=g}get isPlaying(){const g=this._videoElement;if(g){if(g.currentTime>0&&!g.paused&&!g.ended&&g.readyState>g.HAVE_CURRENT_DATA)return!0;if(g.srcObject&&g.srcObject.active)return!0}return!1}get crossOrigin(){var g;return((g=this._videoElement)==null?void 0:g.crossOrigin)??this._crossOrigin}set crossOrigin(g){this._crossOrigin=g,this._videoElement&&(g!==null?this._videoElement.setAttribute("crossorigin",g):this._videoElement.removeAttribute("crossorigin"))}get videoMaterial(){return this._videoMaterial}get videoTexture(){return this._videoTexture}get videoElement(){return this._videoElement}get muted(){var g;return((g=this._videoElement)==null?void 0:g.muted)??this._muted}set muted(g){this._muted=g,this._videoElement&&(this._videoElement.muted=g)}setVideo(g){this.clip=g,this.source=0,this._videoElement?(this._videoElement.srcObject=g,this._isPlaying&&this.play(),this.updateAspect()):this.create(!0)}setClipURL(g){this.url!==g&&(this.url=g,this.source=1,Gr&&console.log("set url",g),this._videoElement?(this._videoElement.src=g,this._isPlaying&&(this.stop(),this.play())):this.create(!0))}awake(){this.create(this.playOnAwake),window.addEventListener("visibilitychange",g=>{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 g,I;this.playOnAwake===!0&&this.handleBeginPlaying(!0),this.screenspace?(g=this._overlay)==null||g.start():(I=this._overlay)==null||I.stop()}onDisable(){this.pause()}onDestroy(){var g;this._videoElement&&((g=this._videoElement.parentElement)==null||g.removeChild(this._videoElement),this._videoElement=null),this._videoTexture&&(this._videoTexture.dispose(),this._videoTexture=null)}play(){var g,I,e;this._videoElement&&(this._isPlaying&&!((g=this._videoElement)!=null&&g.ended)&&!((I=this._videoElement)!=null&&I.paused)||(this._isPlaying=!0,this._receivedInput||(this._videoElement.muted=!0),this.updateVideoElementSettings(),(e=this._videoElement)==null||e.play().catch(t=>{var C;Gr&&console.error("Error playing video",t,"CODE="+t.code,(C=this.videoElement)==null?void 0:C.src,this),setTimeout(()=>{this._isPlaying&&!this.destroyed&&this.activeAndEnabled&&this.play()},1e3)}),Gr&&console.log("play",this._videoElement)))}stop(){this._isPlaying=!1,this._videoElement&&(this._videoElement.currentTime=0,this._videoElement.pause())}pause(){var g;this._isPlaying=!1,(g=this._videoElement)==null||g.pause()}create(g){var e,t;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(),(e=this.context.domElement)==null||e.prepend(this._videoElement),this.updateVideoElementStyles()),typeof I=="string"){this._videoElement.src=I;const C=(t=this._videoElement.captureStream)==null?void 0:t.call(this._videoElement);this.clip=C}else this._videoElement.srcObject=I;this._videoTexture||(this._videoTexture=new NF(this._videoElement)),this._videoTexture.flipY=!1,this._videoTexture.encoding=Ag,this.handleBeginPlaying(g),Gr&&console.log(this)}}updateAspect(){this.aspectMode!==0&&this.startCoroutine(this.updateAspectImpl())}get screenspace(){var g;return((g=this._overlay)==null?void 0:g.enabled)??!1}set screenspace(g){var I;if(g){if(!this._videoTexture)return;this._overlay||(this._overlay=new x5(this.context)),this._overlay.add(this._videoTexture)}else(I=this._overlay)==null||I.remove(this._videoTexture);this._overlay&&(this._overlay.enabled=g)}createVideoElement(){const g=document.createElement("video");return this._crossOrigin&&g.setAttribute("crossorigin",this._crossOrigin),Gr&&console.log("create video elment",g),g}handleBeginPlaying(g){var t,C;if(!this.enabled||!this._videoElement)return;this._targetObjects.length=0;let I=this.gameObject;switch(this.renderMode){case 3:I=(t=this.targetMaterialRenderer)==null?void 0:t.gameObject,I||(I=(C=CA.getComponent(this.gameObject,de))==null?void 0:C.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,EL[this.renderMode],this);return}const e=I.material;if(e)if(this._targetObjects.push(I),e!==this._videoMaterial&&(this._videoMaterial=e.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(),g&&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 g=!this._receivedInput||this.audioOutputMode===0;!g&&this._muted&&(g=!0),this._videoElement.muted=g,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 g=++this._updateAspectRoutineId,I=void 0,e=this.clip;for(;g===this._updateAspectRoutineId&&this.aspectMode!==0&&this.clip&&e===this.clip&&this._isPlaying;){if(!e||typeof e=="string")return;let t;for(const C of e.getVideoTracks()){const o=C.getSettings();if(o&&o.width&&o.height){t=o.width/o.height;break}else t=this.context.renderer.domElement.clientWidth/this.context.renderer.domElement.clientHeight}if(t===void 0){for(let C=0;C<10;C++)yield;if(!this.isPlaying)break;continue}if(I===t){yield;continue}for(const C of this._targetObjects){let o=1;if(C.parent){const s=fi(C.parent);o=s.x/s.y}switch(this.aspectMode){case 1:C.scale.y=1/t*C.scale.x*o;break;case 2:C.scale.x=t*C.scale.y*o;break}}for(let C=0;C<3;C++)yield}}}nC([U(qA)],ei.prototype,"renderer",2);nC([U()],ei.prototype,"playOnAwake",2);nC([U()],ei.prototype,"aspectMode",2);nC([U(URL)],ei.prototype,"clip",2);nC([U()],ei.prototype,"renderMode",2);nC([U()],ei.prototype,"targetMaterialProperty",2);nC([U(de)],ei.prototype,"targetMaterialRenderer",2);nC([U(Lg)],ei.prototype,"targetTexture",2);nC([U()],ei.prototype,"time",2);nC([U()],ei.prototype,"playbackSpeed",1);nC([U()],ei.prototype,"isLooping",1);class x5{constructor(A){Q(this,"context");Q(this,"_videos",[]);Q(this,"_screenspaceModeQuad");Q(this,"_isInScreenspaceMode",!1);Q(this,"_input");this.context=A,this._input=new Y5(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 e;if(this._isInScreenspaceMode||this._videos.length<0)return;const A=this._videos[this._videos.length-1];if(!A)return;if(this._isInScreenspaceMode=!0,!this._screenspaceModeQuad){if(this._screenspaceModeQuad=L5.createPrimitive(rL.Quad,{material:new H5(A)}),!this._screenspaceModeQuad)return;this._screenspaceModeQuad.geometry.scale(2,2,2)}const g=this._screenspaceModeQuad;this.context.scene.add(g),this.updateScreenspaceMaterialUniforms();const I=g.material;I==null||I.reset(),(e=this._input)==null||e.enable(I)}stop(){var A;this._isInScreenspaceMode=!1,this._screenspaceModeQuad&&((A=this._input)==null||A.disable(),this._screenspaceModeQuad.removeFromParent())}updateScreenspaceMaterialUniforms(){var g;const A=(g=this._screenspaceModeQuad)==null?void 0:g.material;A&&(A.screenAspect=this.context.domElement.clientWidth/this.context.domElement.clientHeight)}}class Y5{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=e=>{e.key==="Escape"&&this.overlay.stop()}),window.addEventListener("wheel",this._onMouseWheelFn=e=>{this.overlay.enabled&&(A.zoom+=e.deltaY*5e-4,e.preventDefault())},{passive:!1});const g=new $;window.addEventListener("mousemove",e=>{if(this.overlay.enabled&&this.context.input.getPointerPressed(0)){const t=new $(e.movementX,e.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",e=>{this.overlay.enabled&&this.context.input.getPointerPressed(0)&&this.context.input.getTouchesPressedCount()===1&&(g.set(e.movementX,e.movementY),g.multiplyScalar(A.zoom*-this.context.time.deltaTime*.05),A.offset=A.offset.add(g))});let I=0;window.addEventListener("touchstart",e=>{if(e.touches.length<2){this.context.time.time-I<.3&&this.overlay.stop(),I=this.context.time.time;return}this._isPinching=!0,this._lastPinch=0}),window.addEventListener("touchmove",e=>{if(!this._isPinching||!this._material)return;const t=e.touches[0],C=e.touches[1],o=t.clientX-C.clientX,s=t.clientY-C.clientY,n=Math.sqrt(o*o+s*s);if(this._lastPinch!==0){const B=n-this._lastPinch;this._material.zoom-=B*.004}this._lastPinch=n}),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 H5 extends Og{constructor(g){super();Q(this,"_offset",new $);this.uniforms={map:{value:g},screenAspect:{value:1},offsetScale:{value:new ng(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 I;const g=CA.getComponent(this.gameObject,de);if(g)if(((I=g.sharedMaterial)==null?void 0:I.type)!=="ShadowMaterial"){const e=new vS;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(g){g&&(g.depthWrite=!1,g.stencilWrite=!1)}}hL([U()],hh.prototype,"mode",2);hL([U(lI)],hh.prototype,"shadowColor",2);var $5=Object.defineProperty,AX=Object.getOwnPropertyDescriptor,ap=(i,A,g,I)=>{for(var e=I>1?void 0:I?AX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&$5(A,g,e),e},cf;const lL=(cf=class extends xA{constructor(){super(...arguments);Q(this,"target",null);Q(this,"followFactor",.1);Q(this,"rotateFactor",.1);Q(this,"positionAxes",Lr.All);Q(this,"flipForward",!1);Q(this,"_firstUpdate",!0)}onBeforeRender(){this.updateNow(!1)}updateNow(A){if(!(!this.target||this.target===this.gameObject)){if(this.followFactor>0){const g=Sg(this.target),I=this._firstUpdate||A?1:gg.clamp01(this.context.time.deltaTime*this.followFactor),e=this.worldPosition;this.positionAxes&Lr.X&&(e.x=gg.lerp(e.x,g.x,I)),this.positionAxes&Lr.Y&&(e.y=gg.lerp(e.y,g.y,I)),this.positionAxes&Lr.Z&&(e.z=gg.lerp(e.z,g.z,I)),this.worldPosition=e}if(this.rotateFactor>0){const g=Vi(this.target);this.flipForward&&g.premultiply(lL._invertForward);const I=this._firstUpdate||A?1:gg.clamp01(this.context.time.deltaTime*this.rotateFactor);this.worldQuaternion=this.worldQuaternion.slerp(g,I)}this._firstUpdate=!1}}},Q(cf,"_invertForward",new UA().setFromAxisAngle(new M(0,1,0),Math.PI)),cf);let nn=lL;ap([U(qA)],nn.prototype,"target",2);ap([U()],nn.prototype,"followFactor",2);ap([U()],nn.prototype,"rotateFactor",2);ap([U()],nn.prototype,"positionAxes",2);class gX extends GA{constructor(A){const g=new IX(A),I=new Oe(g.image.width*.001,g.image.height*.001),e=new rI({map:g,toneMapped:!1,transparent:!0});super(I,e);function t(C){e.map.dispatchDOMEvent(C)}this.addEventListener("mousedown",t),this.addEventListener("mousemove",t),this.addEventListener("mouseup",t),this.addEventListener("click",t),this.dispose=function(){I.dispose(),e.dispose(),e.map.dispose(),Zy.delete(A),this.removeEventListener("mousedown",t),this.removeEventListener("mousemove",t),this.removeEventListener("mouseup",t),this.removeEventListener("click",t)}}}class IX extends mS{constructor(A){super(nm(A)),this.dom=A,this.anisotropy=16,this.encoding=Ag,this.minFilter=vg,this.magFilter=vg;const g=new MutationObserver(()=>{this.scheduleUpdate||(this.scheduleUpdate=setTimeout(()=>this.update(),16))}),I={attributes:!0,childList:!0,subtree:!0,characterData:!0};g.observe(A,I),this.observer=g}dispatchDOMEvent(A){A.data&&eX(this.dom,A.type,A.data.x,A.data.y)}update(){this.image=nm(this.dom),this.needsUpdate=!0,this.scheduleUpdate=null}dispose(){this.observer&&this.observer.disconnect(),this.scheduleUpdate=clearTimeout(this.scheduleUpdate),super.dispose()}}const Zy=new WeakMap;function nm(i){const A=document.createRange(),g=new wA;function I(a){const E=[];let c=!1;function h(){if(c&&(c=!1,a.restore()),E.length===0)return;let l=-1/0,u=-1/0,w=1/0,d=1/0;for(let D=0;D<E.length;D++){const p=E[D];l=Math.max(l,p.x),u=Math.max(u,p.y),w=Math.min(w,p.x+p.width),d=Math.min(d,p.y+p.height)}a.save(),a.beginPath(),a.rect(l,u,w-l,d-u),a.clip(),c=!0}return{add:function(l){E.push(l),h()},remove:function(){E.pop(),h()}}}function e(a,E,c,h){h!==""&&(a.textTransform==="uppercase"&&(h=h.toUpperCase()),B.font=a.fontWeight+" "+a.fontSize+" "+a.fontFamily,B.textBaseline="top",B.fillStyle=a.color,B.fillText(h,E,c+parseFloat(a.fontSize)*.1))}function t(a,E,c,h,l){c<2*l&&(l=c/2),h<2*l&&(l=h/2),B.beginPath(),B.moveTo(a+l,E),B.arcTo(a+c,E,a+c,E+h,l),B.arcTo(a+c,E+h,a,E+h,l),B.arcTo(a,E+h,a,E,l),B.arcTo(a,E,a+c,E,l),B.closePath()}function C(a,E,c,h,l,u){const w=a[E+"Width"],d=a[E+"Style"],D=a[E+"Color"];w!=="0px"&&d!=="none"&&D!=="transparent"&&D!=="rgba(0, 0, 0, 0)"&&(B.strokeStyle=D,B.lineWidth=parseFloat(w),B.beginPath(),B.moveTo(c,h),B.lineTo(c+l,h+u),B.stroke())}function o(a,E){let c=0,h=0,l=0,u=0;if(a.nodeType===Node.TEXT_NODE){A.selectNode(a);const d=A.getBoundingClientRect();c=d.left-s.left-.5,h=d.top-s.top-.5,l=d.width,u=d.height,e(E,c,h,a.nodeValue.trim())}else{if(a.nodeType===Node.COMMENT_NODE)return;if(a instanceof HTMLCanvasElement){if(a.style.display==="none")return;B.save();const d=window.devicePixelRatio;B.scale(1/d,1/d),B.drawImage(a,0,0),B.restore()}else{if(a.style.display==="none")return;const d=a.getBoundingClientRect();c=d.left-s.left-.5,h=d.top-s.top-.5,l=d.width,u=d.height,E=window.getComputedStyle(a),t(c,h,l,u,parseFloat(E.borderRadius));const D=E.backgroundColor;D!=="transparent"&&D!=="rgba(0, 0, 0, 0)"&&(B.fillStyle=D,B.fill());const p=["borderTop","borderLeft","borderBottom","borderRight"];let f=!0,S=null;for(const y of p){if(S!==null&&(f=E[y+"Width"]===E[S+"Width"]&&E[y+"Color"]===E[S+"Color"]&&E[y+"Style"]===E[S+"Style"]),f===!1)break;S=y}if(f===!0){const y=parseFloat(E.borderTopWidth);E.borderTopWidth!=="0px"&&E.borderTopStyle!=="none"&&E.borderTopColor!=="transparent"&&E.borderTopColor!=="rgba(0, 0, 0, 0)"&&(B.strokeStyle=E.borderTopColor,B.lineWidth=y,B.stroke())}else C(E,"borderTop",c,h,l,0),C(E,"borderLeft",c,h,0,u),C(E,"borderBottom",c,h+u,l,0),C(E,"borderRight",c+l,h,0,u);if(a instanceof HTMLInputElement){let y=E.accentColor;(y===void 0||y==="auto")&&(y=E.color),g.set(y);const k=Math.sqrt(.299*g.r**2+.587*g.g**2+.114*g.b**2)<.5?"white":"#111111";if(a.type==="radio"&&(t(c,h,l,u,u),B.fillStyle="white",B.strokeStyle=y,B.lineWidth=1,B.fill(),B.stroke(),a.checked&&(t(c+2,h+2,l-4,u-4,u),B.fillStyle=y,B.strokeStyle=k,B.lineWidth=2,B.fill(),B.stroke())),a.type==="checkbox"&&(t(c,h,l,u,2),B.fillStyle=a.checked?y:"white",B.strokeStyle=a.checked?k:y,B.lineWidth=1,B.stroke(),B.fill(),a.checked)){const N=B.textAlign;B.textAlign="center";const J={color:k,fontFamily:E.fontFamily,fontSize:u+"px",fontWeight:"bold"};e(J,c+l/2,h,"✔"),B.textAlign=N}if(a.type==="range"){const[N,J,F]=["min","max","value"].map(x=>parseFloat(a[x])),K=(F-N)/(J-N)*(l-u);t(c,h+u/4,l,u/2,u/4),B.fillStyle=k,B.strokeStyle=y,B.lineWidth=1,B.fill(),B.stroke(),t(c,h+u/4,K+u/2,u/2,u/4),B.fillStyle=y,B.fill(),t(c+K,h,u,u,u/2),B.fillStyle=y,B.fill()}(a.type==="color"||a.type==="text"||a.type==="number")&&(r.add({x:c,y:h,width:l,height:u}),e(E,c+parseInt(E.paddingLeft),h+parseInt(E.paddingTop),a.value),r.remove())}}}const w=E.overflow==="auto"||E.overflow==="hidden";w&&r.add({x:c,y:h,width:l,height:u});for(let d=0;d<a.childNodes.length;d++)o(a.childNodes[d],E);w&&r.remove()}const s=i.getBoundingClientRect();let n=Zy.get(i);n===void 0&&(n=document.createElement("canvas"),n.width=s.width,n.height=s.height,Zy.set(i,n));const B=n.getContext("2d"),r=new I(B);return o(i),n}function eX(i,A,g,I){const e={clientX:g*i.offsetWidth+i.offsetLeft,clientY:I*i.offsetHeight+i.offsetTop,view:i.ownerDocument.defaultView};window.dispatchEvent(new MouseEvent(A,e));const t=i.getBoundingClientRect();g=g*t.width+t.left,I=I*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&&I>s.top&&I<s.bottom&&(o.dispatchEvent(new MouseEvent(A,e)),o instanceof HTMLInputElement&&o.type==="range"&&(A==="mousedown"||A==="click"))){const[n,B]=["min","max"].map(c=>parseFloat(o[c])),r=s.width,E=(g-s.x)/r;o.value=n+(B-n)*E,o.dispatchEvent(new InputEvent("input",{bubbles:!0}))}for(let n=0;n<o.childNodes.length;n++)C(o.childNodes[n])}}C(i)}const kd=new $,Qa={type:"",data:kd};class iX extends zt{constructor(A,g){super();const I=this,e=new dQ,t=new ZA,C=A.domElement;function o(a){a.stopPropagation();const E=A.domElement.getBoundingClientRect();kd.x=(a.clientX-E.left)/E.width*2-1,kd.y=-(a.clientY-E.top)/E.height*2+1,e.setFromCamera(kd,g);const c=e.intersectObjects(I.children,!1);if(c.length>0){const h=c[0],l=h.object,u=h.uv;Qa.type=a.type,Qa.data.set(u.x,1-u.y),l.dispatchEvent(Qa)}}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 n(a){const E=a.target;t.identity().extractRotation(E.matrixWorld),e.ray.origin.setFromMatrixPosition(E.matrixWorld),e.ray.direction.set(0,0,-1).applyMatrix4(t);const c=e.intersectObjects(I.children,!1);if(c.length>0){const h=c[0],l=h.object,u=h.uv;Qa.type=s[a.type],Qa.data.set(u.x,1-u.y),l.dispatchEvent(Qa)}}const B=A.xr.getController(0);B.addEventListener("move",n),B.addEventListener("select",n),B.addEventListener("selectstart",n),B.addEventListener("selectend",n);const r=A.xr.getController(1);r.addEventListener("move",n),r.addEventListener("select",n),r.addEventListener("selectstart",n),r.addEventListener("selectend",n)}}class VG extends xA{constructor(){super(...arguments);Q(this,"id",null);Q(this,"keepAspect",!1)}start(){if(!this.id||!this.context.mainCamera)return;const g=document.getElementById(this.id);if(!g){console.warn('Could not find element with id "'+this.id+'"');return}g.style.display="block",g.style.visibility="hidden";const I=new iX(this.context.renderer,this.context.mainCamera);this.gameObject.add(I);const e=new gX(g);I.add(e),e.visible=!1,console.log(e);const t=e.material;t.transparent=!0,setTimeout(()=>{e.visible=!0;const C=dN(this.gameObject).clone();DN(this.gameObject,0,0,0),this.gameObject.updateMatrixWorld();const o=new Ai;o.setFromObject(I),this.setWorldRotation(C.x,C.y,C.z);const s=o.max.x-o.min.x,n=o.max.y-o.min.y;if(this.keepAspect){const r=s/n;s>n?e.scale.set(1/s,1/n/r,1):e.scale.set(1/s*r,1/n,1)}else e.scale.set(1/s,1/n,1);const B=this.gameObject.scale;e.scale.multiply(B)},1)}}var tX=Object.defineProperty,CX=Object.getOwnPropertyDescriptor,lh=(i,A,g,I)=>{for(var e=I>1?void 0:I?CX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&tX(A,g,e),e};const lE=EA("debugspatialtrigger"),Bm=new Ut,am=new Ut;function oX(i,A){return Bm.mask=i,am.mask=A,Bm.test(am)}class KC extends xA{constructor(){super(...arguments);Q(this,"triggerMask",0);Q(this,"onEnter");Q(this,"onStay");Q(this,"onExit");Q(this,"currentIntersected",[]);Q(this,"lastIntersected",[])}start(){lE&&console.log(this.name,this.triggerMask,this)}update(){this.currentIntersected.length=0;for(const g of dh.triggers)oX(g.triggerMask,this.triggerMask)&&g.test(this.gameObject)&&this.currentIntersected.push(g);for(let g=this.lastIntersected.length-1;g>=0;g--){const I=this.lastIntersected[g];this.currentIntersected.indexOf(I)<0&&(this.onExitTrigger(I),this.lastIntersected.splice(g,1))}for(const g of this.currentIntersected)this.lastIntersected.indexOf(g)<0&&this.onEnterTrigger(g),this.onStayTrigger(g);this.lastIntersected.length=0,this.lastIntersected.push(...this.currentIntersected)}onEnterTrigger(g){var I;lE&&console.log("ENTER TRIGGER",this.name,g.name,this,g),g.raiseOnEnterEvent(this),(I=this.onEnter)==null||I.invoke(this,g)}onExitTrigger(g){var I;lE&&console.log("EXIT TRIGGER",this.name,g.name,this,g),g.raiseOnExitEvent(this),(I=this.onExit)==null||I.invoke(this,g)}onStayTrigger(g){var I;g.raiseOnStayEvent(this),(I=this.onStay)==null||I.invoke(this,g)}}lh([U()],KC.prototype,"triggerMask",2);lh([U(Mi)],KC.prototype,"onEnter",2);lh([U(Mi)],KC.prototype,"onStay",2);lh([U(Mi)],KC.prototype,"onExit",2);var hf;const Md=(hf=class extends xA{constructor(){super(...arguments);Q(this,"triggerMask");Q(this,"boxHelper")}start(){lE&&console.log(this.name,this.triggerMask,this)}onEnable(){var A;Md.triggers.push(this),this.boxHelper||(this.boxHelper=CA.addNewComponent(this.gameObject,pt),(A=this.boxHelper)==null||A.showHelper(null,lE))}onDisable(){Md.triggers.splice(Md.triggers.indexOf(this),1)}test(A){return this.boxHelper?this.boxHelper.isInBox(A)??!1:!1}raiseOnEnterEvent(A){CA.foreachComponent(this.gameObject,g=>{g!==A&&g instanceof KC&&g.onEnterTrigger(this)},!1)}raiseOnStayEvent(A){CA.foreachComponent(this.gameObject,g=>{g!==A&&g instanceof KC&&g.onStayTrigger(this)},!1)}raiseOnExitEvent(A){CA.foreachComponent(this.gameObject,g=>{g!==A&&g instanceof KC&&g.onExitTrigger(this)},!1)}},Q(hf,"triggers",[]),hf);let dh=Md;lh([U()],dh.prototype,"triggerMask",2);var sX=Object.defineProperty,nX=Object.getOwnPropertyDescriptor,BX=(i,A,g,I)=>{for(var e=I>1?void 0:I?nX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&sX(A,g,e),e};const Wi=EA("debugspectator");class Qp extends xA{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(g){this._mode=g}get isSpectating(){var g;return((g=this._handler)==null?void 0:g.currentTarget)!==void 0}isSpectatingUser(g){var I;return((I=this.target)==null?void 0:I.userId)===g}isFollowedBy(g){var I;return(I=this.followers)==null?void 0:I.includes(g)}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(g){var I;if(this._handler){const e=(I=this._handler.currentTarget)==null?void 0:I.userId,t=this.context.players.getPlayerView(this.localId);g===void 0||this.context.isInXR===!1&&(t==null?void 0:t.currentObject)===g.currentObject?this._handler.currentTarget!==void 0&&(this._handler.disable(),CA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),this._networking.onSpectatedObjectChanged(g,e)):this._handler.currentTarget!==g&&(this._handler.set(g),CA.setActive(this.gameObject,!0),this.orbit&&(this.orbit.enabled=!1),this._networking.onSpectatedObjectChanged(g,e))}}get target(){var g;return(g=this._handler)==null?void 0:g.currentTarget}requestAllFollowMe(){this._networking.onRequestFollowMe()}get isSpectatingSelf(){var g,I;return this.isSpectating&&((g=this.target)==null?void 0:g.currentObject)===((I=this.context.players.getPlayerView(this.localId))==null?void 0:I.currentObject)}awake(){if(this._debug=new rX(this.context,this),this._networking=new hX(this.context,this),this._networking.awake(),CA.setActive(this.gameObject,!1),this.cam=CA.getComponent(this.gameObject,mI),!this.cam){console.error("Spectator camera needs camera component",this);return}!this._handler&&this.cam&&(this._handler=new aX(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),Kg.addEventListener(ve.RequestVRSession,this.eventSub_WebXRRequestStartEvent),Kg.addEventListener(ve.XRStarted,this.eventSub_WebXRStartEvent),Kg.addEventListener(ve.XRStopped,this.eventSub_WebXREndEvent),this.orbit=CA.getComponent(this.context.mainCamera,gn)}onDestroy(){var g;this.stopSpectating(),Kg.removeEventListener(ve.RequestVRSession,this.eventSub_WebXRStartEvent),Kg.removeEventListener(ve.XRStarted,this.eventSub_WebXRStartEvent),Kg.removeEventListener(ve.XRStopped,this.eventSub_WebXREndEvent),(g=this._handler)==null||g.destroy(),this._networking.destroy()}isSupportedPlatform(){const g=window.navigator.userAgent,I=/Windows|MacOS/.test(g),e=/Windows NT/.test(g)&&/Edg/.test(g)&&!/Win64/.test(g);return I&&!e}onXRSessionRequestStart(g){this.isSupportedPlatform()&&CA.setActive(this.gameObject,!0)}onXRSessionStart(g){this.isSupportedPlatform()&&(Wi&&console.log(this.context.mainCamera),this.context.mainCamera&&this.followSelf())}onXRSessionEnded(g){var I,e;this.context.removeCamera(this.cam),CA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),(I=this._handler)==null||I.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,Ro.Headset),this.target=this.context.players.getPlayerView(this.localId)),Wi&&console.log("Follow self",this.target)}onAfterRender(){var n,B,r;if(!this.cam)return;const g=this.context.renderer,I=g.xr.enabled;if(!g.xr.isPresenting&&!((n=this._handler)!=null&&n.currentTarget))return;(B=this._handler)==null||B.update(this._mode);const e=g.getRenderTarget();let t=null;if(!e){if(!g.state.bindFramebuffer||!g.state.bindXRFramebuffer)return;t=g._framebuffer,g.state.bindXRFramebuffer(null)}this.setAvatarFlagsBeforeRender();const C=this.context.mainCameraComponent;if(C){const a=C.backgroundColor;a&&g.setClearColor(a,a.alpha),this.cam.backgroundColor=a,this.cam.clearFlags=C.clearFlags,this.cam.nearClipPlane=C.nearClipPlane,this.cam.farClipPlane=C.farClipPlane}else g.setClearColor(new wA(1,1,1));g.setRenderTarget(null),g.xr.enabled=!1;const o=(r=this.cam)==null?void 0:r.cam;this.context.updateAspect(o);const s=g.xr.isPresenting;g.xr.isPresenting=!1,g.setSize(this.context.domWidth,this.context.domHeight),g.render(this.context.scene,o),g.xr.isPresenting=s,g.xr.enabled=I,e?g.setRenderTarget(e):g.state.bindXRFramebuffer(t),this.resetAvatarFlags()}setAvatarFlagsBeforeRender(){const g=this._mode===0;for(const I of Me.instances)if(I.avatar&&"isLocalAvatar"in I.avatar){let e=re.All;this.isSpectatingSelf&&(e=g&&I.avatar.isLocalAvatar?re.FirstPerson:re.ThirdPerson);const t=I.avatar.flags;if(!t)continue;for(const C of t)C.UpdateVisible(e)}}resetAvatarFlags(){var g;for(const I of Me.instances)if(I.avatar&&"flags"in I.avatar){const e=I.avatar.flags;if(!e)continue;for(const t of e)(g=I.avatar)!=null&&g.isLocalAvatar?t.UpdateVisible(re.FirstPerson):t.UpdateVisible(re.ThirdPerson)}}}BX([U()],Qp.prototype,"useKeys",2);class aX{constructor(A,g,I){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=I}get currentTarget(){return this.view}set(A){const g=A==null?void 0:A.currentObject;if(!g){this.spectator.stopSpectating();return}g!==this.currentObject&&(this.currentObject=g,this.view=A,this.follow||(this.follow=CA.addNewComponent(this.cam.gameObject,nn)),this.target||(this.target=new qA),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&&CA.destroy(this.follow)}update(A){var e,t,C,o,s,n;if(((e=this.currentTarget)==null?void 0:e.isConnected)===!1||((t=this.currentTarget)==null?void 0:t.removed)===!0){Wi&&console.log("Target disconnected or timeout",this.currentTarget),this.spectator.stopSpectating();return}this.currentTarget&&((C=this.currentTarget)==null?void 0:C.currentObject)!==this.currentObject&&(Wi&&console.log("Target changed",this.currentObject,"to",this.currentTarget.currentObject),this.set(this.currentTarget));const g=this.context.mainCamera;g&&(this.cam.cam.near!==g.near||this.cam.cam.far!==g.far)&&(this.cam.cam.near=g.near,this.cam.cam.far=g.far,this.cam.cam.updateProjectionMatrix());const I=(o=this.follow)==null?void 0:o.target;if(!(!I||!this.follow)){switch(A){case 0:((s=this.view)==null?void 0:s.viewDevice)!==Ro.Browser?(this.follow.followFactor=5,this.follow.rotateFactor=5):(this.follow.followFactor=50,this.follow.rotateFactor=50),I.position.set(0,0,0);break;case 1:this.follow.followFactor=3,this.follow.rotateFactor=2,I.position.set(0,.5,1.5);break}this.follow.flipForward=!1,((n=this.view)==null?void 0:n.viewDevice)!==Ro.Browser?I.quaternion.copy(QX):I.quaternion.identity()}}}const QX=new UA().setFromAxisAngle(new M(0,1,0),Math.PI);class rX{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",e=>{if(!this.spectator.useKeys)return;e.key==="Escape"&&this.spectator.stopSpectating()});let I=0;this.context.input.addEventListener(Eo.PointerDown,e=>{I=this.context.time.time}),this.context.input.addEventListener(Eo.PointerUp,e=>{const t=this.context.time.time-I;t>1?this.spectator.stopSpectating():this.context.input.getPointerClicked(0)&&t<.3&&this.trySelectObject()})}trySelectObject(){const A=new TC;A.setMask(16777215);const g=this.context.physics.raycast(A);if(Wi&&console.log(...g),g!=null&&g.length)for(const I of g){if(I.distance<.2)continue;const e=I.object,t=CA.getComponentInParent(e,Me),C=t==null?void 0:t.connectionId;if(C){const o=this.context.players.getPlayerView(C);this.spectator.target=o,Wi&&console.log("spectate",C,t);break}}}}class EX{constructor(A,g,I){Q(this,"guid");Q(this,"dontSave",!0);Q(this,"targetUserId");Q(this,"stoppedFollowing");this.guid=A,this.targetUserId=g,this.stoppedFollowing=I}}class cX{constructor(A,g){Q(this,"guid");Q(this,"userId");this.guid=A.guid,this.userId=g}}class hX{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(WI.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(WI.JoinedRoom,this._joinedRoomMethod)}onSpectatedObjectChanged(A,g){if(Wi&&console.log(this.context.connection.connectionId,"onSpectatedObjectChanged",A,g),this.context.connection.connectionId){const I=(A==null?void 0:A.userId)===void 0,e=I?g:A==null?void 0:A.userId,t=new EX(this.context.connection.connectionId,e,I);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,I=new cX(this.spectator,g);this.context.connection.send("spectator-request-follow",I)}}onUserJoinedRoom(){EA("followme")&&this.onRequestFollowMe()}onFollowerEvent(A){const g=A.targetUserId,I=A.guid;if(Wi&&console.log(A),g===this.context.connection.connectionId)if(A.stoppedFollowing){const e=this.followers.indexOf(I);e!==-1&&(this.followers.splice(e,1),this.removeDisconnectedFollowers(),console.log(I,"unfollows you",this.followers.length))}else this.followers.includes(I)||(this.followers.push(I),this.removeDisconnectedFollowers(),console.log(I,"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 lX=Object.defineProperty,dX=Object.getOwnPropertyDescriptor,Jt=(i,A,g,I)=>{for(var e=I>1?void 0:I?dX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&lX(A,g,e),e};const zy=EA("debugspriterenderer"),DX=EA("wireframe"),fD=class{static getOrCreateGeometry(A){if(A._geometry)return A._geometry;if(A.guid&&fD.cache[A.guid])return zy&&console.log("Take cached geometry for sprite",A.guid),fD.cache[A.guid];const g=new lg;A._geometry=g;const I=new Float32Array(A.triangles.length*3),e=new Float32Array(A.triangles.length*2);for(let t=0;t<A.triangles.length;t+=1){const C=A.triangles[t];I[t*3]=-A.vertices[C].x,I[t*3+1]=A.vertices[C].y,I[t*3+2]=0;const o=A.uv[C];e[t*2]=o.x,e[t*2+1]=1-o.y}return g.setAttribute("position",new Qg(I,3)),g.setAttribute("uv",new Qg(e,2)),A.guid&&(this.cache[A.guid]=g),zy&&console.log("Built sprite geometry",A,g),g}};let dE=fD;Q(dE,"cache",{});class Vo{constructor(){Q(this,"guid");Q(this,"texture");Q(this,"triangles");Q(this,"uv");Q(this,"vertices");Q(this,"_geometry")}}Jt([U()],Vo.prototype,"guid",2);Jt([U(Lg)],Vo.prototype,"texture",2);Jt([kQ()],Vo.prototype,"triangles",2);Jt([kQ()],Vo.prototype,"uv",2);Jt([kQ()],Vo.prototype,"vertices",2);const tf=Symbol("spriteOwner");class Dh{constructor(){Q(this,"sprites")}}Jt([U(Vo)],Dh.prototype,"sprites",2);class Ar{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 I=g==null?void 0:g.texture;I&&(I.encoding=Ag,I.minFilter==Zg&&I.magFilter==Zg&&(I.anisotropy=1),I.needsUpdate=!0)}}Jt([U(Dh)],Ar.prototype,"spriteSheet",2);Jt([U()],Ar.prototype,"index",2);class qB extends xA{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(g){if(g!==this._spriteSheet)if(typeof g=="number"){const I=Math.floor(g);I===g&&(this.spriteIndex=I);return}else this._spriteSheet=g,this.updateSprite()}set spriteIndex(g){this._spriteSheet&&(this._spriteSheet.index=g,this.updateSprite())}get spriteIndex(){var g;return((g=this._spriteSheet)==null?void 0:g.index)??0}get spriteFrames(){var g,I;return((I=(g=this._spriteSheet)==null?void 0:g.spriteSheet)==null?void 0:I.sprites.length)??0}awake(){this._currentSprite=void 0,zy&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(){var I,e,t;if(!this.__didAwake||!((e=(I=this.sprite)==null?void 0:I.spriteSheet)!=null&&e.sprites))return;const g=this.sprite.spriteSheet.sprites[this.spriteIndex];if(this._currentSprite)this._currentSprite.geometry=dE.getOrCreateGeometry(g),this._currentSprite.material.map=g.texture;else{const C=new rI({color:16777215,side:fI});if(!C)return;if(DX&&(C.wireframe=!0),this.color&&(C.color||(C.color=new wA),C.color.copy(this.color),C.opacity=this.color.alpha),C.transparent=!0,g.texture&&!C.wireframe){let o=g.texture;o[tf]!==void 0&&o[tf]!==this&&this.spriteFrames>1&&(o=g.texture=o.clone()),o[tf]=this,C.map=o}this.sharedMaterial=C,this._currentSprite=new GA(dE.getOrCreateGeometry(g),C)}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)),(t=this._spriteSheet)==null||t.update()}}Jt([U()],qB.prototype,"drawMode",2);Jt([U(lI)],qB.prototype,"color",2);Jt([U(Fg)],qB.prototype,"sharedMaterial",2);Jt([U(Ar)],qB.prototype,"sprite",1);class fC{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 fC).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedCameraModel(A,g){return A.setPosition(A.position()+du),(g||new fC).__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 $i).__init(this.bb_pos+g,this.bb):null}rot(A){const g=this.bb.__offset(this.bb_pos,12);return g?(A||new $i).__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 uX=Object.defineProperty,pX=Object.getOwnPropertyDescriptor,wX=(i,A,g,I)=>{for(var e=I>1?void 0:I?pX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&uX(A,g,e),e};const dD="SCAM";R0(dD,fC.getRootAsSyncedCameraModel);const bi=new SQ;class fX{constructor(A,g){Q(this,"userId");Q(this,"guid");this.guid=g,this.userId=A}send(A,g){if(A){bi.clear();const I=bi.createString(this.guid),e=bi.createString(this.userId);fC.startSyncedCameraModel(bi),fC.addGuid(bi,I),fC.addUserId(bi,e);const t=Sg(A),C=dN(A);fC.addPos(bi,$i.createVec3(bi,t.x,t.y,t.z)),fC.addRot(bi,$i.createVec3(bi,C.x,C.y,C.z));const o=fC.endSyncedCameraModel(bi);bi.finish(o,dD),g.sendBinary(bi.asUint8Array())}}}var lf;const Vy=(lf=class extends xA{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(A){const g=this.userToCamMap[A];return g?this.remoteCams[g].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(dD,this.onReceivedRemoteCameraInfoBin.bind(this))}onDisable(){this.context.connection.stopListenBinary(dD,this._receiveCallback)}update(){for(const e in this.remoteCams){const t=this.remoteCams[e],C=this.context.time.realtimeSinceStartup-t.lastUpdate;if(!t||C>this._camTimeoutInSeconds){console.log("Remote cam timeout",t,C),t!=null&&t.obj&&CA.destroy(t.obj),delete this.remoteCams[e],t&&delete this.userToCamMap[t.userId],Vy.instances.push(t),this.context.players.removePlayerView(t.userId,Ro.Browser);continue}}if(Kg.IsInWebXR)return;const A=this.context.mainCamera;if(A===null){this.enabled=!1;return}if(!this.context.connection.isConnected||this.context.connection.connectionId===null)return;this._model===null&&(this._model=new fX(this.context.connection.connectionId,this.context.connection.connectionId+"_camera"));const g=Sg(A),I=Vi(A);(g.distanceTo(this._lastWorldPosition)>.001||I.angleTo(this._lastWorldQuaternion)>.01)&&(this._needsUpdate=!0),this._lastWorldPosition.copy(g),this._lastWorldQuaternion.copy(I),!((!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(A,this.context.connection),this.context.isInXR||this.context.players.setPlayerView(this.context.connection.connectionId,A,Ro.Browser))}onReceivedRemoteCameraInfoBin(A){const g=A.guid();if(!g)return;const I=A.userId();if(!I||!this.context.connection.userIsInRoom(I)||!this.cameraPrefab)return;let e=this.remoteCams[g];if(!e)if("isObject3D"in this.cameraPrefab){const s=new qC;s.context=this.context;const n=CA.instantiate(this.cameraPrefab,s);e=this.remoteCams[g]={obj:n,lastUpdate:this.context.time.realtimeSinceStartup,userId:I},e.obj.visible=!0,this.gameObject.add(n),this.userToCamMap[I]=g,Vy.instances.push(e);const B=CA.getOrAddComponent(n,Me);B.connectionId=I,B.avatar=n}else return;const t=e.obj;this.context.players.setPlayerView(I,t,Ro.Browser),e.lastUpdate=this.context.time.realtimeSinceStartup,Gi.markDirty(t);const C=A.pos();C&&bE(t,C.x(),C.y(),C.z());const o=A.rot();o&&DN(t,o.x(),o.y(),o.z())}},Q(lf,"instances",[]),lf);let rp=Vy;wX([U([qA,St])],rp.prototype,"cameraPrefab",2);var yX=Object.defineProperty,SX=Object.getOwnPropertyDescriptor,uh=(i,A,g,I)=>{for(var e=I>1?void 0:I?SX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&yX(A,g,e),e};const Cf="view",vl=EA("debugsyncedroom");class Bn extends xA{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(){vl&&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 g=EA(Cf);if(g&&typeof g=="string"&&g.length>0){console.log("Join as viewer"),this.context.connection.joinRoom(g,!0);return}this.tryJoinRoom()}onDisable(){this.roomName&&this.roomName.length>0&&this.context.connection.leaveRoom(this.roomName)}tryJoinRoom(g=0){g===void 0&&(g=0);let I=!1;if(this.urlParameterName){const e=EA(this.urlParameterName);if(e&&typeof e=="string"){I=!0;const t=bL(e);this.roomName=t}else if(this.joinRandomRoom&&(console.log("No room name found in url, generating random one"),this.setRandomRoomUrlParameter(),g<1))return this.tryJoinRoom(g+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&&!I?(vl&&console.log('No required room parameter "'+this.urlParameterName+'" in url - will not connect to networking backend.'),!1):!this.roomName||this.roomName.length<=0?(vl&&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(),vl&&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(){const g=EA(Cf);return g||EA(this.urlParameterName)}setRandomRoomUrlParameter(){const g=SD(),I=this.generateRoomName();EA(this.urlParameterName)?g.set(this.urlParameterName,I):g.append(this.urlParameterName,I),pm(I,g)}generateRoomName(){return LL()+"_"+qL(100,999)}getViewOnlyUrl(){if(this.context.connection.isConnected&&this.context.connection.currentRoomViewId){const g=window.location.search,I=new URLSearchParams(g);return I.has(this.urlParameterName)&&I.delete(this.urlParameterName),I.set(Cf,this.context.connection.currentRoomViewId),window.location.origin+window.location.pathname+"?"+I.toString()}return null}}uh([U()],Bn.prototype,"roomName",2);uh([U()],Bn.prototype,"urlParameterName",2);uh([U()],Bn.prototype,"joinRandomRoom",2);uh([U()],Bn.prototype,"requireRoomParameter",2);uh([U()],Bn.prototype,"autoRejoin",2);function GX(){const i=EA("testwindowcount")||0;i&&i>0&&kX(i)}function kX(i){if(EA("testwindow"))return null;const A=new URL(window.location.href);SE(A.searchParams,QD,1),SE(A.searchParams,"testwindow",1);const g=A.toString(),I=[];window.onbeforeunload=()=>{for(const s of I)s.close()};const e=.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 n=C*(t*(1+e))+window.screenLeft,B=o*(t*(1+e))+window.screenTop+90+60*o;C+=1;const r=window.open(g,"test window "+s,`popup=yes width=${t} height=${t} top=${B} left=${n}`);if(!r){console.warn("Failed to open window");continue}I.push(r),r.onload=()=>{r.onbeforeunload=()=>{for(let a=0;a<I.length;a++){const E=I[a];E!==r&&E.close()}I.length=0}}}return I}class XG extends xA{awake(){GX()}}class $G extends xA{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(Ac,g=>{});else{this.models=[];for(let g=0;g<this.transformsPerFrame;g++)this.models.push(new dL(this.context.connection.connectionId+"_simulatedTransform_"+g,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 SQ(1024));const g=this.builder;for(let I=0;I<this.transformsPerFrame;I++){g.clear();const e=Qq(this.context.connection.connectionId,this);this.context.connection.sendBinary(e)}}else if(this.models)for(let g=0;g<this.models.length;g++){const I=this.models[g];I.dontSave=!0,I.update(this,null),this.context.connection.send("TestSimulateUserData-"+g,I)}}}}class dL{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 I=A.worldPosition;this.position.x=I.x,this.position.y=I.y,this.position.z=I.z;const e=A.worldQuaternion;if(this.rotation.x=e.x,this.rotation.y=e.y,this.rotation.z=e.z,this.rotation.w=e.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(dL,"temp",new M);var MX=Object.defineProperty,UX=Object.getOwnPropertyDescriptor,gr=(i,A,g,I)=>{for(var e=I>1?void 0:I?UX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&MX(A,g,e),e};class VC extends Ni{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=Jo.MEDIUM,this.resolutionScale.defaultValue=1/window.devicePixelRatio}onCreateEffect(){console.log(this);const g=new Q3({kernelSize:Jo.VERY_LARGE});return this.offset.onValueChanged=I=>g.offset=I,this.rotation.onValueChanged=I=>g.rotation=I,this.focusArea.onValueChanged=I=>g.focusArea=I,this.feather.onValueChanged=I=>g.feather=I,this.kernelSize.onValueChanged=I=>g.blurPass.kernelSize=I,this.resolutionScale.onValueChanged=I=>g.resolution.scale=I/window.devicePixelRatio,g}}gr([U(Ng)],VC.prototype,"offset",2);gr([U(Ng)],VC.prototype,"rotation",2);gr([U(Ng)],VC.prototype,"focusArea",2);gr([U(Ng)],VC.prototype,"feather",2);gr([U(Ng)],VC.prototype,"kernelSize",2);gr([U(Ng)],VC.prototype,"resolutionScale",2);PC("TiltShiftEffect",VC);var RX=Object.defineProperty,mX=Object.getOwnPropertyDescriptor,FX=(i,A,g,I)=>{for(var e=I>1?void 0:I?mX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&RX(A,g,e),e};class ph extends Ni{constructor(){super(...arguments);Q(this,"mode")}get typeName(){return"ToneMapping"}get isToneMapping(){return!0}init(){this.mode.defaultValue=ri}apply(){this.mode.onValueChanged=this._apply.bind(this),this._apply(this.mode.value)}unapply(){this.context.renderer.toneMapping=ri}_apply(g){switch(g){case 0:this.context.renderer.toneMapping=ME;break;case 1:this.context.renderer.toneMapping=BS;break;case 2:this.context.renderer.toneMapping=aS;break}}}FX([U(Ng)],ph.prototype,"mode",2);PC("Tonemapping",ph);const pn=new dQ,pi=new M,hs=new M,SI=new UA,Qm={X:new M(1,0,0),Y:new M(0,1,0),Z:new M(0,0,1)},of={type:"change"},rm={type:"mouseDown"},Em={type:"mouseUp",mode:null},cm={type:"objectChange"};class NX extends qA{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 I=new vX;this._gizmo=I,this.add(I);const e=new xX;this._plane=e,this.add(e);const t=this;function C(w,d){let D=d;Object.defineProperty(t,w,{get:function(){return D!==void 0?D:d},set:function(p){D!==p&&(D=p,e[w]=p,I[w]=p,t.dispatchEvent({type:w+"-changed",value:p}),t.dispatchEvent(of))}}),t[w]=d,e[w]=d,I[w]=d}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,n=new UA,B=new UA,r=new M,a=new UA,E=new M,c=new M,h=new M,l=0,u=new M;C("worldPosition",o),C("worldPositionStart",s),C("worldQuaternion",n),C("worldQuaternionStart",B),C("cameraPosition",r),C("cameraQuaternion",a),C("pointStart",E),C("pointEnd",c),C("rotationAxis",h),C("rotationAngle",l),C("eye",u),this._offset=new M,this._startNorm=new M,this._endNorm=new M,this._cameraScale=new M,this._parentPosition=new M,this._parentQuaternion=new UA,this._parentQuaternionInv=new UA,this._parentScale=new M,this._worldScaleStart=new M,this._worldQuaternionInv=new UA,this._worldScale=new M,this._positionStart=new M,this._quaternionStart=new UA,this._scaleStart=new M,this._getPointer=KX.bind(this),this._onPointerDown=qX.bind(this),this._onPointerHover=JX.bind(this),this._onPointerMove=LX.bind(this),this._onPointerUp=bX.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;pn.setFromCamera(A,this.camera);const g=sf(this._gizmo.picker[this.mode],pn);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){pn.setFromCamera(A,this.camera);const g=sf(this._plane,pn,!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,rm.mode=this.mode,this.dispatchEvent(rm)}}pointerMove(A){const g=this.axis,I=this.mode,e=this.object;let t=this.space;if(I==="scale"?t="local":(g==="E"||g==="XYZE"||g==="XYZ")&&(t="world"),e===void 0||g===null||this.dragging===!1||A.button!==-1)return;pn.setFromCamera(A,this.camera);const C=sf(this._plane,pn,!0);if(C){if(this.pointEnd.copy(C.point).sub(this.worldPositionStart),I==="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),e.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(t==="local"&&(e.position.applyQuaternion(SI.copy(this._quaternionStart).invert()),g.search("X")!==-1&&(e.position.x=Math.round(e.position.x/this.translationSnap)*this.translationSnap),g.search("Y")!==-1&&(e.position.y=Math.round(e.position.y/this.translationSnap)*this.translationSnap),g.search("Z")!==-1&&(e.position.z=Math.round(e.position.z/this.translationSnap)*this.translationSnap),e.position.applyQuaternion(this._quaternionStart)),t==="world"&&(e.parent&&e.position.add(pi.setFromMatrixPosition(e.parent.matrixWorld)),g.search("X")!==-1&&(e.position.x=Math.round(e.position.x/this.translationSnap)*this.translationSnap),g.search("Y")!==-1&&(e.position.y=Math.round(e.position.y/this.translationSnap)*this.translationSnap),g.search("Z")!==-1&&(e.position.z=Math.round(e.position.z/this.translationSnap)*this.translationSnap),e.parent&&e.position.sub(pi.setFromMatrixPosition(e.parent.matrixWorld))));else if(I==="scale"){if(g.search("XYZ")!==-1){let o=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(o*=-1),hs.set(o,o,o)}else pi.copy(this.pointStart),hs.copy(this.pointEnd),pi.applyQuaternion(this._worldQuaternionInv),hs.applyQuaternion(this._worldQuaternionInv),hs.divide(pi),g.search("X")===-1&&(hs.x=1),g.search("Y")===-1&&(hs.y=1),g.search("Z")===-1&&(hs.z=1);e.scale.copy(this._scaleStart).multiply(hs),this.scaleSnap&&(g.search("X")!==-1&&(e.scale.x=Math.round(e.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),g.search("Y")!==-1&&(e.scale.y=Math.round(e.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),g.search("Z")!==-1&&(e.scale.z=Math.round(e.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(I==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const o=20/this.worldPosition.distanceTo(pi.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(pi.copy(this.rotationAxis).cross(this.eye))*o):(g==="X"||g==="Y"||g==="Z")&&(this.rotationAxis.copy(Qm[g]),pi.copy(Qm[g]),t==="local"&&pi.applyQuaternion(this.worldQuaternion),this.rotationAngle=this._offset.dot(pi.cross(this.eye).normalize())*o),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),t==="local"&&g!=="E"&&g!=="XYZE"?(e.quaternion.copy(this._quaternionStart),e.quaternion.multiply(SI.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),e.quaternion.copy(SI.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),e.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(of),this.dispatchEvent(cm)}}pointerUp(A){A.button===0&&(this.dragging&&this.axis!==null&&(Em.mode=this.mode,this.dispatchEvent(Em)),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(of),this.dispatchEvent(cm),this.pointStart.copy(this.pointEnd))}getRaycaster(){return pn}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 KX(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 JX(i){if(this.enabled)switch(i.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(i));break}}function qX(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 LX(i){this.enabled&&this.pointerMove(this._getPointer(i))}function bX(i){this.enabled&&(this.domElement.releasePointerCapture(i.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(i)))}function sf(i,A,g){const I=A.intersectObject(i,!0);for(let e=0;e<I.length;e++)if(I[e].object.visible||g)return I[e];return!1}const xl=new Ce,aI=new M(0,1,0),hm=new M(0,0,0),lm=new ZA,Yl=new UA,Ud=new UA,cC=new M,dm=new ZA,Or=new M(1,0,0),Rn=new M(0,1,0),_r=new M(0,0,1),Hl=new M,kr=new M,Mr=new M;class vX extends qA{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const A=new rI({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),g=new zI({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),I=A.clone();I.opacity=.15;const e=g.clone();e.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 n=A.clone();n.color.setHex(65280),n.opacity=.5;const B=A.clone();B.color.setHex(255),B.opacity=.5;const r=A.clone();r.opacity=.25;const a=A.clone();a.color.setHex(16776960),a.opacity=.25,A.clone().color.setHex(16776960);const c=A.clone();c.color.setHex(7895160);const h=new JI(0,.04,.1,12);h.translate(0,.05,0);const l=new sI(.08,.08,.08);l.translate(0,.04,0);const u=new lg;u.setAttribute("position",new tg([0,0,0,1,0,0],3));const w=new JI(.0075,.0075,.5,3);w.translate(0,.25,0);function d(x,T){const O=new yC(x,.0075,3,64,T*Math.PI*2);return O.rotateY(Math.PI/2),O.rotateX(Math.PI/2),O}function D(){const x=new lg;return x.setAttribute("position",new tg([0,0,0,1,1,1],3)),x}const p={X:[[new GA(h,t),[.5,0,0],[0,0,-Math.PI/2]],[new GA(h,t),[-.5,0,0],[0,0,Math.PI/2]],[new GA(w,t),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new GA(h,C),[0,.5,0]],[new GA(h,C),[0,-.5,0],[Math.PI,0,0]],[new GA(w,C)]],Z:[[new GA(h,o),[0,0,.5],[Math.PI/2,0,0]],[new GA(h,o),[0,0,-.5],[-Math.PI/2,0,0]],[new GA(w,o),null,[Math.PI/2,0,0]]],XYZ:[[new GA(new kC(.1,0),r.clone()),[0,0,0]]],XY:[[new GA(new sI(.15,.15,.01),B.clone()),[.15,.15,0]]],YZ:[[new GA(new sI(.15,.15,.01),s.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new GA(new sI(.15,.15,.01),n.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},f={X:[[new GA(new JI(.2,0,.6,4),I),[.3,0,0],[0,0,-Math.PI/2]],[new GA(new JI(.2,0,.6,4),I),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new GA(new JI(.2,0,.6,4),I),[0,.3,0]],[new GA(new JI(.2,0,.6,4),I),[0,-.3,0],[0,0,Math.PI]]],Z:[[new GA(new JI(.2,0,.6,4),I),[0,0,.3],[Math.PI/2,0,0]],[new GA(new JI(.2,0,.6,4),I),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new GA(new kC(.2,0),I)]],XY:[[new GA(new sI(.2,.2,.01),I),[.15,.15,0]]],YZ:[[new GA(new sI(.2,.2,.01),I),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new GA(new sI(.2,.2,.01),I),[.15,0,.15],[-Math.PI/2,0,0]]]},S={START:[[new GA(new kC(.01,2),e),null,null,null,"helper"]],END:[[new GA(new kC(.01,2),e),null,null,null,"helper"]],DELTA:[[new _I(D(),e),null,null,null,"helper"]],X:[[new _I(u,e.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new _I(u,e.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new _I(u,e.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},y={XYZE:[[new GA(d(.5,1),c),null,[0,Math.PI/2,0]]],X:[[new GA(d(.5,.5),t)]],Y:[[new GA(d(.5,.5),C),null,[0,0,-Math.PI/2]]],Z:[[new GA(d(.5,.5),o),null,[0,Math.PI/2,0]]],E:[[new GA(d(.75,1),a),null,[0,Math.PI/2,0]]]},G={AXIS:[[new _I(u,e.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},k={XYZE:[[new GA(new Ft(.25,10,8),I)]],X:[[new GA(new yC(.5,.1,4,24),I),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new GA(new yC(.5,.1,4,24),I),[0,0,0],[Math.PI/2,0,0]]],Z:[[new GA(new yC(.5,.1,4,24),I),[0,0,0],[0,0,-Math.PI/2]]],E:[[new GA(new yC(.75,.1,2,24),I)]]},N={X:[[new GA(l,t),[.5,0,0],[0,0,-Math.PI/2]],[new GA(w,t),[0,0,0],[0,0,-Math.PI/2]],[new GA(l,t),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new GA(l,C),[0,.5,0]],[new GA(w,C)],[new GA(l,C),[0,-.5,0],[0,0,Math.PI]]],Z:[[new GA(l,o),[0,0,.5],[Math.PI/2,0,0]],[new GA(w,o),[0,0,0],[Math.PI/2,0,0]],[new GA(l,o),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new GA(new sI(.15,.15,.01),B),[.15,.15,0]]],YZ:[[new GA(new sI(.15,.15,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new GA(new sI(.15,.15,.01),n),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new GA(new sI(.1,.1,.1),r.clone())]]},J={X:[[new GA(new JI(.2,0,.6,4),I),[.3,0,0],[0,0,-Math.PI/2]],[new GA(new JI(.2,0,.6,4),I),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new GA(new JI(.2,0,.6,4),I),[0,.3,0]],[new GA(new JI(.2,0,.6,4),I),[0,-.3,0],[0,0,Math.PI]]],Z:[[new GA(new JI(.2,0,.6,4),I),[0,0,.3],[Math.PI/2,0,0]],[new GA(new JI(.2,0,.6,4),I),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new GA(new sI(.2,.2,.01),I),[.15,.15,0]]],YZ:[[new GA(new sI(.2,.2,.01),I),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new GA(new sI(.2,.2,.01),I),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new GA(new sI(.2,.2,.2),I),[0,0,0]]]},F={X:[[new _I(u,e.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new _I(u,e.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new _I(u,e.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function K(x){const T=new qA;for(const O in x)for(let _=x[O].length;_--;){const gA=x[O][_][0].clone(),rA=x[O][_][1],cA=x[O][_][2],DA=x[O][_][3],IA=x[O][_][4];gA.name=O,gA.tag=IA,rA&&gA.position.set(rA[0],rA[1],rA[2]),cA&&gA.rotation.set(cA[0],cA[1],cA[2]),DA&&gA.scale.set(DA[0],DA[1],DA[2]),gA.updateMatrix();const BA=gA.geometry.clone();BA.applyMatrix4(gA.matrix),gA.geometry=BA,gA.renderOrder=1/0,gA.position.set(0,0,0),gA.rotation.set(0,0,0),gA.scale.set(1,1,1),T.add(gA)}return T}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=K(p)),this.add(this.gizmo.rotate=K(y)),this.add(this.gizmo.scale=K(N)),this.add(this.picker.translate=K(f)),this.add(this.picker.rotate=K(k)),this.add(this.picker.scale=K(J)),this.add(this.helper.translate=K(S)),this.add(this.helper.rotate=K(G)),this.add(this.helper.scale=K(F)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(A){const I=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:Ud;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 t=0;t<e.length;t++){const C=e[t];C.visible=!0,C.rotation.set(0,0,0),C.position.copy(this.worldPosition);let o;if(this.camera.isOrthographicCamera?o=(this.camera.top-this.camera.bottom)/this.camera.zoom:o=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),C.scale.set(1,1,1).multiplyScalar(o*this.size/4),C.tag==="helper"){C.visible=!1,C.name==="AXIS"?(C.position.copy(this.worldPositionStart),C.visible=!!this.axis,this.axis==="X"&&(SI.setFromEuler(xl.set(0,0,0)),C.quaternion.copy(I).multiply(SI),Math.abs(aI.copy(Or).applyQuaternion(I).dot(this.eye))>.9&&(C.visible=!1)),this.axis==="Y"&&(SI.setFromEuler(xl.set(0,0,Math.PI/2)),C.quaternion.copy(I).multiply(SI),Math.abs(aI.copy(Rn).applyQuaternion(I).dot(this.eye))>.9&&(C.visible=!1)),this.axis==="Z"&&(SI.setFromEuler(xl.set(0,Math.PI/2,0)),C.quaternion.copy(I).multiply(SI),Math.abs(aI.copy(_r).applyQuaternion(I).dot(this.eye))>.9&&(C.visible=!1)),this.axis==="XYZE"&&(SI.setFromEuler(xl.set(0,Math.PI/2,0)),aI.copy(this.rotationAxis),C.quaternion.setFromRotationMatrix(lm.lookAt(hm,aI,Rn)),C.quaternion.multiply(SI),C.visible=this.dragging),this.axis==="E"&&(C.visible=!1)):C.name==="START"?(C.position.copy(this.worldPositionStart),C.visible=this.dragging):C.name==="END"?(C.position.copy(this.worldPosition),C.visible=this.dragging):C.name==="DELTA"?(C.position.copy(this.worldPositionStart),C.quaternion.copy(this.worldQuaternionStart),pi.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),pi.applyQuaternion(this.worldQuaternionStart.clone().invert()),C.scale.copy(pi),C.visible=this.dragging):(C.quaternion.copy(I),this.dragging?C.position.copy(this.worldPositionStart):C.position.copy(this.worldPosition),this.axis&&(C.visible=this.axis.search(C.name)!==-1));continue}C.quaternion.copy(I),this.mode==="translate"||this.mode==="scale"?(C.name==="X"&&Math.abs(aI.copy(Or).applyQuaternion(I).dot(this.eye))>.99&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="Y"&&Math.abs(aI.copy(Rn).applyQuaternion(I).dot(this.eye))>.99&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="Z"&&Math.abs(aI.copy(_r).applyQuaternion(I).dot(this.eye))>.99&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="XY"&&Math.abs(aI.copy(_r).applyQuaternion(I).dot(this.eye))<.2&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="YZ"&&Math.abs(aI.copy(Or).applyQuaternion(I).dot(this.eye))<.2&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="XZ"&&Math.abs(aI.copy(Rn).applyQuaternion(I).dot(this.eye))<.2&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1)):this.mode==="rotate"&&(Yl.copy(I),aI.copy(this.eye).applyQuaternion(SI.copy(I).invert()),C.name.search("E")!==-1&&C.quaternion.setFromRotationMatrix(lm.lookAt(this.eye,hm,Rn)),C.name==="X"&&(SI.setFromAxisAngle(Or,Math.atan2(-aI.y,aI.z)),SI.multiplyQuaternions(Yl,SI),C.quaternion.copy(SI)),C.name==="Y"&&(SI.setFromAxisAngle(Rn,Math.atan2(aI.x,aI.z)),SI.multiplyQuaternions(Yl,SI),C.quaternion.copy(SI)),C.name==="Z"&&(SI.setFromAxisAngle(_r,Math.atan2(aI.y,aI.x)),SI.multiplyQuaternions(Yl,SI),C.quaternion.copy(SI))),C.visible=C.visible&&(C.name.indexOf("X")===-1||this.showX),C.visible=C.visible&&(C.name.indexOf("Y")===-1||this.showY),C.visible=C.visible&&(C.name.indexOf("Z")===-1||this.showZ),C.visible=C.visible&&(C.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),C.material._color=C.material._color||C.material.color.clone(),C.material._opacity=C.material._opacity||C.material.opacity,C.material.color.copy(C.material._color),C.material.opacity=C.material._opacity,this.enabled&&this.axis&&(C.name===this.axis||this.axis.split("").some(function(s){return C.name===s}))&&(C.material.color.setHex(16776960),C.material.opacity=1)}super.updateMatrixWorld(A)}}class xX extends GA{constructor(){super(new Oe(1e5,1e5,2,2),new rI({visible:!1,wireframe:!0,side:fI,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"),Hl.copy(Or).applyQuaternion(g==="local"?this.worldQuaternion:Ud),kr.copy(Rn).applyQuaternion(g==="local"?this.worldQuaternion:Ud),Mr.copy(_r).applyQuaternion(g==="local"?this.worldQuaternion:Ud),aI.copy(kr),this.mode){case"translate":case"scale":switch(this.axis){case"X":aI.copy(this.eye).cross(Hl),cC.copy(Hl).cross(aI);break;case"Y":aI.copy(this.eye).cross(kr),cC.copy(kr).cross(aI);break;case"Z":aI.copy(this.eye).cross(Mr),cC.copy(Mr).cross(aI);break;case"XY":cC.copy(Mr);break;case"YZ":cC.copy(Hl);break;case"XZ":aI.copy(Mr),cC.copy(kr);break;case"XYZ":case"E":cC.set(0,0,0);break}break;case"rotate":default:cC.set(0,0,0)}cC.length()===0?this.quaternion.copy(this.cameraQuaternion):(dm.lookAt(pi.set(0,0,0),cC,aI),this.quaternion.setFromRotationMatrix(dm)),super.updateMatrixWorld(A)}}var YX=Object.defineProperty,HX=Object.getOwnPropertyDescriptor,TX=(i,A,g,I)=>{for(var e=I>1?void 0:I?HX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&YX(A,g,e),e};class Ep extends xA{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&&!Rc||this.context.mainCamera&&(this.control=new NX(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(g=>{const I=g;if(I.layers.set(2),I){const e=I.material;e&&(e.opacity=.3)}}))}start(){if(this.context.mainCamera){const g=CA.getComponentInParent(this.context.mainCamera,sq)??void 0;this.orbit=g}}onEnable(){var g;this.control&&(this.context.scene.add(this.control),this.control.attach(this.gameObject)),this.changeEventListener=this.onControlChangedEvent.bind(this),(g=this.control)==null||g.addEventListener("dragging-changed",this.changeEventListener),this.attachWindowEvents()}onDisable(){var g,I;(g=this.control)==null||g.removeFromParent(),this.changeEventListener&&((I=this.control)==null||I.removeEventListener("dragging-changed",this.changeEventListener))}onControlChangedEvent(g){const I=this.orbit;if(I&&(I.enabled=!g.value),g.value){const e=CA.getComponentInParent(this.gameObject,Os);e&&e.requestOwnership()}}attachWindowEvents(){const g=this.control;g&&(this.windowKeyDownListener||(this.windowKeyDownListener=I=>{switch(I.keyCode){case 81:g.setSpace(g.space==="local"?"world":"local");break;case 16:g.setTranslationSnap(100),g.setRotationSnap(mi.degToRad(15)),g.setScaleSnap(.25);break;case 87:g.setMode("translate");break;case 69:g.setMode("rotate");break;case 82:g.setMode("scale");break;case 187:case 107:g.setSize(g.size+.1);break;case 189:case 109:g.setSize(Math.max(g.size-.1,.1));break;case 88:g.showX=!g.showX;break;case 89:g.showY=!g.showY;break;case 90:g.showZ=!g.showZ;break;case 32:g.enabled=!g.enabled;break}}),this.windowKeyUpListener||(this.windowKeyUpListener=I=>{switch(I.keyCode){case 16:g.setTranslationSnap(null),g.setRotationSnap(null),g.setScaleSnap(null);break}}),window.addEventListener("keydown",this.windowKeyDownListener),window.addEventListener("keyup",this.windowKeyUpListener))}}TX([U()],Ep.prototype,"isGizmo",2);function OX(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 I=document.createElement("button");I.id="open-in-ar",I.innerText="Open in QuickLook",g.appendChild(I);const e=document.createElement("a");e.id="needle-usdz-link",e.style.display="none",e.rel="ar",e.href="",g.appendChild(e);const t=document.createElement("img");return t.id="button",e.appendChild(t),i.domElement.appendChild(g),e}function _X(){var i=new Date;const A=i.getMonth()+1,g=i.getDate(),I=i.getHours(),e=i.getMinutes(),t=i.getSeconds(),C=(A<10?"0":"")+A,o=(g<10?"0":"")+g,s=(I<10?"0":"")+I,n=(e<10?"0":"")+e,B=(t<10?"0":"")+t;return i.getFullYear()+C+o+"-"+s+n+B}const Tl=EA("debugusdz");function PX(i,A){const g=[],I=CA.getComponentsInChildren(i,et);let e=!1;Tl&&console.log(I);for(const t of I){if(!t||!t.runtimeAnimatorController)continue;Tl&&console.log(t);const C=[];for(const o of t.runtimeAnimatorController.enumerateActions()){Tl&&console.log(o);const s=o.getClip();if(!e&&s.tracks.length>0){e=!0;const n=s.tracks[0],B=n.name.substring(0,n.name.lastIndexOf(".")),r=new At(B+".position",[0,.01],[0,0,0,0,0,0]),a=new At(B+".quaternion",[0,.01],[0,0,0,1,0,0,0,1]);C.push(new gC("rest",.01,[r,a]))}C.includes(s)||C.push(s)}g.push({root:t.gameObject,clips:C})}Tl&&console.log(g);for(const t of g)for(const C of t.clips)A.registerAnimation(t.root,C)}var WX=Object.defineProperty,jX=Object.getOwnPropertyDescriptor,DL=(i,A,g,I)=>{for(var e=I>1?void 0:I?jX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&WX(A,g,e),e};const Ur=EA("debugusdz");class wh extends xA{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 g;Ur&&(window.addEventListener("keydown",I=>{switch(I.key){case"t":this.exportAsync();break}}),oQ()&&setTimeout(()=>{this.exportAsync()},2e3)),(g=document.getElementById("open-in-ar"))==null||g.addEventListener("click",I=>{I.preventDefault(),this.exportAsync()}),this.objectToExport||(this.objectToExport=this.gameObject)}onEnable(){const g=kD(),I=iS();(Ur||g&&I)&&(this.createQuicklookButton(),this.webARSessionRoot=CA.findObjectOfType(An)??void 0,this.lastCallback=this.quicklookCallback.bind(this),this.link=OX(this.context),this.link.addEventListener("message",this.lastCallback))}onDisable(){var g;(g=this.link)==null||g.removeEventListener("message",this.lastCallback)}async exportAsync(){if(!this.objectToExport)return;if(this.webARSessionRoot){const E=this.webARSessionRoot.gameObject,c=1/this.webARSessionRoot.arScale;E.matrix.makeScale(c,c,c),this.webARSessionRoot.invertForward&&E.matrix.multiply(new ZA().makeRotationY(Math.PI))}const g=new bW,I=[...this.extensions],e=new yu;I.push(e),this.autoExportAnimations&&PX(this.objectToExport,e);const t={self:this,exporter:g,extensions:I,object:this.objectToExport};this.dispatchEvent(new CustomEvent("before-export",{detail:t}));let C="needle";Ur&&(C+="-"+_X()),g.debug=Ur;const o=await g.parse(this.objectToExport,I),s=new Blob([o],{type:"application/octet-stream"});this.dispatchEvent(new CustomEvent("after-export",{detail:t}));const n=this.buildQuicklookOverlay(),B=n.callToAction?encodeURIComponent(n.callToAction):"",r=n.checkoutTitle?encodeURIComponent(n.checkoutTitle):"",a=n.checkoutSubtitle?encodeURIComponent(n.checkoutSubtitle):"";this.link.href=URL.createObjectURL(s)+`#callToAction=${B}&checkoutTitle=${r}&checkoutSubtitle=${a}&`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=C+".usdz",this.link.click()}quicklookCallback(g){(g==null?void 0:g.data)=="_apple_ar_quicklook_button_tapped"&&(Ur&&tC("Quicklook closed via call to action button"),this.dispatchEvent(new CustomEvent("quicklook-button-tapped",{detail:this})))}buildQuicklookOverlay(){const g={};return g.callToAction="Close",g.checkoutTitle="🌵 Made with Needle",g.checkoutSubtitle="_",this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:g})),g}async createQuicklookButton(){var g,I;if(!this.webxr)if(await GD(1),this.webxr=CA.findObjectOfType(Kg)??void 0,this.webxr)if(this.webxr.VRButton&&((g=this.webxr.VRButton.parentElement)==null||g.removeChild(this.webxr.VRButton)),this.webxr.ARButton&&this._arButton!==this.webxr.ARButton){this._arButton=this.webxr.ARButton;const e=(I=this.webxr.ARButton.parentElement)==null?void 0:I.querySelector("a");e&&(e.href=""),this.webxr.ARButton.innerText="Open in Quicklook",this.webxr.ARButton.disabled=!1,this.webxr.ARButton.addEventListener("click",t=>{t.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 t=document.createElement("button");t.innerText="Open in Quicklook",t.addEventListener("click",()=>{this.exportAsync()}),t.classList.add("webxr-ar-button"),t.classList.add("webxr-button"),t.classList.add("quicklook-ar-button"),e.appendChild(t),this.dispatchEvent(new CustomEvent("created-button",{detail:t}))}else console.warn("Could not find WebXR component: will not create Quicklook button",Dg.Current)}resetStyles(g){g.style.position="",g.style.top="",g.style.left="",g.style.width="",g.style.height="",g.style.margin="",g.style.padding="",g.style.border="",g.style.background="",g.style.color="",g.style.font="",g.style.textAlign="",g.style.opacity="",g.style.zIndex=""}}DL([U(qA)],wh.prototype,"objectToExport",2);DL([U()],wh.prototype,"autoExportAnimations",2);var ZX=Object.defineProperty,zX=Object.getOwnPropertyDescriptor,Ak=(i,A,g,I)=>{for(var e=I>1?void 0:I?zX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&ZX(A,g,e),e};class LB extends Ni{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 g=new HK;return this.intensity.onValueChanged=I=>{g.offset=I,this.updateDarkness(g)},this.color.onValueChanged=I=>{this.updateDarkness(g)},g}updateDarkness(g){const I=this.intensity.value;g.darkness=I}}Ak([U(Ng)],LB.prototype,"color",2);Ak([U(Ng)],LB.prototype,"intensity",2);Ak([U(Ng)],LB.prototype,"center",2);PC("Vignette",LB);var VX=Object.defineProperty,XX=Object.getOwnPropertyDescriptor,$X=(i,A,g,I)=>{for(var e=I>1?void 0:I?XX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&VX(A,g,e),e};const nf=EA("debugpost");class cp extends xA{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 g;(g=this.sharedProfile)==null||g.init(),nf&&(console.log(this),console.log("Press P to toggle post processing"),window.addEventListener("keydown",I=>{I.key==="p"&&(console.log("Toggle volume: "+this.name,!this.enabled),this.enabled=!this.enabled)}))}onDisable(){var g;(g=this._postprocessing)==null||g.unapply()}onBeforeRender(){if(!this.context.isInXR){if(this.context.composer&&!(this.context.composer instanceof J0))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 g;(g=this._postprocessing)==null||g.dispose()}apply(){var I,e;nf&&console.log("Apply PostProcessing",this,(I=this.context.mainCamera)==null?void 0:I.name),uQ()&&(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,(e=this.sharedProfile)!=null&&e.components&&this._effects.push(...this.sharedProfile.components);const g=this.gameObject.getComponentsInChildren(Ni);if(nf&&(g!=null&&g.length)&&console.log("Additional",g),g)for(const t of g)t.active&&this._effects.push(t);this._effects.length>0&&(this._postprocessing||(this._postprocessing=new np(this.context)),this._postprocessing.apply(this._effects),this._applyPostQueue())}unapply(){var g;(g=this._postprocessing)==null||g.unapply()}_applyPostQueue(){if(this._modificationQueue){for(const g of this._modificationQueue.values())this.onEditorModification(g);this._modificationQueue.clear()}}onEditorModification(g){var I,e;if(g.propertyName.startsWith("postprocessing.")){if(!this._postprocessing)return this._modificationQueue||(this._modificationQueue=new Map),this._modificationQueue.set(g.propertyName,g),!0;if(!((I=this._effects)!=null&&I.length))return;const t=g.propertyName.split(".");if(t.length===3||t.length===4){const C=t[1],o=t[2];for(const s of this._effects)if(((e=s.typeName)==null?void 0:e.toLowerCase())===C.toLowerCase()){if(o==="active"){s.active=g.value,this.scheduleRecreate();return}if(!Ol.has(C)){const n=new Array;Ol.set(C,n);const B=Object.keys(s);for(const r of B)s[r]instanceof Ng&&n.push(r)}if(Ol.has(C)){const n=o.toLowerCase(),B=Ol.get(C);for(const r of B)if(r.toLowerCase()===n){const a=s[r];a instanceof Ng&&(t.length===4&&t[3]==="active"?(a.overrideState=g.value,this.scheduleRecreate()):a&&a.value!==void 0&&(a.value=g.value));return}}console.warn("Unknown modification",o);return}}return!0}return!1}scheduleRecreate(){const g=++this._recreateId;setTimeout(()=>{g===this._recreateId&&(this.onDisable(),this.onEnable())},200)}}$X([kQ(Ah)],cp.prototype,"sharedProfile",2);const Ol=new Map;var A9=Object.defineProperty,g9=Object.getOwnPropertyDescriptor,I9=(i,A,g,I)=>{for(var e=I>1?void 0:I?g9(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&A9(A,g,e),e};class hp extends xA{constructor(){super(...arguments);Q(this,"backgroundTint",new lI(1,1,1,1));Q(this,"_preRender");Q(this,"backgroundPlane");Q(this,"threeTexture");Q(this,"forceTextureInitialization",function(){const g=new rI,I=new Oe,e=new Rt;e.add(new GA(I,g));const t=new nQ;return function(o,s){g.map=s,o.render(e,t)}}())}awake(){Kg.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(g=>g!==this._preRender),this.backgroundPlane&&this.gameObject.remove(this.backgroundPlane)}preRender(){if(!this||!this.gameObject)return;const I=this.context.renderer.xr.getFrame();I&&(!this.threeTexture&&this.context.renderer&&(this.threeTexture=new Lg,this.forceTextureInitialization(this.context.renderer,this.threeTexture)),this.backgroundPlane===void 0&&(this.backgroundPlane=i9(this.backgroundTint),this.gameObject.add(this.backgroundPlane)),this.updateFromFrame(I))}onBeforeRender(g){this.updateFromFrame(g)}updateFromFrame(g){if(!g)return;const I=g.getViewerPose(this.context.renderer.xr.getReferenceSpace());if(I){for(const e of I.views)if("camera"in e&&e.camera){let C=this.context.renderer.xr.getBinding();if(C||(C=new XRWebGLBinding(g.session,this.context.renderer.getContext())),C){let o=null;if("getCameraImage"in C){o=C.getCameraImage(e.camera);const s=this.context.renderer.properties.get(this.threeTexture);s.__webglTexture=o,this.backgroundPlane&&(this.backgroundPlane.setTexture(this.threeTexture),this.backgroundPlane.visible=!0)}}}}}}I9([U()],hp.prototype,"backgroundTint",2);let e9=`
4801
+ `)}}}applyShadowMaterial(){var I;const g=CA.getComponent(this.gameObject,de);if(g)if(((I=g.sharedMaterial)==null?void 0:I.type)!=="ShadowMaterial"){const e=new vS;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(g){g&&(g.depthWrite=!1,g.stencilWrite=!1)}}hL([U()],hh.prototype,"mode",2);hL([U(lI)],hh.prototype,"shadowColor",2);var $5=Object.defineProperty,AX=Object.getOwnPropertyDescriptor,ap=(i,A,g,I)=>{for(var e=I>1?void 0:I?AX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&$5(A,g,e),e},cf;const lL=(cf=class extends xA{constructor(){super(...arguments);Q(this,"target",null);Q(this,"followFactor",.1);Q(this,"rotateFactor",.1);Q(this,"positionAxes",Lr.All);Q(this,"flipForward",!1);Q(this,"_firstUpdate",!0)}onBeforeRender(){this.updateNow(!1)}updateNow(A){if(!(!this.target||this.target===this.gameObject)){if(this.followFactor>0){const g=Sg(this.target),I=this._firstUpdate||A?1:gg.clamp01(this.context.time.deltaTime*this.followFactor),e=this.worldPosition;this.positionAxes&Lr.X&&(e.x=gg.lerp(e.x,g.x,I)),this.positionAxes&Lr.Y&&(e.y=gg.lerp(e.y,g.y,I)),this.positionAxes&Lr.Z&&(e.z=gg.lerp(e.z,g.z,I)),this.worldPosition=e}if(this.rotateFactor>0){const g=Vi(this.target);this.flipForward&&g.premultiply(lL._invertForward);const I=this._firstUpdate||A?1:gg.clamp01(this.context.time.deltaTime*this.rotateFactor);this.worldQuaternion=this.worldQuaternion.slerp(g,I)}this._firstUpdate=!1}}},Q(cf,"_invertForward",new UA().setFromAxisAngle(new M(0,1,0),Math.PI)),cf);let nn=lL;ap([U(qA)],nn.prototype,"target",2);ap([U()],nn.prototype,"followFactor",2);ap([U()],nn.prototype,"rotateFactor",2);ap([U()],nn.prototype,"positionAxes",2);class gX extends GA{constructor(A){const g=new IX(A),I=new Oe(g.image.width*.001,g.image.height*.001),e=new rI({map:g,toneMapped:!1,transparent:!0});super(I,e);function t(C){e.map.dispatchDOMEvent(C)}this.addEventListener("mousedown",t),this.addEventListener("mousemove",t),this.addEventListener("mouseup",t),this.addEventListener("click",t),this.dispose=function(){I.dispose(),e.dispose(),e.map.dispose(),Zy.delete(A),this.removeEventListener("mousedown",t),this.removeEventListener("mousemove",t),this.removeEventListener("mouseup",t),this.removeEventListener("click",t)}}}class IX extends mS{constructor(A){super(nm(A)),this.dom=A,this.anisotropy=16,this.encoding=Ag,this.minFilter=vg,this.magFilter=vg;const g=new MutationObserver(()=>{this.scheduleUpdate||(this.scheduleUpdate=setTimeout(()=>this.update(),16))}),I={attributes:!0,childList:!0,subtree:!0,characterData:!0};g.observe(A,I),this.observer=g}dispatchDOMEvent(A){A.data&&eX(this.dom,A.type,A.data.x,A.data.y)}update(){this.image=nm(this.dom),this.needsUpdate=!0,this.scheduleUpdate=null}dispose(){this.observer&&this.observer.disconnect(),this.scheduleUpdate=clearTimeout(this.scheduleUpdate),super.dispose()}}const Zy=new WeakMap;function nm(i){const A=document.createRange(),g=new wA;function I(a){const E=[];let c=!1;function h(){if(c&&(c=!1,a.restore()),E.length===0)return;let l=-1/0,u=-1/0,w=1/0,d=1/0;for(let D=0;D<E.length;D++){const p=E[D];l=Math.max(l,p.x),u=Math.max(u,p.y),w=Math.min(w,p.x+p.width),d=Math.min(d,p.y+p.height)}a.save(),a.beginPath(),a.rect(l,u,w-l,d-u),a.clip(),c=!0}return{add:function(l){E.push(l),h()},remove:function(){E.pop(),h()}}}function e(a,E,c,h){h!==""&&(a.textTransform==="uppercase"&&(h=h.toUpperCase()),B.font=a.fontWeight+" "+a.fontSize+" "+a.fontFamily,B.textBaseline="top",B.fillStyle=a.color,B.fillText(h,E,c+parseFloat(a.fontSize)*.1))}function t(a,E,c,h,l){c<2*l&&(l=c/2),h<2*l&&(l=h/2),B.beginPath(),B.moveTo(a+l,E),B.arcTo(a+c,E,a+c,E+h,l),B.arcTo(a+c,E+h,a,E+h,l),B.arcTo(a,E+h,a,E,l),B.arcTo(a,E,a+c,E,l),B.closePath()}function C(a,E,c,h,l,u){const w=a[E+"Width"],d=a[E+"Style"],D=a[E+"Color"];w!=="0px"&&d!=="none"&&D!=="transparent"&&D!=="rgba(0, 0, 0, 0)"&&(B.strokeStyle=D,B.lineWidth=parseFloat(w),B.beginPath(),B.moveTo(c,h),B.lineTo(c+l,h+u),B.stroke())}function o(a,E){let c=0,h=0,l=0,u=0;if(a.nodeType===Node.TEXT_NODE){A.selectNode(a);const d=A.getBoundingClientRect();c=d.left-s.left-.5,h=d.top-s.top-.5,l=d.width,u=d.height,e(E,c,h,a.nodeValue.trim())}else{if(a.nodeType===Node.COMMENT_NODE)return;if(a instanceof HTMLCanvasElement){if(a.style.display==="none")return;B.save();const d=window.devicePixelRatio;B.scale(1/d,1/d),B.drawImage(a,0,0),B.restore()}else{if(a.style.display==="none")return;const d=a.getBoundingClientRect();c=d.left-s.left-.5,h=d.top-s.top-.5,l=d.width,u=d.height,E=window.getComputedStyle(a),t(c,h,l,u,parseFloat(E.borderRadius));const D=E.backgroundColor;D!=="transparent"&&D!=="rgba(0, 0, 0, 0)"&&(B.fillStyle=D,B.fill());const p=["borderTop","borderLeft","borderBottom","borderRight"];let f=!0,S=null;for(const y of p){if(S!==null&&(f=E[y+"Width"]===E[S+"Width"]&&E[y+"Color"]===E[S+"Color"]&&E[y+"Style"]===E[S+"Style"]),f===!1)break;S=y}if(f===!0){const y=parseFloat(E.borderTopWidth);E.borderTopWidth!=="0px"&&E.borderTopStyle!=="none"&&E.borderTopColor!=="transparent"&&E.borderTopColor!=="rgba(0, 0, 0, 0)"&&(B.strokeStyle=E.borderTopColor,B.lineWidth=y,B.stroke())}else C(E,"borderTop",c,h,l,0),C(E,"borderLeft",c,h,0,u),C(E,"borderBottom",c,h+u,l,0),C(E,"borderRight",c+l,h,0,u);if(a instanceof HTMLInputElement){let y=E.accentColor;(y===void 0||y==="auto")&&(y=E.color),g.set(y);const k=Math.sqrt(.299*g.r**2+.587*g.g**2+.114*g.b**2)<.5?"white":"#111111";if(a.type==="radio"&&(t(c,h,l,u,u),B.fillStyle="white",B.strokeStyle=y,B.lineWidth=1,B.fill(),B.stroke(),a.checked&&(t(c+2,h+2,l-4,u-4,u),B.fillStyle=y,B.strokeStyle=k,B.lineWidth=2,B.fill(),B.stroke())),a.type==="checkbox"&&(t(c,h,l,u,2),B.fillStyle=a.checked?y:"white",B.strokeStyle=a.checked?k:y,B.lineWidth=1,B.stroke(),B.fill(),a.checked)){const N=B.textAlign;B.textAlign="center";const J={color:k,fontFamily:E.fontFamily,fontSize:u+"px",fontWeight:"bold"};e(J,c+l/2,h,"✔"),B.textAlign=N}if(a.type==="range"){const[N,J,F]=["min","max","value"].map(x=>parseFloat(a[x])),K=(F-N)/(J-N)*(l-u);t(c,h+u/4,l,u/2,u/4),B.fillStyle=k,B.strokeStyle=y,B.lineWidth=1,B.fill(),B.stroke(),t(c,h+u/4,K+u/2,u/2,u/4),B.fillStyle=y,B.fill(),t(c+K,h,u,u,u/2),B.fillStyle=y,B.fill()}(a.type==="color"||a.type==="text"||a.type==="number")&&(r.add({x:c,y:h,width:l,height:u}),e(E,c+parseInt(E.paddingLeft),h+parseInt(E.paddingTop),a.value),r.remove())}}}const w=E.overflow==="auto"||E.overflow==="hidden";w&&r.add({x:c,y:h,width:l,height:u});for(let d=0;d<a.childNodes.length;d++)o(a.childNodes[d],E);w&&r.remove()}const s=i.getBoundingClientRect();let n=Zy.get(i);n===void 0&&(n=document.createElement("canvas"),n.width=s.width,n.height=s.height,Zy.set(i,n));const B=n.getContext("2d"),r=new I(B);return o(i),n}function eX(i,A,g,I){const e={clientX:g*i.offsetWidth+i.offsetLeft,clientY:I*i.offsetHeight+i.offsetTop,view:i.ownerDocument.defaultView};window.dispatchEvent(new MouseEvent(A,e));const t=i.getBoundingClientRect();g=g*t.width+t.left,I=I*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&&I>s.top&&I<s.bottom&&(o.dispatchEvent(new MouseEvent(A,e)),o instanceof HTMLInputElement&&o.type==="range"&&(A==="mousedown"||A==="click"))){const[n,B]=["min","max"].map(c=>parseFloat(o[c])),r=s.width,E=(g-s.x)/r;o.value=n+(B-n)*E,o.dispatchEvent(new InputEvent("input",{bubbles:!0}))}for(let n=0;n<o.childNodes.length;n++)C(o.childNodes[n])}}C(i)}const kd=new $,Qa={type:"",data:kd};class iX extends zt{constructor(A,g){super();const I=this,e=new dQ,t=new ZA,C=A.domElement;function o(a){a.stopPropagation();const E=A.domElement.getBoundingClientRect();kd.x=(a.clientX-E.left)/E.width*2-1,kd.y=-(a.clientY-E.top)/E.height*2+1,e.setFromCamera(kd,g);const c=e.intersectObjects(I.children,!1);if(c.length>0){const h=c[0],l=h.object,u=h.uv;Qa.type=a.type,Qa.data.set(u.x,1-u.y),l.dispatchEvent(Qa)}}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 n(a){const E=a.target;t.identity().extractRotation(E.matrixWorld),e.ray.origin.setFromMatrixPosition(E.matrixWorld),e.ray.direction.set(0,0,-1).applyMatrix4(t);const c=e.intersectObjects(I.children,!1);if(c.length>0){const h=c[0],l=h.object,u=h.uv;Qa.type=s[a.type],Qa.data.set(u.x,1-u.y),l.dispatchEvent(Qa)}}const B=A.xr.getController(0);B.addEventListener("move",n),B.addEventListener("select",n),B.addEventListener("selectstart",n),B.addEventListener("selectend",n);const r=A.xr.getController(1);r.addEventListener("move",n),r.addEventListener("select",n),r.addEventListener("selectstart",n),r.addEventListener("selectend",n)}}class VG extends xA{constructor(){super(...arguments);Q(this,"id",null);Q(this,"keepAspect",!1)}start(){if(!this.id||!this.context.mainCamera)return;const g=document.getElementById(this.id);if(!g){console.warn('Could not find element with id "'+this.id+'"');return}g.style.display="block",g.style.visibility="hidden";const I=new iX(this.context.renderer,this.context.mainCamera);this.gameObject.add(I);const e=new gX(g);I.add(e),e.visible=!1,console.log(e);const t=e.material;t.transparent=!0,setTimeout(()=>{e.visible=!0;const C=dN(this.gameObject).clone();DN(this.gameObject,0,0,0),this.gameObject.updateMatrixWorld();const o=new Ai;o.setFromObject(I),this.setWorldRotation(C.x,C.y,C.z);const s=o.max.x-o.min.x,n=o.max.y-o.min.y;if(this.keepAspect){const r=s/n;s>n?e.scale.set(1/s,1/n/r,1):e.scale.set(1/s*r,1/n,1)}else e.scale.set(1/s,1/n,1);const B=this.gameObject.scale;e.scale.multiply(B)},1)}}var tX=Object.defineProperty,CX=Object.getOwnPropertyDescriptor,lh=(i,A,g,I)=>{for(var e=I>1?void 0:I?CX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&tX(A,g,e),e};const lE=EA("debugspatialtrigger"),Bm=new Ut,am=new Ut;function oX(i,A){return Bm.mask=i,am.mask=A,Bm.test(am)}class KC extends xA{constructor(){super(...arguments);Q(this,"triggerMask",0);Q(this,"onEnter");Q(this,"onStay");Q(this,"onExit");Q(this,"currentIntersected",[]);Q(this,"lastIntersected",[])}start(){lE&&console.log(this.name,this.triggerMask,this)}update(){this.currentIntersected.length=0;for(const g of dh.triggers)oX(g.triggerMask,this.triggerMask)&&g.test(this.gameObject)&&this.currentIntersected.push(g);for(let g=this.lastIntersected.length-1;g>=0;g--){const I=this.lastIntersected[g];this.currentIntersected.indexOf(I)<0&&(this.onExitTrigger(I),this.lastIntersected.splice(g,1))}for(const g of this.currentIntersected)this.lastIntersected.indexOf(g)<0&&this.onEnterTrigger(g),this.onStayTrigger(g);this.lastIntersected.length=0,this.lastIntersected.push(...this.currentIntersected)}onEnterTrigger(g){var I;lE&&console.log("ENTER TRIGGER",this.name,g.name,this,g),g.raiseOnEnterEvent(this),(I=this.onEnter)==null||I.invoke(this,g)}onExitTrigger(g){var I;lE&&console.log("EXIT TRIGGER",this.name,g.name,this,g),g.raiseOnExitEvent(this),(I=this.onExit)==null||I.invoke(this,g)}onStayTrigger(g){var I;g.raiseOnStayEvent(this),(I=this.onStay)==null||I.invoke(this,g)}}lh([U()],KC.prototype,"triggerMask",2);lh([U(Mi)],KC.prototype,"onEnter",2);lh([U(Mi)],KC.prototype,"onStay",2);lh([U(Mi)],KC.prototype,"onExit",2);var hf;const Md=(hf=class extends xA{constructor(){super(...arguments);Q(this,"triggerMask");Q(this,"boxHelper")}start(){lE&&console.log(this.name,this.triggerMask,this)}onEnable(){var A;Md.triggers.push(this),this.boxHelper||(this.boxHelper=CA.addNewComponent(this.gameObject,pt),(A=this.boxHelper)==null||A.showHelper(null,lE))}onDisable(){Md.triggers.splice(Md.triggers.indexOf(this),1)}test(A){return this.boxHelper?this.boxHelper.isInBox(A)??!1:!1}raiseOnEnterEvent(A){CA.foreachComponent(this.gameObject,g=>{g!==A&&g instanceof KC&&g.onEnterTrigger(this)},!1)}raiseOnStayEvent(A){CA.foreachComponent(this.gameObject,g=>{g!==A&&g instanceof KC&&g.onStayTrigger(this)},!1)}raiseOnExitEvent(A){CA.foreachComponent(this.gameObject,g=>{g!==A&&g instanceof KC&&g.onExitTrigger(this)},!1)}},Q(hf,"triggers",[]),hf);let dh=Md;lh([U()],dh.prototype,"triggerMask",2);var sX=Object.defineProperty,nX=Object.getOwnPropertyDescriptor,BX=(i,A,g,I)=>{for(var e=I>1?void 0:I?nX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&sX(A,g,e),e};const Wi=EA("debugspectator");class Qp extends xA{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(g){this._mode=g}get isSpectating(){var g;return((g=this._handler)==null?void 0:g.currentTarget)!==void 0}isSpectatingUser(g){var I;return((I=this.target)==null?void 0:I.userId)===g}isFollowedBy(g){var I;return(I=this.followers)==null?void 0:I.includes(g)}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(g){var I;if(this._handler){const e=(I=this._handler.currentTarget)==null?void 0:I.userId,t=this.context.players.getPlayerView(this.localId);g===void 0||this.context.isInXR===!1&&(t==null?void 0:t.currentObject)===g.currentObject?this._handler.currentTarget!==void 0&&(this._handler.disable(),CA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),this._networking.onSpectatedObjectChanged(g,e)):this._handler.currentTarget!==g&&(this._handler.set(g),CA.setActive(this.gameObject,!0),this.orbit&&(this.orbit.enabled=!1),this._networking.onSpectatedObjectChanged(g,e))}}get target(){var g;return(g=this._handler)==null?void 0:g.currentTarget}requestAllFollowMe(){this._networking.onRequestFollowMe()}get isSpectatingSelf(){var g,I;return this.isSpectating&&((g=this.target)==null?void 0:g.currentObject)===((I=this.context.players.getPlayerView(this.localId))==null?void 0:I.currentObject)}awake(){if(this._debug=new rX(this.context,this),this._networking=new hX(this.context,this),this._networking.awake(),CA.setActive(this.gameObject,!1),this.cam=CA.getComponent(this.gameObject,mI),!this.cam){console.error("Spectator camera needs camera component",this);return}!this._handler&&this.cam&&(this._handler=new aX(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),Kg.addEventListener(ve.RequestVRSession,this.eventSub_WebXRRequestStartEvent),Kg.addEventListener(ve.XRStarted,this.eventSub_WebXRStartEvent),Kg.addEventListener(ve.XRStopped,this.eventSub_WebXREndEvent),this.orbit=CA.getComponent(this.context.mainCamera,gn)}onDestroy(){var g;this.stopSpectating(),Kg.removeEventListener(ve.RequestVRSession,this.eventSub_WebXRStartEvent),Kg.removeEventListener(ve.XRStarted,this.eventSub_WebXRStartEvent),Kg.removeEventListener(ve.XRStopped,this.eventSub_WebXREndEvent),(g=this._handler)==null||g.destroy(),this._networking.destroy()}isSupportedPlatform(){const g=window.navigator.userAgent,I=/Windows|MacOS/.test(g),e=/Windows NT/.test(g)&&/Edg/.test(g)&&!/Win64/.test(g);return I&&!e}onXRSessionRequestStart(g){this.isSupportedPlatform()&&CA.setActive(this.gameObject,!0)}onXRSessionStart(g){this.isSupportedPlatform()&&(Wi&&console.log(this.context.mainCamera),this.context.mainCamera&&this.followSelf())}onXRSessionEnded(g){var I,e;this.context.removeCamera(this.cam),CA.setActive(this.gameObject,!1),this.orbit&&(this.orbit.enabled=!0),(I=this._handler)==null||I.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,Ro.Headset),this.target=this.context.players.getPlayerView(this.localId)),Wi&&console.log("Follow self",this.target)}onAfterRender(){var n,B,r;if(!this.cam)return;const g=this.context.renderer,I=g.xr.enabled;if(!g.xr.isPresenting&&!((n=this._handler)!=null&&n.currentTarget))return;(B=this._handler)==null||B.update(this._mode);const e=g.getRenderTarget();let t=null;if(!e){if(!g.state.bindFramebuffer||!g.state.bindXRFramebuffer)return;t=g._framebuffer,g.state.bindXRFramebuffer(null)}this.setAvatarFlagsBeforeRender();const C=this.context.mainCameraComponent;if(C){const a=C.backgroundColor;a&&g.setClearColor(a,a.alpha),this.cam.backgroundColor=a,this.cam.clearFlags=C.clearFlags,this.cam.nearClipPlane=C.nearClipPlane,this.cam.farClipPlane=C.farClipPlane}else g.setClearColor(new wA(1,1,1));g.setRenderTarget(null),g.xr.enabled=!1;const o=(r=this.cam)==null?void 0:r.cam;this.context.updateAspect(o);const s=g.xr.isPresenting;g.xr.isPresenting=!1,g.setSize(this.context.domWidth,this.context.domHeight),g.render(this.context.scene,o),g.xr.isPresenting=s,g.xr.enabled=I,e?g.setRenderTarget(e):g.state.bindXRFramebuffer(t),this.resetAvatarFlags()}setAvatarFlagsBeforeRender(){const g=this._mode===0;for(const I of Me.instances)if(I.avatar&&"isLocalAvatar"in I.avatar){let e=re.All;this.isSpectatingSelf&&(e=g&&I.avatar.isLocalAvatar?re.FirstPerson:re.ThirdPerson);const t=I.avatar.flags;if(!t)continue;for(const C of t)C.UpdateVisible(e)}}resetAvatarFlags(){var g;for(const I of Me.instances)if(I.avatar&&"flags"in I.avatar){const e=I.avatar.flags;if(!e)continue;for(const t of e)(g=I.avatar)!=null&&g.isLocalAvatar?t.UpdateVisible(re.FirstPerson):t.UpdateVisible(re.ThirdPerson)}}}BX([U()],Qp.prototype,"useKeys",2);class aX{constructor(A,g,I){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=I}get currentTarget(){return this.view}set(A){const g=A==null?void 0:A.currentObject;if(!g){this.spectator.stopSpectating();return}g!==this.currentObject&&(this.currentObject=g,this.view=A,this.follow||(this.follow=CA.addNewComponent(this.cam.gameObject,nn)),this.target||(this.target=new qA),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&&CA.destroy(this.follow)}update(A){var e,t,C,o,s,n;if(((e=this.currentTarget)==null?void 0:e.isConnected)===!1||((t=this.currentTarget)==null?void 0:t.removed)===!0){Wi&&console.log("Target disconnected or timeout",this.currentTarget),this.spectator.stopSpectating();return}this.currentTarget&&((C=this.currentTarget)==null?void 0:C.currentObject)!==this.currentObject&&(Wi&&console.log("Target changed",this.currentObject,"to",this.currentTarget.currentObject),this.set(this.currentTarget));const g=this.context.mainCamera;g&&(this.cam.cam.near!==g.near||this.cam.cam.far!==g.far)&&(this.cam.cam.near=g.near,this.cam.cam.far=g.far,this.cam.cam.updateProjectionMatrix());const I=(o=this.follow)==null?void 0:o.target;if(!(!I||!this.follow)){switch(A){case 0:((s=this.view)==null?void 0:s.viewDevice)!==Ro.Browser?(this.follow.followFactor=5,this.follow.rotateFactor=5):(this.follow.followFactor=50,this.follow.rotateFactor=50),I.position.set(0,0,0);break;case 1:this.follow.followFactor=3,this.follow.rotateFactor=2,I.position.set(0,.5,1.5);break}this.follow.flipForward=!1,((n=this.view)==null?void 0:n.viewDevice)!==Ro.Browser?I.quaternion.copy(QX):I.quaternion.identity()}}}const QX=new UA().setFromAxisAngle(new M(0,1,0),Math.PI);class rX{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",e=>{if(!this.spectator.useKeys)return;e.key==="Escape"&&this.spectator.stopSpectating()});let I=0;this.context.input.addEventListener(Eo.PointerDown,e=>{I=this.context.time.time}),this.context.input.addEventListener(Eo.PointerUp,e=>{const t=this.context.time.time-I;t>1?this.spectator.stopSpectating():this.context.input.getPointerClicked(0)&&t<.3&&this.trySelectObject()})}trySelectObject(){const A=new TC;A.setMask(16777215);const g=this.context.physics.raycast(A);if(Wi&&console.log(...g),g!=null&&g.length)for(const I of g){if(I.distance<.2)continue;const e=I.object,t=CA.getComponentInParent(e,Me),C=t==null?void 0:t.connectionId;if(C){const o=this.context.players.getPlayerView(C);this.spectator.target=o,Wi&&console.log("spectate",C,t);break}}}}class EX{constructor(A,g,I){Q(this,"guid");Q(this,"dontSave",!0);Q(this,"targetUserId");Q(this,"stoppedFollowing");this.guid=A,this.targetUserId=g,this.stoppedFollowing=I}}class cX{constructor(A,g){Q(this,"guid");Q(this,"userId");this.guid=A.guid,this.userId=g}}class hX{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(WI.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(WI.JoinedRoom,this._joinedRoomMethod)}onSpectatedObjectChanged(A,g){if(Wi&&console.log(this.context.connection.connectionId,"onSpectatedObjectChanged",A,g),this.context.connection.connectionId){const I=(A==null?void 0:A.userId)===void 0,e=I?g:A==null?void 0:A.userId,t=new EX(this.context.connection.connectionId,e,I);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,I=new cX(this.spectator,g);this.context.connection.send("spectator-request-follow",I)}}onUserJoinedRoom(){EA("followme")&&this.onRequestFollowMe()}onFollowerEvent(A){const g=A.targetUserId,I=A.guid;if(Wi&&console.log(A),g===this.context.connection.connectionId)if(A.stoppedFollowing){const e=this.followers.indexOf(I);e!==-1&&(this.followers.splice(e,1),this.removeDisconnectedFollowers(),console.log(I,"unfollows you",this.followers.length))}else this.followers.includes(I)||(this.followers.push(I),this.removeDisconnectedFollowers(),console.log(I,"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 lX=Object.defineProperty,dX=Object.getOwnPropertyDescriptor,Jt=(i,A,g,I)=>{for(var e=I>1?void 0:I?dX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&lX(A,g,e),e};const zy=EA("debugspriterenderer"),DX=EA("wireframe"),fD=class{static getOrCreateGeometry(A){if(A._geometry)return A._geometry;if(A.guid&&fD.cache[A.guid])return zy&&console.log("Take cached geometry for sprite",A.guid),fD.cache[A.guid];const g=new lg;A._geometry=g;const I=new Float32Array(A.triangles.length*3),e=new Float32Array(A.triangles.length*2);for(let t=0;t<A.triangles.length;t+=1){const C=A.triangles[t];I[t*3]=-A.vertices[C].x,I[t*3+1]=A.vertices[C].y,I[t*3+2]=0;const o=A.uv[C];e[t*2]=o.x,e[t*2+1]=1-o.y}return g.setAttribute("position",new Qg(I,3)),g.setAttribute("uv",new Qg(e,2)),A.guid&&(this.cache[A.guid]=g),zy&&console.log("Built sprite geometry",A,g),g}};let dE=fD;Q(dE,"cache",{});class Vo{constructor(){Q(this,"guid");Q(this,"texture");Q(this,"triangles");Q(this,"uv");Q(this,"vertices");Q(this,"_geometry")}}Jt([U()],Vo.prototype,"guid",2);Jt([U(Lg)],Vo.prototype,"texture",2);Jt([kQ()],Vo.prototype,"triangles",2);Jt([kQ()],Vo.prototype,"uv",2);Jt([kQ()],Vo.prototype,"vertices",2);const tf=Symbol("spriteOwner");class Dh{constructor(){Q(this,"sprites")}}Jt([U(Vo)],Dh.prototype,"sprites",2);class Ar{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 I=g==null?void 0:g.texture;I&&(I.encoding=Ag,I.minFilter==Zg&&I.magFilter==Zg&&(I.anisotropy=1),I.needsUpdate=!0)}}Jt([U(Dh)],Ar.prototype,"spriteSheet",2);Jt([U()],Ar.prototype,"index",2);class qB extends xA{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(g){if(g!==this._spriteSheet)if(typeof g=="number"){const I=Math.floor(g);I===g&&(this.spriteIndex=I);return}else this._spriteSheet=g,this.updateSprite()}set spriteIndex(g){this._spriteSheet&&(this._spriteSheet.index=g,this.updateSprite())}get spriteIndex(){var g;return((g=this._spriteSheet)==null?void 0:g.index)??0}get spriteFrames(){var g,I;return((I=(g=this._spriteSheet)==null?void 0:g.spriteSheet)==null?void 0:I.sprites.length)??0}awake(){this._currentSprite=void 0,zy&&console.log("Awake",this.name,this,this.sprite)}start(){this._currentSprite?this.gameObject&&this.gameObject.add(this._currentSprite):this.updateSprite()}updateSprite(){var I,e,t;if(!this.__didAwake||!((e=(I=this.sprite)==null?void 0:I.spriteSheet)!=null&&e.sprites))return;const g=this.sprite.spriteSheet.sprites[this.spriteIndex];if(this._currentSprite)this._currentSprite.geometry=dE.getOrCreateGeometry(g),this._currentSprite.material.map=g.texture;else{const C=new rI({color:16777215,side:fI});if(!C)return;if(DX&&(C.wireframe=!0),this.color&&(C.color||(C.color=new wA),C.color.copy(this.color),C.opacity=this.color.alpha),C.transparent=!0,g.texture&&!C.wireframe){let o=g.texture;o[tf]!==void 0&&o[tf]!==this&&this.spriteFrames>1&&(o=g.texture=o.clone()),o[tf]=this,C.map=o}this.sharedMaterial=C,this._currentSprite=new GA(dE.getOrCreateGeometry(g),C)}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),(t=this._spriteSheet)==null||t.update()}}Jt([U()],qB.prototype,"drawMode",2);Jt([U(lI)],qB.prototype,"color",2);Jt([U(Fg)],qB.prototype,"sharedMaterial",2);Jt([U(Ar)],qB.prototype,"sprite",1);class fC{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 fC).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedCameraModel(A,g){return A.setPosition(A.position()+du),(g||new fC).__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 $i).__init(this.bb_pos+g,this.bb):null}rot(A){const g=this.bb.__offset(this.bb_pos,12);return g?(A||new $i).__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 uX=Object.defineProperty,pX=Object.getOwnPropertyDescriptor,wX=(i,A,g,I)=>{for(var e=I>1?void 0:I?pX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&uX(A,g,e),e};const dD="SCAM";R0(dD,fC.getRootAsSyncedCameraModel);const bi=new SQ;class fX{constructor(A,g){Q(this,"userId");Q(this,"guid");this.guid=g,this.userId=A}send(A,g){if(A){bi.clear();const I=bi.createString(this.guid),e=bi.createString(this.userId);fC.startSyncedCameraModel(bi),fC.addGuid(bi,I),fC.addUserId(bi,e);const t=Sg(A),C=dN(A);fC.addPos(bi,$i.createVec3(bi,t.x,t.y,t.z)),fC.addRot(bi,$i.createVec3(bi,C.x,C.y,C.z));const o=fC.endSyncedCameraModel(bi);bi.finish(o,dD),g.sendBinary(bi.asUint8Array())}}}var lf;const Vy=(lf=class extends xA{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(A){const g=this.userToCamMap[A];return g?this.remoteCams[g].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(dD,this.onReceivedRemoteCameraInfoBin.bind(this))}onDisable(){this.context.connection.stopListenBinary(dD,this._receiveCallback)}update(){for(const e in this.remoteCams){const t=this.remoteCams[e],C=this.context.time.realtimeSinceStartup-t.lastUpdate;if(!t||C>this._camTimeoutInSeconds){console.log("Remote cam timeout",t,C),t!=null&&t.obj&&CA.destroy(t.obj),delete this.remoteCams[e],t&&delete this.userToCamMap[t.userId],Vy.instances.push(t),this.context.players.removePlayerView(t.userId,Ro.Browser);continue}}if(Kg.IsInWebXR)return;const A=this.context.mainCamera;if(A===null){this.enabled=!1;return}if(!this.context.connection.isConnected||this.context.connection.connectionId===null)return;this._model===null&&(this._model=new fX(this.context.connection.connectionId,this.context.connection.connectionId+"_camera"));const g=Sg(A),I=Vi(A);(g.distanceTo(this._lastWorldPosition)>.001||I.angleTo(this._lastWorldQuaternion)>.01)&&(this._needsUpdate=!0),this._lastWorldPosition.copy(g),this._lastWorldQuaternion.copy(I),!((!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(A,this.context.connection),this.context.isInXR||this.context.players.setPlayerView(this.context.connection.connectionId,A,Ro.Browser))}onReceivedRemoteCameraInfoBin(A){const g=A.guid();if(!g)return;const I=A.userId();if(!I||!this.context.connection.userIsInRoom(I)||!this.cameraPrefab)return;let e=this.remoteCams[g];if(!e)if("isObject3D"in this.cameraPrefab){const s=new qC;s.context=this.context;const n=CA.instantiate(this.cameraPrefab,s);e=this.remoteCams[g]={obj:n,lastUpdate:this.context.time.realtimeSinceStartup,userId:I},e.obj.visible=!0,this.gameObject.add(n),this.userToCamMap[I]=g,Vy.instances.push(e);const B=CA.getOrAddComponent(n,Me);B.connectionId=I,B.avatar=n}else return;const t=e.obj;this.context.players.setPlayerView(I,t,Ro.Browser),e.lastUpdate=this.context.time.realtimeSinceStartup,Gi.markDirty(t);const C=A.pos();C&&bE(t,C.x(),C.y(),C.z());const o=A.rot();o&&DN(t,o.x(),o.y(),o.z())}},Q(lf,"instances",[]),lf);let rp=Vy;wX([U([qA,St])],rp.prototype,"cameraPrefab",2);var yX=Object.defineProperty,SX=Object.getOwnPropertyDescriptor,uh=(i,A,g,I)=>{for(var e=I>1?void 0:I?SX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&yX(A,g,e),e};const Cf="view",vl=EA("debugsyncedroom");class Bn extends xA{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(){vl&&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 g=EA(Cf);if(g&&typeof g=="string"&&g.length>0){console.log("Join as viewer"),this.context.connection.joinRoom(g,!0);return}this.tryJoinRoom()}onDisable(){this.roomName&&this.roomName.length>0&&this.context.connection.leaveRoom(this.roomName)}tryJoinRoom(g=0){g===void 0&&(g=0);let I=!1;if(this.urlParameterName){const e=EA(this.urlParameterName);if(e&&typeof e=="string"){I=!0;const t=bL(e);this.roomName=t}else if(this.joinRandomRoom&&(console.log("No room name found in url, generating random one"),this.setRandomRoomUrlParameter(),g<1))return this.tryJoinRoom(g+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&&!I?(vl&&console.log('No required room parameter "'+this.urlParameterName+'" in url - will not connect to networking backend.'),!1):!this.roomName||this.roomName.length<=0?(vl&&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(),vl&&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(){const g=EA(Cf);return g||EA(this.urlParameterName)}setRandomRoomUrlParameter(){const g=SD(),I=this.generateRoomName();EA(this.urlParameterName)?g.set(this.urlParameterName,I):g.append(this.urlParameterName,I),pm(I,g)}generateRoomName(){return LL()+"_"+qL(100,999)}getViewOnlyUrl(){if(this.context.connection.isConnected&&this.context.connection.currentRoomViewId){const g=window.location.search,I=new URLSearchParams(g);return I.has(this.urlParameterName)&&I.delete(this.urlParameterName),I.set(Cf,this.context.connection.currentRoomViewId),window.location.origin+window.location.pathname+"?"+I.toString()}return null}}uh([U()],Bn.prototype,"roomName",2);uh([U()],Bn.prototype,"urlParameterName",2);uh([U()],Bn.prototype,"joinRandomRoom",2);uh([U()],Bn.prototype,"requireRoomParameter",2);uh([U()],Bn.prototype,"autoRejoin",2);function GX(){const i=EA("testwindowcount")||0;i&&i>0&&kX(i)}function kX(i){if(EA("testwindow"))return null;const A=new URL(window.location.href);SE(A.searchParams,QD,1),SE(A.searchParams,"testwindow",1);const g=A.toString(),I=[];window.onbeforeunload=()=>{for(const s of I)s.close()};const e=.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 n=C*(t*(1+e))+window.screenLeft,B=o*(t*(1+e))+window.screenTop+90+60*o;C+=1;const r=window.open(g,"test window "+s,`popup=yes width=${t} height=${t} top=${B} left=${n}`);if(!r){console.warn("Failed to open window");continue}I.push(r),r.onload=()=>{r.onbeforeunload=()=>{for(let a=0;a<I.length;a++){const E=I[a];E!==r&&E.close()}I.length=0}}}return I}class XG extends xA{awake(){GX()}}class $G extends xA{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(Ac,g=>{});else{this.models=[];for(let g=0;g<this.transformsPerFrame;g++)this.models.push(new dL(this.context.connection.connectionId+"_simulatedTransform_"+g,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 SQ(1024));const g=this.builder;for(let I=0;I<this.transformsPerFrame;I++){g.clear();const e=Qq(this.context.connection.connectionId,this);this.context.connection.sendBinary(e)}}else if(this.models)for(let g=0;g<this.models.length;g++){const I=this.models[g];I.dontSave=!0,I.update(this,null),this.context.connection.send("TestSimulateUserData-"+g,I)}}}}class dL{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 I=A.worldPosition;this.position.x=I.x,this.position.y=I.y,this.position.z=I.z;const e=A.worldQuaternion;if(this.rotation.x=e.x,this.rotation.y=e.y,this.rotation.z=e.z,this.rotation.w=e.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(dL,"temp",new M);var MX=Object.defineProperty,UX=Object.getOwnPropertyDescriptor,gr=(i,A,g,I)=>{for(var e=I>1?void 0:I?UX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&MX(A,g,e),e};class VC extends Ni{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=Jo.MEDIUM,this.resolutionScale.defaultValue=1/window.devicePixelRatio}onCreateEffect(){console.log(this);const g=new Q3({kernelSize:Jo.VERY_LARGE});return this.offset.onValueChanged=I=>g.offset=I,this.rotation.onValueChanged=I=>g.rotation=I,this.focusArea.onValueChanged=I=>g.focusArea=I,this.feather.onValueChanged=I=>g.feather=I,this.kernelSize.onValueChanged=I=>g.blurPass.kernelSize=I,this.resolutionScale.onValueChanged=I=>g.resolution.scale=I/window.devicePixelRatio,g}}gr([U(Ng)],VC.prototype,"offset",2);gr([U(Ng)],VC.prototype,"rotation",2);gr([U(Ng)],VC.prototype,"focusArea",2);gr([U(Ng)],VC.prototype,"feather",2);gr([U(Ng)],VC.prototype,"kernelSize",2);gr([U(Ng)],VC.prototype,"resolutionScale",2);PC("TiltShiftEffect",VC);var RX=Object.defineProperty,mX=Object.getOwnPropertyDescriptor,FX=(i,A,g,I)=>{for(var e=I>1?void 0:I?mX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&RX(A,g,e),e};class ph extends Ni{constructor(){super(...arguments);Q(this,"mode")}get typeName(){return"ToneMapping"}get isToneMapping(){return!0}init(){this.mode.defaultValue=ri}apply(){this.mode.onValueChanged=this._apply.bind(this),this._apply(this.mode.value)}unapply(){this.context.renderer.toneMapping=ri}_apply(g){switch(g){case 0:this.context.renderer.toneMapping=ME;break;case 1:this.context.renderer.toneMapping=BS;break;case 2:this.context.renderer.toneMapping=aS;break}}}FX([U(Ng)],ph.prototype,"mode",2);PC("Tonemapping",ph);const pn=new dQ,pi=new M,hs=new M,SI=new UA,Qm={X:new M(1,0,0),Y:new M(0,1,0),Z:new M(0,0,1)},of={type:"change"},rm={type:"mouseDown"},Em={type:"mouseUp",mode:null},cm={type:"objectChange"};class NX extends qA{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 I=new vX;this._gizmo=I,this.add(I);const e=new xX;this._plane=e,this.add(e);const t=this;function C(w,d){let D=d;Object.defineProperty(t,w,{get:function(){return D!==void 0?D:d},set:function(p){D!==p&&(D=p,e[w]=p,I[w]=p,t.dispatchEvent({type:w+"-changed",value:p}),t.dispatchEvent(of))}}),t[w]=d,e[w]=d,I[w]=d}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,n=new UA,B=new UA,r=new M,a=new UA,E=new M,c=new M,h=new M,l=0,u=new M;C("worldPosition",o),C("worldPositionStart",s),C("worldQuaternion",n),C("worldQuaternionStart",B),C("cameraPosition",r),C("cameraQuaternion",a),C("pointStart",E),C("pointEnd",c),C("rotationAxis",h),C("rotationAngle",l),C("eye",u),this._offset=new M,this._startNorm=new M,this._endNorm=new M,this._cameraScale=new M,this._parentPosition=new M,this._parentQuaternion=new UA,this._parentQuaternionInv=new UA,this._parentScale=new M,this._worldScaleStart=new M,this._worldQuaternionInv=new UA,this._worldScale=new M,this._positionStart=new M,this._quaternionStart=new UA,this._scaleStart=new M,this._getPointer=KX.bind(this),this._onPointerDown=qX.bind(this),this._onPointerHover=JX.bind(this),this._onPointerMove=LX.bind(this),this._onPointerUp=bX.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;pn.setFromCamera(A,this.camera);const g=sf(this._gizmo.picker[this.mode],pn);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){pn.setFromCamera(A,this.camera);const g=sf(this._plane,pn,!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,rm.mode=this.mode,this.dispatchEvent(rm)}}pointerMove(A){const g=this.axis,I=this.mode,e=this.object;let t=this.space;if(I==="scale"?t="local":(g==="E"||g==="XYZE"||g==="XYZ")&&(t="world"),e===void 0||g===null||this.dragging===!1||A.button!==-1)return;pn.setFromCamera(A,this.camera);const C=sf(this._plane,pn,!0);if(C){if(this.pointEnd.copy(C.point).sub(this.worldPositionStart),I==="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),e.position.copy(this._offset).add(this._positionStart),this.translationSnap&&(t==="local"&&(e.position.applyQuaternion(SI.copy(this._quaternionStart).invert()),g.search("X")!==-1&&(e.position.x=Math.round(e.position.x/this.translationSnap)*this.translationSnap),g.search("Y")!==-1&&(e.position.y=Math.round(e.position.y/this.translationSnap)*this.translationSnap),g.search("Z")!==-1&&(e.position.z=Math.round(e.position.z/this.translationSnap)*this.translationSnap),e.position.applyQuaternion(this._quaternionStart)),t==="world"&&(e.parent&&e.position.add(pi.setFromMatrixPosition(e.parent.matrixWorld)),g.search("X")!==-1&&(e.position.x=Math.round(e.position.x/this.translationSnap)*this.translationSnap),g.search("Y")!==-1&&(e.position.y=Math.round(e.position.y/this.translationSnap)*this.translationSnap),g.search("Z")!==-1&&(e.position.z=Math.round(e.position.z/this.translationSnap)*this.translationSnap),e.parent&&e.position.sub(pi.setFromMatrixPosition(e.parent.matrixWorld))));else if(I==="scale"){if(g.search("XYZ")!==-1){let o=this.pointEnd.length()/this.pointStart.length();this.pointEnd.dot(this.pointStart)<0&&(o*=-1),hs.set(o,o,o)}else pi.copy(this.pointStart),hs.copy(this.pointEnd),pi.applyQuaternion(this._worldQuaternionInv),hs.applyQuaternion(this._worldQuaternionInv),hs.divide(pi),g.search("X")===-1&&(hs.x=1),g.search("Y")===-1&&(hs.y=1),g.search("Z")===-1&&(hs.z=1);e.scale.copy(this._scaleStart).multiply(hs),this.scaleSnap&&(g.search("X")!==-1&&(e.scale.x=Math.round(e.scale.x/this.scaleSnap)*this.scaleSnap||this.scaleSnap),g.search("Y")!==-1&&(e.scale.y=Math.round(e.scale.y/this.scaleSnap)*this.scaleSnap||this.scaleSnap),g.search("Z")!==-1&&(e.scale.z=Math.round(e.scale.z/this.scaleSnap)*this.scaleSnap||this.scaleSnap))}else if(I==="rotate"){this._offset.copy(this.pointEnd).sub(this.pointStart);const o=20/this.worldPosition.distanceTo(pi.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(pi.copy(this.rotationAxis).cross(this.eye))*o):(g==="X"||g==="Y"||g==="Z")&&(this.rotationAxis.copy(Qm[g]),pi.copy(Qm[g]),t==="local"&&pi.applyQuaternion(this.worldQuaternion),this.rotationAngle=this._offset.dot(pi.cross(this.eye).normalize())*o),this.rotationSnap&&(this.rotationAngle=Math.round(this.rotationAngle/this.rotationSnap)*this.rotationSnap),t==="local"&&g!=="E"&&g!=="XYZE"?(e.quaternion.copy(this._quaternionStart),e.quaternion.multiply(SI.setFromAxisAngle(this.rotationAxis,this.rotationAngle)).normalize()):(this.rotationAxis.applyQuaternion(this._parentQuaternionInv),e.quaternion.copy(SI.setFromAxisAngle(this.rotationAxis,this.rotationAngle)),e.quaternion.multiply(this._quaternionStart).normalize())}this.dispatchEvent(of),this.dispatchEvent(cm)}}pointerUp(A){A.button===0&&(this.dragging&&this.axis!==null&&(Em.mode=this.mode,this.dispatchEvent(Em)),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(of),this.dispatchEvent(cm),this.pointStart.copy(this.pointEnd))}getRaycaster(){return pn}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 KX(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 JX(i){if(this.enabled)switch(i.pointerType){case"mouse":case"pen":this.pointerHover(this._getPointer(i));break}}function qX(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 LX(i){this.enabled&&this.pointerMove(this._getPointer(i))}function bX(i){this.enabled&&(this.domElement.releasePointerCapture(i.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.pointerUp(this._getPointer(i)))}function sf(i,A,g){const I=A.intersectObject(i,!0);for(let e=0;e<I.length;e++)if(I[e].object.visible||g)return I[e];return!1}const xl=new Ce,aI=new M(0,1,0),hm=new M(0,0,0),lm=new ZA,Yl=new UA,Ud=new UA,cC=new M,dm=new ZA,Or=new M(1,0,0),Rn=new M(0,1,0),_r=new M(0,0,1),Hl=new M,kr=new M,Mr=new M;class vX extends qA{constructor(){super(),this.isTransformControlsGizmo=!0,this.type="TransformControlsGizmo";const A=new rI({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),g=new zI({depthTest:!1,depthWrite:!1,fog:!1,toneMapped:!1,transparent:!0}),I=A.clone();I.opacity=.15;const e=g.clone();e.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 n=A.clone();n.color.setHex(65280),n.opacity=.5;const B=A.clone();B.color.setHex(255),B.opacity=.5;const r=A.clone();r.opacity=.25;const a=A.clone();a.color.setHex(16776960),a.opacity=.25,A.clone().color.setHex(16776960);const c=A.clone();c.color.setHex(7895160);const h=new JI(0,.04,.1,12);h.translate(0,.05,0);const l=new sI(.08,.08,.08);l.translate(0,.04,0);const u=new lg;u.setAttribute("position",new tg([0,0,0,1,0,0],3));const w=new JI(.0075,.0075,.5,3);w.translate(0,.25,0);function d(x,T){const O=new yC(x,.0075,3,64,T*Math.PI*2);return O.rotateY(Math.PI/2),O.rotateX(Math.PI/2),O}function D(){const x=new lg;return x.setAttribute("position",new tg([0,0,0,1,1,1],3)),x}const p={X:[[new GA(h,t),[.5,0,0],[0,0,-Math.PI/2]],[new GA(h,t),[-.5,0,0],[0,0,Math.PI/2]],[new GA(w,t),[0,0,0],[0,0,-Math.PI/2]]],Y:[[new GA(h,C),[0,.5,0]],[new GA(h,C),[0,-.5,0],[Math.PI,0,0]],[new GA(w,C)]],Z:[[new GA(h,o),[0,0,.5],[Math.PI/2,0,0]],[new GA(h,o),[0,0,-.5],[-Math.PI/2,0,0]],[new GA(w,o),null,[Math.PI/2,0,0]]],XYZ:[[new GA(new kC(.1,0),r.clone()),[0,0,0]]],XY:[[new GA(new sI(.15,.15,.01),B.clone()),[.15,.15,0]]],YZ:[[new GA(new sI(.15,.15,.01),s.clone()),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new GA(new sI(.15,.15,.01),n.clone()),[.15,0,.15],[-Math.PI/2,0,0]]]},f={X:[[new GA(new JI(.2,0,.6,4),I),[.3,0,0],[0,0,-Math.PI/2]],[new GA(new JI(.2,0,.6,4),I),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new GA(new JI(.2,0,.6,4),I),[0,.3,0]],[new GA(new JI(.2,0,.6,4),I),[0,-.3,0],[0,0,Math.PI]]],Z:[[new GA(new JI(.2,0,.6,4),I),[0,0,.3],[Math.PI/2,0,0]],[new GA(new JI(.2,0,.6,4),I),[0,0,-.3],[-Math.PI/2,0,0]]],XYZ:[[new GA(new kC(.2,0),I)]],XY:[[new GA(new sI(.2,.2,.01),I),[.15,.15,0]]],YZ:[[new GA(new sI(.2,.2,.01),I),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new GA(new sI(.2,.2,.01),I),[.15,0,.15],[-Math.PI/2,0,0]]]},S={START:[[new GA(new kC(.01,2),e),null,null,null,"helper"]],END:[[new GA(new kC(.01,2),e),null,null,null,"helper"]],DELTA:[[new _I(D(),e),null,null,null,"helper"]],X:[[new _I(u,e.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new _I(u,e.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new _I(u,e.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]},y={XYZE:[[new GA(d(.5,1),c),null,[0,Math.PI/2,0]]],X:[[new GA(d(.5,.5),t)]],Y:[[new GA(d(.5,.5),C),null,[0,0,-Math.PI/2]]],Z:[[new GA(d(.5,.5),o),null,[0,Math.PI/2,0]]],E:[[new GA(d(.75,1),a),null,[0,Math.PI/2,0]]]},G={AXIS:[[new _I(u,e.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]]},k={XYZE:[[new GA(new Ft(.25,10,8),I)]],X:[[new GA(new yC(.5,.1,4,24),I),[0,0,0],[0,-Math.PI/2,-Math.PI/2]]],Y:[[new GA(new yC(.5,.1,4,24),I),[0,0,0],[Math.PI/2,0,0]]],Z:[[new GA(new yC(.5,.1,4,24),I),[0,0,0],[0,0,-Math.PI/2]]],E:[[new GA(new yC(.75,.1,2,24),I)]]},N={X:[[new GA(l,t),[.5,0,0],[0,0,-Math.PI/2]],[new GA(w,t),[0,0,0],[0,0,-Math.PI/2]],[new GA(l,t),[-.5,0,0],[0,0,Math.PI/2]]],Y:[[new GA(l,C),[0,.5,0]],[new GA(w,C)],[new GA(l,C),[0,-.5,0],[0,0,Math.PI]]],Z:[[new GA(l,o),[0,0,.5],[Math.PI/2,0,0]],[new GA(w,o),[0,0,0],[Math.PI/2,0,0]],[new GA(l,o),[0,0,-.5],[-Math.PI/2,0,0]]],XY:[[new GA(new sI(.15,.15,.01),B),[.15,.15,0]]],YZ:[[new GA(new sI(.15,.15,.01),s),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new GA(new sI(.15,.15,.01),n),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new GA(new sI(.1,.1,.1),r.clone())]]},J={X:[[new GA(new JI(.2,0,.6,4),I),[.3,0,0],[0,0,-Math.PI/2]],[new GA(new JI(.2,0,.6,4),I),[-.3,0,0],[0,0,Math.PI/2]]],Y:[[new GA(new JI(.2,0,.6,4),I),[0,.3,0]],[new GA(new JI(.2,0,.6,4),I),[0,-.3,0],[0,0,Math.PI]]],Z:[[new GA(new JI(.2,0,.6,4),I),[0,0,.3],[Math.PI/2,0,0]],[new GA(new JI(.2,0,.6,4),I),[0,0,-.3],[-Math.PI/2,0,0]]],XY:[[new GA(new sI(.2,.2,.01),I),[.15,.15,0]]],YZ:[[new GA(new sI(.2,.2,.01),I),[0,.15,.15],[0,Math.PI/2,0]]],XZ:[[new GA(new sI(.2,.2,.01),I),[.15,0,.15],[-Math.PI/2,0,0]]],XYZ:[[new GA(new sI(.2,.2,.2),I),[0,0,0]]]},F={X:[[new _I(u,e.clone()),[-1e3,0,0],null,[1e6,1,1],"helper"]],Y:[[new _I(u,e.clone()),[0,-1e3,0],[0,0,Math.PI/2],[1e6,1,1],"helper"]],Z:[[new _I(u,e.clone()),[0,0,-1e3],[0,-Math.PI/2,0],[1e6,1,1],"helper"]]};function K(x){const T=new qA;for(const O in x)for(let _=x[O].length;_--;){const gA=x[O][_][0].clone(),rA=x[O][_][1],cA=x[O][_][2],DA=x[O][_][3],IA=x[O][_][4];gA.name=O,gA.tag=IA,rA&&gA.position.set(rA[0],rA[1],rA[2]),cA&&gA.rotation.set(cA[0],cA[1],cA[2]),DA&&gA.scale.set(DA[0],DA[1],DA[2]),gA.updateMatrix();const BA=gA.geometry.clone();BA.applyMatrix4(gA.matrix),gA.geometry=BA,gA.renderOrder=1/0,gA.position.set(0,0,0),gA.rotation.set(0,0,0),gA.scale.set(1,1,1),T.add(gA)}return T}this.gizmo={},this.picker={},this.helper={},this.add(this.gizmo.translate=K(p)),this.add(this.gizmo.rotate=K(y)),this.add(this.gizmo.scale=K(N)),this.add(this.picker.translate=K(f)),this.add(this.picker.rotate=K(k)),this.add(this.picker.scale=K(J)),this.add(this.helper.translate=K(S)),this.add(this.helper.rotate=K(G)),this.add(this.helper.scale=K(F)),this.picker.translate.visible=!1,this.picker.rotate.visible=!1,this.picker.scale.visible=!1}updateMatrixWorld(A){const I=(this.mode==="scale"?"local":this.space)==="local"?this.worldQuaternion:Ud;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 t=0;t<e.length;t++){const C=e[t];C.visible=!0,C.rotation.set(0,0,0),C.position.copy(this.worldPosition);let o;if(this.camera.isOrthographicCamera?o=(this.camera.top-this.camera.bottom)/this.camera.zoom:o=this.worldPosition.distanceTo(this.cameraPosition)*Math.min(1.9*Math.tan(Math.PI*this.camera.fov/360)/this.camera.zoom,7),C.scale.set(1,1,1).multiplyScalar(o*this.size/4),C.tag==="helper"){C.visible=!1,C.name==="AXIS"?(C.position.copy(this.worldPositionStart),C.visible=!!this.axis,this.axis==="X"&&(SI.setFromEuler(xl.set(0,0,0)),C.quaternion.copy(I).multiply(SI),Math.abs(aI.copy(Or).applyQuaternion(I).dot(this.eye))>.9&&(C.visible=!1)),this.axis==="Y"&&(SI.setFromEuler(xl.set(0,0,Math.PI/2)),C.quaternion.copy(I).multiply(SI),Math.abs(aI.copy(Rn).applyQuaternion(I).dot(this.eye))>.9&&(C.visible=!1)),this.axis==="Z"&&(SI.setFromEuler(xl.set(0,Math.PI/2,0)),C.quaternion.copy(I).multiply(SI),Math.abs(aI.copy(_r).applyQuaternion(I).dot(this.eye))>.9&&(C.visible=!1)),this.axis==="XYZE"&&(SI.setFromEuler(xl.set(0,Math.PI/2,0)),aI.copy(this.rotationAxis),C.quaternion.setFromRotationMatrix(lm.lookAt(hm,aI,Rn)),C.quaternion.multiply(SI),C.visible=this.dragging),this.axis==="E"&&(C.visible=!1)):C.name==="START"?(C.position.copy(this.worldPositionStart),C.visible=this.dragging):C.name==="END"?(C.position.copy(this.worldPosition),C.visible=this.dragging):C.name==="DELTA"?(C.position.copy(this.worldPositionStart),C.quaternion.copy(this.worldQuaternionStart),pi.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),pi.applyQuaternion(this.worldQuaternionStart.clone().invert()),C.scale.copy(pi),C.visible=this.dragging):(C.quaternion.copy(I),this.dragging?C.position.copy(this.worldPositionStart):C.position.copy(this.worldPosition),this.axis&&(C.visible=this.axis.search(C.name)!==-1));continue}C.quaternion.copy(I),this.mode==="translate"||this.mode==="scale"?(C.name==="X"&&Math.abs(aI.copy(Or).applyQuaternion(I).dot(this.eye))>.99&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="Y"&&Math.abs(aI.copy(Rn).applyQuaternion(I).dot(this.eye))>.99&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="Z"&&Math.abs(aI.copy(_r).applyQuaternion(I).dot(this.eye))>.99&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="XY"&&Math.abs(aI.copy(_r).applyQuaternion(I).dot(this.eye))<.2&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="YZ"&&Math.abs(aI.copy(Or).applyQuaternion(I).dot(this.eye))<.2&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1),C.name==="XZ"&&Math.abs(aI.copy(Rn).applyQuaternion(I).dot(this.eye))<.2&&(C.scale.set(1e-10,1e-10,1e-10),C.visible=!1)):this.mode==="rotate"&&(Yl.copy(I),aI.copy(this.eye).applyQuaternion(SI.copy(I).invert()),C.name.search("E")!==-1&&C.quaternion.setFromRotationMatrix(lm.lookAt(this.eye,hm,Rn)),C.name==="X"&&(SI.setFromAxisAngle(Or,Math.atan2(-aI.y,aI.z)),SI.multiplyQuaternions(Yl,SI),C.quaternion.copy(SI)),C.name==="Y"&&(SI.setFromAxisAngle(Rn,Math.atan2(aI.x,aI.z)),SI.multiplyQuaternions(Yl,SI),C.quaternion.copy(SI)),C.name==="Z"&&(SI.setFromAxisAngle(_r,Math.atan2(aI.y,aI.x)),SI.multiplyQuaternions(Yl,SI),C.quaternion.copy(SI))),C.visible=C.visible&&(C.name.indexOf("X")===-1||this.showX),C.visible=C.visible&&(C.name.indexOf("Y")===-1||this.showY),C.visible=C.visible&&(C.name.indexOf("Z")===-1||this.showZ),C.visible=C.visible&&(C.name.indexOf("E")===-1||this.showX&&this.showY&&this.showZ),C.material._color=C.material._color||C.material.color.clone(),C.material._opacity=C.material._opacity||C.material.opacity,C.material.color.copy(C.material._color),C.material.opacity=C.material._opacity,this.enabled&&this.axis&&(C.name===this.axis||this.axis.split("").some(function(s){return C.name===s}))&&(C.material.color.setHex(16776960),C.material.opacity=1)}super.updateMatrixWorld(A)}}class xX extends GA{constructor(){super(new Oe(1e5,1e5,2,2),new rI({visible:!1,wireframe:!0,side:fI,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"),Hl.copy(Or).applyQuaternion(g==="local"?this.worldQuaternion:Ud),kr.copy(Rn).applyQuaternion(g==="local"?this.worldQuaternion:Ud),Mr.copy(_r).applyQuaternion(g==="local"?this.worldQuaternion:Ud),aI.copy(kr),this.mode){case"translate":case"scale":switch(this.axis){case"X":aI.copy(this.eye).cross(Hl),cC.copy(Hl).cross(aI);break;case"Y":aI.copy(this.eye).cross(kr),cC.copy(kr).cross(aI);break;case"Z":aI.copy(this.eye).cross(Mr),cC.copy(Mr).cross(aI);break;case"XY":cC.copy(Mr);break;case"YZ":cC.copy(Hl);break;case"XZ":aI.copy(Mr),cC.copy(kr);break;case"XYZ":case"E":cC.set(0,0,0);break}break;case"rotate":default:cC.set(0,0,0)}cC.length()===0?this.quaternion.copy(this.cameraQuaternion):(dm.lookAt(pi.set(0,0,0),cC,aI),this.quaternion.setFromRotationMatrix(dm)),super.updateMatrixWorld(A)}}var YX=Object.defineProperty,HX=Object.getOwnPropertyDescriptor,TX=(i,A,g,I)=>{for(var e=I>1?void 0:I?HX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&YX(A,g,e),e};class Ep extends xA{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&&!Rc||this.context.mainCamera&&(this.control=new NX(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(g=>{const I=g;if(I.layers.set(2),I){const e=I.material;e&&(e.opacity=.3)}}))}start(){if(this.context.mainCamera){const g=CA.getComponentInParent(this.context.mainCamera,sq)??void 0;this.orbit=g}}onEnable(){var g;this.control&&(this.context.scene.add(this.control),this.control.attach(this.gameObject)),this.changeEventListener=this.onControlChangedEvent.bind(this),(g=this.control)==null||g.addEventListener("dragging-changed",this.changeEventListener),this.attachWindowEvents()}onDisable(){var g,I;(g=this.control)==null||g.removeFromParent(),this.changeEventListener&&((I=this.control)==null||I.removeEventListener("dragging-changed",this.changeEventListener))}onControlChangedEvent(g){const I=this.orbit;if(I&&(I.enabled=!g.value),g.value){const e=CA.getComponentInParent(this.gameObject,Os);e&&e.requestOwnership()}}attachWindowEvents(){const g=this.control;g&&(this.windowKeyDownListener||(this.windowKeyDownListener=I=>{switch(I.keyCode){case 81:g.setSpace(g.space==="local"?"world":"local");break;case 16:g.setTranslationSnap(100),g.setRotationSnap(mi.degToRad(15)),g.setScaleSnap(.25);break;case 87:g.setMode("translate");break;case 69:g.setMode("rotate");break;case 82:g.setMode("scale");break;case 187:case 107:g.setSize(g.size+.1);break;case 189:case 109:g.setSize(Math.max(g.size-.1,.1));break;case 88:g.showX=!g.showX;break;case 89:g.showY=!g.showY;break;case 90:g.showZ=!g.showZ;break;case 32:g.enabled=!g.enabled;break}}),this.windowKeyUpListener||(this.windowKeyUpListener=I=>{switch(I.keyCode){case 16:g.setTranslationSnap(null),g.setRotationSnap(null),g.setScaleSnap(null);break}}),window.addEventListener("keydown",this.windowKeyDownListener),window.addEventListener("keyup",this.windowKeyUpListener))}}TX([U()],Ep.prototype,"isGizmo",2);function OX(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 I=document.createElement("button");I.id="open-in-ar",I.innerText="Open in QuickLook",g.appendChild(I);const e=document.createElement("a");e.id="needle-usdz-link",e.style.display="none",e.rel="ar",e.href="",g.appendChild(e);const t=document.createElement("img");return t.id="button",e.appendChild(t),i.domElement.appendChild(g),e}function _X(){var i=new Date;const A=i.getMonth()+1,g=i.getDate(),I=i.getHours(),e=i.getMinutes(),t=i.getSeconds(),C=(A<10?"0":"")+A,o=(g<10?"0":"")+g,s=(I<10?"0":"")+I,n=(e<10?"0":"")+e,B=(t<10?"0":"")+t;return i.getFullYear()+C+o+"-"+s+n+B}const Tl=EA("debugusdz");function PX(i,A){const g=[],I=CA.getComponentsInChildren(i,et);let e=!1;Tl&&console.log(I);for(const t of I){if(!t||!t.runtimeAnimatorController)continue;Tl&&console.log(t);const C=[];for(const o of t.runtimeAnimatorController.enumerateActions()){Tl&&console.log(o);const s=o.getClip();if(!e&&s.tracks.length>0){e=!0;const n=s.tracks[0],B=n.name.substring(0,n.name.lastIndexOf(".")),r=new At(B+".position",[0,.01],[0,0,0,0,0,0]),a=new At(B+".quaternion",[0,.01],[0,0,0,1,0,0,0,1]);C.push(new gC("rest",.01,[r,a]))}C.includes(s)||C.push(s)}g.push({root:t.gameObject,clips:C})}Tl&&console.log(g);for(const t of g)for(const C of t.clips)A.registerAnimation(t.root,C)}var WX=Object.defineProperty,jX=Object.getOwnPropertyDescriptor,DL=(i,A,g,I)=>{for(var e=I>1?void 0:I?jX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&WX(A,g,e),e};const Ur=EA("debugusdz");class wh extends xA{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 g;Ur&&(window.addEventListener("keydown",I=>{switch(I.key){case"t":this.exportAsync();break}}),oQ()&&setTimeout(()=>{this.exportAsync()},2e3)),(g=document.getElementById("open-in-ar"))==null||g.addEventListener("click",I=>{I.preventDefault(),this.exportAsync()}),this.objectToExport||(this.objectToExport=this.gameObject)}onEnable(){const g=kD(),I=iS();(Ur||g&&I)&&(this.createQuicklookButton(),this.webARSessionRoot=CA.findObjectOfType(An)??void 0,this.lastCallback=this.quicklookCallback.bind(this),this.link=OX(this.context),this.link.addEventListener("message",this.lastCallback))}onDisable(){var g;(g=this.link)==null||g.removeEventListener("message",this.lastCallback)}async exportAsync(){if(!this.objectToExport)return;if(this.webARSessionRoot){const E=this.webARSessionRoot.gameObject,c=1/this.webARSessionRoot.arScale;E.matrix.makeScale(c,c,c),this.webARSessionRoot.invertForward&&E.matrix.multiply(new ZA().makeRotationY(Math.PI))}const g=new bW,I=[...this.extensions],e=new yu;I.push(e),this.autoExportAnimations&&PX(this.objectToExport,e);const t={self:this,exporter:g,extensions:I,object:this.objectToExport};this.dispatchEvent(new CustomEvent("before-export",{detail:t}));let C="needle";Ur&&(C+="-"+_X()),g.debug=Ur;const o=await g.parse(this.objectToExport,I),s=new Blob([o],{type:"application/octet-stream"});this.dispatchEvent(new CustomEvent("after-export",{detail:t}));const n=this.buildQuicklookOverlay(),B=n.callToAction?encodeURIComponent(n.callToAction):"",r=n.checkoutTitle?encodeURIComponent(n.checkoutTitle):"",a=n.checkoutSubtitle?encodeURIComponent(n.checkoutSubtitle):"";this.link.href=URL.createObjectURL(s)+`#callToAction=${B}&checkoutTitle=${r}&checkoutSubtitle=${a}&`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=C+".usdz",this.link.click()}quicklookCallback(g){(g==null?void 0:g.data)=="_apple_ar_quicklook_button_tapped"&&(Ur&&tC("Quicklook closed via call to action button"),this.dispatchEvent(new CustomEvent("quicklook-button-tapped",{detail:this})))}buildQuicklookOverlay(){const g={};return g.callToAction="Close",g.checkoutTitle="🌵 Made with Needle",g.checkoutSubtitle="_",this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:g})),g}async createQuicklookButton(){var g,I;if(!this.webxr)if(await GD(1),this.webxr=CA.findObjectOfType(Kg)??void 0,this.webxr)if(this.webxr.VRButton&&((g=this.webxr.VRButton.parentElement)==null||g.removeChild(this.webxr.VRButton)),this.webxr.ARButton&&this._arButton!==this.webxr.ARButton){this._arButton=this.webxr.ARButton;const e=(I=this.webxr.ARButton.parentElement)==null?void 0:I.querySelector("a");e&&(e.href=""),this.webxr.ARButton.innerText="Open in Quicklook",this.webxr.ARButton.disabled=!1,this.webxr.ARButton.addEventListener("click",t=>{t.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 t=document.createElement("button");t.innerText="Open in Quicklook",t.addEventListener("click",()=>{this.exportAsync()}),t.classList.add("webxr-ar-button"),t.classList.add("webxr-button"),t.classList.add("quicklook-ar-button"),e.appendChild(t),this.dispatchEvent(new CustomEvent("created-button",{detail:t}))}else console.warn("Could not find WebXR component: will not create Quicklook button",Dg.Current)}resetStyles(g){g.style.position="",g.style.top="",g.style.left="",g.style.width="",g.style.height="",g.style.margin="",g.style.padding="",g.style.border="",g.style.background="",g.style.color="",g.style.font="",g.style.textAlign="",g.style.opacity="",g.style.zIndex=""}}DL([U(qA)],wh.prototype,"objectToExport",2);DL([U()],wh.prototype,"autoExportAnimations",2);var ZX=Object.defineProperty,zX=Object.getOwnPropertyDescriptor,Ak=(i,A,g,I)=>{for(var e=I>1?void 0:I?zX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&ZX(A,g,e),e};class LB extends Ni{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 g=new HK;return this.intensity.onValueChanged=I=>{g.offset=I,this.updateDarkness(g)},this.color.onValueChanged=I=>{this.updateDarkness(g)},g}updateDarkness(g){const I=this.intensity.value;g.darkness=I}}Ak([U(Ng)],LB.prototype,"color",2);Ak([U(Ng)],LB.prototype,"intensity",2);Ak([U(Ng)],LB.prototype,"center",2);PC("Vignette",LB);var VX=Object.defineProperty,XX=Object.getOwnPropertyDescriptor,$X=(i,A,g,I)=>{for(var e=I>1?void 0:I?XX(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&VX(A,g,e),e};const nf=EA("debugpost");class cp extends xA{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 g;(g=this.sharedProfile)==null||g.init(),nf&&(console.log(this),console.log("Press P to toggle post processing"),window.addEventListener("keydown",I=>{I.key==="p"&&(console.log("Toggle volume: "+this.name,!this.enabled),this.enabled=!this.enabled)}))}onDisable(){var g;(g=this._postprocessing)==null||g.unapply()}onBeforeRender(){if(!this.context.isInXR){if(this.context.composer&&!(this.context.composer instanceof J0))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 g;(g=this._postprocessing)==null||g.dispose()}apply(){var I,e;nf&&console.log("Apply PostProcessing",this,(I=this.context.mainCamera)==null?void 0:I.name),uQ()&&(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,(e=this.sharedProfile)!=null&&e.components&&this._effects.push(...this.sharedProfile.components);const g=this.gameObject.getComponentsInChildren(Ni);if(nf&&(g!=null&&g.length)&&console.log("Additional",g),g)for(const t of g)t.active&&this._effects.push(t);this._effects.length>0&&(this._postprocessing||(this._postprocessing=new np(this.context)),this._postprocessing.apply(this._effects),this._applyPostQueue())}unapply(){var g;(g=this._postprocessing)==null||g.unapply()}_applyPostQueue(){if(this._modificationQueue){for(const g of this._modificationQueue.values())this.onEditorModification(g);this._modificationQueue.clear()}}onEditorModification(g){var I,e;if(g.propertyName.startsWith("postprocessing.")){if(!this._postprocessing)return this._modificationQueue||(this._modificationQueue=new Map),this._modificationQueue.set(g.propertyName,g),!0;if(!((I=this._effects)!=null&&I.length))return;const t=g.propertyName.split(".");if(t.length===3||t.length===4){const C=t[1],o=t[2];for(const s of this._effects)if(((e=s.typeName)==null?void 0:e.toLowerCase())===C.toLowerCase()){if(o==="active"){s.active=g.value,this.scheduleRecreate();return}if(!Ol.has(C)){const n=new Array;Ol.set(C,n);const B=Object.keys(s);for(const r of B)s[r]instanceof Ng&&n.push(r)}if(Ol.has(C)){const n=o.toLowerCase(),B=Ol.get(C);for(const r of B)if(r.toLowerCase()===n){const a=s[r];a instanceof Ng&&(t.length===4&&t[3]==="active"?(a.overrideState=g.value,this.scheduleRecreate()):a&&a.value!==void 0&&(a.value=g.value));return}}console.warn("Unknown modification",o);return}}return!0}return!1}scheduleRecreate(){const g=++this._recreateId;setTimeout(()=>{g===this._recreateId&&(this.onDisable(),this.onEnable())},200)}}$X([kQ(Ah)],cp.prototype,"sharedProfile",2);const Ol=new Map;var A9=Object.defineProperty,g9=Object.getOwnPropertyDescriptor,I9=(i,A,g,I)=>{for(var e=I>1?void 0:I?g9(A,g):A,t=i.length-1,C;t>=0;t--)(C=i[t])&&(e=(I?C(A,g,e):C(e))||e);return I&&e&&A9(A,g,e),e};class hp extends xA{constructor(){super(...arguments);Q(this,"backgroundTint",new lI(1,1,1,1));Q(this,"_preRender");Q(this,"backgroundPlane");Q(this,"threeTexture");Q(this,"forceTextureInitialization",function(){const g=new rI,I=new Oe,e=new Rt;e.add(new GA(I,g));const t=new nQ;return function(o,s){g.map=s,o.render(e,t)}}())}awake(){Kg.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(g=>g!==this._preRender),this.backgroundPlane&&this.gameObject.remove(this.backgroundPlane)}preRender(){if(!this||!this.gameObject)return;const I=this.context.renderer.xr.getFrame();I&&(!this.threeTexture&&this.context.renderer&&(this.threeTexture=new Lg,this.forceTextureInitialization(this.context.renderer,this.threeTexture)),this.backgroundPlane===void 0&&(this.backgroundPlane=i9(this.backgroundTint),this.gameObject.add(this.backgroundPlane)),this.updateFromFrame(I))}onBeforeRender(g){this.updateFromFrame(g)}updateFromFrame(g){if(!g)return;const I=g.getViewerPose(this.context.renderer.xr.getReferenceSpace());if(I){for(const e of I.views)if("camera"in e&&e.camera){let C=this.context.renderer.xr.getBinding();if(C||(C=new XRWebGLBinding(g.session,this.context.renderer.getContext())),C){let o=null;if("getCameraImage"in C){o=C.getCameraImage(e.camera);const s=this.context.renderer.properties.get(this.threeTexture);s.__webglTexture=o,this.backgroundPlane&&(this.backgroundPlane.setTexture(this.threeTexture),this.backgroundPlane.visible=!0)}}}}}}I9([U()],hp.prototype,"backgroundTint",2);let e9=`
4802
4802
  uniform sampler2D t2D;
4803
4803
 
4804
4804
  varying vec2 vUv;