@needle-tools/engine 3.27.3-beta → 3.27.4-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4286,7 +4286,9 @@ irradiance += 0.;
4286
4286
  irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
4287
4287
  #endif`),OA.lightmap.lightmapScaleOffset={value:new ie(1,1,0,0)};const q9=CA("debugplayerview");var _s=(t=>(t.Browser="browser",t.Headset="headset",t.Handheld="handheld",t))(_s||{});class hT{constructor(A,e){n(this,"userId"),n(this,"context"),n(this,"viewDevice","browser"),n(this,"removed",!1),n(this,"_object"),this.userId=A,this.context=e}get currentObject(){return this._object}set currentObject(A){this._object=A}get isConnected(){return this.context.connection.userIsInRoom(this.userId)}}class cT{constructor(A){n(this,"context"),n(this,"playerViews",new Map),this.context=A}setPlayerView(A,e,i){let g=this.playerViews.get(A);g||(g=new hT(A,this.context),this.playerViews.set(A,g)),g.viewDevice=i,g.currentObject=e,g.removed=!1}getPlayerView(A){if(!!A){if(!this.context.connection.userIsInRoom(A)){this.playerViews.delete(A);return}return this.playerViews.get(A)}}removePlayerView(A,e){const i=this.playerViews.get(A);i?.viewDevice===e&&(q9&&console.log("REMOVE",A),i.removed=!0,this.playerViews.delete(A))}}function*lT(t,A=null){const e=A?A.time:qe.Current.time,i=e.time;for(;e.time-i<t;)yield}function*b9(t){for(let A=0;A<t;A++)yield}function*dT(t){let A=!0;for(t.then(()=>A=!1),t.catch(()=>A=!1);A;)yield}const Aw=new Map;function ew(t,A){Aw.has(A)||Aw.set(A,new Array),Aw.get(A).push(t)}function Hr(t,A){const e=Aw.get(A);if(e&&e.length>0){let i=e;A===Ig.Start&&(i=[...e],e.length=0),L9(t,i)}}function L9(t,A){for(let e=A.length-1;e>=0;e--){const i=A[e];Jr(i,t)}}const nn=CA("debugcontext"),x9=CA("stats"),T9=CA("debugactive"),Y9=CA("debugframerate"),H9=CA("debugcoroutine"),O9={};class _9{constructor(){n(this,"name"),n(this,"alias"),n(this,"hash"),n(this,"runInBackground"),n(this,"domElement"),n(this,"renderer"),n(this,"camera"),n(this,"scene")}}var Ig=(t=>(t[t.Start=-1]="Start",t[t.EarlyUpdate=0]="EarlyUpdate",t[t.Update=1]="Update",t[t.LateUpdate=2]="LateUpdate",t[t.OnBeforeRender=3]="OnBeforeRender",t[t.OnAfterRender=4]="OnAfterRender",t[t.PrePhysicsStep=9]="PrePhysicsStep",t[t.PostPhysicsStep=10]="PostPhysicsStep",t[t.Undefined=-1]="Undefined",t))(Ig||{}),Zc=(t=>(t.ImmersiveVR="immersive-vr",t.ImmersiveAR="immersive-ar",t))(Zc||{});function tw(t,A){if(!t)return;if(!t.isComponent){(Ye()||nn)&&console.error(`Registered script is not a Needle Engine component.
4288
4288
  The script will be ignored. Please make sure your component extends "Behaviour" imported from "@needle-tools/engine"
