@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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [3.27.4-beta] - 2023-12-11
8
+ - Fix: instancing now updating bounds in Needle Engine before render callback if necessary
9
+ - Change: expose `onPauseChanged` on components
10
+ - Change: handle case where a added coroutine function is not a coroutine (Generator)
11
+
7
12
  ## [3.27.3-beta] - 2023-12-09
8
13
  - Add: `InstancingUtil.getRenderer` to get the three InstancedMesh for any Object3D (if it's using instancing)
9
14
  - Add: instancing does now automatically update culling bounds if it's dirty. This can be disabled via `InstancingUtil.setAutoUpdateBounds(obj, false)`
@@ -41720,7 +41720,9 @@ const Ai = class {
41720
41720
  (e = this.domElement) != null && e.parentElement && this.domElement.parentElement.removeChild(this.domElement), Tt.dispatchCallback(sg.ContextDestroyed, this), Tt.unregister(this);
41721
41721
  }
41722
41722
  registerCoroutineUpdate(A, e, t) {
41723
- return this.coroutines[t] || (this.coroutines[t] = []), this.coroutines[t].push({ comp: A, main: e }), e;
41723
+ return typeof (e == null ? void 0 : e.next) != "function" ? (console.error("Registered invalid coroutine function from " + A.name + `
41724
+ Coroutine functions must be generators: "*myCoroutine() {...}"
41725
+ Start a coroutine from a component by calling "this.startCoroutine(myCoroutine())"`), e) : (this.coroutines[t] || (this.coroutines[t] = []), this.coroutines[t].push({ comp: A, main: e }), e);
41724
41726
  }
41725
41727
  unregisterCoroutineUpdate(A, e) {
41726
41728
  if (!this.coroutines[e])
@@ -56692,9 +56694,10 @@ const vF = class {
56692
56694
  r(this, "handles", []);
56693
56695
  r(this, "maxCount");
56694
56696
  r(this, "_needUpdateBounds", !1);
56695
- this.name = A, this.geo = e, this.material = t, this.context = I, this.maxCount = g, CG && (t = new at({ color: this.randomColor() })), this.inst = new ND(e, t, g), this.inst[Mm] = !0, this.inst.onBeforeRender = () => {
56696
- this._needUpdateBounds && this.inst[Mm] === !0 && (CG && console.log("Update instancing bounds", this.name), this.updateBounds());
56697
- }, this.inst.count = 0, this.inst.layers.set(2), this.inst.visible = !0, this.context.scene.add(this.inst);
56697
+ r(this, "onBeforeRender", () => {
56698
+ this._needUpdateBounds && this.inst[Mm] === !0 && (CG && console.log("Update instancing bounds", this.name, this.inst.matrixWorldNeedsUpdate), this.updateBounds());
56699
+ });
56700
+ this.name = A, this.geo = e, this.material = t, this.context = I, this.maxCount = g, CG && (t = new at({ color: this.randomColor() })), this.inst = new ND(e, t, g), this.inst[Mm] = !0, this.inst.count = 0, this.inst.layers.set(2), this.inst.visible = !0, this.context.scene.add(this.inst), I.pre_render_callbacks.push(this.onBeforeRender);
56698
56701
  }
56699
56702
  /** The three instanced mesh
56700
56703
  * @link https://threejs.org/docs/#api/en/objects/InstancedMesh
@@ -41720,7 +41720,9 @@ const Xi = class {
41720
41720
  (t = this.domElement) != null && t.parentElement && this.domElement.parentElement.removeChild(this.domElement), Gi.dispatchCallback(cs.ContextDestroyed, this), Gi.unregister(this);
41721
41721
  }
41722
41722
  registerCoroutineUpdate(e, t, i) {
41723
- return this.coroutines[i] || (this.coroutines[i] = []), this.coroutines[i].push({ comp: e, main: t }), t;
41723
+ return typeof (t == null ? void 0 : t.next) != "function" ? (console.error("Registered invalid coroutine function from " + e.name + `
41724
+ Coroutine functions must be generators: "*myCoroutine() {...}"
41725
+ Start a coroutine from a component by calling "this.startCoroutine(myCoroutine())"`), t) : (this.coroutines[i] || (this.coroutines[i] = []), this.coroutines[i].push({ comp: e, main: t }), t);
41724
41726
  }
41725
41727
  unregisterCoroutineUpdate(e, t) {
41726
41728
  if (!this.coroutines[t])
@@ -56692,9 +56694,10 @@ const KI = class {
56692
56694
  h(this, "handles", []);
56693
56695
  h(this, "maxCount");
56694
56696
  h(this, "_needUpdateBounds", !1);
56695
- this.name = e, this.geo = t, this.material = i, this.context = r, this.maxCount = s, VE && (i = new ai({ color: this.randomColor() })), this.inst = new Ob(t, i, s), this.inst[lE] = !0, this.inst.onBeforeRender = () => {
56696
- this._needUpdateBounds && this.inst[lE] === !0 && (VE && console.log("Update instancing bounds", this.name), this.updateBounds());
56697
- }, this.inst.count = 0, this.inst.layers.set(2), this.inst.visible = !0, this.context.scene.add(this.inst);
56697
+ h(this, "onBeforeRender", () => {
56698
+ this._needUpdateBounds && this.inst[lE] === !0 && (VE && console.log("Update instancing bounds", this.name, this.inst.matrixWorldNeedsUpdate), this.updateBounds());
56699
+ });
56700
+ this.name = e, this.geo = t, this.material = i, this.context = r, this.maxCount = s, VE && (i = new ai({ color: this.randomColor() })), this.inst = new Ob(t, i, s), this.inst[lE] = !0, this.inst.count = 0, this.inst.layers.set(2), this.inst.visible = !0, this.context.scene.add(this.inst), r.pre_render_callbacks.push(this.onBeforeRender);
56698
56701
  }
56699
56702
  /** The three instanced mesh
56700
56703
  * @link https://threejs.org/docs/#api/en/objects/InstancedMesh
@@ -4286,7 +4286,9 @@ irradiance += 0.;
4286
4286
  irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
4287
4287
  #endif`),Ge.lightmap.lightmapScaleOffset={value:new tt(1,1,0,0)};const f7=oe("debugplayerview");var Pa=(i=>(i.Browser="browser",i.Headset="headset",i.Handheld="handheld",i))(Pa||{});class IU{constructor(e,t){h(this,"userId"),h(this,"context"),h(this,"viewDevice","browser"),h(this,"removed",!1),h(this,"_object"),this.userId=e,this.context=t}get currentObject(){return this._object}set currentObject(e){this._object=e}get isConnected(){return this.context.connection.userIsInRoom(this.userId)}}class RU{constructor(e){h(this,"context"),h(this,"playerViews",new Map),this.context=e}setPlayerView(e,t,s){let r=this.playerViews.get(e);r||(r=new IU(e,this.context),this.playerViews.set(e,r)),r.viewDevice=s,r.currentObject=t,r.removed=!1}getPlayerView(e){if(!!e){if(!this.context.connection.userIsInRoom(e)){this.playerViews.delete(e);return}return this.playerViews.get(e)}}removePlayerView(e,t){const s=this.playerViews.get(e);s?.viewDevice===t&&(f7&&console.log("REMOVE",e),s.removed=!0,this.playerViews.delete(e))}}function*PU(i,e=null){const t=e?e.time:Ot.Current.time,s=t.time;for(;t.time-s<i;)yield}function*m7(i){for(let e=0;e<i;e++)yield}function*BU(i){let e=!0;for(i.then(()=>e=!1),i.catch(()=>e=!1);e;)yield}const vb=new Map;function Ab(i,e){vb.has(e)||vb.set(e,new Array),vb.get(e).push(i)}function bu(i,e){const t=vb.get(e);if(t&&t.length>0){let s=t;e===Ws.Start&&(s=[...t],t.length=0),g7(i,s)}}function g7(i,e){for(let t=e.length-1;t>=0;t--){const s=e[t];du(s,i)}}const Wc=oe("debugcontext"),v7=oe("stats"),A7=oe("debugactive"),y7=oe("debugframerate"),b7=oe("debugcoroutine"),_7={};class x7{constructor(){h(this,"name"),h(this,"alias"),h(this,"hash"),h(this,"runInBackground"),h(this,"domElement"),h(this,"renderer"),h(this,"camera"),h(this,"scene")}}var Ws=(i=>(i[i.Start=-1]="Start",i[i.EarlyUpdate=0]="EarlyUpdate",i[i.Update=1]="Update",i[i.LateUpdate=2]="LateUpdate",i[i.OnBeforeRender=3]="OnBeforeRender",i[i.OnAfterRender=4]="OnAfterRender",i[i.PrePhysicsStep=9]="PrePhysicsStep",i[i.PostPhysicsStep=10]="PostPhysicsStep",i[i.Undefined=-1]="Undefined",i))(Ws||{}),Ag=(i=>(i.ImmersiveVR="immersive-vr",i.ImmersiveAR="immersive-ar",i))(Ag||{});function yb(i,e){if(!i)return;if(!i.isComponent){(zt()||Wc)&&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
- `,i);return}const t=e?.new_scripts??Ot.Current.new_scripts;t.includes(i)||t.push(i)}const $i=class{constructor(i){h(this,"name"),h(this,"alias"),h(this,"isManagedExternally",!1),h(this,"isPaused",!1),h(this,"runInBackground",!1),h(this,"targetFrameRate"),h(this,"physicsSteps",1),h(this,"hash"),h(this,"domElement"),h(this,"_resolutionScaleFactor",1),h(this,"_boundingClientRectFrame",-1),h(this,"_boundingClientRect",null),h(this,"_domX"),h(this,"_domY"),h(this,"xrSessionMode"),h(this,"_xrFrame",null),h(this,"_currentFrameEvent",-1),h(this,"scene"),h(this,"renderer"),h(this,"composer",null),h(this,"scripts",[]),h(this,"scripts_pausedChanged",[]),h(this,"scripts_earlyUpdate",[]),h(this,"scripts_update",[]),h(this,"scripts_lateUpdate",[]),h(this,"scripts_onBeforeRender",[]),h(this,"scripts_onAfterRender",[]),h(this,"scripts_WithCorroutines",[]),h(this,"coroutines",{}),h(this,"mainCameraComponent"),h(this,"_camera",null),h(this,"post_setup_callbacks",[]),h(this,"pre_update_callbacks",[]),h(this,"pre_render_callbacks",[]),h(this,"post_render_callbacks",[]),h(this,"new_scripts",[]),h(this,"new_script_start",[]),h(this,"new_scripts_pre_setup_callbacks",[]),h(this,"new_scripts_post_setup_callbacks",[]),h(this,"application"),h(this,"time"),h(this,"input"),h(this,"physics"),h(this,"connection"),h(this,"assets"),h(this,"mainLight",null),h(this,"sceneLighting"),h(this,"addressables"),h(this,"lightmaps"),h(this,"players"),h(this,"_sizeChanged",!1),h(this,"_isCreated",!1),h(this,"_isCreating",!1),h(this,"_isVisible",!1),h(this,"_stats",v7?new OY:null),h(this,"_intersectionObserver",null),h(this,"_disposeCallbacks",[]),h(this,"onUnhandledRejection",s=>{this.domElement.dispatchEvent(new CustomEvent("error",{detail:s.reason}))}),h(this,"_cameraStack",[]),h(this,"_onBeforeRenderListeners",new Map),h(this,"_onAfterRenderListeners",new Map),h(this,"_requireDepthTexture",!1),h(this,"_requireColorTexture",!1),h(this,"_renderTarget"),h(this,"_isRendering",!1),h(this,"_createId",0),h(this,"_renderlooperrors",0),h(this,"_lastTimestamp",0),h(this,"_accumulatedTime",0),h(this,"_dispatchReadyAfterFrame",!1),h(this,"_wasPaused",!1),this.name=i?.name||"",this.alias=i?.alias,this.domElement=i?.domElement||document.body,this.hash=i?.hash,i!=null&&i.renderer&&(this.renderer=i.renderer,this.isManagedExternally=!0),i?.runInBackground!==void 0&&(this.runInBackground=i.runInBackground),i!=null&&i.scene?this.scene=i.scene:this.scene=new mn,i!=null&&i.camera&&(this._camera=i.camera),this.application=new fU(this),this.time=new ek,this.input=new j2(this),this.physics=new Z2(this),this.connection=new wO(this),this.assets=new cL,this.sceneLighting=new dU(this),this.addressables=new hU(this),this.lightmaps=new p7(this),this.players=new RU(this);const e=()=>this._sizeChanged=!0;window.addEventListener("resize",e),this._disposeCallbacks.push(()=>window.removeEventListener("resize",e));const t=new ResizeObserver(s=>this._sizeChanged=!0);t.observe(this.domElement),this._disposeCallbacks.push(()=>t.disconnect()),this._intersectionObserver=new IntersectionObserver(s=>{this._isVisible=s[0].isIntersecting}),this._disposeCallbacks.push(()=>{var s;return(s=this._intersectionObserver)==null?void 0:s.disconnect()}),Mi.register(this)}static get DefaultTargetFrameRate(){return $i._defaultTargetFramerate.value}static set DefaultTargetFrameRate(i){$i._defaultTargetFramerate.value=i}static get DefaultWebGLRendererParameters(){return $i._defaultWebglRendererParameters}get version(){return El}static get Current(){return Mi.Current}static set Current(i){Mi.Current=i}appendHTMLElement(i){return this.domElement.shadowRoot?this.domElement.shadowRoot.appendChild(i):this.domElement.appendChild(i)}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(i){if(i!==this._resolutionScaleFactor&&typeof i=="number"){if(i<=0){console.error("Invalid resolution scale factor",i);return}this._resolutionScaleFactor=i,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 i,e;return((e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.isPresenting)||!1}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){var i,e;return(e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.getSession()}get xrFrame(){return this._xrFrame}get xrCamera(){var i,e;return(e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.getCamera()}get arOverlayElement(){const i=this.domElement;return typeof i.getAROverlayContainer=="function"?i.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this._camera)return this._camera;if(this.mainCameraComponent){const i=this.mainCameraComponent;return i.cam||i.buildCamera(),i.cam}return null}set mainCamera(i){this._camera=i}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}createNewRenderer(){var i,e,t;(i=this.renderer)==null||i.dispose();const s=$i.DefaultWebGLRendererParameters;if(!s.canvas){const r=(t=(e=this.domElement)==null?void 0:e.shadowRoot)==null?void 0:t.querySelector("canvas");r&&(s.canvas=r)}this.renderer=new Ic(s),this.renderer.debug.checkShaderErrors=zt()||oe("checkshadererrors")===!0,this.renderer.toneMappingExposure=1,this.renderer.toneMapping=Qr,this.renderer.setClearColor(new be("lightgrey"),0),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Iw,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputColorSpace=it,this.renderer.useLegacyLights=!1}internalOnUpdateVisible(){var i,e;(i=this._intersectionObserver)==null||i.disconnect(),(e=this._intersectionObserver)==null||e.observe(this.domElement)}updateSize(){var i,e,t;if(!this.isManagedExternally&&((i=this.renderer.xr)==null?void 0:i.isPresenting)===!1){this._sizeChanged=!1;const s=this.resolutionScaleFactor,r=this.domWidth*s,n=this.domHeight*s,o=this.mainCamera;this.updateAspect(o),this.renderer.setSize(r,n,!0),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((e=this.composer.setSize)==null||e.call(this.composer,r,n),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((t=this.composer.setPixelRatio)==null||t.call(this.composer,window.devicePixelRatio)))}}updateAspect(i,e,t){if(!i)return;e===void 0&&(e=this.domWidth),t===void 0&&(t=this.domHeight);const s=i.aspect;i.aspect=e/t,s!==i.aspect&&i.updateProjectionMatrix()}async onCreate(i){return this.create(i)}async create(i){try{return this._isCreating=!0,window.addEventListener("unhandledrejection",this.onUnhandledRejection),await this.internalOnCreate(i)}finally{window.removeEventListener("unhandledrejection",this.onUnhandledRejection),this._isCreating=!1}}clear(){var i,e,t,s;Mi.dispatchCallback(Qs.ContextClearing,this),Ta(this.scene,!0,!0),this.scene=new mn,(i=this.addressables)==null||i.dispose(),(e=this.lightmaps)==null||e.clear(),(s=(t=this.physics)==null?void 0:t.engine)==null||s.clearCaches(),this.isManagedExternally||this.renderer&&(this.renderer.renderLists.dispose(),this.renderer.state.reset(),this.renderer.resetState()),Mi.dispatchCallback(Qs.ContextCleared,this)}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var i,e;this.clear(),(i=this.renderer)==null||i.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 t of this._disposeCallbacks)try{t()}catch(s){console.error("Error in on dispose callback:",s,t)}(e=this.domElement)!=null&&e.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Mi.dispatchCallback(Qs.ContextDestroyed,this),Mi.unregister(this)}registerCoroutineUpdate(i,e,t){return this.coroutines[t]||(this.coroutines[t]=[]),this.coroutines[t].push({comp:i,main:e}),e}unregisterCoroutineUpdate(i,e){if(!this.coroutines[e])return;const t=this.coroutines[e].findIndex(s=>s.main===i);t>=0&&this.coroutines[e].splice(t,1)}stopAllCoroutinesFrom(i){for(const e in this.coroutines){const t=this.coroutines[e];for(let s=t.length-1;s>=0;s--)t[s].comp===i&&t.splice(s,1)}}setCurrentCamera(i){var e;if(!i)return;if(i.cam||i.buildCamera(),!i.cam){console.warn("Camera component is missing camera",i);return}const t=this._cameraStack.indexOf(i);t>=0&&this._cameraStack.splice(t,1),this._cameraStack.push(i),this.mainCameraComponent=i;const s=i.cam;s.isPerspectiveCamera&&this.updateAspect(s),(e=this.mainCameraComponent)==null||e.applyClearFlagsIfIsActiveCamera()}removeCamera(i){if(!i)return;const e=this._cameraStack.indexOf(i);if(e>=0&&this._cameraStack.splice(e,1),this.mainCameraComponent===i&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const t=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(t)}}addBeforeRenderListener(i,e){this._onBeforeRenderListeners.has(i.uuid)||(this._onBeforeRenderListeners.set(i.uuid,[]),i.onBeforeRender=this._createRenderCallbackWrapper(i,this._onBeforeRenderListeners)),this._onBeforeRenderListeners.get(i.uuid).push(e)}removeBeforeRenderListener(i,e){if(this._onBeforeRenderListeners.has(i.uuid)){const t=this._onBeforeRenderListeners.get(i.uuid),s=t.indexOf(e);s>=0&&t.splice(s,1)}}addAfterRenderListener(i,e){var t;this._onAfterRenderListeners.has(i.uuid)||(this._onAfterRenderListeners.set(i.uuid,[]),i.onAfterRender=this._createRenderCallbackWrapper(i,this._onAfterRenderListeners)),(t=this._onAfterRenderListeners.get(i.uuid))==null||t.push(e)}removeAfterRenderListener(i,e){if(this._onAfterRenderListeners.has(i.uuid)){const t=this._onAfterRenderListeners.get(i.uuid),s=t.indexOf(e);s>=0&&t.splice(s,1)}}_createRenderCallbackWrapper(i,e){return(t,s,r,n,o,a)=>{const l=e.get(i.uuid);if(l)for(let c=0;c<l.length;c++){const u=l[c];u(t,s,r,n,o,a)}}}get isRendering(){return this._isRendering}setRequireDepth(i){this._requireDepthTexture=i}setRequireColor(i){this._requireColorTexture=i}get depthTexture(){var i;return((i=this._renderTarget)==null?void 0:i.depthTexture)||null}get opaqueColorTexture(){var i;return((i=this._renderTarget)==null?void 0:i.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const i=getComputedStyle(this.domElement);return i.visibility!=="hidden"&&i.display!=="none"&&i.opacity!=="0"}async internalOnCreate(i){var e,t,s,r,n;const o=++this._createId;this.clear(),this.isManagedExternally===!1&&(this.createNewRenderer(),(e=this.renderer)==null||e.setAnimationLoop(null)),await Dc(1),$i.Current=this,await Mi.dispatchCallback(Qs.ContextCreationStart,this);let a=!0,l;try{$i.Current=this,i?l=await this.internalLoadInitialContent(o,i):l=[]}catch(u){console.error(u),a=!1}if(!a||o!==this._createId)return!1;if(this.internalOnUpdateVisible(),!this.renderer)return Wc&&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),$i.Current=this,$i.Current=this;for(let u=0;u<this.new_scripts.length;u++){const d=this.new_scripts[u];if(d.gameObject!==void 0&&d.gameObject!==null){d.gameObject.userData===void 0&&(d.gameObject.userData={}),d.gameObject.userData.components===void 0&&(d.gameObject.userData.components=[]);const p=d.gameObject.userData.components;p.includes(d)||p.push(d)}}if(this.post_setup_callbacks)for(let u=0;u<this.post_setup_callbacks.length;u++)$i.Current=this,await this.post_setup_callbacks[u](this);if(!this.mainCamera){$i.Current=this;let u=null;Au(this.scene,d=>{const p=d;if(p!=null&&p.isCamera){if(cg(p.gameObject),!p.activeAndEnabled)return;if(p.tag==="MainCamera")return u=p,!0;u=p}}),u?this.setCurrentCamera(u):!Mi.dispatchCallback(Qs.MissingCamera,this,{files:l})&&!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this)}if($i.Current=this,Z0(this),this.physics.engine&&((t=this.physics.engine)==null||t.step(0),(s=this.physics.engine)==null||s.postStep()),!this.isManagedExternally&&this.composer&&this.mainCamera){const u=new nb(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(u),this.composer.setSize(this.domWidth,this.domHeight)}this._sizeChanged=!0,this._stats&&(this._stats.showPanel(0),(r=this.domElement.shadowRoot)==null||r.appendChild(this._stats.dom)),Wc&&u0(this.scene,!0),this.targetFrameRate===void 0?(Wc&&console.warn("No target framerate set, using default",$i.DefaultTargetFrameRate),this.targetFrameRate=$i._defaultTargetFramerate):Wc&&console.log("Target framerate set to",this.targetFrameRate),this._dispatchReadyAfterFrame=!0;const c=Mi.dispatchCallback(Qs.ContextCreated,this,{files:l});return c&&("internalSetLoadingMessage"in this.domElement&&typeof this.domElement.internalSetLoadingMessage=="function"&&((n=this.domElement)==null||n.internalSetLoadingMessage("finish loading")),await c),bu(this,Qs.ContextCreated),this._isCreating=!1,this.isManagedExternally||this.restartRenderLoop(),c}async internalLoadInitialContent(i,e){var t,s;const r=new Array;if(e.files.length===0)return r;const n=[...e.files],o={name:"",progress:null,index:0,count:n.length},a=Zo();let l=0;this.hash&&(l=Number.parseInt(this.hash)??0);for(let c=0;c<n.length;c++){if(i!==this._createId){Wc&&console.log("Aborting loading because create id changed",i,this._createId);break}const u=n[c];if(!u.includes(".glb")&&!u.includes(".gltf")){const p=`Needle Engine: found suspicious src "${u}"`;console.warn(p),qr()&&Hs(p)}(t=e?.onLoadingStart)==null||t.call(this,c,u);const d=await a.loadSync(this,u,u,l,p=>{var f;o.name=u,o.progress=p,o.index=c,o.count=n.length,(f=e.onLoadingProgress)==null||f.call(this,o)});(s=e?.onLoadingFinished)==null||s.call(this,c,u,d??null),d?r.push({src:u,file:d}):console.warn("Could not load file: "+u)}if(i!==this._createId){for(const c of r)if(c&&c.file)for(const u of c.file.scenes)Ta(u,!0,!0)}else for(const c of r)c&&c.file&&this.scene.add(c.file.scene);return r}restartRenderLoop(){return this.renderer?this._isCreating?(console.warn("Can not start render loop while creating context"),!1):(this.renderer.setAnimationLoop((i,e)=>{this.isManagedExternally||this.update(i,e)}),!0):(console.error("Can not start render loop without renderer"),!1)}update(i,e){if(e===void 0&&(e=null),zt()||Wc||kX())try{this.internalStep(i,e),this._renderlooperrors=0}catch(t){this._renderlooperrors+=1,(zt()||Wc)&&(t instanceof Error||t instanceof TypeError)&&cs("Caught unhandled exception during render-loop.<br/>Stopping renderloop...<br/>See console for details.",uo.Error),console.error(t),this._renderlooperrors>10&&(console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null)),this.domElement.dispatchEvent(new CustomEvent("error",{detail:t}))}else this.internalStep(i,e)}updatePhysics(i){this.internalUpdatePhysics(i)}internalStep(i,e){this.internalOnBeforeRender(i,e)!==!1&&(this.internalOnRender(),this.internalOnAfterRender())}internalOnBeforeRender(i,e){var t;if(this._xrFrame=e,this._currentFrameEvent=-1,this.isManagedExternally===!1&&this.isInXR===!1&&this.targetFrameRate!==void 0){this._lastTimestamp===0&&(this._lastTimestamp=i),this._accumulatedTime+=(i-this._lastTimestamp)/1e3,this._lastTimestamp=i;let s=this.targetFrameRate;if(typeof s=="object"&&(s=s.value),this._accumulatedTime<1/(s+1))return!1;this._accumulatedTime=0}if((t=this._stats)==null||t.begin(),$i.Current=this,this.onHandlePaused())return!1;for($i.Current=this,this.time.update(),y7&&console.log("FPS",this.time.smoothedFps.toFixed(0)),Z0(this),$0(this.scene),SL(this),bu(this,-1);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);const s=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(s)}if(this.pre_update_callbacks)for(const s in this.pre_update_callbacks)this.pre_update_callbacks[s]();this._currentFrameEvent=0;for(let s=0;s<this.scripts_earlyUpdate.length;s++){const r=this.scripts_earlyUpdate[s];r.activeAndEnabled&&r.earlyUpdate!==void 0&&($i.Current=this,r.earlyUpdate())}if(this.executeCoroutines(0),bu(this,0),this.onHandlePaused())return!1;this._currentFrameEvent=1;for(let s=0;s<this.scripts_update.length;s++){const r=this.scripts_update[s];r.activeAndEnabled&&r.update!==void 0&&($i.Current=this,r.update())}if(this.executeCoroutines(1),bu(this,1),this.onHandlePaused())return!1;this._currentFrameEvent=2;for(let s=0;s<this.scripts_lateUpdate.length;s++){const r=this.scripts_lateUpdate[s];r.activeAndEnabled&&r.lateUpdate!==void 0&&($i.Current=this,r.lateUpdate())}if(this.executeCoroutines(2),bu(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 s=0;s<this.scripts_onBeforeRender.length;s++){const r=this.scripts_onBeforeRender[s];r.activeAndEnabled&&r.onBeforeRender!==void 0&&($i.Current=this,r.onBeforeRender(e))}if(this.executeCoroutines(3),bu(this,3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(const s in this.pre_render_callbacks)this.pre_render_callbacks[s]()}return!0}internalUpdatePhysics(i){if(!this.physics.engine)return!1;const e=i,t=this.time.deltaTime/e;for(let s=0;s<e;s++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(t),this._currentFrameEvent=10,this.executeCoroutines(10);return this.physics.engine.postStep(),!0}internalOnRender(){this.isManagedExternally||(UX(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4)}internalOnAfterRender(){if(this.isVisibleToUser||this.runInBackground){for(let i=0;i<this.scripts_onAfterRender.length;i++){const e=this.scripts_onAfterRender[i];e.activeAndEnabled&&e.onAfterRender!==void 0&&($i.Current=this,e.onAfterRender())}if(this.executeCoroutines(4),bu(this,4),this.post_render_callbacks)for(const i in this.post_render_callbacks)this.post_render_callbacks[i]()}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")),Mi.dispatchCallback(Qs.ContextFirstFrameRendered,this))}renderNow(i){return!i&&(i=this.mainCamera,!i)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):i&&this.renderer.render(this.scene,i),this._isRendering=!1,!0)}onHandlePaused(){const i=this.evaluatePaused();if(this._wasPaused!==i){A7&&console.log("Paused?",i,"context:"+this.alias);for(let e=0;e<this.scripts_pausedChanged.length;e++){const t=this.scripts_pausedChanged[e];t.activeAndEnabled&&t.onPausedChanged!==void 0&&($i.Current=this,t.onPausedChanged(i,this._wasPaused))}}return this._wasPaused=i,i}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 Kt(this.domWidth,this.domHeight),this._requireDepthTexture){const t=new fm(this.domWidth,this.domHeight);this._renderTarget.depthTexture=t}this._requireColorTexture&&(this._renderTarget.texture=new Dt,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=Ft,this._renderTarget.texture.magFilter=Ft,this._renderTarget.texture.format=bi)}const i=this._renderTarget;i.texture&&(i.texture.colorSpace=this.renderer.outputColorSpace);const e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(i),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(e)}executeCoroutines(i){var e;if(this.coroutines[i]){const s=this.coroutines[i];for(let r=0;r<s.length;r++)try{const n=s[r];if(!n.comp||n.comp.destroyed||!n.main||n.comp.enabled===!1){b7&&console.log("Removing coroutine",n.comp,n.comp.enabled),s.splice(r,1),--r;continue}const o=n.chained;if(o&&o.length>0){const c=o[o.length-1].next();if(c.done&&o.pop(),t(c)&&(n.chained||(n.chained=[]),n.chained.push(c.value)),!c.done)continue}const a=n.main.next();if(a.done===!0){s.splice(r,1),--r;continue}const l=a.value;if(t(l)){if(l.next().done)continue;n.chained||(n.chained=[]),n.chained.push(l)}else if(l instanceof Promise){const c=l;n.chained||(n.chained=[]);const u=BU(c);(e=n.chained)==null||e.push(u);continue}}catch(n){console.error(n)}}function t(s){return!!(s&&s.next&&s.return)}}};let Ot=$i;h(Ot,"_defaultTargetFramerate",{value:60}),h(Ot,"_defaultWebglRendererParameters",{antialias:!0,alpha:!1});const yg=oe("debugoverlay"),DU="ar",w7="quit-ar";class S7{constructor(){h(this,"arContainer",null),h(this,"currentSession",null),h(this,"_createdAROnlyElements",[]),h(this,"_reparentedObjects",[]),h(this,"contentElement",null),h(this,"requestEndAR",()=>{this.onRequestedEndAR()})}get ARContainer(){return this.arContainer}onBegin(e,t,s){var r;if(this.currentSession=s,this.arContainer=t,r0()){const n=e.domElement.children;for(let o=0;o<n?.length;o++){const a=n[o];if(!a||a===this.arContainer)return;this._reparentedObjects.push({el:a,previousParent:a.parentElement}),(r=this.arContainer)==null||r.appendChild(a)}}this.ensureQuitARButton(this.arContainer)}onEnd(e){var t;for(const s of this._createdAROnlyElements)s.remove&&s.remove();for(const s of this._reparentedObjects){const r=s.el;(t=s.previousParent)==null||t.appendChild(r)}this._reparentedObjects.length=0,r0()&&setTimeout(()=>{var s;const r=e.renderer.domElement;r&&((s=e.domElement.shadowRoot)==null||s.prepend(r));const n=document.querySelectorAll("*");for(var o=0;o<n.length;o++){const a=n[o];a&&a._displayChanged!==void 0&&a._displayWas!==void 0&&(a.style.display=a._displayWas)}},10)}createOverlayContainer(e){if(this.contentElement)return this.contentElement;yg&&console.log("Setup overlay container");const t=e.shadowRoot.querySelector(".content");this.contentElement=t;const s=e.shadowRoot.querySelector(".overlay-content");return s&&t.appendChild(s),yg&&!yl()&&this.ensureQuitARButton(t),t}onRequestedEndAR(){this.currentSession&&(this.currentSession.end(),this.currentSession=null)}ensureQuitARButton(e){const t=document.createElement("slot");t.setAttribute("name","quit-ar"),this.appendElement(t,e),this._createdAROnlyElements.push(t),t.style.pointerEvents="auto";const s=document.querySelector(`.${w7}`);if(s){s.addEventListener("click",this.requestEndAR),yg&&s.addEventListener("click",()=>console.log("Clicked quit-ar button"));return}t.addEventListener("click",this.requestEndAR),yg&&t.addEventListener("click",()=>console.log("Clicked fallback close button"));const r=document.createElement("div");r.style.cssText=`
4289
+ `,i);return}const t=e?.new_scripts??Ot.Current.new_scripts;t.includes(i)||t.push(i)}const $i=class{constructor(i){h(this,"name"),h(this,"alias"),h(this,"isManagedExternally",!1),h(this,"isPaused",!1),h(this,"runInBackground",!1),h(this,"targetFrameRate"),h(this,"physicsSteps",1),h(this,"hash"),h(this,"domElement"),h(this,"_resolutionScaleFactor",1),h(this,"_boundingClientRectFrame",-1),h(this,"_boundingClientRect",null),h(this,"_domX"),h(this,"_domY"),h(this,"xrSessionMode"),h(this,"_xrFrame",null),h(this,"_currentFrameEvent",-1),h(this,"scene"),h(this,"renderer"),h(this,"composer",null),h(this,"scripts",[]),h(this,"scripts_pausedChanged",[]),h(this,"scripts_earlyUpdate",[]),h(this,"scripts_update",[]),h(this,"scripts_lateUpdate",[]),h(this,"scripts_onBeforeRender",[]),h(this,"scripts_onAfterRender",[]),h(this,"scripts_WithCorroutines",[]),h(this,"coroutines",{}),h(this,"mainCameraComponent"),h(this,"_camera",null),h(this,"post_setup_callbacks",[]),h(this,"pre_update_callbacks",[]),h(this,"pre_render_callbacks",[]),h(this,"post_render_callbacks",[]),h(this,"new_scripts",[]),h(this,"new_script_start",[]),h(this,"new_scripts_pre_setup_callbacks",[]),h(this,"new_scripts_post_setup_callbacks",[]),h(this,"application"),h(this,"time"),h(this,"input"),h(this,"physics"),h(this,"connection"),h(this,"assets"),h(this,"mainLight",null),h(this,"sceneLighting"),h(this,"addressables"),h(this,"lightmaps"),h(this,"players"),h(this,"_sizeChanged",!1),h(this,"_isCreated",!1),h(this,"_isCreating",!1),h(this,"_isVisible",!1),h(this,"_stats",v7?new OY:null),h(this,"_intersectionObserver",null),h(this,"_disposeCallbacks",[]),h(this,"onUnhandledRejection",s=>{this.domElement.dispatchEvent(new CustomEvent("error",{detail:s.reason}))}),h(this,"_cameraStack",[]),h(this,"_onBeforeRenderListeners",new Map),h(this,"_onAfterRenderListeners",new Map),h(this,"_requireDepthTexture",!1),h(this,"_requireColorTexture",!1),h(this,"_renderTarget"),h(this,"_isRendering",!1),h(this,"_createId",0),h(this,"_renderlooperrors",0),h(this,"_lastTimestamp",0),h(this,"_accumulatedTime",0),h(this,"_dispatchReadyAfterFrame",!1),h(this,"_wasPaused",!1),this.name=i?.name||"",this.alias=i?.alias,this.domElement=i?.domElement||document.body,this.hash=i?.hash,i!=null&&i.renderer&&(this.renderer=i.renderer,this.isManagedExternally=!0),i?.runInBackground!==void 0&&(this.runInBackground=i.runInBackground),i!=null&&i.scene?this.scene=i.scene:this.scene=new mn,i!=null&&i.camera&&(this._camera=i.camera),this.application=new fU(this),this.time=new ek,this.input=new j2(this),this.physics=new Z2(this),this.connection=new wO(this),this.assets=new cL,this.sceneLighting=new dU(this),this.addressables=new hU(this),this.lightmaps=new p7(this),this.players=new RU(this);const e=()=>this._sizeChanged=!0;window.addEventListener("resize",e),this._disposeCallbacks.push(()=>window.removeEventListener("resize",e));const t=new ResizeObserver(s=>this._sizeChanged=!0);t.observe(this.domElement),this._disposeCallbacks.push(()=>t.disconnect()),this._intersectionObserver=new IntersectionObserver(s=>{this._isVisible=s[0].isIntersecting}),this._disposeCallbacks.push(()=>{var s;return(s=this._intersectionObserver)==null?void 0:s.disconnect()}),Mi.register(this)}static get DefaultTargetFrameRate(){return $i._defaultTargetFramerate.value}static set DefaultTargetFrameRate(i){$i._defaultTargetFramerate.value=i}static get DefaultWebGLRendererParameters(){return $i._defaultWebglRendererParameters}get version(){return El}static get Current(){return Mi.Current}static set Current(i){Mi.Current=i}appendHTMLElement(i){return this.domElement.shadowRoot?this.domElement.shadowRoot.appendChild(i):this.domElement.appendChild(i)}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(i){if(i!==this._resolutionScaleFactor&&typeof i=="number"){if(i<=0){console.error("Invalid resolution scale factor",i);return}this._resolutionScaleFactor=i,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 i,e;return((e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.isPresenting)||!1}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){var i,e;return(e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.getSession()}get xrFrame(){return this._xrFrame}get xrCamera(){var i,e;return(e=(i=this.renderer)==null?void 0:i.xr)==null?void 0:e.getCamera()}get arOverlayElement(){const i=this.domElement;return typeof i.getAROverlayContainer=="function"?i.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this._camera)return this._camera;if(this.mainCameraComponent){const i=this.mainCameraComponent;return i.cam||i.buildCamera(),i.cam}return null}set mainCamera(i){this._camera=i}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}createNewRenderer(){var i,e,t;(i=this.renderer)==null||i.dispose();const s=$i.DefaultWebGLRendererParameters;if(!s.canvas){const r=(t=(e=this.domElement)==null?void 0:e.shadowRoot)==null?void 0:t.querySelector("canvas");r&&(s.canvas=r)}this.renderer=new Ic(s),this.renderer.debug.checkShaderErrors=zt()||oe("checkshadererrors")===!0,this.renderer.toneMappingExposure=1,this.renderer.toneMapping=Qr,this.renderer.setClearColor(new be("lightgrey"),0),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=Iw,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputColorSpace=it,this.renderer.useLegacyLights=!1}internalOnUpdateVisible(){var i,e;(i=this._intersectionObserver)==null||i.disconnect(),(e=this._intersectionObserver)==null||e.observe(this.domElement)}updateSize(){var i,e,t;if(!this.isManagedExternally&&((i=this.renderer.xr)==null?void 0:i.isPresenting)===!1){this._sizeChanged=!1;const s=this.resolutionScaleFactor,r=this.domWidth*s,n=this.domHeight*s,o=this.mainCamera;this.updateAspect(o),this.renderer.setSize(r,n,!0),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((e=this.composer.setSize)==null||e.call(this.composer,r,n),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((t=this.composer.setPixelRatio)==null||t.call(this.composer,window.devicePixelRatio)))}}updateAspect(i,e,t){if(!i)return;e===void 0&&(e=this.domWidth),t===void 0&&(t=this.domHeight);const s=i.aspect;i.aspect=e/t,s!==i.aspect&&i.updateProjectionMatrix()}async onCreate(i){return this.create(i)}async create(i){try{return this._isCreating=!0,window.addEventListener("unhandledrejection",this.onUnhandledRejection),await this.internalOnCreate(i)}finally{window.removeEventListener("unhandledrejection",this.onUnhandledRejection),this._isCreating=!1}}clear(){var i,e,t,s;Mi.dispatchCallback(Qs.ContextClearing,this),Ta(this.scene,!0,!0),this.scene=new mn,(i=this.addressables)==null||i.dispose(),(e=this.lightmaps)==null||e.clear(),(s=(t=this.physics)==null?void 0:t.engine)==null||s.clearCaches(),this.isManagedExternally||this.renderer&&(this.renderer.renderLists.dispose(),this.renderer.state.reset(),this.renderer.resetState()),Mi.dispatchCallback(Qs.ContextCleared,this)}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var i,e;this.clear(),(i=this.renderer)==null||i.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 t of this._disposeCallbacks)try{t()}catch(s){console.error("Error in on dispose callback:",s,t)}(e=this.domElement)!=null&&e.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Mi.dispatchCallback(Qs.ContextDestroyed,this),Mi.unregister(this)}registerCoroutineUpdate(i,e,t){return typeof e?.next!="function"?(console.error("Registered invalid coroutine function from "+i.name+`
4290
+ Coroutine functions must be generators: "*myCoroutine() {...}"
4291
+ Start a coroutine from a component by calling "this.startCoroutine(myCoroutine())"`),e):(this.coroutines[t]||(this.coroutines[t]=[]),this.coroutines[t].push({comp:i,main:e}),e)}unregisterCoroutineUpdate(i,e){if(!this.coroutines[e])return;const t=this.coroutines[e].findIndex(s=>s.main===i);t>=0&&this.coroutines[e].splice(t,1)}stopAllCoroutinesFrom(i){for(const e in this.coroutines){const t=this.coroutines[e];for(let s=t.length-1;s>=0;s--)t[s].comp===i&&t.splice(s,1)}}setCurrentCamera(i){var e;if(!i)return;if(i.cam||i.buildCamera(),!i.cam){console.warn("Camera component is missing camera",i);return}const t=this._cameraStack.indexOf(i);t>=0&&this._cameraStack.splice(t,1),this._cameraStack.push(i),this.mainCameraComponent=i;const s=i.cam;s.isPerspectiveCamera&&this.updateAspect(s),(e=this.mainCameraComponent)==null||e.applyClearFlagsIfIsActiveCamera()}removeCamera(i){if(!i)return;const e=this._cameraStack.indexOf(i);if(e>=0&&this._cameraStack.splice(e,1),this.mainCameraComponent===i&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const t=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(t)}}addBeforeRenderListener(i,e){this._onBeforeRenderListeners.has(i.uuid)||(this._onBeforeRenderListeners.set(i.uuid,[]),i.onBeforeRender=this._createRenderCallbackWrapper(i,this._onBeforeRenderListeners)),this._onBeforeRenderListeners.get(i.uuid).push(e)}removeBeforeRenderListener(i,e){if(this._onBeforeRenderListeners.has(i.uuid)){const t=this._onBeforeRenderListeners.get(i.uuid),s=t.indexOf(e);s>=0&&t.splice(s,1)}}addAfterRenderListener(i,e){var t;this._onAfterRenderListeners.has(i.uuid)||(this._onAfterRenderListeners.set(i.uuid,[]),i.onAfterRender=this._createRenderCallbackWrapper(i,this._onAfterRenderListeners)),(t=this._onAfterRenderListeners.get(i.uuid))==null||t.push(e)}removeAfterRenderListener(i,e){if(this._onAfterRenderListeners.has(i.uuid)){const t=this._onAfterRenderListeners.get(i.uuid),s=t.indexOf(e);s>=0&&t.splice(s,1)}}_createRenderCallbackWrapper(i,e){return(t,s,r,n,o,a)=>{const l=e.get(i.uuid);if(l)for(let c=0;c<l.length;c++){const u=l[c];u(t,s,r,n,o,a)}}}get isRendering(){return this._isRendering}setRequireDepth(i){this._requireDepthTexture=i}setRequireColor(i){this._requireColorTexture=i}get depthTexture(){var i;return((i=this._renderTarget)==null?void 0:i.depthTexture)||null}get opaqueColorTexture(){var i;return((i=this._renderTarget)==null?void 0:i.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const i=getComputedStyle(this.domElement);return i.visibility!=="hidden"&&i.display!=="none"&&i.opacity!=="0"}async internalOnCreate(i){var e,t,s,r,n;const o=++this._createId;this.clear(),this.isManagedExternally===!1&&(this.createNewRenderer(),(e=this.renderer)==null||e.setAnimationLoop(null)),await Dc(1),$i.Current=this,await Mi.dispatchCallback(Qs.ContextCreationStart,this);let a=!0,l;try{$i.Current=this,i?l=await this.internalLoadInitialContent(o,i):l=[]}catch(u){console.error(u),a=!1}if(!a||o!==this._createId)return!1;if(this.internalOnUpdateVisible(),!this.renderer)return Wc&&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),$i.Current=this,$i.Current=this;for(let u=0;u<this.new_scripts.length;u++){const d=this.new_scripts[u];if(d.gameObject!==void 0&&d.gameObject!==null){d.gameObject.userData===void 0&&(d.gameObject.userData={}),d.gameObject.userData.components===void 0&&(d.gameObject.userData.components=[]);const p=d.gameObject.userData.components;p.includes(d)||p.push(d)}}if(this.post_setup_callbacks)for(let u=0;u<this.post_setup_callbacks.length;u++)$i.Current=this,await this.post_setup_callbacks[u](this);if(!this.mainCamera){$i.Current=this;let u=null;Au(this.scene,d=>{const p=d;if(p!=null&&p.isCamera){if(cg(p.gameObject),!p.activeAndEnabled)return;if(p.tag==="MainCamera")return u=p,!0;u=p}}),u?this.setCurrentCamera(u):!Mi.dispatchCallback(Qs.MissingCamera,this,{files:l})&&!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this)}if($i.Current=this,Z0(this),this.physics.engine&&((t=this.physics.engine)==null||t.step(0),(s=this.physics.engine)==null||s.postStep()),!this.isManagedExternally&&this.composer&&this.mainCamera){const u=new nb(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(u),this.composer.setSize(this.domWidth,this.domHeight)}this._sizeChanged=!0,this._stats&&(this._stats.showPanel(0),(r=this.domElement.shadowRoot)==null||r.appendChild(this._stats.dom)),Wc&&u0(this.scene,!0),this.targetFrameRate===void 0?(Wc&&console.warn("No target framerate set, using default",$i.DefaultTargetFrameRate),this.targetFrameRate=$i._defaultTargetFramerate):Wc&&console.log("Target framerate set to",this.targetFrameRate),this._dispatchReadyAfterFrame=!0;const c=Mi.dispatchCallback(Qs.ContextCreated,this,{files:l});return c&&("internalSetLoadingMessage"in this.domElement&&typeof this.domElement.internalSetLoadingMessage=="function"&&((n=this.domElement)==null||n.internalSetLoadingMessage("finish loading")),await c),bu(this,Qs.ContextCreated),this._isCreating=!1,this.isManagedExternally||this.restartRenderLoop(),c}async internalLoadInitialContent(i,e){var t,s;const r=new Array;if(e.files.length===0)return r;const n=[...e.files],o={name:"",progress:null,index:0,count:n.length},a=Zo();let l=0;this.hash&&(l=Number.parseInt(this.hash)??0);for(let c=0;c<n.length;c++){if(i!==this._createId){Wc&&console.log("Aborting loading because create id changed",i,this._createId);break}const u=n[c];if(!u.includes(".glb")&&!u.includes(".gltf")){const p=`Needle Engine: found suspicious src "${u}"`;console.warn(p),qr()&&Hs(p)}(t=e?.onLoadingStart)==null||t.call(this,c,u);const d=await a.loadSync(this,u,u,l,p=>{var f;o.name=u,o.progress=p,o.index=c,o.count=n.length,(f=e.onLoadingProgress)==null||f.call(this,o)});(s=e?.onLoadingFinished)==null||s.call(this,c,u,d??null),d?r.push({src:u,file:d}):console.warn("Could not load file: "+u)}if(i!==this._createId){for(const c of r)if(c&&c.file)for(const u of c.file.scenes)Ta(u,!0,!0)}else for(const c of r)c&&c.file&&this.scene.add(c.file.scene);return r}restartRenderLoop(){return this.renderer?this._isCreating?(console.warn("Can not start render loop while creating context"),!1):(this.renderer.setAnimationLoop((i,e)=>{this.isManagedExternally||this.update(i,e)}),!0):(console.error("Can not start render loop without renderer"),!1)}update(i,e){if(e===void 0&&(e=null),zt()||Wc||kX())try{this.internalStep(i,e),this._renderlooperrors=0}catch(t){this._renderlooperrors+=1,(zt()||Wc)&&(t instanceof Error||t instanceof TypeError)&&cs("Caught unhandled exception during render-loop.<br/>Stopping renderloop...<br/>See console for details.",uo.Error),console.error(t),this._renderlooperrors>10&&(console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null)),this.domElement.dispatchEvent(new CustomEvent("error",{detail:t}))}else this.internalStep(i,e)}updatePhysics(i){this.internalUpdatePhysics(i)}internalStep(i,e){this.internalOnBeforeRender(i,e)!==!1&&(this.internalOnRender(),this.internalOnAfterRender())}internalOnBeforeRender(i,e){var t;if(this._xrFrame=e,this._currentFrameEvent=-1,this.isManagedExternally===!1&&this.isInXR===!1&&this.targetFrameRate!==void 0){this._lastTimestamp===0&&(this._lastTimestamp=i),this._accumulatedTime+=(i-this._lastTimestamp)/1e3,this._lastTimestamp=i;let s=this.targetFrameRate;if(typeof s=="object"&&(s=s.value),this._accumulatedTime<1/(s+1))return!1;this._accumulatedTime=0}if((t=this._stats)==null||t.begin(),$i.Current=this,this.onHandlePaused())return!1;for($i.Current=this,this.time.update(),y7&&console.log("FPS",this.time.smoothedFps.toFixed(0)),Z0(this),$0(this.scene),SL(this),bu(this,-1);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);const s=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(s)}if(this.pre_update_callbacks)for(const s in this.pre_update_callbacks)this.pre_update_callbacks[s]();this._currentFrameEvent=0;for(let s=0;s<this.scripts_earlyUpdate.length;s++){const r=this.scripts_earlyUpdate[s];r.activeAndEnabled&&r.earlyUpdate!==void 0&&($i.Current=this,r.earlyUpdate())}if(this.executeCoroutines(0),bu(this,0),this.onHandlePaused())return!1;this._currentFrameEvent=1;for(let s=0;s<this.scripts_update.length;s++){const r=this.scripts_update[s];r.activeAndEnabled&&r.update!==void 0&&($i.Current=this,r.update())}if(this.executeCoroutines(1),bu(this,1),this.onHandlePaused())return!1;this._currentFrameEvent=2;for(let s=0;s<this.scripts_lateUpdate.length;s++){const r=this.scripts_lateUpdate[s];r.activeAndEnabled&&r.lateUpdate!==void 0&&($i.Current=this,r.lateUpdate())}if(this.executeCoroutines(2),bu(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 s=0;s<this.scripts_onBeforeRender.length;s++){const r=this.scripts_onBeforeRender[s];r.activeAndEnabled&&r.onBeforeRender!==void 0&&($i.Current=this,r.onBeforeRender(e))}if(this.executeCoroutines(3),bu(this,3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(const s in this.pre_render_callbacks)this.pre_render_callbacks[s]()}return!0}internalUpdatePhysics(i){if(!this.physics.engine)return!1;const e=i,t=this.time.deltaTime/e;for(let s=0;s<e;s++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(t),this._currentFrameEvent=10,this.executeCoroutines(10);return this.physics.engine.postStep(),!0}internalOnRender(){this.isManagedExternally||(UX(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4)}internalOnAfterRender(){if(this.isVisibleToUser||this.runInBackground){for(let i=0;i<this.scripts_onAfterRender.length;i++){const e=this.scripts_onAfterRender[i];e.activeAndEnabled&&e.onAfterRender!==void 0&&($i.Current=this,e.onAfterRender())}if(this.executeCoroutines(4),bu(this,4),this.post_render_callbacks)for(const i in this.post_render_callbacks)this.post_render_callbacks[i]()}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")),Mi.dispatchCallback(Qs.ContextFirstFrameRendered,this))}renderNow(i){return!i&&(i=this.mainCamera,!i)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):i&&this.renderer.render(this.scene,i),this._isRendering=!1,!0)}onHandlePaused(){const i=this.evaluatePaused();if(this._wasPaused!==i){A7&&console.log("Paused?",i,"context:"+this.alias);for(let e=0;e<this.scripts_pausedChanged.length;e++){const t=this.scripts_pausedChanged[e];t.activeAndEnabled&&t.onPausedChanged!==void 0&&($i.Current=this,t.onPausedChanged(i,this._wasPaused))}}return this._wasPaused=i,i}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 Kt(this.domWidth,this.domHeight),this._requireDepthTexture){const t=new fm(this.domWidth,this.domHeight);this._renderTarget.depthTexture=t}this._requireColorTexture&&(this._renderTarget.texture=new Dt,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=Ft,this._renderTarget.texture.magFilter=Ft,this._renderTarget.texture.format=bi)}const i=this._renderTarget;i.texture&&(i.texture.colorSpace=this.renderer.outputColorSpace);const e=this.renderer.getRenderTarget();this.renderer.setRenderTarget(i),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(e)}executeCoroutines(i){var e;if(this.coroutines[i]){const s=this.coroutines[i];for(let r=0;r<s.length;r++)try{const n=s[r];if(!n.comp||n.comp.destroyed||!n.main||n.comp.enabled===!1){b7&&console.log("Removing coroutine",n.comp,n.comp.enabled),s.splice(r,1),--r;continue}const o=n.chained;if(o&&o.length>0){const c=o[o.length-1].next();if(c.done&&o.pop(),t(c)&&(n.chained||(n.chained=[]),n.chained.push(c.value)),!c.done)continue}const a=n.main.next();if(a.done===!0){s.splice(r,1),--r;continue}const l=a.value;if(t(l)){if(l.next().done)continue;n.chained||(n.chained=[]),n.chained.push(l)}else if(l instanceof Promise){const c=l;n.chained||(n.chained=[]);const u=BU(c);(e=n.chained)==null||e.push(u);continue}}catch(n){console.error(n)}}function t(s){return!!(s&&s.next&&s.return)}}};let Ot=$i;h(Ot,"_defaultTargetFramerate",{value:60}),h(Ot,"_defaultWebglRendererParameters",{antialias:!0,alpha:!1});const yg=oe("debugoverlay"),DU="ar",w7="quit-ar";class S7{constructor(){h(this,"arContainer",null),h(this,"currentSession",null),h(this,"_createdAROnlyElements",[]),h(this,"_reparentedObjects",[]),h(this,"contentElement",null),h(this,"requestEndAR",()=>{this.onRequestedEndAR()})}get ARContainer(){return this.arContainer}onBegin(e,t,s){var r;if(this.currentSession=s,this.arContainer=t,r0()){const n=e.domElement.children;for(let o=0;o<n?.length;o++){const a=n[o];if(!a||a===this.arContainer)return;this._reparentedObjects.push({el:a,previousParent:a.parentElement}),(r=this.arContainer)==null||r.appendChild(a)}}this.ensureQuitARButton(this.arContainer)}onEnd(e){var t;for(const s of this._createdAROnlyElements)s.remove&&s.remove();for(const s of this._reparentedObjects){const r=s.el;(t=s.previousParent)==null||t.appendChild(r)}this._reparentedObjects.length=0,r0()&&setTimeout(()=>{var s;const r=e.renderer.domElement;r&&((s=e.domElement.shadowRoot)==null||s.prepend(r));const n=document.querySelectorAll("*");for(var o=0;o<n.length;o++){const a=n[o];a&&a._displayChanged!==void 0&&a._displayWas!==void 0&&(a.style.display=a._displayWas)}},10)}createOverlayContainer(e){if(this.contentElement)return this.contentElement;yg&&console.log("Setup overlay container");const t=e.shadowRoot.querySelector(".content");this.contentElement=t;const s=e.shadowRoot.querySelector(".overlay-content");return s&&t.appendChild(s),yg&&!yl()&&this.ensureQuitARButton(t),t}onRequestedEndAR(){this.currentSession&&(this.currentSession.end(),this.currentSession=null)}ensureQuitARButton(e){const t=document.createElement("slot");t.setAttribute("name","quit-ar"),this.appendElement(t,e),this._createdAROnlyElements.push(t),t.style.pointerEvents="auto";const s=document.querySelector(`.${w7}`);if(s){s.addEventListener("click",this.requestEndAR),yg&&s.addEventListener("click",()=>console.log("Clicked quit-ar button"));return}t.addEventListener("click",this.requestEndAR),yg&&t.addEventListener("click",()=>console.log("Clicked fallback close button"));const r=document.createElement("div");r.style.cssText=`
4290
4292
  position: fixed;
4291
4293
  top: 0;
4292
4294
  right: 0;
@@ -4915,7 +4917,7 @@ void main() {
4915
4917
  `&&i.length>1&&HN([t],i[i.length-2]),e.offsetX}function _ee(i){if(!i[0])return 0;let e=[],t;for(let s=0;s<i.length;s++){const r=i[s];if(r.char&&GN[r.char]&&i.length>s){e.push(r),t=i[s+1];continue}break}VN(e,t),e=[],t=null;for(let s=i.length-1;s>0;s--){const r=i[s];if(r.char&&GN[r.char]&&s>0){e.push(r),t=i[s-1];continue}break}return HN(e,t),i[0].offsetX}function xee(i){return i[0]?i[0].offsetX:0}function HN(i,e){if(e)for(let t=0;t<i.length;t++){const s=i[t];s.fontFactor=0,s.offsetX=e.offsetX+e.cumulativeWidth,s.cumulativeWidth=0}}function VN(i,e){if(e)for(let t=0;t<i.length;t++){const s=i[t];s.fontFactor=0,s.offsetX=e.offsetX,s.cumulativeWidth=0}}function WN(i,e,t,s){if(s=s||0,!i[e])return s;const r=i[e];return r.lineBreak?s+r.xadvance:WN(i,e+1,t,s+r.xadvance+r.xoffset+r.kerning+t.LETTERSPACING)}function wee(i,e,t,s){return!i||!i.char||e+t<s.INNER_WIDTH?!1:s.BREAKON.indexOf(i.char)>-1}class XN extends HF{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._fontSize._needsProcess=!0,e._layouter._needsProcess=!0}}class qN extends zi{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(e){this._value=this._inheritedInput,e._font._fontVariant&&(e._bounds._needsProcess=!0,e._layouter._needsProcess=!0)}process(e){if(!e._font._fontVariant||!e._font._fontVariant.isReady)return;const t=this._value/e._font._fontVariant.typographic.size,s=e._inlines._value;for(let r=0;r<s.length;r++){const n=s[r];n.resetOffsets(),n.fontSize=this._value,n.fontFactor=t}}get value(){return this._value}}class YN extends VF{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(e,t){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(e)),e._layouter._needsUpdate=!0}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class See extends YN{constructor(){super(),this._value="inherit"}}class Cee extends Lb{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._parent._value._layouter._needsProcess=!1}process(e){if(this._value!=="none"){const t=e._whiteSpace._whiteSpacedContent,s=e._inlines._value;for(let r=1;r<s.length;r++){const n=t[r-1]+t[r];s[r].kerning=e._font._fontVariant.getKerningAmount(n)}}}}class KN extends fi{constructor(){super("children",null,!1),this._uis=[]}update(e,t){}process(e){}_compute(e){}dispose(){}}function Eee(i,e=!1){const t=i[0].index!==null,s=new Set(Object.keys(i[0].attributes)),r=new Set(Object.keys(i[0].morphAttributes)),n={},o={},a=i[0].morphTargetsRelative,l=new Qe.BufferGeometry;let c=0;for(let u=0;u<i.length;++u){const d=i[u];let p=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in d.attributes){if(!s.has(f))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;n[f]===void 0&&(n[f]=[]),n[f].push(d.attributes[f]),p++}if(p!==s.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in d.morphAttributes){if(!r.has(f))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". .morphAttributes must be consistent throughout all geometries."),null;o[f]===void 0&&(o[f]=[]),o[f].push(d.morphAttributes[f])}if(l.userData.mergedUserData=l.userData.mergedUserData||[],l.userData.mergedUserData.push(d.userData),e){let f;if(t)f=d.index.count;else if(d.attributes.position!==void 0)f=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". The geometry must have either an index or a position attribute"),null;l.addGroup(c,f,u),c+=f}}if(t){let u=0;const d=[];for(let p=0;p<i.length;++p){const f=i[p].index;for(let m=0;m<f.count;++m)d.push(f.getX(m)+u);u+=i[p].attributes.position.count}l.setIndex(d)}for(const u in n){const d=JN(n[u]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+u+" attribute."),null;l.setAttribute(u,d)}for(const u in o){const d=o[u][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[u]=[];for(let p=0;p<d;++p){const f=[];for(let A=0;A<o[u].length;++A)f.push(o[u][A][p]);const m=JN(f);if(!m)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+u+" morphAttribute."),null;l.morphAttributes[u].push(m)}}return l}function JN(i){let e,t,s,r=0;for(let a=0;a<i.length;++a){const l=i[a];if(l.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(e===void 0&&(e=l.array.constructor),e!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=l.itemSize),t!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(s===void 0&&(s=l.normalized),s!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;r+=l.array.length}const n=new e(r);let o=0;for(let a=0;a<i.length;++a)n.set(i[a].array,o),o+=i[a].array.length;return new Qe.BufferAttribute(n,t,s)}class Mee extends fi{constructor(){super("renderer")}render(e){if(!e._inlines._value||!e._inlines._value.length)return;const t=e._inlines._value.map(r=>e._font._fontVariant.getGeometricGlyph(r,e).translate(r.offsetX,r.offsetY,0)),s=Eee(t);e.setFontMesh(new Qe.Mesh(s,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class Tee extends AM{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class zf extends Og{constructor(e={}){const t={};zf.definePropertiesValues(t,e),super(t,e),h(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0}),zf.init(this)}add(e){const t=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(t.push(r),r.position.z=.005):console.warn("Block element can only contain Box elements.",r)}return super.add(...t)}set textContent(e){this._textContent.value=e}get textContent(){return this._textContent._value}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(e,t){e.children||(e.children=KN),e.textContent||(e.textContent=cee),e.glyphs||(e.glyphs=uee),e.inlines||(e.inlines=hee),e.layouter||(e.layouter=FN),e.renderer||(e.renderer=Mee),e.fontFamily||(e.fontFamily=jN),e.fontWeight||(e.fontWeight=zN),e.fontStyle||(e.fontStyle=NN),e.fontSize||(e.fontSize=qN),e.color||(e.color=dee),e.backgroundColor||(e.backgroundColor=pee),e.lineBreak||(e.lineBreak=UN),e.letterSpacing||(e.letterSpacing=XN),e.whiteSpace||(e.whiteSpace=ZM),e.segments||(e.segments=See),e.textAlign||(e.textAlign=Tee),e.fontKerning||(e.fontKerning=Cee)}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class Iee extends BF{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this._needsUpdate=!1;for(let s=e.children.length-1;s>=0;s--){const r=e.children[s];r.isUI&&(e.remove(r),r.clear())}e._children._uis=[],this._value&&e.add(new zf({name:"anonymousInline",textContent:this._value}))}}class Ree extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class Pee extends fi{constructor(){super("layouter",null,!1),this._value=null}update(e,t){}process(e){let t=e._width._value;e._width._auto?t=1/0:t=e._bounds._innerWidth;const s=e._lineHeight._value,r=new Ree(new LN);let n=0;e._children._inlines.forEach(d=>{if(!d._inlines.value)return;this._resetInlines(d);const p=d._fontSize._value,f=d._letterSpacing._value*p,m=d._whiteSpace._value,A=d._lineBreak._value,v={WHITESPACE:m,LETTERSPACING:f,BREAKON:A,INNER_WIDTH:t},g=d._whiteSpace._inlineWrapper;n+=d._margin._value.w+d._padding._value.w,d._inlines.value.forEach((b,y,_)=>{const S=r[r.length-1];if(g(_,y,n,v)){if(r.push(new LN(b)),b.offsetX=b.xoffset,b.width===0){n=0;return}b.cumulativeWidth=b.xadvance+f,n=b.cumulativeWidth;return}r[r.length-1].push(b),b.offsetX=n+b.xoffset+b.kerning,b.cumulativeWidth=b.xadvance+b.kerning+f,n+=b.cumulativeWidth,S.length-1===1&&S[S.length-2].width===0&&(b.offsetX-=b.xoffset,n-=b.xoffset)}),n+=d._margin._value.y+d._padding._value.y});const o=e._whiteSpace._inlineCollapser;let a=0,l=0,c=0;r.forEach((d,p)=>{const f=o(d);let m=0,A=0;if(d.forEach(v=>{m=Math.max(m,v.lineHeight),A=Math.max(A,v.lineBase),v.offsetX-=f}),d.lineHeight=m,d.lineBase=A,p===0?c=-(m*s-m)*.5:c-=r[p-1].lineHeight*s,d.y=c,d.x=0,d.forEach(v=>{v.offsetY=c-v.anchor,v.lineHeight<d.lineHeight&&(v.offsetY-=d.lineBase-v.lineBase)}),l+=d.lineHeight*s,d.width=0,d[0]){const v=d[d.length-1];d.width=v.offsetX+v.cumulativeWidth+v.paddingRight+v.marginRight+d[0].offsetX,a=Math.max(a,d.width)}}),r.height=l,r.width=a,this._value=r,t===1/0&&e._bounds.setChildrenWidth(e,r.width),e._height._auto&&e._bounds.setChildrenHeight(e,r.height);const u=e._parent._value;u&&(u._autoSize._needsProcess=!0,u._flexDirection._needsProcess=!0),e._inlineJustificator._needsProcess=!0,e._textAlign._needsProcess=!0,e._overflow._needsUpdate=!0}_resetInlines(e){e._fontSize.process(e)}}class Bee extends AM{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput,this._needsProcess=!0}process(e){Dee(e),e._renderer._needsRender=!0}}function Dee(i){const e=i._layouter._value,t=i._textAlign._value,s=i._bounds._innerWidth;for(let r=0;r<e.length;r++){const n=e[r],o=kee(i,n,r===e.length-1),a=i._padding._value,l=i._borderWidth._value,c=(-a.w+a.y)/2+(-l.w+l.y)/2;n.x+=o;for(let u=0;u<n.length;u++)n[u].offsetX+=o-c}if(t.indexOf("justify")===0)for(let r=0;r<e.length;r++){const n=e[r];if(t.indexOf("-")!==-1&&r===e.length-1)return;const o=s-n.width;if(o<=0)return;let a=0;for(let d=1;d<n.length-1;d++)a+=n[d].char===" "?1:0;const l=o/a;let c=1;t==="justify-right"&&(n.reverse(),c=-1);let u=0;for(let d=1;d<=n.length-1;d++){const p=n[d];p.offsetX+=u*c,u+=p.char===" "?l:0}t==="justify-right"&&n.reverse()}}function kee(i,e,t){switch(i._textAlign._value){case"justify-left":case"justify":case"left":return-i._bounds._innerWidth/2;case"justify-right":case"right":return-e.width+i._bounds._innerWidth/2;case"center":return-e.width/2;case"justify-center":return t?-e.width/2:-i._bounds._innerWidth/2;default:console.warn(`textAlign: '${i._textAlign._value}' is not valid`)}}class Oee extends yM{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput}}class Lee extends GF{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class Uee extends Lb{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e)}}class Fee extends BN{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class Nee extends fi{constructor(){super("children",null,!1),h(this,"_sortOrder",(e,t)=>e._order._value<t._order._value?-1:e._order._value>t._order._value?1:this._uis.indexOf(e)<this._uis.indexOf(t)?-1:1),this._uis=[],this._inlines=[],this._boxes=[]}update(e,t){this._compute(e),this._needsProcess=!0}process(e){this._compute(e),e._overflow._needsRender=!0}_compute(e){this._uis=e.children.filter(t=>t.visible&&t.isUI),this._inlines=this._uis.filter(t=>t.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class zee extends fi{constructor(){super("autosize")}process(e){if(e._layouter._value&&e._layouter._value.length){const t=e._layouter._value,s=e._padding._value,r=e._borderWidth._value;e._width._auto&&e._bounds.setOffsetWidth(e,t.width+s.w+s.y+r.w+r.y),e._height._auto&&e._bounds.setOffsetHeight(e,t.height+s.x+s.z+r.x+r.z)}}}class jee extends ON{constructor(){super("renderer"),this._needsUpdate=!1}render(e){super.render(e);for(const t of e._children._inlines)t._renderer.render(t);e.performAfterUpdate()}}class wA extends _A{constructor(e={},t={}){wA.definePropertiesValues(t,e),super(t,e),wA.init(this)}add(e){const t=[];let s=!1;for(let r=0;r<arguments.length;r++){const n=arguments[r];!n.isUI||n.isInline?(n.isInline&&(s=!0),t.push(n)):console.warn("Block element can only contain Box elements.",n)}return t.length>0&&super.add(...t),s&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(e){this._textContent.value=e}get textContent(){return super.textContent}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(e,t){e.flexDirection=Oee,e.justifyContent=bM,e.alignItems=vM,e.bounds=Fee,e.autoSize=zee,e.renderer=jee,e.children||(e.children=Nee),e.textContent||(e.textContent=Iee),e.layouter||(e.layouter=Pee),e.lineHeight||(e.lineHeight=Lee),e.textAlign||(e.textAlign=Bee),e.whiteSpace||(e.whiteSpace=ZM),e.fontKerning||(e.fontKerning=Uee),e.segments||(e.segments=YN),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class Gee extends fi{constructor(){super("inlines",null,!1),this._value=[]}process(e){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}}class Qee extends fi{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new kN(e)),e._backgroundMesh.position.x=e._inlines._value[0].offsetX+e._inlines._value[0].width/2,e._backgroundMesh.position.y=e._inlines._value[0].offsetY+e._inlines._value[0].lineBase/2,e._bounds.render(e)}}class Hee extends fi{constructor(){super("bounds",null,!1),this._size=new Qe.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(e,t){this.output(t),this._needsProcess=!0}process(e){this._offsetWidth=this._innerWidth=e._inlines._value[0].width,this._offsetHeight=this._innerHeight=e._inlines._value[0].height,this._needsRender=!0,e._borderWidth._needsRender=!0,e._borderRadius._needsRender=!0}render(e){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(e){e.size=this._size}}class SA extends Og{constructor(e={}){const t={};SA.definePropertiesValues(t,e),super(t,e),SA.init(this)}clear(){for(const e of this._inlines._value)e.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new Qe.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];r.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",r):(t.push(r),r.position.z=.005)}return super.add(...t)}static definePropertiesValues(e,t){e.children||(e.children=KN),e.bounds||(e.bounds=Hee),e.inlines||(e.inlines=Gee),e.layouter||(e.layouter=FN),e.renderer||(e.renderer=Qee),e.fontFamily||(e.fontFamily=jN),e.fontWeight||(e.fontWeight=zN),e.fontStyle||(e.fontStyle=NN),e.fontSize||(e.fontSize=qN),e.backgroundColor||(e.backgroundColor=IF),e.lineBreak||(e.lineBreak=UN),e.letterSpacing||(e.letterSpacing=XN),e.whiteSpace||(e.whiteSpace=ZM),e.fontKerning||(e.fontKerning=Lb),t.backgroundSize||(t.backgroundSize="cover"),t.width||(t.width="100%"),t.height||(t.height="100%"),t.boxSizing||(t.boxSizing="border-box")}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),e._inlines._value=[new Vee(e)],e.backgroundMaterial=new PN,e._renderer.render(e)}}class Vee extends UF{constructor(e){super(),this._uiElement=e}get xadvance(){const e=this._uiElement._padding._value,t=this._uiElement._width;return t._relative?t._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.w+e.y+t.value}get width(){const e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get height(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get anchor(){return this.height}get lineHeight(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get lineBase(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}clear(){this._uiElement=null}}class ZN{constructor(e){this._subject=e}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const $N=()=>Vb.update(),e3={BaseProperty:fi,Block:xA,Text:wA,Inline:zf,InlineBlock:SA,MeshUIBaseElement:Og,FontLibrary:Mu,update:$N,MSDFFontMaterialUtils:Fo,ShaderChunkUI:RN,Behavior:ZN,FontVariant:Mg};typeof global<"u"&&(global.ThreeMeshUI=e3);const Wee=e3;var Xee=Ss.w8,t3=Ss.cg,$M=Ss.gO,qee=Ss.wb,eT=Ss.zV,Yee=Ss.HS,Kee=Ss.Ec,Xb=Ss.gF,Jee=Ss.ol,Zee=Ss.pz,$ee=Ss.tx,ete=Ss.hj,tte=Ss.FV,ite=Ss.sV,tT=Ss.xv,ste=Ss.mx,rte=Ss.gE,Tp=Ss.ZP,i3=Ss.Vx;const iT=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:Xee,Behavior:t3,Block:$M,DefaultValues:qee,FontLibrary:eT,FontVariant:Yee,InheritableProperty:Kee,Inline:Xb,InlineBlock:Jee,InlineGlyph:Zee,MSDFFontMaterialUtils:$ee,MaterialTransformers:ete,MeshUIBaseElement:tte,ShaderChunkUI:ite,Text:tT,TypographicFont:ste,TypographicGlyph:rte,default:Tp,update:i3},Symbol.toStringTag,{value:"Module"})),sn=new w,s3=new w,r3=new Me,nte=oe("debuggizmos"),Gl=8947848;class ka{static DrawLabel(e,t,s=.1,r=9999,n,o,a){n||(n=Gl);const l=Cs.getTextLabel(r,t,s,n,o);return a instanceof _e&&a.add(l),l.position.x=e.x,l.position.y=e.y,l.position.z=e.z,l}static DrawRay(e,t,s=Gl,r=0,n=!0){const o=Cs.getLine(r),a=o.geometry.getAttribute("position");a.setXYZ(0,e.x,e.y,e.z),sn.set(t.x,t.y,t.z).multiplyScalar(999999999),a.setXYZ(1,e.x+sn.x,e.y+sn.y,e.z+sn.z),a.needsUpdate=!0,o.material.color.set(s),o.material.depthTest=n,o.material.depthWrite=!1}static DrawDirection(e,t,s=Gl,r=0,n=!0,o=1){const a=Cs.getLine(r),l=a.geometry.getAttribute("position");l.setXYZ(0,e.x,e.y,e.z),t.w!==void 0?(sn.set(0,0,-o),r3.set(t.x,t.y,t.z,t.w),sn.applyQuaternion(r3)):(sn.set(t.x,t.y,t.z),sn.multiplyScalar(o)),l.setXYZ(1,e.x+sn.x,e.y+sn.y,e.z+sn.z),l.needsUpdate=!0,a.material.color.set(s),a.material.depthTest=n,a.material.depthWrite=!1}static DrawLine(e,t,s=Gl,r=0,n=!0){const o=Cs.getLine(r),a=o.geometry.getAttribute("position");a.setXYZ(0,e.x,e.y,e.z),a.setXYZ(1,t.x,t.y,t.z),a.needsUpdate=!0,o.material.color.set(s),o.material.depthTest=n,o.material.depthWrite=!1}static DrawWireSphere(e,t,s=Gl,r=0,n=!0){const o=Cs.getSphere(t,r,!0);lu(o,e.x,e.y,e.z),o.material.color.set(s),o.material.depthTest=n,o.material.depthWrite=!1}static DrawSphere(e,t,s=Gl,r=0,n=!0){const o=Cs.getSphere(t,r,!1);lu(o,e.x,e.y,e.z),o.material.color.set(s),o.material.depthTest=n,o.material.depthWrite=!1}static DrawWireBox(e,t,s=Gl,r=0,n=!0){const o=Cs.getBox(r);o.position.set(e.x,e.y,e.z),o.scale.set(t.x,t.y,t.z),o.material.color.set(s),o.material.depthTest=n,o.material.wireframe=!0,o.material.depthWrite=!1}static DrawWireBox3(e,t=Gl,s=0,r=!0){const n=Cs.getBox(s);n.position.copy(e.getCenter(sn)),n.scale.copy(e.getSize(sn)),n.material.color.set(t),n.material.depthTest=r,n.material.wireframe=!0,n.material.depthWrite=!1}static DrawArrow(e,t,s=Gl,r=0,n=!0,o=!1){const a=Cs.getArrowHead(r);a.position.set(t.x,t.y,t.z),a.quaternion.setFromUnitVectors(this._up.set(0,1,0),sn.set(t.x,t.y,t.z).sub(s3.set(e.x,e.y,e.z)).normalize());const l=sn.set(t.x,t.y,t.z).sub(s3.set(e.x,e.y,e.z)).length()*.1;a.scale.set(l,l,l),a.material.color.set(s),a.material.depthTest=n,a.material.wireframe=o,this.DrawLine(e,t,s,r,n)}}h(ka,"_up",new w(0,1,0));const ote=new Pi(1,1,1);function n3(i=null){const e=new be(i??14540253),t=new pS(ote);return new Ln(t,new os({color:e}))}const o3=Symbol("GizmoCache");class Cs{static ensureFont(){let e=Tp.FontLibrary.getFontFamily(this.familyName);if(!e){e=Tp.FontLibrary.addFontFamily(this.familyName);const t=e.addVariant("normal","normal","./include/needle/arial-msdf.json","./include/needle/arial.png");t?.addEventListener("ready",()=>{Tp.update()})}}static getTextLabel(e,t,s,r,n){this.ensureFont();let o=this.textLabelCache.pop(),a=1;n&&typeof n=="string"&&n?.length>=8&&n.startsWith("#")?(a=parseInt(n.substring(7),16)/255,n=n.substring(0,7),nte&&console.log(n,a)):typeof n=="object"&&n.a!==void 0&&(a=n.a);const l={boxSizing:"border-box",fontFamily:this.familyName,width:"auto",fontSize:s,color:r,lineHeight:.75,backgroundColor:n??void 0,backgroundOpacity:a,textContent:t,borderRadius:1*s,padding:1*s};if(o)o.set(l);else{o=new tT(l);const c=this,u=o;u.setText=function(d){this.set({textContent:d,whiteSpace:"pre"}),c.tmuiNeedsUpdate=!0}}return this.tmuiNeedsUpdate=!0,o.layers.disableAll(),o.layers.enable(2),this.registerTimedObject(Ot.Current,o,e,this.textLabelCache),o}static getBox(e){let t=this.boxesCache.pop();if(!t){const s=new Pi(1,1,1);t=new ge(s)}return this.registerTimedObject(Ot.Current,t,e,this.boxesCache),t}static getLine(e){let t=this.linesCache.pop();if(!t){t=new as;let s=t.geometry.getAttribute("position");s||(s=new et(new Float32Array(2*3),3),t.geometry.setAttribute("position",s))}return this.registerTimedObject(Ot.Current,t,e,this.linesCache),t}static getSphere(e,t,s){let r=this.spheresCache.pop();return r||(r=new ge(new Lo(1,8,8))),r.scale.set(e,e,e),r.material.wireframe=s,this.registerTimedObject(Ot.Current,r,t,this.spheresCache),r}static getArrowHead(e){let t=this.arrowHeadsCache.pop();return t||(t=new ge(new ys(0,.5,1,8))),this.registerTimedObject(Ot.Current,t,e,this.arrowHeadsCache),t}static registerTimedObject(e,t,s,r){if(!this.contextPostRenderCallbacks.get(e)){const n=()=>{this.onPostRender(e,this.timedObjectsBuffer,this.timesBuffer)};this.contextPostRenderCallbacks.set(e,n),e.post_render_callbacks.push(n)}if(!this.contextBeforeRenderCallbacks.get(e)){const n=()=>{this.onBeforeRender(e,this.timedObjectsBuffer)};this.contextBeforeRenderCallbacks.set(e,n),e.pre_render_callbacks.push(n)}t.layers.disableAll(),t.layers.enable(2),t[o3]=r,this.timedObjectsBuffer.push(t),this.timesBuffer.push(Ot.Current.time.time+s),e.scene.add(t)}static onBeforeRender(e,t){this.tmuiNeedsUpdate&&Tp.update();for(let s=0;s<t.length;s++){const r=t[s];if(e.mainCamera&&r instanceof Tp.MeshUIBaseElement){const n=e.isInVR,o=n,a=!n;tC(r,e.mainCamera,o,a)}}}static onPostRender(e,t,s){const r=e.time.time;for(let n=0;n<t.length;n++){const o=t[n];r>s[n]&&(o[o3].push(o),o.removeFromParent(),t.splice(n,1),s.splice(n,1))}}}h(Cs,"familyName","needle-gizmos"),h(Cs,"linesCache",[]),h(Cs,"spheresCache",[]),h(Cs,"boxesCache",[]),h(Cs,"arrowHeadsCache",[]),h(Cs,"textLabelCache",[]),h(Cs,"timedObjectsBuffer",new Array),h(Cs,"timesBuffer",new Array),h(Cs,"contextPostRenderCallbacks",new Map),h(Cs,"contextBeforeRenderCallbacks",new Map),h(Cs,"tmuiNeedsUpdate",!1);const ate=oe("gizmos"),lte=oe("debugboxhelper"),aa=class extends Pe{constructor(){super(...arguments),h(this,"box",null),h(this,"_lastMatrixUpdateFrame",-1),h(this,"_helper",null),h(this,"_color",null)}isInBox(i,e){var t;if(!i)return;if(this.box||(this.box=new _s),i.type==="Mesh")aa.testBox.setFromObject(i);else if(i.type==="Group"){if(aa.testBox.makeEmpty(),i.children.length>0)for(let r=0;r<i.children.length;r++)i.children[r].type==="Mesh"&&aa.testBox.expandByObject(i)}else{const r=ft(i,aa._position),n=Vs(i,aa._size);e!==void 0&&n.multiplyScalar(e),aa.testBox.setFromCenterAndSize(r,n)}this.updateBox();const s=(t=this.box)==null?void 0:t.intersectsBox(aa.testBox);return s&&lte&&ka.DrawWireBox3(aa.testBox,16711680,5),s}intersects(i){return i?this.updateBox(!1).intersectsBox(i):!1}updateBox(i=!1){if(this.box||(this.box=new _s),i||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const e=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const t=e,s=ft(this.gameObject,aa._position,t),r=Vs(this.gameObject,aa._size);this.box.setFromCenterAndSize(s,r)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(i=null,e=!1){var t;if(!(!ate&&!e)){if(this._helper){i&&((t=this._color)==null||t.set(i)),this.gameObject.add(this._helper);return}this._helper=n3(i),this.gameObject.add(this._helper)}}};let Oa=aa;h(Oa,"testBox",new _s),h(Oa,"_position",new w),h(Oa,"_size",new w(.01,.01,.01));var cte=Object.defineProperty,hte=Object.getOwnPropertyDescriptor,a3=(i,e,t,s)=>{for(var r=s>1?void 0:s?hte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&cte(e,t,r),r};const Lg=oe("debugreflectionprobe"),l3=oe("noreflectionprobe"),ute=Symbol("reflectionProbeKey"),dte=Symbol("original material");var qb;const Ql=(qb=class extends Pe{constructor(){var i;super(),h(this,"_texture"),h(this,"center"),h(this,"size"),h(this,"_boxHelper"),Ql._probes.has(this.context)||Ql._probes.set(this.context,[]),(i=Ql._probes.get(this.context))==null||i.push(this)}static get(i,e,t,s){if(!i||i.isObject3D!==!0||l3)return null;const r=Ql._probes.get(e);if(r){for(const n of r)if(n.__didAwake||n.__internalAwake(),n.enabled){if(s){if(n.gameObject===s)return n}else if(n.isInBox(i,void 0))return Lg&&console.log("Found reflection probe",i.name,n.name),n}}return Lg&&console.debug("Did not find reflection probe",i.name,t,i),null}set texture(i){if(i&&!(i instanceof Dt)){console.error("ReflectionProbe.texture must be a Texture",i);return}this._texture=i,i&&(i.mapping=so,i.colorSpace=it,i.needsUpdate=!0)}get texture(){return this._texture}isInBox(i,e){var t;return(t=this._boxHelper)==null?void 0:t.isInBox(i,e)}awake(){this._boxHelper=this.gameObject.addNewComponent(Oa),this._boxHelper.updateBox(!0),Lg&&this._boxHelper.showHelper(5592320,!0),this.texture&&(this.texture.mapping=so,this.texture.colorSpace=it,this.texture.needsUpdate=!0)}onDestroy(){const i=Ql._probes.get(this.context);if(i){const e=i.indexOf(this);e>=0&&i.splice(e,1)}}onSet(i){var e;if(l3||!this.enabled||((e=i.sharedMaterials)==null?void 0:e.length)<=0||!this.texture)return;let t=Ql._rendererMaterialsCache.get(i);t||(t=[],Ql._rendererMaterialsCache.set(i,t));for(let s=0;s<i.sharedMaterials.length;s++){const r=i.sharedMaterials[s];if(!r||r.envMap===void 0)continue;let n=t[s];const o=r===n?.copy,a=!n||n.material.uuid!==r.uuid||n.copy.version!==r.version;if(!o&&a){if(Lg){let u="";n?n.material!==r?u="reference changed; cached instance?: "+o:n.copy.version!==r.version&&(u="version changed"):u="not cached",console.warn("Cloning material",r.name,r.version,"Reason:",u,`
4916
4918
  `,r.uuid,`
4917
4919
  `,n?.copy.uuid,`
4918
- `,i.name)}const c=r.clone();c.version=r.version,n?(n.copy=c,n.material=r):(n={material:r,copy:c},t.push(n)),c[ute]=this,c[dte]=r,Lg&&console.log("Set reflection",i.name,i.guid)}const l=n?.copy;l.envMap=this.texture,i.sharedMaterials[s]=l}}onUnset(i){const e=Ql._rendererMaterialsCache.get(i);if(e)for(let t=0;t<e.length;t++){const s=e[t];i.sharedMaterials[t]=s.material}}},h(qb,"_probes",new Map),h(qb,"_rendererMaterialsCache",new Map),qb);let Ip=Ql;a3([x(w)],Ip.prototype,"center",2),a3([x(w)],Ip.prototype,"size",2);const c3=Symbol("customVisibilityFlag");function Yb(i,e){i.layers[c3]=e}const h3=Symbol("DidPatchLayers");function pte(){const i=Tr.prototype;if(i[h3])return;i[h3]=!0;const e=i.test;i.test=function(t){return this[c3]===!1?!1:e.call(this,t)}}pte();var fte=Object.defineProperty,mte=Object.getOwnPropertyDescriptor,Hl=(i,e,t,s)=>{for(var r=s>1?void 0:s?mte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&fte(e,t,r),r};const Kb=oe("debugrenderer"),gte=oe("debugskinnedmesh"),u3=oe("noInstancing"),sT=oe("debuginstancing"),vte=oe("debugprogressive"),Ate=oe("noprogressive"),yte=oe("wireframe");class rT{constructor(){h(this,"path",null),h(this,"asset",null),h(this,"default")}}class bte{constructor(e,t){h(this,"_renderer"),h(this,"_targets",[]),h(this,"_indexMapMaxIndex"),h(this,"_indexMap"),h(this,"_changed",!1),this._renderer=e;const s=this.setMaterial.bind(this),r=this.getMaterial.bind(this),n=e.gameObject;if(this._targets=[],n)switch(n.type){case"Group":this._targets=[...n.children];break;case"SkinnedMesh":case"Mesh":this._targets.push(n);break}let o=!1,a,l=0;for(let c=0;c<this._targets.length;c++){const u=this._targets[c];if(!u)continue;const d=u.material;if(d){d.shadowSide=d.side;for(let p=0;p<t.length;p++){const f=t[p];if(!f){o=!0;continue}if(d.name===f.name){a===void 0&&(a=new Map),a.set(p,c),l=Math.max(l,p);break}}}}if(o){this._indexMapMaxIndex=l,this._indexMap=a;const c=`Renderer ${e.name} was initialized with missing materials - this may lead to unexpected behaviour when trying to access sharedMaterials by index.`;console.warn(c),qr()&&Hs("Found renderer with missing materials: please check the console for details.")}return new Proxy(this,{get(c,u){if(typeof u=="string"){const d=parseInt(u);if(!isNaN(d))return r(d)}return c[u]},set(c,u,d){return typeof u=="string"&&s(d,Number.parseInt(u)),Reflect.set(c,u,d)?(d instanceof kt&&(c.changed=!0),!0):!1}})}get changed(){return this._changed}set changed(e){e===!0&&Kb&&console.warn("SharedMaterials have changed: "+this._renderer.name,this),this._changed=e}is(e){return this._renderer===e}get length(){return this._indexMapMaxIndex!==void 0?this._indexMapMaxIndex+1:this._targets.length}*[Symbol.iterator](){for(let e=0;e<this.length;e++)yield this.getMaterial(e)}resolveIndex(e){const t=this._indexMap;return t&&t.has(e)?t.get(e):e}setMaterial(e,t){if(t=this.resolveIndex(t),t<0||t>=this._targets.length)return;const s=this._targets[t];!s||s.material===void 0||(s.material=e,this.changed=!0)}getMaterial(e){if(e=this.resolveIndex(e),e<0)return null;const t=this._targets;if(e>=t.length)return null;const s=t[e];return s?s.material:null}}const d3=class extends Pe{constructor(){super(...arguments),h(this,"receiveShadows",!1),h(this,"shadowCastingMode",0),h(this,"lightmapIndex",-1),h(this,"lightmapScaleOffset",new tt(1,1,0,0)),h(this,"enableInstancing"),h(this,"renderOrder"),h(this,"allowOcclusionWhenDynamic",!0),h(this,"probeAnchor"),h(this,"reflectionProbeUsage",0),h(this,"_lightmaps"),h(this,"_sharedMaterials"),h(this,"_originalMaterials"),h(this,"_lightmapTextureOverride"),h(this,"allowProgressiveLoading",!0),h(this,"_isInstancingEnabled",!1),h(this,"handles"),h(this,"prevLayers"),h(this,"onBeforeRenderThree",(i,e,t,s,r,n)=>{var o;if(r.envMapIntensity!==void 0){const a=this.hasLightmap?Math.PI:1,l=((o=this.context.mainCameraComponent)==null?void 0:o.environmentIntensity)??1;r.envMapIntensity=Math.max(0,l*this.context.sceneLighting.environmentIntensity/a)}if(this._lightmaps)for(const a of this._lightmaps)a.updateLightmapUniforms(r)}),h(this,"_reflectionProbe",null)}static setVisible(i,e){Yb(i,e)}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(i){this.sharedMaterials[0]!==i&&(this.sharedMaterials[0]=i,this.applyLightmapping())}get material(){return this.sharedMaterials[0]}set material(i){this.sharedMaterial=i}set sharedMaterials(i){if(!this._originalMaterials)this._originalMaterials=i;else if(i){let e=!1;for(let t=0;t<this._sharedMaterials.length;t++){const s=t<i.length?i[t]:null;s&&s instanceof kt?this.sharedMaterials[t]=s:e||(e=!0,console.warn("Can not assign null as material: "+this.name,s))}}}get sharedMaterials(){return(!this._sharedMaterials||!this._sharedMaterials.is(this))&&(this._originalMaterials||(this._originalMaterials=[]),this._sharedMaterials=new bte(this,this._originalMaterials)),this._sharedMaterials}static get shouldSuppressInstancing(){return u3}get lightmap(){var i;return(i=this._lightmaps)!=null&&i.length?this._lightmaps[0].lightmap:null}set lightmap(i){var e;if(this._lightmapTextureOverride=i,i===void 0&&(i=this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex)),(e=this._lightmaps)!=null&&e.length)for(const t of this._lightmaps)t.lightmap=i}get hasLightmap(){return this.lightmap!=null}registering(){this.enabled||this.setVisibility(!1)}awake(){if(Kb&&console.log("Renderer ",this.name,this),this.clearInstancingState(),this.probeAnchor&&Kb&&this.probeAnchor.add(new Kd(.2)),this._reflectionProbe=null,this.isMultiMaterialObject(this.gameObject)){for(const i of this.gameObject.children)this.context.addBeforeRenderListener(i,this.onBeforeRenderThree),i.layers.mask=this.gameObject.layers.mask;if(this.renderOrder!==void 0){let i=0;for(let e=0;e<this.gameObject.children.length;e++){const t=this.gameObject.children[e];if(!(!this.isMeshOrSkinnedMesh(t)||te.getComponent(t,d3))){if(this.renderOrder.length<=i){console.warn("Incorrect renderOrder element count",this,this.renderOrder.length+" but expected "+this.gameObject.children.length,"Index: "+i,"ChildElement:",t);continue}t.renderOrder=this.renderOrder[i],i+=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(),yte)for(let i=0;i<this.sharedMaterials.length;i++){const e=this.sharedMaterials[i];e&&(e.wireframe=!0)}}applyLightmapping(){var i;if(this.lightmapIndex>=0){const e=this.gameObject.type,t=this._lightmapTextureOverride!==void 0?this._lightmapTextureOverride:this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex);if(t){if(this._lightmaps||(this._lightmaps=[]),e==="Mesh"){const s=this.gameObject.material;if(s!=null&&s.isMeshBasicMaterial)s&&console.warn("Lightmapping is not supported on MeshBasicMaterial",s.name);else{if(this._lightmaps.length<=0){const r=new Cg(this.gameObject,this.context);this._lightmaps.push(r)}this._lightmaps[0].init(this.lightmapIndex,this.lightmapScaleOffset,t)}}else if(this.isMultiMaterialObject(this.gameObject)&&this.sharedMaterials.length>0)for(let s=0;s<this.gameObject.children.length;s++){const r=this.gameObject.children[s];if(!((i=r.material)!=null&&i.isMeshBasicMaterial)){let n;s>=this._lightmaps.length?(n=new Cg(r,this.context),this._lightmaps.push(n)):n=this._lightmaps[s],n.init(this.lightmapIndex,this.lightmapScaleOffset,t)}}}else Kb&&console.warn("Lightmap not found",this.sourceId,this.lightmapIndex)}}clearInstancingState(){this._isInstancingEnabled=!1,this.handles=void 0,this.prevLayers=void 0}setInstancingEnabled(i){if(this._isInstancingEnabled===i)return i&&(this.handles===void 0||this.handles!=null&&this.handles.length>0);if(this._isInstancingEnabled=i,i){if(this.handles===void 0){if(this.handles=xte.setup(this,this.gameObject,this.context,null,{rend:this,foundMeshes:0,useMatrixWorldAutoUpdate:this.useInstanceMatrixWorldAutoUpdate()}),this.handles)return te.markAsInstancedRendered(this.gameObject,!0),!0}else if(this.handles!==null){for(const e of this.handles)e.updateInstanceMatrix(!0),e.add();return te.markAsInstancedRendered(this.gameObject,!0),!0}}else{if(this.handles)for(const e of this.handles)e.remove();return!0}return!1}useInstanceMatrixWorldAutoUpdate(){return!0}start(){if(this.enableInstancing&&!u3&&(this.setInstancingEnabled(!0),Nr.markDirty(this.gameObject)),this.gameObject.frustumCulled=this.allowOcclusionWhenDynamic,this.isMultiMaterialObject(this.gameObject))for(let i=0;i<this.gameObject.children.length;i++){const e=this.gameObject.children[i];e.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 i of this.gameObject.children)this.context.removeBeforeRenderListener(i,this.onBeforeRenderThree);else this.context.removeBeforeRenderListener(this.gameObject,this.onBeforeRenderThree)}applyStencil(){rM.applyStencil(this)}onBeforeRender(){var i,e;if(this.gameObject){if(this.isMultiMaterialObject(this.gameObject)&&((i=this.gameObject.children)==null?void 0:i.length)>0)for(const t of this.gameObject.children)this.applySettings(t);else this.applySettings(this.gameObject);if(this.sharedMaterials.changed&&(this.sharedMaterials.changed=!1,this.applyLightmapping()),(e=this.handles)!=null&&e.length&&this.gameObject[ig]===!0){sT&&console.log("UPDATE INSTANCED MATRICES",this.context.time.frame),this.gameObject[ig]=!1;for(let t=this.handles.length-1;t>=0;t--)this.handles[t].updateInstanceMatrix();this.gameObject.matrixWorldNeedsUpdate=!1}if(this.handles&&this.handles.length<=0&&te.markAsInstancedRendered(this.gameObject,!1),this._isInstancingEnabled&&this.handles)for(let t=0;t<this.handles.length;t++){const s=this.handles[t];this.prevLayers||(this.prevLayers=[]);const r=s.object.layers.mask;t>=this.prevLayers.length?this.prevLayers.push(r):this.prevLayers[t]=r,s.object.layers.disableAll()}for(const t of this.sharedMaterials)t&&this.loadProgressiveTextures(t);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 i=0;i<this.handles.length;i++){const e=this.handles[i];e.object.layers.mask=this.prevLayers[i]}this.reflectionProbeUsage!==0&&this._reflectionProbe&&this._reflectionProbe.onUnset(this)}loadProgressiveTextures(i){return!Ate&&i&&i._didRequestTextureLOD===void 0&&this.allowProgressiveLoading?(i._didRequestTextureLOD=0,vte&&console.log("Load material LOD",i.name),sa.assignTextureLOD(this.context,this.sourceId,i)):Promise.resolve(!0)}applySettings(i){i.receiveShadow=this.receiveShadows,this.shadowCastingMode==1?i.castShadow=!0:i.castShadow=!1}updateReflectionProbe(){if(this._reflectionProbe=null,this.reflectionProbeUsage!==0){if(!this.probeAnchor)return;this.startCoroutine(this._updateReflectionProbe(),Ws.LateUpdate)}}*_updateReflectionProbe(){const i=this.probeAnchor||this.gameObject,e=!!this.probeAnchor;this._reflectionProbe=Ip.get(i,this.context,e,this.probeAnchor)}setVisibility(i){if(!this.isMultiMaterialObject(this.gameObject))Yb(this.gameObject,i);else for(const e of this.gameObject.children)this.isMeshOrSkinnedMesh(e)&&Yb(e,i)}isMultiMaterialObject(i){return i.type==="Group"}isMeshOrSkinnedMesh(i){return i.type==="Mesh"||i.type==="SkinnedMesh"}};let ps=d3;Hl([x()],ps.prototype,"receiveShadows",2),Hl([x()],ps.prototype,"shadowCastingMode",2),Hl([x()],ps.prototype,"lightmapIndex",2),Hl([x(tt)],ps.prototype,"lightmapScaleOffset",2),Hl([x()],ps.prototype,"enableInstancing",2),Hl([x()],ps.prototype,"renderOrder",2),Hl([x()],ps.prototype,"allowOcclusionWhenDynamic",2),Hl([x(_e)],ps.prototype,"probeAnchor",2),Hl([x()],ps.prototype,"reflectionProbeUsage",2);class Jb extends ps{}class nT extends Jb{awake(){var e;super.awake(),this.allowOcclusionWhenDynamic=!1,(e=this.gameObject.parent)==null||e.updateWorldMatrix(!1,!0)}onBeforeRender(){if(super.onBeforeRender(),gte&&this.gameObject instanceof Vo&&this.gameObject.boundingSphere){const e=Bm(this.gameObject.boundingSphere.center).applyMatrix4(this.gameObject.matrixWorld);ka.DrawWireSphere(e,this.gameObject.boundingSphere.radius,"red")}}}class _te{constructor(){h(this,"objs",[])}setup(e,t,s,r,n,o=0){e.applySettings(t);const a=this.tryCreateOrAddInstance(t,s,n);if(a)e.loadProgressiveTextures(a.instancer.material),r===null&&(r=[]),r.push(a);else if(o<=0&&t.type!=="Mesh"){const l=o+1;for(const c of t.children)r=this.setup(e,c,s,r,n,l)}return o===0&&n.useMatrixWorldAutoUpdate&&r&&r.length>=0&&this.autoUpdateInstanceMatrix(t),r}tryCreateOrAddInstance(e,t,s){if(e.type==="Mesh"){const r=s.foundMeshes;if(s.foundMeshes+=1,!s.rend.enableInstancing||r>=s.rend.enableInstancing.length||!s.rend.enableInstancing[r])return null;const n=e,o=n.geometry,a=n.material;for(const c of this.objs)if(!c.isFull()&&c.geo===o&&c.material===a)return c.addInstance(n);const l=new f3(e.name,o,a,200,t);return this.objs.push(l),l.addInstance(n)}return null}autoUpdateInstanceMatrix(e){const t=e.matrixWorld.multiplyMatrices.bind(e.matrixWorld),s=e.matrixWorld.clone(),r=(n,o)=>{const a=t(n,o);return(e[ig]||s.equals(a)===!1)&&(s.copy(a),e[ig]=!0),a};e.matrixWorld.multiplyMatrices=r}}const xte=new _te;class wte{constructor(e,t,s){h(this,"instanceIndex",-1),h(this,"object"),h(this,"instancer"),this.instanceIndex=e,this.object=t,this.instancer=s,t[JO]=s,te.markAsInstancedRendered(t,!0)}get name(){return this.object.name}updateInstanceMatrix(e=!1){this.instanceIndex<0||(this.object.updateWorldMatrix(!0,e),this.instancer.updateInstance(this.object.matrixWorld,this.instanceIndex))}setMatrix(e){this.instanceIndex<0||this.instancer.updateInstance(e,this.instanceIndex)}add(){this.instanceIndex>=0||this.instancer.add(this)}remove(){this.instanceIndex<0||this.instancer.remove(this)}}const p3=class{constructor(i,e,t,s,r){h(this,"name",""),h(this,"geo"),h(this,"material"),h(this,"context"),h(this,"inst"),h(this,"handles",[]),h(this,"maxCount"),h(this,"_needUpdateBounds",!1),this.name=i,this.geo=e,this.material=t,this.context=r,this.maxCount=s,sT&&(t=new ai({color:this.randomColor()})),this.inst=new Sy(e,t,s),this.inst[FC]=!0,this.inst.onBeforeRender=()=>{this._needUpdateBounds&&this.inst[FC]===!0&&(sT&&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(i){this.inst.visible=i}get castShadow(){return this.inst.castShadow}set castShadow(i){this.inst.castShadow=i}set receiveShadow(i){this.inst.receiveShadow=i}updateBounds(i=!0,e=!0){this._needUpdateBounds=!1,i&&this.inst.computeBoundingBox(),e&&this.inst.computeBoundingSphere()}get currentCount(){return this.inst.count}isFull(){return this.currentCount>=this.maxCount}randomColor(){return new be(Math.random(),Math.random(),Math.random())}addInstance(i){if(this.currentCount>=this.maxCount)return console.error("TOO MANY INSTANCES - resize is not yet implemented!",this.inst.count),null;const e=new wte(-1,i,this);return i.castShadow===!0&&this.inst.castShadow===!1&&(this.inst.castShadow=!0),i.receiveShadow===!0&&this.inst.receiveShadow===!1&&(this.inst.receiveShadow=!0),this.add(e),e}add(i){i.instanceIndex<0&&(i.instanceIndex=this.currentCount,i.instanceIndex>=this.handles.length?this.handles.push(i):this.handles[i.instanceIndex]=i),i.object.updateWorldMatrix(!0,!0),this.inst.setMatrixAt(i.instanceIndex,i.object.matrixWorld),this.inst.instanceMatrix.needsUpdate=!0,this.inst.count+=1,this._needUpdateBounds=!0,this.inst.count>0&&(this.inst.visible=!0)}remove(i){if(!(!i||i.instanceIndex<0||i.instanceIndex>=this.handles.length||this.inst.count<=0)){if(this.handles[i.instanceIndex]!==i){console.error("instance handle is not part of renderer, was it removed before?",i.instanceIndex,this.name);const e=this.handles.indexOf(i);if(e<0)return;i.instanceIndex=e}if(this.handles[i.instanceIndex]=null,this.inst.setMatrixAt(i.instanceIndex,p3.nullMatrix),!(i.instanceIndex>=this.currentCount-1)&&this.currentCount>0){const e=this.handles[this.currentCount-1];e&&(e.instanceIndex=i.instanceIndex,e.updateInstanceMatrix(),this.handles[i.instanceIndex]=e,this.handles[this.currentCount-1]=null)}this.inst.count>0&&(this.inst.count-=1),i.instanceIndex=-1,this._needUpdateBounds=!0,this.inst.count<=0&&(this.inst.visible=!1),this.inst.instanceMatrix.needsUpdate=!0}}updateInstance(i,e){this.inst.setMatrixAt(e,i),this.inst.instanceMatrix.needsUpdate=!0,this._needUpdateBounds=!0}};let f3=p3;h(f3,"nullMatrix",new Te);function Zb(i){return i=i.replace(/[^a-zA-Z0-9_]/g,""),i.match(/^[a-zA-Z_]/)||(i="_"+i),i}function m3(i){if(i.length===0)return null;const e=i.map(t=>{const s=new Array;for(;t.parent;)s.unshift(t.parent),t=t.parent;return s});return e[0].findLast(t=>e.every(s=>s.includes(t)))||null}function g3(i){const e=m3(i),t=new Set;for(const s of i){let r=s.parent;for(;r&&r!==e;)i.includes(r)||t.add(r),r=r.parent}return t}const Rp=class{constructor(i,e,t,s=null,r=null,n=null,o=null,a=null){h(this,"uuid"),h(this,"name"),h(this,"matrix"),h(this,"_isDynamic"),h(this,"geometry"),h(this,"material"),h(this,"camera"),h(this,"parent"),h(this,"skinnedMesh"),h(this,"children",[]),h(this,"animations"),h(this,"_eventListeners"),this.uuid=i,this.name=Zb(e),this.matrix=t,this.geometry=s,this.material=r,this.camera=n,this.parent=null,this.children=[],this._eventListeners={},this._isDynamic=!1,this.skinnedMesh=o,this.animations=a}get isDynamic(){return this._isDynamic}set isDynamic(i){this._isDynamic=i}static createEmptyParent(i){const e=new Rp(ir.generateUUID(),i.name+"_empty_"+Rp.USDObject_export_id++,i.matrix);return i.parent.add(e),e.add(i),e.isDynamic=!0,i.matrix=new Te().identity(),e}static createEmpty(){const i=new Rp(ir.generateUUID(),"Empty_"+Rp.USDObject_export_id++,new Te);return i.isDynamic=!0,i}is(i){return i?this.uuid===i.uuid:!1}isEmpty(){return!this.geometry}clone(){const i=new Rp(ir.generateUUID(),this.name,this.matrix,this.geometry,this.material);return i.isDynamic=this.isDynamic,i}getPath(){let i=this.parent,e=this.name;for(;i;)e=(i.parent?i.name:i.name+"/Scenes/Scene")+"/"+e,i=i.parent;return"</"+e+">"}add(i){i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i)}remove(i){const e=this.children.indexOf(i);e>=0&&(i.parent===this&&(i.parent=null),this.children.splice(e,1))}addEventListener(i,e){this._eventListeners[i]||(this._eventListeners[i]=[]),this._eventListeners[i].push(e)}removeEventListener(i,e){if(!this._eventListeners[i])return;const t=this._eventListeners[i].indexOf(e);t>=0&&this._eventListeners[i].splice(t,1)}onSerialize(i,e){const t=this._eventListeners.serialize;t&&t.forEach(s=>s(i,e))}};let xo=Rp;h(xo,"USDObject_export_id",0);class v3 extends xo{constructor(){super(void 0,"StageRoot",new Te,null,null,null),h(this,"stageLength"),this.children=[],this.stageLength=200}get isDocumentRoot(){return!0}get isDynamic(){return!1}add(e){e.parent=this,this.children.push(e)}remove(e){const t=this.children.indexOf(e);t>=0&&(e.parent===this&&(e.parent=null),this.children.splice(t,1))}traverse(e,t=null){if(t!==null?e(t):t=this,t.children)for(const s of t.children)this.traverse(e,s)}findById(e){let t=!1;function s(r){if(!t){if(r.uuid===e)return t=!0,r;if(r.children)for(const n of r.children){const o=s(n);if(o)return o}}}return s(this)}buildHeader(e){return`#usda 1.0
4920
+ `,i.name)}const c=r.clone();c.version=r.version,n?(n.copy=c,n.material=r):(n={material:r,copy:c},t.push(n)),c[ute]=this,c[dte]=r,Lg&&console.log("Set reflection",i.name,i.guid)}const l=n?.copy;l.envMap=this.texture,i.sharedMaterials[s]=l}}onUnset(i){const e=Ql._rendererMaterialsCache.get(i);if(e)for(let t=0;t<e.length;t++){const s=e[t];i.sharedMaterials[t]=s.material}}},h(qb,"_probes",new Map),h(qb,"_rendererMaterialsCache",new Map),qb);let Ip=Ql;a3([x(w)],Ip.prototype,"center",2),a3([x(w)],Ip.prototype,"size",2);const c3=Symbol("customVisibilityFlag");function Yb(i,e){i.layers[c3]=e}const h3=Symbol("DidPatchLayers");function pte(){const i=Tr.prototype;if(i[h3])return;i[h3]=!0;const e=i.test;i.test=function(t){return this[c3]===!1?!1:e.call(this,t)}}pte();var fte=Object.defineProperty,mte=Object.getOwnPropertyDescriptor,Hl=(i,e,t,s)=>{for(var r=s>1?void 0:s?mte(e,t):e,n=i.length-1,o;n>=0;n--)(o=i[n])&&(r=(s?o(e,t,r):o(r))||r);return s&&r&&fte(e,t,r),r};const Kb=oe("debugrenderer"),gte=oe("debugskinnedmesh"),u3=oe("noInstancing"),sT=oe("debuginstancing"),vte=oe("debugprogressive"),Ate=oe("noprogressive"),yte=oe("wireframe");class rT{constructor(){h(this,"path",null),h(this,"asset",null),h(this,"default")}}class bte{constructor(e,t){h(this,"_renderer"),h(this,"_targets",[]),h(this,"_indexMapMaxIndex"),h(this,"_indexMap"),h(this,"_changed",!1),this._renderer=e;const s=this.setMaterial.bind(this),r=this.getMaterial.bind(this),n=e.gameObject;if(this._targets=[],n)switch(n.type){case"Group":this._targets=[...n.children];break;case"SkinnedMesh":case"Mesh":this._targets.push(n);break}let o=!1,a,l=0;for(let c=0;c<this._targets.length;c++){const u=this._targets[c];if(!u)continue;const d=u.material;if(d){d.shadowSide=d.side;for(let p=0;p<t.length;p++){const f=t[p];if(!f){o=!0;continue}if(d.name===f.name){a===void 0&&(a=new Map),a.set(p,c),l=Math.max(l,p);break}}}}if(o){this._indexMapMaxIndex=l,this._indexMap=a;const c=`Renderer ${e.name} was initialized with missing materials - this may lead to unexpected behaviour when trying to access sharedMaterials by index.`;console.warn(c),qr()&&Hs("Found renderer with missing materials: please check the console for details.")}return new Proxy(this,{get(c,u){if(typeof u=="string"){const d=parseInt(u);if(!isNaN(d))return r(d)}return c[u]},set(c,u,d){return typeof u=="string"&&s(d,Number.parseInt(u)),Reflect.set(c,u,d)?(d instanceof kt&&(c.changed=!0),!0):!1}})}get changed(){return this._changed}set changed(e){e===!0&&Kb&&console.warn("SharedMaterials have changed: "+this._renderer.name,this),this._changed=e}is(e){return this._renderer===e}get length(){return this._indexMapMaxIndex!==void 0?this._indexMapMaxIndex+1:this._targets.length}*[Symbol.iterator](){for(let e=0;e<this.length;e++)yield this.getMaterial(e)}resolveIndex(e){const t=this._indexMap;return t&&t.has(e)?t.get(e):e}setMaterial(e,t){if(t=this.resolveIndex(t),t<0||t>=this._targets.length)return;const s=this._targets[t];!s||s.material===void 0||(s.material=e,this.changed=!0)}getMaterial(e){if(e=this.resolveIndex(e),e<0)return null;const t=this._targets;if(e>=t.length)return null;const s=t[e];return s?s.material:null}}const d3=class extends Pe{constructor(){super(...arguments),h(this,"receiveShadows",!1),h(this,"shadowCastingMode",0),h(this,"lightmapIndex",-1),h(this,"lightmapScaleOffset",new tt(1,1,0,0)),h(this,"enableInstancing"),h(this,"renderOrder"),h(this,"allowOcclusionWhenDynamic",!0),h(this,"probeAnchor"),h(this,"reflectionProbeUsage",0),h(this,"_lightmaps"),h(this,"_sharedMaterials"),h(this,"_originalMaterials"),h(this,"_lightmapTextureOverride"),h(this,"allowProgressiveLoading",!0),h(this,"_isInstancingEnabled",!1),h(this,"handles"),h(this,"prevLayers"),h(this,"onBeforeRenderThree",(i,e,t,s,r,n)=>{var o;if(r.envMapIntensity!==void 0){const a=this.hasLightmap?Math.PI:1,l=((o=this.context.mainCameraComponent)==null?void 0:o.environmentIntensity)??1;r.envMapIntensity=Math.max(0,l*this.context.sceneLighting.environmentIntensity/a)}if(this._lightmaps)for(const a of this._lightmaps)a.updateLightmapUniforms(r)}),h(this,"_reflectionProbe",null)}static setVisible(i,e){Yb(i,e)}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(i){this.sharedMaterials[0]!==i&&(this.sharedMaterials[0]=i,this.applyLightmapping())}get material(){return this.sharedMaterials[0]}set material(i){this.sharedMaterial=i}set sharedMaterials(i){if(!this._originalMaterials)this._originalMaterials=i;else if(i){let e=!1;for(let t=0;t<this._sharedMaterials.length;t++){const s=t<i.length?i[t]:null;s&&s instanceof kt?this.sharedMaterials[t]=s:e||(e=!0,console.warn("Can not assign null as material: "+this.name,s))}}}get sharedMaterials(){return(!this._sharedMaterials||!this._sharedMaterials.is(this))&&(this._originalMaterials||(this._originalMaterials=[]),this._sharedMaterials=new bte(this,this._originalMaterials)),this._sharedMaterials}static get shouldSuppressInstancing(){return u3}get lightmap(){var i;return(i=this._lightmaps)!=null&&i.length?this._lightmaps[0].lightmap:null}set lightmap(i){var e;if(this._lightmapTextureOverride=i,i===void 0&&(i=this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex)),(e=this._lightmaps)!=null&&e.length)for(const t of this._lightmaps)t.lightmap=i}get hasLightmap(){return this.lightmap!=null}registering(){this.enabled||this.setVisibility(!1)}awake(){if(Kb&&console.log("Renderer ",this.name,this),this.clearInstancingState(),this.probeAnchor&&Kb&&this.probeAnchor.add(new Kd(.2)),this._reflectionProbe=null,this.isMultiMaterialObject(this.gameObject)){for(const i of this.gameObject.children)this.context.addBeforeRenderListener(i,this.onBeforeRenderThree),i.layers.mask=this.gameObject.layers.mask;if(this.renderOrder!==void 0){let i=0;for(let e=0;e<this.gameObject.children.length;e++){const t=this.gameObject.children[e];if(!(!this.isMeshOrSkinnedMesh(t)||te.getComponent(t,d3))){if(this.renderOrder.length<=i){console.warn("Incorrect renderOrder element count",this,this.renderOrder.length+" but expected "+this.gameObject.children.length,"Index: "+i,"ChildElement:",t);continue}t.renderOrder=this.renderOrder[i],i+=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(),yte)for(let i=0;i<this.sharedMaterials.length;i++){const e=this.sharedMaterials[i];e&&(e.wireframe=!0)}}applyLightmapping(){var i;if(this.lightmapIndex>=0){const e=this.gameObject.type,t=this._lightmapTextureOverride!==void 0?this._lightmapTextureOverride:this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex);if(t){if(this._lightmaps||(this._lightmaps=[]),e==="Mesh"){const s=this.gameObject.material;if(s!=null&&s.isMeshBasicMaterial)s&&console.warn("Lightmapping is not supported on MeshBasicMaterial",s.name);else{if(this._lightmaps.length<=0){const r=new Cg(this.gameObject,this.context);this._lightmaps.push(r)}this._lightmaps[0].init(this.lightmapIndex,this.lightmapScaleOffset,t)}}else if(this.isMultiMaterialObject(this.gameObject)&&this.sharedMaterials.length>0)for(let s=0;s<this.gameObject.children.length;s++){const r=this.gameObject.children[s];if(!((i=r.material)!=null&&i.isMeshBasicMaterial)){let n;s>=this._lightmaps.length?(n=new Cg(r,this.context),this._lightmaps.push(n)):n=this._lightmaps[s],n.init(this.lightmapIndex,this.lightmapScaleOffset,t)}}}else Kb&&console.warn("Lightmap not found",this.sourceId,this.lightmapIndex)}}clearInstancingState(){this._isInstancingEnabled=!1,this.handles=void 0,this.prevLayers=void 0}setInstancingEnabled(i){if(this._isInstancingEnabled===i)return i&&(this.handles===void 0||this.handles!=null&&this.handles.length>0);if(this._isInstancingEnabled=i,i){if(this.handles===void 0){if(this.handles=xte.setup(this,this.gameObject,this.context,null,{rend:this,foundMeshes:0,useMatrixWorldAutoUpdate:this.useInstanceMatrixWorldAutoUpdate()}),this.handles)return te.markAsInstancedRendered(this.gameObject,!0),!0}else if(this.handles!==null){for(const e of this.handles)e.updateInstanceMatrix(!0),e.add();return te.markAsInstancedRendered(this.gameObject,!0),!0}}else{if(this.handles)for(const e of this.handles)e.remove();return!0}return!1}useInstanceMatrixWorldAutoUpdate(){return!0}start(){if(this.enableInstancing&&!u3&&(this.setInstancingEnabled(!0),Nr.markDirty(this.gameObject)),this.gameObject.frustumCulled=this.allowOcclusionWhenDynamic,this.isMultiMaterialObject(this.gameObject))for(let i=0;i<this.gameObject.children.length;i++){const e=this.gameObject.children[i];e.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 i of this.gameObject.children)this.context.removeBeforeRenderListener(i,this.onBeforeRenderThree);else this.context.removeBeforeRenderListener(this.gameObject,this.onBeforeRenderThree)}applyStencil(){rM.applyStencil(this)}onBeforeRender(){var i,e;if(this.gameObject){if(this.isMultiMaterialObject(this.gameObject)&&((i=this.gameObject.children)==null?void 0:i.length)>0)for(const t of this.gameObject.children)this.applySettings(t);else this.applySettings(this.gameObject);if(this.sharedMaterials.changed&&(this.sharedMaterials.changed=!1,this.applyLightmapping()),(e=this.handles)!=null&&e.length&&this.gameObject[ig]===!0){sT&&console.log("UPDATE INSTANCED MATRICES",this.context.time.frame),this.gameObject[ig]=!1;for(let t=this.handles.length-1;t>=0;t--)this.handles[t].updateInstanceMatrix();this.gameObject.matrixWorldNeedsUpdate=!1}if(this.handles&&this.handles.length<=0&&te.markAsInstancedRendered(this.gameObject,!1),this._isInstancingEnabled&&this.handles)for(let t=0;t<this.handles.length;t++){const s=this.handles[t];this.prevLayers||(this.prevLayers=[]);const r=s.object.layers.mask;t>=this.prevLayers.length?this.prevLayers.push(r):this.prevLayers[t]=r,s.object.layers.disableAll()}for(const t of this.sharedMaterials)t&&this.loadProgressiveTextures(t);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 i=0;i<this.handles.length;i++){const e=this.handles[i];e.object.layers.mask=this.prevLayers[i]}this.reflectionProbeUsage!==0&&this._reflectionProbe&&this._reflectionProbe.onUnset(this)}loadProgressiveTextures(i){return!Ate&&i&&i._didRequestTextureLOD===void 0&&this.allowProgressiveLoading?(i._didRequestTextureLOD=0,vte&&console.log("Load material LOD",i.name),sa.assignTextureLOD(this.context,this.sourceId,i)):Promise.resolve(!0)}applySettings(i){i.receiveShadow=this.receiveShadows,this.shadowCastingMode==1?i.castShadow=!0:i.castShadow=!1}updateReflectionProbe(){if(this._reflectionProbe=null,this.reflectionProbeUsage!==0){if(!this.probeAnchor)return;this.startCoroutine(this._updateReflectionProbe(),Ws.LateUpdate)}}*_updateReflectionProbe(){const i=this.probeAnchor||this.gameObject,e=!!this.probeAnchor;this._reflectionProbe=Ip.get(i,this.context,e,this.probeAnchor)}setVisibility(i){if(!this.isMultiMaterialObject(this.gameObject))Yb(this.gameObject,i);else for(const e of this.gameObject.children)this.isMeshOrSkinnedMesh(e)&&Yb(e,i)}isMultiMaterialObject(i){return i.type==="Group"}isMeshOrSkinnedMesh(i){return i.type==="Mesh"||i.type==="SkinnedMesh"}};let ps=d3;Hl([x()],ps.prototype,"receiveShadows",2),Hl([x()],ps.prototype,"shadowCastingMode",2),Hl([x()],ps.prototype,"lightmapIndex",2),Hl([x(tt)],ps.prototype,"lightmapScaleOffset",2),Hl([x()],ps.prototype,"enableInstancing",2),Hl([x()],ps.prototype,"renderOrder",2),Hl([x()],ps.prototype,"allowOcclusionWhenDynamic",2),Hl([x(_e)],ps.prototype,"probeAnchor",2),Hl([x()],ps.prototype,"reflectionProbeUsage",2);class Jb extends ps{}class nT extends Jb{awake(){var e;super.awake(),this.allowOcclusionWhenDynamic=!1,(e=this.gameObject.parent)==null||e.updateWorldMatrix(!1,!0)}onBeforeRender(){if(super.onBeforeRender(),gte&&this.gameObject instanceof Vo&&this.gameObject.boundingSphere){const e=Bm(this.gameObject.boundingSphere.center).applyMatrix4(this.gameObject.matrixWorld);ka.DrawWireSphere(e,this.gameObject.boundingSphere.radius,"red")}}}class _te{constructor(){h(this,"objs",[])}setup(e,t,s,r,n,o=0){e.applySettings(t);const a=this.tryCreateOrAddInstance(t,s,n);if(a)e.loadProgressiveTextures(a.instancer.material),r===null&&(r=[]),r.push(a);else if(o<=0&&t.type!=="Mesh"){const l=o+1;for(const c of t.children)r=this.setup(e,c,s,r,n,l)}return o===0&&n.useMatrixWorldAutoUpdate&&r&&r.length>=0&&this.autoUpdateInstanceMatrix(t),r}tryCreateOrAddInstance(e,t,s){if(e.type==="Mesh"){const r=s.foundMeshes;if(s.foundMeshes+=1,!s.rend.enableInstancing||r>=s.rend.enableInstancing.length||!s.rend.enableInstancing[r])return null;const n=e,o=n.geometry,a=n.material;for(const c of this.objs)if(!c.isFull()&&c.geo===o&&c.material===a)return c.addInstance(n);const l=new f3(e.name,o,a,200,t);return this.objs.push(l),l.addInstance(n)}return null}autoUpdateInstanceMatrix(e){const t=e.matrixWorld.multiplyMatrices.bind(e.matrixWorld),s=e.matrixWorld.clone(),r=(n,o)=>{const a=t(n,o);return(e[ig]||s.equals(a)===!1)&&(s.copy(a),e[ig]=!0),a};e.matrixWorld.multiplyMatrices=r}}const xte=new _te;class wte{constructor(e,t,s){h(this,"instanceIndex",-1),h(this,"object"),h(this,"instancer"),this.instanceIndex=e,this.object=t,this.instancer=s,t[JO]=s,te.markAsInstancedRendered(t,!0)}get name(){return this.object.name}updateInstanceMatrix(e=!1){this.instanceIndex<0||(this.object.updateWorldMatrix(!0,e),this.instancer.updateInstance(this.object.matrixWorld,this.instanceIndex))}setMatrix(e){this.instanceIndex<0||this.instancer.updateInstance(e,this.instanceIndex)}add(){this.instanceIndex>=0||this.instancer.add(this)}remove(){this.instanceIndex<0||this.instancer.remove(this)}}const p3=class{constructor(i,e,t,s,r){h(this,"name",""),h(this,"geo"),h(this,"material"),h(this,"context"),h(this,"inst"),h(this,"handles",[]),h(this,"maxCount"),h(this,"_needUpdateBounds",!1),h(this,"onBeforeRender",()=>{this._needUpdateBounds&&this.inst[FC]===!0&&(sT&&console.log("Update instancing bounds",this.name,this.inst.matrixWorldNeedsUpdate),this.updateBounds())}),this.name=i,this.geo=e,this.material=t,this.context=r,this.maxCount=s,sT&&(t=new ai({color:this.randomColor()})),this.inst=new Sy(e,t,s),this.inst[FC]=!0,this.inst.count=0,this.inst.layers.set(2),this.inst.visible=!0,this.context.scene.add(this.inst),r.pre_render_callbacks.push(this.onBeforeRender)}get mesh(){return this.inst}get visible(){return this.inst.visible}set visible(i){this.inst.visible=i}get castShadow(){return this.inst.castShadow}set castShadow(i){this.inst.castShadow=i}set receiveShadow(i){this.inst.receiveShadow=i}updateBounds(i=!0,e=!0){this._needUpdateBounds=!1,i&&this.inst.computeBoundingBox(),e&&this.inst.computeBoundingSphere()}get currentCount(){return this.inst.count}isFull(){return this.currentCount>=this.maxCount}randomColor(){return new be(Math.random(),Math.random(),Math.random())}addInstance(i){if(this.currentCount>=this.maxCount)return console.error("TOO MANY INSTANCES - resize is not yet implemented!",this.inst.count),null;const e=new wte(-1,i,this);return i.castShadow===!0&&this.inst.castShadow===!1&&(this.inst.castShadow=!0),i.receiveShadow===!0&&this.inst.receiveShadow===!1&&(this.inst.receiveShadow=!0),this.add(e),e}add(i){i.instanceIndex<0&&(i.instanceIndex=this.currentCount,i.instanceIndex>=this.handles.length?this.handles.push(i):this.handles[i.instanceIndex]=i),i.object.updateWorldMatrix(!0,!0),this.inst.setMatrixAt(i.instanceIndex,i.object.matrixWorld),this.inst.instanceMatrix.needsUpdate=!0,this.inst.count+=1,this._needUpdateBounds=!0,this.inst.count>0&&(this.inst.visible=!0)}remove(i){if(!(!i||i.instanceIndex<0||i.instanceIndex>=this.handles.length||this.inst.count<=0)){if(this.handles[i.instanceIndex]!==i){console.error("instance handle is not part of renderer, was it removed before?",i.instanceIndex,this.name);const e=this.handles.indexOf(i);if(e<0)return;i.instanceIndex=e}if(this.handles[i.instanceIndex]=null,this.inst.setMatrixAt(i.instanceIndex,p3.nullMatrix),!(i.instanceIndex>=this.currentCount-1)&&this.currentCount>0){const e=this.handles[this.currentCount-1];e&&(e.instanceIndex=i.instanceIndex,e.updateInstanceMatrix(),this.handles[i.instanceIndex]=e,this.handles[this.currentCount-1]=null)}this.inst.count>0&&(this.inst.count-=1),i.instanceIndex=-1,this._needUpdateBounds=!0,this.inst.count<=0&&(this.inst.visible=!1),this.inst.instanceMatrix.needsUpdate=!0}}updateInstance(i,e){this.inst.setMatrixAt(e,i),this.inst.instanceMatrix.needsUpdate=!0,this._needUpdateBounds=!0}};let f3=p3;h(f3,"nullMatrix",new Te);function Zb(i){return i=i.replace(/[^a-zA-Z0-9_]/g,""),i.match(/^[a-zA-Z_]/)||(i="_"+i),i}function m3(i){if(i.length===0)return null;const e=i.map(t=>{const s=new Array;for(;t.parent;)s.unshift(t.parent),t=t.parent;return s});return e[0].findLast(t=>e.every(s=>s.includes(t)))||null}function g3(i){const e=m3(i),t=new Set;for(const s of i){let r=s.parent;for(;r&&r!==e;)i.includes(r)||t.add(r),r=r.parent}return t}const Rp=class{constructor(i,e,t,s=null,r=null,n=null,o=null,a=null){h(this,"uuid"),h(this,"name"),h(this,"matrix"),h(this,"_isDynamic"),h(this,"geometry"),h(this,"material"),h(this,"camera"),h(this,"parent"),h(this,"skinnedMesh"),h(this,"children",[]),h(this,"animations"),h(this,"_eventListeners"),this.uuid=i,this.name=Zb(e),this.matrix=t,this.geometry=s,this.material=r,this.camera=n,this.parent=null,this.children=[],this._eventListeners={},this._isDynamic=!1,this.skinnedMesh=o,this.animations=a}get isDynamic(){return this._isDynamic}set isDynamic(i){this._isDynamic=i}static createEmptyParent(i){const e=new Rp(ir.generateUUID(),i.name+"_empty_"+Rp.USDObject_export_id++,i.matrix);return i.parent.add(e),e.add(i),e.isDynamic=!0,i.matrix=new Te().identity(),e}static createEmpty(){const i=new Rp(ir.generateUUID(),"Empty_"+Rp.USDObject_export_id++,new Te);return i.isDynamic=!0,i}is(i){return i?this.uuid===i.uuid:!1}isEmpty(){return!this.geometry}clone(){const i=new Rp(ir.generateUUID(),this.name,this.matrix,this.geometry,this.material);return i.isDynamic=this.isDynamic,i}getPath(){let i=this.parent,e=this.name;for(;i;)e=(i.parent?i.name:i.name+"/Scenes/Scene")+"/"+e,i=i.parent;return"</"+e+">"}add(i){i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i)}remove(i){const e=this.children.indexOf(i);e>=0&&(i.parent===this&&(i.parent=null),this.children.splice(e,1))}addEventListener(i,e){this._eventListeners[i]||(this._eventListeners[i]=[]),this._eventListeners[i].push(e)}removeEventListener(i,e){if(!this._eventListeners[i])return;const t=this._eventListeners[i].indexOf(e);t>=0&&this._eventListeners[i].splice(t,1)}onSerialize(i,e){const t=this._eventListeners.serialize;t&&t.forEach(s=>s(i,e))}};let xo=Rp;h(xo,"USDObject_export_id",0);class v3 extends xo{constructor(){super(void 0,"StageRoot",new Te,null,null,null),h(this,"stageLength"),this.children=[],this.stageLength=200}get isDocumentRoot(){return!0}get isDynamic(){return!1}add(e){e.parent=this,this.children.push(e)}remove(e){const t=this.children.indexOf(e);t>=0&&(e.parent===this&&(e.parent=null),this.children.splice(t,1))}traverse(e,t=null){if(t!==null?e(t):t=this,t.children)for(const s of t.children)this.traverse(e,s)}findById(e){let t=!1;function s(r){if(!t){if(r.uuid===e)return t=!0,r;if(r.children)for(const n of r.children){const o=s(n);if(o)return o}}}return s(this)}buildHeader(e){return`#usda 1.0
4919
4921
  (
4920
4922
  customLayerData = {
4921
4923
  string creator = "Needle Engine USDZExporter"