@needle-tools/engine 2.38.0-pre.1 → 2.38.0-pre.2

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.
@@ -6389,7 +6389,7 @@ irradiance += 0.;
6389
6389
  irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
6390
6390
  #endif`);VA.lightmap.lightmapScaleOffset={value:new Ie(1,1,0,0)};var y1=cA("debugplayerview");var yM=class{userId;context;viewDevice="browser";get currentObject(){return this._object}set currentObject(A){this._object=A}get isConnected(){return this.context.connection.userIsInRoom(this.userId)}removed=!1;_object;constructor(A,e){this.userId=A,this.context=e}},ff=class{context;playerViews=new Map;constructor(A){this.context=A}setPlayerView(A,e,t){let i=this.playerViews.get(A);i||(i=new yM(A,this.context),this.playerViews.set(A,i)),i.viewDevice=t,i.currentObject=e,i.removed=!1}getPlayerView(A){if(!A)return;if(!this.context.connection.userIsInRoom(A)){this.playerViews.delete(A);return}return this.playerViews.get(A)}removePlayerView(A,e){let t=this.playerViews.get(A);t?.viewDevice===e&&(y1&&console.log("REMOVE",A),t.removed=!0,this.playerViews.delete(A))}};var M1=cA("debugSetup"),k1=cA("stats"),wf={};var GI=(o=>(o[o.EarlyUpdate=0]="EarlyUpdate",o[o.Update=1]="Update",o[o.LateUpdate=2]="LateUpdate",o[o.OnBeforeRender=3]="OnBeforeRender",o[o.OnAfterRender=4]="OnAfterRender",o[o.PrePhysicsStep=9]="PrePhysicsStep",o[o.PostPhysicsStep=10]="PostPhysicsStep",o))(GI||{});function sD(I,A){if(!I)return;let e=A?.new_scripts??ue.Current.new_scripts;e.includes(I)||e.push(I)}var Pg=class{static get Current(){return this._current}static set Current(A){this._current=A}name;alias;isManagedExternally=!1;hash;domElement;get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(A){if(A!==this._resolutionScaleFactor&&typeof A=="number"){if(A<=0){console.error("Invalid resolution scale factor",A);return}this._resolutionScaleFactor=A,this.updateSize()}}_resolutionScaleFactor=1;get domWidth(){return this.domElement.clientWidth}get domHeight(){return this.domElement.clientHeight}get domX(){return this.domElement.offsetLeft}get domY(){return this.domElement.offsetTop}get isInXR(){return this.renderer.xr?.isPresenting||!1}xrSessionMode=void 0;get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){return this.renderer.xr?.getSession()}get arOverlayElement(){let A=this.domElement;return typeof A.getAROverlayContainer=="function"?A.getAROverlayContainer():this.domElement}scene;renderer;composer=null;scripts=[];scripts_earlyUpdate=[];scripts_update=[];scripts_lateUpdate=[];scripts_onBeforeRender=[];scripts_onAfterRender=[];scripts_WithCorroutines=[];coroutines={};get mainCamera(){if(this.mainCameraComponent){let A=this.mainCameraComponent;return A.cam||A.buildCamera(),A.cam}return null}mainCameraComponent;post_setup_callbacks=[];pre_update_callbacks=[];pre_render_callbacks=[];post_render_callbacks=[];new_scripts=[];new_script_start=[];new_scripts_pre_setup_callbacks=[];new_scripts_post_setup_callbacks=[];application;time;input;physics;connection;assets;mainLight=null;rendererData;addressables;lightmaps;players;_sizeChanged=!1;_isCreated=!1;_stats=k1?OL.default():null;constructor(A){if(this.name=A?.name||"",this.alias=A?.alias,this.domElement=A?.domElement||document.body,this.hash=A?.hash,A?.renderer)this.renderer=A.renderer,this.isManagedExternally=!0;else{let t=cA("postfx");this.renderer=new rE({antialias:!0}),this.renderer.toneMappingExposure=1,this.renderer.toneMapping=uI,this.renderer.setClearColor(new P("lightgrey"),0),this.renderer.antialias=!0,this.renderer.alpha=!1,this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Kp,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputEncoding=Ue,this.renderer.physicallyCorrectLights=!0,this.composer=t?new m1(this.renderer):null}this.scene=new Is,this.application=new uf(this),this.time=new zD,this.input=new Zp(this),this.physics=new Ds(this),this.connection=new af(this),this.assets=new hf,this.rendererData=new lf(this),this.addressables=new df(this),this.lightmaps=new Df(this),this.players=new ff(this),window.addEventListener("resize",()=>this._sizeChanged=!0),new ResizeObserver(t=>this._sizeChanged=!0).observe(this.domElement)}updateSize(){if(!this.isManagedExternally&&!this.renderer.xr.isPresenting){this._sizeChanged=!1;let A=this.resolutionScaleFactor,e=this.domWidth*A,t=this.domHeight*A,i=this.mainCamera;this.updateAspect(i),this.renderer.setSize(e,t),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&(this.composer.setSize(e,t),this.composer.setPixelRatio(window.devicePixelRatio))}}updateAspect(A){if(!A)return;let e=this.domWidth,t=this.domHeight,i=A.aspect;A.aspect=e/t,i!==A.aspect&&A.updateProjectionMatrix()}onCreate(A,e){return this._isCreated?(console.warn("Context already created"),null):(this._isCreated=!0,this.internalOnCreate(A,e))}onDestroy(){!this._isCreated||(this._isCreated=!1,tC(this.scene,!0),this.renderer?.setAnimationLoop(null),this.isManagedExternally||this.renderer?.dispose())}registerCoroutineUpdate(A,e,t){return this.coroutines[t]||(this.coroutines[t]=[]),this.coroutines[t].push({comp:A,main:e}),e}unregisterCoroutineUpdate(A,e){if(!this.coroutines[e])return;let t=this.coroutines[e].findIndex(i=>i.main===A);t>=0&&this.coroutines[e].splice(t,1)}stopAllCoroutinesFrom(A){for(let e in this.coroutines){let t=this.coroutines[e];for(let i=t.length-1;i>=0;i--)t[i].comp===A&&t.splice(i,1)}}_cameraStack=[];setCurrentCamera(A){if(!A)return;if(A.cam||A.buildCamera(),!A.cam){console.warn("Camera component is missing camera",A);return}let e=this._cameraStack.indexOf(A);e>=0&&this._cameraStack.splice(e,1),this._cameraStack.push(A),this.mainCameraComponent=A;let t=A.cam;t.isPerspectiveCamera&&this.updateAspect(t),this.mainCameraComponent?.applyClearFlagsIfIsActiveCamera()}removeCamera(A){if(!A)return;let e=this._cameraStack.indexOf(A);if(e>=0&&this._cameraStack.splice(e,1),this.mainCameraComponent===A&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){let t=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(t)}}_onBeforeRenderListeners={};addBeforeRenderListener(A,e){if(!this._onBeforeRenderListeners[A.uuid]){this._onBeforeRenderListeners[A.uuid]=[];let t=(i,g,C,o,n,s)=>{let r=this._onBeforeRenderListeners[A.uuid];if(!!r)for(let a=0;a<r.length;a++){let B=r[a];B(i,g,C,o,n,s)}};A.onBeforeRender=t}this._onBeforeRenderListeners[A.uuid].push(e)}removeBeforeRenderListener(A,e){if(this._onBeforeRenderListeners[A.uuid]){let t=this._onBeforeRenderListeners[A.uuid],i=t.indexOf(e);i>=0&&t.splice(i,1)}}_requireDepthTexture=!1;_requireColorTexture=!1;_renderTarget;_isRendering=!1;get isRendering(){return this._isRendering}setRequireDepth(A){this._requireDepthTexture=A}setRequireColor(A){this._requireColorTexture=A}get depthTexture(){return this._renderTarget?.depthTexture||null}get opaqueColorTexture(){return this._renderTarget?.texture||null}async internalOnCreate(A,e){await this.physics.createWorld();let t=!0;try{Pg.Current=this,A&&await A(this,e)}catch(i){console.error(i),t=!1}if(!!t){this.isManagedExternally||this.domElement.prepend(this.renderer.domElement),Fq(this),Uq(this),qL(this),Pg._current=this;for(let i=0;i<this.new_scripts.length;i++){let g=this.new_scripts[i];if(g.gameObject!==void 0&&g.gameObject!==null){g.gameObject.userData===void 0&&(g.gameObject.userData={}),g.gameObject.userData.components===void 0&&(g.gameObject.userData.components=[]);let C=g.gameObject.userData.components;C.includes(g)||C.push(g)}}if(this.post_setup_callbacks)for(let i=0;i<this.post_setup_callbacks.length;i++)Pg._current=this,await this.post_setup_callbacks[i](this);if(!this.mainCamera){Pg._current=this;let i=null;iC(this.scene,g=>{let C=g;if(C?.isCamera){if(C.tag==="MainCamera")return i=C,!0;i=C}}),i?this.setCurrentCamera(i):console.error("MISSING camera",this)}if(Pg._current=this,$o(this),!this.isManagedExternally&&this.composer&&this.mainCamera){let i=new G1(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(i),this.composer.setSize(this.domWidth,this.domHeight)}this._sizeChanged=!0,this._stats&&(this._stats.showPanel(1),this.domElement.appendChild(this._stats.dom)),this.renderer.setAnimationLoop(this.render.bind(this)),M1&&nl(this.scene,!0)}}render(A,e){for(this._stats?.begin(),Pg._current=this,this.time.update(),$o(this),cE(),tD(this);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);let t=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(t)}if(this.pre_update_callbacks)for(let t in this.pre_update_callbacks)this.pre_update_callbacks[t]();for(let t=0;t<this.scripts_earlyUpdate.length;t++){let i=this.scripts_earlyUpdate[t];!i.activeAndEnabled||i.earlyUpdate!==void 0&&(Pg._current=this,i.earlyUpdate())}this.executeCoroutines(0);for(let t=0;t<this.scripts_update.length;t++){let i=this.scripts_update[t];!i.activeAndEnabled||i.update!==void 0&&(Pg._current=this,i.update())}this.executeCoroutines(1);for(let t=0;t<this.scripts_lateUpdate.length;t++){let i=this.scripts_lateUpdate[t];!i.activeAndEnabled||i.lateUpdate!==void 0&&(Pg._current=this,i.lateUpdate())}this.executeCoroutines(2);try{let i=this.time.deltaTime/1;for(let g=0;g<1;g++)this.executeCoroutines(9),this.physics.step(i),this.executeCoroutines(10)}catch(t){console.error(t)}this.physics.postStep();for(let t=0;t<this.scripts_onBeforeRender.length;t++){let i=this.scripts_onBeforeRender[t];!i.activeAndEnabled||i.onBeforeRender!==void 0&&(Pg._current=this,i.onBeforeRender(e))}if(this.executeCoroutines(3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(let t in this.pre_render_callbacks)this.pre_render_callbacks[t]();this._isRendering=!0,this.renderRequiredTextures(),this.isManagedExternally||(this.composer&&!this.isInXR?this.composer.render():this.mainCamera&&this.renderer.render(this.scene,this.mainCamera)),this._isRendering=!1;for(let t=0;t<this.scripts_onAfterRender.length;t++){let i=this.scripts_onAfterRender[t];!i.activeAndEnabled||i.onAfterRender!==void 0&&(Pg._current=this,i.onAfterRender())}if(this.executeCoroutines(4),this.post_render_callbacks)for(let t in this.post_render_callbacks)this.post_render_callbacks[t]();this.connection.sendBufferedMessagesNow(),this._stats?.end()}renderRequiredTextures(){if(!this.mainCamera||!this._requireDepthTexture&&!this._requireColorTexture)return;if(!this._renderTarget){if(this._renderTarget=new Ji(this.domWidth,this.domHeight),this._requireDepthTexture){let t=new vQ(this.domWidth,this.domHeight);this._renderTarget.depthTexture=t}this._requireColorTexture&&(this._renderTarget.texture=new He,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=at,this._renderTarget.texture.magFilter=at,this._renderTarget.texture.format=Ni)}let A=this._renderTarget;A.texture&&(A.texture.encoding=this.renderer.outputEncoding);let e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(A),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(e)}executeCoroutines(A){if(this.coroutines[A]){let t=this.coroutines[A];for(let i=0;i<t.length;i++){let g=t[i];if(!g.comp||g.comp.destroyed||!g.main||g.comp.enabled===!1){t.splice(i,1),--i;continue}let o=g.chained;if(o&&o.length>0){let a=o[o.length-1].next();if(a.done&&o.pop(),e(a)&&(g.chained||(g.chained=[]),g.chained.push(a.value)),!a.done)continue}let n=g.main.next();if(n.done===!0){t.splice(i,1),--i;continue}let s=n.value;if(e(s)){if(s.next().done)continue;g.chained||(g.chained=[]),g.chained.push(s)}}}function e(t){return!!(t&&t.next&&t.return)}}},ue=Pg;mA(ue,"_current");var mM={};Cu(mM,{Behaviour:()=>sA,Component:()=>Wg,GameObject:()=>iA});var iA=class extends qA{guid;static setActive(A,e,t=!0,i=!0){!A||(BD(A,e,i),cE(A),e&&t&&tD(ue.Current,A))}static isActiveSelf(A){return fa(A)}static isActiveInHierarchy(A){return Pq(A)}static markAsInstancedRendered(A,e){Wq(A,e)}static isUsingInstancing(A){return QD(A)}static foreachComponent(A,e,t=!0){return iC(A,e,t)}static instantiateSynced(A,e){return A?ID(A,e):null}static instantiate(A,e=null){return Sa(A,e)}static destroySynced(A,e,t=!0){if(!A)return;let i=A;e=e??ue.Current,hE(i,e.connection,t)}static destroy(A,e=!0,t=!0){return tC(A,e,t)}static add(A,e,t){if(!(!A||!e)){if(A===e){console.warn("Can not add object to self",A);return}t||(t=ue.Current),e.add(A),BD(A,!0),cE(A),t?iA.foreachComponent(A,i=>{YG(i,t),!i.__internalDidAwakeAndStart&&t.new_script_start.includes(i)===!1&&t.new_script_start.push(i)},!0):console.warn("Missing context")}}static remove(A){!A||(A.parent?.remove(A),BD(A,!1),cE(A),iA.foreachComponent(A,e=>{fq(e)},!0))}static invokeOnChildren(A,e,...t){this.invoke(A,e,!0,t)}static invoke(A,e,t=!1,...i){!A||this.foreachComponent(A,g=>{let C=g[e];C&&typeof C=="function"&&C.bind(g)(...i)},t)}static addNewComponent(A,e,t=!0){let i=new e;return cs(A,i,t),i}static addComponent(A,e){if(e.gameObject==null)throw new Error("Did you mean to create a new component? Use addNewComponent");vq(A,e)}static removeComponent(A){return oD(A.gameObject,A),A}static getOrAddComponent(A,e){return nD(A,e)}static getComponent(A,e){return A===null?null:ya(A,e)}static getComponents(A,e,t=null){return A===null?t??[]:dE(A,e,t)}static findByGuid(A,e){return wa(A,e)}static findObjectOfType(A,e,t=!0){return Yq(A,e??ue.Current,t)}static findObjectsOfType(A,e){let t=[];return _q(A,t,e),t}static getComponentInChildren(A,e){return ma(A,e)}static getComponentsInChildren(A,e,t=null){return uE(A,e,t??void 0)}static getComponentInParent(A,e){return lE(A,e)}static getComponentsInParent(A,e,t=null){return al(A,e,t)}static getAllComponents(A){return[...A.userData?.components]}static*iterateComponents(A){let e=A?.userData?.components;if(e&&Array.isArray(e))for(let t=0;t<e.length;t++)yield e[t]}},oC=class{get isComponent(){return!0}__context;get context(){return this.__context??ue.Current}set context(A){this.__context=A}get scene(){return this.context.scene}get layer(){return this.gameObject?.userData?.layer}get name(){return this.gameObject?.userData.name}__name;set name(A){this.gameObject?(this.gameObject.userData||(this.gameObject.userData={}),this.gameObject.userData.name=A,this.__name=A):this.__name=A}get tag(){return this.gameObject?.userData.tag}set tag(A){this.gameObject&&(this.gameObject.userData.tag=A)}get static(){return this.gameObject?.userData.static}get hideFlags(){return this.gameObject?.userData.hideFlags}get activeAndEnabled(){return!(this.destroyed||this.__isEnabled===!1||!this.__isActiveInHierarchy)}get __isActive(){return this.gameObject.visible}get __isActiveInHierarchy(){if(!this.gameObject)return!1;let A=this.gameObject[LC];return A===void 0?!0:A}set __isActiveInHierarchy(A){!this.gameObject||(this.gameObject[LC]=A)}gameObject;guid="invalid";sourceId;awake(){}onEnable(){}onDisable(){}onDestroy(){this.__destroyed=!0}startCoroutine(A,e=1){return this.context.registerCoroutineUpdate(this,A,e)}stopCoroutine(A,e=1){this.context.unregisterCoroutineUpdate(A,e)}get destroyed(){return this.__destroyed}destroy(){this.__destroyed||this.__internalDestroy()}__didAwake=!1;__didStart=!1;__didEnable=!1;__isEnabled=void 0;__destroyed=!1;get __internalDidAwakeAndStart(){return this.__didAwake&&this.__didStart}constructor(){this.__internalNewInstanceCreated()}__internalNewInstanceCreated(){this.__didAwake=!1,this.__didStart=!1,this.__didEnable=!1,this.__isEnabled=void 0,this.__destroyed=!1}__internalAwake(){this.__didAwake||(this.__didAwake=!0,this.awake())}__internalStart(){this.__didStart||(this.__didStart=!0,this.start&&this.start())}__internalEnable(){return this.__didEnable?!1:(this.__didEnable=!0,this.onEnable(),this.__isEnabled=!0,!0)}__internalDisable(){!this.__didEnable||(this.__didEnable=!1,this.onDisable(),this.__isEnabled=!1)}__internalDestroy(){this.__destroyed||(this.__destroyed=!0,this.destroy?.call(this),Tq(this))}get enabled(){return this.__isEnabled??!0}set enabled(A){if(typeof A=="number"&&(A>=.5?A=!0:A=!1),!this.__didAwake){this.__isEnabled=A;return}A?this.__internalEnable():this.__internalDisable()}_worldPosition=void 0;_worldQuaternion=void 0;_worldEuler=void 0;_worldRotation=void 0;get worldPosition(){return this._worldPosition||(this._worldPosition=new R),Ce(this.gameObject,this._worldPosition),this._worldPosition}set worldPosition(A){Ze(this.gameObject,A)}setWorldPosition(A,e,t){oC._worldPositionBuffer.set(A,e,t),this.worldPosition=oC._worldPositionBuffer}get worldQuaternion(){return this._worldQuaternion||(this._worldQuaternion=new vA),xt(this.gameObject,this._worldQuaternion)}set worldQuaternion(A){eg(this.gameObject,A)}setWorldQuaternion(A,e,t,i){oC._worldQuaternionBuffer.set(A,e,t,i),this.worldQuaternion=oC._worldQuaternionBuffer}get worldEuler(){return this._worldEuler||(this._worldEuler=new Ye),this._worldEuler.setFromQuaternion(this.worldQuaternion),this._worldEuler}set worldEuler(A){this._worldQuaternion||(this._worldQuaternion=new vA),this._worldQuaternion?.setFromEuler(A),this.worldQuaternion=this._worldQuaternion}get worldRotation(){let A=this.worldEuler;this._worldRotation||(this._worldRotation=new R);let e=this._worldRotation;return e.set(A.x,A.y,A.z),e.x=ce.toDegrees(e.x),e.y=ce.toDegrees(e.y),e.z=ce.toDegrees(e.z),e}set worldRotation(A){this.setWorldRotation(A.x,A.y,A.z,!0)}setWorldRotation(A,e,t,i=!0){i&&(A=ce.toRadians(A),e=ce.toRadians(e),t=ce.toRadians(t)),oC._worldEulerBuffer.set(A,e,t),oC._worldQuaternionBuffer.setFromEuler(oC._worldEulerBuffer),this.worldQuaternion=oC._worldQuaternionBuffer}get forward(){return oC._forward.set(0,0,-1).applyQuaternion(this.worldQuaternion)}_eventListeners=new Map;addEventListener(A,e){this._eventListeners[A]=this._eventListeners[A]||[],this._eventListeners[A].push(e)}removeEventListener(A,e){if(!this._eventListeners[A])return;let t=this._eventListeners[A].indexOf(e);t>=0&&this._eventListeners[A].splice(t,1)}dispatchEvent(A){if(!this._eventListeners[A.type])return!1;let e=this._eventListeners[A.type];for(let t=0;t<e.length;t++)e[t](A);return!1}},Wg=oC;mA(Wg,"_worldPositionBuffer",new R),mA(Wg,"_worldQuaternionBuffer",new vA),mA(Wg,"_worldEulerBuffer",new Ye),mA(Wg,"_tempQuaternionBuffer2",new vA),mA(Wg,"_forward",new R);var sA=class extends Wg{};var R1=cA("debugloadingbar");function GM(I){return I.index/I.count+I.progress.loaded/I.progress.total/I.count}var Sf=class{loadingProgress=0;container;_progress=0;_allowCustomLoadingElement=!1;_loadingElement;_loadingTextContainer=null;_loadingBar=null;_messageContainer=null;_loadingElementOptions;constructor(A,e){this.container=A,this._loadingElementOptions=e}onLoadingBegin(A){if(!this._loadingElement){for(let e=0;e<this.container.children.length;e++){let t=this.container.children[e];if(t.classList.contains("loading")){if(!this._allowCustomLoadingElement){console.warn("Custom loading container is not allowed"),this.container.removeChild(t);continue}this._loadingElement=this.createLoadingElement(t);return}}this._loadingElement=this.createLoadingElement()}this._progress=0,this.loadingProgress=0,this._loadingElement.style.display="flex",this.container.appendChild(this._loadingElement),this.smoothProgressLoop(),this.setMessage(A??"")}onLoadingUpdate(A,e){this._loadingElement?.parentElement||this.onLoadingBegin(e);let t=0;typeof A=="number"?t=A:("index"in A&&(t=GM(A)),!e&&"name"in A&&this.setMessage(A.name)),this.loadingProgress=t,e&&this.setMessage(e),this.updateDisplay()}onLoadingFinished(A){this.loadingProgress=1,this.setMessage(A??"")}setMessage(A){this._messageContainer&&(this._messageContainer.innerText=A)}_progressLoop;smoothProgressLoop(){if(this._progressLoop)return;let A=1/12;R1&&(A=.001);let e=1-.05;this._progressLoop=setInterval(()=>{if(this.loadingProgress>=1&&this._progress>=e){this._loadingElement&&(this._loadingElement.style.display="none",this._loadingElement.remove()),clearInterval(this._progressLoop),this._progressLoop=null;return}this._progress=ce.lerp(this._progress,this.loadingProgress,A*this.loadingProgress),this.updateDisplay()},A)}updateDisplay(){let A=this._progress,e=(A*100).toFixed(0)+"%";this._loadingBar&&(this._loadingBar.style.width=A*100+"%"),this._loadingTextContainer&&(this._loadingTextContainer.textContent=e)}createLoadingElement(A){this._loadingElement=A||document.createElement("div"),A||(this._loadingElement.style.position="fixed",this._loadingElement.style.width="100%",this._loadingElement.style.height="100%",this._loadingElement.style.left="0",this._loadingElement.style.top="0",this._loadingElement.style.backgroundColor="#000000",this._loadingElement.style.display="flex",this._loadingElement.style.alignItems="center",this._loadingElement.style.justifyContent="center",this._loadingElement.style.zIndex="1000",this._loadingElement.style.flexDirection="column",this._loadingElement.style.pointerEvents="none",this._loadingElement.style.color="white");let e=this._loadingElementOptions?.className??"loading";if(this._loadingElement.classList.add(e),this._loadingElementOptions?.additionalClasses)for(let o of this._loadingElementOptions.additionalClasses)this._loadingElement.classList.add(o);let t=document.createElement("div"),i=30;t.style.display="flex",t.style.width=i+"%",t.style.height="2px",t.style.background="rgba(255,255,255,.1)",this._loadingElement.appendChild(t),this._loadingBar=document.createElement("div"),t.appendChild(this._loadingBar);let g=function(o){return ce.lerp(i*.5,100-i*.5,o)+"%"};this._loadingBar.style.background=`linear-gradient(90deg, #02022B ${g(0)}, #0BA398 ${g(.4)}, #99CC33 ${g(.5)}, #D7DB0A ${g(1)})`,this._loadingBar.style.backgroundAttachment="fixed",this._loadingBar.style.width="0%",this._loadingBar.style.height="100%",this._loadingTextContainer=document.createElement("div"),this._loadingTextContainer.style.display="flex",this._loadingTextContainer.style.justifyContent="center",this._loadingTextContainer.style.marginTop=".9em",this._loadingElement.appendChild(this._loadingTextContainer);let C=document.createElement("div");return this._messageContainer=C,C.style.display="flex",C.style.fontSize=".8em",C.style.paddingTop=".5em",C.style.color="rgba(255,255,255,.5)",C.style.justifyContent="center",this._loadingElement.appendChild(C),this._loadingElement}};import{DRACOLoader as MM}from"three/examples/jsm/loaders/DRACOLoader.js";import{KTX2Loader as PL}from"three/examples/jsm/loaders/KTX2Loader.js";var Ol=cA("debugdecoders"),nC,Ss;function kM(I){I!==void 0&&typeof I=="string"&&(nC||(nC=new MM),Ol&&console.log("Setting draco decoder path to",I),nC.setDecoderPath(I))}function RM(I){I!==void 0&&typeof I=="string"&&(nC||(nC=new MM),Ol&&console.log("Setting draco decoder type to",I),nC.setDecoderConfig({type:I}))}function UM(I){I!==void 0&&typeof I=="string"&&(Ss||(Ss=new PL),Ol&&console.log("Setting ktx2 transcoder path to",I),Ss.setTranscoderPath(I))}function en(I,A){nC||(nC=new MM,nC.setDecoderPath("./include/draco/"),nC.setDecoderConfig({type:"js"}),Ol&&console.log("Setting draco decoder path to","./include/draco/")),Ss||(Ss=new PL,Ss.setTranscoderPath("./include/ktx2/"),Ol&&console.log("Setting ktx2 transcoder path to","./include/ktx2/"),A.renderer&&Ss.detectSupport(A.renderer)),I.setDRACOLoader(nC),I.setKTX2Loader(Ss)}var vE=class{_name;get name(){return this._name}_nameHash;get nameHash(){return this._nameHash}_normalizedTime;get normalizedTime(){return this._normalizedTime}_length;get length(){return this._length}_speed;get speed(){return this._speed}constructor(A,e,t,i){this._name=A.name,this._nameHash=A.hash,this._normalizedTime=e,this._length=t,this._speed=i}};function VL(I,A){return{name:"",isLooping:!1,guid:A?.generateUUID()??tl.generateUUID(),index:-1,clip:new $I(I,1,[])}}var ys=cA("debuganimatorcontroller"),FM=cA("debugrootmotion"),MI=class{Play(A,e=-1,t=Number.NEGATIVE_INFINITY,i=0){if(e<0)e=0;else if(e>=this.model.layers.length){console.warn("invalid layer");return}let C=this.model.layers[e].stateMachine;for(let o of C.states)if(o.name===A||o.hash===A){ys&&console.log("transition to ",o),this.transitionTo(o,i,t);return}console.warn("Could not find "+A+" to play")}Reset(){this.setStartTransition()}SetBool(A,e){let t=typeof A=="string"?"name":"hash";return this.model?.parameters.filter(i=>i[t]===A).forEach(i=>i.value=e)}GetBool(A){let e=typeof A=="string"?"name":"hash";return this.model?.parameters.find(t=>t[e]===A)?.value??!1}SetFloat(A,e){let t=typeof A=="string"?"name":"hash";return this.model?.parameters.filter(i=>i[t]===A).forEach(i=>i.value=e)}GetFloat(A){let e=typeof A=="string"?"name":"hash";return this.model?.parameters.find(t=>t[e]===A)?.value??0}SetInteger(A,e){let t=typeof A=="string"?"name":"hash";return this.model?.parameters.filter(i=>i[t]===A).forEach(i=>i.value=e)}GetInteger(A){let e=typeof A=="string"?"name":"hash";return this.model?.parameters.find(t=>t[e]===A)?.value??0}SetTrigger(A){ys&&console.log("SET TRIGGER",A);let e=typeof A=="string"?"name":"hash";return this.model?.parameters.filter(t=>t[e]===A).forEach(t=>t.value=!0)}ResetTrigger(A){let e=typeof A=="string"?"name":"hash";return this.model?.parameters.filter(t=>t[e]===A).forEach(t=>t.value=!1)}IsInTransition(){return this._activeStates.length>1}SetSpeed(A){this._speed=A}FindState(A){if(!A)return null;for(let e of this.model.layers)for(let t of e.stateMachine.states)if(t.name===A)return t;return null}normalizedStartOffset=0;_speed=1;animator;model;get context(){return this.animator?.context}bind(A){this.animator=A,this._mixer=new Oo(this.animator.gameObject),this.createActions(this.animator)}clone(){let A=il(this.model,(t,i,g)=>g==null?!0:!(g.type==="Object3D"||g.isObject3D===!0||g?.constructor?.name==="AnimationAction"||g.tracks!==void 0));return console.assert(A!==this.model),new MI(A)}update(){if(!this.animator)return;this.evaluateTransitions(),this.updateActiveStates();let A=this.animator.context.time.deltaTime;this.animator.applyRootMotion&&this.rootMotionHandler?.onBeforeUpdate(),this._mixer.update(A),this.animator.applyRootMotion&&this.rootMotionHandler?.onAfterUpdate()}_mixer;_activeState;constructor(A){this.model=A,ys&&console.log(this)}_activeStates=[];updateActiveStates(){for(let A=0;A<this._activeStates.length;A++){let e=this._activeStates[A],t=e.motion;if(!t.action)this._activeStates.splice(A,1),A--;else{let i=t.action;i.getEffectiveWeight()<=0&&!i.isRunning()&&(ys&&console.debug("REMOVE",e.name,i.getEffectiveWeight(),i.isRunning(),i.isScheduled()),this._activeStates.splice(A,1),A--)}}}setStartTransition(){for(let A of this.model.layers){let e=A.stateMachine,t=e.states[e.defaultState];this.transitionTo(t,0,this.normalizedStartOffset)}}evaluateTransitions(){let e=!1;if(!this._activeState){if(this.setStartTransition(),!this._activeState)return;e=!0}let t=this._activeState,i=t.motion.action,g=0;for(let o of t.transitions){if(++g,!o.hasExitTime&&o.conditions.length<=0)continue;let n=!0;for(let s of o.conditions)if(!this.evaluateCondition(s)){n=!1;break}if(!!n){for(let s of o.conditions){let r=this.model.parameters.find(a=>a.name===s.parameter);r?.type===9&&(r.value=!1)}if(i){let s=t.motion.clip.duration,r=s<=0?1:i.time/s;if(o.hasExitTime?r>=o.exitTime:!0){i.clampWhenFinished=!0,ys&&console.log("transition to "+o.destinationState,o,r,o.exitTime,o.hasExitTime),this.transitionTo(o.destinationState,o.duration,o.offset);return}}else{this.transitionTo(o.destinationState,o.duration,o.offset);return}}}let C=!1;if(t.motion.isLooping&&i&&i.time>=i.getClip().duration&&(C=!0,i.reset(),i.time=0,i.play()),!C&&t&&!e&&i&&this.animator&&t.behaviours){let o=i?.getClip().duration,n=i.time/o,s=new vE(this._activeState,n,o,this._speed);for(let r of t.behaviours)r.instance&&r.instance.onStateUpdate?.call(r.instance,this.animator,s,0)}}getState(A,e){return typeof A=="number"&&(A==-1&&(A=this.model.layers[e].stateMachine.defaultState),A=this.model.layers[e].stateMachine.states[A]),A}transitionTo(A,e,t){if(!this.animator)return;let i=0;if(A=this.getState(A,i),!A?.motion||!A.motion.clip)return;let g=this._activeState===A;if(g){let s=A.motion;!s.action_loopback&&s.clip&&(this._mixer.uncacheAction(s.clip,this.animator.gameObject),s.action_loopback=this.createAction(s.clip))}if(this._activeState?.behaviours&&this._activeState.motion.action){let s=this._activeState?.motion.clip.duration,r=this._activeState.motion.action.time/s,a=new vE(this._activeState,r,s,this._speed);for(let B of this._activeState.behaviours)B.instance?.onStateExit?.call(B.instance,this.animator,a,i)}let C=this._activeState?.motion.action;C&&C.fadeOut(e),g&&(A.motion.action=A.motion.action_loopback,A.motion.action_loopback=C);let o=this._activeState;this._activeState=A;let n=A.motion?.action;if(n){t=Math.max(0,Math.min(1,t)),n.isRunning()&&n.stop(),n.reset(),n.timeScale=this._speed,n.enabled=!0;let s=A.motion.clip.duration;if(n.time=t*s,n.clampWhenFinished=!0,n.setLoop(nE,0),e>0?n.fadeIn(e):n.setEffectiveWeight(1),n.play(),this.rootMotionHandler&&this.rootMotionHandler.onStart(n),this._activeStates.includes(A)||this._activeStates.push(A),this._activeState.behaviours){let r=new vE(A,t,s,this._speed);for(let a of this._activeState.behaviours)a.instance?.onStateEnter?.call(a.instance,this.animator,r,i)}}else console.warn("No action",A.motion,this);ys&&console.log("TRANSITION FROM "+o?.name+" TO "+A.name,e,C,n,n?.getEffectiveTimeScale(),n?.getEffectiveWeight(),n?.isRunning(),n?.isScheduled(),n?.paused)}createAction(A){if(this._mixer.existingAction(A)&&this._mixer.uncacheAction(A,this.animator?.gameObject),this.animator?.applyRootMotion){this.rootMotionHandler||(this.rootMotionHandler=new NM(this));let t=this.animator.gameObject;return this.rootMotionHandler.createClip(this._mixer,t,A)}else return this._mixer.clipAction(A)}evaluateCondition(A){let e=this.model.parameters.find(t=>t.name===A.parameter);if(!e)return!1;switch(A.mode){case 1:return e.value===!0;case 2:return e.value===!1;case 3:return e.value>A.threshold;case 4:return e.value<A.threshold;case 6:return e.value===A.threshold;case 7:return e.value!==A.threshold}return!1}createActions(A){for(let e of this.model.layers){let t=e.stateMachine;for(let i=0;i<t.states.length;i++){let g=t.states[i];if(g.motion||(g.motion=VL(g.name)),this.animator&&g.motion.clips){let C=g.motion.clips?.find(o=>o.node.name===this.animator?.gameObject?.name);g.motion.clip=C?.clip}if(!g.motion.clip){let C=new $I;g.motion.clip=C}if(g.motion?.clip){let C=g.motion.clip,o=this.createAction(C);g.motion.action=o}if(g.behaviours&&Array.isArray(g.behaviours))for(let C of g.behaviours){if(!C?.typeName)continue;let o=hA.get(C.typeName),n=new o;n.isStateMachineBehaviour&&(n._context=this.context??void 0,Zo(n,C.properties),C.instance=n),ys&&console.log("Created animator controller behaviour",g.name,C.typeName,C.properties,n)}}}}*enumerateActions(){for(let A of this.model.layers){let e=A.stateMachine;for(let t=0;t<e.states.length;t++){let i=e.states[t];i?.motion&&(i.motion.action&&(yield i.motion.action),i.motion.action_loopback&&(yield i.motion.action_loopback))}}}rootMotionHandler},yf=class{track;createdInterpolant;originalEvaluate;customEvaluate;constructor(A,e){this.track=A;let t=A,i=t.createInterpolant.bind(A);t.createInterpolant=()=>(t.createInterpolant=i,this.createdInterpolant=i(),this.originalEvaluate=this.createdInterpolant.evaluate.bind(this.createdInterpolant),this.customEvaluate=g=>{if(!this.originalEvaluate)return;let C=this.originalEvaluate(g);return e(g,C)},this.createdInterpolant.evaluate=this.customEvaluate,this.createdInterpolant)}evaluate(A){this.customEvaluate&&this.customEvaluate(A)}dispose(){this.createdInterpolant&&this.originalEvaluate&&(this.createdInterpolant.evaluate=this.originalEvaluate),this.track=void 0,this.createdInterpolant=null,this.originalEvaluate=void 0,this.customEvaluate=void 0}},Ht=class{set action(A){this._action=A}get action(){return this._action}_action;root;clip;positionWrapper=null;rotationWrapper=null;context;positionChange=new R;rotationChange=new vA;constructor(A,e,t,i,g){if(this.context=A,this.root=e,this.clip=t,Ht.firstKeyframeRotation[t.uuid]||(Ht.firstKeyframeRotation[t.uuid]=new vA),g){let C=g.values;Ht.firstKeyframeRotation[t.uuid].set(C[0],C[1],C[2],C[3])}Ht.spaceRotation[t.uuid]||(Ht.spaceRotation[t.uuid]=new vA),Ht.effectiveSpaceRotation[t.uuid]||(Ht.effectiveSpaceRotation[t.uuid]=new vA),Ht.clipOffsetRotation[t.uuid]=new vA,g&&Ht.clipOffsetRotation[t.uuid].set(g.values[0],g.values[1],g.values[2],g.values[3]).invert(),this.handlePosition(t,i),this.handleRotation(t,g)}onStart(A){if(A.getClip()!==this.clip)return;let e=Ht.lastObjRotation[this.root.uuid];Ht.spaceRotation[this.clip.uuid].copy(e);{let t=new Ye().setFromQuaternion(e);console.log("START",this.clip.name,ce.toDegrees(t.y))}}getClipRotationOffset(){return Ht.clipOffsetRotation[this.clip.uuid]}handlePosition(A,e){if(e){let t=this.root;FM&&t.add(new AC),Ht.lastObjPosition[t.uuid]||(Ht.lastObjPosition[t.uuid]=new R);let i=new R,g=new R,C=0;this.positionWrapper=new yf(e,(o,n)=>{let s=this.action.getEffectiveWeight();if(FM&&t.position.length()>8&&t.position.set(0,t.position.y,0),o>C){i.set(n[0],n[1],n[2]),i.sub(g),i.multiplyScalar(s),i.applyQuaternion(this.getClipRotationOffset());let r=this.clip.uuid;i.applyQuaternion(Ht.spaceRotation[r]),this.positionChange.copy(i)}return g.fromArray(n),C=o,n[0]=0,n[1]=0,n[2]=0,n})}}handleRotation(A,e){if(e){if(FM){let o=e.values,n=new Ye().setFromQuaternion(new vA(o[0],o[1],o[2],o[3]));console.log(A.name,e.name,"FIRST ROTATION IN TRACK",ce.toDegrees(n.y));let s=e.values.length-4,r=new vA().set(o[s],o[s+1],o[s+2],o[s+3]),a=new Ye().setFromQuaternion(r);console.log(A.name,e.name,"LAST ROTATION IN TRACK",ce.toDegrees(a.y))}let t=this.root;Ht.lastObjRotation[t.uuid]||(Ht.lastObjRotation[t.uuid]=new vA);let i=0,g=new vA,C=new vA;this.rotationWrapper=new yf(e,(o,n)=>(o>i&&(C.set(n[0],n[1],n[2],n[3]),g.invert(),C.multiply(g),this.rotationChange.copy(C)),g.fromArray(n),i=o,n[0]=0,n[1]=0,n[2]=0,n[3]=1,n))}}onBeforeUpdate(){this.positionChange.set(0,0,0),this.rotationChange.set(0,0,0,1)}onAfterUpdate(){let A=this.action.getEffectiveWeight();this.positionChange.multiplyScalar(A),this.rotationChange.slerp(Ht.identityQuaternion,1-A)}},sC=Ht;mA(sC,"lastObjPosition",{}),mA(sC,"lastObjRotation",{}),mA(sC,"firstKeyframeRotation",{}),mA(sC,"spaceRotation",{}),mA(sC,"effectiveSpaceRotation",{}),mA(sC,"clipOffsetRotation",{}),mA(sC,"identityQuaternion",new vA);var NM=class{controller;handler=[];root;constructor(A){this.controller=A}createClip(A,e,t){this.root=e;let i="";e&&"name"in e&&(i=e.name);let g=this.findRootTrack(t,".position"),C=this.findRootTrack(t,".quaternion"),o=new sC(this.controller.context,e,t,g,C);this.handler.push(o);let n=A.clipAction(t);return o.action=n,n}onStart(A){for(let e of this.handler)e.onStart(A)}onBeforeUpdate(){for(let A of this.handler)A.onBeforeUpdate()}summedPosition=new R;summedRotation=new vA;onAfterUpdate(){this.summedPosition.set(0,0,0),this.summedRotation.set(0,0,0,1);for(let A of this.handler)A.onAfterUpdate(),this.summedPosition.add(A.positionChange),this.summedRotation.multiply(A.rotationChange);this.root.position.add(this.summedPosition),this.root.quaternion.multiply(this.summedRotation),sC.lastObjRotation[this.root.uuid].copy(this.root.quaternion)}findRootTrack(A,e){let t=A.tracks;for(let i of t)if(i.name.endsWith(e))return i;return null}};var O=function(I){if(I===void 0&&(I=null),!Array.isArray(I))I=jL(I);else for(let A=0;A<I.length;A++){let e=I[A];I[A]=jL(e)}return function(A,e){Object.getOwnPropertyDescriptor(A,"$serializedTypes")||(A.$serializedTypes={});let t=A.$serializedTypes=A.$serializedTypes||{};t[e]=I}};function jL(I){switch(I?.prototype?.constructor?.name){case"Number":case"String":case"Boolean":return null}return I}var U1=cA("debuganimator"),vi=class extends sA{applyRootMotion=!1;hasRootMotion=!1;keepAnimatorControllerStateOnDisable=!1;set runtimeAnimatorController(A){this._animatorController&&this._animatorController.model===A||(A?A instanceof MI?this._animatorController=A:this._animatorController=new MI(A):this._animatorController=null)}get runtimeAnimatorController(){return this._animatorController}Play(A,e=-1,t=Number.NEGATIVE_INFINITY,i=0){this.runtimeAnimatorController?.Play(A,e,t,i)}Reset(){this._animatorController?.Reset()}SetBool(A,e){this.runtimeAnimatorController?.SetBool(A,e)}GetBool(A){return this.runtimeAnimatorController?.GetBool(A)??!1}SetFloat(A,e){this.runtimeAnimatorController?.SetFloat(A,e)}GetFloat(A){return this.runtimeAnimatorController?.GetFloat(A)??-1}SetInteger(A,e){this.runtimeAnimatorController?.SetInteger(A,e)}GetInteger(A){return this.runtimeAnimatorController?.GetInteger(A)??-1}SetTrigger(A){this.runtimeAnimatorController?.SetTrigger(A)}ResetTrigger(A){this.runtimeAnimatorController?.ResetTrigger(A)}IsInTransition(){return this.runtimeAnimatorController?.IsInTransition()??!1}SetSpeed(A){A!==this.speed&&(this.speed=A,this._animatorController?.SetSpeed(A))}set minMaxSpeed(A){this.speed=ce.lerp(A.x,A.y,Math.random())}set minMaxOffsetNormalized(A){this.normalizedStartOffset=ce.lerp(A.x,A.y,Math.random()),this.runtimeAnimatorController&&(this.runtimeAnimatorController.normalizedStartOffset=this.normalizedStartOffset)}speed=1;normalizedStartOffset=0;_animatorController=null;awake(){if(!!this.gameObject){if(this.runtimeAnimatorController){let A=this.runtimeAnimatorController.clone();console.assert(this.runtimeAnimatorController!==A),this.runtimeAnimatorController=A,console.assert(this.runtimeAnimatorController===A),this.runtimeAnimatorController.bind(this),this.runtimeAnimatorController.SetSpeed(this.speed),this.runtimeAnimatorController.normalizedStartOffset=this.normalizedStartOffset}U1&&console.log("ANIMATOR",this.name,this)}}onDisable(){this.keepAnimatorControllerStateOnDisable||this._animatorController?.Reset()}onBeforeRender(){this._animatorController&&this._animatorController.update()}};W([O()],vi.prototype,"applyRootMotion",2),W([O()],vi.prototype,"hasRootMotion",2),W([O()],vi.prototype,"keepAnimatorControllerStateOnDisable",2),W([O()],vi.prototype,"runtimeAnimatorController",1);var PC=class extends sA{playAutomatically=!0;randomStartTime=!0;minMaxSpeed;minMaxOffsetNormalized;_tempAnimationClipBeforeGameObjectExisted=null;get clip(){return this.animations?.length?this.animations[0]:null}set clip(A){if(!this.gameObject){this._tempAnimationClipBeforeGameObjectExisted=A;return}!A||(this.gameObject.animations||(this.gameObject.animations=[]),this.gameObject.animations.push(A))}set animations(A){this.gameObject.animations=A}get animations(){return this.gameObject.animations}get currentAction(){return this._currentActions[0]}get currentActions(){return this._currentActions}mixer=void 0;get actions(){return this._actions}set actions(A){this._actions=A}_actions=[];_currentActions=[];_handles=[];awake(){this._tempAnimationClipBeforeGameObjectExisted&&(this.clip=this._tempAnimationClipBeforeGameObjectExisted,this._tempAnimationClipBeforeGameObjectExisted=null),this.playAutomatically&&this.init()}onEnable(){if(this.playAutomatically&&this.actions.length>0&&this.currentActions.length<=0){let A=Math.floor(Math.random()*this.actions.length);this.play(A)}}start(){this.randomStartTime&&this.currentAction&&(this.currentAction.time=Math.random()*this.currentAction.getClip().duration)}update(){if(!!this.mixer){this.mixer.update(this.context.time.deltaTime);for(let A of this._handles)A._update();this._handles?.length>0&&tt.markDirty(this.gameObject)}}getAction(A){return this.actions?.find(e=>e.getClip().name===A)}get isPlaying(){for(let A=0;A<this._currentActions.length;A++)if(this._currentActions[A].isRunning())return!0;return!1}play(A,e){if(this.init(),!this.mixer)return;let t=A;if(typeof A=="number"){if(A>=this.animations.length)return;t=this.animations[A]}else typeof A=="string"&&(t=this.animations.find(g=>g.name===A));if(!t){console.error("Could not find clip",A);return}e||(e={}),e.minMaxOffsetNormalized||(e.minMaxOffsetNormalized=this.minMaxOffsetNormalized),e.minMaxSpeed||(e.minMaxSpeed=this.minMaxSpeed);for(let g of this.actions)if(g.getClip()===t)return this.internalOnPlay(g,e);let i=this.mixer.clipAction(t);return this.actions.push(i),this.internalOnPlay(i,e)}internalOnPlay(A,e){var t=this.currentAction;if(t===A&&t.isRunning()&&t.time<t.getClip().duration){let o=this.tryFindHandle(A);if(o)return o.getPromise()}let i=e?.exclusive??!0;e?.fadeDuration?(i&&t?.fadeOut(e.fadeDuration),A.fadeIn(e.fadeDuration)):i&&t?.stop(),A.reset(),A.enabled=!0,A.time=0,A.timeScale=1;let g=A.getClip();e?.minMaxOffsetNormalized&&(A.time=ce.lerp(e.minMaxOffsetNormalized.x,e.minMaxOffsetNormalized.y,Math.random())*g.duration),e?.minMaxSpeed&&(A.timeScale=ce.lerp(e.minMaxSpeed.x,e.minMaxSpeed.y,Math.random())),e?.clampWhenFinished&&(A.clampWhenFinished=!0),e?.startTime!==void 0&&(A.time=e.startTime),e?.loop!==void 0&&(A.loop=e.loop?bp:nE),A.play();let C=new KM(A,this.mixer,e,o=>{this._handles.splice(this._handles.indexOf(C),1)});return this._handles.push(C),C.getPromise()}tryFindHandle(A){for(let e of this._handles)if(e.action===A)return e}_didInit=!1;init(){if(!this._didInit&&(this._didInit=!0,!!this.gameObject)){this.actions=[],this.mixer=new Oo(this.gameObject);for(let A=0;A<this.animations.length;A++){let e=this.mixer.clipAction(this.animations[A]);this.actions.push(e)}}}};W([O()],PC.prototype,"playAutomatically",2),W([O()],PC.prototype,"randomStartTime",2);var KM=class{mixer;action;promise=null;resolve=null;reject=null;_options;_resolveCallback=null;_rejectCallback=null;_loopCallback;_finishedCallback;_resolvedOrRejectedCallback;constructor(A,e,t,i){this.action=A,this.mixer=e,this._resolvedOrRejectedCallback=i,this._options=t}getPromise(){return this.promise?this.promise:(this.promise=new Promise((A,e)=>{this._resolveCallback=A,this._rejectCallback=e,this.resolve=this.onResolve.bind(this),this.reject=this.onReject.bind(this)}),this._loopCallback=this.onLoop.bind(this),this._finishedCallback=this.onFinished.bind(this),this.mixer.addEventListener("loop",this._loopCallback),this.mixer.addEventListener("finished",this._finishedCallback),this.promise)}_update(){!this._options||this._options.endTime!==void 0&&this.action.time>this._options.endTime&&(this._options.loop===!0?this.action.time=this._options.startTime??0:(this.action.time=this._options.endTime,this.action.timeScale=0,this.onResolve()))}onResolve(){this.dispose(),this._resolvedOrRejectedCallback?.call(this,this),this._resolveCallback?.call(this,this.action)}onReject(A){this.dispose(),this._resolvedOrRejectedCallback?.call(this,this),this._rejectCallback?.call(this,A)}onLoop(A){}onFinished(A){A.action===this.action&&this.onResolve()}dispose(){this._loopCallback&&this.mixer.removeEventListener("loop",this._loopCallback),this._finishedCallback&&this.mixer.removeEventListener("finished",this._finishedCallback),this._loopCallback=void 0,this._finishedCallback=void 0}};import{GLTFLoader as _T}from"three/examples/jsm/loaders/GLTFLoader.js";var tn=cA("debugshaders"),TE="NEEDLE_techniques_webgl";var JM=class{objectToWorldMatrix=new te;worldToObjectMatrix=new te;objectToWorld=new Array;worldToObject=new Array;updateFrom(A){this.objectToWorldMatrix.copy(A.matrixWorld),Yl(this.objectToWorldMatrix,this.objectToWorld),this.worldToObjectMatrix.copy(A.matrixWorld).invert(),Yl(this.worldToObjectMatrix,this.worldToObject)}};var st=class extends XQ{identifier;onBeforeRenderSceneCallback=this.onBeforeRenderScene.bind(this);clone(){let A=super.clone();return zL(A),A}constructor(A,...e){super(...e),this.identifier=A,tn&&console.log(this),this.type="NEEDLE_CUSTOM_SHADER",this.uniforms[this._objToWorldName]||(this.uniforms[this._objToWorldName]={value:[]}),this.uniforms[this._worldToObjectName]||(this.uniforms[this._worldToObjectName]={value:[]}),this.uniforms[this._viewProjectionName]||(this.uniforms[this._viewProjectionName]={value:[]}),this.uniforms[this._sphericalHarmonicsName]&&this.waitForLighting(),(this.depthTextureUniform||this.opaqueTextureUniform)&&ue.Current.pre_render_callbacks.push(this.onBeforeRenderSceneCallback)}dispose(){super.dispose();let A=ue.Current.pre_render_callbacks.indexOf(this.onBeforeRenderSceneCallback);A>=0&&ue.Current.pre_render_callbacks.splice(A,1)}async waitForLighting(){let A=ue.Current;if(!A){console.error("Missing context");return}let e=await A.rendererData.getSceneLightingData(this.identifier);if(!e||!e.array){console.warn("Missing lighting data for custom shader, getSceneLightingData did not return anything");return}tn&&console.log(e);let t=e.array,i=e.texture;this.uniforms.unity_SpecCube0={value:i},pM(this.uniforms,t);let g=Math.sqrt(Math.PI*.5);this.uniforms.unity_SpecCube0_HDR={value:new Ie(g,g,g,g)},tn&&console.log("Set environment lighting",this.uniforms)}_sphericalHarmonicsName="unity_SpecCube0";_objToWorldName="hlslcc_mtx4x4unity_ObjectToWorld";_worldToObjectName="hlslcc_mtx4x4unity_WorldToObject";_viewProjectionName="hlslcc_mtx4x4unity_MatrixVP";_viewMatrixName="hlslcc_mtx4x4unity_MatrixV";_rendererData=new JM;get depthTextureUniform(){if(!!this.uniforms)return this.uniforms._CameraDepthTexture}get opaqueTextureUniform(){if(!!this.uniforms)return this.uniforms._CameraOpaqueTexture}onBeforeRenderScene(){this.opaqueTextureUniform&&ue.Current.setRequireColor(!0),this.depthTextureUniform&&ue.Current.setRequireDepth(!0)}onBeforeRender(A,e,t,i,g,C){i.attributes.tangent||i.computeTangents(),this.onUpdateUniforms(t,g)}onUpdateUniforms(A,e){let t=ue.Current;A&&(st.viewProjection&&this.uniforms[this._viewProjectionName]&&(st.viewProjection.copy(A.projectionMatrix).multiply(A.matrixWorldInverse),Yl(st.viewProjection,st._viewProjectionValues)),st.viewMatrix&&this.uniforms[this._viewMatrixName]&&(st.viewMatrix.copy(A.matrixWorldInverse),Yl(st.viewMatrix,st._viewMatrixValues)),this.uniforms[st._worldSpaceCameraPosName]&&st._worldSpaceCameraPos.setFromMatrixPosition(A.matrixWorld)),this.uniforms._TimeParameters?this.uniforms._TimeParameters.value=t.rendererData.timeVec4:this.uniforms._Time&&(this.uniforms._Time.value=t.rendererData.timeVec4);let i=t.mainLight;if(i){let o=Ce(i.gameObject,st._mainLightPosition);this.uniforms._MainLightPosition={value:o.normalize()},st._mainLightColor.set(i.color.r,i.color.g,i.color.b,0),this.uniforms._MainLightColor={value:st._mainLightColor};let n=i.intensity;st._lightData.z=n,this.uniforms.unity_LightData={value:st._lightData}}if(A&&(st.viewProjection&&this.uniforms[this._viewProjectionName]&&(this.uniforms[this._viewProjectionName].value=st._viewProjectionValues),st.viewMatrix&&this.uniforms[this._viewMatrixName]&&(this.uniforms[this._viewMatrixName].value=st._viewMatrixValues),this.uniforms[st._worldSpaceCameraPosName]&&(this.uniforms[st._worldSpaceCameraPosName]={value:st._worldSpaceCameraPos}),t.mainCameraComponent)){if(this.uniforms._ProjectionParams){let o=this.uniforms._ProjectionParams.value;o.x=1,o.y=t.mainCameraComponent.nearClipPlane,o.z=t.mainCameraComponent.farClipPlane,o.w=1/o.z,this.uniforms._ProjectionParams.value=o}if(this.uniforms._ZBufferParams){let o=this.uniforms._ZBufferParams.value,n=t.mainCameraComponent;o.x=1-n.farClipPlane/n.nearClipPlane,o.y=n.farClipPlane/n.nearClipPlane,o.z=o.x/n.farClipPlane,o.w=o.y/n.farClipPlane,this.uniforms._ZBufferParams.value=o}if(this.uniforms._ScreenParams){let o=this.uniforms._ScreenParams.value;o.x=t.domWidth,o.y=t.domHeight,o.z=1+1/o.x,o.w=1+1/o.y,this.uniforms._ScreenParams.value=o}}let g=this.depthTextureUniform;g&&(g.value=t.depthTexture);let C=this.opaqueTextureUniform;if(C&&(C.value=t.opaqueColorTexture),e){let o=this._rendererData;o.updateFrom(e),this.uniforms[this._worldToObjectName].value=o.worldToObject,this.uniforms[this._objToWorldName].value=o.objectToWorld}this.uniformsNeedUpdate=!0}},kI=st;mA(kI,"viewProjection",new te),mA(kI,"_viewProjectionValues",[]),mA(kI,"viewMatrix",new te),mA(kI,"_viewMatrixValues",[]),mA(kI,"_worldSpaceCameraPosName","_WorldSpaceCameraPos"),mA(kI,"_worldSpaceCameraPos",new R),mA(kI,"_mainLightColor",new Ie),mA(kI,"_mainLightPosition",new R),mA(kI,"_lightData",new Ie);var mf=class{get name(){return TE}parser;identifier;constructor(A,e){this.parser=A,this.identifier=e}loadMaterial(A){let e=this.parser.json.materials[A];if(!e)return tn&&console.log(A,this.parser.json.materials),null;if(!e.extensions||!e.extensions[TE])return tn&&console.log("material "+A+" does not use NEEDLE_techniques_webgl"),null;let t=e.extensions[TE].technique;if(t<0)return null;let i=this.parser.json.extensions[TE];if(!i)return null;tn&&console.log(i);let g=i.techniques[t];return g?new Promise(async(C,o)=>{let n=await HL(i,g.program),s=n?.fragmentShader,r=n?.vertexShader;if(!s||!r)return o();tn&&console.log("loadMaterial",e,n);let a={},B=g.uniforms;r.includes("_Time")&&(a._Time={value:new Ie(0,0,0,0)});for(let c in B){let l=c;switch(l){case"_TimeParameters":let d=new Ie;a[l]={value:d};break;case"hlslcc_mtx4x4unity_MatrixV":case"hlslcc_mtx4x4unity_MatrixVP":a[l]={value:[]};break;case"_MainLightPosition":case"_MainLightColor":case"_WorldSpaceCameraPos":a[l]={value:[0,0,0,1]};break;case"unity_OrthoParams":break;case"unity_SpecCube0":a[l]={value:null};break;default:case"_ScreenParams":case"_ZBufferParams":case"_ProjectionParams":a[l]={value:[0,0,0,0]};break;case"_CameraOpaqueTexture":case"_CameraDepthTexture":a[l]={value:null};break}}let Q=!1;if(e.extensions&&e.extensions[TE]){let c=e.extensions[TE];if(c.technique===t){tn&&console.log(e.name,"Material Properties",c);for(let l in c.values){let d=c.values[l];if(typeof d=="string"){if(d.startsWith("/textures/")){let u=d.substring(10),p=Number.parseInt(u);if(p>=0){let D=await this.parser.getDependency("texture",p);D&&(D.encoding=FC,D.needsUpdate=!0),a[l]={value:D};continue}}switch(l){case"alphaMode":d==="BLEND"&&(Q=!0);continue}}if(Array.isArray(d)&&d.length===4){a[l]={value:new Ie(d[0],d[1],d[2],d[3])};continue}a[l]={value:d}}}}let h=new kI(this.identifier,{name:e.name??"",uniforms:a,vertexShader:r,fragmentShader:s,lights:!1});switch(a._Cull?.value){case 0:h.side=Fi;break;case 1:h.side=Xi;break;case 2:h.side=Jg;break;default:h.side=Jg;break}h.transparent=Q,Q&&(h.depthWrite=!1),pM(a),h.onUpdateUniforms();for(let c in B){let l=c,d=B[c].type;if(a[l]?.value===void 0)switch(d){case 35678:a[l]={value:xL},console.warn("Missing/unassigned texture, fallback to white: "+l);break;default:console.warn("TODO: EXPECTED UNIFORM / fallback NOT SET: "+l,B[c]);break}}tn&&console.log(h.uuid,a),zL(h),C(h)}):null}};function zL(I){if(I.uniforms)for(let A in I.uniforms)Object.getOwnPropertyDescriptor(I,A)||Object.defineProperty(I,A,{get:()=>I.uniforms[A].value,set:e=>{I.uniforms[A].value=e,I.needsUpdate=!0}})}var ms=Xt,Gf="$___Export_Components",N1="NEEDLE_components",qM=class{[Da]},LM=class{node;nodeIndex;nodeDef;constructor(A,e,t){this.node=A,this.nodeIndex=e,this.nodeDef=t}},HE=class{get name(){return N1}parser;nodeToObjectMap={};exportContext;objectToNodeMap={};context;writer;registerExport(A){A.register(e=>{let t=e.serializeUserData.bind(e);return this.writer=e,e.serializeUserData=(i,g)=>{try{this.serializeUserData(i,g),t(i,g)}finally{this.afterSerializeUserData(i,g)}},this})}beforeParse(){this.exportContext={},this.objectToNodeMap={}}serializeUserData(A,e){let t=A.userData?.components;!t||t.length<=0||(delete A.userData.components,A[Gf]=t)}afterSerializeUserData(A,e){if(A.type==="Scene"&&ms&&console.log("DONE",JSON.stringify(e)),A[Gf]===void 0)return;let t=A[Gf];delete A[Gf],t!==null&&(A.userData.components=t)}writeNode(A,e){let t=this.writer.json.nodes.length;console.log(A.name,t,A.uuid);let i=new LM(A,t,e);this.exportContext[t]=i,this.objectToNodeMap[A.uuid]=t}afterParse(A){ms&&console.log("AFTER",A);for(let e in this.exportContext){let t=this.exportContext[e],i=t.node,g=t.nodeDef,C=t.nodeIndex,o=i.userData?.components;if(!o||o.length<=0)continue;let n=new qM;g.extensions=g.extensions||{},g.extensions[this.name]=n,this.context.object=i,this.context.nodeId=C,this.context.objectToNode=this.objectToNodeMap;let s=[];for(let r of o){this.context.target=r;let a=bi().writeBuiltinComponentData(r,this.context);a!==null&&s.push(a)}s.length>0&&(n[Da]=s,ms&&console.log("DID WRITE",i,"nodeIndex",C,s))}}beforeRoot(){return ms&&console.log("BEGIN LOAD"),this.nodeToObjectMap={},null}async afterRoot(A){let e=A.parser,t=e?.extensions;if(!t)return;let i=t[this.name];ms&&console.log("After root",A,this.parser,t);let g=[];if(i===!0){let C=e.json.nodes;for(let o=0;o<C.length;o++){let n=await e.getDependency("node",o);this.nodeToObjectMap[o]=n}for(let o=0;o<C.length;o++){let n=C[o],s=o,r=n.extensions;if(!r)continue;let a=r[this.name];if(!a)continue;ms&&console.log("NODE",n);let B=this.nodeToObjectMap[s];if(!B){console.error("Could not find object for node index: "+s,n,e);continue}pE(B),g.push(this.createComponents(B,a))}}await Promise.all(g)}async createComponents(A,e){if(!e)return;let t=e[Da];if(t){ms&&console.log(A.name,t);for(let i in t){let g=t[i];ms&&console.log("Serialized data",JSON.parse(JSON.stringify(g))),g&&this.parser&&await BE(this.parser,g),A.userData=A.userData||{},A.userData[Da]=A.userData[Da]||[],A.userData[Da].push(g)}}}};import{EXRLoader as K1}from"three/examples/jsm/loaders/EXRLoader";var bM=cA("debugexr"),Mf=class{constructor(A){this.parser=A,this.name="EXT_texture_exr",bM&&console.log(A)}loadTexture(A){let e=this.name,t=this.parser,g=t.json.textures[A];if(bM&&console.log("EXT_texture_exr.loadTexture",A,g),!g.extensions||!g.extensions[e])return null;let C=g.extensions[e],o=new K1(t.options.manager);return bM&&console.log("EXT_texture_exr.loadTexture",C,o),t.loadTextureImage(A,C.source,o)}};var ZL="NEEDLE_gameobject_data",kf=class{get name(){return ZL}parser;constructor(A){this.parser=A}afterRoot(A){let e=[];for(let t=0;t<this.parser.json.nodes.length;t++){let i=this.parser.json.nodes[t];if(i&&i.extensions){let g=i.extensions[ZL];if(g){let C=this.findAndApplyExtensionData(t,g);e.push(C)}}}return Promise.all(e).then(()=>{})}async findAndApplyExtensionData(A,e){let t=await this.parser.getDependency("node",A);t&&this.applyExtensionData(t,e)}applyExtensionData(A,e){A.userData.layer=e.layers,A.layers.disableAll(),A.layers.set(e.layers),A.userData.tag=e.tag,A.userData.hideFlags=e.hideFlags,A.userData.static=e.static,A.visible=e.activeSelf,A.guid=e.guid}};var XL="NEEDLE_lighting_settings",YE=cA("debugenvlight"),Rf=class{get name(){return XL}parser;sourceId;context;constructor(A,e,t){this.parser=A,this.sourceId=e,this.context=t}afterRoot(A){let e=this.parser.json.extensions;if(e){let t=e[XL];if(t){YE&&console.log(t);let i=iA.addNewComponent(A.scene,xM,!1);i.sourceId=this.sourceId,i.ambientIntensity=t.ambientIntensity,i.ambientLight=new P().fromArray(t.ambientLight),Array.isArray(t.ambientTrilight)&&(i.ambientTrilight=t.ambientTrilight.map(g=>new P().fromArray(g))),i.ambientMode=t.ambientMode,i.environmentReflectionSource=t.environmentReflectionSource,this.context&&this.context.rendererData.registerSceneLightSettings(i)}}return null}},xM=class extends sA{ambientMode=0;ambientLight;ambientTrilight;ambientIntensity=1;environmentReflectionSource=0;_hasReflection=!1;_ambientLightObj;_lightProbeObj;awake(){if(this.sourceId){let A=this.environmentReflectionSource===0?1:2,e=this.context.lightmaps.tryGet(this.sourceId,A,0);this._hasReflection=e!=null,e&&this.context.rendererData.registerReflection(this.sourceId,e)}YE&&window.addEventListener("keydown",A=>{switch(A.key){case"l":this.enabled=!this.enabled;break}})}onEnable(){let A=this.context.mainCameraComponent?.sourceId===this.sourceId;if(YE&&console.log("Enable scene lighting",this.sourceId,A,this,this.context.mainCameraComponent?.sourceId),A||YE&&console.warn("This is no active?!",this.context.mainCameraComponent?.sourceId),this.ambientMode==3)this.ambientLight&&!this._ambientLightObj&&(this._ambientLightObj=new iE(this.ambientLight,Math.PI*this.ambientIntensity)),this._ambientLightObj&&this.gameObject.add(this._ambientLightObj),this._lightProbeObj&&this._lightProbeObj.removeFromParent();else if(this.ambientMode===1){if(this.ambientTrilight){let e=this.ambientTrilight[0],t=this.ambientTrilight[this.ambientTrilight.length-1],i=new $Q(t,e,this.ambientIntensity);this.gameObject.add(i)}}else this._ambientLightObj&&this._ambientLightObj.removeFromParent(),this._lightProbeObj?this.enabled&&this.destroyed&&this._lightProbeObj&&this.scene.add(this._lightProbeObj):this.sourceId&&this.context.rendererData.getSceneLightingData(this.sourceId).then(e=>{YE&&console.log(e),e&&(this._lightProbeObj=e.lightProbe,this.enabled&&!this.destroyed&&this._lightProbeObj&&this.scene.add(this._lightProbeObj))});this.sourceId&&this.context.rendererData.enableReflection(this.sourceId)}onDisable(){YE&&console.log("disable",this.sourceId,this),this._lightProbeObj&&this._lightProbeObj.removeFromParent(),this._ambientLightObj&&this._ambientLightObj.removeFromParent(),this.sourceId&&this.context.rendererData.disableReflection()}};var vM=cA("debugstencil");function J1(I,A){return(I&1<<A.layer)!=0}var Ya=class{static applyStencil(A){if(!A)return;let e=A.sourceId;if(vM&&console.log(e,Ya.stencils),!e)return;let t=Ya.stencils[e];if(!!t)for(let i=t.length-1;i>=0;i--){let g=t[i];if(J1(g.layer,A)){vM&&console.log(g);let C=A.sharedMaterial?.clone();C&&(A.sharedMaterial=C,A.gameObject.renderOrder=g.event*1e3+g.index*50,C.stencilWrite=!0,C.stencilWriteMask=255,C.stencilFuncMask=255,C.stencilRef=g.value,C.stencilFunc=g.compareFunc,C.stencilZPass=g.passOp,C.stencilFail=g.failOp,C.stencilZFail=g.zFailOp);break}}}parser;source;constructor(A,e){this.parser=A,this.source=e}afterRoot(A){let e=this.parser.json.extensions;if(e){let t=e[L1];if(t){vM&&console.log(t);let i=t.stencil;if(i&&Array.isArray(i))for(let g of i){let C={...g};C.compareFunc=q1(C.compareFunc),C.passOp=TM(C.passOp),C.failOp=TM(C.failOp),C.zFailOp=TM(C.zFailOp),Ya.stencils[this.source]||(Ya.stencils[this.source]=[]),Ya.stencils[this.source].push(C)}}}return null}},_a=Ya;mA(_a,"stencils",{});function TM(I){switch(I){case 0:return NQ;case 1:return AG;case 2:return eG;case 3:return tG;case 4:return iG;case 6:return gG;case 7:return IG;case 5:return CG}return 0}function q1(I){switch(I){case 1:return oG;case 2:return nG;case 3:return sG;case 4:return rG;case 5:return aG;case 6:return BG;case 7:return QG;case 8:return vp}return 0}var L1="NEEDLE_render_objects";import{GLTFLoader as b1}from"three/examples/jsm/loaders/GLTFLoader";var HM="NEEDLE_deferred_texture",dg=cA("debugprogressive"),_M=new Map,YM=!1;dg&&window.addEventListener("keyup",I=>{I.key==="p"&&(_M.forEach((A,e)=>{Object.entries(A).forEach(([t,i])=>{YM?e[t]=i.lod0:e[t]=i.original,e.needsUpdate=!0})}),YM=!YM)});var Pl=class{static assignTextureLOD(A,e,t,i=0){if(!!t)for(let g of Object.keys(t)){let C=t[g];C?.isTexture===!0&&(dg&&console.log(`-----------
