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