softbox 4.6.0 → 4.8.0
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/README.md +4 -2
- package/dist/CopyShader-DPSZNOxL.cjs +24 -0
- package/dist/CopyShader-DVL8Bcar.js +41 -0
- package/dist/EffectComposer-BdHnHszK.js +188 -0
- package/dist/EffectComposer-D2IQ0sek.cjs +1 -0
- package/dist/OutputPass-Dy4KNHYF.cjs +72 -0
- package/dist/OutputPass-Tt8WbC_B.js +125 -0
- package/dist/Pass-C1mreNp8.cjs +1 -0
- package/dist/Pass-DOcH4lwV.js +88 -0
- package/dist/RenderPass-B57TYmjs.js +37 -0
- package/dist/RenderPass-BVzyKWsC.cjs +1 -0
- package/dist/ShaderPass-BQRqK8zp.cjs +1 -0
- package/dist/ShaderPass-C2HX8lsT.js +45 -0
- package/dist/{ThreePathTracingService-DdrIay3N.cjs → ThreePathTracingService-BgK90Qzi.cjs} +62 -62
- package/dist/{ThreePathTracingService-DlCiqA08.js → ThreePathTracingService-yfJv1Gh-.js} +446 -488
- package/dist/UnrealBloomPass-Kx7djcld.cjs +115 -0
- package/dist/UnrealBloomPass-rjyQu37v.js +281 -0
- package/dist/VignetteShader-BG_QwoTp.js +45 -0
- package/dist/VignetteShader-Drpo9YxI.cjs +27 -0
- package/dist/{index-DoB8YjQ9.js → index-C4Vga5nj.js} +2468 -2278
- package/dist/index-CPZ7CXqQ.cjs +29 -0
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/simple-viewer.cjs +1 -1
- package/dist/simple-viewer.es.js +1 -1
- package/package.json +1 -1
- package/dist/index-BA_1qZxy.cjs +0 -11
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";var jo=Object.create;var Ui=Object.defineProperty;var Go=Object.getOwnPropertyDescriptor;var Wo=Object.getOwnPropertyNames;var Zo=Object.getPrototypeOf,Ko=Object.prototype.hasOwnProperty;var Xo=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Wo(e))!Ko.call(i,s)&&s!==t&&Ui(i,s,{get:()=>e[s],enumerable:!(n=Go(e,s))||n.enumerable});return i};var Cs=(i,e,t)=>(t=i!=null?jo(Zo(i)):{},Xo(e||!i||!i.__esModule?Ui(t,"default",{value:i,enumerable:!0}):t,i));const me=require("react/jsx-runtime"),se=require("react"),f=require("three");function Yo(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const E=Yo(f);class Z extends Error{constructor(e,t,n){super(e),this.code=t,this.context=n,this.name="ThreeViewerError",this.timestamp=new Date,Error.captureStackTrace&&Error.captureStackTrace(this,Z)}static fromError(e,t,n){if(e instanceof Z)return e;const s=e instanceof Error?e.message:String(e),r={...n,originalError:e instanceof Error?{name:e.name,message:e.message,stack:e.stack}:e};return new Z(s,t,r)}}var X=(i=>(i.SCENE_INIT_FAILED="SCENE_INIT_FAILED",i.RENDERER_INIT_FAILED="RENDERER_INIT_FAILED",i.RENDERER_NOT_INITIALIZED="RENDERER_NOT_INITIALIZED",i.CAMERA_INIT_FAILED="CAMERA_INIT_FAILED",i.WEBGL_NOT_SUPPORTED="WEBGL_NOT_SUPPORTED",i.INITIALIZATION_FAILED="INITIALIZATION_FAILED",i.PATH_TRACING_INIT_FAILED="PATH_TRACING_INIT_FAILED",i.MODEL_LOAD_FAILED="MODEL_LOAD_FAILED",i.TEXTURE_LOAD_FAILED="TEXTURE_LOAD_FAILED",i.RESOURCE_NOT_FOUND="RESOURCE_NOT_FOUND",i.UNSUPPORTED_FORMAT="UNSUPPORTED_FORMAT",i.INVALID_CONFIGURATION="INVALID_CONFIGURATION",i.RENDER_ERROR="RENDER_ERROR",i.RENDER_FAILED="RENDER_FAILED",i.SCENE_OPERATION_FAILED="SCENE_OPERATION_FAILED",i.COMPONENT_NOT_MOUNTED="COMPONENT_NOT_MOUNTED",i.INVALID_STATE="INVALID_STATE",i.INVALID_PARAMETER="INVALID_PARAMETER",i.OPERATION_FAILED="OPERATION_FAILED",i.UNKNOWN="UNKNOWN",i))(X||{});const F={ok(i){return{ok:!0,value:i}},err(i){return{ok:!1,error:i}},wrap(i){try{return F.ok(i())}catch(e){return F.err(e instanceof Z?e:new Z(String(e),X.UNKNOWN,{originalError:e}))}}};class Ts{constructor(){this.listeners=new Map}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set);const n=this.listeners.get(e);return n&&n.add(t),()=>{var s;(s=this.listeners.get(e))==null||s.delete(t)}}emit(e,t){var n;(n=this.listeners.get(e))==null||n.forEach(s=>{try{s(t)}catch(r){console.error(`Error in event listener for ${String(e)}:`,r)}})}once(e,t){const n=this.on(e,s=>{n(),t(s)});return n}removeAllListeners(e){e?this.listeners.delete(e):this.listeners.clear()}listenerCount(e){var t;return((t=this.listeners.get(e))==null?void 0:t.size)||0}off(e,t){var n;(n=this.listeners.get(e))==null||n.delete(t)}removeListener(e,t){this.off(e,t)}}const Qs=300,Ps={meters:1,centimeters:.01,millimeters:.001,feet:.3048,inches:.0254},qo="softbox-units-scale";function vr(i){const e=i??"meters";if(!Object.prototype.hasOwnProperty.call(Ps,e))throw new Z(`Unknown units '${String(e)}'. Valid values: ${Object.keys(Ps).join(", ")}`,X.INVALID_PARAMETER);return Ps[e]}const Vi="#1a1a1f";class $o{configureScene(e,t,n){var a,c,u;if(n.helpers){const d={grid:n.helpers.grid,axes:n.helpers.axes,gridColor:"#AAAAAA"},h=t.addHelpers(e,d);h.ok||console.warn("Failed to add helpers:",h.error)}const s=n.lighting;if(s){const d={ambient:s.ambientLight?{color:String(s.ambientLight.color),intensity:s.ambientLight.intensity}:void 0,hemisphere:s.hemisphereLight?{skyColor:String(s.hemisphereLight.skyColor),groundColor:String(s.hemisphereLight.groundColor),intensity:s.hemisphereLight.intensity}:void 0,directional:s.directionalLight?{color:String(s.directionalLight.color),intensity:s.directionalLight.intensity,position:Array.isArray(s.directionalLight.position)?s.directionalLight.position:void 0,castShadow:s.directionalLight.castShadow,shadow:s.directionalLight.shadow}:void 0},h=t.addLighting(e,d);h.ok||console.warn("Failed to add lighting:",h.error)}const r=(a=n.environment)==null?void 0:a.url,o=(((c=n.helpers)==null?void 0:c.studioEnvironment)??!1)&&(((u=n.helpers)==null?void 0:u.darkStudioMode)??!1);if(n.backgroundColor&&!r&&!o){const d=String(n.backgroundColor),h=t.createGradientBackground(e,{topColor:d,bottomColor:d});h.ok||console.warn("Failed to set background:",h.error)}}async configureEnvironment(e,t,n,s,r,o){var d,h,p,m,w,x;const a=await t.initialize({renderer:s,autoDispose:!0});if(o())return;a.ok||console.warn("Failed to initialize environment service:",a.error);const c={backgroundBlurriness:(d=r.environment)==null?void 0:d.backgroundBlurriness,backgroundIntensity:(h=r.environment)==null?void 0:h.backgroundIntensity,environmentIntensity:(p=r.environment)==null?void 0:p.environmentIntensity},u=(m=r.environment)==null?void 0:m.url;if(u){const _=await t.loadEnvironmentMap(u);if(o())return;_.ok?t.applyToScene(e,_.value,c):console.warn("Failed to load environment map:",_.error)}else if((w=r.helpers)!=null&&w.studioEnvironment){const _=t.createStudioEnvironment();if(_.ok){if(t.applyToScene(e,_.value,{...c,setBackground:!1}),(x=r.helpers)!=null&&x.darkStudioMode&&n){const v=n.createGradientBackground(e,{topColor:Vi,bottomColor:Vi});v.ok||console.warn("Failed to set dark studio background:",v.error)}}else console.warn("Failed to create studio environment:",_.error)}}}class Qo{constructor(e={}){this.animationFrameId=null,this.lastRenderTime=0,this.idleTimeout=null,this.isIdle=!1,this.needsRender=!0,this.continuousRenderingEnabled=!1,this.continuousReasons=new Set,this.alwaysRender=!1,this.enableIdleDetection=e.enableIdleDetection??!0,this.idleDelay=e.idleDelay??1e3,this.targetFPS=e.targetFPS??60,this.frameInterval=1e3/this.targetFPS,this.enableFrameRateLimiting=e.enableFrameRateLimiting??!0,this.alwaysRender=e.alwaysRender??!1,this.lastRenderTime=performance.now()}requestRender(){this.needsRender=!0,this.wakeUp()}requireContinuous(e){this.continuousReasons.add(e),this.continuousRenderingEnabled=!0,this.wakeUp()}releaseContinuous(e){this.continuousReasons.delete(e),this.continuousRenderingEnabled=this.continuousReasons.size>0}hasContinuousDemand(){return this.continuousReasons.size>0}setAlwaysRender(e){this.alwaysRender=e,e&&this.wakeUp()}wakeUp(){this.idleTimeout!==null&&(clearTimeout(this.idleTimeout),this.idleTimeout=null),this.isIdle=!1}start(e){if(this.animationFrameId!==null)return;const t=n=>{if(this.animationFrameId===null)return;const s=n-this.lastRenderTime;if(this.enableFrameRateLimiting&&s<this.frameInterval){this.animationFrameId=requestAnimationFrame(t);return}(this.alwaysRender||this.needsRender||this.continuousRenderingEnabled)&&(e(s),this.lastRenderTime=n,this.needsRender=!1),this.enableIdleDetection&&!this.alwaysRender&&(this.continuousRenderingEnabled||this.needsRender?this.wakeUp():this.idleTimeout===null&&!this.isIdle&&(this.idleTimeout=window.setTimeout(()=>{this.isIdle=!0},this.idleDelay))),this.alwaysRender||!this.enableIdleDetection||!this.isIdle||this.continuousRenderingEnabled||this.needsRender?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=null};this.animationFrameId=requestAnimationFrame(t)}stop(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.idleTimeout!==null&&(clearTimeout(this.idleTimeout),this.idleTimeout=null),this.isIdle=!1,this.needsRender=!1,this.continuousRenderingEnabled=!1,this.continuousReasons.clear(),this.alwaysRender=!1}isRunning(){return this.animationFrameId!==null}getIsIdle(){return this.isIdle}getNeedsRender(){return this.needsRender||this.continuousRenderingEnabled||this.alwaysRender}}function Vn(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)}function ms(i,e){if(!Vn(i)||!Vn(e))return e===void 0?i:e;const t=e,n={...i};for(const s of Object.keys(t)){const r=t[s];if(r===void 0)continue;const o=n[s];n[s]=Vn(o)&&Vn(r)?ms(o,r):r}return n}class Mr{static serialize(e,t,n,s){const r=t.position,o=n.target||{x:0,y:0,z:0};return{modelUrl:e,cameraPosition:{x:r.x,y:r.y,z:r.z},cameraTarget:{x:o.x,y:o.y,z:o.z},controlsTarget:{x:o.x,y:o.y,z:o.z},rendererSize:{width:s.clientWidth,height:s.clientHeight}}}static async restore(e,t,n,s){t.position.set(e.cameraPosition.x,e.cameraPosition.y,e.cameraPosition.z),t.lookAt({x:e.cameraTarget.x,y:e.cameraTarget.y,z:e.cameraTarget.z,set:()=>{},copy:()=>{},add:()=>{},multiply:()=>{},normalize:()=>{},length:()=>0}),n.target&&n.target.set(e.controlsTarget.x,e.controlsTarget.y,e.controlsTarget.z),n.update&&n.update(),e.modelUrl&&s&&await s(e.modelUrl)}}function Js(i,e){i.type==="perspective"&&"aspect"in i&&(i.aspect=e),i.updateProjectionMatrix()}class gt{constructor(e={}){this.data=Object.freeze({status:"idle",currentModel:null,error:null,isInitialized:!1,loadProgress:0,renderInfo:{frameCount:0,fps:0,lastRenderTime:0,averageRenderTime:0},...e})}get status(){return this.data.status}get currentModel(){return this.data.currentModel}get error(){return this.data.error}get isInitialized(){return this.data.isInitialized}get loadProgress(){return this.data.loadProgress}get renderInfo(){return this.data.renderInfo}setInitialized(){return new gt({...this.data,isInitialized:!0,status:"idle"})}startLoading(){return new gt({...this.data,status:"loading",loadProgress:0,error:null})}updateLoadProgress(e){return new gt({...this.data,loadProgress:Math.min(Math.max(0,e),1)})}setLoaded(e){return new gt({...this.data,status:"loaded",currentModel:e,loadProgress:1,error:null})}setError(e){return new gt({...this.data,status:"error",error:e,loadProgress:0})}startRendering(){return new gt({...this.data,status:"rendering"})}updateRenderInfo(e){return new gt({...this.data,renderInfo:{...this.data.renderInfo,...e}})}dispose(){return new gt({...this.data,status:"disposed",currentModel:null})}canLoad(){return this.data.isInitialized&&(this.data.status==="idle"||this.data.status==="loaded"||this.data.status==="error"||this.data.status==="rendering")}canRender(){return this.data.isInitialized&&this.data.status==="loaded"&&this.data.currentModel!==null}isLoading(){return this.data.status==="loading"}hasError(){return this.data.status==="error"&&this.data.error!==null}toJSON(){return{...this.data}}}class Jo{constructor(){this.state=new gt,this.stateChangeCallbacks=new Set}getState(){return this.state}setInitialized(){this.updateState(this.state.setInitialized())}startLoading(){this.updateState(this.state.startLoading())}setLoaded(e){this.updateState(this.state.setLoaded(e))}setError(e){this.updateState(this.state.setError(e))}startRendering(){this.updateState(this.state.startRendering())}updateRenderInfo(e){this.updateState(this.state.updateRenderInfo(e))}setDisposed(){this.updateState(this.state.dispose())}canLoad(){return this.state.canLoad()}isInitialized(){return this.state.isInitialized}getStatus(){return this.state.status}getCurrentModel(){return this.state.currentModel}onStateChange(e){return this.stateChangeCallbacks.add(e),()=>{this.stateChangeCallbacks.delete(e)}}clearCallbacks(){this.stateChangeCallbacks.clear()}updateState(e){this.state=e,this.stateChangeCallbacks.forEach(t=>{try{t(e)}catch(n){console.error("Error in state change callback:",n)}})}}function Rr(i){const e=i.toDataURL("image/png");return!e||e==="data:,"?null:e}class ea{constructor(e){this.screenshotElement=null,this.isShowingScreenshot=!1,this.renderer=e.renderer,this.onRestore=e.onRestore}isActive(){return this.isShowingScreenshot}captureAndReplace(e,t,n,s){if(this.isShowingScreenshot)return;const r=this.renderer.getDomElement(),o=Rr(r);if(!o){console.warn("[ScreenshotManager] Screenshot capture produced no image, keeping live scene");return}const a=document.createElement("img");a.src=o,a.style.position="absolute",a.style.top="0",a.style.left="0",a.style.width="100%",a.style.height="100%",a.style.pointerEvents="auto",a.style.cursor="grab";const c=r.parentElement;if(c){this.serializedSceneState=Mr.serialize(n,e,t,r),r.style.display="none",c.appendChild(a),this.screenshotElement=a,this.isShowingScreenshot=!0;const u=()=>{this.restore()};a.addEventListener("mousedown",u),a.addEventListener("touchstart",u);const d=()=>{this.isShowingScreenshot&&this.restore()};window.addEventListener("resize",d),this.screenshotResizeHandler=d,s==null||s()}}async restore(){if(!this.isShowingScreenshot||!this.screenshotElement)return;const e=this.renderer.getDomElement(),t=this.screenshotElement.parentElement;t&&(this.screenshotResizeHandler&&(window.removeEventListener("resize",this.screenshotResizeHandler),this.screenshotResizeHandler=void 0),t.removeChild(this.screenshotElement),e.style.display="",this.screenshotElement=null,this.isShowingScreenshot=!1,this.onRestore&&await this.onRestore())}getSerializedState(){return this.serializedSceneState}dispose(){this.screenshotResizeHandler&&(window.removeEventListener("resize",this.screenshotResizeHandler),this.screenshotResizeHandler=void 0),this.screenshotElement&&this.screenshotElement.parentElement&&this.screenshotElement.parentElement.removeChild(this.screenshotElement),this.isShowingScreenshot&&(this.renderer.getDomElement().style.display=""),this.screenshotElement=null,this.isShowingScreenshot=!1,this.serializedSceneState=void 0}}class ta{constructor(e){this.currentModel=null,this.modelLoader=e.modelLoader,this.scene=e.scene,this.camera=e.camera,this.controls=e.controls,this.floorAlignmentService=e.floorAlignmentService,this.sceneSetupService=e.sceneSetupService,this.renderer=e.renderer,this.autoFitToObject=e.autoFitToObject??!1,this.unitsScaleToMeters=e.unitsScaleToMeters??1}getCurrentModel(){return this.currentModel}getLastModelUrl(){return this.lastModelUrl}async loadModel(e,t){const n=performance.now();try{let s;if(typeof e=="string"){this.lastModelUrl=e,t.emit("model:loading",{url:e});const a=await this.modelLoader.load(e,(c,u)=>{t.emit("model:progress",{url:e,loaded:c,total:u})});if(!a.ok)throw a.error;s=a.value.scene}else s=e;if(this.unitsScaleToMeters!==1){if(!this.sceneSetupService)throw new Z("A units conversion is configured but no scene setup service is available to apply it",X.INVALID_PARAMETER);const a=this.sceneSetupService.wrapInUnitsScaleGroup(s,this.unitsScaleToMeters);if(!a.ok)throw a.error;s=a.value}this.currentModel&&(this.scene.remove(this.currentModel),this.disposeObject(this.currentModel));const r=this.scene.add(s);if(!r.ok)throw r.error;if(this.floorAlignmentService){const a=this.floorAlignmentService.alignToFloor(s);a.ok||console.warn("Failed to align model to floor:",a.error)}if(s.traverse(a=>{"castShadow"in a&&"receiveShadow"in a&&(a.castShadow=!0,a.receiveShadow=!0)}),this.currentModel=s,this.sceneSetupService){const a=this.sceneSetupService.addDynamicGrid(this.scene,s,2);a.ok||console.warn("Failed to add dynamic grid:",a.error);const c=this.sceneSetupService.snapObjectToFloor(this.scene,s);c.ok||console.warn("Failed to snap object to floor:",c.error);const u=this.sceneSetupService.fitShadowCameraToObject(this.scene,s);if(u.ok||console.warn("Failed to fit shadow camera to object:",u.error),this.renderer){const d=this.sceneSetupService.bakeContactShadow(this.scene,s,this.renderer);d.ok||console.warn("Failed to bake contact shadow:",d.error)}}if(this.autoFitToObject&&this.sceneSetupService){const a=this.sceneSetupService.fitCameraToObject(s,this.camera,this.controls);a.ok||console.warn("Failed to fit camera to object:",a.error)}const o=performance.now()-n;return t.emit("model:loaded",{model:s,loadTime:o}),F.ok(s)}catch(s){const r=s instanceof Z?s:new Z("Failed to load model",X.MODEL_LOAD_FAILED,{originalError:s,source:e});return t.emit("model:error",{error:r,url:typeof e=="string"?e:void 0}),F.err(r)}}disposeCurrentModel(){this.currentModel&&(this.scene.remove(this.currentModel),this.disposeObject(this.currentModel),this.currentModel=null)}disposeObject(e){e.dispose()}dispose(){var e,t;this.disposeCurrentModel(),(t=(e=this.modelLoader).dispose)==null||t.call(e),this.lastModelUrl=void 0}}class na{constructor(e){this.scene=e.scene,this.pathTracingService=e.pathTracingService,this.environmentService=e.environmentService}updateServices(e){e.pathTracingService&&(this.pathTracingService=e.pathTracingService),e.environmentService&&(this.environmentService=e.environmentService)}disposeSceneResources(e=!1){this.scene.disposeContents({keepBackgrounds:!0}),this.triggerGarbageCollection()}disposeServices(){this.pathTracingService&&(this.pathTracingService.dispose(),this.pathTracingService=void 0),this.environmentService&&(this.environmentService.dispose(),this.environmentService=void 0)}dispose(){this.disposeServices(),this.scene.disposeContents(),this.triggerGarbageCollection()}triggerGarbageCollection(){var e;globalThis.gc&&((e=globalThis.gc)==null||e.call(globalThis))}}class sa{constructor(e){this.completeHandled=!1,this.suspendedForAnimation=!1,this.initialized=!1,this.initializing=!1,this.selfPauseListeners=new Set,this.deps=e}isEnabled(){var e;return!!(this.deps.service&&(((e=this.deps.getOptions().pathTracing)==null?void 0:e.enabled)??!1))}getMaxSamples(){var e;return((e=this.deps.getOptions().pathTracing)==null?void 0:e.maxSamples)??Qs}isCompleteHandled(){return this.completeHandled}isAccumulating(){var e;return!!((e=this.deps.service)!=null&&e.isEnabled())}onSelfPause(e){return this.selfPauseListeners.add(e),()=>this.selfPauseListeners.delete(e)}async initialize(){this.isEnabled()&&await this.ensureInitialized()}async ensureInitialized(){const{service:e,getOptions:t,isDisposed:n,renderer:s,renderLoopManager:r,schedule:o}=this.deps;if(!(!e||this.initialized||this.initializing)){this.initializing=!0;try{const a=await e.initialize({enabled:!0,renderer:s});if(n())return;if(!a.ok){console.warn("Failed to initialize path tracing:",a.error);return}this.initialized=!0;const c=t().pathTracing;c&&e.updateSettings({samples:c.maxSamples??Qs,bounces:c.bounces,transmissiveBounces:c.transmissiveBounces,renderScale:c.renderScale,lowResScale:c.lowResScale,dynamicLowRes:c.dynamicLowRes,enablePathTracing:c.enabled??!0}),e.events.on("pathtracing:paused",({reason:u})=>{r.releaseContinuous("path-tracing"),t().staticScene||r.setAlwaysRender(!1),o(()=>{r.hasContinuousDemand()||r.stop()},100),u==="gave-up"&&this.selfPauseListeners.forEach(d=>d())})}finally{this.initializing=!1}}}async enableRuntime(){var s;const{service:e,renderLoopManager:t,getOptions:n}=this.deps;return!e||(await this.ensureInitialized(),!this.initialized)||!(((s=n().pathTracing)==null?void 0:s.enabled)??!1)?!1:(e.setEnabled(!0),e.reset(!0),this.completeHandled=!1,this.suspendedForAnimation=!1,t.requireContinuous("path-tracing"),!0)}disableRuntime(){const{service:e,renderLoopManager:t}=this.deps;e&&(e.setEnabled(!1),e.reset(),t.releaseContinuous("path-tracing"),this.completeHandled=!1,this.suspendedForAnimation=!1,this.selfPauseListeners.forEach(n=>n()))}resetAccumulation(e=!1){const{service:t,renderLoopManager:n}=this.deps;!t||!this.isEnabled()||(t.reset(e),this.completeHandled=!1,!t.isEnabled()&&(t.canResume()||this.suspendedForAnimation)&&(this.suspendedForAnimation=!1,t.setEnabled(!0),n.requireContinuous("path-tracing")))}suspendWhileAnimating(){const e=this.deps.service;if(e)if(e.isEnabled()){const t=!this.suspendedForAnimation;this.suspendedForAnimation=!0,e.setEnabled(!1),this.deps.renderLoopManager.releaseContinuous("path-tracing"),t&&this.selfPauseListeners.forEach(n=>n())}else e.canResume()&&e.getSampleCount()>0&&(e.reset(),this.completeHandled=!1,this.suspendedForAnimation=!0)}getSampleCount(){var e;return((e=this.deps.service)==null?void 0:e.getSampleCount())||0}beforeFrame(){var e;return{wasActive:((e=this.deps.service)==null?void 0:e.isEnabled())||!1,samples:this.getSampleCount()}}render(e,t){const n=this.deps.service;if(!n||n.isPathTracerDisposed())return null;const s=n.getSampleCount(),r=s>=this.getMaxSamples()&&s>0;return!n.isEnabled()&&!r?null:(s===0&&(this.startTime=performance.now()),n.render(e,t))}detectCompletion(e,t){const n=this.deps.service;if(!n)return;(n.getSampleCount()||0)>=this.getMaxSamples()&&!this.completeHandled&&e.wasActive&&this.handleComplete(e.samples,t)}handleComplete(e,t){const{events:n,renderLoopManager:s,getOptions:r,schedule:o,replaceWithScreenshot:a}=this.deps;this.completeHandled=!0,s.releaseContinuous("path-tracing"),r().staticScene||s.setAlwaysRender(!1),n.emit("pathtracing:complete",{samples:e,totalTime:t-(this.startTime||0)});const c=()=>{s.hasContinuousDemand()||s.stop()};if(r().replaceWithScreenshotOnComplete){o(()=>{a(),o(c,200)},100);return}s.requestRender(),o(c,100)}onResizeStart(){var t;const e=((t=this.deps.service)==null?void 0:t.isEnabled())??!1;return this.deps.service&&this.completeHandled&&(this.deps.service.reset(),this.completeHandled=!1),e}onResizeEnd(e){e&&this.deps.service&&this.deps.service.setEnabled(!0)}}function Cr(){const i="0123456789abcdef";return Array.from("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",t=>t==="x"?i[Math.floor(Math.random()*16)]:t==="y"?(Math.floor(Math.random()*16)&3|8).toString(16):t).join("")}const ia=i=>[i,"video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm","video/mp4"].filter(t=>!!t).find(t=>MediaRecorder.isTypeSupported(t));class ra{constructor(e){this.pendingSettlers=new Set,this.pathTracedWaitSettlers=new Set,this.deps=e}async captureStill(e={}){return this.deps.isDisposed()?F.err(new Z("Cannot capture a still from a disposed viewer",X.INVALID_STATE)):(await this.deps.awaitModelLoads().catch(()=>{}),this.deps.isDisposed()?F.err(new Z("Viewer was disposed while a model load finished",X.INVALID_STATE)):this.deps.isScreenshotActive()?F.err(new Z("Cannot capture a still while a screenshot is replacing the canvas",X.INVALID_STATE)):this.deps.pathTracing.isEnabled()?this.capturePathTracedStill(e):this.captureRasterStill(e))}settleOnDispose(){[...this.pendingSettlers].forEach(e=>e("disposed"))}notifyTurntableEnabled(){[...this.pathTracedWaitSettlers].forEach(e=>e("turntable"))}async captureVideo(e={}){var d;if(this.deps.isDisposed())return F.err(new Z("Cannot capture video from a disposed viewer",X.INVALID_STATE));if(await this.deps.awaitModelLoads().catch(()=>{}),this.deps.isDisposed())return F.err(new Z("Viewer was disposed while a model load finished",X.INVALID_STATE));if(this.deps.isScreenshotActive())return F.err(new Z("Cannot capture video while a screenshot is replacing the canvas",X.INVALID_STATE));const t=e.duration??3;if(!(t>0))return F.err(new Z("Video duration must be a positive number of seconds",X.INVALID_PARAMETER));const n=this.deps.renderer.getDomElement();if(typeof MediaRecorder>"u"||typeof n.captureStream!="function")return F.err(new Z("Video capture needs MediaRecorder and canvas.captureStream support",X.UNSUPPORTED_FORMAT));const s=n.captureStream(e.fps??30);let r;try{r=new MediaRecorder(s,{mimeType:ia(e.mimeType),videoBitsPerSecond:e.videoBitsPerSecond})}catch(h){return s.getTracks().forEach(p=>p.stop()),F.err(new Z("Failed to start the video recorder",X.OPERATION_FAILED,{originalError:h}))}const o=s.getVideoTracks()[0],a=(d=o==null?void 0:o.requestFrame)==null?void 0:d.bind(o),c=a?this.deps.events.on("render:complete",()=>a()):()=>{},u=`video-capture:${Cr()}`;return this.deps.renderLoopManager.requireContinuous(u),this.deps.reviveRenderLoop(),this.deps.renderLoopManager.requestRender(),new Promise(h=>{const p=[];let m=null,w=!1;const x=v=>{w||(w=!0,this.pendingSettlers.delete(_),c(),m!==null&&clearTimeout(m),this.deps.renderLoopManager.releaseContinuous(u),s.getTracks().forEach(T=>T.stop()),h(v))},_=()=>{x(F.err(new Z("Viewer was disposed during video capture",X.INVALID_STATE)));try{r.stop()}catch{}};this.pendingSettlers.add(_),r.ondataavailable=v=>{v.data.size>0&&p.push(v.data)},r.onstop=()=>{x(F.ok(new Blob(p,{type:r.mimeType||"video/webm"})))},r.onerror=()=>{x(F.err(new Z("Video recording failed",X.OPERATION_FAILED)))},r.start(250),m=setTimeout(()=>{r.state!=="inactive"&&r.stop()},t*1e3)})}async capturePathTracedStill(e){if(e.width!==void 0||e.height!==void 0)return F.err(new Z("Path-traced stills are captured at the canvas resolution; omit width/height",X.INVALID_PARAMETER));if(this.deps.isAutoRotating())return F.err(new Z("Cannot capture a path-traced still while the turntable is spinning — pause autoRotate first",X.INVALID_STATE));const t=this.deps.pathTracing.isAccumulating()&&this.deps.getStatus()!=="error";if(!this.deps.pathTracing.isCompleteHandled()&&t){const n=await this.waitForPathTracingOutcome();if(n==="disposed")return F.err(new Z("Viewer was disposed while waiting for the path tracer",X.INVALID_STATE));if(n==="error")return F.err(new Z("Model failed while waiting for the path tracer",X.RENDER_FAILED));if(n==="turntable")return F.err(new Z("Cannot capture a path-traced still while the turntable is spinning — pause autoRotate first",X.INVALID_STATE))}return this.readCanvasPng()}waitForPathTracingOutcome(){return new Promise(e=>{let t=()=>{},n=()=>{},s=()=>{},r=()=>{};const o=a=>{this.pendingSettlers.delete(o),this.pathTracedWaitSettlers.delete(o),t(),n(),s(),r(),e(a)};this.pendingSettlers.add(o),this.pathTracedWaitSettlers.add(o),t=this.deps.events.once("pathtracing:complete",()=>o("complete")),n=this.deps.events.once("model:error",()=>o("error")),s=this.deps.pathTracing.onSelfPause(()=>o("complete")),r=this.deps.events.on("controls:change",()=>{this.deps.isAutoRotating()&&o("turntable")})})}captureRasterStill(e){const{renderer:t,scene:n,camera:s,renderLoopManager:r}=this.deps,o=t.getDomElement(),a=t.getPixelRatio(),c=o.clientWidth>0&&o.clientHeight>0,u=c?o.clientWidth:Math.round(o.width/a),d=c?o.clientHeight:Math.round(o.height/a);if(u<=0||d<=0)return F.err(new Z("Cannot capture: the canvas has no size",X.INVALID_STATE));const h=u/d,p=Math.round(e.width??(e.height!==void 0?e.height*h:u*a)),m=Math.round(e.height??(e.width!==void 0?e.width/h:d*a)),w=t.capabilities.maxTextureSize;if(!Number.isFinite(p)||!Number.isFinite(m)||p<=0||m<=0||p>w||m>w)return F.err(new Z(`Requested still size ${p}x${m} is outside 1..${w}`,X.INVALID_PARAMETER));t.setPixelRatio(1),t.setSize(p,m),Js(s,p/m);const x=t.renderPostProcessed?t.renderPostProcessed(n,s):t.render(n,s),_=x.ok?this.readCanvasPng():F.err(x.error);return t.setSize(u,d),t.setPixelRatio(a),Js(s,h),t.render(n,s),r.requestRender(),_}readCanvasPng(){const e=Rr(this.deps.renderer.getDomElement());return e?F.ok(e):F.err(new Z("Canvas produced an empty image",X.RENDER_FAILED))}}class oa{constructor(e){var r;this.frameCount=0,this.disposed=!1,this.pendingTimers=new Set,this.modelLoadChain=Promise.resolve(),this.controlsChangeUnsubscribe=null,this.renderer=e.renderer,this.scene=e.scene,this.camera=e.camera,this.controls=e.controls,this.options=e.options,this.rendererOptions=e.rendererOptions,this.sceneSetupService=e.sceneSetupService,this.environmentService=e.environmentService,this.selectionService=e.selectionService,this.anchorProjectionService=e.anchorProjectionService,this.animationService=e.animationService,this.stateManager=new Jo,this.screenshotManager=new ea({renderer:this.renderer,onRestore:async()=>{await this.restoreFromScreenshot()}});const t=vr(this.options.units);this.modelManager=new ta({modelLoader:e.modelLoader,scene:this.scene,camera:this.camera,controls:this.controls,floorAlignmentService:e.floorAlignmentService,sceneSetupService:this.sceneSetupService,renderer:this.renderer,autoFitToObject:(r=this.options.camera)==null?void 0:r.autoFitToObject,unitsScaleToMeters:t}),this.resourceManager=new na({scene:this.scene,pathTracingService:e.pathTracingService,environmentService:this.environmentService}),this.sceneConfigurator=new $o,this.events=new Ts;const n=this.options.rendering||{},s=this.options.staticScene!==!1;this.renderLoopManager=new Qo({enableIdleDetection:n.enableIdleDetection??s,idleDelay:n.idleDelay,targetFPS:n.targetFPS,enableFrameRateLimiting:n.enableFrameRateLimiting,alwaysRender:!1}),this.pathTracing=new sa({service:e.pathTracingService,events:this.events,renderLoopManager:this.renderLoopManager,renderer:this.renderer,getOptions:()=>this.options,isDisposed:()=>this.disposed,schedule:(o,a)=>this.schedule(o,a),replaceWithScreenshot:()=>this.replaceWithScreenshot()}),this.capture=new ra({renderer:this.renderer,scene:this.scene,camera:this.camera,events:this.events,renderLoopManager:this.renderLoopManager,pathTracing:this.pathTracing,getStatus:()=>this.stateManager.getStatus(),isDisposed:()=>this.disposed,awaitModelLoads:()=>this.modelLoadChain,reviveRenderLoop:()=>this.reviveRenderLoop(),isAutoRotating:()=>this.controls.autoRotate,isScreenshotActive:()=>this.screenshotManager.isActive()})}async initialize(){var e,t;try{const n=this.renderer.initialize(this.rendererOptions||{});return n.ok?(this.sceneSetupService&&this.sceneConfigurator.configureScene(this.scene,this.sceneSetupService,this.options),this.environmentService&&(await this.sceneConfigurator.configureEnvironment(this.scene,this.environmentService,this.sceneSetupService,this.renderer,this.options,()=>this.disposed),this.disposed)||(await this.pathTracing.initialize(),this.disposed)||(this.selectionService&&this.selectionService.initialize({canvas:this.renderer.getDomElement(),camera:this.camera,getPickRoot:()=>this.modelManager.getCurrentModel(),bvh:(e=this.options.selection)==null?void 0:e.bvh,onPick:s=>{s&&!this.disposed&&this.events.emit("object:selected",s)}}),this.stateManager.setInitialized(),this.startRenderLoop(),this.controlsChangeUnsubscribe=this.controls.onChange(()=>{this.disposed||(this.reviveRenderLoop(),this.renderLoopManager.requestRender())}),this.options.staticScene?this.pathTracing.isEnabled()&&this.renderLoopManager.requireContinuous("path-tracing"):this.renderLoopManager.setAlwaysRender(!0),(t=this.options.controls)!=null&&t.autoRotate&&this.renderLoopManager.requireContinuous("turntable"),this.renderLoopManager.requestRender()),F.ok(void 0)):n}catch(n){const s=new Z("Failed to initialize viewer",X.INITIALIZATION_FAILED,{originalError:n});return this.stateManager.setError(s),this.events.emit("error",{error:s}),F.err(s)}}loadModel(e){const t=this.modelLoadChain.then(()=>this.runLoadModel(e));return this.modelLoadChain=t.then(()=>{},()=>{}),t}async runLoadModel(e){if(this.disposed)return F.err(new Z("Cannot load model after dispose",X.INVALID_STATE));if(!this.stateManager.canLoad())return F.err(new Z("Cannot load model in current state",X.INVALID_STATE,{currentState:this.stateManager.getStatus(),isInitialized:this.stateManager.isInitialized()}));try{this.stateManager.startLoading();const t=await this.modelManager.loadModel(e,this.events);return this.disposed?(t.ok&&this.modelManager.disposeCurrentModel(),F.err(new Z("Viewer was disposed while the model was loading",X.INVALID_STATE))):t.ok?(this.stateManager.setLoaded(t.value),this.attachAnimations(t.value),this.reviveRenderLoop(),this.renderLoopManager.requestRender(),this.pathTracing.resetAccumulation(!0),F.ok(void 0)):(this.stateManager.setError(t.error),t)}catch(t){const n=t instanceof Z?t:new Z("Failed to load model",X.MODEL_LOAD_FAILED,{originalError:t,source:e});return this.stateManager.setError(n),F.err(n)}}startRenderLoop(){this.renderLoopManager.start(e=>{var a;if(this.disposed){this.renderLoopManager.stop();return}if(!this.stateManager.isInitialized()||this.stateManager.getStatus()==="error")return;if(!this.renderer||this.renderer.isDisposed()){this.renderLoopManager.stop();return}const t=performance.now(),n=e>0?1e3/e:0,s=((a=this.animationService)==null?void 0:a.isPlaying())??!1;this.controls.update()&&(this.events.emit("controls:change",{controls:this.controls}),s||this.pathTracing.resetAccumulation(),this.renderLoopManager.requestRender()),s&&this.animationService&&(this.animationService.update(e/1e3),this.pathTracing.suspendWhileAnimating());const o=this.pathTracing.beforeFrame();this.renderFrame().catch(c=>{console.error("[ViewerCore] Render frame error:",c)}),this.pathTracing.detectCompletion(o,t),this.frameCount++,this.stateManager.updateRenderInfo({frameCount:this.frameCount,fps:Math.round(n),lastRenderTime:performance.now()-t})})}stopRenderLoop(){this.renderLoopManager.stop()}schedule(e,t){const n=setTimeout(()=>{this.pendingTimers.delete(n),!this.disposed&&e()},t);this.pendingTimers.add(n)}async renderFrame(){const e=performance.now();if(!this.renderer||!this.scene||!this.camera){console.warn("[ViewerCore] Cannot render - components not initialized");return}if(this.screenshotManager.isActive())return;this.stateManager.startRendering();const t=await(this.pathTracing.render(this.scene,this.camera)??Promise.resolve(this.renderRaster()));if(!t.ok){console.error("[ViewerCore] Render failed:",t.error),this.events.emit("error",{error:t.error});return}this.events.emit("render:complete",{frame:this.frameCount,renderTime:performance.now()-e,samples:this.pathTracing.getSampleCount()})}renderRaster(){return this.renderer.renderPostProcessed?this.renderer.renderPostProcessed(this.scene,this.camera):this.renderer.render(this.scene,this.camera)}updateOptions(e){var m,w,x,_,v,T,S,b,A,L,P;if(this.disposed)return;const t=(m=this.options.animations)==null?void 0:m.autoplay,n=(w=this.options.controls)==null?void 0:w.autoRotate,s=((x=this.options.pathTracing)==null?void 0:x.enabled)??!1;this.options=ms(this.options,e);let r=!1;e.backgroundColor!==void 0&&this.applyBackgroundColor(e.backgroundColor);const o=(_=e.renderer)==null?void 0:_.toneMappingExposure;o!==void 0&&(this.renderer.setToneMappingExposure(o),r=!0);const a=(v=e.environment)==null?void 0:v.environmentIntensity;a!==void 0&&(this.scene.setEnvironmentIntensity(a),r=!0);const c=(T=e.controls)==null?void 0:T.autoRotate;c!==void 0&&c!==n&&(this.controls.autoRotate=c,c?(this.renderLoopManager.requireContinuous("turntable"),this.capture.notifyTurntableEnabled()):this.renderLoopManager.releaseContinuous("turntable"),r=!0);const u=(S=e.controls)==null?void 0:S.autoRotateSpeed;u!==void 0&&(this.controls.autoRotateSpeed=u,r=!0);const d=(b=e.animations)==null?void 0:b.autoplay;d!==void 0&&d!==t&&(d?this.modelManager.getCurrentModel()&&this.autoplayFromOptions(d):this.pauseAnimations(),r=!0);const h=(A=e.animations)==null?void 0:A.speed;h!==void 0&&((L=this.animationService)==null||L.setSpeed(h),r=!0);const p=(P=e.pathTracing)==null?void 0:P.enabled;p!==void 0&&p!==s&&(this.setPathTracingEnabled(p),r=!0),r&&(this.reviveRenderLoop(),this.renderLoopManager.requestRender())}applyBackgroundColor(e){var n;if((n=this.options.environment)!=null&&n.url||!this.sceneSetupService)return;const t=this.sceneSetupService.createGradientBackground(this.scene,{topColor:String(e),bottomColor:String(e)});if(!t.ok){console.warn("Failed to update background color:",t.error);return}this.renderLoopManager.requestRender()}resize(e,t){if(this.disposed)return;const n=this.renderer.getDomElement();if(n.width===e&&n.height===t)return;const s=this.pathTracing.onResizeStart();Js(this.camera,e/t),this.renderer.setSize(e,t);try{this.renderer.render(this.scene,this.camera)}catch{}this.pathTracing.onResizeEnd(s),this.renderLoopManager.requestRender()}getState(){return this.stateManager.getState()}onStateChange(e){return this.stateManager.onStateChange(e)}getEvents(){return this.events}getDomElement(){return this.renderer.getDomElement()}getRenderer(){return this.renderer}getScene(){return this.scene}getCamera(){return this.camera}getControls(){return this.controls}getModel(){return this.modelManager.getCurrentModel()}requestRender(){this.renderLoopManager.requestRender()}reviveRenderLoop(){this.stateManager.isInitialized()&&!this.renderLoopManager.isRunning()&&this.startRenderLoop()}setPathTracingEnabled(e){e?this.pathTracing.enableRuntime().then(t=>{t&&!this.disposed&&(this.reviveRenderLoop(),this.renderLoopManager.requestRender())}):(this.pathTracing.disableRuntime(),this.reviveRenderLoop(),this.renderLoopManager.requestRender())}getAnimationNames(){var e;return((e=this.animationService)==null?void 0:e.getClipNames())??[]}playAnimations(e){var n;if(!this.animationService)return e!==void 0?F.err(new Z(`Cannot play animation clip '${e}': the viewer was assembled without an animation service`,X.INVALID_STATE)):F.ok(void 0);const t=this.animationService.play(e);return t.ok?(this.animationService.isPlaying()&&((n=this.sceneSetupService)==null||n.setContactShadowMode(this.scene,"live"),this.renderLoopManager.requireContinuous("animations"),this.reviveRenderLoop(),this.renderLoopManager.requestRender()),F.ok(void 0)):t}autoplayFromOptions(e){const t=this.playAnimations(typeof e=="string"?e:void 0);t.ok||console.error("animations.autoplay failed:",t.error.message)}pauseAnimations(){var e;(e=this.animationService)==null||e.pause(),this.renderLoopManager.releaseContinuous("animations"),this.rebakeContactShadowForCurrentPose(),this.pathTracing.resetAccumulation(!0),this.renderLoopManager.requestRender()}rebakeContactShadowForCurrentPose(){const e=this.modelManager.getCurrentModel();if(!e||!this.sceneSetupService)return;const t=this.sceneSetupService.bakeContactShadow(this.scene,e,this.renderer);t.ok||console.warn("Failed to re-bake contact shadow after pausing animations:",t.error)}attachAnimations(e){if(!this.animationService)return;this.renderLoopManager.releaseContinuous("animations"),this.animationService.attach(e);const t=this.options.animations;(t==null?void 0:t.speed)!==void 0&&this.animationService.setSpeed(t.speed);const n=t==null?void 0:t.autoplay;n&&this.autoplayFromOptions(n)}createAnchorProjector(){return this.anchorProjectionService?this.anchorProjectionService.createProjector({camera:this.camera,getCanvas:()=>this.renderer.getDomElement(),getModel:()=>this.getModel()}):null}captureStill(e={}){return this.capture.captureStill(e)}captureVideo(e={}){return this.capture.captureVideo(e)}replaceWithScreenshot(){const e=this.modelManager.getLastModelUrl();this.screenshotManager.captureAndReplace(this.camera,this.controls,e,()=>{this.modelManager.disposeCurrentModel(),this.resourceManager.disposeSceneResources(!0)})}async restoreFromScreenshot(){const e=this.screenshotManager.getSerializedState();e&&await Mr.restore(e,this.camera,this.controls,async t=>{const n=await this.loadModel(t);n.ok||console.error("[ViewerCore] Failed to reload model:",n.error)}),this.renderLoopManager.isRunning()||this.startRenderLoop(),this.renderLoopManager.requestRender()}dispose(){var e,t,n;this.disposed=!0,this.pendingTimers.forEach(s=>clearTimeout(s)),this.pendingTimers.clear(),this.stopRenderLoop(),(e=this.controlsChangeUnsubscribe)==null||e.call(this),this.controlsChangeUnsubscribe=null,(t=this.selectionService)==null||t.dispose(),(n=this.animationService)==null||n.detach(),this.modelManager.dispose(),this.resourceManager.dispose(),this.screenshotManager.dispose(),this.controls.dispose(),this.renderer.dispose(),this.stateManager.setDisposed(),this.capture.settleOnDispose(),this.events.removeAllListeners(),this.stateManager.clearCallbacks()}}class Ot{constructor(e){this.vector=e}get x(){return this.vector.x}set x(e){this.vector.x=e}get y(){return this.vector.y}set y(e){this.vector.y=e}get z(){return this.vector.z}set z(e){this.vector.z=e}set(e,t,n){this.vector.set(e,t,n)}copy(e){this.vector.set(e.x,e.y,e.z)}add(e){this.vector.x+=e.x,this.vector.y+=e.y,this.vector.z+=e.z}multiply(e){this.vector.x*=e.x,this.vector.y*=e.y,this.vector.z*=e.z}normalize(){this.vector.normalize()}length(){return this.vector.length()}getThreeVector(){return this.vector}static fromThreeVector(e){return new Ot(e)}static create(e=0,t=0,n=0){return new Ot(new E.Vector3(e,t,n))}}const Pr=0,aa=1,Ir=2,Hi=2,Is=1.25,ji=1,Ve=32,De=Ve/4,Ti=65535,ca=Ti<<16,ds=Math.pow(2,-24),Si=Symbol("SKIP_GENERATION"),Lr={strategy:Pr,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Si]:!1};function Ae(i,e,t){return t.min.x=e[i],t.min.y=e[i+1],t.min.z=e[i+2],t.max.x=e[i+3],t.max.y=e[i+4],t.max.z=e[i+5],t}function Gi(i){let e=-1,t=-1/0;for(let n=0;n<3;n++){const s=i[n+3]-i[n];s>t&&(t=s,e=n)}return e}function Wi(i,e){e.set(i)}function Zi(i,e,t){let n,s;for(let r=0;r<3;r++){const o=r+3;n=i[r],s=e[r],t[r]=n<s?n:s,n=i[o],s=e[o],t[o]=n>s?n:s}}function Hn(i,e,t){for(let n=0;n<3;n++){const s=e[i+2*n],r=e[i+2*n+1],o=s-r,a=s+r;o<t[n]&&(t[n]=o),a>t[n+3]&&(t[n+3]=a)}}function un(i){const e=i[3]-i[0],t=i[4]-i[1],n=i[5]-i[2];return 2*(e*t+t*n+n*e)}function Pe(i,e){return e[i+15]===Ti}function He(i,e){return e[i+6]}function Xe(i,e){return e[i+14]}function ke(i){return i+De}function Be(i,e){const t=e[i+6];return i+t*De}function Ss(i,e){return e[i+7]}function la(i){return i}function Ls(i,e,t,n,s){let r=1/0,o=1/0,a=1/0,c=-1/0,u=-1/0,d=-1/0,h=1/0,p=1/0,m=1/0,w=-1/0,x=-1/0,_=-1/0;const v=i.offset||0;for(let T=(e-v)*6,S=(e+t-v)*6;T<S;T+=6){const b=i[T+0],A=i[T+1],L=b-A,P=b+A;L<r&&(r=L),P>c&&(c=P),b<h&&(h=b),b>w&&(w=b);const C=i[T+2],D=i[T+3],I=C-D,k=C+D;I<o&&(o=I),k>u&&(u=k),C<p&&(p=C),C>x&&(x=C);const N=i[T+4],H=i[T+5],G=N-H,$=N+H;G<a&&(a=G),$>d&&(d=$),N<m&&(m=N),N>_&&(_=N)}n[0]=r,n[1]=o,n[2]=a,n[3]=c,n[4]=u,n[5]=d,s[0]=h,s[1]=p,s[2]=m,s[3]=w,s[4]=x,s[5]=_}const _t=32,ha=(i,e)=>i.candidate-e.candidate,Mt=new Array(_t).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),jn=new Float32Array(6);function ua(i,e,t,n,s,r){let o=-1,a=0;if(r===Pr)o=Gi(e),o!==-1&&(a=(e[o]+e[o+3])/2);else if(r===aa)o=Gi(i),o!==-1&&(a=da(t,n,s,o));else if(r===Ir){const c=un(i);let u=Is*s;const d=t.offset||0,h=(n-d)*6,p=(n+s-d)*6;for(let m=0;m<3;m++){const w=e[m],v=(e[m+3]-w)/_t;if(s<_t/4){const T=[...Mt];T.length=s;let S=0;for(let A=h;A<p;A+=6,S++){const L=T[S];L.candidate=t[A+2*m],L.count=0;const{bounds:P,leftCacheBounds:C,rightCacheBounds:D}=L;for(let I=0;I<3;I++)D[I]=1/0,D[I+3]=-1/0,C[I]=1/0,C[I+3]=-1/0,P[I]=1/0,P[I+3]=-1/0;Hn(A,t,P)}T.sort(ha);let b=s;for(let A=0;A<b;A++){const L=T[A];for(;A+1<b&&T[A+1].candidate===L.candidate;)T.splice(A+1,1),b--}for(let A=h;A<p;A+=6){const L=t[A+2*m];for(let P=0;P<b;P++){const C=T[P];L>=C.candidate?Hn(A,t,C.rightCacheBounds):(Hn(A,t,C.leftCacheBounds),C.count++)}}for(let A=0;A<b;A++){const L=T[A],P=L.count,C=s-L.count,D=L.leftCacheBounds,I=L.rightCacheBounds;let k=0;P!==0&&(k=un(D)/c);let N=0;C!==0&&(N=un(I)/c);const H=ji+Is*(k*P+N*C);H<u&&(o=m,u=H,a=L.candidate)}}else{for(let b=0;b<_t;b++){const A=Mt[b];A.count=0,A.candidate=w+v+b*v;const L=A.bounds;for(let P=0;P<3;P++)L[P]=1/0,L[P+3]=-1/0}for(let b=h;b<p;b+=6){let P=~~((t[b+2*m]-w)/v);P>=_t&&(P=_t-1);const C=Mt[P];C.count++,Hn(b,t,C.bounds)}const T=Mt[_t-1];Wi(T.bounds,T.rightCacheBounds);for(let b=_t-2;b>=0;b--){const A=Mt[b],L=Mt[b+1];Zi(A.bounds,L.rightCacheBounds,A.rightCacheBounds)}let S=0;for(let b=0;b<_t-1;b++){const A=Mt[b],L=A.count,P=A.bounds,D=Mt[b+1].rightCacheBounds;L!==0&&(S===0?Wi(P,jn):Zi(P,jn,jn)),S+=L;let I=0,k=0;S!==0&&(I=un(jn)/c);const N=s-S;N!==0&&(k=un(D)/c);const H=ji+Is*(I*S+k*N);H<u&&(o=m,u=H,a=A.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${r} used.`);return{axis:o,pos:a}}function da(i,e,t,n){let s=0;const r=i.offset;for(let o=e,a=e+t;o<a;o++)s+=i[(o-r)*6+n*2];return s/t}class Os{constructor(){this.boundingData=new Float32Array(6)}}function pa(i,e,t,n,s,r){let o=n,a=n+s-1;const c=r.pos,u=r.axis*2,d=t.offset||0;for(;;){for(;o<=a&&t[(o-d)*6+u]<c;)o++;for(;o<=a&&t[(a-d)*6+u]>=c;)a--;if(o<a){for(let h=0;h<e;h++){let p=i[o*e+h];i[o*e+h]=i[a*e+h],i[a*e+h]=p}for(let h=0;h<6;h++){const p=o-d,m=a-d,w=t[p*6+h];t[p*6+h]=t[m*6+h],t[m*6+h]=w}o++,a--}else return o}}let Or,ps,ei,Dr;const fa=Math.pow(2,32);function ti(i){return"count"in i?1:1+ti(i.left)+ti(i.right)}function ma(i,e,t){return Or=new Float32Array(t),ps=new Uint32Array(t),ei=new Uint16Array(t),Dr=new Uint8Array(t),ni(i,e)}function ni(i,e){const t=i/4,n=i/2,s="count"in e,r=e.boundingData;for(let o=0;o<6;o++)Or[t+o]=r[o];if(s)return e.buffer?(Dr.set(new Uint8Array(e.buffer),i),i+e.buffer.byteLength):(ps[t+6]=e.offset,ei[n+14]=e.count,ei[n+15]=Ti,i+Ve);{const{left:o,right:a,splitAxis:c}=e,u=i+Ve;let d=ni(u,o);const h=i/Ve,m=d/Ve-h;if(m>fa)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return ps[t+6]=m,ps[t+7]=c,ni(d,a)}}function ga(i,e,t,n,s,r){const{maxDepth:o,verbose:a,maxLeafSize:c,strategy:u,onProgress:d}=s,h=i.primitiveBuffer,p=i.primitiveBufferStride,m=new Float32Array(6);let w=!1;const x=new Os;return Ls(e,t,n,x.boundingData,m),v(x,t,n,m),x;function _(T){d&&d((T-r.offset)/r.count)}function v(T,S,b,A=null,L=0){if(!w&&L>=o&&(w=!0,a&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`)),b<=c||L>=o)return _(S+b),T.offset=S,T.count=b,T;const P=ua(T.boundingData,A,e,S,b,u);if(P.axis===-1)return _(S+b),T.offset=S,T.count=b,T;const C=pa(h,p,e,S,b,P);if(C===S||C===S+b)_(S+b),T.offset=S,T.count=b;else{T.splitAxis=P.axis;const D=new Os,I=S,k=C-S;T.left=D,Ls(e,I,k,D.boundingData,m),v(D,I,k,m,L+1);const N=new Os,H=C,G=b-k;T.right=N,Ls(e,H,G,N.boundingData,m),v(N,H,G,m,L+1)}return T}}function ya(i,e){const t=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=i.getRootRanges(e.range),s=n[0],r=n[n.length-1],o={offset:s.offset,count:r.offset+r.count-s.offset},a=new Float32Array(6*o.count);a.offset=o.offset,i.computePrimitiveBounds(o.offset,o.count,a),i._roots=n.map(c=>{const u=ga(i,a,c.offset,c.count,e,o),d=ti(u),h=new t(Ve*d);return ma(0,u,h),h})}class _i{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class wa{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const be=new wa;let Lt,nn;const Wt=[],Gn=new _i(()=>new f.Box3);function Ea(i,e,t,n,s,r){Lt=Gn.getPrimitive(),nn=Gn.getPrimitive(),Wt.push(Lt,nn),be.setBuffer(i._roots[e]);const o=si(0,i.geometry,t,n,s,r);be.clearBuffer(),Gn.releasePrimitive(Lt),Gn.releasePrimitive(nn),Wt.pop(),Wt.pop();const a=Wt.length;return a>0&&(nn=Wt[a-1],Lt=Wt[a-2]),o}function si(i,e,t,n,s=null,r=0,o=0){const{float32Array:a,uint16Array:c,uint32Array:u}=be;let d=i*2;if(Pe(d,c)){const p=He(i,u),m=Xe(d,c);return Ae(i,a,Lt),n(p,m,!1,o,r+i/De,Lt)}else{let I=function(N){const{uint16Array:H,uint32Array:G}=be;let $=N*2;for(;!Pe($,H);)N=ke(N),$=N*2;return He(N,G)},k=function(N){const{uint16Array:H,uint32Array:G}=be;let $=N*2;for(;!Pe($,H);)N=Be(N,G),$=N*2;return He(N,G)+Xe($,H)};const p=ke(i),m=Be(i,u);let w=p,x=m,_,v,T,S;if(s&&(T=Lt,S=nn,Ae(w,a,T),Ae(x,a,S),_=s(T),v=s(S),v<_)){w=m,x=p;const N=_;_=v,v=N,T=S}T||(T=Lt,Ae(w,a,T));const b=Pe(w*2,c),A=t(T,b,_,o+1,r+w/De);let L;if(A===Hi){const N=I(w),G=k(w)-N;L=n(N,G,!0,o+1,r+w/De,T)}else L=A&&si(w,e,t,n,s,r,o+1);if(L)return!0;S=nn,Ae(x,a,S);const P=Pe(x*2,c),C=t(S,P,v,o+1,r+x/De);let D;if(C===Hi){const N=I(x),G=k(x)-N;D=n(N,G,!0,o+1,r+x/De,S)}else D=C&&si(x,e,t,n,s,r,o+1);return!!D}}const _n=new be.constructor,gs=new be.constructor,Pt=new _i(()=>new f.Box3),Zt=new f.Box3,Kt=new f.Box3,Ds=new f.Box3,Ns=new f.Box3;let Fs=!1;function Ta(i,e,t,n){if(Fs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Fs=!0;const s=i._roots,r=e._roots;let o,a=0,c=0;const u=new f.Matrix4().copy(t).invert();for(let d=0,h=s.length;d<h;d++){_n.setBuffer(s[d]),c=0;const p=Pt.getPrimitive();Ae(0,_n.float32Array,p),p.applyMatrix4(u);for(let m=0,w=r.length;m<w&&(gs.setBuffer(r[m]),o=ht(0,0,t,u,n,a,c,0,0,p),gs.clearBuffer(),c+=r[m].byteLength/Ve,!o);m++);if(Pt.releasePrimitive(p),_n.clearBuffer(),a+=s[d].byteLength/Ve,o)break}return Fs=!1,o}function ht(i,e,t,n,s,r=0,o=0,a=0,c=0,u=null,d=!1){let h,p;d?(h=gs,p=_n):(h=_n,p=gs);const m=h.float32Array,w=h.uint32Array,x=h.uint16Array,_=p.float32Array,v=p.uint32Array,T=p.uint16Array,S=i*2,b=e*2,A=Pe(S,x),L=Pe(b,T);let P=!1;if(L&&A)d?P=s(He(e,v),Xe(e*2,T),He(i,w),Xe(i*2,x),c,o+e/De,a,r+i/De):P=s(He(i,w),Xe(i*2,x),He(e,v),Xe(e*2,T),a,r+i/De,c,o+e/De);else if(L){const C=Pt.getPrimitive();Ae(e,_,C),C.applyMatrix4(t);const D=ke(i),I=Be(i,w);Ae(D,m,Zt),Ae(I,m,Kt);const k=C.intersectsBox(Zt),N=C.intersectsBox(Kt);P=k&&ht(e,D,n,t,s,o,r,c,a+1,C,!d)||N&&ht(e,I,n,t,s,o,r,c,a+1,C,!d),Pt.releasePrimitive(C)}else{const C=ke(e),D=Be(e,v);Ae(C,_,Ds),Ae(D,_,Ns);const I=u.intersectsBox(Ds),k=u.intersectsBox(Ns);if(I&&k)P=ht(i,C,t,n,s,r,o,a,c+1,u,d)||ht(i,D,t,n,s,r,o,a,c+1,u,d);else if(I)if(A)P=ht(i,C,t,n,s,r,o,a,c+1,u,d);else{const N=Pt.getPrimitive();N.copy(Ds).applyMatrix4(t);const H=ke(i),G=Be(i,w);Ae(H,m,Zt),Ae(G,m,Kt);const $=N.intersectsBox(Zt),re=N.intersectsBox(Kt);P=$&&ht(C,H,n,t,s,o,r,c,a+1,N,!d)||re&&ht(C,G,n,t,s,o,r,c,a+1,N,!d),Pt.releasePrimitive(N)}else if(k)if(A)P=ht(i,D,t,n,s,r,o,a,c+1,u,d);else{const N=Pt.getPrimitive();N.copy(Ns).applyMatrix4(t);const H=ke(i),G=Be(i,w);Ae(H,m,Zt),Ae(G,m,Kt);const $=N.intersectsBox(Zt),re=N.intersectsBox(Kt);P=$&&ht(D,H,n,t,s,o,r,c,a+1,N,!d)||re&&ht(D,G,n,t,s,o,r,c,a+1,N,!d),Pt.releasePrimitive(N)}}return P}const Ki=new f.Box3,Xt=new Float32Array(6);class Sa{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Lr,...e},ya(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,n,s){let r=1/0,o=1/0,a=1/0,c=-1/0,u=-1/0,d=-1/0;for(let h=e,p=e+t;h<p;h++){this.writePrimitiveBounds(h,Xt,0);const[m,w,x,_,v,T]=Xt;m<r&&(r=m),_>c&&(c=_),w<o&&(o=w),v>u&&(u=v),x<a&&(a=x),T>d&&(d=T)}return n[s+0]=r,n[s+1]=o,n[s+2]=a,n[s+3]=c,n[s+4]=u,n[s+5]=d,n}computePrimitiveBounds(e,t,n){const s=n.offset||0;for(let r=e,o=e+t;r<o;r++){this.writePrimitiveBounds(r,Xt,0);const[a,c,u,d,h,p]=Xt,m=(a+d)/2,w=(c+h)/2,x=(u+p)/2,_=(d-a)/2,v=(h-c)/2,T=(p-u)/2,S=(r-s)*6;n[S+0]=m,n[S+1]=_+(Math.abs(m)+_)*ds,n[S+2]=w,n[S+3]=v+(Math.abs(w)+v)*ds,n[S+4]=x,n[S+5]=T+(Math.abs(x)+T)*ds}return n}shiftPrimitiveOffsets(e){const t=this._indirectBuffer;if(t)for(let n=0,s=t.length;n<s;n++)t[n]+=e;else{const n=this._roots;for(let s=0;s<n.length;s++){const r=n[s],o=new Uint32Array(r),a=new Uint16Array(r),c=r.byteLength/Ve;for(let u=0;u<c;u++){const d=De*u,h=2*d;Pe(h,a)&&(o[d+6]+=e)}}}}traverse(e,t=0){const n=this._roots[t],s=new Uint32Array(n),r=new Uint16Array(n);o(0);function o(a,c=0){const u=a*2,d=Pe(u,r);if(d){const h=s[a+6],p=r[u+14];e(c,d,new Float32Array(n,a*4,6),h,p)}else{const h=ke(a),p=Be(a,s),m=Ss(a,s);e(c,d,new Float32Array(n,a*4,6),m)||(o(h,c+1),o(p,c+1))}}}refit(){const e=this._roots;for(let t=0,n=e.length;t<n;t++){const s=e[t],r=new Uint32Array(s),o=new Uint16Array(s),a=new Float32Array(s),c=s.byteLength/Ve;for(let u=c-1;u>=0;u--){const d=u*De,h=d*2;if(Pe(h,o)){const m=He(d,r),w=Xe(h,o);this.writePrimitiveRangeBounds(m,w,Xt,0),a.set(Xt,d)}else{const m=ke(d),w=Be(d,r);for(let x=0;x<3;x++){const _=a[m+x],v=a[m+x+3],T=a[w+x],S=a[w+x+3];a[d+x]=_<T?_:T,a[d+x+3]=v>S?v:S}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(n=>{Ae(0,new Float32Array(n),Ki),e.union(Ki)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:s,intersectsPrimitive:r,scratchPrimitive:o,iterate:a}=e;if(s&&r){const h=s;s=(p,m,w,x,_)=>h(p,m,w,x,_)?!0:a(p,m,this,r,w,x,o)}else s||(r?s=(h,p,m,w)=>a(h,p,this,r,m,w,o):s=(h,p,m)=>m);let c=!1,u=0;const d=this._roots;for(let h=0,p=d.length;h<p;h++){const m=d[h];if(c=Ea(this,h,n,s,t,u),c)break;u+=m.byteLength/Ve}return c}bvhcast(e,t,n){let{intersectsRanges:s}=n;return Ta(this,e,t,s)}}function _a(){return typeof SharedArrayBuffer<"u"}function _s(i){return i.index?i.index.count:i.attributes.position.count}function bs(i){return _s(i)/3}function Nr(i,e=ArrayBuffer){return i>65535?new Uint32Array(new e(4*i)):new Uint16Array(new e(2*i))}function ba(i,e){if(!i.index){const t=i.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Nr(t,n);i.setIndex(new f.BufferAttribute(s,1));for(let r=0;r<t;r++)s[r]=r}}function xa(i,e,t){const n=_s(i)/t,s=e||i.drawRange,r=s.start/t,o=(s.start+s.count)/t,a=Math.max(0,r),c=Math.min(n,o)-a;return{offset:Math.floor(a),count:Math.floor(c)}}function Aa(i,e){return i.groups.map(t=>({offset:t.start/e,count:t.count/e}))}function Xi(i,e,t){const n=xa(i,e,t),s=Aa(i,t);if(!s.length)return[n];const r=[],o=n.offset,a=n.offset+n.count,c=_s(i)/t,u=[];for(const p of s){const{offset:m,count:w}=p,x=m,_=isFinite(w)?w:c-m,v=m+_;x<a&&v>o&&(u.push({pos:Math.max(o,x),isStart:!0}),u.push({pos:Math.min(a,v),isStart:!1}))}u.sort((p,m)=>p.pos!==m.pos?p.pos-m.pos:p.type==="end"?-1:1);let d=0,h=null;for(const p of u){const m=p.pos;d!==0&&m!==h&&r.push({offset:h,count:m-h}),d+=p.isStart?1:-1,h=m}return r}function va(i,e){const t=i[i.length-1],n=t.offset+t.count>2**16,s=i.reduce((u,d)=>u+d.count,0),r=n?4:2,o=e?new SharedArrayBuffer(s*r):new ArrayBuffer(s*r),a=n?new Uint32Array(o):new Uint16Array(o);let c=0;for(let u=0;u<i.length;u++){const{offset:d,count:h}=i[u];for(let p=0;p<h;p++)a[c+p]=d+p;c+=h}return a}class Ma extends Sa{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(t.useSharedArrayBuffer&&!_a())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?n=>this._indirectBuffer[n]:n=>n,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...Lr,...t},t[Si]||this.init(t)}init(e){const{geometry:t,primitiveStride:n}=this;if(e.indirect){const s=Xi(t,e.range,n),r=va(s,e.useSharedArrayBuffer);this._indirectBuffer=r}else ba(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new f.Box3))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Xi(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class xt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,s=-1/0;for(let r=0,o=e.length;r<o;r++){const c=e[r][t];n=c<n?c:n,s=c>s?c:s}this.min=n,this.max=s}setFromPoints(e,t){let n=1/0,s=-1/0;for(let r=0,o=t.length;r<o;r++){const a=t[r],c=e.dot(a);n=c<n?c:n,s=c>s?c:s}this.min=n,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}xt.prototype.setFromBox=(function(){const i=new f.Vector3;return function(t,n){const s=n.min,r=n.max;let o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let u=0;u<=1;u++)for(let d=0;d<=1;d++){i.x=s.x*c+r.x*(1-c),i.y=s.y*u+r.y*(1-u),i.z=s.z*d+r.z*(1-d);const h=t.dot(i);o=Math.min(h,o),a=Math.max(h,a)}this.min=o,this.max=a}})();const Ra=(function(){const i=new f.Vector3,e=new f.Vector3,t=new f.Vector3;return function(s,r,o){const a=s.start,c=i,u=r.start,d=e;t.subVectors(a,u),i.subVectors(s.end,s.start),e.subVectors(r.end,r.start);const h=t.dot(d),p=d.dot(c),m=d.dot(d),w=t.dot(c),_=c.dot(c)*m-p*p;let v,T;_!==0?v=(h*p-w*m)/_:v=0,T=(h+v*p)/m,o.x=v,o.y=T}})(),bi=(function(){const i=new f.Vector2,e=new f.Vector3,t=new f.Vector3;return function(s,r,o,a){Ra(s,r,i);let c=i.x,u=i.y;if(c>=0&&c<=1&&u>=0&&u<=1){s.at(c,o),r.at(u,a);return}else if(c>=0&&c<=1){u<0?r.at(0,a):r.at(1,a),s.closestPointToPoint(a,!0,o);return}else if(u>=0&&u<=1){c<0?s.at(0,o):s.at(1,o),r.closestPointToPoint(o,!0,a);return}else{let d;c<0?d=s.start:d=s.end;let h;u<0?h=r.start:h=r.end;const p=e,m=t;if(s.closestPointToPoint(h,!0,e),r.closestPointToPoint(d,!0,t),p.distanceToSquared(h)<=m.distanceToSquared(d)){o.copy(p),a.copy(h);return}else{o.copy(d),a.copy(m);return}}}})(),Ca=(function(){const i=new f.Vector3,e=new f.Vector3,t=new f.Plane,n=new f.Line3;return function(r,o){const{radius:a,center:c}=r,{a:u,b:d,c:h}=o;if(n.start=u,n.end=d,n.closestPointToPoint(c,!0,i).distanceTo(c)<=a||(n.start=u,n.end=h,n.closestPointToPoint(c,!0,i).distanceTo(c)<=a)||(n.start=d,n.end=h,n.closestPointToPoint(c,!0,i).distanceTo(c)<=a))return!0;const x=o.getPlane(t);if(Math.abs(x.distanceToPoint(c))<=a){const v=x.projectPoint(c,e);if(o.containsPoint(v))return!0}return!1}})(),Pa=["x","y","z"],bt=1e-15,Yi=bt*bt;function nt(i){return Math.abs(i)<bt}class dt extends f.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new f.Vector3),this.satBounds=new Array(4).fill().map(()=>new xt),this.points=[this.a,this.b,this.c],this.plane=new f.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new f.Line3,this.needsUpdate=!0}intersectsSphere(e){return Ca(e,this)}update(){const e=this.a,t=this.b,n=this.c,s=this.points,r=this.satAxes,o=this.satBounds,a=r[0],c=o[0];this.getNormal(a),c.setFromPoints(a,s);const u=r[1],d=o[1];u.subVectors(e,t),d.setFromPoints(u,s);const h=r[2],p=o[2];h.subVectors(t,n),p.setFromPoints(h,s);const m=r[3],w=o[3];m.subVectors(n,e),w.setFromPoints(m,s);const x=u.length(),_=h.length(),v=m.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,x<bt?_<bt||v<bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):_<bt?v<bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):v<bt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(a,e),this.needsUpdate=!1}}dt.prototype.closestPointToSegment=(function(){const i=new f.Vector3,e=new f.Vector3,t=new f.Line3;return function(s,r=null,o=null){const{start:a,end:c}=s,u=this.points;let d,h=1/0;for(let p=0;p<3;p++){const m=(p+1)%3;t.start.copy(u[p]),t.end.copy(u[m]),bi(t,s,i,e),d=i.distanceToSquared(e),d<h&&(h=d,r&&r.copy(i),o&&o.copy(e))}return this.closestPointToPoint(a,i),d=a.distanceToSquared(i),d<h&&(h=d,r&&r.copy(i),o&&o.copy(a)),this.closestPointToPoint(c,i),d=c.distanceToSquared(i),d<h&&(h=d,r&&r.copy(i),o&&o.copy(c)),Math.sqrt(h)}})();dt.prototype.intersectsTriangle=(function(){const i=new dt,e=new xt,t=new xt,n=new f.Vector3,s=new f.Vector3,r=new f.Vector3,o=new f.Vector3,a=new f.Line3,c=new f.Line3,u=new f.Vector3,d=new f.Vector2,h=new f.Vector2;function p(S,b,A,L){const P=n;!S.isDegenerateIntoPoint&&!S.isDegenerateIntoSegment?P.copy(S.plane.normal):P.copy(b.plane.normal);const C=S.satBounds,D=S.satAxes;for(let N=1;N<4;N++){const H=C[N],G=D[N];if(e.setFromPoints(G,b.points),H.isSeparated(e)||(o.copy(P).cross(G),e.setFromPoints(o,S.points),t.setFromPoints(o,b.points),e.isSeparated(t)))return!1}const I=b.satBounds,k=b.satAxes;for(let N=1;N<4;N++){const H=I[N],G=k[N];if(e.setFromPoints(G,S.points),H.isSeparated(e)||(o.crossVectors(P,G),e.setFromPoints(o,S.points),t.setFromPoints(o,b.points),e.isSeparated(t)))return!1}return A&&(L||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),A.start.set(0,0,0),A.end.set(0,0,0)),!0}function m(S,b,A,L,P,C,D,I,k,N,H){let G=D/(D-I);N.x=L+(P-L)*G,H.start.subVectors(b,S).multiplyScalar(G).add(S),G=D/(D-k),N.y=L+(C-L)*G,H.end.subVectors(A,S).multiplyScalar(G).add(S)}function w(S,b,A,L,P,C,D,I,k,N,H){if(P>0)m(S.c,S.a,S.b,L,b,A,k,D,I,N,H);else if(C>0)m(S.b,S.a,S.c,A,b,L,I,D,k,N,H);else if(I*k>0||D!=0)m(S.a,S.b,S.c,b,A,L,D,I,k,N,H);else if(I!=0)m(S.b,S.a,S.c,A,b,L,I,D,k,N,H);else if(k!=0)m(S.c,S.a,S.b,L,b,A,k,D,I,N,H);else return!0;return!1}function x(S,b,A,L){const P=b.degenerateSegment,C=S.plane.distanceToPoint(P.start),D=S.plane.distanceToPoint(P.end);return nt(C)?nt(D)?p(S,b,A,L):(A&&(A.start.copy(P.start),A.end.copy(P.start)),S.containsPoint(P.start)):nt(D)?(A&&(A.start.copy(P.end),A.end.copy(P.end)),S.containsPoint(P.end)):S.plane.intersectLine(P,n)!=null?(A&&(A.start.copy(n),A.end.copy(n)),S.containsPoint(n)):!1}function _(S,b,A){const L=b.a;return nt(S.plane.distanceToPoint(L))&&S.containsPoint(L)?(A&&(A.start.copy(L),A.end.copy(L)),!0):!1}function v(S,b,A){const L=S.degenerateSegment,P=b.a;return L.closestPointToPoint(P,!0,n),P.distanceToSquared(n)<Yi?(A&&(A.start.copy(P),A.end.copy(P)),!0):!1}function T(S,b,A,L){if(S.isDegenerateIntoSegment)if(b.isDegenerateIntoSegment){const P=S.degenerateSegment,C=b.degenerateSegment,D=s,I=r;P.delta(D),C.delta(I);const k=n.subVectors(C.start,P.start),N=D.x*I.y-D.y*I.x;if(nt(N))return!1;const H=(k.x*I.y-k.y*I.x)/N,G=-(D.x*k.y-D.y*k.x)/N;if(H<0||H>1||G<0||G>1)return!1;const $=P.start.z+D.z*H,re=C.start.z+I.z*G;return nt($-re)?(A&&(A.start.copy(P.start).addScaledVector(D,H),A.end.copy(P.start).addScaledVector(D,H)),!0):!1}else return b.isDegenerateIntoPoint?v(S,b,A):x(b,S,A,L);else{if(S.isDegenerateIntoPoint)return b.isDegenerateIntoPoint?b.a.distanceToSquared(S.a)<Yi?(A&&(A.start.copy(S.a),A.end.copy(S.a)),!0):!1:b.isDegenerateIntoSegment?v(b,S,A):_(b,S,A);if(b.isDegenerateIntoPoint)return _(S,b,A);if(b.isDegenerateIntoSegment)return x(S,b,A,L)}}return function(b,A=null,L=!1){this.needsUpdate&&this.update(),b.isExtendedTriangle?b.needsUpdate&&b.update():(i.copy(b),i.update(),b=i);const P=T(this,b,A,L);if(P!==void 0)return P;const C=this.plane,D=b.plane;let I=D.distanceToPoint(this.a),k=D.distanceToPoint(this.b),N=D.distanceToPoint(this.c);nt(I)&&(I=0),nt(k)&&(k=0),nt(N)&&(N=0);const H=I*k,G=I*N;if(H>0&&G>0)return!1;let $=C.distanceToPoint(b.a),re=C.distanceToPoint(b.b),Ne=C.distanceToPoint(b.c);nt($)&&($=0),nt(re)&&(re=0),nt(Ne)&&(Ne=0);const ot=$*re,Re=$*Ne;if(ot>0&&Re>0)return!1;s.copy(C.normal),r.copy(D.normal);const ze=s.cross(r);let je=0,ve=Math.abs(ze.x);const ye=Math.abs(ze.y);ye>ve&&(ve=ye,je=1),Math.abs(ze.z)>ve&&(je=2);const Ge=Pa[je],At=this.a[Ge],ge=this.b[Ge],at=this.c[Ge],ct=b.a[Ge],an=b.b[Ge],Ht=b.c[Ge];if(w(this,At,ge,at,H,G,I,k,N,d,a))return p(this,b,A,L);if(w(b,ct,an,Ht,ot,Re,$,re,Ne,h,c))return p(this,b,A,L);if(d.y<d.x){const St=d.y;d.y=d.x,d.x=St,u.copy(a.start),a.start.copy(a.end),a.end.copy(u)}if(h.y<h.x){const St=h.y;h.y=h.x,h.x=St,u.copy(c.start),c.start.copy(c.end),c.end.copy(u)}return d.y<h.x||h.y<d.x?!1:(A&&(h.x>d.x?A.start.copy(c.start):A.start.copy(a.start),h.y<d.y?A.end.copy(c.end):A.end.copy(a.end)),!0)}})();dt.prototype.distanceToPoint=(function(){const i=new f.Vector3;return function(t){return this.closestPointToPoint(t,i),t.distanceTo(i)}})();dt.prototype.distanceToTriangle=(function(){const i=new f.Vector3,e=new f.Vector3,t=["a","b","c"],n=new f.Line3,s=new f.Line3;return function(o,a=null,c=null){const u=a||c?n:null;if(this.intersectsTriangle(o,u,!0))return(a||c)&&(a&&u.getCenter(a),c&&u.getCenter(c)),0;let d=1/0;for(let h=0;h<3;h++){let p;const m=t[h],w=o[m];this.closestPointToPoint(w,i),p=w.distanceToSquared(i),p<d&&(d=p,a&&a.copy(i),c&&c.copy(w));const x=this[m];o.closestPointToPoint(x,i),p=x.distanceToSquared(i),p<d&&(d=p,a&&a.copy(x),c&&c.copy(i))}for(let h=0;h<3;h++){const p=t[h],m=t[(h+1)%3];n.set(this[p],this[m]);for(let w=0;w<3;w++){const x=t[w],_=t[(w+1)%3];s.set(o[x],o[_]),bi(n,s,i,e);const v=i.distanceToSquared(e);v<d&&(d=v,a&&a.copy(i),c&&c.copy(e))}}return Math.sqrt(d)}})();class Ye{constructor(e,t,n){this.isOrientedBox=!0,this.min=new f.Vector3,this.max=new f.Vector3,this.matrix=new f.Matrix4,this.invMatrix=new f.Matrix4,this.points=new Array(8).fill().map(()=>new f.Vector3),this.satAxes=new Array(3).fill().map(()=>new f.Vector3),this.satBounds=new Array(3).fill().map(()=>new xt),this.alignedSatBounds=new Array(3).fill().map(()=>new xt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}Ye.prototype.update=(function(){return function(){const e=this.matrix,t=this.min,n=this.max,s=this.points;for(let u=0;u<=1;u++)for(let d=0;d<=1;d++)for(let h=0;h<=1;h++){const p=1*u|2*d|4*h,m=s[p];m.x=u?n.x:t.x,m.y=d?n.y:t.y,m.z=h?n.z:t.z,m.applyMatrix4(e)}const r=this.satBounds,o=this.satAxes,a=s[0];for(let u=0;u<3;u++){const d=o[u],h=r[u],p=1<<u,m=s[p];d.subVectors(a,m),h.setFromPoints(d,s)}const c=this.alignedSatBounds;c[0].setFromPointsField(s,"x"),c[1].setFromPointsField(s,"y"),c[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})();Ye.prototype.intersectsBox=(function(){const i=new xt;return function(t){this.needsUpdate&&this.update();const n=t.min,s=t.max,r=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(i.min=n.x,i.max=s.x,a[0].isSeparated(i)||(i.min=n.y,i.max=s.y,a[1].isSeparated(i))||(i.min=n.z,i.max=s.z,a[2].isSeparated(i)))return!1;for(let c=0;c<3;c++){const u=o[c],d=r[c];if(i.setFromBox(u,t),d.isSeparated(i))return!1}return!0}})();Ye.prototype.intersectsTriangle=(function(){const i=new dt,e=new Array(3),t=new xt,n=new xt,s=new f.Vector3;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(i.copy(o),i.update(),o=i);const a=this.satBounds,c=this.satAxes;e[0]=o.a,e[1]=o.b,e[2]=o.c;for(let p=0;p<3;p++){const m=a[p],w=c[p];if(t.setFromPoints(w,e),m.isSeparated(t))return!1}const u=o.satBounds,d=o.satAxes,h=this.points;for(let p=0;p<3;p++){const m=u[p],w=d[p];if(t.setFromPoints(w,h),m.isSeparated(t))return!1}for(let p=0;p<3;p++){const m=c[p];for(let w=0;w<4;w++){const x=d[w];if(s.crossVectors(m,x),t.setFromPoints(s,e),n.setFromPoints(s,h),t.isSeparated(n))return!1}}return!0}})();Ye.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})();Ye.prototype.distanceToPoint=(function(){const i=new f.Vector3;return function(t){return this.closestPointToPoint(t,i),t.distanceTo(i)}})();Ye.prototype.distanceToBox=(function(){const i=["x","y","z"],e=new Array(12).fill().map(()=>new f.Line3),t=new Array(12).fill().map(()=>new f.Line3),n=new f.Vector3,s=new f.Vector3;return function(o,a=0,c=null,u=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||u)&&(o.getCenter(s),this.closestPointToPoint(s,n),o.closestPointToPoint(n,s),c&&c.copy(n),u&&u.copy(s)),0;const d=a*a,h=o.min,p=o.max,m=this.points;let w=1/0;for(let _=0;_<8;_++){const v=m[_];s.copy(v).clamp(h,p);const T=v.distanceToSquared(s);if(T<w&&(w=T,c&&c.copy(v),u&&u.copy(s),T<d))return Math.sqrt(T)}let x=0;for(let _=0;_<3;_++)for(let v=0;v<=1;v++)for(let T=0;T<=1;T++){const S=(_+1)%3,b=(_+2)%3,A=v<<S|T<<b,L=1<<_|v<<S|T<<b,P=m[A],C=m[L];e[x].set(P,C);const I=i[_],k=i[S],N=i[b],H=t[x],G=H.start,$=H.end;G[I]=h[I],G[k]=v?h[k]:p[k],G[N]=T?h[N]:p[k],$[I]=p[I],$[k]=v?h[k]:p[k],$[N]=T?h[N]:p[k],x++}for(let _=0;_<=1;_++)for(let v=0;v<=1;v++)for(let T=0;T<=1;T++){s.x=_?p.x:h.x,s.y=v?p.y:h.y,s.z=T?p.z:h.z,this.closestPointToPoint(s,n);const S=s.distanceToSquared(n);if(S<w&&(w=S,c&&c.copy(n),u&&u.copy(s),S<d))return Math.sqrt(S)}for(let _=0;_<12;_++){const v=e[_];for(let T=0;T<12;T++){const S=t[T];bi(v,S,n,s);const b=n.distanceToSquared(s);if(b<w&&(w=b,c&&c.copy(n),u&&u.copy(s),b<d))return Math.sqrt(b)}}return Math.sqrt(w)}})();class Ia extends _i{constructor(){super(()=>new dt)}}const rt=new Ia,dn=new f.Vector3,ks=new f.Vector3;function La(i,e,t={},n=0,s=1/0){const r=n*n,o=s*s;let a=1/0,c=null;if(i.shapecast({boundsTraverseOrder:d=>(dn.copy(e).clamp(d.min,d.max),dn.distanceToSquared(e)),intersectsBounds:(d,h,p)=>p<a&&p<o,intersectsTriangle:(d,h)=>{d.closestPointToPoint(e,dn);const p=e.distanceToSquared(dn);return p<a&&(ks.copy(dn),a=p,c=h),p<r}}),a===1/0)return null;const u=Math.sqrt(a);return t.point?t.point.copy(ks):t.point=ks.clone(),t.distance=u,t.faceIndex=c,t}const Wn=parseInt(f.REVISION)>=169,Oa=parseInt(f.REVISION)<=161,Ft=new f.Vector3,kt=new f.Vector3,Bt=new f.Vector3,Zn=new f.Vector2,Kn=new f.Vector2,Xn=new f.Vector2,qi=new f.Vector3,$i=new f.Vector3,Qi=new f.Vector3,pn=new f.Vector3;function Da(i,e,t,n,s,r,o,a){let c;if(r===f.BackSide?c=i.intersectTriangle(n,t,e,!0,s):c=i.intersectTriangle(e,t,n,r!==f.DoubleSide,s),c===null)return null;const u=i.origin.distanceTo(s);return u<o||u>a?null:{distance:u,point:s.clone()}}function Ji(i,e,t,n,s,r,o,a,c,u,d){Ft.fromBufferAttribute(e,r),kt.fromBufferAttribute(e,o),Bt.fromBufferAttribute(e,a);const h=Da(i,Ft,kt,Bt,pn,c,u,d);if(h){if(n){Zn.fromBufferAttribute(n,r),Kn.fromBufferAttribute(n,o),Xn.fromBufferAttribute(n,a),h.uv=new f.Vector2;const m=f.Triangle.getInterpolation(pn,Ft,kt,Bt,Zn,Kn,Xn,h.uv);Wn||(h.uv=m)}if(s){Zn.fromBufferAttribute(s,r),Kn.fromBufferAttribute(s,o),Xn.fromBufferAttribute(s,a),h.uv1=new f.Vector2;const m=f.Triangle.getInterpolation(pn,Ft,kt,Bt,Zn,Kn,Xn,h.uv1);Wn||(h.uv1=m),Oa&&(h.uv2=h.uv1)}if(t){qi.fromBufferAttribute(t,r),$i.fromBufferAttribute(t,o),Qi.fromBufferAttribute(t,a),h.normal=new f.Vector3;const m=f.Triangle.getInterpolation(pn,Ft,kt,Bt,qi,$i,Qi,h.normal);h.normal.dot(i.direction)>0&&h.normal.multiplyScalar(-1),Wn||(h.normal=m)}const p={a:r,b:o,c:a,normal:new f.Vector3,materialIndex:0};if(f.Triangle.getNormal(Ft,kt,Bt,p.normal),h.face=p,h.faceIndex=r,Wn){const m=new f.Vector3;f.Triangle.getBarycoord(pn,Ft,kt,Bt,m),h.barycoord=m}}return h}function er(i){return i&&i.isMaterial?i.side:i}function xs(i,e,t,n,s,r,o){const a=n*3;let c=a+0,u=a+1,d=a+2;const{index:h,groups:p}=i;i.index&&(c=h.getX(c),u=h.getX(u),d=h.getX(d));const{position:m,normal:w,uv:x,uv1:_}=i.attributes;if(Array.isArray(e)){const v=n*3;for(let T=0,S=p.length;T<S;T++){const{start:b,count:A,materialIndex:L}=p[T];if(v>=b&&v<b+A){const P=er(e[L]),C=Ji(t,m,w,x,_,c,u,d,P,r,o);if(C)if(C.faceIndex=n,C.face.materialIndex=L,s)s.push(C);else return C}}}else{const v=er(e),T=Ji(t,m,w,x,_,c,u,d,v,r,o);if(T)if(T.faceIndex=n,T.face.materialIndex=0,s)s.push(T);else return T}return null}function Ie(i,e,t,n){const s=i.a,r=i.b,o=i.c;let a=e,c=e+1,u=e+2;t&&(a=t.getX(a),c=t.getX(c),u=t.getX(u)),s.x=n.getX(a),s.y=n.getY(a),s.z=n.getZ(a),r.x=n.getX(c),r.y=n.getY(c),r.z=n.getZ(c),o.x=n.getX(u),o.y=n.getY(u),o.z=n.getZ(u)}function Na(i,e,t,n,s,r,o,a){const{geometry:c,_indirectBuffer:u}=i;for(let d=n,h=n+s;d<h;d++)xs(c,e,t,d,r,o,a)}function Fa(i,e,t,n,s,r,o){const{geometry:a,_indirectBuffer:c}=i;let u=1/0,d=null;for(let h=n,p=n+s;h<p;h++){let m;m=xs(a,e,t,h,null,r,o),m&&m.distance<u&&(d=m,u=m.distance)}return d}function ka(i,e,t,n,s,r,o){const{geometry:a}=t,{index:c}=a,u=a.attributes.position;for(let d=i,h=e+i;d<h;d++){let p;if(p=d,Ie(o,p*3,c,u),o.needsUpdate=!0,n(o,p,s,r))return!0}return!1}function Ba(i,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=i.geometry,n=t.index?t.index.array:null,s=t.attributes.position;let r,o,a,c,u=0;const d=i._roots;for(let p=0,m=d.length;p<m;p++)r=d[p],o=new Uint32Array(r),a=new Uint16Array(r),c=new Float32Array(r),h(0,u),u+=r.byteLength;function h(p,m,w=!1){const x=p*2;if(Pe(x,a)){const _=He(p,o),v=Xe(x,a);let T=1/0,S=1/0,b=1/0,A=-1/0,L=-1/0,P=-1/0;for(let C=3*_,D=3*(_+v);C<D;C++){let I=n[C];const k=s.getX(I),N=s.getY(I),H=s.getZ(I);k<T&&(T=k),k>A&&(A=k),N<S&&(S=N),N>L&&(L=N),H<b&&(b=H),H>P&&(P=H)}return c[p+0]!==T||c[p+1]!==S||c[p+2]!==b||c[p+3]!==A||c[p+4]!==L||c[p+5]!==P?(c[p+0]=T,c[p+1]=S,c[p+2]=b,c[p+3]=A,c[p+4]=L,c[p+5]=P,!0):!1}else{const _=ke(p),v=Be(p,o);let T=w,S=!1,b=!1;if(e){if(!T){const I=_/De+m/Ve,k=v/De+m/Ve;S=e.has(I),b=e.has(k),T=!S&&!b}}else S=!0,b=!0;const A=T||S,L=T||b;let P=!1;A&&(P=h(_,m,T));let C=!1;L&&(C=h(v,m,T));const D=P||C;if(D)for(let I=0;I<3;I++){const k=_+I,N=v+I,H=c[k],G=c[k+3],$=c[N],re=c[N+3];c[p+I]=H<$?H:$,c[p+I+3]=G>re?G:re}return D}}}function Dt(i,e,t,n,s){let r,o,a,c,u,d;const h=1/t.direction.x,p=1/t.direction.y,m=1/t.direction.z,w=t.origin.x,x=t.origin.y,_=t.origin.z;let v=e[i],T=e[i+3],S=e[i+1],b=e[i+3+1],A=e[i+2],L=e[i+3+2];return h>=0?(r=(v-w)*h,o=(T-w)*h):(r=(T-w)*h,o=(v-w)*h),p>=0?(a=(S-x)*p,c=(b-x)*p):(a=(b-x)*p,c=(S-x)*p),r>c||a>o||((a>r||isNaN(r))&&(r=a),(c<o||isNaN(o))&&(o=c),m>=0?(u=(A-_)*m,d=(L-_)*m):(u=(L-_)*m,d=(A-_)*m),r>d||u>o)?!1:((u>r||r!==r)&&(r=u),(d<o||o!==o)&&(o=d),r<=s&&o>=n)}function za(i,e,t,n,s,r,o,a){const{geometry:c,_indirectBuffer:u}=i;for(let d=n,h=n+s;d<h;d++){let p=u?u[d]:d;xs(c,e,t,p,r,o,a)}}function Ua(i,e,t,n,s,r,o){const{geometry:a,_indirectBuffer:c}=i;let u=1/0,d=null;for(let h=n,p=n+s;h<p;h++){let m;m=xs(a,e,t,c?c[h]:h,null,r,o),m&&m.distance<u&&(d=m,u=m.distance)}return d}function Va(i,e,t,n,s,r,o){const{geometry:a}=t,{index:c}=a,u=a.attributes.position;for(let d=i,h=e+i;d<h;d++){let p;if(p=t.resolveTriangleIndex(d),Ie(o,p*3,c,u),o.needsUpdate=!0,n(o,p,s,r))return!0}return!1}function Ha(i,e,t,n,s,r,o){be.setBuffer(i._roots[e]),ii(0,i,t,n,s,r,o),be.clearBuffer()}function ii(i,e,t,n,s,r,o){const{float32Array:a,uint16Array:c,uint32Array:u}=be,d=i*2;if(Pe(d,c)){const p=He(i,u),m=Xe(d,c);Na(e,t,n,p,m,s,r,o)}else{const p=ke(i);Dt(p,a,n,r,o)&&ii(p,e,t,n,s,r,o);const m=Be(i,u);Dt(m,a,n,r,o)&&ii(m,e,t,n,s,r,o)}}const ja=["x","y","z"];function Ga(i,e,t,n,s,r){be.setBuffer(i._roots[e]);const o=ri(0,i,t,n,s,r);return be.clearBuffer(),o}function ri(i,e,t,n,s,r){const{float32Array:o,uint16Array:a,uint32Array:c}=be;let u=i*2;if(Pe(u,a)){const h=He(i,c),p=Xe(u,a);return Fa(e,t,n,h,p,s,r)}else{const h=Ss(i,c),p=ja[h],w=n.direction[p]>=0;let x,_;w?(x=ke(i),_=Be(i,c)):(x=Be(i,c),_=ke(i));const T=Dt(x,o,n,s,r)?ri(x,e,t,n,s,r):null;if(T){const A=T.point[p];if(w?A<=o[_+h]:A>=o[_+h+3])return T}const b=Dt(_,o,n,s,r)?ri(_,e,t,n,s,r):null;return T&&b?T.distance<=b.distance?T:b:T||b||null}}const Yn=new f.Box3,Yt=new dt,qt=new dt,fn=new f.Matrix4,tr=new Ye,qn=new Ye;function Wa(i,e,t,n){be.setBuffer(i._roots[e]);const s=oi(0,i,t,n);return be.clearBuffer(),s}function oi(i,e,t,n,s=null){const{float32Array:r,uint16Array:o,uint32Array:a}=be;let c=i*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),tr.set(t.boundingBox.min,t.boundingBox.max,n),s=tr),Pe(c,o)){const d=e.geometry,h=d.index,p=d.attributes.position,m=t.index,w=t.attributes.position,x=He(i,a),_=Xe(c,o);if(fn.copy(n).invert(),t.boundsTree)return Ae(i,r,qn),qn.matrix.copy(fn),qn.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:T=>qn.intersectsBox(T),intersectsTriangle:T=>{T.a.applyMatrix4(n),T.b.applyMatrix4(n),T.c.applyMatrix4(n),T.needsUpdate=!0;for(let S=x*3,b=(_+x)*3;S<b;S+=3)if(Ie(qt,S,h,p),qt.needsUpdate=!0,T.intersectsTriangle(qt))return!0;return!1}});{const v=bs(t);for(let T=x*3,S=(_+x)*3;T<S;T+=3){Ie(Yt,T,h,p),Yt.a.applyMatrix4(fn),Yt.b.applyMatrix4(fn),Yt.c.applyMatrix4(fn),Yt.needsUpdate=!0;for(let b=0,A=v*3;b<A;b+=3)if(Ie(qt,b,m,w),qt.needsUpdate=!0,Yt.intersectsTriangle(qt))return!0}}}else{const d=ke(i),h=Be(i,a);return Ae(d,r,Yn),!!(s.intersectsBox(Yn)&&oi(d,e,t,n,s)||(Ae(h,r,Yn),s.intersectsBox(Yn)&&oi(h,e,t,n,s)))}}const $n=new f.Matrix4,Bs=new Ye,mn=new Ye,Za=new f.Vector3,Ka=new f.Vector3,Xa=new f.Vector3,Ya=new f.Vector3;function qa(i,e,t,n={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Bs.set(e.boundingBox.min,e.boundingBox.max,t),Bs.needsUpdate=!0;const a=i.geometry,c=a.attributes.position,u=a.index,d=e.attributes.position,h=e.index,p=rt.getPrimitive(),m=rt.getPrimitive();let w=Za,x=Ka,_=null,v=null;s&&(_=Xa,v=Ya);let T=1/0,S=null,b=null;return $n.copy(t).invert(),mn.matrix.copy($n),i.shapecast({boundsTraverseOrder:A=>Bs.distanceToBox(A),intersectsBounds:(A,L,P)=>P<T&&P<o?(L&&(mn.min.copy(A.min),mn.max.copy(A.max),mn.needsUpdate=!0),!0):!1,intersectsRange:(A,L)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:C=>mn.distanceToBox(C),intersectsBounds:(C,D,I)=>I<T&&I<o,intersectsRange:(C,D)=>{for(let I=C,k=C+D;I<k;I++){Ie(m,3*I,h,d),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let N=A,H=A+L;N<H;N++){Ie(p,3*N,u,c),p.needsUpdate=!0;const G=p.distanceToTriangle(m,w,_);if(G<T&&(x.copy(w),v&&v.copy(_),T=G,S=N,b=I),G<r)return!0}}}});{const P=bs(e);for(let C=0,D=P;C<D;C++){Ie(m,3*C,h,d),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let I=A,k=A+L;I<k;I++){Ie(p,3*I,u,c),p.needsUpdate=!0;const N=p.distanceToTriangle(m,w,_);if(N<T&&(x.copy(w),v&&v.copy(_),T=N,S=I,b=C),N<r)return!0}}}}}),rt.releasePrimitive(p),rt.releasePrimitive(m),T===1/0?null:(n.point?n.point.copy(x):n.point=x.clone(),n.distance=T,n.faceIndex=S,s&&(s.point?s.point.copy(v):s.point=v.clone(),s.point.applyMatrix4($n),x.applyMatrix4($n),s.distance=x.sub(s.point).length(),s.faceIndex=b),n)}function $a(i,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=i.geometry,n=t.index?t.index.array:null,s=t.attributes.position;let r,o,a,c,u=0;const d=i._roots;for(let p=0,m=d.length;p<m;p++)r=d[p],o=new Uint32Array(r),a=new Uint16Array(r),c=new Float32Array(r),h(0,u),u+=r.byteLength;function h(p,m,w=!1){const x=p*2;if(Pe(x,a)){const _=He(p,o),v=Xe(x,a);let T=1/0,S=1/0,b=1/0,A=-1/0,L=-1/0,P=-1/0;for(let C=_,D=_+v;C<D;C++){const I=3*i.resolveTriangleIndex(C);for(let k=0;k<3;k++){let N=I+k;N=n?n[N]:N;const H=s.getX(N),G=s.getY(N),$=s.getZ(N);H<T&&(T=H),H>A&&(A=H),G<S&&(S=G),G>L&&(L=G),$<b&&(b=$),$>P&&(P=$)}}return c[p+0]!==T||c[p+1]!==S||c[p+2]!==b||c[p+3]!==A||c[p+4]!==L||c[p+5]!==P?(c[p+0]=T,c[p+1]=S,c[p+2]=b,c[p+3]=A,c[p+4]=L,c[p+5]=P,!0):!1}else{const _=ke(p),v=Be(p,o);let T=w,S=!1,b=!1;if(e){if(!T){const I=_/De+m/Ve,k=v/De+m/Ve;S=e.has(I),b=e.has(k),T=!S&&!b}}else S=!0,b=!0;const A=T||S,L=T||b;let P=!1;A&&(P=h(_,m,T));let C=!1;L&&(C=h(v,m,T));const D=P||C;if(D)for(let I=0;I<3;I++){const k=_+I,N=v+I,H=c[k],G=c[k+3],$=c[N],re=c[N+3];c[p+I]=H<$?H:$,c[p+I+3]=G>re?G:re}return D}}}function Qa(i,e,t,n,s,r,o){be.setBuffer(i._roots[e]),ai(0,i,t,n,s,r,o),be.clearBuffer()}function ai(i,e,t,n,s,r,o){const{float32Array:a,uint16Array:c,uint32Array:u}=be,d=i*2;if(Pe(d,c)){const p=He(i,u),m=Xe(d,c);za(e,t,n,p,m,s,r,o)}else{const p=ke(i);Dt(p,a,n,r,o)&&ai(p,e,t,n,s,r,o);const m=Be(i,u);Dt(m,a,n,r,o)&&ai(m,e,t,n,s,r,o)}}const Ja=["x","y","z"];function ec(i,e,t,n,s,r){be.setBuffer(i._roots[e]);const o=ci(0,i,t,n,s,r);return be.clearBuffer(),o}function ci(i,e,t,n,s,r){const{float32Array:o,uint16Array:a,uint32Array:c}=be;let u=i*2;if(Pe(u,a)){const h=He(i,c),p=Xe(u,a);return Ua(e,t,n,h,p,s,r)}else{const h=Ss(i,c),p=Ja[h],w=n.direction[p]>=0;let x,_;w?(x=ke(i),_=Be(i,c)):(x=Be(i,c),_=ke(i));const T=Dt(x,o,n,s,r)?ci(x,e,t,n,s,r):null;if(T){const A=T.point[p];if(w?A<=o[_+h]:A>=o[_+h+3])return T}const b=Dt(_,o,n,s,r)?ci(_,e,t,n,s,r):null;return T&&b?T.distance<=b.distance?T:b:T||b||null}}const Qn=new f.Box3,$t=new dt,Qt=new dt,gn=new f.Matrix4,nr=new Ye,Jn=new Ye;function tc(i,e,t,n){be.setBuffer(i._roots[e]);const s=li(0,i,t,n);return be.clearBuffer(),s}function li(i,e,t,n,s=null){const{float32Array:r,uint16Array:o,uint32Array:a}=be;let c=i*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),nr.set(t.boundingBox.min,t.boundingBox.max,n),s=nr),Pe(c,o)){const d=e.geometry,h=d.index,p=d.attributes.position,m=t.index,w=t.attributes.position,x=He(i,a),_=Xe(c,o);if(gn.copy(n).invert(),t.boundsTree)return Ae(i,r,Jn),Jn.matrix.copy(gn),Jn.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:T=>Jn.intersectsBox(T),intersectsTriangle:T=>{T.a.applyMatrix4(n),T.b.applyMatrix4(n),T.c.applyMatrix4(n),T.needsUpdate=!0;for(let S=x,b=_+x;S<b;S++)if(Ie(Qt,3*e.resolveTriangleIndex(S),h,p),Qt.needsUpdate=!0,T.intersectsTriangle(Qt))return!0;return!1}});{const v=bs(t);for(let T=x,S=_+x;T<S;T++){const b=e.resolveTriangleIndex(T);Ie($t,3*b,h,p),$t.a.applyMatrix4(gn),$t.b.applyMatrix4(gn),$t.c.applyMatrix4(gn),$t.needsUpdate=!0;for(let A=0,L=v*3;A<L;A+=3)if(Ie(Qt,A,m,w),Qt.needsUpdate=!0,$t.intersectsTriangle(Qt))return!0}}}else{const d=ke(i),h=Be(i,a);return Ae(d,r,Qn),!!(s.intersectsBox(Qn)&&li(d,e,t,n,s)||(Ae(h,r,Qn),s.intersectsBox(Qn)&&li(h,e,t,n,s)))}}const es=new f.Matrix4,zs=new Ye,yn=new Ye,nc=new f.Vector3,sc=new f.Vector3,ic=new f.Vector3,rc=new f.Vector3;function oc(i,e,t,n={},s={},r=0,o=1/0){e.boundingBox||e.computeBoundingBox(),zs.set(e.boundingBox.min,e.boundingBox.max,t),zs.needsUpdate=!0;const a=i.geometry,c=a.attributes.position,u=a.index,d=e.attributes.position,h=e.index,p=rt.getPrimitive(),m=rt.getPrimitive();let w=nc,x=sc,_=null,v=null;s&&(_=ic,v=rc);let T=1/0,S=null,b=null;return es.copy(t).invert(),yn.matrix.copy(es),i.shapecast({boundsTraverseOrder:A=>zs.distanceToBox(A),intersectsBounds:(A,L,P)=>P<T&&P<o?(L&&(yn.min.copy(A.min),yn.max.copy(A.max),yn.needsUpdate=!0),!0):!1,intersectsRange:(A,L)=>{if(e.boundsTree){const P=e.boundsTree;return P.shapecast({boundsTraverseOrder:C=>yn.distanceToBox(C),intersectsBounds:(C,D,I)=>I<T&&I<o,intersectsRange:(C,D)=>{for(let I=C,k=C+D;I<k;I++){const N=P.resolveTriangleIndex(I);Ie(m,3*N,h,d),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let H=A,G=A+L;H<G;H++){const $=i.resolveTriangleIndex(H);Ie(p,3*$,u,c),p.needsUpdate=!0;const re=p.distanceToTriangle(m,w,_);if(re<T&&(x.copy(w),v&&v.copy(_),T=re,S=H,b=I),re<r)return!0}}}})}else{const P=bs(e);for(let C=0,D=P;C<D;C++){Ie(m,3*C,h,d),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let I=A,k=A+L;I<k;I++){const N=i.resolveTriangleIndex(I);Ie(p,3*N,u,c),p.needsUpdate=!0;const H=p.distanceToTriangle(m,w,_);if(H<T&&(x.copy(w),v&&v.copy(_),T=H,S=I,b=C),H<r)return!0}}}}}),rt.releasePrimitive(p),rt.releasePrimitive(m),T===1/0?null:(n.point?n.point.copy(x):n.point=x.clone(),n.distance=T,n.faceIndex=S,s&&(s.point?s.point.copy(v):s.point=v.clone(),s.point.applyMatrix4(es),x.applyMatrix4(es),s.distance=x.sub(s.point).length(),s.faceIndex=b),n)}function sr(i,e,t){return i===null?null:(i.point.applyMatrix4(e.matrixWorld),i.distance=i.point.distanceTo(t.ray.origin),i.object=e,i)}const ts=new Ye,ns=new f.Ray,ir=new f.Vector3,rr=new f.Matrix4,or=new f.Vector3,Us=["getX","getY","getZ"];class An extends Ma{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,s=e._roots,r=e._indirectBuffer,o=n.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(a.roots=s.map(c=>c.slice()),a.index=o?o.array.slice():null,a.indirectBuffer=r?r.slice():null):(a.roots=s,a.index=o?o.array:null,a.indirectBuffer=r),a}static deserialize(e,t,n={}){n={setIndex:!0,indirect:!!e.indirectBuffer,...n};const{index:s,roots:r,indirectBuffer:o}=e;e.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),c(r));const a=new An(t,{...n,[Si]:!0});if(a._roots=r,a._indirectBuffer=o||null,n.setIndex){const u=t.getIndex();if(u===null){const d=new f.BufferAttribute(e.index,1,!1);t.setIndex(d)}else u.array!==s&&(u.array.set(s),u.needsUpdate=!0)}return a;function c(u){for(let d=0;d<u.length;d++){const h=u[d],p=new Uint32Array(h),m=new Uint16Array(h);for(let w=0,x=h.byteLength/Ve;w<x;w++){const _=De*w,v=2*_;Pe(v,m)||(p[_+6]=p[_+6]/De-w)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),t={...t,maxLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){const s=this.geometry,r=this._indirectBuffer,o=s.attributes.position,a=s.index?s.index.array:null,u=(r?r[e]:e)*3;let d=u+0,h=u+1,p=u+2;a&&(d=a[d],h=a[h],p=a[p]);for(let m=0;m<3;m++){const w=o[Us[m]](d),x=o[Us[m]](h),_=o[Us[m]](p);let v=w;x<v&&(v=x),_<v&&(v=_);let T=w;x>T&&(T=x),_>T&&(T=_),t[n+m]=v,t[n+m+3]=T}return t}computePrimitiveBounds(e,t,n){const s=this.geometry,r=this._indirectBuffer,o=s.attributes.position,a=s.index?s.index.array:null,c=o.normalized;if(e<0||t+e-n.offset>n.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const u=o.array,d=o.offset||0;let h=3;o.isInterleavedBufferAttribute&&(h=o.data.stride);const p=["getX","getY","getZ"],m=n.offset;for(let w=e,x=e+t;w<x;w++){const v=(r?r[w]:w)*3,T=(w-m)*6;let S=v+0,b=v+1,A=v+2;a&&(S=a[S],b=a[b],A=a[A]),c||(S=S*h+d,b=b*h+d,A=A*h+d);for(let L=0;L<3;L++){let P,C,D;c?(P=o[p[L]](S),C=o[p[L]](b),D=o[p[L]](A)):(P=u[S+L],C=u[b+L],D=u[A+L]);let I=P;C<I&&(I=C),D<I&&(I=D);let k=P;C>k&&(k=C),D>k&&(k=D);const N=(k-I)/2,H=L*2;n[T+H+0]=I+N,n[T+H+1]=N+(Math.abs(I)+N)*ds}}return n}raycastObject3D(e,t,n=[]){const{material:s}=e;if(s===void 0)return;rr.copy(e.matrixWorld).invert(),ns.copy(t.ray).applyMatrix4(rr),or.setFromMatrixScale(e.matrixWorld),ir.copy(ns.direction).multiply(or);const r=ir.length(),o=t.near/r,a=t.far/r;if(t.firstHitOnly===!0){let c=this.raycastFirst(ns,s,o,a);c=sr(c,e,t),c&&n.push(c)}else{const c=this.raycast(ns,s,o,a);for(let u=0,d=c.length;u<d;u++){const h=sr(c[u],e,t);h&&n.push(h)}}return n}refit(e=null){return(this.indirect?$a:Ba)(this,e)}raycast(e,t=f.FrontSide,n=0,s=1/0){const r=this._roots,o=[],a=this.indirect?Qa:Ha;for(let c=0,u=r.length;c<u;c++)a(this,c,t,e,o,n,s);return o}raycastFirst(e,t=f.FrontSide,n=0,s=1/0){const r=this._roots;let o=null;const a=this.indirect?ec:Ga;for(let c=0,u=r.length;c<u;c++){const d=a(this,c,t,e,n,s);d!=null&&(o==null||d.distance<o.distance)&&(o=d)}return o}intersectsGeometry(e,t){let n=!1;const s=this._roots,r=this.indirect?tc:Wa;for(let o=0,a=s.length;o<a&&(n=r(this,o,e,t),!n);o++);return n}shapecast(e){const t=rt.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Va:ka});return rt.releasePrimitive(t),n}bvhcast(e,t,n){let{intersectsRanges:s,intersectsTriangles:r}=n;const o=rt.getPrimitive(),a=this.geometry.index,c=this.geometry.attributes.position,u=this.indirect?w=>{const x=this.resolveTriangleIndex(w);Ie(o,x*3,a,c)}:w=>{Ie(o,w*3,a,c)},d=rt.getPrimitive(),h=e.geometry.index,p=e.geometry.attributes.position,m=e.indirect?w=>{const x=e.resolveTriangleIndex(w);Ie(d,x*3,h,p)}:w=>{Ie(d,w*3,h,p)};if(r){if(!(e instanceof An))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const w=(x,_,v,T,S,b,A,L)=>{for(let P=v,C=v+T;P<C;P++){m(P),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let D=x,I=x+_;D<I;D++)if(u(D),o.needsUpdate=!0,r(o,d,D,P,S,b,A,L))return!0}return!1};if(s){const x=s;s=function(_,v,T,S,b,A,L,P){return x(_,v,T,S,b,A,L,P)?!0:w(_,v,T,S,b,A,L,P)}}else s=w}return super.bvhcast(e,t,{intersectsRanges:s})}intersectsBox(e,t){return ts.set(e.min,e.max,t),ts.needsUpdate=!0,this.shapecast({intersectsBounds:n=>ts.intersectsBox(n),intersectsTriangle:n=>ts.intersectsTriangle(n)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},s={},r=0,o=1/0){return(this.indirect?oc:qa)(this,e,t,n,s,r,o)}closestPointToPoint(e,t={},n=0,s=1/0){return La(this,e,t,n,s)}}const tn={Mesh:f.Mesh.prototype.raycast,Line:f.Line.prototype.raycast,LineSegments:f.LineSegments.prototype.raycast,LineLoop:f.LineLoop.prototype.raycast,Points:f.Points.prototype.raycast,BatchedMesh:f.BatchedMesh.prototype.raycast},Ue=new f.Mesh,ss=[];function ac(i,e){if(this.isBatchedMesh)cc.call(this,i,e);else{const{geometry:t}=this;if(t.boundsTree)t.boundsTree.raycastObject3D(this,i,e);else{let n;if(this instanceof f.Mesh)n=tn.Mesh;else if(this instanceof f.LineSegments)n=tn.LineSegments;else if(this instanceof f.LineLoop)n=tn.LineLoop;else if(this instanceof f.Line)n=tn.Line;else if(this instanceof f.Points)n=tn.Points;else throw new Error("BVH: Fallback raycast function not found.");n.call(this,i,e)}}}function cc(i,e){if(this.boundsTrees){const t=this.boundsTrees,n=this._drawInfo||this._instanceInfo,s=this._drawRanges||this._geometryInfo,r=this.matrixWorld;Ue.material=this.material,Ue.geometry=this.geometry;const o=Ue.geometry.boundsTree,a=Ue.geometry.drawRange;Ue.geometry.boundingSphere===null&&(Ue.geometry.boundingSphere=new f.Sphere);for(let c=0,u=n.length;c<u;c++){if(!this.getVisibleAt(c))continue;const d=n[c].geometryIndex;if(Ue.geometry.boundsTree=t[d],this.getMatrixAt(c,Ue.matrixWorld).premultiply(r),!Ue.geometry.boundsTree){this.getBoundingBoxAt(d,Ue.geometry.boundingBox),this.getBoundingSphereAt(d,Ue.geometry.boundingSphere);const h=s[d];Ue.geometry.setDrawRange(h.start,h.count)}Ue.raycast(i,ss);for(let h=0,p=ss.length;h<p;h++){const m=ss[h];m.object=this,m.batchId=c,e.push(m)}ss.length=0}Ue.geometry.boundsTree=o,Ue.geometry.drawRange=a,Ue.material=null,Ue.geometry=null}else tn.BatchedMesh.call(this,i,e)}function Fr(i){i.traverse(e=>{var s,r,o;const t=e;if(!t.isMesh||t.isSkinnedMesh||t.isInstancedMesh||t.isBatchedMesh)return;const n=t.geometry;!((s=n==null?void 0:n.attributes)!=null&&s.position)||(o=(r=n.morphAttributes)==null?void 0:r.position)!=null&&o.length||(n.boundsTree||(n.boundsTree=new An(n)),t.raycast=ac)})}function lc(i){i.boundsTree&&(i.boundsTree=void 0)}function ar(i){const e=i;for(const n of Object.keys(e)){const s=e[n];s instanceof E.Texture&&s.dispose()}const t=i;if(t.isShaderMaterial&&t.uniforms)for(const n of Object.values(t.uniforms))(n==null?void 0:n.value)instanceof E.Texture&&n.value.dispose();i.dispose()}function As(i){i.traverse(e=>{var r;const t=e;t.geometry&&typeof t.geometry.dispose=="function"&&(lc(t.geometry),t.geometry.dispose());const n=t.material;Array.isArray(n)?n.forEach(ar):n&&ar(n);const s=e;s.isLight&&((r=s.shadow)!=null&&r.dispose)&&s.shadow.dispose()})}function hc(i,e){if(!(e!=null&&e.keepBackgrounds)){i.background instanceof E.Texture&&(i.background.dispose(),i.background=null),i.environment instanceof E.Texture&&(i.environment.dispose(),i.environment=null);const t=i;t.__originalEnvironmentTexture&&(t.__originalEnvironmentTexture=void 0)}for(const t of[...i.children])As(t),i.remove(t)}class Ke{constructor(e){this.object=e,this.positionAdapter=Ot.fromThreeVector(e.position),this.rotationAdapter=Ot.fromThreeVector(e.rotation),this.scaleAdapter=Ot.fromThreeVector(e.scale)}get id(){return this.object.uuid}get name(){return this.object.name}set name(e){this.object.name=e}get visible(){return this.object.visible}set visible(e){this.object.visible=e}get castShadow(){return this.object.castShadow}set castShadow(e){this.object.castShadow=e}get receiveShadow(){return this.object.receiveShadow}set receiveShadow(e){this.object.receiveShadow=e}get position(){return this.positionAdapter}get rotation(){return this.rotationAdapter}get scale(){return this.scaleAdapter}add(e){try{return e instanceof Ke?(this.object.add(e.getThreeObject()),F.ok(void 0)):F.err(new Z("Child must be a ThreeObject3DAdapter",X.INVALID_PARAMETER))}catch(t){return F.err(new Z("Failed to add child object",X.SCENE_OPERATION_FAILED,{originalError:t}))}}remove(e){try{return e instanceof Ke?(this.object.remove(e.getThreeObject()),F.ok(void 0)):F.err(new Z("Child must be a ThreeObject3DAdapter",X.INVALID_PARAMETER))}catch(t){return F.err(new Z("Failed to remove child object",X.SCENE_OPERATION_FAILED,{originalError:t}))}}traverse(e){this.object.traverse(t=>{e(new Ke(t))})}clone(){return new Ke(this.object.clone())}dispose(){As(this.object)}getThreeObject(){return this.object}static fromThreeObject(e){return new Ke(e)}static create(){return new Ke(new E.Object3D)}}class hi{constructor(e){this.scene=e||new E.Scene}get id(){return this.scene.uuid}get name(){return this.scene.name}set name(e){this.scene.name=e}add(e){try{return e instanceof Ke?(this.scene.add(e.getThreeObject()),F.ok(void 0)):F.err(new Z("Object must be a ThreeObject3DAdapter",X.INVALID_PARAMETER))}catch(t){return F.err(new Z("Failed to add object to scene",X.SCENE_OPERATION_FAILED,{originalError:t}))}}remove(e){try{return e instanceof Ke?(this.scene.remove(e.getThreeObject()),F.ok(void 0)):F.err(new Z("Object must be a ThreeObject3DAdapter",X.INVALID_PARAMETER))}catch(t){return F.err(new Z("Failed to remove object from scene",X.SCENE_OPERATION_FAILED,{originalError:t}))}}clear(){for(;this.scene.children.length>0;)this.scene.remove(this.scene.children[0])}disposeContents(e){hc(this.scene,e)}traverse(e){this.scene.traverse(t=>{e(new Ke(t))})}get background(){return this.scene.background instanceof E.Color?new ui(this.scene.background):this.scene.background instanceof E.Texture?new is(this.scene.background):null}set background(e){e instanceof ui?this.scene.background=e.getThreeColor():e instanceof is?this.scene.background=e.getThreeTexture():this.scene.background=null}get fog(){return this.scene.fog?new cr(this.scene.fog):null}set fog(e){e instanceof cr?this.scene.fog=e.getThreeFog():this.scene.fog=null}get environment(){return this.scene.environment?new is(this.scene.environment):null}set environment(e){e instanceof is?this.scene.environment=e.getThreeTexture():this.scene.environment=null}setEnvironmentIntensity(e){this.scene.environmentIntensity=e}getInternalRenderer(){return this.scene}getThreeScene(){return this.scene}}class ui{constructor(e){this.color=e}get r(){return this.color.r}set r(e){this.color.r=e}get g(){return this.color.g}set g(e){this.color.g=e}get b(){return this.color.b}set b(e){this.color.b=e}setHex(e){this.color.setHex(e)}setRGB(e,t,n){this.color.setRGB(e,t,n)}getHex(){return this.color.getHex()}getThreeColor(){return this.color}}let is=class{constructor(e){this.texture=e}get id(){return this.texture.uuid}get image(){return this.texture.image||null}get needsUpdate(){return this.texture.needsUpdate}set needsUpdate(e){this.texture.needsUpdate=e}dispose(){this.texture.dispose()}getThreeTexture(){return this.texture}};class cr{constructor(e){this.fog=e}get color(){return new ui(this.fog.color)}get near(){return this.fog.near||0}get far(){return this.fog.far||1e3}getThreeFog(){return this.fog}}class di extends Ke{constructor(e){super(e),this.camera=e}get near(){return this.camera instanceof E.PerspectiveCamera||this.camera instanceof E.OrthographicCamera?this.camera.near:.1}set near(e){(this.camera instanceof E.PerspectiveCamera||this.camera instanceof E.OrthographicCamera)&&(this.camera.near=e)}get far(){return this.camera instanceof E.PerspectiveCamera||this.camera instanceof E.OrthographicCamera?this.camera.far:1e3}set far(e){(this.camera instanceof E.PerspectiveCamera||this.camera instanceof E.OrthographicCamera)&&(this.camera.far=e)}lookAt(e){e instanceof Ot?this.camera.lookAt(e.getThreeVector()):this.camera.lookAt(e.x,e.y,e.z)}updateProjectionMatrix(){(this.camera instanceof E.PerspectiveCamera||this.camera instanceof E.OrthographicCamera)&&this.camera.updateProjectionMatrix()}getWorldDirection(e){const t=new E.Vector3;this.camera.getWorldDirection(t),e.set(t.x,t.y,t.z)}getInternalRenderer(){return this.camera}getThreeCamera(){return this.camera}}class xi extends di{constructor(e){const t=e||new E.PerspectiveCamera;super(t),this.perspectiveCamera=t}get type(){return"perspective"}get fov(){return this.perspectiveCamera.fov}set fov(e){this.perspectiveCamera.fov=e}get aspect(){return this.perspectiveCamera.aspect}set aspect(e){this.perspectiveCamera.aspect=e}static create(e=30,t=1,n=.1,s=1e3){return new xi(new E.PerspectiveCamera(e,t,n,s))}}function uc(i){return i.bloom||i.vignette||i.filmGrain}const dc={uniforms:{tDiffuse:{value:null},intensity:{value:.05}},vertexShader:`
|
|
2
|
+
varying vec2 vUv;
|
|
3
|
+
void main() {
|
|
4
|
+
vUv = uv;
|
|
5
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
6
|
+
}
|
|
7
|
+
`,fragmentShader:`
|
|
8
|
+
uniform sampler2D tDiffuse;
|
|
9
|
+
uniform float intensity;
|
|
10
|
+
varying vec2 vUv;
|
|
11
|
+
float hash( vec2 p ) {
|
|
12
|
+
return fract( sin( dot( p, vec2( 12.9898, 78.233 ) ) ) * 43758.5453 );
|
|
13
|
+
}
|
|
14
|
+
void main() {
|
|
15
|
+
vec4 color = texture2D( tDiffuse, vUv );
|
|
16
|
+
float grain = hash( floor( gl_FragCoord.xy ) ) - 0.5;
|
|
17
|
+
gl_FragColor = vec4( color.rgb + grain * intensity, color.a );
|
|
18
|
+
}
|
|
19
|
+
`};class pc{constructor(e,t){this.modules=null,this.composer=null,this.renderPass=null,this.disposed=!1,this.loadFailed=!1,this.renderer=e,this.config=t,this.load()}async load(){try{const e=this.config.vignette||this.config.filmGrain,[t,n,s,r,o,a]=await Promise.all([Promise.resolve().then(()=>require("./EffectComposer-D2IQ0sek.cjs")),Promise.resolve().then(()=>require("./RenderPass-BVzyKWsC.cjs")),Promise.resolve().then(()=>require("./OutputPass-Dy4KNHYF.cjs")),this.config.bloom?Promise.resolve().then(()=>require("./UnrealBloomPass-Kx7djcld.cjs")):Promise.resolve(null),e?Promise.resolve().then(()=>require("./ShaderPass-BQRqK8zp.cjs")):Promise.resolve(null),this.config.vignette?Promise.resolve().then(()=>require("./VignetteShader-Drpo9YxI.cjs")):Promise.resolve(null)]);if(this.disposed)return;this.modules={EffectComposer:t.EffectComposer,RenderPass:n.RenderPass,OutputPass:s.OutputPass,UnrealBloomPass:r==null?void 0:r.UnrealBloomPass,ShaderPass:o==null?void 0:o.ShaderPass,VignetteShader:a==null?void 0:a.VignetteShader}}catch(e){this.loadFailed=!0,console.warn("Failed to load post-processing effects; falling back to the plain renderer:",e)}}isReady(){return this.modules!==null&&!this.disposed&&!this.loadFailed}render(e,t){const n=this.modules;if(n===null||this.disposed||this.loadFailed)return!1;const s=this.composer??this.build(n,e,t);return this.renderPass&&(this.renderPass.scene=e,this.renderPass.camera=t),s.render(),!0}build(e,t,n){const s=this.renderer.getDrawingBufferSize(new E.Vector2),r=new e.EffectComposer(this.renderer),o=Math.min(4,this.renderer.capabilities.maxSamples||0);o>0&&(r.renderTarget1.samples=o,r.renderTarget2.samples=o);const a=new e.RenderPass(t,n);if(this.renderPass=a,r.addPass(a),this.config.bloom&&e.UnrealBloomPass&&r.addPass(new e.UnrealBloomPass(new E.Vector2(s.x,s.y),.18,.25,1)),r.addPass(new e.OutputPass),this.config.vignette&&e.ShaderPass&&e.VignetteShader){const c=new e.ShaderPass(e.VignetteShader);c.uniforms.offset.value=1.15,c.uniforms.darkness.value=1.05,r.addPass(c)}return this.config.filmGrain&&e.ShaderPass&&r.addPass(new e.ShaderPass(dc)),this.composer=r,r}setSize(e,t){var n;(n=this.composer)==null||n.setSize(e,t)}setPixelRatio(e){var t,n;(n=(t=this.composer)==null?void 0:t.setPixelRatio)==null||n.call(t,e)}dispose(){var e,t;this.disposed=!0,(t=(e=this.composer)==null?void 0:e.dispose)==null||t.call(e),this.composer=null,this.renderPass=null,this.modules=null}}class fc{constructor(e){this.renderer=null,this._id=Cr(),this.postPipeline=null,this.canvas=e}get id(){return this._id}initialize(e){var t,n,s,r,o,a;try{if(this.renderer=new E.WebGLRenderer({canvas:this.canvas,antialias:e.antialias??!0,alpha:e.alpha??!1,premultipliedAlpha:e.premultipliedAlpha??!0,preserveDrawingBuffer:e.preserveDrawingBuffer??!1,powerPreference:e.powerPreference??"default"}),e.shadowMap&&(this.renderer.shadowMap.enabled=e.shadowMap.enabled,this.renderer.shadowMap.autoUpdate=!0,e.shadowMap.type)){const d={basic:E.BasicShadowMap,pcf:E.PCFShadowMap,pcfsoft:E.PCFSoftShadowMap,vsm:E.VSMShadowMap};this.renderer.shadowMap.type=d[e.shadowMap.type]}if(e.toneMapping){const d={none:E.NoToneMapping,linear:E.LinearToneMapping,reinhard:E.ReinhardToneMapping,cineon:E.CineonToneMapping,aces:E.ACESFilmicToneMapping,agx:E.AgXToneMapping,neutral:E.NeutralToneMapping};this.renderer.toneMapping=d[e.toneMapping.type],this.renderer.toneMappingExposure=e.toneMapping.exposure}const c=uc({bloom:((t=e.postProcessing)==null?void 0:t.bloom)??!1,vignette:((n=e.postProcessing)==null?void 0:n.vignette)??!1,filmGrain:((s=e.postProcessing)==null?void 0:s.filmGrain)??!1}),u=e.pixelRatio??window.devicePixelRatio;if(this.renderer.setPixelRatio(c?Math.min(u,2):u),this.canvas){const{clientWidth:d,clientHeight:h}=this.canvas.parentElement||this.canvas;d&&h&&this.renderer.setSize(d,h)}return this.renderer.outputColorSpace=E.SRGBColorSpace,c&&(this.postPipeline=new pc(this.renderer,{bloom:((r=e.postProcessing)==null?void 0:r.bloom)??!1,vignette:((o=e.postProcessing)==null?void 0:o.vignette)??!1,filmGrain:((a=e.postProcessing)==null?void 0:a.filmGrain)??!1})),F.ok(void 0)}catch(c){return F.err(new Z("Failed to initialize renderer",X.RENDERER_INIT_FAILED,{originalError:c,options:e}))}}render(e,t){if(!this.renderer)return F.err(new Z("Renderer not initialized",X.RENDERER_NOT_INITIALIZED));try{if(!(e instanceof hi))return F.err(new Z("Scene must be a ThreeSceneAdapter",X.INVALID_PARAMETER));if(!(t instanceof di))return F.err(new Z("Camera must be a ThreeCameraAdapter",X.INVALID_PARAMETER));const n=e.getThreeScene(),s=t.getThreeCamera();return this.renderer.render(n,s),F.ok(void 0)}catch(n){return F.err(new Z("Failed to render frame",X.RENDER_FAILED,{originalError:n}))}}renderPostProcessed(e,t){if(!this.postPipeline||!this.renderer||!(e instanceof hi)||!(t instanceof di))return this.render(e,t);try{return this.postPipeline.render(e.getThreeScene(),t.getThreeCamera())?F.ok(void 0):this.render(e,t)}catch(n){return F.err(new Z("Failed to render frame with post-processing",X.RENDER_FAILED,{originalError:n}))}}setSize(e,t){var n;if(this.renderer){this.renderer.setSize(e,t,!1),(n=this.postPipeline)==null||n.setSize(e,t);const s=this.renderer.domElement;s.style.width="100%",s.style.height="100%"}}setPixelRatio(e){var t;this.renderer&&(this.renderer.setPixelRatio(e),(t=this.postPipeline)==null||t.setPixelRatio(e))}getPixelRatio(){return this.renderer?this.renderer.getPixelRatio():1}setToneMappingExposure(e){this.renderer&&(this.renderer.toneMappingExposure=e)}getDomElement(){if(!this.renderer)throw new Error("Renderer not initialized");return this.renderer.domElement}getContext(){if(!this.renderer)throw new Error("Renderer not initialized");return this.renderer.getContext()}get capabilities(){if(!this.renderer)return{maxTextureSize:0,maxCubemapSize:0,maxAttributes:0,maxVertexUniforms:0,maxFragmentUniforms:0,maxSamples:0,isWebGL2:!1};const e=this.renderer.capabilities;return{maxTextureSize:e.maxTextureSize,maxCubemapSize:e.maxCubemapSize,maxAttributes:e.maxAttributes,maxVertexUniforms:e.maxVertexUniforms,maxFragmentUniforms:e.maxFragmentUniforms,maxSamples:e.maxSamples||0,isWebGL2:e.isWebGL2}}dispose(){var e;(e=this.postPipeline)==null||e.dispose(),this.postPipeline=null,this.renderer&&(this.renderer.dispose(),this.renderer=null)}isDisposed(){return this.renderer===null}getInternalRenderer(){return this.renderer}getThreeRenderer(){return this.getInternalRenderer()}}function lr(i,e){if(e===f.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),i;if(e===f.TriangleFanDrawMode||e===f.TriangleStripDrawMode){let t=i.getIndex();if(t===null){const o=[],a=i.getAttribute("position");if(a!==void 0){for(let c=0;c<a.count;c++)o.push(c);i.setIndex(o),t=i.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),i}const n=t.count-2,s=[];if(e===f.TriangleFanDrawMode)for(let o=1;o<=n;o++)s.push(t.getX(0)),s.push(t.getX(o)),s.push(t.getX(o+1));else for(let o=0;o<n;o++)o%2===0?(s.push(t.getX(o)),s.push(t.getX(o+1)),s.push(t.getX(o+2))):(s.push(t.getX(o+2)),s.push(t.getX(o+1)),s.push(t.getX(o)));s.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const r=i.clone();return r.setIndex(s),r.clearGroups(),r}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),i}function mc(i){const e=new Map,t=new Map,n=i.clone();return kr(i,n,function(s,r){e.set(r,s),t.set(s,r)}),n.traverse(function(s){if(!s.isSkinnedMesh)return;const r=s,o=e.get(s),a=o.skeleton.bones;r.skeleton=o.skeleton.clone(),r.bindMatrix.copy(o.bindMatrix),r.skeleton.bones=a.map(function(c){return t.get(c)}),r.bind(r.skeleton,r.bindMatrix)}),n}function kr(i,e,t){t(i,e);for(let n=0;n<i.children.length;n++)kr(i.children[n],e.children[n],t)}class gc extends f.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Sc(t)}),this.register(function(t){return new _c(t)}),this.register(function(t){return new Ic(t)}),this.register(function(t){return new Lc(t)}),this.register(function(t){return new Oc(t)}),this.register(function(t){return new xc(t)}),this.register(function(t){return new Ac(t)}),this.register(function(t){return new vc(t)}),this.register(function(t){return new Mc(t)}),this.register(function(t){return new Tc(t)}),this.register(function(t){return new Rc(t)}),this.register(function(t){return new bc(t)}),this.register(function(t){return new Pc(t)}),this.register(function(t){return new Cc(t)}),this.register(function(t){return new wc(t)}),this.register(function(t){return new hr(t,le.EXT_MESHOPT_COMPRESSION)}),this.register(function(t){return new hr(t,le.KHR_MESHOPT_COMPRESSION)}),this.register(function(t){return new Dc(t)})}load(e,t,n,s){const r=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const u=f.LoaderUtils.extractUrlBase(e);o=f.LoaderUtils.resolveURL(u,this.path)}else o=f.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=function(u){s?s(u):console.error(u),r.manager.itemError(e),r.manager.itemEnd(e)},c=new f.FileLoader(this.manager);c.setPath(this.path),c.setResponseType("arraybuffer"),c.setRequestHeader(this.requestHeader),c.setWithCredentials(this.withCredentials),c.load(e,function(u){try{r.parse(u,o,function(d){t(d),r.manager.itemEnd(e)},a)}catch(d){a(d)}},n,a)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,s){let r;const o={},a={},c=new TextDecoder;if(typeof e=="string")r=JSON.parse(e);else if(e instanceof ArrayBuffer)if(c.decode(new Uint8Array(e,0,4))===Br){try{o[le.KHR_BINARY_GLTF]=new Nc(e)}catch(h){s&&s(h);return}r=JSON.parse(o[le.KHR_BINARY_GLTF].content)}else r=JSON.parse(c.decode(e));else r=e;if(r.asset===void 0||r.asset.version[0]<2){s&&s(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const u=new Xc(r,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});u.fileLoader.setRequestHeader(this.requestHeader);for(let d=0;d<this.pluginCallbacks.length;d++){const h=this.pluginCallbacks[d](u);h.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[h.name]=h,o[h.name]=!0}if(r.extensionsUsed)for(let d=0;d<r.extensionsUsed.length;++d){const h=r.extensionsUsed[d],p=r.extensionsRequired||[];switch(h){case le.KHR_MATERIALS_UNLIT:o[h]=new Ec;break;case le.KHR_DRACO_MESH_COMPRESSION:o[h]=new Fc(r,this.dracoLoader);break;case le.KHR_TEXTURE_TRANSFORM:o[h]=new kc;break;case le.KHR_MESH_QUANTIZATION:o[h]=new Bc;break;default:p.indexOf(h)>=0&&a[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}u.setExtensions(o),u.setPlugins(a),u.parse(n,s)}parseAsync(e,t){const n=this;return new Promise(function(s,r){n.parse(e,t,s,r)})}}function yc(){let i={};return{get:function(e){return i[e]},add:function(e,t){i[e]=t},remove:function(e){delete i[e]},removeAll:function(){i={}}}}function Me(i,e,t){const n=i.json.materials[e];return n.extensions&&n.extensions[t]?n.extensions[t]:null}const le={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class wc{constructor(e){this.parser=e,this.name=le.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let n=0,s=t.length;n<s;n++){const r=t[n];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){const t=this.parser,n="light:"+e;let s=t.cache.get(n);if(s)return s;const r=t.json,c=((r.extensions&&r.extensions[this.name]||{}).lights||[])[e];let u;const d=new f.Color(16777215);c.color!==void 0&&d.setRGB(c.color[0],c.color[1],c.color[2],f.LinearSRGBColorSpace);const h=c.range!==void 0?c.range:0;switch(c.type){case"directional":u=new f.DirectionalLight(d),u.target.position.set(0,0,-1),u.add(u.target);break;case"point":u=new f.PointLight(d),u.distance=h;break;case"spot":u=new f.SpotLight(d),u.distance=h,c.spot=c.spot||{},c.spot.innerConeAngle=c.spot.innerConeAngle!==void 0?c.spot.innerConeAngle:0,c.spot.outerConeAngle=c.spot.outerConeAngle!==void 0?c.spot.outerConeAngle:Math.PI/4,u.angle=c.spot.outerConeAngle,u.penumbra=1-c.spot.innerConeAngle/c.spot.outerConeAngle,u.target.position.set(0,0,-1),u.add(u.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+c.type)}return u.position.set(0,0,0),yt(u,c),c.intensity!==void 0&&(u.intensity=c.intensity),u.name=t.createUniqueName(c.name||"light_"+e),s=Promise.resolve(u),t.cache.add(n,s),s}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,n=this.parser,r=n.json.nodes[e],a=(r.extensions&&r.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(c){return n._getNodeRef(t.cache,a,c)})}}class Ec{constructor(){this.name=le.KHR_MATERIALS_UNLIT}getMaterialType(){return f.MeshBasicMaterial}extendParams(e,t,n){const s=[];e.color=new f.Color(1,1,1),e.opacity=1;const r=t.pbrMetallicRoughness;if(r){if(Array.isArray(r.baseColorFactor)){const o=r.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],f.LinearSRGBColorSpace),e.opacity=o[3]}r.baseColorTexture!==void 0&&s.push(n.assignTexture(e,"map",r.baseColorTexture,f.SRGBColorSpace))}return Promise.all(s)}}class Tc{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}}class Sc{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&s.push(this.parser.assignTexture(t,"clearcoatMap",n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&s.push(this.parser.assignTexture(t,"clearcoatRoughnessMap",n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(s.push(this.parser.assignTexture(t,"clearcoatNormalMap",n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){const r=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new f.Vector2(r,r)}return Promise.all(s)}}class _c{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_DISPERSION}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion!==void 0?n.dispersion:0),Promise.resolve()}}class bc{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&s.push(this.parser.assignTexture(t,"iridescenceMap",n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&s.push(this.parser.assignTexture(t,"iridescenceThicknessMap",n.iridescenceThicknessTexture)),Promise.all(s)}}class xc{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_SHEEN}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];if(t.sheenColor=new f.Color(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){const r=n.sheenColorFactor;t.sheenColor.setRGB(r[0],r[1],r[2],f.LinearSRGBColorSpace)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&s.push(this.parser.assignTexture(t,"sheenColorMap",n.sheenColorTexture,f.SRGBColorSpace)),n.sheenRoughnessTexture!==void 0&&s.push(this.parser.assignTexture(t,"sheenRoughnessMap",n.sheenRoughnessTexture)),Promise.all(s)}}class Ac{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&s.push(this.parser.assignTexture(t,"transmissionMap",n.transmissionTexture)),Promise.all(s)}}class vc{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_VOLUME}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];t.thickness=n.thicknessFactor!==void 0?n.thicknessFactor:0,n.thicknessTexture!==void 0&&s.push(this.parser.assignTexture(t,"thicknessMap",n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;const r=n.attenuationColor||[1,1,1];return t.attenuationColor=new f.Color().setRGB(r[0],r[1],r[2],f.LinearSRGBColorSpace),Promise.all(s)}}class Mc{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_IOR}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);return n===null||(t.ior=n.ior!==void 0?n.ior:1.5,t.ior===0&&(t.ior=1e3)),Promise.resolve()}}class Rc{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_SPECULAR}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];t.specularIntensity=n.specularFactor!==void 0?n.specularFactor:1,n.specularTexture!==void 0&&s.push(this.parser.assignTexture(t,"specularIntensityMap",n.specularTexture));const r=n.specularColorFactor||[1,1,1];return t.specularColor=new f.Color().setRGB(r[0],r[1],r[2],f.LinearSRGBColorSpace),n.specularColorTexture!==void 0&&s.push(this.parser.assignTexture(t,"specularColorMap",n.specularColorTexture,f.SRGBColorSpace)),Promise.all(s)}}class Cc{constructor(e){this.parser=e,this.name=le.EXT_MATERIALS_BUMP}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];return t.bumpScale=n.bumpFactor!==void 0?n.bumpFactor:1,n.bumpTexture!==void 0&&s.push(this.parser.assignTexture(t,"bumpMap",n.bumpTexture)),Promise.all(s)}}class Pc{constructor(e){this.parser=e,this.name=le.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return Me(this.parser,e,this.name)!==null?f.MeshPhysicalMaterial:null}extendMaterialParams(e,t){const n=Me(this.parser,e,this.name);if(n===null)return Promise.resolve();const s=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&s.push(this.parser.assignTexture(t,"anisotropyMap",n.anisotropyTexture)),Promise.all(s)}}class Ic{constructor(e){this.parser=e,this.name=le.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,n=t.json,s=n.textures[e];if(!s.extensions||!s.extensions[this.name])return null;const r=s.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,r.source,o)}}class Lc{constructor(e){this.parser=e,this.name=le.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,n=this.parser,s=n.json,r=s.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],a=s.images[o.source];let c=n.textureLoader;if(a.uri){const u=n.options.manager.getHandler(a.uri);u!==null&&(c=u)}return n.loadTextureImage(e,o.source,c)}}class Oc{constructor(e){this.parser=e,this.name=le.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,n=this.parser,s=n.json,r=s.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],a=s.images[o.source];let c=n.textureLoader;if(a.uri){const u=n.options.manager.getHandler(a.uri);u!==null&&(c=u)}return n.loadTextureImage(e,o.source,c)}}class hr{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){const t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){const s=n.extensions[this.name],r=this.parser.getDependency("buffer",s.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return r.then(function(a){const c=s.byteOffset||0,u=s.byteLength||0,d=s.count,h=s.byteStride,p=new Uint8Array(a,c,u);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(d,h,p,s.mode,s.filter).then(function(m){return m.buffer}):o.ready.then(function(){const m=new ArrayBuffer(d*h);return o.decodeGltfBuffer(new Uint8Array(m),d,h,p,s.mode,s.filter),m})})}else return null}}class Dc{constructor(e){this.name=le.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;const s=t.meshes[n.mesh];for(const u of s.primitives)if(u.mode!==st.TRIANGLES&&u.mode!==st.TRIANGLE_STRIP&&u.mode!==st.TRIANGLE_FAN&&u.mode!==void 0)return null;const o=n.extensions[this.name].attributes,a=[],c={};for(const u in o)a.push(this.parser.getDependency("accessor",o[u]).then(d=>(c[u]=d,c[u])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(u=>{const d=u.pop(),h=d.isGroup?d.children:[d],p=u[0].count,m=[];for(const w of h){const x=new f.Matrix4,_=new f.Vector3,v=new f.Quaternion,T=new f.Vector3(1,1,1),S=new f.InstancedMesh(w.geometry,w.material,p);for(let b=0;b<p;b++)c.TRANSLATION&&_.fromBufferAttribute(c.TRANSLATION,b),c.ROTATION&&v.fromBufferAttribute(c.ROTATION,b),c.SCALE&&T.fromBufferAttribute(c.SCALE,b),S.setMatrixAt(b,x.compose(_,v,T));for(const b in c)if(b==="_COLOR_0"){const A=c[b];S.instanceColor=new f.InstancedBufferAttribute(A.array,A.itemSize,A.normalized)}else b!=="TRANSLATION"&&b!=="ROTATION"&&b!=="SCALE"&&w.geometry.setAttribute(b,c[b]);f.Object3D.prototype.copy.call(S,w),this.parser.assignFinalMaterial(S),m.push(S)}return d.isGroup?(d.clear(),d.add(...m),d):m[0]}))}}const Br="glTF",wn=12,ur={JSON:1313821514,BIN:5130562};class Nc{constructor(e){this.name=le.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,wn),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==Br)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const s=this.header.length-wn,r=new DataView(e,wn);let o=0;for(;o<s;){const a=r.getUint32(o,!0);o+=4;const c=r.getUint32(o,!0);if(o+=4,c===ur.JSON){const u=new Uint8Array(e,wn+o,a);this.content=n.decode(u)}else if(c===ur.BIN){const u=wn+o;this.body=e.slice(u,u+a)}o+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Fc{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=le.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const n=this.json,s=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},c={},u={};for(const d in o){const h=pi[d]||d.toLowerCase();a[h]=o[d]}for(const d in e.attributes){const h=pi[d]||d.toLowerCase();if(o[d]!==void 0){const p=n.accessors[e.attributes[d]],m=rn[p.componentType];u[h]=m.name,c[h]=p.normalized===!0}}return t.getDependency("bufferView",r).then(function(d){return new Promise(function(h,p){s.decodeDracoFile(d,function(m){for(const w in m.attributes){const x=m.attributes[w],_=c[w];_!==void 0&&(x.normalized=_)}h(m)},a,u,f.LinearSRGBColorSpace,p)})})}}class kc{constructor(){this.name=le.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class Bc{constructor(){this.name=le.KHR_MESH_QUANTIZATION}}class zr extends f.Interpolant{constructor(e,t,n,s){super(e,t,n,s)}copySampleValue_(e){const t=this.resultBuffer,n=this.sampleValues,s=this.valueSize,r=e*s*3+s;for(let o=0;o!==s;o++)t[o]=n[r+o];return t}interpolate_(e,t,n,s){const r=this.resultBuffer,o=this.sampleValues,a=this.valueSize,c=a*2,u=a*3,d=s-t,h=(n-t)/d,p=h*h,m=p*h,w=e*u,x=w-u,_=-2*m+3*p,v=m-p,T=1-_,S=v-p+h;for(let b=0;b!==a;b++){const A=o[x+b+a],L=o[x+b+c]*d,P=o[w+b+a],C=o[w+b]*d;r[b]=T*A+S*L+_*P+v*C}return r}}const zc=new f.Quaternion;class Uc extends zr{interpolate_(e,t,n,s){const r=super.interpolate_(e,t,n,s);return zc.fromArray(r).normalize().toArray(r),r}}const st={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},rn={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},dr={9728:f.NearestFilter,9729:f.LinearFilter,9984:f.NearestMipmapNearestFilter,9985:f.LinearMipmapNearestFilter,9986:f.NearestMipmapLinearFilter,9987:f.LinearMipmapLinearFilter},pr={33071:f.ClampToEdgeWrapping,33648:f.MirroredRepeatWrapping,10497:f.RepeatWrapping},Vs={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},pi={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},Rt={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Vc={CUBICSPLINE:void 0,LINEAR:f.InterpolateLinear,STEP:f.InterpolateDiscrete},Hs={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function Hc(i){return i.DefaultMaterial===void 0&&(i.DefaultMaterial=new f.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:f.FrontSide})),i.DefaultMaterial}function zt(i,e,t){for(const n in t.extensions)i[n]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[n]=t.extensions[n])}function yt(i,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(i.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function jc(i,e,t){let n=!1,s=!1,r=!1;for(let u=0,d=e.length;u<d;u++){const h=e[u];if(h.POSITION!==void 0&&(n=!0),h.NORMAL!==void 0&&(s=!0),h.COLOR_0!==void 0&&(r=!0),n&&s&&r)break}if(!n&&!s&&!r)return Promise.resolve(i);const o=[],a=[],c=[];for(let u=0,d=e.length;u<d;u++){const h=e[u];if(n){const p=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):i.attributes.position;o.push(p)}if(s){const p=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):i.attributes.normal;a.push(p)}if(r){const p=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):i.attributes.color;c.push(p)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(c)]).then(function(u){const d=u[0],h=u[1],p=u[2];return n&&(i.morphAttributes.position=d),s&&(i.morphAttributes.normal=h),r&&(i.morphAttributes.color=p),i.morphTargetsRelative=!0,i})}function Gc(i,e){if(i.updateMorphTargets(),e.weights!==void 0)for(let t=0,n=e.weights.length;t<n;t++)i.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(i.morphTargetInfluences.length===t.length){i.morphTargetDictionary={};for(let n=0,s=t.length;n<s;n++)i.morphTargetDictionary[t[n]]=n}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function Wc(i){let e;const t=i.extensions&&i.extensions[le.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+js(t.attributes):e=i.indices+":"+js(i.attributes)+":"+i.mode,i.targets!==void 0)for(let n=0,s=i.targets.length;n<s;n++)e+=":"+js(i.targets[n]);return e}function js(i){let e="";const t=Object.keys(i).sort();for(let n=0,s=t.length;n<s;n++)e+=t[n]+":"+i[t[n]]+";";return e}function fi(i){switch(i){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function Zc(i){return i.search(/\.jpe?g($|\?)/i)>0||i.search(/^data\:image\/jpeg/)===0?"image/jpeg":i.search(/\.webp($|\?)/i)>0||i.search(/^data\:image\/webp/)===0?"image/webp":i.search(/\.ktx2($|\?)/i)>0||i.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const Kc=new f.Matrix4;class Xc{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new yc,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,s=-1,r=!1,o=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){const a=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(a)===!0;const c=a.match(/Version\/(\d+)/);s=n&&c?parseInt(c[1],10):-1,r=a.indexOf("Firefox")>-1,o=r?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&s<17||r&&o<98?this.textureLoader=new f.TextureLoader(this.options.manager):this.textureLoader=new f.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new f.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const n=this,s=this.json,r=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(o){const a={scene:o[0][s.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:s.asset,parser:n,userData:{}};return zt(r,a,s),yt(a,s),Promise.all(n._invokeAll(function(c){return c.afterRoot&&c.afterRoot(a)})).then(function(){for(const c of a.scenes)c.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let s=0,r=t.length;s<r;s++){const o=t[s].joints;for(let a=0,c=o.length;a<c;a++)e[o[a]].isBone=!0}for(let s=0,r=e.length;s<r;s++){const o=e[s];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(n[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;const s=n.clone(),r=(o,a)=>{const c=this.associations.get(o);c!=null&&this.associations.set(a,c);for(const[u,d]of o.children.entries())r(d,a.children[u])};return r(n,s),s.name+="_instance_"+e.uses[t]++,s}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){const s=e(t[n]);if(s)return s}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const n=[];for(let s=0;s<t.length;s++){const r=e(t[s]);r&&n.push(r)}return n}getDependency(e,t){const n=e+":"+t;let s=this.cache.get(n);if(!s){switch(e){case"scene":s=this.loadScene(t);break;case"node":s=this._invokeOne(function(r){return r.loadNode&&r.loadNode(t)});break;case"mesh":s=this._invokeOne(function(r){return r.loadMesh&&r.loadMesh(t)});break;case"accessor":s=this.loadAccessor(t);break;case"bufferView":s=this._invokeOne(function(r){return r.loadBufferView&&r.loadBufferView(t)});break;case"buffer":s=this.loadBuffer(t);break;case"material":s=this._invokeOne(function(r){return r.loadMaterial&&r.loadMaterial(t)});break;case"texture":s=this._invokeOne(function(r){return r.loadTexture&&r.loadTexture(t)});break;case"skin":s=this.loadSkin(t);break;case"animation":s=this._invokeOne(function(r){return r.loadAnimation&&r.loadAnimation(t)});break;case"camera":s=this.loadCamera(t);break;default:if(s=this._invokeOne(function(r){return r!=this&&r.getDependency&&r.getDependency(e,t)}),!s)throw new Error("Unknown type: "+e);break}this.cache.add(n,s)}return s}getDependencies(e){let t=this.cache.get(e);if(!t){const n=this,s=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(s.map(function(r,o){return n.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[le.KHR_BINARY_GLTF].body);const s=this.options;return new Promise(function(r,o){n.load(f.LoaderUtils.resolveURL(t.uri,s.path),r,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(n){const s=t.byteLength||0,r=t.byteOffset||0;return n.slice(r,r+s)})}loadAccessor(e){const t=this,n=this.json,s=this.json.accessors[e];if(s.bufferView===void 0&&s.sparse===void 0){const o=Vs[s.type],a=rn[s.componentType],c=s.normalized===!0,u=new a(s.count*o);return Promise.resolve(new f.BufferAttribute(u,o,c))}const r=[];return s.bufferView!==void 0?r.push(this.getDependency("bufferView",s.bufferView)):r.push(null),s.sparse!==void 0&&(r.push(this.getDependency("bufferView",s.sparse.indices.bufferView)),r.push(this.getDependency("bufferView",s.sparse.values.bufferView))),Promise.all(r).then(function(o){const a=o[0],c=Vs[s.type],u=rn[s.componentType],d=u.BYTES_PER_ELEMENT,h=d*c,p=s.byteOffset||0,m=s.bufferView!==void 0?n.bufferViews[s.bufferView].byteStride:void 0,w=s.normalized===!0;let x,_;if(m&&m!==h){const v=Math.floor(p/m),T="InterleavedBuffer:"+s.bufferView+":"+s.componentType+":"+v+":"+s.count;let S=t.cache.get(T);S||(x=new u(a,v*m,s.count*m/d),S=new f.InterleavedBuffer(x,m/d),t.cache.add(T,S)),_=new f.InterleavedBufferAttribute(S,c,p%m/d,w)}else a===null?x=new u(s.count*c):x=new u(a,p,s.count*c),_=new f.BufferAttribute(x,c,w);if(s.sparse!==void 0){const v=Vs.SCALAR,T=rn[s.sparse.indices.componentType],S=s.sparse.indices.byteOffset||0,b=s.sparse.values.byteOffset||0,A=new T(o[1],S,s.sparse.count*v),L=new u(o[2],b,s.sparse.count*c);a!==null&&(_=new f.BufferAttribute(_.array.slice(),_.itemSize,_.normalized)),_.normalized=!1;for(let P=0,C=A.length;P<C;P++){const D=A[P];if(_.setX(D,L[P*c]),c>=2&&_.setY(D,L[P*c+1]),c>=3&&_.setZ(D,L[P*c+2]),c>=4&&_.setW(D,L[P*c+3]),c>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}_.normalized=w}return _})}loadTexture(e){const t=this.json,n=this.options,r=t.textures[e].source,o=t.images[r];let a=this.textureLoader;if(o.uri){const c=n.manager.getHandler(o.uri);c!==null&&(a=c)}return this.loadTextureImage(e,r,a)}loadTextureImage(e,t,n){const s=this,r=this.json,o=r.textures[e],a=r.images[t],c=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[c])return this.textureCache[c];const u=this.loadImageSource(t,n).then(function(d){d.flipY=!1,d.name=o.name||a.name||"",d.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(d.name=a.uri);const p=(r.samplers||{})[o.sampler]||{};return d.magFilter=dr[p.magFilter]||f.LinearFilter,d.minFilter=dr[p.minFilter]||f.LinearMipmapLinearFilter,d.wrapS=pr[p.wrapS]||f.RepeatWrapping,d.wrapT=pr[p.wrapT]||f.RepeatWrapping,d.generateMipmaps=!d.isCompressedTexture&&d.minFilter!==f.NearestFilter&&d.minFilter!==f.LinearFilter,s.associations.set(d,{textures:e}),d}).catch(function(){return null});return this.textureCache[c]=u,u}loadImageSource(e,t){const n=this,s=this.json,r=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(h=>h.clone());const o=s.images[e],a=self.URL||self.webkitURL;let c=o.uri||"",u=!1;if(o.bufferView!==void 0)c=n.getDependency("bufferView",o.bufferView).then(function(h){u=!0;const p=new Blob([h],{type:o.mimeType});return c=a.createObjectURL(p),c});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const d=Promise.resolve(c).then(function(h){return new Promise(function(p,m){let w=p;t.isImageBitmapLoader===!0&&(w=function(x){const _=new f.Texture(x);_.needsUpdate=!0,p(_)}),t.load(f.LoaderUtils.resolveURL(h,r.path),w,void 0,m)})}).then(function(h){return u===!0&&a.revokeObjectURL(c),yt(h,o),h.userData.mimeType=o.mimeType||Zc(o.uri),h}).catch(function(h){throw console.error("THREE.GLTFLoader: Couldn't load texture",c),h});return this.sourceCache[e]=d,d}assignTexture(e,t,n,s){const r=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(o=o.clone(),o.channel=n.texCoord),r.extensions[le.KHR_TEXTURE_TRANSFORM]){const a=n.extensions!==void 0?n.extensions[le.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const c=r.associations.get(o);o=r.extensions[le.KHR_TEXTURE_TRANSFORM].extendTexture(o,a),r.associations.set(o,c)}}return s!==void 0&&(o.colorSpace=s),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let n=e.material;const s=t.attributes.tangent===void 0,r=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const a="PointsMaterial:"+n.uuid;let c=this.cache.get(a);c||(c=new f.PointsMaterial,f.Material.prototype.copy.call(c,n),c.color.copy(n.color),c.map=n.map,c.sizeAttenuation=!1,this.cache.add(a,c)),n=c}else if(e.isLine){const a="LineBasicMaterial:"+n.uuid;let c=this.cache.get(a);c||(c=new f.LineBasicMaterial,f.Material.prototype.copy.call(c,n),c.color.copy(n.color),c.map=n.map,this.cache.add(a,c)),n=c}if(s||r||o){let a="ClonedMaterial:"+n.uuid+":";s&&(a+="derivative-tangents:"),r&&(a+="vertex-colors:"),o&&(a+="flat-shading:");let c=this.cache.get(a);c||(c=n.clone(),r&&(c.vertexColors=!0),o&&(c.flatShading=!0),s&&(c.normalScale&&(c.normalScale.y*=-1),c.clearcoatNormalScale&&(c.clearcoatNormalScale.y*=-1)),this.cache.add(a,c),this.associations.set(c,this.associations.get(n))),n=c}e.material=n}getMaterialType(){return f.MeshStandardMaterial}loadMaterial(e){const t=this,n=this.json,s=this.extensions,r=n.materials[e];let o;const a={},c=r.extensions||{},u=[];if(c[le.KHR_MATERIALS_UNLIT]){const h=s[le.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),u.push(h.extendParams(a,r,t))}else{const h=r.pbrMetallicRoughness||{};if(a.color=new f.Color(1,1,1),a.opacity=1,Array.isArray(h.baseColorFactor)){const p=h.baseColorFactor;a.color.setRGB(p[0],p[1],p[2],f.LinearSRGBColorSpace),a.opacity=p[3]}h.baseColorTexture!==void 0&&u.push(t.assignTexture(a,"map",h.baseColorTexture,f.SRGBColorSpace)),a.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,a.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(u.push(t.assignTexture(a,"metalnessMap",h.metallicRoughnessTexture)),u.push(t.assignTexture(a,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(p){return p.getMaterialType&&p.getMaterialType(e)}),u.push(Promise.all(this._invokeAll(function(p){return p.extendMaterialParams&&p.extendMaterialParams(e,a)})))}r.doubleSided===!0&&(a.side=f.DoubleSide);const d=r.alphaMode||Hs.OPAQUE;if(d===Hs.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,d===Hs.MASK&&(a.alphaTest=r.alphaCutoff!==void 0?r.alphaCutoff:.5)),r.normalTexture!==void 0&&o!==f.MeshBasicMaterial&&(u.push(t.assignTexture(a,"normalMap",r.normalTexture)),a.normalScale=new f.Vector2(1,1),r.normalTexture.scale!==void 0)){const h=r.normalTexture.scale;a.normalScale.set(h,h)}if(r.occlusionTexture!==void 0&&o!==f.MeshBasicMaterial&&(u.push(t.assignTexture(a,"aoMap",r.occlusionTexture)),r.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=r.occlusionTexture.strength)),r.emissiveFactor!==void 0&&o!==f.MeshBasicMaterial){const h=r.emissiveFactor;a.emissive=new f.Color().setRGB(h[0],h[1],h[2],f.LinearSRGBColorSpace)}return r.emissiveTexture!==void 0&&o!==f.MeshBasicMaterial&&u.push(t.assignTexture(a,"emissiveMap",r.emissiveTexture,f.SRGBColorSpace)),Promise.all(u).then(function(){const h=new o(a);return r.name&&(h.name=r.name),yt(h,r),t.associations.set(h,{materials:e}),r.extensions&&zt(s,h,r),h})}createUniqueName(e){const t=f.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,n=this.extensions,s=this.primitiveCache;function r(a){return n[le.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(c){return fr(c,a,t)})}const o=[];for(let a=0,c=e.length;a<c;a++){const u=e[a],d=Wc(u),h=s[d];if(h)o.push(h.promise);else{let p;u.extensions&&u.extensions[le.KHR_DRACO_MESH_COMPRESSION]?p=r(u):p=fr(new f.BufferGeometry,u,t),s[d]={primitive:u,promise:p},o.push(p)}}return Promise.all(o)}loadMesh(e){const t=this,n=this.json,s=this.extensions,r=n.meshes[e],o=r.primitives,a=[];for(let c=0,u=o.length;c<u;c++){const d=o[c].material===void 0?Hc(this.cache):this.getDependency("material",o[c].material);a.push(d)}return a.push(t.loadGeometries(o)),Promise.all(a).then(function(c){const u=c.slice(0,c.length-1),d=c[c.length-1],h=[];for(let m=0,w=d.length;m<w;m++){const x=d[m],_=o[m];let v;const T=u[m];if(_.mode===st.TRIANGLES||_.mode===st.TRIANGLE_STRIP||_.mode===st.TRIANGLE_FAN||_.mode===void 0)v=r.isSkinnedMesh===!0?new f.SkinnedMesh(x,T):new f.Mesh(x,T),v.isSkinnedMesh===!0&&v.normalizeSkinWeights(),_.mode===st.TRIANGLE_STRIP?v.geometry=lr(v.geometry,f.TriangleStripDrawMode):_.mode===st.TRIANGLE_FAN&&(v.geometry=lr(v.geometry,f.TriangleFanDrawMode));else if(_.mode===st.LINES)v=new f.LineSegments(x,T);else if(_.mode===st.LINE_STRIP)v=new f.Line(x,T);else if(_.mode===st.LINE_LOOP)v=new f.LineLoop(x,T);else if(_.mode===st.POINTS)v=new f.Points(x,T);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+_.mode);Object.keys(v.geometry.morphAttributes).length>0&&Gc(v,r),v.name=t.createUniqueName(r.name||"mesh_"+e),yt(v,r),_.extensions&&zt(s,v,_),t.assignFinalMaterial(v),h.push(v)}for(let m=0,w=h.length;m<w;m++)t.associations.set(h[m],{meshes:e,primitives:m});if(h.length===1)return r.extensions&&zt(s,h[0],r),h[0];const p=new f.Group;r.extensions&&zt(s,p,r),t.associations.set(p,{meshes:e});for(let m=0,w=h.length;m<w;m++)p.add(h[m]);return p})}loadCamera(e){let t;const n=this.json.cameras[e],s=n[n.type];if(!s){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return n.type==="perspective"?t=new f.PerspectiveCamera(f.MathUtils.radToDeg(s.yfov),s.aspectRatio||1,s.znear||1,s.zfar||2e6):n.type==="orthographic"&&(t=new f.OrthographicCamera(-s.xmag,s.xmag,s.ymag,-s.ymag,s.znear,s.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),yt(t,n),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],n=[];for(let s=0,r=t.joints.length;s<r;s++)n.push(this._loadNodeShallow(t.joints[s]));return t.inverseBindMatrices!==void 0?n.push(this.getDependency("accessor",t.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(s){const r=s.pop(),o=s,a=[],c=[];for(let u=0,d=o.length;u<d;u++){const h=o[u];if(h){a.push(h);const p=new f.Matrix4;r!==null&&p.fromArray(r.array,u*16),c.push(p)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[u])}return new f.Skeleton(a,c)})}loadAnimation(e){const t=this.json,n=this,s=t.animations[e],r=s.name?s.name:"animation_"+e,o=[],a=[],c=[],u=[],d=[];for(let h=0,p=s.channels.length;h<p;h++){const m=s.channels[h],w=s.samplers[m.sampler],x=m.target,_=x.node,v=s.parameters!==void 0?s.parameters[w.input]:w.input,T=s.parameters!==void 0?s.parameters[w.output]:w.output;x.node!==void 0&&(o.push(this.getDependency("node",_)),a.push(this.getDependency("accessor",v)),c.push(this.getDependency("accessor",T)),u.push(w),d.push(x))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(c),Promise.all(u),Promise.all(d)]).then(function(h){const p=h[0],m=h[1],w=h[2],x=h[3],_=h[4],v=[];for(let S=0,b=p.length;S<b;S++){const A=p[S],L=m[S],P=w[S],C=x[S],D=_[S];if(A===void 0)continue;A.updateMatrix&&A.updateMatrix();const I=n._createAnimationTracks(A,L,P,C,D);if(I)for(let k=0;k<I.length;k++)v.push(I[k])}const T=new f.AnimationClip(r,void 0,v);return yt(T,s),T})}createNodeMesh(e){const t=this.json,n=this,s=t.nodes[e];return s.mesh===void 0?null:n.getDependency("mesh",s.mesh).then(function(r){const o=n._getNodeRef(n.meshCache,s.mesh,r);return s.weights!==void 0&&o.traverse(function(a){if(a.isMesh)for(let c=0,u=s.weights.length;c<u;c++)a.morphTargetInfluences[c]=s.weights[c]}),o})}loadNode(e){const t=this.json,n=this,s=t.nodes[e],r=n._loadNodeShallow(e),o=[],a=s.children||[];for(let u=0,d=a.length;u<d;u++)o.push(n.getDependency("node",a[u]));const c=s.skin===void 0?Promise.resolve(null):n.getDependency("skin",s.skin);return Promise.all([r,Promise.all(o),c]).then(function(u){const d=u[0],h=u[1],p=u[2];p!==null&&d.traverse(function(m){m.isSkinnedMesh&&m.bind(p,Kc)});for(let m=0,w=h.length;m<w;m++)d.add(h[m]);if(d.userData.pivot!==void 0&&h.length>0){const m=d.userData.pivot,w=h[0];d.pivot=new f.Vector3().fromArray(m),d.position.x-=m[0],d.position.y-=m[1],d.position.z-=m[2],w.position.set(0,0,0),delete d.userData.pivot}return d})}_loadNodeShallow(e){const t=this.json,n=this.extensions,s=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const r=t.nodes[e],o=r.name?s.createUniqueName(r.name):"",a=[],c=s._invokeOne(function(u){return u.createNodeMesh&&u.createNodeMesh(e)});return c&&a.push(c),r.camera!==void 0&&a.push(s.getDependency("camera",r.camera).then(function(u){return s._getNodeRef(s.cameraCache,r.camera,u)})),s._invokeAll(function(u){return u.createNodeAttachment&&u.createNodeAttachment(e)}).forEach(function(u){a.push(u)}),this.nodeCache[e]=Promise.all(a).then(function(u){let d;if(r.isBone===!0?d=new f.Bone:u.length>1?d=new f.Group:u.length===1?d=u[0]:d=new f.Object3D,d!==u[0])for(let h=0,p=u.length;h<p;h++)d.add(u[h]);if(r.name&&(d.userData.name=r.name,d.name=o),yt(d,r),r.extensions&&zt(n,d,r),r.matrix!==void 0){const h=new f.Matrix4;h.fromArray(r.matrix),d.applyMatrix4(h)}else r.translation!==void 0&&d.position.fromArray(r.translation),r.rotation!==void 0&&d.quaternion.fromArray(r.rotation),r.scale!==void 0&&d.scale.fromArray(r.scale);if(!s.associations.has(d))s.associations.set(d,{});else if(r.mesh!==void 0&&s.meshCache.refs[r.mesh]>1){const h=s.associations.get(d);s.associations.set(d,{...h})}return s.associations.get(d).nodes=e,d}),this.nodeCache[e]}loadScene(e){const t=this.extensions,n=this.json.scenes[e],s=this,r=new f.Group;n.name&&(r.name=s.createUniqueName(n.name)),yt(r,n),n.extensions&&zt(t,r,n);const o=n.nodes||[],a=[];for(let c=0,u=o.length;c<u;c++)a.push(s.getDependency("node",o[c]));return Promise.all(a).then(function(c){for(let d=0,h=c.length;d<h;d++){const p=c[d];p.parent!==null?r.add(mc(p)):r.add(p)}const u=d=>{const h=new Map;for(const[p,m]of s.associations)(p instanceof f.Material||p instanceof f.Texture)&&h.set(p,m);return d.traverse(p=>{const m=s.associations.get(p);m!=null&&h.set(p,m)}),h};return s.associations=u(r),r})}_createAnimationTracks(e,t,n,s,r){const o=[],a=e.name?e.name:e.uuid,c=[];function u(m){m.morphTargetInfluences&&c.push(m.name?m.name:m.uuid)}Rt[r.path]===Rt.weights?(u(e),e.isGroup&&e.children.forEach(u)):c.push(a);let d;switch(Rt[r.path]){case Rt.weights:d=f.NumberKeyframeTrack;break;case Rt.rotation:d=f.QuaternionKeyframeTrack;break;case Rt.translation:case Rt.scale:d=f.VectorKeyframeTrack;break;default:switch(n.itemSize){case 1:d=f.NumberKeyframeTrack;break;case 2:case 3:default:d=f.VectorKeyframeTrack;break}break}const h=s.interpolation!==void 0?Vc[s.interpolation]:f.InterpolateLinear,p=this._getArrayFromAccessor(n);for(let m=0,w=c.length;m<w;m++){const x=new d(c[m]+"."+Rt[r.path],t.array,p,h);s.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(x),o.push(x)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const n=fi(t.constructor),s=new Float32Array(t.length);for(let r=0,o=t.length;r<o;r++)s[r]=t[r]*n;t=s}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(n){const s=this instanceof f.QuaternionKeyframeTrack?Uc:zr;return new s(this.times,this.values,this.getValueSize()/3,n)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function Yc(i,e,t){const n=e.attributes,s=new f.Box3;if(n.POSITION!==void 0){const a=t.json.accessors[n.POSITION],c=a.min,u=a.max;if(c!==void 0&&u!==void 0){if(s.set(new f.Vector3(c[0],c[1],c[2]),new f.Vector3(u[0],u[1],u[2])),a.normalized){const d=fi(rn[a.componentType]);s.min.multiplyScalar(d),s.max.multiplyScalar(d)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const r=e.targets;if(r!==void 0){const a=new f.Vector3,c=new f.Vector3;for(let u=0,d=r.length;u<d;u++){const h=r[u];if(h.POSITION!==void 0){const p=t.json.accessors[h.POSITION],m=p.min,w=p.max;if(m!==void 0&&w!==void 0){if(c.setX(Math.max(Math.abs(m[0]),Math.abs(w[0]))),c.setY(Math.max(Math.abs(m[1]),Math.abs(w[1]))),c.setZ(Math.max(Math.abs(m[2]),Math.abs(w[2]))),p.normalized){const x=fi(rn[p.componentType]);c.multiplyScalar(x)}a.max(c)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}s.expandByVector(a)}i.boundingBox=s;const o=new f.Sphere;s.getCenter(o.center),o.radius=s.min.distanceTo(s.max)/2,i.boundingSphere=o}function fr(i,e,t){const n=e.attributes,s=[];function r(o,a){return t.getDependency("accessor",o).then(function(c){i.setAttribute(a,c)})}for(const o in n){const a=pi[o]||o.toLowerCase();a in i.attributes||s.push(r(n[o],a))}if(e.indices!==void 0&&!i.index){const o=t.getDependency("accessor",e.indices).then(function(a){i.setIndex(a)});s.push(o)}return f.ColorManagement.workingColorSpace!==f.LinearSRGBColorSpace&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${f.ColorManagement.workingColorSpace}" not supported.`),yt(i,e),Yc(i,e,t),Promise.all(s).then(function(){return e.targets!==void 0?jc(i,e.targets,t):i})}const qc=E.REVISION.replace(/\D/g,""),Ur=`https://cdn.jsdelivr.net/npm/three@0.${qc}/examples/jsm/libs`,$c=`${Ur}/draco/`,Qc=`${Ur}/basis/`;class Jc{constructor(e={}){this.loadingManager=new E.LoadingManager,this.loader=new gc(this.loadingManager),this.config=e}ensureDecoders(){return this.decodersReady||(this.decodersReady=this.configureDecoders()),this.decodersReady}async configureDecoders(){const e=this.config,t=[];(e.draco??!0)&&t.push(this.configureDraco(e)),(e.ktx2??!0)&&t.push(this.configureKtx2(e)),(e.meshopt??!0)&&t.push(this.configureMeshopt());const n=await Promise.allSettled(t);for(const s of n)s.status==="rejected"&&console.warn("softbox: a compression decoder failed to initialize; compressed assets using it may not load.",s.reason)}async configureDraco(e){const{DRACOLoader:t}=await import("three/examples/jsm/loaders/DRACOLoader.js"),n=new t(this.loadingManager);n.setDecoderPath(e.dracoDecoderPath??$c),this.dracoLoader=n,this.loader.setDRACOLoader(n)}async configureKtx2(e){const{KTX2Loader:t}=await import("three/examples/jsm/loaders/KTX2Loader.js"),n=new t(this.loadingManager);n.setTranscoderPath(e.ktx2TranscoderPath??Qc),e.renderer&&n.detectSupport(e.renderer),this.ktx2Loader=n,this.loader.setKTX2Loader(n)}async configureMeshopt(){const e=await import("three/examples/jsm/libs/meshopt_decoder.module.js");this.loader.setMeshoptDecoder(e.MeshoptDecoder)}async load(e,t){try{return await this.ensureDecoders(),new Promise(n=>{this.loader.load(e,s=>{var o;(this.config.bvh??!0)&&Fr(s.scene),s.scene.animations=s.animations;const r={scene:new Ke(s.scene),animations:this.convertAnimations(s.animations),cameras:(o=s.cameras)==null?void 0:o.map(a=>{const c=a instanceof E.PerspectiveCamera,u=a instanceof E.OrthographicCamera;return{name:a.name,type:a.type,fov:c?a.fov:void 0,aspect:c?a.aspect:void 0,near:c||u?a.near:.1,far:c||u?a.far:1e3}}),userData:s.userData};n(F.ok(r))},s=>{s.total>0&&(t==null||t(s.loaded,s.total))},s=>{n(F.err(new Z("Failed to load GLTF model",X.MODEL_LOAD_FAILED,{url:e,originalError:s})))})})}catch(n){return F.err(new Z("Failed to initiate model loading",X.MODEL_LOAD_FAILED,{url:e,originalError:n}))}}supports(e){var n;const t=(n=e.split(".").pop())==null?void 0:n.toLowerCase();return t==="gltf"||t==="glb"}dispose(){var e,t;(e=this.dracoLoader)==null||e.dispose(),(t=this.ktx2Loader)==null||t.dispose()}convertAnimations(e){return e.map(t=>({name:t.name,duration:t.duration,tracks:t.tracks.map(n=>({name:n.name,type:this.getTrackType(n),times:n.times,values:n.values}))}))}getTrackType(e){return e instanceof E.VectorKeyframeTrack?"vector":e instanceof E.QuaternionKeyframeTrack?"quaternion":e instanceof E.NumberKeyframeTrack?"number":e instanceof E.BooleanKeyframeTrack?"boolean":"number"}}class mr{static createLoader(e,t={}){var s;const n=(s=e.split(".").pop())==null?void 0:s.toLowerCase();switch(n){case"gltf":case"glb":return new Jc(t);default:throw new Z(`Unsupported file format: ${n}`,X.UNSUPPORTED_FORMAT,{url:e,extension:n})}}}const gr={type:"change"},Ai={type:"start"},Vr={type:"end"},rs=new f.Ray,yr=new f.Plane,el=Math.cos(70*f.MathUtils.DEG2RAD),Le=new f.Vector3,$e=2*Math.PI,Ee={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},Gs=1e-6;class Hr extends f.Controls{constructor(e,t=null){super(e,t),this.state=Ee.NONE,this.target=new f.Vector3,this.cursor=new f.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:f.MOUSE.ROTATE,MIDDLE:f.MOUSE.DOLLY,RIGHT:f.MOUSE.PAN},this.touches={ONE:f.TOUCH.ROTATE,TWO:f.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle="auto",this._domElementKeyEvents=null,this._lastPosition=new f.Vector3,this._lastQuaternion=new f.Quaternion,this._lastTargetPosition=new f.Vector3,this._quat=new f.Quaternion().setFromUnitVectors(e.up,new f.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new f.Spherical,this._sphericalDelta=new f.Spherical,this._scale=1,this._panOffset=new f.Vector3,this._rotateStart=new f.Vector2,this._rotateEnd=new f.Vector2,this._rotateDelta=new f.Vector2,this._panStart=new f.Vector2,this._panEnd=new f.Vector2,this._panDelta=new f.Vector2,this._dollyStart=new f.Vector2,this._dollyEnd=new f.Vector2,this._dollyDelta=new f.Vector2,this._dollyDirection=new f.Vector3,this._mouse=new f.Vector2,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=nl.bind(this),this._onPointerDown=tl.bind(this),this._onPointerUp=sl.bind(this),this._onContextMenu=hl.bind(this),this._onMouseWheel=ol.bind(this),this._onKeyDown=al.bind(this),this._onTouchStart=cl.bind(this),this._onTouchMove=ll.bind(this),this._onMouseDown=il.bind(this),this._onMouseMove=rl.bind(this),this._interceptControlDown=ul.bind(this),this._interceptControlUp=dl.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e==="grab"?this.domElement.style.cursor="grab":this.domElement.style.cursor="auto"}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=""}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(gr),this.update(),this.state=Ee.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){const t=this.object.position;Le.copy(t).sub(this.target),Le.applyQuaternion(this._quat),this._spherical.setFromVector3(Le),this.autoRotate&&this.state===Ee.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,s=this.maxAzimuthAngle;isFinite(n)&&isFinite(s)&&(n<-Math.PI?n+=$e:n>Math.PI&&(n-=$e),s<-Math.PI?s+=$e:s>Math.PI&&(s-=$e),n<=s?this._spherical.theta=Math.max(n,Math.min(s,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+s)/2?Math.max(n,this._spherical.theta):Math.min(s,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let r=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const o=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),r=o!=this._spherical.radius}if(Le.setFromSpherical(this._spherical),Le.applyQuaternion(this._quatInverse),t.copy(this.target).add(Le),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let o=null;if(this.object.isPerspectiveCamera){const a=Le.length();o=this._clampDistance(a*this._scale);const c=a-o;this.object.position.addScaledVector(this._dollyDirection,c),this.object.updateMatrixWorld(),r=!!c}else if(this.object.isOrthographicCamera){const a=new f.Vector3(this._mouse.x,this._mouse.y,0);a.unproject(this.object);const c=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),r=c!==this.object.zoom;const u=new f.Vector3(this._mouse.x,this._mouse.y,0);u.unproject(this.object),this.object.position.sub(u).add(a),this.object.updateMatrixWorld(),o=Le.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;o!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position):(rs.origin.copy(this.object.position),rs.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(rs.direction))<el?this.object.lookAt(this.target):(yr.setFromNormalAndCoplanarPoint(this.object.up,this.target),rs.intersectPlane(yr,this.target))))}else if(this.object.isOrthographicCamera){const o=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),o!==this.object.zoom&&(this.object.updateProjectionMatrix(),r=!0)}return this._scale=1,this._performCursorZoom=!1,r||this._lastPosition.distanceToSquared(this.object.position)>Gs||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Gs||this._lastTargetPosition.distanceToSquared(this.target)>Gs?(this.dispatchEvent(gr),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?$e/60*this.autoRotateSpeed*e:$e/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){Le.setFromMatrixColumn(t,0),Le.multiplyScalar(-e),this._panOffset.add(Le)}_panUp(e,t){this.screenSpacePanning===!0?Le.setFromMatrixColumn(t,1):(Le.setFromMatrixColumn(t,0),Le.crossVectors(this.object.up,Le)),Le.multiplyScalar(e),this._panOffset.add(Le)}_pan(e,t){const n=this.domElement;if(this.object.isPerspectiveCamera){const s=this.object.position;Le.copy(s).sub(this.target);let r=Le.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*r/n.clientHeight,this.object.matrix),this._panUp(2*t*r/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),s=e-n.left,r=t-n.top,o=n.width,a=n.height;this._mouse.x=s/o*2-1,this._mouse.y=-(r/a)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft($e*this._rotateDelta.x/t.clientHeight),this._rotateUp($e*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp($e*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-$e*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft($e*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-$e*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._rotateStart.set(n,s)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panStart.set(n,s)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,s=e.pageY-t.y,r=Math.sqrt(n*n+s*s);this._dollyStart.set(0,r)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const n=this._getSecondPointerPosition(e),s=.5*(e.pageX+n.x),r=.5*(e.pageY+n.y);this._rotateEnd.set(s,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft($e*this._rotateDelta.x/t.clientHeight),this._rotateUp($e*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panEnd.set(n,s)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,s=e.pageY-t.y,r=Math.sqrt(n*n+s*s);this._dollyEnd.set(0,r),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const o=(e.pageX+t.x)*.5,a=(e.pageY+t.y)*.5;this._updateZoomParameters(o,a)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new f.Vector2,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function tl(i){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(i.pointerId),this.domElement.ownerDocument.addEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(i)&&(this._addPointer(i),i.pointerType==="touch"?this._onTouchStart(i):this._onMouseDown(i),this._cursorStyle==="grab"&&(this.domElement.style.cursor="grabbing")))}function nl(i){this.enabled!==!1&&(i.pointerType==="touch"?this._onTouchMove(i):this._onMouseMove(i))}function sl(i){switch(this._removePointer(i),this._pointers.length){case 0:this.domElement.releasePointerCapture(i.pointerId),this.domElement.ownerDocument.removeEventListener("pointermove",this._onPointerMove),this.domElement.ownerDocument.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Vr),this.state=Ee.NONE,this._cursorStyle==="grab"&&(this.domElement.style.cursor="grab");break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function il(i){let e;switch(i.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case f.MOUSE.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(i),this.state=Ee.DOLLY;break;case f.MOUSE.ROTATE:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=Ee.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=Ee.ROTATE}break;case f.MOUSE.PAN:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=Ee.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=Ee.PAN}break;default:this.state=Ee.NONE}this.state!==Ee.NONE&&this.dispatchEvent(Ai)}function rl(i){switch(this.state){case Ee.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(i);break;case Ee.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(i);break;case Ee.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(i);break}}function ol(i){this.enabled===!1||this.enableZoom===!1||this.state!==Ee.NONE||(i.preventDefault(),this.dispatchEvent(Ai),this._handleMouseWheel(this._customWheelEvent(i)),this.dispatchEvent(Vr))}function al(i){this.enabled!==!1&&this._handleKeyDown(i)}function cl(i){switch(this._trackPointer(i),this._pointers.length){case 1:switch(this.touches.ONE){case f.TOUCH.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(i),this.state=Ee.TOUCH_ROTATE;break;case f.TOUCH.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(i),this.state=Ee.TOUCH_PAN;break;default:this.state=Ee.NONE}break;case 2:switch(this.touches.TWO){case f.TOUCH.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(i),this.state=Ee.TOUCH_DOLLY_PAN;break;case f.TOUCH.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(i),this.state=Ee.TOUCH_DOLLY_ROTATE;break;default:this.state=Ee.NONE}break;default:this.state=Ee.NONE}this.state!==Ee.NONE&&this.dispatchEvent(Ai)}function ll(i){switch(this._trackPointer(i),this.state){case Ee.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(i),this.update();break;case Ee.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(i),this.update();break;case Ee.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(i),this.update();break;case Ee.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(i),this.update();break;default:this.state=Ee.NONE}}function hl(i){this.enabled!==!1&&i.preventDefault()}function ul(i){i.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function dl(i){i.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}const Ws=new f.Plane,os=new f.Raycaster,Jt=new f.Vector2,Zs=new f.Vector3;class pl extends Hr{constructor(e,t){super(e,t),this.screenSpacePanning=!1,this.mouseButtons={LEFT:f.MOUSE.PAN,MIDDLE:f.MOUSE.DOLLY,RIGHT:f.MOUSE.ROTATE},this.touches={ONE:f.TOUCH.PAN,TWO:f.TOUCH.DOLLY_ROTATE},this._panWorldStart=new f.Vector3}_handleMouseDownPan(e){if(super._handleMouseDownPan(e),this._panOffset.set(0,0,0),this.screenSpacePanning===!0)return;Ws.setFromNormalAndCoplanarPoint(this.object.up,this.target);const n=this.domElement.getBoundingClientRect();Jt.x=(e.clientX-n.left)/n.width*2-1,Jt.y=-((e.clientY-n.top)/n.height)*2+1,os.setFromCamera(Jt,this.object),os.ray.intersectPlane(Ws,this._panWorldStart)}_handleMouseMovePan(e){if(this.screenSpacePanning===!0){super._handleMouseMovePan(e);return}const n=this.domElement.getBoundingClientRect();Jt.x=(e.clientX-n.left)/n.width*2-1,Jt.y=-((e.clientY-n.top)/n.height)*2+1,os.setFromCamera(Jt,this.object),os.ray.intersectPlane(Ws,Zs)&&(Zs.sub(this._panWorldStart),this._panOffset.copy(Zs).negate(),this.update())}}class jr{constructor(e){this.controls=e,this.targetAdapter=Ot.fromThreeVector(e.target)}get enabled(){return this.controls.enabled}set enabled(e){this.controls.enabled=e}get enableDamping(){return this.controls.enableDamping}set enableDamping(e){this.controls.enableDamping=e}get dampingFactor(){return this.controls.dampingFactor}set dampingFactor(e){this.controls.dampingFactor=e}get enableZoom(){return this.controls.enableZoom}set enableZoom(e){this.controls.enableZoom=e}get enableRotate(){return this.controls.enableRotate}set enableRotate(e){this.controls.enableRotate=e}get enablePan(){return this.controls.enablePan}set enablePan(e){this.controls.enablePan=e}get zoomSpeed(){return this.controls.zoomSpeed}set zoomSpeed(e){this.controls.zoomSpeed=e}get minDistance(){return this.controls.minDistance}set minDistance(e){this.controls.minDistance=e}get maxDistance(){return this.controls.maxDistance}set maxDistance(e){this.controls.maxDistance=e}get rotateSpeed(){return this.controls.rotateSpeed}set rotateSpeed(e){this.controls.rotateSpeed=e}get minPolarAngle(){return this.controls.minPolarAngle}set minPolarAngle(e){this.controls.minPolarAngle=e}get maxPolarAngle(){return this.controls.maxPolarAngle}set maxPolarAngle(e){this.controls.maxPolarAngle=e}get minAzimuthAngle(){return this.controls.minAzimuthAngle}set minAzimuthAngle(e){this.controls.minAzimuthAngle=e}get maxAzimuthAngle(){return this.controls.maxAzimuthAngle}set maxAzimuthAngle(e){this.controls.maxAzimuthAngle=e}get panSpeed(){return this.controls.panSpeed}set panSpeed(e){this.controls.panSpeed=e}get screenSpacePanning(){return this.controls.screenSpacePanning}set screenSpacePanning(e){this.controls.screenSpacePanning=e}get target(){return this.targetAdapter}update(){return this.controls.update()}onChange(e){return this.controls.addEventListener("change",e),()=>this.controls.removeEventListener("change",e)}reset(){this.controls.reset()}dispose(){this.controls.dispose()}connect(e){}disconnect(){this.controls.dispose()}get autoRotate(){return this.controls.autoRotate}set autoRotate(e){this.controls.autoRotate=e}get autoRotateSpeed(){return this.controls.autoRotateSpeed}set autoRotateSpeed(e){this.controls.autoRotateSpeed=e}getThreeControls(){return this.controls}}class fl extends jr{constructor(e,t){super(new Hr(e,t))}get type(){return"orbit"}}class ml extends jr{constructor(e,t){const n=new pl(e,t);super(n),n.screenSpacePanning=!0}get type(){return"map"}get screenSpacePanning(){return!0}set screenSpacePanning(e){}}const mi="contact-shadow-baked",Ut="contact-shadow-live",vs="softboxContactShadowHelper",wr=Math.PI*(3-Math.sqrt(5)),xe=class xe{constructor(e){this.explicitPasses=e==null?void 0:e.passes}bake(e){const{renderer:t,scene:n,object:s,light:r}=e;if(t.getContext().isContextLost()){this.leaveLiveCatcherInCharge(n);return}const o=this.measureBakeRegion(s);if(!o)return;const a=n.getObjectByName(Ut);(a==null?void 0:a.geometry)instanceof E.CircleGeometry&&(o.halfExtent=Math.min(o.halfExtent,a.geometry.parameters.radius));const c=new E.WebGLRenderTarget(xe.ACCUMULATION_TEXTURE_SIZE,xe.ACCUMULATION_TEXTURE_SIZE,{type:t.capabilities.isWebGL2?E.HalfFloatType:E.UnsignedByteType,depthBuffer:!1,stencilBuffer:!1}),u=new E.CircleGeometry(o.halfExtent,64);if(this.accumulateShadowPasses(t,s,r,o,c,u),t.getContext().isContextLost()){c.dispose(),u.dispose(),this.leaveLiveCatcherInCharge(n),console.warn("Contact-shadow bake aborted: WebGL context was lost mid-bake");return}this.installBakedMesh(n,o,c,u)}leaveLiveCatcherInCharge(e){this.evictBakedMesh(e);const t=e.getObjectByName(Ut);t&&(t.visible=!0)}evictBakedMesh(e){const t=e.getObjectByName(mi);t&&(e.remove(t),As(t))}measureBakeRegion(e){const t=new E.Box3().setFromObject(e);if(t.isEmpty()||!Number.isFinite(t.min.x)||!Number.isFinite(t.max.x))return null;const n=t.getSize(new E.Vector3),s=t.getCenter(new E.Vector3),o=Math.max(Math.max(n.x,n.z)*1.6+n.y,.05);return{center:s,halfExtent:o,objectHeight:n.y}}accumulateShadowPasses(e,t,n,s,r,o){const a=new E.Scene,c=t.parent;a.add(t);const u=this.disableColorWrite(t),d=this.createBakeLight(n);a.add(d),a.add(d.target),d.target.position.copy(n.target.parent?n.target.getWorldPosition(new E.Vector3):n.target.position);const h=new E.ShadowMaterial({transparent:!0,opacity:0,depthWrite:!1});h.blending=E.CustomBlending,h.blendEquation=E.AddEquation,h.blendSrc=E.OneFactor,h.blendDst=E.OneFactor;const p=new E.Mesh(o,h);p.rotation.x=-Math.PI/2,p.position.set(s.center.x,0,s.center.z),p.receiveShadow=!0,a.add(p);const m=this.createBakeCamera(s);a.add(m);const w=e.getRenderTarget(),x=e.autoClear,_=e.getClearColor(new E.Color),v=e.getClearAlpha(),T=e.shadowMap.autoUpdate;try{e.shadowMap.autoUpdate=!0,e.setRenderTarget(r),e.setClearColor(0,0),e.clear(!0,!1,!1),e.autoClear=!1;const S=this.explicitPasses??this.measureAffordablePasses(e,a,m,n,d,r);h.opacity=1/S;for(const b of this.sampleLightPositions(n,S))d.position.copy(b),e.render(a,m)}finally{e.autoClear=x,e.setClearColor(_,v),e.setRenderTarget(w),e.shadowMap.autoUpdate=T,this.restoreColorWrite(u),c?c.add(t):a.remove(t),d.dispose(),h.dispose()}}measureAffordablePasses(e,t,n,s,r,o){r.position.copy(s.position),e.render(t,n),this.awaitGpuIdle(e,o);const a=performance.now();e.render(t,n),this.awaitGpuIdle(e,o);const c=Math.max(performance.now()-a,.01);return E.MathUtils.clamp(Math.round(xe.BAKE_BUDGET_MS/c),xe.MIN_PASSES,xe.MAX_PASSES)}awaitGpuIdle(e,t){if(!e.capabilities.textureTypeReadable(t.texture.type))return;const n=t.texture.type===E.HalfFloatType?new Uint16Array(4):new Uint8Array(4);e.readRenderTargetPixels(t,0,0,1,1,n)}createBakeLight(e){const t=new E.DirectionalLight(16777215,1);t.castShadow=!0,t.shadow.mapSize.set(xe.BAKE_SHADOW_MAP_SIZE,xe.BAKE_SHADOW_MAP_SIZE),t.shadow.bias=e.shadow.bias,t.shadow.normalBias=e.shadow.normalBias,t.shadow.radius=4;const n=e.shadow.camera,s=t.shadow.camera;return s.left=n.left,s.right=n.right,s.top=n.top,s.bottom=n.bottom,s.near=n.near,s.far=n.far,s.updateProjectionMatrix(),t}createBakeCamera(e){const t=new E.OrthographicCamera(-e.halfExtent,e.halfExtent,e.halfExtent,-e.halfExtent,.1,Math.max(e.objectHeight,1)*4);return t.position.set(e.center.x,Math.max(e.objectHeight,1)*2,e.center.z),t.up.set(0,0,-1),t.lookAt(e.center.x,0,e.center.z),t.updateProjectionMatrix(),t.updateMatrixWorld(!0),t}sampleLightPositions(e,t){const n=e.position.clone(),s=e.target.parent?e.target.getWorldPosition(new E.Vector3):e.target.position.clone(),r=s.clone().sub(n),o=r.length(),a=r.normalize(),c=new E.Vector3().crossVectors(a,new E.Vector3(0,1,0));c.lengthSq()<1e-6&&c.set(1,0,0),c.normalize();const u=new E.Vector3().crossVectors(a,c),d=Math.round(t*xe.AMBIENT_RATIO),h=t-d,p=E.MathUtils.degToRad(xe.LIGHT_APERTURE_DEGREES),m=Math.tan(p/2)*o,w=[];for(let v=0;v<h;v++){const T=m*Math.sqrt((v+.5)/h),S=v*wr;w.push(n.clone().addScaledVector(c,T*Math.cos(S)).addScaledVector(u,T*Math.sin(S)))}const x=Math.sin(E.MathUtils.degToRad(xe.AMBIENT_MIN_ELEVATION_DEGREES)),_=.98;for(let v=0;v<d;v++){const T=Math.sqrt((v+.5)/d),S=x+(_-x)*T,b=Math.sqrt(1-S*S),A=v*wr;w.push(new E.Vector3(b*Math.cos(A),S,b*Math.sin(A)).multiplyScalar(o).add(s))}return w}installBakedMesh(e,t,n,s){this.evictBakedMesh(e);const r=new E.MeshBasicMaterial({map:n.texture,transparent:!0,opacity:xe.SHADOW_STRENGTH,depthWrite:!1,toneMapped:!1});r.onBeforeCompile=u=>{u.fragmentShader=u.fragmentShader.replace("#include <map_fragment>",`#include <map_fragment>
|
|
20
|
+
diffuseColor.a = pow(diffuseColor.a, 0.75);`)},r.customProgramCacheKey=()=>"contact-shadow-alpha-gamma",r.addEventListener("dispose",()=>n.dispose());const o=new E.Mesh(s,r);o.name=mi,o.userData[vs]=!0,o.rotation.x=-Math.PI/2;const a=E.MathUtils.clamp(t.objectHeight*.0025,2e-4,.01);o.position.set(t.center.x,a,t.center.z),o.userData.renderTarget=n,e.add(o);const c=e.getObjectByName(Ut);c&&(c.visible=!1)}disableColorWrite(e){const t=new Map;return e.traverse(n=>{const s=n;if(!s.isMesh)return;const r=Array.isArray(s.material)?s.material:[s.material];for(const o of r)o&&!t.has(o)&&(t.set(o,o.colorWrite),o.colorWrite=!1)}),t}restoreColorWrite(e){e.forEach((t,n)=>{n.colorWrite=t})}};xe.AMBIENT_RATIO=.45,xe.LIGHT_APERTURE_DEGREES=9,xe.AMBIENT_MIN_ELEVATION_DEGREES=55,xe.ACCUMULATION_TEXTURE_SIZE=1024,xe.BAKE_SHADOW_MAP_SIZE=1024,xe.SHADOW_STRENGTH=.85,xe.BAKE_BUDGET_MS=100,xe.MIN_PASSES=24,xe.MAX_PASSES=96;let gi=xe;const on=(i,e)=>{if(i&&typeof i=="object"){const t=i[e];if(typeof t=="function")return t.call(i)}return null};function Et(i){return on(i,"getThreeObject")??(i instanceof E.Object3D?i:null)}function Rn(i){return on(i,"getThreeCamera")??(i instanceof E.Camera?i:null)}function Tt(i){return on(i,"getThreeScene")??(i instanceof E.Scene?i:null)}function gl(i){return on(i,"getThreeTexture")??(i instanceof E.Texture?i:null)}function Gr(i){return on(i,"getThreeRenderer")??(i instanceof E.WebGLRenderer?i:null)}function vi(i){return on(i,"getThreeControls")}var wt=(i=>(i.SHADOW_FLOOR="shadow_floor",i.SQUARE_WIRE="square_wire",i.HEXAGONAL_WIRE="hexagonal_wire",i.HEXAGONAL_GLASS="hexagonal_glass",i.STONE_TILES="stone_tiles",i.CUSTOM="custom",i))(wt||{});class yl{constructor(){this.name="Square Wire Grid"}createGrid(e){const t=e.size||10,n=e.divisions||10,s=new E.Color(e.color||8947848),r=new E.Color(e.centerLineColor||e.color||4473924),o=new E.GridHelper(t,n,r,s);if(e.opacity!==void 0&&e.opacity<1){const a=o.material;a.transparent=!0,a.opacity=e.opacity}return o}dispose(){}}class wl{constructor(){this.name="Hexagonal Wire Grid"}createGrid(e){var d;const t=new E.Group,n=((d=e.styleOptions)==null?void 0:d.hexRadius)??Math.floor(e.divisions/2),s=e.size/Math.max(1,n*2),r=new E.Color(e.color||8947848),o=e.opacity||.4,a=new E.LineBasicMaterial({color:r,transparent:!0,opacity:o}),c=s*Math.sqrt(3),u=s*2;for(let h=-n;h<=n;h++){const p=Math.max(-n,-h-n),m=Math.min(n,-h+n);for(let w=p;w<=m;w++){const x=c*(h+w/2),_=u*.75*w,v=[],T=Math.PI*2/6;for(let A=0;A<=6;A++){const L=A*T+Math.PI/6,P=x+s*Math.cos(L),C=_+s*Math.sin(L);v.push(new E.Vector3(P,0,C))}const S=new E.BufferGeometry().setFromPoints(v),b=new E.Line(S,a);t.add(b)}}return t}dispose(){}}const xn=class xn{static getHeight(e){return e*this.HEIGHT_RATIO}static getBevelSize(e){return e*this.BEVEL_RATIO}static getBevelThickness(e){return this.getBevelSize(e)}static getBaseSize(e){return e+this.getBevelSize(e)+this.getBevelThickness(e)}static getGapFactor(){return this.GAP_FACTOR}static getGridSpacing(e){const t=this.getBaseSize(e),n=this.getGapFactor();return{width:Math.sqrt(3)*t*n,height:2*t*n}}static getYPosition(e){return-this.getBevelSize(e)}};xn.HEIGHT_RATIO=.075,xn.BEVEL_RATIO=.04,xn.GAP_FACTOR=1.05;let Vt=xn;class El{constructor(e,t,n,s={}){this.position=e,this.size=t,this.color=n,this.materialOptions=s,this.height=Vt.getHeight(this.size),this.bevel=Vt.getBevelSize(this.size)}createGeometry(){const e=new E.Shape,t=this.size+this.bevel,n=Math.PI*2/6;for(let o=0;o<6;o++){const a=t*Math.cos(o*n),c=t*Math.sin(o*n);o===0?e.moveTo(a,c):e.lineTo(a,c)}e.closePath();const s={depth:this.height,bevelEnabled:!0,bevelSize:this.bevel,bevelThickness:this.bevel,bevelSegments:2},r=new E.ExtrudeGeometry(e,s);return r.rotateZ(Math.PI/6),r.rotateX(Math.PI/2),r.translate(this.position.x,this.position.y,this.position.z),r}createMaterial(){const{metalness:e=0,roughness:t=.15,transmission:n=1,thickness:s=.4,ior:r=1.5}=this.materialOptions,o=n>0;return new E.MeshPhysicalMaterial({color:new E.Color(this.color),metalness:e,roughness:t,transparent:o,transmission:n,thickness:s,ior:r,opacity:1,clearcoat:o?1:0,clearcoatRoughness:.05,sheen:o?1:0,sheenColor:new E.Color(16777215),envMapIntensity:1})}}function Tl(i,e){var d;const t=i.getIndex()?i.toNonIndexed():i,n=t.getAttribute("position").array,s=t.getAttribute("normal").array,r=(d=t.getAttribute("uv"))==null?void 0:d.array,o=new Float32Array(n.length*e.length),a=new Float32Array(s.length*e.length),c=r?new Float32Array(r.length*e.length):void 0;e.forEach((h,p)=>{const m=p*n.length;o.set(n,m);for(let w=m;w<m+n.length;w+=3)o[w]+=h.x,o[w+1]+=h.y,o[w+2]+=h.z;a.set(s,p*s.length),c&&r&&c.set(r,p*r.length)});const u=new E.BufferGeometry;return u.setAttribute("position",new E.BufferAttribute(o,3)),u.setAttribute("normal",new E.BufferAttribute(a,3)),c&&u.setAttribute("uv",new E.BufferAttribute(c,2)),u}class Sl{constructor(){this.name="Hexagonal Glass Grid"}createGrid(e){var w,x,_,v,T,S,b;const t=new E.Group,n=((w=e.styleOptions)==null?void 0:w.hexRadius)??Math.floor(e.divisions/2),s=((x=e.styleOptions)==null?void 0:x.tileSize)||1,r=String(e.color||"#ffffff"),o=Vt.getGridSpacing(s),a=o.width,c=o.height,u=new El(new E.Vector3(0,0,0),s,r,{metalness:(_=e.styleOptions)==null?void 0:_.metalness,roughness:(v=e.styleOptions)==null?void 0:v.roughness,transmission:(T=e.styleOptions)==null?void 0:T.transmission,thickness:(S=e.styleOptions)==null?void 0:S.thickness,ior:(b=e.styleOptions)==null?void 0:b.ior}),d=u.createGeometry(),h=Vt.getYPosition(s),p=[];for(let A=-n;A<=n;A++){const L=Math.max(-n,-A-n),P=Math.min(n,-A+n);for(let C=L;C<=P;C++)p.push(new E.Vector3(a*(A+C/2),h,c*.75*C))}const m=new E.Mesh(Tl(d,p),u.createMaterial());return m.receiveShadow=!0,t.add(m),d.dispose(),t.add(this.createShadowCatcher(a*(n+.5))),t}createShadowCatcher(e){const t=new E.Mesh(new E.CircleGeometry(Math.max(e,1),64),new E.ShadowMaterial({opacity:.35}));return t.name=Ut,t.userData[vs]=!0,t.rotation.x=-Math.PI/2,t.position.y=.002,t.receiveShadow=!0,t}dispose(){}}class _l{constructor(){this.name="Stone Tile Grid",this.textureLoader=new E.TextureLoader}createGrid(e){var m,w,x,_;const t=new E.Group,n=e.size,s=Math.max(1,e.divisions),r=n/s,o=r*.02,a=r-o,c=((m=e.styleOptions)==null?void 0:m.height)||r*.05,u=((w=e.styleOptions)==null?void 0:w.bevelSize)||c*.2,d=((x=e.styleOptions)==null?void 0:x.randomHeight)||!1,h=((_=e.styleOptions)==null?void 0:_.randomRotation)||!1,p=this.createStoneMaterial(e);for(let v=0;v<s;v++)for(let T=0;T<s;T++){const S=(v-s/2)*r+r/2,b=(T-s/2)*r+r/2,A=d?c*(.8+Math.random()*.4):c,L=new E.Shape,P=a/2;L.moveTo(-P,-P),L.lineTo(P,-P),L.lineTo(P,P),L.lineTo(-P,P),L.closePath();const C={depth:A,bevelEnabled:!0,bevelSize:u,bevelThickness:u,bevelSegments:2},D=new E.ExtrudeGeometry(L,C);D.rotateX(-Math.PI/2);const I=new E.Mesh(D,p);I.position.set(S,-A/2,b),I.castShadow=!0,I.receiveShadow=!0,h&&(I.rotation.y=Math.floor(Math.random()*4)*(Math.PI/2)),t.add(I)}return t}createStoneMaterial(e){var o,a,c,u,d;const t=new E.Color(e.color||8421504),n=((o=e.styleOptions)==null?void 0:o.metalness)||0,s=((a=e.styleOptions)==null?void 0:a.roughness)||.8,r={color:t,metalness:n,roughness:s};if((c=e.styleOptions)!=null&&c.texture){const h=this.loadTexture(e.styleOptions.texture);h&&(r.map=h,h.wrapS=h.wrapT=E.RepeatWrapping,h.repeat.set(1,1))}if((u=e.styleOptions)!=null&&u.normalMap){const h=this.loadTexture(e.styleOptions.normalMap);h&&(r.normalMap=h,h.wrapS=h.wrapT=E.RepeatWrapping,h.repeat.set(1,1))}if((d=e.styleOptions)!=null&&d.roughnessMap){const h=this.loadTexture(e.styleOptions.roughnessMap);h&&(r.roughnessMap=h,h.wrapS=h.wrapT=E.RepeatWrapping,h.repeat.set(1,1))}return new E.MeshStandardMaterial(r)}loadTexture(e){try{return this.textureLoader.load(e)}catch(t){return console.warn("Failed to load texture:",e,t),null}}}class bl{constructor(){this.name="Shadow Floor"}createGrid(e){const t=new E.Group,n=Math.max(e.size||1,1)*1.5;return t.add(this.createShadowCatcher(n)),t}createShadowCatcher(e){const t=new E.Mesh(new E.CircleGeometry(Math.max(e,1),64),new E.ShadowMaterial({opacity:.35}));return t.name=Ut,t.userData[vs]=!0,t.rotation.x=-Math.PI/2,t.position.y=.002,t.receiveShadow=!0,t}dispose(){}}const Ci=class Ci{static createGrid(e,t){const n=this.gridStyles.get(e);if(!n){console.warn(`Unknown grid type: ${e}, falling back to square wire grid`);const r=this.gridStyles.get(wt.SQUARE_WIRE);if(!r)throw new Error("Square wire grid style not found");return r.createGrid(t)}const s=n.createGrid(t);return s.name=`Grid_${e}`,s}static registerGridStyle(e,t){this.gridStyles.set(e,t)}static getAvailableTypes(){return Array.from(this.gridStyles.keys())}static disposeGridStyle(e){const t=this.gridStyles.get(e);t&&t.dispose&&t.dispose()}};Ci.gridStyles=new Map([[wt.SHADOW_FLOOR,new bl],[wt.SQUARE_WIRE,new yl],[wt.HEXAGONAL_WIRE,new wl],[wt.HEXAGONAL_GLASS,new Sl],[wt.STONE_TILES,new _l]]);let ys=Ci;function xl(i,e){try{const t=Tt(i);if(!t)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));if(e.grid){const n=t.userData,s=typeof e.grid=="object"?e.grid:null,r={enabled:!0,color:(s==null?void 0:s.colorGrid)||e.gridColor||"#AAAAAA",type:s!=null&&s.type?s.type:wt.HEXAGONAL_GLASS,opacity:s==null?void 0:s.opacity,styleOptions:s==null?void 0:s.styleOptions};if(t.userData={...n,gridOptions:r},s!=null&&s.size||s!=null&&s.divisions){const o=r.type||wt.HEXAGONAL_GLASS,a=s.size||10,c=s.divisions||10,u={size:a,divisions:c,color:r.color,opacity:r.opacity,styleOptions:{hexRadius:Math.floor(c/2),tileSize:1,...r.styleOptions}},d=ys.createGrid(o,u);d.userData.isGrid=!0,d.userData.isDefaultGrid=!0,t.add(d)}}if(e.axes){const n=e.axesSize||5,s=new E.AxesHelper(n);t.add(s)}return F.ok(void 0)}catch(t){return F.err(new Z("Failed to add helpers to scene",X.SCENE_OPERATION_FAILED,{originalError:t,options:e}))}}function Al(i,e,t=1.2){var n;try{const s=Tt(i);if(!s)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));const r=s.userData,o=r==null?void 0:r.gridOptions;if(!(o!=null&&o.enabled))return F.ok(void 0);const a=[];s.traverse(C=>{var D,I,k;((D=C.userData)!=null&&D.isGrid||(I=C.userData)!=null&&I.isHexGrid||(k=C.userData)!=null&&k.isDefaultGrid)&&a.push(C)}),a.forEach(C=>{As(C),s.remove(C)});const c=Et(e);if(!c)return F.err(new Z("Object must expose a Three.js Object3D",X.INVALID_PARAMETER));const u=new E.Box3().setFromObject(c),d=u.getSize(new E.Vector3);if(u.isEmpty()||!Number.isFinite(d.x)||!Number.isFinite(d.z))return console.warn("Skipping dynamic grid: object has an empty or non-finite bounding box"),F.ok(void 0);const h=(n=o.styleOptions)==null?void 0:n.tileSize,p=typeof h=="number"?h:1,w=Vt.getGridSpacing(p).width,x=Math.max(d.x,d.z)*t+d.y;let _=x<=w?0:Math.ceil((x/w-1)/2);const v=60;_>v&&(console.warn(`Dynamic grid would need ${_} rings to cover the object; capping at ${v}. The floor will not fully reach the configured coverage for this tileSize/object-size combination.`),_=v),x<w*.8?_=0:_<3&&x>w*2&&(_=3);const T=o.type||wt.HEXAGONAL_GLASS,b={size:Math.max(d.x,d.z)*t,divisions:_*2+1,color:o.color,opacity:o.opacity,styleOptions:{hexRadius:_,tileSize:p,...o.styleOptions}},A=ys.createGrid(T,b);A.userData.isGrid=!0,A.userData.isHexGrid=!0;const L=A.getObjectByName(Ut);L&&(L.position.y=E.MathUtils.clamp(d.y*.0025,2e-4,.002));const P=u.getCenter(new E.Vector3);return A.position.set(P.x,0,P.z),s.add(A),F.ok(void 0)}catch(s){return F.err(new Z("Failed to add dynamic grid",X.SCENE_OPERATION_FAILED,{originalError:s}))}}function vl(i,e){try{const t=Tt(i);if(!t)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));const n=Et(e);if(!n)return F.err(new Z("Object must expose a Three.js Object3D",X.INVALID_PARAMETER));const s=S=>{var A,L,P;let b=S;for(;b;){if((A=b.userData)!=null&&A.isGrid||(L=b.userData)!=null&&L.isHexGrid||(P=b.userData)!=null&&P.isDefaultGrid)return!0;b=b.parent}return!1};t.updateMatrixWorld(!0);const r=[];t.traverse(S=>{S.isMesh&&s(S)&&r.push(S)});const o=[];if(n.traverse(S=>{S.isMesh&&o.push(S)}),r.length===0||o.length===0)return F.ok(void 0);let a=-1/0;const c=new E.Box3;for(const S of r)c.setFromObject(S),Number.isFinite(c.max.y)&&(a=Math.max(a,c.max.y));if(!Number.isFinite(a))return F.ok(void 0);const u=new E.Box3().setFromObject(n);if(u.isEmpty()||!Number.isFinite(u.min.x)||!Number.isFinite(u.max.x))return F.ok(void 0);const d=40,h=Math.max(1,u.max.y-u.min.y),p=u.max.y+h,m=u.min.y-h,w=new E.Raycaster,x=new E.Vector3(0,-1,0),_=new E.Vector3(0,1,0);let v=1/0;const T=(S,b,A,L)=>{w.set(new E.Vector3(S,b,A),L);for(const P of w.intersectObjects(o,!1))P.point.y<v&&(v=P.point.y)};for(let S=0;S<=d;S++)for(let b=0;b<=d;b++){const A=u.min.x+(u.max.x-u.min.x)*(S/d),L=u.min.z+(u.max.z-u.min.z)*(b/d);T(A,p,L,x),T(A,m,L,_)}if(Number.isFinite(v)){const S=v-a;Math.abs(S)>1e-4&&(n.position.y-=S)}return F.ok(void 0)}catch(t){return F.err(new Z("Failed to snap object to floor",X.SCENE_OPERATION_FAILED,{originalError:t}))}}const Wr=i=>{let e=null;return i.traverse(t=>{!e&&t.isDirectionalLight&&(e=t)}),e};function Ml(i,e){try{const t=Tt(i);if(!t)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));const n=Et(e);if(!n)return F.err(new Z("Object must expose a Three.js Object3D",X.INVALID_PARAMETER));const s=new E.Box3().setFromObject(n);if(s.isEmpty()||!Number.isFinite(s.min.x)||!Number.isFinite(s.max.x))return F.ok(void 0);const r=s.getSize(new E.Vector3),o=s.getCenter(new E.Vector3),a=Wr(t);if(!a||!a.castShadow)return F.ok(void 0);if(a.parent===t&&a.target.parent===t){const m=a.position.clone().sub(a.target.position);a.target.position.copy(o),a.position.copy(o).add(m)}const h=Math.max(r.x,r.y,r.z,.1)*2,p=a.shadow.camera;return p.left=-h,p.right=h,p.top=h,p.bottom=-h,p.updateProjectionMatrix(),F.ok(void 0)}catch(t){return F.err(new Z("Failed to fit shadow camera to object",X.SCENE_OPERATION_FAILED,{originalError:t}))}}function Rl(i,e,t,n){try{const s=Tt(i);if(!s)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));const r=Et(e);if(!r)return F.err(new Z("Object must expose a Three.js Object3D",X.INVALID_PARAMETER));const o=Gr(t.getInternalRenderer());if(!o||!o.shadowMap.enabled)return F.ok(void 0);const a=Wr(s);return!a||!a.castShadow||n.bake({renderer:o,scene:s,object:r,light:a}),F.ok(void 0)}catch(s){return F.err(new Z("Failed to bake contact shadow",X.SCENE_OPERATION_FAILED,{originalError:s}))}}function Cl(i,e){try{const t=Tt(i);if(!t)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));const n=t.getObjectByName(mi),s=t.getObjectByName(Ut);return e==="baked"&&!n||(n&&(n.visible=e==="baked"),s&&(s.visible=e==="live")),F.ok(void 0)}catch(t){return F.err(new Z("Failed to switch contact shadow mode",X.SCENE_OPERATION_FAILED,{originalError:t}))}}function Pl(i,e){try{const t=Et(i);if(!t)return F.err(new Z("Object must expose a Three.js Object3D",X.INVALID_PARAMETER));const n=new E.Group;return n.name=qo,n.scale.setScalar(e),n.add(t),F.ok(new Ke(n))}catch(t){return F.err(new Z("Failed to apply the units scale to the model",X.SCENE_OPERATION_FAILED,{originalError:t}))}}function Il(i,e){try{const t=Tt(i);if(!t)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));if(e.ambient){const n=new E.Color(e.ambient.color||"#404040"),s=e.ambient.intensity??Math.PI,r=new E.AmbientLight(n,s);t.add(r)}if(e.hemisphere){const n=new E.Color(e.hemisphere.skyColor||"#ffffbb"),s=new E.Color(e.hemisphere.groundColor||"#080820"),r=e.hemisphere.intensity??1,o=new E.HemisphereLight(n,s,r);t.add(o)}if(e.directional){const n=new E.Color(e.directional.color||"#ffffff"),s=e.directional.intensity??Math.PI,r=new E.DirectionalLight(n,s);if(e.directional.position){const o=e.directional.position;if(o instanceof E.Vector3)r.position.copy(o);else if(Array.isArray(o))r.position.set(o[0],o[1],o[2]);else if(typeof o=="object"&&"x"in o&&"y"in o&&"z"in o){const a=o;r.position.set(a.x,a.y,a.z)}}else r.position.set(6,6,6);if(e.directional.castShadow&&(r.castShadow=!0,e.directional.shadow)){const o=e.directional.shadow;if(o.mapSize&&(r.shadow.mapSize.width=o.mapSize.width,r.shadow.mapSize.height=o.mapSize.height),o.camera){const a=r.shadow.camera;o.camera.near!==void 0&&(a.near=o.camera.near),o.camera.far!==void 0&&(a.far=o.camera.far),o.camera.left!==void 0&&(a.left=o.camera.left),o.camera.right!==void 0&&(a.right=o.camera.right),o.camera.top!==void 0&&(a.top=o.camera.top),o.camera.bottom!==void 0&&(a.bottom=o.camera.bottom)}o.bias!==void 0&&(r.shadow.bias=o.bias),o.radius!==void 0&&(r.shadow.radius=o.radius)}r.target.position.set(0,0,0),t.add(r),t.add(r.target),r.shadow&&r.shadow.camera.updateProjectionMatrix()}return F.ok(void 0)}catch(t){return F.err(new Z("Failed to add lighting to scene",X.SCENE_OPERATION_FAILED,{originalError:t,options:e}))}}function Ll(i,e){try{const t=Tt(i);if(!t)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));const n=document.createElement("canvas");n.width=2,n.height=512;const s=n.getContext("2d");if(!s)return F.err(new Z("Failed to create canvas context",X.SCENE_OPERATION_FAILED));const r=s.createLinearGradient(0,0,0,n.height);r.addColorStop(0,e.topColor),r.addColorStop(1,e.bottomColor),s.fillStyle=r,s.fillRect(0,0,n.width,n.height);const o=new E.CanvasTexture(n);o.needsUpdate=!0;const a=t.background;return a instanceof E.Texture&&a!==t.environment&&a.dispose(),t.background=o,F.ok(void 0)}catch(t){return F.err(new Z("Failed to create gradient background",X.SCENE_OPERATION_FAILED,{originalError:t,options:e}))}}function Ol(i,e,t){try{const n=Et(i);if(!n)return F.err(new Z("Object must expose a Three.js Object3D",X.INVALID_PARAMETER));const s=Rn(e);if(!(s instanceof E.PerspectiveCamera)&&!(s instanceof E.OrthographicCamera))return F.err(new Z("Camera must expose a perspective or orthographic Three.js camera",X.INVALID_PARAMETER));const r=vi(t);if(!r)return F.err(new Z("Controls must expose the underlying Three.js controls",X.INVALID_PARAMETER));const o=new E.Box3().setFromObject(n),a=o.getCenter(new E.Vector3),c=o.getSize(new E.Vector3),u=Math.max(c.x,c.y,c.z);let d;"fov"in s?d=s.fov*(Math.PI/180):d=50*(Math.PI/180);let h=Math.abs(u/2/Math.tan(d/2));h*=2;const p=-Math.PI/4,m=Math.PI/8,w=a.x+h*Math.sin(p)*Math.cos(m),x=a.y+h*Math.sin(m),_=a.z+h*Math.cos(p)*Math.cos(m);return s.position.set(w,x,_),s.lookAt(a),s.updateProjectionMatrix(),r.target&&(r.target.copy(a),r.update()),F.ok(void 0)}catch(n){return F.err(new Z("Failed to fit camera to object",X.CAMERA_INIT_FAILED,{originalError:n}))}}class Dl{constructor(){this.contactShadowBaker=new gi}addHelpers(e,t){return xl(e,t)}addDynamicGrid(e,t,n=1.2){return Al(e,t,n)}snapObjectToFloor(e,t){return vl(e,t)}fitShadowCameraToObject(e,t){return Ml(e,t)}bakeContactShadow(e,t,n){return Rl(e,t,n,this.contactShadowBaker)}setContactShadowMode(e,t){return Cl(e,t)}wrapInUnitsScaleGroup(e,t){return Pl(e,t)}addLighting(e,t){return Il(e,t)}createGradientBackground(e,t){return Ll(e,t)}fitCameraToObject(e,t,n){return Ol(e,t,n)}}class Nl{constructor(){this.events=new Ts,this.disposed=!1}async initialize(e){const{ThreePathTracingService:t}=await Promise.resolve().then(()=>require("./ThreePathTracingService-BgK90Qzi.cjs"));if(this.disposed)return F.ok(void 0);const n=new t;return this.inner=n,n.events.on("pathtracing:paused",s=>{this.events.emit("pathtracing:paused",s)}),this.pendingSettings&&(n.updateSettings(this.pendingSettings),this.pendingSettings=void 0),this.pendingEnabled!==void 0&&(n.setEnabled(this.pendingEnabled),this.pendingEnabled=void 0),n.initialize(e)}setEnabled(e){this.inner?this.inner.setEnabled(e):this.pendingEnabled=e}updateSettings(e){this.inner?this.inner.updateSettings(e):this.pendingSettings={...this.pendingSettings,...e}}render(e,t){return this.inner?this.inner.render(e,t):Promise.resolve(F.ok(void 0))}getSampleCount(){var e;return((e=this.inner)==null?void 0:e.getSampleCount())??0}isEnabled(){var e;return((e=this.inner)==null?void 0:e.isEnabled())??!1}isPathTracerDisposed(){var e;return((e=this.inner)==null?void 0:e.isPathTracerDisposed())??!1}canResume(){var e;return((e=this.inner)==null?void 0:e.canResume())??!1}reset(e){var t;(t=this.inner)==null||t.reset(e)}dispose(){var e;this.disposed=!0,(e=this.inner)==null||e.dispose()}isSupported(){var e;return((e=this.inner)==null?void 0:e.isSupported())??!0}}/*!
|
|
21
|
+
fflate - fast JavaScript compression/decompression
|
|
22
|
+
<https://101arrowz.github.io/fflate>
|
|
23
|
+
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
|
|
24
|
+
version 0.8.2
|
|
25
|
+
*/var it=Uint8Array,sn=Uint16Array,Fl=Int32Array,Zr=new it([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Kr=new it([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),kl=new it([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Xr=function(i,e){for(var t=new sn(31),n=0;n<31;++n)t[n]=e+=1<<i[n-1];for(var s=new Fl(t[30]),n=1;n<30;++n)for(var r=t[n];r<t[n+1];++r)s[r]=r-t[n]<<5|n;return{b:t,r:s}},Yr=Xr(Zr,2),qr=Yr.b,Bl=Yr.r;qr[28]=258,Bl[258]=28;var zl=Xr(Kr,0),Ul=zl.b,yi=new sn(32768);for(var _e=0;_e<32768;++_e){var Ct=(_e&43690)>>1|(_e&21845)<<1;Ct=(Ct&52428)>>2|(Ct&13107)<<2,Ct=(Ct&61680)>>4|(Ct&3855)<<4,yi[_e]=((Ct&65280)>>8|(Ct&255)<<8)>>1}var bn=(function(i,e,t){for(var n=i.length,s=0,r=new sn(e);s<n;++s)i[s]&&++r[i[s]-1];var o=new sn(e);for(s=1;s<e;++s)o[s]=o[s-1]+r[s-1]<<1;var a;if(t){a=new sn(1<<e);var c=15-e;for(s=0;s<n;++s)if(i[s])for(var u=s<<4|i[s],d=e-i[s],h=o[i[s]-1]++<<d,p=h|(1<<d)-1;h<=p;++h)a[yi[h]>>c]=u}else for(a=new sn(n),s=0;s<n;++s)i[s]&&(a[s]=yi[o[i[s]-1]++]>>15-i[s]);return a}),Cn=new it(288);for(var _e=0;_e<144;++_e)Cn[_e]=8;for(var _e=144;_e<256;++_e)Cn[_e]=9;for(var _e=256;_e<280;++_e)Cn[_e]=7;for(var _e=280;_e<288;++_e)Cn[_e]=8;var $r=new it(32);for(var _e=0;_e<32;++_e)$r[_e]=5;var Vl=bn(Cn,9,1),Hl=bn($r,5,1),Ks=function(i){for(var e=i[0],t=1;t<i.length;++t)i[t]>e&&(e=i[t]);return e},lt=function(i,e,t){var n=e/8|0;return(i[n]|i[n+1]<<8)>>(e&7)&t},Xs=function(i,e){var t=e/8|0;return(i[t]|i[t+1]<<8|i[t+2]<<16)>>(e&7)},jl=function(i){return(i+7)/8|0},Gl=function(i,e,t){return(t==null||t>i.length)&&(t=i.length),new it(i.subarray(e,t))},Wl=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],ut=function(i,e,t){var n=new Error(e||Wl[i]);if(n.code=i,Error.captureStackTrace&&Error.captureStackTrace(n,ut),!t)throw n;return n},Zl=function(i,e,t,n){var s=i.length,r=0;if(!s||e.f&&!e.l)return t||new it(0);var o=!t,a=o||e.i!=2,c=e.i;o&&(t=new it(s*3));var u=function(Ht){var St=t.length;if(Ht>St){var Pn=new it(Math.max(St*2,Ht));Pn.set(t),t=Pn}},d=e.f||0,h=e.p||0,p=e.b||0,m=e.l,w=e.d,x=e.m,_=e.n,v=s*8;do{if(!m){d=lt(i,h,1);var T=lt(i,h+1,3);if(h+=3,T)if(T==1)m=Vl,w=Hl,x=9,_=5;else if(T==2){var L=lt(i,h,31)+257,P=lt(i,h+10,15)+4,C=L+lt(i,h+5,31)+1;h+=14;for(var D=new it(C),I=new it(19),k=0;k<P;++k)I[kl[k]]=lt(i,h+k*3,7);h+=P*3;for(var N=Ks(I),H=(1<<N)-1,G=bn(I,N,1),k=0;k<C;){var $=G[lt(i,h,H)];h+=$&15;var S=$>>4;if(S<16)D[k++]=S;else{var re=0,Ne=0;for(S==16?(Ne=3+lt(i,h,3),h+=2,re=D[k-1]):S==17?(Ne=3+lt(i,h,7),h+=3):S==18&&(Ne=11+lt(i,h,127),h+=7);Ne--;)D[k++]=re}}var ot=D.subarray(0,L),Re=D.subarray(L);x=Ks(ot),_=Ks(Re),m=bn(ot,x,1),w=bn(Re,_,1)}else ut(1);else{var S=jl(h)+4,b=i[S-4]|i[S-3]<<8,A=S+b;if(A>s){c&&ut(0);break}a&&u(p+b),t.set(i.subarray(S,A),p),e.b=p+=b,e.p=h=A*8,e.f=d;continue}if(h>v){c&&ut(0);break}}a&&u(p+131072);for(var ze=(1<<x)-1,je=(1<<_)-1,ve=h;;ve=h){var re=m[Xs(i,h)&ze],ye=re>>4;if(h+=re&15,h>v){c&&ut(0);break}if(re||ut(2),ye<256)t[p++]=ye;else if(ye==256){ve=h,m=null;break}else{var pt=ye-254;if(ye>264){var k=ye-257,Ge=Zr[k];pt=lt(i,h,(1<<Ge)-1)+qr[k],h+=Ge}var At=w[Xs(i,h)&je],ge=At>>4;At||ut(3),h+=At&15;var Re=Ul[ge];if(ge>3){var Ge=Kr[ge];Re+=Xs(i,h)&(1<<Ge)-1,h+=Ge}if(h>v){c&&ut(0);break}a&&u(p+131072);var at=p+pt;if(p<Re){var ct=r-Re,an=Math.min(Re,at);for(ct+p<0&&ut(3);p<an;++p)t[p]=n[ct+p]}for(;p<at;++p)t[p]=t[p-Re]}}e.l=m,e.p=ve,e.b=p,e.f=d,m&&(d=1,e.m=x,e.d=w,e.n=_)}while(!d);return p!=t.length&&o?Gl(t,0,p):t.subarray(0,p)},Kl=new it(0),Xl=function(i,e){return((i[0]&15)!=8||i[0]>>4>7||(i[0]<<8|i[1])%31)&&ut(6,"invalid zlib data"),(i[1]>>5&1)==1&&ut(6,"invalid zlib data: "+(i[1]&32?"need":"unexpected")+" dictionary"),(i[1]>>3&4)+2};function En(i,e){return Zl(i.subarray(Xl(i),-4),{i:2},e,e)}var Yl=typeof TextDecoder<"u"&&new TextDecoder,ql=0;try{Yl.decode(Kl,{stream:!0}),ql=1}catch{}class $l extends f.DataTextureLoader{constructor(e){super(e),this.type=f.HalfFloatType,this.outputFormat=f.RGBAFormat,this.part=0}parse(e){const D=Math.pow(2.7182818,2.2);let I=null;function k(l,g){let y=0;for(let O=0;O<65536;++O)(O==0||l[O>>3]&1<<(O&7))&&(g[y++]=O);const R=y-1;for(;y<65536;)g[y++]=0;return R}function N(l){for(let g=0;g<16384;g++)l[g]={},l[g].len=0,l[g].lit=0,l[g].p=null}const H={l:0,c:0,lc:0};function G(l,g,y,R,O){for(;y<l;)g=g<<8|Ni(R,O),y+=8;y-=l,H.l=g>>y&(1<<l)-1,H.c=g,H.lc=y}const $=new Array(59);function re(l){for(let y=0;y<=58;++y)$[y]=0;for(let y=0;y<65537;++y)$[l[y]]+=1;let g=0;for(let y=58;y>0;--y){const R=g+$[y]>>1;$[y]=g,g=R}for(let y=0;y<65537;++y){const R=l[y];R>0&&(l[y]=R|$[R]++<<6)}}function Ne(l,g,y,R,O,z){const M=g;let V=0,B=0;for(;R<=O;R++){if(M.value-g.value>y)return!1;G(6,V,B,l,M);const U=H.l;if(V=H.c,B=H.lc,z[R]=U,U==63){if(M.value-g.value>y)throw new Error("THREE.EXRLoader: Something wrong with hufUnpackEncTable");G(8,V,B,l,M);let j=H.l+6;if(V=H.c,B=H.lc,R+j>O+1)throw new Error("THREE.EXRLoader: Something wrong with hufUnpackEncTable");for(;j--;)z[R++]=0;R--}else if(U>=59){let j=U-59+2;if(R+j>O+1)throw new Error("THREE.EXRLoader: Something wrong with hufUnpackEncTable");for(;j--;)z[R++]=0;R--}}re(z)}function ot(l){return l&63}function Re(l){return l>>6}function ze(l,g,y,R){for(;g<=y;g++){const O=Re(l[g]),z=ot(l[g]);if(O>>z)throw new Error("THREE.EXRLoader: Invalid table entry");if(z>14){const M=R[O>>z-14];if(M.len)throw new Error("THREE.EXRLoader: Invalid table entry");if(M.lit++,M.p){const V=M.p;M.p=new Array(M.lit);for(let B=0;B<M.lit-1;++B)M.p[B]=V[B]}else M.p=new Array(1);M.p[M.lit-1]=g}else if(z){let M=0;for(let V=1<<14-z;V>0;V--){const B=R[(O<<14-z)+M];if(B.len||B.p)throw new Error("THREE.EXRLoader: Invalid table entry");B.len=z,B.lit=g,M++}}}return!0}const je={c:0,lc:0};function ve(l,g,y,R){l=l<<8|Ni(y,R),g+=8,je.c=l,je.lc=g}const ye={c:0,lc:0};function pt(l,g,y,R,O,z,M,V,B){if(l==g){R<8&&(ve(y,R,O,z),y=je.c,R=je.lc),R-=8;let U=y>>R;if(U=new Uint8Array([U])[0],V.value+U>B)return!1;const j=M[V.value-1];for(;U-- >0;)M[V.value++]=j}else if(V.value<B)M[V.value++]=l;else return!1;ye.c=y,ye.lc=R}function Ge(l){return l&65535}function At(l){const g=Ge(l);return g>32767?g-65536:g}const ge={a:0,b:0};function at(l,g){const y=At(l),O=At(g),z=y+(O&1)+(O>>1),M=z,V=z-O;ge.a=M,ge.b=V}function ct(l,g){const y=Ge(l),R=Ge(g),O=y-(R>>1)&65535,z=R+O-32768&65535;ge.a=z,ge.b=O}function an(l,g,y,R,O,z,M){const V=M<16384,B=y>O?O:y;let U=1,j,K;for(;U<=B;)U<<=1;for(U>>=1,j=U,U>>=1;U>=1;){K=0;const W=K+z*(O-j),q=z*U,ee=z*j,Y=R*U,Q=R*j;let oe,he,ae,de;for(;K<=W;K+=ee){let ne=K;const te=K+R*(y-j);for(;ne<=te;ne+=Q){const ie=ne+Y,we=ne+q,fe=we+Y;V?(at(l[ne+g],l[we+g]),oe=ge.a,ae=ge.b,at(l[ie+g],l[fe+g]),he=ge.a,de=ge.b,at(oe,he),l[ne+g]=ge.a,l[ie+g]=ge.b,at(ae,de),l[we+g]=ge.a,l[fe+g]=ge.b):(ct(l[ne+g],l[we+g]),oe=ge.a,ae=ge.b,ct(l[ie+g],l[fe+g]),he=ge.a,de=ge.b,ct(oe,he),l[ne+g]=ge.a,l[ie+g]=ge.b,ct(ae,de),l[we+g]=ge.a,l[fe+g]=ge.b)}if(y&U){const ie=ne+q;V?at(l[ne+g],l[ie+g]):ct(l[ne+g],l[ie+g]),oe=ge.a,l[ie+g]=ge.b,l[ne+g]=oe}}if(O&U){let ne=K;const te=K+R*(y-j);for(;ne<=te;ne+=Q){const ie=ne+Y;V?at(l[ne+g],l[ie+g]):ct(l[ne+g],l[ie+g]),oe=ge.a,l[ie+g]=ge.b,l[ne+g]=oe}}j=U,U>>=1}return K}function Ht(l,g,y,R,O,z,M,V,B){let U=0,j=0;const K=M,W=Math.trunc(R.value+(O+7)/8);for(;R.value<W;)for(ve(U,j,y,R),U=je.c,j=je.lc;j>=14;){const ee=U>>j-14&16383,Y=g[ee];if(Y.len)j-=Y.len,pt(Y.lit,z,U,j,y,R,V,B,K),U=ye.c,j=ye.lc;else{if(!Y.p)throw new Error("THREE.EXRLoader: hufDecode issues");let Q;for(Q=0;Q<Y.lit;Q++){const oe=ot(l[Y.p[Q]]);for(;j<oe&&R.value<W;)ve(U,j,y,R),U=je.c,j=je.lc;if(j>=oe&&Re(l[Y.p[Q]])==(U>>j-oe&(1<<oe)-1)){j-=oe,pt(Y.p[Q],z,U,j,y,R,V,B,K),U=ye.c,j=ye.lc;break}}if(Q==Y.lit)throw new Error("THREE.EXRLoader: hufDecode issues")}}const q=8-O&7;for(U>>=q,j-=q;j>0;){const ee=g[U<<14-j&16383];if(ee.len)j-=ee.len,pt(ee.lit,z,U,j,y,R,V,B,K),U=ye.c,j=ye.lc;else throw new Error("THREE.EXRLoader: hufDecode issues")}return!0}function St(l,g,y,R,O,z){const M={value:0},V=y.value,B=Je(g,y),U=Je(g,y);y.value+=4;const j=Je(g,y);if(y.value+=4,B<0||B>=65537||U<0||U>=65537)throw new Error("THREE.EXRLoader: Something wrong with HUF_ENCSIZE");const K=new Array(65537),W=new Array(16384);N(W);const q=R-(y.value-V);if(Ne(l,y,q,B,U,K),j>8*(R-(y.value-V)))throw new Error("THREE.EXRLoader: Something wrong with hufUncompress");ze(K,B,U,W),Ht(K,W,l,y,j,U,z,O,M)}function Pn(l,g,y){for(let R=0;R<y;++R)g[R]=l[g[R]]}function In(l){for(let g=1;g<l.length;g++){const y=l[g-1]+l[g]-128;l[g]=y}}function Ln(l,g){let y=0,R=Math.floor((l.length+1)/2),O=0;const z=l.length-1;for(;!(O>z||(g[O++]=l[y++],O>z));)g[O++]=l[R++]}function Ms(l){let g=l.byteLength;const y=new Array;let R=0;const O=new DataView(l);for(;g>0;){const z=O.getInt8(R++);if(z<0){const M=-z;g-=M+1;for(let V=0;V<M;V++)y.push(O.getUint8(R++))}else{const M=z;g-=2;const V=O.getUint8(R++);for(let B=0;B<M+1;B++)y.push(V)}}return y}function ho(l,g,y,R,O,z){let M=new DataView(z.buffer);const V=y[l.idx[0]].width,B=y[l.idx[0]].height,U=3,j=Math.floor(V/8),K=Math.ceil(V/8),W=Math.ceil(B/8),q=V-(K-1)*8,ee=B-(W-1)*8,Y={value:0},Q=new Array(U),oe=new Array(U),he=new Array(U),ae=new Array(U),de=new Array(U);for(let te=0;te<U;++te)de[te]=g[l.idx[te]],Q[te]=te<1?0:Q[te-1]+K*W,oe[te]=new Float32Array(64),he[te]=new Uint16Array(64),ae[te]=new Uint16Array(K*64);for(let te=0;te<W;++te){let ie=8;te==W-1&&(ie=ee);let we=8;for(let ce=0;ce<K;++ce){ce==K-1&&(we=q);for(let ue=0;ue<U;++ue)he[ue].fill(0),he[ue][0]=O[Q[ue]++],Pi(Y,R,he[ue]),Ii(he[ue],oe[ue]),Li(oe[ue]);po(oe);for(let ue=0;ue<U;++ue)Oi(oe[ue],ae[ue],ce*64)}let fe=0;for(let ce=0;ce<U;++ce){const ue=y[l.idx[ce]].type;for(let Ce=8*te;Ce<8*te+ie;++Ce){fe=de[ce][Ce];for(let et=0;et<j;++et){const Se=et*64+(Ce&7)*8;M.setUint16(fe+0*ue,ae[ce][Se+0],!0),M.setUint16(fe+2*ue,ae[ce][Se+1],!0),M.setUint16(fe+4*ue,ae[ce][Se+2],!0),M.setUint16(fe+6*ue,ae[ce][Se+3],!0),M.setUint16(fe+8*ue,ae[ce][Se+4],!0),M.setUint16(fe+10*ue,ae[ce][Se+5],!0),M.setUint16(fe+12*ue,ae[ce][Se+6],!0),M.setUint16(fe+14*ue,ae[ce][Se+7],!0),fe+=16*ue}}if(j!=K)for(let Ce=8*te;Ce<8*te+ie;++Ce){const et=de[ce][Ce]+8*j*2*ue,Se=j*64+(Ce&7)*8;for(let ft=0;ft<we;++ft)M.setUint16(et+ft*2*ue,ae[ce][Se+ft],!0)}}}const ne=new Uint16Array(V);M=new DataView(z.buffer);for(let te=0;te<U;++te){y[l.idx[te]].decoded=!0;const ie=y[l.idx[te]].type;if(y[te].type==2)for(let we=0;we<B;++we){const fe=de[te][we];for(let ce=0;ce<V;++ce)ne[ce]=M.getUint16(fe+ce*2*ie,!0);for(let ce=0;ce<V;++ce)M.setFloat32(fe+ce*2*ie,J(ne[ce]),!0)}}}function uo(l,g,y,R,O,z){const M=new DataView(z.buffer),V=y[l],B=V.width,U=V.height,j=Math.ceil(B/8),K=Math.ceil(U/8),W=Math.floor(B/8),q=B-(j-1)*8,ee=U-(K-1)*8,Y={value:0};let Q=0;const oe=new Float32Array(64),he=new Uint16Array(64),ae=new Uint16Array(j*64);for(let de=0;de<K;++de){let ne=8;de==K-1&&(ne=ee);for(let te=0;te<j;++te)he.fill(0),he[0]=O[Q++],Pi(Y,R,he),Ii(he,oe),Li(oe),Oi(oe,ae,te*64);for(let te=8*de;te<8*de+ne;++te){let ie=g[l][te];for(let we=0;we<W;++we){const fe=we*64+(te&7)*8;for(let ce=0;ce<8;++ce)M.setUint16(ie+ce*2*V.type,ae[fe+ce],!0);ie+=16*V.type}if(j!=W){const we=W*64+(te&7)*8;for(let fe=0;fe<q;++fe)M.setUint16(ie+fe*2*V.type,ae[we+fe],!0)}}}V.decoded=!0}function Pi(l,g,y){let R,O=1;for(;O<64;)R=g[l.value],R==65280?O=64:R>>8==255?O+=R&255:(y[O]=R,O++),l.value++}function Ii(l,g){g[0]=J(l[0]),g[1]=J(l[1]),g[2]=J(l[5]),g[3]=J(l[6]),g[4]=J(l[14]),g[5]=J(l[15]),g[6]=J(l[27]),g[7]=J(l[28]),g[8]=J(l[2]),g[9]=J(l[4]),g[10]=J(l[7]),g[11]=J(l[13]),g[12]=J(l[16]),g[13]=J(l[26]),g[14]=J(l[29]),g[15]=J(l[42]),g[16]=J(l[3]),g[17]=J(l[8]),g[18]=J(l[12]),g[19]=J(l[17]),g[20]=J(l[25]),g[21]=J(l[30]),g[22]=J(l[41]),g[23]=J(l[43]),g[24]=J(l[9]),g[25]=J(l[11]),g[26]=J(l[18]),g[27]=J(l[24]),g[28]=J(l[31]),g[29]=J(l[40]),g[30]=J(l[44]),g[31]=J(l[53]),g[32]=J(l[10]),g[33]=J(l[19]),g[34]=J(l[23]),g[35]=J(l[32]),g[36]=J(l[39]),g[37]=J(l[45]),g[38]=J(l[52]),g[39]=J(l[54]),g[40]=J(l[20]),g[41]=J(l[22]),g[42]=J(l[33]),g[43]=J(l[38]),g[44]=J(l[46]),g[45]=J(l[51]),g[46]=J(l[55]),g[47]=J(l[60]),g[48]=J(l[21]),g[49]=J(l[34]),g[50]=J(l[37]),g[51]=J(l[47]),g[52]=J(l[50]),g[53]=J(l[56]),g[54]=J(l[59]),g[55]=J(l[61]),g[56]=J(l[35]),g[57]=J(l[36]),g[58]=J(l[48]),g[59]=J(l[49]),g[60]=J(l[57]),g[61]=J(l[58]),g[62]=J(l[62]),g[63]=J(l[63])}function Li(l){const g=.5*Math.cos(.7853975),y=.5*Math.cos(3.14159/16),R=.5*Math.cos(3.14159/8),O=.5*Math.cos(3*3.14159/16),z=.5*Math.cos(5*3.14159/16),M=.5*Math.cos(3*3.14159/8),V=.5*Math.cos(7*3.14159/16),B=new Array(4),U=new Array(4),j=new Array(4),K=new Array(4);for(let W=0;W<8;++W){const q=W*8;B[0]=R*l[q+2],B[1]=M*l[q+2],B[2]=R*l[q+6],B[3]=M*l[q+6],U[0]=y*l[q+1]+O*l[q+3]+z*l[q+5]+V*l[q+7],U[1]=O*l[q+1]-V*l[q+3]-y*l[q+5]-z*l[q+7],U[2]=z*l[q+1]-y*l[q+3]+V*l[q+5]+O*l[q+7],U[3]=V*l[q+1]-z*l[q+3]+O*l[q+5]-y*l[q+7],j[0]=g*(l[q+0]+l[q+4]),j[3]=g*(l[q+0]-l[q+4]),j[1]=B[0]+B[3],j[2]=B[1]-B[2],K[0]=j[0]+j[1],K[1]=j[3]+j[2],K[2]=j[3]-j[2],K[3]=j[0]-j[1],l[q+0]=K[0]+U[0],l[q+1]=K[1]+U[1],l[q+2]=K[2]+U[2],l[q+3]=K[3]+U[3],l[q+4]=K[3]-U[3],l[q+5]=K[2]-U[2],l[q+6]=K[1]-U[1],l[q+7]=K[0]-U[0]}for(let W=0;W<8;++W)B[0]=R*l[16+W],B[1]=M*l[16+W],B[2]=R*l[48+W],B[3]=M*l[48+W],U[0]=y*l[8+W]+O*l[24+W]+z*l[40+W]+V*l[56+W],U[1]=O*l[8+W]-V*l[24+W]-y*l[40+W]-z*l[56+W],U[2]=z*l[8+W]-y*l[24+W]+V*l[40+W]+O*l[56+W],U[3]=V*l[8+W]-z*l[24+W]+O*l[40+W]-y*l[56+W],j[0]=g*(l[W]+l[32+W]),j[3]=g*(l[W]-l[32+W]),j[1]=B[0]+B[3],j[2]=B[1]-B[2],K[0]=j[0]+j[1],K[1]=j[3]+j[2],K[2]=j[3]-j[2],K[3]=j[0]-j[1],l[0+W]=K[0]+U[0],l[8+W]=K[1]+U[1],l[16+W]=K[2]+U[2],l[24+W]=K[3]+U[3],l[32+W]=K[3]-U[3],l[40+W]=K[2]-U[2],l[48+W]=K[1]-U[1],l[56+W]=K[0]-U[0]}function po(l){for(let g=0;g<64;++g){const y=l[0][g],R=l[1][g],O=l[2][g];l[0][g]=y+1.5747*O,l[1][g]=y-.1873*R-.4682*O,l[2][g]=y+1.8556*R}}function Oi(l,g,y){for(let R=0;R<64;++R)g[y+R]=f.DataUtils.toHalfFloat(fo(l[R]))}function fo(l){return l<=1?Math.sign(l)*Math.pow(Math.abs(l),2.2):Math.sign(l)*Math.pow(D,Math.abs(l)-1)}function On(l){return new DataView(l.array.buffer,l.offset.value,l.size)}function mo(l){const g=l.viewer.buffer.slice(l.offset.value,l.offset.value+l.size),y=new Uint8Array(Ms(g)),R=new Uint8Array(y.length);return In(y),Ln(y,R),new DataView(R.buffer)}function Rs(l){const g=l.array.slice(l.offset.value,l.offset.value+l.size),y=En(g),R=new Uint8Array(y.length);return In(y),Ln(y,R),new DataView(R.buffer)}function go(l){const g=l.viewer,y={value:l.offset.value},R=new Uint16Array(l.columns*l.lines*(l.inputChannels.length*l.type)),O=new Uint8Array(8192);let z=0;const M=new Array(l.inputChannels.length);for(let ee=0,Y=l.inputChannels.length;ee<Y;ee++)M[ee]={},M[ee].start=z,M[ee].end=M[ee].start,M[ee].nx=l.columns,M[ee].ny=l.lines,M[ee].size=l.type,z+=M[ee].nx*M[ee].ny*M[ee].size;const V=cn(g,y),B=cn(g,y);if(B>=8192)throw new Error("THREE.EXRLoader: Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(V<=B)for(let ee=0;ee<B-V+1;ee++)O[ee+V]=vt(g,y);const U=new Uint16Array(65536),j=k(O,U),K=Je(g,y);St(l.array,g,y,K,R,z);for(let ee=0;ee<l.inputChannels.length;++ee){const Y=M[ee];for(let Q=0;Q<M[ee].size;++Q)an(R,Y.start+Q,Y.nx,Y.size,Y.ny,Y.nx*Y.size,j)}Pn(U,R,z);let W=0;const q=new Uint8Array(R.buffer.byteLength);for(let ee=0;ee<l.lines;ee++)for(let Y=0;Y<l.inputChannels.length;Y++){const Q=M[Y],oe=Q.nx*Q.size,he=new Uint8Array(R.buffer,Q.end*2,oe*2);q.set(he,W),W+=oe*2,Q.end+=oe}return new DataView(q.buffer)}function yo(l){const g=l.array.slice(l.offset.value,l.offset.value+l.size),y=En(g),R=l.inputChannels.length*l.lines*l.columns*l.totalBytes,O=new ArrayBuffer(R),z=new DataView(O);let M=0,V=0;const B=new Array(4);for(let U=0;U<l.lines;U++)for(let j=0;j<l.inputChannels.length;j++){let K=0;switch(l.inputChannels[j].pixelType){case 1:B[0]=M,B[1]=B[0]+l.columns,M=B[1]+l.columns;for(let q=0;q<l.columns;++q){const ee=y[B[0]++]<<8|y[B[1]++];K+=ee,z.setUint16(V,K,!0),V+=2}break;case 2:B[0]=M,B[1]=B[0]+l.columns,B[2]=B[1]+l.columns,M=B[2]+l.columns;for(let q=0;q<l.columns;++q){const ee=y[B[0]++]<<24|y[B[1]++]<<16|y[B[2]++]<<8;K+=ee,z.setUint32(V,K,!0),V+=4}break}}return z}function wo(l){const g=l.array;let y=l.offset.value;const R=l.columns,O=l.lines,z=l.inputChannels,M=l.totalBytes,V=Ze.compression==="B44A_COMPRESSION",B=new Uint8Array(O*R*M),U=new Uint16Array(16);let j=0;for(let K=0;K<z.length;K++){const W=z[K],q=W.pixelType*2,ee=Math.ceil(R/W.xSampling),Y=Math.ceil(O/W.ySampling),Q=W.xSampling===1&&W.ySampling===1;if(W.pixelType!==1){for(let ae=0;ae<Y;ae++)if(Q){const de=ae*R*M+j*R;for(let ne=0;ne<ee*q;ne++)B[de+ne]=g[y++]}else y+=ee*q;j+=q;continue}const oe=Math.ceil(ee/4),he=Math.ceil(Y/4);for(let ae=0;ae<he;ae++)for(let de=0;de<oe;de++){if(V&&g[y+2]>=52){const ne=g[y]<<8|g[y+1],te=ne&32768?ne&32767:~ne&65535;U.fill(te),y+=3}else{const ne=g[y]<<8|g[y+1],te=g[y+2]>>2,ie=32<<te,we=ne+((g[y+2]<<4|g[y+3]>>4)&63)*(1<<te)-ie&65535,fe=we+((g[y+3]<<2|g[y+4]>>6)&63)*(1<<te)-ie&65535,ce=fe+(g[y+4]&63)*(1<<te)-ie&65535,ue=ne+(g[y+5]>>2&63)*(1<<te)-ie&65535,Ce=we+((g[y+5]<<4|g[y+6]>>4)&63)*(1<<te)-ie&65535,et=fe+((g[y+6]<<2|g[y+7]>>6)&63)*(1<<te)-ie&65535,Se=ce+(g[y+7]&63)*(1<<te)-ie&65535,ft=ue+(g[y+8]>>2&63)*(1<<te)-ie&65535,jt=Ce+((g[y+8]<<4|g[y+9]>>4)&63)*(1<<te)-ie&65535,ln=et+((g[y+9]<<2|g[y+10]>>6)&63)*(1<<te)-ie&65535,mt=Se+(g[y+10]&63)*(1<<te)-ie&65535,Nt=ft+(g[y+11]>>2&63)*(1<<te)-ie&65535,Bn=jt+((g[y+11]<<4|g[y+12]>>4)&63)*(1<<te)-ie&65535,zn=ln+((g[y+12]<<2|g[y+13]>>6)&63)*(1<<te)-ie&65535,Un=mt+(g[y+13]&63)*(1<<te)-ie&65535,hn=[ne,ue,ft,Nt,we,Ce,jt,Bn,fe,et,ln,zn,ce,Se,mt,Un];for(let Gt=0;Gt<16;Gt++)U[Gt]=hn[Gt]&32768?hn[Gt]&32767:~hn[Gt]&65535;y+=14}if(W.pLinear){if(I===null){I=new Uint16Array(65536);for(let ne=0;ne<65536;ne++)if((ne&31744)===31744||ne>32768)I[ne]=0;else{const te=J(ne);I[ne]=te<=0?0:f.DataUtils.toHalfFloat(8*Math.log(te))}}for(let ne=0;ne<16;ne++)U[ne]=I[U[ne]]}for(let ne=0;ne<4;ne++){const te=ae*4+ne;if(!(te>=Y))for(let ie=0;ie<4;ie++){const we=de*4+ie;if(we>=ee)continue;const fe=U[ne*4+ie];for(let ce=0;ce<W.ySampling;ce++){const ue=te*W.ySampling+ce;if(!(ue>=O))for(let Ce=0;Ce<W.xSampling;Ce++){const et=we*W.xSampling+Ce;if(et>=R)continue;const Se=ue*R*M+j*R+et*2;B[Se]=fe&255,B[Se+1]=fe>>8&255}}}}}j+=2}return new DataView(B.buffer)}function Di(l){const g=l.viewer,y={value:l.offset.value},R=new Uint8Array(l.columns*l.lines*(l.inputChannels.length*l.type*2)),O={version:Fe(g,y),unknownUncompressedSize:Fe(g,y),unknownCompressedSize:Fe(g,y),acCompressedSize:Fe(g,y),dcCompressedSize:Fe(g,y),rleCompressedSize:Fe(g,y),rleUncompressedSize:Fe(g,y),rleRawSize:Fe(g,y),totalAcUncompressedCount:Fe(g,y),totalDcUncompressedCount:Fe(g,y),acCompression:Fe(g,y)};if(O.version<2)throw new Error("THREE.EXRLoader: "+Ze.compression+" version "+O.version+" is unsupported");const z=new Array;let M=cn(g,y)-2;for(;M>0;){const Y=Dn(g.buffer,y),Q=vt(g,y),oe=Q>>2&3,he=(Q>>4)-1,ae=new Int8Array([he])[0],de=vt(g,y);z.push({name:Y,index:ae,type:de,compression:oe}),M-=Y.length+3}const V=Ze.channels,B=new Array(l.inputChannels.length);for(let Y=0;Y<l.inputChannels.length;++Y){const Q=B[Y]={},oe=V[Y];Q.name=oe.name,Q.compression=0,Q.decoded=!1,Q.type=oe.pixelType,Q.pLinear=oe.pLinear,Q.width=l.columns,Q.height=l.lines}const U={idx:new Array(3)};for(let Y=0;Y<l.inputChannels.length;++Y){const Q=B[Y],oe=Q.name.lastIndexOf("."),he=oe>=0?Q.name.substring(oe+1):Q.name;for(let ae=0;ae<z.length;++ae){const de=z[ae];he===de.name&&Q.type===de.type&&(Q.compression=de.compression,de.index>=0&&(U.idx[de.index]=Y),Q.offset=Y)}}let j,K,W;if(O.acCompressedSize>0)switch(O.acCompression){case 0:j=new Uint16Array(O.totalAcUncompressedCount),St(l.array,g,y,O.acCompressedSize,j,O.totalAcUncompressedCount);break;case 1:const Y=l.array.slice(y.value,y.value+O.totalAcUncompressedCount),Q=En(Y);j=new Uint16Array(Q.buffer),y.value+=O.totalAcUncompressedCount;break}if(O.dcCompressedSize>0){const Y={array:l.array,offset:y,size:O.dcCompressedSize};K=new Uint16Array(Rs(Y).buffer),y.value+=O.dcCompressedSize}if(O.rleRawSize>0){const Y=l.array.slice(y.value,y.value+O.rleCompressedSize),Q=En(Y);W=Ms(Q.buffer),y.value+=O.rleCompressedSize}let q=0;const ee=new Array(B.length);for(let Y=0;Y<ee.length;++Y)ee[Y]=new Array;for(let Y=0;Y<l.lines;++Y)for(let Q=0;Q<B.length;++Q)ee[Q].push(q),q+=B[Q].width*l.type*2;U.idx[0]!==void 0&&B[U.idx[0]]&&ho(U,ee,B,j,K,R);for(let Y=0;Y<B.length;++Y){const Q=B[Y];if(!Q.decoded)switch(Q.compression){case 2:let oe=0,he=0;for(let ae=0;ae<l.lines;++ae){let de=ee[Y][oe];for(let ne=0;ne<Q.width;++ne){for(let te=0;te<2*Q.type;++te)R[de++]=W[he+te*Q.width*Q.height];he++}oe++}break;case 1:uo(Y,ee,B,j,K,R);break;default:throw new Error("THREE.EXRLoader: unsupported channel compression")}}return new DataView(R.buffer)}function Dn(l,g){const y=new Uint8Array(l);let R=0;for(;y[g.value+R]!=0;)R+=1;const O=new TextDecoder().decode(y.slice(g.value,g.value+R));return g.value=g.value+R+1,O}function Eo(l,g,y){const R=new TextDecoder().decode(new Uint8Array(l).slice(g.value,g.value+y));return g.value=g.value+y,R}function To(l,g){const y=qe(l,g),R=Je(l,g);return[y,R]}function So(l,g){const y=Je(l,g),R=Je(l,g);return[y,R]}function qe(l,g){const y=l.getInt32(g.value,!0);return g.value=g.value+4,y}function Je(l,g){const y=l.getUint32(g.value,!0);return g.value=g.value+4,y}function Ni(l,g){const y=l[g.value];return g.value=g.value+1,y}function vt(l,g){const y=l.getUint8(g.value);return g.value=g.value+1,y}const Fe=function(l,g){const y=Number(l.getBigInt64(g.value,!0));return g.value+=8,y};function We(l,g){const y=l.getFloat32(g.value,!0);return g.value+=4,y}function _o(l,g){return f.DataUtils.toHalfFloat(We(l,g))}function J(l){const g=(l&31744)>>10,y=l&1023;return(l>>15?-1:1)*(g?g===31?y?NaN:1/0:Math.pow(2,g-15)*(1+y/1024):6103515625e-14*(y/1024))}function cn(l,g){const y=l.getUint16(g.value,!0);return g.value+=2,y}function bo(l,g){return J(cn(l,g))}function xo(l,g,y,R){const O=y.value,z=[];for(;y.value<O+R-1;){const M=Dn(g,y),V=qe(l,y),B=vt(l,y);y.value+=3;const U=qe(l,y),j=qe(l,y);z.push({name:M,pixelType:V,pLinear:B,xSampling:U,ySampling:j})}return y.value+=1,z}function Ao(l,g){const y=We(l,g),R=We(l,g),O=We(l,g),z=We(l,g),M=We(l,g),V=We(l,g),B=We(l,g),U=We(l,g);return{redX:y,redY:R,greenX:O,greenY:z,blueX:M,blueY:V,whiteX:B,whiteY:U}}function vo(l,g){const y=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],R=vt(l,g);return y[R]}function Mo(l,g){const y=qe(l,g),R=qe(l,g),O=qe(l,g),z=qe(l,g);return{xMin:y,yMin:R,xMax:O,yMax:z}}function Ro(l,g){const y=["INCREASING_Y","DECREASING_Y","RANDOM_Y"],R=vt(l,g);return y[R]}function Co(l,g){const y=["ENVMAP_LATLONG","ENVMAP_CUBE"],R=vt(l,g);return y[R]}function Po(l,g){const y=["ONE_LEVEL","MIPMAP_LEVELS","RIPMAP_LEVELS"],R=["ROUND_DOWN","ROUND_UP"],O=Je(l,g),z=Je(l,g),M=vt(l,g);return{xSize:O,ySize:z,levelMode:y[M&15],roundingMode:R[M>>4]}}function Io(l,g){const y=We(l,g),R=We(l,g);return[y,R]}function Lo(l,g){const y=We(l,g),R=We(l,g),O=We(l,g);return[y,R,O]}function Oo(l,g,y,R,O){if(R==="string"||R==="stringvector"||R==="iccProfile")return Eo(g,y,O);if(R==="chlist")return xo(l,g,y,O);if(R==="chromaticities")return Ao(l,y);if(R==="compression")return vo(l,y);if(R==="box2i")return Mo(l,y);if(R==="envmap")return Co(l,y);if(R==="tiledesc")return Po(l,y);if(R==="lineOrder")return Ro(l,y);if(R==="float")return We(l,y);if(R==="v2f")return Io(l,y);if(R==="v3f")return Lo(l,y);if(R==="int")return qe(l,y);if(R==="rational")return To(l,y);if(R==="timecode")return So(l,y);if(R==="preview"||R==="deepImageState"||R==="idmanifest")return y.value+=O,"skipped";y.value+=O}function Do(l,g){const y=Math.log2(l);return g=="ROUND_DOWN"?Math.floor(y):Math.ceil(y)}function No(l,g,y){let R=0;switch(l.levelMode){case"ONE_LEVEL":R=1;break;case"MIPMAP_LEVELS":R=Do(Math.max(g,y),l.roundingMode)+1;break;case"RIPMAP_LEVELS":throw new Error("THREE.EXRLoader: RIPMAP_LEVELS tiles currently unsupported.")}return R}function Fi(l,g,y,R){const O=new Array(l);for(let z=0;z<l;z++){const M=1<<z;let V=g/M|0;R=="ROUND_UP"&&V*M<g&&(V+=1);const B=Math.max(V,1);O[z]=(B+y-1)/y|0}return O}function Fo(){const l=this,g=l.offset,y={value:0};for(let R=0;R<l.tileCount;R++){const O=qe(l.viewer,g),z=qe(l.viewer,g);g.value+=8,l.size=Je(l.viewer,g);const M=O*l.blockWidth,V=z*l.blockHeight;l.columns=M+l.blockWidth>l.width?l.width-M:l.blockWidth,l.lines=V+l.blockHeight>l.height?l.height-V:l.blockHeight;const B=l.columns*l.totalBytes,j=l.size<l.lines*B?l.uncompress(l):On(l);g.value+=l.size;for(let K=0;K<l.lines;K++){const W=K*l.columns*l.totalBytes;for(let q=0;q<l.inputChannels.length;q++){const ee=Ze.channels[q].name,Y=l.channelByteOffsets[ee]*l.columns,Q=l.decodeChannels[ee];if(Q===void 0)continue;y.value=W+Y;const oe=(l.height-(1+V+K))*l.outLineWidth;for(let he=0;he<l.columns;he++){const ae=oe+(he+M)*l.outputChannels+Q;l.byteArray[ae]=l.getter(j,y)}}}}}function ko(){const l=this,g=l.offset,y={value:0};for(let R=0;R<l.height/l.blockHeight;R++){const O=qe(l.viewer,g)-Ze.dataWindow.yMin;l.size=Je(l.viewer,g),l.lines=O+l.blockHeight>l.height?l.height-O:l.blockHeight;const z=l.columns*l.totalBytes,V=l.size<l.lines*z?l.uncompress(l):On(l);g.value+=l.size;for(let B=0;B<l.lines;B++){const U=O+B,j=B*z,K=(l.height-1-U)*l.outLineWidth;for(let W=0;W<l.inputChannels.length;W++){const q=Ze.channels[W].name,ee=l.channelByteOffsets[q]*l.columns,Y=l.decodeChannels[q];if(Y!==void 0){y.value=j+ee;for(let Q=0;Q<l.columns;Q++){const oe=K+Q*l.outputChannels+Y;l.byteArray[oe]=l.getter(V,y)}}}}}}function Bo(){const l=this,g=l.chunkOffsets,y={value:0};for(let R=0;R<g.length;R++){const O={value:g[R]};O.value+=4;const z=qe(l.viewer,O)-Ze.dataWindow.yMin;l.size=Je(l.viewer,O),l.lines=z+l.blockHeight>l.height?l.height-z:l.blockHeight;const M=l.columns*l.totalBytes,V=l.size<l.lines*M,B=l.offset;l.offset=O;const U=V?l.uncompress(l):On(l);l.offset=B;for(let j=0;j<l.lines;j++){const K=z+j,W=j*M,q=(l.height-1-K)*l.outLineWidth;for(let ee=0;ee<l.inputChannels.length;ee++){const Y=Ze.channels[ee].name,Q=l.channelByteOffsets[Y]*l.columns,oe=l.decodeChannels[Y];if(oe!==void 0){y.value=W+Q;for(let he=0;he<l.columns;he++){const ae=q+he*l.outputChannels+oe;l.byteArray[ae]=l.getter(U,y)}}}}}}function ki(l,g,y,R){if(y===0)return null;const O=l.slice(g,g+y);switch(R){case"NO_COMPRESSION":return new DataView(O.buffer,O.byteOffset,O.byteLength);case"RLE_COMPRESSION":{const z=new Uint8Array(Ms(O.buffer.slice(O.byteOffset,O.byteOffset+O.byteLength))),M=new Uint8Array(z.length);return In(z),Ln(z,M),new DataView(M.buffer)}case"ZIPS_COMPRESSION":{const z=En(O),M=new Uint8Array(z.length);return In(z),Ln(z,M),new DataView(M.buffer)}default:throw new Error("THREE.EXRLoader: "+R+" is unsupported for deep data")}}function zo(){const l=this,g=l.chunkOffsets,y=l.width,R=l.height,O=l.deepChannels,z=Ze.compression,M=l.multiPart,V=l.decodeChannels,B=l.outputChannels,U=l.byteArray instanceof Uint16Array;let j=-1;for(let K=0;K<O.length;K++)if(O[K].name==="A"){j=K;break}for(let K=0;K<g.length;K++){const W={value:g[K]};M&&(W.value+=4);const q=qe(l.viewer,W)-Ze.dataWindow.yMin,ee=Fe(l.viewer,W),Y=Fe(l.viewer,W);Fe(l.viewer,W);const Q=ki(l.array,W.value,ee,z);if(W.value+=ee,Q===null)continue;const oe=new Uint32Array(y);for(let ie=0;ie<y;ie++)oe[ie]=Q.getUint32(ie*4,!0);const he=oe[y-1];if(he===0){W.value+=Y;continue}const ae=ki(l.array,W.value,Y,z),de=[];let ne=0;for(let ie=0;ie<O.length;ie++)de.push(ne),ne+=he*O[ie].bytesPerSample;const te=(R-1-q)*l.outLineWidth;for(let ie=0;ie<y;ie++){const we=ie===0?0:oe[ie-1],ce=oe[ie]-we;if(ce===0)continue;const ue=new Float32Array(B);let Ce=0;for(let Se=0;Se<ce;Se++){const ft=we+Se,jt=1-Ce;if(jt<=0)break;let ln=1;if(j>=0){const mt=O[j].bytesPerSample,Nt=de[j]+ft*mt;ln=mt===2?J(ae.getUint16(Nt,!0)):ae.getFloat32(Nt,!0)}for(let mt=0;mt<O.length;mt++){const Nt=O[mt],Bn=V[Nt.name];if(Bn===void 0)continue;const zn=Nt.bytesPerSample,Un=de[mt]+ft*zn,hn=zn===2?J(ae.getUint16(Un,!0)):ae.getFloat32(Un,!0);ue[Bn]+=hn*jt}Ce+=ln*jt}V.A!==void 0&&(ue[V.A]=Ce);const et=te+ie*B;for(let Se=0;Se<B;Se++)l.byteArray[et+Se]=U?f.DataUtils.toHalfFloat(ue[Se]):ue[Se]}}}function Bi(l,g,y){const R={};let O=!1;for(;;){const z=Dn(g,y);if(z==="")break;O=!0;const M=Dn(g,y),V=Je(l,y),B=Oo(l,g,y,M,V);B===void 0?console.warn(`THREE.EXRLoader: Skipped unknown header attribute type '${M}'.`):R[z]=B}return O?R:null}function Uo(l,g,y){if(l.getUint32(0,!0)!=20000630)throw new Error("THREE.EXRLoader: Provided file doesn't appear to be in OpenEXR format.");const R=l.getUint8(4),O=l.getUint8(5),z={singleTile:!!(O&2),longName:!!(O&4),deepFormat:!!(O&8),multiPart:!!(O&16)};y.value=8;const M=[];if(z.multiPart){for(;;){const V=Bi(l,g,y);if(V===null)break;V.version=R,V.spec=z,M.push(V)}if(M.length===0)throw new Error("THREE.EXRLoader: No valid part headers found.")}else{const V=Bi(l,g,y);V.version=R,V.spec=z,M.push(V)}return M}function Vo(l,g,y,R,O,z){const M={size:0,viewer:g,array:y,offset:R,width:l.dataWindow.xMax-l.dataWindow.xMin+1,height:l.dataWindow.yMax-l.dataWindow.yMin+1,inputChannels:l.channels,channelByteOffsets:{},shouldExpand:!1,yCbCr:!1,totalBytes:null,columns:null,lines:null,type:null,uncompress:null,getter:null,format:null,colorSpace:f.LinearSRGBColorSpace};switch(l.compression){case"NO_COMPRESSION":M.blockHeight=1,M.uncompress=On;break;case"RLE_COMPRESSION":M.blockHeight=1,M.uncompress=mo;break;case"ZIPS_COMPRESSION":M.blockHeight=1,M.uncompress=Rs;break;case"ZIP_COMPRESSION":M.blockHeight=16,M.uncompress=Rs;break;case"PIZ_COMPRESSION":M.blockHeight=32,M.uncompress=go;break;case"PXR24_COMPRESSION":M.blockHeight=16,M.uncompress=yo;break;case"B44_COMPRESSION":case"B44A_COMPRESSION":M.blockHeight=32,M.uncompress=wo;break;case"DWAA_COMPRESSION":M.blockHeight=32,M.uncompress=Di;break;case"DWAB_COMPRESSION":M.blockHeight=256,M.uncompress=Di;break;default:throw new Error("THREE.EXRLoader: "+l.compression+" is unsupported")}const V={};for(const W of l.channels)switch(W.name){case"BY":case"RY":case"Y":case"R":case"G":case"B":case"A":V[W.name]=!0,M.type=W.pixelType}let B=!1,U=!1;if(V.Y&&V.RY&&V.BY)M.outputChannels=4,M.yCbCr=!0;else if(V.R&&V.G&&V.B)M.outputChannels=4;else if(V.Y)M.outputChannels=1;else throw new Error("THREE.EXRLoader: file contains unsupported data channels.");switch(M.outputChannels){case 4:z==f.RGBAFormat?(B=!V.A,M.format=f.RGBAFormat,M.colorSpace=f.LinearSRGBColorSpace,M.outputChannels=4,M.decodeChannels={R:0,G:1,B:2,A:3}):z==f.RGFormat?(M.format=f.RGFormat,M.colorSpace=f.LinearSRGBColorSpace,M.outputChannels=2,M.decodeChannels={R:0,G:1}):z==f.RedFormat?(M.format=f.RedFormat,M.colorSpace=f.LinearSRGBColorSpace,M.outputChannels=1,M.decodeChannels={R:0}):U=!0;break;case 1:z==f.RGBAFormat?(B=!0,M.format=f.RGBAFormat,M.colorSpace=f.LinearSRGBColorSpace,M.outputChannels=4,M.shouldExpand=!0,M.decodeChannels={Y:0}):z==f.RGFormat?(M.format=f.RGFormat,M.colorSpace=f.LinearSRGBColorSpace,M.outputChannels=2,M.shouldExpand=!0,M.decodeChannels={Y:0}):z==f.RedFormat?(M.format=f.RedFormat,M.colorSpace=f.LinearSRGBColorSpace,M.outputChannels=1,M.decodeChannels={Y:0}):U=!0;break;default:U=!0}if(U)throw new Error("THREE.EXRLoader: invalid output format for specified file.");if(M.yCbCr&&(M.format=f.RGBAFormat,M.outputChannels=4,M.decodeChannels={Y:0,RY:1,BY:2},B=!0),M.type==1)switch(O){case f.FloatType:M.getter=bo;break;case f.HalfFloatType:M.getter=cn;break}else if(M.type==2)switch(O){case f.FloatType:M.getter=We;break;case f.HalfFloatType:M.getter=_o}else throw new Error("THREE.EXRLoader: unsupported pixelType "+M.type+" for "+l.compression+".");M.columns=M.width;const j=M.width*M.height*M.outputChannels;switch(O){case f.FloatType:M.byteArray=new Float32Array(j),B&&M.byteArray.fill(1,0,j);break;case f.HalfFloatType:M.byteArray=new Uint16Array(j),B&&M.byteArray.fill(15360,0,j);break;default:console.error("THREE.EXRLoader: unsupported type: ",O);break}let K=0;for(const W of l.channels)M.decodeChannels[W.name]!==void 0&&(M.channelByteOffsets[W.name]=K),K+=W.pixelType*2;if(M.totalBytes=K,M.outLineWidth=M.width*M.outputChannels,l.spec.deepFormat){M.deepChannels=[];let W=0;for(const q of l.channels){const ee=q.pixelType===0?4:q.pixelType*2;M.deepChannels.push({name:q.name,pixelType:q.pixelType,bytesPerSample:ee}),W+=ee}M.deepBytesPerSample=W,M.chunkOffsets=l._chunkOffsets,M.multiPart=l.spec.multiPart,M.decode=zo.bind(M)}else if(l.spec.singleTile){M.blockHeight=l.tiles.ySize,M.blockWidth=l.tiles.xSize;const W=No(l.tiles,M.width,M.height),q=Fi(W,M.width,l.tiles.xSize,l.tiles.roundingMode),ee=Fi(W,M.height,l.tiles.ySize,l.tiles.roundingMode);M.tileCount=q[0]*ee[0];for(let Y=0;Y<W;Y++)for(let Q=0;Q<ee[Y];Q++)for(let oe=0;oe<q[Y];oe++)Fe(g,R);M.decode=Fo.bind(M)}else if(l.spec.multiPart)M.blockWidth=M.width,M.chunkOffsets=l._chunkOffsets,M.decode=Bo.bind(M);else{M.blockWidth=M.width;const W=Math.ceil(M.height/M.blockHeight);for(let q=0;q<W;q++)Fe(g,R);M.decode=ko.bind(M)}return M}const Nn={value:0},Fn=new DataView(e),Ho=new Uint8Array(e),kn=Uo(Fn,e,Nn),zi=Math.max(0,Math.min(this.part,kn.length-1)),Ze=kn[zi];if(Ze.spec.multiPart||Ze.spec.deepFormat)for(let l=0;l<kn.length;l++){const g=kn[l].chunkCount;if(l===zi){Ze._chunkOffsets=[];for(let y=0;y<g;y++)Ze._chunkOffsets.push(Fe(Fn,Nn))}else for(let y=0;y<g;y++)Fe(Fn,Nn)}const tt=Vo(Ze,Fn,Ho,Nn,this.type,this.outputFormat);if(tt.decode(),tt.shouldExpand){const l=tt.byteArray;if(this.outputFormat==f.RGBAFormat)for(let g=0;g<l.length;g+=4)l[g+2]=l[g+1]=l[g];else if(this.outputFormat==f.RGFormat)for(let g=0;g<l.length;g+=2)l[g+1]=l[g]}if(tt.yCbCr){const l=tt.byteArray,g=tt.width*tt.height;if(this.type===f.HalfFloatType)for(let y=0;y<g;y++){const R=y*4,O=J(l[R]),z=J(l[R+1]),M=J(l[R+2]),V=(1+z)*O,B=(1+M)*O,U=(O-V*.2126-B*.0722)/.7152;l[R]=f.DataUtils.toHalfFloat(Math.max(0,V)),l[R+1]=f.DataUtils.toHalfFloat(Math.max(0,U)),l[R+2]=f.DataUtils.toHalfFloat(Math.max(0,B))}else for(let y=0;y<g;y++){const R=y*4,O=l[R],z=l[R+1],M=l[R+2],V=(1+z)*O,B=(1+M)*O;l[R]=Math.max(0,V),l[R+1]=Math.max(0,(O-V*.2126-B*.0722)/.7152),l[R+2]=Math.max(0,B)}}return{header:Ze,width:tt.width,height:tt.height,data:tt.byteArray,format:tt.format,colorSpace:tt.colorSpace,type:this.type,minFilter:f.LinearFilter,magFilter:f.LinearFilter,generateMipmaps:!1,flipY:!1}}setDataType(e){return this.type=e,this}setOutputFormat(e){return this.outputFormat=e,this}setPart(e){return this.part=e,this}}class Ql extends f.DataTextureLoader{constructor(e){super(e),this.type=f.HalfFloatType}parse(e){const o=function(C,D){switch(C){case 1:throw new Error("THREE.HDRLoader: Read Error: "+(D||""));case 2:throw new Error("THREE.HDRLoader: Write Error: "+(D||""));case 3:throw new Error("THREE.HDRLoader: Bad File Format: "+(D||""));default:case 4:throw new Error("THREE.HDRLoader: Memory Error: "+(D||""))}},h=function(C,D,I){D=D||1024;let N=C.pos,H=-1,G=0,$="",re=String.fromCharCode.apply(null,new Uint16Array(C.subarray(N,N+128)));for(;0>(H=re.indexOf(`
|
|
26
|
+
`))&&G<D&&N<C.byteLength;)$+=re,G+=re.length,N+=128,re=String.fromCharCode.apply(null,new Uint16Array(C.subarray(N,N+128)));return-1<H?(C.pos+=G+H+1,$+re.slice(0,H)):!1},p=function(C){const D=/^#\?(\S+)/,I=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,k=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,N=/^\s*FORMAT=(\S+)\s*$/,H=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,G={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let $,re;for((C.pos>=C.byteLength||!($=h(C)))&&o(1,"no header found"),(re=$.match(D))||o(3,"bad initial token"),G.valid|=1,G.programtype=re[1],G.string+=$+`
|
|
27
|
+
`;$=h(C),$!==!1;){if(G.string+=$+`
|
|
28
|
+
`,$.charAt(0)==="#"){G.comments+=$+`
|
|
29
|
+
`;continue}if((re=$.match(I))&&(G.gamma=parseFloat(re[1])),(re=$.match(k))&&(G.exposure=parseFloat(re[1])),(re=$.match(N))&&(G.valid|=2,G.format=re[1]),(re=$.match(H))&&(G.valid|=4,G.height=parseInt(re[1],10),G.width=parseInt(re[2],10)),G.valid&2&&G.valid&4)break}return G.valid&2||o(3,"missing format specifier"),G.valid&4||o(3,"missing image size specifier"),G},m=function(C,D,I){const k=D;if(k<8||k>32767||C[0]!==2||C[1]!==2||C[2]&128)return new Uint8Array(C);k!==(C[2]<<8|C[3])&&o(3,"wrong scanline width");const N=new Uint8Array(4*D*I);N.length||o(4,"unable to allocate buffer space");let H=0,G=0;const $=4*k,re=new Uint8Array(4),Ne=new Uint8Array($);let ot=I;for(;ot>0&&G<C.byteLength;){G+4>C.byteLength&&o(1),re[0]=C[G++],re[1]=C[G++],re[2]=C[G++],re[3]=C[G++],(re[0]!=2||re[1]!=2||(re[2]<<8|re[3])!=k)&&o(3,"bad rgbe scanline format");let Re=0,ze;for(;Re<$&&G<C.byteLength;){ze=C[G++];const ve=ze>128;if(ve&&(ze-=128),(ze===0||Re+ze>$)&&o(3,"bad scanline data"),ve){const ye=C[G++];for(let pt=0;pt<ze;pt++)Ne[Re++]=ye}else Ne.set(C.subarray(G,G+ze),Re),Re+=ze,G+=ze}const je=k;for(let ve=0;ve<je;ve++){let ye=0;N[H]=Ne[ve+ye],ye+=k,N[H+1]=Ne[ve+ye],ye+=k,N[H+2]=Ne[ve+ye],ye+=k,N[H+3]=Ne[ve+ye],H+=4}ot--}return N},w=function(C,D,I,k){const N=C[D+3],H=Math.pow(2,N-128)/255;I[k+0]=C[D+0]*H,I[k+1]=C[D+1]*H,I[k+2]=C[D+2]*H,I[k+3]=1},x=function(C,D,I,k){const N=C[D+3],H=Math.pow(2,N-128)/255;I[k+0]=f.DataUtils.toHalfFloat(Math.min(C[D+0]*H,65504)),I[k+1]=f.DataUtils.toHalfFloat(Math.min(C[D+1]*H,65504)),I[k+2]=f.DataUtils.toHalfFloat(Math.min(C[D+2]*H,65504)),I[k+3]=f.DataUtils.toHalfFloat(1)},_=new Uint8Array(e);_.pos=0;const v=p(_),T=v.width,S=v.height,b=m(_.subarray(_.pos),T,S);let A,L,P;switch(this.type){case f.FloatType:P=b.length/4;const C=new Float32Array(P*4);for(let I=0;I<P;I++)w(b,I*4,C,I*4);A=C,L=f.FloatType;break;case f.HalfFloatType:P=b.length/4;const D=new Uint16Array(P*4);for(let I=0;I<P;I++)x(b,I*4,D,I*4);A=D,L=f.HalfFloatType;break;default:throw new Error("THREE.HDRLoader: Unsupported type: "+this.type)}return{width:T,height:S,data:A,header:v.string,gamma:v.gamma,exposure:v.exposure,type:L,colorSpace:f.LinearSRGBColorSpace,minFilter:f.LinearFilter,magFilter:f.LinearFilter,generateMipmaps:!1,flipY:!0}}setDataType(e){return this.type=e,this}}class Jl extends Ql{constructor(e){console.warn("RGBELoader has been deprecated. Please use HDRLoader instead."),super(e)}}class eh extends f.Scene{constructor(){super(),this.name="RoomEnvironment",this.position.y=-3.5;const e=new f.BoxGeometry;e.deleteAttribute("uv");const t=new f.MeshStandardMaterial({side:f.BackSide}),n=new f.MeshStandardMaterial,s=new f.PointLight(16777215,900,28,2);s.position.set(.418,16.199,.3),this.add(s);const r=new f.Mesh(e,t);r.position.set(-.757,13.219,.717),r.scale.set(31.713,28.305,28.591),this.add(r);const o=new f.InstancedMesh(e,n,6),a=new f.Object3D;a.position.set(-10.906,2.009,1.846),a.rotation.set(0,-.195,0),a.scale.set(2.328,7.905,4.651),a.updateMatrix(),o.setMatrixAt(0,a.matrix),a.position.set(-5.607,-.754,-.758),a.rotation.set(0,.994,0),a.scale.set(1.97,1.534,3.955),a.updateMatrix(),o.setMatrixAt(1,a.matrix),a.position.set(6.167,.857,7.803),a.rotation.set(0,.561,0),a.scale.set(3.927,6.285,3.687),a.updateMatrix(),o.setMatrixAt(2,a.matrix),a.position.set(-2.017,.018,6.124),a.rotation.set(0,.333,0),a.scale.set(2.002,4.566,2.064),a.updateMatrix(),o.setMatrixAt(3,a.matrix),a.position.set(2.291,-.756,-2.621),a.rotation.set(0,-.286,0),a.scale.set(1.546,1.552,1.496),a.updateMatrix(),o.setMatrixAt(4,a.matrix),a.position.set(-2.193,-.369,-5.547),a.rotation.set(0,.516,0),a.scale.set(3.875,3.487,2.986),a.updateMatrix(),o.setMatrixAt(5,a.matrix),this.add(o);const c=new f.Mesh(e,en(50));c.position.set(-16.116,14.37,8.208),c.scale.set(.1,2.428,2.739),this.add(c);const u=new f.Mesh(e,en(50));u.position.set(-16.109,18.021,-8.207),u.scale.set(.1,2.425,2.751),this.add(u);const d=new f.Mesh(e,en(17));d.position.set(14.904,12.198,-1.832),d.scale.set(.15,4.265,6.331),this.add(d);const h=new f.Mesh(e,en(43));h.position.set(-.462,8.89,14.52),h.scale.set(4.38,5.441,.088),this.add(h);const p=new f.Mesh(e,en(20));p.position.set(3.235,11.486,-12.541),p.scale.set(2.5,2,.1),this.add(p);const m=new f.Mesh(e,en(100));m.position.set(0,20,0),m.scale.set(1,.1,1),this.add(m)}dispose(){const e=new Set;this.traverse(t=>{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(const t of e)t.dispose()}}function en(i){return new f.MeshLambertMaterial({color:0,emissive:16777215,emissiveIntensity:i})}class th{constructor(){this.pmremGenerator=null,this.threeRenderer=null,this.loadedTextures=new Map,this.renderTargets=[],this.studioPmremTexture=null,this.studioCubeTarget=null,this.disposed=!1}async initialize(e){var t;try{const n=e.renderer;let s=n.renderer||((t=n.getThreeRenderer)==null?void 0:t.call(n));if(!s&&n.getDomElement){const r=n.getDomElement();if(r&&"parentElement"in r&&r.parentElement){const o=r.parentElement.renderer;o instanceof E.WebGLRenderer&&(s=o)}}return s?(this.threeRenderer=s,this.pmremGenerator=new E.PMREMGenerator(s),this.pmremGenerator.compileEquirectangularShader(),F.ok(void 0)):F.err(new Z("Could not access Three.js renderer",X.INITIALIZATION_FAILED))}catch(n){return F.err(new Z("Failed to initialize environment service",X.INITIALIZATION_FAILED,{originalError:n}))}}async loadEnvironmentMap(e){var t;try{const n=this.loadedTextures.get(e);if(n)return F.ok(new Tn(n));const s=(t=e.split(".").pop())==null?void 0:t.toLowerCase();let r;switch(s){case"hdr":r=new Jl;break;case"exr":r=new $l;break;case"jpg":case"jpeg":case"png":r=new E.TextureLoader;break;default:return F.err(new Z(`Unsupported environment map format: ${s}`,X.UNSUPPORTED_FORMAT,{url:e,extension:s}))}const o=await new Promise((a,c)=>{r.load(e,u=>{a(u)},void 0,u=>c(u))});if(this.disposed)return o.dispose(),F.err(new Z("Environment service was disposed during the load",X.INVALID_STATE,{url:e}));if(this.pmremGenerator){o.mapping=E.EquirectangularReflectionMapping;const a=this.pmremGenerator.fromEquirectangular(o);this.renderTargets.push(a);const c=a.texture;return this.loadedTextures.set(e,c),this.loadedTextures.set(e+"_original",o),F.ok(new Tn(c))}return this.loadedTextures.set(e,o),F.ok(new Tn(o))}catch(n){return F.err(new Z("Failed to load environment map",X.TEXTURE_LOAD_FAILED,{url:e,originalError:n}))}}applyToScene(e,t,n){try{const s=Tt(e);if(!s)return F.err(new Z("Scene must be ThreeSceneAdapter",X.INVALID_PARAMETER));const r=gl(t);if(!r)return F.err(new Z("Texture must be ThreeTextureAdapter",X.INVALID_PARAMETER));if(s.environment=r,n&&(n.backgroundBlurriness!==void 0&&(s.backgroundBlurriness=n.backgroundBlurriness),n.backgroundIntensity!==void 0&&(s.backgroundIntensity=n.backgroundIntensity),n.environmentIntensity!==void 0&&(s.environmentIntensity=n.environmentIntensity)),r.mapping===E.CubeUVReflectionMapping){const a=Array.from(this.loadedTextures.entries()).find(([c,u])=>c.endsWith("_original")&&u.mapping===E.EquirectangularReflectionMapping);a?s.__originalEnvironmentTexture=a[1]:r===this.studioPmremTexture&&this.studioCubeTarget&&(s.__originalEnvironmentTexture=this.studioCubeTarget.texture)}else r.mapping===E.EquirectangularReflectionMapping&&(s.__originalEnvironmentTexture=r);if((n==null?void 0:n.setBackground)??!0)if(r.mapping===E.EquirectangularReflectionMapping)s.background=r;else if(r.mapping===E.CubeUVReflectionMapping){const a=Array.from(this.loadedTextures.entries()).find(([c,u])=>c.endsWith("_original")&&u.mapping===E.EquirectangularReflectionMapping);a?s.background=a[1]:s.background=r}else s.background=r;return F.ok(void 0)}catch(s){return F.err(new Z("Failed to apply environment to scene",X.SCENE_OPERATION_FAILED,{originalError:s}))}}getOriginalEnvironmentTexture(e){const t=this.loadedTextures.get(e+"_original");return t?new Tn(t):null}createStudioEnvironment(e={}){try{if(!this.pmremGenerator)return F.err(new Z("Environment service not initialized",X.INITIALIZATION_FAILED));const t=new eh,n=this.pmremGenerator.fromScene(t);this.renderTargets.push(n);const s=n.texture;return this.captureStudioCubeOriginal(t,s),t.dispose(),F.ok(new Tn(s))}catch(t){return F.err(new Z("Failed to create studio environment",X.TEXTURE_LOAD_FAILED,{originalError:t}))}}captureStudioCubeOriginal(e,t){var n;if(this.threeRenderer)try{const s=new E.WebGLCubeRenderTarget(256,{type:E.HalfFloatType}),r=new E.CubeCamera(.1,100,s),o=this.threeRenderer.toneMapping;this.threeRenderer.toneMapping=E.NoToneMapping;try{r.update(this.threeRenderer,e)}finally{this.threeRenderer.toneMapping=o}(n=this.studioCubeTarget)==null||n.dispose(),this.studioCubeTarget=s,this.studioPmremTexture=t}catch(s){console.warn("Failed to capture the studio environment for path tracing:",s)}}dispose(){var e;this.disposed=!0,this.loadedTextures.forEach(t=>t.dispose()),this.loadedTextures.clear(),this.renderTargets.forEach(t=>t.dispose()),this.renderTargets=[],(e=this.studioCubeTarget)==null||e.dispose(),this.studioCubeTarget=null,this.studioPmremTexture=null,this.pmremGenerator&&(this.pmremGenerator.dispose(),this.pmremGenerator=null),this.threeRenderer=null}}class Tn{constructor(e){this.texture=e}get id(){return this.texture.uuid}get image(){return this.texture.image}get needsUpdate(){return this.texture.needsUpdate}set needsUpdate(e){this.texture.needsUpdate=e}dispose(){this.texture.dispose()}getThreeTexture(){return this.texture}}class nh{constructor(e){this.object=e,this.boundingBox=new E.Box3().setFromObject(this.object)}alignToFloor(){const e=this.calculateFloorOffset();this.applyOffset(e)}calculateFloorOffset(){const e=this.boundingBox.min.y,t=this.boundingBox.max.y-e,n=new E.Vector3;return t>0?n.y=-e:n.y=0,n}applyOffset(e){this.object.position.add(e)}}class sh{alignToFloor(e){try{let t=null;return"getThreeObject"in e&&typeof e.getThreeObject=="function"?t=e.getThreeObject():e instanceof E.Object3D&&(t=e),t?(new nh(t).alignToFloor(),F.ok(void 0)):F.err(new Z("Could not get Three.js object for floor alignment",X.INVALID_PARAMETER))}catch(t){return F.err(new Z("Failed to align object to floor",X.OPERATION_FAILED,{originalError:t}))}}}const Er={touch:10,default:5};class ih{constructor(){this.raycaster=new E.Raycaster,this.activePointers=new Set,this.options=null,this.pending=null,this.detach=null}initialize(e){this.dispose(),this.options=e;const{canvas:t}=e,n=o=>{this.activePointers.add(o.pointerId);try{t.setPointerCapture(o.pointerId)}catch{}if(this.activePointers.size>1||o.button!==0){this.pending=null;return}this.pending={pointerId:o.pointerId,x:o.clientX,y:o.clientY,threshold:o.pointerType==="touch"?Er.touch:Er.default}},s=o=>{this.activePointers.delete(o.pointerId);const a=this.pending;!a||a.pointerId!==o.pointerId||(this.pending=null,Math.hypot(o.clientX-a.x,o.clientY-a.y)>a.threshold)||this.pick(o.clientX,o.clientY)},r=o=>{this.activePointers.delete(o.pointerId),this.pending=null};t.addEventListener("pointerdown",n),t.addEventListener("pointerup",s),t.addEventListener("pointercancel",r),this.detach=()=>{t.removeEventListener("pointerdown",n),t.removeEventListener("pointerup",s),t.removeEventListener("pointercancel",r)}}pick(e,t){if(!this.options)return;const{canvas:n,camera:s,getPickRoot:r,onPick:o}=this.options,a=r(),c=Et(a),u=Rn(s);if(!c||!u){o(null);return}const d=n.getBoundingClientRect();if(d.width===0||d.height===0){o(null);return}const h=new E.Vector2((e-d.left)/d.width*2-1,-((t-d.top)/d.height)*2+1);(this.options.bvh??!0)&&Fr(c),this.raycaster.setFromCamera(h,u),this.raycaster.firstHitOnly=!0;const p=this.raycaster.intersectObject(c,!0)[0];if(!p){o(null);return}o({object:new Ke(p.object),point:{x:p.point.x,y:p.point.y,z:p.point.z}})}dispose(){var e;(e=this.detach)==null||e.call(this),this.detach=null,this.options=null,this.pending=null,this.activePointers.clear()}}const rh=.001,Tr={visible:!1};class oh{constructor(e){this.sources=e,this.anchor=new E.Vector3,this.projected=new E.Vector3,this.cameraPosition=new E.Vector3,this.toAnchor=new E.Vector3,this.raycaster=new E.Raycaster,this.lastCameraMatrix=new E.Matrix4,this.lastWidth=-1,this.lastHeight=-1,this.hasProjected=!1}invalidate(){this.hasProjected=!1}project(e,t){const n=Rn(this.sources.camera),s=this.sources.getCanvas();if(!n||!s)return null;const r=s.clientWidth||s.width,o=s.clientHeight||s.height;return this.hasProjected&&r===this.lastWidth&&o===this.lastHeight&&this.lastCameraMatrix.equals(n.matrixWorld)?null:(this.lastCameraMatrix.copy(n.matrixWorld),this.lastWidth=r,this.lastHeight=o,this.hasProjected=!0,this.anchor.set(e.x,e.y,e.z),n.getWorldPosition(this.cameraPosition),this.projected.copy(this.anchor).applyMatrix4(n.matrixWorldInverse),this.projected.z>=0||t&&this.isOccluded(n)?Tr:(this.projected.copy(this.anchor).project(n),{visible:!0,left:(this.projected.x+1)/2*r,top:(1-this.projected.y)/2*o}))}isOccluded(e){const t=Et(this.sources.getModel());if(!t)return!1;this.toAnchor.copy(this.anchor).sub(this.cameraPosition);const n=this.toAnchor.length();this.raycaster.set(this.cameraPosition,this.toAnchor.normalize()),this.raycaster.camera=e,this.raycaster.firstHitOnly=!0;const s=this.raycaster.intersectObject(t,!0)[0];return!!(s&&s.distance<n-rh)}}class ah{createProjector(e){return new oh(e)}}class ch{constructor(){this.mixer=null,this.clips=[],this.activeActions=[],this.playing=!1,this.speed=1}attach(e){this.detach();const t=Et(e);if(!t)return;const n=lh(t);n&&(this.clips=n.animations,this.mixer=new E.AnimationMixer(n),this.mixer.timeScale=this.speed)}getClipNames(){return this.clips.map(e=>e.name)}play(e){if(e!==void 0){if(this.clips.length===0)return F.err(new Z(`Cannot play animation clip '${e}': no animation clips are attached`,X.INVALID_STATE));if(!this.clips.some(s=>s.name===e)){const s=this.clips.map(r=>r.name);return F.err(new Z(`Unknown animation clip '${e}'. Available clips: ${s.join(", ")}`,X.INVALID_PARAMETER))}}if(!this.mixer)return F.ok(void 0);if(!this.playing&&this.activeActions.length>0&&e===void 0)return this.playing=!0,F.ok(void 0);const t=e?this.clips.filter(s=>s.name===e):this.clips;if(t.length===0)return F.ok(void 0);const n=this.mixer;return n.stopAllAction(),this.activeActions=t.map(s=>{const r=n.clipAction(s);return r.play(),r}),this.playing=!0,F.ok(void 0)}pause(){this.playing=!1}isPlaying(){return this.playing}setSpeed(e){this.speed=e,this.mixer&&(this.mixer.timeScale=e)}update(e){this.playing&&this.mixer&&this.mixer.update(e)}detach(){this.mixer&&(this.mixer.stopAllAction(),this.mixer.uncacheRoot(this.mixer.getRoot())),this.mixer=null,this.clips=[],this.activeActions=[],this.playing=!1}}function lh(i){let e=null;return i.traverse(t=>{var n;!e&&(((n=t.animations)==null?void 0:n.length)??0)>0&&(e=t)}),e}var vn=(i=>(i.MapControls="MapControls",i.OrbitControls="OrbitControls",i))(vn||{});class hh{static convertRendererOptions(e){const t={antialias:e.antialias,alpha:e.alpha,premultipliedAlpha:e.premultipliedAlpha,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference,pixelRatio:e.pixelRatio};(e.shadowMapEnabled!==void 0||e.shadowMapType!==void 0)&&(t.shadowMap={enabled:e.shadowMapEnabled??!0,type:this.convertShadowMapType(e.shadowMapType)}),(e.toneMapping!==void 0||e.toneMappingExposure!==void 0)&&(t.toneMapping={type:this.convertToneMappingType(e.toneMapping),exposure:e.toneMappingExposure??1});const n=e.bloom,s=e.vignette,r=e.filmGrain;return(n||s||r)&&(t.postProcessing={bloom:n??!1,vignette:s??!1,filmGrain:r??!1}),t}static convertShadowMapType(e){if(typeof e=="number"){if(e===E.BasicShadowMap)return"basic";if(e===E.PCFShadowMap)return"pcf";if(e===E.PCFSoftShadowMap)return"pcfsoft";if(e===E.VSMShadowMap)return"vsm"}return typeof e=="string"?e:void 0}static convertToneMappingType(e){if(typeof e=="number"){if(e===E.NoToneMapping)return"none";if(e===E.LinearToneMapping)return"linear";if(e===E.ReinhardToneMapping)return"reinhard";if(e===E.CineonToneMapping)return"cineon";if(e===E.ACESFilmicToneMapping)return"aces";if(e===E.AgXToneMapping)return"agx";if(e===E.NeutralToneMapping)return"neutral"}return typeof e=="string"?e:"neutral"}}class uh{static createViewer(e,t){var v;vr(t.units);const n=new fc(e),s=new hi,r=this.createCamera(t),o=this.createControls(r.getThreeCamera(),e,t),a=new dh().createDefaultLoader({renderer:n.getThreeRenderer()??void 0,bvh:(v=t.selection)==null?void 0:v.bvh,...t.loaders}),c=new Dl,u=new th,d=new Nl,h=new sh,p=new ih,m=new ah,w=new ch,x=hh.convertRendererOptions(t.renderer||{});x.preserveDrawingBuffer=!0;const _={renderer:n,scene:s,camera:r,controls:o,modelLoader:a,options:t,rendererOptions:x,sceneSetupService:c,environmentService:u,pathTracingService:d,floorAlignmentService:h,selectionService:p,anchorProjectionService:m,animationService:w};return new oa(_)}static createCamera(e){const n=e.camera||{},s=n.fov||n.cameraFov||30,r=n.near||n.cameraNear||.1,o=n.far||n.cameraFar||1e5,a=n.position||n.cameraPosition,c=n.target||n.cameraTarget,u=xi.create(s,1,r,o);return a&&u.position.set(a[0],a[1],a[2]),c&&u.lookAt({x:c[0],y:c[1],z:c[2],set:()=>{},copy:()=>{},add:()=>{},multiply:()=>{},normalize:()=>{},length:()=>0}),u}static createControls(e,t,n){const s=n.controls||{},r=s.type||vn.OrbitControls;let o;r===vn.MapControls?o=new ml(e,t):o=new fl(e,t),o.enabled=s.enabled??!0,o.enableDamping=s.enableDamping??!0,o.dampingFactor=s.dampingFactor??.25,o.enableZoom=s.enableZoom??!0,o.enableRotate=s.enableRotate??!0,o.enablePan=s.enablePan??!0,o.autoRotate=s.autoRotate??!1,s.autoRotateSpeed!==void 0&&(o.autoRotateSpeed=s.autoRotateSpeed),s.minDistance!==void 0&&(o.minDistance=s.minDistance),s.maxDistance!==void 0&&(o.maxDistance=s.maxDistance),s.minPolarAngle!==void 0&&(o.minPolarAngle=s.minPolarAngle),s.maxPolarAngle!==void 0&&(o.maxPolarAngle=s.maxPolarAngle);const c=n.camera||{},u=c.target||c.cameraTarget;return u&&o.target&&(o.target.set(u[0],u[1],u[2]),o.update()),o}}class dh extends mr{createDefaultLoader(e={}){return mr.createLoader("model.glb",e)}}const ph=["toneMappingExposure"],fh=["environmentIntensity"],mh=["autoRotate","autoRotateSpeed"],gh=["enabled"];function Qr(i){var t,n,s,r,o,a,c,u,d,h,p;const e={backgroundColor:i.backgroundColor};return((t=i.renderer)==null?void 0:t.toneMappingExposure)!==void 0&&(e.renderer={toneMappingExposure:i.renderer.toneMappingExposure}),((n=i.environment)==null?void 0:n.environmentIntensity)!==void 0&&(e.environment={environmentIntensity:i.environment.environmentIntensity}),(((s=i.controls)==null?void 0:s.autoRotate)!==void 0||((r=i.controls)==null?void 0:r.autoRotateSpeed)!==void 0)&&(e.controls={autoRotate:(o=i.controls)==null?void 0:o.autoRotate,autoRotateSpeed:(a=i.controls)==null?void 0:a.autoRotateSpeed}),(((c=i.animations)==null?void 0:c.autoplay)!==void 0||((u=i.animations)==null?void 0:u.speed)!==void 0)&&(e.animations={autoplay:(d=i.animations)==null?void 0:d.autoplay,speed:(h=i.animations)==null?void 0:h.speed}),((p=i.pathTracing)==null?void 0:p.enabled)!==void 0&&(e.pathTracing={enabled:i.pathTracing.enabled}),e}const ws={staticScene:!1,backgroundColor:"#f0f0f7",replaceWithScreenshotOnComplete:!1,units:"meters",pathTracing:{enabled:!1,maxSamples:16,bounces:16,transmissiveBounces:4,renderScale:.8,lowResScale:.25,dynamicLowRes:!0},camera:{position:[60,60,60],target:[0,0,0],fov:30,near:.1,far:1e5,autoFitToObject:!0},environment:{backgroundIntensity:1,environmentIntensity:.5},lighting:{ambientLight:{color:"#4a4a4a",intensity:.5},hemisphereLight:{skyColor:"#fff6ec",groundColor:"#3c3630",intensity:.45},directionalLight:{color:"#fff8f2",intensity:1.9,position:[40,90,40],castShadow:!0,shadow:{mapSize:{width:4096,height:4096},camera:{near:.5,far:200,left:-50,right:50,top:50,bottom:-50},bias:-1e-4,radius:14}}},renderer:{antialias:!0,alpha:!1,shadowMapEnabled:!0,pixelRatio:typeof window<"u"?window.devicePixelRatio:1,shadowMapType:1,toneMapping:7,toneMappingExposure:1.15},controls:{type:vn.OrbitControls,enabled:!0,enableDamping:!0,dampingFactor:.25,enableZoom:!0,enableRotate:!0,enablePan:!0,maxPolarAngle:Math.PI/2},helpers:{grid:{type:"shadow_floor",size:20,divisions:20,colorGrid:"#a8a8a2",opacity:.5,styleOptions:{tileSize:.1173,metalness:0,roughness:.9,transmission:0}},axes:!1,stats:!1,gizmo:!1,studioEnvironment:!0,darkStudioMode:!1}},Mi={studio:{backgroundColor:"#f0f0f7",renderer:{toneMappingExposure:1.15},environment:{environmentIntensity:.5}},product:{backgroundColor:"#ffffff",renderer:{toneMappingExposure:1.2},environment:{environmentIntensity:.55}},neutral:{backgroundColor:"#d9d9de",renderer:{toneMappingExposure:1.1},environment:{environmentIntensity:.45}},dark:{backgroundColor:"#1a1a1f",renderer:{toneMappingExposure:1.2},environment:{environmentIntensity:.5}},outdoor:{backgroundColor:"#bcd4e6",renderer:{toneMappingExposure:1.2},environment:{environmentIntensity:.6}}};function Jr(i){return i?Mi[i]:{}}function wi(i,e){return ms(ms(i,Jr(e.preset)),e)}const as=(i,...e)=>{if(!i)return;const t={...i};for(const n of e)delete t[n];return Object.keys(t).length>0?t:void 0};function yh(i){const e=se.useMemo(()=>{var s;return JSON.stringify({pathTracing:as(i.pathTracing,...gh),staticScene:i.staticScene,renderer:as(i.renderer,...ph),camera:i.camera,controls:as(i.controls,...mh),environment:as(i.environment,...fh),lighting:i.lighting,helpers:i.helpers,rendering:i.rendering,replaceWithScreenshotOnComplete:i.replaceWithScreenshotOnComplete,loaders:i.loaders,units:i.units??"meters",selectionBvh:((s=i.selection)==null?void 0:s.bvh)!==!1})},[i.pathTracing,i.staticScene,i.renderer,i.camera,i.controls,i.environment,i.lighting,i.helpers,i.rendering,i.replaceWithScreenshotOnComplete,i.loaders,i.units,i.selection]),t=se.useMemo(()=>{const s=wi(ws,i);return JSON.stringify(Qr(s))},[i.preset,i.backgroundColor,i.renderer,i.environment,i.controls,i.animations,i.pathTracing]);return{options:se.useMemo(()=>i,[e,t]),structuralKey:e,runtimeKey:t}}const wh="200px";function Eh(i,e){const[t,n]=se.useState(!e);return se.useEffect(()=>{if(t)return;if(!e){n(!0);return}const s=i.current;if(!s||typeof IntersectionObserver>"u"){n(!0);return}const r=new IntersectionObserver(o=>{o.some(a=>a.isIntersecting)&&n(!0)},{rootMargin:wh});return r.observe(s),()=>r.disconnect()},[i,e,t]),t}function Th(i,e){const t=se.useRef(null),n=se.useRef({width:0,height:0}),[s,r]=se.useState(!1),[o,a]=se.useState(null),{options:c,structuralKey:u,runtimeKey:d}=yh(e),h=Eh(i,(e.loading??"eager")==="lazy");return se.useEffect(()=>{if(!h||!i.current||t.current)return;a(null);const p=wi(ws,c);let m;try{m=uh.createViewer(i.current,p)}catch(x){console.error("Failed to create viewer:",x),a(x instanceof Error?x:new Error(String(x)));return}t.current=m,n.current={width:0,height:0};let w=!1;return m.initialize().then(x=>{w||(x.ok?r(!0):(console.error("Failed to initialize viewer:",x.error),a(x.error)))}),()=>{w=!0,m.dispose(),t.current=null,r(!1)}},[i,u,h]),se.useEffect(()=>{if(!t.current||!s)return;const p=wi(ws,c);t.current.updateOptions(Qr(p))},[d,s]),se.useEffect(()=>{if(!t.current||!i.current)return;let p=null;const m=_=>{if(i.current&&t.current){const v=i.current.parentElement||i.current;let{clientWidth:T,clientHeight:S}=v;if(_&&_[0]){const{width:b,height:A}=_[0].contentRect;T=Math.floor(b),S=Math.floor(A)}if(n.current.width===T&&n.current.height===S)return;p!==null&&cancelAnimationFrame(p),p=requestAnimationFrame(()=>{t.current&&i.current&&(t.current.resize(T,S),n.current={width:T,height:S})})}};m();const w=()=>m();window.addEventListener("resize",w);let x=null;return typeof ResizeObserver<"u"&&i.current.parentElement&&(x=new ResizeObserver(m),x.observe(i.current.parentElement)),()=>{window.removeEventListener("resize",w),x==null||x.disconnect(),p!==null&&cancelAnimationFrame(p)}},[s,i]),{viewer:t.current,isInitialized:s,initError:o}}function eo(i,e){const t=se.useRef(e);t.current=e,se.useEffect(()=>{if(!i)return;const n=i.getEvents(),s=[],r=o=>{const a=c=>{var u,d;(d=(u=t.current)[o])==null||d.call(u,c)};return n.on(o,a),()=>n.off(o,a)};return Object.keys(e).forEach(o=>{e[o]&&s.push(r(o))}),()=>{s.forEach(o=>o())}},[i])}function Sh(i,e){const[t,n]=se.useState(null),s=se.useRef(new Set);se.useEffect(()=>{if(i!==void 0&&s.current.has(i)){s.current.delete(i),n(c=>c===i?null:c);return}s.current.clear(),n(null)},[i]);const r=!!(e!=null&&e.presets);se.useEffect(()=>{r||(s.current.clear(),n(null))},[r]);const o=e==null?void 0:e.onPresetChange,a=se.useCallback(c=>{n(c),o&&(s.current.add(c),o(c))},[o]);return{activePreset:t??i,pickerEnabled:r,selectPreset:a}}function _h(i,e,t,n,s){return se.useMemo(()=>{var u,d,h;const r=i.preset!==e,o=t===!0&&((u=i.pathTracing)==null?void 0:u.enabled)===void 0,a=n!==void 0&&((d=i.controls)==null?void 0:d.autoRotate)===void 0,c=s!==void 0&&((h=i.animations)==null?void 0:h.autoplay)===void 0;return!r&&!o&&!a&&!c?i:{...i,...r?{preset:e}:{},...o?{pathTracing:{...i.pathTracing,enabled:!0}}:{},...a?{controls:{...i.controls,autoRotate:n}}:{},...c?{animations:{...i.animations,autoplay:s}}:{}}},[i,e,t,n,s])}function bh(i,e,t){const n=se.useMemo(()=>{if(typeof t=="string")return t;if(t)return`object-${t.uuid||"no-uuid"}`},[t]),[s,r]=se.useState(()=>({status:t?"loading":"idle"}));return se.useEffect(()=>{r({status:t?"loading":"idle"})},[n]),se.useEffect(()=>{if(!i||!e||!t)return;let o=!0;const a=typeof t=="string"?t:new Ke(t);return i.loadModel(a).then(c=>{o&&(c.ok?r({status:"loaded"}):(r({status:"error",error:c.error.message}),console.error("Failed to load model:",c.error)))}),()=>{o=!1}},[i,e,n]),s}class Ys{static toThreeObject(e){const t=Et(e);if(t)return t;const n=new E.Object3D;return n.position.set(e.position.x,e.position.y,e.position.z),n.rotation.set(e.rotation.x,e.rotation.y,e.rotation.z),n.scale.set(e.scale.x,e.scale.y,e.scale.z),n}static toThreeCamera(e){return Rn(e)??new E.PerspectiveCamera}static toThreeControls(e){return vi(e)??e}static convertModelLoaded(e){return{model:this.toThreeObject(e.model),loadTime:e.loadTime}}static convertControlsChange(e){return{type:e.type,camera:e.camera?this.toThreeCamera(e.camera):void 0,controls:e.controls?this.toThreeControls(e.controls):void 0}}static convertObjectSelected(e){return{object:this.toThreeObject(e.object),point:e.point}}static convertInitialized(e,t){return{viewer:t}}static convertDisposed(e,t){return{viewer:t}}}function xh(i){const e=se.useRef(new Ts),t=se.useMemo(()=>({"model:loading":n=>e.current.emit("model:loading",n),"model:progress":n=>e.current.emit("model:progress",n),"model:loaded":n=>e.current.emit("model:loaded",Ys.convertModelLoaded(n)),"model:error":n=>e.current.emit("model:error",n),"render:complete":n=>e.current.emit("render:complete",n),"controls:change":n=>e.current.emit("controls:change",Ys.convertControlsChange(n)),"object:selected":n=>e.current.emit("object:selected",Ys.convertObjectSelected(n)),error:n=>e.current.emit("error",n)}),[]);return eo(i,t),e.current}function Ah(i,e,t){const n=se.useRef(t);n.current=t;const s=se.useMemo(()=>({"model:loaded":()=>{var o,a;return(a=(o=n.current).onLoad)==null?void 0:a.call(o)},"model:progress":o=>{var a,c;return(c=(a=n.current).onProgress)==null?void 0:c.call(a,Math.min(1,o.loaded/o.total))},"model:error":o=>{var a,c;return(c=(a=n.current).onError)==null?void 0:c.call(a,o.error)}}),[]);eo(i,s);const r=se.useRef(null);se.useEffect(()=>{if(!e){r.current=null;return}const o=n.current.onError;o&&r.current!==e&&(r.current=e,o(e))})}const to=se.createContext(null);function vh({viewer:i,canvasRef:e,children:t}){const n=se.useMemo(()=>({viewer:i,canvasRef:e}),[i,e]);return me.jsx(to.Provider,{value:n,children:t})}function no(){const i=se.useContext(to);if(!i)throw new Error("useViewerContext must be used within ViewerProvider");return i}function Mh(){const{canvasRef:i}=no();return me.jsx("canvas",{ref:i,style:{width:"100%",height:"100%",display:"block",imageRendering:"auto",background:"transparent"}})}(function(){try{if(typeof document<"u"){var i=document.createElement("style");i.appendChild(document.createTextNode(".gizmo-default{width:100px;height:100px;position:absolute;top:0;right:0;z-index:2;cursor:pointer}.custom-gizmo-style{width:360px;height:360px;position:absolute;top:0;right:0;z-index:2;cursor:pointer}.map-gizmo-style,.cad-gizmo-style{width:96px;height:96px;position:absolute;top:0;right:0;z-index:2;cursor:pointer}.example-container{position:relative;width:640px;height:360px;background-color:#3d5361;border-radius:6px;overflow:hidden}body{background-color:#f0f0f0;margin:0;padding:0}.content{display:flex;justify-content:center;align-items:center;flex-direction:column;height:100vh}.example-select{margin-bottom:24px}")),document.head.appendChild(i)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();const Rh=(i,e,t,n,s,r)=>{const o=performance.now(),a=()=>{const c=performance.now()-o,u=Math.min(c/s,1);i.position.lerpVectors(t,n,u),e==null||e.update(),r(),u<1&&requestAnimationFrame(a)};requestAnimationFrame(a)},Sr={type:"change"},Ri={type:"start"},so={type:"end"},cs=new f.Ray,_r=new f.Plane,Ch=Math.cos(70*f.MathUtils.DEG2RAD),Oe=new f.Vector3,Qe=2*Math.PI,Te={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},qs=1e-6;class io extends f.Controls{constructor(e,t=null){super(e,t),this.state=Te.NONE,this.target=new f.Vector3,this.cursor=new f.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:f.MOUSE.ROTATE,MIDDLE:f.MOUSE.DOLLY,RIGHT:f.MOUSE.PAN},this.touches={ONE:f.TOUCH.ROTATE,TWO:f.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new f.Vector3,this._lastQuaternion=new f.Quaternion,this._lastTargetPosition=new f.Vector3,this._quat=new f.Quaternion().setFromUnitVectors(e.up,new f.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new f.Spherical,this._sphericalDelta=new f.Spherical,this._scale=1,this._panOffset=new f.Vector3,this._rotateStart=new f.Vector2,this._rotateEnd=new f.Vector2,this._rotateDelta=new f.Vector2,this._panStart=new f.Vector2,this._panEnd=new f.Vector2,this._panDelta=new f.Vector2,this._dollyStart=new f.Vector2,this._dollyEnd=new f.Vector2,this._dollyDelta=new f.Vector2,this._dollyDirection=new f.Vector3,this._mouse=new f.Vector2,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Ih.bind(this),this._onPointerDown=Ph.bind(this),this._onPointerUp=Lh.bind(this),this._onContextMenu=zh.bind(this),this._onMouseWheel=Nh.bind(this),this._onKeyDown=Fh.bind(this),this._onTouchStart=kh.bind(this),this._onTouchMove=Bh.bind(this),this._onMouseDown=Oh.bind(this),this._onMouseMove=Dh.bind(this),this._interceptControlDown=Uh.bind(this),this._interceptControlUp=Vh.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(Sr),this.update(),this.state=Te.NONE}update(e=null){const t=this.object.position;Oe.copy(t).sub(this.target),Oe.applyQuaternion(this._quat),this._spherical.setFromVector3(Oe),this.autoRotate&&this.state===Te.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,s=this.maxAzimuthAngle;isFinite(n)&&isFinite(s)&&(n<-Math.PI?n+=Qe:n>Math.PI&&(n-=Qe),s<-Math.PI?s+=Qe:s>Math.PI&&(s-=Qe),n<=s?this._spherical.theta=Math.max(n,Math.min(s,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+s)/2?Math.max(n,this._spherical.theta):Math.min(s,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let r=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const o=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),r=o!=this._spherical.radius}if(Oe.setFromSpherical(this._spherical),Oe.applyQuaternion(this._quatInverse),t.copy(this.target).add(Oe),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let o=null;if(this.object.isPerspectiveCamera){const a=Oe.length();o=this._clampDistance(a*this._scale);const c=a-o;this.object.position.addScaledVector(this._dollyDirection,c),this.object.updateMatrixWorld(),r=!!c}else if(this.object.isOrthographicCamera){const a=new f.Vector3(this._mouse.x,this._mouse.y,0);a.unproject(this.object);const c=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),r=c!==this.object.zoom;const u=new f.Vector3(this._mouse.x,this._mouse.y,0);u.unproject(this.object),this.object.position.sub(u).add(a),this.object.updateMatrixWorld(),o=Oe.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;o!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position):(cs.origin.copy(this.object.position),cs.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(cs.direction))<Ch?this.object.lookAt(this.target):(_r.setFromNormalAndCoplanarPoint(this.object.up,this.target),cs.intersectPlane(_r,this.target))))}else if(this.object.isOrthographicCamera){const o=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),o!==this.object.zoom&&(this.object.updateProjectionMatrix(),r=!0)}return this._scale=1,this._performCursorZoom=!1,r||this._lastPosition.distanceToSquared(this.object.position)>qs||8*(1-this._lastQuaternion.dot(this.object.quaternion))>qs||this._lastTargetPosition.distanceToSquared(this.target)>qs?(this.dispatchEvent(Sr),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?Qe/60*this.autoRotateSpeed*e:Qe/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){Oe.setFromMatrixColumn(t,0),Oe.multiplyScalar(-e),this._panOffset.add(Oe)}_panUp(e,t){this.screenSpacePanning===!0?Oe.setFromMatrixColumn(t,1):(Oe.setFromMatrixColumn(t,0),Oe.crossVectors(this.object.up,Oe)),Oe.multiplyScalar(e),this._panOffset.add(Oe)}_pan(e,t){const n=this.domElement;if(this.object.isPerspectiveCamera){const s=this.object.position;Oe.copy(s).sub(this.target);let r=Oe.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*r/n.clientHeight,this.object.matrix),this._panUp(2*t*r/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),s=e-n.left,r=t-n.top,o=n.width,a=n.height;this._mouse.x=s/o*2-1,this._mouse.y=-(r/a)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(Qe*this._rotateDelta.x/t.clientHeight),this._rotateUp(Qe*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(Qe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-Qe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(Qe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-Qe*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._rotateStart.set(n,s)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panStart.set(n,s)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,s=e.pageY-t.y,r=Math.sqrt(n*n+s*s);this._dollyStart.set(0,r)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const n=this._getSecondPointerPosition(e),s=.5*(e.pageX+n.x),r=.5*(e.pageY+n.y);this._rotateEnd.set(s,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(Qe*this._rotateDelta.x/t.clientHeight),this._rotateUp(Qe*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),s=.5*(e.pageY+t.y);this._panEnd.set(n,s)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,s=e.pageY-t.y,r=Math.sqrt(n*n+s*s);this._dollyEnd.set(0,r),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const o=(e.pageX+t.x)*.5,a=(e.pageY+t.y)*.5;this._updateZoomParameters(o,a)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new f.Vector2,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function Ph(i){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(i.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(i)&&(this._addPointer(i),i.pointerType==="touch"?this._onTouchStart(i):this._onMouseDown(i)))}function Ih(i){this.enabled!==!1&&(i.pointerType==="touch"?this._onTouchMove(i):this._onMouseMove(i))}function Lh(i){switch(this._removePointer(i),this._pointers.length){case 0:this.domElement.releasePointerCapture(i.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(so),this.state=Te.NONE;break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function Oh(i){let e;switch(i.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case f.MOUSE.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(i),this.state=Te.DOLLY;break;case f.MOUSE.ROTATE:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=Te.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=Te.ROTATE}break;case f.MOUSE.PAN:if(i.ctrlKey||i.metaKey||i.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(i),this.state=Te.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(i),this.state=Te.PAN}break;default:this.state=Te.NONE}this.state!==Te.NONE&&this.dispatchEvent(Ri)}function Dh(i){switch(this.state){case Te.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(i);break;case Te.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(i);break;case Te.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(i);break}}function Nh(i){this.enabled===!1||this.enableZoom===!1||this.state!==Te.NONE||(i.preventDefault(),this.dispatchEvent(Ri),this._handleMouseWheel(this._customWheelEvent(i)),this.dispatchEvent(so))}function Fh(i){this.enabled!==!1&&this._handleKeyDown(i)}function kh(i){switch(this._trackPointer(i),this._pointers.length){case 1:switch(this.touches.ONE){case f.TOUCH.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(i),this.state=Te.TOUCH_ROTATE;break;case f.TOUCH.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(i),this.state=Te.TOUCH_PAN;break;default:this.state=Te.NONE}break;case 2:switch(this.touches.TWO){case f.TOUCH.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(i),this.state=Te.TOUCH_DOLLY_PAN;break;case f.TOUCH.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(i),this.state=Te.TOUCH_DOLLY_ROTATE;break;default:this.state=Te.NONE}break;default:this.state=Te.NONE}this.state!==Te.NONE&&this.dispatchEvent(Ri)}function Bh(i){switch(this._trackPointer(i),this.state){case Te.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(i),this.update();break;case Te.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(i),this.update();break;case Te.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(i),this.update();break;case Te.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(i),this.update();break;default:this.state=Te.NONE}}function zh(i){this.enabled!==!1&&i.preventDefault()}function Uh(i){i.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function Vh(i){i.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}class Hh extends io{constructor(e,t){super(e,t),this.screenSpacePanning=!1,this.mouseButtons={LEFT:f.MOUSE.PAN,MIDDLE:f.MOUSE.DOLLY,RIGHT:f.MOUSE.ROTATE},this.touches={ONE:f.TOUCH.PAN,TWO:f.TOUCH.DOLLY_ROTATE}}}const pe={CUBE_SIZE:1.8,EDGE_SECTION_SIZE:.35,FACE_THICKNESS:.35,CANVAS_SIZE:256,FONT_SIZE:"62px",TEXT_COLOR:"#000000",TEXT_ALIGN:"center",TEXT_BASELINE:"middle",FACE_COLOR:"#EFF3F2",EDGE_COLOR:"#EFF3F2",CORNER_COLOR:"#EFF3F2",LINE_COLOR:0};var It=(i=>(i.FRONT="FRONT",i.BACK="BACK",i.RIGHT="RIGHT",i.LEFT="LEFT",i.TOP="TOP",i.BOTTOM="BOTTOM",i))(It||{});new E.Vector3(0,1,0);const Mn="rotation-arrows-name",Ei="left-rotation-arrow-name",Es="right-rotation-arrow-name",jh="gizmo-group-name",Gh=[Es,Ei],fs={GIZMO_DISTANCE:8,DEFAULT_UP:new E.Vector3(0,1,0),FORWARD:new E.Vector3(0,0,-1)},$s=i=>fs.FORWARD.clone().applyQuaternion(i),br=(i,e,t=new E.Vector3)=>t.clone().add(i.multiplyScalar(-e));class Wh{constructor(e,t=Mn){this.gizmoScene=e,this.gizmoArrowsName=t}syncGizmoWithMain(e,t){e.quaternion.copy(t.quaternion),e.up.copy(t.up);const n=$s(e.quaternion).normalize();e.position.copy(br(n,fs.GIZMO_DISTANCE)),e.camera.updateMatrixWorld(!0);const s=this.gizmoScene.getObjectByName(this.gizmoArrowsName);s&&s.rotation.copy(e.camera.rotation)}syncMainWithGizmo(e,t,n){const s=n.target.clone(),r=e.position.distanceTo(s),o=e.camera instanceof E.PerspectiveCamera;n instanceof Hh&&!o?this.syncMapControls(e,t,s,r):this.syncOrbitControls(e,t,s,r),e.camera.updateMatrix(),e.camera.updateMatrixWorld(!0),n.update()}syncMapControls(e,t,n,s){const r=e.position.y-n.y,o=$s(t.quaternion);o.y=0,o.normalize();const a=n.clone();a.y+=r,a.add(o.multiplyScalar(-s)),e.position.copy(a),e.up.copy(fs.DEFAULT_UP),e.camera.lookAt(n)}syncOrbitControls(e,t,n,s){const r=$s(t.quaternion),o=fs.DEFAULT_UP.clone().applyQuaternion(t.quaternion),a=br(r,s,n);e.position.copy(a),e.up.copy(o),e.camera.lookAt(n)}}const ro=i=>new Wh(i),xr=(i,e,t)=>{ro(t).syncGizmoWithMain({camera:i,position:i.position,quaternion:i.quaternion,up:i.up},{camera:e,position:e.position,quaternion:e.quaternion,up:e.up})},Zh=(i,e,t)=>{ro(e.userData.scene).syncMainWithGizmo({camera:i,position:i.position,quaternion:i.quaternion,up:i.up},{camera:e,position:e.position,quaternion:e.quaternion,up:e.up},t)},Kh=()=>{try{const i=document.createElement("canvas");return!!(window.WebGLRenderingContext&&(i.getContext("webgl")||i.getContext("experimental-webgl")))}catch{return!1}},Xh=()=>Kh()?new E.WebGLRenderer({alpha:!0,antialias:!1}):(console.error("WebGL is not supported in this environment."),null),Yh=i=>{const e=new E.AmbientLight(16777215,1);i.add(e);const t=new E.DirectionalLight(16777215,1);t.position.set(5,10,5),i.add(t);const n=new E.DirectionalLight(16777215,1);n.position.set(-5,-10,5),i.add(n);const s=new E.PointLight(16777215,1,100);s.position.set(0,0,5),i.add(s),t.castShadow=!1,n.castShadow=!1,s.castShadow=!1};class qh{static createTextTexture(e){const t=document.createElement("canvas"),n=t.getContext("2d");t.width=pe.CANVAS_SIZE,t.height=pe.CANVAS_SIZE,n&&(n.clearRect(0,0,t.width,t.height),n.font=`${pe.FONT_SIZE} Arial`,n.fillStyle=pe.TEXT_COLOR,n.textAlign=pe.TEXT_ALIGN,n.textBaseline=pe.TEXT_BASELINE,n.fillText(e,t.width/2,t.height/2));const s=new E.CanvasTexture(t);return s.needsUpdate=!0,s}}class ls{static createWireframe([e,t,n]){const s=new E.BoxGeometry(e,t,n),r=new E.EdgesGeometry(s),o=new E.LineBasicMaterial({color:pe.LINE_COLOR}),a=new E.LineSegments(r,o);return a.name="Wireframe",a}static createEdgeBox(e,t,n){const s=pe.CUBE_SIZE-pe.EDGE_SECTION_SIZE,r={x:pe.EDGE_SECTION_SIZE,y:pe.EDGE_SECTION_SIZE,z:pe.EDGE_SECTION_SIZE};r[t]=s;const o=new E.BoxGeometry(r.x,r.y,r.z),a=new E.MeshStandardMaterial({color:pe.EDGE_COLOR}),c=new E.Mesh(o,a);return c.position.copy(e),c.name=`Edge Box ${n}`,c}static createCornerCube(e,t){const n=new E.BoxGeometry(pe.EDGE_SECTION_SIZE,pe.EDGE_SECTION_SIZE,pe.EDGE_SECTION_SIZE),s=new E.MeshStandardMaterial({color:pe.CORNER_COLOR}),r=new E.Mesh(n,s);return r.position.copy(e),r.name=`Corner Cube ${t}`,r}static createFace(e,t,n){const s=new E.Group,r=new E.BoxGeometry(pe.CUBE_SIZE-pe.EDGE_SECTION_SIZE,pe.CUBE_SIZE-pe.EDGE_SECTION_SIZE,pe.FACE_THICKNESS),o=new E.MeshStandardMaterial({color:pe.FACE_COLOR}),a=new E.Mesh(r,o);a.name=`Face Box ${n}`,s.add(a);const c=new E.PlaneGeometry(pe.CUBE_SIZE-pe.EDGE_SECTION_SIZE,pe.CUBE_SIZE-pe.EDGE_SECTION_SIZE),u=new E.MeshStandardMaterial({map:qh.createTextTexture(n),transparent:!0,depthWrite:!1}),d=new E.Mesh(c,u);return d.position.set(0,0,pe.FACE_THICKNESS/2+.01),s.add(d),s.position.copy(e),s.rotation.copy(t),s}}const $h=(i,e)=>{const t=document.createElement("canvas");t.width=64,t.height=64;const n=t.getContext("2d");n.fillStyle="rgba(0, 0, 0, 0)",n.fillRect(0,0,t.width,t.height),n.font="Bold 48px Arial",n.fillStyle=`#${e.toString(16).padStart(6,"0")}`,n.textAlign="center",n.textBaseline="middle",n.fillText(i,t.width/2,t.height/2);const s=new E.CanvasTexture(t),r=new E.SpriteMaterial({map:s}),o=new E.Sprite(r);return o.scale.set(.5,.5,.5),o};class Qh{constructor(e){this.hoveredObject=null,this.originalColor=null,this.config=e}get vectorToCube(){var e;return(e=this.hoveredObject)==null?void 0:e.userData.vectorToCube}getInitialRotation(){switch(this.config.initialFace){case It.BACK:return new E.Euler(0,Math.PI,0);case It.RIGHT:return new E.Euler(0,-Math.PI/2,0);case It.LEFT:return new E.Euler(0,Math.PI/2,0);case It.TOP:return new E.Euler(Math.PI/2,0,0);case It.BOTTOM:return new E.Euler(-Math.PI/2,0,0);case It.FRONT:default:return new E.Euler(0,0,0)}}createWireframe(){const e=pe.CUBE_SIZE+pe.EDGE_SECTION_SIZE,t=ls.createWireframe([e,e,e]);return t.userData.gizmoCube=this,t}createEdgeBox(e,t,n){const s=ls.createEdgeBox(e,t,n);return s.userData.gizmoCube=this,s}createCornerCube(e,t){const n=ls.createCornerCube(e,t);return n.userData.gizmoCube=this,n}createFace(e,t,n){const s=ls.createFace(e,t,n),r=s.getObjectByName(`Face Box ${n}`);return r.userData.gizmoCube=this,s}createEdges(e){const t=pe.CUBE_SIZE/2;[{axis:"x",pos:new E.Vector3(0,t,-t)},{axis:"x",pos:new E.Vector3(0,t,t)},{axis:"x",pos:new E.Vector3(0,-t,-t)},{axis:"x",pos:new E.Vector3(0,-t,t)},{axis:"y",pos:new E.Vector3(t,0,-t)},{axis:"y",pos:new E.Vector3(t,0,t)},{axis:"y",pos:new E.Vector3(-t,0,-t)},{axis:"y",pos:new E.Vector3(-t,0,t)},{axis:"z",pos:new E.Vector3(t,t,0)},{axis:"z",pos:new E.Vector3(t,-t,0)},{axis:"z",pos:new E.Vector3(-t,t,0)},{axis:"z",pos:new E.Vector3(-t,-t,0)}].forEach(({axis:n,pos:s},r)=>{const o=this.createEdgeBox(s,n,r+1);e.add(o)})}createCorners(e){const t=pe.CUBE_SIZE/2;[new E.Vector3(-t,-t,-t),new E.Vector3(-t,-t,t),new E.Vector3(-t,t,-t),new E.Vector3(-t,t,t),new E.Vector3(t,-t,-t),new E.Vector3(t,-t,t),new E.Vector3(t,t,-t),new E.Vector3(t,t,t)].forEach((n,s)=>{const r=this.createCornerCube(n,s+1);e.add(r)})}createFaces(e){const t=pe.CUBE_SIZE/2;[{pos:new E.Vector3(0,0,t),rotation:new E.Euler(0,0,0),label:"FRONT"},{pos:new E.Vector3(0,0,-t),rotation:new E.Euler(0,Math.PI,0),label:"BACK"},{pos:new E.Vector3(t,0,0),rotation:new E.Euler(0,Math.PI/2,0),label:"RIGHT"},{pos:new E.Vector3(-t,0,0),rotation:new E.Euler(0,-Math.PI/2,0),label:"LEFT"},{pos:new E.Vector3(0,t,0),rotation:new E.Euler(-Math.PI/2,0,0),label:"TOP"},{pos:new E.Vector3(0,-t,0),rotation:new E.Euler(Math.PI/2,0,0),label:"BOTTOM"}].forEach(({pos:n,rotation:s,label:r})=>{const o=this.createFace(n,s,r);e.add(o)})}createAxis(e){const{color:t,direction:n,length:s,origin:r,lineWidth:o,label:a}=e,c=new E.Group,u=o/2,d=new E.CylinderGeometry(u,u,s,32),h=new E.MeshBasicMaterial({color:t}),p=new E.Mesh(d,h);if(p.position.copy(r).add(n.clone().multiplyScalar(s/2)),!n.equals(new E.Vector3(0,1,0))){const w=new E.Vector3(0,1,0).cross(n).normalize(),x=Math.acos(new E.Vector3(0,1,0).dot(n));p.setRotationFromAxisAngle(w,x)}c.add(p);const m=$h(a,t);return m.position.copy(r).add(n.clone().multiplyScalar(s+.1)),c.add(m),c}createCoordinateAxes(){const e=new E.Group,t=pe.CUBE_SIZE,n=pe.EDGE_SECTION_SIZE,s=-1.075,r=a=>{const c=new E.Vector3(1,1,1);return new E.Vector3(a,a,a).add(c.clone().normalize().negate().multiplyScalar(.04))},o=t+1.25*n;return[{color:16711680,direction:new E.Vector3(1,0,0),length:o,origin:r(s),lineWidth:.04,label:"X"},{color:65280,direction:new E.Vector3(0,1,0),length:o,origin:r(s),lineWidth:.04,label:"Y"},{color:255,direction:new E.Vector3(0,0,1),length:o,origin:r(s),lineWidth:.04,label:"Z"}].forEach(a=>{const c=this.createAxis(a);e.add(c)}),e}create(){const e=new E.Group;e.name=jh;const t=this.createWireframe();e.add(t),this.createEdges(e),this.createCorners(e),this.createFaces(e);const n=this.createCoordinateAxes();e.add(n);const s=this.getInitialRotation();return e.setRotationFromEuler(s),e}highlightObject(e){if(this.hoveredObject!==e)if(this.hoveredObject&&this.originalColor&&this.hoveredObject.material.color.set(this.originalColor),e&&e instanceof E.Mesh){const t=e.material;this.hoveredObject=e,this.originalColor=t.color.clone(),t.color.set(11519973)}else this.hoveredObject=null,this.originalColor=null}handleClick(){if(this.hoveredObject){let e=new E.Vector3;e=this.hoveredObject.getWorldPosition(e).clone();const t=new E.Vector3(0,0,0),n=e.sub(t).normalize();this.hoveredObject.userData.vectorToCube=n}}}class Jh{constructor(e){this.onChangeMainControlsListener=()=>{},this.onChangeGizmoControlsListener=()=>{},this.animationId=0;const{gizmoParams:t,mainParams:n,syncFunctions:s,options:r}=e;this.gizmoDiv=t.gizmoDiv,this.gizmoScene=t.gizmoScene,this.gizmoRenderer=t.gizmoRenderer,this.gizmoCamera=t.gizmoCamera,this.mainCamera=n.mainCamera,this.mainControls=n.mainControls,this.renderGizmo=n.renderGizmo,this.syncFunctions=s,this.options=r,this.gizmoControls=new io(this.gizmoCamera,this.gizmoRenderer.domElement),this.initializeRenderer(),this.initializeScene(),this.initializeControls(),this.startAnimationLoop()}initializeRenderer(){var e;this.gizmoRenderer.setPixelRatio(window.devicePixelRatio),this.gizmoRenderer.setSize(this.gizmoDiv.clientWidth,this.gizmoDiv.clientHeight);const t=this.gizmoDiv.clientWidth/this.gizmoDiv.clientHeight;this.gizmoCamera.aspect=t,this.gizmoCamera.updateProjectionMatrix(),(e=this.options)!=null&&e.up&&this.gizmoCamera.up.copy(this.options.up),this.gizmoDiv.appendChild(this.gizmoRenderer.domElement)}initializeScene(){var e;const t=new Qh({initialFace:((e=this.options)==null?void 0:e.initialFace)??It.FRONT}).create();this.gizmoScene.add(t),Yh(this.gizmoScene)}initializeControls(){this.onChangeMainControlsListener=()=>this.syncFunctions.syncGizmoCameraWithMain(this.gizmoCamera,this.mainCamera,this.gizmoScene),this.mainControls.addEventListener("change",this.onChangeMainControlsListener),this.gizmoControls.enableZoom=!1,this.gizmoControls.enablePan=!1,this.gizmoControls.rotateSpeed=.5,this.gizmoControls.update(),this.onChangeGizmoControlsListener=()=>{const e=this.gizmoScene.getObjectByName(Mn);e==null||e.rotation.copy(this.gizmoCamera.rotation),this.syncFunctions.syncMainCameraWithGizmo(this.mainCamera,this.gizmoCamera,this.mainControls),this.renderGizmo()},this.gizmoControls.addEventListener("change",this.onChangeGizmoControlsListener)}startAnimationLoop(){const e=()=>{this.gizmoRenderer.render(this.gizmoScene,this.gizmoCamera)},t=()=>{this.animationId=requestAnimationFrame(t),e()};t()}dispose(){this.mainControls.removeEventListener("change",this.onChangeMainControlsListener),this.gizmoControls.removeEventListener("change",this.onChangeGizmoControlsListener),this.gizmoScene.clear(),cancelAnimationFrame(this.animationId)}}const eu=(i,e)=>{let t;return function(...n){t||(i.apply(this,n),t=!0,setTimeout(()=>t=!1,e))}};function Ar(i,e,t){if(!e)return;const n=e.domElement.getBoundingClientRect();t.x=(i.clientX-n.left)/n.width*2-1,t.y=-((i.clientY-n.top)/n.height)*2+1}const oo=(i,e,t,n)=>(n.setFromCamera(i,e),n.intersectObjects(t.children,!0)),ao=i=>{var e;const t=["Wireframe",""];return((e=i.find(n=>!t.includes(n.object.name)))==null?void 0:e.object)||null};function tu(i,e,t,n){if(!e||!t)return null;const s=oo(i,e,t,n);return ao(s)}function nu(i,e){const t=i==null?void 0:i.userData.gizmoCube;if(i&&t){t.handleClick();const n=t.vectorToCube;n&&e(n)}}const su={radius:2.1,color:12369854,tubeRadius:.1,tubeSegments:8,numPoints:64,tubeOffset:1.5},iu={size:.2,depth:.1,heightRatio:1.4,segments:1};class ru{constructor(e={}){this.config={...su,...e},this.material=new E.MeshBasicMaterial({color:this.config.color})}create(){const e=new E.Group,t=this.createQuarterCircleCurves();return e.add(...this.createTubes(t),...this.createArrowHeads(t)),e.name=Mn,e}createQuarterCircleCurves(){const e=this.generateQuarterCirclePoints(),t=Math.floor(e.length/2);return[new E.CatmullRomCurve3(e.slice(0,t-this.config.tubeOffset)),new E.CatmullRomCurve3(e.slice(t+this.config.tubeOffset))]}generateQuarterCirclePoints(){const e=Math.PI/2,t=e/2,n=e/4;return Array.from({length:this.config.numPoints+1},(s,r)=>{const o=r/this.config.numPoints,a=n+t*o,c=this.config.radius*Math.sin(a),u=this.config.radius*Math.cos(a);return new E.Vector3(c,u,0)})}createTubes([e,t]){const n=(s,r)=>{const o=new E.TubeGeometry(s,this.config.numPoints,this.config.tubeRadius,this.config.tubeSegments,!1),a=new E.Mesh(o,this.material);return a.name=r,a};return[n(e,Ei),n(t,Es)]}createArrowHeads([e,t]){const{size:n,depth:s,heightRatio:r,segments:o}=iu,a=this.createArrowShape(n,r),c=new E.ExtrudeGeometry(a,{steps:o,depth:s,bevelEnabled:!1}).center(),u=(d,h,p)=>{const m=new E.Mesh(c,this.material);return m.position.copy(d),m.rotation.z=h,m.name=p,m};return[u(e.getPoint(0),this.calculateArrowRotation(e.getTangent(0))+Math.PI/2,Ei),u(t.getPoint(1),this.calculateArrowRotation(t.getTangent(1))-Math.PI/2,Es)]}createArrowShape(e,t){return new E.Shape().moveTo(0,0).lineTo(e,-e*t).lineTo(-e,-e*t).lineTo(0,0)}calculateArrowRotation(e){return Math.atan2(e.y,e.x)}}const ou=i=>{const e=i.rotation,t=.01,n=Math.PI,s=(Math.abs(e.x)%(2*n)+2*n)%(2*n),r=(Math.abs(e.y)%(2*n)+2*n)%(2*n),o=Math.abs(s-n/2)<t||Math.abs(s-3*n/2)<t||Math.abs(r-n/2)<t||Math.abs(r-3*n/2)<t,a=(Math.abs(s)<t||Math.abs(s-n)<t)&&(Math.abs(r)<t||Math.abs(r-n)<t);return!(o||a)},au=25,cu=200;function lu({gizmoRenderer:i,gizmoScene:e,gizmoCamera:t,alignCameraWithVector:n,gizmoControlRef:s}){const r=se.useRef(null),o=se.useRef(null),a=se.useRef(new E.Raycaster).current,c=se.useRef(new E.Vector2).current,u=se.useCallback(()=>{const x=e.getObjectByName(Mn),_=ou(t);if(x&&_){e.remove(x);return}if(x||_)return;const v=new ru().create();v.rotation.copy(t.rotation),e.add(v)},[e,t]),d=se.useCallback(()=>{const x=e.getObjectByName(Mn);x&&e.remove(x)},[e]),h=se.useCallback(eu(x=>{if(!s.current||!i)return;Ar(x,i,c);const _=oo(c,t,e,a),v=ao(_);v!=null&&v.userData.gizmoCube?v.userData.gizmoCube.highlightObject(v):e.traverse(T=>{T.userData.gizmoCube&&T.userData.gizmoCube.highlightObject(null)}),_.length>0?u():d()},1e3/au),[s,i,t,e,a,c,u,d]),p=se.useCallback(x=>{r.current=Date.now(),o.current={x:x.clientX,y:x.clientY}},[]),m=se.useCallback(x=>{var _;const v=x.name===Es?1:-1,T=90*Math.PI/180,S=new E.Vector3(0,0,0),b=v*T,A=new E.Matrix4;A.makeRotationZ(b),t.up.applyMatrix4(A),t.lookAt(S),(_=s.current)==null||_.gizmoControls.update()},[t,s]),w=se.useCallback(x=>{if((r.current?Date.now()-r.current:0)<cu){Ar(x,i,c);const _=tu(c,t,e,a);_!=null&&_.name&&Gh.includes(_.name)?m(_):nu(_,n)}r.current=null,o.current=null},[m,n,i,t,e,a,c]);return{onMouseDown:p,onMouseMove:h,onMouseUp:w,onMouseLeave:d}}const hu=({camera:i,controls:e,className:t,render:n,options:s})=>{const r=se.useRef(null),o=se.useRef(new E.Scene).current,[a]=se.useState(()=>Xh()),c=30,u=1,d=.1,h=10,p=new E.PerspectiveCamera(c,u,d,h),m=se.useRef(p).current,w=se.useRef(null),x=se.useCallback(()=>{a&&(n(),a.render(o,m))},[n,a,o,m]),_=se.useCallback(A=>{if(!i||!e)return;const L=i.position.length(),P=A.clone().multiplyScalar(L),C=400,D=new E.Matrix4;D.lookAt(P,new E.Vector3(0,0,0),new E.Vector3(0,1,0));const I=new E.Quaternion;I.setFromRotationMatrix(D),i.quaternion.copy(I),Rh(i,e,i.position.clone(),P,C,x),i.up.set(0,1,0),i.lookAt(new E.Vector3(0,0,0)),e.target.set(0,0,0),e.update()},[i,e,x,o]),{onMouseDown:v,onMouseMove:T,onMouseUp:S,onMouseLeave:b}=lu({gizmoRenderer:a,gizmoScene:o,gizmoCamera:m,alignCameraWithVector:_,gizmoControlRef:w});return se.useEffect(()=>{const A=r.current;if(!A||!i||!e||!a)return;w.current&&w.current.dispose();const L={gizmoDiv:A,gizmoScene:o,gizmoRenderer:a,gizmoCamera:m},P={mainCamera:i,mainControls:e,renderGizmo:x},C={syncGizmoCameraWithMain:xr,syncMainCameraWithGizmo:Zh};return w.current=new Jh({gizmoParams:L,mainParams:P,syncFunctions:C,options:s}),A.addEventListener("mousedown",v),A.addEventListener("mousemove",T),A.addEventListener("mouseup",S),A.addEventListener("mouseleave",b),()=>{w.current&&(w.current.dispose(),w.current=null),A.removeEventListener("mousedown",v),A.removeEventListener("mousemove",T),A.removeEventListener("mouseup",S),A.removeEventListener("mouseleave",b)}},[i,e,x,T,v,S]),se.useEffect(()=>{i&&(xr(m,i,o),x())},[i,x]),me.jsx("div",{className:t?`${t}`:"gizmo-default",ref:r})},hs=10,uu=i=>({top:i.startsWith("top")?hs:"auto",bottom:i.startsWith("bottom")?hs:"auto",left:i.endsWith("left")?hs:"auto",right:i.endsWith("right")?hs:"auto"}),du=({camera:i,controls:e,render:t,placement:n="top-right",size:s=128})=>{if(!i||!e)return null;const r=e;return me.jsx("div",{className:"viewer-gizmo-container",style:{position:"absolute",width:s,height:s,zIndex:1e3,...uu(n)},children:me.jsx(hu,{camera:i,controls:r,render:t})})};class pu extends se.Component{constructor(e){super(e),this.reset=()=>{this.setState({hasError:!1,error:null})},this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("ViewerErrorBoundary caught error:",e,t)}render(){var e;return this.state.hasError?this.props.fallback?this.props.fallback:me.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f0f0",color:"#333",fontFamily:"sans-serif",padding:"20px",textAlign:"center"},children:me.jsxs("div",{children:[me.jsx("h3",{children:"Error Loading 3D Viewer"}),me.jsx("p",{children:((e=this.state.error)==null?void 0:e.message)||"An unexpected error occurred"}),me.jsx("button",{type:"button",onClick:this.reset,children:"Try again"})]})}):this.props.children}}function fu({status:i,label:e,color:t,backdrop:n}){const s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;return me.jsxs("div",{"data-testid":"viewer-loading-overlay",role:"status","aria-live":"polite","aria-busy":i==="loading",style:{position:"absolute",inset:0,zIndex:20,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12,background:n,color:t,pointerEvents:"none",userSelect:"none",fontFamily:"system-ui, -apple-system, Segoe UI, Roboto, sans-serif",fontSize:14},children:[i==="loading"?me.jsxs("svg",{width:"44",height:"44",viewBox:"0 0 44 44","aria-hidden":"true",children:[me.jsx("circle",{cx:"22",cy:"22",r:"18",fill:"none",stroke:t,strokeOpacity:"0.25",strokeWidth:"4"}),me.jsx("path",{d:"M22 4 a18 18 0 0 1 18 18",fill:"none",stroke:t,strokeWidth:"4",strokeLinecap:"round",children:!s&&me.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 22 22",to:"360 22 22",dur:"0.9s",repeatCount:"indefinite"})})]}):me.jsxs("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[me.jsx("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),me.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),me.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e&&me.jsx("div",{style:{opacity:.92,maxWidth:"80%",textAlign:"center"},children:e})]})}const mu='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',gu={background:"rgba(255,255,255,0.78)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:"1px solid rgba(0,0,0,0.06)",boxShadow:"0 8px 30px rgba(0,0,0,0.10)"},yu=Object.keys(Mi);function wu({active:i,onSelect:e}){return me.jsx("div",{"data-testid":"viewer-preset-picker",role:"group","aria-label":"Visual preset",style:{position:"absolute",bottom:16,left:"50%",transform:"translateX(-50%)",zIndex:10,display:"flex",gap:2,padding:4,borderRadius:999,maxWidth:"calc(100% - 16px)",overflowX:"auto",...gu},children:yu.map(t=>me.jsx("button",{type:"button","aria-pressed":t===i,onClick:()=>e(t),style:{padding:"6px 14px",borderRadius:999,border:t===i?"1px solid #111318":"1px solid transparent",background:t===i?"#111318":"transparent",color:t===i?"#fff":"#3f3f4a",fontFamily:mu,fontSize:13,fontWeight:500,lineHeight:1,whiteSpace:"nowrap",flexShrink:0,cursor:"pointer",textTransform:"capitalize",transition:"background 120ms ease, color 120ms ease"},children:t},t))})}const Sn={enabled:!0,label:"Loading…",color:"#ffffff",backdrop:"rgba(15,16,20,0.6)"};function Eu(i){return i===void 0||i===!0?Sn:i===!1?{...Sn,enabled:!1}:{enabled:i.enabled??!0,label:i.label??Sn.label,errorLabel:i.errorLabel,color:i.color??Sn.color,backdrop:i.backdrop??Sn.backdrop}}const us=()=>new Z("Viewer is not ready yet",X.COMPONENT_NOT_MOUNTED),co=se.forwardRef(({object:i,options:e={},preset:t,pathTraced:n,turntable:s,animations:r,children:o},a)=>{var N,H;const c=se.useRef(null),u=e.preset??t,{activePreset:d,pickerEnabled:h,selectPreset:p}=Sh(u,e.ui),m=_h(e,d,n,s,r),{viewer:w,isInitialized:x,initError:_}=Th(c,m),v=bh(w,x,i),T=xh(w);Ah(w,_,e);const S=w?Rn(w.getCamera()):null,b=w?vi(w.getControls()):null,A=w?Gr(w.getRenderer()):null,L=se.useCallback(()=>{w==null||w.requestRender()},[w]),P=((N=e.helpers)==null?void 0:N.gizmo)!==void 0&&e.helpers.gizmo!==!1,C=typeof((H=e.helpers)==null?void 0:H.gizmo)=="object"?e.helpers.gizmo:{},D=se.useMemo(()=>Eu(e.loadingIndicator),[e.loadingIndicator]),I=v.status==="error"||!!_,k=D.enabled&&(v.status==="loading"||I);return se.useImperativeHandle(a,()=>({scene:w?Tt(w.getScene()):null,camera:S,renderer:A,controls:b,events:T,loadModel:async G=>{if(!w)throw us();const $=typeof G=="string"?G:new Ke(G),re=await w.loadModel($);if(!re.ok)throw re.error},captureStill:async G=>{if(!w)throw us();const $=await w.captureStill(G);if(!$.ok)throw $.error;return $.value},captureVideo:async G=>{if(!w)throw us();const $=await w.captureVideo(G);if(!$.ok)throw $.error;return $.value},getAnimationNames:()=>(w==null?void 0:w.getAnimationNames())??[],playAnimations:G=>{if(!w)throw us();const $=w.playAnimations(G);if(!$.ok)throw $.error},pauseAnimations:()=>{w==null||w.pauseAnimations()},dispose:()=>{w==null||w.dispose()}}),[w,S,A,b,T]),me.jsx(pu,{children:me.jsx(vh,{viewer:w,canvasRef:c,children:me.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[me.jsx(Mh,{}),P&&x&&S&&b&&me.jsx(du,{camera:S,controls:b,render:L,placement:C.placement,size:C.size}),k&&me.jsx(fu,{status:I?"error":"loading",label:I?D.errorLabel??(_==null?void 0:_.message)??v.error??"Failed to load model":D.label,color:D.color,backdrop:D.backdrop}),h&&me.jsx(wu,{active:d??"studio",onSelect:p}),o]})})})});co.displayName="SimpleViewer";const lo=se.forwardRef((i,e)=>me.jsx(co,{ref:e,...i}));lo.displayName="SimpleViewer";const Tu=()=>me.jsx("span",{"aria-hidden":"true",style:{display:"block",width:14,height:14,borderRadius:"50%",background:"rgba(17,19,24,0.9)",border:"2px solid rgba(255,255,255,0.95)",boxShadow:"0 2px 8px rgba(0,0,0,0.35)"}});function Su({position:i,occlude:e=!1,children:t}){const{viewer:n}=no(),s=se.useRef(null),[r,o,a]=i;se.useEffect(()=>{if(!n)return;const u=s.current;if(!u)return;const d=n.createAnchorProjector();if(!d)return;const h={x:r,y:o,z:a},p=()=>{const _=d.project(h,e);if(_){if(!_.visible){u.style.visibility="hidden";return}u.style.visibility="visible",u.style.left=`${_.left}px`,u.style.top=`${_.top}px`}},m=()=>{d.invalidate(),p()};p();const w=n.getEvents(),x=[w.on("render:complete",p),w.on("controls:change",p),w.on("model:loaded",m)];return window.addEventListener("resize",m),()=>{x.forEach(_=>_()),window.removeEventListener("resize",m)}},[n,r,o,a,e]);const c=t!=null&&t!==!1;return me.jsx("div",{ref:s,"data-testid":"viewer-hotspot",style:{position:"absolute",left:0,top:0,transform:"translate(-50%, -50%)",visibility:"hidden",zIndex:5,pointerEvents:c?"auto":"none"},children:c?t:me.jsx(Tu,{})})}exports.BOUNDING_DATA_INDEX=la;exports.BYTES_PER_NODE=Ve;exports.CONTACT_SHADOW_HELPER_FLAG=vs;exports.COUNT=Xe;exports.ControlType=vn;exports.DEFAULT_PATH_TRACING_SAMPLES=Qs;exports.ErrorCode=X;exports.Hotspot=Su;exports.IS_LEAF=Pe;exports.LEAFNODE_MASK_32=ca;exports.MeshBVH=An;exports.OFFSET=He;exports.Result=F;exports.SAH=Ir;exports.SPLIT_AXIS=Ss;exports.SimpleViewerWrapper=lo;exports.ThreeViewerError=Z;exports.TypedEventEmitter=Ts;exports.VIEWER_PRESETS=Mi;exports.defaultOptions=ws;exports.getIndexArray=Nr;exports.getVertexCount=_s;exports.resolvePreset=Jr;
|