6391
6391
  `,"FIND",t.name,g,C?.name,C?.userData,C),Pl.getOrLoadTexture(A,e,t,g,C,i).then(o=>{if(o?.isTexture===!0&&(o.needsUpdate=!0,dg&&console.log("Assign LOD",t.name,g,o.name,o.guid,t,"Prev:",C,"Now:",o,`
6392
- --------------`),t[g]=o,t.needsUpdate=!0,dg)){let n=_M.get(t);n||(n={},_M.set(t,n));let s=n[g];s||(s=n[g]={original:C,lod0:o}),s.lod0=o}}))}}get name(){return HM}parser;sourceId;context;constructor(A,e,t){this.parser=A,this.sourceId=e,this.context=t}_loading=[];afterRoot(A){return dg&&console.log("AFTER",this.sourceId,A),this.parser.json.textures?.forEach((e,t)=>{if(e?.extensions){let i=e?.extensions[HM];if(i){let g=this.parser.getDependency("texture",t);this._loading.splice(this._loading.indexOf(t),1),g.then(C=>{dg&&console.log("register texture",C.name,C.uuid,i),C.userData.deferred=i,Pl.cache.set(C.uuid,i)})}}}),null}static async getOrLoadTexture(A,e,t,i,g,C){let o=g.uuid,n=Pl.cache.get(o);if(n){dg&&console.log(o,n.uri,n.guid);let s=JC(e,n.uri);if(s.endsWith(".glb")||s.endsWith(".gltf")){if(!n.guid)return console.warn("missing pointer for glb/gltf texture",n),null;let r=s+"_"+n.guid;if(this.resolved[r])return dg&&console.log("Texture has already been loaded: "+r,t.name,i,g.name),this.resolved[r];let a=new b1;en(a,A),dg&&console.log("Load "+s,t.name,i,n.guid);let B=await a.loadAsync(s),Q=B.parser;dg&&console.log("Loading finished "+s,t.name,i,n.guid);let h=-1,E=!1;for(let l of B.parser.json.textures)if(h++,l?.extensions){let d=l?.extensions[HM];if(d?.guid&&d.guid===n.guid){E=!0;break}}if(!E)return null;let c=await Q.getDependency("texture",h);return c&&(c.guid=n.guid),this.resolved[r]=c,dg&&console.log(t.name,i,'change "'+g.name+'" \u2192 "'+c.name+'"',s,h,c,t,r),c}else{dg&&console.log("Load texture from uri: "+s);let a=await new _o().loadAsync(s);return a&&dg?console.log(n,a):console.warn("failed loading",s),a}}else dg&&console.warn("unknown uuid",g.name,g.uuid,g);return null}},gn=Pl;mA(gn,"cache",new Map),mA(gn,"resolved",{});function PM(I){let A=new HE;return I.register(e=>(A.parser=e,A)),A}var OM=class{resolvePath(A){return A.includes("/extensions/builtin_components/")?A.replace("/extensions/builtin_components/","/userData/components/"):A.includes("extensions/builtin_components/")?A.replace("extensions/builtin_components/","/userData/components/"):A}};function WM(I,A,e){I.register(i=>new kf(i)),I.register(i=>new Op(i)),I.register(i=>new pf(i,A.lightmaps,e)),I.register(i=>new Rf(i,e,A)),I.register(i=>new mf(i,e)),I.register(i=>new _a(i,e)),I.register(i=>new gn(i,e,A)),I.register(i=>new Mf(i));let t=I.setAnimationPointerResolver;typeof t=="function"&&t.bind(I)(new OM)}var In=class extends sA{from;to;width=0;centered=!0;_centerPos;awake(){this._centerPos=new R}update(){if(!this.from||!this.to)return;let A=Ce(this.from).clone(),e=Ce(this.to).clone(),t=A.distanceTo(e);this._centerPos.copy(A),this._centerPos.add(e),this._centerPos.multiplyScalar(.5),Ze(this.gameObject,this.centered?this._centerPos:A),this.gameObject.lookAt(Ce(this.to).clone()),this.gameObject.scale.set(this.width,this.width,t)}};W([O(iA)],In.prototype,"from",2),W([O(iA)],In.prototype,"to",2);var WC=class{time;value;inTangent;inWeight;outTangent;outWeight;weightedMode};W([O()],WC.prototype,"time",2),W([O()],WC.prototype,"value",2),W([O()],WC.prototype,"inTangent",2),W([O()],WC.prototype,"inWeight",2),W([O()],WC.prototype,"outTangent",2),W([O()],WC.prototype,"outWeight",2),W([O()],WC.prototype,"weightedMode",2);var Gs=class{keys;get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(A){if(!this.keys||this.keys.length==0)return 0;let e=null;for(let t of this.keys){if(e&&t.time>A&&A>e.time)return ce.lerp(e.value,t.value,(A-e.time)/(t.time-e.time));e=t}return this.keys[this.keys.length-1].value}};W([O(WC)],Gs.prototype,"keys",2);import{PositionalAudioHelper as x1}from"three/examples/jsm/helpers/PositionalAudioHelper.js";var ug=cA("debugaudio");var oi=class extends sA{static get userInteractionRegistered(){return oi._didCallBeginWaitForUserInteraction||(oi._didCallBeginWaitForUserInteraction=!0,oi._beginWaitForUserInteraction()),oi._userInteractionRegistered}static registerWaitForAllowAudio(A){if(A!==null){if(this._userInteractionRegistered){A();return}this.callbacks.indexOf(A)===-1&&this.callbacks.push(A),oi._didCallBeginWaitForUserInteraction||(oi._didCallBeginWaitForUserInteraction=!0,oi._beginWaitForUserInteraction())}}static _beginWaitForUserInteraction(A=null){if(this._userInteractionRegistered){A&&A();return}A!==null&&this.registerWaitForAllowAudio(A);let t=(()=>{if(t!=null&&!oi._userInteractionRegistered){oi._userInteractionRegistered=!0,console.log("registered interaction, can play audio now"),document.removeEventListener("pointerdown",t),document.removeEventListener("click",t),document.removeEventListener("dragstart",t),document.removeEventListener("touchstart",t);for(let i of this.callbacks)i();this.callbacks.length=0}}).bind(this);document.addEventListener("pointerdown",t),document.addEventListener("click",t),document.addEventListener("dragstart",t),document.addEventListener("touchstart",t)}clip="";playOnAwake=!1;get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(A){this._loop=A,this.sound&&this.sound.setLoop(A)}get spatialBlend(){return this._spatialBlend}set spatialBlend(A){A!==this._spatialBlend&&(this._spatialBlend=A,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(A){this._minDistance!==A&&(this._minDistance=A,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(A){this._maxDistance!==A&&(this._maxDistance=A,this._needUpdateSpatialDistanceSettings=!0)}_spatialBlend=0;_minDistance=1;_maxDistance=100;get volume(){return this._volume}set volume(A){this._volume=A,this.sound&&(ug&&console.log(this.name,"audio set volume",A),this.sound.setVolume(A))}_volume=1;rollOffMode=0;_loop=!1;sound=null;helper=null;wasPlaying=!1;audioLoader=null;shouldPlay=!1;_lastClipStartedLoading=null;get Sound(){if(!this.sound&&oi._userInteractionRegistered){let A=iA.getComponent(this.context.mainCamera,RI)??iA.findObjectOfType(RI,this.context);A?.listener&&(this.sound=new jh(A.listener),this.gameObject.add(this.sound))}return this.sound}get ShouldPlay(){return this.shouldPlay}_focusCallback;awake(){this.audioLoader=new rs,this.playOnAwake&&(this.shouldPlay=!0),window.addEventListener("visibilitychange",A=>{switch(document.visibilityState){case"hidden":this.wasPlaying=this.isPlaying,this.pause();break;case"visible":this.wasPlaying&&this.play();break}}),this._focusCallback=()=>{this.enabled&&this.playOnAwake&&!this.isPlaying&&oi._userInteractionRegistered&&this.play()},this.context.application.addEventListener("application-visible",this._focusCallback)}onDestroy(){this.context.application.removeEventListener("application-visible",this._focusCallback)}onEnable(){oi._userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():oi._beginWaitForUserInteraction(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.loadAndPlay(this.clip)})}onDisable(){this.stop()}lerp=(A,e,t)=>A*(1-t)+e*t;onLoaded(A){ug&&console.log("audio buffer loaded"),oi.registerWaitForAllowAudio(()=>{ug&&console.log("finished loading",A);let e=this.Sound;if(!e){console.warn("Failed getting sound",this.name);return}e.isPlaying&&e.stop(),e.setBuffer(A),e.loop=this.loop,e.setVolume(this.volume),e.autoplay=this.shouldPlay,this.applySpatialDistanceSettings(),e.isPlaying&&e.stop(),ug&&console.log(this.name,this.shouldPlay,oi.userInteractionRegistered,this),this.shouldPlay&&oi._userInteractionRegistered&&this.play()})}applySpatialDistanceSettings(){let A=this.sound;if(!A)return;this._needUpdateSpatialDistanceSettings=!1;let e=this.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch(ug&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+e),A.setRefDistance(e),A.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:A.setDistanceModel("exponential");break;case 1:A.setDistanceModel("linear");break;case 2:break}this.spatialBlend>0?ug&&!this.helper&&(this.helper=new x1(A,A.getRefDistance()),A.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}loadAndPlay(A){if(A&&(this.clip=A),this.clip&&(ug&&console.log(this.clip),this.clip.endsWith(".mp3")||this.clip.endsWith(".wav"))){if(this.audioLoader||(this.audioLoader=new rs),this.shouldPlay=!0,this._lastClipStartedLoading===this.clip){ug&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=this.clip,ug&&console.log("load audio",this.clip),this.audioLoader.load(this.clip,this.onLoaded.bind(this),()=>{},console.error)}}play(A=void 0){if(!this.audioLoader||!this.sound||A&&A!==this.clip){this.loadAndPlay(A);return}this.shouldPlay=!0,this._hasEnded=!1,ug&&console.log("play",this.sound?.getVolume(),this.sound),this.sound&&!this.sound.isPlaying&&this.sound.play()}pause(){ug&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.isPlaying&&this.sound.source&&(this._lastContextTime=this.sound?.context.currentTime,this.sound.pause())}stop(){ug&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.source&&(this._lastContextTime=this.sound?.context.currentTime,ug&&console.log(this._lastContextTime),this.sound.stop())}_lastContextTime=0;get isPlaying(){return this.sound?.isPlaying??!1}set isPlaying(A){}get time(){return this.sound?.source?this.sound.source?.context.currentTime-this._lastContextTime+this.sound.offset:0}set time(A){if(this.sound){if(A===this.sound.offset)return;let e=this.isPlaying;this.stop(),this.sound.offset=A,e&&this.play()}}_hasEnded=!0;_needUpdateSpatialDistanceSettings=!1;update(){this.helper&&(this.isPlaying&&this.helper.update(),this.helper.visible=this.isPlaying),this._needUpdateSpatialDistanceSettings&&this.applySpatialDistanceSettings(),this.sound&&!this.sound.isPlaying&&this.shouldPlay&&!this._hasEnded&&(this._hasEnded=!0,ug&&console.log("Audio clip ended",this.clip),this.sound.dispatchEvent({type:"ended",target:this}))}},Xe=oi;mA(Xe,"_didCallBeginWaitForUserInteraction",!1),mA(Xe,"callbacks",[]),mA(Xe,"_userInteractionRegistered",!1),W([O()],Xe.prototype,"clip",2),W([O()],Xe.prototype,"playOnAwake",2),W([O()],Xe.prototype,"loop",1),W([O()],Xe.prototype,"spatialBlend",1),W([O()],Xe.prototype,"minDistance",1),W([O()],Xe.prototype,"maxDistance",1),W([O()],Xe.prototype,"volume",1),W([O()],Xe.prototype,"rollOffMode",2);var ft=class extends P{alpha=1;get isRGBAColor(){return!0}constructor(A,e,t,i){super(A,e,t),this.alpha=i}clone(){let A=super.clone();return A.alpha=this.alpha,A}copy(A){return super.copy(A),"alpha"in A&&typeof A.alpha=="number"?this.alpha=A.alpha:typeof A.a=="number"&&(this.alpha=A.a),this}lerp(A,e){let t=A;return t.alpha&&(this.alpha=ce.lerp(this.alpha,t.alpha,e)),super.lerp(A,e)}multiply(A){let e=A;return e.alpha&&(this.alpha=this.alpha*e.alpha),super.multiply(A)}};var Uf=cA("debugcam"),rt=class extends sA{get isCamera(){return!0}get aspect(){return this._cam instanceof et?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._fov}set fieldOfView(A){let e=this._fov!=A;this._fov=A,e&&this._cam&&this._cam instanceof et&&(this._cam.fov=this._fov,this._cam.updateProjectionMatrix())}get nearClipPlane(){return this._nearClipPlane}set nearClipPlane(A){let e=this._nearClipPlane!=A;this._nearClipPlane=A,this._cam&&e&&(this._cam.near=A,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(A){let e=this._farClipPlane!=A;this._farClipPlane=A,this._cam&&e&&(this._cam.far=A,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(A){A!==this._clearFlags&&(this._clearFlags=A,this.applyClearFlagsIfIsActiveCamera())}orthographic=!1;orthographicSize=5;ARBackgroundAlpha=0;_nearClipPlane=.1;_farClipPlane=1e3;get backgroundColor(){return this._backgroundColor??null}set backgroundColor(A){if(!!A){if(this._backgroundColor)this._backgroundColor.copy(A);else{if(!A.clone)return;this._backgroundColor=A.clone()}this.applyClearFlagsIfIsActiveCamera()}}_backgroundColor;_fov=60;_cam=null;_clearFlags=2;_skybox;get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}awake(){this.sourceId||console.warn("Camera has no source - the camera should be exported inside a gltf",this.name)}onEnable(){Uf&&console.log(this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&this.context.setCurrentCamera(this),this.applyClearFlagsIfIsActiveCamera()}onDisable(){this.context.removeCamera(this)}buildCamera(){if(this._cam)return;let A=this.gameObject.isCamera,e=null;if(A?e=this.gameObject:e=this.gameObject.children[0],e&&e.isCamera)e.type==="PerspectiveCamera"&&(e.fov=this._fov,e.near=this._nearClipPlane,e.far=this._farClipPlane,e.updateProjectionMatrix());else if(!this.orthographic)e=new et(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),e.fov=this.fieldOfView;else{let t=this.orthographicSize*100;e=new gs(window.innerWidth/-t,window.innerWidth/t,window.innerHeight/t,window.innerHeight/-t,this._nearClipPlane,this._farClipPlane)}this._cam=e,this.layer===0&&this._cam.layers.enableAll(),this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){if(Uf&&eC("apply Camera clear flags"),this._cam&&this.context.mainCameraComponent===this)switch(this._clearFlags){case 1:if(this.environmentIsTransparent()&&(!this.ARBackgroundAlpha||this.ARBackgroundAlpha<.001)){this.context.scene.background=null,this.context.renderer.setClearColor(0,0);return}this.enableSkybox();break;case 2:if(this._backgroundColor){let A=this._backgroundColor.alpha;this.environmentIsTransparent()&&(A=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,A)}break;case 4:this.context.scene.background=null,this.context.renderer.setClearColor(0,0);break}}environmentIsTransparent(){let A=this.context.renderer.xr?.getSession();if(!A)return!1;let e=A.environmentBlendMode;Uf&&eC("Environment blend mode: "+e+" on "+navigator.userAgent);let t=e==="additive"||e==="alpha-blend";if(this.context.xrSessionMode==="immersive-ar"&&e==="opaque"){if(navigator.userAgent?.includes("OculusBrowser"))return!0;if(navigator.userAgent?.includes("Mozilla")&&navigator.userAgent?.includes("Mobile WebXRViewer/v2"))return!0}return t}enableSkybox(){this._skybox||(this._skybox=new VM(this)),this._skybox.enable()}};W([O()],rt.prototype,"fieldOfView",1),W([O()],rt.prototype,"nearClipPlane",1),W([O()],rt.prototype,"farClipPlane",1),W([O()],rt.prototype,"clearFlags",1),W([O()],rt.prototype,"orthographic",2),W([O()],rt.prototype,"orthographicSize",2),W([O()],rt.prototype,"ARBackgroundAlpha",2),W([O(ft)],rt.prototype,"backgroundColor",1);var VM=class{_camera;_skybox;get context(){return this._camera?.context}constructor(A){this._camera=A}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?(Uf&&console.log("Set skybox",this._camera,this._skybox),this._skybox.encoding=Ue,this._skybox.mapping=Bg,this.context.scene.background=this._skybox):console.warn("Failed to load/find skybox texture",this)}};var RI=class extends sA{get listener(){return this._listener==null&&(this._listener=new Qa),this._listener}_listener=null;awake(){Xe.registerWaitForAllowAudio(()=>{let A=this.listener;if(A==null||A.parent)return;let e=iA.getComponentInParent(this.gameObject,rt);e?e.cam.add(A):this.gameObject.add(A)})}};import{GLTFLoader as T1}from"three/examples/jsm/loaders/GLTFLoader";var Wl=cA("debugavatar"),Ms=class{root;head;leftHand;rigthHand;get isValid(){return this.head!==null&&this.head!==void 0}constructor(A,e,t,i){this.root=A,this.head=e,this.leftHand=t,this.rigthHand=i,this.root?.traverse(g=>g.layers.set(2))}},Cn=class{avatarRegistryUrl=null;async getOrCreateNewAvatarInstance(A,e){if(!e)return console.error("Can not create avatar: failed to provide id or root object"),null;let t=null;if(typeof e=="string"){if(t=await this.loadAvatar(A,e),!t){let g=new wi;t=iA.instantiate(Qs(e,A.scene),g)}}else t=e;if(!t)return null;let i=this.findAvatar(t);return i.isValid?(Wl&&console.log("[Custom Avatar] valid config",e,Wl?i:""),i):(console.warn("[Custom Avatar] config isn't valid",e,Wl?i:""),null)}async loadAvatar(A,e){if(console.assert(e!=null&&typeof e=="string","Avatar id must not be null"),e.length<=0||!e)return null;if(Wl&&console.log("[Custom Avatar] "+e+", loading..."),e.endsWith(".glb")||(e+=".glb"),this.avatarRegistryUrl===null){let i=await fetch("./"+e),g=null;if(i.ok){let o=await i.blob();o&&(g=await o.arrayBuffer())}return!g&&(g=await Qf(e,e,0,"no url here go away",!0),!g)?null:(await bi().parseSync(A,g,null,0))?.scene??null}let t=new T1;return en(t,A),new Promise((i,g)=>{let C=this.avatarRegistryUrl+"/"+e;t.load(C,async o=>{await bi().createBuiltinComponents(A,C,o,null,void 0),i(o.scene)},o=>{Wl&&console.log("[Custom Avatar] "+o.loaded/o.total*100+"% loaded of "+o.total/1024+"kB")},o=>{console.error("[Custom Avatar] Error when loading: "+o),i(null)})})}cacheModel(A,e){}findAvatar(A){let e=A,t=e;t.children.length==1&&(t=A.children[0]);let i=this.findAvatarPart(t,["head"]),g=this.findAvatarPart(t,["left","hand"]),C=this.findAvatarPart(t,["right","hand"]);if(!i){i=e;let n=new R;new jt().setFromObject(i).getSize(n);let s=Math.max(n.x,n.y,n.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+s+" meters! Should be < 0.3m"),s>.3&&i.scale.multiplyScalar(1/s*.3)}return new Ms(e,i,g,C)}findAvatarPart(A,e){let t=A.name.toLowerCase(),i=!0;for(let g of e){if(!i)break;t.indexOf(g)===-1&&(i=!1)}if(i)return A;if(A.children)for(let g of A.children){let C=this.findAvatarPart(g,e);if(C)return C}return null}handleCustomAvatarErrors(A){if(!A.ok)throw Error(A.statusText);return A}};var VC=class extends sA{length=1;depthTest=!0;isGizmo=!0;_axes=null;onEnable(){if(this.isGizmo&&!qC)return;this._axes||(this._axes=new AC(this.length)),this.gameObject.add(this._axes);let A=this._axes.material;A&&A.depthTest!==void 0&&(A.depthTest=this.depthTest)}onDisable(){!this._axes||this.gameObject.remove(this._axes)}};W([O()],VC.prototype,"length",2),W([O()],VC.prototype,"depthTest",2),W([O()],VC.prototype,"isGizmo",2);var Oa=class extends sA{from;to;hint;desiredDistance=1;onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;let A=Ce(this.to).clone(),e=Ce(this.from).clone(),t=A.distanceTo(e),i=A.clone();i.sub(e);let g=e.clone();g.add(A),g.multiplyScalar(.5);let C=Ce(this.hint).clone();C.sub(g);let o=new R;o.crossVectors(C,i),o.crossVectors(i,o),o.normalize();let n=t*.5,s=Math.max(this.desiredDistance,n),r=Math.sqrt(s*s-n*n),a=o.clone();a.multiplyScalar(r),a.add(g),Ze(this.gameObject,a);let B=g.clone();B.sub(o),this.gameObject.lookAt(B)}};var H1=new Qg(1,1,1);function Ff(I=null){let A=new P(I??14540253),e=new zQ(H1);return new qi(e,new Mt({color:A}))}var _1=cA("gizmos"),Vg=class extends sA{box=null;_lastMatrixUpdateFrame=-1;isInBox(A,e){if(!!A){if(this.box||(this.box=new jt),A.type==="Mesh")Vg.testBox.setFromObject(A);else if(A.type==="Group"){if(A.children.length>0){Vg.testBox.setFromCenterAndSize(Vg._position.set(0,0,0),Vg._size.set(0,0,0));for(let t=0;t<A.children.length;t++)A.children[t].type==="Mesh"&&Vg.testBox.expandByObject(A)}}else{let t=Ce(A,Vg._position),i=vg(A,Vg._size);e!==void 0&&i.multiplyScalar(e),Vg.testBox.setFromCenterAndSize(t,i)}return this.updateBox(),this.box?.intersectsBox(Vg.testBox)}}intersects(A){return A?this.updateBox(!1).intersectsBox(A):!1}updateBox(A=!1){if(this.box||(this.box=new jt),A||this.context.time.frameCount!=this._lastMatrixUpdateFrame){let e=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;let t=e,i=Ce(this.gameObject,Vg._position,t),g=vg(this.gameObject,Vg._size);this.box.setFromCenterAndSize(i,g)}return this.box}_helper=null;_color=null;awake(){this._helper=null,this._color=null,this.box=null}showHelper(A=null,e=!1){if(!(!_1&&!e)){if(this._helper){A&&this._color?.set(A),this.gameObject.add(this._helper);return}this._helper=Ff(A),this.gameObject.add(this._helper)}}},ni=Vg;mA(ni,"testBox",new jt),mA(ni,"_position",new R),mA(ni,"_size",new R(.01,.01,.01));var rC=class{method;enabled;constructor(A,e){this.method=A,this.enabled=e!==void 0?e:!0}invoke(...A){if(this.enabled!==!1){if(!this.method){console.warn("No function. Please check you assigned a method to invoke on export",this);return}this.method(...A)}}},O1=I=>/^[A-Z]*$/.test(I),ks=class extends Event{args},kt=class{target;key;setEventTarget(A,e){if(this.key=A,this.target=e,this.key!==void 0){let t="",i=!1;for(let g of this.key)i&&O1(g)&&(t+="-"),i=!0,t+=g.toLowerCase();this.key=t}}_isInvoking=!1;methods=[];constructor(A){this.methods=A??[]}invoke(...A){if(this._isInvoking){console.warn("Circular event invocation detected. Please check your event listeners for circular references.",this);return}this._isInvoking=!0;try{for(let e of this.methods)e.invoke(...A);if(typeof this.target=="object"&&typeof this.key=="string"){let e=this.target.dispatchEvent;if(typeof e=="function"){let t=new ks(this.key);t.args=A,e.call(this.target,t)}}}finally{this._isInvoking=!1}}addEventListener(A){return this.methods.push(new rC(A,!0)),A}removeEventListener(A){if(!!A)for(let e=this.methods.length-1;e>=0;e--)this.methods[e].method===A&&(this.methods[e].enabled=!1,this.methods.splice(e,1))}removeAllEventListeners(){this.methods.length=0}};var zM=class extends zo{constructor(){super([P,ft])}onDeserialize(A){if(A!=null)return A.a!==void 0?new ft(A.r,A.g,A.b,A.a):A.alpha!==void 0?new ft(A.r,A.g,A.b,A.alpha):new P(A.r,A.g,A.b)}onSerialize(A){if(A!=null)return A.a!==void 0?{r:A.r,g:A.g,b:A.b,a:A.a}:{r:A.r,g:A.g,b:A.b}}},MtA=new zM,ZM=class extends zo{constructor(){super(qA)}onSerialize(A,e){if(e.objectToNode!==void 0&&A.uuid){let t=e.objectToNode[A.uuid];return Xt&&console.log(t,A.name,A.uuid),{node:t}}}onDeserialize(A,e){if(A){if(A.node!==void 0&&e.nodeToObject){let t=e.nodeToObject[A.node];return Xt&&console.log("Deserialized object reference?",A,t,e?.nodeToObject),t||console.warn("Did not find node: "+A.node,e.nodeToObject,e.object),t}else if(A.guid){if(!e.context){console.error("Missing context");return}let t,i=e.gltf?.scene;return i&&(t=iA.findByGuid(A.guid,i)),t||(t=iA.findByGuid(A.guid,e.context.scene)),t?Xt&&console.log("Deserialized object reference?",A,t,e?.nodeToObject):console.warn("could not resolve reference",A,e.target,e.path,e.context.scene),t}}}},P1=new ZM,XM=class extends zo{constructor(){super([Wg,sA])}onSerialize(A,e){if(A?.guid)return{guid:A.guid}}onDeserialize(A,e){if(A?.guid){Xt&&console.log(A.guid,e.root,e.object,e.target);let t=this.findObjectForGuid(A.guid,e.root);if(t)return t;if(e.context)return this.findObjectForGuid(A.guid,e.context?.scene)}}findObjectForGuid(A,e){if(e.guid===A)return e;let t=iA.foreachComponent(e,i=>{if(i.guid===A)return i},!1);if(t!==void 0)return t;for(let i=0;i<e.children.length;i++){let g=e.children[i],C=this.findObjectForGuid(A,g);if(C)return C}}},jM=new XM,$M=class extends zo{constructor(){super([kt])}onSerialize(A,e){console.log("TODO: SERIALIZE EVENT")}onDeserialize(A,e){if(A&&A.type==="EventList"){Xt&&console.log("DESERIALIZE EVENT",A);let t=new Array;for(let C of A.calls){Xt&&console.log(C);let o=jM.findObjectForGuid(C.target,e.root);!o&&e.context?.scene&&(o=jM.findObjectForGuid(C.target,e.context?.scene));let n=C.method?.length>0;if(o&&n){let B=()=>console.warn(`Could not find method ${C.method} on object ${o.name}`,o,typeof o[C.method]);if(typeof o[C.method]!="function"){let Q=!1;C.method.startsWith("set_")&&C.method.length>4&&(C.method=C.method.substring(4),o[C.method]!==void 0&&(Q=!0)),Q||B()}}let s,r=C.argument;C.argument!==void 0?(typeof r=="object"&&(r=P1.onDeserialize(C.argument,e),r||(r=jM.onDeserialize(C.argument,e))),s=new rC(n?(...B)=>a(...B):void 0,C.enabled)):s=new rC(n?(...B)=>a(...B):void 0,C.enabled);let a=(...B)=>{let Q=o[C.method];typeof Q=="function"?r!==void 0?Q?.call(o,r):Q?.call(o,...B):o[C.method]=r};if(s.method||(s.__debuginfo=e.object?.name),!o||!s.method){let B=e.object?"Current object: "+e.object.name+", "+e.object.guid:null;o?console.warn('EventList method not found: "'+C.method+'" on',o):console.warn("EventList is missing target - will be ignored",C.target,B,A)}else t.push(s)}let i=new kt(t);Xt&&console.log(i);let g=e.target;return g!==void 0&&e.path!==void 0&&i.setEventTarget(e.path,g),i}}},ktA=new $M;var aC=function(I,A){return function(e,t,i){V1(e,t,i,I,A)}};function V1(I,A,e,t,i){if(!(!i&&!t&&!I.onValidate)){if(e!==void 0){console.error("Invalid usage of validate decorator. Only fields can be validated.",I,A,e),eC("Invalid usage of validate decorator. Only fields can be validated. Property: "+A,2);return}if(I.__internalAwake){let g=Symbol(A),C=I.__internalAwake;I.__internalAwake=function(){this[g]===void 0&&(this[g]=this[A],Object.defineProperty(this,A,{set:function(o){if(this[zp]===!0)this[g]=o;else{t?.call(this,o);let n=this[g];this[g]=o,this.onValidate?.call(this,A,n)}},get:function(){return i?.call(this),this[g]}})),C.call(this)}}}}var Ak=class{get isDirty(){return this.positionChanged||this.rotationChanged}positionChanged=!1;rotationChanged=!1;position;quaternion;_positionKeys=["x","y","z"];_quaternionKeys=["_x","_y","_z","_w"];reset(A=!1){if(this.positionChanged=!1,this.rotationChanged=!1,this.mute=!1,A){if(this.position)for(let e of this._positionKeys)delete this.position[e];if(this.quaternion)for(let e of this._quaternionKeys)delete this.quaternion[e]}}mute=!1;applyValues(){if(this.positionChanged&&this.position)for(let A of this._positionKeys){let e=this.position[A];e!==void 0&&(this.obj.position[A]=e)}if(this.rotationChanged&&this.quaternion)for(let A of this._quaternionKeys){let e=this.quaternion[A];e!==void 0&&(this.obj.quaternion[A]=e)}}context;obj;_positionWatch;_rotationWatch;constructor(A,e){this.context=e,this.obj=A}start(A,e){this.reset(),A&&(this._positionWatch||(this._positionWatch=new Vo(this.obj.position,["x","y","z"])),this._positionWatch.apply(),this.position={},this._positionWatch.subscribeWrite((t,i)=>{if(this.context.physics.isUpdating||this.mute)return;let g=this.position[i];Math.abs(g-t)<1e-5||(this.position[i]=t,this.positionChanged=!0)})),e&&(this._rotationWatch||(this._rotationWatch=new Vo(this.obj.quaternion,["_x","_y","_z","_w"])),this._rotationWatch.apply(),this.quaternion={},this._rotationWatch.subscribeWrite((t,i)=>{if(this.context.physics.isUpdating||this.mute)return;let g=this.quaternion[i];Math.abs(g-t)<1e-5||(this.quaternion[i]=t,this.rotationChanged=!0)}))}stop(){this._positionWatch?.revoke(),this._rotationWatch?.revoke()}},Nf=class extends sA{mass=1;useGravity=!0;constraints=0;isKinematic=!1;drag=0;angularDrag=1;detectCollisions=!0;sleepThreshold=.01;collisionDetectionMode=0;get lockPositionX(){return(this.constraints&2)!==0}get lockPositionY(){return(this.constraints&4)!==0}get lockPositionZ(){return(this.constraints&8)!==0}get lockRotationX(){return(this.constraints&16)!==0}get lockRotationY(){return(this.constraints&32)!==0}get lockRotationZ(){return(this.constraints&64)!==0}set lockPositionX(A){A?this.constraints|=2:this.constraints&=-3}set lockPositionY(A){A?this.constraints|=4:this.constraints&=-5}set lockPositionZ(A){A?this.constraints|=8:this.constraints&=-9}set lockRotationX(A){A?this.constraints|=16:this.constraints&=-17}set lockRotationY(A){A?this.constraints|=32:this.constraints&=-33}set lockRotationZ(A){A?this.constraints|=64:this.constraints&=-65}_propertiesChanged=!1;_currentVelocity;_smoothedVelocity;_smoothedVelocityGetter;_lastPosition;_watch;awake(){this._watch=void 0,this._currentVelocity=new R,this._smoothedVelocity=new R,this._smoothedVelocityGetter=new R,this._lastPosition=new R}onEnable(){this._watch||(this._watch=new Ak(this.gameObject,this.context)),this._watch.start(!0,!0),this.startCoroutine(this.beforePhysics(),2)}onDisable(){this._watch?.stop(),this.context.physics.removeBody(this)}onDestroy(){this.context.physics.removeBody(this)}onValidate(){this._propertiesChanged=!0}*beforePhysics(){for(;;)this._propertiesChanged&&(this._propertiesChanged=!1,this.context.physics.updateProperties(this)),this._watch?.isDirty&&(this._watch.mute=!0,this._watch.applyValues(),this.context.physics.updateBody(this,this._watch.positionChanged,this._watch.rotationChanged),this._watch.reset()),this.captureVelocity(),yield}get body(){return this.context.physics.internal_getRigidbody(this)}teleport(A,e=!0){this._watch?.reset(!0),e?this.gameObject.position.set(A.x,A.y,A.z):this.setWorldPosition(A.x,A.y,A.z),this.resetForcesAndTorques(),this.resetVelocities()}resetForces(){this.body?.resetForces(!0)}resetTorques(){this.body?.resetTorques(!0)}resetVelocities(){this.setVelocity(0,0,0),this.setAngularVelocity(0,0,0)}resetForcesAndTorques(){this.resetForces(),this.resetTorques()}wakeUp(){this.body?.wakeUp()}applyForce(A,e){this.body?.addForce(A,!0)}applyImpulse(A){this.body?.applyImpulse(A,!0)}setForce(A,e,t){this.body?.resetForces(!0),this.body?.addForce({x:A,y:e,z:t},!0)}getVelocity(){let A=this.body?.linvel();return A?(this._currentVelocity.x=A.x,this._currentVelocity.y=A.y,this._currentVelocity.z=A.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setVelocity(A,e,t){if(A instanceof R){let i=A;this.body?.setLinvel(i,!0);return}e===void 0||t===void 0||this.body?.setLinvel({x:A,y:e,z:t},!0)}setAngularVelocity(A,e,t){if(A instanceof R){let i=A;this.body?.setAngvel(i,!0);return}e===void 0||t===void 0||this.body?.setAngvel({x:A,y:e,z:t},!0)}setTorque(A,e,t){this.setAngularVelocity(A,e,t)}get smoothedVelocity(){return this._smoothedVelocityGetter.copy(this._smoothedVelocity),this._smoothedVelocityGetter.multiplyScalar(1/this.context.time.deltaTime)}setBodyFromGameObject(A=null){this.gameObject&&this.destroyed}captureVelocity(){if(this.body){let A=Ce(this.gameObject);Nf.tempPosition.copy(A);let e=A.sub(this._lastPosition);this._lastPosition.copy(Nf.tempPosition),this._smoothedVelocity.lerp(e,this.context.time.deltaTime/.1)}}},be=Nf;mA(be,"tempPosition",new R),W([aC(),O()],be.prototype,"mass",2),W([aC(),O()],be.prototype,"useGravity",2),W([aC(),O()],be.prototype,"constraints",2),W([aC(),O()],be.prototype,"isKinematic",2),W([aC(),O()],be.prototype,"drag",2),W([aC(),O()],be.prototype,"angularDrag",2),W([aC(),O()],be.prototype,"detectCollisions",2),W([aC(),O()],be.prototype,"sleepThreshold",2),W([aC(),O()],be.prototype,"collisionDetectionMode",2);var zg=class extends sA{get isCollider(){return!0}attachedRigidbody=null;isTrigger=!1;awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(be))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(be))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(be))}onDisable(){this.context.physics.removeBody(this)}};W([O(be)],zg.prototype,"attachedRigidbody",2),W([O()],zg.prototype,"isTrigger",2);var on=class extends zg{radius=.5;center=new R(0,0,0);onEnable(){super.onEnable(),this.context.physics.addSphereCollider(this,this.center,this.radius)}};W([O()],on.prototype,"radius",2),W([O(R)],on.prototype,"center",2);var nn=class extends zg{size=new R(1,1,1);center=new R(0,0,0);onEnable(){super.onEnable(),this.context.physics.addBoxCollider(this,this.center,this.size)}};W([O(R)],nn.prototype,"size",2),W([O(R)],nn.prototype,"center",2);var Rs=class extends zg{sharedMesh;convex=!1;onEnable(){super.onEnable(),this.sharedMesh?.isMesh||this.gameObject instanceof Fe&&(this.sharedMesh=this.gameObject),this.sharedMesh?.isMesh&&this.context.physics.addMeshCollider(this,this.sharedMesh,this.convex)}};W([O()],Rs.prototype,"convex",2);var jg=class extends zg{center=new R(0,0,0);radius=.5;height=2;onEnable(){super.onEnable(),this.context.physics.addCapsuleCollider(this,this.center,this.height,this.radius)}};W([O(R)],jg.prototype,"center",2),W([O()],jg.prototype,"radius",2),W([O()],jg.prototype,"height",2);var BC=class extends sA{center=new R(0,0,0);radius=.5;height=2;_rigidbody=null;get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(be),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(be)),this.rigidbody)}onEnable(){let A=this.rigidbody,e=this.gameObject.getComponent(jg);e||(e=this.gameObject.addNewComponent(jg)),e.center.copy(this.center),e.radius=this.radius,e.height=this.height,this.gameObject.rotation.x=0,this.gameObject.rotation.z=0,A.lockRotationX=!0,A.lockRotationY=!0,A.lockRotationZ=!0}move(A){this.gameObject.position.add(A)}_activeGroundCollisions=new Set;onCollisionEnter(A){for(let e of A.contacts)if(e.normal.y>.1){this._activeGroundCollisions.add(A);break}}onCollisionExit(A){this._activeGroundCollisions.delete(A)}get isGrounded(){return this._activeGroundCollisions.size>0}};W([O(R)],BC.prototype,"center",2),W([O()],BC.prototype,"radius",2),W([O()],BC.prototype,"height",2);var UI=class extends sA{controller;movementSpeed=2;rotationSpeed=2;jumpForce=1;animator;lookForward=!0;_currentSpeed=new R(0,0,0);_currentAngularSpeed=new R(0,0,0);_temp=new R(0,0,0);_jumpCount=0;_currentRotation;awake(){this._currentRotation=new vA}update(){this.controller?.isGrounded&&(this._jumpCount=0,this.animator?.SetBool("doubleJump",!1));let A=this.context.input.isKeyPressed("w"),e=this.context.input.isKeyPressed("s"),t=this.context.input.isKeyPressed("a"),i=this.context.input.isKeyPressed("d"),g=this.context.input.isKeyDown(" "),C=A?1:0+e?-1:0;this._currentSpeed.z+=C*this.movementSpeed*this.context.time.deltaTime,this.animator?.SetBool("running",C!=0),this.animator?.SetBool("jumping",this.controller?.isGrounded===!0&&g),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp);let o=t?1:0+i?-1:0;if(this._currentAngularSpeed.y+=ce.toRadians(o*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){let n=this.context.mainCameraComponent.forward;n.y=0,n.normalize(),this._currentRotation.setFromUnitVectors(new R(0,0,1),n),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&g&&this.jumpForce>0){let n=this.controller?.isGrounded;if(!this.controller?.isGrounded&&this._jumpCount===1&&(n=!0,this.animator?.SetBool("doubleJump",!0)),n){this._jumpCount+=1;let s=this.controller.rigidbody,r=this._jumpCount===2?2:1;s.applyImpulse(new R(0,1,0).multiplyScalar(this.jumpForce*r))}}if(this.controller){let n=this.controller?.rigidbody.getVelocity().y;if(n<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new qg),this._raycastOptions.ray.origin.copy(Ce(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);let s=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);let r=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(s),(r.length&&r[0].distance>2||n<-10)&&this.animator?.SetBool("falling",!0)}else this.animator?.SetBool("falling",!1)}}_raycastOptions=new Dt};W([O(BC)],UI.prototype,"controller",2),W([O()],UI.prototype,"movementSpeed",2),W([O()],UI.prototype,"rotationSpeed",2),W([O()],UI.prototype,"jumpForce",2),W([O(vi)],UI.prototype,"animator",2);var Zg=class extends sA{canGrab=!0;onPointerClick(A){}},Xg=class extends sA{isUsed=!0;usedBy=null};var Us=class extends ni{},Pa=class extends sA{deleteBoxes=[];awake(){this.deleteBoxes=iA.findObjectsOfType(Us,this.context)}update(){for(let A of this.deleteBoxes){let e=this.gameObject;A.isInBox(e)===!0&&(iA.getComponentInParent(this.gameObject,Xg)||hE(this.gameObject,this.context.connection))}}};var Fs=class extends sA{visibleOn;onEnable(){this.apply()}apply(){this.test()||iA.setActive(this.gameObject,!1)}test(){return this.visibleOn<0?!0:j1()?(this.visibleOn&2)!==0:(this.visibleOn&1)!==0}};W([O()],Fs.prototype,"visibleOn",2);var Kf;function j1(){if(Kf===!0||Kf===!1)return Kf;let I=!1;return function(A){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(A)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(A.substr(0,4)))&&(I=!0)}(navigator.userAgent||navigator.vendor||window.opera),Kf=I,I}var Yt=class{bb=null;bb_pos=0;__init(A,e){return this.bb_pos=A,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}static sizeOf(){return 12}static createVec3(A,e,t,i){return A.prep(4,12),A.writeFloat32(i),A.writeFloat32(t),A.writeFloat32(e),A.offset()}};var _E=class{bb=null;bb_pos=0;__init(A,e){return this.bb_pos=A,this.bb=e,this}position(A){return(A||new Yt).__init(this.bb_pos,this.bb)}rotation(A){return(A||new Yt).__init(this.bb_pos+12,this.bb)}scale(A){return(A||new Yt).__init(this.bb_pos+24,this.bb)}static sizeOf(){return 36}static createTransform(A,e,t,i,g,C,o,n,s,r){return A.prep(4,36),A.prep(4,12),A.writeFloat32(r),A.writeFloat32(s),A.writeFloat32(n),A.prep(4,12),A.writeFloat32(o),A.writeFloat32(C),A.writeFloat32(g),A.prep(4,12),A.writeFloat32(i),A.writeFloat32(t),A.writeFloat32(e),A.offset()}};var FI=class{bb=null;bb_pos=0;__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsSyncedTransformModel(A,e){return(e||new FI).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedTransformModel(A,e){return A.setPosition(A.position()+4),(e||new FI).__init(A.readInt32(A.position())+A.position(),A)}guid(A){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}fast(){let A=this.bb.__offset(this.bb_pos,6);return A?!!this.bb.readInt8(this.bb_pos+A):!1}transform(A){let e=this.bb.__offset(this.bb_pos,8);return e?(A||new _E).__init(this.bb_pos+e,this.bb):null}dontSave(){let A=this.bb.__offset(this.bb_pos,10);return A?!!this.bb.readInt8(this.bb_pos+A):!1}static startSyncedTransformModel(A){A.startObject(4)}static addGuid(A,e){A.addFieldOffset(0,e,0)}static addFast(A,e){A.addFieldInt8(1,+e,0)}static addTransform(A,e){A.addFieldStruct(2,e,0)}static addDontSave(A,e){A.addFieldInt8(3,+e,0)}static endSyncedTransformModel(A){return A.endObject()}static finishSyncedTransformModelBuffer(A,e){A.finish(e)}static finishSizePrefixedSyncedTransformModelBuffer(A,e){A.finish(e,void 0,!0)}};var Ns=cA("debugsync"),OE="STRS";xE(OE,FI.getRootAsSyncedTransformModel);var jC=new _g;function ek(I,A,e=!0){jC.clear();let t=jC.createString(I);FI.startSyncedTransformModel(jC),FI.addGuid(jC,t),FI.addFast(jC,e);let i=A.worldPosition,g=A.worldEuler,C=A.gameObject.scale;FI.addTransform(jC,_E.createTransform(jC,i.x,i.y,i.z,g.x,g.y,g.z,C.x,C.y,C.z));let o=FI.endSyncedTransformModel(jC);return jC.finish(o,OE),jC.asUint8Array()}var pg=class extends sA{overridePhysics=!0;interpolatePosition=!0;interpolateRotation=!0;fastMode=!1;syncDestroy=!1;_model=null;_needsUpdate=!0;rb=null;_wasKinematic=!1;_receivedDataBefore=!1;_targetPosition;_targetRotation;_receivedFastUpdate=!1;_shouldRequestOwnership=!1;requestOwnership(){Ns&&console.log("Request ownership"),this._model?this._model.requestOwnership():(this._shouldRequestOwnership=!0,this._needsUpdate=!0)}hasOwnership(){return this._model?.hasOwnership??void 0}isOwned(){return this._model?.isOwned}joinedRoomCallback=null;receivedDataCallback=null;awake(){Ns&&console.log("new instance",this.guid,this),this._receivedDataBefore=!1,this._targetPosition=new R,this._targetRotation=new vA,this.lastWorldPos=new R,this.lastWorldRotation=new vA,this.rb=iA.getComponentInChildren(this.gameObject,be),this.rb&&(this._wasKinematic=this.rb.isKinematic),this.receivedUpdate=!0,this._model=new ws(this.context.connection,this.guid),this.context.connection.isConnected&&this.tryGetLastState(),this.joinedRoomCallback=this.tryGetLastState.bind(this),this.context.connection.beginListen("joined-room",this.joinedRoomCallback),this.receivedDataCallback=this.onReceivedData.bind(this),this.context.connection.beginListenBinrary(OE,this.receivedDataCallback)}onDestroy(){this.syncDestroy&&Rq(this.guid,this.context.connection),this._model=null,this.context.connection.stopListening("joined-room",this.joinedRoomCallback),this.context.connection.stopListenBinary(OE,this.receivedDataCallback)}tryGetLastState(){let A=this.context.connection.tryGetState(this.guid);A&&this.onReceivedData(A)}tempEuler=new Ye;onReceivedData(A){if(!this.destroyed&&typeof A.guid=="function"&&A.guid()===this.guid){Ns&&console.log("new data",this.context.connection.connectionId,this.context.time.frameCount,this.guid,A),this.receivedUpdate=!0,this._receivedFastUpdate=A.fast();let e=A.transform();if(e){tt.markDirty(this.gameObject,!0);let t=e.position();t&&(this.interpolatePosition&&this._targetPosition?.set(t.x(),t.y(),t.z()),(!this.interpolatePosition||!this._receivedDataBefore)&&this.setWorldPosition(t.x(),t.y(),t.z()));let i=e.rotation();i&&(this.tempEuler.set(i.x(),i.y(),i.z()),this.interpolateRotation&&this._targetRotation.setFromEuler(this.tempEuler),(!this.interpolateRotation||!this._receivedDataBefore)&&Dq(this.gameObject,this.tempEuler))}this._receivedDataBefore=!0}}onEnable(){this.lastWorldPos.copy(this.worldPosition),this.lastWorldRotation.copy(this.worldQuaternion),this._needsUpdate=!0,this._model&&this._model.updateIsOwned()}onDisable(){this._model&&this._model.freeOwnership()}receivedUpdate=!1;lastWorldPos;lastWorldRotation;onBeforeRender(){if(!this.activeAndEnabled||!this.context.connection.isConnected)return;if(!this.context.connection.isInRoom||!this._model){Ns&&console.log("no model or room",this.name,this.guid,this.context.connection.isInRoom);return}this._shouldRequestOwnership&&(this._shouldRequestOwnership=!1,this._model.requestOwnership());let A=this.worldPosition,e=this.worldQuaternion;if(this._model.isOwned&&!this.receivedUpdate){let g=A.distanceTo(this.lastWorldPos),C=e.angleTo(this.lastWorldRotation),o=this._model.hasOwnership||this.fastMode?1e-4:.001;(g>o||C>o)&&(this._model.hasOwnership?this._needsUpdate=!0:(Ns&&console.log(this.guid,"reset because not owned but",this.gameObject.name,this.lastWorldPos),this.worldPosition=this.lastWorldPos,A.copy(this.lastWorldPos),this.worldQuaternion=this.lastWorldRotation,e.copy(this.lastWorldRotation),tt.markDirty(this.gameObject,!0),this._needsUpdate=!1))}if(this._model&&!this._model.hasOwnership&&this._model.isOwned&&this._receivedDataBefore){let C=this._receivedFastUpdate||this.fastMode?.5:.3,o=!1;if(this.interpolatePosition&&this._targetPosition){let n=this.worldPosition;n.lerp(this._targetPosition,C),this.worldPosition=n,o=!0}if(this.interpolateRotation&&this._targetRotation){let n=this.worldQuaternion;n.slerp(this._targetRotation,C),this.worldQuaternion=n,o=!0}o&&tt.markDirty(this.gameObject,!0)}if(this.receivedUpdate=!1,this.lastWorldPos.copy(A),this.lastWorldRotation.copy(e),!this._model)return;if(!this._model||this._model.hasOwnership===void 0||!this._model.hasOwnership){this.rb&&(this.rb.isKinematic=this._model.isOwned??!1,this.rb.setVelocity(0,0,0),this.rb.setBodyFromGameObject());return}this.rb&&(this._wasKinematic!==void 0&&(Ns&&console.log("reset kinematic",this.rb.name,this._wasKinematic),this.rb.isKinematic=this._wasKinematic),this.gameObject.position.distanceTo(new R(0,0,0))>1e3&&(Ns&&console.log("RESET",this.name),this.gameObject.position.set(0,1,0),this.rb.setVelocity(0,0,0),this.rb.setBodyFromGameObject()));let t=10,i=this.rb||this.fastMode;if(this._needsUpdate&&(t<=0||t>0&&this.context.time.frameCount%t===0||i)){Ns&&console.log("send update",this.context.connection.connectionId,this.guid,this.gameObject.name,this.gameObject.guid),this.overridePhysics&&this.rb&&this.rb.setBodyFromGameObject(),this._needsUpdate=!1;let g=ek(this.guid,this,!!i);this.context.connection.sendBinary(g)}}};var Jf=class{static createButton(A,e={}){let t=document.createElement("button");function i(){if(e.domOverlay===void 0){var n=document.createElement("div");n.style.display="none",document.body.appendChild(n);var s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("width",38),s.setAttribute("height",38),s.style.position="absolute",s.style.right="20px",s.style.top="20px",s.addEventListener("click",function(){a.end()}),n.appendChild(s);var r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),r.setAttribute("stroke","#fff"),r.setAttribute("stroke-width",2),s.appendChild(r),e.optionalFeatures===void 0&&(e.optionalFeatures=[]),e.optionalFeatures.push("dom-overlay"),e.domOverlay={root:n}}e.optionalFeatures===void 0&&(e.optionalFeatures=[]),e.optionalFeatures.push("local-floor"),e.optionalFeatures.push("hand-tracking"),e.optionalFeatures.push("layers");let a=null;async function B(h){h.addEventListener("end",Q),await A.xr.setSession(h),t.textContent="STOP AR",e.domOverlay.root.style.display="",a=h}function Q(){a.removeEventListener("end",Q),t.textContent="START AR",e.domOverlay.root.style.display="none",a=null}t.style.display="",t.style.cursor="pointer",t.style.left="calc(50% - 50px)",t.style.width="100px",t.textContent="START AR",t.onmouseenter=function(){t.style.opacity="1.0"},t.onmouseleave=function(){t.style.opacity="0.5"},t.onclick=function(){a===null?navigator.xr.requestSession("immersive-ar",e).then(B):a.end()}}function g(){t.disabled=!0,t.style.display="",t.style.cursor="auto",t.style.left="calc(50% - 75px)",t.style.width="150px",t.onmouseenter=null,t.onmouseleave=null,t.onclick=null}function C(){g(),t.textContent="AR NOT SUPPORTED"}function o(n){n.style.position="absolute",n.style.bottom="20px",n.style.padding="12px 6px",n.style.border="1px solid #fff",n.style.borderRadius="4px",n.style.background="rgba(0,0,0,0.1)",n.style.color="#fff",n.style.font="normal 13px sans-serif",n.style.textAlign="center",n.style.opacity="0.5",n.style.outline="none",n.style.zIndex="999"}if("xr"in navigator)return t.id="ARButton",t.style.display="none",o(t),navigator.xr.isSessionSupported("immersive-ar").then(function(n){n?i():C()}).catch(C),t;{let n=document.createElement("a");return window.isSecureContext===!1?(n.href=document.location.href.replace(/^http:/,"https:"),n.innerHTML="WEBXR NEEDS HTTPS"):(n.href="https://immersiveweb.dev/",n.innerHTML="WEBXR NOT AVAILABLE"),n.style.left="calc(50% - 90px)",n.style.width="180px",n.style.textDecoration="none",o(n),n}}};var qf=class{static createButton(A,e){e&&console.error('THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.');let t=document.createElement("button");function i(){let n=null;async function s(a){a.addEventListener("end",r),await A.xr.setSession(a),t.textContent="EXIT VR",n=a}function r(){n.removeEventListener("end",r),t.textContent="ENTER VR",n=null}t.style.display="",t.style.cursor="pointer",t.style.left="calc(50% - 50px)",t.style.width="100px",t.textContent="ENTER VR",t.onmouseenter=function(){t.style.opacity="1.0"},t.onmouseleave=function(){t.style.opacity="0.5"},t.onclick=function(){if(n===null){let a={optionalFeatures:["local-floor","bounded-floor","hand-tracking","high-fixed-foveation-level","layers"]};navigator.xr.requestSession("immersive-vr",a).then(s)}else n.end()}}function g(){t.disabled=!0,t.style.display="",t.style.cursor="auto",t.style.left="calc(50% - 75px)",t.style.width="150px",t.onmouseenter=null,t.onmouseleave=null,t.onclick=null}function C(){g(),t.textContent="VR NOT SUPPORTED"}function o(n){n.style.position="absolute",n.style.bottom="20px",n.style.padding="12px 6px",n.style.border="1px solid #fff",n.style.borderRadius="4px",n.style.background="rgba(0,0,0,0.1)",n.style.color="#fff",n.style.font="normal 13px sans-serif",n.style.textAlign="center",n.style.opacity="0.5",n.style.outline="none",n.style.zIndex="999"}if("xr"in navigator)return t.id="VRButton",t.style.display="none",o(t),navigator.xr.isSessionSupported("immersive-vr").then(function(n){n?i():C(),qf.xrSessionIsGranted&&(console.log("XR session is granted - will enter immersive web now"),t.click())}),t;{let n=document.createElement("a");return window.isSecureContext===!1?(n.href=document.location.href.replace(/^http:/,"https:"),n.innerHTML="WEBXR NEEDS HTTPS"):(n.href="https://immersiveweb.dev/",n.innerHTML="WEBXR NOT AVAILABLE"),n.style.left="calc(50% - 90px)",n.style.width="180px",n.style.textDecoration="none",o(n),n}}static registerSessionGrantedListener(){if("xr"in navigator)try{navigator.xr.addEventListener("sessiongranted",()=>{console.log("Received session granted event"),qf.xrSessionIsGranted=!0})}catch(A){console.error(A)}}},WE=qf;mA(WE,"xrSessionIsGranted",!1);WE.registerSessionGrantedListener();var $L=Gr(of(),1);var VE="noVoip",Dg=cA("debugvoip"),z1=cA("voip");var tk=class{id;constructor(A){this.id=A}};var ik=class{peer;voip;userId;peerId;call=null;callErrorListener=null;stream=null;constructor(A,e,t,i){this.voip=A,this.peer=e,this.userId=t,this.peerId=i}close(){Dg&&console.log("close voip call"),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.open&&this.call.close(),this.stream?.getTracks().forEach(function(A){A.stop()})}updateMute(A){if(!this.stream)return;let e=this.stream?.getAudioTracks();for(let t of e)t.enabled=!A}async startVoipCall(){if(!await Ti.HasMicrophonePermissions()){console.warn("no permission to use microphone, can not start call");return}Dg&&console.log("start voip call"),this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),this.updateMute(this.voip.muteOutput),Dg&&console.log(this.stream),this.call=this.peer.call(this.peerId,this.stream,{metadata:{userId:this.userId}}),this.call.on("error",e=>{console.error(e)}),this.call.on("stream",e=>{Dg&&console.log("received stream from remote again",e)}),this.peer.on("close",this.onCallClose.bind(this)),this.callErrorListener=e=>{e.message.includes(this.peerId)?(console.log("Could not connect to "+this.peerId),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.close(),this.stream?.getTracks().forEach(function(t){t.stop()}),this.stream=null):console.error(e)},this.peer.on("error",this.callErrorListener)}onCallClose(A){Dg&&console.log("call closed",A)}},gk=class{get currentStream(){return this.stream}get currentAudio(){return this.audio}get currentAnalyzer(){return this.analyzer}voip;call;audio=null;stream=null;obj;analyzer=null;waitingForStart=!1;closed=!1;audioElement=null;constructor(A,e,t){this.voip=A,this.obj=e,this.call=t}openAudioStream(A){let e=A.getAudioTracks();for(let t of e)if(t.kind==="audio"&&t.readyState==="live"){this.open(t);return}console.warn("failed finding valid audio stream to begin call")}open(A){console.assert(A.kind==="audio","invalid track kind, expected audio but received "+A.kind),!this.waitingForStart&&(this.waitingForStart=!0,Xe.userInteractionRegistered||Dg&&console.log("Incoming call, waiting for user interaction before opening audio"),Xe.registerWaitForAllowAudio(async()=>{if(this.call.open&&!this.closed){Dg&&console.log("Setup audio and begin listening"),this.stream=new MediaStream([A]);let e=new Qa;this.audio=new as(e),this.audio.setVolume(this.voip.muteInput?0:1),this.audio.setMediaStreamSource(this.stream);let t=document.createElement("audio");this.audioElement=t,t.style.display="none",document.body.appendChild(t),t.srcObject=this.stream,t.sinkId!==void 0&&navigator.mediaDevices.enumerateDevices().then(i=>{if(!!t){console.log(i);for(let g of i)if(g.label==="Speakerphone"){t.sinkId=g.deviceId;break}}}),Dg&&console.log("call is setup, you should hear something now"),this.analyzer=new zh(this.audio,32)}}))}close(){this.closed=!0,this.call?.open&&this.call.close(),this.audio?.disconnect(),this.stream?.getTracks().forEach(A=>{A.stop()}),this.stream=null,this.audioElement&&this.audioElement.remove()}},Ti=class extends sA{requireParam=!1;set muteInput(A){if(A===this._inputMuted||(this._inputMuted=A,!this.currentIncomingCalls))return;let e=this._inputMuted?0:1;for(let t in this.currentIncomingCalls)this.currentIncomingCalls[t]?.currentAudio?.setVolume(e)}get muteInput(){return this._inputMuted}set muteOutput(A){if(A!==this._outputMuted&&(this._outputMuted=A,!!this.connections))for(let e in this.connections)this.connections[e]?.updateMute(A)}get muteOutput(){return this._outputMuted}getFrequency(A){if(A===null){for(let t in this.currentIncomingCalls){let i=this.currentIncomingCalls[t];if(i&&i.currentAnalyzer)return i.currentAnalyzer.getAverageFrequency()}return null}let e=this.currentIncomingCalls[A];return e&&e.currentAnalyzer?e.currentAnalyzer.getAverageFrequency():null}peer=null;model=null;connections={};currentIncomingCalls={};_inputMuted=!1;_outputMuted=!1;awake(){if(cA(VE)){console.log("VOIP is disabled by url parameter: "+VE);return}if(this.requireParam&&!z1){console.debug("VOIP must be enabled explicitly by url parameter");return}this.peer=new $L.default,navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.context.connection.beginListen("joined-room",A=>{navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}),this.context.connection.beginListen("peer-update-id",A=>{if(A.id!==this.context.connection.connectionId){let e=this.connections[A.id];if(e&&e.close(),this.peer&&this.context.connection.connectionId){let t=new ik(this,this.peer,this.context.connection.connectionId,A.peerId);this.connections[A.id]=t,t.startVoipCall()}}}),this.context.connection.beginListen("user-left-room",A=>{let{userId:e}=A,t=this.connections[e];this.connections[e]=null,t&&t.close();let i=this.currentIncomingCalls[e];Dg&&console.log("UserLeftRoom",A,e,i),i&&(i.close(),this.currentIncomingCalls[e]=null)}),this.peer.on("open",this.onOpenPeerConnection.bind(this))}onEnable(){}onDisable(){console.log("TODO: close all");for(let A in this.currentIncomingCalls)this.currentIncomingCalls[A]?.close(),this.connections[A]?.close()}async onOpenPeerConnection(A){Dg&&console.log("Peer connection established and received id"),this.model=new tk(A),this.context.connection.send("peer-update-id",this.model,1),this.peer&&(this.peer.on("call",this.onReceiveCall.bind(this)),this.peer.on("connection",function(e){Dg&&console.log("CONNECTION",e),e.on("data",function(t){Dg&&console.log("Received",t)})}))}async onReceiveCall(A){let{metadata:e}=A;console.assert(e.userId);let{userId:t}=e,{peer:i}=A,g=this.currentIncomingCalls[t];if(g&&g.close(),Dg&&console.log("received call"),await Ti.HasMicrophonePermissions()){let C=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1});A.answer(C)}else A.answer(null);this.currentIncomingCalls[t]=new gk(this,this.gameObject,A),A.on("stream",C=>{Dg&&console.log("receive caller stream, will setup audio now"),this.currentIncomingCalls[t]?.openAudioStream(C)}),A.on("error",console.error)}static async HasMicrophonePermissions(){return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}};var $g=class extends sA{webAR=null;get rig(){return this.webAR?.webxr.Rig}invertForward=!1;get arScale(){return this._arScale}set arScale(A){A!==this._arScale&&(this._arScale=A,this.setScale(A))}_initalMatrix=new te;_selectStartFn=this.onSelectStart.bind(this);_selectEndFn=this.onSelectEnd.bind(this);start(){let A=iA.findObjectOfType(le);A&&(A.Rig.updateMatrix(),this._initalMatrix.copy(A.Rig.matrix))}_arScale=5;_rig=null;_startPose=null;_placementPose=null;_isTouching=!1;_rigStartPose=null;onBegin(A){this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose=this.gameObject.matrix.clone(),this._rigStartPose=this.rig?.matrix.clone(),A.addEventListener("selectstart",this._selectStartFn),A.addEventListener("selectend",this._selectEndFn),this.gameObject.visible=!1,this.rig&&(this.rig.matrixAutoUpdate=!0,this._initalMatrix.decompose(this.rig.position,this.rig.quaternion,this.rig.scale))}onUpdate(A,e,t){return t&&!this._placementPose&&this._isTouching?(this.webAR&&this.webAR.setReticleActive(!1),this.placeAt(A,new te().fromArray(t.transform.matrix).invert()),!0):!1}placeAt(A,e){if(this._placementPose||(this._placementPose=new te),this._placementPose.copy(e),A){if(this.invertForward){let t=new te().makeRotationY(Math.PI);this._placementPose.premultiply(t)}this._rig=A,this.setScale(this.arScale)}else this._rig=null;this.gameObject.visible=!0}onEnd(A,e){this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose&&this.gameObject.matrix.copy(this._startPose),A&&(A.matrixAutoUpdate=!0,this._rigStartPose&&this._rigStartPose.decompose(A.position,A.quaternion,A.scale)),tt.markDirty(this.gameObject,!0),setTimeout(()=>{this.gameObject.matrixAutoUpdate=!0,this.gameObject.visible=!0},100)}onSelectStart(){this._isTouching=!0}onSelectEnd(){this._isTouching=!1}setScale(A){let e=this._rig;!e||!this._placementPose||(this._rigStartPose||(this._rigStartPose=e.matrix.clone()),e.matrixAutoUpdate=!1,e.matrix.multiplyMatrices(new te().makeScale(A,A,A),this._placementPose),e.matrix.decompose(e.position,e.quaternion,e.scale),e.updateMatrixWorld(),console.log("Place",e.position))}};W([O()],$g.prototype,"invertForward",2),W([O()],$g.prototype,"arScale",1);import{OculusHandModel as q4}from"three/examples/jsm/webxr/OculusHandModel.js";import{OculusHandPointerModel as L4}from"three/examples/jsm/webxr/OculusHandPointerModel.js";import{XRControllerModelFactory as b4}from"three/examples/jsm/webxr/XRControllerModelFactory.js";import{GLTFLoader as x4}from"three/examples/jsm/loaders/GLTFLoader.js";var jE=cA("debugflags");var Ik=class{Mask=17;Has(A){let e=this.Mask&A;return jE&&console.log("HAS",A,this.Mask,"Result="+e),e!==0}Set(A){this.Mask=A,Rt.Apply()}Enable(A){this.Mask|=A,Rt.Apply()}Disable(A){this.Mask&=~A,Rt.Apply()}Toggle(A){this.Mask^=A,Rt.Apply()}EnableAll(){this.Mask=-1,Rt.Apply()}DisableAll(){this.Mask=0,Rt.Apply()}},fg=Ik;mA(fg,"Global",new Ik);var zC=class extends sA{static Apply(){for(let A of this.registry)A.UpdateVisible(fg.Global)}awake(){zC.registry.push(this)}onEnable(){zC.firstApply||(zC.firstApply=!0,zC.Apply())}onDestroy(){let A=zC.registry.indexOf(this);A>=0&&zC.registry.splice(A,1)}visibleIn;get isOn(){return this.gameObject.visible}UpdateVisible(A=null){if(!this.enabled)return;let e,t=A;t&&typeof t=="number"&&(console.assert(typeof t=="number","XRFlag.UpdateVisible: state must be a number",t),jE&&console.log(t),zC.buffer.Mask=t,A=zC.buffer);let i=A;if(i?(jE&&console.log("use passed in mask"),e=i.Has(this.visibleIn)):(jE&&console.log("use global mask"),fg.Global.Has(this.visibleIn)),e!==void 0)if(e)jE&&console.trace("is visible",this.name,this.gameObject.uuid),iA.setActive(this.gameObject,!0);else{if(jE&&console.trace("is not visible",this.name,this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},Rt=zC;mA(Rt,"registry",[]),mA(Rt,"firstApply"),mA(Rt,"buffer",new fg);var Ks=cA("debugavatar"),QC=class extends sA{static getAvatar(A){return A>=0&&A<QC.instances.length?QC.instances[A]:null}static onAvatarMarkerCreated(A){return QC._onNewAvatarMarkerAdded.push(A),A}static onAvatarMarkerDestroyed(A){return QC._onAvatarMarkerDestroyed.push(A),A}connectionId;avatar;awake(){QC.instances.push(this),Ks&&console.log(this);for(let A of QC._onNewAvatarMarkerAdded)A({avatarMarker:this,gameObject:this.gameObject})}onDestroy(){QC.instances.splice(QC.instances.indexOf(this),1);for(let A of QC._onAvatarMarkerDestroyed)A({avatarMarker:this,gameObject:this.gameObject})}isLocalAvatar(){return this.connectionId===this.context.connection.connectionId}setVisible(A){this.avatar&&("setVisible"in this.avatar?this.avatar.setVisible(A):iA.setActive(this.avatar,A))}},it=QC;mA(it,"instances",[]),mA(it,"_onNewAvatarMarkerAdded",[]),mA(it,"_onAvatarMarkerDestroyed",[]);var Vl=class{_isVisible=!0;setVisible(A){this._isVisible=A,this.updateVisibility()}get isWebXRAvatar(){return!0}guid;root=null;head=null;handLeft=null;handRight=null;lastUpdate=-1;isLocalAvatar=!1;flags=null;headScale=new R(1,1,1);handLeftScale=new R(1,1,1);handRightScale=new R(1,1,1);webxr;lastAvatarId=null;hasAvatarOverride=!1;context;avatarMarker=null;constructor(A,e,t){this.context=A,this.guid=e,this.webxr=t,this.setupCustomAvatar(this.webxr.defaultAvatar)}updateFlags(){if(!this.flags)return;let A=this.isLocalAvatar?8:16;for(let e of this.flags)e.gameObject.visible=!0,e.UpdateVisible(A)}async setAvatarOverride(A){return this.hasAvatarOverride=A!==null,this.hasAvatarOverride&&this.lastAvatarId!==A&&(this.lastAvatarId=A,A!=null&&A.length>0)?await this.setupCustomAvatar(A):null}_headTarget=new qA;_handLeftTarget=new qA;_handRightTarget=new qA;_canInterpolate=!1;tryUpdate(A,e){if(A.guid===this.guid&&(this.lastAvatarId!==A.avatarId&&A.avatarId&&A.avatarId.length>0&&(this.lastAvatarId=A.avatarId,this.setupCustomAvatar(A.avatarId)),this.lastUpdate=A.time,this.head)){let t=this.webxr.IsInAR?"handheld":"headset",i=this.head;this.context.players.setPlayerView(A.guid,i,t),tt.markDirty(this.head),this._canInterpolate=!0;let g=this.isLocalAvatar?this.head:this._headTarget;if(g.position.set(A.position.x,A.position.y,A.position.z),g.quaternion.set(A.rotation.x,A.rotation.y,A.rotation.z,A.rotation.w),g.scale.set(A.scale,A.scale,A.scale),g.scale.multiply(this.headScale),this.handLeft){let C=this.isLocalAvatar?this.handLeft:this._handLeftTarget;C.position.set(A.posLeftHand.x,A.posLeftHand.y,A.posLeftHand.z),C.quaternion.set(A.rotLeftHand._x,A.rotLeftHand._y,A.rotLeftHand._z,A.rotLeftHand._w),C.quaternion.multiply(Vl.invertRotation),C.scale.set(A.scale,A.scale,A.scale),C.scale.multiply(this.handLeftScale),tt.markDirty(this.handLeft)}if(this.handRight){let C=this.isLocalAvatar?this.handRight:this._handRightTarget;C.position.set(A.posRightHand.x,A.posRightHand.y,A.posRightHand.z),C.quaternion.set(A.rotRightHand._x,A.rotRightHand._y,A.rotRightHand._z,A.rotRightHand._w),C.quaternion.multiply(Vl.invertRotation),C.scale.set(A.scale,A.scale,A.scale),C.scale.multiply(this.handRightScale),tt.markDirty(this.handRight)}}}update(){if(this.isLocalAvatar||!this._canInterpolate)return;let A=this.context.time.deltaTime/.1;this.head&&(this.head.position.lerp(this._headTarget.position,A),this.head.quaternion.slerp(this._headTarget.quaternion,A),this.head.scale.lerp(this._headTarget.scale,A)),this.handLeft&&this._handLeftTarget&&(this.handLeft.position.lerp(this._handLeftTarget.position,A),this.handLeft.quaternion.slerp(this._handLeftTarget.quaternion,A),this.handLeft.scale.lerp(this._handLeftTarget.scale,A)),this.handRight&&this._handRightTarget&&(this.handRight.position.lerp(this._handRightTarget.position,A),this.handRight.quaternion.slerp(this._handRightTarget.quaternion,A),this.handRight.scale.lerp(this._handRightTarget.scale,A))}destroy(){Ks&&console.log("Destroy avatar",this.guid),this.root?.removeFromParent(),this.avatarMarker?.destroy(),this.lastAvatarId=null,this.head&&wt.Remove(this.context,this.head)}updateVisibility(){let A=this.root;A&&iA.setActive(A,this._isVisible)}async setupCustomAvatar(A){if(Ks&&console.log("LOAD",A,this),!A||typeof A=="string"&&A.length<=0)return!1;this.head&&wt.Remove(this.context,this.head);let e=A;if(e?.loadAssetAsync!==void 0){await e.loadAssetAsync();let i=e.asset;iA.setActive(i,!1),A=iA.instantiate(i),iA.setActive(A,!0)}Ks&&console.log(A);let t=await Vl.loader.getOrCreateNewAvatarInstance(this.context,A);if(Ks&&console.log(t,t?.isValid,this.lastAvatarId,A),t?.isValid){if(this.root=t.root,this.root.position.set(0,0,0),this.root.quaternion.set(0,0,0,1),this.root.scale.set(1,1,1),this.avatarMarker=iA.addNewComponent(this.root,it),this.avatarMarker.connectionId=this.guid,this.avatarMarker.avatar=this,this.head&&this.head!==t.head&&this.head?.removeFromParent(),this.head=t.head,this.headScale.copy(this.head.scale),this.head&&!this.isLocalAvatar&&wt.Add(this.context,this.head,this.avatarMarker),t.leftHand&&this.handLeft?.removeFromParent(),this.handLeft=t.leftHand??this.handLeft,this.handLeft?this.handLeftScale.copy(this.handLeft.scale):this.handLeftScale.set(1,1,1),t.rigthHand&&this.handRight?.removeFromParent(),this.handRight=t.rigthHand??this.handRight,this.handRight?this.handRightScale.copy(this.handRight.scale):this.handRightScale.set(1,1,1),this.context.scene.add(this.root),this.flags==null&&(this.flags=[]),this.flags.length=0,this.flags.push(...iA.getComponentsInChildren(this.root,Rt)),this.flags.length<=0&&this.head){let i=iA.addNewComponent(this.head,Rt);i.visibleIn=20,this.flags.push(i),Ks&&console.log("Added flag to head: "+i.visibleIn,this.head.name)}return Ks&&console.log("[Avatar], is Local? ",this.isLocalAvatar,this.root),this.updateFlags(),this.updateVisibility(),!0}else return Ks&&console.warn("build avatar failed"),!1}},AI=Vl;mA(AI,"loader",new Cn),mA(AI,"invertRotation",new vA().setFromAxisAngle(new R(0,1,0),Math.PI));var wt=class{static Add(A,e,t=null){if(!!e){for(let i of this.Pois)if(i.obj===e)return;this.Pois.push({obj:e,avatar:t}),this.LastChangeTime=A.time.time}}static Remove(A,e){if(!!e){for(let t of this.Pois)if(t.obj===e){this.Pois.splice(this.Pois.indexOf(t),1),this.LastChangeTime=A?.time.time??ue.Current?.time.time;return}}}};mA(wt,"Pois",[]),mA(wt,"LastChangeTime",0);var Ck=class{guid;position=new R},ZC=class extends sA{set controlledTarget(A){this.target=A;let e=hA.get("MoveRandom");if(e&&this.target){let t=iA.getComponent(this.target,e);t&&t.destroy()}}target=null;avatar=null;_model=null;_targetModel=new Ck;_currentTargetObject=null;_lastUpdateTime=0;_lookDuration=0;_lastPoiChangedTime=0;awake(){if(this.avatar=iA.getComponentInParent(this.gameObject,it),this.avatar){let A=iA.getComponentInParent(this.gameObject,it);this._model=new ws(this.context.connection,this.guid),A?.isLocalAvatar&&this._model.requestOwnership()}this.context.connection.beginListen("avatar-look-target-changed",A=>{this.target&&A&&A.guid===this.avatar?.guid&&Ze(this.target,A.position)})}update(){if((!this.context.connection.isConnected||this._model?.hasOwnership)&&(wt.LastChangeTime!==this._lastPoiChangedTime&&(this._lastPoiChangedTime=wt.LastChangeTime,this._lookDuration=0),this.selectTarget(),this._currentTargetObject&&this.context.time.frameCount%10===0&&this.target)){let e=Ce(this._currentTargetObject);Ze(this.target,e),this.context.connection.isConnected&&this.avatar&&(this.context.connection.send("avatar-look-target-changed",this._targetModel),this._targetModel.guid=this.avatar.guid,this._targetModel.position.copy(e))}}selectTarget(){if(this.context.time.time-this._lastUpdateTime>this._lookDuration){this._lastUpdateTime=this.context.time.time,this._lookDuration=Math.random()*.5+.2;let e=wt.Pois;if(e.length>0){let t=e[Math.floor(Math.random()*e.length)];if(t&&t.obj){if(t.avatar&&t.avatar===this.avatar)return;this._currentTargetObject=t.obj}}}}};var $E={};Cu($E,{AlignItems:()=>y4,Block:()=>Ad,ContentDirection:()=>m4,FontLibrary:()=>G4,InlineBlock:()=>M4,JustifyContent:()=>k4,Keyboard:()=>mk,Text:()=>Gk,TextAlign:()=>R4,Whitespace:()=>U4,default:()=>F4,update:()=>Mk});var mi={};mi.d=(I,A)=>{for(var e in A)mi.o(A,e)&&!mi.o(I,e)&&Object.defineProperty(I,e,{enumerable:!0,get:A[e]})};mi.o=(I,A)=>Object.prototype.hasOwnProperty.call(I,A);mi.r=I=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(I,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(I,"__esModule",{value:!0})};var eI={};mi.d(eI,{g1:()=>Of,gO:()=>Wa,km:()=>_f,zV:()=>zl,ol:()=>Xl,uM:()=>Pf,N1:()=>Yf,xv:()=>Zl,PH:()=>Vf,UH:()=>Wf,ZP:()=>S4,Vx:()=>mb});var _f={};mi.r(_f);mi.d(_f,{COLUMN:()=>jf,COLUMN_REVERSE:()=>Cb,ROW:()=>jl,ROW_REVERSE:()=>Ib,contentDirection:()=>ob});var Of={};mi.r(Of);mi.d(Of,{CENTER:()=>Qk,END:()=>Ek,START:()=>Bk,STRETCH:()=>nb,alignItems:()=>sb,warnAboutDeprecatedAlignItems:()=>rb});var Pf={};mi.r(Pf);mi.d(Pf,{CENTER:()=>hk,END:()=>lk,SPACE_AROUND:()=>dk,SPACE_BETWEEN:()=>uk,SPACE_EVENLY:()=>pk,START:()=>ck,justifyContent:()=>ab});var Wf={};mi.r(Wf);mi.d(Wf,{NORMAL:()=>$l,NOWRAP:()=>ZE,PRE:()=>zf,PRE_LINE:()=>XE,PRE_WRAP:()=>Zf,WHITE_CHARS:()=>nk,collapseWhitespaceOnInlines:()=>cb,collapseWhitespaceOnString:()=>Bb,newlineBreakability:()=>Qb,shouldBreak:()=>Eb});var Vf={};mi.r(Vf);mi.d(Vf,{CENTER:()=>fk,JUSTIFY:()=>wk,JUSTIFY_CENTER:()=>pb,JUSTIFY_LEFT:()=>ub,JUSTIFY_RIGHT:()=>Tf,LEFT:()=>lb,RIGHT:()=>db,textAlign:()=>Db});var Z1=I=>{var A={};return mi.d(A,I),A};var Ke=Z1({BufferAttribute:()=>Ge,BufferGeometry:()=>Qe,CanvasTexture:()=>Jh,Color:()=>P,FileLoader:()=>pi,LinearFilter:()=>Bt,Mesh:()=>Fe,Object3D:()=>qA,Plane:()=>di,PlaneGeometry:()=>Eg,ShaderMaterial:()=>bt,TextureLoader:()=>_o,Vector2:()=>SA,Vector3:()=>R}),jl="row",Ib="row-reverse",jf="column",Cb="column-reverse";function ob(I,A,e,t){let i=e,g="getWidth",C="x",o="y";A.indexOf(jf)===0&&(g="getHeight",C="y",o="x");for(let n=0;n<I.childrenBoxes.length;n++){let s=I.childrenBoxes[n],r=s.id,a=s[g](),B=s.margin||0;i+=B*t,I.childrenPos[r]={[C]:i+a/2*t,[o]:0},i+=t*(a+B)}}var Bk="start",Qk="center",Ek="end",nb="stretch";function sb(I,A){let e=I.getAlignItems();X1.indexOf(e)===-1&&console.warn(`alignItems === '${e}' is not supported`);let t="getWidth",i="x";A.indexOf(jl)===0&&(t="getHeight",i="y");let g=I[t]()/2-(I.padding||0);I.childrenBoxes.forEach(C=>{let o;switch(e){case Ek:case"right":case"bottom":A.indexOf(jl)===0?o=-g+C[t]()/2+(C.margin||0):o=g-C[t]()/2-(C.margin||0);break;case Bk:case"left":case"top":A.indexOf(jl)===0?o=g-C[t]()/2-(C.margin||0):o=-g+C[t]()/2+(C.margin||0);break}I.childrenPos[C.id][i]=o||0})}function rb(I){$1.indexOf(I)!==-1&&console.warn(`alignItems === '${I}' is deprecated and will be remove in 7.x.x. Fallback are 'start'|'end'`)}var X1=[Bk,Qk,Ek,nb,"top","right","bottom","left"],$1=["top","right","bottom","left"],ck="start",hk="center",lk="end",dk="space-around",uk="space-between",pk="space-evenly";function ab(I,A,e,t){let i=I.getJustifyContent();A4.indexOf(i)===-1&&console.warn(`justifyContent === '${i}' is not supported`);let g=A.indexOf("row")===0?"width":"height",C=I.getChildrenSideSum(g),n=(g==="width"?I.getInnerWidth():I.getInnerHeight())-C,s=e*2-C*Math.sign(e),r=e4(i,s),a=t4(I.childrenBoxes,n,i,t),B=A.indexOf("row")===0?"x":"y";I.childrenBoxes.forEach((Q,h)=>{I.childrenPos[Q.id][B]-=r-a[h]})}var A4=[ck,hk,lk,dk,uk,pk];function e4(I,A){switch(I){case lk:return A;case hk:return A/2}return 0}function t4(I,A,e,t){let i=Array(I.length).fill(0);if(A>0)switch(e){case uk:if(I.length>1){let g=A/(I.length-1)*t;i[0]=0;for(let C=1;C<I.length;C++)i[C]=g*C}break;case pk:if(I.length>1){let g=A/(I.length+1)*t;for(let C=0;C<I.length;C++)i[C]=g*(C+1)}break;case dk:if(I.length>1){let g=A/I.length*t,C=g/2;i[0]=C;for(let o=1;o<I.length;o++)i[o]=C+g*o}break}return i}function Dk(I){return class extends I{constructor(e){super(e),this.isBoxComponent=!0,this.childrenPos={}}getInnerWidth(){let e=this.getContentDirection();switch(e){case"row":case"row-reverse":return this.width-(this.padding*2||0)||this.getChildrenSideSum("width");case"column":case"column-reverse":return this.getHighestChildSizeOn("width");default:console.error(`Invalid contentDirection : ${e}`);break}}getInnerHeight(){let e=this.getContentDirection();switch(e){case"row":case"row-reverse":return this.getHighestChildSizeOn("height");case"column":case"column-reverse":return this.height-(this.padding*2||0)||this.getChildrenSideSum("height");default:console.error(`Invalid contentDirection : ${e}`);break}}getChildrenSideSum(e){return this.childrenBoxes.reduce((t,i)=>{let g=i.margin*2||0,C=e==="width"?i.getWidth()+g:i.getHeight()+g;return t+C},0)}setPosFromParentRecords(){this.parentUI&&this.parentUI.childrenPos[this.id]&&(this.position.x=this.parentUI.childrenPos[this.id].x,this.position.y=this.parentUI.childrenPos[this.id].y)}computeChildrenPosition(){if(this.children.length>0){let e=this.getContentDirection(),t;switch(e){case jl:t=-this.getInnerWidth()/2;break;case Ib:t=this.getInnerWidth()/2;break;case jf:t=this.getInnerHeight()/2;break;case Cb:t=-this.getInnerHeight()/2;break}let i=-Math.sign(t);ob(this,e,t,i),ab(this,e,t,i),sb(this,e)}}getHighestChildSizeOn(e){return this.childrenBoxes.reduce((t,i)=>{let g=i.margin||0,C=e==="width"?i.getWidth()+g*2:i.getHeight()+g*2;return Math.max(t,C)},0)}getWidth(){return this.parentUI&&this.parentUI.getAlignItems()==="stretch"&&this.parentUI.getContentDirection().indexOf("column")!==-1?this.parentUI.getWidth()-(this.parentUI.padding*2||0):this.width||this.getInnerWidth()+(this.padding*2||0)}getHeight(){return this.parentUI&&this.parentUI.getAlignItems()==="stretch"&&this.parentUI.getContentDirection().indexOf("row")!==-1?this.parentUI.getHeight()-(this.parentUI.padding*2||0):this.height||this.getInnerHeight()+(this.padding*2||0)}}}var nk={" ":" ","\n":`
6392
+ --------------`),t[g]=o,t.needsUpdate=!0,dg)){let n=_M.get(t);n||(n={},_M.set(t,n));let s=n[g];s||(s=n[g]={original:C,lod0:o}),s.lod0=o}}))}}get name(){return HM}parser;sourceId;context;constructor(A,e,t){this.parser=A,this.sourceId=e,this.context=t}_loading=[];afterRoot(A){return dg&&console.log("AFTER",this.sourceId,A),this.parser.json.textures?.forEach((e,t)=>{if(e?.extensions){let i=e?.extensions[HM];if(i){let g=this.parser.getDependency("texture",t);this._loading.splice(this._loading.indexOf(t),1),g.then(C=>{dg&&console.log("register texture",C.name,C.uuid,i),C.userData.deferred=i,Pl.cache.set(C.uuid,i)})}}}),null}static async getOrLoadTexture(A,e,t,i,g,C){let o=g.uuid,n=Pl.cache.get(o);if(n){dg&&console.log(o,n.uri,n.guid);let s=JC(e,n.uri);if(s.endsWith(".glb")||s.endsWith(".gltf")){if(!n.guid)return console.warn("missing pointer for glb/gltf texture",n),null;let r=s+"_"+n.guid;if(this.resolved[r])return dg&&console.log("Texture has already been loaded: "+r,t.name,i,g.name),this.resolved[r];let a=new b1;en(a,A),dg&&console.log("Load "+s,t.name,i,n.guid);let B=await a.loadAsync(s),Q=B.parser;dg&&console.log("Loading finished "+s,t.name,i,n.guid);let h=-1,E=!1;for(let l of B.parser.json.textures)if(h++,l?.extensions){let d=l?.extensions[HM];if(d?.guid&&d.guid===n.guid){E=!0;break}}if(!E)return null;let c=await Q.getDependency("texture",h);return c&&(c.guid=n.guid),this.resolved[r]=c,dg&&console.log(t.name,i,'change "'+g.name+'" \u2192 "'+c.name+'"',s,h,c,t,r),c}else{dg&&console.log("Load texture from uri: "+s);let a=await new _o().loadAsync(s);return a&&dg?console.log(n,a):console.warn("failed loading",s),a}}else dg&&console.warn("unknown uuid",g.name,g.uuid,g);return null}},gn=Pl;mA(gn,"cache",new Map),mA(gn,"resolved",{});function PM(I){let A=new HE;return I.register(e=>(A.parser=e,A)),A}var OM=class{resolvePath(A){return A.includes("/extensions/builtin_components/")?A.replace("/extensions/builtin_components/","/userData/components/"):A.includes("extensions/builtin_components/")?A.replace("extensions/builtin_components/","/userData/components/"):A}};function WM(I,A,e){I.register(i=>new kf(i)),I.register(i=>new Op(i)),I.register(i=>new pf(i,A.lightmaps,e)),I.register(i=>new Rf(i,e,A)),I.register(i=>new mf(i,e)),I.register(i=>new _a(i,e)),I.register(i=>new gn(i,e,A)),I.register(i=>new Mf(i));let t=I.setAnimationPointerResolver;typeof t=="function"&&t.bind(I)(new OM)}var In=class extends sA{from;to;width=0;centered=!0;_centerPos;awake(){this._centerPos=new R}update(){if(!this.from||!this.to)return;let A=Ce(this.from).clone(),e=Ce(this.to).clone(),t=A.distanceTo(e);this._centerPos.copy(A),this._centerPos.add(e),this._centerPos.multiplyScalar(.5),Ze(this.gameObject,this.centered?this._centerPos:A),this.gameObject.lookAt(Ce(this.to).clone()),this.gameObject.scale.set(this.width,this.width,t)}};W([O(iA)],In.prototype,"from",2),W([O(iA)],In.prototype,"to",2);var WC=class{time;value;inTangent;inWeight;outTangent;outWeight;weightedMode};W([O()],WC.prototype,"time",2),W([O()],WC.prototype,"value",2),W([O()],WC.prototype,"inTangent",2),W([O()],WC.prototype,"inWeight",2),W([O()],WC.prototype,"outTangent",2),W([O()],WC.prototype,"outWeight",2),W([O()],WC.prototype,"weightedMode",2);var Gs=class{keys;get duration(){return!this.keys||this.keys.length==0?0:this.keys[this.keys.length-1].time}evaluate(A){if(!this.keys||this.keys.length==0)return 0;let e=null;for(let t of this.keys){if(e&&t.time>A&&A>e.time)return ce.lerp(e.value,t.value,(A-e.time)/(t.time-e.time));e=t}return this.keys[this.keys.length-1].value}};W([O(WC)],Gs.prototype,"keys",2);import{PositionalAudioHelper as x1}from"three/examples/jsm/helpers/PositionalAudioHelper.js";var ug=cA("debugaudio");var oi=class extends sA{static get userInteractionRegistered(){return oi._didCallBeginWaitForUserInteraction||(oi._didCallBeginWaitForUserInteraction=!0,oi._beginWaitForUserInteraction()),oi._userInteractionRegistered}static registerWaitForAllowAudio(A){if(A!==null){if(this._userInteractionRegistered){A();return}this.callbacks.indexOf(A)===-1&&this.callbacks.push(A),oi._didCallBeginWaitForUserInteraction||(oi._didCallBeginWaitForUserInteraction=!0,oi._beginWaitForUserInteraction())}}static _beginWaitForUserInteraction(A=null){if(this._userInteractionRegistered){A&&A();return}A!==null&&this.registerWaitForAllowAudio(A);let t=(()=>{if(t!=null&&!oi._userInteractionRegistered){oi._userInteractionRegistered=!0,console.log("registered interaction, can play audio now"),document.removeEventListener("pointerdown",t),document.removeEventListener("click",t),document.removeEventListener("dragstart",t),document.removeEventListener("touchstart",t);for(let i of this.callbacks)i();this.callbacks.length=0}}).bind(this);document.addEventListener("pointerdown",t),document.addEventListener("click",t),document.addEventListener("dragstart",t),document.addEventListener("touchstart",t)}clip="";playOnAwake=!1;get loop(){return this.sound&&(this._loop=this.sound.getLoop()),this._loop}set loop(A){this._loop=A,this.sound&&this.sound.setLoop(A)}get spatialBlend(){return this._spatialBlend}set spatialBlend(A){A!==this._spatialBlend&&(this._spatialBlend=A,this._needUpdateSpatialDistanceSettings=!0)}get minDistance(){return this._minDistance}set minDistance(A){this._minDistance!==A&&(this._minDistance=A,this._needUpdateSpatialDistanceSettings=!0)}get maxDistance(){return this._maxDistance}set maxDistance(A){this._maxDistance!==A&&(this._maxDistance=A,this._needUpdateSpatialDistanceSettings=!0)}_spatialBlend=0;_minDistance=1;_maxDistance=100;get volume(){return this._volume}set volume(A){this._volume=A,this.sound&&(ug&&console.log(this.name,"audio set volume",A),this.sound.setVolume(A))}_volume=1;rollOffMode=0;_loop=!1;sound=null;helper=null;wasPlaying=!1;audioLoader=null;shouldPlay=!1;_lastClipStartedLoading=null;get Sound(){if(!this.sound&&oi._userInteractionRegistered){let A=iA.getComponent(this.context.mainCamera,RI)??iA.findObjectOfType(RI,this.context);A?.listener&&(this.sound=new jh(A.listener),this.gameObject.add(this.sound))}return this.sound}get ShouldPlay(){return this.shouldPlay}_focusCallback;awake(){this.audioLoader=new rs,this.playOnAwake&&(this.shouldPlay=!0),window.addEventListener("visibilitychange",A=>{switch(document.visibilityState){case"hidden":this.wasPlaying=this.isPlaying,this.pause();break;case"visible":this.wasPlaying&&this.play();break}}),this._focusCallback=()=>{this.enabled&&this.playOnAwake&&!this.isPlaying&&oi._userInteractionRegistered&&this.play()},this.context.application.addEventListener("application-visible",this._focusCallback)}onDestroy(){this.context.application.removeEventListener("application-visible",this._focusCallback)}onEnable(){oi._userInteractionRegistered?this.playOnAwake&&this.context.application.isVisible&&this.play():oi._beginWaitForUserInteraction(()=>{this.enabled&&!this.destroyed&&this.shouldPlay&&this.loadAndPlay(this.clip)})}onDisable(){this.stop()}lerp=(A,e,t)=>A*(1-t)+e*t;onLoaded(A){ug&&console.log("audio buffer loaded"),oi.registerWaitForAllowAudio(()=>{ug&&console.log("finished loading",A);let e=this.Sound;if(!e){console.warn("Failed getting sound",this.name);return}e.isPlaying&&e.stop(),e.setBuffer(A),e.loop=this.loop,e.setVolume(this.volume),e.autoplay=this.shouldPlay,this.applySpatialDistanceSettings(),e.isPlaying&&e.stop(),ug&&console.log(this.name,this.shouldPlay,oi.userInteractionRegistered,this),this.shouldPlay&&oi._userInteractionRegistered&&this.play()})}applySpatialDistanceSettings(){let A=this.sound;if(!A)return;this._needUpdateSpatialDistanceSettings=!1;let e=this.lerp(10*this._maxDistance/Math.max(1e-4,this.spatialBlend),this._minDistance,this.spatialBlend);switch(ug&&console.log(this.name,this._minDistance,this._maxDistance,this.spatialBlend,"Ref distance="+e),A.setRefDistance(e),A.setMaxDistance(Math.max(.01,this._maxDistance)),this.rollOffMode){case 0:A.setDistanceModel("exponential");break;case 1:A.setDistanceModel("linear");break;case 2:break}this.spatialBlend>0?ug&&!this.helper&&(this.helper=new x1(A,A.getRefDistance()),A.add(this.helper)):this.helper&&this.helper.parent&&this.helper.removeFromParent()}loadAndPlay(A){if(A&&(this.clip=A),this.clip&&(ug&&console.log(this.clip),this.clip.endsWith(".mp3")||this.clip.endsWith(".wav"))){if(this.audioLoader||(this.audioLoader=new rs),this.shouldPlay=!0,this._lastClipStartedLoading===this.clip){ug&&console.log("Is currently loading:",this._lastClipStartedLoading,this);return}this._lastClipStartedLoading=this.clip,ug&&console.log("load audio",this.clip),this.audioLoader.load(this.clip,this.onLoaded.bind(this),()=>{},console.error)}}play(A=void 0){if(!this.audioLoader||!this.sound||A&&A!==this.clip){this.loadAndPlay(A);return}this.shouldPlay=!0,this._hasEnded=!1,ug&&console.log("play",this.sound?.getVolume(),this.sound),this.sound&&!this.sound.isPlaying&&this.sound.play()}pause(){ug&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.isPlaying&&this.sound.source&&(this._lastContextTime=this.sound?.context.currentTime,this.sound.pause())}stop(){ug&&console.log("Pause",this),this._hasEnded=!0,this.shouldPlay=!1,this.sound&&this.sound.source&&(this._lastContextTime=this.sound?.context.currentTime,ug&&console.log(this._lastContextTime),this.sound.stop())}_lastContextTime=0;get isPlaying(){return this.sound?.isPlaying??!1}set isPlaying(A){}get time(){return this.sound?.source?this.sound.source?.context.currentTime-this._lastContextTime+this.sound.offset:0}set time(A){if(this.sound){if(A===this.sound.offset)return;let e=this.isPlaying;this.stop(),this.sound.offset=A,e&&this.play()}}_hasEnded=!0;_needUpdateSpatialDistanceSettings=!1;update(){this.helper&&(this.isPlaying&&this.helper.update(),this.helper.visible=this.isPlaying),this._needUpdateSpatialDistanceSettings&&this.applySpatialDistanceSettings(),this.sound&&!this.sound.isPlaying&&this.shouldPlay&&!this._hasEnded&&(this._hasEnded=!0,ug&&console.log("Audio clip ended",this.clip),this.sound.dispatchEvent({type:"ended",target:this}))}},Xe=oi;mA(Xe,"_didCallBeginWaitForUserInteraction",!1),mA(Xe,"callbacks",[]),mA(Xe,"_userInteractionRegistered",!1),W([O()],Xe.prototype,"clip",2),W([O()],Xe.prototype,"playOnAwake",2),W([O()],Xe.prototype,"loop",1),W([O()],Xe.prototype,"spatialBlend",1),W([O()],Xe.prototype,"minDistance",1),W([O()],Xe.prototype,"maxDistance",1),W([O()],Xe.prototype,"volume",1),W([O()],Xe.prototype,"rollOffMode",2);var ft=class extends P{alpha=1;get isRGBAColor(){return!0}constructor(A,e,t,i){super(A,e,t),this.alpha=i}clone(){let A=super.clone();return A.alpha=this.alpha,A}copy(A){return super.copy(A),"alpha"in A&&typeof A.alpha=="number"?this.alpha=A.alpha:typeof A.a=="number"&&(this.alpha=A.a),this}lerp(A,e){let t=A;return t.alpha&&(this.alpha=ce.lerp(this.alpha,t.alpha,e)),super.lerp(A,e)}multiply(A){let e=A;return e.alpha&&(this.alpha=this.alpha*e.alpha),super.multiply(A)}};var Uf=cA("debugcam"),rt=class extends sA{get isCamera(){return!0}get aspect(){return this._cam instanceof et?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._fov}set fieldOfView(A){let e=this._fov!=A;this._fov=A,e&&this._cam&&this._cam instanceof et&&(this._cam.fov=this._fov,this._cam.updateProjectionMatrix())}get nearClipPlane(){return this._nearClipPlane}set nearClipPlane(A){let e=this._nearClipPlane!=A;this._nearClipPlane=A,this._cam&&e&&(this._cam.near=A,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(A){let e=this._farClipPlane!=A;this._farClipPlane=A,this._cam&&e&&(this._cam.far=A,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(A){A!==this._clearFlags&&(this._clearFlags=A,this.applyClearFlagsIfIsActiveCamera())}orthographic=!1;orthographicSize=5;ARBackgroundAlpha=0;_nearClipPlane=.1;_farClipPlane=1e3;get backgroundColor(){return this._backgroundColor??null}set backgroundColor(A){if(!!A){if(this._backgroundColor)this._backgroundColor.copy(A);else{if(!A.clone)return;this._backgroundColor=A.clone()}A.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}_backgroundColor;_fov=60;_cam=null;_clearFlags=2;_skybox;get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}awake(){this.sourceId||console.warn("Camera has no source - the camera should be exported inside a gltf",this.name)}onEnable(){Uf&&console.log(this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&this.context.setCurrentCamera(this),this.applyClearFlagsIfIsActiveCamera()}onDisable(){this.context.removeCamera(this)}buildCamera(){if(this._cam)return;let A=this.gameObject.isCamera,e=null;if(A?e=this.gameObject:e=this.gameObject.children[0],e&&e.isCamera)e.type==="PerspectiveCamera"&&(e.fov=this._fov,e.near=this._nearClipPlane,e.far=this._farClipPlane,e.updateProjectionMatrix());else if(!this.orthographic)e=new et(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),e.fov=this.fieldOfView;else{let t=this.orthographicSize*100;e=new gs(window.innerWidth/-t,window.innerWidth/t,window.innerHeight/t,window.innerHeight/-t,this._nearClipPlane,this._farClipPlane)}this._cam=e,this.layer===0&&this._cam.layers.enableAll(),this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){if(Uf&&eC("apply Camera clear flags"),this._cam&&this.context.mainCameraComponent===this)switch(this._clearFlags){case 1:if(this.environmentIsTransparent()&&(!this.ARBackgroundAlpha||this.ARBackgroundAlpha<.001)){this.context.scene.background=null,this.context.renderer.setClearColor(0,0);return}this.enableSkybox();break;case 2:if(this._backgroundColor){let A=this._backgroundColor.alpha;this.environmentIsTransparent()&&(A=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,A)}break;case 4:this.context.scene.background=null,this.context.renderer.setClearColor(0,0);break}}environmentIsTransparent(){let A=this.context.renderer.xr?.getSession();if(!A)return!1;let e=A.environmentBlendMode;Uf&&eC("Environment blend mode: "+e+" on "+navigator.userAgent);let t=e==="additive"||e==="alpha-blend";if(this.context.xrSessionMode==="immersive-ar"&&e==="opaque"){if(navigator.userAgent?.includes("OculusBrowser"))return!0;if(navigator.userAgent?.includes("Mozilla")&&navigator.userAgent?.includes("Mobile WebXRViewer/v2"))return!0}return t}enableSkybox(){this._skybox||(this._skybox=new VM(this)),this._skybox.enable()}};W([O()],rt.prototype,"fieldOfView",1),W([O()],rt.prototype,"nearClipPlane",1),W([O()],rt.prototype,"farClipPlane",1),W([O()],rt.prototype,"clearFlags",1),W([O()],rt.prototype,"orthographic",2),W([O()],rt.prototype,"orthographicSize",2),W([O()],rt.prototype,"ARBackgroundAlpha",2),W([O(ft)],rt.prototype,"backgroundColor",1);var VM=class{_camera;_skybox;get context(){return this._camera?.context}constructor(A){this._camera=A}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?(Uf&&console.log("Set skybox",this._camera,this._skybox),this._skybox.encoding=Ue,this._skybox.mapping=Bg,this.context.scene.background=this._skybox):console.warn("Failed to load/find skybox texture",this)}};var RI=class extends sA{get listener(){return this._listener==null&&(this._listener=new Qa),this._listener}_listener=null;awake(){Xe.registerWaitForAllowAudio(()=>{let A=this.listener;if(A==null||A.parent)return;let e=iA.getComponentInParent(this.gameObject,rt);e?e.cam.add(A):this.gameObject.add(A)})}};import{GLTFLoader as T1}from"three/examples/jsm/loaders/GLTFLoader";var Wl=cA("debugavatar"),Ms=class{root;head;leftHand;rigthHand;get isValid(){return this.head!==null&&this.head!==void 0}constructor(A,e,t,i){this.root=A,this.head=e,this.leftHand=t,this.rigthHand=i,this.root?.traverse(g=>g.layers.set(2))}},Cn=class{avatarRegistryUrl=null;async getOrCreateNewAvatarInstance(A,e){if(!e)return console.error("Can not create avatar: failed to provide id or root object"),null;let t=null;if(typeof e=="string"){if(t=await this.loadAvatar(A,e),!t){let g=new wi;t=iA.instantiate(Qs(e,A.scene),g)}}else t=e;if(!t)return null;let i=this.findAvatar(t);return i.isValid?(Wl&&console.log("[Custom Avatar] valid config",e,Wl?i:""),i):(console.warn("[Custom Avatar] config isn't valid",e,Wl?i:""),null)}async loadAvatar(A,e){if(console.assert(e!=null&&typeof e=="string","Avatar id must not be null"),e.length<=0||!e)return null;if(Wl&&console.log("[Custom Avatar] "+e+", loading..."),e.endsWith(".glb")||(e+=".glb"),this.avatarRegistryUrl===null){let i=await fetch("./"+e),g=null;if(i.ok){let o=await i.blob();o&&(g=await o.arrayBuffer())}return!g&&(g=await Qf(e,e,0,"no url here go away",!0),!g)?null:(await bi().parseSync(A,g,null,0))?.scene??null}let t=new T1;return en(t,A),new Promise((i,g)=>{let C=this.avatarRegistryUrl+"/"+e;t.load(C,async o=>{await bi().createBuiltinComponents(A,C,o,null,void 0),i(o.scene)},o=>{Wl&&console.log("[Custom Avatar] "+o.loaded/o.total*100+"% loaded of "+o.total/1024+"kB")},o=>{console.error("[Custom Avatar] Error when loading: "+o),i(null)})})}cacheModel(A,e){}findAvatar(A){let e=A,t=e;t.children.length==1&&(t=A.children[0]);let i=this.findAvatarPart(t,["head"]),g=this.findAvatarPart(t,["left","hand"]),C=this.findAvatarPart(t,["right","hand"]);if(!i){i=e;let n=new R;new jt().setFromObject(i).getSize(n);let s=Math.max(n.x,n.y,n.z);console.warn("[Custom Avatar] Normalizing head scale, it's too big: "+s+" meters! Should be < 0.3m"),s>.3&&i.scale.multiplyScalar(1/s*.3)}return new Ms(e,i,g,C)}findAvatarPart(A,e){let t=A.name.toLowerCase(),i=!0;for(let g of e){if(!i)break;t.indexOf(g)===-1&&(i=!1)}if(i)return A;if(A.children)for(let g of A.children){let C=this.findAvatarPart(g,e);if(C)return C}return null}handleCustomAvatarErrors(A){if(!A.ok)throw Error(A.statusText);return A}};var VC=class extends sA{length=1;depthTest=!0;isGizmo=!0;_axes=null;onEnable(){if(this.isGizmo&&!qC)return;this._axes||(this._axes=new AC(this.length)),this.gameObject.add(this._axes);let A=this._axes.material;A&&A.depthTest!==void 0&&(A.depthTest=this.depthTest)}onDisable(){!this._axes||this.gameObject.remove(this._axes)}};W([O()],VC.prototype,"length",2),W([O()],VC.prototype,"depthTest",2),W([O()],VC.prototype,"isGizmo",2);var Oa=class extends sA{from;to;hint;desiredDistance=1;onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;let A=Ce(this.to).clone(),e=Ce(this.from).clone(),t=A.distanceTo(e),i=A.clone();i.sub(e);let g=e.clone();g.add(A),g.multiplyScalar(.5);let C=Ce(this.hint).clone();C.sub(g);let o=new R;o.crossVectors(C,i),o.crossVectors(i,o),o.normalize();let n=t*.5,s=Math.max(this.desiredDistance,n),r=Math.sqrt(s*s-n*n),a=o.clone();a.multiplyScalar(r),a.add(g),Ze(this.gameObject,a);let B=g.clone();B.sub(o),this.gameObject.lookAt(B)}};var H1=new Qg(1,1,1);function Ff(I=null){let A=new P(I??14540253),e=new zQ(H1);return new qi(e,new Mt({color:A}))}var _1=cA("gizmos"),Vg=class extends sA{box=null;_lastMatrixUpdateFrame=-1;isInBox(A,e){if(!!A){if(this.box||(this.box=new jt),A.type==="Mesh")Vg.testBox.setFromObject(A);else if(A.type==="Group"){if(A.children.length>0){Vg.testBox.setFromCenterAndSize(Vg._position.set(0,0,0),Vg._size.set(0,0,0));for(let t=0;t<A.children.length;t++)A.children[t].type==="Mesh"&&Vg.testBox.expandByObject(A)}}else{let t=Ce(A,Vg._position),i=vg(A,Vg._size);e!==void 0&&i.multiplyScalar(e),Vg.testBox.setFromCenterAndSize(t,i)}return this.updateBox(),this.box?.intersectsBox(Vg.testBox)}}intersects(A){return A?this.updateBox(!1).intersectsBox(A):!1}updateBox(A=!1){if(this.box||(this.box=new jt),A||this.context.time.frameCount!=this._lastMatrixUpdateFrame){let e=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;let t=e,i=Ce(this.gameObject,Vg._position,t),g=vg(this.gameObject,Vg._size);this.box.setFromCenterAndSize(i,g)}return this.box}_helper=null;_color=null;awake(){this._helper=null,this._color=null,this.box=null}showHelper(A=null,e=!1){if(!(!_1&&!e)){if(this._helper){A&&this._color?.set(A),this.gameObject.add(this._helper);return}this._helper=Ff(A),this.gameObject.add(this._helper)}}},ni=Vg;mA(ni,"testBox",new jt),mA(ni,"_position",new R),mA(ni,"_size",new R(.01,.01,.01));var rC=class{method;enabled;constructor(A,e){this.method=A,this.enabled=e!==void 0?e:!0}invoke(...A){if(this.enabled!==!1){if(!this.method){console.warn("No function. Please check you assigned a method to invoke on export",this);return}this.method(...A)}}},O1=I=>/^[A-Z]*$/.test(I),ks=class extends Event{args},kt=class{target;key;setEventTarget(A,e){if(this.key=A,this.target=e,this.key!==void 0){let t="",i=!1;for(let g of this.key)i&&O1(g)&&(t+="-"),i=!0,t+=g.toLowerCase();this.key=t}}_isInvoking=!1;methods=[];constructor(A){this.methods=A??[]}invoke(...A){if(this._isInvoking){console.warn("Circular event invocation detected. Please check your event listeners for circular references.",this);return}this._isInvoking=!0;try{for(let e of this.methods)e.invoke(...A);if(typeof this.target=="object"&&typeof this.key=="string"){let e=this.target.dispatchEvent;if(typeof e=="function"){let t=new ks(this.key);t.args=A,e.call(this.target,t)}}}finally{this._isInvoking=!1}}addEventListener(A){return this.methods.push(new rC(A,!0)),A}removeEventListener(A){if(!!A)for(let e=this.methods.length-1;e>=0;e--)this.methods[e].method===A&&(this.methods[e].enabled=!1,this.methods.splice(e,1))}removeAllEventListeners(){this.methods.length=0}};var zM=class extends zo{constructor(){super([P,ft])}onDeserialize(A){if(A!=null)return A.a!==void 0?new ft(A.r,A.g,A.b,A.a):A.alpha!==void 0?new ft(A.r,A.g,A.b,A.alpha):new P(A.r,A.g,A.b)}onSerialize(A){if(A!=null)return A.a!==void 0?{r:A.r,g:A.g,b:A.b,a:A.a}:{r:A.r,g:A.g,b:A.b}}},MtA=new zM,ZM=class extends zo{constructor(){super(qA)}onSerialize(A,e){if(e.objectToNode!==void 0&&A.uuid){let t=e.objectToNode[A.uuid];return Xt&&console.log(t,A.name,A.uuid),{node:t}}}onDeserialize(A,e){if(A){if(A.node!==void 0&&e.nodeToObject){let t=e.nodeToObject[A.node];return Xt&&console.log("Deserialized object reference?",A,t,e?.nodeToObject),t||console.warn("Did not find node: "+A.node,e.nodeToObject,e.object),t}else if(A.guid){if(!e.context){console.error("Missing context");return}let t,i=e.gltf?.scene;return i&&(t=iA.findByGuid(A.guid,i)),t||(t=iA.findByGuid(A.guid,e.context.scene)),t?Xt&&console.log("Deserialized object reference?",A,t,e?.nodeToObject):console.warn("could not resolve reference",A,e.target,e.path,e.context.scene),t}}}},P1=new ZM,XM=class extends zo{constructor(){super([Wg,sA])}onSerialize(A,e){if(A?.guid)return{guid:A.guid}}onDeserialize(A,e){if(A?.guid){Xt&&console.log(A.guid,e.root,e.object,e.target);let t=this.findObjectForGuid(A.guid,e.root);if(t)return t;if(e.context)return this.findObjectForGuid(A.guid,e.context?.scene)}}findObjectForGuid(A,e){if(e.guid===A)return e;let t=iA.foreachComponent(e,i=>{if(i.guid===A)return i},!1);if(t!==void 0)return t;for(let i=0;i<e.children.length;i++){let g=e.children[i],C=this.findObjectForGuid(A,g);if(C)return C}}},jM=new XM,$M=class extends zo{constructor(){super([kt])}onSerialize(A,e){console.log("TODO: SERIALIZE EVENT")}onDeserialize(A,e){if(A&&A.type==="EventList"){Xt&&console.log("DESERIALIZE EVENT",A);let t=new Array;for(let C of A.calls){Xt&&console.log(C);let o=jM.findObjectForGuid(C.target,e.root);!o&&e.context?.scene&&(o=jM.findObjectForGuid(C.target,e.context?.scene));let n=C.method?.length>0;if(o&&n){let B=()=>console.warn(`Could not find method ${C.method} on object ${o.name}`,o,typeof o[C.method]);if(typeof o[C.method]!="function"){let Q=!1;C.method.startsWith("set_")&&C.method.length>4&&(C.method=C.method.substring(4),o[C.method]!==void 0&&(Q=!0)),Q||B()}}let s,r=C.argument;C.argument!==void 0?(typeof r=="object"&&(r=P1.onDeserialize(C.argument,e),r||(r=jM.onDeserialize(C.argument,e))),s=new rC(n?(...B)=>a(...B):void 0,C.enabled)):s=new rC(n?(...B)=>a(...B):void 0,C.enabled);let a=(...B)=>{let Q=o[C.method];typeof Q=="function"?r!==void 0?Q?.call(o,r):Q?.call(o,...B):o[C.method]=r};if(s.method||(s.__debuginfo=e.object?.name),!o||!s.method){let B=e.object?"Current object: "+e.object.name+", "+e.object.guid:null;o?console.warn('EventList method not found: "'+C.method+'" on',o):console.warn("EventList is missing target - will be ignored",C.target,B,A)}else t.push(s)}let i=new kt(t);Xt&&console.log(i);let g=e.target;return g!==void 0&&e.path!==void 0&&i.setEventTarget(e.path,g),i}}},ktA=new $M;var aC=function(I,A){return function(e,t,i){V1(e,t,i,I,A)}};function V1(I,A,e,t,i){if(!(!i&&!t&&!I.onValidate)){if(e!==void 0){console.error("Invalid usage of validate decorator. Only fields can be validated.",I,A,e),eC("Invalid usage of validate decorator. Only fields can be validated. Property: "+A,2);return}if(I.__internalAwake){let g=Symbol(A),C=I.__internalAwake;I.__internalAwake=function(){this[g]===void 0&&(this[g]=this[A],Object.defineProperty(this,A,{set:function(o){if(this[zp]===!0)this[g]=o;else{t?.call(this,o);let n=this[g];this[g]=o,this.onValidate?.call(this,A,n)}},get:function(){return i?.call(this),this[g]}})),C.call(this)}}}}var Ak=class{get isDirty(){return this.positionChanged||this.rotationChanged}positionChanged=!1;rotationChanged=!1;position;quaternion;_positionKeys=["x","y","z"];_quaternionKeys=["_x","_y","_z","_w"];reset(A=!1){if(this.positionChanged=!1,this.rotationChanged=!1,this.mute=!1,A){if(this.position)for(let e of this._positionKeys)delete this.position[e];if(this.quaternion)for(let e of this._quaternionKeys)delete this.quaternion[e]}}mute=!1;applyValues(){if(this.positionChanged&&this.position)for(let A of this._positionKeys){let e=this.position[A];e!==void 0&&(this.obj.position[A]=e)}if(this.rotationChanged&&this.quaternion)for(let A of this._quaternionKeys){let e=this.quaternion[A];e!==void 0&&(this.obj.quaternion[A]=e)}}context;obj;_positionWatch;_rotationWatch;constructor(A,e){this.context=e,this.obj=A}start(A,e){this.reset(),A&&(this._positionWatch||(this._positionWatch=new Vo(this.obj.position,["x","y","z"])),this._positionWatch.apply(),this.position={},this._positionWatch.subscribeWrite((t,i)=>{if(this.context.physics.isUpdating||this.mute)return;let g=this.position[i];Math.abs(g-t)<1e-5||(this.position[i]=t,this.positionChanged=!0)})),e&&(this._rotationWatch||(this._rotationWatch=new Vo(this.obj.quaternion,["_x","_y","_z","_w"])),this._rotationWatch.apply(),this.quaternion={},this._rotationWatch.subscribeWrite((t,i)=>{if(this.context.physics.isUpdating||this.mute)return;let g=this.quaternion[i];Math.abs(g-t)<1e-5||(this.quaternion[i]=t,this.rotationChanged=!0)}))}stop(){this._positionWatch?.revoke(),this._rotationWatch?.revoke()}},Nf=class extends sA{mass=1;useGravity=!0;constraints=0;isKinematic=!1;drag=0;angularDrag=1;detectCollisions=!0;sleepThreshold=.01;collisionDetectionMode=0;get lockPositionX(){return(this.constraints&2)!==0}get lockPositionY(){return(this.constraints&4)!==0}get lockPositionZ(){return(this.constraints&8)!==0}get lockRotationX(){return(this.constraints&16)!==0}get lockRotationY(){return(this.constraints&32)!==0}get lockRotationZ(){return(this.constraints&64)!==0}set lockPositionX(A){A?this.constraints|=2:this.constraints&=-3}set lockPositionY(A){A?this.constraints|=4:this.constraints&=-5}set lockPositionZ(A){A?this.constraints|=8:this.constraints&=-9}set lockRotationX(A){A?this.constraints|=16:this.constraints&=-17}set lockRotationY(A){A?this.constraints|=32:this.constraints&=-33}set lockRotationZ(A){A?this.constraints|=64:this.constraints&=-65}_propertiesChanged=!1;_currentVelocity;_smoothedVelocity;_smoothedVelocityGetter;_lastPosition;_watch;awake(){this._watch=void 0,this._currentVelocity=new R,this._smoothedVelocity=new R,this._smoothedVelocityGetter=new R,this._lastPosition=new R}onEnable(){this._watch||(this._watch=new Ak(this.gameObject,this.context)),this._watch.start(!0,!0),this.startCoroutine(this.beforePhysics(),2)}onDisable(){this._watch?.stop(),this.context.physics.removeBody(this)}onDestroy(){this.context.physics.removeBody(this)}onValidate(){this._propertiesChanged=!0}*beforePhysics(){for(;;)this._propertiesChanged&&(this._propertiesChanged=!1,this.context.physics.updateProperties(this)),this._watch?.isDirty&&(this._watch.mute=!0,this._watch.applyValues(),this.context.physics.updateBody(this,this._watch.positionChanged,this._watch.rotationChanged),this._watch.reset()),this.captureVelocity(),yield}get body(){return this.context.physics.internal_getRigidbody(this)}teleport(A,e=!0){this._watch?.reset(!0),e?this.gameObject.position.set(A.x,A.y,A.z):this.setWorldPosition(A.x,A.y,A.z),this.resetForcesAndTorques(),this.resetVelocities()}resetForces(){this.body?.resetForces(!0)}resetTorques(){this.body?.resetTorques(!0)}resetVelocities(){this.setVelocity(0,0,0),this.setAngularVelocity(0,0,0)}resetForcesAndTorques(){this.resetForces(),this.resetTorques()}wakeUp(){this.body?.wakeUp()}applyForce(A,e){this.body?.addForce(A,!0)}applyImpulse(A){this.body?.applyImpulse(A,!0)}setForce(A,e,t){this.body?.resetForces(!0),this.body?.addForce({x:A,y:e,z:t},!0)}getVelocity(){let A=this.body?.linvel();return A?(this._currentVelocity.x=A.x,this._currentVelocity.y=A.y,this._currentVelocity.z=A.z,this._currentVelocity):this._currentVelocity.set(0,0,0)}setVelocity(A,e,t){if(A instanceof R){let i=A;this.body?.setLinvel(i,!0);return}e===void 0||t===void 0||this.body?.setLinvel({x:A,y:e,z:t},!0)}setAngularVelocity(A,e,t){if(A instanceof R){let i=A;this.body?.setAngvel(i,!0);return}e===void 0||t===void 0||this.body?.setAngvel({x:A,y:e,z:t},!0)}setTorque(A,e,t){this.setAngularVelocity(A,e,t)}get smoothedVelocity(){return this._smoothedVelocityGetter.copy(this._smoothedVelocity),this._smoothedVelocityGetter.multiplyScalar(1/this.context.time.deltaTime)}setBodyFromGameObject(A=null){this.gameObject&&this.destroyed}captureVelocity(){if(this.body){let A=Ce(this.gameObject);Nf.tempPosition.copy(A);let e=A.sub(this._lastPosition);this._lastPosition.copy(Nf.tempPosition),this._smoothedVelocity.lerp(e,this.context.time.deltaTime/.1)}}},be=Nf;mA(be,"tempPosition",new R),W([aC(),O()],be.prototype,"mass",2),W([aC(),O()],be.prototype,"useGravity",2),W([aC(),O()],be.prototype,"constraints",2),W([aC(),O()],be.prototype,"isKinematic",2),W([aC(),O()],be.prototype,"drag",2),W([aC(),O()],be.prototype,"angularDrag",2),W([aC(),O()],be.prototype,"detectCollisions",2),W([aC(),O()],be.prototype,"sleepThreshold",2),W([aC(),O()],be.prototype,"collisionDetectionMode",2);var zg=class extends sA{get isCollider(){return!0}attachedRigidbody=null;isTrigger=!1;awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(be))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(be))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(be))}onDisable(){this.context.physics.removeBody(this)}};W([O(be)],zg.prototype,"attachedRigidbody",2),W([O()],zg.prototype,"isTrigger",2);var on=class extends zg{radius=.5;center=new R(0,0,0);onEnable(){super.onEnable(),this.context.physics.addSphereCollider(this,this.center,this.radius)}};W([O()],on.prototype,"radius",2),W([O(R)],on.prototype,"center",2);var nn=class extends zg{size=new R(1,1,1);center=new R(0,0,0);onEnable(){super.onEnable(),this.context.physics.addBoxCollider(this,this.center,this.size)}};W([O(R)],nn.prototype,"size",2),W([O(R)],nn.prototype,"center",2);var Rs=class extends zg{sharedMesh;convex=!1;onEnable(){super.onEnable(),this.sharedMesh?.isMesh||this.gameObject instanceof Fe&&(this.sharedMesh=this.gameObject),this.sharedMesh?.isMesh&&this.context.physics.addMeshCollider(this,this.sharedMesh,this.convex)}};W([O()],Rs.prototype,"convex",2);var jg=class extends zg{center=new R(0,0,0);radius=.5;height=2;onEnable(){super.onEnable(),this.context.physics.addCapsuleCollider(this,this.center,this.height,this.radius)}};W([O(R)],jg.prototype,"center",2),W([O()],jg.prototype,"radius",2),W([O()],jg.prototype,"height",2);var BC=class extends sA{center=new R(0,0,0);radius=.5;height=2;_rigidbody=null;get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(be),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(be)),this.rigidbody)}onEnable(){let A=this.rigidbody,e=this.gameObject.getComponent(jg);e||(e=this.gameObject.addNewComponent(jg)),e.center.copy(this.center),e.radius=this.radius,e.height=this.height,this.gameObject.rotation.x=0,this.gameObject.rotation.z=0,A.lockRotationX=!0,A.lockRotationY=!0,A.lockRotationZ=!0}move(A){this.gameObject.position.add(A)}_activeGroundCollisions=new Set;onCollisionEnter(A){for(let e of A.contacts)if(e.normal.y>.1){this._activeGroundCollisions.add(A);break}}onCollisionExit(A){this._activeGroundCollisions.delete(A)}get isGrounded(){return this._activeGroundCollisions.size>0}};W([O(R)],BC.prototype,"center",2),W([O()],BC.prototype,"radius",2),W([O()],BC.prototype,"height",2);var UI=class extends sA{controller;movementSpeed=2;rotationSpeed=2;jumpForce=1;animator;lookForward=!0;_currentSpeed=new R(0,0,0);_currentAngularSpeed=new R(0,0,0);_temp=new R(0,0,0);_jumpCount=0;_currentRotation;awake(){this._currentRotation=new vA}update(){this.controller?.isGrounded&&(this._jumpCount=0,this.animator?.SetBool("doubleJump",!1));let A=this.context.input.isKeyPressed("w"),e=this.context.input.isKeyPressed("s"),t=this.context.input.isKeyPressed("a"),i=this.context.input.isKeyPressed("d"),g=this.context.input.isKeyDown(" "),C=A?1:0+e?-1:0;this._currentSpeed.z+=C*this.movementSpeed*this.context.time.deltaTime,this.animator?.SetBool("running",C!=0),this.animator?.SetBool("jumping",this.controller?.isGrounded===!0&&g),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp);let o=t?1:0+i?-1:0;if(this._currentAngularSpeed.y+=ce.toRadians(o*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){let n=this.context.mainCameraComponent.forward;n.y=0,n.normalize(),this._currentRotation.setFromUnitVectors(new R(0,0,1),n),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&g&&this.jumpForce>0){let n=this.controller?.isGrounded;if(!this.controller?.isGrounded&&this._jumpCount===1&&(n=!0,this.animator?.SetBool("doubleJump",!0)),n){this._jumpCount+=1;let s=this.controller.rigidbody,r=this._jumpCount===2?2:1;s.applyImpulse(new R(0,1,0).multiplyScalar(this.jumpForce*r))}}if(this.controller){let n=this.controller?.rigidbody.getVelocity().y;if(n<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new qg),this._raycastOptions.ray.origin.copy(Ce(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);let s=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);let r=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(s),(r.length&&r[0].distance>2||n<-10)&&this.animator?.SetBool("falling",!0)}else this.animator?.SetBool("falling",!1)}}_raycastOptions=new Dt};W([O(BC)],UI.prototype,"controller",2),W([O()],UI.prototype,"movementSpeed",2),W([O()],UI.prototype,"rotationSpeed",2),W([O()],UI.prototype,"jumpForce",2),W([O(vi)],UI.prototype,"animator",2);var Zg=class extends sA{canGrab=!0;onPointerClick(A){}},Xg=class extends sA{isUsed=!0;usedBy=null};var Us=class extends ni{},Pa=class extends sA{deleteBoxes=[];awake(){this.deleteBoxes=iA.findObjectsOfType(Us,this.context)}update(){for(let A of this.deleteBoxes){let e=this.gameObject;A.isInBox(e)===!0&&(iA.getComponentInParent(this.gameObject,Xg)||hE(this.gameObject,this.context.connection))}}};var Fs=class extends sA{visibleOn;onEnable(){this.apply()}apply(){this.test()||iA.setActive(this.gameObject,!1)}test(){return this.visibleOn<0?!0:j1()?(this.visibleOn&2)!==0:(this.visibleOn&1)!==0}};W([O()],Fs.prototype,"visibleOn",2);var Kf;function j1(){if(Kf===!0||Kf===!1)return Kf;let I=!1;return function(A){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(A)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(A.substr(0,4)))&&(I=!0)}(navigator.userAgent||navigator.vendor||window.opera),Kf=I,I}var Yt=class{bb=null;bb_pos=0;__init(A,e){return this.bb_pos=A,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}static sizeOf(){return 12}static createVec3(A,e,t,i){return A.prep(4,12),A.writeFloat32(i),A.writeFloat32(t),A.writeFloat32(e),A.offset()}};var _E=class{bb=null;bb_pos=0;__init(A,e){return this.bb_pos=A,this.bb=e,this}position(A){return(A||new Yt).__init(this.bb_pos,this.bb)}rotation(A){return(A||new Yt).__init(this.bb_pos+12,this.bb)}scale(A){return(A||new Yt).__init(this.bb_pos+24,this.bb)}static sizeOf(){return 36}static createTransform(A,e,t,i,g,C,o,n,s,r){return A.prep(4,36),A.prep(4,12),A.writeFloat32(r),A.writeFloat32(s),A.writeFloat32(n),A.prep(4,12),A.writeFloat32(o),A.writeFloat32(C),A.writeFloat32(g),A.prep(4,12),A.writeFloat32(i),A.writeFloat32(t),A.writeFloat32(e),A.offset()}};var FI=class{bb=null;bb_pos=0;__init(A,e){return this.bb_pos=A,this.bb=e,this}static getRootAsSyncedTransformModel(A,e){return(e||new FI).__init(A.readInt32(A.position())+A.position(),A)}static getSizePrefixedRootAsSyncedTransformModel(A,e){return A.setPosition(A.position()+4),(e||new FI).__init(A.readInt32(A.position())+A.position(),A)}guid(A){let e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,A):null}fast(){let A=this.bb.__offset(this.bb_pos,6);return A?!!this.bb.readInt8(this.bb_pos+A):!1}transform(A){let e=this.bb.__offset(this.bb_pos,8);return e?(A||new _E).__init(this.bb_pos+e,this.bb):null}dontSave(){let A=this.bb.__offset(this.bb_pos,10);return A?!!this.bb.readInt8(this.bb_pos+A):!1}static startSyncedTransformModel(A){A.startObject(4)}static addGuid(A,e){A.addFieldOffset(0,e,0)}static addFast(A,e){A.addFieldInt8(1,+e,0)}static addTransform(A,e){A.addFieldStruct(2,e,0)}static addDontSave(A,e){A.addFieldInt8(3,+e,0)}static endSyncedTransformModel(A){return A.endObject()}static finishSyncedTransformModelBuffer(A,e){A.finish(e)}static finishSizePrefixedSyncedTransformModelBuffer(A,e){A.finish(e,void 0,!0)}};var Ns=cA("debugsync"),OE="STRS";xE(OE,FI.getRootAsSyncedTransformModel);var jC=new _g;function ek(I,A,e=!0){jC.clear();let t=jC.createString(I);FI.startSyncedTransformModel(jC),FI.addGuid(jC,t),FI.addFast(jC,e);let i=A.worldPosition,g=A.worldEuler,C=A.gameObject.scale;FI.addTransform(jC,_E.createTransform(jC,i.x,i.y,i.z,g.x,g.y,g.z,C.x,C.y,C.z));let o=FI.endSyncedTransformModel(jC);return jC.finish(o,OE),jC.asUint8Array()}var pg=class extends sA{overridePhysics=!0;interpolatePosition=!0;interpolateRotation=!0;fastMode=!1;syncDestroy=!1;_model=null;_needsUpdate=!0;rb=null;_wasKinematic=!1;_receivedDataBefore=!1;_targetPosition;_targetRotation;_receivedFastUpdate=!1;_shouldRequestOwnership=!1;requestOwnership(){Ns&&console.log("Request ownership"),this._model?this._model.requestOwnership():(this._shouldRequestOwnership=!0,this._needsUpdate=!0)}hasOwnership(){return this._model?.hasOwnership??void 0}isOwned(){return this._model?.isOwned}joinedRoomCallback=null;receivedDataCallback=null;awake(){Ns&&console.log("new instance",this.guid,this),this._receivedDataBefore=!1,this._targetPosition=new R,this._targetRotation=new vA,this.lastWorldPos=new R,this.lastWorldRotation=new vA,this.rb=iA.getComponentInChildren(this.gameObject,be),this.rb&&(this._wasKinematic=this.rb.isKinematic),this.receivedUpdate=!0,this._model=new ws(this.context.connection,this.guid),this.context.connection.isConnected&&this.tryGetLastState(),this.joinedRoomCallback=this.tryGetLastState.bind(this),this.context.connection.beginListen("joined-room",this.joinedRoomCallback),this.receivedDataCallback=this.onReceivedData.bind(this),this.context.connection.beginListenBinrary(OE,this.receivedDataCallback)}onDestroy(){this.syncDestroy&&Rq(this.guid,this.context.connection),this._model=null,this.context.connection.stopListening("joined-room",this.joinedRoomCallback),this.context.connection.stopListenBinary(OE,this.receivedDataCallback)}tryGetLastState(){let A=this.context.connection.tryGetState(this.guid);A&&this.onReceivedData(A)}tempEuler=new Ye;onReceivedData(A){if(!this.destroyed&&typeof A.guid=="function"&&A.guid()===this.guid){Ns&&console.log("new data",this.context.connection.connectionId,this.context.time.frameCount,this.guid,A),this.receivedUpdate=!0,this._receivedFastUpdate=A.fast();let e=A.transform();if(e){tt.markDirty(this.gameObject,!0);let t=e.position();t&&(this.interpolatePosition&&this._targetPosition?.set(t.x(),t.y(),t.z()),(!this.interpolatePosition||!this._receivedDataBefore)&&this.setWorldPosition(t.x(),t.y(),t.z()));let i=e.rotation();i&&(this.tempEuler.set(i.x(),i.y(),i.z()),this.interpolateRotation&&this._targetRotation.setFromEuler(this.tempEuler),(!this.interpolateRotation||!this._receivedDataBefore)&&Dq(this.gameObject,this.tempEuler))}this._receivedDataBefore=!0}}onEnable(){this.lastWorldPos.copy(this.worldPosition),this.lastWorldRotation.copy(this.worldQuaternion),this._needsUpdate=!0,this._model&&this._model.updateIsOwned()}onDisable(){this._model&&this._model.freeOwnership()}receivedUpdate=!1;lastWorldPos;lastWorldRotation;onBeforeRender(){if(!this.activeAndEnabled||!this.context.connection.isConnected)return;if(!this.context.connection.isInRoom||!this._model){Ns&&console.log("no model or room",this.name,this.guid,this.context.connection.isInRoom);return}this._shouldRequestOwnership&&(this._shouldRequestOwnership=!1,this._model.requestOwnership());let A=this.worldPosition,e=this.worldQuaternion;if(this._model.isOwned&&!this.receivedUpdate){let g=A.distanceTo(this.lastWorldPos),C=e.angleTo(this.lastWorldRotation),o=this._model.hasOwnership||this.fastMode?1e-4:.001;(g>o||C>o)&&(this._model.hasOwnership?this._needsUpdate=!0:(Ns&&console.log(this.guid,"reset because not owned but",this.gameObject.name,this.lastWorldPos),this.worldPosition=this.lastWorldPos,A.copy(this.lastWorldPos),this.worldQuaternion=this.lastWorldRotation,e.copy(this.lastWorldRotation),tt.markDirty(this.gameObject,!0),this._needsUpdate=!1))}if(this._model&&!this._model.hasOwnership&&this._model.isOwned&&this._receivedDataBefore){let C=this._receivedFastUpdate||this.fastMode?.5:.3,o=!1;if(this.interpolatePosition&&this._targetPosition){let n=this.worldPosition;n.lerp(this._targetPosition,C),this.worldPosition=n,o=!0}if(this.interpolateRotation&&this._targetRotation){let n=this.worldQuaternion;n.slerp(this._targetRotation,C),this.worldQuaternion=n,o=!0}o&&tt.markDirty(this.gameObject,!0)}if(this.receivedUpdate=!1,this.lastWorldPos.copy(A),this.lastWorldRotation.copy(e),!this._model)return;if(!this._model||this._model.hasOwnership===void 0||!this._model.hasOwnership){this.rb&&(this.rb.isKinematic=this._model.isOwned??!1,this.rb.setVelocity(0,0,0),this.rb.setBodyFromGameObject());return}this.rb&&(this._wasKinematic!==void 0&&(Ns&&console.log("reset kinematic",this.rb.name,this._wasKinematic),this.rb.isKinematic=this._wasKinematic),this.gameObject.position.distanceTo(new R(0,0,0))>1e3&&(Ns&&console.log("RESET",this.name),this.gameObject.position.set(0,1,0),this.rb.setVelocity(0,0,0),this.rb.setBodyFromGameObject()));let t=10,i=this.rb||this.fastMode;if(this._needsUpdate&&(t<=0||t>0&&this.context.time.frameCount%t===0||i)){Ns&&console.log("send update",this.context.connection.connectionId,this.guid,this.gameObject.name,this.gameObject.guid),this.overridePhysics&&this.rb&&this.rb.setBodyFromGameObject(),this._needsUpdate=!1;let g=ek(this.guid,this,!!i);this.context.connection.sendBinary(g)}}};var Jf=class{static createButton(A,e={}){let t=document.createElement("button");function i(){if(e.domOverlay===void 0){var n=document.createElement("div");n.style.display="none",document.body.appendChild(n);var s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.setAttribute("width",38),s.setAttribute("height",38),s.style.position="absolute",s.style.right="20px",s.style.top="20px",s.addEventListener("click",function(){a.end()}),n.appendChild(s);var r=document.createElementNS("http://www.w3.org/2000/svg","path");r.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),r.setAttribute("stroke","#fff"),r.setAttribute("stroke-width",2),s.appendChild(r),e.optionalFeatures===void 0&&(e.optionalFeatures=[]),e.optionalFeatures.push("dom-overlay"),e.domOverlay={root:n}}e.optionalFeatures===void 0&&(e.optionalFeatures=[]),e.optionalFeatures.push("local-floor"),e.optionalFeatures.push("hand-tracking"),e.optionalFeatures.push("layers");let a=null;async function B(h){h.addEventListener("end",Q),await A.xr.setSession(h),t.textContent="STOP AR",e.domOverlay.root.style.display="",a=h}function Q(){a.removeEventListener("end",Q),t.textContent="START AR",e.domOverlay.root.style.display="none",a=null}t.style.display="",t.style.cursor="pointer",t.style.left="calc(50% - 50px)",t.style.width="100px",t.textContent="START AR",t.onmouseenter=function(){t.style.opacity="1.0"},t.onmouseleave=function(){t.style.opacity="0.5"},t.onclick=function(){a===null?navigator.xr.requestSession("immersive-ar",e).then(B):a.end()}}function g(){t.disabled=!0,t.style.display="",t.style.cursor="auto",t.style.left="calc(50% - 75px)",t.style.width="150px",t.onmouseenter=null,t.onmouseleave=null,t.onclick=null}function C(){g(),t.textContent="AR NOT SUPPORTED"}function o(n){n.style.position="absolute",n.style.bottom="20px",n.style.padding="12px 6px",n.style.border="1px solid #fff",n.style.borderRadius="4px",n.style.background="rgba(0,0,0,0.1)",n.style.color="#fff",n.style.font="normal 13px sans-serif",n.style.textAlign="center",n.style.opacity="0.5",n.style.outline="none",n.style.zIndex="999"}if("xr"in navigator)return t.id="ARButton",t.style.display="none",o(t),navigator.xr.isSessionSupported("immersive-ar").then(function(n){n?i():C()}).catch(C),t;{let n=document.createElement("a");return window.isSecureContext===!1?(n.href=document.location.href.replace(/^http:/,"https:"),n.innerHTML="WEBXR NEEDS HTTPS"):(n.href="https://immersiveweb.dev/",n.innerHTML="WEBXR NOT AVAILABLE"),n.style.left="calc(50% - 90px)",n.style.width="180px",n.style.textDecoration="none",o(n),n}}};var qf=class{static createButton(A,e){e&&console.error('THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.');let t=document.createElement("button");function i(){let n=null;async function s(a){a.addEventListener("end",r),await A.xr.setSession(a),t.textContent="EXIT VR",n=a}function r(){n.removeEventListener("end",r),t.textContent="ENTER VR",n=null}t.style.display="",t.style.cursor="pointer",t.style.left="calc(50% - 50px)",t.style.width="100px",t.textContent="ENTER VR",t.onmouseenter=function(){t.style.opacity="1.0"},t.onmouseleave=function(){t.style.opacity="0.5"},t.onclick=function(){if(n===null){let a={optionalFeatures:["local-floor","bounded-floor","hand-tracking","high-fixed-foveation-level","layers"]};navigator.xr.requestSession("immersive-vr",a).then(s)}else n.end()}}function g(){t.disabled=!0,t.style.display="",t.style.cursor="auto",t.style.left="calc(50% - 75px)",t.style.width="150px",t.onmouseenter=null,t.onmouseleave=null,t.onclick=null}function C(){g(),t.textContent="VR NOT SUPPORTED"}function o(n){n.style.position="absolute",n.style.bottom="20px",n.style.padding="12px 6px",n.style.border="1px solid #fff",n.style.borderRadius="4px",n.style.background="rgba(0,0,0,0.1)",n.style.color="#fff",n.style.font="normal 13px sans-serif",n.style.textAlign="center",n.style.opacity="0.5",n.style.outline="none",n.style.zIndex="999"}if("xr"in navigator)return t.id="VRButton",t.style.display="none",o(t),navigator.xr.isSessionSupported("immersive-vr").then(function(n){n?i():C(),qf.xrSessionIsGranted&&(console.log("XR session is granted - will enter immersive web now"),t.click())}),t;{let n=document.createElement("a");return window.isSecureContext===!1?(n.href=document.location.href.replace(/^http:/,"https:"),n.innerHTML="WEBXR NEEDS HTTPS"):(n.href="https://immersiveweb.dev/",n.innerHTML="WEBXR NOT AVAILABLE"),n.style.left="calc(50% - 90px)",n.style.width="180px",n.style.textDecoration="none",o(n),n}}static registerSessionGrantedListener(){if("xr"in navigator)try{navigator.xr.addEventListener("sessiongranted",()=>{console.log("Received session granted event"),qf.xrSessionIsGranted=!0})}catch(A){console.error(A)}}},WE=qf;mA(WE,"xrSessionIsGranted",!1);WE.registerSessionGrantedListener();var $L=Gr(of(),1);var VE="noVoip",Dg=cA("debugvoip"),z1=cA("voip");var tk=class{id;constructor(A){this.id=A}};var ik=class{peer;voip;userId;peerId;call=null;callErrorListener=null;stream=null;constructor(A,e,t,i){this.voip=A,this.peer=e,this.userId=t,this.peerId=i}close(){Dg&&console.log("close voip call"),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.open&&this.call.close(),this.stream?.getTracks().forEach(function(A){A.stop()})}updateMute(A){if(!this.stream)return;let e=this.stream?.getAudioTracks();for(let t of e)t.enabled=!A}async startVoipCall(){if(!await Ti.HasMicrophonePermissions()){console.warn("no permission to use microphone, can not start call");return}Dg&&console.log("start voip call"),this.stream=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),this.updateMute(this.voip.muteOutput),Dg&&console.log(this.stream),this.call=this.peer.call(this.peerId,this.stream,{metadata:{userId:this.userId}}),this.call.on("error",e=>{console.error(e)}),this.call.on("stream",e=>{Dg&&console.log("received stream from remote again",e)}),this.peer.on("close",this.onCallClose.bind(this)),this.callErrorListener=e=>{e.message.includes(this.peerId)?(console.log("Could not connect to "+this.peerId),this.callErrorListener&&this.peer.off("error",this.callErrorListener),this.call&&this.call.close(),this.stream?.getTracks().forEach(function(t){t.stop()}),this.stream=null):console.error(e)},this.peer.on("error",this.callErrorListener)}onCallClose(A){Dg&&console.log("call closed",A)}},gk=class{get currentStream(){return this.stream}get currentAudio(){return this.audio}get currentAnalyzer(){return this.analyzer}voip;call;audio=null;stream=null;obj;analyzer=null;waitingForStart=!1;closed=!1;audioElement=null;constructor(A,e,t){this.voip=A,this.obj=e,this.call=t}openAudioStream(A){let e=A.getAudioTracks();for(let t of e)if(t.kind==="audio"&&t.readyState==="live"){this.open(t);return}console.warn("failed finding valid audio stream to begin call")}open(A){console.assert(A.kind==="audio","invalid track kind, expected audio but received "+A.kind),!this.waitingForStart&&(this.waitingForStart=!0,Xe.userInteractionRegistered||Dg&&console.log("Incoming call, waiting for user interaction before opening audio"),Xe.registerWaitForAllowAudio(async()=>{if(this.call.open&&!this.closed){Dg&&console.log("Setup audio and begin listening"),this.stream=new MediaStream([A]);let e=new Qa;this.audio=new as(e),this.audio.setVolume(this.voip.muteInput?0:1),this.audio.setMediaStreamSource(this.stream);let t=document.createElement("audio");this.audioElement=t,t.style.display="none",document.body.appendChild(t),t.srcObject=this.stream,t.sinkId!==void 0&&navigator.mediaDevices.enumerateDevices().then(i=>{if(!!t){console.log(i);for(let g of i)if(g.label==="Speakerphone"){t.sinkId=g.deviceId;break}}}),Dg&&console.log("call is setup, you should hear something now"),this.analyzer=new zh(this.audio,32)}}))}close(){this.closed=!0,this.call?.open&&this.call.close(),this.audio?.disconnect(),this.stream?.getTracks().forEach(A=>{A.stop()}),this.stream=null,this.audioElement&&this.audioElement.remove()}},Ti=class extends sA{requireParam=!1;set muteInput(A){if(A===this._inputMuted||(this._inputMuted=A,!this.currentIncomingCalls))return;let e=this._inputMuted?0:1;for(let t in this.currentIncomingCalls)this.currentIncomingCalls[t]?.currentAudio?.setVolume(e)}get muteInput(){return this._inputMuted}set muteOutput(A){if(A!==this._outputMuted&&(this._outputMuted=A,!!this.connections))for(let e in this.connections)this.connections[e]?.updateMute(A)}get muteOutput(){return this._outputMuted}getFrequency(A){if(A===null){for(let t in this.currentIncomingCalls){let i=this.currentIncomingCalls[t];if(i&&i.currentAnalyzer)return i.currentAnalyzer.getAverageFrequency()}return null}let e=this.currentIncomingCalls[A];return e&&e.currentAnalyzer?e.currentAnalyzer.getAverageFrequency():null}peer=null;model=null;connections={};currentIncomingCalls={};_inputMuted=!1;_outputMuted=!1;awake(){if(cA(VE)){console.log("VOIP is disabled by url parameter: "+VE);return}if(this.requireParam&&!z1){console.debug("VOIP must be enabled explicitly by url parameter");return}this.peer=new $L.default,navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.context.connection.beginListen("joined-room",A=>{navigator.mediaDevices.getUserMedia({audio:!0,video:!1})}),this.context.connection.beginListen("peer-update-id",A=>{if(A.id!==this.context.connection.connectionId){let e=this.connections[A.id];if(e&&e.close(),this.peer&&this.context.connection.connectionId){let t=new ik(this,this.peer,this.context.connection.connectionId,A.peerId);this.connections[A.id]=t,t.startVoipCall()}}}),this.context.connection.beginListen("user-left-room",A=>{let{userId:e}=A,t=this.connections[e];this.connections[e]=null,t&&t.close();let i=this.currentIncomingCalls[e];Dg&&console.log("UserLeftRoom",A,e,i),i&&(i.close(),this.currentIncomingCalls[e]=null)}),this.peer.on("open",this.onOpenPeerConnection.bind(this))}onEnable(){}onDisable(){console.log("TODO: close all");for(let A in this.currentIncomingCalls)this.currentIncomingCalls[A]?.close(),this.connections[A]?.close()}async onOpenPeerConnection(A){Dg&&console.log("Peer connection established and received id"),this.model=new tk(A),this.context.connection.send("peer-update-id",this.model,1),this.peer&&(this.peer.on("call",this.onReceiveCall.bind(this)),this.peer.on("connection",function(e){Dg&&console.log("CONNECTION",e),e.on("data",function(t){Dg&&console.log("Received",t)})}))}async onReceiveCall(A){let{metadata:e}=A;console.assert(e.userId);let{userId:t}=e,{peer:i}=A,g=this.currentIncomingCalls[t];if(g&&g.close(),Dg&&console.log("received call"),await Ti.HasMicrophonePermissions()){let C=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1});A.answer(C)}else A.answer(null);this.currentIncomingCalls[t]=new gk(this,this.gameObject,A),A.on("stream",C=>{Dg&&console.log("receive caller stream, will setup audio now"),this.currentIncomingCalls[t]?.openAudioStream(C)}),A.on("error",console.error)}static async HasMicrophonePermissions(){return(await navigator.permissions.query({name:"microphone"})).state!=="denied"}};var $g=class extends sA{webAR=null;get rig(){return this.webAR?.webxr.Rig}invertForward=!1;get arScale(){return this._arScale}set arScale(A){A!==this._arScale&&(this._arScale=A,this.setScale(A))}_initalMatrix=new te;_selectStartFn=this.onSelectStart.bind(this);_selectEndFn=this.onSelectEnd.bind(this);start(){let A=iA.findObjectOfType(le);A&&(A.Rig.updateMatrix(),this._initalMatrix.copy(A.Rig.matrix))}_arScale=5;_rig=null;_startPose=null;_placementPose=null;_isTouching=!1;_rigStartPose=null;onBegin(A){this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose=this.gameObject.matrix.clone(),this._rigStartPose=this.rig?.matrix.clone(),A.addEventListener("selectstart",this._selectStartFn),A.addEventListener("selectend",this._selectEndFn),this.gameObject.visible=!1,this.rig&&(this.rig.matrixAutoUpdate=!0,this._initalMatrix.decompose(this.rig.position,this.rig.quaternion,this.rig.scale))}onUpdate(A,e,t){return t&&!this._placementPose&&this._isTouching?(this.webAR&&this.webAR.setReticleActive(!1),this.placeAt(A,new te().fromArray(t.transform.matrix).invert()),!0):!1}placeAt(A,e){if(this._placementPose||(this._placementPose=new te),this._placementPose.copy(e),A){if(this.invertForward){let t=new te().makeRotationY(Math.PI);this._placementPose.premultiply(t)}this._rig=A,this.setScale(this.arScale)}else this._rig=null;this.gameObject.visible=!0}onEnd(A,e){this._placementPose=null,this.gameObject.visible=!1,this.gameObject.matrixAutoUpdate=!1,this._startPose&&this.gameObject.matrix.copy(this._startPose),A&&(A.matrixAutoUpdate=!0,this._rigStartPose&&this._rigStartPose.decompose(A.position,A.quaternion,A.scale)),tt.markDirty(this.gameObject,!0),setTimeout(()=>{this.gameObject.matrixAutoUpdate=!0,this.gameObject.visible=!0},100)}onSelectStart(){this._isTouching=!0}onSelectEnd(){this._isTouching=!1}setScale(A){let e=this._rig;!e||!this._placementPose||(this._rigStartPose||(this._rigStartPose=e.matrix.clone()),e.matrixAutoUpdate=!1,e.matrix.multiplyMatrices(new te().makeScale(A,A,A),this._placementPose),e.matrix.decompose(e.position,e.quaternion,e.scale),e.updateMatrixWorld(),console.log("Place",e.position))}};W([O()],$g.prototype,"invertForward",2),W([O()],$g.prototype,"arScale",1);import{OculusHandModel as q4}from"three/examples/jsm/webxr/OculusHandModel.js";import{OculusHandPointerModel as L4}from"three/examples/jsm/webxr/OculusHandPointerModel.js";import{XRControllerModelFactory as b4}from"three/examples/jsm/webxr/XRControllerModelFactory.js";import{GLTFLoader as x4}from"three/examples/jsm/loaders/GLTFLoader.js";var jE=cA("debugflags");var Ik=class{Mask=17;Has(A){let e=this.Mask&A;return jE&&console.log("HAS",A,this.Mask,"Result="+e),e!==0}Set(A){this.Mask=A,Rt.Apply()}Enable(A){this.Mask|=A,Rt.Apply()}Disable(A){this.Mask&=~A,Rt.Apply()}Toggle(A){this.Mask^=A,Rt.Apply()}EnableAll(){this.Mask=-1,Rt.Apply()}DisableAll(){this.Mask=0,Rt.Apply()}},fg=Ik;mA(fg,"Global",new Ik);var zC=class extends sA{static Apply(){for(let A of this.registry)A.UpdateVisible(fg.Global)}awake(){zC.registry.push(this)}onEnable(){zC.firstApply||(zC.firstApply=!0,zC.Apply())}onDestroy(){let A=zC.registry.indexOf(this);A>=0&&zC.registry.splice(A,1)}visibleIn;get isOn(){return this.gameObject.visible}UpdateVisible(A=null){if(!this.enabled)return;let e,t=A;t&&typeof t=="number"&&(console.assert(typeof t=="number","XRFlag.UpdateVisible: state must be a number",t),jE&&console.log(t),zC.buffer.Mask=t,A=zC.buffer);let i=A;if(i?(jE&&console.log("use passed in mask"),e=i.Has(this.visibleIn)):(jE&&console.log("use global mask"),fg.Global.Has(this.visibleIn)),e!==void 0)if(e)jE&&console.trace("is visible",this.name,this.gameObject.uuid),iA.setActive(this.gameObject,!0);else{if(jE&&console.trace("is not visible",this.name,this.gameObject.uuid),!this.gameObject.visible)return;this.gameObject.visible=!1}}},Rt=zC;mA(Rt,"registry",[]),mA(Rt,"firstApply"),mA(Rt,"buffer",new fg);var Ks=cA("debugavatar"),QC=class extends sA{static getAvatar(A){return A>=0&&A<QC.instances.length?QC.instances[A]:null}static onAvatarMarkerCreated(A){return QC._onNewAvatarMarkerAdded.push(A),A}static onAvatarMarkerDestroyed(A){return QC._onAvatarMarkerDestroyed.push(A),A}connectionId;avatar;awake(){QC.instances.push(this),Ks&&console.log(this);for(let A of QC._onNewAvatarMarkerAdded)A({avatarMarker:this,gameObject:this.gameObject})}onDestroy(){QC.instances.splice(QC.instances.indexOf(this),1);for(let A of QC._onAvatarMarkerDestroyed)A({avatarMarker:this,gameObject:this.gameObject})}isLocalAvatar(){return this.connectionId===this.context.connection.connectionId}setVisible(A){this.avatar&&("setVisible"in this.avatar?this.avatar.setVisible(A):iA.setActive(this.avatar,A))}},it=QC;mA(it,"instances",[]),mA(it,"_onNewAvatarMarkerAdded",[]),mA(it,"_onAvatarMarkerDestroyed",[]);var Vl=class{_isVisible=!0;setVisible(A){this._isVisible=A,this.updateVisibility()}get isWebXRAvatar(){return!0}guid;root=null;head=null;handLeft=null;handRight=null;lastUpdate=-1;isLocalAvatar=!1;flags=null;headScale=new R(1,1,1);handLeftScale=new R(1,1,1);handRightScale=new R(1,1,1);webxr;lastAvatarId=null;hasAvatarOverride=!1;context;avatarMarker=null;constructor(A,e,t){this.context=A,this.guid=e,this.webxr=t,this.setupCustomAvatar(this.webxr.defaultAvatar)}updateFlags(){if(!this.flags)return;let A=this.isLocalAvatar?8:16;for(let e of this.flags)e.gameObject.visible=!0,e.UpdateVisible(A)}async setAvatarOverride(A){return this.hasAvatarOverride=A!==null,this.hasAvatarOverride&&this.lastAvatarId!==A&&(this.lastAvatarId=A,A!=null&&A.length>0)?await this.setupCustomAvatar(A):null}_headTarget=new qA;_handLeftTarget=new qA;_handRightTarget=new qA;_canInterpolate=!1;tryUpdate(A,e){if(A.guid===this.guid&&(this.lastAvatarId!==A.avatarId&&A.avatarId&&A.avatarId.length>0&&(this.lastAvatarId=A.avatarId,this.setupCustomAvatar(A.avatarId)),this.lastUpdate=A.time,this.head)){let t=this.webxr.IsInAR?"handheld":"headset",i=this.head;this.context.players.setPlayerView(A.guid,i,t),tt.markDirty(this.head),this._canInterpolate=!0;let g=this.isLocalAvatar?this.head:this._headTarget;if(g.position.set(A.position.x,A.position.y,A.position.z),g.quaternion.set(A.rotation.x,A.rotation.y,A.rotation.z,A.rotation.w),g.scale.set(A.scale,A.scale,A.scale),g.scale.multiply(this.headScale),this.handLeft){let C=this.isLocalAvatar?this.handLeft:this._handLeftTarget;C.position.set(A.posLeftHand.x,A.posLeftHand.y,A.posLeftHand.z),C.quaternion.set(A.rotLeftHand._x,A.rotLeftHand._y,A.rotLeftHand._z,A.rotLeftHand._w),C.quaternion.multiply(Vl.invertRotation),C.scale.set(A.scale,A.scale,A.scale),C.scale.multiply(this.handLeftScale),tt.markDirty(this.handLeft)}if(this.handRight){let C=this.isLocalAvatar?this.handRight:this._handRightTarget;C.position.set(A.posRightHand.x,A.posRightHand.y,A.posRightHand.z),C.quaternion.set(A.rotRightHand._x,A.rotRightHand._y,A.rotRightHand._z,A.rotRightHand._w),C.quaternion.multiply(Vl.invertRotation),C.scale.set(A.scale,A.scale,A.scale),C.scale.multiply(this.handRightScale),tt.markDirty(this.handRight)}}}update(){if(this.isLocalAvatar||!this._canInterpolate)return;let A=this.context.time.deltaTime/.1;this.head&&(this.head.position.lerp(this._headTarget.position,A),this.head.quaternion.slerp(this._headTarget.quaternion,A),this.head.scale.lerp(this._headTarget.scale,A)),this.handLeft&&this._handLeftTarget&&(this.handLeft.position.lerp(this._handLeftTarget.position,A),this.handLeft.quaternion.slerp(this._handLeftTarget.quaternion,A),this.handLeft.scale.lerp(this._handLeftTarget.scale,A)),this.handRight&&this._handRightTarget&&(this.handRight.position.lerp(this._handRightTarget.position,A),this.handRight.quaternion.slerp(this._handRightTarget.quaternion,A),this.handRight.scale.lerp(this._handRightTarget.scale,A))}destroy(){Ks&&console.log("Destroy avatar",this.guid),this.root?.removeFromParent(),this.avatarMarker?.destroy(),this.lastAvatarId=null,this.head&&wt.Remove(this.context,this.head)}updateVisibility(){let A=this.root;A&&iA.setActive(A,this._isVisible)}async setupCustomAvatar(A){if(Ks&&console.log("LOAD",A,this),!A||typeof A=="string"&&A.length<=0)return!1;this.head&&wt.Remove(this.context,this.head);let e=A;if(e?.loadAssetAsync!==void 0){await e.loadAssetAsync();let i=e.asset;iA.setActive(i,!1),A=iA.instantiate(i),iA.setActive(A,!0)}Ks&&console.log(A);let t=await Vl.loader.getOrCreateNewAvatarInstance(this.context,A);if(Ks&&console.log(t,t?.isValid,this.lastAvatarId,A),t?.isValid){if(this.root=t.root,this.root.position.set(0,0,0),this.root.quaternion.set(0,0,0,1),this.root.scale.set(1,1,1),this.avatarMarker=iA.addNewComponent(this.root,it),this.avatarMarker.connectionId=this.guid,this.avatarMarker.avatar=this,this.head&&this.head!==t.head&&this.head?.removeFromParent(),this.head=t.head,this.headScale.copy(this.head.scale),this.head&&!this.isLocalAvatar&&wt.Add(this.context,this.head,this.avatarMarker),t.leftHand&&this.handLeft?.removeFromParent(),this.handLeft=t.leftHand??this.handLeft,this.handLeft?this.handLeftScale.copy(this.handLeft.scale):this.handLeftScale.set(1,1,1),t.rigthHand&&this.handRight?.removeFromParent(),this.handRight=t.rigthHand??this.handRight,this.handRight?this.handRightScale.copy(this.handRight.scale):this.handRightScale.set(1,1,1),this.context.scene.add(this.root),this.flags==null&&(this.flags=[]),this.flags.length=0,this.flags.push(...iA.getComponentsInChildren(this.root,Rt)),this.flags.length<=0&&this.head){let i=iA.addNewComponent(this.head,Rt);i.visibleIn=20,this.flags.push(i),Ks&&console.log("Added flag to head: "+i.visibleIn,this.head.name)}return Ks&&console.log("[Avatar], is Local? ",this.isLocalAvatar,this.root),this.updateFlags(),this.updateVisibility(),!0}else return Ks&&console.warn("build avatar failed"),!1}},AI=Vl;mA(AI,"loader",new Cn),mA(AI,"invertRotation",new vA().setFromAxisAngle(new R(0,1,0),Math.PI));var wt=class{static Add(A,e,t=null){if(!!e){for(let i of this.Pois)if(i.obj===e)return;this.Pois.push({obj:e,avatar:t}),this.LastChangeTime=A.time.time}}static Remove(A,e){if(!!e){for(let t of this.Pois)if(t.obj===e){this.Pois.splice(this.Pois.indexOf(t),1),this.LastChangeTime=A?.time.time??ue.Current?.time.time;return}}}};mA(wt,"Pois",[]),mA(wt,"LastChangeTime",0);var Ck=class{guid;position=new R},ZC=class extends sA{set controlledTarget(A){this.target=A;let e=hA.get("MoveRandom");if(e&&this.target){let t=iA.getComponent(this.target,e);t&&t.destroy()}}target=null;avatar=null;_model=null;_targetModel=new Ck;_currentTargetObject=null;_lastUpdateTime=0;_lookDuration=0;_lastPoiChangedTime=0;awake(){if(this.avatar=iA.getComponentInParent(this.gameObject,it),this.avatar){let A=iA.getComponentInParent(this.gameObject,it);this._model=new ws(this.context.connection,this.guid),A?.isLocalAvatar&&this._model.requestOwnership()}this.context.connection.beginListen("avatar-look-target-changed",A=>{this.target&&A&&A.guid===this.avatar?.guid&&Ze(this.target,A.position)})}update(){if((!this.context.connection.isConnected||this._model?.hasOwnership)&&(wt.LastChangeTime!==this._lastPoiChangedTime&&(this._lastPoiChangedTime=wt.LastChangeTime,this._lookDuration=0),this.selectTarget(),this._currentTargetObject&&this.context.time.frameCount%10===0&&this.target)){let e=Ce(this._currentTargetObject);Ze(this.target,e),this.context.connection.isConnected&&this.avatar&&(this.context.connection.send("avatar-look-target-changed",this._targetModel),this._targetModel.guid=this.avatar.guid,this._targetModel.position.copy(e))}}selectTarget(){if(this.context.time.time-this._lastUpdateTime>this._lookDuration){this._lastUpdateTime=this.context.time.time,this._lookDuration=Math.random()*.5+.2;let e=wt.Pois;if(e.length>0){let t=e[Math.floor(Math.random()*e.length)];if(t&&t.obj){if(t.avatar&&t.avatar===this.avatar)return;this._currentTargetObject=t.obj}}}}};var $E={};Cu($E,{AlignItems:()=>y4,Block:()=>Ad,ContentDirection:()=>m4,FontLibrary:()=>G4,InlineBlock:()=>M4,JustifyContent:()=>k4,Keyboard:()=>mk,Text:()=>Gk,TextAlign:()=>R4,Whitespace:()=>U4,default:()=>F4,update:()=>Mk});var mi={};mi.d=(I,A)=>{for(var e in A)mi.o(A,e)&&!mi.o(I,e)&&Object.defineProperty(I,e,{enumerable:!0,get:A[e]})};mi.o=(I,A)=>Object.prototype.hasOwnProperty.call(I,A);mi.r=I=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(I,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(I,"__esModule",{value:!0})};var eI={};mi.d(eI,{g1:()=>Of,gO:()=>Wa,km:()=>_f,zV:()=>zl,ol:()=>Xl,uM:()=>Pf,N1:()=>Yf,xv:()=>Zl,PH:()=>Vf,UH:()=>Wf,ZP:()=>S4,Vx:()=>mb});var _f={};mi.r(_f);mi.d(_f,{COLUMN:()=>jf,COLUMN_REVERSE:()=>Cb,ROW:()=>jl,ROW_REVERSE:()=>Ib,contentDirection:()=>ob});var Of={};mi.r(Of);mi.d(Of,{CENTER:()=>Qk,END:()=>Ek,START:()=>Bk,STRETCH:()=>nb,alignItems:()=>sb,warnAboutDeprecatedAlignItems:()=>rb});var Pf={};mi.r(Pf);mi.d(Pf,{CENTER:()=>hk,END:()=>lk,SPACE_AROUND:()=>dk,SPACE_BETWEEN:()=>uk,SPACE_EVENLY:()=>pk,START:()=>ck,justifyContent:()=>ab});var Wf={};mi.r(Wf);mi.d(Wf,{NORMAL:()=>$l,NOWRAP:()=>ZE,PRE:()=>zf,PRE_LINE:()=>XE,PRE_WRAP:()=>Zf,WHITE_CHARS:()=>nk,collapseWhitespaceOnInlines:()=>cb,collapseWhitespaceOnString:()=>Bb,newlineBreakability:()=>Qb,shouldBreak:()=>Eb});var Vf={};mi.r(Vf);mi.d(Vf,{CENTER:()=>fk,JUSTIFY:()=>wk,JUSTIFY_CENTER:()=>pb,JUSTIFY_LEFT:()=>ub,JUSTIFY_RIGHT:()=>Tf,LEFT:()=>lb,RIGHT:()=>db,textAlign:()=>Db});var Z1=I=>{var A={};return mi.d(A,I),A};var Ke=Z1({BufferAttribute:()=>Ge,BufferGeometry:()=>Qe,CanvasTexture:()=>Jh,Color:()=>P,FileLoader:()=>pi,LinearFilter:()=>Bt,Mesh:()=>Fe,Object3D:()=>qA,Plane:()=>di,PlaneGeometry:()=>Eg,ShaderMaterial:()=>bt,TextureLoader:()=>_o,Vector2:()=>SA,Vector3:()=>R}),jl="row",Ib="row-reverse",jf="column",Cb="column-reverse";function ob(I,A,e,t){let i=e,g="getWidth",C="x",o="y";A.indexOf(jf)===0&&(g="getHeight",C="y",o="x");for(let n=0;n<I.childrenBoxes.length;n++){let s=I.childrenBoxes[n],r=s.id,a=s[g](),B=s.margin||0;i+=B*t,I.childrenPos[r]={[C]:i+a/2*t,[o]:0},i+=t*(a+B)}}var Bk="start",Qk="center",Ek="end",nb="stretch";function sb(I,A){let e=I.getAlignItems();X1.indexOf(e)===-1&&console.warn(`alignItems === '${e}' is not supported`);let t="getWidth",i="x";A.indexOf(jl)===0&&(t="getHeight",i="y");let g=I[t]()/2-(I.padding||0);I.childrenBoxes.forEach(C=>{let o;switch(e){case Ek:case"right":case"bottom":A.indexOf(jl)===0?o=-g+C[t]()/2+(C.margin||0):o=g-C[t]()/2-(C.margin||0);break;case Bk:case"left":case"top":A.indexOf(jl)===0?o=g-C[t]()/2-(C.margin||0):o=-g+C[t]()/2+(C.margin||0);break}I.childrenPos[C.id][i]=o||0})}function rb(I){$1.indexOf(I)!==-1&&console.warn(`alignItems === '${I}' is deprecated and will be remove in 7.x.x. Fallback are 'start'|'end'`)}var X1=[Bk,Qk,Ek,nb,"top","right","bottom","left"],$1=["top","right","bottom","left"],ck="start",hk="center",lk="end",dk="space-around",uk="space-between",pk="space-evenly";function ab(I,A,e,t){let i=I.getJustifyContent();A4.indexOf(i)===-1&&console.warn(`justifyContent === '${i}' is not supported`);let g=A.indexOf("row")===0?"width":"height",C=I.getChildrenSideSum(g),n=(g==="width"?I.getInnerWidth():I.getInnerHeight())-C,s=e*2-C*Math.sign(e),r=e4(i,s),a=t4(I.childrenBoxes,n,i,t),B=A.indexOf("row")===0?"x":"y";I.childrenBoxes.forEach((Q,h)=>{I.childrenPos[Q.id][B]-=r-a[h]})}var A4=[ck,hk,lk,dk,uk,pk];function e4(I,A){switch(I){case lk:return A;case hk:return A/2}return 0}function t4(I,A,e,t){let i=Array(I.length).fill(0);if(A>0)switch(e){case uk:if(I.length>1){let g=A/(I.length-1)*t;i[0]=0;for(let C=1;C<I.length;C++)i[C]=g*C}break;case pk:if(I.length>1){let g=A/(I.length+1)*t;for(let C=0;C<I.length;C++)i[C]=g*(C+1)}break;case dk:if(I.length>1){let g=A/I.length*t,C=g/2;i[0]=C;for(let o=1;o<I.length;o++)i[o]=C+g*o}break}return i}function Dk(I){return class extends I{constructor(e){super(e),this.isBoxComponent=!0,this.childrenPos={}}getInnerWidth(){let e=this.getContentDirection();switch(e){case"row":case"row-reverse":return this.width-(this.padding*2||0)||this.getChildrenSideSum("width");case"column":case"column-reverse":return this.getHighestChildSizeOn("width");default:console.error(`Invalid contentDirection : ${e}`);break}}getInnerHeight(){let e=this.getContentDirection();switch(e){case"row":case"row-reverse":return this.getHighestChildSizeOn("height");case"column":case"column-reverse":return this.height-(this.padding*2||0)||this.getChildrenSideSum("height");default:console.error(`Invalid contentDirection : ${e}`);break}}getChildrenSideSum(e){return this.childrenBoxes.reduce((t,i)=>{let g=i.margin*2||0,C=e==="width"?i.getWidth()+g:i.getHeight()+g;return t+C},0)}setPosFromParentRecords(){this.parentUI&&this.parentUI.childrenPos[this.id]&&(this.position.x=this.parentUI.childrenPos[this.id].x,this.position.y=this.parentUI.childrenPos[this.id].y)}computeChildrenPosition(){if(this.children.length>0){let e=this.getContentDirection(),t;switch(e){case jl:t=-this.getInnerWidth()/2;break;case Ib:t=this.getInnerWidth()/2;break;case jf:t=this.getInnerHeight()/2;break;case Cb:t=-this.getInnerHeight()/2;break}let i=-Math.sign(t);ob(this,e,t,i),ab(this,e,t,i),sb(this,e)}}getHighestChildSizeOn(e){return this.childrenBoxes.reduce((t,i)=>{let g=i.margin||0,C=e==="width"?i.getWidth()+g*2:i.getHeight()+g*2;return Math.max(t,C)},0)}getWidth(){return this.parentUI&&this.parentUI.getAlignItems()==="stretch"&&this.parentUI.getContentDirection().indexOf("column")!==-1?this.parentUI.getWidth()-(this.parentUI.padding*2||0):this.width||this.getInnerWidth()+(this.padding*2||0)}getHeight(){return this.parentUI&&this.parentUI.getAlignItems()==="stretch"&&this.parentUI.getContentDirection().indexOf("row")!==-1?this.parentUI.getHeight()-(this.parentUI.padding*2||0):this.height||this.getInnerHeight()+(this.padding*2||0)}}}var nk={" ":" ","\n":`
6393
6393
  `,"\r":"\r"," ":" "},$l="normal",ZE="nowrap",zf="pre",XE="pre-line",Zf="pre-wrap",Bb=function(I,A){switch(A){case ZE:case $l:I=I.replace(/\n/g," ");case XE:I=I.replace(/[ ]{2,}/g," ");break;default:}return I},Qb=function(I){switch(I){case zf:case Zf:case XE:return"mandatory";case ZE:case $l:default:}},Eb=function(I,A,e,t){let i=I[A];switch(t.WHITESPACE){case $l:case XE:case Zf:if(i.lineBreak==="mandatory")return!0;let g=i.kerning?i.kerning:0,C=i.xoffset?i.xoffset:0,o=i.xadvance?i.xadvance:i.width;if(e+o+C+g>t.INNER_WIDTH)return!0;let n=hb(I,A,t);return i4(I[A-1],e,n,t);case zf:return i.lineBreak==="mandatory";case ZE:default:return!1}},cb=function(I,A){let e=I[0],t=I[I.length-1];switch(A){case Zf:e.glyph&&e.glyph===`
