import{f as g,Q as d,M as y,bd as f,aF as x,aN as b,aO as A}from"./index-6jOCfdig.js";import{_ as w}from"./environmentTextureTools-CmnD6g13.js";import{CubeTexture as T}from"./cubeTexture-YXFzWVC3.js";import{GLTFLoader as S,ArrayItem as u}from"./glTFLoader-Bx351I09.js";import"./index-Ds2meNS5.js";import"./svelte/svelte_svelte.js";import"./svelte/svelte_animate.js";import"./svelte/svelte_attachments.js";import"./svelte/svelte_easing.js";import"./svelte/svelte_internal_client.js";import"./svelte/svelte_internal_flags_async.js";import"./svelte/svelte_internal_flags_legacy.js";import"./svelte/svelte_internal_flags_tracing.js";import"./svelte/svelte_internal_server.js";import"./svelte/svelte_legacy.js";import"./svelte/svelte_motion.js";import"./svelte/svelte_reactivity.js";import"./svelte/svelte_reactivity_window.js";import"./svelte/svelte_server.js";import"./svelte/svelte_store.js";import"./svelte/svelte_transition.js";import"./svelte/svelte_events.js";import"./dumpTools-DaCMxSuy.js";import"./abstractEngine.cubeTexture-IPepzteq.js";import"./bone-DdTyU8i_.js";import"./skeleton-C0c5yg7x.js";import"./rawTexture-CpjOe2U7.js";import"./assetContainer-Drc86vic.js";import"./objectModelMapping-DT0r674A.js";class c extends T{constructor(t,e,a,n=5,r=0,i=!1,o=!1,l=3,s=null){super("",t),this._texture=t.getEngine().createRawCubeTexture(e,a,n,r,i,o,l,s)}update(t,e,a,n,r=null){this._texture.getEngine().updateRawCubeTexture(this._texture,t,e,a,n,r)}updateRGBDAsync(t,e=null,a=.8,n=0){return w(this._texture,t,e,a,n).then(()=>{})}clone(){return g.Clone(()=>{const t=this.getScene(),e=this._texture,a=new c(t,e._bufferViewArray,e.width,e.format,e.type,e.generateMipMaps,e.invertY,e.samplingMode,e._compression);return e.source===13&&a.updateRGBDAsync(e._bufferViewArrayArray,e._sphericalPolynomial,e._lodGenerationScale,e._lodGenerationOffset),a},this)}}const m="EXT_lights_image_based";class I{constructor(t){this.name=m,this._loader=t,this.enabled=this._loader.isExtensionUsed(m)}dispose(){this._loader=null,delete this._lights}onLoading(){const t=this._loader.gltf.extensions;if(t&&t[this.name]){const e=t[this.name];this._lights=e.lights}}loadSceneAsync(t,e){return S.LoadExtensionAsync(t,e,this.name,async(a,n)=>{this._loader._allMaterialsDirtyRequired=!0;const r=new Array;r.push(this._loader.loadSceneAsync(t,e)),this._loader.logOpen(`${a}`);const i=u.Get(`${a}/light`,this._lights,n.light);return r.push(this._loadLightAsync(`/extensions/${this.name}/lights/${n.light}`,i).then(o=>{this._loader.babylonScene.environmentTexture=o})),this._loader.logClose(),await Promise.all(r).then(()=>{})})}_loadLightAsync(t,e){if(!e._loaded){const a=new Array;this._loader.logOpen(`${t}`);const n=new Array(e.specularImages.length);for(let r=0;r<e.specularImages.length;r++){const i=e.specularImages[r];n[r]=new Array(i.length);for(let o=0;o<i.length;o++){const l=`${t}/specularImages/${r}/${o}`;this._loader.logOpen(`${l}`);const s=i[o],h=u.Get(l,this._loader.gltf.images,s);a.push(this._loader.loadImageAsync(`/images/${s}`,h).then(_=>{n[r][o]=_})),this._loader.logClose()}}this._loader.logClose(),e._loaded=Promise.all(a).then(async()=>{const r=new c(this._loader.babylonScene,null,e.specularImageSize);if(r.name=e.name||"environment",e._babylonTexture=r,e.intensity!=null&&(r.level=e.intensity),e.rotation){let s=d.FromArray(e.rotation);this._loader.babylonScene.useRightHandedSystem||(s=d.Inverse(s)),y.FromQuaternionToRef(s,r.getReflectionTextureMatrix())}if(!e.irradianceCoefficients)throw new Error(`${t}: Irradiance coefficients are missing`);const i=f.FromArray(e.irradianceCoefficients);i.scaleInPlace(e.intensity),i.convertIrradianceToLambertianRadiance();const o=x.FromHarmonics(i),l=(n.length-1)/Math.log2(e.specularImageSize);return await r.updateRGBDAsync(n,o,l)})}return e._loaded.then(()=>e._babylonTexture)}}b(m);A(m,!0,p=>new I(p));export{I as EXT_lights_image_based};
