@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 +5 -0
- package/dist/needle-engine.js +7 -4
- package/dist/needle-engine.light.js +7 -4
- package/dist/needle-engine.light.min.js +4 -2
- package/dist/needle-engine.light.umd.cjs +4 -2
- package/dist/needle-engine.min.js +4 -2
- package/dist/needle-engine.umd.cjs +4 -2
- package/lib/engine/engine_context.js +4 -0
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine-components/Component.d.ts +2 -0
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Renderer.js +8 -7
- package/lib/engine-components/Renderer.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_context.ts +4 -0
- package/src/engine-components/Component.ts +4 -0
- package/src/engine-components/Renderer.ts +9 -7
|
@@ -4286,7 +4286,9 @@ irradiance += 0.;
|
|
|
4286
4286
|
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
4287
4287
|
#endif`);ze.lightmap.lightmapScaleOffset={value:new $e(1,1,0,0)};const p7=re("debugplayerview");var Ka=(n=>(n.Browser="browser",n.Headset="headset",n.Handheld="handheld",n))(Ka||{});class u3{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 d3{constructor(e){h(this,"context");h(this,"playerViews",new Map);this.context=e}setPlayerView(e,t,i){let s=this.playerViews.get(e);s||(s=new u3(e,this.context),this.playerViews.set(e,s)),s.viewDevice=i,s.currentObject=t,s.removed=!1}getPlayerView(e){if(!e)return;if(!this.context.connection.userIsInRoom(e)){this.playerViews.delete(e);return}return this.playerViews.get(e)}removePlayerView(e,t){const i=this.playerViews.get(e);(i==null?void 0:i.viewDevice)===t&&(p7&&console.log("REMOVE",e),i.removed=!0,this.playerViews.delete(e))}}function*f3(n,e=null){const t=e?e.time:Lt.Current.time,i=t.time;for(;t.time-i<n;)yield}function*m7(n){for(let e=0;e<n;e++)yield}function*p3(n){let e=!0;for(n.then(()=>e=!1),n.catch(()=>e=!1);e;)yield}const Y0=new Map;function Cx(n,e){Y0.has(e)||Y0.set(e,new Array),Y0.get(e).push(n)}function eu(n,e){const t=Y0.get(e);if(t&&t.length>0){let i=t;e===ts.Start&&(i=[...t],t.length=0),g7(n,i)}}function g7(n,e){for(let t=e.length-1;t>=0;t--){const i=e[t];Bu(i,n)}}const Hl=re("debugcontext"),A7=re("stats"),v7=re("debugactive"),y7=re("debugframerate"),b7=re("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 ts=(n=>(n[n.Start=-1]="Start",n[n.EarlyUpdate=0]="EarlyUpdate",n[n.Update=1]="Update",n[n.LateUpdate=2]="LateUpdate",n[n.OnBeforeRender=3]="OnBeforeRender",n[n.OnAfterRender=4]="OnAfterRender",n[n.PrePhysicsStep=9]="PrePhysicsStep",n[n.PostPhysicsStep=10]="PostPhysicsStep",n[n.Undefined=-1]="Undefined",n))(ts||{}),tA=(n=>(n.ImmersiveVR="immersive-vr",n.ImmersiveAR="immersive-ar",n))(tA||{});function Ex(n,e){if(!n)return;if(!n.isComponent){(Ht()||Hl)&&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
|
-
`,n);return}const t=(e==null?void 0:e.new_scripts)??Lt.Current.new_scripts;t.includes(n)||t.push(n)}const Yi=class{constructor(e){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",A7?new kY:null);h(this,"_intersectionObserver",null);h(this,"_disposeCallbacks",[]);h(this,"onUnhandledRejection",e=>{this.domElement.dispatchEvent(new CustomEvent("error",{detail:e.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=(e==null?void 0:e.name)||"",this.alias=e==null?void 0:e.alias,this.domElement=(e==null?void 0:e.domElement)||document.body,this.hash=e==null?void 0:e.hash,e!=null&&e.renderer&&(this.renderer=e.renderer,this.isManagedExternally=!0),(e==null?void 0:e.runInBackground)!==void 0&&(this.runInBackground=e.runInBackground),e!=null&&e.scene?this.scene=e.scene:this.scene=new Mr,e!=null&&e.camera&&(this._camera=e.camera),this.application=new s3(this),this.time=new jF,this.input=new GF(this),this.physics=new WF(this),this.connection=new HU(this),this.assets=new uN,this.sceneLighting=new i3(this),this.addressables=new e3(this),this.lightmaps=new f7(this),this.players=new d3(this);const t=()=>this._sizeChanged=!0;window.addEventListener("resize",t),this._disposeCallbacks.push(()=>window.removeEventListener("resize",t));const i=new ResizeObserver(s=>this._sizeChanged=!0);i.observe(this.domElement),this._disposeCallbacks.push(()=>i.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()}),Ii.register(this)}static get DefaultTargetFrameRate(){return Yi._defaultTargetFramerate.value}static set DefaultTargetFrameRate(e){Yi._defaultTargetFramerate.value=e}static get DefaultWebGLRendererParameters(){return Yi._defaultWebglRendererParameters}get version(){return Va}static get Current(){return Ii.Current}static set Current(e){Ii.Current=e}appendHTMLElement(e){return this.domElement.shadowRoot?this.domElement.shadowRoot.appendChild(e):this.domElement.appendChild(e)}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(e){if(e!==this._resolutionScaleFactor&&typeof e=="number"){if(e<=0){console.error("Invalid resolution scale factor",e);return}this._resolutionScaleFactor=e,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 e,t;return((t=(e=this.renderer)==null?void 0:e.xr)==null?void 0:t.isPresenting)||!1}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){var e,t;return(t=(e=this.renderer)==null?void 0:e.xr)==null?void 0:t.getSession()}get xrFrame(){return this._xrFrame}get xrCamera(){var e,t;return(t=(e=this.renderer)==null?void 0:e.xr)==null?void 0:t.getCamera()}get arOverlayElement(){const e=this.domElement;return typeof e.getAROverlayContainer=="function"?e.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this._camera)return this._camera;if(this.mainCameraComponent){const e=this.mainCameraComponent;return e.cam||e.buildCamera(),e.cam}return null}set mainCamera(e){this._camera=e}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}createNewRenderer(){var t,i,s;(t=this.renderer)==null||t.dispose();const e=Yi.DefaultWebGLRendererParameters;if(!e.canvas){const r=(s=(i=this.domElement)==null?void 0:i.shadowRoot)==null?void 0:s.querySelector("canvas");r&&(e.canvas=r)}this.renderer=new bh(e),this.renderer.debug.checkShaderErrors=Ht()||re("checkshadererrors")===!0,this.renderer.toneMappingExposure=1,this.renderer.toneMapping=sr,this.renderer.setClearColor(new be("lightgrey"),0),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=v1,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputColorSpace=it,this.renderer.useLegacyLights=!1}internalOnUpdateVisible(){var e,t;(e=this._intersectionObserver)==null||e.disconnect(),(t=this._intersectionObserver)==null||t.observe(this.domElement)}updateSize(){var e,t,i;if(!this.isManagedExternally&&((e=this.renderer.xr)==null?void 0:e.isPresenting)===!1){this._sizeChanged=!1;const s=this.resolutionScaleFactor,r=this.domWidth*s,o=this.domHeight*s,a=this.mainCamera;this.updateAspect(a),this.renderer.setSize(r,o,!0),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((t=this.composer.setSize)==null||t.call(this.composer,r,o),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((i=this.composer.setPixelRatio)==null||i.call(this.composer,window.devicePixelRatio)))}}updateAspect(e,t,i){if(!e)return;t===void 0&&(t=this.domWidth),i===void 0&&(i=this.domHeight);const s=e.aspect;e.aspect=t/i,s!==e.aspect&&e.updateProjectionMatrix()}async onCreate(e){return this.create(e)}async create(e){try{return this._isCreating=!0,window.addEventListener("unhandledrejection",this.onUnhandledRejection),await this.internalOnCreate(e)}finally{window.removeEventListener("unhandledrejection",this.onUnhandledRejection),this._isCreating=!1}}clear(){var e,t,i,s;Ii.dispatchCallback(Kn.ContextClearing,this),ic(this.scene,!0,!0),this.scene=new Mr,(e=this.addressables)==null||e.dispose(),(t=this.lightmaps)==null||t.clear(),(s=(i=this.physics)==null?void 0:i.engine)==null||s.clearCaches(),this.isManagedExternally||this.renderer&&(this.renderer.renderLists.dispose(),this.renderer.state.reset(),this.renderer.resetState()),Ii.dispatchCallback(Kn.ContextCleared,this)}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var e,t;this.clear(),(e=this.renderer)==null||e.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 i of this._disposeCallbacks)try{i()}catch(s){console.error("Error in on dispose callback:",s,i)}(t=this.domElement)!=null&&t.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Ii.dispatchCallback(Kn.ContextDestroyed,this),Ii.unregister(this)}registerCoroutineUpdate(e,t,i){return this.coroutines[i]||(this.coroutines[i]=[]),this.coroutines[i].push({comp:e,main:t}),t}unregisterCoroutineUpdate(e,t){if(!this.coroutines[t])return;const i=this.coroutines[t].findIndex(s=>s.main===e);i>=0&&this.coroutines[t].splice(i,1)}stopAllCoroutinesFrom(e){for(const t in this.coroutines){const i=this.coroutines[t];for(let s=i.length-1;s>=0;s--)i[s].comp===e&&i.splice(s,1)}}setCurrentCamera(e){var s;if(!e)return;if(e.cam||e.buildCamera(),!e.cam){console.warn("Camera component is missing camera",e);return}const t=this._cameraStack.indexOf(e);t>=0&&this._cameraStack.splice(t,1),this._cameraStack.push(e),this.mainCameraComponent=e;const i=e.cam;i.isPerspectiveCamera&&this.updateAspect(i),(s=this.mainCameraComponent)==null||s.applyClearFlagsIfIsActiveCamera()}removeCamera(e){if(!e)return;const t=this._cameraStack.indexOf(e);if(t>=0&&this._cameraStack.splice(t,1),this.mainCameraComponent===e&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const i=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(i)}}addBeforeRenderListener(e,t){this._onBeforeRenderListeners.has(e.uuid)||(this._onBeforeRenderListeners.set(e.uuid,[]),e.onBeforeRender=this._createRenderCallbackWrapper(e,this._onBeforeRenderListeners)),this._onBeforeRenderListeners.get(e.uuid).push(t)}removeBeforeRenderListener(e,t){if(this._onBeforeRenderListeners.has(e.uuid)){const i=this._onBeforeRenderListeners.get(e.uuid),s=i.indexOf(t);s>=0&&i.splice(s,1)}}addAfterRenderListener(e,t){var i;this._onAfterRenderListeners.has(e.uuid)||(this._onAfterRenderListeners.set(e.uuid,[]),e.onAfterRender=this._createRenderCallbackWrapper(e,this._onAfterRenderListeners)),(i=this._onAfterRenderListeners.get(e.uuid))==null||i.push(t)}removeAfterRenderListener(e,t){if(this._onAfterRenderListeners.has(e.uuid)){const i=this._onAfterRenderListeners.get(e.uuid),s=i.indexOf(t);s>=0&&i.splice(s,1)}}_createRenderCallbackWrapper(e,t){return(i,s,r,o,a,c)=>{const l=t.get(e.uuid);if(l)for(let u=0;u<l.length;u++){const d=l[u];d(i,s,r,o,a,c)}}}get isRendering(){return this._isRendering}setRequireDepth(e){this._requireDepthTexture=e}setRequireColor(e){this._requireColorTexture=e}get depthTexture(){var e;return((e=this._renderTarget)==null?void 0:e.depthTexture)||null}get opaqueColorTexture(){var e;return((e=this._renderTarget)==null?void 0:e.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const e=getComputedStyle(this.domElement);return e.visibility!=="hidden"&&e.display!=="none"&&e.opacity!=="0"}async internalOnCreate(e){var o,a,c,l,u;const t=++this._createId;this.clear(),this.isManagedExternally===!1&&(this.createNewRenderer(),(o=this.renderer)==null||o.setAnimationLoop(null)),await dh(1),Yi.Current=this,await Ii.dispatchCallback(Kn.ContextCreationStart,this);let i=!0,s;try{Yi.Current=this,e?s=await this.internalLoadInitialContent(t,e):s=[]}catch(d){console.error(d),i=!1}if(!i||t!==this._createId)return!1;if(this.internalOnUpdateVisible(),!this.renderer)return Hl&&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),Yi.Current=this,Yi.Current=this;for(let d=0;d<this.new_scripts.length;d++){const f=this.new_scripts[d];if(f.gameObject!==void 0&&f.gameObject!==null){f.gameObject.userData===void 0&&(f.gameObject.userData={}),f.gameObject.userData.components===void 0&&(f.gameObject.userData.components=[]);const p=f.gameObject.userData.components;p.includes(f)||p.push(f)}}if(this.post_setup_callbacks)for(let d=0;d<this.post_setup_callbacks.length;d++)Yi.Current=this,await this.post_setup_callbacks[d](this);if(!this.mainCamera){Yi.Current=this;let d=null;Vu(this.scene,f=>{const p=f;if(p!=null&&p.isCamera){if(mg(p.gameObject),!p.activeAndEnabled)return;if(p.tag==="MainCamera")return d=p,!0;d=p}}),d?this.setCurrentCamera(d):!Ii.dispatchCallback(Kn.MissingCamera,this,{files:s})&&!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this)}if(Yi.Current=this,zb(this),this.physics.engine&&((a=this.physics.engine)==null||a.step(0),(c=this.physics.engine)==null||c.postStep()),!this.isManagedExternally&&this.composer&&this.mainCamera){const d=new xx(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(d),this.composer.setSize(this.domWidth,this.domHeight)}this._sizeChanged=!0,this._stats&&(this._stats.showPanel(0),(l=this.domElement.shadowRoot)==null||l.appendChild(this._stats.dom)),Hl&&Bb(this.scene,!0),this.targetFrameRate===void 0?(Hl&&console.warn("No target framerate set, using default",Yi.DefaultTargetFrameRate),this.targetFrameRate=Yi._defaultTargetFramerate):Hl&&console.log("Target framerate set to",this.targetFrameRate),this._dispatchReadyAfterFrame=!0;const r=Ii.dispatchCallback(Kn.ContextCreated,this,{files:s});return r&&("internalSetLoadingMessage"in this.domElement&&typeof this.domElement.internalSetLoadingMessage=="function"&&((u=this.domElement)==null||u.internalSetLoadingMessage("finish loading")),await r),eu(this,Kn.ContextCreated),this._isCreating=!1,this.isManagedExternally||this.restartRenderLoop(),r}async internalLoadInitialContent(e,t){var c,l;const i=new Array;if(t.files.length===0)return i;const s=[...t.files],r={name:"",progress:null,index:0,count:s.length},o=da();let a=0;this.hash&&(a=Number.parseInt(this.hash)??0);for(let u=0;u<s.length;u++){if(e!==this._createId){Hl&&console.log("Aborting loading because create id changed",e,this._createId);break}const d=s[u];if(!d.includes(".glb")&&!d.includes(".gltf")){const p=`Needle Engine: found suspicious src "${d}"`;console.warn(p),ar()&&ss(p)}(c=t==null?void 0:t.onLoadingStart)==null||c.call(this,u,d);const f=await o.loadSync(this,d,d,a,p=>{var m;r.name=d,r.progress=p,r.index=u,r.count=s.length,(m=t.onLoadingProgress)==null||m.call(this,r)});(l=t==null?void 0:t.onLoadingFinished)==null||l.call(this,u,d,f??null),f?i.push({src:d,file:f}):console.warn("Could not load file: "+d)}if(e!==this._createId){for(const u of i)if(u&&u.file)for(const d of u.file.scenes)ic(d,!0,!0)}else for(const u of i)u&&u.file&&this.scene.add(u.file.scene);return i}restartRenderLoop(){return this.renderer?this._isCreating?(console.warn("Can not start render loop while creating context"),!1):(this.renderer.setAnimationLoop((e,t)=>{this.isManagedExternally||this.update(e,t)}),!0):(console.error("Can not start render loop without renderer"),!1)}update(e,t){if(t===void 0&&(t=null),Ht()||Hl||Oq())try{this.internalStep(e,t),this._renderlooperrors=0}catch(i){this._renderlooperrors+=1,(Ht()||Hl)&&(i instanceof Error||i instanceof TypeError)&&gn("Caught unhandled exception during render-loop.<br/>Stopping renderloop...<br/>See console for details.",ko.Error),console.error(i),this._renderlooperrors>10&&(console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null)),this.domElement.dispatchEvent(new CustomEvent("error",{detail:i}))}else this.internalStep(e,t)}updatePhysics(e){this.internalUpdatePhysics(e)}internalStep(e,t){this.internalOnBeforeRender(e,t)!==!1&&(this.internalOnRender(),this.internalOnAfterRender())}internalOnBeforeRender(e,t){var i;if(this._xrFrame=t,this._currentFrameEvent=-1,this.isManagedExternally===!1&&this.isInXR===!1&&this.targetFrameRate!==void 0){this._lastTimestamp===0&&(this._lastTimestamp=e),this._accumulatedTime+=(e-this._lastTimestamp)/1e3,this._lastTimestamp=e;let s=this.targetFrameRate;if(typeof s=="object"&&(s=s.value),this._accumulatedTime<1/(s+1))return!1;this._accumulatedTime=0}if((i=this._stats)==null||i.begin(),Yi.Current=this,this.onHandlePaused())return!1;for(Yi.Current=this,this.time.update(),y7&&console.log("FPS",this.time.smoothedFps.toFixed(0)),zb(this),j0(this.scene),CN(this),eu(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&&(Yi.Current=this,r.earlyUpdate())}if(this.executeCoroutines(0),eu(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&&(Yi.Current=this,r.update())}if(this.executeCoroutines(1),eu(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&&(Yi.Current=this,r.lateUpdate())}if(this.executeCoroutines(2),eu(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&&(Yi.Current=this,r.onBeforeRender(t))}if(this.executeCoroutines(3),eu(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(e){if(!this.physics.engine)return!1;const t=e,i=this.time.deltaTime/t;for(let s=0;s<t;s++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(i),this._currentFrameEvent=10,this.executeCoroutines(10);return this.physics.engine.postStep(),!0}internalOnRender(){this.isManagedExternally||(Fq(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4)}internalOnAfterRender(){if(this.isVisibleToUser||this.runInBackground){for(let e=0;e<this.scripts_onAfterRender.length;e++){const t=this.scripts_onAfterRender[e];t.activeAndEnabled&&t.onAfterRender!==void 0&&(Yi.Current=this,t.onAfterRender())}if(this.executeCoroutines(4),eu(this,4),this.post_render_callbacks)for(const e in this.post_render_callbacks)this.post_render_callbacks[e]()}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")),Ii.dispatchCallback(Kn.ContextFirstFrameRendered,this))}renderNow(e){return!e&&(e=this.mainCamera,!e)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):e&&this.renderer.render(this.scene,e),this._isRendering=!1,!0)}onHandlePaused(){const e=this.evaluatePaused();if(this._wasPaused!==e){v7&&console.log("Paused?",e,"context:"+this.alias);for(let t=0;t<this.scripts_pausedChanged.length;t++){const i=this.scripts_pausedChanged[t];i.activeAndEnabled&&i.onPausedChanged!==void 0&&(Yi.Current=this,i.onPausedChanged(e,this._wasPaused))}}return this._wasPaused=e,e}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 Jt(this.domWidth,this.domHeight),this._requireDepthTexture){const i=new DA(this.domWidth,this.domHeight);this._renderTarget.depthTexture=i}this._requireColorTexture&&(this._renderTarget.texture=new Ft,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=Nt,this._renderTarget.texture.magFilter=Nt,this._renderTarget.texture.format=xi)}const e=this._renderTarget;e.texture&&(e.texture.colorSpace=this.renderer.outputColorSpace);const t=this.renderer.getRenderTarget();this.renderer.setRenderTarget(e),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(t)}executeCoroutines(e){var i;if(this.coroutines[e]){const s=this.coroutines[e];for(let r=0;r<s.length;r++)try{const o=s[r];if(!o.comp||o.comp.destroyed||!o.main||o.comp.enabled===!1){b7&&console.log("Removing coroutine",o.comp,o.comp.enabled),s.splice(r,1),--r;continue}const c=o.chained;if(c&&c.length>0){const f=c[c.length-1].next();if(f.done&&c.pop(),t(f)&&(o.chained||(o.chained=[]),o.chained.push(f.value)),!f.done)continue}const l=o.main.next();if(l.done===!0){s.splice(r,1),--r;continue}const u=l.value;if(t(u)){if(u.next().done)continue;o.chained||(o.chained=[]),o.chained.push(u)}else if(u instanceof Promise){const d=u;o.chained||(o.chained=[]);const f=p3(d);(i=o.chained)==null||i.push(f);continue}}catch(o){console.error(o)}}function t(s){return!!(s&&s.next&&s.return)}}};let Lt=Yi;h(Lt,"_defaultTargetFramerate",{value:60}),h(Lt,"_defaultWebglRendererParameters",{antialias:!0,alpha:!1});const bm=re("debugoverlay"),m3="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,i){var s;if(this.currentSession=i,this.arContainer=t,Mb()){const r=e.domElement.children;for(let o=0;o<(r==null?void 0:r.length);o++){const a=r[o];if(!a||a===this.arContainer)return;this._reparentedObjects.push({el:a,previousParent:a.parentElement}),(s=this.arContainer)==null||s.appendChild(a)}}this.ensureQuitARButton(this.arContainer)}onEnd(e){var t;for(const i of this._createdAROnlyElements)i.remove&&i.remove();for(const i of this._reparentedObjects){const s=i.el;(t=i.previousParent)==null||t.appendChild(s)}this._reparentedObjects.length=0,Mb()&&setTimeout(()=>{var o;const i=e.renderer.domElement;i&&((o=e.domElement.shadowRoot)==null||o.prepend(i));const s=document.querySelectorAll("*");for(var r=0;r<s.length;r++){const a=s[r];a&&a._displayChanged!==void 0&&a._displayWas!==void 0&&(a.style.display=a._displayWas)}},10)}createOverlayContainer(e){if(this.contentElement)return this.contentElement;bm&&console.log("Setup overlay container");const t=e.shadowRoot.querySelector(".content");this.contentElement=t;const i=e.shadowRoot.querySelector(".overlay-content");return i&&t.appendChild(i),bm&&!pl()&&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 i=document.querySelector(`.${w7}`);if(i){i.addEventListener("click",this.requestEndAR),bm&&i.addEventListener("click",()=>console.log("Clicked quit-ar button"));return}t.addEventListener("click",this.requestEndAR),bm&&t.addEventListener("click",()=>console.log("Clicked fallback close button"));const s=document.createElement("div");s.style.cssText=`
|
|
4289
|
+
`,n);return}const t=(e==null?void 0:e.new_scripts)??Lt.Current.new_scripts;t.includes(n)||t.push(n)}const Yi=class{constructor(e){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",A7?new kY:null);h(this,"_intersectionObserver",null);h(this,"_disposeCallbacks",[]);h(this,"onUnhandledRejection",e=>{this.domElement.dispatchEvent(new CustomEvent("error",{detail:e.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=(e==null?void 0:e.name)||"",this.alias=e==null?void 0:e.alias,this.domElement=(e==null?void 0:e.domElement)||document.body,this.hash=e==null?void 0:e.hash,e!=null&&e.renderer&&(this.renderer=e.renderer,this.isManagedExternally=!0),(e==null?void 0:e.runInBackground)!==void 0&&(this.runInBackground=e.runInBackground),e!=null&&e.scene?this.scene=e.scene:this.scene=new Mr,e!=null&&e.camera&&(this._camera=e.camera),this.application=new s3(this),this.time=new jF,this.input=new GF(this),this.physics=new WF(this),this.connection=new HU(this),this.assets=new uN,this.sceneLighting=new i3(this),this.addressables=new e3(this),this.lightmaps=new f7(this),this.players=new d3(this);const t=()=>this._sizeChanged=!0;window.addEventListener("resize",t),this._disposeCallbacks.push(()=>window.removeEventListener("resize",t));const i=new ResizeObserver(s=>this._sizeChanged=!0);i.observe(this.domElement),this._disposeCallbacks.push(()=>i.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()}),Ii.register(this)}static get DefaultTargetFrameRate(){return Yi._defaultTargetFramerate.value}static set DefaultTargetFrameRate(e){Yi._defaultTargetFramerate.value=e}static get DefaultWebGLRendererParameters(){return Yi._defaultWebglRendererParameters}get version(){return Va}static get Current(){return Ii.Current}static set Current(e){Ii.Current=e}appendHTMLElement(e){return this.domElement.shadowRoot?this.domElement.shadowRoot.appendChild(e):this.domElement.appendChild(e)}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(e){if(e!==this._resolutionScaleFactor&&typeof e=="number"){if(e<=0){console.error("Invalid resolution scale factor",e);return}this._resolutionScaleFactor=e,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 e,t;return((t=(e=this.renderer)==null?void 0:e.xr)==null?void 0:t.isPresenting)||!1}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){var e,t;return(t=(e=this.renderer)==null?void 0:e.xr)==null?void 0:t.getSession()}get xrFrame(){return this._xrFrame}get xrCamera(){var e,t;return(t=(e=this.renderer)==null?void 0:e.xr)==null?void 0:t.getCamera()}get arOverlayElement(){const e=this.domElement;return typeof e.getAROverlayContainer=="function"?e.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this._camera)return this._camera;if(this.mainCameraComponent){const e=this.mainCameraComponent;return e.cam||e.buildCamera(),e.cam}return null}set mainCamera(e){this._camera=e}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}createNewRenderer(){var t,i,s;(t=this.renderer)==null||t.dispose();const e=Yi.DefaultWebGLRendererParameters;if(!e.canvas){const r=(s=(i=this.domElement)==null?void 0:i.shadowRoot)==null?void 0:s.querySelector("canvas");r&&(e.canvas=r)}this.renderer=new bh(e),this.renderer.debug.checkShaderErrors=Ht()||re("checkshadererrors")===!0,this.renderer.toneMappingExposure=1,this.renderer.toneMapping=sr,this.renderer.setClearColor(new be("lightgrey"),0),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=v1,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputColorSpace=it,this.renderer.useLegacyLights=!1}internalOnUpdateVisible(){var e,t;(e=this._intersectionObserver)==null||e.disconnect(),(t=this._intersectionObserver)==null||t.observe(this.domElement)}updateSize(){var e,t,i;if(!this.isManagedExternally&&((e=this.renderer.xr)==null?void 0:e.isPresenting)===!1){this._sizeChanged=!1;const s=this.resolutionScaleFactor,r=this.domWidth*s,o=this.domHeight*s,a=this.mainCamera;this.updateAspect(a),this.renderer.setSize(r,o,!0),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((t=this.composer.setSize)==null||t.call(this.composer,r,o),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((i=this.composer.setPixelRatio)==null||i.call(this.composer,window.devicePixelRatio)))}}updateAspect(e,t,i){if(!e)return;t===void 0&&(t=this.domWidth),i===void 0&&(i=this.domHeight);const s=e.aspect;e.aspect=t/i,s!==e.aspect&&e.updateProjectionMatrix()}async onCreate(e){return this.create(e)}async create(e){try{return this._isCreating=!0,window.addEventListener("unhandledrejection",this.onUnhandledRejection),await this.internalOnCreate(e)}finally{window.removeEventListener("unhandledrejection",this.onUnhandledRejection),this._isCreating=!1}}clear(){var e,t,i,s;Ii.dispatchCallback(Kn.ContextClearing,this),ic(this.scene,!0,!0),this.scene=new Mr,(e=this.addressables)==null||e.dispose(),(t=this.lightmaps)==null||t.clear(),(s=(i=this.physics)==null?void 0:i.engine)==null||s.clearCaches(),this.isManagedExternally||this.renderer&&(this.renderer.renderLists.dispose(),this.renderer.state.reset(),this.renderer.resetState()),Ii.dispatchCallback(Kn.ContextCleared,this)}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var e,t;this.clear(),(e=this.renderer)==null||e.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 i of this._disposeCallbacks)try{i()}catch(s){console.error("Error in on dispose callback:",s,i)}(t=this.domElement)!=null&&t.parentElement&&this.domElement.parentElement.removeChild(this.domElement),Ii.dispatchCallback(Kn.ContextDestroyed,this),Ii.unregister(this)}registerCoroutineUpdate(e,t,i){return typeof(t==null?void 0:t.next)!="function"?(console.error("Registered invalid coroutine function from "+e.name+`
|
|
4290
|
+
Coroutine functions must be generators: "*myCoroutine() {...}"
|
|
4291
|
+
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)}unregisterCoroutineUpdate(e,t){if(!this.coroutines[t])return;const i=this.coroutines[t].findIndex(s=>s.main===e);i>=0&&this.coroutines[t].splice(i,1)}stopAllCoroutinesFrom(e){for(const t in this.coroutines){const i=this.coroutines[t];for(let s=i.length-1;s>=0;s--)i[s].comp===e&&i.splice(s,1)}}setCurrentCamera(e){var s;if(!e)return;if(e.cam||e.buildCamera(),!e.cam){console.warn("Camera component is missing camera",e);return}const t=this._cameraStack.indexOf(e);t>=0&&this._cameraStack.splice(t,1),this._cameraStack.push(e),this.mainCameraComponent=e;const i=e.cam;i.isPerspectiveCamera&&this.updateAspect(i),(s=this.mainCameraComponent)==null||s.applyClearFlagsIfIsActiveCamera()}removeCamera(e){if(!e)return;const t=this._cameraStack.indexOf(e);if(t>=0&&this._cameraStack.splice(t,1),this.mainCameraComponent===e&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const i=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(i)}}addBeforeRenderListener(e,t){this._onBeforeRenderListeners.has(e.uuid)||(this._onBeforeRenderListeners.set(e.uuid,[]),e.onBeforeRender=this._createRenderCallbackWrapper(e,this._onBeforeRenderListeners)),this._onBeforeRenderListeners.get(e.uuid).push(t)}removeBeforeRenderListener(e,t){if(this._onBeforeRenderListeners.has(e.uuid)){const i=this._onBeforeRenderListeners.get(e.uuid),s=i.indexOf(t);s>=0&&i.splice(s,1)}}addAfterRenderListener(e,t){var i;this._onAfterRenderListeners.has(e.uuid)||(this._onAfterRenderListeners.set(e.uuid,[]),e.onAfterRender=this._createRenderCallbackWrapper(e,this._onAfterRenderListeners)),(i=this._onAfterRenderListeners.get(e.uuid))==null||i.push(t)}removeAfterRenderListener(e,t){if(this._onAfterRenderListeners.has(e.uuid)){const i=this._onAfterRenderListeners.get(e.uuid),s=i.indexOf(t);s>=0&&i.splice(s,1)}}_createRenderCallbackWrapper(e,t){return(i,s,r,o,a,c)=>{const l=t.get(e.uuid);if(l)for(let u=0;u<l.length;u++){const d=l[u];d(i,s,r,o,a,c)}}}get isRendering(){return this._isRendering}setRequireDepth(e){this._requireDepthTexture=e}setRequireColor(e){this._requireColorTexture=e}get depthTexture(){var e;return((e=this._renderTarget)==null?void 0:e.depthTexture)||null}get opaqueColorTexture(){var e;return((e=this._renderTarget)==null?void 0:e.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const e=getComputedStyle(this.domElement);return e.visibility!=="hidden"&&e.display!=="none"&&e.opacity!=="0"}async internalOnCreate(e){var o,a,c,l,u;const t=++this._createId;this.clear(),this.isManagedExternally===!1&&(this.createNewRenderer(),(o=this.renderer)==null||o.setAnimationLoop(null)),await dh(1),Yi.Current=this,await Ii.dispatchCallback(Kn.ContextCreationStart,this);let i=!0,s;try{Yi.Current=this,e?s=await this.internalLoadInitialContent(t,e):s=[]}catch(d){console.error(d),i=!1}if(!i||t!==this._createId)return!1;if(this.internalOnUpdateVisible(),!this.renderer)return Hl&&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),Yi.Current=this,Yi.Current=this;for(let d=0;d<this.new_scripts.length;d++){const f=this.new_scripts[d];if(f.gameObject!==void 0&&f.gameObject!==null){f.gameObject.userData===void 0&&(f.gameObject.userData={}),f.gameObject.userData.components===void 0&&(f.gameObject.userData.components=[]);const p=f.gameObject.userData.components;p.includes(f)||p.push(f)}}if(this.post_setup_callbacks)for(let d=0;d<this.post_setup_callbacks.length;d++)Yi.Current=this,await this.post_setup_callbacks[d](this);if(!this.mainCamera){Yi.Current=this;let d=null;Vu(this.scene,f=>{const p=f;if(p!=null&&p.isCamera){if(mg(p.gameObject),!p.activeAndEnabled)return;if(p.tag==="MainCamera")return d=p,!0;d=p}}),d?this.setCurrentCamera(d):!Ii.dispatchCallback(Kn.MissingCamera,this,{files:s})&&!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this)}if(Yi.Current=this,zb(this),this.physics.engine&&((a=this.physics.engine)==null||a.step(0),(c=this.physics.engine)==null||c.postStep()),!this.isManagedExternally&&this.composer&&this.mainCamera){const d=new xx(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(d),this.composer.setSize(this.domWidth,this.domHeight)}this._sizeChanged=!0,this._stats&&(this._stats.showPanel(0),(l=this.domElement.shadowRoot)==null||l.appendChild(this._stats.dom)),Hl&&Bb(this.scene,!0),this.targetFrameRate===void 0?(Hl&&console.warn("No target framerate set, using default",Yi.DefaultTargetFrameRate),this.targetFrameRate=Yi._defaultTargetFramerate):Hl&&console.log("Target framerate set to",this.targetFrameRate),this._dispatchReadyAfterFrame=!0;const r=Ii.dispatchCallback(Kn.ContextCreated,this,{files:s});return r&&("internalSetLoadingMessage"in this.domElement&&typeof this.domElement.internalSetLoadingMessage=="function"&&((u=this.domElement)==null||u.internalSetLoadingMessage("finish loading")),await r),eu(this,Kn.ContextCreated),this._isCreating=!1,this.isManagedExternally||this.restartRenderLoop(),r}async internalLoadInitialContent(e,t){var c,l;const i=new Array;if(t.files.length===0)return i;const s=[...t.files],r={name:"",progress:null,index:0,count:s.length},o=da();let a=0;this.hash&&(a=Number.parseInt(this.hash)??0);for(let u=0;u<s.length;u++){if(e!==this._createId){Hl&&console.log("Aborting loading because create id changed",e,this._createId);break}const d=s[u];if(!d.includes(".glb")&&!d.includes(".gltf")){const p=`Needle Engine: found suspicious src "${d}"`;console.warn(p),ar()&&ss(p)}(c=t==null?void 0:t.onLoadingStart)==null||c.call(this,u,d);const f=await o.loadSync(this,d,d,a,p=>{var m;r.name=d,r.progress=p,r.index=u,r.count=s.length,(m=t.onLoadingProgress)==null||m.call(this,r)});(l=t==null?void 0:t.onLoadingFinished)==null||l.call(this,u,d,f??null),f?i.push({src:d,file:f}):console.warn("Could not load file: "+d)}if(e!==this._createId){for(const u of i)if(u&&u.file)for(const d of u.file.scenes)ic(d,!0,!0)}else for(const u of i)u&&u.file&&this.scene.add(u.file.scene);return i}restartRenderLoop(){return this.renderer?this._isCreating?(console.warn("Can not start render loop while creating context"),!1):(this.renderer.setAnimationLoop((e,t)=>{this.isManagedExternally||this.update(e,t)}),!0):(console.error("Can not start render loop without renderer"),!1)}update(e,t){if(t===void 0&&(t=null),Ht()||Hl||Oq())try{this.internalStep(e,t),this._renderlooperrors=0}catch(i){this._renderlooperrors+=1,(Ht()||Hl)&&(i instanceof Error||i instanceof TypeError)&&gn("Caught unhandled exception during render-loop.<br/>Stopping renderloop...<br/>See console for details.",ko.Error),console.error(i),this._renderlooperrors>10&&(console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null)),this.domElement.dispatchEvent(new CustomEvent("error",{detail:i}))}else this.internalStep(e,t)}updatePhysics(e){this.internalUpdatePhysics(e)}internalStep(e,t){this.internalOnBeforeRender(e,t)!==!1&&(this.internalOnRender(),this.internalOnAfterRender())}internalOnBeforeRender(e,t){var i;if(this._xrFrame=t,this._currentFrameEvent=-1,this.isManagedExternally===!1&&this.isInXR===!1&&this.targetFrameRate!==void 0){this._lastTimestamp===0&&(this._lastTimestamp=e),this._accumulatedTime+=(e-this._lastTimestamp)/1e3,this._lastTimestamp=e;let s=this.targetFrameRate;if(typeof s=="object"&&(s=s.value),this._accumulatedTime<1/(s+1))return!1;this._accumulatedTime=0}if((i=this._stats)==null||i.begin(),Yi.Current=this,this.onHandlePaused())return!1;for(Yi.Current=this,this.time.update(),y7&&console.log("FPS",this.time.smoothedFps.toFixed(0)),zb(this),j0(this.scene),CN(this),eu(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&&(Yi.Current=this,r.earlyUpdate())}if(this.executeCoroutines(0),eu(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&&(Yi.Current=this,r.update())}if(this.executeCoroutines(1),eu(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&&(Yi.Current=this,r.lateUpdate())}if(this.executeCoroutines(2),eu(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&&(Yi.Current=this,r.onBeforeRender(t))}if(this.executeCoroutines(3),eu(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(e){if(!this.physics.engine)return!1;const t=e,i=this.time.deltaTime/t;for(let s=0;s<t;s++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(i),this._currentFrameEvent=10,this.executeCoroutines(10);return this.physics.engine.postStep(),!0}internalOnRender(){this.isManagedExternally||(Fq(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4)}internalOnAfterRender(){if(this.isVisibleToUser||this.runInBackground){for(let e=0;e<this.scripts_onAfterRender.length;e++){const t=this.scripts_onAfterRender[e];t.activeAndEnabled&&t.onAfterRender!==void 0&&(Yi.Current=this,t.onAfterRender())}if(this.executeCoroutines(4),eu(this,4),this.post_render_callbacks)for(const e in this.post_render_callbacks)this.post_render_callbacks[e]()}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")),Ii.dispatchCallback(Kn.ContextFirstFrameRendered,this))}renderNow(e){return!e&&(e=this.mainCamera,!e)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):e&&this.renderer.render(this.scene,e),this._isRendering=!1,!0)}onHandlePaused(){const e=this.evaluatePaused();if(this._wasPaused!==e){v7&&console.log("Paused?",e,"context:"+this.alias);for(let t=0;t<this.scripts_pausedChanged.length;t++){const i=this.scripts_pausedChanged[t];i.activeAndEnabled&&i.onPausedChanged!==void 0&&(Yi.Current=this,i.onPausedChanged(e,this._wasPaused))}}return this._wasPaused=e,e}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 Jt(this.domWidth,this.domHeight),this._requireDepthTexture){const i=new DA(this.domWidth,this.domHeight);this._renderTarget.depthTexture=i}this._requireColorTexture&&(this._renderTarget.texture=new Ft,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=Nt,this._renderTarget.texture.magFilter=Nt,this._renderTarget.texture.format=xi)}const e=this._renderTarget;e.texture&&(e.texture.colorSpace=this.renderer.outputColorSpace);const t=this.renderer.getRenderTarget();this.renderer.setRenderTarget(e),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(t)}executeCoroutines(e){var i;if(this.coroutines[e]){const s=this.coroutines[e];for(let r=0;r<s.length;r++)try{const o=s[r];if(!o.comp||o.comp.destroyed||!o.main||o.comp.enabled===!1){b7&&console.log("Removing coroutine",o.comp,o.comp.enabled),s.splice(r,1),--r;continue}const c=o.chained;if(c&&c.length>0){const f=c[c.length-1].next();if(f.done&&c.pop(),t(f)&&(o.chained||(o.chained=[]),o.chained.push(f.value)),!f.done)continue}const l=o.main.next();if(l.done===!0){s.splice(r,1),--r;continue}const u=l.value;if(t(u)){if(u.next().done)continue;o.chained||(o.chained=[]),o.chained.push(u)}else if(u instanceof Promise){const d=u;o.chained||(o.chained=[]);const f=p3(d);(i=o.chained)==null||i.push(f);continue}}catch(o){console.error(o)}}function t(s){return!!(s&&s.next&&s.return)}}};let Lt=Yi;h(Lt,"_defaultTargetFramerate",{value:60}),h(Lt,"_defaultWebglRendererParameters",{antialias:!0,alpha:!1});const bm=re("debugoverlay"),m3="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,i){var s;if(this.currentSession=i,this.arContainer=t,Mb()){const r=e.domElement.children;for(let o=0;o<(r==null?void 0:r.length);o++){const a=r[o];if(!a||a===this.arContainer)return;this._reparentedObjects.push({el:a,previousParent:a.parentElement}),(s=this.arContainer)==null||s.appendChild(a)}}this.ensureQuitARButton(this.arContainer)}onEnd(e){var t;for(const i of this._createdAROnlyElements)i.remove&&i.remove();for(const i of this._reparentedObjects){const s=i.el;(t=i.previousParent)==null||t.appendChild(s)}this._reparentedObjects.length=0,Mb()&&setTimeout(()=>{var o;const i=e.renderer.domElement;i&&((o=e.domElement.shadowRoot)==null||o.prepend(i));const s=document.querySelectorAll("*");for(var r=0;r<s.length;r++){const a=s[r];a&&a._displayChanged!==void 0&&a._displayWas!==void 0&&(a.style.display=a._displayWas)}},10)}createOverlayContainer(e){if(this.contentElement)return this.contentElement;bm&&console.log("Setup overlay container");const t=e.shadowRoot.querySelector(".content");this.contentElement=t;const i=e.shadowRoot.querySelector(".overlay-content");return i&&t.appendChild(i),bm&&!pl()&&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 i=document.querySelector(`.${w7}`);if(i){i.addEventListener("click",this.requestEndAR),bm&&i.addEventListener("click",()=>console.log("Clicked quit-ar button"));return}t.addEventListener("click",this.requestEndAR),bm&&t.addEventListener("click",()=>console.log("Clicked fallback close button"));const s=document.createElement("div");s.style.cssText=`
|
|
4290
4292
|
position: fixed;
|
|
4291
4293
|
top: 0;
|
|
4292
4294
|
right: 0;
|
|
@@ -4915,7 +4917,7 @@ void main() {
|
|
|
4915
4917
|
`&&n.length>1&&qz([t],n[n.length-2]),e.offsetX}function _ee(n){if(!n[0])return 0;let e=[],t;for(let i=0;i<n.length;i++){const s=n[i];if(s.char&&GO[s.char]&&n.length>i){e.push(s),t=n[i+1];continue}break}Xz(e,t),e=[],t=null;for(let i=n.length-1;i>0;i--){const s=n[i];if(s.char&&GO[s.char]&&i>0){e.push(s),t=n[i-1];continue}break}return qz(e,t),n[0].offsetX}function xee(n){return n[0]?n[0].offsetX:0}function qz(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX+e.cumulativeWidth,i.cumulativeWidth=0}}function Xz(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX,i.cumulativeWidth=0}}function Yz(n,e,t,i){if(i=i||0,!n[e])return i;const s=n[e];return s.lineBreak?i+s.xadvance:Yz(n,e+1,t,i+s.xadvance+s.xoffset+s.kerning+t.LETTERSPACING)}function wee(n,e,t,i){return!n||!n.char||e+t<i.INNER_WIDTH?!1:i.BREAKON.indexOf(n.char)>-1}class Jz extends tz{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 Kz extends ji{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,i=e._inlines._value;for(let s=0;s<i.length;s++){const r=i[s];r.resetOffsets(),r.fontSize=this._value,r.fontFactor=t}}get value(){return this._value}}class Zz extends iz{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 Zz{constructor(){super(),this._value="inherit"}}class Cee extends Px{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,i=e._inlines._value;for(let s=1;s<i.length;s++){const r=t[s-1]+t[s];i[s].kerning=e._font._fontVariant.getKerningAmount(r)}}}}class $z extends Ai{constructor(){super("children",null,!1),this._uis=[]}update(e,t){}process(e){}_compute(e){}dispose(){}}function Eee(n,e=!1){const t=n[0].index!==null,i=new Set(Object.keys(n[0].attributes)),s=new Set(Object.keys(n[0].morphAttributes)),r={},o={},a=n[0].morphTargetsRelative,c=new He.BufferGeometry;let l=0;for(let u=0;u<n.length;++u){const d=n[u];let f=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 p in d.attributes){if(!i.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;r[p]===void 0&&(r[p]=[]),r[p].push(d.attributes[p]),f++}if(f!==i.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 p in d.morphAttributes){if(!s.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+u+". .morphAttributes must be consistent throughout all geometries."),null;o[p]===void 0&&(o[p]=[]),o[p].push(d.morphAttributes[p])}if(c.userData.mergedUserData=c.userData.mergedUserData||[],c.userData.mergedUserData.push(d.userData),e){let p;if(t)p=d.index.count;else if(d.attributes.position!==void 0)p=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;c.addGroup(l,p,u),l+=p}}if(t){let u=0;const d=[];for(let f=0;f<n.length;++f){const p=n[f].index;for(let m=0;m<p.count;++m)d.push(p.getX(m)+u);u+=n[f].attributes.position.count}c.setIndex(d)}for(const u in r){const d=HO(r[u]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+u+" attribute."),null;c.setAttribute(u,d)}for(const u in o){const d=o[u][0].length;if(d===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[u]=[];for(let f=0;f<d;++f){const p=[];for(let A=0;A<o[u].length;++A)p.push(o[u][A][f]);const m=HO(p);if(!m)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+u+" morphAttribute."),null;c.morphAttributes[u].push(m)}}return c}function HO(n){let e,t,i,s=0;for(let a=0;a<n.length;++a){const c=n[a];if(c.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(e===void 0&&(e=c.array.constructor),e!==c.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=c.itemSize),t!==c.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(i===void 0&&(i=c.normalized),i!==c.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;s+=c.array.length}const r=new e(s);let o=0;for(let a=0;a<n.length;++a)r.set(n[a].array,o),o+=n[a].array.length;return new He.BufferAttribute(r,t,i)}class Mee extends Ai{constructor(){super("renderer")}render(e){if(!e._inlines._value||!e._inlines._value.length)return;const t=e._inlines._value.map(s=>e._font._fontVariant.getGeometricGlyph(s,e).translate(s.offsetX,s.offsetY,0)),i=Eee(t);e.setFontMesh(new He.Mesh(i,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class Tee extends fI{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class fp extends rv{constructor(t={}){const i={};fp.definePropertiesValues(i,t);super(i,t);h(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0});fp.init(this)}add(t){const i=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(i.push(r),r.position.z=.005):console.warn("Block element can only contain Box elements.",r)}return super.add(...i)}set textContent(t){this._textContent.value=t}get textContent(){return this._textContent._value}set invertAlpha(t){this._invertAlpha.value=t}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(t,i){t.children||(t.children=$z),t.textContent||(t.textContent=lee),t.glyphs||(t.glyphs=uee),t.inlines||(t.inlines=hee),t.layouter||(t.layouter=Hz),t.renderer||(t.renderer=Mee),t.fontFamily||(t.fontFamily=Wz),t.fontWeight||(t.fontWeight=Qz),t.fontStyle||(t.fontStyle=Vz),t.fontSize||(t.fontSize=Kz),t.color||(t.color=dee),t.backgroundColor||(t.backgroundColor=fee),t.lineBreak||(t.lineBreak=Gz),t.letterSpacing||(t.letterSpacing=Jz),t.whiteSpace||(t.whiteSpace=UI),t.segments||(t.segments=See),t.textAlign||(t.textAlign=Tee),t.fontKerning||(t.fontKerning=Cee)}static init(t){Object.defineProperties(t,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class Iee extends V3{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 i=e.children.length-1;i>=0;i--){const s=e.children[i];s.isUI&&(e.remove(s),s.clear())}e._children._uis=[],this._value&&e.add(new fp({name:"anonymousInline",textContent:this._value}))}}class Ree extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class Pee extends Ai{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 i=e._lineHeight._value,s=new Ree(new zO);let r=0;e._children._inlines.forEach(d=>{if(!d._inlines.value)return;this._resetInlines(d);const f=d._fontSize._value,p=d._letterSpacing._value*f,m=d._whiteSpace._value,A=d._lineBreak._value,v={WHITESPACE:m,LETTERSPACING:p,BREAKON:A,INNER_WIDTH:t},g=d._whiteSpace._inlineWrapper;r+=d._margin._value.w+d._padding._value.w,d._inlines.value.forEach((b,y,_)=>{const E=s[s.length-1];if(g(_,y,r,v)){if(s.push(new zO(b)),b.offsetX=b.xoffset,b.width===0){r=0;return}b.cumulativeWidth=b.xadvance+p,r=b.cumulativeWidth;return}s[s.length-1].push(b),b.offsetX=r+b.xoffset+b.kerning,b.cumulativeWidth=b.xadvance+b.kerning+p,r+=b.cumulativeWidth,E.length-1===1&&E[E.length-2].width===0&&(b.offsetX-=b.xoffset,r-=b.xoffset)}),r+=d._margin._value.y+d._padding._value.y});const o=e._whiteSpace._inlineCollapser;let a=0,c=0,l=0;s.forEach((d,f)=>{const p=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-=p}),d.lineHeight=m,d.lineBase=A,f===0?l=-(m*i-m)*.5:l-=s[f-1].lineHeight*i,d.y=l,d.x=0,d.forEach(v=>{v.offsetY=l-v.anchor,v.lineHeight<d.lineHeight&&(v.offsetY-=d.lineBase-v.lineBase)}),c+=d.lineHeight*i,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)}}),s.height=c,s.width=a,this._value=s,t===1/0&&e._bounds.setChildrenWidth(e,s.width),e._height._auto&&e._bounds.setChildrenHeight(e,s.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 fI{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(n){const e=n._layouter._value,t=n._textAlign._value,i=n._bounds._innerWidth;for(let s=0;s<e.length;s++){const r=e[s],o=Oee(n,r,s===e.length-1),a=n._padding._value,c=n._borderWidth._value,l=(-a.w+a.y)/2+(-c.w+c.y)/2;r.x+=o;for(let u=0;u<r.length;u++)r[u].offsetX+=o-l}if(t.indexOf("justify")===0)for(let s=0;s<e.length;s++){const r=e[s];if(t.indexOf("-")!==-1&&s===e.length-1)return;const o=i-r.width;if(o<=0)return;let a=0;for(let d=1;d<r.length-1;d++)a+=r[d].char===" "?1:0;const c=o/a;let l=1;t==="justify-right"&&(r.reverse(),l=-1);let u=0;for(let d=1;d<=r.length-1;d++){const f=r[d];f.offsetX+=u*l,u+=f.char===" "?c:0}t==="justify-right"&&r.reverse()}}function Oee(n,e,t){switch(n._textAlign._value){case"justify-left":case"justify":case"left":return-n._bounds._innerWidth/2;case"justify-right":case"right":return-e.width+n._bounds._innerWidth/2;case"center":return-e.width/2;case"justify-center":return t?-e.width/2:-n._bounds._innerWidth/2;default:console.warn(`textAlign: '${n._textAlign._value}' is not valid`)}}class kee extends pI{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput}}class Lee extends $3{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class Fee extends Px{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e)}}class Uee extends Uz{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class Nee extends Ai{constructor(){super("children",null,!1);h(this,"_sortOrder",(t,i)=>t._order._value<i._order._value?-1:t._order._value>i._order._value?1:this._uis.indexOf(t)<this._uis.indexOf(i)?-1:1);this._uis=[],this._inlines=[],this._boxes=[]}update(t,i){this._compute(t),this._needsProcess=!0}process(t){this._compute(t),t._overflow._needsRender=!0}_compute(t){this._uis=t.children.filter(i=>i.visible&&i.isUI),this._inlines=this._uis.filter(i=>i.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class zee extends Ai{constructor(){super("autosize")}process(e){if(e._layouter._value&&e._layouter._value.length){const t=e._layouter._value,i=e._padding._value,s=e._borderWidth._value;e._width._auto&&e._bounds.setOffsetWidth(e,t.width+i.w+i.y+s.w+s.y),e._height._auto&&e._bounds.setOffsetHeight(e,t.height+i.x+i.z+s.x+s.z)}}}class Gee extends zz{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 cA extends oA{constructor(e={},t={}){cA.definePropertiesValues(t,e),super(t,e),cA.init(this)}add(e){const t=[];let i=!1;for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(r.isInline&&(i=!0),t.push(r)):console.warn("Block element can only contain Box elements.",r)}return t.length>0&&super.add(...t),i&&(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=kee,e.justifyContent=mI,e.alignItems=dI,e.bounds=Uee,e.autoSize=zee,e.renderer=Gee,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=UI),e.fontKerning||(e.fontKerning=Fee),e.segments||(e.segments=Zz),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class Hee extends Ai{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 Vee extends Ai{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new Nz(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 Qee extends Ai{constructor(){super("bounds",null,!1),this._size=new He.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 lA extends rv{constructor(e={}){const t={};lA.definePropertiesValues(t,e),super(t,e),lA.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 He.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let i=0;i<arguments.length;i++){const s=arguments[i];s.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",s):(t.push(s),s.position.z=.005)}return super.add(...t)}static definePropertiesValues(e,t){e.children||(e.children=$z),e.bounds||(e.bounds=Qee),e.inlines||(e.inlines=Hee),e.layouter||(e.layouter=Hz),e.renderer||(e.renderer=Vee),e.fontFamily||(e.fontFamily=Wz),e.fontWeight||(e.fontWeight=Qz),e.fontStyle||(e.fontStyle=Vz),e.fontSize||(e.fontSize=Kz),e.backgroundColor||(e.backgroundColor=z3),e.lineBreak||(e.lineBreak=Gz),e.letterSpacing||(e.letterSpacing=Jz),e.whiteSpace||(e.whiteSpace=UI),e.fontKerning||(e.fontKerning=Px),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 Wee(e)],e.backgroundMaterial=new Fz,e._renderer.render(e)}}class Wee extends X3{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 eG{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 tG=()=>$b.update(),iG={BaseProperty:Ai,Block:aA,Text:cA,Inline:fp,InlineBlock:lA,MeshUIBaseElement:rv,FontLibrary:Qu,update:tG,MSDFFontMaterialUtils:Mo,ShaderChunkUI:Lz,Behavior:eG,FontVariant:tv};typeof global<"u"&&(global.ThreeMeshUI=iG);const jee=iG;var qee=Dn.w8,nG=Dn.cg,NI=Dn.gO,Xee=Dn.wb,kM=Dn.zV,Yee=Dn.HS,Jee=Dn.Ec,eb=Dn.gF,Kee=Dn.ol,Zee=Dn.pz,$ee=Dn.tx,ete=Dn.hj,tte=Dn.FV,ite=Dn.sV,zI=Dn.xv,nte=Dn.mx,ste=Dn.gE,lf=Dn.ZP,sG=Dn.Vx;const pC=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:qee,Behavior:nG,Block:NI,DefaultValues:Xee,FontLibrary:kM,FontVariant:Yee,InheritableProperty:Jee,Inline:eb,InlineBlock:Kee,InlineGlyph:Zee,MSDFFontMaterialUtils:$ee,MaterialTransformers:ete,MeshUIBaseElement:tte,ShaderChunkUI:ite,Text:zI,TypographicFont:nte,TypographicGlyph:ste,default:lf,update:sG},Symbol.toStringTag,{value:"Module"})),Ys=new w,VO=new w,QO=new Ce,rte=re("debuggizmos"),wc=8947848;class Qa{static DrawLabel(e,t,i=.1,s=9999,r,o,a){r||(r=wc);const c=In.getTextLabel(s,t,i,r,o);return a instanceof _e&&a.add(c),c.position.x=e.x,c.position.y=e.y,c.position.z=e.z,c}static DrawRay(e,t,i=wc,s=0,r=!0){const o=In.getLine(s),a=o.geometry.getAttribute("position");a.setXYZ(0,e.x,e.y,e.z),Ys.set(t.x,t.y,t.z).multiplyScalar(999999999),a.setXYZ(1,e.x+Ys.x,e.y+Ys.y,e.z+Ys.z),a.needsUpdate=!0,o.material.color.set(i),o.material.depthTest=r,o.material.depthWrite=!1}static DrawDirection(e,t,i=wc,s=0,r=!0,o=1){const a=In.getLine(s),c=a.geometry.getAttribute("position");c.setXYZ(0,e.x,e.y,e.z),t.w!==void 0?(Ys.set(0,0,-o),QO.set(t.x,t.y,t.z,t.w),Ys.applyQuaternion(QO)):(Ys.set(t.x,t.y,t.z),Ys.multiplyScalar(o)),c.setXYZ(1,e.x+Ys.x,e.y+Ys.y,e.z+Ys.z),c.needsUpdate=!0,a.material.color.set(i),a.material.depthTest=r,a.material.depthWrite=!1}static DrawLine(e,t,i=wc,s=0,r=!0){const o=In.getLine(s),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(i),o.material.depthTest=r,o.material.depthWrite=!1}static DrawWireSphere(e,t,i=wc,s=0,r=!0){const o=In.getSphere(t,s,!0);Hu(o,e.x,e.y,e.z),o.material.color.set(i),o.material.depthTest=r,o.material.depthWrite=!1}static DrawSphere(e,t,i=wc,s=0,r=!0){const o=In.getSphere(t,s,!1);Hu(o,e.x,e.y,e.z),o.material.color.set(i),o.material.depthTest=r,o.material.depthWrite=!1}static DrawWireBox(e,t,i=wc,s=0,r=!0){const o=In.getBox(s);o.position.set(e.x,e.y,e.z),o.scale.set(t.x,t.y,t.z),o.material.color.set(i),o.material.depthTest=r,o.material.wireframe=!0,o.material.depthWrite=!1}static DrawWireBox3(e,t=wc,i=0,s=!0){const r=In.getBox(i);r.position.copy(e.getCenter(Ys)),r.scale.copy(e.getSize(Ys)),r.material.color.set(t),r.material.depthTest=s,r.material.wireframe=!0,r.material.depthWrite=!1}static DrawArrow(e,t,i=wc,s=0,r=!0,o=!1){const a=In.getArrowHead(s);a.position.set(t.x,t.y,t.z),a.quaternion.setFromUnitVectors(this._up.set(0,1,0),Ys.set(t.x,t.y,t.z).sub(VO.set(e.x,e.y,e.z)).normalize());const l=Ys.set(t.x,t.y,t.z).sub(VO.set(e.x,e.y,e.z)).length()*.1;a.scale.set(l,l,l),a.material.color.set(i),a.material.depthTest=r,a.material.wireframe=o,this.DrawLine(e,t,i,s,r)}}h(Qa,"_up",new w(0,1,0));const ote=new Ti(1,1,1);function rG(n=null){const e=new be(n??14540253),t=new tT(ote);return new no(t,new _n({color:e}))}const WO=Symbol("GizmoCache");class In{static ensureFont(){let e=lf.FontLibrary.getFontFamily(this.familyName);if(!e){e=lf.FontLibrary.addFontFamily(this.familyName);const t=e.addVariant("normal","normal","./include/needle/arial-msdf.json","./include/needle/arial.png");t==null||t.addEventListener("ready",()=>{lf.update()})}}static getTextLabel(e,t,i,s,r){this.ensureFont();let o=this.textLabelCache.pop(),a=1;r&&typeof r=="string"&&(r==null?void 0:r.length)>=8&&r.startsWith("#")?(a=parseInt(r.substring(7),16)/255,r=r.substring(0,7),rte&&console.log(r,a)):typeof r=="object"&&r.a!==void 0&&(a=r.a);const c={boxSizing:"border-box",fontFamily:this.familyName,width:"auto",fontSize:i,color:s,lineHeight:.75,backgroundColor:r??void 0,backgroundOpacity:a,textContent:t,borderRadius:1*i,padding:1*i};if(o)o.set(c);else{o=new zI(c);const l=this,u=o;u.setText=function(d){this.set({textContent:d,whiteSpace:"pre"}),l.tmuiNeedsUpdate=!0}}return this.tmuiNeedsUpdate=!0,o.layers.disableAll(),o.layers.enable(2),this.registerTimedObject(Lt.Current,o,e,this.textLabelCache),o}static getBox(e){let t=this.boxesCache.pop();if(!t){const i=new Ti(1,1,1);t=new ge(i)}return this.registerTimedObject(Lt.Current,t,e,this.boxesCache),t}static getLine(e){let t=this.linesCache.pop();if(!t){t=new fn;let i=t.geometry.getAttribute("position");i||(i=new Ke(new Float32Array(2*3),3),t.geometry.setAttribute("position",i))}return this.registerTimedObject(Lt.Current,t,e,this.linesCache),t}static getSphere(e,t,i){let s=this.spheresCache.pop();return s||(s=new ge(new zo(1,8,8))),s.scale.set(e,e,e),s.material.wireframe=i,this.registerTimedObject(Lt.Current,s,t,this.spheresCache),s}static getArrowHead(e){let t=this.arrowHeadsCache.pop();return t||(t=new ge(new hn(0,.5,1,8))),this.registerTimedObject(Lt.Current,t,e,this.arrowHeadsCache),t}static registerTimedObject(e,t,i,s){if(!this.contextPostRenderCallbacks.get(e)){const r=()=>{this.onPostRender(e,this.timedObjectsBuffer,this.timesBuffer)};this.contextPostRenderCallbacks.set(e,r),e.post_render_callbacks.push(r)}if(!this.contextBeforeRenderCallbacks.get(e)){const r=()=>{this.onBeforeRender(e,this.timedObjectsBuffer)};this.contextBeforeRenderCallbacks.set(e,r),e.pre_render_callbacks.push(r)}t.layers.disableAll(),t.layers.enable(2),t[WO]=s,this.timedObjectsBuffer.push(t),this.timesBuffer.push(Lt.Current.time.time+i),e.scene.add(t)}static onBeforeRender(e,t){this.tmuiNeedsUpdate&&lf.update();for(let i=0;i<t.length;i++){const s=t[i];if(e.mainCamera&&s instanceof lf.MeshUIBaseElement){const r=e.isInVR,o=r,a=!r;xT(s,e.mainCamera,o,a)}}}static onPostRender(e,t,i){const s=e.time.time;for(let r=0;r<t.length;r++){const o=t[r];s>i[r]&&(o[WO].push(o),o.removeFromParent(),t.splice(r,1),i.splice(r,1))}}}h(In,"familyName","needle-gizmos"),h(In,"linesCache",[]),h(In,"spheresCache",[]),h(In,"boxesCache",[]),h(In,"arrowHeadsCache",[]),h(In,"textLabelCache",[]),h(In,"timedObjectsBuffer",new Array),h(In,"timesBuffer",new Array),h(In,"contextPostRenderCallbacks",new Map),h(In,"contextBeforeRenderCallbacks",new Map),h(In,"tmuiNeedsUpdate",!1);const ate=re("gizmos"),cte=re("debugboxhelper"),wo=class extends Ie{constructor(){super(...arguments);h(this,"box",null);h(this,"_lastMatrixUpdateFrame",-1);h(this,"_helper",null);h(this,"_color",null)}isInBox(t,i){var r;if(!t)return;if(this.box||(this.box=new Pn),t.type==="Mesh")wo.testBox.setFromObject(t);else if(t.type==="Group"){if(wo.testBox.makeEmpty(),t.children.length>0)for(let o=0;o<t.children.length;o++)t.children[o].type==="Mesh"&&wo.testBox.expandByObject(t)}else{const o=pt(t,wo._position),a=$n(t,wo._size);i!==void 0&&a.multiplyScalar(i),wo.testBox.setFromCenterAndSize(o,a)}this.updateBox();const s=(r=this.box)==null?void 0:r.intersectsBox(wo.testBox);return s&&cte&&Qa.DrawWireBox3(wo.testBox,16711680,5),s}intersects(t){return t?this.updateBox(!1).intersectsBox(t):!1}updateBox(t=!1){if(this.box||(this.box=new Pn),t||this.context.time.frameCount!=this._lastMatrixUpdateFrame){const i=this._lastMatrixUpdateFrame<0;this._lastMatrixUpdateFrame=this.context.time.frameCount;const s=i,r=pt(this.gameObject,wo._position,s),o=$n(this.gameObject,wo._size);this.box.setFromCenterAndSize(r,o)}return this.box}awake(){this._helper=null,this._color=null,this.box=null}showHelper(t=null,i=!1){var s;if(!(!ate&&!i)){if(this._helper){t&&((s=this._color)==null||s.set(t)),this.gameObject.add(this._helper);return}this._helper=rG(t),this.gameObject.add(this._helper)}}};let Io=wo;h(Io,"testBox",new Pn),h(Io,"_position",new w),h(Io,"_size",new w(.01,.01,.01));var lte=Object.defineProperty,hte=Object.getOwnPropertyDescriptor,oG=(n,e,t,i)=>{for(var s=i>1?void 0:i?hte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&<e(e,t,s),s};const Cm=re("debugreflectionprobe"),jO=re("noreflectionprobe"),ute=Symbol("reflectionProbeKey"),dte=Symbol("original material");var C0;const Ec=(C0=class extends Ie{constructor(){var e;super();h(this,"_texture");h(this,"center");h(this,"size");h(this,"_boxHelper");Ec._probes.has(this.context)||Ec._probes.set(this.context,[]),(e=Ec._probes.get(this.context))==null||e.push(this)}static get(e,t,i,s){if(!e||e.isObject3D!==!0||jO)return null;const r=Ec._probes.get(t);if(r){for(const o of r)if(o.__didAwake||o.__internalAwake(),o.enabled){if(s){if(o.gameObject===s)return o}else if(o.isInBox(e,void 0))return Cm&&console.log("Found reflection probe",e.name,o.name),o}}return Cm&&console.debug("Did not find reflection probe",e.name,i,e),null}set texture(e){if(e&&!(e instanceof Ft)){console.error("ReflectionProbe.texture must be a Texture",e);return}this._texture=e,e&&(e.mapping=Do,e.colorSpace=it,e.needsUpdate=!0)}get texture(){return this._texture}isInBox(e,t){var i;return(i=this._boxHelper)==null?void 0:i.isInBox(e,t)}awake(){this._boxHelper=this.gameObject.addNewComponent(Io),this._boxHelper.updateBox(!0),Cm&&this._boxHelper.showHelper(5592320,!0),this.texture&&(this.texture.mapping=Do,this.texture.colorSpace=it,this.texture.needsUpdate=!0)}onDestroy(){const e=Ec._probes.get(this.context);if(e){const t=e.indexOf(this);t>=0&&e.splice(t,1)}}onSet(e){var i;if(jO||!this.enabled||((i=e.sharedMaterials)==null?void 0:i.length)<=0||!this.texture)return;let t=Ec._rendererMaterialsCache.get(e);t||(t=[],Ec._rendererMaterialsCache.set(e,t));for(let s=0;s<e.sharedMaterials.length;s++){const r=e.sharedMaterials[s];if(!r||r.envMap===void 0)continue;let o=t[s];const a=r===(o==null?void 0:o.copy),c=!o||o.material.uuid!==r.uuid||o.copy.version!==r.version;if(!a&&c){if(Cm){let d="";o?o.material!==r?d="reference changed; cached instance?: "+a:o.copy.version!==r.version&&(d="version changed"):d="not cached",console.warn("Cloning material",r.name,r.version,"Reason:",d,`
|
|
4916
4918
|
`,r.uuid,`
|
|
4917
4919
|
`,o==null?void 0:o.copy.uuid,`
|
|
4918
|
-
`,e.name)}const u=r.clone();u.version=r.version,o?(o.copy=u,o.material=r):(o={material:r,copy:u},t.push(o)),u[ute]=this,u[dte]=r,Cm&&console.log("Set reflection",e.name,e.guid)}const l=o==null?void 0:o.copy;l.envMap=this.texture,e.sharedMaterials[s]=l}}onUnset(e){const t=Ec._rendererMaterialsCache.get(e);if(t)for(let i=0;i<t.length;i++){const s=t[i];e.sharedMaterials[i]=s.material}}},h(C0,"_probes",new Map),h(C0,"_rendererMaterialsCache",new Map),C0);let Pp=Ec;oG([x(w)],Pp.prototype,"center",2);oG([x(w)],Pp.prototype,"size",2);const aG=Symbol("customVisibilityFlag");function tb(n,e){n.layers[aG]=e}const qO=Symbol("DidPatchLayers");function fte(){const n=Ns.prototype;if(n[qO])return;n[qO]=!0;const e=n.test;n.test=function(t){return this[aG]===!1?!1:e.call(this,t)}}fte();var pte=Object.defineProperty,mte=Object.getOwnPropertyDescriptor,Al=(n,e,t,i)=>{for(var s=i>1?void 0:i?mte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&pte(e,t,s),s};const ib=re("debugrenderer"),gte=re("debugskinnedmesh"),XO=re("noInstancing"),LM=re("debuginstancing"),Ate=re("debugprogressive"),vte=re("noprogressive"),yte=re("wireframe");class GI{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 i=this.setMaterial.bind(this),s=this.getMaterial.bind(this),r=e.gameObject;if(this._targets=[],r)switch(r.type){case"Group":this._targets=[...r.children];break;case"SkinnedMesh":case"Mesh":this._targets.push(r);break}let o=!1,a,c=0;for(let l=0;l<this._targets.length;l++){const u=this._targets[l];if(!u)continue;const d=u.material;if(d){d.shadowSide=d.side;for(let f=0;f<t.length;f++){const p=t[f];if(!p){o=!0;continue}if(d.name===p.name){a===void 0&&(a=new Map),a.set(f,l),c=Math.max(c,f);break}}}}if(o){this._indexMapMaxIndex=c,this._indexMap=a;const l=`Renderer ${e.name} was initialized with missing materials - this may lead to unexpected behaviour when trying to access sharedMaterials by index.`;console.warn(l),ar()&&ss("Found renderer with missing materials: please check the console for details.")}return new Proxy(this,{get(l,u){if(typeof u=="string"){const d=parseInt(u);if(!isNaN(d))return s(d)}return l[u]},set(l,u,d){return typeof u=="string"&&i(d,Number.parseInt(u)),Reflect.set(l,u,d)?(d instanceof Ut&&(l.changed=!0),!0):!1}})}get changed(){return this._changed}set changed(e){e===!0&&ib&&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 i=this._targets[t];!i||i.material===void 0||(i.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 i=t[e];return i?i.material:null}}const cG=class extends Ie{constructor(){super(...arguments);h(this,"receiveShadows",!1);h(this,"shadowCastingMode",0);h(this,"lightmapIndex",-1);h(this,"lightmapScaleOffset",new $e(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",(e,t,i,s,r,o)=>{var a;if(r.envMapIntensity!==void 0){const c=this.hasLightmap?Math.PI:1,l=((a=this.context.mainCameraComponent)==null?void 0:a.environmentIntensity)??1;r.envMapIntensity=Math.max(0,l*this.context.sceneLighting.environmentIntensity/c)}if(this._lightmaps)for(const c of this._lightmaps)c.updateLightmapUniforms(r)});h(this,"_reflectionProbe",null)}static setVisible(e,t){tb(e,t)}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(e){this.sharedMaterials[0]!==e&&(this.sharedMaterials[0]=e,this.applyLightmapping())}get material(){return this.sharedMaterials[0]}set material(e){this.sharedMaterial=e}set sharedMaterials(e){if(!this._originalMaterials)this._originalMaterials=e;else if(e){let t=!1;for(let i=0;i<this._sharedMaterials.length;i++){const s=i<e.length?e[i]:null;s&&s instanceof Ut?this.sharedMaterials[i]=s:t||(t=!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 XO}get lightmap(){var e;return(e=this._lightmaps)!=null&&e.length?this._lightmaps[0].lightmap:null}set lightmap(e){var t;if(this._lightmapTextureOverride=e,e===void 0&&(e=this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex)),(t=this._lightmaps)!=null&&t.length)for(const i of this._lightmaps)i.lightmap=e}get hasLightmap(){const e=this.lightmap;return e!=null}registering(){this.enabled||this.setVisibility(!1)}awake(){if(ib&&console.log("Renderer ",this.name,this),this.clearInstancingState(),this.probeAnchor&&ib&&this.probeAnchor.add(new yp(.2)),this._reflectionProbe=null,this.isMultiMaterialObject(this.gameObject)){for(const e of this.gameObject.children)this.context.addBeforeRenderListener(e,this.onBeforeRenderThree),e.layers.mask=this.gameObject.layers.mask;if(this.renderOrder!==void 0){let e=0;for(let t=0;t<this.gameObject.children.length;t++){const i=this.gameObject.children[t];if(!(!this.isMeshOrSkinnedMesh(i)||ne.getComponent(i,cG))){if(this.renderOrder.length<=e){console.warn("Incorrect renderOrder element count",this,this.renderOrder.length+" but expected "+this.gameObject.children.length,"Index: "+e,"ChildElement:",i);continue}i.renderOrder=this.renderOrder[e],e+=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 e=0;e<this.sharedMaterials.length;e++){const t=this.sharedMaterials[e];t&&(t.wireframe=!0)}}applyLightmapping(){var e;if(this.lightmapIndex>=0){const t=this.gameObject.type,i=this._lightmapTextureOverride!==void 0?this._lightmapTextureOverride:this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex);if(i){if(this._lightmaps||(this._lightmaps=[]),t==="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 o=new iA(this.gameObject,this.context);this._lightmaps.push(o)}this._lightmaps[0].init(this.lightmapIndex,this.lightmapScaleOffset,i)}}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(!((e=r.material)!=null&&e.isMeshBasicMaterial)){let o;s>=this._lightmaps.length?(o=new iA(r,this.context),this._lightmaps.push(o)):o=this._lightmaps[s],o.init(this.lightmapIndex,this.lightmapScaleOffset,i)}}}else ib&&console.warn("Lightmap not found",this.sourceId,this.lightmapIndex)}}clearInstancingState(){this._isInstancingEnabled=!1,this.handles=void 0,this.prevLayers=void 0}setInstancingEnabled(e){if(this._isInstancingEnabled===e)return e&&(this.handles===void 0||this.handles!=null&&this.handles.length>0);if(this._isInstancingEnabled=e,e){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 ne.markAsInstancedRendered(this.gameObject,!0),!0}else if(this.handles!==null){for(const t of this.handles)t.updateInstanceMatrix(!0),t.add();return ne.markAsInstancedRendered(this.gameObject,!0),!0}}else{if(this.handles)for(const t of this.handles)t.remove();return!0}return!1}useInstanceMatrixWorldAutoUpdate(){return!0}start(){if(this.enableInstancing&&!XO&&(this.setInstancingEnabled(!0),Gs.markDirty(this.gameObject)),this.gameObject.frustumCulled=this.allowOcclusionWhenDynamic,this.isMultiMaterialObject(this.gameObject))for(let e=0;e<this.gameObject.children.length;e++){const t=this.gameObject.children[e];t.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 e of this.gameObject.children)this.context.removeBeforeRenderListener(e,this.onBeforeRenderThree);else this.context.removeBeforeRenderListener(this.gameObject,this.onBeforeRenderThree)}applyStencil(){yg.applyStencil(this)}onBeforeRender(){var e,t;if(this.gameObject){if(this.isMultiMaterialObject(this.gameObject)&&((e=this.gameObject.children)==null?void 0:e.length)>0)for(const i of this.gameObject.children)this.applySettings(i);else this.applySettings(this.gameObject);if(this.sharedMaterials.changed&&(this.sharedMaterials.changed=!1,this.applyLightmapping()),(t=this.handles)!=null&&t.length&&this.gameObject[Zg]===!0){LM&&console.log("UPDATE INSTANCED MATRICES",this.context.time.frame),this.gameObject[Zg]=!1;for(let s=this.handles.length-1;s>=0;s--)this.handles[s].updateInstanceMatrix();this.gameObject.matrixWorldNeedsUpdate=!1}if(this.handles&&this.handles.length<=0&&ne.markAsInstancedRendered(this.gameObject,!1),this._isInstancingEnabled&&this.handles)for(let i=0;i<this.handles.length;i++){const s=this.handles[i];this.prevLayers||(this.prevLayers=[]);const r=s.object.layers.mask;i>=this.prevLayers.length?this.prevLayers.push(r):this.prevLayers[i]=r,s.object.layers.disableAll()}for(const i of this.sharedMaterials)i&&this.loadProgressiveTextures(i);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 e=0;e<this.handles.length;e++){const t=this.handles[e];t.object.layers.mask=this.prevLayers[e]}this.reflectionProbeUsage!==0&&this._reflectionProbe&&this._reflectionProbe.onUnset(this)}loadProgressiveTextures(e){return!vte&&e&&e._didRequestTextureLOD===void 0&&this.allowProgressiveLoading?(e._didRequestTextureLOD=0,Ate&&console.log("Load material LOD",e.name),Vr.assignTextureLOD(this.context,this.sourceId,e)):Promise.resolve(!0)}applySettings(e){e.receiveShadow=this.receiveShadows,this.shadowCastingMode==1?e.castShadow=!0:e.castShadow=!1}updateReflectionProbe(){if(this._reflectionProbe=null,this.reflectionProbeUsage!==0){if(!this.probeAnchor)return;this.startCoroutine(this._updateReflectionProbe(),ts.LateUpdate)}}*_updateReflectionProbe(){const e=this.probeAnchor||this.gameObject,t=!!this.probeAnchor;this._reflectionProbe=Pp.get(e,this.context,t,this.probeAnchor)}setVisibility(e){if(!this.isMultiMaterialObject(this.gameObject))tb(this.gameObject,e);else for(const t of this.gameObject.children)this.isMeshOrSkinnedMesh(t)&&tb(t,e)}isMultiMaterialObject(e){return e.type==="Group"}isMeshOrSkinnedMesh(e){return e.type==="Mesh"||e.type==="SkinnedMesh"}};let xn=cG;Al([x()],xn.prototype,"receiveShadows",2);Al([x()],xn.prototype,"shadowCastingMode",2);Al([x()],xn.prototype,"lightmapIndex",2);Al([x($e)],xn.prototype,"lightmapScaleOffset",2);Al([x()],xn.prototype,"enableInstancing",2);Al([x()],xn.prototype,"renderOrder",2);Al([x()],xn.prototype,"allowOcclusionWhenDynamic",2);Al([x(_e)],xn.prototype,"probeAnchor",2);Al([x()],xn.prototype,"reflectionProbeUsage",2);class Lx extends xn{}class HI extends Lx{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 la&&this.gameObject.boundingSphere){const e=zA(this.gameObject.boundingSphere.center).applyMatrix4(this.gameObject.matrixWorld);Qa.DrawWireSphere(e,this.gameObject.boundingSphere.radius,"red")}}}class _te{constructor(){h(this,"objs",[])}setup(e,t,i,s,r,o=0){e.applySettings(t);const a=this.tryCreateOrAddInstance(t,i,r);if(a)e.loadProgressiveTextures(a.instancer.material),s===null&&(s=[]),s.push(a);else if(o<=0&&t.type!=="Mesh"){const c=o+1;for(const l of t.children)s=this.setup(e,l,i,s,r,c)}return o===0&&r.useMatrixWorldAutoUpdate&&s&&s.length>=0&&this.autoUpdateInstanceMatrix(t),s}tryCreateOrAddInstance(e,t,i){if(e.type==="Mesh"){const s=i.foundMeshes;if(i.foundMeshes+=1,!i.rend.enableInstancing||s>=i.rend.enableInstancing.length||!i.rend.enableInstancing[s])return null;const r=e,o=r.geometry,a=r.material;for(const u of this.objs)if(!u.isFull()&&u.geo===o&&u.material===a)return u.addInstance(r);const c=new nb(e.name,o,a,200,t);return this.objs.push(c),c.addInstance(r)}return null}autoUpdateInstanceMatrix(e){const t=e.matrixWorld.multiplyMatrices.bind(e.matrixWorld),i=e.matrixWorld.clone(),s=(r,o)=>{const a=t(r,o);return(e[Zg]||i.equals(a)===!1)&&(i.copy(a),e[Zg]=!0),a};e.matrixWorld.multiplyMatrices=s}}const xte=new _te;class wte{constructor(e,t,i){h(this,"instanceIndex",-1);h(this,"object");h(this,"instancer");this.instanceIndex=e,this.object=t,this.instancer=i,t[rN]=i,ne.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 sP=class{constructor(e,t,i,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=e,this.geo=t,this.material=i,this.context=r,this.maxCount=s,LM&&(i=new ai({color:this.randomColor()})),this.inst=new D_(t,i,s),this.inst[rM]=!0,this.inst.onBeforeRender=()=>{this._needUpdateBounds&&this.inst[rM]===!0&&(LM&&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(e){this.inst.visible=e}get castShadow(){return this.inst.castShadow}set castShadow(e){this.inst.castShadow=e}set receiveShadow(e){this.inst.receiveShadow=e}updateBounds(e=!0,t=!0){this._needUpdateBounds=!1,e&&this.inst.computeBoundingBox(),t&&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(e){if(this.currentCount>=this.maxCount)return console.error("TOO MANY INSTANCES - resize is not yet implemented!",this.inst.count),null;const t=new wte(-1,e,this);return e.castShadow===!0&&this.inst.castShadow===!1&&(this.inst.castShadow=!0),e.receiveShadow===!0&&this.inst.receiveShadow===!1&&(this.inst.receiveShadow=!0),this.add(t),t}add(e){e.instanceIndex<0&&(e.instanceIndex=this.currentCount,e.instanceIndex>=this.handles.length?this.handles.push(e):this.handles[e.instanceIndex]=e),e.object.updateWorldMatrix(!0,!0),this.inst.setMatrixAt(e.instanceIndex,e.object.matrixWorld),this.inst.instanceMatrix.needsUpdate=!0,this.inst.count+=1,this._needUpdateBounds=!0,this.inst.count>0&&(this.inst.visible=!0)}remove(e){if(!e||e.instanceIndex<0||e.instanceIndex>=this.handles.length||this.inst.count<=0)return;if(this.handles[e.instanceIndex]!==e){console.error("instance handle is not part of renderer, was it removed before?",e.instanceIndex,this.name);const i=this.handles.indexOf(e);if(i<0)return;e.instanceIndex=i}if(this.handles[e.instanceIndex]=null,this.inst.setMatrixAt(e.instanceIndex,sP.nullMatrix),!(e.instanceIndex>=this.currentCount-1)&&this.currentCount>0){const i=this.handles[this.currentCount-1];i&&(i.instanceIndex=e.instanceIndex,i.updateInstanceMatrix(),this.handles[e.instanceIndex]=i,this.handles[this.currentCount-1]=null)}this.inst.count>0&&(this.inst.count-=1),e.instanceIndex=-1,this._needUpdateBounds=!0,this.inst.count<=0&&(this.inst.visible=!1),this.inst.instanceMatrix.needsUpdate=!0}updateInstance(e,t){this.inst.setMatrixAt(t,e),this.inst.instanceMatrix.needsUpdate=!0,this._needUpdateBounds=!0}};let nb=sP;h(nb,"nullMatrix",new Te);function Fx(n){return n=n.replace(/[^a-zA-Z0-9_]/g,""),n.match(/^[a-zA-Z_]/)||(n="_"+n),n}function lG(n){if(n.length===0)return null;const e=n.map(i=>{const s=new Array;for(;i.parent;)s.unshift(i.parent),i=i.parent;return s});return e[0].findLast(i=>e.every(s=>s.includes(i)))||null}function hG(n){const e=lG(n),t=new Set;for(const i of n){let s=i.parent;for(;s&&s!==e;)n.includes(s)||t.add(s),s=s.parent}return t}const bu=class{constructor(e,t,i,s=null,r=null,o=null,a=null,c=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=e,this.name=Fx(t),this.matrix=i,this.geometry=s,this.material=r,this.camera=o,this.parent=null,this.children=[],this._eventListeners={},this._isDynamic=!1,this.skinnedMesh=a,this.animations=c}get isDynamic(){return this._isDynamic}set isDynamic(e){this._isDynamic=e}static createEmptyParent(e){const t=new bu(ps.generateUUID(),e.name+"_empty_"+bu.USDObject_export_id++,e.matrix);return e.parent.add(t),t.add(e),t.isDynamic=!0,e.matrix=new Te().identity(),t}static createEmpty(){const e=new bu(ps.generateUUID(),"Empty_"+bu.USDObject_export_id++,new Te);return e.isDynamic=!0,e}is(e){return e?this.uuid===e.uuid:!1}isEmpty(){return!this.geometry}clone(){const e=new bu(ps.generateUUID(),this.name,this.matrix,this.geometry,this.material);return e.isDynamic=this.isDynamic,e}getPath(){let e=this.parent,t=this.name;for(;e;)t=(e.parent?e.name:e.name+"/Scenes/Scene")+"/"+t,e=e.parent;return"</"+t+">"}add(e){e.parent&&e.parent.remove(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))}addEventListener(e,t){this._eventListeners[e]||(this._eventListeners[e]=[]),this._eventListeners[e].push(t)}removeEventListener(e,t){if(!this._eventListeners[e])return;const i=this._eventListeners[e].indexOf(t);i>=0&&this._eventListeners[e].splice(i,1)}onSerialize(e,t){const i=this._eventListeners.serialize;i&&i.forEach(s=>s(e,t))}};let Sr=bu;h(Sr,"USDObject_export_id",0);class uG extends Sr{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(t){t.parent=this,this.children.push(t)}remove(t){const i=this.children.indexOf(t);i>=0&&(t.parent===this&&(t.parent=null),this.children.splice(i,1))}traverse(t,i=null){if(i!==null?t(i):i=this,i.children)for(const s of i.children)this.traverse(t,s)}findById(t){let i=!1;function s(r){if(!i){if(r.uuid===t)return i=!0,r;if(r.children)for(const o of r.children){const a=s(o);if(a)return a}}}return s(this)}buildHeader(t){return`#usda 1.0
|
|
4920
|
+
`,e.name)}const u=r.clone();u.version=r.version,o?(o.copy=u,o.material=r):(o={material:r,copy:u},t.push(o)),u[ute]=this,u[dte]=r,Cm&&console.log("Set reflection",e.name,e.guid)}const l=o==null?void 0:o.copy;l.envMap=this.texture,e.sharedMaterials[s]=l}}onUnset(e){const t=Ec._rendererMaterialsCache.get(e);if(t)for(let i=0;i<t.length;i++){const s=t[i];e.sharedMaterials[i]=s.material}}},h(C0,"_probes",new Map),h(C0,"_rendererMaterialsCache",new Map),C0);let Pp=Ec;oG([x(w)],Pp.prototype,"center",2);oG([x(w)],Pp.prototype,"size",2);const aG=Symbol("customVisibilityFlag");function tb(n,e){n.layers[aG]=e}const qO=Symbol("DidPatchLayers");function fte(){const n=Ns.prototype;if(n[qO])return;n[qO]=!0;const e=n.test;n.test=function(t){return this[aG]===!1?!1:e.call(this,t)}}fte();var pte=Object.defineProperty,mte=Object.getOwnPropertyDescriptor,Al=(n,e,t,i)=>{for(var s=i>1?void 0:i?mte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&pte(e,t,s),s};const ib=re("debugrenderer"),gte=re("debugskinnedmesh"),XO=re("noInstancing"),LM=re("debuginstancing"),Ate=re("debugprogressive"),vte=re("noprogressive"),yte=re("wireframe");class GI{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 i=this.setMaterial.bind(this),s=this.getMaterial.bind(this),r=e.gameObject;if(this._targets=[],r)switch(r.type){case"Group":this._targets=[...r.children];break;case"SkinnedMesh":case"Mesh":this._targets.push(r);break}let o=!1,a,c=0;for(let l=0;l<this._targets.length;l++){const u=this._targets[l];if(!u)continue;const d=u.material;if(d){d.shadowSide=d.side;for(let f=0;f<t.length;f++){const p=t[f];if(!p){o=!0;continue}if(d.name===p.name){a===void 0&&(a=new Map),a.set(f,l),c=Math.max(c,f);break}}}}if(o){this._indexMapMaxIndex=c,this._indexMap=a;const l=`Renderer ${e.name} was initialized with missing materials - this may lead to unexpected behaviour when trying to access sharedMaterials by index.`;console.warn(l),ar()&&ss("Found renderer with missing materials: please check the console for details.")}return new Proxy(this,{get(l,u){if(typeof u=="string"){const d=parseInt(u);if(!isNaN(d))return s(d)}return l[u]},set(l,u,d){return typeof u=="string"&&i(d,Number.parseInt(u)),Reflect.set(l,u,d)?(d instanceof Ut&&(l.changed=!0),!0):!1}})}get changed(){return this._changed}set changed(e){e===!0&&ib&&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 i=this._targets[t];!i||i.material===void 0||(i.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 i=t[e];return i?i.material:null}}const cG=class extends Ie{constructor(){super(...arguments);h(this,"receiveShadows",!1);h(this,"shadowCastingMode",0);h(this,"lightmapIndex",-1);h(this,"lightmapScaleOffset",new $e(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",(e,t,i,s,r,o)=>{var a;if(r.envMapIntensity!==void 0){const c=this.hasLightmap?Math.PI:1,l=((a=this.context.mainCameraComponent)==null?void 0:a.environmentIntensity)??1;r.envMapIntensity=Math.max(0,l*this.context.sceneLighting.environmentIntensity/c)}if(this._lightmaps)for(const c of this._lightmaps)c.updateLightmapUniforms(r)});h(this,"_reflectionProbe",null)}static setVisible(e,t){tb(e,t)}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(e){this.sharedMaterials[0]!==e&&(this.sharedMaterials[0]=e,this.applyLightmapping())}get material(){return this.sharedMaterials[0]}set material(e){this.sharedMaterial=e}set sharedMaterials(e){if(!this._originalMaterials)this._originalMaterials=e;else if(e){let t=!1;for(let i=0;i<this._sharedMaterials.length;i++){const s=i<e.length?e[i]:null;s&&s instanceof Ut?this.sharedMaterials[i]=s:t||(t=!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 XO}get lightmap(){var e;return(e=this._lightmaps)!=null&&e.length?this._lightmaps[0].lightmap:null}set lightmap(e){var t;if(this._lightmapTextureOverride=e,e===void 0&&(e=this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex)),(t=this._lightmaps)!=null&&t.length)for(const i of this._lightmaps)i.lightmap=e}get hasLightmap(){const e=this.lightmap;return e!=null}registering(){this.enabled||this.setVisibility(!1)}awake(){if(ib&&console.log("Renderer ",this.name,this),this.clearInstancingState(),this.probeAnchor&&ib&&this.probeAnchor.add(new yp(.2)),this._reflectionProbe=null,this.isMultiMaterialObject(this.gameObject)){for(const e of this.gameObject.children)this.context.addBeforeRenderListener(e,this.onBeforeRenderThree),e.layers.mask=this.gameObject.layers.mask;if(this.renderOrder!==void 0){let e=0;for(let t=0;t<this.gameObject.children.length;t++){const i=this.gameObject.children[t];if(!(!this.isMeshOrSkinnedMesh(i)||ne.getComponent(i,cG))){if(this.renderOrder.length<=e){console.warn("Incorrect renderOrder element count",this,this.renderOrder.length+" but expected "+this.gameObject.children.length,"Index: "+e,"ChildElement:",i);continue}i.renderOrder=this.renderOrder[e],e+=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 e=0;e<this.sharedMaterials.length;e++){const t=this.sharedMaterials[e];t&&(t.wireframe=!0)}}applyLightmapping(){var e;if(this.lightmapIndex>=0){const t=this.gameObject.type,i=this._lightmapTextureOverride!==void 0?this._lightmapTextureOverride:this.context.lightmaps.tryGetLightmap(this.sourceId,this.lightmapIndex);if(i){if(this._lightmaps||(this._lightmaps=[]),t==="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 o=new iA(this.gameObject,this.context);this._lightmaps.push(o)}this._lightmaps[0].init(this.lightmapIndex,this.lightmapScaleOffset,i)}}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(!((e=r.material)!=null&&e.isMeshBasicMaterial)){let o;s>=this._lightmaps.length?(o=new iA(r,this.context),this._lightmaps.push(o)):o=this._lightmaps[s],o.init(this.lightmapIndex,this.lightmapScaleOffset,i)}}}else ib&&console.warn("Lightmap not found",this.sourceId,this.lightmapIndex)}}clearInstancingState(){this._isInstancingEnabled=!1,this.handles=void 0,this.prevLayers=void 0}setInstancingEnabled(e){if(this._isInstancingEnabled===e)return e&&(this.handles===void 0||this.handles!=null&&this.handles.length>0);if(this._isInstancingEnabled=e,e){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 ne.markAsInstancedRendered(this.gameObject,!0),!0}else if(this.handles!==null){for(const t of this.handles)t.updateInstanceMatrix(!0),t.add();return ne.markAsInstancedRendered(this.gameObject,!0),!0}}else{if(this.handles)for(const t of this.handles)t.remove();return!0}return!1}useInstanceMatrixWorldAutoUpdate(){return!0}start(){if(this.enableInstancing&&!XO&&(this.setInstancingEnabled(!0),Gs.markDirty(this.gameObject)),this.gameObject.frustumCulled=this.allowOcclusionWhenDynamic,this.isMultiMaterialObject(this.gameObject))for(let e=0;e<this.gameObject.children.length;e++){const t=this.gameObject.children[e];t.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 e of this.gameObject.children)this.context.removeBeforeRenderListener(e,this.onBeforeRenderThree);else this.context.removeBeforeRenderListener(this.gameObject,this.onBeforeRenderThree)}applyStencil(){yg.applyStencil(this)}onBeforeRender(){var e,t;if(this.gameObject){if(this.isMultiMaterialObject(this.gameObject)&&((e=this.gameObject.children)==null?void 0:e.length)>0)for(const i of this.gameObject.children)this.applySettings(i);else this.applySettings(this.gameObject);if(this.sharedMaterials.changed&&(this.sharedMaterials.changed=!1,this.applyLightmapping()),(t=this.handles)!=null&&t.length&&this.gameObject[Zg]===!0){LM&&console.log("UPDATE INSTANCED MATRICES",this.context.time.frame),this.gameObject[Zg]=!1;for(let s=this.handles.length-1;s>=0;s--)this.handles[s].updateInstanceMatrix();this.gameObject.matrixWorldNeedsUpdate=!1}if(this.handles&&this.handles.length<=0&&ne.markAsInstancedRendered(this.gameObject,!1),this._isInstancingEnabled&&this.handles)for(let i=0;i<this.handles.length;i++){const s=this.handles[i];this.prevLayers||(this.prevLayers=[]);const r=s.object.layers.mask;i>=this.prevLayers.length?this.prevLayers.push(r):this.prevLayers[i]=r,s.object.layers.disableAll()}for(const i of this.sharedMaterials)i&&this.loadProgressiveTextures(i);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 e=0;e<this.handles.length;e++){const t=this.handles[e];t.object.layers.mask=this.prevLayers[e]}this.reflectionProbeUsage!==0&&this._reflectionProbe&&this._reflectionProbe.onUnset(this)}loadProgressiveTextures(e){return!vte&&e&&e._didRequestTextureLOD===void 0&&this.allowProgressiveLoading?(e._didRequestTextureLOD=0,Ate&&console.log("Load material LOD",e.name),Vr.assignTextureLOD(this.context,this.sourceId,e)):Promise.resolve(!0)}applySettings(e){e.receiveShadow=this.receiveShadows,this.shadowCastingMode==1?e.castShadow=!0:e.castShadow=!1}updateReflectionProbe(){if(this._reflectionProbe=null,this.reflectionProbeUsage!==0){if(!this.probeAnchor)return;this.startCoroutine(this._updateReflectionProbe(),ts.LateUpdate)}}*_updateReflectionProbe(){const e=this.probeAnchor||this.gameObject,t=!!this.probeAnchor;this._reflectionProbe=Pp.get(e,this.context,t,this.probeAnchor)}setVisibility(e){if(!this.isMultiMaterialObject(this.gameObject))tb(this.gameObject,e);else for(const t of this.gameObject.children)this.isMeshOrSkinnedMesh(t)&&tb(t,e)}isMultiMaterialObject(e){return e.type==="Group"}isMeshOrSkinnedMesh(e){return e.type==="Mesh"||e.type==="SkinnedMesh"}};let xn=cG;Al([x()],xn.prototype,"receiveShadows",2);Al([x()],xn.prototype,"shadowCastingMode",2);Al([x()],xn.prototype,"lightmapIndex",2);Al([x($e)],xn.prototype,"lightmapScaleOffset",2);Al([x()],xn.prototype,"enableInstancing",2);Al([x()],xn.prototype,"renderOrder",2);Al([x()],xn.prototype,"allowOcclusionWhenDynamic",2);Al([x(_e)],xn.prototype,"probeAnchor",2);Al([x()],xn.prototype,"reflectionProbeUsage",2);class Lx extends xn{}class HI extends Lx{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 la&&this.gameObject.boundingSphere){const e=zA(this.gameObject.boundingSphere.center).applyMatrix4(this.gameObject.matrixWorld);Qa.DrawWireSphere(e,this.gameObject.boundingSphere.radius,"red")}}}class _te{constructor(){h(this,"objs",[])}setup(e,t,i,s,r,o=0){e.applySettings(t);const a=this.tryCreateOrAddInstance(t,i,r);if(a)e.loadProgressiveTextures(a.instancer.material),s===null&&(s=[]),s.push(a);else if(o<=0&&t.type!=="Mesh"){const c=o+1;for(const l of t.children)s=this.setup(e,l,i,s,r,c)}return o===0&&r.useMatrixWorldAutoUpdate&&s&&s.length>=0&&this.autoUpdateInstanceMatrix(t),s}tryCreateOrAddInstance(e,t,i){if(e.type==="Mesh"){const s=i.foundMeshes;if(i.foundMeshes+=1,!i.rend.enableInstancing||s>=i.rend.enableInstancing.length||!i.rend.enableInstancing[s])return null;const r=e,o=r.geometry,a=r.material;for(const u of this.objs)if(!u.isFull()&&u.geo===o&&u.material===a)return u.addInstance(r);const c=new nb(e.name,o,a,200,t);return this.objs.push(c),c.addInstance(r)}return null}autoUpdateInstanceMatrix(e){const t=e.matrixWorld.multiplyMatrices.bind(e.matrixWorld),i=e.matrixWorld.clone(),s=(r,o)=>{const a=t(r,o);return(e[Zg]||i.equals(a)===!1)&&(i.copy(a),e[Zg]=!0),a};e.matrixWorld.multiplyMatrices=s}}const xte=new _te;class wte{constructor(e,t,i){h(this,"instanceIndex",-1);h(this,"object");h(this,"instancer");this.instanceIndex=e,this.object=t,this.instancer=i,t[rN]=i,ne.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 sP=class{constructor(e,t,i,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[rM]===!0&&(LM&&console.log("Update instancing bounds",this.name,this.inst.matrixWorldNeedsUpdate),this.updateBounds())});this.name=e,this.geo=t,this.material=i,this.context=r,this.maxCount=s,LM&&(i=new ai({color:this.randomColor()})),this.inst=new D_(t,i,s),this.inst[rM]=!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(e){this.inst.visible=e}get castShadow(){return this.inst.castShadow}set castShadow(e){this.inst.castShadow=e}set receiveShadow(e){this.inst.receiveShadow=e}updateBounds(e=!0,t=!0){this._needUpdateBounds=!1,e&&this.inst.computeBoundingBox(),t&&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(e){if(this.currentCount>=this.maxCount)return console.error("TOO MANY INSTANCES - resize is not yet implemented!",this.inst.count),null;const t=new wte(-1,e,this);return e.castShadow===!0&&this.inst.castShadow===!1&&(this.inst.castShadow=!0),e.receiveShadow===!0&&this.inst.receiveShadow===!1&&(this.inst.receiveShadow=!0),this.add(t),t}add(e){e.instanceIndex<0&&(e.instanceIndex=this.currentCount,e.instanceIndex>=this.handles.length?this.handles.push(e):this.handles[e.instanceIndex]=e),e.object.updateWorldMatrix(!0,!0),this.inst.setMatrixAt(e.instanceIndex,e.object.matrixWorld),this.inst.instanceMatrix.needsUpdate=!0,this.inst.count+=1,this._needUpdateBounds=!0,this.inst.count>0&&(this.inst.visible=!0)}remove(e){if(!e||e.instanceIndex<0||e.instanceIndex>=this.handles.length||this.inst.count<=0)return;if(this.handles[e.instanceIndex]!==e){console.error("instance handle is not part of renderer, was it removed before?",e.instanceIndex,this.name);const i=this.handles.indexOf(e);if(i<0)return;e.instanceIndex=i}if(this.handles[e.instanceIndex]=null,this.inst.setMatrixAt(e.instanceIndex,sP.nullMatrix),!(e.instanceIndex>=this.currentCount-1)&&this.currentCount>0){const i=this.handles[this.currentCount-1];i&&(i.instanceIndex=e.instanceIndex,i.updateInstanceMatrix(),this.handles[e.instanceIndex]=i,this.handles[this.currentCount-1]=null)}this.inst.count>0&&(this.inst.count-=1),e.instanceIndex=-1,this._needUpdateBounds=!0,this.inst.count<=0&&(this.inst.visible=!1),this.inst.instanceMatrix.needsUpdate=!0}updateInstance(e,t){this.inst.setMatrixAt(t,e),this.inst.instanceMatrix.needsUpdate=!0,this._needUpdateBounds=!0}};let nb=sP;h(nb,"nullMatrix",new Te);function Fx(n){return n=n.replace(/[^a-zA-Z0-9_]/g,""),n.match(/^[a-zA-Z_]/)||(n="_"+n),n}function lG(n){if(n.length===0)return null;const e=n.map(i=>{const s=new Array;for(;i.parent;)s.unshift(i.parent),i=i.parent;return s});return e[0].findLast(i=>e.every(s=>s.includes(i)))||null}function hG(n){const e=lG(n),t=new Set;for(const i of n){let s=i.parent;for(;s&&s!==e;)n.includes(s)||t.add(s),s=s.parent}return t}const bu=class{constructor(e,t,i,s=null,r=null,o=null,a=null,c=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=e,this.name=Fx(t),this.matrix=i,this.geometry=s,this.material=r,this.camera=o,this.parent=null,this.children=[],this._eventListeners={},this._isDynamic=!1,this.skinnedMesh=a,this.animations=c}get isDynamic(){return this._isDynamic}set isDynamic(e){this._isDynamic=e}static createEmptyParent(e){const t=new bu(ps.generateUUID(),e.name+"_empty_"+bu.USDObject_export_id++,e.matrix);return e.parent.add(t),t.add(e),t.isDynamic=!0,e.matrix=new Te().identity(),t}static createEmpty(){const e=new bu(ps.generateUUID(),"Empty_"+bu.USDObject_export_id++,new Te);return e.isDynamic=!0,e}is(e){return e?this.uuid===e.uuid:!1}isEmpty(){return!this.geometry}clone(){const e=new bu(ps.generateUUID(),this.name,this.matrix,this.geometry,this.material);return e.isDynamic=this.isDynamic,e}getPath(){let e=this.parent,t=this.name;for(;e;)t=(e.parent?e.name:e.name+"/Scenes/Scene")+"/"+t,e=e.parent;return"</"+t+">"}add(e){e.parent&&e.parent.remove(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))}addEventListener(e,t){this._eventListeners[e]||(this._eventListeners[e]=[]),this._eventListeners[e].push(t)}removeEventListener(e,t){if(!this._eventListeners[e])return;const i=this._eventListeners[e].indexOf(t);i>=0&&this._eventListeners[e].splice(i,1)}onSerialize(e,t){const i=this._eventListeners.serialize;i&&i.forEach(s=>s(e,t))}};let Sr=bu;h(Sr,"USDObject_export_id",0);class uG extends Sr{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(t){t.parent=this,this.children.push(t)}remove(t){const i=this.children.indexOf(t);i>=0&&(t.parent===this&&(t.parent=null),this.children.splice(i,1))}traverse(t,i=null){if(i!==null?t(i):i=this,i.children)for(const s of i.children)this.traverse(t,s)}findById(t){let i=!1;function s(r){if(!i){if(r.uuid===t)return i=!0,r;if(r.children)for(const o of r.children){const a=s(o);if(a)return a}}}return s(this)}buildHeader(t){return`#usda 1.0
|
|
4919
4921
|
(
|
|
4920
4922
|
customLayerData = {
|
|
4921
4923
|
string creator = "Needle Engine USDZExporter"
|