import{d as t,V as A,Q as F,M as b,L as g,aN as L,aO as M}from"./index-6jOCfdig.js";import{GLTFLoader as V,ArrayItem as w}from"./glTFLoader-Bx351I09.js";import"./thinInstanceMesh-Dh3xKL92.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"./bone-DdTyU8i_.js";import"./skeleton-C0c5yg7x.js";import"./rawTexture-CpjOe2U7.js";import"./assetContainer-Drc86vic.js";import"./objectModelMapping-DT0r674A.js";const c="EXT_mesh_gpu_instancing";class B{constructor(m){this.name=c,this._loader=m,this.enabled=this._loader.isExtensionUsed(c)}dispose(){this._loader=null}loadNodeAsync(m,s,T){return V.LoadExtensionAsync(m,s,this.name,async(u,f)=>{this._loader._disableInstancedMesh++;const h=this._loader.loadNodeAsync(`/nodes/${s.index}`,s,T);if(this._loader._disableInstancedMesh--,!s._primitiveBabylonMeshes)return await h;const l=new Array;let e=0;const n=i=>{if(f.attributes[i]==null){l.push(Promise.resolve(null));return}const o=w.Get(`${u}/attributes/${i}`,this._loader.gltf.accessors,f.attributes[i]);if(l.push(this._loader._loadFloatAccessorAsync(`/accessors/${o.bufferView}`,o)),e===0)e=o.count;else if(e!==o.count)throw new Error(`${u}/attributes: Instance buffer accessors do not have the same count.`)};return n("TRANSLATION"),n("ROTATION"),n("SCALE"),n("_COLOR_0"),await h.then(async i=>{const[o,d,_,a]=await Promise.all(l),y=new Float32Array(e*16);t.Vector3[0].copyFromFloats(0,0,0),t.Quaternion[0].copyFromFloats(0,0,0,1),t.Vector3[1].copyFromFloats(1,1,1);for(let r=0;r<e;++r)o&&A.FromArrayToRef(o,r*3,t.Vector3[0]),d&&F.FromArrayToRef(d,r*4,t.Quaternion[0]),_&&A.FromArrayToRef(_,r*3,t.Vector3[1]),b.ComposeToRef(t.Vector3[1],t.Quaternion[0],t.Vector3[0],t.Matrix[0]),t.Matrix[0].copyToArray(y,r*16);for(const r of s._primitiveBabylonMeshes)r.thinInstanceSetBuffer("matrix",y,16,!0),a&&(a.length===e*3?r.thinInstanceSetBuffer("color",a,3,!0):a.length===e*4?r.thinInstanceSetBuffer("color",a,4,!0):g.Warn("Unexpected size of _COLOR_0 attribute for mesh "+r.name));return i})})}}L(c);M(c,!0,p=>new B(p));export{B as EXT_mesh_gpu_instancing};