4289
- `,t);return}const e=A?.new_scripts??qe.Current.new_scripts;e.includes(t)||e.push(t)}const Ii=class{constructor(t){n(this,"name"),n(this,"alias"),n(this,"isManagedExternally",!1),n(this,"isPaused",!1),n(this,"runInBackground",!1),n(this,"targetFrameRate"),n(this,"physicsSteps",1),n(this,"hash"),n(this,"domElement"),n(this,"_resolutionScaleFactor",1),n(this,"_boundingClientRectFrame",-1),n(this,"_boundingClientRect",null),n(this,"_domX"),n(this,"_domY"),n(this,"xrSessionMode"),n(this,"_xrFrame",null),n(this,"_currentFrameEvent",-1),n(this,"scene"),n(this,"renderer"),n(this,"composer",null),n(this,"scripts",[]),n(this,"scripts_pausedChanged",[]),n(this,"scripts_earlyUpdate",[]),n(this,"scripts_update",[]),n(this,"scripts_lateUpdate",[]),n(this,"scripts_onBeforeRender",[]),n(this,"scripts_onAfterRender",[]),n(this,"scripts_WithCorroutines",[]),n(this,"coroutines",{}),n(this,"mainCameraComponent"),n(this,"_camera",null),n(this,"post_setup_callbacks",[]),n(this,"pre_update_callbacks",[]),n(this,"pre_render_callbacks",[]),n(this,"post_render_callbacks",[]),n(this,"new_scripts",[]),n(this,"new_script_start",[]),n(this,"new_scripts_pre_setup_callbacks",[]),n(this,"new_scripts_post_setup_callbacks",[]),n(this,"application"),n(this,"time"),n(this,"input"),n(this,"physics"),n(this,"connection"),n(this,"assets"),n(this,"mainLight",null),n(this,"sceneLighting"),n(this,"addressables"),n(this,"lightmaps"),n(this,"players"),n(this,"_sizeChanged",!1),n(this,"_isCreated",!1),n(this,"_isCreating",!1),n(this,"_isVisible",!1),n(this,"_stats",x9?new g9:null),n(this,"_intersectionObserver",null),n(this,"_disposeCallbacks",[]),n(this,"onUnhandledRejection",i=>{this.domElement.dispatchEvent(new CustomEvent("error",{detail:i.reason}))}),n(this,"_cameraStack",[]),n(this,"_onBeforeRenderListeners",new Map),n(this,"_onAfterRenderListeners",new Map),n(this,"_requireDepthTexture",!1),n(this,"_requireColorTexture",!1),n(this,"_renderTarget"),n(this,"_isRendering",!1),n(this,"_createId",0),n(this,"_renderlooperrors",0),n(this,"_lastTimestamp",0),n(this,"_accumulatedTime",0),n(this,"_dispatchReadyAfterFrame",!1),n(this,"_wasPaused",!1),this.name=t?.name||"",this.alias=t?.alias,this.domElement=t?.domElement||document.body,this.hash=t?.hash,t!=null&&t.renderer&&(this.renderer=t.renderer,this.isManagedExternally=!0),t?.runInBackground!==void 0&&(this.runInBackground=t.runInBackground),t!=null&&t.scene?this.scene=t.scene:this.scene=new fI,t!=null&&t.camera&&(this._camera=t.camera),this.application=new AT(this),this.time=new xq,this.input=new kq(this),this.physics=new bq(this),this.connection=new aL(this),this.assets=new VL,this.sceneLighting=new Xx(this),this.addressables=new zx(this),this.lightmaps=new v9(this),this.players=new cT(this);const A=()=>this._sizeChanged=!0;window.addEventListener("resize",A),this._disposeCallbacks.push(()=>window.removeEventListener("resize",A));const e=new ResizeObserver(i=>this._sizeChanged=!0);e.observe(this.domElement),this._disposeCallbacks.push(()=>e.disconnect()),this._intersectionObserver=new IntersectionObserver(i=>{this._isVisible=i[0].isIntersecting}),this._disposeCallbacks.push(()=>{var i;return(i=this._intersectionObserver)==null?void 0:i.disconnect()}),Gt.register(this)}static get DefaultTargetFrameRate(){return Ii._defaultTargetFramerate.value}static set DefaultTargetFrameRate(t){Ii._defaultTargetFramerate.value=t}static get DefaultWebGLRendererParameters(){return Ii._defaultWebglRendererParameters}get version(){return xC}static get Current(){return Gt.Current}static set Current(t){Gt.Current=t}appendHTMLElement(t){return this.domElement.shadowRoot?this.domElement.shadowRoot.appendChild(t):this.domElement.appendChild(t)}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(t){if(t!==this._resolutionScaleFactor&&typeof t=="number"){if(t<=0){console.error("Invalid resolution scale factor",t);return}this._resolutionScaleFactor=t,this.updateSize()}}calculateBoundingClientRect(){if(this.isInAR){this._domX=0,this._domY=0;return}this._boundingClientRectFrame!==this.time.frame&&(this._boundingClientRectFrame=this.time.frame,this._boundingClientRect=this.domElement.getBoundingClientRect(),this._domX=this._boundingClientRect.x,this._domY=this._boundingClientRect.y)}get domWidth(){return this.isInAR?window.innerWidth:this.domElement.clientWidth}get domHeight(){return this.isInAR?window.innerHeight:this.domElement.clientHeight}get domX(){return this.calculateBoundingClientRect(),this._domX}get domY(){return this.calculateBoundingClientRect(),this._domY}get isInXR(){var t,A;return((A=(t=this.renderer)==null?void 0:t.xr)==null?void 0:A.isPresenting)||!1}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){var t,A;return(A=(t=this.renderer)==null?void 0:t.xr)==null?void 0:A.getSession()}get xrFrame(){return this._xrFrame}get xrCamera(){var t,A;return(A=(t=this.renderer)==null?void 0:t.xr)==null?void 0:A.getCamera()}get arOverlayElement(){const t=this.domElement;return typeof t.getAROverlayContainer=="function"?t.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this._camera)return this._camera;if(this.mainCameraComponent){const t=this.mainCameraComponent;return t.cam||t.buildCamera(),t.cam}return null}set mainCamera(t){this._camera=t}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}createNewRenderer(){var t,A,e;(t=this.renderer)==null||t.dispose();const i=Ii.DefaultWebGLRendererParameters;if(!i.canvas){const g=(e=(A=this.domElement)==null?void 0:A.shadowRoot)==null?void 0:e.querySelector("canvas");g&&(i.canvas=g)}this.renderer=new Pa(i),this.renderer.debug.checkShaderErrors=Ye()||CA("checkshadererrors")===!0,this.renderer.toneMappingExposure=1,this.renderer.toneMapping=$g,this.renderer.setClearColor(new SA("lightgrey"),0),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=j0,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputColorSpace=ge,this.renderer.useLegacyLights=!1}internalOnUpdateVisible(){var t,A;(t=this._intersectionObserver)==null||t.disconnect(),(A=this._intersectionObserver)==null||A.observe(this.domElement)}updateSize(){var t,A,e;if(!this.isManagedExternally&&((t=this.renderer.xr)==null?void 0:t.isPresenting)===!1){this._sizeChanged=!1;const i=this.resolutionScaleFactor,g=this.domWidth*i,I=this.domHeight*i,o=this.mainCamera;this.updateAspect(o),this.renderer.setSize(g,I,!0),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((A=this.composer.setSize)==null||A.call(this.composer,g,I),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((e=this.composer.setPixelRatio)==null||e.call(this.composer,window.devicePixelRatio)))}}updateAspect(t,A,e){if(!t)return;A===void 0&&(A=this.domWidth),e===void 0&&(e=this.domHeight);const i=t.aspect;t.aspect=A/e,i!==t.aspect&&t.updateProjectionMatrix()}async onCreate(t){return this.create(t)}async create(t){try{return this._isCreating=!0,window.addEventListener("unhandledrejection",this.onUnhandledRejection),await this.internalOnCreate(t)}finally{window.removeEventListener("unhandledrejection",this.onUnhandledRejection),this._isCreating=!1}}clear(){var t,A,e,i;Gt.dispatchCallback(Wi.ContextClearing,this),Ys(this.scene,!0,!0),this.scene=new fI,(t=this.addressables)==null||t.dispose(),(A=this.lightmaps)==null||A.clear(),(i=(e=this.physics)==null?void 0:e.engine)==null||i.clearCaches(),this.isManagedExternally||this.renderer&&(this.renderer.renderLists.dispose(),this.renderer.state.reset(),this.renderer.resetState()),Gt.dispatchCallback(Wi.ContextCleared,this)}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var t,A;this.clear(),(t=this.renderer)==null||t.setAnimationLoop(null),this.renderer&&(this.renderer.setClearAlpha(0),this.renderer.clear()),this.isManagedExternally||this.renderer.dispose(),this.scene=null,this.renderer=null,this.input.dispose();for(const e of this._disposeCallbacks)try{e()}catch(i){console.error("Error in on dispose callback:",i,e)}(A=this.domElement)!=null&&A.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Gt.dispatchCallback(Wi.ContextDestroyed,this),Gt.unregister(this)}registerCoroutineUpdate(t,A,e){return this.coroutines[e]||(this.coroutines[e]=[]),this.coroutines[e].push({comp:t,main:A}),A}unregisterCoroutineUpdate(t,A){if(!this.coroutines[A])return;const e=this.coroutines[A].findIndex(i=>i.main===t);e>=0&&this.coroutines[A].splice(e,1)}stopAllCoroutinesFrom(t){for(const A in this.coroutines){const e=this.coroutines[A];for(let i=e.length-1;i>=0;i--)e[i].comp===t&&e.splice(i,1)}}setCurrentCamera(t){var A;if(!t)return;if(t.cam||t.buildCamera(),!t.cam){console.warn("Camera component is missing camera",t);return}const e=this._cameraStack.indexOf(t);e>=0&&this._cameraStack.splice(e,1),this._cameraStack.push(t),this.mainCameraComponent=t;const i=t.cam;i.isPerspectiveCamera&&this.updateAspect(i),(A=this.mainCameraComponent)==null||A.applyClearFlagsIfIsActiveCamera()}removeCamera(t){if(!t)return;const A=this._cameraStack.indexOf(t);if(A>=0&&this._cameraStack.splice(A,1),this.mainCameraComponent===t&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const e=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(e)}}addBeforeRenderListener(t,A){this._onBeforeRenderListeners.has(t.uuid)||(this._onBeforeRenderListeners.set(t.uuid,[]),t.onBeforeRender=this._createRenderCallbackWrapper(t,this._onBeforeRenderListeners)),this._onBeforeRenderListeners.get(t.uuid).push(A)}removeBeforeRenderListener(t,A){if(this._onBeforeRenderListeners.has(t.uuid)){const e=this._onBeforeRenderListeners.get(t.uuid),i=e.indexOf(A);i>=0&&e.splice(i,1)}}addAfterRenderListener(t,A){var e;this._onAfterRenderListeners.has(t.uuid)||(this._onAfterRenderListeners.set(t.uuid,[]),t.onAfterRender=this._createRenderCallbackWrapper(t,this._onAfterRenderListeners)),(e=this._onAfterRenderListeners.get(t.uuid))==null||e.push(A)}removeAfterRenderListener(t,A){if(this._onAfterRenderListeners.has(t.uuid)){const e=this._onAfterRenderListeners.get(t.uuid),i=e.indexOf(A);i>=0&&e.splice(i,1)}}_createRenderCallbackWrapper(t,A){return(e,i,g,I,o,s)=>{const C=A.get(t.uuid);if(C)for(let a=0;a<C.length;a++){const r=C[a];r(e,i,g,I,o,s)}}}get isRendering(){return this._isRendering}setRequireDepth(t){this._requireDepthTexture=t}setRequireColor(t){this._requireColorTexture=t}get depthTexture(){var t;return((t=this._renderTarget)==null?void 0:t.depthTexture)||null}get opaqueColorTexture(){var t;return((t=this._renderTarget)==null?void 0:t.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const t=getComputedStyle(this.domElement);return t.visibility!=="hidden"&&t.display!=="none"&&t.opacity!=="0"}async internalOnCreate(t){var A,e,i,g,I;const o=++this._createId;this.clear(),this.isManagedExternally===!1&&(this.createNewRenderer(),(A=this.renderer)==null||A.setAnimationLoop(null)),await za(1),Ii.Current=this,await Gt.dispatchCallback(Wi.ContextCreationStart,this);let s=!0,C;try{Ii.Current=this,t?C=await this.internalLoadInitialContent(o,t):C=[]}catch(r){console.error(r),s=!1}if(!s||o!==this._createId)return!1;if(this.internalOnUpdateVisible(),!this.renderer)return nn&&console.warn("Context has no renderer (perhaps it was disconnected?",this.domElement.isConnected),!1;!this.isManagedExternally&&!this.domElement.shadowRoot&&this.domElement.prepend(this.renderer.domElement),Ii.Current=this,Ii.Current=this;for(let r=0;r<this.new_scripts.length;r++){const B=this.new_scripts[r];if(B.gameObject!==void 0&&B.gameObject!==null){B.gameObject.userData===void 0&&(B.gameObject.userData={}),B.gameObject.userData.components===void 0&&(B.gameObject.userData.components=[]);const Q=B.gameObject.userData.components;Q.includes(B)||Q.push(B)}}if(this.post_setup_callbacks)for(let r=0;r<this.post_setup_callbacks.length;r++)Ii.Current=this,await this.post_setup_callbacks[r](this);if(!this.mainCamera){Ii.Current=this;let r=null;Tr(this.scene,B=>{const Q=B;if(Q!=null&&Q.isCamera){if(Yc(Q.gameObject),!Q.activeAndEnabled)return;if(Q.tag==="MainCamera")return r=Q,!0;r=Q}}),r?this.setCurrentCamera(r):!Gt.dispatchCallback(Wi.MissingCamera,this,{files:C})&&!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this)}if(Ii.Current=this,JD(this),this.physics.engine&&((e=this.physics.engine)==null||e.step(0),(i=this.physics.engine)==null||i.postStep()),!this.isManagedExternally&&this.composer&&this.mainCamera){const r=new YD(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(r),this.composer.setSize(this.domWidth,this.domHeight)}this._sizeChanged=!0,this._stats&&(this._stats.showPanel(0),(g=this.domElement.shadowRoot)==null||g.appendChild(this._stats.dom)),nn&&Wu(this.scene,!0),this.targetFrameRate===void 0?(nn&&console.warn("No target framerate set, using default",Ii.DefaultTargetFrameRate),this.targetFrameRate=Ii._defaultTargetFramerate):nn&&console.log("Target framerate set to",this.targetFrameRate),this._dispatchReadyAfterFrame=!0;const a=Gt.dispatchCallback(Wi.ContextCreated,this,{files:C});return a&&("internalSetLoadingMessage"in this.domElement&&typeof this.domElement.internalSetLoadingMessage=="function"&&((I=this.domElement)==null||I.internalSetLoadingMessage("finish loading")),await a),Hr(this,Wi.ContextCreated),this._isCreating=!1,this.isManagedExternally||this.restartRenderLoop(),a}async internalLoadInitialContent(t,A){var e,i;const g=new Array;if(A.files.length===0)return g;const I=[...A.files],o={name:"",progress:null,index:0,count:I.length},s=ns();let C=0;this.hash&&(C=Number.parseInt(this.hash)??0);for(let a=0;a<I.length;a++){if(t!==this._createId){nn&&console.log("Aborting loading because create id changed",t,this._createId);break}const r=I[a];if(!r.includes(".glb")&&!r.includes(".gltf")){const Q=`Needle Engine: found suspicious src "${r}"`;console.warn(Q),gI()&&ig(Q)}(e=A?.onLoadingStart)==null||e.call(this,a,r);const B=await s.loadSync(this,r,r,C,Q=>{var E;o.name=r,o.progress=Q,o.index=a,o.count=I.length,(E=A.onLoadingProgress)==null||E.call(this,o)});(i=A?.onLoadingFinished)==null||i.call(this,a,r,B??null),B?g.push({src:r,file:B}):console.warn("Could not load file: "+r)}if(t!==this._createId){for(const a of g)if(a&&a.file)for(const r of a.file.scenes)Ys(r,!0,!0)}else for(const a of g)a&&a.file&&this.scene.add(a.file.scene);return g}restartRenderLoop(){return this.renderer?this._isCreating?(console.warn("Can not start render loop while creating context"),!1):(this.renderer.setAnimationLoop((t,A)=>{this.isManagedExternally||this.update(t,A)}),!0):(console.error("Can not start render loop without renderer"),!1)}update(t,A){if(A===void 0&&(A=null),Ye()||nn||i5())try{this.internalStep(t,A),this._renderlooperrors=0}catch(e){this._renderlooperrors+=1,(Ye()||nn)&&(e instanceof Error||e instanceof TypeError)&&li("Caught unhandled exception during render-loop.<br/>Stopping renderloop...<br/>See console for details.",yo.Error),console.error(e),this._renderlooperrors>10&&(console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null)),this.domElement.dispatchEvent(new CustomEvent("error",{detail:e}))}else this.internalStep(t,A)}updatePhysics(t){this.internalUpdatePhysics(t)}internalStep(t,A){this.internalOnBeforeRender(t,A)!==!1&&(this.internalOnRender(),this.internalOnAfterRender())}internalOnBeforeRender(t,A){var e;if(this._xrFrame=A,this._currentFrameEvent=-1,this.isManagedExternally===!1&&this.isInXR===!1&&this.targetFrameRate!==void 0){this._lastTimestamp===0&&(this._lastTimestamp=t),this._accumulatedTime+=(t-this._lastTimestamp)/1e3,this._lastTimestamp=t;let i=this.targetFrameRate;if(typeof i=="object"&&(i=i.value),this._accumulatedTime<1/(i+1))return!1;this._accumulatedTime=0}if((e=this._stats)==null||e.begin(),Ii.Current=this,this.onHandlePaused())return!1;for(Ii.Current=this,this.time.update(),Y9&&console.log("FPS",this.time.smoothedFps.toFixed(0)),JD(this),vD(this.scene),nx(this),Hr(this,-1);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);const i=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(i)}if(this.pre_update_callbacks)for(const i in this.pre_update_callbacks)this.pre_update_callbacks[i]();this._currentFrameEvent=0;for(let i=0;i<this.scripts_earlyUpdate.length;i++){const g=this.scripts_earlyUpdate[i];g.activeAndEnabled&&g.earlyUpdate!==void 0&&(Ii.Current=this,g.earlyUpdate())}if(this.executeCoroutines(0),Hr(this,0),this.onHandlePaused())return!1;this._currentFrameEvent=1;for(let i=0;i<this.scripts_update.length;i++){const g=this.scripts_update[i];g.activeAndEnabled&&g.update!==void 0&&(Ii.Current=this,g.update())}if(this.executeCoroutines(1),Hr(this,1),this.onHandlePaused())return!1;this._currentFrameEvent=2;for(let i=0;i<this.scripts_lateUpdate.length;i++){const g=this.scripts_lateUpdate[i];g.activeAndEnabled&&g.lateUpdate!==void 0&&(Ii.Current=this,g.lateUpdate())}if(this.executeCoroutines(2),Hr(this,2),this.onHandlePaused()||(this.physicsSteps===void 0&&(this.physicsSteps=1),this.physics.engine&&this.physicsSteps>0&&this.internalUpdatePhysics(this.physicsSteps),this.onHandlePaused()))return!1;if(this.isVisibleToUser||this.runInBackground){this._currentFrameEvent=3;for(let i=0;i<this.scripts_onBeforeRender.length;i++){const g=this.scripts_onBeforeRender[i];g.activeAndEnabled&&g.onBeforeRender!==void 0&&(Ii.Current=this,g.onBeforeRender(A))}if(this.executeCoroutines(3),Hr(this,3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(const i in this.pre_render_callbacks)this.pre_render_callbacks[i]()}return!0}internalUpdatePhysics(t){if(!this.physics.engine)return!1;const A=t,e=this.time.deltaTime/A;for(let i=0;i<A;i++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(e),this._currentFrameEvent=10,this.executeCoroutines(10);return this.physics.engine.postStep(),!0}internalOnRender(){this.isManagedExternally||(o5(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4)}internalOnAfterRender(){if(this.isVisibleToUser||this.runInBackground){for(let t=0;t<this.scripts_onAfterRender.length;t++){const A=this.scripts_onAfterRender[t];A.activeAndEnabled&&A.onAfterRender!==void 0&&(Ii.Current=this,A.onAfterRender())}if(this.executeCoroutines(4),Hr(this,4),this.post_render_callbacks)for(const t in this.post_render_callbacks)this.post_render_callbacks[t]()}this._currentFrameEvent=-1,this.connection.sendBufferedMessagesNow(),this._stats&&(this._stats.end(),this.time.frameCount%150===0&&console.log({...this.renderer.info.memory},{...this.renderer.info.render})),this._dispatchReadyAfterFrame&&(this._dispatchReadyAfterFrame=!1,this.domElement.dispatchEvent(new CustomEvent("ready")),Gt.dispatchCallback(Wi.ContextFirstFrameRendered,this))}renderNow(t){return!t&&(t=this.mainCamera,!t)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):t&&this.renderer.render(this.scene,t),this._isRendering=!1,!0)}onHandlePaused(){const t=this.evaluatePaused();if(this._wasPaused!==t){T9&&console.log("Paused?",t,"context:"+this.alias);for(let A=0;A<this.scripts_pausedChanged.length;A++){const e=this.scripts_pausedChanged[A];e.activeAndEnabled&&e.onPausedChanged!==void 0&&(Ii.Current=this,e.onPausedChanged(t,this._wasPaused))}}return this._wasPaused=t,t}evaluatePaused(){return this.isInXR?!1:this.isPaused?!0:this.runInBackground?!1:!this.isVisibleToUser}renderRequiredTextures(){if(!this.mainCamera||!this._requireDepthTexture&&!this._requireColorTexture)return;if(!this._renderTarget){if(this._renderTarget=new $e(this.domWidth,this.domHeight),this._requireDepthTexture){const e=new jh(this.domWidth,this.domHeight);this._renderTarget.depthTexture=e}this._requireColorTexture&&(this._renderTarget.texture=new Je,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=xe,this._renderTarget.texture.magFilter=xe,this._renderTarget.texture.format=ft)}const t=this._renderTarget;t.texture&&(t.texture.colorSpace=this.renderer.outputColorSpace);const A=this.renderer.getRenderTarget();this.renderer.setRenderTarget(t),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(A)}executeCoroutines(t){var A;if(this.coroutines[t]){const i=this.coroutines[t];for(let g=0;g<i.length;g++)try{const I=i[g];if(!I.comp||I.comp.destroyed||!I.main||I.comp.enabled===!1){H9&&console.log("Removing coroutine",I.comp,I.comp.enabled),i.splice(g,1),--g;continue}const o=I.chained;if(o&&o.length>0){const a=o[o.length-1].next();if(a.done&&o.pop(),e(a)&&(I.chained||(I.chained=[]),I.chained.push(a.value)),!a.done)continue}const s=I.main.next();if(s.done===!0){i.splice(g,1),--g;continue}const C=s.value;if(e(C)){if(C.next().done)continue;I.chained||(I.chained=[]),I.chained.push(C)}else if(C instanceof Promise){const a=C;I.chained||(I.chained=[]);const r=dT(a);(A=I.chained)==null||A.push(r);continue}}catch(I){console.error(I)}}function e(i){return!!(i&&i.next&&i.return)}}};let qe=Ii;n(qe,"_defaultTargetFramerate",{value:60}),n(qe,"_defaultWebglRendererParameters",{antialias:!0,alpha:!1});const Xc=CA("debugoverlay"),pT="ar",P9="quit-ar";class j9{constructor(){n(this,"arContainer",null),n(this,"currentSession",null),n(this,"_createdAROnlyElements",[]),n(this,"_reparentedObjects",[]),n(this,"contentElement",null),n(this,"requestEndAR",()=>{this.onRequestedEndAR()})}get ARContainer(){return this.arContainer}onBegin(A,e,i){var g;if(this.currentSession=i,this.arContainer=e,Tu()){const I=A.domElement.children;for(let o=0;o<I?.length;o++){const s=I[o];if(!s||s===this.arContainer)return;this._reparentedObjects.push({el:s,previousParent:s.parentElement}),(g=this.arContainer)==null||g.appendChild(s)}}this.ensureQuitARButton(this.arContainer)}onEnd(A){var e;for(const i of this._createdAROnlyElements)i.remove&&i.remove();for(const i of this._reparentedObjects){const g=i.el;(e=i.previousParent)==null||e.appendChild(g)}this._reparentedObjects.length=0,Tu()&&setTimeout(()=>{var i;const g=A.renderer.domElement;g&&((i=A.domElement.shadowRoot)==null||i.prepend(g));const I=document.querySelectorAll("*");for(var o=0;o<I.length;o++){const s=I[o];s&&s._displayChanged!==void 0&&s._displayWas!==void 0&&(s.style.display=s._displayWas)}},10)}createOverlayContainer(A){if(this.contentElement)return this.contentElement;Xc&&console.log("Setup overlay container");const e=A.shadowRoot.querySelector(".content");this.contentElement=e;const i=A.shadowRoot.querySelector(".overlay-content");return i&&e.appendChild(i),Xc&&!FC()&&this.ensureQuitARButton(e),e}onRequestedEndAR(){this.currentSession&&(this.currentSession.end(),this.currentSession=null)}ensureQuitARButton(A){const e=document.createElement("slot");e.setAttribute("name","quit-ar"),this.appendElement(e,A),this._createdAROnlyElements.push(e),e.style.pointerEvents="auto";const i=document.querySelector(`.${P9}`);if(i){i.addEventListener("click",this.requestEndAR),Xc&&i.addEventListener("click",()=>console.log("Clicked quit-ar button"));return}e.addEventListener("click",this.requestEndAR),Xc&&e.addEventListener("click",()=>console.log("Clicked fallback close button"));const g=document.createElement("div");g.style.cssText=`
4289
+ `,t);return}const e=A?.new_scripts??qe.Current.new_scripts;e.includes(t)||e.push(t)}const Ii=class{constructor(t){n(this,"name"),n(this,"alias"),n(this,"isManagedExternally",!1),n(this,"isPaused",!1),n(this,"runInBackground",!1),n(this,"targetFrameRate"),n(this,"physicsSteps",1),n(this,"hash"),n(this,"domElement"),n(this,"_resolutionScaleFactor",1),n(this,"_boundingClientRectFrame",-1),n(this,"_boundingClientRect",null),n(this,"_domX"),n(this,"_domY"),n(this,"xrSessionMode"),n(this,"_xrFrame",null),n(this,"_currentFrameEvent",-1),n(this,"scene"),n(this,"renderer"),n(this,"composer",null),n(this,"scripts",[]),n(this,"scripts_pausedChanged",[]),n(this,"scripts_earlyUpdate",[]),n(this,"scripts_update",[]),n(this,"scripts_lateUpdate",[]),n(this,"scripts_onBeforeRender",[]),n(this,"scripts_onAfterRender",[]),n(this,"scripts_WithCorroutines",[]),n(this,"coroutines",{}),n(this,"mainCameraComponent"),n(this,"_camera",null),n(this,"post_setup_callbacks",[]),n(this,"pre_update_callbacks",[]),n(this,"pre_render_callbacks",[]),n(this,"post_render_callbacks",[]),n(this,"new_scripts",[]),n(this,"new_script_start",[]),n(this,"new_scripts_pre_setup_callbacks",[]),n(this,"new_scripts_post_setup_callbacks",[]),n(this,"application"),n(this,"time"),n(this,"input"),n(this,"physics"),n(this,"connection"),n(this,"assets"),n(this,"mainLight",null),n(this,"sceneLighting"),n(this,"addressables"),n(this,"lightmaps"),n(this,"players"),n(this,"_sizeChanged",!1),n(this,"_isCreated",!1),n(this,"_isCreating",!1),n(this,"_isVisible",!1),n(this,"_stats",x9?new g9:null),n(this,"_intersectionObserver",null),n(this,"_disposeCallbacks",[]),n(this,"onUnhandledRejection",i=>{this.domElement.dispatchEvent(new CustomEvent("error",{detail:i.reason}))}),n(this,"_cameraStack",[]),n(this,"_onBeforeRenderListeners",new Map),n(this,"_onAfterRenderListeners",new Map),n(this,"_requireDepthTexture",!1),n(this,"_requireColorTexture",!1),n(this,"_renderTarget"),n(this,"_isRendering",!1),n(this,"_createId",0),n(this,"_renderlooperrors",0),n(this,"_lastTimestamp",0),n(this,"_accumulatedTime",0),n(this,"_dispatchReadyAfterFrame",!1),n(this,"_wasPaused",!1),this.name=t?.name||"",this.alias=t?.alias,this.domElement=t?.domElement||document.body,this.hash=t?.hash,t!=null&&t.renderer&&(this.renderer=t.renderer,this.isManagedExternally=!0),t?.runInBackground!==void 0&&(this.runInBackground=t.runInBackground),t!=null&&t.scene?this.scene=t.scene:this.scene=new fI,t!=null&&t.camera&&(this._camera=t.camera),this.application=new AT(this),this.time=new xq,this.input=new kq(this),this.physics=new bq(this),this.connection=new aL(this),this.assets=new VL,this.sceneLighting=new Xx(this),this.addressables=new zx(this),this.lightmaps=new v9(this),this.players=new cT(this);const A=()=>this._sizeChanged=!0;window.addEventListener("resize",A),this._disposeCallbacks.push(()=>window.removeEventListener("resize",A));const e=new ResizeObserver(i=>this._sizeChanged=!0);e.observe(this.domElement),this._disposeCallbacks.push(()=>e.disconnect()),this._intersectionObserver=new IntersectionObserver(i=>{this._isVisible=i[0].isIntersecting}),this._disposeCallbacks.push(()=>{var i;return(i=this._intersectionObserver)==null?void 0:i.disconnect()}),Gt.register(this)}static get DefaultTargetFrameRate(){return Ii._defaultTargetFramerate.value}static set DefaultTargetFrameRate(t){Ii._defaultTargetFramerate.value=t}static get DefaultWebGLRendererParameters(){return Ii._defaultWebglRendererParameters}get version(){return xC}static get Current(){return Gt.Current}static set Current(t){Gt.Current=t}appendHTMLElement(t){return this.domElement.shadowRoot?this.domElement.shadowRoot.appendChild(t):this.domElement.appendChild(t)}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(t){if(t!==this._resolutionScaleFactor&&typeof t=="number"){if(t<=0){console.error("Invalid resolution scale factor",t);return}this._resolutionScaleFactor=t,this.updateSize()}}calculateBoundingClientRect(){if(this.isInAR){this._domX=0,this._domY=0;return}this._boundingClientRectFrame!==this.time.frame&&(this._boundingClientRectFrame=this.time.frame,this._boundingClientRect=this.domElement.getBoundingClientRect(),this._domX=this._boundingClientRect.x,this._domY=this._boundingClientRect.y)}get domWidth(){return this.isInAR?window.innerWidth:this.domElement.clientWidth}get domHeight(){return this.isInAR?window.innerHeight:this.domElement.clientHeight}get domX(){return this.calculateBoundingClientRect(),this._domX}get domY(){return this.calculateBoundingClientRect(),this._domY}get isInXR(){var t,A;return((A=(t=this.renderer)==null?void 0:t.xr)==null?void 0:A.isPresenting)||!1}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){var t,A;return(A=(t=this.renderer)==null?void 0:t.xr)==null?void 0:A.getSession()}get xrFrame(){return this._xrFrame}get xrCamera(){var t,A;return(A=(t=this.renderer)==null?void 0:t.xr)==null?void 0:A.getCamera()}get arOverlayElement(){const t=this.domElement;return typeof t.getAROverlayContainer=="function"?t.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this._camera)return this._camera;if(this.mainCameraComponent){const t=this.mainCameraComponent;return t.cam||t.buildCamera(),t.cam}return null}set mainCamera(t){this._camera=t}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}createNewRenderer(){var t,A,e;(t=this.renderer)==null||t.dispose();const i=Ii.DefaultWebGLRendererParameters;if(!i.canvas){const g=(e=(A=this.domElement)==null?void 0:A.shadowRoot)==null?void 0:e.querySelector("canvas");g&&(i.canvas=g)}this.renderer=new Pa(i),this.renderer.debug.checkShaderErrors=Ye()||CA("checkshadererrors")===!0,this.renderer.toneMappingExposure=1,this.renderer.toneMapping=$g,this.renderer.setClearColor(new SA("lightgrey"),0),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=j0,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputColorSpace=ge,this.renderer.useLegacyLights=!1}internalOnUpdateVisible(){var t,A;(t=this._intersectionObserver)==null||t.disconnect(),(A=this._intersectionObserver)==null||A.observe(this.domElement)}updateSize(){var t,A,e;if(!this.isManagedExternally&&((t=this.renderer.xr)==null?void 0:t.isPresenting)===!1){this._sizeChanged=!1;const i=this.resolutionScaleFactor,g=this.domWidth*i,I=this.domHeight*i,o=this.mainCamera;this.updateAspect(o),this.renderer.setSize(g,I,!0),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((A=this.composer.setSize)==null||A.call(this.composer,g,I),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((e=this.composer.setPixelRatio)==null||e.call(this.composer,window.devicePixelRatio)))}}updateAspect(t,A,e){if(!t)return;A===void 0&&(A=this.domWidth),e===void 0&&(e=this.domHeight);const i=t.aspect;t.aspect=A/e,i!==t.aspect&&t.updateProjectionMatrix()}async onCreate(t){return this.create(t)}async create(t){try{return this._isCreating=!0,window.addEventListener("unhandledrejection",this.onUnhandledRejection),await this.internalOnCreate(t)}finally{window.removeEventListener("unhandledrejection",this.onUnhandledRejection),this._isCreating=!1}}clear(){var t,A,e,i;Gt.dispatchCallback(Wi.ContextClearing,this),Ys(this.scene,!0,!0),this.scene=new fI,(t=this.addressables)==null||t.dispose(),(A=this.lightmaps)==null||A.clear(),(i=(e=this.physics)==null?void 0:e.engine)==null||i.clearCaches(),this.isManagedExternally||this.renderer&&(this.renderer.renderLists.dispose(),this.renderer.state.reset(),this.renderer.resetState()),Gt.dispatchCallback(Wi.ContextCleared,this)}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var t,A;this.clear(),(t=this.renderer)==null||t.setAnimationLoop(null),this.renderer&&(this.renderer.setClearAlpha(0),this.renderer.clear()),this.isManagedExternally||this.renderer.dispose(),this.scene=null,this.renderer=null,this.input.dispose();for(const e of this._disposeCallbacks)try{e()}catch(i){console.error("Error in on dispose callback:",i,e)}(A=this.domElement)!=null&&A.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Gt.dispatchCallback(Wi.ContextDestroyed,this),Gt.unregister(this)}registerCoroutineUpdate(t,A,e){return typeof A?.next!="function"?(console.error("Registered invalid coroutine function from "+t.name+`
4290
+ Coroutine functions must be generators: "*myCoroutine() {...}"
4291
+ Start a coroutine from a component by calling "this.startCoroutine(myCoroutine())"`),A):(this.coroutines[e]||(this.coroutines[e]=[]),this.coroutines[e].push({comp:t,main:A}),A)}unregisterCoroutineUpdate(t,A){if(!this.coroutines[A])return;const e=this.coroutines[A].findIndex(i=>i.main===t);e>=0&&this.coroutines[A].splice(e,1)}stopAllCoroutinesFrom(t){for(const A in this.coroutines){const e=this.coroutines[A];for(let i=e.length-1;i>=0;i--)e[i].comp===t&&e.splice(i,1)}}setCurrentCamera(t){var A;if(!t)return;if(t.cam||t.buildCamera(),!t.cam){console.warn("Camera component is missing camera",t);return}const e=this._cameraStack.indexOf(t);e>=0&&this._cameraStack.splice(e,1),this._cameraStack.push(t),this.mainCameraComponent=t;const i=t.cam;i.isPerspectiveCamera&&this.updateAspect(i),(A=this.mainCameraComponent)==null||A.applyClearFlagsIfIsActiveCamera()}removeCamera(t){if(!t)return;const A=this._cameraStack.indexOf(t);if(A>=0&&this._cameraStack.splice(A,1),this.mainCameraComponent===t&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const e=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(e)}}addBeforeRenderListener(t,A){this._onBeforeRenderListeners.has(t.uuid)||(this._onBeforeRenderListeners.set(t.uuid,[]),t.onBeforeRender=this._createRenderCallbackWrapper(t,this._onBeforeRenderListeners)),this._onBeforeRenderListeners.get(t.uuid).push(A)}removeBeforeRenderListener(t,A){if(this._onBeforeRenderListeners.has(t.uuid)){const e=this._onBeforeRenderListeners.get(t.uuid),i=e.indexOf(A);i>=0&&e.splice(i,1)}}addAfterRenderListener(t,A){var e;this._onAfterRenderListeners.has(t.uuid)||(this._onAfterRenderListeners.set(t.uuid,[]),t.onAfterRender=this._createRenderCallbackWrapper(t,this._onAfterRenderListeners)),(e=this._onAfterRenderListeners.get(t.uuid))==null||e.push(A)}removeAfterRenderListener(t,A){if(this._onAfterRenderListeners.has(t.uuid)){const e=this._onAfterRenderListeners.get(t.uuid),i=e.indexOf(A);i>=0&&e.splice(i,1)}}_createRenderCallbackWrapper(t,A){return(e,i,g,I,o,s)=>{const C=A.get(t.uuid);if(C)for(let a=0;a<C.length;a++){const r=C[a];r(e,i,g,I,o,s)}}}get isRendering(){return this._isRendering}setRequireDepth(t){this._requireDepthTexture=t}setRequireColor(t){this._requireColorTexture=t}get depthTexture(){var t;return((t=this._renderTarget)==null?void 0:t.depthTexture)||null}get opaqueColorTexture(){var t;return((t=this._renderTarget)==null?void 0:t.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const t=getComputedStyle(this.domElement);return t.visibility!=="hidden"&&t.display!=="none"&&t.opacity!=="0"}async internalOnCreate(t){var A,e,i,g,I;const o=++this._createId;this.clear(),this.isManagedExternally===!1&&(this.createNewRenderer(),(A=this.renderer)==null||A.setAnimationLoop(null)),await za(1),Ii.Current=this,await Gt.dispatchCallback(Wi.ContextCreationStart,this);let s=!0,C;try{Ii.Current=this,t?C=await this.internalLoadInitialContent(o,t):C=[]}catch(r){console.error(r),s=!1}if(!s||o!==this._createId)return!1;if(this.internalOnUpdateVisible(),!this.renderer)return nn&&console.warn("Context has no renderer (perhaps it was disconnected?",this.domElement.isConnected),!1;!this.isManagedExternally&&!this.domElement.shadowRoot&&this.domElement.prepend(this.renderer.domElement),Ii.Current=this,Ii.Current=this;for(let r=0;r<this.new_scripts.length;r++){const B=this.new_scripts[r];if(B.gameObject!==void 0&&B.gameObject!==null){B.gameObject.userData===void 0&&(B.gameObject.userData={}),B.gameObject.userData.components===void 0&&(B.gameObject.userData.components=[]);const Q=B.gameObject.userData.components;Q.includes(B)||Q.push(B)}}if(this.post_setup_callbacks)for(let r=0;r<this.post_setup_callbacks.length;r++)Ii.Current=this,await this.post_setup_callbacks[r](this);if(!this.mainCamera){Ii.Current=this;let r=null;Tr(this.scene,B=>{const Q=B;if(Q!=null&&Q.isCamera){if(Yc(Q.gameObject),!Q.activeAndEnabled)return;if(Q.tag==="MainCamera")return r=Q,!0;r=Q}}),r?this.setCurrentCamera(r):!Gt.dispatchCallback(Wi.MissingCamera,this,{files:C})&&!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this)}if(Ii.Current=this,JD(this),this.physics.engine&&((e=this.physics.engine)==null||e.step(0),(i=this.physics.engine)==null||i.postStep()),!this.isManagedExternally&&this.composer&&this.mainCamera){const r=new YD(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(r),this.composer.setSize(this.domWidth,this.domHeight)}this._sizeChanged=!0,this._stats&&(this._stats.showPanel(0),(g=this.domElement.shadowRoot)==null||g.appendChild(this._stats.dom)),nn&&Wu(this.scene,!0),this.targetFrameRate===void 0?(nn&&console.warn("No target framerate set, using default",Ii.DefaultTargetFrameRate),this.targetFrameRate=Ii._defaultTargetFramerate):nn&&console.log("Target framerate set to",this.targetFrameRate),this._dispatchReadyAfterFrame=!0;const a=Gt.dispatchCallback(Wi.ContextCreated,this,{files:C});return a&&("internalSetLoadingMessage"in this.domElement&&typeof this.domElement.internalSetLoadingMessage=="function"&&((I=this.domElement)==null||I.internalSetLoadingMessage("finish loading")),await a),Hr(this,Wi.ContextCreated),this._isCreating=!1,this.isManagedExternally||this.restartRenderLoop(),a}async internalLoadInitialContent(t,A){var e,i;const g=new Array;if(A.files.length===0)return g;const I=[...A.files],o={name:"",progress:null,index:0,count:I.length},s=ns();let C=0;this.hash&&(C=Number.parseInt(this.hash)??0);for(let a=0;a<I.length;a++){if(t!==this._createId){nn&&console.log("Aborting loading because create id changed",t,this._createId);break}const r=I[a];if(!r.includes(".glb")&&!r.includes(".gltf")){const Q=`Needle Engine: found suspicious src "${r}"`;console.warn(Q),gI()&&ig(Q)}(e=A?.onLoadingStart)==null||e.call(this,a,r);const B=await s.loadSync(this,r,r,C,Q=>{var E;o.name=r,o.progress=Q,o.index=a,o.count=I.length,(E=A.onLoadingProgress)==null||E.call(this,o)});(i=A?.onLoadingFinished)==null||i.call(this,a,r,B??null),B?g.push({src:r,file:B}):console.warn("Could not load file: "+r)}if(t!==this._createId){for(const a of g)if(a&&a.file)for(const r of a.file.scenes)Ys(r,!0,!0)}else for(const a of g)a&&a.file&&this.scene.add(a.file.scene);return g}restartRenderLoop(){return this.renderer?this._isCreating?(console.warn("Can not start render loop while creating context"),!1):(this.renderer.setAnimationLoop((t,A)=>{this.isManagedExternally||this.update(t,A)}),!0):(console.error("Can not start render loop without renderer"),!1)}update(t,A){if(A===void 0&&(A=null),Ye()||nn||i5())try{this.internalStep(t,A),this._renderlooperrors=0}catch(e){this._renderlooperrors+=1,(Ye()||nn)&&(e instanceof Error||e instanceof TypeError)&&li("Caught unhandled exception during render-loop.<br/>Stopping renderloop...<br/>See console for details.",yo.Error),console.error(e),this._renderlooperrors>10&&(console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null)),this.domElement.dispatchEvent(new CustomEvent("error",{detail:e}))}else this.internalStep(t,A)}updatePhysics(t){this.internalUpdatePhysics(t)}internalStep(t,A){this.internalOnBeforeRender(t,A)!==!1&&(this.internalOnRender(),this.internalOnAfterRender())}internalOnBeforeRender(t,A){var e;if(this._xrFrame=A,this._currentFrameEvent=-1,this.isManagedExternally===!1&&this.isInXR===!1&&this.targetFrameRate!==void 0){this._lastTimestamp===0&&(this._lastTimestamp=t),this._accumulatedTime+=(t-this._lastTimestamp)/1e3,this._lastTimestamp=t;let i=this.targetFrameRate;if(typeof i=="object"&&(i=i.value),this._accumulatedTime<1/(i+1))return!1;this._accumulatedTime=0}if((e=this._stats)==null||e.begin(),Ii.Current=this,this.onHandlePaused())return!1;for(Ii.Current=this,this.time.update(),Y9&&console.log("FPS",this.time.smoothedFps.toFixed(0)),JD(this),vD(this.scene),nx(this),Hr(this,-1);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);const i=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(i)}if(this.pre_update_callbacks)for(const i in this.pre_update_callbacks)this.pre_update_callbacks[i]();this._currentFrameEvent=0;for(let i=0;i<this.scripts_earlyUpdate.length;i++){const g=this.scripts_earlyUpdate[i];g.activeAndEnabled&&g.earlyUpdate!==void 0&&(Ii.Current=this,g.earlyUpdate())}if(this.executeCoroutines(0),Hr(this,0),this.onHandlePaused())return!1;this._currentFrameEvent=1;for(let i=0;i<this.scripts_update.length;i++){const g=this.scripts_update[i];g.activeAndEnabled&&g.update!==void 0&&(Ii.Current=this,g.update())}if(this.executeCoroutines(1),Hr(this,1),this.onHandlePaused())return!1;this._currentFrameEvent=2;for(let i=0;i<this.scripts_lateUpdate.length;i++){const g=this.scripts_lateUpdate[i];g.activeAndEnabled&&g.lateUpdate!==void 0&&(Ii.Current=this,g.lateUpdate())}if(this.executeCoroutines(2),Hr(this,2),this.onHandlePaused()||(this.physicsSteps===void 0&&(this.physicsSteps=1),this.physics.engine&&this.physicsSteps>0&&this.internalUpdatePhysics(this.physicsSteps),this.onHandlePaused()))return!1;if(this.isVisibleToUser||this.runInBackground){this._currentFrameEvent=3;for(let i=0;i<this.scripts_onBeforeRender.length;i++){const g=this.scripts_onBeforeRender[i];g.activeAndEnabled&&g.onBeforeRender!==void 0&&(Ii.Current=this,g.onBeforeRender(A))}if(this.executeCoroutines(3),Hr(this,3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(const i in this.pre_render_callbacks)this.pre_render_callbacks[i]()}return!0}internalUpdatePhysics(t){if(!this.physics.engine)return!1;const A=t,e=this.time.deltaTime/A;for(let i=0;i<A;i++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(e),this._currentFrameEvent=10,this.executeCoroutines(10);return this.physics.engine.postStep(),!0}internalOnRender(){this.isManagedExternally||(o5(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4)}internalOnAfterRender(){if(this.isVisibleToUser||this.runInBackground){for(let t=0;t<this.scripts_onAfterRender.length;t++){const A=this.scripts_onAfterRender[t];A.activeAndEnabled&&A.onAfterRender!==void 0&&(Ii.Current=this,A.onAfterRender())}if(this.executeCoroutines(4),Hr(this,4),this.post_render_callbacks)for(const t in this.post_render_callbacks)this.post_render_callbacks[t]()}this._currentFrameEvent=-1,this.connection.sendBufferedMessagesNow(),this._stats&&(this._stats.end(),this.time.frameCount%150===0&&console.log({...this.renderer.info.memory},{...this.renderer.info.render})),this._dispatchReadyAfterFrame&&(this._dispatchReadyAfterFrame=!1,this.domElement.dispatchEvent(new CustomEvent("ready")),Gt.dispatchCallback(Wi.ContextFirstFrameRendered,this))}renderNow(t){return!t&&(t=this.mainCamera,!t)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):t&&this.renderer.render(this.scene,t),this._isRendering=!1,!0)}onHandlePaused(){const t=this.evaluatePaused();if(this._wasPaused!==t){T9&&console.log("Paused?",t,"context:"+this.alias);for(let A=0;A<this.scripts_pausedChanged.length;A++){const e=this.scripts_pausedChanged[A];e.activeAndEnabled&&e.onPausedChanged!==void 0&&(Ii.Current=this,e.onPausedChanged(t,this._wasPaused))}}return this._wasPaused=t,t}evaluatePaused(){return this.isInXR?!1:this.isPaused?!0:this.runInBackground?!1:!this.isVisibleToUser}renderRequiredTextures(){if(!this.mainCamera||!this._requireDepthTexture&&!this._requireColorTexture)return;if(!this._renderTarget){if(this._renderTarget=new $e(this.domWidth,this.domHeight),this._requireDepthTexture){const e=new jh(this.domWidth,this.domHeight);this._renderTarget.depthTexture=e}this._requireColorTexture&&(this._renderTarget.texture=new Je,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=xe,this._renderTarget.texture.magFilter=xe,this._renderTarget.texture.format=ft)}const t=this._renderTarget;t.texture&&(t.texture.colorSpace=this.renderer.outputColorSpace);const A=this.renderer.getRenderTarget();this.renderer.setRenderTarget(t),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(A)}executeCoroutines(t){var A;if(this.coroutines[t]){const i=this.coroutines[t];for(let g=0;g<i.length;g++)try{const I=i[g];if(!I.comp||I.comp.destroyed||!I.main||I.comp.enabled===!1){H9&&console.log("Removing coroutine",I.comp,I.comp.enabled),i.splice(g,1),--g;continue}const o=I.chained;if(o&&o.length>0){const a=o[o.length-1].next();if(a.done&&o.pop(),e(a)&&(I.chained||(I.chained=[]),I.chained.push(a.value)),!a.done)continue}const s=I.main.next();if(s.done===!0){i.splice(g,1),--g;continue}const C=s.value;if(e(C)){if(C.next().done)continue;I.chained||(I.chained=[]),I.chained.push(C)}else if(C instanceof Promise){const a=C;I.chained||(I.chained=[]);const r=dT(a);(A=I.chained)==null||A.push(r);continue}}catch(I){console.error(I)}}function e(i){return!!(i&&i.next&&i.return)}}};let qe=Ii;n(qe,"_defaultTargetFramerate",{value:60}),n(qe,"_defaultWebglRendererParameters",{antialias:!0,alpha:!1});const Xc=CA("debugoverlay"),pT="ar",P9="quit-ar";class j9{constructor(){n(this,"arContainer",null),n(this,"currentSession",null),n(this,"_createdAROnlyElements",[]),n(this,"_reparentedObjects",[]),n(this,"contentElement",null),n(this,"requestEndAR",()=>{this.onRequestedEndAR()})}get ARContainer(){return this.arContainer}onBegin(A,e,i){var g;if(this.currentSession=i,this.arContainer=e,Tu()){const I=A.domElement.children;for(let o=0;o<I?.length;o++){const s=I[o];if(!s||s===this.arContainer)return;this._reparentedObjects.push({el:s,previousParent:s.parentElement}),(g=this.arContainer)==null||g.appendChild(s)}}this.ensureQuitARButton(this.arContainer)}onEnd(A){var e;for(const i of this._createdAROnlyElements)i.remove&&i.remove();for(const i of this._reparentedObjects){const g=i.el;(e=i.previousParent)==null||e.appendChild(g)}this._reparentedObjects.length=0,Tu()&&setTimeout(()=>{var i;const g=A.renderer.domElement;g&&((i=A.domElement.shadowRoot)==null||i.prepend(g));const I=document.querySelectorAll("*");for(var o=0;o<I.length;o++){const s=I[o];s&&s._displayChanged!==void 0&&s._displayWas!==void 0&&(s.style.display=s._displayWas)}},10)}createOverlayContainer(A){if(this.contentElement)return this.contentElement;Xc&&console.log("Setup overlay container");const e=A.shadowRoot.querySelector(".content");this.contentElement=e;const i=A.shadowRoot.querySelector(".overlay-content");return i&&e.appendChild(i),Xc&&!FC()&&this.ensureQuitARButton(e),e}onRequestedEndAR(){this.currentSession&&(this.currentSession.end(),this.currentSession=null)}ensureQuitARButton(A){const e=document.createElement("slot");e.setAttribute("name","quit-ar"),this.appendElement(e,A),this._createdAROnlyElements.push(e),e.style.pointerEvents="auto";const i=document.querySelector(`.${P9}`);if(i){i.addEventListener("click",this.requestEndAR),Xc&&i.addEventListener("click",()=>console.log("Clicked quit-ar button"));return}e.addEventListener("click",this.requestEndAR),Xc&&e.addEventListener("click",()=>console.log("Clicked fallback close button"));const g=document.createElement("div");g.style.cssText=`
4290
4292
  position: fixed;
