UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

72 lines 225 kB
class e extends Error{}e._setPrototypeOf=Object.setPrototypeOf||((e,t)=>(e.__proto__=t,e));class t extends e{constructor(n="Operation aborted"){super(n),this.name="AbortError",e._setPrototypeOf(this,t.prototype)}}class n{get resolve(){return this._resolve}get reject(){return this._reject}constructor(){this.promise=new Promise((e,t)=>{this._resolve=e,this._reject=t})}}class i{constructor(){this._currentOperation=Promise.resolve()}lockAsync(e,t){t?.throwIfAborted();const n=t?()=>(t.throwIfAborted(),e()):e,i=this._currentOperation.then(n);return this._currentOperation=new Promise(e=>{i.then(()=>e(),e)}),i}static async LockAsync(e,t,i){if(i?.throwIfAborted(),0===t.length)return await e();const r=new n;let s=0;for(const n of t)n.lockAsync(async()=>(s++,s===t.length&&r.resolve(await e()),await r.promise),i).catch(e=>r.reject(e));return await r.promise}}class r{static _CheckLimit(e,t){let n=r._LogLimitOutputs[e];return n?n.current++:(n={limit:t,current:1},r._LogLimitOutputs[e]=n),n.current<=n.limit}static _GenerateLimitMessage(e,t=1){const n=r._LogLimitOutputs[e];if(!n||!r.MessageLimitReached)return;const i=this._Levels[t];n.current===n.limit&&r[i.name](r.MessageLimitReached.replace(/%LIMIT%/g,""+n.limit).replace(/%TYPE%/g,i.name??""))}static _AddLogEntry(e){r._LogCache=e+r._LogCache,r.OnNewCacheEntry&&r.OnNewCacheEntry(e)}static _FormatMessage(e){const t=e=>e<10?"0"+e:""+e,n=new Date;return"["+t(n.getHours())+":"+t(n.getMinutes())+":"+t(n.getSeconds())+"]: "+e}static _LogDisabled(e,t){}static _LogEnabled(e=1,t,n){const i=Array.isArray(t)?t[0]:t;if(void 0!==n&&!r._CheckLimit(i,n))return;const s=r._FormatMessage(i),o=this._Levels[e],a=Array.isArray(t)?t.slice(1):[];o.logFunc&&o.logFunc("BJS - "+s,...a);const l=`<div style='color:${o.color}'>${s}</div><br>`;r._AddLogEntry(l),r._GenerateLimitMessage(i,e)}static get LogCache(){return r._LogCache}static ClearLogCache(){r._LogCache="",r._LogLimitOutputs={},r.errorsCount=0}static set LogLevels(e){r.Log=r._LogDisabled,r.Warn=r._LogDisabled,r.Error=r._LogDisabled;const t=[r.MessageLogLevel,r.WarningLogLevel,r.ErrorLogLevel];for(const n of t)if((e&n)===n){const e=this._Levels[n];r[e.name]=r._LogEnabled.bind(r,n)}}}r.NoneLogLevel=0,r.MessageLogLevel=1,r.WarningLogLevel=2,r.ErrorLogLevel=4,r.AllLogLevel=7,r.MessageLimitReached="Too many %TYPE%s (%LIMIT%), no more %TYPE%s will be reported for this message.",r._LogCache="",r._LogLimitOutputs={},r._Levels=[{},{color:"white",logFunc:console.log,name:"Log"},{color:"orange",logFunc:console.warn,name:"Warn"},{},{color:"red",logFunc:console.error,name:"Error"}],r.errorsCount=0,r.Log=r._LogEnabled.bind(r,r.MessageLogLevel),r.Warn=r._LogEnabled.bind(r,r.WarningLogLevel),r.Error=r._LogEnabled.bind(r,r.ErrorLogLevel);const s="undefined"!=typeof WeakRef;class o{constructor(e,t=!1,n,i){this.initialize(e,t,n,i)}initialize(e,t=!1,n,i){return this.mask=e,this.skipNextObservers=t,this.target=n,this.currentTarget=i,this}}class a{constructor(e,t,n=null){this.callback=e,this.mask=t,this.scope=n,this._willBeUnregistered=!1,this.unregisterOnNextCall=!1,this._remove=null}remove(e=!1){this._remove&&this._remove(e)}}class l{static FromPromise(e,t){const n=new l;return e.then(e=>{n.notifyObservers(e)}).catch(e=>{if(!t)throw e;t.notifyObservers(e)}),n}get observers(){return this._observers}constructor(e,t=!1){this.notifyIfTriggered=t,this._observers=new Array,this._numObserversMarkedAsDeleted=0,this._hasNotified=!1,this._eventState=new o(0),e&&(this._onObserverAdded=e)}add(e,t=-1,n=!1,i=null,r=!1){if(!e)return null;const o=new a(e,t,i);o.unregisterOnNextCall=r,n?this._observers.unshift(o):this._observers.push(o),this._onObserverAdded&&this._onObserverAdded(o),this._hasNotified&&this.notifyIfTriggered&&void 0!==this._lastNotifiedValue&&this.notifyObserver(o,this._lastNotifiedValue);const l=s?new WeakRef(this):{deref:()=>this};return o._remove=(e=!1)=>{const t=l.deref();t&&(e?t.remove(o):t._remove(o))},o}addOnce(e){return this.add(e,void 0,void 0,void 0,!0)}remove(e){if(!e)return!1;e._remove=null;return-1!==this._observers.indexOf(e)&&(this._deferUnregister(e),!0)}removeCallback(e,t){for(let n=0;n<this._observers.length;n++){const i=this._observers[n];if(!i._willBeUnregistered&&(i.callback===e&&(!t||t===i.scope)))return this._deferUnregister(i),!0}return!1}_deferUnregister(e){e._willBeUnregistered||(this._numObserversMarkedAsDeleted++,e.unregisterOnNextCall=!1,e._willBeUnregistered=!0,setTimeout(()=>{this._remove(e)},0))}_remove(e,t=!0){if(!e)return!1;const n=this._observers.indexOf(e);return-1!==n&&(t&&this._numObserversMarkedAsDeleted--,this._observers.splice(n,1),!0)}makeObserverTopPriority(e){this._remove(e,!1),this._observers.unshift(e)}makeObserverBottomPriority(e){this._remove(e,!1),this._observers.push(e)}notifyObservers(e,t=-1,n,i,r){if(this.notifyIfTriggered&&(this._hasNotified=!0,this._lastNotifiedValue=e),!this._observers.length)return!0;const s=this._eventState;s.mask=t,s.target=n,s.currentTarget=i,s.skipNextObservers=!1,s.lastReturnValue=e,s.userInfo=r;for(const n of this._observers)if(!n._willBeUnregistered&&(n.mask&t&&(n.unregisterOnNextCall&&this._deferUnregister(n),n.scope?s.lastReturnValue=n.callback.apply(n.scope,[e,s]):s.lastReturnValue=n.callback(e,s)),s.skipNextObservers))return!1;return!0}notifyObserver(e,t,n=-1){if(this.notifyIfTriggered&&(this._hasNotified=!0,this._lastNotifiedValue=t),e._willBeUnregistered)return;const i=this._eventState;i.mask=n,i.skipNextObservers=!1,e.unregisterOnNextCall&&this._deferUnregister(e),e.callback(t,i)}hasObservers(){return this._observers.length-this._numObserversMarkedAsDeleted>0}clear(){for(;this._observers.length;){const e=this._observers.pop();e&&(e._remove=null)}this._onObserverAdded=null,this._numObserversMarkedAsDeleted=0,this.cleanLastNotifiedState()}cleanLastNotifiedState(){this._hasNotified=!1,this._lastNotifiedValue=void 0}clone(){const e=new l;return e._observers=this._observers.slice(0),e}hasSpecificMask(e=-1){for(const t of this._observers)if(t.mask&e||t.mask===e)return!0;return!1}}function c(...e){for(const t of e)t?.throwIfAborted()}function u(e){(async()=>{try{await e}catch(e){e instanceof t||r.Error(e)}})()}const h=["none","normal","high"],d=["none","standard","aces","neutral"];function p(e){return d.includes(e)}class _{constructor(){this.screenPosition=[NaN,NaN],this.worldPosition=[NaN,NaN,NaN],this.visibility=NaN}}const f={clearColor:[0,0,0,0],autoSuspendRendering:!0,environmentConfig:{intensity:1,blur:.3,rotation:0},environmentLighting:"auto",environmentSkybox:"none",cameraAutoOrbit:{enabled:!1,delay:2e3,speed:.05},animationAutoPlay:!1,animationSpeed:1,shadowConfig:{quality:"none"},postProcessing:{toneMapping:"neutral",contrast:1,exposure:1,ssao:"auto"},useRightHandedSystem:!1,useOpenPBR:!1},m=Math.PI/2,g=Math.PI/2.4;class b{constructor(){this.onEnvironmentChanged=new l,this.onEnvironmentConfigurationChanged=new l,this.onEnvironmentError=new l,this.onShadowsConfigurationChanged=new l,this.onPostProcessingChanged=new l,this.onModelChanged=new l,this.onModelError=new l,this.onLoadingProgressChanged=new l,this.onCameraAutoOrbitChanged=new l,this.onSelectedAnimationChanged=new l,this.onAnimationSpeedChanged=new l,this.onIsAnimationPlayingChanged=new l,this.onAnimationProgressChanged=new l,this.onSelectedMaterialVariantChanged=new l,this.onHotSpotsChanged=new l,this.onCamerasAsHotSpotsChanged=new l,this.onAfterRenderObservable=new l,this.onClearColorChanged=new l,this._loadOperations=new Set,this._isDisposed=!1,this._loadEnvironmentLightingLock=new i,this._loadEnvironmentLightingAbortController=null,this._loadEnvironmentSkyboxLock=new i,this._loadEnvironmentSkyboxAbortController=null,this._environmentIntensity=f.environmentConfig.intensity,this._environmentBlur=f.environmentConfig.blur,this._environmentRotation=f.environmentConfig.rotation,this._autoOrbitEnabled=f.cameraAutoOrbit.enabled,this._autoOrbitSpeed=f.cameraAutoOrbit.speed,this._autoOrbitDelay=f.cameraAutoOrbit.delay,this._clearColor={r:0,g:0,b:0,a:0},this._hotSpots={},this._loadModelLock=new i,this._loadModelAbortController=null,this._updateShadowsLock=new i,this._shadowsAbortController=null,this._shadowQuality=f.shadowConfig.quality}get loadingProgress(){if(this._loadOperations.size>0){let e=0;for(const t of this._loadOperations){if(null==t.progress)return!0;e+=t.progress}return e/this._loadOperations.size}return!1}_beginLoadOperation(){const e=this;let t=null;const n={get progress(){return t},set progress(n){t=n,e.onLoadingProgressChanged.notifyObservers()},dispose:()=>{e._loadOperations.delete(n),e.onLoadingProgressChanged.notifyObservers()}};return this._loadOperations.add(n),this.onLoadingProgressChanged.notifyObservers(),n}_throwIfDisposedOrAborted(...e){if(this._isDisposed)throw new Error("Viewer is disposed.");c(...e)}get _loadEnvironmentLightingAbortSignal(){return this._loadEnvironmentLightingAbortController?.signal}get _loadEnvironmentSkyboxAbortSignal(){return this._loadEnvironmentSkyboxAbortController?.signal}async loadEnvironment(e,t,n){return await this._updateEnvironment(e,t,n)}async resetEnvironment(e,t){return await this._updateEnvironment(void 0,e,t)}async _updateEnvironment(e,n,r){this._throwIfDisposedOrAborted(r);const s=!n||!!n.lighting,o=!n||!!n.skybox;if(!s&&!o)return;const a={...n,lighting:s,skybox:o},l=[],u=[];if(s){this._loadEnvironmentLightingAbortController?.abort(new t("New environment lighting is being loaded before previous environment lighting finished loading."));const e=this._loadEnvironmentLightingAbortController=new AbortController;l.push(this._loadEnvironmentLightingLock),u.push(e)}if(o){this._loadEnvironmentSkyboxAbortController?.abort(new t("New environment skybox is being loaded before previous environment skybox finished loading."));const e=this._loadEnvironmentSkyboxAbortController=new AbortController;l.push(this._loadEnvironmentSkyboxLock),u.push(e)}const h=new AbortController,d=()=>{u.every(e=>e.signal.aborted)&&h.abort(new t(u.map(e=>e.signal.reason).join(" | ")))};for(const e of u)e.signal.addEventListener("abort",d);try{await i.LockAsync(async()=>{c(r,h.signal),await this._loadEnvironmentImpl(e?.trim()??e,a,r,h.signal)},l)}finally{for(const e of u)e.signal.removeEventListener("abort",d)}}get environmentConfig(){return{intensity:this._environmentIntensity,blur:this._environmentBlur,rotation:this._environmentRotation}}set environmentConfig(e){void 0!==e.blur&&e.blur!==this._environmentBlur&&(this._environmentBlur=e.blur,this._applyEnvironmentBlur()),void 0!==e.intensity&&e.intensity!==this._environmentIntensity&&(this._environmentIntensity=e.intensity,this._applyEnvironmentIntensity()),void 0!==e.rotation&&e.rotation!==this._environmentRotation&&(this._environmentRotation=e.rotation,this._applyEnvironmentRotation()),this.onEnvironmentConfigurationChanged.notifyObservers()}get cameraAutoOrbit(){return{enabled:this._autoOrbitEnabled,speed:this._autoOrbitSpeed,delay:this._autoOrbitDelay}}set cameraAutoOrbit(e){let t=!1;void 0!==e.enabled&&e.enabled!==this._autoOrbitEnabled&&(this._autoOrbitEnabled=e.enabled,this._applyCameraAutoOrbitEnabled(),t=!0),void 0!==e.speed&&e.speed!==this._autoOrbitSpeed&&(this._autoOrbitSpeed=e.speed,this._applyCameraAutoOrbitSpeed(),t=!0),void 0!==e.delay&&e.delay!==this._autoOrbitDelay&&(this._autoOrbitDelay=e.delay,this._applyCameraAutoOrbitDelay(),t=!0),t&&this.onCameraAutoOrbitChanged.notifyObservers()}get clearColor(){return this._clearColor}set clearColor(e){this._clearColor.r=e.r,this._clearColor.g=e.g,this._clearColor.b=e.b,this._clearColor.a=e.a,this._applyClearColor(),this.onClearColorChanged.notifyObservers()}get hotSpots(){return this._hotSpots}set hotSpots(e){this._hotSpots=e,this.onHotSpotsChanged.notifyObservers()}get _loadModelAbortSignal(){return this._loadModelAbortController?.signal}async loadModel(e,t,n){return await this._updateModel(e,t,n)}async resetModel(e){return await this._updateModel(void 0,void 0,e)}async _updateModel(e,n,i){this._throwIfDisposedOrAborted(i),this._loadModelAbortController?.abort(new t("New model is being loaded before previous model finished loading."));const r=this._loadModelAbortController=new AbortController;await this._loadModelLock.lockAsync(async()=>{c(i,r.signal),await this._loadModelImpl(e,n,i,r.signal)}),r.signal.aborted||await this._afterLoadModel(e,n,i,r.signal)}async _afterLoadModel(e,t,n,i){}get _shadowsAbortSignal(){return this._shadowsAbortController?.signal}get shadowConfig(){return{quality:this._shadowQuality}}async updateShadows(e,t){if(void 0===e.quality||e.quality===this._shadowQuality)return;const n=this._shadowQuality;this._shadowQuality=e.quality;try{await this._updateShadows(this._shadowQuality,t)}catch(t){throw this._shadowQuality===e.quality&&(this._shadowQuality=n),t}this.onShadowsConfigurationChanged.notifyObservers()}async _updateShadows(e=this._shadowQuality,n){this._throwIfDisposedOrAborted(n),this._shadowsAbortController?.abort(new t("Shadows quality is being changed before previous shadows finished initializing."));const i=this._shadowsAbortController=new AbortController;await this._updateShadowsLock.lockAsync(async()=>{c(n,i.signal),await this._updateShadowsImpl(e,n,i.signal)})}dispose(){this._loadEnvironmentLightingAbortController?.abort(new t("The viewer is being disposed.")),this._loadEnvironmentLightingAbortController=null,this._loadEnvironmentSkyboxAbortController?.abort(new t("The viewer is being disposed.")),this._loadEnvironmentSkyboxAbortController=null,this._loadModelAbortController?.abort(new t("The viewer is being disposed.")),this._loadModelAbortController=null,this._shadowsAbortController?.abort(new t("The viewer is being disposed.")),this._shadowsAbortController=null,this.onEnvironmentChanged.clear(),this.onEnvironmentConfigurationChanged.clear(),this.onEnvironmentError.clear(),this.onShadowsConfigurationChanged.clear(),this.onPostProcessingChanged.clear(),this.onModelChanged.clear(),this.onModelError.clear(),this.onLoadingProgressChanged.clear(),this.onCameraAutoOrbitChanged.clear(),this.onSelectedAnimationChanged.clear(),this.onAnimationSpeedChanged.clear(),this.onIsAnimationPlayingChanged.clear(),this.onAnimationProgressChanged.clear(),this.onSelectedMaterialVariantChanged.clear(),this.onHotSpotsChanged.clear(),this.onCamerasAsHotSpotsChanged.clear(),this.onAfterRenderObservable.clear(),this.onClearColorChanged.clear(),this._isDisposed=!0}reset(...e){this._reset(!0,...e)}_reset(e,...t){const n=0===t.length;(n||t.includes("source"))&&this._resetModel(),(n||t.includes("environment"))&&this._resetEnvironment(),(n||t.includes("shadow"))&&this._resetShadows(),(n||t.includes("animation"))&&this._resetAnimation(),(n||t.includes("camera"))&&this._resetCamera(e),(n||t.includes("post-processing"))&&this._resetPostProcessing(),(n||t.includes("material-variant"))&&this._resetMaterialVariant()}_resetModel(){u(this._updateModel(this._options?.source))}_resetShadows(){u(this.updateShadows({quality:this._options?.shadowConfig?.quality??f.shadowConfig.quality}))}_resetMaterialVariant(){this.selectedMaterialVariant=this._options?.selectedMaterialVariant??null}}function v(e,t,n,i,r,s){function o(e){if(void 0!==e&&"function"!=typeof e)throw new TypeError("Function expected");return e}for(var a,l=i.kind,c="getter"===l?"get":"setter"===l?"set":"value",u=!t&&e?i.static?e:e.prototype:null,h=t||(u?Object.getOwnPropertyDescriptor(u,i.name):{}),d=!1,p=n.length-1;p>=0;p--){var _={};for(var f in i)_[f]="access"===f?{}:i[f];for(var f in i.access)_.access[f]=i.access[f];_.addInitializer=function(e){if(d)throw new TypeError("Cannot add initializers after decoration has completed");s.push(o(e||null))};var m=(0,n[p])("accessor"===l?{get:h.get,set:h.set}:h[c],_);if("accessor"===l){if(void 0===m)continue;if(null===m||"object"!=typeof m)throw new TypeError("Object expected");(a=o(m.get))&&(h.get=a),(a=o(m.set))&&(h.set=a),(a=o(m.init))&&r.unshift(a)}else(a=o(m))&&("field"===l?r.unshift(a):h[c]=a)}u&&Object.defineProperty(u,i.name,h),d=!0}function y(e,t,n){for(var i=arguments.length>2,r=0;r<t.length;r++)n=i?t[r].call(e,n):t[r].call(e);return i?n:void 0}function w(e,t,n){return"symbol"==typeof t&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:n?"".concat(n," ",t):t})}function x(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function C(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}"function"==typeof SuppressedError&&SuppressedError;
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const A=e=>(t,n)=>{void 0!==n?n.addInitializer(()=>{customElements.define(e,t)}):customElements.define(e,t)},M=globalThis,S=M.ShadowRoot&&(void 0===M.ShadyCSS||M.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,k=Symbol(),P=new WeakMap;
/**
 * @license
 * Copyright 2019 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */let E=class{constructor(e,t,n){if(this._$cssResult$=!0,n!==k)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(S&&void 0===e){const n=void 0!==t&&1===t.length;n&&(e=P.get(t)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),n&&P.set(t,e))}return e}toString(){return this.cssText}};const O=(e,...t)=>{const n=1===e.length?e[0]:t.reduce((t,n,i)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+e[i+1],e[0]);return new E(n,e,k)},T=S?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const n of e.cssRules)t+=n.cssText;return(e=>new E("string"==typeof e?e:e+"",void 0,k))(t)})(e):e,{is:B,defineProperty:L,getOwnPropertyDescriptor:I,getOwnPropertyNames:R,getOwnPropertySymbols:$,getPrototypeOf:N}=Object,V=globalThis,F=V.trustedTypes,z=F?F.emptyScript:"",D=V.reactiveElementPolyfillSupport,G=(e,t)=>e,U={toAttribute(e,t){switch(t){case Boolean:e=e?z:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let n=e;switch(t){case Boolean:n=null!==e;break;case Number:n=null===e?null:Number(e);break;case Object:case Array:try{n=JSON.parse(e)}catch(e){n=null}}return n}},j=(e,t)=>!B(e,t),W={attribute:!0,type:String,converter:U,reflect:!1,useDefault:!1,hasChanged:j};
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */Symbol.metadata??=Symbol("metadata"),V.litPropertyMetadata??=new WeakMap;let H=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=W){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){const n=Symbol(),i=this.getPropertyDescriptor(e,n,t);void 0!==i&&L(this.prototype,e,i)}}static getPropertyDescriptor(e,t,n){const{get:i,set:r}=I(this.prototype,e)??{get(){return this[t]},set(e){this[t]=e}};return{get:i,set(t){const s=i?.call(this);r?.call(this,t),this.requestUpdate(e,s,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??W}static _$Ei(){if(this.hasOwnProperty(G("elementProperties")))return;const e=N(this);e.finalize(),void 0!==e.l&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(G("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(G("properties"))){const e=this.properties,t=[...R(e),...$(e)];for(const n of t)this.createProperty(n,e[n])}const e=this[Symbol.metadata];if(null!==e){const t=litPropertyMetadata.get(e);if(void 0!==t)for(const[e,n]of t)this.elementProperties.set(e,n)}this._$Eh=new Map;for(const[e,t]of this.elementProperties){const n=this._$Eu(e,t);void 0!==n&&this._$Eh.set(n,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const n=new Set(e.flat(1/0).reverse());for(const e of n)t.unshift(T(e))}else void 0!==e&&t.push(T(e));return t}static _$Eu(e,t){const n=t.attribute;return!1===n?void 0:"string"==typeof n?n:"string"==typeof e?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),void 0!==this.renderRoot&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const n of t.keys())this.hasOwnProperty(n)&&(e.set(n,this[n]),delete this[n]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((e,t)=>{if(S)e.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const n of t){const t=document.createElement("style"),i=M.litNonce;void 0!==i&&t.setAttribute("nonce",i),t.textContent=n.cssText,e.appendChild(t)}})(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,t,n){this._$AK(e,n)}_$ET(e,t){const n=this.constructor.elementProperties.get(e),i=this.constructor._$Eu(e,n);if(void 0!==i&&!0===n.reflect){const r=(void 0!==n.converter?.toAttribute?n.converter:U).toAttribute(t,n.type);this._$Em=e,null==r?this.removeAttribute(i):this.setAttribute(i,r),this._$Em=null}}_$AK(e,t){const n=this.constructor,i=n._$Eh.get(e);if(void 0!==i&&this._$Em!==i){const e=n.getPropertyOptions(i),r="function"==typeof e.converter?{fromAttribute:e.converter}:void 0!==e.converter?.fromAttribute?e.converter:U;this._$Em=i;const s=r.fromAttribute(t,e.type);this[i]=s??this._$Ej?.get(i)??s,this._$Em=null}}requestUpdate(e,t,n,i=!1,r){if(void 0!==e){const s=this.constructor;if(!1===i&&(r=this[e]),n??=s.getPropertyOptions(e),!((n.hasChanged??j)(r,t)||n.useDefault&&n.reflect&&r===this._$Ej?.get(e)&&!this.hasAttribute(s._$Eu(e,n))))return;this.C(e,t,n)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(e,t,{useDefault:n,reflect:i,wrapped:r},s){n&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,s??t??this[e]),!0!==r||void 0!==s)||(this._$AL.has(e)||(this.hasUpdated||n||(t=void 0),this._$AL.set(e,t)),!0===i&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}const e=this.scheduleUpdate();return null!=e&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[e,t]of this._$Ep)this[e]=t;this._$Ep=void 0}const e=this.constructor.elementProperties;if(e.size>0)for(const[t,n]of e){const{wrapped:e}=n,i=this[t];!0!==e||this._$AL.has(t)||void 0===i||this.C(t,void 0,n,i)}}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),this._$EO?.forEach(e=>e.hostUpdate?.()),this.update(t)):this._$EM()}catch(t){throw e=!1,this._$EM(),t}e&&this._$AE(t)}willUpdate(e){}_$AE(e){this._$EO?.forEach(e=>e.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(e=>this._$ET(e,this[e])),this._$EM()}updated(e){}firstUpdated(e){}};H.elementStyles=[],H.shadowRootOptions={mode:"open"},H[G("elementProperties")]=new Map,H[G("finalized")]=new Map,D?.({ReactiveElement:H}),(V.reactiveElementVersions??=[]).push("2.1.2");
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const q={attribute:!0,type:String,converter:U,reflect:!1,hasChanged:j},X=(e=q,t,n)=>{const{kind:i,metadata:r}=n;let s=globalThis.litPropertyMetadata.get(r);if(void 0===s&&globalThis.litPropertyMetadata.set(r,s=new Map),"setter"===i&&((e=Object.create(e)).wrapped=!0),s.set(n.name,e),"accessor"===i){const{name:i}=n;return{set(n){const r=t.get.call(this);t.set.call(this,n),this.requestUpdate(i,r,e,!0,n)},init(t){return void 0!==t&&this.C(i,void 0,e,t),t}}}if("setter"===i){const{name:i}=n;return function(n){const r=this[i];t.call(this,n),this.requestUpdate(i,r,e,!0,n)}}throw Error("Unsupported decorator location: "+i)};function Y(e){return(t,n)=>"object"==typeof n?X(e,t,n):((e,t,n)=>{const i=t.hasOwnProperty(n);return t.constructor.createProperty(n,e),i?Object.getOwnPropertyDescriptor(t,n):void 0})(e,t,n)}
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */function Q(e){return Y({...e,state:!0,attribute:!1})}
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
function Z(e,t){return(t,n,i)=>((e,t,n)=>(n.configurable=!0,n.enumerable=!0,Reflect.decorate&&"object"!=typeof t&&Object.defineProperty(e,t,n),n))(t,n,{get(){return(t=>t.renderRoot?.querySelector(e)??null)(this)}})}
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */const K=globalThis,J=e=>e,ee=K.trustedTypes,te=ee?ee.createPolicy("lit-html",{createHTML:e=>e}):void 0,ne="$lit$",ie=`lit$${Math.random().toFixed(9).slice(2)}$`,re="?"+ie,se=`<${re}>`,oe=document,ae=()=>oe.createComment(""),le=e=>null===e||"object"!=typeof e&&"function"!=typeof e,ce=Array.isArray,ue="[ \t\n\f\r]",he=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,de=/-->/g,pe=/>/g,_e=RegExp(`>|${ue}(?:([^\\s"'>=/]+)(${ue}*=${ue}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),fe=/'/g,me=/"/g,ge=/^(?:script|style|textarea|title)$/i,be=(e=>(t,...n)=>({_$litType$:e,strings:t,values:n}))(1),ve=Symbol.for("lit-noChange"),ye=Symbol.for("lit-nothing"),we=new WeakMap,xe=oe.createTreeWalker(oe,129);function Ce(e,t){if(!ce(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==te?te.createHTML(t):t}const Ae=(e,t)=>{const n=e.length-1,i=[];let r,s=2===t?"<svg>":3===t?"<math>":"",o=he;for(let t=0;t<n;t++){const n=e[t];let a,l,c=-1,u=0;for(;u<n.length&&(o.lastIndex=u,l=o.exec(n),null!==l);)u=o.lastIndex,o===he?"!--"===l[1]?o=de:void 0!==l[1]?o=pe:void 0!==l[2]?(ge.test(l[2])&&(r=RegExp("</"+l[2],"g")),o=_e):void 0!==l[3]&&(o=_e):o===_e?">"===l[0]?(o=r??he,c=-1):void 0===l[1]?c=-2:(c=o.lastIndex-l[2].length,a=l[1],o=void 0===l[3]?_e:'"'===l[3]?me:fe):o===me||o===fe?o=_e:o===de||o===pe?o=he:(o=_e,r=void 0);const h=o===_e&&e[t+1].startsWith("/>")?" ":"";s+=o===he?n+se:c>=0?(i.push(a),n.slice(0,c)+ne+n.slice(c)+ie+h):n+ie+(-2===c?t:h)}return[Ce(e,s+(e[n]||"<?>")+(2===t?"</svg>":3===t?"</math>":"")),i]};class Me{constructor({strings:e,_$litType$:t},n){let i;this.parts=[];let r=0,s=0;const o=e.length-1,a=this.parts,[l,c]=Ae(e,t);if(this.el=Me.createElement(l,n),xe.currentNode=this.el.content,2===t||3===t){const e=this.el.content.firstChild;e.replaceWith(...e.childNodes)}for(;null!==(i=xe.nextNode())&&a.length<o;){if(1===i.nodeType){if(i.hasAttributes())for(const e of i.getAttributeNames())if(e.endsWith(ne)){const t=c[s++],n=i.getAttribute(e).split(ie),o=/([.?@])?(.*)/.exec(t);a.push({type:1,index:r,name:o[2],strings:n,ctor:"."===o[1]?Oe:"?"===o[1]?Te:"@"===o[1]?Be:Ee}),i.removeAttribute(e)}else e.startsWith(ie)&&(a.push({type:6,index:r}),i.removeAttribute(e));if(ge.test(i.tagName)){const e=i.textContent.split(ie),t=e.length-1;if(t>0){i.textContent=ee?ee.emptyScript:"";for(let n=0;n<t;n++)i.append(e[n],ae()),xe.nextNode(),a.push({type:2,index:++r});i.append(e[t],ae())}}}else if(8===i.nodeType)if(i.data===re)a.push({type:2,index:r});else{let e=-1;for(;-1!==(e=i.data.indexOf(ie,e+1));)a.push({type:7,index:r}),e+=ie.length-1}r++}}static createElement(e,t){const n=oe.createElement("template");return n.innerHTML=e,n}}function Se(e,t,n=e,i){if(t===ve)return t;let r=void 0!==i?n._$Co?.[i]:n._$Cl;const s=le(t)?void 0:t._$litDirective$;return r?.constructor!==s&&(r?._$AO?.(!1),void 0===s?r=void 0:(r=new s(e),r._$AT(e,n,i)),void 0!==i?(n._$Co??=[])[i]=r:n._$Cl=r),void 0!==r&&(t=Se(e,r._$AS(e,t.values),r,i)),t}class ke{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:n}=this._$AD,i=(e?.creationScope??oe).importNode(t,!0);xe.currentNode=i;let r=xe.nextNode(),s=0,o=0,a=n[0];for(;void 0!==a;){if(s===a.index){let t;2===a.type?t=new Pe(r,r.nextSibling,this,e):1===a.type?t=new a.ctor(r,a.name,a.strings,this,e):6===a.type&&(t=new Le(r,this,e)),this._$AV.push(t),a=n[++o]}s!==a?.index&&(r=xe.nextNode(),s++)}return xe.currentNode=oe,i}p(e){let t=0;for(const n of this._$AV)void 0!==n&&(void 0!==n.strings?(n._$AI(e,n,t),t+=n.strings.length-2):n._$AI(e[t])),t++}}class Pe{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,t,n,i){this.type=2,this._$AH=ye,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=n,this.options=i,this._$Cv=i?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return void 0!==t&&11===e?.nodeType&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=Se(this,e,t),le(e)?e===ye||null==e||""===e?(this._$AH!==ye&&this._$AR(),this._$AH=ye):e!==this._$AH&&e!==ve&&this._(e):void 0!==e._$litType$?this.$(e):void 0!==e.nodeType?this.T(e):(e=>ce(e)||"function"==typeof e?.[Symbol.iterator])(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==ye&&le(this._$AH)?this._$AA.nextSibling.data=e:this.T(oe.createTextNode(e)),this._$AH=e}$(e){const{values:t,_$litType$:n}=e,i="number"==typeof n?this._$AC(e):(void 0===n.el&&(n.el=Me.createElement(Ce(n.h,n.h[0]),this.options)),n);if(this._$AH?._$AD===i)this._$AH.p(t);else{const e=new ke(i,this),n=e.u(this.options);e.p(t),this.T(n),this._$AH=e}}_$AC(e){let t=we.get(e.strings);return void 0===t&&we.set(e.strings,t=new Me(e)),t}k(e){ce(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let n,i=0;for(const r of e)i===t.length?t.push(n=new Pe(this.O(ae()),this.O(ae()),this,this.options)):n=t[i],n._$AI(r),i++;i<t.length&&(this._$AR(n&&n._$AB.nextSibling,i),t.length=i)}_$AR(e=this._$AA.nextSibling,t){for(this._$AP?.(!1,!0,t);e!==this._$AB;){const t=J(e).nextSibling;J(e).remove(),e=t}}setConnected(e){void 0===this._$AM&&(this._$Cv=e,this._$AP?.(e))}}class Ee{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,n,i,r){this.type=1,this._$AH=ye,this._$AN=void 0,this.element=e,this.name=t,this._$AM=i,this.options=r,n.length>2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=ye}_$AI(e,t=this,n,i){const r=this.strings;let s=!1;if(void 0===r)e=Se(this,e,t,0),s=!le(e)||e!==this._$AH&&e!==ve,s&&(this._$AH=e);else{const i=e;let o,a;for(e=r[0],o=0;o<r.length-1;o++)a=Se(this,i[n+o],t,o),a===ve&&(a=this._$AH[o]),s||=!le(a)||a!==this._$AH[o],a===ye?e=ye:e!==ye&&(e+=(a??"")+r[o+1]),this._$AH[o]=a}s&&!i&&this.j(e)}j(e){e===ye?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class Oe extends Ee{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===ye?void 0:e}}class Te extends Ee{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==ye)}}class Be extends Ee{constructor(e,t,n,i,r){super(e,t,n,i,r),this.type=5}_$AI(e,t=this){if((e=Se(this,e,t,0)??ye)===ve)return;const n=this._$AH,i=e===ye&&n!==ye||e.capture!==n.capture||e.once!==n.once||e.passive!==n.passive,r=e!==ye&&(n===ye||i);i&&this.element.removeEventListener(this.name,this,n),r&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,e):this._$AH.handleEvent(e)}}class Le{constructor(e,t,n){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=n}get _$AU(){return this._$AM._$AU}_$AI(e){Se(this,e)}}const Ie=K.litHtmlPolyfillSupport;Ie?.(Me,Pe),(K.litHtmlVersions??=[]).push("3.3.2");const Re=globalThis;
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */let $e=class extends H{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=((e,t,n)=>{const i=n?.renderBefore??t;let r=i._$litPart$;if(void 0===r){const e=n?.renderBefore??null;i._$litPart$=r=new Pe(t.insertBefore(ae(),e),e,void 0,n??{})}return r._$AI(e),r})(t,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return ve}};$e._$litElement$=!0,$e.finalized=!0,Re.litElementHydrateSupport?.({LitElement:$e});const Ne=Re.litElementPolyfillSupport;Ne?.({LitElement:$e}),(Re.litElementVersions??=[]).push("4.2.2");
/**
 * @license
 * Copyright 2020 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const Ve=2;
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */class Fe{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,t,n){this._$Ct=e,this._$AM=t,this._$Ci=n}_$AS(e,t){return this.update(e,t)}update(e,t){return this.render(...t)}}
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */const ze=(e,t)=>{const n=e._$AN;if(void 0===n)return!1;for(const e of n)e._$AO?.(t,!1),ze(e,t);return!0},De=e=>{let t,n;do{if(void 0===(t=e._$AM))break;n=t._$AN,n.delete(e),e=t}while(0===n?.size)},Ge=e=>{for(let t;t=e._$AM;e=t){let n=t._$AN;if(void 0===n)t._$AN=n=new Set;else if(n.has(e))break;n.add(e),We(t)}};function Ue(e){void 0!==this._$AN?(De(this),this._$AM=e,Ge(this)):this._$AM=e}function je(e,t=!1,n=0){const i=this._$AH,r=this._$AN;if(void 0!==r&&0!==r.size)if(t)if(Array.isArray(i))for(let e=n;e<i.length;e++)ze(i[e],!1),De(i[e]);else null!=i&&(ze(i,!1),De(i));else ze(this,e)}const We=e=>{e.type==Ve&&(e._$AP??=je,e._$AQ??=Ue)};class He extends Fe{constructor(){super(...arguments),this._$AN=void 0}_$AT(e,t,n){super._$AT(e,t,n),Ge(this),this.isConnected=e._$AU}_$AO(e,t=!0){e!==this.isConnected&&(this.isConnected=e,e?this.reconnected?.():this.disconnected?.()),t&&(ze(this,e),De(this))}setValue(e){if((e=>void 0===e.strings)(this._$Ct))this._$Ct._$AI(e,this);else{const t=[...this._$Ct._$AH];t[this._$Ci]=e,this._$Ct._$AI(t,this,0)}}disconnected(){}reconnected(){}}const qe=new WeakMap,Xe=(e=>(...t)=>({_$litDirective$:e,values:t}))(class extends He{render(e){return ye}update(e,[t]){const n=t!==this.G;return n&&void 0!==this.G&&this.rt(void 0),(n||this.lt!==this.ct)&&(this.G=t,this.ht=e.options?.host,this.rt(this.ct=e.element)),ye}rt(e){if(this.isConnected||(e=void 0),"function"==typeof this.G){const t=this.ht??globalThis;let n=qe.get(t);void 0===n&&(n=new WeakMap,qe.set(t,n)),void 0!==n.get(this.G)&&this.G.call(this.ht,void 0),n.set(this.G,e),void 0!==e&&this.G.call(this.ht,e)}else this.G.value=e}get lt(){return"function"==typeof this.G?qe.get(this.ht??globalThis)?.get(this.G):this.G?.value}disconnected(){this.lt===this.ct&&this.rt(void 0)}reconnected(){this.rt(this.ct)}}),Ye=[.5,1,1.5,2];function Qe(e){if(!e)return null;const t=document.createElement("canvas");t.width=t.height=1;const n=t.getContext("2d");if(!n)throw new Error("Unable to get 2d context for parseColor");n.clearRect(0,0,1,1),n.fillStyle=e,n.fillRect(0,0,1,1);const i=n.getImageData(0,0,1,1).data;return{r:i[0]/255,g:i[1]/255,b:i[2]/255,a:i[3]/255}}function Ze(e){return null==e?null:Number(e)}function Ke(e){if(!e)return null;const t=e.trim().split(/\s+/);if(3!==t.length)throw new Error(`Camera orbit and target should be defined as three space separated numbers, but was specified as "${e}".`);return t.map(e=>Number(e))}function Je(e){return e&&function(e){return h.includes(e)}(e)?e:null}function et(e){return e&&"auto"!==e?"reframe"===e?"reframe":e.trim().split(/\s+/):"auto"}let tt=(()=>{var e,n,s,o,a,l,c,u,h,d,_,f,m,g,b,w,A,M,S,k,P,E,T,B,L,I,R,$,N,V,F,z,D,G;let U,j,W,H,q,X,K,J,ee,te,ne,ie,re,se,oe,ae,le,ce,ue,he,de,pe,_e,fe,me,ge,ve,ye,we,xe,Ce,Ae,Me,Se,ke=$e,Pe=[],Ee=[],Oe=[],Te=[],Be=[],Le=[],Ie=[],Re=[],Ne=[],Ve=[],Fe=[],ze=[],De=[],Ge=[],Ue=[],je=[],We=[],He=[],qe=[],tt=[],nt=[],it=[],rt=[],st=[],ot=[],at=[],lt=[],ct=[],ut=[],ht=[],dt=[],pt=[],_t=[],ft=[],mt=[],gt=[],bt=[],vt=[],yt=[],wt=[],xt=[],Ct=[],At=[],Mt=[],St=[],kt=[],Pt=[],Et=[],Ot=[],Tt=[],Bt=[],Lt=[],It=[],Rt=[],$t=[],Nt=[],Vt=[],Ft=[],zt=[],Dt=[],Gt=[],Ut=[],jt=[],Wt=[],Ht=[],qt=[],Xt=[];return e=class extends ke{constructor(e={}){super(),this._options=(y(this,Pe),e),this._viewerLock=new i,this._animationSliderResizeObserver=null,this._propertyBindings=[this._createPropertyBinding("clearColor",e=>e.onClearColorChanged,e=>e.clearColor=this.clearColor??{r:0,g:0,b:0,a:0},e=>this.clearColor=e.clearColor),this._createPropertyBinding("skyboxBlur",e=>e.onEnvironmentConfigurationChanged,e=>e.environmentConfig={blur:this.skyboxBlur??e.environmentConfig.blur},e=>this.skyboxBlur=e.environmentConfig.blur),this._createPropertyBinding("environmentIntensity",e=>e.onEnvironmentConfigurationChanged,e=>e.environmentConfig={intensity:this.environmentIntensity??e.environmentConfig.intensity},e=>this.environmentIntensity=e.environmentConfig.intensity),this._createPropertyBinding("environmentRotation",e=>e.onEnvironmentConfigurationChanged,e=>e.environmentConfig={rotation:this.environmentRotation??e.environmentConfig.rotation},e=>this.environmentRotation=e.environmentConfig.rotation),this._createPropertyBinding("toneMapping",e=>e.onPostProcessingChanged,e=>{this.toneMapping&&(e.postProcessing={toneMapping:this.toneMapping})},e=>this.toneMapping=e.postProcessing?.toneMapping),this._createPropertyBinding("contrast",e=>e.onPostProcessingChanged,e=>e.postProcessing={contrast:this.contrast??void 0},e=>this.contrast=e.postProcessing.contrast),this._createPropertyBinding("exposure",e=>e.onPostProcessingChanged,e=>e.postProcessing={exposure:this.exposure??void 0},e=>this.exposure=e.postProcessing.exposure),this._createPropertyBinding("ssao",e=>e.onPostProcessingChanged,e=>e.postProcessing={ssao:this.ssao??void 0},e=>this.ssao=e.postProcessing.ssao),this._createPropertyBinding("cameraAutoOrbit",e=>e.onCameraAutoOrbitChanged,e=>e.cameraAutoOrbit={enabled:this.cameraAutoOrbit},e=>this.cameraAutoOrbit=e.cameraAutoOrbit.enabled),this._createPropertyBinding("cameraAutoOrbitSpeed",e=>e.onCameraAutoOrbitChanged,e=>e.cameraAutoOrbit={speed:this.cameraAutoOrbitSpeed??void 0},e=>this.cameraAutoOrbitSpeed=e.cameraAutoOrbit.speed),this._createPropertyBinding("cameraAutoOrbitDelay",e=>e.onCameraAutoOrbitChanged,e=>e.cameraAutoOrbit={delay:this.cameraAutoOrbitDelay??void 0},e=>this.cameraAutoOrbitDelay=e.cameraAutoOrbit.delay),this._createPropertyBinding("animationSpeed",e=>e.onAnimationSpeedChanged,e=>e.animationSpeed=this.animationSpeed,e=>{let t=e.animationSpeed;t=Ye.reduce((e,n)=>Math.abs(n-t)<Math.abs(e-t)?n:e),this.animationSpeed=t,this._dispatchCustomEvent("animationspeedchange",e=>new Event(e))}),this._createPropertyBinding("selectedAnimation",e=>e.onSelectedAnimationChanged,e=>e.selectedAnimation=this.selectedAnimation??e.selectedAnimation,e=>this.selectedAnimation=e.selectedAnimation),this._createPropertyBinding("selectedMaterialVariant",e=>e.onSelectedMaterialVariantChanged,e=>e.selectedMaterialVariant=this.selectedMaterialVariant??e.selectedMaterialVariant??"",e=>this.selectedMaterialVariant=e.selectedMaterialVariant),this._createPropertyBinding("hotSpots",e=>e.onHotSpotsChanged,e=>e.hotSpots=this.hotSpots??e.hotSpots,e=>this.hotSpots=e.hotSpots),this._createPropertyBinding("camerasAsHotSpots",e=>e.onCamerasAsHotSpotsChanged,e=>e.camerasAsHotSpots=this.camerasAsHotSpots??e.camerasAsHotSpots,e=>this.camerasAsHotSpots=e.camerasAsHotSpots)],n.set(this,y(this,Ee,!1)),s.set(this,(y(this,Oe),y(this,Te,!1===this._options.autoSuspendRendering))),o.set(this,(y(this,Be),y(this,Le,this._options.source??null))),a.set(this,(y(this,Ie),y(this,Re,null))),l.set(this,(y(this,Ne),y(this,Ve,this._options.useOpenPBR??!1))),c.set(this,(y(this,Fe),y(this,ze,this._options.environmentLighting??null))),u.set(this,(y(this,De),y(this,Ge,this._options.environmentSkybox??null))),h.set(this,(y(this,Ue),y(this,je,this._options.environmentConfig?.intensity??null))),d.set(this,(y(this,We),y(this,He,this._options.environmentConfig?.rotation??null))),_.set(this,(y(this,qe),y(this,tt,null))),f.set(this,(y(this,nt),y(this,it,!1))),m.set(this,(y(this,rt),y(this,st,this._options.environmentConfig?.blur??null))),g.set(this,(y(this,ot),y(this,at,this._options.postProcessing?.toneMapping??null))),b.set(this,(y(this,lt),y(this,ct,this._options.postProcessing?.contrast??null))),w.set(this,(y(this,ut),y(this,ht,this._options.postProcessing?.exposure??null))),A.set(this,(y(this,dt),y(this,pt,this._options.postProcessing?.ssao??null))),M.set(this,(y(this,_t),y(this,ft,this._options.clearColor?{r:this._options.clearColor[0],g:this._options.clearColor[1],b:this._options.clearColor[2],a:this._options.clearColor[3]??1}:null))),S.set(this,(y(this,mt),y(this,gt,this._options.cameraAutoOrbit?.enabled??!1))),k.set(this,(y(this,bt),y(this,vt,this._options.cameraAutoOrbit?.speed??null))),P.set(this,(y(this,yt),y(this,wt,this._options.cameraAutoOrbit?.delay??null))),E.set(this,(y(this,xt),y(this,Ct,this._options.hotSpots??{}))),T.set(this,(y(this,At),y(this,Mt,!!this._options.animationAutoPlay))),B.set(this,(y(this,St),y(this,kt,this._options.selectedAnimation??null))),L.set(this,(y(this,Pt),y(this,Et,this._options.animationSpeed??1))),I.set(this,(y(this,Ot),y(this,Tt,0))),R.set(this,(y(this,Bt),y(this,Lt,[]))),$.set(this,(y(this,It),y(this,Rt,!1))),N.set(this,(y(this,$t),y(this,Nt,!0))),V.set(this,(y(this,Vt),y(this,Ft,this._options.selectedMaterialVariant??null))),F.set(this,(y(this,zt),y(this,Dt,!1))),z.set(this,(y(this,Gt),y(this,Ut,"auto"))),D.set(this,(y(this,jt),y(this,Wt,void 0))),G.set(this,(y(this,Ht),y(this,qt,void 0))),y(this,Xt),this._options=e}static get observedAttributes(){return[...super.observedAttributes,"camera-orbit","camera-target"]}queryHotSpot(e,t){return!!this._viewer&&this._viewer.queryHotSpot(e,t)}focusHotSpot(e){return!!this._viewer&&this._viewer.focusHotSpot(e)}get _isFaultedBacking(){return x(this,n,"f")}set _isFaultedBacking(e){C(this,n,e,"f")}get _isFaulted(){return this._isFaultedBacking}get renderWhenIdle(){return x(this,s,"f")}set renderWhenIdle(e){C(this,s,e,"f")}get source(){return x(this,o,"f")}set source(e){C(this,o,e,"f")}get extension(){return x(this,a,"f")}set extension(e){C(this,a,e,"f")}get useOpenPBR(){return x(this,l,"f")}set useOpenPBR(e){C(this,l,e,"f")}get environment(){return{lighting:this.environmentLighting,skybox:this.environmentSkybox}}set environment(e){this.environmentLighting=e||null,this.environmentSkybox=e||null}get environmentLighting(){return x(this,c,"f")}set environmentLighting(e){C(this,c,e,"f")}get environmentSkybox(){return x(this,u,"f")}set environmentSkybox(e){C(this,u,e,"f")}get environmentIntensity(){return x(this,h,"f")}set environmentIntensity(e){C(this,h,e,"f")}get environmentRotation(){return x(this,d,"f")}set environmentRotation(e){C(this,d,e,"f")}get shadowQuality(){return x(this,_,"f")}set shadowQuality(e){C(this,_,e,"f")}get _loadingProgress(){return x(this,f,"f")}set _loadingProgress(e){C(this,f,e,"f")}get loadingProgress(){return this._loadingProgress}get skyboxBlur(){return x(this,m,"f")}set skyboxBlur(e){C(this,m,e,"f")}get toneMapping(){return x(this,g,"f")}set toneMapping(e){C(this,g,e,"f")}get contrast(){return x(this,b,"f")}set contrast(e){C(this,b,e,"f")}get exposure(){return x(this,w,"f")}set exposure(e){C(this,w,e,"f")}get ssao(){return x(this,A,"f")}set ssao(e){C(this,A,e,"f")}get clearColor(){return x(this,M,"f")}set clearColor(e){C(this,M,e,"f")}get cameraAutoOrbit(){return x(this,S,"f")}set cameraAutoOrbit(e){C(this,S,e,"f")}get cameraAutoOrbitSpeed(){return x(this,k,"f")}set cameraAutoOrbitSpeed(e){C(this,k,e,"f")}get cameraAutoOrbitDelay(){return x(this,P,"f")}set cameraAutoOrbitDelay(e){C(this,P,e,"f")}get hotSpots(){return x(this,E,"f")}set hotSpots(e){C(this,E,e,"f")}get _hasHotSpots(){return Object.keys(this.hotSpots).length>0}get animationAutoPlay(){return x(this,T,"f")}set animationAutoPlay(e){C(this,T,e,"f")}get animations(){return this._animations}get _hasAnimations(){return this._animations.length>0}get selectedAnimation(){return x(this,B,"f")}set selectedAnimation(e){C(this,B,e,"f")}get isAnimationPlaying(){return this._isAnimationPlaying}get animationSpeed(){return x(this,L,"f")}set animationSpeed(e){C(this,L,e,"f")}get animationProgress(){return x(this,I,"f")}set animationProgress(e){C(this,I,e,"f")}get _animations(){return x(this,R,"f")}set _animations(e){C(this,R,e,"f")}get _isAnimationPlaying(){return x(this,$,"f")}set _isAnimationPlaying(e){C(this,$,e,"f")}get _showAnimationSlider(){return x(this,N,"f")}set _showAnimationSlider(e){C(this,N,e,"f")}get materialVariants(){return this._viewer?.materialVariants??[]}get selectedMaterialVariant(){return x(this,V,"f")}set selectedMaterialVariant(e){C(this,V,e,"f")}get camerasAsHotSpots(){return x(this,F,"f")}set camerasAsHotSpots(e){C(this,F,e,"f")}get resetMode(){return x(this,z,"f")}set resetMode(e){C(this,z,e,"f")}get _canvasContainer(){return x(this,D,"f")}set _canvasContainer(e){C(this,D,e,"f")}get _hotSpotSelect(){return x(this,G,"f")}set _hotSpotSelect(e){C(this,G,e,"f")}toggleAnimation(){this._viewer?.toggleAnimation()}reset(){this._reset(this.resetMode)}_reset(e){switch(e){case"auto":this._viewer?.resetCamera(void 0);break;case"reframe":this._viewer?.resetCamera(!0);break;default:this._viewer?.reset(...e)}}resetCamera(){this._reset("reframe")}reload(){this._tearDownViewer(),this._setupViewer()}connectedCallback(){super.connectedCallback(),this._setupViewer()}disconnectedCallback(){super.disconnectedCallback(),this._tearDownViewer()}attributeChangedCallback(e,t,n){if(super.attributeChangedCallback(e,t,n),this.hasUpdated)if("camera-orbit"==e){const e=Ke(n);e?this._viewer?.updateCamera({alpha:e[0],beta:e[1],radius:e[2]}):this._viewer?.resetCamera(!1)}else if("camera-target"==e){const e=Ke(n);e?this._viewer?.updateCamera({targetX:e[0],targetY:e[1],targetZ:e[2]}):this._viewer?.resetCamera(!1)}}update(e){super.update(e),this._hotSpotSelect&&(this._hotSpotSelect.value=""),this._needsReload(e)?(this._tearDownViewer(),this._setupViewer()):(this._propertyBindings.filter(t=>e.has(t.property)).forEach(e=>e.updateViewer()),(e.has("source")||e.has("useOpenPBR"))&&this._updateModel(),(e.has("environmentLighting")||e.has("environmentSkybox"))&&this._updateEnv({lighting:e.has("environmentLighting"),skybox:e.has("environmentSkybox")}),e.has("shadowQuality")&&this._updateShadows(this.shadowQuality))}_needsReload(e){return null!=e.get("renderWhenIdle")}render(){return be`<div class="full-size"><div id="canvasContainer" class="full-size"></div>${this._renderOverlay()}</div>`}_renderProgressBar(){const e=!1!==this.loadingProgress,t="boolean"==typeof this.loadingProgress?0:100*this.loadingProgress,n=!0===this.loadingProgress;return be`<div part="progress-bar" class="bar loading-progress-outer ${e?"":"loading-progress-outer-inactive"}" aria-label="Loading Progress"><div class="loading-progress-inner ${n?"loading-progress-inner-indeterminate":""}" style="${n?"":`width: ${t}%`}"></div></div>`}_renderToolbar(){let e=[];if(this._viewer?.isModelLoaded){this._hasAnimations&&e.push(be`<div class="animation-timeline"><button aria-label="${this.isAnimationPlaying?"Pause":"Play"}" @click="${this.toggleAnimation}">${this.isAnimationPlaying?be`<svg viewBox="0 0 24 24"><path d="${"M5.74609 3C4.7796 3 3.99609 3.7835 3.99609 4.75V19.25C3.99609 20.2165 4.7796 21 5.74609 21H9.24609C10.2126 21 10.9961 20.2165 10.9961 19.25V4.75C10.9961 3.7835 10.2126 3 9.24609 3H5.74609ZM14.7461 3C13.7796 3 12.9961 3.7835 12.9961 4.75V19.25C12.9961 20.2165 13.7796 21 14.7461 21H18.2461C19.2126 21 19.9961 20.2165 19.9961 19.25V4.75C19.9961 3.7835 19.2126 3 18.2461 3H14.7461Z"}" fill="currentColor"></path></svg>`:be`<svg viewBox="0 0 24 24"><path d="${"M5 5.27368C5 3.56682 6.82609 2.48151 8.32538 3.2973L20.687 10.0235C22.2531 10.8756 22.2531 13.124 20.687 13.9762L8.32538 20.7024C6.82609 21.5181 5 20.4328 5 18.726V5.27368Z"}" fill="currentColor"></path></svg>`}</button> <input ${Xe(this._onAnimationSliderChanged)} aria-label="Animation Progress" class="animation-timeline-input" style="${this._showAnimationSlider?"":"visibility: hidden"}" type="range" min="0" max="1" step="0.0001" .value="${this.animationProgress}" @input="${this._onAnimationTimelineChanged}" @pointerdown="${this._onAnimationTimelinePointerDown}"></div><select aria-label="Select Animation Speed" @change="${this._onAnimationSpeedChanged}">${Ye.map(e=>be`<option value="${e}" .selected="${this.animationSpeed===e}">${e}x</option>`)}</select> ${this.animations.length>1?be`<select aria-label="Select Animation" @change="${this._onSelectedAnimationChanged}">${this.animations.map((e,t)=>be`<option value="${t}" .selected="${this.selectedAnimation===t}">${e}</option>`)}</select>`:""}`),this.materialVariants.length>1&&e.push(be`<select aria-label="Select Material Variant" @change="${this._onMaterialVariantChanged}">${this.materialVariants.map(e=>be`<option value="${e}" .selected="${this.selectedMaterialVariant===e}">${e}</option>`)}</select>`),e.push(be`<button aria-label="Reset Camera Pose" @click="${this.reset}"><svg viewBox="0 0 24 24"><path d="${"M7.20711 2.54289C7.59763 2.93342 7.59763 3.56658 7.20711 3.95711L5.41421 5.75H13.25C17.6683 5.75 21.25 9.33172 21.25 13.75C21.25 18.1683 17.6683 21.75 13.25 21.75C8.83172 21.75 5.25 18.1683 5.25 13.75C5.25 13.1977 5.69772 12.75 6.25 12.75C6.80228 12.75 7.25 13.1977 7.25 13.75C7.25 17.0637 9.93629 19.75 13.25 19.75C16.5637 19.75 19.25 17.0637 19.25 13.75C19.25 10.4363 16.5637 7.75 13.25 7.75H5.41421L7.20711 9.54289C7.59763 9.93342 7.59763 10.5666 7.20711 10.9571C6.81658 11.3476 6.18342 11.3476 5.79289 10.9571L2.29289 7.45711C1.90237 7.06658 1.90237 6.43342 2.29289 6.04289L5.79289 2.54289C6.18342 2.15237 6.81658 2.15237 7.20711 2.54289Z"}" fill="currentColor"></path></svg></button>`),this._hasHotSpots&&e.push(be`<div class="select-container"><select id="hotSpotSelect" aria-label="Select HotSpot" @change="${this._onHotSpotsChanged}">${Object.keys(this.hotSpots).map(e=>be`<option value="${e}">${e}  </option>`)}</select> <button style="pointer-events:none"><svg viewBox="0 0 24 24"><path d="${"M12 14C13.1046 14 14 13.1046 14 12C14 10.8954 13.1046 10 12 10C10.8954 10 10 10.8954 10 12C10 13.1046 10.8954 14 12 14ZM6 12C6 8.68629 8.68629 6 12 6C15.3137 6 18 8.68629 18 12C18 15.3137 15.3137 18 12 18C8.68629 18 6 15.3137 6 12ZM12 8C9.79086 8 8 9.79086 8 12C8 14.2091 9.79086 16 12 16C14.2091 16 16 14.2091 16 12C16 9.79086 14.2091 8 12 8ZM2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12ZM12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4Z"}" fill="currentColor"></path></svg></button></div>`);const t=e.length,n=be`<div class="divider"></div>`;e=e.reduce((e,i,r)=>r<t-1?[...e,i,n]:[...e,i],new Array)}return e.length>0?be`<div part="tool-bar" class="bar ${this._hasAnimations?"":"bar-min"} tool-bar">${e}</div>`:be``}_renderReloadButton(){return be`${this._isFaulted?be`<button aria-label="Reload" part="reload-button" class="reload-button" @click="${this.reload}"><svg viewBox="0 0 24 24"><path d="${"M5 12C5 8.13401 8.13401 5 12 5C13.32 5 14.5542 5.36484 15.608 6H15C14.4477 6 14 6.44772 14 7C14 7.55228 14.4477 8 15 8H18C18.5523 8 19 7.55228 19 7C19 6 19 5 19 4C19 3.44772 18.5523 3 18 3C17.4477 3 17 3.44772 17 4V4.51575C15.5702 3.5588 13.85 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21C16.9706 21 21 16.9706 21 12C21 11.6199 20.9764 11.2448 20.9304 10.8763C20.8621 10.3282 20.3624 9.93935 19.8144 10.0077C19.2663 10.076 18.8775 10.5757 18.9458 11.1237C18.9815 11.4104 19 11.7028 19 12C19 15.866 15.866 19 12 19C8.13401 19 5 15.866 5 12Z"}" fill="currentColor"></path></svg></button>`:""}`}_renderOverlay(){return be`<slot class="full-size children-slot"></slot><slot name="progress-bar">${this._renderProgressBar()}</slot><slot name="tool-bar">${this._renderToolbar()}</slot><slot name="reload-button">${this._renderReloadButton()}</slot>`}_dispatchCustomEvent(e,t){this.dispatchEvent(t(e))}_onSelectedAnimationChanged(e){const t=e.target;this.selectedAnimation=Number(t.value)}_onAnimationSpeedChanged(e){const t=e.target;this.animationSpeed=Number(t.value)}_onAnimationTimelineChanged(e){if(this._viewer){const t=e.target,n=Number(t.value);n!==this.animationProgress&&(this._viewer.animationProgress=n)}}_onAnimationTimelinePointerDown(e){if(this._viewer?.isAnimationPlaying){this._viewer.pauseAnimation();e.target.addEventListener("pointerup",()=>this._viewer?.playAnimation(),{once:!0})}}_onMaterialVariantChanged(e){const t=e.target;this.selectedMaterialVariant=t.value}_onHotSpotsChanged(e){const t=e.target,n=t.value;t.value="",this.focusHotSpot(n)}_onAnimationSliderChanged(e){this._animationSliderResizeObserver?.disconnect(),e&&(this._animationSliderResizeObserver=new ResizeObserver(()=>{this._showAnimationSlider=e.clientWidth>=80}),this._animationSliderResizeObserver.observe(e))}_createPropertyBinding(e,t,n,i){const s=e=>{try{n(e)}catch(e){r.Error(e)}};return{property:e,onInitialized:e=>{t(e).add(()=>{i(e)}),s(e)},updateViewer:()=>{this._viewer&&s(this._viewer)}}}async _setupViewer(){await this._viewerLock.lockAsync(async()=>{if(this._canvasContainer||await this.updateComplete,this._canvasContainer&&!this._viewer){const e=document.createElement("canvas");e.className="full-size canvas",e.setAttribute("touch-action","none"),this._canvasContainer.appendChild(e);const t=this,n=new Proxy(this._options,{get(e,n){switch(n){case"autoSuspendRendering":return!(t.hasAttribute("render-when-idle")||!1===e.autoSuspendRendering);case"source":return t.getAttribute("source")??e.source;case"pluginExtension":return t.extension??e.pluginExtension;case"useOpenPBR":return!!t.hasAttribute("use-open-pbr")||(t.useOpenPBR??e.useOpenPBR);case"environmentLighting":return t.getAttribute("environment-lighting")??t.getAttribute("environment")??e.environmentLighting;case"environmentSkybox":return t.getAttribute("environment-skybox")??t.getAttribute("environment")??e.environmentSkybox;case"environmentConfig":return{intensity:Ze(t.getAttribute("environment-intensity"))??e.environmentConfig?.intensity,blur:Ze(t.getAttribute("skybox-blur"))??e.environmentConfig?.blur,rotation:Ze(t.getAttribute("environment-rotation"))??e.environmentConfig?.rotation};case"shadowConfig":return{quality:Je(t.getAttribute("shadow-quality"))??e.shadowConfig?.quality};case"cameraOrbit":return Ke(t.getAttribute("camera-orbit"))??e.cameraOrbit;case"cameraTarget":return Ke(t.getAttribute("camera-target"))??e.cameraTarget;case"cameraAutoOrbit":return{enabled:t.hasAttribute("camera-auto-orbit")||e.cameraAutoOrbit?.enabled,speed:Ze(t.getAttribute("camera-auto-orbit-speed"))??e.cameraAutoOrbit?.speed,delay:Ze(t.getAttribute("camera-auto-orbit-delay"))??e.cameraAutoOrbit?.delay};case"animationAutoPlay":return t.hasAttribute("animation-auto-play")||e.animationAutoPlay;case"animationSpeed":return Ze(t.getAttribute("animation-speed"))??e.animationSpeed;case"selectedAnimation":return Ze(t.getAttribute("selected-animation"))??e.selectedAnimation;case"postProcessing":return{toneMapping:(i=t.getAttribute("tone-mapping"),(i&&p(i)?i:null)??e.postProcessing?.toneMapping),contrast:Ze(t.getAttribute("contrast"))??e.postProcessing?.contrast,exposure:Ze(t.getAttribute("exposure"))??e.postProcessing?.exposure,ssao:t.hasAttribute("ssao")||e.postProcessing?.ssao};case"selectedMaterialVariant":return t.getAttribute("material-variant")??e.selectedMaterialVariant;case"onFaulted":return n=>{t._isFaultedBacking=!0,e.onFaulted?.(n),t._tearDownViewer()};default:return e[n]}var i}}),i=await this._createViewer(e,n);this._viewer=i,i.onEnvironmentChanged.add(()=>{this._dispatchCustomEvent("environmentchange",e=>new Event(e))}),i.onEnvironmentConfigurationChanged.add(()=>{this._dispatchCustomEvent("environmentconfigurationchange",e=>new Event(e))}),i.onEnvironmentError.add(e=>{this._dispatchCustomEvent("environmenterror",t=>new ErrorEvent(t,{error:e}))}),i.onShadowsConfigurationChanged.add(()=>{this._dispatchCustomEvent("shadowsconfigurationchange",e=>new Event(e))}),i.onModelChanged.add(e=>{this._animations=[...i.animations],this._dispatchCustomEvent("modelchange",t=>new CustomEvent(t,{detail:e}))}),i.onModelError.add(e=>{this._animations=[...i.animations],this._dispatchCustomEvent("modelerror",t=>new ErrorEvent(t,{error:e}))}),i.onLoadingProgressChanged.add(()=>{this._loadingProgress=i.loadingProgress,this._dispatchCustomEvent("loadingprogresschange",e=>new Event(e))}),i.onSelectedAnimationChanged.add(()=>{this._dispatchCustomEvent("selectedanimationchange",e=>new Event(e))}),i.onIsAnimationPlayingChanged.add(()=>{this._isAnimationPlaying=i.isAnimationPlaying??!1,this._dispatchCustomEvent("animationplayingchange",e=>new Event(e))}),i.onAnimationProgressChanged.add(()=>{this.animationProgress=i.animationProgress??0,this._dispatchCustomEvent("animationprogresschange",e=>new Event(e))}),i.onSelectedMaterialVariantChanged.add(()=>{this._dispatchCustomEvent("selectedmaterialvariantchange",e=>new Event(e))}),i.onAfterRenderObservable.add(()=>{this._dispatchCustomEvent("viewerrender",e=>new Event(e))}),this._propertyBindings.forEach(e=>e.onInitialized(i)),this._dispatchCustomEvent("viewerready",e=>new Event(e))}this._isFaultedBacking=!1})}async _tearDownViewer(){await this._viewerLock.lockAsync(async()=>{this._viewer&&(this._viewer.dispose(),this._viewer=void 0),this._onViewerTornDown(),this._loadingProgress=!1,this._canvasContainer&&this._canvasContainer.firstElementChild&&this._canvasContainer.removeChild(this._canvasContainer.firstElementChild)})}_onViewerTornDown(){}async _updateModel(){if(this._viewer)try{this.source?await this._viewer.loadModel(this.source,{pluginExtension:this.extension??void 0,useOpenPBR:this.useOpenPBR}):await this._viewer.resetModel()}catch(e){e instanceof t||r.Error(e)}}async _updateEnv(e){if(this._viewer)try{const t=[];e.lighting&&e.skybox&&this.environmentLighting===this.environmentSkybox?t.push([this.environmentLighting,{lighting:!0,skybox:!0}]):(e.lighting&&t.push([this.environmentLighting,{lighting:!0}]),e.skybox&&t.push([this.environmentSkybox,{skybox:!0}]));const n=t.map(async([e,t])=>{e?await(this._viewer?.loadEnvironment(e,t)):await(this._viewer?.resetEnvironment(t))});await Promise.all(n)}catch(e){e instanceof t||r.Error(e)}}async _updateShadows(e){if(e)try{const t={quality:e};await(this._viewer?.updateShadows(t))}catch(e){e instanceof t||r.Error(e)}}},n=new WeakMap,s=new WeakMap,o=new WeakMap,a=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,h=new WeakMap,d=new WeakMap,_=new WeakMap,f=new WeakMap,m=new WeakMap,g=new WeakMap,b=new WeakMap,w=new WeakMap,A=new WeakMap,M=new WeakMap,S=new WeakMap,k=new WeakMap,P=new WeakMap,E=new WeakMap,T=new WeakMap,B=new WeakMap,L=new WeakMap,I=new WeakMap,R=new WeakMap,$=new WeakMap,N=new WeakMap,V=new WeakMap,F=new WeakMap,z=new WeakMap,D=new WeakMap,G=new WeakMap,(()=>{const t="function"==typeof Symbol&&Symbol.metadata?Object.create(ke[Symbol.metadata]??null):void 0;U=[Q()],j=[Y({attribute:"render-when-idle",type:Boolean})],W=[Y()],H=[Y()],q=[Y({attribute:"use-open-pbr",type:Boolean})],X=[Y({hasChanged:(e,t)=>{const n=e||null;return n!==t.lighting||n!==t.skybox}})],K=[Y({attribute:"environment-lighting"})],J=[Y({attribute:"environment-skybox"})],ee=[Y({type:Number,attribute:"environment-intensity"})],te=[Y({type:Number,attribute:"environment-rotation"})],ne=[Y({attribute:"shadow-quality"})],ie=[Q()],re=[Y({attribute:"skybox-blur"})],se=[Y({attribute:"tone-mapping",converter:e=>e&&p(e)?e:"neutral"})],oe=[Y()],ae=[Y()],le=[Y({type:String})],ce=[Y({attribute:"clear-color",converter:{fromAttribute:Qe,toAttribute:e=>e?function(e){const t=e=>Math.round(255*e).toString(16).padStart(2,"0");return`#${t(e.r)}${t(e.g)}${t(e.b)}${t(e.a)}`}(e):null}})],ue=[Y({attribute:"camera-auto-orbit",type:Boolean})],he=[Y({attribute:"camera-auto-orbit-speed",type:Number})],de=[Y({attribute:"camera-auto-orbit-delay",type:Number})],pe=[Y({attribute:"hotspots",converter:e=>e?JSON.parse(e):{}})],_e=[Y({attribute:"animation-auto-play",type:Boolean})],fe=[Y({attribute:"selected-animation",type:Number})],me=[Y({attribute:"animation-speed"})],ge=[Y({attribute:!1})],ve=[Q()],ye=[Q()],we=[Q()],xe=[Y({attribute:"material-variant"})],Ce=[Y({attribute:"cameras-as-hotspots",type:Boolean})],Ae=[Y({attribute:"reset-mode",converter:et})],Me=[Z("#canvasContainer")],Se=[Z("#hotSpotSelect")],v(e,null,U,{kind:"accessor",name:"_isFaultedBacking",static:!1,private:!1,access:{has:e=>"_isFaultedBacking"in e,get:e=>e._isFaultedBacking,set:(e,t)=>{e._isFaultedBacking=t}},metadata:t},Ee,Oe),v(e,null,j,{kind:"accessor",name:"renderWhenIdle",static:!1,private:!1,access:{has:e=>"renderWhenIdle"in e,get:e=>e.renderWhenIdle,set:(e,t)=>{e.renderWhenIdle=t}},metadata:t},Te,Be),v(e,null,W,{kind:"accessor",name:"source",static:!1,private:!1,access:{has:e=>"source"in e,get:e=>e.source,set:(e,t)=>{e.source=t}},metadata:t},Le,Ie),v(e,null,H,{kind:"accessor",name:"extension",static:!1,private:!1,access:{has:e=>"extension"in e,get:e=>e.extension,set:(e,t)=>{e.extension=t}},metadata:t},Re,Ne),v(e,null,q,{kind:"accessor",name:"useOpenPBR",static:!1,private:!1,access:{has:e=>"useOpenPBR"in e,get:e=>e.useOpenPBR,set:(e,t)=>{e.useOpenPBR=t}},metadata:t},Ve,Fe),v(e,null,X,{kind:"setter",name:"environment",static:!1,private:!1,access:{has:e=>"environment"in e,set:(e,t)=>{e.environment=t}},metadata:t},null,Pe),v(e,null,K,{kind:"accessor",name:"environmentLighting",static:!1,private:!1,access:{has:e=>"environmentLighting"in e,get:e=>e.environmentLighting,set:(e,t)=>{e.environmentLighting=t}},metadata:t},ze,De),v(e,null,J,{kind:"accessor",name:"environmentSkybox",static:!1,private:!1,access:{has:e=>"environmentSkybox"in e,get:e=>e.environmentSkybox,set:(e,t)=>{e.environmentSkybox=t}},metadata:t},Ge,Ue),v(e,null,ee,{kind:"accessor",name:"environmentIntensity",static:!1,private:!1,access:{has:e=>"environmentIntensity"in e,get:e=>e.environmentIntensity,set:(e,t)=>{e.environmentIntensity=t}},metadata:t},je,We),v(e,null,te,{kind:"accessor",name:"environmentRotation",static:!1,private:!1,access:{has:e=>"environmentRotation"in e,get:e=>e.environmentRotation,set:(e,t)=>{e.environmentRotation=t}},metadata:t},He,qe),v(e,null,ne,{kind:"accessor",name:"shadowQuality",static:!1,private:!1,access:{has:e=>"shadowQuality"in e,get:e=>e.shadowQuality,set:(e,t)=>{e.shadowQuality=t}},metadata:t},tt,nt),v(e,null,ie,{kind:"accessor",name:"_loadingProgress",static:!1,private:!1,access:{has:e=>"_loadingProgress"in e,get:e=>e._loadingProgress,set:(e,t)=>{e._loadingProgress=t}},metadata:t},it,rt),v(e,null,re,{kind:"accessor",name:"skyboxBlur",static:!1,private:!1,access:{has:e=>"skyboxBlur"in e,get:e=>e.skyboxBlur,set:(e,t)=>{e.skyboxBlur=t}},metadata:t},st,ot),v(e,null,se,{kind:"accessor",name:"toneMapping",static:!1,private:!1,access:{has:e=>"toneMapping"in e,get:e=>e.toneMapping,set:(e,t)=>{e.toneMapping=t}},metadata:t},at,lt),v(e,null,oe,{kind:"accessor",name:"contrast",static:!1,private:!1,access:{has:e=>"contrast"in e,get:e=>e.contrast,set:(e,t)=>{e.contrast=t}},metadata:t},ct,ut),v(e,null,ae,{kind:"accessor",name:"exposure",static:!1,private:!1,access:{has:e=>"exposure"in e,get:e=>e.exposure,set:(e,t)=>{e.exposure=t}},metadata:t},ht,dt),v(e,null,le,{kind:"accessor",name:"ssao",static:!1,private:!1,access:{has:e=>"ssao"in e,get:e=>e.ssao,set:(e,t)=>{e.ssao=t}},metadata:t},pt,_t),v(e,null,ce,{kind:"accessor",name:"clearColor",static:!1,private:!1,access:{has:e=>"clearColor"in e,get:e=>e.clearColor,set:(e,t)=>{e.clearColor=t}},metadata:t},ft,mt),v(e,null,ue,{kind:"accessor",name:"cameraAutoOrbit",static:!1,private:!1,access:{has:e=>"cameraAutoOrbit"in e,get:e=>e.cameraAutoOrbit,set:(e,t)=>{e.cameraAutoOrbit=t}},metadata:t},gt,bt),v(e,null,he,{kind:"accessor",name:"cameraAutoOrbitSpeed",static:!1,private:!1,access:{has:e=>"cameraAutoOrbitSpeed"in e,get:e=>e.cameraAutoOrbitSpeed,set:(e,t)=>{e.cameraAutoOrbitSpeed=t}},metadata:t},vt,yt),v(e,null,de,{kind:"accessor",name:"cameraAutoOrbitDelay",static:!1,private:!1,access:{has:e=>"cameraAutoOrbitDelay"in e,get:e=>e.cameraAutoOrbitDelay,set:(e,t)=>{e.cameraAutoOrbitDelay=t}},metadata:t},wt,xt),v(e,null,pe,{kind:"accessor",name:"hotSpots",static:!1,private:!1,access:{has:e=>"hotSpots"in e,get:e=>e.hotSpots,set:(e,t)=>{e.hotSpots=t}},metadata:t},Ct,At),v(e,null,_e,{kind:"accessor",name:"animationAutoPlay",static:!1,private:!1,access:{has:e=>"animationAutoPlay"in e,get:e=>e.animationAutoPlay,set:(e,t)=>{e.animationAutoPlay=t}},metadata:t},Mt,St),v(e,null,fe,{kind:"accessor",name:"selectedAnimation",static:!1,private:!1,access:{has:e=>"selectedAnimation"in e,get:e=>e.selectedAnimation,set:(e,t)=>{e.selectedAnimation=t}},metadata:t},kt,Pt),v(e,null,me,{kind:"accessor",name:"animationSpeed",static:!1,private:!1,access:{has:e=>"animationSpeed"in e,get:e=>e.animationSpeed,set:(e,t)=>{e.animationSpeed=t}},metadata:t},Et,Ot),v(e,null,ge,{kind:"accessor",name:"animationProgress",static:!1,private:!1,access:{has:e=>"animationProgress"in e,get:e=>e.animationProgress,set:(e,t)=>{e.animationProgress=t}},metadata:t},Tt,Bt),v(e,null,ve,{kind:"accessor",name:"_animations",static:!1,private:!1,access:{has:e=>"_animations"in e,get:e=>e._animations,set:(e,t)=>{e._animations=t}},metadata:t},Lt,It),v(e,null,ye,{kind:"accessor",name:"_isAnimationPlaying",static:!1,private:!1,access:{has:e=>"_isAnimationPlaying"in e,get:e=>e._isAnimationPlaying,set:(e,t)=>{e._isAnimationPlaying=t}},metadata:t},Rt,$t),v(e,null,we,{kind:"accessor",name:"_showAnimationSlider",static:!1,private:!1,access:{has:e=>"_showAnimationSlider"in e,get:e=>e._showAnimationSlider,set:(e,t)=>{e._showAnimationSlider=t}},metadata:t},Nt,Vt),v(e,null,xe,{kind:"accessor",name:"selectedMaterialVariant",static:!1,private:!1,access:{has:e=>"selectedMaterialVariant"in e,get:e=>e.selectedMaterialVariant,set:(e,t)=>{e.selectedMaterialVariant=t}},metadata:t},Ft,zt),v(e,null,Ce,{kind:"accessor",name:"camerasAsHotSpots",static:!1,private:!1,access:{has:e=>"camerasAsHotSpots"in e,get:e=>e.camerasAsHotSpots,set:(e,t)=>{e.camerasAsHotSpots=t}},metadata:t},Dt,Gt),v(e,null,Ae,{kind:"accessor",name:"resetMode",static:!1,private:!1,access:{has:e=>"resetMode"in e,get:e=>e.resetMode,set:(e,t)=>{e.resetMode=t}},metadata:t},Ut,jt),v(e,null,Me,{kind:"accessor",name:"_canvasContainer",static:!1,private:!1,access:{has:e=>"_canvasContainer"in e,get:e=>e._canvasContainer,set:(e,t)=>{e._canvasContainer=t}},metadata:t},Wt,Ht),v(e,null,Se,{kind:"accessor",name:"_hotSpotSelect",static:!1,private:!1,access:{has:e=>"_hotSpotSelect"in e,get:e=>e._hotSpotSelect,set:(e,t)=>{e._hotSpotSelect=t}},metadata:t},qt,Xt),t&&Object.defineProperty(e,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:t})})(),e.styles=O`:host{--ui-foreground-color:white;--ui-background-hue:233;--ui-background-saturation:8%;--ui-background-lightness:39%;--ui-background-opacity:0.75;--ui-background-color:hsla(var(--ui-background-hue), var(--ui-background-saturation), var(--ui-background-lightness), var(--ui-background-opacity));--ui-background-color-hover:hsla(
                var(--ui-background-hue),
                var(--ui-background-saturation),
                calc(var(--ui-background-lightness) - 10%),
                calc(var(--ui-background-opacity) - 0.1)
            );all:inherit;overflow:hidden}.full-size{display:block;position:relative;width:100%;height:100%}.canvas{outline:0}.children-slot{position:absolute;top:0;background:0 0;pointer-events:none}.reload-button{position:absolute;top:50%;left:50%;width:25%;transform:translate(-50%,-50%);color:var(--ui-foreground-color);background-color:var(--ui-background-color);border:1px solid transparent;border-radius:24px;padding:0;cursor:pointer;outline:0}.reload-button:hover{background-color:var(--ui-background-color-hover)}.bar{position:absolute;width:calc(100% - 24px);min-width:370px;max-width:1280px;left:50%;transform:translateX(-50%);background-color:var(--ui-background-color)}.bar-min{width:unset;min-width:unset;max-width:unset}.loading-progress-outer{height:4px;border-radius:4px;border:1px solid var(--ui-background-color);outline:0;top:12px;pointer-events:none;transition:opacity .5s ease}.loading-progress-outer-inactive{opacity:0;background-color:var(--ui-foreground-color)}.loading-progress-inner{width:0;height:100%;border-radius:inherit;background-color:var(--ui-foreground-color);transition:width .3s linear}@keyframes indeterminate{0%{left:0;width:0%}23%{left:0;width:30%}77%{left:70%;width:30%}100%{left:100%;width:0%}}.loading-progress-inner-indeterminate{position:absolute;animation:indeterminate 1.5s infinite;animation-timing-function:linear}.tool-bar{display:flex;flex-direction:row;align-items:center;border-radius:12px;border-color:var(--ui-foreground-color);height:48px;bottom:12px;color:var(--ui-foreground-color);-webkit-tap-highlight-color:transparent}.tool-bar *{height:100%;min-width:48px}.tool-bar .divider{min-width:1px;margin:0 6px;height:66%;background-color:var(--ui-foreground-color)}.tool-bar select{background:0 0;min-width:52px;max-width:128px;border:1px solid transparent;border-radius:inherit;color:inherit;font-size:14px;padding:0 12px;cursor:pointer;outline:0;appearance:none;-webkit-appearance:none}.tool-bar .select-container{position:relative;display:flex;border-radius:inherit;border-width:0;padding:0}.tool-bar .select-container select{position:absolute;min-width:0;width:100%}.tool-bar .select-container button{position:absolute;border-width:0}.tool-bar select:focus,.tool-bar select:hover{background-color:var(--ui-background-color-hover)}.tool-bar select option{background-color:var(--ui-background-color);color:var(--ui-foreground-color)}.tool-bar select:focus-visible{border-color:inherit}.tool-bar button{background:0 0;border:1px solid transparent;border-radius:inherit;color:inherit;padding:0;cursor:pointer;outline:0}.tool-bar button:hover{background-color:var(--ui-background-color-hover)}.tool-bar button:focus-visible{border-color:inherit}.tool-bar button svg{width:32px;height:32px}.animation-timeline{display:flex;flex:1;position:relative;overflow:hidden;cursor:pointer;align-items:center;border-radius:inherit;border-color:inherit}.animation-timeline-input{-webkit-appearance:none;cursor:pointer;width:100%;height:100%;outline:0;border:1px solid transparent;border-radius:inherit;padding:0 12px;background-color:transparent}.animation-timeline-input:focus-visible{border-color:inherit}.animation-timeline-input::-webkit-slider-thumb{-webkit-appearance:none;width:20px;height:20px;border:2px solid;color:var(--ui-foreground-color);border-radius:50%;background:hsla(var(--ui-background-hue),var(--ui-background-saturation),var(--ui-background-lightness),1);margin-top:-10px}.animation-timeline-input::-webkit-slider-runnable-track{height:2px;-webkit-appearance:none;background-color:var(--ui-foreground-color)}.animation-timeline-input::-moz-range-progress{height:2px;background-color:var(--ui-foreground-color)}.animation-timeline-input::-moz-range-thumb{width:16px;height:16px;border:2px solid var(--ui-foreground-color);border-radius:50%;background:hsla(var(--ui-background-hue),var(--ui-background-saturation),var(--ui-background-lightness),1)}.animation-timeline-input::-moz-range-track{height:2px;background:var(--ui-foreground-color)}`,e})();function nt(e,...t){const n=new Error(`#${e}`);throw n.lite=t,n}const it=Float32Array,rt=Float64Array,st=Uint32Array,ot=Int32Array,at=Uint16Array,lt=Int16Array,ct=Uint8Array,ut=Int8Array,ht=Uint8ClampedArray,dt=DataView;function pt(){return new it(16)}let _t;function ft(){return(_t??pt)()}const mt=globalThis.GPUTextureUsage,gt=globalThis.GPUBufferUsage,bt=globalThis.GPUShaderStage,vt=globalThis.GPUColorWrite,yt="greater-equal";function wt(e){return`${e._colorFormat??"-"}|${e._depthStencilFormat??"-"}|${e._depthCompare??""}|${e._sampleCount}`}function xt(e){return{_descriptor:e,_colorTexture:null,_colorView:null,_depthTexture:null,_depthView:null,_width:0,_height:0}}function Ct(e,t){if(e._eager)return;At(e);const n=e._descriptor,{width:i,height:r}=function(e){const t=e.size;if("canvas"in t){const e=t.canvas;return{width:e.width,height:e.height}}return t}(n);e._width=i,e._height=r;const s=t._device;!!n.format&&(e._colorTexture=s.createTexture({label:n.lbl,size:{width:i,height:r},format:n.format,sampleCount:n.samples,usage:mt.RENDER_ATTACHMENT|mt.TEXTURE_BINDING|mt.COPY_SRC}),e._colorView=e._colorTexture.createView()),n.dFormat&&(e._depthTexture=s.createTexture({label:n.lbl,size:{width:i,height:r},format:n.dFormat,sampleCount:n.samples,usage:mt.RENDER_ATTACHMENT|mt.TEXTURE_BINDING}),e._depthView=e._depthTexture.createView())}function At(e){e&&!e._eager&&(e._colorTexture&&(e._colorTexture.destroy(),e._colorTexture=null,e._colorView=null),e._depthTexture&&(!1!==e._ownsDepthTexture&&e._depthTexture.destroy(),e._depthTexture=null,e._depthView=null),e._width=0,e._height=0)}const Mt=`Babylon Lite v${(()=>"1.24.0")()}`;function St(e){return"clientWidth"in e}let kt=1;function Pt(e){const t=e._context.getCurrentTexture(),n=e.scRT;n._colorTexture=t,n._colorView=t.createView({format:e.format}),n._width=t.width,n._height=t.height}function Et(e){const t=e.canvas;if(!St(t))return;const n=e._w??t.clientWidth,i=e._h??t.clientHeight;if(!(n>0&&i>0))return;const r=Math.min(globalThis.devicePixelRatio||1,e.maxDevicePixelRatio);!function(e,t,n){const i=e.canvas,r=0|t,s=0|n;if(!(r>0&&s>0))return;if(r===i.width&&s===i.height)return;i.width=r,i.height=s,e.scRT._width=r,e.scRT._height=s;for(const t of e._renderingContexts)t._resize?.()}(e,n*r|0,i*r|0)}function Ot(e){for(const t of e.splice(0))try{t()}catch{}}function Tt(e,t){(e._retirements??=[]).push(t)}function Bt(e){const t=e._retirements;if(!t)return;e._retirements=null;const n=e._retiring??=[];n.push(t),queueMicrotask(()=>{e._device.queue.onSubmittedWorkDone().then(()=>{const e=n.indexOf(t);e>=0&&n.splice(e,1),Ot(t)}).catch(()=>{})})}function Lt(e){const t=e._retirements,n=e._retiring;e._retirements=null,e._retiring=null,t&&Ot(t),n?.forEach(Ot)}let It=0;function Rt(){It=It+1|0}function $t(e,t){return-1!==e._renderingContexts.indexOf(t)}function Nt(e,t){return-1===e._renderingContexts.indexOf(t)&&(e._renderingContexts.push(t),!0)}function Vt(e,t){const n=e._renderingContexts,i=n.indexOf(t);return-1!==i&&(n.splice(i,1),!0)}async function Ft(e,t){const n=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});n||nt(46);const i=[];for(const e of["float32-filterable","texture-compression-astc","texture-compression-bc","texture-compression-etc2","timestamp-query","primitive-index"])n.features.has(e)&&i.push(e);const r=await n.requestDevice({requiredFeatures:i,requiredLimits:t?.requiredLimits});console.log(`${Mt} - WebGPU engine`);const s=!!t?.useHighPrecisionMatrix,o=!!t?.useFloatingOrigin;if(o&&!s&&nt(47),s){const{allocateF64Mat4:e}=await import("./_mat4-storage-f64-DK-NH_5C.esm.min.js");_t=e}let a,l,c,u;if(o){const[{wrapRenderableForFO:e,lightFoVersion:t,applyLightFoOffset:n},{makePackMeshWorld:i}]=await Promise.all([import("./floating-origin-D9zFZN_X.esm.min.js"),import("./pack-mat4-with-offset-DP8LbdFN.esm.min.js")]);a=e,l=i,c=t,u=n}const h={_device:r},d=[h];return Object.assign(h,{engine:h,surfaces:d,_surfaces:d,_device:r,_options:t,drawCallCount:0,gpuFrameTimeMs:0,useHighPrecisionMatrix:s,useFloatingOrigin:o,_animFrameId:0,_renderFn:null,_currentEncoder:void 0,_currentDelta:0,_cbs:[],_wrapRenderableForFO:a,_makePackMeshWorld:l,_lightFoVersion:c,_applyLightFoOffset:u},function(e,t,n){const i=t.getContext("webgpu");i||nt(48),St(t)&&t.setAttribute("data-engine",Mt);const r=n?.format??navigator.gpu.getPreferredCanvasFormat(),s=n?.srgb?(o=r).endsWith("-srgb")?o:`${o}-srgb`:r;var o;const a=n?.alphaMode??"opaque";i.configure({device:e._device,format:r,alphaMode:a,viewFormats:[s]});const l=1===n?.msaaSamples?1:4,c=xt({lbl:"swapchain",format:s,samples:1,size:{width:0,height:0}});return c._eager=!0,{engine:e,canvas:t,format:s,msaaSamples:l,scRT:c,maxDevicePixelRatio:n?.maxDevicePixelRatio??1/0,_uniqueId:kt++,_context:i,_configureFormat:r,_alphaMode:a,_renderingContexts:[]}}(h,e,t)),Et(h),Pt(h),h}function zt(e){for(const t of e.surfaces)Et(t)}function Dt(e){const t=e.canvas;return{width:t.width,height:t.height}}function Gt(e){return new Promise(t=>{let n=!0,i=0;e._renderFn=r=>{const s=n?0:i>0?r-i:16.667;i=r,zt(e),function(e,t){const n=e.surfaces;let i=0;for(let e=0;e<n.length;e++)i+=n[e]._renderingContexts.length;if(0===i)return void Bt(e);const r=e._device.createCommandEncoder({label:"frame"});e._currentEncoder=r,e._currentDelta=t,e._gpuTimerBegin?.(r);let s=0;for(let e=0;e<n.length;e++){const t=n[e];t._capturePreFrame?.(t),Pt(t);const i=t._renderingContexts;for(let e=0;e<i.length;e++){const t=i[e];t._update(),s+=t._drawCallsPre,s+=t._record()}}const o=e._currentEncoder;for(let e=0;e<n.length;e++){const t=n[e];t._captureService?.(t,o)}e._gpuTimerEnd?.(o),e._cbs[0]=o.finish(),e._device.queue.submit(e._cbs),Bt(e),e.drawCallCount=s,e._gpuTimerResolve?.()}(e,s),n&&(n=!1,t()),e._renderFn&&(e._animFrameId=requestAnimationFrame(e._renderFn))},e._animFrameId=requestAnimationFrame(e._renderFn)})}function Ut(e){e._animFrameId&&cancelAnimationFrame(e._animFrameId),e._animFrameId=0,e._renderFn=null,Bt(e)}function jt(e,t){const n=function(e){return e._deviceLostRecovery??={_forceNextLoss:!1,_requiredFeatures:[],_armedDevice:null,_registrations:[],_samplerDescriptors:new WeakMap,_captureRefs:0,_meshCaptureRefs:0}}(e),i=n._registrations;0===i.length&&(n._requiredFeatures=Array.from(e._device.features)),i.some(e=>e._kind===t._kind)||t._enable?.(e),i.push(t),Wt(e,n);let r=!1;return{disable(){if(r)return;r=!0;const n=i.indexOf(t);n>=0&&i.splice(n,1),i.some(e=>e._kind===t._kind)||t._disable?.(e)}}}function Wt(e,t){const n=e._device;t._armedDevice!==n&&(t._armedDevice=n,n.lost.then(i=>{if(0===t._registrations.length||t._armedDevice!==n)return;if("destroyed"===i.reason&&!t._forceNextLoss)return;t._forceNextLoss=!1;const r=[...t._registrations];for(const e of r)e._onLost?.(i);import("./device-lost-recovery-run-yo28fUiH.esm.min.js").then(({runDeviceLostRecovery:n})=>n(e,t,r)).then(()=>{Wt(e,t);for(const e of r)e._onRecovered?.()},e=>{for(const t of r)t._onRecoveryFailed?.(e)})}))}function Ht(e,t={}){return jt(e,{_kind:"scene",_recoverOrder:100,_enable(e){!function(e,t=!1){const n=e._deviceLostRecovery;n||nt(42),n._captureRefs++,t&&n._meshCaptureRefs++,1===n._captureRefs&&function(e){const t=e._deviceLostRecovery;e._dlr={u(e,t,n){e._recoverySource={kind:"url",url:t,opts:{...n}}},s(e,t,n,i,r){e._recoverySource={kind:"solid",rgba:[t,n,i,r]}},b(e,t,n,i,r){e._recoverySource={kind:"bitmap",bitmap:t,srgb:n,mipMaps:i,fallback:r}},p(e,t,n){e._recoverySource={kind:"pixels",data:t.slice(0,e.width*e.height*4),width:e.width,height:e.height,options:{...n}}},r(e,t,n,i,r){e._recoverySource={kind:"render",width:t,height:n,format:i,samplerDesc:r}},w(e,t,n,i,r,s,o=0,a=4*r){const l=e._recoverySource;if("pixels"!==l?.kind)return;const c=4*r;for(let e=0;e<s;e++){const r=o+e*a,s=4*((i+e)*l.width+n);l.data.set(t.subarray(r,r+c),s)}},m(t,n,i,r,s,o){e._deviceLostRecovery?._meshCaptureRefs&&(t._cpuUv2s=n??null,t._cpuTangents=i??null,t._cpuColors=r??null,t._cpuGpuIndices=s,t._cpuIndexFormat=o)},e(e,n,i){t._meshCaptureRefs&&(e._envRecoverySource={kind:"env",url:n,brdfUrl:i})},h(e,n,i){t._meshCaptureRefs&&(e._envRecoverySource={kind:"hdr",url:n,faceSize:i})}}}(e)}(e,!0)},_disable(e){!function(e,t=!1){const n=e._deviceLostRecovery;n&&0!==n._captureRefs&&(n._captureRefs--,t&&n._meshCaptureRefs>0&&n._meshCaptureRefs--,0===n._captureRefs&&(e._dlr=void 0))}(e,!0)},async _recover(e){const{rebuildRegisteredScenes:t}=await import("./recovery-rebuild-CtDyYGBR.esm.min.js");await t(e)},_onLost:t.onLost,_onRecovered:t.onRecovered,_onRecoveryFailed:t.onRecoveryFailed})}function qt(e){e._refCount=(e._refCount??1)+1}function Xt(e){const t=e._refCount;return void 0===t||t<=1||(e._refCount=t-1,!1)}function Yt(e,t,n,i=t.material){return import("./scene-runtime-mesh-build-C-1tN3dF.esm.min.js").then(r=>r.A(e,i,t,n)).catch(e=>console.error(e))}function Qt(e,t,n){e._runtimeThinBuild=Yt,e.thinInstances?(e.thinInstances.matrices=t,e.thinInstances.count=n,e.thinInstances._capacity=n,e.thinInstances._version++,e.thinInstances._dirtyMin=0,e.thinInstances._dirtyMax=n):e.thinInstances={matrices:t,count:n,_capacity:n,_version:1,_gpuBuffer:null,_gpuBufferStorage:!1,_gpuVersion:0,_dirtyMin:0,_dirtyMax:n,_colorVersion:0,_colorDirtyMin:0,_colorDirtyMax:0,_colorGpuBuffer:null,_colorGpuBufferStorage:!1,_colorGpuVersion:0,_gpuCullingEnabled:!1}}function Zt(e){e._lodSource=null,e._lodBuckets=null,e._lodAutoCull&&(e._lodAutoCull=!1,e._gpuCullingEnabled=!1,e._gpuVersion=-1,e._colorGpuVersion=-1)}function Kt(e){if(e._disposed)return;e._disposed=!0;const t=e._gpu;Xt(t)&&(t.positionBuffer.destroy(),t.normalBuffer.destroy(),t.uvBuffer.destroy(),t.indexBuffer.destroy(),t.tangentBuffer?.destroy(),t.uv2Buffer?.destroy(),t.colorBuffer?.destroy());const n=e.thinInstances;n&&Xt(n)&&(!function(e){const t=e.thinInstances;if(!t)return;const n=t._lodSource,i=n?.thinInstances;n&&i?._lodPartner===e&&(i._lodPartner=null,i._lodDistance=void 0,i._lodBand=void 0,i._lodBuckets=null,n._clone=void 0),t._lodSource&&Zt(t);const r=t._lodPartner,s=r?.thinInstances;t._lodPartner=null,t._lodDistance=void 0,t._lodBand=void 0,t._lodBuckets=null,e._clone=void 0,r&&s?._lodSource===e&&(r._clone=void 0,Zt(s))}(e),n._gpuBuffer?.destroy(),n._colorGpuBuffer?.destroy(),n._drawArgsBuffer?.destroy());const i=e.skeleton;i&&Xt(i)&&(i.boneTexture.destroy(),Xt(i._skinBuffers)&&(i.jointsBuffer.destroy(),i.weightsBuffer.destroy(),i.joints1Buffer?.destroy(),i.weights1Buffer?.destroy()));const r=e.vat;r&&Xt(r)&&(r.settingsBuffer.destroy(),r.instanceTexture?.destroy(),Xt(r._textureResource)&&r._textureResource.texture.destroy(),Xt(r._skinBuffers)&&(r.jointsBuffer.destroy(),r.weightsBuffer.destroy(),r.joints1Buffer?.destroy(),r.weights1Buffer?.destroy()));const s=e.morphTargets;s&&Xt(s)&&(s.deltasBuffer.destroy(),s.weightsBuffer.destroy())}let Jt=null;function en(e,t){e._materialSwapQueue.includes(t)||e._materialSwapQueue.push(t)}function tn(e,t){t._disposed&&nt(371,t.name);const n=Jt??=new WeakMap;let i=n.get(t);i||(n.set(t,i=new Set),function(e){let t=e.material;Object.defineProperty(e,"material",{get:()=>t,set(n){if(n!==t){t=n;const i=Jt?.get(e);if(i)for(const t of i)en(t,e)}},configurable:!0,enumerable:!0})}(t)),i.add(e)}function nn(e,t){const n=Jt?.get(t);return!n||(n.delete(e),0===n.size)}function rn(e){const t=e._materialSwapQueue;if(!t[0]||e._runtimeBuilds?.w)return;let n,i,r;const s=e._renderables;for(const o of t){const t=o.material;if(!t)continue;const a=o._runtimeThinBuild;if(a){i=a(e,o,i);continue}const l=e._groups.get(t._buildGroup),c=l?.r;if(!c){(r??=[]).push(o);continue}if(l._w?.(o)){(r??=[]).push([o,t]);continue}const u=e._meshDisposables.get(o);u&&(e._meshDisposables.delete(o),Tt(e.surface.engine,()=>u.forEach(e=>e())));const h=l.o;let d;for(let e=s.length;e--;)s[e].mesh===o&&(d=s.splice(e,1)[0]);t._csmGen=-~t._csmGen;const p=c(e,o);if(h){const e=h.indexOf(d);e<0?h.push(p):h[e]=p}n=s.push(p)}if(n&&(s.sort((e,t)=>e.order-t.order),e._renderableVersion++,e._materialEpoch++),t.length=0,!r)return i;const o=r;return import("./scene-runtime-mesh-build-C-1tN3dF.esm.min.js").then(({C:t})=>t(e,o,i),t=>{const n=e._runtimeBuilds;n?n._x(t):console.error(t)})}let sn=null;function on(e,t,n){sn?.(e,t,n)}function an(e,t){t._passes.length=0,e._currentProcessedTask=t;try{t.record()}finally{e._currentProcessedTask=null}}function ln(e,t,n,i,r,s){const o=n[i],a=n[i+1],l=n[i+2],c=n[i+3],u=n[i+4],h=n[i+5],d=n[i+6],p=n[i+7],_=n[i+8],f=n[i+9],m=n[i+10],g=n[i+11],b=n[i+12],v=n[i+13],y=n[i+14],w=n[i+15];let x=r[s],C=r[s+1],A=r[s+2],M=r[s+3];e[t]=o*x+u*C+_*A+b*M,e[t+1]=a*x+h*C+f*A+v*M,e[t+2]=l*x+d*C+m*A+y*M,e[t+3]=c*x+p*C+g*A+w*M,x=r[s+4],C=r[s+5],A=r[s+6],M=r[s+7],e[t+4]=o*x+u*C+_*A+b*M,e[t+5]=a*x+h*C+f*A+v*M,e[t+6]=l*x+d*C+m*A+y*M,e[t+7]=c*x+p*C+g*A+w*M,x=r[s+8],C=r[s+9],A=r[s+10],M=r[s+11],e[t+8]=o*x+u*C+_*A+b*M,e[t+9]=a*x+h*C+f*A+v*M,e[t+10]=l*x+d*C+m*A+y*M,e[t+11]=c*x+p*C+g*A+w*M,x=r[s+12],C=r[s+13],A=r[s+14],M=r[s+15],e[t+12]=o*x+u*C+_*A+b*M,e[t+13]=a*x+h*C+f*A+v*M,e[t+14]=l*x+d*C+m*A+y*M,e[t+15]=c*x+p*C+g*A+w*M}function cn(e){const t=e.worldMatrixVersion;if(e._viewVer===t)return e._viewCache;const n=e._viewCache,i=e.worldMatrix,r=e._useFloatingOrigin,s=r?0:i[12],o=r?0:i[13],a=r?0:i[14];return n[0]=i[0],n[1]=i[4],n[2]=i[8],n[3]=0,n[4]=i[1],n[5]=i[5],n[6]=i[9],n[7]=0,n[8]=i[2],n[9]=i[6],n[10]=i[10],n[11]=0,n[12]=-(i[0]*s+i[1]*o+i[2]*a),n[13]=-(i[4]*s+i[5]*o+i[6]*a),n[14]=-(i[8]*s+i[9]*o+i[10]*a),n[15]=1,e._viewVer=t,n}function un(e){return e._projFov===e.fov&&e._projNear===e.nearPlane&&e._projFar===e.farPlane||(e._projFov=e.fov,e._projNear=e.nearPlane,e._projFar=e.farPlane,e._projRev=(e._projRev??0)+1),e.worldMatrixVersion+(e._projRev??0)}function hn(e,t){const n=un(e);if(e._projVer===n&&e._projAspect===t)return e._projCache;const i=e._projCache;return function(e,t,n,i,r){const s=1/Math.tan(.5*t),o=r-i;e[0]=s/n,e[5]=s,e[10]=-i/o,e[11]=1,e[14]=r*i/o}(i,e.fov,t,e.nearPlane,e.farPlane),e._projVer=n,e._projAspect=t,i}function dn(e,t){const n=un(e);if(e._vpVer===n&&e._vpAspect===t)return e._vpCache;const i=e._vpCache;return ln(i,0,hn(e,t),0,cn(e),0),e._vpVer=n,e._vpAspect=t,i}function pn(e){const t=e.worldMatrix;return{x:t[12],y:t[13],z:t[14]}}let _n=null,fn=null;function mn(e){const t=e._device;return _n&&fn===t||(fn=t,_n=t.createBindGroupLayout({label:"scene",entries:[{binding:0,visibility:bt.VERTEX|bt.FRAGMENT,buffer:{type:"uniform"}},{binding:1,visibility:bt.FRAGMENT,buffer:{type:"uniform"}}]})),_n}function gn(){_n=null,fn=null}function bn(e){const t=e._blend?{format:e._format,blend:e._blend}:{format:e._format};return{label:e._label,layout:e._engine._device.createPipelineLayout({bindGroupLayouts:e._bgls}),vertex:{module:e._vertModule,entryPoint:"main",buffers:e._vertexBuffers},fragment:{module:e._fragModule,entryPoint:"main",targets:[t]},depthStencil:{format:e._depthStencilFormat??"depth24plus-stencil8",depthCompare:e._depthCompare??yt,depthWriteEnabled:e._depthWriteEnabled??!0},multisample:{count:e._msaaSamples},primitive:{topology:"triangle-list",cullMode:e._cullMode??"back",frontFace:"ccw"}}}function vn(e,t,n=0,i=0){const r=t;if(0===i&&16===r.length)return void e.set(r,n);const s=i,o=n;e[o+0]=r[s+0],e[o+1]=r[s+1],e[o+2]=r[s+2],e[o+3]=r[s+3],e[o+4]=r[s+4],e[o+5]=r[s+5],e[o+6]=r[s+6],e[o+7]=r[s+7],e[o+8]=r[s+8],e[o+9]=r[s+9],e[o+10]=r[s+10],e[o+11]=r[s+11],e[o+12]=r[s+12],e[o+13]=r[s+13],e[o+14]=r[s+14],e[o+15]=r[s+15]}function yn(e,t){return e+t-1&~(t-1)}function wn(e,t,n){const i=e._device,r=i.createBuffer({label:n,size:yn(t.byteLength,16),usage:gt.UNIFORM|gt.COPY_DST});return i.queue.writeBuffer(r,0,t.buffer,t.byteOffset,t.byteLength),r}function xn(e,t,n){return e._device.createBuffer({label:n,size:yn(t,16),usage:gt.UNIFORM|gt.COPY_DST})}function Cn(e,t,n,i){const r=yn(Math.max(t.byteLength,4),4),s=e._device.createBuffer({label:i,size:r,usage:n|gt.COPY_DST,mappedAtCreation:!0});return new ct(s.getMappedRange()).set(new ct(t.buffer,t.byteOffset,t.byteLength)),s.unmap(),s}const An=368;let Mn=16;function Sn(e){if(!Number.isFinite(e)||e<1)throw new Error(`setMaxLights: expected positive integer, got ${e}`);Mn=0|e}const kn=16,Pn=new st(1),En=new it(Pn.buffer);function On(e){let t=0;for(const n of e)t+=n._lightVersion??0;return t}function Tn(e,t){e.fill(0);let n=0;for(const i of t){if(n>=Mn)break;i._writeLightUbo&&(i._writeLightUbo(e,4+16*n),n++)}Pn[0]=n,e[0]=En[0]}function Bn(e,t){let n=t._lightGpuState;const i=16+16*Mn*4;if(n&&n._byteSize===i)return n;const r=!n;n?._buffer.destroy();const s=new it(i/4);return Tn(s,t.lights),e._applyLightFoOffset?.(s,t),n={_buffer:wn(e,s),_scratch:s,_version:On(t.lights)+(e._lightFoVersion?.(t)??0),_listVersion:t._lightListVersion??0,_lightCount:t.lights.length,_byteSize:i},t._lightGpuState=n,r&&t._disposables.push(()=>{t._lightGpuState?._buffer.destroy(),t._lightGpuState=void 0}),n}function Ln(e){e.push({_name:"lc",_type:"u32"}),e.push({_name:"li",_type:`array<vec4<u32>, ${Math.ceil(Mn/4)}>`})}function In(e,t="mli"){return`fn ${t}(i: u32) -> u32 { return ${e}.li[i / 4u][i % 4u]; }`}function Rn(e,t){const n=t.id,i=e.includedOnlyMeshIds;return i?.size?!!n&&i.has(n):!n||!e.excludedMeshIds?.has(n)}function $n(e,t,n){const i=n?new st(n.buffer,n.byteOffset,n.byteLength/4):null;let r=0,s=-1,o=0;for(const n of t){if(o>=Mn)break;n._writeLightUbo&&(Rn(n,e)&&(s=o,i&&(i[20+r]=o),r++),o++)}if(i){i[16]=r;for(let e=r;e<Mn;e++)i[20+e]=0}return 1===r?s+1:-r}function Nn(e,t,n){const i=n;e.clr??=!0;const r=e.rt._descriptor,s={_colorFormat:r.format,_depthStencilFormat:e.depth?._descriptor.dFormat??r.dFormat,_depthCompare:r._depthCompare,_sampleCount:r.samples??1},o=mn(t),a=xn(t,368),l=Bn(t,i)._buffer,c=t._device.createBindGroup({layout:o,entries:[{binding:0,resource:{buffer:a}},{binding:1,resource:{buffer:l}}]}),u={loadOp:"clear",storeOp:"store"},h={targetWidth:0,targetHeight:0},d=!1!==e.autoMirror,p=!e.sharedRt,_={name:e.name,_config:e,engine:t,scene:i,_passes:[],_renderables:[],_opaqueBindings:[],_directBindings:[],_transparentBindings:[],_ob:[],_lastVersion:-1,_lastVis:0,_recorded:!1,_renderPassDescriptor:{colorAttachments:[u]},_colorAttachment:u,_sceneUBO:a,_sceneBG:c,_lightsUBO:l,_suData:new it(92),_sceneUboCacheKey:[],_targetSignature:s,_updateBatches:[],_pendingMeshes:[],addMesh(e,n){const r=n?.material??e.material;r&&(_._pendingMeshes.push({mesh:e,material:r}),_._recorded&&(Fn(_,i),_._af=!1,zn(_,t,s)))},record(){_._af&&(_._renderables.length=0),Fn(_,i),_._af=d&&!_._renderables.length,_._af&&_._renderables.push(...i._renderables);const n=e.rt;p&&(Ct(n,t),e.rst&&(n._descriptor.samples??1)>1&&Ct(e.rst,t)),e.depth&&!e.depth._eager&&Ct(e.depth,t),h.targetWidth=n._width,h.targetHeight=n._height,Dn(_,t),zn(_,t,s),function(e,t){const n=e._config,i=e._colorAttachment;i.view=t._colorView,i.resolveTarget=n.rst?._colorView??void 0,e._renderPassDescriptor.colorAttachments=t._colorView?[i]:[];const r=n.depth??t,s=r._depthView;let o;if(s){const e=r._descriptor,t=(n.depth?r._eager:!1===n.depthClear)?"load":"clear";o={view:s,depthClearValue:e._depthClearValue??0,depthLoadOp:t,depthStoreOp:"store"},e.dFormat?.includes("stencil")&&(o.stencilClearValue=0,o.stencilLoadOp=t,o.stencilStoreOp="store")}e._renderPassDescriptor.depthStencilAttachment=o}(_,n),_._recorded=!0},execute:()=>function(e,t,n,i){if(!1===e.enabled)return 0;const r=e.scene,s=n._sampleCount;!function(e,t,n,i){const r=e.scene;e._af&&e._lastVersion!==r._renderableVersion&&(e._renderables.length=0,e._renderables.push(...r._renderables),zn(e,t,n));Dn(e,t);const s=e._config.cam??r.camera;n._colorFormat&&(e._config._skipClusteredLights||r._clusteredLightUpdater?.(s,i.targetWidth,i.targetHeight),function(e,t){const n=Bn(e,t),i=On(t.lights)+(e._lightFoVersion?.(t)??0),r=t._lightListVersion??0;i===n._version&&r===n._listVersion&&t.lights.length===n._lightCount||(n._version=i,n._listVersion=r,n._lightCount=t.lights.length,Tn(n._scratch,t.lights),e._applyLightFoOffset?.(n._scratch,t),e._device.queue.writeBuffer(n._buffer,0,n._scratch)),n._buffer}(t,r));(function(e,t,n,i){if(!i)return;const r=i.viewport,s=e._config.rt,o=(e._config.cs?t.canvas.width/t.canvas.height:s._width/s._height)*(r?r.width/r.height:1),a=n.fog,l=n.imageProcessing,c=un(i),u=n._envTextures,h=e._sceneUboCacheKey;if(h[0]===i&&h[1]===a&&h[2]===c&&h[3]===o&&h[4]===l.exposure&&h[5]===l.contrast&&h[6]===u)return;h[0]=i,h[1]=a,h[2]=c,h[3]=o,h[4]=l.exposure,h[5]=l.contrast,h[6]=u;const d=e._suData;!function(e,t,n,i,r){e.fill(0);const s=dn(i,r),o=cn(i),a=i.worldMatrix;vn(e,s,0),vn(e,o,16),t.useFloatingOrigin?(e[32]=0,e[33]=0,e[34]=0):(e[32]=a[12],e[33]=a[13],e[34]=a[14]),e[87]=t.canvas.width;const l=n._envTextures,c=n.imageProcessing;e[76]=c.exposure,e[77]=c.contrast,e[78]=l?.lodGenerationScale??.8,e[79]=+c.toneMappingEnabled,e[37]=t.canvas.height}(d,t,n,i,o);const p=n._sceneUboContributors;if(p)for(const e of p)e(d,n);t._device.queue.writeBuffer(e._sceneUBO,0,d)})(e,t,r,s),i._camera=s;for(const t of e._updateBatches)t.reset();Gn(e._opaqueBindings,i),Gn(e._directBindings,i),Gn(e._transparentBindings,i);for(const n of e._updateBatches)n.flush(t);!function(e,t){const n=e._transparentBindings;if(n.length<=1||!t)return;const i=cn(t);for(const e of n){const t=e.renderable._worldCenter;e._sortDistance=t?t[0]*i[2]+t[1]*i[6]+t[2]*i[10]+i[14]:0}n.sort((e,t)=>t._sortDistance-e._sortDistance||e.renderable.order-t.renderable.order)}(e,s)}(e,t,n,i);const o=e._colorAttachment,a=e._config;a.rt._colorView&&(a.rt===t.scRT&&(o.view=a.rt._colorView),o.resolveTarget=a.rst?._colorView??void 0,o.clearValue=a.clrColor??r.clearColor,o.loadOp=a.clr?"clear":"load");if(e._executeWithTransmission)return e._executeWithTransmission(s);const l=t._currentEncoder.beginRenderPass(e._renderPassDescriptor),c=function(e,t){const n=e.engine,i=e._config,r=i.rt,s=e.scene,o=e._opaqueBindings,a=e._ob,l=e._sceneBG,c=i.cam??s.camera,u=c?.viewport;if(u){const e=r._width,n=r._height,i=Math.floor(u.x*e),s=Math.floor((1-u.y-u.height)*n),o=Math.ceil((u.x+u.width)*e)-i,a=Math.ceil((1-u.y)*n)-s;t.setViewport(i,s,o,a,0,1),t.setScissorRect(i,s,o,a)}if(t.setBindGroup(0,l),e._lastVersion!==s._renderableVersion||e._lastVis!==It||!a.length){const t=r._descriptor,i=n._device.createRenderBundleEncoder({colorFormats:t.format?[t.format]:[],depthStencilFormat:e._targetSignature._depthStencilFormat,sampleCount:t.samples??1});i.setBindGroup(0,l),Un(i,o,n),a[0]=i.finish(),e._lastVersion=s._renderableVersion,e._lastVis=It}let h=o.length;return t.executeBundles(a),t.setBindGroup(0,l),h+=Un(t,e._directBindings,n),h+=Un(t,e._transparentBindings,n),h}(e,l);return l.end(),c}(_,t,s,h),dispose(){_._passes.length=_._opaqueBindings.length=_._directBindings.length=0,_._transparentBindings.length=_._renderables.length=_._ob.length=0,p&&(At(e.rt),At(e.rst)),At(e.depth),_._sceneUBO.destroy();for(const e of _._updateBatches)e.destroy();_._updateBatches.length=0}};return _}function Vn(e,t){if(!e._renderables)return;let n=!1;for(let i=e._pendingMeshes.length-1;i>=0;i--)e._pendingMeshes[i].mesh===t&&(e._pendingMeshes.splice(i,1),n=!0);for(let i=e._renderables.length-1;i>=0;i--)e._renderables[i].mesh===t&&(e._renderables.splice(i,1),n=!0);for(const i of[e._opaqueBindings,e._directBindings,e._transparentBindings])for(let e=i.length-1;e>=0;e--)i[e].renderable.mesh===t&&(i.splice(e,1),n=!0);n&&(e._ob.length=0,e._lastVersion=-1)}function Fn(e,t){if(e._pendingMeshes.length){for(const{mesh:n,material:i}of e._pendingMeshes){const r=i._buildGroup,s=t._groups.get(r),o=s?s.r:r._rebuildSingle;if(!o)throw Error();const a=o(t,n,i);e._renderables.includes(a)||e._renderables.push(a)}e._pendingMeshes.length=0}}function zn(e,t,n){const i=e._opaqueBindings,r=e._directBindings,s=e._transparentBindings;i.length=r.length=s.length=0;for(const o of e._renderables){const a=o.bind(t,n);for(const t of a._updateBatches??[])e._updateBatches.includes(t)||e._updateBatches.push(t);o.isTransparent||o._transmissive?s.push(a):o._direct?r.push(a):i.push(a)}i.sort((e,t)=>e.renderable.order-t.renderable.order),r.sort((e,t)=>e.renderable.order-t.renderable.order),e._ob.length=0,e._lastVersion=e.scene._renderableVersion}function Dn(e,t){const n=Bn(t,e.scene)._buffer;n!==e._lightsUBO&&(e._lightsUBO=n,e._sceneBG=t._device.createBindGroup({layout:mn(t),entries:[{binding:0,resource:{buffer:e._sceneUBO}},{binding:1,resource:{buffer:n}}]}),e._ob.length=0,e._lastVersion=-1)}function Gn(e,t){for(const n of e)n.update?.(t)}function Un(e,t,n){let i=null,r=0;for(const s of t){const t=s.renderable.mesh;t&&!1===t.visible||(s.pipeline!==i&&(e.setPipeline(s.pipeline),i=s.pipeline),r+=s.draw(e,n))}return r}let jn=null;function Wn(e,t){const n=e.engine,i={_kind:"scene",surface:e,clearColor:{r:.2,g:.2,b:.3,a:1},camera:null,lights:[],meshes:[],animationGroups:[],fog:null,clipPlane:null,shadowGenerators:[],imageProcessing:{exposure:1,contrast:1,toneMappingEnabled:!1},_renderables:[],_prePasses:[],_pickSources:[],_uniformUpdaters:[],fixedDeltaMs:0,_beforeRender:[],_deferredBuilders:[],_groups:new Map,_disposables:[],_meshDisposables:new Map,_meshAuxDisposables:new Map,_materialSwapQueue:[],_renderableVersion:0,_materialEpoch:0,_built:!1,_drawCallsPre:0,_update(){n.useFloatingOrigin&&r.camera&&!r.camera._useFloatingOrigin&&(r.camera._useFloatingOrigin=!0,r.camera._viewVer=-1,r.camera._vpVer=-1);const e=r.fixedDeltaMs>0?r.fixedDeltaMs:n._currentDelta,t=n._currentEncoder;let i=0;for(const t of r._beforeRender)t(e);r._materialSwapQueue.length&&rn(r);for(const e of r._prePasses)i+=e.execute(t,n);for(const e of r._uniformUpdaters)e.update(n);r._drawCallsPre=i},_record:()=>r._frameGraph.execute(),_resize(){r._frameGraph.build()}},r=i,s=function(){const e={_tasks:[],_currentProcessedTask:null,build(){for(let t=0;t<e._tasks.length;t++)an(e,e._tasks[t]);for(let t=0;t<e._tasks.length;t++){const n=e._tasks[t]._passes;for(let e=0;e<n.length;e++)n[e]._initialize()}},execute(){let t=0;for(const n of e._tasks)if(n.execute)t+=n.execute();else for(const e of n._passes)t+=e._execute();return t},dispose(){for(const t of e._tasks)t.dispose();e._tasks.length=0,e._currentProcessedTask=null}};return e}();r._frameGraph=s;{const t=e.msaaSamples>1,i=t?xt({lbl:"scene-color",format:e.format,dFormat:"depth24plus-stencil8",samples:e.msaaSamples,size:e}):e.scRT,o=t?void 0:xt({lbl:"scene-depth",dFormat:"depth24plus-stencil8",samples:1,size:e});!function(e,t){e._tasks.push(t)}(s,Nn({name:"scene",rt:i,rst:t?e.scRT:void 0,depth:o},n,r))}return r._disposables.push(()=>s.dispose()),r}function Hn(e,t){const n=e;if("entities"in t){const i=t;for(const t of i.entities)Hn(e,t);if(i.clearColor&&(n.clearColor=i.clearColor),i.camera&&!n.camera&&(n.camera=i.camera),i.animationGroups?.length){const e=n.surface.engine,t=i.animationGroups;n.animationGroups.push(...t);const r=n=>{for(const i of t)on(i,n,e)};i._beforeRenderHook=r,n._beforeRender.push(r)}return void i._sceneSetup?.(n,i)}if("_gpu"in t&&"material"in t){const e=t;tn(n,e),n.meshes.push(e);const i=e.material?e.material._buildGroup:void 0;if(i){let t=n._groups.get(i);t||(t=[],n._groups.set(i,t),n._built||n._deferredBuilders.push(async()=>{const e=await i(n,t);n._renderables.push(...e.renderables),t.o=e.renderables,e.updater&&n._uniformUpdaters.push(e.updater),t.r=e.rebuildSingle})),t.push(e),(n._built||t.r)&&en(n,e)}}else"lightType"in t&&n.lights.push(t);const i=t.children;if(i?.length)for(const n of i)n.parent=t,Hn(e,n)}async function qn(e){const t=e;for(t._built||(t._materialSwapQueue.length=0);t._deferredBuilders.length;){const e=t._deferredBuilders.splice(0);await Promise.all(e.map(e=>e()))}await rn(t),jn?.get(t)?.()||(t._runtimeBuilds?._e(),t._renderableVersion++,t._built=!0),await(t._rebuildHook?.(t))}async function Xn(e){const t=e,n=t.surface;if(!$t(n,t)){if(await qn(e),t._renderables.sort(Yn),await async function(e,t){if(t._frameGraph._tasks.some(e=>"shadow"===e.name))return;const{createShadowTask:n}=await import("./shadow-task-Bj4Ho70L.esm.min.js");t._frameGraph._tasks.unshift(n(e,t))}(n.engine,t),await Promise.all(t._frameGraph._tasks.map(e=>e._preload?.())),t._frameGraph.build(),n._renderingContexts[0]){(await import("./swapchain-overlay-CKIgRD0Z.esm.min.js")).configureSwapchainOverlayScene(n,t)}jn?.get(t)?.()||Nt(n,t)}}const Yn=(e,t)=>e.order-t.order;function Qn(e){Vt(e.surface,e)}const Zn={x:0,y:1,z:0};function Kn(e,t,n,i,r,s,o,a,l,c,u,h){const d=s*s,p=o*o,_=a*a,f=s*o,m=s*a,g=o*a,b=l*s,v=l*o,y=l*a;e[t]=(1-2*(p+_))*c,e[t+1]=2*(f+y)*c,e[t+2]=2*(m-v)*c,e[t+3]=0,e[t+4]=2*(f-y)*u,e[t+5]=(1-2*(d+_))*u,e[t+6]=2*(g+b)*u,e[t+7]=0,e[t+8]=2*(m+v)*h,e[t+9]=2*(g-b)*h,e[t+10]=(1-2*(d+p))*h,e[t+11]=0,e[t+12]=n,e[t+13]=i,e[t+14]=r,e[t+15]=1}function Jn(){const e=ft();return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}const ei=Symbol("wmState");function ti(e,t){e[ei]=t}function ni(e,t,n){return 0===e.x&&0===e.y&&0===e.z&&0===t.x&&0===t.y&&0===t.z&&1===t.w&&1===n.x&&1===n.y&&1===n.z?Jn():function(e,t,n,i,r,s,o,a,l,c){const u=ft();return Kn(u,0,e,t,n,i,r,s,o,a,l,c),u}(e.x,e.y,e.z,t.x,t.y,t.z,t.w,n.x,n.y,n.z)}function ii(e){let t=0,n=-1,i=null;const r=ft();let s=null,o=null;const a=[];function l(){i=null,t++;for(const e of a)e._invalidate()}function c(){const e=s.worldMatrixVersion;e!==n&&(n=e,l())}const u={get parent(){return s},set parent(e){e!==s&&(null!==o&&o._removeChild(u),s=e,o=function(e){return null===e?null:e[ei]??null}(e),null!==o&&o._addChild(u),n=-1,l())},markLocalDirty(){l()},getWorldMatrix(){if(null===o&&null!==s&&c(),null!==i)return i;const t=e();if(null!==s){const e=s.worldMatrix;ln(r,0,e,0,t,0),i=r}else i=t;return i},getWorldMatrixVersion:()=>(null===o&&null!==s&&c(),t),_invalidate(){l()},_addChild(e){a.push(e)},_removeChild(e){const t=a.indexOf(e);t>=0&&a.splice(t,1)}};return u}class ri{_x;_y;_z;_onDirty;constructor(e,t,n,i){this._x=e,this._y=t,this._z=n,this._onDirty=i}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._onDirty())}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._onDirty())}get z(){return this._z}set z(e){this._z!==e&&(this._z=e,this._onDirty())}set(e,t,n){this._x=e,this._y=t,this._z=n,this._onDirty()}copyFrom(e){this.set(e.x,e.y,e.z)}toArray(e,t=0){e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z}}function si(e,t,n,i){const r=ft();const s=ii(function(){return function(e,t,n,i){e[3]=0,e[7]=0,e[11]=0,e[12]=t.x,e[13]=t.y,e[14]=t.z,e[15]=1;let r=n.x-t.x,s=n.y-t.y,o=n.z-t.z;const a=Math.sqrt(r*r+s*s+o*o);let l=0,c=0,u=0,h=0;if(a>=1e-10){const e=1/a;r*=e,s*=e,o*=e,l=i.y*o-i.z*s,c=i.z*r-i.x*o,u=i.x*s-i.y*r,h=Math.sqrt(l*l+c*c+u*u)}if(h<1e-10)return e[0]=1,e[1]=0,e[2]=0,e[4]=0,e[5]=1,e[6]=0,e[8]=0,e[9]=0,void(e[10]=1);const d=1/h;l*=d,c*=d,u*=d,e[0]=l,e[1]=c,e[2]=u,e[4]=s*u-o*c,e[5]=o*l-r*u,e[6]=r*c-s*l,e[8]=r,e[9]=s,e[10]=o}(r,function(){const e=Math.cos(l.alpha),t=Math.sin(l.alpha),n=Math.cos(l.beta);let i=Math.sin(l.beta);return 0===i&&(i=1e-4),{x:l.target.x+l.radius*e*i,y:l.target.y+l.radius*n,z:l.target.z+l.radius*t*i}}(),l.target,Zn),r}),o=()=>s.markLocalDirty(),a={alpha:e,beta:t,radius:n},l={alpha:0,beta:0,radius:0,target:new ri(i.x,i.y,i.z,o),fov:.8,nearPlane:.1,farPlane:1e3,children:[],inertia:.9,panningInertia:.9,angularSensibility:1e3,panningSensibility:50,wheelPrecision:3,inertialAlphaOffset:0,inertialBetaOffset:0,inertialRadiusOffset:0,inertialPanningX:0,inertialPanningY:0,_viewCache:ft(),_projCache:ft(),_vpCache:ft(),get parent(){return s.parent},set parent(e){s.parent=e},get worldMatrix(){return s.getWorldMatrix()},get worldMatrixVersion(){return s.getWorldMatrixVersion()}};for(const e of["alpha","beta","radius"])Object.defineProperty(l,e,{get:()=>a[e],set:t=>{a[e]!==t&&(a[e]=t,o(),l._clampToLimits?.())},configurable:!0,enumerable:!0});return ti(l,s),l}function oi(e,t,n,i){const r=n-i,s=n+i,o=0===t?"minX":1===t?"minY":"minZ",a=0===t?"maxX":1===t?"maxY":"maxZ";r<e[o]&&(e[o]=r),s>e[a]&&(e[a]=s)}function ai(e,t){const n=t.boundMin,i=t.boundMax;if(!n||!i)return;if(void 0!==t._expandWorldBounds)return void t._expandWorldBounds(e,t);const r=t.worldMatrix,s=[.5*(n[0]+i[0]),.5*(n[1]+i[1]),.5*(n[2]+i[2])],o=[.5*(i[0]-n[0]),.5*(i[1]-n[1]),.5*(i[2]-n[2])];for(let t=0;t<3;t++){let n=r[12+t],i=0;for(let e=0;e<3;e++){const a=r[4*e+t];n+=a*s[e],i+=Math.abs(a)*o[e]}oi(e,t,n,i)}}function li(e,t){if("entities"in t){const n=t;for(const t of n.entities)li(e,t);n.camera&&e.camera===n.camera&&(e.camera=null);const i=n.animationGroups;if(i?.length)for(const t of i)di(e.animationGroups,t);const r=n._beforeRenderHook;r&&(di(e._beforeRender,r),n._beforeRenderHook=void 0);const s=n._sceneCleanups;if(s){const t=s.get(e);t&&(di(e._disposables,t),s.delete(e),e._z||t())}return}if("_gpu"in t&&"material"in t)return function(e,t){for(const n of e._frameGraph._tasks)n._removeMesh?.(t);const n=e._meshDisposables.get(t);let i=!1;const r=[];n&&(i=!0,r.push(...n),e._meshDisposables.delete(t));const s=e._meshAuxDisposables.get(t);s&&(i=!0,r.push(...s),e._meshAuxDisposables.delete(t));const o=e.meshes.indexOf(t);o>=0&&(e.meshes.splice(o,1),i=!0);const a=e._renderables.findIndex(e=>e.mesh===t);a>=0&&(e._renderables.splice(a,1),i=!0);i&&e._renderableVersion++;for(const n of e._groups.values()){const e=n.indexOf(t);e>=0&&n.splice(e,1)}const l=e._materialSwapQueue.indexOf(t);l>=0&&e._materialSwapQueue.splice(l,1);e._runtimeBuilds?.remove(t),t.parent=null;for(const n of e._frameGraph._tasks)"_renderables"in n&&Vn(n,t);nn(e,t)&&r.push(()=>Kt(t));r.length&&function(e,t){for(const e of t){const t=e.p;if(t){t._disposed=!0;const e=t._owner;if(e){const n=e.indexOf(t);n>=0&&e.splice(n,1),t._owner=void 0}}}!function(e,t){if(e._z)return void t();Tt(e.surface.engine,t)}(e,()=>{for(const e of t)e()})}(e,r)}(e,t),void pi(e,t);if("lightType"in t){di(e.lights,t);const n=t.shadowGenerator;n?ci(e,n):ui(e)}else"fov"in t&&"nearPlane"in t?e.camera===t&&(e.camera=null):"_shadowType"in t&&"_light"in t&&ci(e,t);var n;(n=t)&&"object"==typeof n&&"parent"in n&&(n.parent=null),pi(e,t)}function ci(e,t){di(e.shadowGenerators,t);const n=t._light;n&&n.shadowGenerator===t&&(n.shadowGenerator=void 0),ui(e);const i=t._shadowTaskState;i&&(t._shadowTaskState=void 0,function(e,t){e._pendingTopologyRetirements||(e._pendingTopologyRetirements=[],e._disposables.push(()=>function(e){const t=e._pendingTopologyRetirements?.splice(0);if(!t?.length)return;const n=()=>{for(const e of t)try{e()}catch{}},i=e.surface.engine._device;i?i.queue.onSubmittedWorkDone().then(n,n):n()}(e)));e._pendingTopologyRetirements.push(t)}(e,()=>i._task.dispose()))}function ui(e){e._lightListVersion=(e._lightListVersion??0)+1,e._built&&(e._rebuildHook=hi)}async function hi(e){const{rebuildSceneRenderables:t}=await Promise.resolve().then(function(){return Es});await t(e)}function di(e,t){const n=e.indexOf(t);n>=0&&e.splice(n,1)}function pi(e,t){const n=t.children;if(n?.length)for(const t of[...n])li(e,t)}function _i(e,t){e[36]=t._environmentRotation??0;const n=t._envTextures?.sphericalHarmonics;n&&e.set(n,40)}function fi(e,t){const n=e._sceneUboContributors??=[];n.includes(t)||n.push(t)}function mi(e){for(const t of e._frameGraph._tasks)t._sceneUboCacheKey&&(t._sceneUboCacheKey.length=0)}function gi(e){fi(e,_i)}const bi=/textureSampleLevel\(\s*([^,]+?)\s*,\s*([^,]+?)\s*,\s*([^,]+?)\s*,\s*0(?:\.0?)?\s*\)\.rgb/,vi=Object.freeze(Object.defineProperty({__proto__:null,_apply:(e,t)=>{const n=e.match(bi),i=n?.[1],r=n?.[2],s=n?.[3];if(!i||!r||!s)throw new Error("Environment blur: skybox cubemap sample not found.");const o=`clamp(scene._envPad1*log2(f32(textureDimensions(${i}).x))*${"dds"===t?"0.8":"scene.vImageInfos.z+scene._envPad2"},0.0,f32(textureNumLevels(${i})-1))`;return e.replace(bi,`textureSampleLevel(${i},${r},${s},0.0+(${o})).rgb`)}},Symbol.toStringTag,{value:"Module"})),yi="struct a{viewProjection:mat4x4<f32>,view:mat4x4<f32>,vEyePosition:vec4<f32>,envRotationY:f32,_envPad0:f32,_envPad1:f32,_envPad2:f32,vSphericalL00:vec4<f32>,vSphericalL1_1:vec4<f32>,vSphericalL10:vec4<f32>,vSphericalL11:vec4<f32>,vSphericalL2_2:vec4<f32>,vSphericalL2_1:vec4<f32>,vSphericalL20:vec4<f32>,vSphericalL21:vec4<f32>,vSphericalL22:vec4<f32>,vImageInfos:vec4<f32>,vFogInfos:vec4<f32>,vFogColor:vec4<f32>,clipPlane:vec4<f32>}@group(0) @binding(0) var<uniform> scene:a;";function wi(e,t,n){const i=e._environmentSkyboxShaderPatchLoaders??=[];i[t]=n,e._environmentSkyboxShaderComposer??=async(e,t)=>{e="hdr"===t?yi+e:e;for(const n of i.slice())n&&(e=(await n())._apply(e,t));return e}}const xi=()=>vi;function Ci(e,t){e[38]=t._environmentBlur??0,e[39]=t._envTextures?.lodGenerationOffset??0}function Ai(e,t){e._environmentBlur=t,wi(e,1,xi),fi(e,Ci),mi(e)}const Mi=()=>import("./environment-rotation-fragment-jwyCatZa.esm.min.js");function Si(e,t){gi(e),e._environmentRotation=t,wi(e,0,Mi),mi(e)}let ki=null;function Pi(){return ki||(ki=new WeakMap),ki}function Ei(e){const t=Pi();t.set(e.texture,(t.get(e.texture)??0)+1)}function Oi(e){const t=Pi(),n=(t.get(e.texture)??1)-1;return n<=0?(e.texture.destroy(),t.delete(e.texture),!0):(t.set(e.texture,n),!1)}function Ti(e){const t=Pi();t.set(e,(t.get(e)??0)+1)}function Bi(e){const t=Pi(),n=(t.get(e)??1)-1;return n<=0?(e.destroy(),t.delete(e),!0):(t.set(e,n),!1)}let Li=null;function Ii(e,t={}){const n=e._device;Li||(Li=new WeakMap);let i=Li.get(n);i||(i=new Map,Li.set(n,i));const r=function(e){return`${e.minFilter??"nearest"}:${e.magFilter??"nearest"}:${e.mipmapFilter??"nearest"}:${e.addressModeU??"clamp-to-edge"}:${e.addressModeV??"clamp-to-edge"}:${e.addressModeW??"clamp-to-edge"}:${e.maxAnisotropy??1}`}(t);let s=i.get(r);return s||(s=n.createSampler(t),i.set(r,s)),s}function Ri(e){const t=e._device;Li?.delete(t)}const $i={magFilter:"linear",minFilter:"linear"},Ni={magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"};function Vi(e){return Ii(e,$i)}function Fi(e){return Ii(e,Ni)}function zi(e,t){return Math.floor(Math.log2(Math.max(e,t)))+1}function Di(e,t,n){const i=Math.max(e,t);return Math.max(1,Math.floor(Math.log2(i)-n)+1)}function Gi(e){const t=e,n=t[0],i=t[1],r=t[2],s=t[3],o=t[4],a=t[5],l=t[6],c=t[7],u=t[8],h=t[9],d=t[10],p=t[11],_=t[12],f=t[13],m=t[14],g=t[15],b=n*a-i*o,v=n*l-r*o,y=n*c-s*o,w=i*l-r*a,x=i*c-s*a,C=r*c-s*l,A=u*f-h*_,M=u*m-d*_,S=u*g-p*_,k=h*m-d*f,P=h*g-p*f,E=d*g-p*m;let O=b*E-v*P+y*k+w*S-x*M+C*A;if(Math.abs(O)<1e-10)return null;O=1/O;const T=ft();return T[0]=(a*E-l*P+c*k)*O,T[1]=(r*P-i*E-s*k)*O,T[2]=(f*C-m*x+g*w)*O,T[3]=(d*x-h*C-p*w)*O,T[4]=(l*S-o*E-c*M)*O,T[5]=(n*E-r*S+s*M)*O,T[6]=(m*y-_*C-g*v)*O,T[7]=(u*C-d*y+p*v)*O,T[8]=(o*P-a*S+c*A)*O,T[9]=(i*S-n*P-s*A)*O,T[10]=(_*x-f*y+g*b)*O,T[11]=(h*y-u*x-p*b)*O,T[12]=(a*M-o*k-l*A)*O,T[13]=(n*k-i*M+r*A)*O,T[14]=(f*v-_*w-m*b)*O,T[15]=(u*w-h*v+d*b)*O,T}function Ui(e){return e instanceof Error?e:new Error(String(e))}const ji=()=>{};function Wi(e,t,n){const i=2*Math.PI;let r=(t-e)%i;return r>Math.PI?r-=i:r<-Math.PI&&(r+=i),e+r*n}const Hi=.001;function qi(e,t,n){return void 0!==t&&e<t?t:void 0!==n&&e>n?n:e}function Xi(e,t,n,i,r){const s=void 0!==n.alpha&&!isNaN(n.alpha),o=void 0!==n.beta&&!isNaN(n.beta),a=void 0!==n.radius&&!isNaN(n.radius),l=void 0!==n.target;let c=0,u=0,h=0;const d={x:0,y:0,z:0};let p=0,_=0,f=0;const m={x:0,y:0,z:0};let g=!0;return function(e,t,n){return new Promise((i,r)=>{if(n?.aborted)return void r(Ui(n.reason));let s,o=!1;const a=()=>{if(o)return;o=!0;const t=e._beforeRender,i=t.indexOf(l);if(i>=0)for(t[i]=ji;t.length>0&&t[t.length-1]===ji;)t.pop();s&&n&&n.removeEventListener("abort",s)},l=e=>{if(o)return;const n=(e>0?e:1e3/60)/1e3;let s;try{s=t(n)}catch(e){return a(),void r(Ui(e))}s||(a(),i())};n&&(s=()=>{a(),r(Ui(n.reason))},n.addEventListener("abort",s)),e._beforeRender.push(l)})}(t,t=>{if(g)g=!1,e.inertialAlphaOffset=0,e.inertialBetaOffset=0,e.inertialRadiusOffset=0,e.inertialPanningX=0,e.inertialPanningY=0,c=s?n.alpha:e.alpha,u=o?n.beta:e.beta,h=a?n.radius:e.radius,d.x=l?n.target.x:e.target.x,d.y=l?n.target.y:e.target.y,d.z=l?n.target.z:e.target.z;else if(e.alpha!==p||e.beta!==_||e.radius!==f||e.target.x!==m.x||e.target.y!==m.y||e.target.z!==m.z)throw new Error("ArcRotate camera interpolation was interrupted.");const i=qi(c,e.lowerAlphaLimit,e.upperAlphaLimit),r=qi(u,e.lowerBetaLimit,e.upperBetaLimit),b=qi(h,e.lowerRadiusLimit,e.upperRadiusLimit),v=function(e,t){return e<=0?0:1-Math.pow(2,-e/t)}(t,.1);e.alpha=Wi(e.alpha,i,v),e.beta=Wi(e.beta,r,v),e.radius=function(e,t,n){return e+(t-e)*n}(e.radius,b,v),function(e,t,n,i){i.x=e.x+(t.x-e.x)*n,i.y=e.y+(t.y-e.y)*n,i.z=e.z+(t.z-e.z)*n}(e.target,d,v,e.target);const y=Math.abs(b)>1e-6?Math.abs(b):1,w=Math.abs(Wi(e.alpha,i,1)-e.alpha),x=Math.abs(Wi(e.beta,r,1)-e.beta),C=Math.abs(b-e.radius)/y,A=d.x-e.target.x,M=d.y-e.target.y,S=d.z-e.target.z,k=Math.hypot(A,M,S)/y;return w<Hi&&x<Hi&&C<Hi&&k<Hi?(e.alpha=i,e.beta=r,e.radius=b,e.target.x=d.x,e.target.y=d.y,e.target.z=d.z,!1):(p=e.alpha,_=e.beta,f=e.radius,m.x=e.target.x,m.y=e.target.y,m.z=e.target.z,!0)},i)}function Yi(e,t,n,i){const r=e[0]*t+e[4]*n+e[8]*i+e[12],s=e[1]*t+e[5]*n+e[9]*i+e[13],o=e[2]*t+e[6]*n+e[10]*i+e[14],a=1/(e[3]*t+e[7]*n+e[11]*i+e[15]);return[r*a,s*a,o*a]}function Qi(e){const t=ii(e),n={_lightVersion:0,b(){n._lightVersion++}};return{wm:t,onDirty:()=>{t.markLocalDirty(),n._lightVersion++},lvs:n}}function Zi(e,t,n){return Object.defineProperties(e,{parent:{get:()=>t.parent,set(e){t.parent=e},enumerable:!0,configurable:!0},worldMatrix:{get:()=>t.getWorldMatrix(),enumerable:!0,configurable:!0},worldMatrixVersion:{get:()=>t.getWorldMatrixVersion(),enumerable:!0,configurable:!0}}),n&&(Object.defineProperty(e,"_lightVersion",{get:()=>n._lightVersion,enumerable:!1,configurable:!0}),e._bumpLightVersion=n.b),ti(e,t),e}function Ki(e,t,n,i=0,r=0,s=0,o){const a=Math.sqrt(e*e+t*t+n*n)||1,l=e/a,c=t/a,u=n/a;let h=-u,d=l;const p=Math.sqrt(h*h+0+d*d)||1;h/=p,d/=p;const _=c*d-0*u,f=u*h-l*d,m=0*l-c*h,g=o??new it(16),b=g;return b[0]=h,b[1]=0,b[2]=d,b[3]=0,b[4]=_,b[5]=f,b[6]=m,b[7]=0,b[8]=l,b[9]=c,b[10]=u,b[11]=0,b[12]=i,b[13]=r,b[14]=s,b[15]=1,g}function Ji(e,t=1){const n=ft(),{wm:i,onDirty:r,lvs:s}=Qi(()=>Ki(o.direction.x,o.direction.y,o.direction.z,o.position.x,o.position.y,o.position.z,n)),o=Zi({lightType:"directional",children:[],direction:new ri(e[0],e[1],e[2],r),position:new ri(0,0,0,r),diffuse:[1,1,1],specular:[1,1,1],intensity:t,_writeLightUbo:(e,t)=>{const n=t,i=o.worldMatrix;e[n]=i[8],e[n+1]=i[9],e[n+2]=i[10],e[n+3]=1,e[n+4]=o.diffuse[0]*o.intensity,e[n+5]=o.diffuse[1]*o.intensity,e[n+6]=o.diffuse[2]*o.intensity,e[n+7]=Number.MAX_VALUE,e[n+8]=o.specular[0]*o.intensity,e[n+9]=o.specular[1]*o.intensity,e[n+10]=o.specular[2]*o.intensity}},i,s);return o}var er=Object.freeze({__proto__:null,createDirectionalLight:Ji});const tr=1,nr=2,ir=4,rr=8,sr=16,or=32,ar=64,lr=128,cr=256,ur=1024,hr=2048,dr=4096,pr=32768,_r=1<<17,fr=1<<20,mr=1<<21,gr=1<<22,br=1<<23,vr=1<<25,yr=1<<26,wr=1<<27,xr=1<<28,Cr=1<<29,Ar=1<<30,Mr=16,Sr=512,kr=1024,Pr=2048,Er=4096,Or=32768,Tr=65536;let Br=null,Lr=null;function Ir(e){(Br??=new Map).set(e.id,e),Lr=null}function Rr(){return Br??=new Map}let $r=null;function Nr(e){($r??=new Set).add(e)}function Vr(){return $r??[]}class Fr{_x;_y;_z;_w;_onDirty;_version=0;constructor(e,t,n,i,r){this._x=e,this._y=t,this._z=n,this._w=i,this._onDirty=r}get version(){return this._version}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._version++,this._onDirty())}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._version++,this._onDirty())}get z(){return this._z}set z(e){this._z!==e&&(this._z=e,this._version++,this._onDirty())}get w(){return this._w}set w(e){this._w!==e&&(this._w=e,this._version++,this._onDirty())}set(e,t,n,i){this._x=e,this._y=t,this._z=n,this._w=i,this._version++,this._onDirty()}copyFrom(e){this.set(e.x,e.y,e.z,e.w)}toArray(e,t=0){e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w}}function zr(e,t,n){const i=Math.cos(.5*e),r=Math.sin(.5*e),s=Math.cos(.5*t),o=Math.sin(.5*t),a=Math.cos(.5*n),l=Math.sin(.5*n);return[r*s*a+i*o*l,i*o*a-r*s*l,i*s*l+r*o*a,i*s*a-r*o*l]}function Dr(e){let t=0,n=0,i=0,r=-1;const s=()=>{if(e.version!==r){const s=function(e,t,n,i){const r=2*(e*n+i*t),s=Math.asin(Math.max(-1,Math.min(1,r)));return[Math.atan2(-2*(t*n-i*e),1-2*(e*e+t*t)),s,Math.atan2(-2*(e*t-i*n),1-2*(t*t+n*n))]}(e.x,e.y,e.z,e.w);t=s[0],n=s[1],i=s[2],r=e.version}},o=(s,o,a)=>{t=s,n=o,i=a;const[l,c,u,h]=zr(s,o,a);e.set(l,c,u,h),r=e.version};return{get x(){return s(),t},set x(e){s(),o(e,n,i)},get y(){return s(),n},set y(e){s(),o(t,e,i)},get z(){return s(),i},set z(e){s(),o(t,n,e)},set:o}}function Gr(e,t,n=0,i=0,r=0,s=0,o=0,a=0,l=1,c=1,u=1,h=1){const d=ii(()=>m._localMatrix??ni(m.position,m.rotationQuaternion,m.scaling)),p=()=>{m._localMatrix||d.markLocalDirty()},_=new ri(n,i,r,p),f=new Fr(s,o,a,l,p),m={name:e,children:[],position:_,rotationQuaternion:f,rotation:Dr(f),scaling:new ri(c,u,h,p),get parent(){return d.parent},set parent(e){d.parent=e},get worldMatrix(){return d.getWorldMatrix()},get worldMatrixVersion(){return d.getWorldMatrixVersion()}};return t&&(m._localMatrix=t),ti(m,d),m}function Ur(e,t=0,n=0,i=0,r=0,s=0,o=0,a=1,l=1,c=1){const u=ii(()=>ni(v.position,v.rotationQuaternion,v.scaling)),h=()=>u.markLocalDirty(),[d,p,_,f]=zr(r,s,o),m=new Fr(d,p,_,f,h),g=m,b=Dr(m),v={...e,position:new ri(t,n,i,h),rotationQuaternion:g,rotation:b,scaling:new ri(a,l,c,h)};return v.children||(v.children=[]),Object.defineProperty(v,"parent",{get:()=>u.parent,set(e){u.parent=e},configurable:!0,enumerable:!0}),Object.defineProperty(v,"worldMatrix",{get:()=>u.getWorldMatrix(),configurable:!0,enumerable:!1}),Object.defineProperty(v,"worldMatrixVersion",{get:()=>u.getWorldMatrixVersion(),configurable:!0,enumerable:!1}),ti(v,u),v}function jr(e,t,n,i,r,s,o,a){const l=e._device,c=Cn(e,t,gt.VERTEX),u=Cn(e,n,gt.VERTEX),h=Cn(e,i,gt.INDEX);let d;r&&r.length>0?d=Cn(e,r,gt.VERTEX):(d=l.createBuffer({size:t.length/3*8,usage:gt.VERTEX,mappedAtCreation:!0}),d.unmap());return{positionBuffer:c,normalBuffer:u,uvBuffer:d,uv2Buffer:null,tangentBuffer:null,colorBuffer:null,hasUv:!!r&&r.length>0,hasUv2:!1,hasTangent:!1,hasColor:!1,indexBuffer:h,indexCount:i.length,indexFormat:"uint32"}}function Wr(e,t){let n=1/0,i=1/0,r=1/0,s=-1/0,o=-1/0,a=-1/0;for(let t=0;t<e.length;t+=3){const l=e[t],c=e[t+1],u=e[t+2];l<n&&(n=l),l>s&&(s=l),c<i&&(i=c),c>o&&(o=c),u<r&&(r=u),u>a&&(a=u)}return[[n,i,r],[s,o,a]]}function Hr(e,t){const n=function(e={}){const t=e.radius??.5,n=e.tessellation??64,i=e.arc&&(e.arc<=0||e.arc>1)?1:e.arc??1,r=[],s=[],o=[];r.push(0,0,0),s.push(.5,.5);const a=2*Math.PI*i,l=1===i?a/n:a/(n-1);let c=0;for(let e=0;e<n;e++){const e=Math.cos(c),n=Math.sin(c);r.push(t*e,t*n,0),s.push((e+1)/2,(1-n)/2),c+=l}1===i&&(r.push(r[3],r[4],r[5]),s.push(s[2],s[3]));const u=r.length/3;for(let e=1;e<u-1;e++)o.push(e+1,0,e);const h=new it(3*u);for(let e=0;e<u;e++)h[3*e+2]=-1;return{positions:new it(r),normals:h,uvs:new it(s),indices:new st(o)}}(t);return function(e,t,n,i,r,s){const[o,a]=Wr(n),l=Ur({name:t,material:null,receiveShadows:!1,boundMin:isFinite(o[0])?o:void 0,boundMax:isFinite(a[0])?a:void 0,_gpu:jr(e,n,i,r,s)});return l._cpuPositions=n,l._cpuNormals=i,l._cpuUvs=s,l._cpuIndices=r,e._dlr?.m(l,null,null,null,r,"uint32"),l}(e,"disc",n.positions,n.normals,n.indices,n.uvs)}const qr=1,Xr=2,Yr=4,Qr=8,Zr=16,Kr=32,Jr=64,es=128,ts=256,ns=1024;function is(e,t=!1){const n=e._gpu;let i=0;return n.tangentBuffer&&(i|=1),e.vat?(i|=512,e.vat.joints1Buffer&&(i|=4)):e.skeleton&&(i|=2,e.skeleton.joints1Buffer&&(i|=4)),e.morphTargets&&(i|=8),e.thinInstances&&(i|=16,e.thinInstances.colors&&(i|=32)),n.colorBuffer&&(i|=64),n.uv2Buffer&&(i|=128),e._flatNormal&&(i|=1024),t&&(i|=256),i}let rs=null;const ss=new Map;let os=null;function as(e){os!==e._device&&(ss.clear(),os=e._device)}function ls(){ss.clear(),os=null}function cs(e,t,n,i,r,s,o="",a=null){as(e);const l=`${t}:${n}:${i}:${r}:${o}`,c=ss.get(l);if(c)return c;const u=e._device,h=u.createBindGroupLayout(s._meshBGLDescriptor);let d=null;s._shadowBGLDescriptor&&(d=u.createBindGroupLayout(s._shadowBGLDescriptor));const p={_features:t,_features2:n,_meshFeatures:i,_meshBGL:h,_shadowBGL:d,_composed:s,_pipelines:new Map};return ss.set(l,p),p}function us(e,t,n,i){as(e),t._sampleCount;const r=`${wt(t)}`,s=n._pipelines.get(r);if(s)return s;const o=e._device,{_features:a,_features2:l,_composed:c}=n,u=0!==(l&Tr),h=!u&&!!(64&a),d=!!(256&a),p=mn(e),_=n._shadowBGL?[p,n._meshBGL,n._shadowBGL]:[p,n._meshBGL],f=o.createShaderModule({code:c._vertexWGSL}),m=!!(32768&l),g=t._colorFormat||m?o.createShaderModule({code:c._fragmentWGSL}):null,b=m?null:{format:t._colorFormat,writeMask:vt.ALL};h&&b&&(b.blend={color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one",operation:"add"}});const v=o.createRenderPipeline({layout:o.createPipelineLayout({bindGroupLayouts:_}),vertex:{module:f,entryPoint:"main",buffers:c._vertexBufferLayouts},...g?{fragment:{module:g,entryPoint:"main",targets:b?[b]:[]}}:{},...t._depthStencilFormat?{depthStencil:{format:t._depthStencilFormat,depthCompare:t._depthCompare??yt,depthWriteEnabled:m||u||!h}}:{},multisample:{count:t._sampleCount},primitive:{cullMode:d?"none":"back",...c._prim}});return n._pipelines.set(r,v),v}function hs(e,t,n,i,r,s,o,a,l){const c=e._device,u=t._features,h=t._features2,d=t._meshFeatures,p=!!(1&u)&&!!(1&d)||!(!(1&u)||1&d),_=!!(2&u),f=!!(128&u),m=0!==(h&Tr),g=[];let b=0;const v=e=>{g.push({binding:b++,resource:e.view}),g.push({binding:b++,resource:e.sampler})},y={_engine:e,_features:u,_features2:h,_meshFeatures:d,_material:s,_mesh:a??void 0,_env:o,_refractionTexture:l},w=function(){if(!Lr){const e=Br;Lr=e?Array.from(e.values()).sort((e,t)=>e.id.localeCompare(t.id)):[]}return Lr}(),x=n._fragmentKey?n._fragmentKey.split("|").filter(e=>e.length>0):[];g.push({binding:b++,resource:{buffer:i}}),g.push({binding:b++,resource:{buffer:r}});for(const e of w)"vertex"===e.phase&&e.bind&&(b=e.bind(y,g,b));v(s.baseColorTexture??rs?.(e)),p&&v(s.normalTexture),v(s.ormTexture??rs?.(e)),0!==(h&Pr)&&128&d&&s.occlusionTexture&&1===s.occlusionTexCoord&&v(s.occlusionTexture),_&&v(s.emissiveTexture),f&&v(s.specGlossTexture),m&&g.push({binding:b++,resource:{buffer:s._esmShadowParamsUBO}});const C=[];for(const e of x){const t=w.find(t=>t.id===e||e.startsWith(t.id+"-"));t&&"vertex"!==t.phase&&t.bind&&!C.includes(t)&&(C.push(t),b=t.bind(y,g,b))}return c.createBindGroup({layout:t._meshBGL,entries:g})}let ds=null;function ps(){if(ds)return ds;const e=async(t,n)=>{const i=t._envTextures,r=await import("./pbr-renderable-BR-cc1W5.esm.min.js"),s=await r.buildPbrRenderables(t,n,i);return e._rebuildSingle=s.rebuildSingle,s};return e._materialFamily="pbr",ds=e}function _s(e){let t=(e.emissiveTexture?2:0)|(e.normalTexture?1:0)|(!0===e.alphaBlend||(e._alphaCutOff??0)<=0&&e.alpha<1?64:0)|(e.specGlossTexture?128:0)|(e.doubleSided?256:0);(e.occlusionStrength??1)>0&&(t|=32768),e.enableSpecularAA&&(t|=_r);let n=0;for(const i of Rr().values())if(i.detect){const r=i.detect(e);t|=r.f,n|=r.f2}return e._uv2Mask&&(n|=Pr),e.baseColorFactor&&(n|=4096),{features:t,features2:n}}function fs(e){var t;return t=e=>e._pbrFallbackTex??=function(e,t,n,i,r=1){const s=e._device,o=s.createTexture({size:{width:1,height:1},format:"rgba8unorm",usage:mt.TEXTURE_BINDING|mt.COPY_DST}),a=new ct([Math.round(255*t),Math.round(255*n),Math.round(255*i),Math.round(255*r)]);s.queue.writeTexture({texture:o},a,{bytesPerRow:4,rowsPerImage:1},{width:1,height:1});const l=Vi(e),c={texture:o,view:o.createView(),sampler:l,width:1,height:1};return e._dlr?.s(c,t,n,i,r),c}(e,1,1,1),rs=t,{...e,_buildGroup:ps(),_uboVersion:0}}function ms(e){const t=[];for(const n of[e.baseColorTexture,e.normalTexture,e.ormTexture,e.occlusionTexture,e.emissiveTexture,e.specGlossTexture])n&&t.push(n);for(const n of Rr().values())n.textures?.(e,t);return t}const gs=1<<30;const bs={id:"shadow-only",phase:"fragment",detect:e=>e._shadowOnly?{f:64,f2:gs}:{f:0,f2:0},frag:e=>e._features2&gs?function(){const e=[];for(let t=0;t<Mn;t++)e.push(`so_shadowMin = min(so_shadowMin, shadowFactors[${t}]);`);return{_id:"shadow-only",_uboFields:[{_name:"shadowOnlyColor",_type:"vec3<f32>"},{_name:"shadowOnlyOpacity",_type:"f32"},{_name:"shadowOnlyFalloff",_type:"f32"}],_fragmentSlots:{BC:`\n{\nvar so_shadowMin = 1.0;\n${e.join("\n")}\ncolor = material.shadowOnlyColor;\nalpha = saturate((1.0 - so_shadowMin) * material.shadowOnlyFalloff) * material.shadowOnlyOpacity;\n}\n`,FA:"finalAlpha = alpha * material.materialAlpha;"}}}():null,writeUbo:function(e,t,n){if(t._shadowOnly){if(n.has("shadowOnlyColor")){const i=n.get("shadowOnlyColor")/4,r=t._shadowOnlyColor??[0,0,0];e[i]=r[0],e[i+1]=r[1],e[i+2]=r[2]}n.has("shadowOnlyOpacity")&&(e[n.get("shadowOnlyOpacity")/4]=t._shadowOnlyOpacity??1),n.has("shadowOnlyFalloff")&&(e[n.get("shadowOnlyFalloff")/4]=t._shadowOnlyFalloff??1)}}};let vs=null,ys=null;function ws(e,t){(vs??=new WeakMap,vs).set(e,t),ys&&(e._preloadPending=t,ys(e,t).then(()=>{e._preloadPending===t&&(e._preloadPending=void 0)},e=>console.error(e)))}function xs(e){return vs?.get(e)}function Cs(e){ys=e}const As=(e,t)=>e.order-t.order,Ms=e=>ks(e);async function Ss(e,t=!1){await Ps(e,"pbr",t)}async function ks(e){await Ps(e,void 0,!1)}async function Ps(e,t,n){const i=e;if(!i._built&&!n)return;const r=i._lightListVersion??0,s=i.surface.engine,o=e=>{i._z?e.forEach(e=>e()):Tt(s,()=>e.forEach(e=>e()))};let a=!1,l=!1,c=!1,u=!1;try{for(let e=1;;e++){if(void 0!==t){await h();break}if(p(i),await h(),!d(i))break;if(e>=8){i._rebuildHook=Ms,u=!0,l=!0;break}}c=!0}finally{if(a&&(i._renderables.sort(As),i._renderableVersion++,i._materialEpoch++,i._built&&i._frameGraph.build()),void 0===t&&c&&!l&&(i._lightListVersion??0)===r){const e=i._pendingTopologyRetirements?.splice(0);e?.length&&o(e),u||(i._rebuildHook=void 0)}}async function h(){for(const[e,n]of i._groups){if(void 0!==t&&e._materialFamily!==t)continue;if(0===n.length){(n.o||n.r)&&(_(e,n),a=!0);continue}const r=i._runtimeBuilds;await(r?.wait(n));let s=!1;const c=async()=>{const t=[...n].filter(t=>i.meshes.includes(t)&&t.material?._buildGroup===e);if(0===t.length)return void _(e,n);const a=!!n.r,l=i._disposables.length,c=new Map,u=new Map(t.map(e=>[e,e.material]));for(const e of t){const t=i._meshDisposables.get(e);t&&(c.set(e,t),i._meshDisposables.delete(e))}let h,d;i._p=e=>(d=e,!0);try{h=await e(i,t)}catch(r){d?.[1]();for(const r of t){const t=c.get(r),s=i._meshDisposables.get(r);if(s&&s!==t)for(const e of s)e();const a=i.meshes.includes(r)&&r.material===u.get(r)&&r.material?._buildGroup===e&&n.includes(r);t&&a?i._meshDisposables.set(r,t):(i._meshDisposables.delete(r),t&&o(t))}throw r}finally{delete i._p}if(i._z||r?._d()){d?.[1]();for(const e of t){const t=i._meshDisposables.get(e),n=c.get(e);if(t&&t!==n)for(const e of t)e();i._meshDisposables.delete(e)}for(const e of i._disposables.splice(0))e();const e=[...c.values()].flat();return void o(e)}d?.[0](),e._rebuildSingle=h.rebuildSingle,n.r=i._runtimeBuilds?.base(e,h.rebuildSingle)??h.rebuildSingle,"pbr"===e._materialFamily&&h._G&&(n._w=null),a&&f(i,l);const p=new Set(t.filter(t=>i.meshes.includes(t)&&t.material===u.get(t)&&t.material?._buildGroup===e&&n.includes(t)));if(p.size!==t.length&&h.renderables.some(e=>!e.mesh)){for(const e of t){const t=i._meshDisposables.get(e),n=c.get(e);if(t&&t!==n)for(const e of t)e();n&&i.meshes.includes(e)?i._meshDisposables.set(e,n):(i._meshDisposables.delete(e),n&&o(n))}return void(s=!0)}const m=new Set;for(const e of t){if(!p.has(e)){const t=c.get(e),n=i._meshDisposables.get(e);if(n&&n!==t)for(const e of n)e();t&&i.meshes.includes(e)?(i._meshDisposables.set(e,t),c.delete(e)):i._meshDisposables.delete(e);continue}m.add(e.material),i._runtimeBuilds?.reset(e)}for(const e of m)e._csmGen=(e._csmGen??0)+1;const g=n.o,b=g?.length?new Set(g):null;for(let e=i._renderables.length-1;e>=0;e--){const t=i._renderables[e];(p.has(t.mesh)||b?.has(t))&&i._renderables.splice(e,1)}const v=h.renderables.filter(e=>!e.mesh||p.has(e.mesh));i._renderables.push(...v),n.o=v;const y=[...c.values()].flat();o(y)},{X:h}=await import("./scene-runtime-mesh-build-C-1tN3dF.esm.min.js"),d=3;for(let t=1;;t++){if(s=!1,await h(i,e,c),i._z||r?._d())return void(l=!0);if(!s)break;if(t>=d){_(e,n),i._rebuildHook=Ms,u=!0,l=!0;break}}s?a=!0:a=!0}}function d(e){for(const t of e.meshes){const n=t.material?._buildGroup;if(n&&!e._groups.get(n)?.includes(t))return!0}return!1}function p(e){const t=new Map;for(const n of e.meshes){const e=n.material?._buildGroup;if(!e)continue;const i=t.get(e);i?i.push(n):t.set(e,[n])}for(const[n,i]of e._groups){const e=t.get(n)??[];(i.length!==e.length||e.some((e,t)=>i[t]!==e))&&(i.length=0,i.push(...e)),t.delete(n)}for(const[n,i]of t){const t=i;e._groups.set(n,t)}}function _(e,t){const n=t.o;if(n?.length){const e=new Set(n);for(let t=i._renderables.length-1;t>=0;t--)e.has(i._renderables[t])&&i._renderables.splice(t,1)}t.o=void 0,t.r=void 0,i._runtimeBuilds?.dropBase(e),i._rebuildHook=Ms,u=!0}function f(e,t){const n=new Set(e._disposables.slice(0,t));for(let i=e._disposables.length-1;i>=t;i--)n.has(e._disposables[i])&&e._disposables.splice(i,1)}}var Es=Object.freeze({__proto__:null,rebuildScenePbrPipelines:Ss,rebuildSceneRenderables:ks});const Os={id:"standard",helpersWGSL:"",callWGSL:"color*=scene.vImageInfos.x;\ncolor=1.0-exp2(-1.590579*color);"};const Ts={id:"aces",helpersWGSL:"\nconst ACESInputMat = mat3x3<f32>(vec3<f32>(0.59719,0.07600,0.02840),vec3<f32>(0.35458,0.90834,0.13383),vec3<f32>(0.04823,0.01566,0.83777));\nconst ACESOutputMat = mat3x3<f32>(vec3<f32>(1.60475,-0.10208,-0.00327),vec3<f32>(-0.53108,1.10813,-0.07276),vec3<f32>(-0.07367,-0.00605,1.07602));\nfn RRTAndODTFit(v: vec3<f32>) -> vec3<f32> { let a = v*(v+0.0245786)-0.000090537; let b = v*(0.983729*v+0.4329510)+0.238081; return a/b; }\nfn ACESFitted(color: vec3<f32>) -> vec3<f32> { var c = ACESInputMat*color; c = RRTAndODTFit(c); c = ACESOutputMat*c; return saturate(c); }\n",callWGSL:"color *= scene.vImageInfos.x;\ncolor = ACESFitted(color);"},Bs={id:"neutral",helpersWGSL:"\nconst PBRNeutralStartCompression: f32 = 0.8 - 0.04;\nconst PBRNeutralDesaturation: f32 = 0.15;\nfn PBRNeutralToneMapping(color: vec3<f32>) -> vec3<f32> {\n    let x = min(color.r, min(color.g, color.b));\n    let offset = select(0.04, x - 6.25 * x * x, x < 0.08);\n    var result = color - offset;\n    let peak = max(result.r, max(result.g, result.b));\n    if (peak < PBRNeutralStartCompression) { return result; }\n    let d = 1.0 - PBRNeutralStartCompression;\n    let newPeak = 1.0 - d * d / (peak + d - PBRNeutralStartCompression);\n    result *= newPeak / peak;\n    let g = 1.0 - 1.0 / (PBRNeutralDesaturation * (peak - newPeak) + 1.0);\n    return mix(result, newPeak * vec3<f32>(1.0, 1.0, 1.0), g);\n}\n",callWGSL:"color *= scene.vImageInfos.x;\ncolor = PBRNeutralToneMapping(color);"};function Ls(e){return e[0]*(e[5]*e[10]-e[6]*e[9])+e[1]*(e[6]*e[8]-e[4]*e[10])+e[2]*(e[4]*e[9]-e[5]*e[8])}function Is(e,t=0,n=0,i=0,r=0,s=0,o=0,a=1,l=1,c=1,u=1){return function(e,t=0,n=0,i=0,r=0,s=0,o=0,a=1,l=1,c=1,u=1){return Gr(e,null,t,n,i,r,s,o,a,l,c,u)}(e,t,n,i,r,s,o,a,l,c,u)}let Rs=null,$s=null;function Ns(){return $s??=ft()}const Vs={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16};function Fs(e,t,n){const i=e.accessors[n],r=Vs[i.type]??1,s=i.count,o=s*r;let a;switch(i.componentType){case 5126:a=it;break;case 5123:a=at;break;case 5125:a=st;break;case 5121:a=ct;break;case 5122:a=lt;break;case 5120:a=ut;break;default:nt(108,i.componentType)}return{_data:void 0===i.bufferView?new a(o):new a(t.buffer,t.byteOffset+(e.bufferViews[i.bufferView].byteOffset??0)+(i.byteOffset??0),o),_count:s,_componentCount:r}}function zs(e){return e.extensions?.EXT_texture_webp?.source??e.source}function Ds(e,t){for(const n of e.meshes??[])for(const e of n.primitives??[])if(t(e))return!0;return!1}function Gs(e){const t=e.materials??[],n=e.textures??[];for(const e of t){const t=e.pbrMetallicRoughness?.metallicRoughnessTexture,i=e.occlusionTexture;if(t&&i&&n[t.index]&&n[i.index]&&zs(n[t.index])!==zs(n[i.index]))return!0}return!1}const Us=new it([-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function js(e,t){return e.get(t)??-1}function Ws(e,t,n,i){const r=i.get(t);if(r)return r;const s=e.nodes[t],o=js(n,t),a=-1!==o?Ws(e,o,n,i):Us;let l;if(s.matrix)l=new it(s.matrix);else{const e=s.translation??[0,0,0],t=s.rotation??[0,0,0,1],n=s.scale??[1,1,1],i=Rs??=ft();Kn(i,0,e[0],e[1],e[2],t[0],t[1],t[2],t[3],n[0],n[1],n[2]),l=i}const c=new it(16);return ln(c,0,a,0,l,0),i.set(t,c),c}async function Hs(e,t,n,i,r){const s=e.materials?.[n],o=s??{},a=o.pbrMetallicRoughness??{},l=qs(e,t,i,r),[c,u,h,d,p]=await Promise.all([l(a.baseColorTexture),l(a.metallicRoughnessTexture),l(o.normalTexture),l(o.occlusionTexture),l(o.emissiveTexture)]);return{_baseColorFactor:a.baseColorFactor??[1,1,1,1],_metallicFactor:a.metallicFactor??1,_roughnessFactor:a.roughnessFactor??1,_emissiveFactor:o.emissiveFactor??[0,0,0],_baseColorImage:c,_metallicRoughnessImage:u,_normalImage:h,_normalScale:"number"==typeof o.normalTexture?.scale?o.normalTexture.scale:1,_occlusionTexCoord:"number"==typeof o.occlusionTexture?.texCoord?o.occlusionTexture.texCoord:0,_occlusionImage:d,_emissiveImage:p,_doubleSided:!!o.doubleSided,_alphaMode:o.alphaMode??"OPAQUE",_alphaCutoff:o.alphaCutoff??.5,_rawMatDef:s}}function qs(e,t,n,i){return r=>{if(!r)return Promise.resolve(null);const s=zs(e.textures[r.index]);return i[s]??=async function(e,t,n,i){const r=e.images[n];if(void 0!==r.bufferView){const n=e.bufferViews[r.bufferView],i=t.byteOffset+(n.byteOffset??0),s=t.buffer.slice(i,i+n.byteLength),o=new Blob([s],{type:r.mimeType??"image/png"});return createImageBitmap(o,{premultiplyAlpha:"none",colorSpaceConversion:"none"})}if(r.uri)return(await import("./gltf-json-asset-LWoWNTG-.esm.min.js")).resolveExternalImage(r.uri,i);nt(109)}(e,t,s,n)}}function Xs(e){const t=Math.max(0,Math.min(1,e));return Math.round(255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055))}const Ys=e=>e;function Qs(e,t,n,i,r,s){const o=e._device,a=t?.width??1,l=t?.height??1,c=n?"rgba8unorm-srgb":"rgba8unorm",u=t?zi(a,l):1,h=o.createTexture({size:{width:a,height:l},format:c,usage:mt.TEXTURE_BINDING|mt.COPY_DST|mt.COPY_SRC|mt.RENDER_ATTACHMENT,mipLevelCount:u});t?(o.queue.copyExternalImageToTexture({source:t},{texture:h,premultipliedAlpha:!1},{width:a,height:l}),r(e,h)):o.queue.writeTexture({texture:h},s??new ct([255,255,255,255]),{bytesPerRow:4},{width:1,height:1});const d={texture:h,view:h.createView(),sampler:i,width:a,height:l};return e._dlr?.b(d,t,n,!!t,s),d}function Zs(e,t,n,i){return Qs(e,null,!0,n,i,new ct([Xs(t[0]),Xs(t[1]),Xs(t[2]),Math.round(255*Math.max(0,Math.min(1,t[3])))]))}function Ks(e,t,n,i,r){const s=e=>Math.round(255*Math.max(0,Math.min(1,e)));return Qs(e,null,!1,i,r,new ct([255,s(t),s(n),255]))}async function Js(e,t){if(!e._emissiveColor&&function(e,t){const n=e._emissiveFactor;return!(0===n[0]&&0===n[1]&&0===n[2]||t&&1===n[0]&&1===n[1]&&1===n[2])}(t,e.emissiveTexture)){const{setPbrEmissive:n}=await import("./set-emissive-ETRtw7CD.esm.min.js"),i=t._emissiveFactor;n(e,[i[0],i[1],i[2]])}if("MASK"===t._alphaMode){const{setPbrAlphaCutoff:n}=await import("./set-alpha-cutoff-CwLLdn4_.esm.min.js");n(e,t._alphaCutoff)}}function eo(e){return 1===e[0]&&1===e[1]&&1===e[2]&&1===e[3]}let to,no,io;function ro(){return to??=import("./gltf-interleave-Dk166jq6.esm.min.js")}function so(){return io??=import("./gltf-color-normalize-Bgbsj4Ls.esm.min.js")}function oo(e,t,n,i,r){const[s,o]=Wr(t._positions),a=t._indices,l=a instanceof st,c=r?r._gpu:{positionBuffer:Cn(e,t._positions,gt.VERTEX),normalBuffer:Cn(e,t._normals,gt.VERTEX),tangentBuffer:t._tangents?Cn(e,t._tangents,gt.VERTEX):null,uvBuffer:Cn(e,t._uvs,gt.VERTEX),uv2Buffer:t._uv2s?Cn(e,t._uv2s,gt.VERTEX):null,colorBuffer:t._colors?Cn(e,t._colors,gt.VERTEX):null,indexBuffer:Cn(e,a,gt.INDEX),indexCount:t._indexCount,indexFormat:l?"uint32":"uint16"},u=Ur({name:i,material:n,receiveShadows:!1,boundMin:s,boundMax:o,_gpu:c,_flatNormal:t._flatNormal});return u._cpuPositions=t._positions,u._cpuNormals=t._normals,u._cpuUvs=t._uvs,u._cpuIndices=r?r._cpuIndices:l?a:new st(a),e._dlr?.m(u,t._uv2s,t._tangents,t._colors,a,c.indexFormat),u}async function ao(e,t){const{json:n,binChunk:i,baseUrl:r}=await async function(e){const t="string"==typeof e;let n="";if(t)try{n=new URL(".",new URL(e,globalThis.location?.href))+""}catch{}const i=t?await(await fetch(e)).arrayBuffer():e instanceof Blob?await e.arrayBuffer():e;if(i.byteLength>=4&&1179937895===new dt(i).getUint32(0,!0)){return{...(await import("./gltf-glb-parser-jc5R5M6S.esm.min.js")).parseGlbContainer(i),baseUrl:n}}return(await import("./gltf-json-asset-LWoWNTG-.esm.min.js")).parseGltfJsonAsset(i,n)}(t),s=function(e){const t=new Map,n=e.nodes??[];for(let e=0;e<n.length;e++){const i=n[e].children;if(i)for(const n of i)t.set(n,e)}return t}(n),o=new Map,a=function(e){return e.extensionsUsed?.length||e.animations?.length||/extras|sparse/.test(JSON.stringify(e))||e.skins?.length&&Ds(e,e=>void 0!==e.attributes?.JOINTS_0)||Ds(e,e=>!!e.targets?.length)||e.nodes?.some(e=>e.scale?e.scale[0]*e.scale[1]*e.scale[2]<0:!!e.matrix&&Ls(e.matrix)<0)||Ds(e,e=>void 0!==e.mode&&4!==e.mode)||Gs(e)}(n)?await(no??=import("./gltf-feature-registry-CosAHUNk.esm.min.js")):void 0,l=a?await a.loadGltfFeatures(n):[];let c=i;for(const e of l)if(e.preParse){const t=await e.preParse(n,c);t&&(c=t)}const u=l.filter(e=>e.applyMaterial),h=l.filter(e=>e.wrapTexture).map(e=>e.wrapTexture),d=h.length?(e,t)=>h.reduce((e,n)=>n(e,t),e):Ys,p=new Map;for(const e of await Promise.all(l.flatMap(e=>e.preMesh?[e.preMesh(n,c,r)]:[])))for(const[t,n]of e)p.set(t,n);const _=await async function(e,t,n,i,r,s){const o=[],a=[],l=i=>{const r=(i??-1)+1;return a[r]??=Hs(e,t,r-1,n,o)},c=[],u=[],h=e.accessors,d=e.bufferViews,p=e=>{for(const t in e.attributes){const n=h[e.attributes[t]],i=d?.[n?.bufferView]?.byteStride;if(void 0!==i&&i!==(Vs[n.type]??1)*(5126===n.componentType||5125===n.componentType?4:5123===n.componentType||5122===n.componentType?2:1))return!0}return!1};for(let n=0;n<e.nodes.length;n++){const o=e.nodes[n];if(void 0===o.mesh)continue;const a=o.mesh,h=e.meshes[a],d=Ws(e,n,i,r);for(let i=0;i<h.primitives.length;i++){const r=h.primitives[i],o=r.attributes,a=s.get(r);if(!a&&p(r)){const i=await(await ro()).buildInterleavedPartial(e,t,r,d,n);if(i){u.push(l(r.material)),c.push(i);continue}}const _=n=>{if(a&&a._attributes.has(n)){const e=a._attributes.get(n),t=e.length/a._vertexCount;return{_data:e,_count:a._vertexCount,_componentCount:t}}const i=o[n];return void 0!==i?Fs(e,t,i):null},f=_("POSITION"),m=_("NORMAL"),g=_("TEXCOORD_0"),b=_("TEXCOORD_1"),v=_("TANGENT"),y=_("COLOR_0"),w=a?a._indexCount>0?{_data:a._indices,_count:a._indexCount}:null:void 0!==r.indices?Fs(e,t,r.indices):null,x=w&&m?null:await import("./gltf-normals-BSzLZia6.esm.min.js"),C=y?(await so()).normalizeColorToVec4(y._data,y._count,y._componentCount):null,A=g?g._data instanceof it?g._data:(await so()).normalizeUvToVec2(g._data,g._count):new it(2*f._count),M=b?b._data instanceof it?b._data:(await so()).normalizeUvToVec2(b._data,b._count):null,S=w?w._data instanceof st?new st(w._data):w._data instanceof ct?Uint16Array.from(w._data):new at(w._data.buffer,w._data.byteOffset,w._count):x.createSequentialIndices(f._count);u.push(l(r.material));const k=m?m._data:x.computeSmoothNormals(f._data,S,f._count);c.push({_positions:f._data,_normals:k,_tangents:v?v._data:null,_uvs:A,_uv2s:M,_colors:C,_flatNormal:!m,_indices:S,_vertexCount:f._count,_indexCount:S.length,_worldMatrix:d,_nodeIndex:n,_primitive:r,_decoded:a})}}const _=await Promise.all(u);return c.map((e,t)=>({...e,_material:_[t]}))}(n,c,r,s,o,p),f={_engine:e,_json:n,_binChunk:c,_baseUrl:r,_parentMap:s,_worldMatrixCache:o,_matExts:u,_runMatExts:a?.runGltfMaterialFeatures,_wrapTex:d},m=await async function(e,t,n){const{_engine:i,_json:r,_binChunk:s,_baseUrl:o,_matExts:a,_wrapTex:l}=n,c=Ii(i,{magFilter:"linear",minFilter:"linear",mipmapFilter:"linear",addressModeU:"repeat",addressModeV:"repeat",maxAnisotropy:4});let u,h;if(r.samplers?.some(e=>e.wrapS>10497||e.wrapT>10497||9728===e.magFilter||null!=e.minFilter&&9729!==e.minFilter&&9987!==e.minFilter)){const e=await import("./gltf-sampler-desc-DUv0FNS4.esm.min.js");u=e.makeSamplerFor(i,r,c),h=e.buildSampledPbrTextures}await async function(){lo||(lo=(await import("./generate-mipmaps-Cs76X4rW.esm.min.js")).generateMipmaps)}();const d=t.filter(e=>e.applyMesh),p=new Map,_=(e,t)=>{let n=p.get(e);n||p.set(e,n=[]);const r=+t;let s=n[r];return s||(s=Qs(i,e,t,c,lo),n[r]=s),s},f=a.length?[]:null,m=f?qs(r,s,o,f):null,g={_engine:i,async _texture(e,t){if(!e||!m)return;const n=await m(e);return n?l(_(n,t),e):void 0},_uploadImage:(e,t)=>Qs(i,e,t,c,lo)};let b=l!==Ys;if(!b){const e=r.materials;e&&JSON.stringify(e).includes('"texCoord":1')&&(b=!0)}let v=null;const y=()=>v??=import("./gltf-pbr-builder-ext-CGEH1DFB.esm.min.js"),w=new Map,x=e=>{let t=w.get(e);return t||(t=(async()=>{const t=a.length?await n._runMatExts(e,a,g):void 0;let r;if(b){const n=await y(),s=n.buildDefaultPbrTexturesExt(i,e,c,lo,_,l,u);r=n.assemblePbrPropsExt(e,s,t),await n.applyGltfUvTransform(r,s)}else{const n=h?h(i,e,c,lo,u,_):function(e,t,n,i,r){const s=t._baseColorImage?r(t._baseColorImage,!0):Zs(e,t._baseColorFactor,n,i),o=t._normalImage?r(t._normalImage,!1):void 0,a=t._emissiveImage?r(t._emissiveImage,!0):void 0,l=t._metallicRoughnessImage??t._occlusionImage;let c;return c=!l||t._metallicRoughnessImage&&t._occlusionImage&&t._metallicRoughnessImage!==t._occlusionImage?l?r(t._metallicRoughnessImage,!1):Ks(e,t._roughnessFactor,t._metallicFactor,n,i):r(l,!1),{baseColorTexture:s,ormTexture:c,normalTexture:o,emissiveTexture:a}}(i,e,c,lo,_);r=function(e,t,n,i,r,s){return{baseColorTexture:t,normalTexture:i,ormTexture:n,emissiveTexture:r,...e._baseColorImage&&!eo(e._baseColorFactor)?{baseColorFactor:e._baseColorFactor}:void 0,doubleSided:e._doubleSided,occlusionStrength:e._occlusionImage?1:0,...1!==e._normalScale?{normalTextureScale:e._normalScale}:void 0,...e._metallicRoughnessImage?{metallicFactor:e._metallicFactor,roughnessFactor:e._roughnessFactor}:void 0,enableSpecularAA:!0,..."BLEND"===e._alphaMode?{alphaBlend:!0,alpha:e._baseColorFactor[3]}:void 0,..."MASK"===e._alphaMode?{alpha:e._baseColorFactor[3]}:void 0,...e._rawMatDef?.name?{name:e._rawMatDef.name}:void 0,...s,_buildGroup:ps(),_uboVersion:0}}(e,n.baseColorTexture,n.ormTexture,n.normalTexture,n.emissiveTexture,t)}return await Js(r,e),r})(),w.set(e,t)),t};if(new Set(e.map(e=>e._primitive)).size<e.length)return import("./gltf-share-CnlRTXpm.esm.min.js").then(t=>t.share(e,x,oo,d,n));return Promise.all(e.map(async(e,t)=>{const s=await x(e._material),o=r.meshes[r.nodes[e._nodeIndex].mesh].name||`gltf_mesh_${t}`,a=e._vb?(await ro()).buildInterleavedMesh(i,e,t,s,o):oo(i,e,s,o);return a._authoredSign=-1,await Promise.all(d.map(t=>t.applyMesh(e,a,n))),a}))}(_,l,f),{root:g,nodeMap:b}=function(e,t,n){const i=[];for(let e=0;e<n.length;e++){const r=n[e]._nodeIndex;(i[r]??=[]).push(t[e])}const r=new Array(e.nodes?.length??0);function s(t){const n=e.nodes[t],o=n.name??`node_${t}`;let a;if(n.matrix)a=function(e,t){return Gr(e,t)}(o,n.matrix);else{const e=n.translation??[0,0,0],t=n.rotation??[0,0,0,1],i=n.scale??[1,1,1];a=Is(o,e[0],e[1],e[2],t[0],t[1],t[2],t[3],i[0],i[1],i[2])}if(r[t]=a,n.children)for(const e of n.children)a.children.push(s(e));const l=i[t]??[];return a.children.push(...l),a}const o=e.scenes?.[e.scene??0]?.nodes??[],a=o.map(e=>s(e)),l=Is("__root__",0,0,0,0,0,0,1,-1,1,1);return l.children.push(...a),{root:l,nodeMap:r}}(n,m,_);f._nodeMap=b;const v=await Promise.all(l.flatMap(e=>e.applyAsset?[e.applyAsset(m,g,f)]:[])),y={entities:[g]};for(const e of v){e.entities?.length&&y.entities.push(...e.entities);const{entities:t,_sceneSetup:n,...i}=e;if(Object.assign(y,i),n){const e=y._sceneSetup;y._sceneSetup=(t,i)=>{e?.(t,i),n(t,i)}}}return y}let lo=null;function co(e){const t=[],n=new Set,i=e=>{if(n.has(e))return;n.add(e),e._gpu&&t.push(e);const r=e.children;if(r)for(const e of r)i(e)};for(const t of e.entities)"lightType"in t||i(t);return t}function uo(e){const t=e.materialVariants;if(t)for(const e of t.originals)e.mesh.material=e.material}const ho=new ct([134,22,135,150,246,214,150,54]);function po(e){const t=new ct(e);for(let e=0;e<8;e++)if(t[e]!==ho[e])throw new Error("Invalid .env file: bad magic");let n=8;for(;n<t.length&&0!==t[n];)n++;const i=(new TextDecoder).decode(t.subarray(8,n));n++;const r=n,s=JSON.parse(i),o=s.width,a=zi(o,o),l=s.irradiance,c=new it(27),u=["x","y","z","xx","yy","zz","yz","zx","xy"];for(let e=0;e<9;e++){const t=l[u[e]];c[3*e]=t[0],c[3*e+1]=t[1],c[3*e+2]=t[2]}const h=s.specular.mipmaps,d=s.imageType||"image/png",p=[];for(const t of h){const n=r+t.position,i=e.slice(n,n+t.length);p.push(new Blob([i],{type:d}))}return{faceBlobs:p,irradianceSH:c,width:o,mipCount:a}}function _o(e,t){const n={minX:1/0,minY:1/0,minZ:1/0,maxX:-1/0,maxY:-1/0,maxZ:-1/0};for(const t of e.meshes)ai(n,t);const i=n.minX,r=n.minY,s=n.minZ,o=n.maxX,a=n.maxY,l=n.maxZ;if(!isFinite(i))return{groundSize:15,skyboxSize:t,rootPosition:[0,0,0]};const c=o-i,u=a-r,h=l-s,d=Math.sqrt(c*c+u*u+h*h);let p=15,_=t;const f=e.camera;f&&"upperRadiusLimit"in f&&f.upperRadiusLimit&&(p=2*f.upperRadiusLimit,_=p),d>p&&(p=2*d,_=p),p*=1.1,_*=1.5;return{groundSize:p,skyboxSize:_,rootPosition:[i+.5*c,r-1e-5,s+.5*h]}}var fo=Object.freeze({__proto__:null,computeSceneSize:_o});async function mo(e){const t=await fetch(e);if(t.ok)try{return await createImageBitmap(await t.blob(),{premultiplyAlpha:"none",colorSpaceConversion:"none"})}catch{}throw new Error(`BRDF LUT '${e}' is not an image (${t.status} ${t.headers.get("content-type")??""}).`)}function go(e,t,n,i,r,s){return{specularCube:e,specularCubeView:e.createView({dimension:"cube"}),brdfLut:t,brdfLutView:t.createView(),cubeSampler:Fi(r),brdfSampler:Vi(r),irradianceSH:n,sphericalHarmonics:s??bo(n),lodGenerationScale:i}}function bo(e){const t=1.4999984284682104,n=3.999982863580422,i=new it(36);for(let r=0;r<3;r++){const s=e[r],o=e[3+r],a=e[6+r],l=e[9+r],c=e[12+r],u=e[15+r],h=e[18+r],d=e[21+r],p=e[24+r];i[r]=.3333338747897695*(l+c)+.33333298856284405*u,i[4+r]=o*t,i[8+r]=a*t,i[12+r]=s*t,i[16+r]=p*n,i[20+r]=h*n,i[24+r]=1.3333326611423701*u-.6666653397393608*(l+c),i[28+r]=d*n,i[32+r]=1.999991431790211*(l-c)}return i}function vo(e){const t=new ct(e);let n=0;function i(){let e="";for(;n<t.length;){const i=t[n++];if(10===i)break;13!==i&&(e+=String.fromCharCode(i))}return e}i().startsWith("#?")||nt(112);let r="";for(;n<t.length;){const e=i();if(""===e)break;e.startsWith("FORMAT=")&&(r=e.slice(7))}r&&"32-bit_rle_rgbe"!==r&&nt(113,r);const s=i(),o=s.match(/-Y\s+(\d+)\s+\+X\s+(\d+)/);o||nt(114,s);const a=parseInt(o[1],10),l=parseInt(o[2],10),c=new it(l*a*3),u=new ct(4*l);for(let e=0;e<a;e++)n=yo(t,n,l,c,e*l*3,u);return{width:l,height:a,data:c}}function yo(e,t,n,i,r,s){if(n>=8&&n<=32767&&2===e[t]&&2===e[t+1]&&e[t+2]===(n>>8&255)&&e[t+3]===(255&n)){t+=4;for(let i=0;i<4;i++){let r=i,o=0;for(;o<n;){const n=e[t++];if(n>128){const i=n-128,a=e[t++];for(let e=0;e<i;e++)s[r]=a,r+=4;o+=i}else{for(let i=0;i<n;i++)s[r]=e[t++],r+=4;o+=n}}}for(let e=0;e<n;e++)wo(s[4*e],s[4*e+1],s[4*e+2],s[4*e+3],i,r+3*e)}else for(let s=0;s<n;s++)wo(e[t],e[t+1],e[t+2],e[t+3],i,r+3*s),t+=4;return t}function wo(e,t,n,i,r,s){if(0===i)r[s]=r[s+1]=r[s+2]=0;else{const o=Math.pow(2,i-136);r[s]=e*o,r[s+1]=t*o,r[s+2]=n*o}}function xo(e,t,n){const i=.48860251190292,r=1.092548430592079,s=new rt(27);let o=0;for(let a=0;a<n;a++){const l=(a+.5)/n*Math.PI,c=Math.sin(l),u=Math.cos(l),h=c*(Math.PI/n)*(2*Math.PI/t);for(let n=0;n<t;n++){const l=(2*(n+.5)/t-1)*Math.PI,d=c*Math.sin(l),p=u,_=c*Math.cos(l),f=3*(a*t+n);let m=e[f],g=e[f+1],b=e[f+2];const v=Math.max(m,g,b);if(v>4096){const e=4096/v;m*=e,g*=e,b*=e}const y=h;o+=y;const w=[.282094791773878,i*p,i*_,i*d,r*d*p,r*p*_,.31539156525252*(3*_*_-1),r*d*_,.54627421529604*(d*d-p*p)];for(let e=0;e<9;e++){const t=w[e]*y;s[e]=s[e]+m*t,s[9+e]=s[9+e]+g*t,s[18+e]=s[18+e]+b*t}}}const a=4*Math.PI/o;for(let e=0;e<27;e++)s[e]=s[e]*a;const l=[1,2/3,2/3,2/3,.25,.25,.25,.25,.25];for(let e=0;e<3;e++)for(let t=0;t<9;t++)s[9*e+t]=s[9*e+t]*l[t];return function(e){const t=1/Math.PI,n=new it(27);for(let i=0;i<3;i++){const r=9*i,s=e[r],o=e[r+1],a=e[r+2],l=e[r+3],c=e[r+4],u=e[r+5],h=e[r+6],d=e[r+7],p=e[r+8];n[0+i]=1.02333*l*t,n[3+i]=1.02333*o*t,n[6+i]=1.02333*a*t,n[9+i]=(.886227*s-.247708*h+.429043*p)*t,n[12+i]=(.886227*s-.247708*h-.429043*p)*t,n[15+i]=(.886227*s+.495417*h)*t,n[18+i]=.858086*u*t,n[21+i]=.858086*d*t,n[24+i]=.858086*c*t}return n}(s)}var Co=Object.freeze({__proto__:null,computeSHFromEquirect:xo,parseRGBE:vo});const Ao="@group(0) @binding(0) var z:texture_storage_2d<rgba16float,write>;fn x(G:u32)->f32{var a=G;a=(a<<16u)|(a>>16u);a=((a&0x55555555u)<<1u)|((a&0xAAAAAAAAu)>>1u);a=((a&0x33333333u)<<2u)|((a&0xCCCCCCCCu)>>2u);a=((a&0x0F0F0F0Fu)<<4u)|((a&0xF0F0F0F0u)>>4u);a=((a&0x00FF00FFu)<<8u)|((a&0xFF00FF00u)>>8u);return f32(a)*2.3283064365386963e-10;}fn w(B:f32,u:f32,J:f32)->vec3f{let t=2.0*3.14159265359*B;let k=sqrt((1.0-u)/(1.0+(J-1.0)*u));let q=sqrt(1.0-k*k);return vec3f(cos(t)*q,sin(t)*q,k);}fn y(b:f32,n:f32)->vec2f{let o=vec3f(sqrt(1.0-b*b),0.0,b);let p=n*n;let e=p*p;var r=0.0;var l=0.0;let g=1024u;for(var f=0u;f<g;f++){let F=f32(f)/f32(g);let E=x(f);let j=w(F,E,e);let i=max(dot(o,j),0.0);let A=2.0*i*j-o;let d=max(A.z,0.0);let s=max(j.z,0.0);if (d>0.0&&s>0.0){let C=d*sqrt(b*b*(1.0-e)+e);let D=b*sqrt(d*d*(1.0-e)+e);let v=(0.5/max(C+D,1e-6))*d*(4.0*i/s);let m=pow(1.0-i,5.0);r+=(1.0-m)*v;l+=m*v;}}return vec2f(r/f32(g),l/f32(g));}@compute @workgroup_size(8,8) fn main(@builtin(global_invocation_id) c:vec3u){if (c.x>=256u||c.y>=256u){return;}let H=max((f32(c.x)+0.5)/256.0,0.001);let I=max((f32(c.y)+0.5)/256.0,0.04);let h=y(H,I);textureStore(z,vec2u(c.x,c.y),vec4f(h.y,h.x+h.y,0.0,1.0));}";function Mo(e,t,n){const i=e._device,r=i.createTexture({size:[t.width,t.height],format:"rgba32float",usage:mt.TEXTURE_BINDING|mt.COPY_DST});{const e=new it(t.width*t.height*4);for(let n=0;n<t.width*t.height;n++)e[4*n]=t.data[3*n],e[4*n+1]=t.data[3*n+1],e[4*n+2]=t.data[3*n+2],e[4*n+3]=1;i.queue.writeTexture({texture:r},e.buffer,{bytesPerRow:16*t.width},{width:t.width,height:t.height})}const s=i.createTexture({size:[n,n,6],format:"rgba16float",usage:mt.TEXTURE_BINDING|mt.STORAGE_BINDING|mt.COPY_SRC,dimension:"2d"}),o=i.createShaderModule({code:"struct t{faceSize:u32,equirectWidth:u32,equirectHeight:u32,_pad:u32}@group(0) @binding(0) var p:texture_2d<f32>;@group(0) @binding(1) var k:texture_storage_2d_array<rgba16float,write>;@group(0) @binding(2) var<uniform> params:t;const i=3.14159265359;const d=array<vec3<f32>,24>(vec3(1.0,-1.0,1.0),vec3(-1.0,-1.0,1.0),vec3(1.0,1.0,1.0),vec3(-1.0,1.0,1.0),vec3(-1.0,-1.0,-1.0),vec3(1.0,-1.0,-1.0),vec3(-1.0,1.0,-1.0),vec3(1.0,1.0,-1.0),vec3(-1.0,-1.0,-1.0),vec3(-1.0,-1.0,1.0),vec3(1.0,-1.0,-1.0),vec3(1.0,-1.0,1.0),vec3(1.0,1.0,-1.0),vec3(1.0,1.0,1.0),vec3(-1.0,1.0,-1.0),vec3(-1.0,1.0,1.0),vec3(1.0,-1.0,-1.0),vec3(1.0,-1.0,1.0),vec3(1.0,1.0,-1.0),vec3(1.0,1.0,1.0),vec3(-1.0,-1.0,1.0),vec3(-1.0,-1.0,-1.0),vec3(-1.0,1.0,1.0),vec3(-1.0,1.0,-1.0));@compute @workgroup_size(8,8,1) fn main(@builtin(global_invocation_id) a:vec3u){let h=a.z;let c=params.faceSize;if (a.x>=c||a.y>=c||h>=6u){return;}let f=f32(a.x)/f32(c);let e=f32(a.y)/f32(c);let b=h*4u;let g=normalize(d[b]*(1.0-f)*(1.0-e)+d[b+1u]*f*(1.0-e)+d[b+2u]*(1.0-f)*e+d[b+3u]*f*e);let l=atan2(g.z,g.x);let m=acos(clamp(g.y,-1.0,1.0));let n=l/i*0.5+0.5;let o=m/i;let j=clamp(i32(round(n*f32(params.equirectWidth))),0,i32(params.equirectWidth)-1);let q=clamp(i32(round(o*f32(params.equirectHeight))),0,i32(params.equirectHeight)-1);let r=i32(params.equirectHeight)-q-1;let s=textureLoad(p,vec2<i32>(j,r),0);textureStore(k,vec2<i32>(a.xy),i32(h),vec4<f32>(s.rgb,1.0));}"}),a=i.createComputePipeline({layout:"auto",compute:{module:o,entryPoint:"main"}}),l=wn(e,new st([n,t.width,t.height,0])),c=i.createBindGroup({layout:a.getBindGroupLayout(0),entries:[{binding:0,resource:r.createView()},{binding:1,resource:s.createView({dimension:"2d-array",arrayLayerCount:6})},{binding:2,resource:{buffer:l}}]}),u=i.createCommandEncoder(),h=u.beginComputePass();return h.setPipeline(a),h.setBindGroup(0,c),h.dispatchWorkgroups(Math.ceil(n/8),Math.ceil(n/8),6),h.end(),i.queue.submit([u.finish()]),r.destroy(),l.destroy(),s}function So(e,t,n,i){const r=e._device,s=r.createTexture({size:{width:n,height:n,depthOrArrayLayers:6},mipLevelCount:i,format:"rgba16float",usage:mt.TEXTURE_BINDING|mt.STORAGE_BINDING|mt.COPY_DST}),o=t.createView({dimension:"cube"}),a=Vi(e),l=r.createComputePipeline({layout:"auto",compute:{module:r.createShaderModule({code:"struct ha{faceSize:u32,mipLevel:u32,totalMips:u32,srcSize:u32}@group(0) @binding(0) var x:texture_cube<f32>;@group(0) @binding(1) var F:sampler;@group(0) @binding(2) var z:texture_storage_2d_array<rgba16float,write>;@group(0) @binding(3) var<uniform> params:ha;const k=3.14159265359;const n=1024u;const g=array<vec3<f32>,24>(vec3(1.0,-1.0,1.0),vec3(-1.0,-1.0,1.0),vec3(1.0,1.0,1.0),vec3(-1.0,1.0,1.0),vec3(-1.0,-1.0,-1.0),vec3(1.0,-1.0,-1.0),vec3(-1.0,1.0,-1.0),vec3(1.0,1.0,-1.0),vec3(-1.0,-1.0,-1.0),vec3(-1.0,-1.0,1.0),vec3(1.0,-1.0,-1.0),vec3(1.0,-1.0,1.0),vec3(1.0,1.0,-1.0),vec3(1.0,1.0,1.0),vec3(-1.0,1.0,-1.0),vec3(-1.0,1.0,1.0),vec3(1.0,-1.0,-1.0),vec3(1.0,-1.0,1.0),vec3(1.0,1.0,-1.0),vec3(1.0,1.0,1.0),vec3(-1.0,-1.0,1.0),vec3(-1.0,-1.0,-1.0),vec3(-1.0,1.0,1.0),vec3(-1.0,1.0,-1.0));fn I(ca:u32,j:f32,d:f32)->vec3<f32>{let i=ca*4u;return normalize(g[i]*(1.0-j)*(1.0-d)+g[i+1u]*j*(1.0-d)+g[i+2u]*(1.0-j)*d+g[i+3u]*j*d);}fn J(ba:u32)->f32{var a=ba;a=(a<<16u)|(a>>16u);a=((a&0x55555555u)<<1u)|((a&0xAAAAAAAAu)>>1u);a=((a&0x33333333u)<<2u)|((a&0xCCCCCCCCu)>>2u);a=((a&0x0F0F0F0Fu)<<4u)|((a&0xF0F0F0F0u)>>4u);a=((a&0x00FF00FFu)<<8u)|((a&0xFF00FF00u)>>8u);return f32(a)*2.3283064365386963e-10;}fn K(aa:f32,C:f32,s:f32)->vec3<f32>{let Z=s*s;let u=2.0*k*aa;let o=sqrt((1.0-C)/(1.0+(Z-1.0)*C));let w=sqrt(1.0-o*o);return vec3<f32>(cos(u)*w,sin(u)*w,o);}fn L(y:f32,t:f32)->f32{let A=y*y*(t-1.0)+1.0;return t/(k*A*A);}fn H(Y:u32,M:f32,S:f32)->vec3<f32>{return I(Y,M,S);}@compute @workgroup_size(8,8,1) fn main(@builtin(global_invocation_id) c:vec3u){let f=c.z;let h=params.faceSize>>params.mipLevel;if (c.x>=h||c.y>=h||f>=6u){return;}let R=f32(c.x)/f32(h);let Q=f32(c.y)/f32(h);let b=normalize(H(f,R,Q));let q=pow(2.0,f32(params.mipLevel)/0.8)/f32(params.srcSize);if (params.mipLevel==0u){let O=textureSampleLevel(x,F,b,0.0);textureStore(z,vec2<i32>(c.xy),i32(f),vec4<f32>(O.rgb,1.0));return;}var X=select(vec3<f32>(1.0,0.0,0.0),vec3<f32>(0.0,0.0,1.0),abs(b.z)<0.999);let v=normalize(cross(X,b));let P=cross(b,v);var p=vec3<f32>(0.0);var m=0.0;let E=f32(params.srcSize);let T=4.0*k/(6.0*E*E);let U=f32(params.totalMips)-1.0;for(var e=0u;e<n;e++){let W=f32(e)/f32(n);let N=J(e);let r=K(W,N,q);let B=v*r.x+P*r.y+b*r.z;let D=max(dot(b,B),0.0);let G=2.0*D*B-b;let l=dot(b,G);if (l>0.0){let da=q*q;let ea=L(D,da)/4.0;let fa=1.0/(f32(n)*max(ea,0.0001));let ga=clamp(0.5*log2(fa/T)+1.0,0.0,U);let V=textureSampleLevel(x,F,G,ga);p+=V.rgb*l;m+=l;}}if (m>0.0){p/=m;}textureStore(z,vec2<i32>(c.xy),i32(f),vec4<f32>(p,1.0));}"}),entryPoint:"main"}}),c=xn(e,16);{const e=r.createCommandEncoder();e.copyTextureToTexture({texture:t},{texture:s,mipLevel:0},{width:n,height:n,depthOrArrayLayers:6}),r.queue.submit([e.finish()])}for(let e=1;e<i;e++){const t=n>>e;if(t<1)break;r.queue.writeBuffer(c,0,new st([n,e,i,n]));const u=s.createView({dimension:"2d-array",baseMipLevel:e,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:6}),h=r.createBindGroup({layout:l.getBindGroupLayout(0),entries:[{binding:0,resource:o},{binding:1,resource:a},{binding:2,resource:u},{binding:3,resource:{buffer:c}}]}),d=r.createCommandEncoder(),p=d.beginComputePass();p.setPipeline(l),p.setBindGroup(0,h),p.dispatchWorkgroups(Math.ceil(t/8),Math.ceil(t/8),6),p.end(),r.queue.submit([d.finish()])}return t.destroy(),c.destroy(),s}let ko=null,Po=null;function Eo(e){const t=e._device;ko&&Po===t||(ko=t.createComputePipeline({layout:"auto",compute:{module:t.createShaderModule({code:Ao}),entryPoint:"main"}}),Po=t);const n=256,i=t.createTexture({size:{width:n,height:n},format:"rgba16float",usage:mt.TEXTURE_BINDING|mt.STORAGE_BINDING}),r=t.createBindGroup({layout:ko.getBindGroupLayout(0),entries:[{binding:0,resource:i.createView()}]}),s=t.createCommandEncoder(),o=s.beginComputePass();return o.setPipeline(ko),o.setBindGroup(0,r),o.dispatchWorkgroups(Math.ceil(32),Math.ceil(32)),o.end(),t.queue.submit([s.finish()]),i}var Oo=Object.freeze({__proto__:null,equirectToCubemapGPU:Mo,generateBrdfLut:Eo,prefilterCubemapGPU:So});function To(e,t){vn(e,t._lightMatrix,0),e[16]=t._depthValues[0],e[17]=t._depthValues[1],e[18]=0,e[19]=0,e[20]=t._shadowsInfo[0],e[21]=t._shadowsInfo[1],e[22]=t._shadowsInfo[2],e[23]=t._shadowsInfo[3]}function Bo(e,t){const n=new it(16);for(let i=0;i<4;i++)for(let r=0;r<4;r++){let s=0;for(let n=0;n<4;n++)s+=e[i+4*n]*t[n+4*r];n[i+4*r]=s}return n}function Lo(e,t,n,i,r=0,s=0,o=0){const a=function(e,t,n,i,r,s){const o=Math.sqrt(e*e+t*t+n*n)||1,a=e/o,l=t/o,c=n/o;let u=0,h=1,d=0;Math.abs(l)>.99&&(u=0,h=0,d=1);let p=h*c-d*l,_=d*a-u*c,f=u*l-h*a;const m=Math.sqrt(p*p+_*_+f*f)||1;p/=m,_/=m,f/=m;const g=l*f-c*_,b=c*p-a*f,v=a*_-l*p;return new it([p,g,a,0,_,b,l,0,f,v,c,0,-(p*i+_*r+f*s),-(g*i+b*r+v*s),-(a*i+l*r+c*s),1])}(e.direction.x,e.direction.y,e.direction.z,e.position.x-r,e.position.y-s,e.position.z-o);let l=1/0,c=-1/0,u=1/0,h=-1/0;for(const e of t){const t=e.worldMatrix,n=e.boundMin??[-.5,-.5,-.5],i=e.boundMax??[.5,.5,.5];for(let e=0;e<8;e++){const d=1&e?i[0]:n[0],p=2&e?i[1]:n[1],_=4&e?i[2]:n[2],f=t[0]*d+t[4]*p+t[8]*_+t[12]-r,m=t[1]*d+t[5]*p+t[9]*_+t[13]-s,g=t[2]*d+t[6]*p+t[10]*_+t[14]-o,b=a[0]*f+a[4]*m+a[8]*g+a[12],v=a[1]*f+a[5]*m+a[9]*g+a[13];l=Math.min(l,b),c=Math.max(c,b),u=Math.min(u,v),h=Math.max(h,v)}}Number.isFinite(l)||(l=-1,c=1,u=-1,h=1);const d=.1*(c-l),p=.1*(h-u);l-=d,c+=d,u-=p,h+=p;const _=new it(16);return _[0]=2/(c-l),_[5]=2/(h-u),_[10]=1/(i-n),_[12]=-(c+l)/(c-l),_[13]=-(h+u)/(h-u),_[14]=-n/(i-n),_[15]=1,{_view:a,_viewProj:Bo(_,a),_near:n,_far:i}}function Io(e,t=null,n=e._depthTexture){const i=e._config._mapSize;return{_descriptor:{size:{width:i,height:i},format:t?"rgba16float":void 0,dFormat:"depth32float",_depthClearValue:1,_depthCompare:"less-equal",samples:1},_colorTexture:t,_colorView:t?.createView()??null,_depthTexture:n,_depthView:n.createView(),_width:i,_height:i,_eager:!0,_ownsDepthTexture:!1}}let Ro,$o,No,Vo=null;function Fo(e,t){(Vo??=new WeakMap,Vo).set(e,t)}function zo(e){return Vo?.get(e)??null}async function Do(e){const t=[];let n=!1,i=!1,r=!1;for(const t of e){const e=t.material?._buildGroup._materialFamily;n||="standard"===e,i||="pbr"===e,r||="node"===e}n&&!Ro&&t.push(import("./esm-shadow-view-nhqYpMvF.esm.min.js").then(e=>{Ro=e.createStandardEsmShadowMaterialView})),i&&!$o&&t.push(import("./esm-shadow-view-D-kcuLsM.esm.min.js").then(e=>{$o=e.createPbrEsmShadowMaterialView})),r&&!No&&t.push(import("./esm-shadow-view-B3fClxhq.esm.min.js").then(e=>{No=e.createNodeEsmShadowMaterialView})),await Promise.all(t)}function Go(e){const t=1/3;return Math.exp(-e*e/(2*t*t))/(Math.sqrt(2*Math.PI)*t)}function Uo(e){const t=function(e){const t=Math.round(Math.max(e,1));for(const e of[t,t-1,t+1,t-2,t+2])if(e%2!=0&&Math.floor(e/2)%2==0&&e>0)return Math.max(e,3);return Math.max(t,3)}(e),n=(t-1)/2,i=[],r=[];let s=0;for(let e=0;e<t;e++){const o=Go(2*(e/(t-1))-1);i[e]=e-n,r[e]=o,s+=o}for(let e=0;e<r.length;e++)r[e]=r[e]/s;const o=[],a=[];for(let e=0;e<=n;e+=2){const t=Math.min(e+1,Math.floor(n));if(e===t){o.push(i[e]),a.push(r[e]);continue}const s=t===n,l=r[e]+r[t]*(s?.5:1),c=i[e]+1/(1+r[e]/r[t]);0===c?(o.push(i[e],i[e+1]),a.push(r[e],r[e+1])):(o.push(c,-c),a.push(l,l))}return{offsets:o,weights:a}}function jo(e){let t=(Object.is(e,-0)?0:e).toPrecision(10);return/[.eE]/.test(t)||(t+=".0"),t}function Wo(e){const{offsets:t,weights:n}=Uo(e),i=t.length;return`struct BlurParams{delta:vec2<f32>,_pad:vec2<f32>,};@group(0) @binding(0) var<uniform> params:BlurParams;@group(0) @binding(1) var srcTex:texture_2d<f32>;@group(0) @binding(2) var srcSampler:sampler;const OFFSETS=array<f32,${i}>(${t.map(jo).join(",")});const WEIGHTS=array<f32,${i}>(${n.map(jo).join(",")});@fragment fn main(@location(0) sampleCenter:vec2<f32>)->@location(0) vec4<f32>{var blend=vec4<f32>(0.0);for(var i=0u;i<${i}u;i=i+1u){blend+=textureSample(srcTex,srcSampler,sampleCenter+params.delta*OFFSETS[i])*WEIGHTS[i];}return blend;}`}function Ho(e,t,n,i,r){const s=r;if(s){if(s._casterMeshes===i)return s;s._task.dispose()}const o=zo(n);if(!o)throw new Error("ShadowTask: missing ESM metadata.");const a=new Map,l=function(e){return{fov:1,nearPlane:1,farPlane:1,children:[],_viewCache:ft(),_projCache:ft(),_vpCache:ft(),get worldMatrix(){return e._light.worldMatrix},get worldMatrixVersion(){return this._shadowCameraVersion??e._light.worldMatrixVersion}}}(n),c={_task:Nn({name:"esm",rt:Io(n,o._esmTexture,o._depthBuffer),clr:!0,clrColor:{r:0,g:0,b:0,a:0},cam:l,_skipClusteredLights:!0},e,t),_camera:l,_cameraVersion:0,_lastCasterVersion:-1,_lastLightVersion:-1,_lastFoVersion:-1,_casterMeshes:i,_scene:t};for(const e of i){const t=e.material;t&&c._task.addMesh(e,{material:Xo(t,a,n._shadowParamsUBO)})}return c}function qo(e,t,n){const i=zo(t);if(!i)return 0;const r=n._casterMeshes,s=function(e){let t=0;for(const n of e)t+=n.worldMatrixVersion+~~n.thinInstances?._version;return t}(r),o=t._light.worldMatrixVersion,a=e.useFloatingOrigin?n._scene.camera:null,l=a?a.worldMatrixVersion:0,c=a?a.worldMatrix[12]:0,u=a?a.worldMatrix[13]:0,h=a?a.worldMatrix[14]:0;if(!t._config._forceRefreshEveryFrame&&s===n._lastCasterVersion&&o===n._lastLightVersion&&l===n._lastFoVersion)return 0;const d=Lo(t._light,r,t._config._orthoMinZ,t._config._orthoMaxZ,c,u,h);(function(e,t){for(let n=0;n<16;n++)if(e[n]!==t[n])return!0;return!1})(t._lightMatrix,d._viewProj)&&(vn(t._lightMatrix,d._viewProj,0),t._version++,To(i._shadowUboData,t),e._device.queue.writeBuffer(t._shadowUBO,0,i._shadowUboData)),function(e,t){e._cameraVersion++,n=e._camera,i=e._cameraVersion,r=t._near,s=t._far,o=t._view,a=t._viewProj,n.nearPlane=r,n.farPlane=s,n._shadowCameraVersion=i,n._viewCache=o,n._viewVer=i,n._vpCache=a,n._vpVer=un(n),n._vpAspect=1;var n,i,r,s,o,a}(n,d),n._lastCasterVersion=s,n._lastLightVersion=o,n._lastFoVersion=l;let p=n._task.execute?.()??0;const _=e._currentEncoder,f=_.beginRenderPass({colorAttachments:[{view:i._blurTexH.createView(),loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]});f.setPipeline(i._blurPipeline),f.setBindGroup(0,i._blurHBG),f.draw(3),f.end();const m=_.beginRenderPass({colorAttachments:[{view:t._depthTexture.createView(),loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]});return m.setPipeline(i._blurPipeline),m.setBindGroup(0,i._blurVBG),m.draw(3),m.end(),p+=2,p}function Xo(e,t,n){const i=t.get(e);if(i)return i;const r=e._buildGroup._materialFamily;let s;return"standard"===r?s=Ro(e,n):"pbr"===r?s=$o(e,n):"node"===r&&(s=No(e,n)),t.set(e,s),s}function Yo(e,t,n={}){const i=e._device,r=n.mapSize??1024,s=n.depthScale??50,o=n.bias??5e-5,a=n.blurKernel??1,l=n.blurScale??2,c=n.darkness??0,u=n.frustumEdgeFalloff??0,h=r/l,d={_mapSize:r,_bias:o,_orthoMinZ:n.orthoMinZ??1,_orthoMaxZ:n.orthoMaxZ??1e4,_forceRefreshEveryFrame:n.forceRefreshEveryFrame??!1},p=function(e,t,n){const i=new it(8);return i[0]=t,i[2]=n,i[4]=0,i[5]=1,wn(e,i)}(e,o,s),_=i.createTexture({size:{width:r,height:r},format:"rgba16float",usage:mt.RENDER_ATTACHMENT|mt.TEXTURE_BINDING}),f=i.createTexture({size:{width:r,height:r},format:"depth32float",usage:mt.RENDER_ATTACHMENT}),m=i.createTexture({size:{width:h,height:h},format:"rgba16float",usage:mt.RENDER_ATTACHMENT|mt.TEXTURE_BINDING}),g=i.createTexture({size:{width:h,height:h},format:"rgba16float",usage:mt.RENDER_ATTACHMENT|mt.TEXTURE_BINDING}),b=i.createShaderModule({code:"struct c{@builtin(position) clipPos:vec4<f32>,@location(0) sampleCenter:vec2<f32>}@vertex fn main(@builtin(vertex_index) d:u32)->c{var e=array<vec2<f32>,3>(vec2<f32>(-1.0,-1.0),vec2<f32>(3.0,-1.0),vec2<f32>(-1.0,3.0));var a:c;let b=e[d];a.clipPos=vec4<f32>(b,0.0,1.0);a.sampleCenter=b*vec2<f32>(0.5,-0.5)+0.5;return a;}"}),v=i.createShaderModule({code:Wo(a)}),y=i.createBindGroupLayout({entries:[{binding:0,visibility:bt.VERTEX|bt.FRAGMENT,buffer:{type:"uniform"}},{binding:1,visibility:bt.FRAGMENT,texture:{sampleType:"float"}},{binding:2,visibility:bt.FRAGMENT,sampler:{type:"filtering"}}]}),w=i.createRenderPipeline({layout:i.createPipelineLayout({bindGroupLayouts:[y]}),vertex:{module:b,entryPoint:"main"},fragment:{module:v,entryPoint:"main",targets:[{format:"rgba16float"}]},primitive:{topology:"triangle-list",cullMode:"none"}}),x=Vi(e),C=wn(e,new it([1/h,0,0,0])),A=i.createBindGroup({layout:y,entries:[{binding:0,resource:{buffer:C}},{binding:1,resource:_.createView()},{binding:2,resource:x}]}),M=wn(e,new it([0,1/h,0,0])),S=i.createBindGroup({layout:y,entries:[{binding:0,resource:{buffer:M}},{binding:1,resource:m.createView()},{binding:2,resource:x}]}),k=new it(16),P=new it([c,0,s,u]),E=new it([0,1]),{ubo:O,data:T}=function(e,t,n,i){const r=new it(24);return To(r,{_lightMatrix:t,_depthValues:n,_shadowsInfo:i}),{ubo:wn(e,r),data:r}}(e,k,E,P),B={_shadowType:"esm",_light:t,_depthTexture:g,_depthSampler:x,_lightMatrix:k,_shadowsInfo:P,_depthValues:E,_shadowParamsUBO:p,_shadowUBO:O,_config:d,_version:0};return B._preloadShadowTask=Do,B._ensureShadowTaskState=(e,t,n)=>{const i=Ho(e,t,B,n,B._shadowTaskState??null);return B._shadowTaskState=i,i},B._renderShadowMap=(e,t)=>qo(e,B,t),Fo(B,{_esmTexture:_,_depthBuffer:f,_blurTexH:m,_blurPipeline:w,_blurHBG:A,_blurVBG:S,_shadowUboData:T,_blurKernel:a,_blurScale:l}),B}var Qo=Object.freeze({__proto__:null,createEsmDirectionalShadowGenerator:Yo,getEsmShadowTaskResources:zo,setEsmShadowTaskResources:Fo});const Zo=0,Ko=1,Jo=2,ea=0,ta=1,na=2,ia=3,ra=4;const sa=new it([0,0,0,1]);function oa(e,t){const n=e[t],i=e[t+1],r=e[t+2],s=e[t+3],o=n*n+i*i+r*r+s*s;if(o>0){const a=1/Math.sqrt(o);e[t]=n*a,e[t+1]=i*a,e[t+2]=r*a,e[t+3]=s*a}}function aa(e,t,n,i,r,s){const{input:o,output:a,interpolation:l}=e,c=o.length;if(0===c)return;if(1===c||t<=o[0]){const e=2===l?n:0;for(let t=0;t<n;t++)r[s+t]=a[e+t];return}const u=function(e,t){let n=0,i=e.length-1;if(t<=e[0])return 0;if(t>=e[i])return i>0?i-1:0;for(;n<i-1;){const r=n+i>>1;e[r]<=t?n=r:i=r}return n}(o,t),h=o[u],d=o[u+1];if(1===l){const e=(t>=d?u+1:u)*n;for(let t=0;t<n;t++)r[s+t]=a[e+t];return}const p=d-h,_=t>=d?1:p>0?(t-h)/p:0;if(2===l){const e=_*_,t=e*_,o=2*t-3*e+1,l=t-2*e+_,c=-2*t+3*e,h=t-e,d=u*n*3,f=(u+1)*n*3;for(let e=0;e<n;e++){const t=a[d+n+e],i=a[d+2*n+e]*p,u=a[f+n+e],_=a[f+e]*p;r[s+e]=o*t+l*i+c*u+h*_}return void(i&&oa(r,s))}const f=u*n,m=(u+1)*n;if(i)!function(e,t,n,i,r,s,o,a,l,c){let u=t*s+n*o+i*a+r*l;if(u<0&&(s=-s,o=-o,a=-a,l=-l,u=-u),u>.9995)return e[0]=t+c*(s-t),e[1]=n+c*(o-n),e[2]=i+c*(a-i),e[3]=r+c*(l-r),void oa(e,0);const h=Math.acos(u),d=Math.sin(h),p=Math.sin((1-c)*h)/d,_=Math.sin(c*h)/d;e[0]=p*t+_*s,e[1]=p*n+_*o,e[2]=p*i+_*a,e[3]=p*r+_*l}(sa,a[f],a[f+1],a[f+2],a[f+3],a[m],a[m+1],a[m+2],a[m+3],_),r[s]=sa[0],r[s+1]=sa[1],r[s+2]=sa[2],r[s+3]=sa[3];else for(let e=0;e<n;e++)r[s+e]=a[f+e]+_*(a[m+e]-a[f+e])}const la=new it(16),ca=new it([-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function ua(e,t,n,i,r,s,o,a){const l=n.length>0||i.length>0,c=t.length,u=[];if(r){const t=new Map;for(let n=0;n<e.channels.length;n++){const i=e.channels[n],o=0===i.path?1:1===i.path?2:2===i.path?4:0;if(0===o)continue;const a=i.nodeIdx;a<0||s?.has(a)||!r[a]||t.set(a,(t.get(a)??0)|o)}for(const[e,n]of t)u.push({target:r[e],off:12*e,mask:n})}const h=new it(12*c),d=new it(16*c),p=new it(16*c),_=function(e){const t=e.length,n=new ot(t),i=new ct(t);let r=0;function s(t){if(i[t])return;i[t]=1;const o=e[t].parentIdx;o>=0&&s(o),n[r++]=t}for(let e=0;e<t;e++)s(e);return n}(t),f=n.map(e=>e.boneMatrices),m=[];for(let e=0;e<i.length;e++){const t=i[e];let n=m[t.nodeIdx];n||(n=[],m[t.nodeIdx]=n),n.push(t)}const g=new it(16);let b,v=g,y=!0;const w={time:0,playing:!0,speedRatio:1,loop:!0,_setMask:e=>{!e||e.disabled},_debugWorldMat:p,_tickCpu(e,t){const n=y;y=!1;try{w.tick(e,t)}finally{y=n}},tick:e.duration<=0?ha:(i,r)=>{r&&(b=r);const s=r??b;l&&y&&!s&&nt(378);const a=l&&y?s._device:null;w.playing&&(w.time+=i/1e3*w.speedRatio),w.loop?(w.time%=e.duration,w.time<0&&(w.time+=e.duration)):w.time=Math.min(Math.max(w.time,0),e.duration);const x=w.time;for(let e=0;e<c;e++){const n=t[e],i=12*e;h[i+0]=n.tx,h[i+0+1]=n.ty,h[i+0+2]=n.tz,h[i+3]=n.rx,h[i+3+1]=n.ry,h[i+3+2]=n.rz,h[i+3+3]=n.rw,h[i+7]=n.sx,h[i+7+1]=n.sy,h[i+7+2]=n.sz}void 0!==o&&o.size;for(let t=0;t<e.channels.length;t++){const n=e.channels[t],i=e.samplers[n.samplerIdx],r=12*n.nodeIdx;switch(n.path){case 0:aa(i,x,3,!1,h,r+0);break;case 1:aa(i,x,4,!0,h,r+3);break;case 2:aa(i,x,3,!1,h,r+7);break;case 3:{const e=m[n.nodeIdx];if(e){const t=e[0].targetCount;t>v.length&&(v=new it(t)),v.fill(0),aa(i,x,t,!1,v,0);for(let n=0;n<e.length;n++){const i=e[n];i.weights.set(v.subarray(0,t)),y&&a.queue.writeBuffer(i.runtimeMorphTargets?.weightsBuffer??i.weightsBuffer,16,v.buffer,0,4*t)}}break}case 4:n.pointerArity&&n.pointerWriter&&(aa(i,x,n.pointerArity,!0===n.pointerQuaternion,g,0),n.pointerWriter(g,0))}}void 0!==o&&o.size;for(let e=0;e<u.length;e++){const t=u[e],n=t.off;1&t.mask&&t.target.position.set(h[n+0],h[n+0+1],h[n+0+2]),2&t.mask&&t.target.rotationQuaternion.set(h[n+3],h[n+3+1],h[n+3+2],h[n+3+3]),4&t.mask&&t.target.scaling.set(h[n+7],h[n+7+1],h[n+7+2])}for(let e=0;e<c;e++){const n=_[e],i=t[n],r=12*n;i._matrix?d.set(i._matrix,16*n):Kn(d,16*n,h[r+0],h[r+0+1],h[r+0+2],h[r+3],h[r+3+1],h[r+3+2],h[r+3+3],h[r+7],h[r+7+1],h[r+7+2]);const s=i.parentIdx;s>=0?ln(p,16*n,p,16*s,d,16*n):ln(p,16*n,ca,0,d,16*n)}for(let e=0;e<n.length;e++){const t=n[e],i=f[e];for(let e=0;e<t.boneCount;e++){const n=t.jointNodes[e],r=16*e;ln(la,0,t.invMeshWorld,0,p,16*n),ln(i,16*e,la,0,t.inverseBindMatrices,r)}if(y){const e=4*t.boneCount;a.queue.writeTexture({texture:t.runtimeSkeleton?.boneTexture??t.boneTexture},i.buffer,{bytesPerRow:16*e},{width:e,height:1})}}}};return w}function ha(){}function da(e){e.isPlaying=!0,e._stopped=!1}function pa(e){e.isPlaying=!1}function _a(e){e.isPlaying=!1,e.currentTime=0,e._stopped=!0}function fa(e,t){t.time=e.currentTime,t.playing=e.isPlaying,t.speedRatio=e.speedRatio,t.loop=e.loopAnimation,t._setMask?.(e.mask??null)}function ma(e,t,n){!e._stopped&&e._ctrl&&(fa(e,e._ctrl),e._ctrl.tick(t,n),e.currentTime=e._ctrl.time)}function ga(e,t,n){e._animationManager||ma(e,t,n)}function ba(){sn=ga}function va(e,t,n){const i=e._ctrl;e.currentTime=t/(e.frameRate||60),e.isPlaying=!1,i&&(fa(e,i),!n&&e._stopped&&e._gltfMixer||(i.tick(0,n),e.currentTime=i.time))}var ya=Object.freeze({__proto__:null,_installTickAnimation:ba,createAnimationGroups:function(e){const{clips:t,nodes:n,skeletons:i,morphBindings:r,nodeTargets:s,excludedNodeIndices:o,nodeNames:a,boneOverrides:l}=e,c=t.some(e=>e.channels.some(e=>4===e.path)),u=t.some(e=>e.channels.some(e=>(0===e.path||1===e.path||2===e.path)&&e.nodeIdx>=0&&!o.has(e.nodeIdx)&&!!s[e.nodeIdx]));return 0===t.length||0===i.length&&0===r.length&&!c&&!u?[]:(ba(),t.map((e,t)=>{const c=ua(e,n,i,r,s,o,l),u=0===t,h={name:e.name||`animation_${t}`,duration:e.duration,frameRate:e.frameRate||60,isPlaying:u,currentTime:0,targetedAnimations:e.channels.map(e=>{const t=e.nodeIdx>=0?e.nodeIdx:void 0;return{target:void 0!==t?s[t]:void 0,targetName:void 0!==t?a[t]:void 0,nodeIndex:t,path:(n=e.path,0===n?"translation":1===n?"rotation":2===n?"scale":4===n?"pointer":"weights")};var n}),speedRatio:1,loopAnimation:!0,weight:1,_ctrl:c,_stopped:!u};return h._gltfMixer=[e,n,i],h}))},goToFrame:va,pauseAnimation:pa,playAnimation:da,stopAnimation:_a,tickAnimationCore:ma});const wa={x:0,y:0,width:1,height:1};function xa(e){return Math.max(0,Math.min(1,e))}function Ca(e,t){const n=new Float32Array(24);for(let i=0;i<8;i++)n[3*i]=1&i?t[0]:e[0],n[3*i+1]=2&i?t[1]:e[1],n[3*i+2]=4&i?t[2]:e[2];return n}function Aa(e){const t=e._cpuPositions;if(!t||0===t.length)return e.boundMin&&e.boundMax?{bones:null,corners:Ca(e.boundMin,e.boundMax)}:{bones:null,corners:null};const n=t.length/3|0,{minP:i,maxP:r}=function(e,t){const n=e._cpuPositions,i=3*t,r=new Float32Array(n.subarray(0,i)),s=new Float32Array(r),o=e.morphTargets;if(o)for(const e of o.targets){const t=e.positions,o=Math.min(t.length,i);for(let e=0;e<o;e++){const i=n[e]+t[e];i<r[e]&&(r[e]=i),i>s[e]&&(s[e]=i)}}return{minP:r,maxP:s}}(e,n),s=e.skeleton;if(s&&s.weights){const e=s.boneCount,t=new Float32Array(3*e).fill(Number.POSITIVE_INFINITY),o=new Float32Array(3*e).fill(Number.NEGATIVE_INFINITY),a=new Uint8Array(e),l=(n,s,l)=>{const c=4*l;for(let u=0;u<4;u++)if(s[c+u]>0){const s=n[c+u];if(s<e){const e=3*s,n=3*l;i[n]<t[e]&&(t[e]=i[n]),i[n+1]<t[e+1]&&(t[e+1]=i[n+1]),i[n+2]<t[e+2]&&(t[e+2]=i[n+2]),r[n]>o[e]&&(o[e]=r[n]),r[n+1]>o[e+1]&&(o[e+1]=r[n+1]),r[n+2]>o[e+2]&&(o[e+2]=r[n+2]),a[s]=1}}},c=s.joints,u=s.weights,h=s.joints1,d=s.weights1;for(let e=0;e<n;e++)l(c,u,e),h&&d&&l(h,d,e);const p=[];for(let n=0;n<e;n++)if(a[n]){const e=3*n;p.push({boneIndex:n,corners:Ca([t[e],t[e+1],t[e+2]],[o[e],o[e+1],o[e+2]])})}return{bones:p,corners:null}}let o=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,l=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,u=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY;for(let e=0;e<n;e++){const t=3*e;i[t]<o&&(o=i[t]),i[t+1]<a&&(a=i[t+1]),i[t+2]<l&&(l=i[t+2]),r[t]>c&&(c=r[t]),r[t+1]>u&&(u=r[t+1]),r[t+2]>h&&(h=r[t+2])}return{bones:null,corners:Ca([o,a,l],[c,u,h])}}function Ma(e,t,n){const i=t[0],r=t[1],s=t[2],o=t[4],a=t[5],l=t[6],c=t[8],u=t[9],h=t[10],d=t[12],p=t[13],_=t[14],f=n.minimum,m=n.maximum;for(let t=0;t<8;t++){const n=e[3*t],g=e[3*t+1],b=e[3*t+2],v=i*n+o*g+c*b+d,y=r*n+a*g+u*b+p,w=s*n+l*g+h*b+_;v<f[0]&&(f[0]=v),y<f[1]&&(f[1]=y),w<f[2]&&(f[2]=w),v>m[0]&&(m[0]=v),y>m[1]&&(m[1]=y),w>m[2]&&(m[2]=w)}}function Sa(e,t,n){return e._device.createBindGroupLayout({label:t,entries:[{binding:0,visibility:n,buffer:{type:"uniform"}}]})}let ka=null,Pa=null;function Ea(e){return ka!==e._device&&(ka=e._device,Pa=null),Pa??=Sa(e,"picking-scene-bgl",bt.VERTEX|bt.FRAGMENT)}const Oa=new it(20),Ta=new ArrayBuffer(80),Ba=new it(Ta),La=new st(Ta),Ia=new ct(Ta);function Ra(e,t,n,i,r){const s=n.storage;if(!s||0===s.length)return null;const o=[];for(let t=0;t<s.length;t++){const n=s[t].data(i);if(!n)return null;const a=Cn(e,n,gt.STORAGE,"pick-discard-storage");r.push(a),o.push({binding:t,resource:{buffer:a}})}return e._device.createBindGroup({label:`pick-discard-${n.key}-bg`,layout:t,entries:o})}async function $a(e,t,n,i){const r=e._scene,s=i?.filter??null,o=i?.discard??null,a=i?.ignore,l=i?.debugLabel,c=r.surface.engine;if(!r.camera)return{hit:!1,distance:0,pickedPoint:null,pickedNormal:null,pickedNormalWorld:null,pickedFaceNormal:null,pickedFaceNormalWorld:null,pickedMesh:null,faceId:-1,bu:0,bv:0,subMeshId:0,thinInstanceIndex:-1,ray:null,_normalsInvalid:!1};!function(e,t){t._device!==e._device&&(t._device&&Na(t),t._device=e._device)}(c,e);const u=c._device,h=e._detailedPicking,d=[];if(!s&&r._pickSources.length>0){const t=r._pickSources.slice();for(const n of t){let t=e._contributors?.get(n);if(!t){const i=await n.load();if(!r._pickSources.includes(n))continue;t=i.createPickContributor(n.entity),(e._contributors??=new Map).set(n,t)}d.push({source:n,contributor:t})}}let p,_=!1,f=!!o?.worldAdjustWgsl||!!o?.vertexData||!!o?.storage?.some(e=>e.vertex);if(a){const e=(await import("./picking-ignore-NPS8FESj.esm.min.js")).prepareIgnoredCandidates(r.meshes,a,s,f);p=e.candidates,_=e.deformed,f=e.advanced}else{p=[];for(const e of r.meshes)!1===e.pickable||s&&!s(e)||(p.push({mesh:e,ignore:null}),_||=!(!e.morphTargets&&!e.skeleton),f||=!!e.vat||!!e.thinInstances||!!e._gpu._vbLayout?._p)}const m=_&&!f?await import("./deform-picking-projection-BQbR83dT.esm.min.js"):null,g=_&&h?await Promise.resolve().then(function(){return qa}):null,b=h?await import("./detailed-picking-BWY0nhrI.esm.min.js"):null,v=l?await import("./picking-debug-ChMPmqth.esm.min.js"):null,y=f?await(await import("./picking-advanced-draw-DTRGKtrD.esm.min.js")).prepareAdvancedDraw(c,p):null,w=y?null:h?await import("./picking-detailed-pipeline-CgKWE4wY.esm.min.js"):await import("./picking-pipeline-BG_xXFV2.esm.min.js");if(c._device!==u)return $a(e,t,n,i);const x=r.surface.canvas,C=r.camera;if(!C)return{hit:!1,distance:0,pickedPoint:null,pickedNormal:null,pickedNormalWorld:null,pickedFaceNormal:null,pickedFaceNormalWorld:null,pickedMesh:null,faceId:-1,bu:0,bv:0,subMeshId:0,thinInstanceIndex:-1,ray:null,_normalsInvalid:!1};const A=x.width,M=x.height,S=("clientWidth"in x?x.clientWidth:0)||A,k=("clientHeight"in x?x.clientHeight:0)||M,P=t*(A/S),E=n*(M/k),O=function(e,t,n){const i=e?.viewport??wa,r=xa(i.x),s=xa(1-i.y-i.height),o=xa(i.x+i.width),a=xa(1-i.y),l=Math.floor(r*t),c=Math.floor(s*n);return{x:l,y:c,width:Math.max(0,Math.ceil(o*t)-l),height:Math.max(0,Math.ceil(a*n)-c)}}(C,A,M),T=O.width,B=O.height;if(0===T||0===B)return{hit:!1,distance:0,pickedPoint:null,pickedNormal:null,pickedNormalWorld:null,pickedFaceNormal:null,pickedFaceNormalWorld:null,pickedMesh:null,faceId:-1,bu:0,bv:0,subMeshId:0,thinInstanceIndex:-1,ray:null,_normalsInvalid:!1};if(P<O.x||E<O.y||P>=O.x+O.width||E>=O.y+O.height)return{hit:!1,distance:0,pickedPoint:null,pickedNormal:null,pickedNormalWorld:null,pickedFaceNormal:null,pickedFaceNormalWorld:null,pickedMesh:null,faceId:-1,bu:0,bv:0,subMeshId:0,thinInstanceIndex:-1,ray:null,_normalsInvalid:!1};const L=Math.max(0,Math.min(Math.floor(P-O.x),T-1)),I=Math.max(0,Math.min(Math.floor(E-O.y),B-1)),R=P-O.x,$=E-O.y,N=L+.5,V=I+.5,F=dn(C,T/B),z=h||l?function(e,t,n,i,r){const s=Gi(n);if(!s)return null;const o=2*e/i-1,a=1-2*t/r,l=Yi(s,o,a,1),c=Yi(s,o,a,0),u=c[0]-l[0],h=c[1]-l[1],d=c[2]-l[2],p=Math.sqrt(u*u+h*h+d*d);if(p<1e-10)return null;const _=1/p;return{origin:l,direction:[u*_,h*_,d*_],length:p}}(R,$,F,T,B):null,D=v?[t,n,P,E,L,I,A,M,S,k,O.x,O.y,O.width,O.height]:null;!function(e,t,n,i,r,s){const o=2*n/r-1,a=1-2*i/s;for(let n=0;n<4;n++){const i=4*n,l=t[i+3];e[i]=r*(t[i]-o*l),e[i+1]=s*(t[i+1]-a*l),e[i+2]=t[i+2],e[i+3]=l}}(Oa,F,R,$,T,B),Oa[16]=O.x+N,Oa[17]=O.y+V;const G=function(e,t){const n=e._device;if(t._rt)return t._rt;const i=n.createTexture({label:"pick-color",size:[1,1],format:"rgba8unorm",usage:mt.RENDER_ATTACHMENT|mt.COPY_SRC}),r=n.createTexture({label:"pick-depth-color",size:[1,1],format:"r32float",usage:mt.RENDER_ATTACHMENT|mt.COPY_SRC}),s=n.createTexture({label:"pick-depth",size:[1,1],format:"depth24plus",usage:mt.RENDER_ATTACHMENT});return t._rt={colorTex:i,colorView:i.createView(),depthColorTex:r,depthColorView:r.createView(),detail:null,depthTex:s,depthView:s.createView(),colorStaging:n.createBuffer({label:"pick-color-staging",size:256,usage:gt.COPY_DST|gt.MAP_READ}),depthStaging:n.createBuffer({label:"pick-depth-staging",size:256,usage:gt.COPY_DST|gt.MAP_READ})},t._rt}(c,e),U=h?b.ensureDetailTarget(c,G):null,j=function(e,t){const n=e._device;if(!t._sceneUbo){t._sceneUbo=xn(e,80,"pick-scene-ubo");const i=Ea(e);t._sceneBG=n.createBindGroup({label:"pick-scene-bg",layout:i,entries:[{binding:0,resource:{buffer:t._sceneUbo}}]})}return t._sceneUbo}(c,e);u.queue.writeBuffer(j,0,Oa);let W=1;const H=u.createCommandEncoder({label:"pick"}),q=[{view:G.colorView,clearValue:{r:0,g:0,b:0,a:0},loadOp:"clear",storeOp:"store"},{view:G.depthColorView,clearValue:{r:1,g:0,b:0,a:0},loadOp:"clear",storeOp:"store"}];U&&q.push({view:U.view,clearValue:{r:4294967295,g:0,b:0,a:0},loadOp:"clear",storeOp:"store"});const X=H.beginRenderPass({colorAttachments:q,depthStencilAttachment:{view:G.depthView,depthClearValue:0,depthLoadOp:"clear",depthStoreOp:"discard"}}),Y=[],Q=h?new Map:null,Z=h?new Map:null,K=g?.captureDeformPoses(p)??null;let J;if(y){const t=y.draw(X,e._sceneBG,W,o,h,b,Y,Q,Z);W=t.nextId,J=t.ranges}else{J=[];for(const{mesh:t}of p){const n=t._gpu,i=m?.getDeformPickingProjection(c,t)??null,r=w.getPickingPipelineSet(c,null,i),s=o?w.getPickingPipelineSet(c,o,i):null;Q&&t._cpuPositions&&Q.set(t,t._cpuPositions),Z&&t._cpuNormals&&Z.set(t,t._cpuNormals);const a=o&&s?.discardBGL?Ra(c,s.discardBGL,o,t,Y):null,l=!s||s.discardBGL&&!a?r:s;Ba.set(t.worldMatrix,0),La[16]=W;const h=wn(c,Ia,"pick-mesh-ubo");Y.push(h),X.setPipeline(l.regularPipeline),X.setBindGroup(0,e._sceneBG),X.setBindGroup(1,u.createBindGroup({layout:l.regularPipeline.getBindGroupLayout(1),entries:[{binding:0,resource:{buffer:h}}]})),a&&X.setBindGroup(2,a),X.setVertexBuffer(0,n.positionBuffer),i&&m.bindDeformPickingProjection(c,X,l.regularPipeline,t,1,!!a),X.setIndexBuffer(n.indexBuffer,n.indexFormat),X.drawIndexed(n.indexCount),J.push({base:W++,count:1,mesh:t,thin:!1,world:b?b.copyDetailedWorldMatrix(t.worldMatrix):null,thinVersion:0,worldAdjusted:!1})}}const ee=[];if(d.length>0){const t={picker:e,pass:X,engine:c,scene:r,camera:C,sceneBG:e._sceneBG,px:R,py:$,w:T,h:B,detailed:h};for(const{source:e,contributor:n}of d){if(!r._pickSources.includes(e))continue;const i=W;W=n.draw(t,i),W>i&&ee.push({base:i,count:W-i,contributor:n})}}let te,ne;X.end(),H.copyTextureToBuffer({texture:G.colorTex},{buffer:G.colorStaging,bytesPerRow:256},{width:1,height:1}),H.copyTextureToBuffer({texture:G.depthColorTex},{buffer:G.depthStaging,bytesPerRow:256},{width:1,height:1}),U&&b.copyDetailTarget(H,U),u.queue.submit([H.finish()]);let ie=-1,re=null;try{const e=[G.colorStaging.mapAsync(GPUMapMode.READ),G.depthStaging.mapAsync(GPUMapMode.READ)],t=U?b.readDetailTarget(U):null;t&&e.push(t.then(()=>{})),await Promise.all(e);const n=new ct(G.colorStaging.getMappedRange());te=n[0]<<16|n[1]<<8|n[2],ne=new it(G.depthStaging.getMappedRange())[0],t&&({primitiveIndex:ie,localPoint:re}=await t),G.colorStaging.unmap(),G.depthStaging.unmap()}finally{for(let e=0;e<Y.length;e++)Y[e].destroy()}if(0===te)return v&&v.tracePick(l,D,z,te,ne,!1),{hit:!1,distance:0,pickedPoint:null,pickedNormal:null,pickedNormalWorld:null,pickedFaceNormal:null,pickedFaceNormalWorld:null,pickedMesh:null,faceId:-1,bu:0,bv:0,subMeshId:0,thinInstanceIndex:-1,ray:null,_normalsInvalid:!1};let se=null,oe=null,ae=-1;for(let e=0;e<J.length;e++){const t=J[e];if(te>=t.base&&te<t.base+t.count){se=t.mesh,oe=t,ae=t.thin?te-t.base:-1;break}}let le=null,ce=-1;if(!se)for(let e=0;e<ee.length;e++){const t=ee[e];if(te>=t.base&&te<t.base+t.count){le=t.contributor,ce=te-t.base;break}}if(!se&&!le)return v&&v.tracePick(l,D,z,te,ne,!1,!0),{hit:!1,distance:0,pickedPoint:null,pickedNormal:null,pickedNormalWorld:null,pickedFaceNormal:null,pickedFaceNormalWorld:null,pickedMesh:null,faceId:-1,bu:0,bv:0,subMeshId:0,thinInstanceIndex:-1,ray:null,_normalsInvalid:!1};const ue={hit:!1,distance:0,pickedPoint:null,pickedNormal:null,pickedNormalWorld:null,pickedFaceNormal:null,pickedFaceNormalWorld:null,pickedMesh:null,faceId:-1,bu:0,bv:0,subMeshId:0,thinInstanceIndex:-1,ray:null,_normalsInvalid:!1};ue.hit=!0,ue.pickedMesh=se,ue.thinInstanceIndex=ae,ue.ray=h?z:null;const he=Gi(F);if(he){const e=2*R/T-1,t=1-2*$/B,n=he[0]*e+he[4]*t+he[8]*ne+he[12],i=he[1]*e+he[5]*t+he[9]*ne+he[13],r=he[2]*e+he[6]*t+he[10]*ne+he[14],s=1/(he[3]*e+he[7]*t+he[11]*ne+he[15]);ue.pickedPoint=[n*s,i*s,r*s];const o=h&&z?{x:z.origin[0],y:z.origin[1],z:z.origin[2]}:pn(C),a=ue.pickedPoint[0]-o.x,l=ue.pickedPoint[1]-o.y,c=ue.pickedPoint[2]-o.z;ue.distance=Math.sqrt(a*a+l*l+c*c)}if(le)le.resolve(ue,ce);else if(se&&oe?.world&&re&&ie>=0){if(!oe.thin||se.thinInstances?._version===oe.thinVersion){const e=Q?.get(se),t=b.detailedWorldMatrix(oe.world,se,ae),n=g?.deformerFor(K,se)??null;b.populateDetailedMeshInfo(ue,se,ie,re,e,Z?.get(se),t,!oe.worldAdjusted,n)}}return v&&v.tracePick(l,D,ue.ray??z,te,ne,!0,!1,se?se.name??"(unnamed)":"(contributor)",ae,ue),ue}function Na(e){if(e._rt){for(const t of[e._rt.colorTex,e._rt.depthColorTex,e._rt.detail?.texture,e._rt.depthTex,e._rt.colorStaging,e._rt.depthStaging,e._rt.detail?.staging])t?.destroy();e._rt=null}if(e._sceneUbo?.destroy(),e._sceneUbo=null,e._sceneBG=null,e._contributors){for(const t of e._contributors.values())t.dispose?.();e._contributors=null}e._device=null}const Va=[0,0,0];function Fa(e,t,n,i,r,s,o){const a=16*t;o[0]=e[a]*n+e[a+4]*i+e[a+8]*r+e[a+12]*s,o[1]=e[a+1]*n+e[a+5]*i+e[a+9]*r+e[a+13]*s,o[2]=e[a+2]*n+e[a+6]*i+e[a+10]*r+e[a+14]*s}function za(e){const t=e.skeleton,n=e.morphTargets;return t||n?{boneMatrices:t?new Float32Array(t.boneMatrices):null,morphWeights:n?new Float32Array(n.weights):null}:null}let Da,Ga;function Ua(e,t,n){return ja(e,t,n,null)}function ja(e,t,n,i){const r=e._cpuPositions;if(!r)return!1;const s=3*t;if(s<0||s+2>=r.length)return!1;const o=Da??=new Float32Array(3);o[0]=r[s],o[1]=r[s+1],o[2]=r[s+2];const a=e.morphTargets;a&&function(e,t,n,i,r){let s=t[n],o=t[n+1],a=t[n+2];const l=r??e.weights,c=Math.min(e.count,e.targets.length);for(let t=0;t<c;t++){const n=l[t]??0;if(0===n)continue;const r=e.targets[t].positions;s+=r[i]*n,o+=r[i+1]*n,a+=r[i+2]*n}t[n]=s,t[n+1]=o,t[n+2]=a}(a,o,0,s,i?.morphWeights);const l=e.skeleton;return l&&function(e,t,n,i,r,s,o,a,l,c,u,h){let d=0,p=0,_=0;const f=4*s;for(let i=0;i<4;i++){const r=n[f+i]??0;0!==r&&(Fa(e,t[f+i]??0,o,a,l,c,Va),d+=Va[0]*r,p+=Va[1]*r,_+=Va[2]*r)}if(i&&r)for(let t=0;t<4;t++){const n=r[f+t]??0;0!==n&&(Fa(e,i[f+t]??0,o,a,l,c,Va),d+=Va[0]*n,p+=Va[1]*n,_+=Va[2]*n)}u[h]=d,u[h+1]=p,u[h+2]=_}(i?.boneMatrices??l.boneMatrices,l.joints,l.weights,l.joints1,l.weights1,t,o[0],o[1],o[2],1,o,0),n.x=o[0],n.y=o[1],n.z=o[2],!0}function Wa(e,t,n,i,r){const s=Ga??={x:0,y:0,z:0};return!!ja(e,t,s,r)&&(n[i]=s.x,n[i+1]=s.y,n[i+2]=s.z,!0)}function Ha(e,t,n,i,r,s=null){return Wa(e,t,r,0,s)&&Wa(e,n,r,3,s)&&Wa(e,i,r,6,s)}var qa=Object.freeze({__proto__:null,captureDeformPose:za,captureDeformPoses:function(e){const t=new Map;for(const{mesh:n}of e){const e=za(n);e&&t.set(n,e)}return t},computeDeformedPositionToRef:Ua,deformTriangleToRef:Ha,deformerFor:function(e,t){const n=e?.get(t)??null;return n?(e,t,i,r,s)=>Ha(e,t,i,r,s,n):null}});const Xa=f,Ya=-Math.PI/2,Qa=Math.PI/2.5,Za=[.12,-1,.05],Ka={x:0,y:0,z:0},Ja={x:0,y:0,z:0},el={x:0,y:0,z:0},tl={x:0,y:0,z:0},nl={x:0,y:0,z:0};class il extends b{constructor(e,t){super(),this._engine=e,this._options=t,this._detachControl=null,this._renderLoopRunning=!1,this._sceneRegistered=!1,this._suspendRenderCount=0,this._renderLoopLock=new i,this._renderLoopStopped=null,this._autoOrbitIdleTime=0,this._lastPointerTime=0,this._currentLightingUrl=null,this._currentSkyboxUrl=null,this._toneMapping=this._options?.postProcessing?.toneMapping??Xa.postProcessing.toneMapping,this._contrast=this._options?.postProcessing?.contrast??Xa.postProcessing.contrast,this._exposure=this._options?.postProcessing?.exposure??Xa.postProcessing.exposure,this._ssaoOption=this._options?.postProcessing?.ssao??Xa.postProcessing.ssao,this._pbrRebuildLock=new i,this._shadowGenerator=null,this._shadowLight=null,this._shadowGround=null,this._container=null,this._picker=null,this._modelSource=null,this._modelMaterialGroupBuilt=!1,this._cachedModelBounds=null,this._selectedAnimation=-1,this._animationSpeed=this._options?.animationSpeed??Xa.animationSpeed,this._wasPlaying=!1,this._lastProgress=-1,this._selectedMaterialVariant=null,this._camerasAsHotSpots=!1,this._cameraInterpolationAbort=null,this._defaultTarget={x:0,y:0,z:0},this._onPointerActivity=()=>{this._lastPointerTime=performance.now()},this._onCanvasDoubleClick=e=>{this._handleDoubleClick(e.offsetX,e.offsetY)},this._deviceLostRecovery=Ht(e,{onRecoveryFailed:e=>{const t=e instanceof Error?e:new Error(`Babylon Lite device recovery failed: ${String(e)}`,{cause:e});this._options?.onFaulted?this._options.onFaulted(t):r.Error(t.stack??t.message)}}),this._shadowQuality=this._options?.shadowConfig?.quality??Xa.shadowConfig.quality,this._environmentIntensity=this._options?.environmentConfig?.intensity??Xa.environmentConfig.intensity,this._environmentBlur=this._options?.environmentConfig?.blur??Xa.environmentConfig.blur,this._environmentRotation=this._options?.environmentConfig?.rotation??Xa.environmentConfig.rotation,this._autoOrbitEnabled=this._options?.cameraAutoOrbit?.enabled??Xa.cameraAutoOrbit.enabled,this._autoOrbitSpeed=this._options?.cameraAutoOrbit?.speed??Xa.cameraAutoOrbit.speed,this._autoOrbitDelay=this._options?.cameraAutoOrbit?.delay??Xa.cameraAutoOrbit.delay,this._options?.hotSpots&&(this.hotSpots=this._options.hotSpots),this._scene=Wn(e);const n=t?.cameraOrbit?.[0],s=t?.cameraOrbit?.[1],o=t?.cameraOrbit?.[2],a=null==n||isNaN(n)?Ya:n,l=null==s||isNaN(s)?Qa:s,c=null==o||isNaN(o)?3:o;if(this._defaultAlpha=a,this._defaultBeta=l,this._defaultRadius=c,t?.cameraTarget){const e=t.cameraTarget[0],n=t.cameraTarget[1],i=t.cameraTarget[2];this._defaultTarget={x:null==e||isNaN(e)?0:e,y:null==n||isNaN(n)?0:n,z:null==i||isNaN(i)?0:i}}var h,d;this._camera=si(a,l,c,this._defaultTarget),this._scene.camera=this._camera,this._detachControl=function(e,t,n){const i=1e-4;let r=!1,s=!1,o=0,a=0;const l=new Map;let c=0,u=0;function h(e){e.preventDefault()}function d(){if(0!==e.inertialAlphaOffset||0!==e.inertialBetaOffset){e.alpha+=e.inertialAlphaOffset,e.beta+=e.inertialBetaOffset;const t=.01;e.beta=Math.max(t,Math.min(Math.PI-t,e.beta)),e.inertialAlphaOffset*=e.inertia,e.inertialBetaOffset*=e.inertia,Math.abs(e.inertialAlphaOffset)<.001&&(e.inertialAlphaOffset=0),Math.abs(e.inertialBetaOffset)<.001&&(e.inertialBetaOffset=0)}if(0!==e.inertialRadiusOffset&&(e.radius-=e.inertialRadiusOffset,e.radius=Math.max(.01,e.radius),e.inertialRadiusOffset*=e.inertia,Math.abs(e.inertialRadiusOffset)<.001&&(e.inertialRadiusOffset=0)),0!==e.inertialPanningX||0!==e.inertialPanningY){const t=Math.cos(e.alpha),n=-Math.sin(e.alpha),r=t,s=.001*e.radius;e.target.x+=n*e.inertialPanningX*s,e.target.y+=e.inertialPanningY*s,e.target.z+=r*e.inertialPanningX*s,e.inertialPanningX*=e.panningInertia,e.inertialPanningY*=e.panningInertia,Math.abs(e.inertialPanningX)<i&&(e.inertialPanningX=0),Math.abs(e.inertialPanningY)<i&&(e.inertialPanningY=0)}}n&&n._beforeRender.push(d);const p=[["pointerdown",function(e){t.setPointerCapture(e.pointerId),o=e.clientX,a=e.clientY,0===e.button?(r=!0,s=!1):2===e.button&&(r=!1,s=!0)}],["pointermove",function(t){const n=t.clientX-o,i=t.clientY-a;if(o=t.clientX,a=t.clientY,!(l.size>=2)&&(r||s)){if(r){const t=e.angularSensibility;e.inertialAlphaOffset-=n/t,e.inertialBetaOffset-=i/t}if(s){const t=e.panningSensibility;e.inertialPanningX+=-n/t,e.inertialPanningY+=i/t}}}],["pointerup",function(e){t.releasePointerCapture(e.pointerId),r=!1,s=!1}],["wheel",function(t){t.preventDefault(),e.inertialRadiusOffset-=t.deltaY*e.radius/(1e3*e.wheelPrecision)},{passive:!1}],["contextmenu",function(e){e.preventDefault()}],["touchstart",function(t){for(let e=0;e<t.changedTouches.length;e++){const n=t.changedTouches[e];l.set(n.identifier,{x:n.clientX,y:n.clientY})}if(l.size>=2){r=!1,s=!1;const n=l.values(),i=n.next().value,o=n.next().value;c=Math.hypot(o.x-i.x,o.y-i.y),u=e.radius,t.preventDefault()}},{passive:!1}],["touchmove",function(t){for(let e=0;e<t.changedTouches.length;e++){const n=t.changedTouches[e];l.set(n.identifier,{x:n.clientX,y:n.clientY})}if(l.size>=2){t.preventDefault();const n=l.values(),i=n.next().value,r=n.next().value,s=Math.hypot(r.x-i.x,r.y-i.y);c>0&&s>0&&(e.radius=u*(c/s),e.radius=Math.max(.01,e.radius))}},{passive:!1}],["touchend",function(e){for(let t=0;t<e.changedTouches.length;t++)l.delete(e.changedTouches[t].identifier);if(1===l.size){const e=l.values().next().value;o=e.x,a=e.y}l.size<2&&(c=0)}],["gesturestart",h,{passive:!1}],["gesturechange",h,{passive:!1}],["gestureend",h,{passive:!1}]];for(const[e,n,i]of p)t.addEventListener(e,n,i);return()=>{if(n){const e=n._beforeRender.indexOf(d);e>=0&&n._beforeRender.splice(e,1)}for(const[e,n]of p)t.removeEventListener(e,n)}}(this._camera,this._engine.canvas,this._scene),this._lastPointerTime=performance.now(),this._engine.canvas.addEventListener("pointerdown",this._onPointerActivity),this._engine.canvas.addEventListener("pointermove",this._onPointerActivity),this._engine.canvas.addEventListener("wheel",this._onPointerActivity),this._engine.canvas.addEventListener("dblclick",this._onCanvasDoubleClick),this._clearColor.r=t?.clearColor?.[0]??0,this._clearColor.g=t?.clearColor?.[1]??0,this._clearColor.b=t?.clearColor?.[2]??0,this._clearColor.a=t?.clearColor?.[3]??0,this._applyClearColor(),this._applyImageProcessingToScene(),t?.shadowConfig?.quality&&u(this.updateShadows({quality:t.shadowConfig.quality})),h=this._scene,d=e=>{this._isDisposed||(this._updateAutoOrbit(e),this._pollAnimationState(),this.onAfterRenderObservable.notifyObservers())},h._beforeRender.unshift(d),t?.source&&"none"!==this._shadowQuality||u(this._beginRendering());const p=t?.environmentLighting??Xa.environmentLighting,_=t?.environmentSkybox??Xa.environmentSkybox;u((async()=>{const e=[];p===_?"none"!==p&&e.push(this.loadEnvironment(p)):("none"!==p&&e.push(this.loadEnvironment(p,{lighting:!0,skybox:!1})),"none"!==_&&e.push(this.loadEnvironment(_,{lighting:!1,skybox:!0}))),await Promise.allSettled(e),t?.source&&await this.loadModel(t.source)})())}_applyClearColor(){const e=this._scene.clearColor;e.r=this._clearColor.r,e.g=this._clearColor.g,e.b=this._clearColor.b,e.a=this._clearColor.a}_applyCameraAutoOrbitEnabled(){}_applyCameraAutoOrbitSpeed(){}_applyCameraAutoOrbitDelay(){}resetCamera(e){this._resetCameraCore(e,!0)}_resetCameraCore(e,t){void 0===e&&(e=this._selectedAnimation!==(this._options?.selectedAnimation??0)),e?this._frameCameraToModel(t):this._frameCameraToModel(t,!0)||this._moveCameraTo({alpha:this._defaultAlpha,beta:this._defaultBeta,radius:this._defaultRadius,target:this._defaultTarget},t)}updateCamera(e){const t=void 0!==e.targetX||void 0!==e.targetY||void 0!==e.targetZ?{x:e.targetX??this._camera.target.x,y:e.targetY??this._camera.target.y,z:e.targetZ??this._camera.target.z}:void 0;this._moveCameraTo({alpha:e.alpha,beta:e.beta,radius:e.radius,target:t},!0)}_moveCameraTo(e,n){n?this._interpolateCameraTo(e):(this._cameraInterpolationAbort?.abort(new t("Camera interpolation superseded.")),this._cameraInterpolationAbort=null,void 0===e.alpha||isNaN(e.alpha)||(this._camera.alpha=e.alpha),void 0===e.beta||isNaN(e.beta)||(this._camera.beta=e.beta),void 0===e.radius||isNaN(e.radius)||(this._camera.radius=e.radius),e.target&&(this._camera.target.x=e.target.x,this._camera.target.y=e.target.y,this._camera.target.z=e.target.z))}_frameCameraToModel(e,t=!1){const n=this._computeModelBounds();if(!n)return!1;let i=2*n.radius*1.1;(!isFinite(i)||i<=0)&&(i=1),this._camera.nearPlane=.001*i,this._camera.farPlane=1e3*i,this._camera.lowerRadiusLimit=.001*i,this._camera.upperRadiusLimit=5*i;let r=m,s=g,o=i;const a={x:n.center[0],y:n.center[1],z:n.center[2]};if(t){const e=this._options?.cameraOrbit;e&&(null==e[0]||isNaN(e[0])||(r=e[0]),null==e[1]||isNaN(e[1])||(s=e[1]),null==e[2]||isNaN(e[2])||(o=e[2]));const t=this._options?.cameraTarget;t&&(null==t[0]||isNaN(t[0])||(a.x=t[0]),null==t[1]||isNaN(t[1])||(a.y=t[1]),null==t[2]||isNaN(t[2])||(a.z=t[2]))}return this._moveCameraTo({alpha:r,beta:s,radius:o,target:a},e),!0}_computeModelBounds(){if(!this._container)return null;if(this._cachedModelBounds)return this._cachedModelBounds;const e=co(this._container);if(0===e.length)return null;const t=function(e,t=null,n=null,i=1/6){const r=e.map(Aa),s=e.map(()=>({minimum:[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY],maximum:[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY]})),o=new Float32Array(16),a=()=>{for(let t=0;t<e.length;t++){const n=r[t],i=e[t].worldMatrix;if(n.bones){const r=e[t].skeleton.boneMatrices;for(const e of n.bones)ln(o,0,i,0,r,16*e.boneIndex),Ma(e.corners,o,s[t])}else n.corners&&Ma(n.corners,i,s[t])}};if(t&&t.duration>0){const e=t.frameRate||60,r=t.currentTime,s=t.isPlaying,o=t._stopped,l=Math.max(i,.001),c=n??void 0;t._stopped=!1;for(let n=0;n<=t.duration;n+=l)va(t,n*e,c),a();va(t,r*e,c),t._stopped=o,t.isPlaying=s}else a();return s}(e,this._getActiveAnimationGroup(),this._engine);let n=1/0,i=1/0,r=1/0,s=-1/0,o=-1/0,a=-1/0;for(const e of t)e.minimum[0]>e.maximum[0]||(e.minimum[0]<n&&(n=e.minimum[0]),e.minimum[1]<i&&(i=e.minimum[1]),e.minimum[2]<r&&(r=e.minimum[2]),e.maximum[0]>s&&(s=e.maximum[0]),e.maximum[1]>o&&(o=e.maximum[1]),e.maximum[2]>a&&(a=e.maximum[2]));if(n>s)return null;const l=s-n,c=o-i,u=a-r,h=Math.sqrt(l*l+c*c+u*u)/2;return this._cachedModelBounds={min:[n,i,r],max:[s,o,a],center:[(n+s)/2,(i+o)/2,(r+a)/2],radius:h},this._cachedModelBounds}_applyEnvironmentIntensity(){}_applyEnvironmentBlur(){null!==this._currentSkyboxUrl&&Ai(this._scene,this._environmentBlur)}_applyEnvironmentRotation(){Si(this._scene,this._environmentRotation),this._rotateShadowLightWithEnvironment()}async _loadEnvironmentImpl(e,n,i,r){const s=n.lighting,o=n.skybox,a=s?e??null:this._currentLightingUrl,l=o?e??null:this._currentSkyboxUrl;if(a!==this._currentLightingUrl||l!==this._currentSkyboxUrl)try{if(null!==this._currentLightingUrl&&a!==this._currentLightingUrl){throw new Error(`Babylon Lite cannot ${null===a?"remove":"replace"} the loaded environment lighting ("${this._currentLightingUrl}"${null===a?"":` → "${a}"`}). Recreate the Viewer to change the environment.`)}if(null!==this._currentSkyboxUrl&&l!==this._currentSkyboxUrl){throw new Error(`Babylon Lite cannot ${null===l?"remove":"replace"} the loaded environment skybox ("${this._currentSkyboxUrl}"${null===l?"":` → "${l}"`}). Recreate the Viewer to change the environment.`)}const e=!s&&o&&null===this._currentLightingUrl?l??"auto":a??"auto",t="auto"===e?(await import("./defaultEnvironment-DPUnnTO0.esm.min.js")).default:e,u=function(e,t){if(t)return t.startsWith(".")?t:`.${t}`;const n=e.lastIndexOf(".");return n>=0?e.substring(n).toLowerCase():""}(t,n.extension);if(Si(this._scene,this._environmentRotation),null!==l&&Ai(this._scene,this._environmentBlur),".hdr"===u&&!o)throw new Error("Babylon Lite cannot load only the lighting from a .hdr URL — `loadHdrEnvironment` always builds a skybox. Update lighting and skybox together, or use a .env URL.");if(".hdr"===u)await async function(e,t,n){const i=e.surface.engine,r=n?.faceSize??256,s=await fetch(t).then(e=>e.arrayBuffer()),o=vo(s),a=xo(o.data,o.width,o.height),l=So(i,Mo(i,o,r),r,zi(r,r)),c=Eo(i),u=go(l,c,a,1,i);return e._envTextures=u,gi(e),Ti(l),Ti(c),e._disposables.push(()=>{Bi(l),Bi(c)}),e.imageProcessing.toneMappingEnabled=!1,e.imageProcessing.exposure=.8,e.imageProcessing.contrast=1.2,i._dlr?.h(e,t,r),e._deferredBuilders.push(async()=>{if(u.specularCubeView){let t=n?.skyboxSize,i=n?.skyboxPosition;if(void 0===t||void 0===i){const{computeSceneSize:n}=await Promise.resolve().then(function(){return fo}),r=n(e,t);t=r.skyboxSize,i=r.rootPosition}const r=e.environmentPrimaryColor??[.08697355964132344,.08697355964132344,.2122208331110881],{buildHdrSkyboxRenderable:s}=await import("./background-hdr-skybox-BTd3RR4P.esm.min.js");e._renderables.push(await s(e,u,t/2,i,r))}}),u}(this._scene,t,{useCubemapSkybox:!0,skipGround:!0,skyboxSize:20}),this._currentLightingUrl=e,this._currentSkyboxUrl=e;else{const n="auto"===l?(await import("./defaultEnvironment-DPUnnTO0.esm.min.js")).default:l??void 0;await async function(e,t,n){const i=e.surface.engine,r=fetch(t).then(e=>e.arrayBuffer()),s=mo(n.brdfUrl),o=await r,{faceBlobs:a,irradianceSH:l,width:c,mipCount:u}=po(o),h=await Promise.all(a.map(e=>createImageBitmap(e,{premultiplyAlpha:"none",colorSpaceConversion:"none"}))),d=await import("./rgbd-decode-D4WHAcMb.esm.min.js"),p=d.uploadCubemapRGBD(i,h,c,u);for(const e of h)e.close();const _=await s,f=d.decodeBrdfPng(i,_);_.close();const m=go(p,f,l,.8,i);e._envTextures=m,gi(e),Ti(p),Ti(f),e._disposables.push(()=>{Bi(p),Bi(f)}),e.imageProcessing.toneMappingEnabled=!0,e.imageProcessing.exposure=.8,e.imageProcessing.contrast=1.2;const g=n?.groundTextureUrl;g&&fetch(g).then(e=>e.blob()).then(e=>createImageBitmap(e,{premultiplyAlpha:"none"}));const b=n?.skyboxUrl,v=null!=b&&b.toLowerCase().endsWith(".dds"),y=null!=b&&(b===t||b.toLowerCase().endsWith(".env")),w=v||y||n?.skipSkybox;return i._dlr?.e(e,t,n.brdfUrl),e._deferredBuilders.push(async()=>{const t=e.environmentPrimaryColor??[.08697355964132344,.08697355964132344,.2122208331110881],{groundSize:i,skyboxSize:r,rootPosition:s}=_o(e,n?.skyboxSize),o=r/2;if(!w){const n=await import("./background-solid-skybox-BlAFqRVA.esm.min.js");e._renderables.push(n.buildSolidSkyboxRenderable(e,m,o,s,t))}if(v){const n=await import("./background-dds-skybox-De6RohmZ.esm.min.js");e._renderables.push(await n.buildDdsSkyboxRenderable(e,o,s,t,b))}if(y){const n=await import("./background-hdr-skybox-BTd3RR4P.esm.min.js");e._renderables.push(await n.buildHdrSkyboxRenderable(e,m,o,s,t))}}),m}(this._scene,t,{brdfUrl:(await import("./defaultBRDF-BCnyNPOr.esm.min.js")).default,skyboxUrl:n,skipSkybox:!o,skipGround:!0,skyboxSize:20}),this._currentLightingUrl=e,o&&(this._currentSkyboxUrl=l)}this._applyImageProcessingToScene(),this._sceneRegistered&&await this._beginRendering(),this._sceneRegistered&&this._container&&await this._rebuildModelPbrForEnvironment(),c(i,r),this.onEnvironmentChanged.notifyObservers()}catch(e){throw e instanceof t||this.onEnvironmentError.notifyObservers(e),e}}get postProcessing(){return{toneMapping:this._toneMapping,contrast:this._contrast,exposure:this._exposure,ssao:this._ssaoOption}}set postProcessing(e){let t=!1;void 0!==e.toneMapping&&e.toneMapping!==this._toneMapping&&(this._toneMapping=e.toneMapping,t=!0),void 0!==e.exposure&&e.exposure!==this._exposure&&(this._exposure=e.exposure,t=!0),void 0!==e.contrast&&e.contrast!==this._contrast&&(this._contrast=e.contrast,t=!0),void 0!==e.ssao&&e.ssao!==this._ssaoOption&&(this._ssaoOption=e.ssao,"disabled"!==e.ssao&&r.Warn("Viewer: SSAO is not supported by Babylon Lite."),t=!0),t&&(this._applyImageProcessingDynamic(),this.onPostProcessingChanged.notifyObservers())}_applyImageProcessingDynamic(){u(this._pbrRebuildLock.lockAsync(async()=>await async function(e,t){const n=e.imageProcessing,i=n.toneMappingEnabled,r=n.toneMapping?.id??Os.id;Object.assign(n,t);const s=n.toneMappingEnabled!==i,o=n.toneMapping?.id??Os.id,a=n.toneMappingEnabled&&o!==r;(s||a)&&await Ss(e)}(this._scene,this._liteImageProcessingUpdate())))}async _rebuildModelPbrForEnvironment(){await this._pbrRebuildLock.lockAsync(async()=>{await Ss(this._scene)})}_liteImageProcessingUpdate(){const e=function(e){switch(e){case"standard":return Os;case"aces":return Ts;case"neutral":return Bs;case"none":return}}(this._toneMapping);return{toneMappingEnabled:void 0!==e,toneMapping:e,exposure:this._exposure,contrast:this._contrast}}_applyImageProcessingToScene(){Object.assign(this._scene.imageProcessing,this._liteImageProcessingUpdate())}async updateShadows(e,t){if("high"===e.quality)throw new Error("Babylon Lite does not support 'high' shadow quality. Use 'normal' or 'none'.");return await super.updateShadows(e,t)}async _updateShadowsImpl(e,t,n){r.Warn("Babylon Lite cannot toggle shadow quality after the model is loaded. Set `shadowConfig.quality` in the viewer constructor options instead, or recreate the viewer to change shadow rendering.")}async _setupShadows(e,t){if(!this._container||"none"===this._shadowQuality)return;const n=[...this._scene.meshes];if(0===n.length)return;const i=n.some(e=>!!e.morphTargets),r=n.some(e=>!!e.skeleton),s=i||r?await import("./viewerShadows-Dn87sbg2.esm.min.js"):void 0;c(e,t);const o=this._computeModelBounds()??{min:[-1,-1,-1],center:[0,0,0],radius:1},a=o.min[1],[l,u,h]=o.center,d=o.radius,p=[...Za],_=Math.sqrt(p[0]**2+p[1]**2+p[2]**2),f=3*d,m=Ji(p,1);m.position.set(l-p[0]/_*f,u-p[1]/_*f,h-p[2]/_*f),Hn(this._scene,m),this._shadowLight=m,this._rotateShadowLightWithEnvironment();const g=1e3*d,b=Hr(this._engine,{radius:g,tessellation:64});b.rotation.x=Math.PI/2,b.position.y=a,b.receiveShadows=!0;const v=fs({});var y,w;w={color:[0,0,0],opacity:.3,falloff:1},(y=v)._shadowOnly=!0,w?.color&&(y._shadowOnlyColor=w.color),void 0!==w?.opacity&&(y._shadowOnlyOpacity=w.opacity),void 0!==w?.falloff&&(y._shadowOnlyFalloff=w.falloff),Ir(bs),b.material=v,Hn(this._scene,b),this._shadowGround=b;const x=100*f;this._shadowGenerator=Yo(this._engine,m,{orthoMinZ:0,orthoMaxZ:x,blurKernel:48}),i&&s?.enableMorphTargetShadows(this._shadowGenerator),r&&s?.enableSkeletonShadows(this._shadowGenerator),ws(this._shadowGenerator,n),m.shadowGenerator=this._shadowGenerator??void 0}_rotateShadowLightWithEnvironment(){const e=this._shadowLight,t=this._computeModelBounds();if(!e||!t)return;const n=-this._environmentRotation,i=Math.cos(n),r=Math.sin(n),s=Za[0]*i+Za[2]*r,o=Za[1],a=-.12*r+Za[2]*i,l=Math.sqrt(s**2+o**2+a**2),c=3*t.radius,[u,h,d]=t.center;e.direction.set(s,o,a),e.position.set(u-s/l*c,h-o/l*c,d-a/l*c)}async _loadModelImpl(e,n,i,s){if(void 0===e){const e=null!==this._modelSource;return this._unloadCurrentModel(),void(e&&this.onModelChanged.notifyObservers(null))}const o=this._beginLoadOperation();try{if("string"!=typeof e)throw r.Warn("Viewer: Only string URLs are supported for model loading. File and ArrayBufferView sources are not supported."),new Error("Unsupported model source type");this._unloadCurrentModel();const t=e;if(n?.pluginExtension){const e=n.pluginExtension.startsWith(".")?n.pluginExtension:`.${n.pluginExtension}`;t.toLowerCase().endsWith(e.toLowerCase())}const o=await ao(this._engine,t);c(i,s),this._container=o,this._modelSource=e,this._setupAnimations(),Hn(this._scene,o),this._frameCameraToModel(!1,!0),"none"!==this._shadowQuality&&await this._setupShadows(i,s),this._sceneRegistered&&"none"===this._shadowQuality&&this._modelMaterialGroupBuilt||await this._beginRendering(),this._modelMaterialGroupBuilt=!0,o.clearColor&&(this._scene.clearColor=o.clearColor,this.onClearColorChanged.notifyObservers()),this._options?.selectedMaterialVariant&&(this.selectedMaterialVariant=this._options.selectedMaterialVariant),this.onModelChanged.notifyObservers(e)}catch(e){throw e instanceof t||this.onModelError.notifyObservers(e),e}finally{o.dispose()}}_unloadCurrentModel(){if(this._selectedAnimation=-1,this._wasPlaying=!1,this._lastProgress=-1,this._container){null!==this._selectedMaterialVariant&&(uo(this._container),this._selectedMaterialVariant=null);const e=this._container.animationGroups;if(e){for(const t of e)_a(t);for(const t of e){const e=this._scene.animationGroups.indexOf(t);e>=0&&this._scene.animationGroups.splice(e,1)}}for(const e of co(this._container))li(this._scene,e)}if(this._shadowGround&&(li(this._scene,this._shadowGround),Kt(this._shadowGround),this._shadowGround=null),this._shadowLight){const e=this._scene.lights.indexOf(this._shadowLight);e>=0&&this._scene.lights.splice(e,1),this._shadowLight=null}this._shadowGenerator=null,this._container=null,this._modelSource=null,this._cachedModelBounds=null}get animations(){const e=this._container?.animationGroups;return e&&0!==e.length?e.map(e=>e.name):[]}get selectedAnimation(){return this._selectedAnimation}set selectedAnimation(e){const t=this._container?.animationGroups;if(!t||0===t.length)return this._selectedAnimation=-1,void this.onSelectedAnimationChanged.notifyObservers();const n=e>=0&&e<t.length?e:-1;if(n===this._selectedAnimation)return;const i=this._getActiveAnimationGroup(),r=i?.isPlaying??!1;this._selectedAnimation=n,this._isolateSelectedAnimation(),this._cachedModelBounds=null,this._frameCameraToModel(!0),this.onSelectedAnimationChanged.notifyObservers(),r&&this.playAnimation()}get animationSpeed(){return this._animationSpeed}set animationSpeed(e){this._animationSpeed=e;const t=this._getActiveAnimationGroup();t&&(t.speedRatio=e),this.onAnimationSpeedChanged.notifyObservers()}get isAnimationPlaying(){const e=this._getActiveAnimationGroup();return!!e&&e.isPlaying}get animationProgress(){const e=this._getActiveAnimationGroup();return!e||e.duration<=0?0:Math.min(e.currentTime/e.duration,1)}set animationProgress(e){const t=this._getActiveAnimationGroup();if(!t||t.duration<=0)return;va(t,60*(e*t.duration)),this.onAnimationProgressChanged.notifyObservers()}toggleAnimation(){this.isAnimationPlaying?u(this.pauseAnimation()):this.playAnimation()}playAnimation(){const e=this._getActiveAnimationGroup();e&&(e.speedRatio=this._animationSpeed,e.loopAnimation=!0,da(e),this.onIsAnimationPlayingChanged.notifyObservers())}async pauseAnimation(){const e=this._getActiveAnimationGroup();e&&(pa(e),this.onIsAnimationPlayingChanged.notifyObservers())}_getActiveAnimationGroup(){const e=this._container?.animationGroups;return!e||this._selectedAnimation<0||this._selectedAnimation>=e.length?null:e[this._selectedAnimation]}_isolateSelectedAnimation(){const e=this._container?.animationGroups;if(e)for(let t=0;t<e.length;t++){const n=e[t];t===this._selectedAnimation?(da(n),pa(n)):_a(n)}}_setupAnimations(){const e=this._container?.animationGroups;if(!e||0===e.length)return void(this._selectedAnimation=-1);const t=this._options?.selectedAnimation??0;this._selectedAnimation=t>=0&&t<e.length?t:0,this._isolateSelectedAnimation(),this.onSelectedAnimationChanged.notifyObservers(),this._options?.animationAutoPlay&&this.playAnimation()}_pollAnimationState(){const e=this._getActiveAnimationGroup();if(!e)return;const t=e.isPlaying;if(t!==this._wasPlaying&&(this._wasPlaying=t,this.onIsAnimationPlayingChanged.notifyObservers()),t){const t=e.duration>0?e.currentTime/e.duration:0;t!==this._lastProgress&&(this._lastProgress=t,this.onAnimationProgressChanged.notifyObservers())}}get materialVariants(){return this._container?(e=this._container,e.materialVariants?.names??[]):[];var e}get selectedMaterialVariant(){return this._selectedMaterialVariant}set selectedMaterialVariant(e){e!==this._selectedMaterialVariant&&(this._selectedMaterialVariant=e,this._container&&(null===e?uo(this._container):function(e,t){const n=e.materialVariants;if(!n)return;for(const e of n.originals)e.mesh.material=e.material;const i=n.variants[t];if(i)for(const e of i)e.mesh.material=e.material}(this._container,e)),this.onSelectedMaterialVariantChanged.notifyObservers())}get camerasAsHotSpots(){return this._camerasAsHotSpots}set camerasAsHotSpots(e){e!==this._camerasAsHotSpots&&(this._camerasAsHotSpots=e,this.onCamerasAsHotSpotsChanged.notifyObservers())}queryHotSpot(e,t){return null!=this._queryHotSpot(e,t)}focusHotSpot(e){const t=new _,n=this._queryHotSpot(e,t);if(!n)return!1;u(this.pauseAnimation());const i=n.cameraOrbit,r=null==i?.[0]?void 0:Number(i[0]),s=null==i?.[1]?void 0:Number(i[1]),o=null==i?.[2]?void 0:Number(i[2]);return this._interpolateCameraTo({alpha:r,beta:s,radius:o,target:{x:t.worldPosition[0],y:t.worldPosition[1],z:t.worldPosition[2]}}),!0}_interpolateCameraTo(e){this._cameraInterpolationAbort?.abort(new t("Camera interpolation superseded."));const n=new AbortController;this._cameraInterpolationAbort=n,(async()=>{try{await Xi(this._camera,this._scene,e,n.signal)}catch{}finally{this._cameraInterpolationAbort===n&&(this._cameraInterpolationAbort=null)}})()}_queryHotSpot(e,t){const n=this.hotSpots[e];if(!n)return null;const i=tl,r=nl;if("surface"===n.type){const e=(this._container?co(this._container):[])[n.meshIndex-1];if(!e)return null;if(!this._getSurfaceHotSpotToRef(e,n.pointIndex,n.barycentric,i,r))return null}else i.x=n.position[0],i.y=n.position[1],i.z=n.position[2],r.x=n.normal[0],r.y=n.normal[1],r.z=n.normal[2];const s=this._engine.canvas,o=s.width||1,a=s.height||1,l=s.clientWidth||o,c=s.clientHeight||a,u=function(e,t,n){const i=e?.viewport;return t/n*(i?i.width/i.height:1)}(this._camera,o,a),h=dn(this._camera,u),d=h[0]*i.x+h[4]*i.y+h[8]*i.z+h[12],p=h[1]*i.x+h[5]*i.y+h[9]*i.z+h[13],_=h[3]*i.x+h[7]*i.y+h[11]*i.z+h[15];if(_<=0)t.screenPosition[0]=NaN,t.screenPosition[1]=NaN;else{const e=d/_,n=p/_;t.screenPosition[0]=(e+1)/2*l,t.screenPosition[1]=(1-n)/2*c}t.worldPosition[0]=i.x,t.worldPosition[1]=i.y,t.worldPosition[2]=i.z;const f=pn(this._camera);let m=f.x-i.x,g=f.y-i.y,b=f.z-i.z;const v=Math.hypot(m,g,b)||1;return m/=v,g/=v,b/=v,t.visibility=m*r.x+g*r.y+b*r.z,n}_getSurfaceHotSpotToRef(e,t,n,i,r){const s=Ka,o=Ja,a=el;if(!Ua(e,t[0],s)||!Ua(e,t[1],o)||!Ua(e,t[2],a))return!1;const l=s.x*n[0]+o.x*n[1]+a.x*n[2],c=s.y*n[0]+o.y*n[1]+a.y*n[2],u=s.z*n[0]+o.z*n[1]+a.z*n[2],h=o.x-s.x,d=o.y-s.y,p=o.z-s.z,_=a.x-s.x,f=a.y-s.y,m=a.z-s.z,g=d*m-p*f,b=p*_-h*m,v=h*f-d*_,y=e.worldMatrix;i.x=y[0]*l+y[4]*c+y[8]*u+y[12],i.y=y[1]*l+y[5]*c+y[9]*u+y[13],i.z=y[2]*l+y[6]*c+y[10]*u+y[14];const w=y[0]*g+y[4]*b+y[8]*v,x=y[1]*g+y[5]*b+y[9]*v,C=y[2]*g+y[6]*b+y[10]*v,A=Math.hypot(w,x,C)||1;return r.x=w/A,r.y=x/A,r.z=C/A,!0}get isModelLoaded(){return null!==this._container}_resetEnvironment(){this.environmentConfig={intensity:this._options?.environmentConfig?.intensity??Xa.environmentConfig.intensity,blur:this._options?.environmentConfig?.blur??Xa.environmentConfig.blur,rotation:this._options?.environmentConfig?.rotation??Xa.environmentConfig.rotation},u(this.resetEnvironment());const e=this._options?.environmentLighting??Xa.environmentLighting,t=this._options?.environmentSkybox??Xa.environmentSkybox;e===t?"none"!==e&&u(this.loadEnvironment(e)):("none"!==e&&u(this.loadEnvironment(e,{lighting:!0,skybox:!1})),"none"!==t&&u(this.loadEnvironment(t,{lighting:!1,skybox:!0})))}_resetAnimation(){const e=this._container?.animationGroups;e&&e.length>0&&(this._selectedAnimation=this._options?.selectedAnimation??0,this._animationSpeed=this._options?.animationSpeed??1,this._isolateSelectedAnimation(),this.onSelectedAnimationChanged.notifyObservers(),this.onAnimationSpeedChanged.notifyObservers(),this._options?.animationAutoPlay&&this.playAnimation())}_resetCamera(e){this._resetCameraCore(void 0,e),this.cameraAutoOrbit=this._options?.cameraAutoOrbit?{enabled:this._options.cameraAutoOrbit.enabled??Xa.cameraAutoOrbit.enabled,speed:this._options.cameraAutoOrbit.speed??Xa.cameraAutoOrbit.speed,delay:this._options.cameraAutoOrbit.delay??Xa.cameraAutoOrbit.delay}:{...Xa.cameraAutoOrbit}}_resetPostProcessing(){this.postProcessing={toneMapping:this._options?.postProcessing?.toneMapping??Xa.postProcessing.toneMapping,contrast:this._options?.postProcessing?.contrast??Xa.postProcessing.contrast,exposure:this._options?.postProcessing?.exposure??Xa.postProcessing.exposure,ssao:this._options?.postProcessing?.ssao??Xa.postProcessing.ssao}}async _beginRendering(){await this._renderLoopLock.lockAsync(async()=>{this._isDisposed||(this._stopRenderLoop(),this._sceneRegistered&&(Qn(this._scene),this._sceneRegistered=!1),"none"===this._shadowQuality?await async function(e){const t=e,n=t.surface;$t(n,t)||(await qn(e),t._renderables.sort(Yn),await Promise.all(t._frameGraph._tasks.map(e=>e._preload?.())),t._frameGraph.build(),n._renderingContexts[0]&&(await import("./swapchain-overlay-CKIgRD0Z.esm.min.js")).configureSwapchainOverlayScene(n,t),jn?.get(t)?.()||Nt(n,t))}(this._scene):await Xn(this._scene),this._isDisposed||(this._sceneRegistered=!0,await this._startRenderLoop()))})}async _startRenderLoop(){if(this._renderLoopRunning||this._isDisposed||this._suspendRenderCount>0)return;this._renderLoopRunning=!0;const e=Gt(this._engine),t=new Promise(e=>this._renderLoopStopped=e);await Promise.race([e,t]),this._renderLoopStopped=null}_stopRenderLoop(){this._renderLoopRunning&&(Ut(this._engine),this._renderLoopRunning=!1),this._renderLoopStopped?.(),this._renderLoopStopped=null}_suspendRendering(){0===this._suspendRenderCount++&&u(this._renderLoopLock.lockAsync(()=>this._stopRenderLoop()));let e=!1;return{dispose:()=>{e||(e=!0,0===--this._suspendRenderCount&&u(this._renderLoopLock.lockAsync(async()=>await this._startRenderLoop())))}}}dispose(){this._isDisposed||(this._deviceLostRecovery.disable(),this._detachControl?.(),this._detachControl=null,this._cameraInterpolationAbort?.abort(new t("Viewer disposed.")),this._cameraInterpolationAbort=null,this._engine.canvas.removeEventListener("pointerdown",this._onPointerActivity),this._engine.canvas.removeEventListener("pointermove",this._onPointerActivity),this._engine.canvas.removeEventListener("wheel",this._onPointerActivity),this._engine.canvas.removeEventListener("dblclick",this._onCanvasDoubleClick),this._picker&&(Na(this._picker),this._picker=null),this._unloadCurrentModel(),this._stopRenderLoop(),Qn(this._scene),this._sceneRegistered=!1,function(e){const t=e;if(t._z)return;t._z=!0;const n=jn??=new WeakMap;n.set(t,()=>1),Vt(t.surface,t),(()=>{n.set(t,()=>{for(const e of t._meshDisposables.values())e.forEach(e=>e());for(const e of t._meshAuxDisposables.values())e.forEach(e=>e());return t._meshDisposables.clear(),t._meshAuxDisposables.clear(),t._disposables.splice(0).forEach(e=>e()),t._renderables.length=t._uniformUpdaters.length=0,1});for(const e of t._disposables)e();for(const e of t._meshDisposables.values())for(const t of e)t();t._meshDisposables.clear();for(const e of t._meshAuxDisposables.values())for(const t of e)t();t._meshAuxDisposables.clear();for(const e of t.meshes)nn(t,e)&&Kt(e);t._groups.clear(),t.meshes.length=0,t._renderables.length=0,t._prePasses.length=0,t._pickSources.length=0,t._uniformUpdaters.length=0,t._beforeRender.length=0,t._deferredBuilders.length=0,t._disposables.length=0,t._materialSwapQueue.length=0,t.lights.length=0,t.animationGroups.length=0,t.shadowGenerators.length=0,t.camera=null})()}(this._scene),function(e){Lt(e),Ut(e);const t=e._surfaces;for(const e of t)e._renderingContexts.length=0,e._ro?.disconnect(),e._context.unconfigure();t.length=0,e._disposeStorageBuffers?.(),e._device.destroy()}(this._engine),super.dispose())}async _handleDoubleClick(e,t){if(this._container){const n=new Set(co(this._container));this._picker??={_detailedPicking:!1,_device:null,_scene:this._scene,_rt:null,_sceneUbo:null,_sceneBG:null,_contributors:null,_pending:null};const i=await function(e,t,n,i){const r=(e._pending??Promise.resolve()).then(()=>$a(e,t,n,i),()=>$a(e,t,n,i));return e._pending=r.then(()=>{},()=>{}),r}(this._picker,e,t,{filter:e=>n.has(e)});if(this._isDisposed)return;if(i.hit&&i.pickedPoint)return void this._focusCameraOnPoint(i.pickedPoint)}this.resetCamera(!0)}_focusCameraOnPoint(e){const t=pn(this._camera),n=this._camera.target;let i=n.x-t.x,r=n.y-t.y,s=n.z-t.z;const o=Math.hypot(i,r,s)||1;i/=o,r/=o,s/=o;const a=(e[0]-t.x)*i+(e[1]-t.y)*r+(e[2]-t.z)*s;n.x=t.x+i*a,n.y=t.y+r*a,n.z=t.z+s*a,this._camera.radius=a,this._interpolateCameraTo({target:{x:e[0],y:e[1],z:e[2]}})}_updateAutoOrbit(e){if(!this._autoOrbitEnabled||this._cameraInterpolationAbort)return void(this._autoOrbitIdleTime=0);if(performance.now()-this._lastPointerTime<this._autoOrbitDelay)return void(this._autoOrbitIdleTime=0);this._autoOrbitIdleTime+=e;const t=this._autoOrbitSpeed*e/1e3;this._camera.alpha+=t}}async function rl(e,t){const n=await Ft(e,{alphaMode:"premultiplied"}),i=new il(n,t),r=function(e,t){let n=null;const i=new IntersectionObserver(e=>{e.length>0&&(e[e.length-1].isIntersecting?(n?.dispose(),n=null):n??=t())});return i.observe(e),{dispose:()=>i.disconnect()}}(e,()=>i._suspendRendering()),s=i.dispose.bind(i);return i.dispose=()=>{r.dispose(),s()},i}class sl extends tt{constructor(e={}){super(e)}get viewer(){return this._viewer}async _createViewer(e,t){return await rl(e,t)}}let ol=(()=>{let e,t,n=[A("babylon-viewer")],i=[],r=sl;return t=class extends r{constructor(e){super(e)}},w(t,"HTML3DElement"),(()=>{const s="function"==typeof Symbol&&Symbol.metadata?Object.create(r[Symbol.metadata]??null):void 0;v(null,e={value:t},n,{kind:"class",name:t.name,metadata:s},null,i),t=e.value,s&&Object.defineProperty(t,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:s}),y(t,i)})(),t})();function al(e,t){customElements.define(e,class extends ol{constructor(){super(t)}})}let ll=(()=>{var e;let t,n,i,r=[A("babylon-viewer-annotation")],s=[],o=$e,a=[],l=[];return n=class extends o{get hotSpot(){return x(this,e,"f")}set hotSpot(t){C(this,e,t,"f")}connectedCallback(){super.connectedCallback(),this._internals.states?.add("invalid"),this._connectingAbortController?.abort(),this._connectingAbortController=new AbortController;const e=this._connectingAbortController.signal;(async()=>{if(this.parentElement?.matches(":not(:defined)")&&(await customElements.whenDefined(this.parentElement?.tagName.toLowerCase()),e.aborted))return;if(!(this.parentElement instanceof tt))return void console.warn("The babylon-viewer-annotation element must be a child of a babylon-viewer element.");this._mutationObserver.observe(this,{childList:!0,characterData:!0}),this._sanitizeInnerHTML();const t=this.parentElement,n=new _,i=this._updateAnnotation=()=>{if(this.hotSpot)if(t.queryHotSpot(this.hotSpot,n)){const[e,t]=n.screenPosition;this.style.transform=`translate(${e}px, ${t}px)`,this._internals.states?.delete("invalid"),n.visibility<=0?this._internals.states?.add("back-facing"):this._internals.states?.delete("back-facing")}else this._internals.states?.add("invalid")};this._updateAnnotation(),t.addEventListener("viewerrender",i),this._viewerAttachment={dispose(){t.removeEventListener("viewerrender",i)}}})()}disconnectedCallback(){super.disconnectedCallback(),this._connectingAbortController?.abort(),this._connectingAbortController=null,this._viewerAttachment?.dispose(),this._viewerAttachment=null,this._internals.states?.add("invalid"),this._updateAnnotation=null}render(){return be`<slot><div aria-label="${this.hotSpot} annotation" part="annotation" class="annotation">${this.hotSpot}</div></slot>`}update(e){super.update(e),e.has("hotSpot")&&this._updateAnnotation?.()}_sanitizeInnerHTML(){0===this.innerHTML.trim().length&&(this.innerHTML="")}constructor(){super(...arguments),this._internals=this.attachInternals(),this._mutationObserver=new MutationObserver(e=>{e.some(e=>"childList"===e.type)&&this._sanitizeInnerHTML()}),this._viewerAttachment=null,this._connectingAbortController=null,this._updateAnnotation=null,e.set(this,y(this,a,"")),y(this,l)}},e=new WeakMap,w(n,"HTML3DAnnotationElement"),(()=>{const e="function"==typeof Symbol&&Symbol.metadata?Object.create(o[Symbol.metadata]??null):void 0;i=[Y({attribute:"hotspot"})],v(n,null,i,{kind:"accessor",name:"hotSpot",static:!1,private:!1,access:{has:e=>"hotSpot"in e,get:e=>e.hotSpot,set:(e,t)=>{e.hotSpot=t}},metadata:e},a,l),v(null,t={value:n},r,{kind:"class",name:n.name,metadata:e},null,s),n=t.value,e&&Object.defineProperty(n,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:e})})(),n.styles=O`:host{--annotation-foreground-color:black;--annotation-background-color:white;display:inline-block;position:absolute;transition:opacity .25s}:host([hidden]){display:none}:host(:state(back-facing)){opacity:.2}:host(:state(invalid)){display:none}.annotation{transform:translate(-50%,-135%);font-size:14px;padding:0 6px;border-radius:6px;color:var(--annotation-foreground-color);background-color:var(--annotation-background-color)}.annotation::after{content:"";position:absolute;left:50%;height:60%;aspect-ratio:1;transform:translate(-50%,110%) rotate(-45deg);background-color:inherit;clip-path:polygon(0 0,100% 100%,0 100%,0 0)}`,y(n,s),n})();export{sr as $,Cr as A,gt as B,_r as C,qr as D,ir as E,it as F,ts as G,yr as H,ot as I,Zr as J,Jr as K,kn as L,Mn as M,es as N,lr as O,nr as P,or as Q,Kr as R,An as S,nt as T,at as U,Tr as V,Or as W,pr as X,Er as Y,ar as Z,xs as _,rt as a,Ws as a$,cr as a0,ns as a1,Qr as a2,mr as a3,ur as a4,hr as a5,kr as a6,$n as a7,Ir as a8,Vr as a9,Qs as aA,ft as aB,ln as aC,Ea as aD,Ut as aE,Lt as aF,Pt as aG,zt as aH,Gt as aI,rr as aJ,go as aK,Ti as aL,Bi as aM,mo as aN,po as aO,Xr as aP,Yr as aQ,Rt as aR,dn as aS,fr as aT,br as aU,gr as aV,Ar as aW,xr as aX,wr as aY,ht as aZ,Sn as a_,Os as aa,ls as ab,Ri as ac,_s as ad,is as ae,cs as af,vn as ag,Mr as ah,hs as ai,ms as aj,Ei as ak,Oi as al,us as am,Vs as an,Ur as ao,st as ap,Fs as aq,dt as ar,Gs as as,Ds as at,Ls as au,Zs as av,Ks as aw,qt as ax,Vi as ay,ps as az,gn as b,ii as b0,ni as b1,Fr as b2,Dr as b3,ri as b4,ti as b5,zr as b6,vt as b7,Dt as b8,cn as b9,pn as bA,Ao as bB,Ys as bC,Hs as bD,Js as bE,qs as bF,al as bG,rl as bH,Xa as bI,ll as bJ,ol as bK,il as bL,sl as bM,_ as bN,er as bO,Es as bP,Co as bQ,Oo as bR,Qo as bS,ya as bT,hn as ba,ut as bb,lt as bc,Gi as bd,Jn as be,Ns as bf,Jo as bg,Ko as bh,Zo as bi,ia as bj,na as bk,ta as bl,ea as bm,js as bn,ra as bo,Qt as bp,Kn as bq,Nr as br,xt as bs,Un as bt,It as bu,Di as bv,dr as bw,Qi as bx,Zi as by,Ki as bz,Wr as c,xn as d,Bn as e,Cn as f,mn as g,Cs as h,$t as i,wn as j,yi as k,bn as l,Sa as m,bt as n,mt as o,ct as p,Ii as q,Tt as r,Ln as s,wt as t,In as u,Rr as v,tr as w,Pr as x,Sr as y,vr as z};
//# sourceMappingURL=index-B8IgtevW.esm.min.js.map