6394
6394
  `&&I.length>1&&ib([e],I[1]),t.glyph&&t.glyph===`
6395
6395
  `&&I.length>1&&tb([t],I[I.length-2]);break;case XE:case ZE:case $l:let i=[],g;for(let C=0;C<I.length;C++){let o=I[C];if(o.glyph&&nk[o.glyph]&&I.length>C){i.push(o),g=I[C+1];continue}break}ib(i,g),i=[],g=null;for(let C=I.length-1;C>0;C--){let o=I[C];if(o.glyph&&nk[o.glyph]&&C>0){i.push(o),g=I[C-1];continue}break}tb(i,g);break;case zf:break;default:return console.warn(`whiteSpace: '${A}' is not valid`),0}return e.offsetX};function tb(I,A){if(!!A)for(let e=0;e<I.length;e++){let t=I[e];t.width=0,t.height=0,t.offsetX=A.offsetX+A.width}}function ib(I,A){if(!!A)for(let e=0;e<I.length;e++){let t=I[e];t.width=0,t.height=0,t.offsetX=A.offsetX}}function hb(I,A,e,t){if(t=t||0,!I[A])return t;let i=I[A],g=i.kerning?i.kerning:0,C=i.xoffset?i.xoffset:0,o=i.xadvance?i.xadvance:i.width;return i.lineBreak?t+o:hb(I,A+1,e,t+o+e.LETTERSPACING+C+g)}function i4(I,A,e,t){return!I||!I.glyph||A+e<t.INNER_WIDTH?!1:t.BREAKON.indexOf(I.glyph)>-1}var lb="left",db="right",fk="center",wk="justify",ub="justify-left",Tf="justify-right",pb="justify-center";function Db(I,A,e){for(let t=0;t<I.length;t++){let i=I[t],g=g4(i,A,e,t===I.length-1);for(let C=0;C<i.length;C++)i[C].offsetX+=g}if(A.indexOf(wk)===0)for(let t=0;t<I.length;t++){let i=I[t];if(A.indexOf("-")!==-1&&t===I.length-1)return;let g=e-i.width;if(g<=0)return;let C=0;for(let r=1;r<i.length-1;r++)C+=i[r].glyph===" "?1:0;let o=g/C,n=1;A===Tf&&(i.reverse(),n=-1);let s=0;for(let r=1;r<=i.length-1;r++){let a=i[r];a.offsetX+=s*n,s+=a.glyph===" "?o:0}A===Tf&&i.reverse()}}var g4=(I,A,e,t)=>{switch(A){case ub:case wk:case lb:return-e/2;case Tf:case db:return-I.width+e/2;case fk:return-I.width/2;case pb:return t?-I.width/2:-e/2;default:console.warn(`textAlign: '${A}' is not valid`)}};function fb(I){return class extends I{computeInlinesPosition(){let e=this.getWidth()-(this.padding*2||0),t=this.getHeight()-(this.padding*2||0),i=this.getJustifyContent(),g=this.getTextAlign(),C=this.getInterLine(),o=this.computeLines(),n=o.reduce((r,a,B,Q)=>{let h=a.lineHeight-a.lineBase;return a.forEach(E=>{E.offsetY=r-a.lineHeight+h+Q[0].lineHeight}),r-a.lineHeight-C},0)+C;n=Math.abs(n);let s=(()=>{switch(i){case"start":return t/2-o[0].lineHeight;case"end":return n-o[0].lineHeight-t/2+(o[o.length-1].lineHeight-o[o.length-1].lineHeight);case"center":return n/2-o[0].lineHeight;default:console.warn(`justifyContent: '${i}' is not valid`)}})();o.forEach(r=>{r.forEach(a=>{a.offsetY+=s})}),Db(o,g,e),this.lines=o}calculateBestFit(e){if(this.childrenInlines.length!==0)switch(e){case"grow":this.calculateGrowFit();break;case"shrink":this.calculateShrinkFit();break;case"auto":this.calculateAutoFit();break}}calculateGrowFit(){let e=this.getHeight()-(this.padding*2||0),t=1,i=.075,g=this.childrenInlines.find(r=>r.isText),C=1,o=2,n=g._fitFontSize?g._fitFontSize/g.getFontSize():1,s;do if(s=this.calculateHeight(n),s>e){if(n<=C){this.childrenInlines.forEach(r=>{r.isInlineBlock||(r._fitFontSize=r.getFontSize())});break}o=n,n-=(o-C)/2}else{if(Math.abs(e-s)<i)break;Math.abs(n-o)<5e-10&&(o*=2),C=n,n+=(o-C)/2}while(++t<=10)}calculateShrinkFit(){let e=this.getHeight()-(this.padding*2||0),t=1,i=.075,g=this.childrenInlines.find(r=>r.isText),C=0,o=1,n=g._fitFontSize?g._fitFontSize/g.getFontSize():1,s;do if(s=this.calculateHeight(n),s>e)o=n,n-=(o-C)/2;else{if(n>=o){this.childrenInlines.forEach(r=>{r.isInlineBlock||(r._fitFontSize=r.getFontSize())});break}if(Math.abs(e-s)<i)break;C=n,n+=(o-C)/2}while(++t<=10)}calculateAutoFit(){let e=this.getHeight()-(this.padding*2||0),t=1,i=.075,g=this.childrenInlines.find(r=>r.isText),C=0,o=2,n=g._fitFontSize?g._fitFontSize/g.getFontSize():1,s;do if(s=this.calculateHeight(n),s>e)o=n,n-=(o-C)/2;else{if(Math.abs(e-s)<i)break;Math.abs(n-o)<5e-10&&(o*=2),C=n,n+=(o-C)/2}while(++t<=10)}computeLines(){let e=this.getWidth()-(this.padding*2||0),t=[[]];return this.childrenInlines.reduce((i,g)=>{if(!g.inlines)return;let C=g._fitFontSize||g.getFontSize(),o=g.isText?g.getLetterSpacing()*C:0,n=g.getWhiteSpace(),s=g.getBreakOn(),r={WHITESPACE:n,LETTERSPACING:o,BREAKON:s,INNER_WIDTH:e};return g.inlines.reduce((B,Q,h,E)=>{let c=Q.kerning?Q.kerning:0,l=Q.xoffset?Q.xoffset:0,d=Q.xadvance?Q.xadvance:Q.width;return Eb(E,h,B,r)?(t.push([Q]),Q.offsetX=l,Q.width===0?0:d+o):(t[t.length-1].push(Q),Q.offsetX=B+l+c,B+d+c+o)},i)},0),t.forEach(i=>{if(i.lineHeight=i.reduce((C,o)=>{let n=o.lineHeight!==void 0?o.lineHeight:o.height;return Math.max(C,n)},0),i.lineBase=i.reduce((C,o)=>{let n=o.lineBase!==void 0?o.lineBase:o.height;return Math.max(C,n)},0),i.width=0,i[0]){let C=this.getWhiteSpace(),o=cb(i,C);i.forEach(n=>{n.offsetX-=o}),i.width=this.computeLineWidth(i)}}),t}calculateHeight(e){this.childrenInlines.forEach(C=>{C.isInlineBlock||(C._fitFontSize=C.getFontSize()*e,C.calculateInlines(C._fitFontSize))});let t=this.computeLines(),i=this.getInterLine(),g=t.reduce((C,o)=>C-o.lineHeight-i,0)+i;return Math.abs(g)}computeLineWidth(e){let t=e[0],i=e[e.length-1];return i.offsetX+i.width+t.offsetX}}}var I4=new Ke.FileLoader,sk=[],bf={},C4=new Ke.TextureLoader,rk=[],xf={},Hi={};function o4(I,A){typeof A=="string"?s4(I,A):(Hi[I.id]||(Hi[I.id]={component:I}),Sk(A),Hi[I.id].json=A,I._updateFontFamily(A))}function n4(I,A){rk.indexOf(A)===-1&&(rk.push(A),C4.load(A,e=>{e.generateMipmaps=!1,e.minFilter=Ke.LinearFilter,e.magFilter=Ke.LinearFilter,xf[A]=e;for(let t of Object.keys(Hi))A===Hi[t].textureURL&&Hi[t].component._updateFontTexture(e)})),Hi[I.id]||(Hi[I.id]={component:I}),Hi[I.id].textureURL=A,xf[A]&&I._updateFontTexture(xf[A])}function wb(I){let A=Hi[I.id];return!A&&I.parentUI?wb(I.parentUI):A}function s4(I,A){sk.indexOf(A)===-1&&(sk.push(A),I4.load(A,e=>{let t=JSON.parse(e);Sk(t),bf[A]=t;for(let i of Object.keys(Hi))A===Hi[i].jsonURL&&Hi[i].component._updateFontFamily(t)})),Hi[I.id]||(Hi[I.id]={component:I}),Hi[I.id].jsonURL=A,bf[A]&&I._updateFontFamily(bf[A])}function Sk(I){if(I._kernings)return;let A={};for(let e=0;e<I.kernings.length;e++){let t=I.kernings[e];if(t.amount===0)continue;let i=String.fromCharCode(t.first,t.second);A[i]=t.amount}I._kernings=A}function r4(I,A,e){e.generateMipmaps=!1,e.minFilter=Ke.LinearFilter,e.magFilter=Ke.LinearFilter,sk.push(I),bf[I]=A,Sk(A),e&&(rk.push(I),xf[I]=e)}var a4={setFontFamily:o4,setFontTexture:n4,getFontOf:wb,addFont:r4},zl=a4,sn=class{static requestUpdate(A,e,t,i){A.traverse(g=>{!g.isUI||(this.requestedUpdates[g.id]?(e&&(this.requestedUpdates[g.id].updateParsing=!0),t&&(this.requestedUpdates[g.id].updateLayout=!0),i&&(this.requestedUpdates[g.id].updateInner=!0)):this.requestedUpdates[g.id]={updateParsing:e,updateLayout:t,updateInner:i,needCallback:e||t||i})})}static register(A){this.components.includes(A)||this.components.push(A)}static disposeOf(A){let e=this.components.indexOf(A);e>-1&&this.components.splice(e,1)}static update(){if(Object.keys(this.requestedUpdates).length>0){let A=this.components.filter(e=>!e.parentUI);A.forEach(e=>this.traverseParsing(e)),A.forEach(e=>this.traverseUpdates(e))}}static traverseParsing(A){let e=this.requestedUpdates[A.id];e&&e.updateParsing&&(A.parseParams(),e.updateParsing=!1),A.childrenUIs.forEach(t=>this.traverseParsing(t))}static traverseUpdates(A){let e=this.requestedUpdates[A.id];delete this.requestedUpdates[A.id],e&&e.updateLayout&&(e.updateLayout=!1,A.updateLayout()),e&&e.updateInner&&(e.updateInner=!1,A.updateInner()),A.childrenUIs.forEach(t=>{this.traverseUpdates(t)}),e&&e.needCallback&&A.onAfterUpdate()}};sn.components=[];sn.requestedUpdates={};var yi={container:null,fontFamily:null,fontSize:.05,fontKerning:"normal",bestFit:"none",offset:.01,interLine:.01,breakOn:`- ,.:?!