4291
4293
  top: 0;
4292
4294
  right: 0;
@@ -4915,7 +4917,7 @@ void main() {
4915
4917
  `&&t.length>1&&RH([e],t[t.length-2]),A.offsetX}function OeA(t){if(!t[0])return 0;let A=[],e;for(let i=0;i<t.length;i++){const g=t[i];if(g.char&&GH[g.char]&&t.length>i){A.push(g),e=t[i+1];continue}break}UH(A,e),A=[],e=null;for(let i=t.length-1;i>0;i--){const g=t[i];if(g.char&&GH[g.char]&&i>0){A.push(g),e=t[i-1];continue}break}return RH(A,e),t[0].offsetX}function _eA(t){return t[0]?t[0].offsetX:0}function RH(t,A){if(A)for(let e=0;e<t.length;e++){const i=t[e];i.fontFactor=0,i.offsetX=A.offsetX+A.cumulativeWidth,i.cumulativeWidth=0}}function UH(t,A){if(A)for(let e=0;e<t.length;e++){const i=t[e];i.fontFactor=0,i.offsetX=A.offsetX,i.cumulativeWidth=0}}function NH(t,A,e,i){if(i=i||0,!t[A])return i;const g=t[A];return g.lineBreak?i+g.xadvance:NH(t,A+1,e,i+g.xadvance+g.xoffset+g.kerning+e.LETTERSPACING)}function PeA(t,A,e,i){return!t||!t.char||A+e<i.INNER_WIDTH?!1:i.BREAKON.indexOf(t.char)>-1}class FH extends RY{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._fontSize._needsProcess=!0,A._layouter._needsProcess=!0}}class KH extends jt{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(A){this._value=this._inheritedInput,A._font._fontVariant&&(A._bounds._needsProcess=!0,A._layouter._needsProcess=!0)}process(A){if(!A._font._fontVariant||!A._font._fontVariant.isReady)return;const e=this._value/A._font._fontVariant.typographic.size,i=A._inlines._value;for(let g=0;g<i.length;g++){const I=i[g];I.resetOffsets(),I.fontSize=this._value,I.fontFactor=e}}get value(){return this._value}}class JH extends UY{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(A,e){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(A)),A._layouter._needsUpdate=!0}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class jeA extends JH{constructor(){super(),this._value="inherit"}}class WeA extends pw{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A),A._parent._value._layouter._needsProcess=!1}process(A){if(this._value!=="none"){const e=A._whiteSpace._whiteSpacedContent,i=A._inlines._value;for(let g=1;g<i.length;g++){const I=e[g-1]+e[g];i[g].kerning=A._font._fontVariant.getKerningAmount(I)}}}}class vH extends dt{constructor(){super("children",null,!1),this._uis=[]}update(A,e){}process(A){}_compute(A){}dispose(){}}function VeA(t,A=!1){const e=t[0].index!==null,i=new Set(Object.keys(t[0].attributes)),g=new Set(Object.keys(t[0].morphAttributes)),I={},o={},s=t[0].morphTargetsRelative,C=new _A.BufferGeometry;let a=0;for(let r=0;r<t.length;++r){const B=t[r];let Q=0;if(e!==(B.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+r+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const E in B.attributes){if(!i.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+r+'. All geometries must have compatible attributes; make sure "'+E+'" attribute exists among all geometries, or in none of them.'),null;I[E]===void 0&&(I[E]=[]),I[E].push(B.attributes[E]),Q++}if(Q!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+r+". Make sure all geometries have the same number of attributes."),null;if(s!==B.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+r+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const E in B.morphAttributes){if(!g.has(E))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+r+". .morphAttributes must be consistent throughout all geometries."),null;o[E]===void 0&&(o[E]=[]),o[E].push(B.morphAttributes[E])}if(C.userData.mergedUserData=C.userData.mergedUserData||[],C.userData.mergedUserData.push(B.userData),A){let E;if(e)E=B.index.count;else if(B.attributes.position!==void 0)E=B.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+r+". The geometry must have either an index or a position attribute"),null;C.addGroup(a,E,r),a+=E}}if(e){let r=0;const B=[];for(let Q=0;Q<t.length;++Q){const E=t[Q].index;for(let h=0;h<E.count;++h)B.push(E.getX(h)+r);r+=t[Q].attributes.position.count}C.setIndex(B)}for(const r in I){const B=qH(I[r]);if(!B)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+r+" attribute."),null;C.setAttribute(r,B)}for(const r in o){const B=o[r][0].length;if(B===0)break;C.morphAttributes=C.morphAttributes||{},C.morphAttributes[r]=[];for(let Q=0;Q<B;++Q){const E=[];for(let d=0;d<o[r].length;++d)E.push(o[r][d][Q]);const h=qH(E);if(!h)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+r+" morphAttribute."),null;C.morphAttributes[r].push(h)}}return C}function qH(t){let A,e,i,g=0;for(let s=0;s<t.length;++s){const C=t[s];if(C.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(A===void 0&&(A=C.array.constructor),A!==C.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=C.itemSize),e!==C.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(i===void 0&&(i=C.normalized),i!==C.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;g+=C.array.length}const I=new A(g);let o=0;for(let s=0;s<t.length;++s)I.set(t[s].array,o),o+=t[s].array.length;return new _A.BufferAttribute(I,e,i)}class zeA extends dt{constructor(){super("renderer")}render(A){if(!A._inlines._value||!A._inlines._value.length)return;const e=A._inlines._value.map(g=>A._font._fontVariant.getGeometricGlyph(g,A).translate(g.offsetX,g.offsetY,0)),i=VeA(e);A.setFontMesh(new _A.Mesh(i,A.fontMaterial)),A._fontMesh.renderOrder=1/0}}class ZeA extends qM{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(A){this._value=this._inheritedInput,A._layouter._needsProcess=!0}}class dh extends El{constructor(A={}){const e={};dh.definePropertiesValues(e,A),super(e,A),n(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0}),dh.init(this)}add(A){const e=[];for(let i=0;i<arguments.length;i++){const g=arguments[i];!g.isUI||g.isInline?(e.push(g),g.position.z=.005):console.warn("Block element can only contain Box elements.",g)}return super.add(...e)}set textContent(A){this._textContent.value=A}get textContent(){return this._textContent._value}set invertAlpha(A){this._invertAlpha.value=A}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(A,e){A.children||(A.children=vH),A.textContent||(A.textContent=NeA),A.glyphs||(A.glyphs=KeA),A.inlines||(A.inlines=FeA),A.layouter||(A.layouter=SH),A.renderer||(A.renderer=zeA),A.fontFamily||(A.fontFamily=kH),A.fontWeight||(A.fontWeight=mH),A.fontStyle||(A.fontStyle=fH),A.fontSize||(A.fontSize=KH),A.color||(A.color=JeA),A.backgroundColor||(A.backgroundColor=veA),A.lineBreak||(A.lineBreak=yH),A.letterSpacing||(A.letterSpacing=FH),A.whiteSpace||(A.whiteSpace=lR),A.segments||(A.segments=jeA),A.textAlign||(A.textAlign=ZeA),A.fontKerning||(A.fontKerning=WeA)}static init(A){Object.defineProperties(A,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class XeA extends dY{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(A){this._value!==A&&(this._value=A,this._needsUpdate=!0)}update(A,e){this._needsUpdate=!1;for(let i=A.children.length-1;i>=0;i--){const g=A.children[i];g.isUI&&(A.remove(g),g.clear())}A._children._uis=[],this._value&&A.add(new dh({name:"anonymousInline",textContent:this._value}))}}class $eA extends Array{constructor(...A){super(...A),this.width=0,this.height=0}}class AtA extends dt{constructor(){super("layouter",null,!1),this._value=null}update(A,e){}process(A){let e=A._width._value;A._width._auto?e=1/0:e=A._bounds._innerWidth;const i=A._lineHeight._value,g=new $eA(new wH);let I=0;A._children._inlines.forEach(B=>{if(!B._inlines.value)return;this._resetInlines(B);const Q=B._fontSize._value,E=B._letterSpacing._value*Q,h=B._whiteSpace._value,d=B._lineBreak._value,l={WHITESPACE:h,LETTERSPACING:E,BREAKON:d,INNER_WIDTH:e},c=B._whiteSpace._inlineWrapper;I+=B._margin._value.w+B._padding._value.w,B._inlines.value.forEach((u,p,D)=>{const S=g[g.length-1];if(c(D,p,I,l)){if(g.push(new wH(u)),u.offsetX=u.xoffset,u.width===0){I=0;return}u.cumulativeWidth=u.xadvance+E,I=u.cumulativeWidth;return}g[g.length-1].push(u),u.offsetX=I+u.xoffset+u.kerning,u.cumulativeWidth=u.xadvance+u.kerning+E,I+=u.cumulativeWidth,S.length-1===1&&S[S.length-2].width===0&&(u.offsetX-=u.xoffset,I-=u.xoffset)}),I+=B._margin._value.y+B._padding._value.y});const o=A._whiteSpace._inlineCollapser;let s=0,C=0,a=0;g.forEach((B,Q)=>{const E=o(B);let h=0,d=0;if(B.forEach(l=>{h=Math.max(h,l.lineHeight),d=Math.max(d,l.lineBase),l.offsetX-=E}),B.lineHeight=h,B.lineBase=d,Q===0?a=-(h*i-h)*.5:a-=g[Q-1].lineHeight*i,B.y=a,B.x=0,B.forEach(l=>{l.offsetY=a-l.anchor,l.lineHeight<B.lineHeight&&(l.offsetY-=B.lineBase-l.lineBase)}),C+=B.lineHeight*i,B.width=0,B[0]){const l=B[B.length-1];B.width=l.offsetX+l.cumulativeWidth+l.paddingRight+l.marginRight+B[0].offsetX,s=Math.max(s,B.width)}}),g.height=C,g.width=s,this._value=g,e===1/0&&A._bounds.setChildrenWidth(A,g.width),A._height._auto&&A._bounds.setChildrenHeight(A,g.height);const r=A._parent._value;r&&(r._autoSize._needsProcess=!0,r._flexDirection._needsProcess=!0),A._inlineJustificator._needsProcess=!0,A._textAlign._needsProcess=!0,A._overflow._needsUpdate=!0}_resetInlines(A){A._fontSize.process(A)}}class etA extends qM{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput,this._needsProcess=!0}process(A){ttA(A),A._renderer._needsRender=!0}}function ttA(t){const A=t._layouter._value,e=t._textAlign._value,i=t._bounds._innerWidth;for(let g=0;g<A.length;g++){const I=A[g],o=itA(t,I,g===A.length-1),s=t._padding._value,C=t._borderWidth._value,a=(-s.w+s.y)/2+(-C.w+C.y)/2;I.x+=o;for(let r=0;r<I.length;r++)I[r].offsetX+=o-a}if(e.indexOf("justify")===0)for(let g=0;g<A.length;g++){const I=A[g];if(e.indexOf("-")!==-1&&g===A.length-1)return;const o=i-I.width;if(o<=0)return;let s=0;for(let B=1;B<I.length-1;B++)s+=I[B].char===" "?1:0;const C=o/s;let a=1;e==="justify-right"&&(I.reverse(),a=-1);let r=0;for(let B=1;B<=I.length-1;B++){const Q=I[B];Q.offsetX+=r*a,r+=Q.char===" "?C:0}e==="justify-right"&&I.reverse()}}function itA(t,A,e){switch(t._textAlign._value){case"justify-left":case"justify":case"left":return-t._bounds._innerWidth/2;case"justify-right":case"right":return-A.width+t._bounds._innerWidth/2;case"center":return-A.width/2;case"justify-center":return e?-A.width/2:-t._bounds._innerWidth/2;default:console.warn(`textAlign: '${t._textAlign._value}' is not valid`)}}class gtA extends bM{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(A){this._value=this._inheritedInput}}class ItA extends GY{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class otA extends pw{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(A){super._computeFromInherited(A)}}class stA extends dH{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class CtA extends dt{constructor(){super("children",null,!1),n(this,"_sortOrder",(A,e)=>A._order._value<e._order._value?-1:A._order._value>e._order._value?1:this._uis.indexOf(A)<this._uis.indexOf(e)?-1:1),this._uis=[],this._inlines=[],this._boxes=[]}update(A,e){this._compute(A),this._needsProcess=!0}process(A){this._compute(A),A._overflow._needsRender=!0}_compute(A){this._uis=A.children.filter(e=>e.visible&&e.isUI),this._inlines=this._uis.filter(e=>e.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class atA extends dt{constructor(){super("autosize")}process(A){if(A._layouter._value&&A._layouter._value.length){const e=A._layouter._value,i=A._padding._value,g=A._borderWidth._value;A._width._auto&&A._bounds.setOffsetWidth(A,e.width+i.w+i.y+g.w+g.y),A._height._auto&&A._bounds.setOffsetHeight(A,e.height+i.x+i.z+g.x+g.z)}}}class ntA extends DH{constructor(){super("renderer"),this._needsUpdate=!1}render(A){super.render(A);for(const e of A._children._inlines)e._renderer.render(e);A.performAfterUpdate()}}class Ip extends ip{constructor(A={},e={}){Ip.definePropertiesValues(e,A),super(e,A),Ip.init(this)}add(A){const e=[];let i=!1;for(let g=0;g<arguments.length;g++){const I=arguments[g];!I.isUI||I.isInline?(I.isInline&&(i=!0),e.push(I)):console.warn("Block element can only contain Box elements.",I)}return e.length>0&&super.add(...e),i&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(A){this._textContent.value=A}get textContent(){return super.textContent}set invertAlpha(A){this._invertAlpha.value=A}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(A,e){A.flexDirection=gtA,A.justifyContent=LM,A.alignItems=vM,A.bounds=stA,A.autoSize=atA,A.renderer=ntA,A.children||(A.children=CtA),A.textContent||(A.textContent=XeA),A.layouter||(A.layouter=AtA),A.lineHeight||(A.lineHeight=ItA),A.textAlign||(A.textAlign=etA),A.whiteSpace||(A.whiteSpace=lR),A.fontKerning||(A.fontKerning=otA),A.segments||(A.segments=JH),e.width||(e.width="100%"),e.fontSide||(e.fontSide=0)}static init(A){Object.defineProperties(A,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class rtA extends dt{constructor(){super("inlines",null,!1),this._value=[]}process(A){this._value[0].paddingLeft=A._padding._value.w,this._value[0].marginLeft=A._margin._value.w;const e=this._value.length-1;this._value[e].paddingRight=A._padding._value.y,this._value[e].marginRight=A._margin._value.y}}class BtA extends dt{constructor(){super("renderer")}render(A){A._backgroundMesh||A.setBackgroundMesh(new uH(A)),A._backgroundMesh.position.x=A._inlines._value[0].offsetX+A._inlines._value[0].width/2,A._backgroundMesh.position.y=A._inlines._value[0].offsetY+A._inlines._value[0].lineBase/2,A._bounds.render(A)}}class QtA extends dt{constructor(){super("bounds",null,!1),this._size=new _A.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(A,e){this.output(e),this._needsProcess=!0}process(A){this._offsetWidth=this._innerWidth=A._inlines._value[0].width,this._offsetHeight=this._innerHeight=A._inlines._value[0].height,this._needsRender=!0,A._borderWidth._needsRender=!0,A._borderRadius._needsRender=!0}render(A){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(A){A.size=this._size}}class op extends El{constructor(A={}){const e={};op.definePropertiesValues(e,A),super(e,A),op.init(this)}clear(){for(const A of this._inlines._value)A.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new _A.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(A){const e=[];for(let i=0;i<arguments.length;i++){const g=arguments[i];g.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",g):(e.push(g),g.position.z=.005)}return super.add(...e)}static definePropertiesValues(A,e){A.children||(A.children=vH),A.bounds||(A.bounds=QtA),A.inlines||(A.inlines=rtA),A.layouter||(A.layouter=SH),A.renderer||(A.renderer=BtA),A.fontFamily||(A.fontFamily=kH),A.fontWeight||(A.fontWeight=mH),A.fontStyle||(A.fontStyle=fH),A.fontSize||(A.fontSize=KH),A.backgroundColor||(A.backgroundColor=hY),A.lineBreak||(A.lineBreak=yH),A.letterSpacing||(A.letterSpacing=FH),A.whiteSpace||(A.whiteSpace=lR),A.fontKerning||(A.fontKerning=pw),e.backgroundSize||(e.backgroundSize="cover"),e.width||(e.width="100%"),e.height||(e.height="100%"),e.boxSizing||(e.boxSizing="border-box")}static init(A){Object.defineProperties(A,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),A._inlines._value=[new EtA(A)],A.backgroundMaterial=new lH,A._renderer.render(A)}}class EtA extends yY{constructor(A){super(),this._uiElement=A}get xadvance(){const A=this._uiElement._padding._value,e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.w+A.y+e.value}get width(){const A=this._uiElement._width;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get height(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get anchor(){return this.height}get lineHeight(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}get lineBase(){const A=this._uiElement._height;return A._relative?A._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):A.value}clear(){this._uiElement=null}}class bH{constructor(A){this._subject=A}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const LH=()=>Gw.update(),xH={BaseProperty:dt,Block:gp,Text:Ip,Inline:dh,InlineBlock:op,MeshUIBaseElement:El,FontLibrary:zr,update:LH,MSDFFontMaterialUtils:Vo,ShaderChunkUI:cH,Behavior:bH,FontVariant:ol};typeof global<"u"&&(global.ThreeMeshUI=xH);const htA=xH;var ctA=Ji.w8,TH=Ji.cg,dR=Ji.gO,ltA=Ji.wb,pR=Ji.zV,dtA=Ji.HS,ptA=Ji.Ec,Rw=Ji.gF,utA=Ji.ol,DtA=Ji.pz,wtA=Ji.tx,ytA=Ji.hj,StA=Ji.FV,ftA=Ji.sV,uR=Ji.xv,mtA=Ji.mx,ktA=Ji.gE,AE=Ji.ZP,YH=Ji.Vx;const DR=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:ctA,Behavior:TH,Block:dR,DefaultValues:ltA,FontLibrary:pR,FontVariant:dtA,InheritableProperty:ptA,Inline:Rw,InlineBlock:utA,InlineGlyph:DtA,MSDFFontMaterialUtils:wtA,MaterialTransformers:ytA,MeshUIBaseElement:StA,ShaderChunkUI:ftA,Text:uR,TypographicFont:mtA,TypographicGlyph:ktA,default:AE,update:YH},Symbol.toStringTag,{value:"Module"})),BI=new y,HH=new y,OH=new UA,GtA=CA("debuggizmos"),ta=8947848;class Ws{static DrawLabel(A,e,i=.1,g=9999,I,o,s){I||(I=ta);const C=vi.getTextLabel(g,e,i,I,o);return s instanceof fA&&s.add(C),C.position.x=A.x,C.position.y=A.y,C.position.z=A.z,C}static DrawRay(A,e,i=ta,g=0,I=!0){const o=vi.getLine(g),s=o.geometry.getAttribute("position");s.setXYZ(0,A.x,A.y,A.z),BI.set(e.x,e.y,e.z).multiplyScalar(999999999),s.setXYZ(1,A.x+BI.x,A.y+BI.y,A.z+BI.z),s.needsUpdate=!0,o.material.color.set(i),o.material.depthTest=I,o.material.depthWrite=!1}static DrawDirection(A,e,i=ta,g=0,I=!0,o=1){const s=vi.getLine(g),C=s.geometry.getAttribute("position");C.setXYZ(0,A.x,A.y,A.z),e.w!==void 0?(BI.set(0,0,-o),OH.set(e.x,e.y,e.z,e.w),BI.applyQuaternion(OH)):(BI.set(e.x,e.y,e.z),BI.multiplyScalar(o)),C.setXYZ(1,A.x+BI.x,A.y+BI.y,A.z+BI.z),C.needsUpdate=!0,s.material.color.set(i),s.material.depthTest=I,s.material.depthWrite=!1}static DrawLine(A,e,i=ta,g=0,I=!0){const o=vi.getLine(g),s=o.geometry.getAttribute("position");s.setXYZ(0,A.x,A.y,A.z),s.setXYZ(1,e.x,e.y,e.z),s.needsUpdate=!0,o.material.color.set(i),o.material.depthTest=I,o.material.depthWrite=!1}static DrawWireSphere(A,e,i=ta,g=0,I=!0){const o=vi.getSphere(e,g,!0);Ur(o,A.x,A.y,A.z),o.material.color.set(i),o.material.depthTest=I,o.material.depthWrite=!1}static DrawSphere(A,e,i=ta,g=0,I=!0){const o=vi.getSphere(e,g,!1);Ur(o,A.x,A.y,A.z),o.material.color.set(i),o.material.depthTest=I,o.material.depthWrite=!1}static DrawWireBox(A,e,i=ta,g=0,I=!0){const o=vi.getBox(g);o.position.set(A.x,A.y,A.z),o.scale.set(e.x,e.y,e.z),o.material.color.set(i),o.material.depthTest=I,o.material.wireframe=!0,o.material.depthWrite=!1}static DrawWireBox3(A,e=ta,i=0,g=!0){const I=vi.getBox(i);I.position.copy(A.getCenter(BI)),I.scale.copy(A.getSize(BI)),I.material.color.set(e),I.material.depthTest=g,I.material.wireframe=!0,I.material.depthWrite=!1}static DrawArrow(A,e,i=ta,g=0,I=!0,o=!1){const s=vi.getArrowHead(g);s.position.set(e.x,e.y,e.z),s.quaternion.setFromUnitVectors(this._up.set(0,1,0),BI.set(e.x,e.y,e.z).sub(HH.set(A.x,A.y,A.z)).normalize());const C=BI.set(e.x,e.y,e.z).sub(HH.set(A.x,A.y,A.z)).length()*.1;s.scale.set(C,C,C),s.material.color.set(i),s.material.depthTest=I,s.material.wireframe=o,this.DrawLine(A,e,i,g,I)}}n(Ws,"_up",new y(0,1,0));const MtA=new vt(1,1,1);function _H(t=null){const A=new SA(t??14540253),e=new Nm(MtA);return new jI(e,new Ei({color:A}))}const PH=Symbol("GizmoCache");class vi{static ensureFont(){let A=AE.FontLibrary.getFontFamily(this.familyName);if(!A){A=AE.FontLibrary.addFontFamily(this.familyName);const e=A.addVariant("normal","normal","./include/needle/arial-msdf.json","./include/needle/arial.png");e?.addEventListener("ready",()=>{AE.update()})}}static getTextLabel(A,e,i,g,I){this.ensureFont();let o=this.textLabelCache.pop(),s=1;I&&typeof I=="string"&&I?.length>=8&&I.startsWith("#")?(s=parseInt(I.substring(7),16)/255,I=I.substring(0,7),GtA&&console.log(I,s)):typeof I=="object"&&I.a!==void 0&&(s=I.a);const C={boxSizing:"border-box",fontFamily:this.familyName,width:"auto",fontSize:i,color:g,lineHeight:.75,backgroundColor:I??void 0,backgroundOpacity:s,textContent:e,borderRadius:1*i,padding:1*i};if(o)o.set(C);else{o=new uR(C);const a=this,r=o;r.setText=function(B){this.set({textContent:B,whiteSpace:"pre"}),a.tmuiNeedsUpdate=!0}}return this.tmuiNeedsUpdate=!0,o.layers.disableAll(),o.layers.enable(2),this.registerTimedObject(qe.Current,o,A,this.textLabelCache),o}static getBox(A){let e=this.boxesCache.pop();if(!e){const i=new vt(1,1,1);e=new uA(i)}return this.registerTimedObject(qe.Current,e,A,this.boxesCache),e}static getLine(A){let e=this.linesCache.pop();if(!e){e=new hi;let i=e.geometry.getAttribute("position");i||(i=new te(new Float32Array(2*3),3),e.geometry.setAttribute("position",i))}return this.registerTimedObject(qe.Current,e,A,this.linesCache),e}static getSphere(A,e,i){let g=this.spheresCache.pop();return g||(g=new uA(new jo(1,8,8))),g.scale.set(A,A,A),g.material.wireframe=i,this.registerTimedObject(qe.Current,g,e,this.spheresCache),g}static getArrowHead(A){let e=this.arrowHeadsCache.pop();return e||(e=new uA(new Gi(0,.5,1,8))),this.registerTimedObject(qe.Current,e,A,this.arrowHeadsCache),e}static registerTimedObject(A,e,i,g){if(!this.contextPostRenderCallbacks.get(A)){const I=()=>{this.onPostRender(A,this.timedObjectsBuffer,this.timesBuffer)};this.contextPostRenderCallbacks.set(A,I),A.post_render_callbacks.push(I)}if(!this.contextBeforeRenderCallbacks.get(A)){const I=()=>{this.onBeforeRender(A,this.timedObjectsBuffer)};this.contextBeforeRenderCallbacks.set(A,I),A.pre_render_callbacks.push(I)}e.layers.disableAll(),e.layers.enable(2),e[PH]=g,this.timedObjectsBuffer.push(e),this.timesBuffer.push(qe.Current.time.time+i),A.scene.add(e)}static onBeforeRender(A,e){this.tmuiNeedsUpdate&&AE.update();for(let i=0;i<e.length;i++){const g=e[i];if(A.mainCamera&&g instanceof AE.MeshUIBaseElement){const I=A.isInVR,o=I,s=!I;uk(g,A.mainCamera,o,s)}}}static onPostRender(A,e,i){const g=A.time.time;for(let I=0;I<e.length;I++){const o=e[I];g>i[I]&&(o[PH].push(o),o.removeFromParent(),e.splice(I,1),i.splice(I,1))}}}n(vi,"familyName","needle-gizmos"),n(vi,"linesCache",[]),n(vi,"spheresCache",[]),n(vi,"boxesCache",[]),n(vi,"arrowHeadsCache",[]),n(vi,"textLabelCache",[]),n(vi,"timedObjectsBuffer",new Array),n(vi,"timesBuffer",new Array),n(vi,"contextPostRenderCallbacks",new Map),n(vi,"contextBeforeRenderCallbacks",new Map),n(vi,"tmuiNeedsUpdate",!1);const RtA=CA("gizmos"),UtA=CA("debugboxhelper"),ps=class extends JA{constructor(){super(...arguments),n(this,"box",null),n(this,"_lastMatrixUpdateFrame",-1),n(this,"_helper",null),n(this,"_color",null)}isInBox(t,A){var e;if(!t)return;if(this.box||(this.box=new Ni),t.type==="Mesh")ps.testBox.setFromObject(t);else if(t.type==="Group"){if(ps.testBox.makeEmpty(),t.children.length>0)for(let g=0;g<t.children.length;g++)t.children[g].type==="Mesh"&&ps.testBox.expandByObject(t)}else{const g=he(t,ps._position),I=gg(t,ps._size);A!==void 0&&I.multiplyScalar(A),ps.testBox.setFromCenterAndSize(g,I)}this.updateBox();const i=(e=this.box)==null?void 0:e.intersectsBox(ps.testBox);return i&&UtA&&Ws.DrawWireBox3(ps.testBox,16711680,5),i}intersects(t){return t?this.updateBox(!1).intersectsBox(t):!1}updateBox(t=!1){if(this.box||(this.box=new Ni),t||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const A=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const e=A,i=he(this.gameObject,ps._position,e),g=gg(this.gameObject,ps._size);this.box.setFromCenterAndSize(i,g)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(t=null,A=!1){var e;if(!(!RtA&&!A)){if(this._helper){t&&((e=this._color)==null||e.set(t)),this.gameObject.add(this._helper);return}this._helper=_H(t),this.gameObject.add(this._helper)}}};let Vs=ps;n(Vs,"testBox",new Ni),n(Vs,"_position",new y),n(Vs,"_size",new y(.01,.01,.01));var NtA=Object.defineProperty,FtA=Object.getOwnPropertyDescriptor,jH=(t,A,e,i)=>{for(var g=i>1?void 0:i?FtA(A,e):A,I=t.length-1,o;I>=0;I--)(o=t[I])&&(g=(i?o(A,e,g):o(g))||g);return i&&g&&NtA(A,e,g),g};const hl=CA("debugreflectionprobe"),WH=CA("noreflectionprobe"),KtA=Symbol("reflectionProbeKey"),JtA=Symbol("original material");var Uw;const ia=(Uw=class extends JA{constructor(){var t;super(),n(this,"_texture"),n(this,"center"),n(this,"size"),n(this,"_boxHelper"),ia._probes.has(this.context)||ia._probes.set(this.context,[]),(t=ia._probes.get(this.context))==null||t.push(this)}static get(t,A,e,i){if(!t||t.isObject3D!==!0||WH)return null;const g=ia._probes.get(A);if(g){for(const I of g)if(I.__didAwake||I.__internalAwake(),I.enabled){if(i){if(I.gameObject===i)return I}else if(I.isInBox(t,void 0))return hl&&console.log("Found reflection probe",t.name,I.name),I}}return hl&&console.debug("Did not find reflection probe",t.name,e,t),null}set texture(t){if(t&&!(t instanceof Je)){console.error("ReflectionProbe.texture must be a Texture",t);return}this._texture=t,t&&(t.mapping=Eo,t.colorSpace=ge,t.needsUpdate=!0)}get texture(){return this._texture}isInBox(t,A){var e;return(e=this._boxHelper)==null?void 0:e.isInBox(t,A)}awake(){this._boxHelper=this.gameObject.addNewComponent(Vs),this._boxHelper.updateBox(!0),hl&&this._boxHelper.showHelper(5592320,!0),this.texture&&(this.texture.mapping=Eo,this.texture.colorSpace=ge,this.texture.needsUpdate=!0)}onDestroy(){const t=ia._probes.get(this.context);if(t){const A=t.indexOf(this);A>=0&&t.splice(A,1)}}onSet(t){var A;if(WH||!this.enabled||((A=t.sharedMaterials)==null?void 0:A.length)<=0||!this.texture)return;let e=ia._rendererMaterialsCache.get(t);e||(e=[],ia._rendererMaterialsCache.set(t,e));for(let i=0;i<t.sharedMaterials.length;i++){const g=t.sharedMaterials[i];if(!g||g.envMap===void 0)continue;let I=e[i];const o=g===I?.copy,s=!I||I.material.uuid!==g.uuid||I.copy.version!==g.version;if(!o&&s){if(hl){let r="";I?I.material!==g?r="reference changed; cached instance?: "+o:I.copy.version!==g.version&&(r="version changed"):r="not cached",console.warn("Cloning material",g.name,g.version,"Reason:",r,`
4916
4918
  `,g.uuid,`
4917
4919
  `,I?.copy.uuid,`
4918
- `,t.name)}const a=g.clone();a.version=g.version,I?(I.copy=a,I.material=g):(I={material:g,copy:a},e.push(I)),a[KtA]=this,a[JtA]=g,hl&&console.log("Set reflection",t.name,t.guid)}const C=I?.copy;C.envMap=this.texture,t.sharedMaterials[i]=C}}onUnset(t){const A=ia._rendererMaterialsCache.get(t);if(A)for(let e=0;e<A.length;e++){const i=A[e];t.sharedMaterials[e]=i.material}}},n(Uw,"_probes",new Map),n(Uw,"_rendererMaterialsCache",new Map),Uw);let eE=ia;jH([w(y)],eE.prototype,"center",2),jH([w(y)],eE.prototype,"size",2);const VH=Symbol("customVisibilityFlag");function Nw(t,A){t.layers[VH]=A}const zH=Symbol("DidPatchLayers");function vtA(){const t=Lg.prototype;if(t[zH])return;t[zH]=!0;const A=t.test;t.test=function(e){return this[VH]===!1?!1:A.call(this,e)}}vtA();var qtA=Object.defineProperty,btA=Object.getOwnPropertyDescriptor,ga=(t,A,e,i)=>{for(var g=i>1?void 0:i?btA(A,e):A,I=t.length-1,o;I>=0;I--)(o=t[I])&&(g=(i?o(A,e,g):o(g))||g);return i&&g&&qtA(A,e,g),g};const Fw=CA("debugrenderer"),LtA=CA("debugskinnedmesh"),ZH=CA("noInstancing"),wR=CA("debuginstancing"),xtA=CA("debugprogressive"),TtA=CA("noprogressive"),YtA=CA("wireframe");class yR{constructor(){n(this,"path",null),n(this,"asset",null),n(this,"default")}}class HtA{constructor(A,e){n(this,"_renderer"),n(this,"_targets",[]),n(this,"_indexMapMaxIndex"),n(this,"_indexMap"),n(this,"_changed",!1),this._renderer=A;const i=this.setMaterial.bind(this),g=this.getMaterial.bind(this),I=A.gameObject;if(this._targets=[],I)switch(I.type){case"Group":this._targets=[...I.children];break;case"SkinnedMesh":case"Mesh":this._targets.push(I);break}let o=!1,s,C=0;for(let a=0;a<this._targets.length;a++){const r=this._targets[a];if(!r)continue;const B=r.material;if(B){B.shadowSide=B.side;for(let Q=0;Q<e.length;Q++){const E=e[Q];if(!E){o=!0;continue}if(B.name===E.name){s===void 0&&(s=new Map),s.set(Q,a),C=Math.max(C,Q);break}}}}if(o){this._indexMapMaxIndex=C,this._indexMap=s;const a=`Renderer ${A.name} was initialized with missing materials - this may lead to unexpected behaviour when trying to access sharedMaterials by index.`;console.warn(a),gI()&&ig("Found renderer with missing materials: please check the console for details.")}return new Proxy(this,{get(a,r){if(typeof r=="string"){const B=parseInt(r);if(!isNaN(B))return g(B)}return a[r]},set(a,r,B){return typeof r=="string"&&i(B,Number.parseInt(r)),Reflect.set(a,r,B)?(B instanceof ve&&(a.changed=!0),!0):!1}})}get changed(){return this._changed}set changed(A){A===!0&&Fw&&console.warn("SharedMaterials have changed: "+this._renderer.name,this),this._changed=A}is(A){return this._renderer===A}get length(){return this._indexMapMaxIndex!==void 0?this._indexMapMaxIndex+1:this._targets.length}*[Symbol.iterator](){for(let A=0;A<this.length;A++)yield this.getMaterial(A)}resolveIndex(A){const e=this._indexMap;return e&&e.has(A)?e.get(A):A}setMaterial(A,e){if(e=this.resolveIndex(e),e<0||e>=this._targets.length)return;const i=this._targets[e];!i||i.material===void 0||(i.material=A,this.changed=!0)}getMaterial(A){if(A=this.resolveIndex(A),A<0)return null;const e=this._targets;if(A>=e.length)return null;const i=e[A];return i?i.material:null}}const XH=class extends JA{constructor(){super(...arguments),n(this,"receiveShadows",!1),n(this,"shadowCastingMode",0),n(this,"lightmapIndex",-1),n(this,"lightmapScaleOffset",new ie(1,1,0,0)),n(this,"enableInstancing"),n(this,"renderOrder"),n(this,"allowOcclusionWhenDynamic",!0),n(this,"probeAnchor"),n(this,"reflectionProbeUsage",0),n(this,"_lightmaps"),n(this,"_sharedMaterials"),n(this,"_originalMaterials"),n(this,"_lightmapTextureOverride"),n(this,"allowProgressiveLoading",!0),n(this,"_isInstancingEnabled",!1),n(this,"handles"),n(this,"prevLayers"),n(this,"onBeforeRenderThree",(t,A,e,i,g,I)=>{var o;if(g.envMapIntensity!==void 0){const s=this.hasLightmap?Math.PI:1,C=((o=this.context.mainCameraComponent)==null?void 0:o.environmentIntensity)??1;g.envMapIntensity=Math.max(0,C*this.context.sceneLighting.environmentIntensity/s)}if(this._lightmaps)for(const s of this._lightmaps)s.updateLightmapUniforms(g)}),n(this,"_reflectionProbe",null)}static setVisible(t,A){Nw(t,A)}get sharedMesh(){if(this.gameObject.type==="Mesh")return this.gameObject;if(this.gameObject.type==="SkinnesMesh")return this.gameObject;if(this.gameObject.type==="Group")return this.gameObject.children[0]}get sharedMaterial(){return this.sharedMaterials[0]}set sharedMaterial(t){this.sharedMaterials[0]!==t&&(this.sharedMaterials[0]=t,this.applyLightmapping())}get material(){return this.sharedMaterials[0]}set material(t){this.sharedMaterial=t}set sharedMaterials(t){if(!this._originalMaterials)this._originalMaterials=t;else if(t){let A=!1;for(let e=0;e<this._sharedMaterials.length;e++){const i=e<t.length?t[e]:null;i&&i instanceof ve?this.sharedMaterials[e]=i:A||(A=!0,console.warn("Can not assign null as material: "+this.name,i))}}}get sharedMaterials(){return(!this._sharedMaterials||!this._sharedMaterials.is(this))&&(this._originalMaterials||(this._originalMaterials=[]),this._sharedMaterials=new HtA(this,this._originalMaterials)),this._sharedMaterials}static get shouldSuppressInstancing(){return ZH}get lightmap(){var t;return(t=this._lightmaps)!=null&&t.length?this._lightmaps[0].lightmap:null}set lightmap(t){var A;if(this._lightmapTextureOverride=t,t===void 0&&(t=this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex)),(A=this._lightmaps)!=null&&A.length)for(const e of this._lightmaps)e.lightmap=t}get hasLightmap(){return this.lightmap!=null}registering(){this.enabled||this.setVisibility(!1)}awake(){if(Fw&&console.log("Renderer ",this.name,this),this.clearInstancingState(),this.probeAnchor&&Fw&&this.probeAnchor.add(new wQ(.2)),this._reflectionProbe=null,this.isMultiMaterialObject(this.gameObject)){for(const t of this.gameObject.children)this.context.addBeforeRenderListener(t,this.onBeforeRenderThree),t.layers.mask=this.gameObject.layers.mask;if(this.renderOrder!==void 0){let t=0;for(let A=0;A<this.gameObject.children.length;A++){const e=this.gameObject.children[A];if(!(!this.isMeshOrSkinnedMesh(e)||iA.getComponent(e,XH))){if(this.renderOrder.length<=t){console.warn("Incorrect renderOrder element count",this,this.renderOrder.length+" but expected "+this.gameObject.children.length,"Index: "+t,"ChildElement:",e);continue}e.renderOrder=this.renderOrder[t],t+=1}}}}else this.isMeshOrSkinnedMesh(this.gameObject)?(this.context.addBeforeRenderListener(this.gameObject,this.onBeforeRenderThree),this.renderOrder!==void 0&&this.renderOrder.length>0&&(this.gameObject.renderOrder=this.renderOrder[0])):this.context.addBeforeRenderListener(this.gameObject,this.onBeforeRenderThree);if(this.applyLightmapping(),YtA)for(let t=0;t<this.sharedMaterials.length;t++){const A=this.sharedMaterials[t];A&&(A.wireframe=!0)}}applyLightmapping(){var t;if(this.lightmapIndex>=0){const A=this.gameObject.type,e=this._lightmapTextureOverride!==void 0?this._lightmapTextureOverride:this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex);if(e){if(this._lightmaps||(this._lightmaps=[]),A==="Mesh"){const i=this.gameObject.material;if(i!=null&&i.isMeshBasicMaterial)i&&console.warn("Lightmapping is not supported on MeshBasicMaterial",i.name);else{if(this._lightmaps.length<=0){const g=new gl(this.gameObject,this.context);this._lightmaps.push(g)}this._lightmaps[0].init(this.lightmapIndex,this.lightmapScaleOffset,e)}}else if(this.isMultiMaterialObject(this.gameObject)&&this.sharedMaterials.length>0)for(let i=0;i<this.gameObject.children.length;i++){const g=this.gameObject.children[i];if(!((t=g.material)!=null&&t.isMeshBasicMaterial)){let I;i>=this._lightmaps.length?(I=new gl(g,this.context),this._lightmaps.push(I)):I=this._lightmaps[i],I.init(this.lightmapIndex,this.lightmapScaleOffset,e)}}}else Fw&&console.warn("Lightmap not found",this.sourceId,this.lightmapIndex)}}clearInstancingState(){this._isInstancingEnabled=!1,this.handles=void 0,this.prevLayers=void 0}setInstancingEnabled(t){if(this._isInstancingEnabled===t)return t&&(this.handles===void 0||this.handles!=null&&this.handles.length>0);if(this._isInstancingEnabled=t,t){if(this.handles===void 0){if(this.handles=_tA.setup(this,this.gameObject,this.context,null,{rend:this,foundMeshes:0,useMatrixWorldAutoUpdate:this.useInstanceMatrixWorldAutoUpdate()}),this.handles)return iA.markAsInstancedRendered(this.gameObject,!0),!0}else if(this.handles!==null){for(const A of this.handles)A.updateInstanceMatrix(!0),A.add();return iA.markAsInstancedRendered(this.gameObject,!0),!0}}else{if(this.handles)for(const A of this.handles)A.remove();return!0}return!1}useInstanceMatrixWorldAutoUpdate(){return!0}start(){if(this.enableInstancing&&!ZH&&(this.setInstancingEnabled(!0),Vg.markDirty(this.gameObject)),this.gameObject.frustumCulled=this.allowOcclusionWhenDynamic,this.isMultiMaterialObject(this.gameObject))for(let t=0;t<this.gameObject.children.length;t++){const A=this.gameObject.children[t];A.frustumCulled=this.allowOcclusionWhenDynamic}}onEnable(){this.setVisibility(!0),this._isInstancingEnabled?this.setInstancingEnabled(!0):this.enabled&&this.applyStencil(),this.updateReflectionProbe()}onDisable(){this.setVisibility(!1),this.handles&&this.handles.length>0&&this.setInstancingEnabled(!1)}onDestroy(){if(this.handles=null,this.isMultiMaterialObject(this.gameObject))for(const t of this.gameObject.children)this.context.removeBeforeRenderListener(t,this.onBeforeRenderThree);else this.context.removeBeforeRenderListener(this.gameObject,this.onBeforeRenderThree)}applyStencil(){yM.applyStencil(this)}onBeforeRender(){var t,A;if(this.gameObject){if(this.isMultiMaterialObject(this.gameObject)&&((t=this.gameObject.children)==null?void 0:t.length)>0)for(const e of this.gameObject.children)this.applySettings(e);else this.applySettings(this.gameObject);if(this.sharedMaterials.changed&&(this.sharedMaterials.changed=!1,this.applyLightmapping()),(A=this.handles)!=null&&A.length&&this.gameObject[Jc]===!0){wR&&console.log("UPDATE INSTANCED MATRICES",this.context.time.frame),this.gameObject[Jc]=!1;for(let e=this.handles.length-1;e>=0;e--)this.handles[e].updateInstanceMatrix();this.gameObject.matrixWorldNeedsUpdate=!1}if(this.handles&&this.handles.length<=0&&iA.markAsInstancedRendered(this.gameObject,!1),this._isInstancingEnabled&&this.handles)for(let e=0;e<this.handles.length;e++){const i=this.handles[e];this.prevLayers||(this.prevLayers=[]);const g=i.object.layers.mask;e>=this.prevLayers.length?this.prevLayers.push(g):this.prevLayers[e]=g,i.object.layers.disableAll()}for(const e of this.sharedMaterials)e&&this.loadProgressiveTextures(e);this.reflectionProbeUsage!==0&&this._reflectionProbe&&this._reflectionProbe.onSet(this)}}onAfterRender(){if(this._isInstancingEnabled&&this.handles&&this.prevLayers&&this.prevLayers.length>=this.handles.length)for(let t=0;t<this.handles.length;t++){const A=this.handles[t];A.object.layers.mask=this.prevLayers[t]}this.reflectionProbeUsage!==0&&this._reflectionProbe&&this._reflectionProbe.onUnset(this)}loadProgressiveTextures(t){return!TtA&&t&&t._didRequestTextureLOD===void 0&&this.allowProgressiveLoading?(t._didRequestTextureLOD=0,xtA&&console.log("Load material LOD",t.name),hs.assignTextureLOD(this.context,this.sourceId,t)):Promise.resolve(!0)}applySettings(t){t.receiveShadow=this.receiveShadows,this.shadowCastingMode==1?t.castShadow=!0:t.castShadow=!1}updateReflectionProbe(){if(this._reflectionProbe=null,this.reflectionProbeUsage!==0){if(!this.probeAnchor)return;this.startCoroutine(this._updateReflectionProbe(),Ig.LateUpdate)}}*_updateReflectionProbe(){const t=this.probeAnchor||this.gameObject,A=!!this.probeAnchor;this._reflectionProbe=eE.get(t,this.context,A,this.probeAnchor)}setVisibility(t){if(!this.isMultiMaterialObject(this.gameObject))Nw(this.gameObject,t);else for(const A of this.gameObject.children)this.isMeshOrSkinnedMesh(A)&&Nw(A,t)}isMultiMaterialObject(t){return t.type==="Group"}isMeshOrSkinnedMesh(t){return t.type==="Mesh"||t.type==="SkinnedMesh"}};let Di=XH;ga([w()],Di.prototype,"receiveShadows",2),ga([w()],Di.prototype,"shadowCastingMode",2),ga([w()],Di.prototype,"lightmapIndex",2),ga([w(ie)],Di.prototype,"lightmapScaleOffset",2),ga([w()],Di.prototype,"enableInstancing",2),ga([w()],Di.prototype,"renderOrder",2),ga([w()],Di.prototype,"allowOcclusionWhenDynamic",2),ga([w(fA)],Di.prototype,"probeAnchor",2),ga([w()],Di.prototype,"reflectionProbeUsage",2);class Kw extends Di{}class SR extends Kw{awake(){var A;super.awake(),this.allowOcclusionWhenDynamic=!1,(A=this.gameObject.parent)==null||A.updateWorldMatrix(!1,!0)}onBeforeRender(){if(super.onBeforeRender(),LtA&&this.gameObject instanceof is&&this.gameObject.boundingSphere){const A=rc(this.gameObject.boundingSphere.center).applyMatrix4(this.gameObject.matrixWorld);Ws.DrawWireSphere(A,this.gameObject.boundingSphere.radius,"red")}}}class OtA{constructor(){n(this,"objs",[])}setup(A,e,i,g,I,o=0){A.applySettings(e);const s=this.tryCreateOrAddInstance(e,i,I);if(s)A.loadProgressiveTextures(s.instancer.material),g===null&&(g=[]),g.push(s);else if(o<=0&&e.type!=="Mesh"){const C=o+1;for(const a of e.children)g=this.setup(A,a,i,g,I,C)}return o===0&&I.useMatrixWorldAutoUpdate&&g&&g.length>=0&&this.autoUpdateInstanceMatrix(e),g}tryCreateOrAddInstance(A,e,i){if(A.type==="Mesh"){const g=i.foundMeshes;if(i.foundMeshes+=1,!i.rend.enableInstancing||g>=i.rend.enableInstancing.length||!i.rend.enableInstancing[g])return null;const I=A,o=I.geometry,s=I.material;for(const a of this.objs)if(!a.isFull()&&a.geo===o&&a.material===s)return a.addInstance(I);const C=new A2(A.name,o,s,200,e);return this.objs.push(C),C.addInstance(I)}return null}autoUpdateInstanceMatrix(A){const e=A.matrixWorld.multiplyMatrices.bind(A.matrixWorld),i=A.matrixWorld.clone(),g=(I,o)=>{const s=e(I,o);return(A[Jc]||i.equals(s)===!1)&&(i.copy(s),A[Jc]=!0),s};A.matrixWorld.multiplyMatrices=g}}const _tA=new OtA;class PtA{constructor(A,e,i){n(this,"instanceIndex",-1),n(this,"object"),n(this,"instancer"),this.instanceIndex=A,this.object=e,this.instancer=i,e[qL]=i,iA.markAsInstancedRendered(e,!0)}get name(){return this.object.name}updateInstanceMatrix(A=!1){this.instanceIndex<0||(this.object.updateWorldMatrix(!0,A),this.instancer.updateInstance(this.object.matrixWorld,this.instanceIndex))}setMatrix(A){this.instanceIndex<0||this.instancer.updateInstance(A,this.instanceIndex)}add(){this.instanceIndex>=0||this.instancer.add(this)}remove(){this.instanceIndex<0||this.instancer.remove(this)}}const $H=class{constructor(t,A,e,i,g){n(this,"name",""),n(this,"geo"),n(this,"material"),n(this,"context"),n(this,"inst"),n(this,"handles",[]),n(this,"maxCount"),n(this,"_needUpdateBounds",!1),this.name=t,this.geo=A,this.material=e,this.context=g,this.maxCount=i,wR&&(e=new nt({color:this.randomColor()})),this.inst=new su(A,e,i),this.inst[iG]=!0,this.inst.onBeforeRender=()=>{this._needUpdateBounds&&this.inst[iG]===!0&&(wR&&console.log("Update instancing bounds",this.name),this.updateBounds())},this.inst.count=0,this.inst.layers.set(2),this.inst.visible=!0,this.context.scene.add(this.inst)}get mesh(){return this.inst}get visible(){return this.inst.visible}set visible(t){this.inst.visible=t}get castShadow(){return this.inst.castShadow}set castShadow(t){this.inst.castShadow=t}set receiveShadow(t){this.inst.receiveShadow=t}updateBounds(t=!0,A=!0){this._needUpdateBounds=!1,t&&this.inst.computeBoundingBox(),A&&this.inst.computeBoundingSphere()}get currentCount(){return this.inst.count}isFull(){return this.currentCount>=this.maxCount}randomColor(){return new SA(Math.random(),Math.random(),Math.random())}addInstance(t){if(this.currentCount>=this.maxCount)return console.error("TOO MANY INSTANCES - resize is not yet implemented!",this.inst.count),null;const A=new PtA(-1,t,this);return t.castShadow===!0&&this.inst.castShadow===!1&&(this.inst.castShadow=!0),t.receiveShadow===!0&&this.inst.receiveShadow===!1&&(this.inst.receiveShadow=!0),this.add(A),A}add(t){t.instanceIndex<0&&(t.instanceIndex=this.currentCount,t.instanceIndex>=this.handles.length?this.handles.push(t):this.handles[t.instanceIndex]=t),t.object.updateWorldMatrix(!0,!0),this.inst.setMatrixAt(t.instanceIndex,t.object.matrixWorld),this.inst.instanceMatrix.needsUpdate=!0,this.inst.count+=1,this._needUpdateBounds=!0,this.inst.count>0&&(this.inst.visible=!0)}remove(t){if(!(!t||t.instanceIndex<0||t.instanceIndex>=this.handles.length||this.inst.count<=0)){if(this.handles[t.instanceIndex]!==t){console.error("instance handle is not part of renderer, was it removed before?",t.instanceIndex,this.name);const A=this.handles.indexOf(t);if(A<0)return;t.instanceIndex=A}if(this.handles[t.instanceIndex]=null,this.inst.setMatrixAt(t.instanceIndex,$H.nullMatrix),!(t.instanceIndex>=this.currentCount-1)&&this.currentCount>0){const A=this.handles[this.currentCount-1];A&&(A.instanceIndex=t.instanceIndex,A.updateInstanceMatrix(),this.handles[t.instanceIndex]=A,this.handles[this.currentCount-1]=null)}this.inst.count>0&&(this.inst.count-=1),t.instanceIndex=-1,this._needUpdateBounds=!0,this.inst.count<=0&&(this.inst.visible=!1),this.inst.instanceMatrix.needsUpdate=!0}}updateInstance(t,A){this.inst.setMatrixAt(A,t),this.inst.instanceMatrix.needsUpdate=!0,this._needUpdateBounds=!0}};let A2=$H;n(A2,"nullMatrix",new NA);function Jw(t){return t=t.replace(/[^a-zA-Z0-9_]/g,""),t.match(/^[a-zA-Z_]/)||(t="_"+t),t}function e2(t){if(t.length===0)return null;const A=t.map(e=>{const i=new Array;for(;e.parent;)i.unshift(e.parent),e=e.parent;return i});return A[0].findLast(e=>A.every(i=>i.includes(e)))||null}function t2(t){const A=e2(t),e=new Set;for(const i of t){let g=i.parent;for(;g&&g!==A;)t.includes(g)||e.add(g),g=g.parent}return e}const tE=class{constructor(t,A,e,i=null,g=null,I=null,o=null,s=null){n(this,"uuid"),n(this,"name"),n(this,"matrix"),n(this,"_isDynamic"),n(this,"geometry"),n(this,"material"),n(this,"camera"),n(this,"parent"),n(this,"skinnedMesh"),n(this,"children",[]),n(this,"animations"),n(this,"_eventListeners"),this.uuid=t,this.name=Jw(A),this.matrix=e,this.geometry=i,this.material=g,this.camera=I,this.parent=null,this.children=[],this._eventListeners={},this._isDynamic=!1,this.skinnedMesh=o,this.animations=s}get isDynamic(){return this._isDynamic}set isDynamic(t){this._isDynamic=t}static createEmptyParent(t){const A=new tE(Eg.generateUUID(),t.name+"_empty_"+tE.USDObject_export_id++,t.matrix);return t.parent.add(A),A.add(t),A.isDynamic=!0,t.matrix=new NA().identity(),A}static createEmpty(){const t=new tE(Eg.generateUUID(),"Empty_"+tE.USDObject_export_id++,new NA);return t.isDynamic=!0,t}is(t){return t?this.uuid===t.uuid:!1}isEmpty(){return!this.geometry}clone(){const t=new tE(Eg.generateUUID(),this.name,this.matrix,this.geometry,this.material);return t.isDynamic=this.isDynamic,t}getPath(){let t=this.parent,A=this.name;for(;t;)A=(t.parent?t.name:t.name+"/Scenes/Scene")+"/"+A,t=t.parent;return"</"+A+">"}add(t){t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t)}remove(t){const A=this.children.indexOf(t);A>=0&&(t.parent===this&&(t.parent=null),this.children.splice(A,1))}addEventListener(t,A){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(A)}removeEventListener(t,A){if(!this._eventListeners[t])return;const e=this._eventListeners[t].indexOf(A);e>=0&&this._eventListeners[t].splice(e,1)}onSerialize(t,A){const e=this._eventListeners.serialize;e&&e.forEach(i=>i(t,A))}};let Fo=tE;n(Fo,"USDObject_export_id",0);class i2 extends Fo{constructor(){super(void 0,"StageRoot",new NA,null,null,null),n(this,"stageLength"),this.children=[],this.stageLength=200}get isDocumentRoot(){return!0}get isDynamic(){return!1}add(A){A.parent=this,this.children.push(A)}remove(A){const e=this.children.indexOf(A);e>=0&&(A.parent===this&&(A.parent=null),this.children.splice(e,1))}traverse(A,e=null){if(e!==null?A(e):e=this,e.children)for(const i of e.children)this.traverse(A,i)}findById(A){let e=!1;function i(g){if(!e){if(g.uuid===A)return e=!0,g;if(g.children)for(const I of g.children){const o=i(I);if(o)return o}}}return i(this)}buildHeader(A){return`#usda 1.0
4920
+ `,t.name)}const a=g.clone();a.version=g.version,I?(I.copy=a,I.material=g):(I={material:g,copy:a},e.push(I)),a[KtA]=this,a[JtA]=g,hl&&console.log("Set reflection",t.name,t.guid)}const C=I?.copy;C.envMap=this.texture,t.sharedMaterials[i]=C}}onUnset(t){const A=ia._rendererMaterialsCache.get(t);if(A)for(let e=0;e<A.length;e++){const i=A[e];t.sharedMaterials[e]=i.material}}},n(Uw,"_probes",new Map),n(Uw,"_rendererMaterialsCache",new Map),Uw);let eE=ia;jH([w(y)],eE.prototype,"center",2),jH([w(y)],eE.prototype,"size",2);const VH=Symbol("customVisibilityFlag");function Nw(t,A){t.layers[VH]=A}const zH=Symbol("DidPatchLayers");function vtA(){const t=Lg.prototype;if(t[zH])return;t[zH]=!0;const A=t.test;t.test=function(e){return this[VH]===!1?!1:A.call(this,e)}}vtA();var qtA=Object.defineProperty,btA=Object.getOwnPropertyDescriptor,ga=(t,A,e,i)=>{for(var g=i>1?void 0:i?btA(A,e):A,I=t.length-1,o;I>=0;I--)(o=t[I])&&(g=(i?o(A,e,g):o(g))||g);return i&&g&&qtA(A,e,g),g};const Fw=CA("debugrenderer"),LtA=CA("debugskinnedmesh"),ZH=CA("noInstancing"),wR=CA("debuginstancing"),xtA=CA("debugprogressive"),TtA=CA("noprogressive"),YtA=CA("wireframe");class yR{constructor(){n(this,"path",null),n(this,"asset",null),n(this,"default")}}class HtA{constructor(A,e){n(this,"_renderer"),n(this,"_targets",[]),n(this,"_indexMapMaxIndex"),n(this,"_indexMap"),n(this,"_changed",!1),this._renderer=A;const i=this.setMaterial.bind(this),g=this.getMaterial.bind(this),I=A.gameObject;if(this._targets=[],I)switch(I.type){case"Group":this._targets=[...I.children];break;case"SkinnedMesh":case"Mesh":this._targets.push(I);break}let o=!1,s,C=0;for(let a=0;a<this._targets.length;a++){const r=this._targets[a];if(!r)continue;const B=r.material;if(B){B.shadowSide=B.side;for(let Q=0;Q<e.length;Q++){const E=e[Q];if(!E){o=!0;continue}if(B.name===E.name){s===void 0&&(s=new Map),s.set(Q,a),C=Math.max(C,Q);break}}}}if(o){this._indexMapMaxIndex=C,this._indexMap=s;const a=`Renderer ${A.name} was initialized with missing materials - this may lead to unexpected behaviour when trying to access sharedMaterials by index.`;console.warn(a),gI()&&ig("Found renderer with missing materials: please check the console for details.")}return new Proxy(this,{get(a,r){if(typeof r=="string"){const B=parseInt(r);if(!isNaN(B))return g(B)}return a[r]},set(a,r,B){return typeof r=="string"&&i(B,Number.parseInt(r)),Reflect.set(a,r,B)?(B instanceof ve&&(a.changed=!0),!0):!1}})}get changed(){return this._changed}set changed(A){A===!0&&Fw&&console.warn("SharedMaterials have changed: "+this._renderer.name,this),this._changed=A}is(A){return this._renderer===A}get length(){return this._indexMapMaxIndex!==void 0?this._indexMapMaxIndex+1:this._targets.length}*[Symbol.iterator](){for(let A=0;A<this.length;A++)yield this.getMaterial(A)}resolveIndex(A){const e=this._indexMap;return e&&e.has(A)?e.get(A):A}setMaterial(A,e){if(e=this.resolveIndex(e),e<0||e>=this._targets.length)return;const i=this._targets[e];!i||i.material===void 0||(i.material=A,this.changed=!0)}getMaterial(A){if(A=this.resolveIndex(A),A<0)return null;const e=this._targets;if(A>=e.length)return null;const i=e[A];return i?i.material:null}}const XH=class extends JA{constructor(){super(...arguments),n(this,"receiveShadows",!1),n(this,"shadowCastingMode",0),n(this,"lightmapIndex",-1),n(this,"lightmapScaleOffset",new ie(1,1,0,0)),n(this,"enableInstancing"),n(this,"renderOrder"),n(this,"allowOcclusionWhenDynamic",!0),n(this,"probeAnchor"),n(this,"reflectionProbeUsage",0),n(this,"_lightmaps"),n(this,"_sharedMaterials"),n(this,"_originalMaterials"),n(this,"_lightmapTextureOverride"),n(this,"allowProgressiveLoading",!0),n(this,"_isInstancingEnabled",!1),n(this,"handles"),n(this,"prevLayers"),n(this,"onBeforeRenderThree",(t,A,e,i,g,I)=>{var o;if(g.envMapIntensity!==void 0){const s=this.hasLightmap?Math.PI:1,C=((o=this.context.mainCameraComponent)==null?void 0:o.environmentIntensity)??1;g.envMapIntensity=Math.max(0,C*this.context.sceneLighting.environmentIntensity/s)}if(this._lightmaps)for(const s of this._lightmaps)s.updateLightmapUniforms(g)}),n(this,"_reflectionProbe",null)}static setVisible(t,A){Nw(t,A)}get sharedMesh(){if(this.gameObject.type==="Mesh")return this.gameObject;if(this.gameObject.type==="SkinnesMesh")return this.gameObject;if(this.gameObject.type==="Group")return this.gameObject.children[0]}get sharedMaterial(){return this.sharedMaterials[0]}set sharedMaterial(t){this.sharedMaterials[0]!==t&&(this.sharedMaterials[0]=t,this.applyLightmapping())}get material(){return this.sharedMaterials[0]}set material(t){this.sharedMaterial=t}set sharedMaterials(t){if(!this._originalMaterials)this._originalMaterials=t;else if(t){let A=!1;for(let e=0;e<this._sharedMaterials.length;e++){const i=e<t.length?t[e]:null;i&&i instanceof ve?this.sharedMaterials[e]=i:A||(A=!0,console.warn("Can not assign null as material: "+this.name,i))}}}get sharedMaterials(){return(!this._sharedMaterials||!this._sharedMaterials.is(this))&&(this._originalMaterials||(this._originalMaterials=[]),this._sharedMaterials=new HtA(this,this._originalMaterials)),this._sharedMaterials}static get shouldSuppressInstancing(){return ZH}get lightmap(){var t;return(t=this._lightmaps)!=null&&t.length?this._lightmaps[0].lightmap:null}set lightmap(t){var A;if(this._lightmapTextureOverride=t,t===void 0&&(t=this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex)),(A=this._lightmaps)!=null&&A.length)for(const e of this._lightmaps)e.lightmap=t}get hasLightmap(){return this.lightmap!=null}registering(){this.enabled||this.setVisibility(!1)}awake(){if(Fw&&console.log("Renderer ",this.name,this),this.clearInstancingState(),this.probeAnchor&&Fw&&this.probeAnchor.add(new wQ(.2)),this._reflectionProbe=null,this.isMultiMaterialObject(this.gameObject)){for(const t of this.gameObject.children)this.context.addBeforeRenderListener(t,this.onBeforeRenderThree),t.layers.mask=this.gameObject.layers.mask;if(this.renderOrder!==void 0){let t=0;for(let A=0;A<this.gameObject.children.length;A++){const e=this.gameObject.children[A];if(!(!this.isMeshOrSkinnedMesh(e)||iA.getComponent(e,XH))){if(this.renderOrder.length<=t){console.warn("Incorrect renderOrder element count",this,this.renderOrder.length+" but expected "+this.gameObject.children.length,"Index: "+t,"ChildElement:",e);continue}e.renderOrder=this.renderOrder[t],t+=1}}}}else this.isMeshOrSkinnedMesh(this.gameObject)?(this.context.addBeforeRenderListener(this.gameObject,this.onBeforeRenderThree),this.renderOrder!==void 0&&this.renderOrder.length>0&&(this.gameObject.renderOrder=this.renderOrder[0])):this.context.addBeforeRenderListener(this.gameObject,this.onBeforeRenderThree);if(this.applyLightmapping(),YtA)for(let t=0;t<this.sharedMaterials.length;t++){const A=this.sharedMaterials[t];A&&(A.wireframe=!0)}}applyLightmapping(){var t;if(this.lightmapIndex>=0){const A=this.gameObject.type,e=this._lightmapTextureOverride!==void 0?this._lightmapTextureOverride:this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex);if(e){if(this._lightmaps||(this._lightmaps=[]),A==="Mesh"){const i=this.gameObject.material;if(i!=null&&i.isMeshBasicMaterial)i&&console.warn("Lightmapping is not supported on MeshBasicMaterial",i.name);else{if(this._lightmaps.length<=0){const g=new gl(this.gameObject,this.context);this._lightmaps.push(g)}this._lightmaps[0].init(this.lightmapIndex,this.lightmapScaleOffset,e)}}else if(this.isMultiMaterialObject(this.gameObject)&&this.sharedMaterials.length>0)for(let i=0;i<this.gameObject.children.length;i++){const g=this.gameObject.children[i];if(!((t=g.material)!=null&&t.isMeshBasicMaterial)){let I;i>=this._lightmaps.length?(I=new gl(g,this.context),this._lightmaps.push(I)):I=this._lightmaps[i],I.init(this.lightmapIndex,this.lightmapScaleOffset,e)}}}else Fw&&console.warn("Lightmap not found",this.sourceId,this.lightmapIndex)}}clearInstancingState(){this._isInstancingEnabled=!1,this.handles=void 0,this.prevLayers=void 0}setInstancingEnabled(t){if(this._isInstancingEnabled===t)return t&&(this.handles===void 0||this.handles!=null&&this.handles.length>0);if(this._isInstancingEnabled=t,t){if(this.handles===void 0){if(this.handles=_tA.setup(this,this.gameObject,this.context,null,{rend:this,foundMeshes:0,useMatrixWorldAutoUpdate:this.useInstanceMatrixWorldAutoUpdate()}),this.handles)return iA.markAsInstancedRendered(this.gameObject,!0),!0}else if(this.handles!==null){for(const A of this.handles)A.updateInstanceMatrix(!0),A.add();return iA.markAsInstancedRendered(this.gameObject,!0),!0}}else{if(this.handles)for(const A of this.handles)A.remove();return!0}return!1}useInstanceMatrixWorldAutoUpdate(){return!0}start(){if(this.enableInstancing&&!ZH&&(this.setInstancingEnabled(!0),Vg.markDirty(this.gameObject)),this.gameObject.frustumCulled=this.allowOcclusionWhenDynamic,this.isMultiMaterialObject(this.gameObject))for(let t=0;t<this.gameObject.children.length;t++){const A=this.gameObject.children[t];A.frustumCulled=this.allowOcclusionWhenDynamic}}onEnable(){this.setVisibility(!0),this._isInstancingEnabled?this.setInstancingEnabled(!0):this.enabled&&this.applyStencil(),this.updateReflectionProbe()}onDisable(){this.setVisibility(!1),this.handles&&this.handles.length>0&&this.setInstancingEnabled(!1)}onDestroy(){if(this.handles=null,this.isMultiMaterialObject(this.gameObject))for(const t of this.gameObject.children)this.context.removeBeforeRenderListener(t,this.onBeforeRenderThree);else this.context.removeBeforeRenderListener(this.gameObject,this.onBeforeRenderThree)}applyStencil(){yM.applyStencil(this)}onBeforeRender(){var t,A;if(this.gameObject){if(this.isMultiMaterialObject(this.gameObject)&&((t=this.gameObject.children)==null?void 0:t.length)>0)for(const e of this.gameObject.children)this.applySettings(e);else this.applySettings(this.gameObject);if(this.sharedMaterials.changed&&(this.sharedMaterials.changed=!1,this.applyLightmapping()),(A=this.handles)!=null&&A.length&&this.gameObject[Jc]===!0){wR&&console.log("UPDATE INSTANCED MATRICES",this.context.time.frame),this.gameObject[Jc]=!1;for(let e=this.handles.length-1;e>=0;e--)this.handles[e].updateInstanceMatrix();this.gameObject.matrixWorldNeedsUpdate=!1}if(this.handles&&this.handles.length<=0&&iA.markAsInstancedRendered(this.gameObject,!1),this._isInstancingEnabled&&this.handles)for(let e=0;e<this.handles.length;e++){const i=this.handles[e];this.prevLayers||(this.prevLayers=[]);const g=i.object.layers.mask;e>=this.prevLayers.length?this.prevLayers.push(g):this.prevLayers[e]=g,i.object.layers.disableAll()}for(const e of this.sharedMaterials)e&&this.loadProgressiveTextures(e);this.reflectionProbeUsage!==0&&this._reflectionProbe&&this._reflectionProbe.onSet(this)}}onAfterRender(){if(this._isInstancingEnabled&&this.handles&&this.prevLayers&&this.prevLayers.length>=this.handles.length)for(let t=0;t<this.handles.length;t++){const A=this.handles[t];A.object.layers.mask=this.prevLayers[t]}this.reflectionProbeUsage!==0&&this._reflectionProbe&&this._reflectionProbe.onUnset(this)}loadProgressiveTextures(t){return!TtA&&t&&t._didRequestTextureLOD===void 0&&this.allowProgressiveLoading?(t._didRequestTextureLOD=0,xtA&&console.log("Load material LOD",t.name),hs.assignTextureLOD(this.context,this.sourceId,t)):Promise.resolve(!0)}applySettings(t){t.receiveShadow=this.receiveShadows,this.shadowCastingMode==1?t.castShadow=!0:t.castShadow=!1}updateReflectionProbe(){if(this._reflectionProbe=null,this.reflectionProbeUsage!==0){if(!this.probeAnchor)return;this.startCoroutine(this._updateReflectionProbe(),Ig.LateUpdate)}}*_updateReflectionProbe(){const t=this.probeAnchor||this.gameObject,A=!!this.probeAnchor;this._reflectionProbe=eE.get(t,this.context,A,this.probeAnchor)}setVisibility(t){if(!this.isMultiMaterialObject(this.gameObject))Nw(this.gameObject,t);else for(const A of this.gameObject.children)this.isMeshOrSkinnedMesh(A)&&Nw(A,t)}isMultiMaterialObject(t){return t.type==="Group"}isMeshOrSkinnedMesh(t){return t.type==="Mesh"||t.type==="SkinnedMesh"}};let Di=XH;ga([w()],Di.prototype,"receiveShadows",2),ga([w()],Di.prototype,"shadowCastingMode",2),ga([w()],Di.prototype,"lightmapIndex",2),ga([w(ie)],Di.prototype,"lightmapScaleOffset",2),ga([w()],Di.prototype,"enableInstancing",2),ga([w()],Di.prototype,"renderOrder",2),ga([w()],Di.prototype,"allowOcclusionWhenDynamic",2),ga([w(fA)],Di.prototype,"probeAnchor",2),ga([w()],Di.prototype,"reflectionProbeUsage",2);class Kw extends Di{}class SR extends Kw{awake(){var A;super.awake(),this.allowOcclusionWhenDynamic=!1,(A=this.gameObject.parent)==null||A.updateWorldMatrix(!1,!0)}onBeforeRender(){if(super.onBeforeRender(),LtA&&this.gameObject instanceof is&&this.gameObject.boundingSphere){const A=rc(this.gameObject.boundingSphere.center).applyMatrix4(this.gameObject.matrixWorld);Ws.DrawWireSphere(A,this.gameObject.boundingSphere.radius,"red")}}}class OtA{constructor(){n(this,"objs",[])}setup(A,e,i,g,I,o=0){A.applySettings(e);const s=this.tryCreateOrAddInstance(e,i,I);if(s)A.loadProgressiveTextures(s.instancer.material),g===null&&(g=[]),g.push(s);else if(o<=0&&e.type!=="Mesh"){const C=o+1;for(const a of e.children)g=this.setup(A,a,i,g,I,C)}return o===0&&I.useMatrixWorldAutoUpdate&&g&&g.length>=0&&this.autoUpdateInstanceMatrix(e),g}tryCreateOrAddInstance(A,e,i){if(A.type==="Mesh"){const g=i.foundMeshes;if(i.foundMeshes+=1,!i.rend.enableInstancing||g>=i.rend.enableInstancing.length||!i.rend.enableInstancing[g])return null;const I=A,o=I.geometry,s=I.material;for(const a of this.objs)if(!a.isFull()&&a.geo===o&&a.material===s)return a.addInstance(I);const C=new A2(A.name,o,s,200,e);return this.objs.push(C),C.addInstance(I)}return null}autoUpdateInstanceMatrix(A){const e=A.matrixWorld.multiplyMatrices.bind(A.matrixWorld),i=A.matrixWorld.clone(),g=(I,o)=>{const s=e(I,o);return(A[Jc]||i.equals(s)===!1)&&(i.copy(s),A[Jc]=!0),s};A.matrixWorld.multiplyMatrices=g}}const _tA=new OtA;class PtA{constructor(A,e,i){n(this,"instanceIndex",-1),n(this,"object"),n(this,"instancer"),this.instanceIndex=A,this.object=e,this.instancer=i,e[qL]=i,iA.markAsInstancedRendered(e,!0)}get name(){return this.object.name}updateInstanceMatrix(A=!1){this.instanceIndex<0||(this.object.updateWorldMatrix(!0,A),this.instancer.updateInstance(this.object.matrixWorld,this.instanceIndex))}setMatrix(A){this.instanceIndex<0||this.instancer.updateInstance(A,this.instanceIndex)}add(){this.instanceIndex>=0||this.instancer.add(this)}remove(){this.instanceIndex<0||this.instancer.remove(this)}}const $H=class{constructor(t,A,e,i,g){n(this,"name",""),n(this,"geo"),n(this,"material"),n(this,"context"),n(this,"inst"),n(this,"handles",[]),n(this,"maxCount"),n(this,"_needUpdateBounds",!1),n(this,"onBeforeRender",()=>{this._needUpdateBounds&&this.inst[iG]===!0&&(wR&&console.log("Update instancing bounds",this.name,this.inst.matrixWorldNeedsUpdate),this.updateBounds())}),this.name=t,this.geo=A,this.material=e,this.context=g,this.maxCount=i,wR&&(e=new nt({color:this.randomColor()})),this.inst=new su(A,e,i),this.inst[iG]=!0,this.inst.count=0,this.inst.layers.set(2),this.inst.visible=!0,this.context.scene.add(this.inst),g.pre_render_callbacks.push(this.onBeforeRender)}get mesh(){return this.inst}get visible(){return this.inst.visible}set visible(t){this.inst.visible=t}get castShadow(){return this.inst.castShadow}set castShadow(t){this.inst.castShadow=t}set receiveShadow(t){this.inst.receiveShadow=t}updateBounds(t=!0,A=!0){this._needUpdateBounds=!1,t&&this.inst.computeBoundingBox(),A&&this.inst.computeBoundingSphere()}get currentCount(){return this.inst.count}isFull(){return this.currentCount>=this.maxCount}randomColor(){return new SA(Math.random(),Math.random(),Math.random())}addInstance(t){if(this.currentCount>=this.maxCount)return console.error("TOO MANY INSTANCES - resize is not yet implemented!",this.inst.count),null;const A=new PtA(-1,t,this);return t.castShadow===!0&&this.inst.castShadow===!1&&(this.inst.castShadow=!0),t.receiveShadow===!0&&this.inst.receiveShadow===!1&&(this.inst.receiveShadow=!0),this.add(A),A}add(t){t.instanceIndex<0&&(t.instanceIndex=this.currentCount,t.instanceIndex>=this.handles.length?this.handles.push(t):this.handles[t.instanceIndex]=t),t.object.updateWorldMatrix(!0,!0),this.inst.setMatrixAt(t.instanceIndex,t.object.matrixWorld),this.inst.instanceMatrix.needsUpdate=!0,this.inst.count+=1,this._needUpdateBounds=!0,this.inst.count>0&&(this.inst.visible=!0)}remove(t){if(!(!t||t.instanceIndex<0||t.instanceIndex>=this.handles.length||this.inst.count<=0)){if(this.handles[t.instanceIndex]!==t){console.error("instance handle is not part of renderer, was it removed before?",t.instanceIndex,this.name);const A=this.handles.indexOf(t);if(A<0)return;t.instanceIndex=A}if(this.handles[t.instanceIndex]=null,this.inst.setMatrixAt(t.instanceIndex,$H.nullMatrix),!(t.instanceIndex>=this.currentCount-1)&&this.currentCount>0){const A=this.handles[this.currentCount-1];A&&(A.instanceIndex=t.instanceIndex,A.updateInstanceMatrix(),this.handles[t.instanceIndex]=A,this.handles[this.currentCount-1]=null)}this.inst.count>0&&(this.inst.count-=1),t.instanceIndex=-1,this._needUpdateBounds=!0,this.inst.count<=0&&(this.inst.visible=!1),this.inst.instanceMatrix.needsUpdate=!0}}updateInstance(t,A){this.inst.setMatrixAt(A,t),this.inst.instanceMatrix.needsUpdate=!0,this._needUpdateBounds=!0}};let A2=$H;n(A2,"nullMatrix",new NA);function Jw(t){return t=t.replace(/[^a-zA-Z0-9_]/g,""),t.match(/^[a-zA-Z_]/)||(t="_"+t),t}function e2(t){if(t.length===0)return null;const A=t.map(e=>{const i=new Array;for(;e.parent;)i.unshift(e.parent),e=e.parent;return i});return A[0].findLast(e=>A.every(i=>i.includes(e)))||null}function t2(t){const A=e2(t),e=new Set;for(const i of t){let g=i.parent;for(;g&&g!==A;)t.includes(g)||e.add(g),g=g.parent}return e}const tE=class{constructor(t,A,e,i=null,g=null,I=null,o=null,s=null){n(this,"uuid"),n(this,"name"),n(this,"matrix"),n(this,"_isDynamic"),n(this,"geometry"),n(this,"material"),n(this,"camera"),n(this,"parent"),n(this,"skinnedMesh"),n(this,"children",[]),n(this,"animations"),n(this,"_eventListeners"),this.uuid=t,this.name=Jw(A),this.matrix=e,this.geometry=i,this.material=g,this.camera=I,this.parent=null,this.children=[],this._eventListeners={},this._isDynamic=!1,this.skinnedMesh=o,this.animations=s}get isDynamic(){return this._isDynamic}set isDynamic(t){this._isDynamic=t}static createEmptyParent(t){const A=new tE(Eg.generateUUID(),t.name+"_empty_"+tE.USDObject_export_id++,t.matrix);return t.parent.add(A),A.add(t),A.isDynamic=!0,t.matrix=new NA().identity(),A}static createEmpty(){const t=new tE(Eg.generateUUID(),"Empty_"+tE.USDObject_export_id++,new NA);return t.isDynamic=!0,t}is(t){return t?this.uuid===t.uuid:!1}isEmpty(){return!this.geometry}clone(){const t=new tE(Eg.generateUUID(),this.name,this.matrix,this.geometry,this.material);return t.isDynamic=this.isDynamic,t}getPath(){let t=this.parent,A=this.name;for(;t;)A=(t.parent?t.name:t.name+"/Scenes/Scene")+"/"+A,t=t.parent;return"</"+A+">"}add(t){t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t)}remove(t){const A=this.children.indexOf(t);A>=0&&(t.parent===this&&(t.parent=null),this.children.splice(A,1))}addEventListener(t,A){this._eventListeners[t]||(this._eventListeners[t]=[]),this._eventListeners[t].push(A)}removeEventListener(t,A){if(!this._eventListeners[t])return;const e=this._eventListeners[t].indexOf(A);e>=0&&this._eventListeners[t].splice(e,1)}onSerialize(t,A){const e=this._eventListeners.serialize;e&&e.forEach(i=>i(t,A))}};let Fo=tE;n(Fo,"USDObject_export_id",0);class i2 extends Fo{constructor(){super(void 0,"StageRoot",new NA,null,null,null),n(this,"stageLength"),this.children=[],this.stageLength=200}get isDocumentRoot(){return!0}get isDynamic(){return!1}add(A){A.parent=this,this.children.push(A)}remove(A){const e=this.children.indexOf(A);e>=0&&(A.parent===this&&(A.parent=null),this.children.splice(e,1))}traverse(A,e=null){if(e!==null?A(e):e=this,e.children)for(const i of e.children)this.traverse(A,i)}findById(A){let e=!1;function i(g){if(!e){if(g.uuid===A)return e=!0,g;if(g.children)for(const I of g.children){const o=i(I);if(o)return o}}}return i(this)}buildHeader(A){return`#usda 1.0
4919
4921
  (
4920
4922
  customLayerData = {
4921
4923
  string creator = "Needle Engine USDZExporter"