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.

3 lines (2 loc) 2.16 kB
import{j as e,ai as o,I as t,F as r}from"./index-DFZFpUG-.esm.min.js";let s=null,n=null;async function c(){return s||(s=(async()=>(await(n||(n=new Promise((e,o)=>{const t=globalThis.DracoDecoderModule;if(t)return void e(t);const r=document.createElement("script");r.src="/draco_decoder.js",r.onload=()=>{const t=globalThis.DracoDecoderModule;t?e(t):o(new Error("draco_decoder.js loaded but DracoDecoderModule is undefined"))},r.onerror=()=>o(new Error("Failed to load draco_decoder.js from "+r.src)),document.head.appendChild(r)}),n)))({locateFile:e=>"/"+e}))(),s)}async function a(e,s,n){const a=await c(),i=new a.Decoder,d=new a.DecoderBuffer;d.Init(e,e.byteLength);const f=new a.Mesh,u=i.DecodeBufferToMesh(d,f);if(!u.ok()){const e=u.error_msg();throw a.destroy(d),a.destroy(f),a.destroy(i),new Error("Draco decode failed: "+e)}const l=f.num_points(),_=3*f.num_faces(),b=4*_,w=a._malloc(b);i.GetTrianglesUInt32Array(f,b,w);const m=new o(a.HEAPU32.buffer,w,_).slice();a._free(w);const y=new Map;for(const e of Object.keys(s)){const o=s[e],c=i.GetAttributeByUniqueId(f,o),d=l*(n[e]??3),u="JOINTS_0"===e||"JOINTS_1"===e,_=d*4,b=a._malloc(_),w=u?a.DT_INT32:a.DT_FLOAT32;i.GetAttributeDataArrayForAllPoints(f,c,w,_,b),u?y.set(e,new t(a.HEAP32.buffer,b,d).slice()):y.set(e,new r(a.HEAPF32.buffer,b,d).slice()),a._free(b)}return a.destroy(d),a.destroy(f),a.destroy(i),{_attributes:y,_indices:m,_vertexCount:l,_indexCount:_}}function i(o,t,r){const s=o.bufferViews[r];if(!s)throw new Error(`Draco bufferView ${r} not found`);const n=t.byteOffset+(s.byteOffset??0);return new e(t.buffer,n,s.byteLength)}const d={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},f={id:"KHR_draco_mesh_compression",async preMesh(e,o){const t=e,r=new Map;for(const e of t.meshes??[])for(const s of e.primitives??[]){const e=s.extensions?.KHR_draco_mesh_compression;if(!e)continue;const n=i(t,o,e.bufferView),c={};for(const o of Object.keys(e.attributes)){const e=s.attributes?.[o];void 0!==e&&t.accessors?.[e]&&(c[o]=d[t.accessors[e].type]??3)}const f=await a(n,e.attributes,c);r.set(s,f)}return r}};export{f as default}; //# sourceMappingURL=gltf-feature-draco-Cr-J1knn.esm.min.js.map