@margoengine/gltf 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/NOTICE +4 -4
- package/README.md +1754 -1438
- package/dist/accessor-CU_1uSZ1.js +1 -0
- package/dist/asset-DN3ocEdY.js +4 -0
- package/dist/asset-entry.js +1 -1
- package/dist/asset.d.ts +76 -0
- package/dist/audio.js +1 -1
- package/dist/auto.js +1 -1
- package/dist/compression-CUOCmjmE.js +1 -0
- package/dist/compression.d.ts +6 -0
- package/dist/dds.js +1 -1
- package/dist/default-materials.d.ts +3 -1
- package/dist/default-transmission.d.ts +13 -0
- package/dist/extended.js +1 -1
- package/dist/group.d.ts +15 -3
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -1
- package/dist/{instanced-shader-BebTnbkj.js → instanced-shader-C9ZMazvo.js} +1 -1
- package/dist/instancing.js +1 -1
- package/dist/lights.js +1 -1
- package/dist/material-draw-state-GKiHDb0p.js +1 -0
- package/dist/material-draw.js +1 -1
- package/dist/meshopt.js +1 -1
- package/dist/mipmaps-38NmjDc3.js +21 -0
- package/dist/model-C77ATxi1.js +25 -0
- package/dist/model-entry.js +1 -1
- package/dist/model.d.ts +84 -7
- package/dist/native-glass-D85twud0.js +19 -0
- package/dist/pack-DdxRO8k6.js +1 -0
- package/dist/pbr-instancing.js +1 -1
- package/dist/pbr.js +1 -1
- package/dist/physics.js +1 -1
- package/dist/prepare.js +1 -1
- package/dist/progressive-lod.d.ts +13 -0
- package/dist/progressive.d.ts +5 -2
- package/dist/progressive.js +3 -3
- package/dist/quantized.js +1 -1
- package/dist/report.js +1 -1
- package/dist/scene-data.js +1 -1
- package/dist/scene-scope-CZDEkd24.js +2 -2
- package/dist/scene.js +3 -3
- package/dist/{shader-DPqfUcmp.js → shader-C29RtPAw.js} +43 -39
- package/dist/shader.d.ts +24 -0
- package/dist/shared/caster.d.ts +159 -152
- package/dist/shared/gltf.d.ts +257 -257
- package/dist/shared/iridescence.d.ts +2 -2
- package/dist/shared/prepared-geometry.d.ts +8 -8
- package/dist/soft-mesh.d.ts +39 -1
- package/dist/soft-mesh.js +2 -2
- package/dist/spec-gloss.js +2 -2
- package/dist/splats.js +1 -1
- package/dist/src-Btvz5f6i.js +4 -0
- package/dist/stream-CrfNNCRd.js +1 -0
- package/dist/stream.d.ts +20 -3
- package/dist/stroke-width-B2cnYGgn.js +1 -0
- package/dist/stroke-width.d.ts +18 -0
- package/dist/strokes.d.ts +12 -0
- package/dist/strokes.js +1 -0
- package/dist/texture-stream-Cu_XpyVO.js +3 -3
- package/dist/textured.js +3 -3
- package/dist/transmission.d.ts +81 -0
- package/dist/transmission.js +66 -0
- package/dist/version-B6NE5cJf.js +1 -0
- package/dist/vertex-inputs.d.ts +6 -0
- package/dist/{unit-light-DvtsuFYP.js → warning-UqjZyyqW.js} +2 -22
- package/dist/warning.d.ts +24 -0
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +3 -3
- package/dist/workers/gltf.js +36 -36
- package/dist/workers/progressive.js +1 -1
- package/package.json +234 -213
- package/dist/accessor-nVsu_f1L.js +0 -1
- package/dist/asset-1b8ejkZX.js +0 -4
- package/dist/compression-D4IkO5vE.js +0 -1
- package/dist/errors-THVaUwlL.js +0 -1
- package/dist/material-draw-state-BHeTb1FP.js +0 -1
- package/dist/model-iRvuj19h.js +0 -39
- package/dist/optimize-7SEzNA23.js +0 -1
- package/dist/pack-BVDYuqZe.js +0 -1
- package/dist/src-WMRHArDp.js +0 -4
- package/dist/stream-C3bKMy1B.js +0 -1
- package/dist/version-BmU1nesQ.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){var e=Object.defineProperty,t=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},n=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};function r(e,t=new Set,n=new Set){let r=[e];for(;r.length;){let e=r.pop();if(e&&typeof e==`object`&&!n.has(e)){if(n.add(e),ArrayBuffer.isView(e))e.buffer instanceof ArrayBuffer&&t.add(e.buffer);else if(e instanceof ArrayBuffer)t.add(e);else if(typeof ImageBitmap<`u`&&e instanceof ImageBitmap)t.add(e);else if(e instanceof Map)for(let[t,n]of e)r.push(t,n);else for(let t in e)r.push(e[t])}}return t}var i,a,o,s=t((()=>{i=(e,t)=>Object.assign(Error(t),{name:`MargoError`,code:e}),a=(e,t)=>`${e}; see https://margoengine.com/errors#${t}`,o=(e,t,n=e)=>i(e,a(t,n))}));function c(e,t){if(Number.isSafeInteger(t)&&e>t+3)throw o(`failed`,`GLB BIN chunk holds ${e} bytes, more than buffer 0's byteLength ${t} plus 3 padding bytes; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}var l=t((()=>{s()}));function u(e,t,n){return n===5126?e.getFloat32(t,!0):n===5125?e.getUint32(t,!0):n===5123?e.getUint16(t,!0):n===5122?e.getInt16(t,!0):n===5121?e.getUint8(t):e.getInt8(t)}var d,f=t((()=>{d={__proto__:null,5120:1,5121:1,5122:2,5123:2,5125:4,5126:4}})),p=t((()=>{}));function m(e){let t=/^(\d+)\.(\d+)$/,n=typeof e?.version==`string`?t.exec(e.version):null;if(!n||n[1]!==`2`)return!1;if(e.minVersion===void 0)return!0;let r=typeof e.minVersion==`string`?t.exec(e.minVersion):null;return!!r&&r[1]===`2`&&r[2]===`0`}var h=t((()=>{})),g,_,v,y=t((()=>{g=/"(?:__proto__|constructor|prototype)"|\\u/,_=(e,t)=>e===`__proto__`||e===`constructor`||e===`prototype`?void 0:t,v=e=>g.test(e)?JSON.parse(e,_):JSON.parse(e)}));function b(e){for(let t=0;t<8;t++){if(w.test(e))return!0;let t=e.replace(/%[\da-f]{2}/gi,e=>String.fromCharCode(`0x${e.slice(1)}`));if(t===e)return!1;e=t}return!0}function x(e,t){let n;try{n=new URL(t)}catch{throw TypeError(`allowedURLs entry ${String(t)} is not an absolute URL; pass a full http(s) URL`)}if(n.origin!==e.origin||n.protocol!==`http:`&&n.protocol!==`https:`||n.search&&n.search!==e.search)return!1;let r=n.pathname;return r.endsWith(`/`)?e.pathname.startsWith(r):e.pathname===r||e.pathname.startsWith(`${r}/`)}function S(e,t,n=[],r=`Asset`){if(typeof e!=`string`||!e||e.length>8192)throw TypeError(`Invalid ${r} URI; pass a shorter string`);let i;try{i=new URL(e,t)}catch{throw TypeError(`Invalid ${r} URI; pass a valid URL`)}if((i.protocol===`http:`||i.protocol===`https:`)&&!b(i.pathname)){for(let e of n)if(x(i,e))return i;let e=t===void 0?void 0:new URL(`.`,t);if(e&&i.origin===e.origin&&i.pathname.startsWith(e.pathname))return i}throw TypeError(`${r} URI ${i.href} leaves the model's directory; add its prefix to allowedURLs to load it`)}function C(e,t,n=[],r=`Asset`){if(!e.url)return e;try{S(e.url,t,n,r)}catch{throw e.body?.cancel().catch(()=>{}),TypeError(`${r} URI redirected to ${e.url}, which leaves the model's directory; add its prefix to allowedURLs to load it`)}return e}var w,ee=t((()=>{w=/%2f|%5c|%00|\u0000|(^|\/)(\.|%2e){1,2}(\/|$)/i})),T,te=t((()=>{T=class{constructor(...e){this.failed=e.length>0,this.error=e[0]}run(e){try{e()}catch(e){this.failed||(this.error=e),this.failed=!0}return this}finish(){if(this.failed)throw this.error}}}));async function ne(e,{maxBytes:t,signal:n,label:r=`Asset`,output:i=null,expected:a=0}){if(!Number.isSafeInteger(t)||t<0||i!==null&&(!(i instanceof Uint8Array)||i.length!==t))throw RangeError(`Invalid asset byte budget; pass maxBytes as an integer`);if(n?.throwIfAborted(),!e)throw TypeError(`Empty ${r} response; check the URL`);let o=e.getReader(),s=[],c=0,l=i,u=new T,d=e=>{try{Promise.resolve(o.cancel(e)).catch(()=>{})}catch{}},f=()=>d(n.reason);n?.addEventListener(`abort`,f,{once:!0});try{for(!i&&Number.isSafeInteger(a)&&a>0&&a<=t&&(l=new Uint8Array(a));;){n?.throwIfAborted();let{done:e,value:i}=await o.read();if(n?.throwIfAborted(),e)break;if(!(i instanceof Uint8Array))throw TypeError(`${r} stream requires byte chunks`);if(i.byteLength>t-c)throw RangeError(`${r} byte budget exceeded; raise maxBytes`);l&&i.length<=l.length-c?l.set(i,c):(l&&s.push(l.subarray(0,c)),l=null,s.push(i.length<i.buffer.byteLength||!(i.buffer instanceof ArrayBuffer)?i.slice():i)),c+=i.byteLength}}catch(e){d(e),u=new T(e)}if(u.run(()=>n?.removeEventListener(`abort`,f)).run(()=>o.releaseLock()).finish(),i)return i.subarray(0,c);if(l)return c<l.length?l.slice(0,c):l;let p=new Uint8Array(c),m=0;for(let e of s)p.set(e,m),m+=e.length;return p}async function re(e,t){try{if(t.signal?.throwIfAborted(),!e.ok)throw i(`failed`,`${t.label??`Asset`} request failed: HTTP ${e.status}; check the URL and that the server serves it`);let n=Number(e.headers.get(`content-length`));if(Number.isFinite(n)&&n>t.maxBytes)throw RangeError(`${t.label??`Asset`} byte budget exceeded; raise maxBytes`);let r=e.headers.get(`content-encoding`);(!r||r===`identity`)&&(t={...t,expected:n})}catch(t){try{Promise.resolve(e.body?.cancel(t)).catch(()=>{})}catch{}throw t}return ne(e.body,t)}var ie=t((()=>{s(),te()}));function ae(e,t=1e5){if(!Number.isSafeInteger(t)||t<1||t>8388608)throw RangeError(`${e} must be an integer from 1 to 8388608`);return t}function oe(e,t,n,r){if(t>n)throw RangeError(`${e} (${t} > ${n}; raise the ${r} option)`)}var se=t((()=>{}));function ce(e,t,n,r,i){let a=e.length/t,o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0;for(let e=0;e<r*i;e+=i){let t=n[e],r=n[e+1],i=n[e+2];t<o&&(o=t),t>l&&(l=t),r<s&&(s=r),r>u&&(u=r),i<c&&(c=i),i>d&&(d=i)}let f=1023.999/(Math.max(l-o,u-s,d-c)||1),p=f,m=f,h=new Uint32Array(a),g=e=>(e=(e|e<<16)&50331903,e=(e|e<<8)&50393103,e=(e|e<<4)&51130563,(e|e<<2)&153391689);for(let r=0,l=0;r<a;r++,l+=t){let a=0,u=0,d=0;for(let r=0;r<t;r++){let t=e[l+r]*i;a+=n[t],u+=n[t+1],d+=n[t+2]}h[r]=(g((a/t-o)*f|0)<<2|g((u/t-s)*p|0)<<1|g((d/t-c)*m|0))>>>0}let _=new Uint32Array(a),v=new Uint32Array(a);for(let e=0;e<a;e++)_[e]=e;let y=new Uint32Array(1024);for(let e=0;e<30;e+=10){y.fill(0);for(let t=0;t<a;t++)y[h[t]>>>e&1023]++;for(let e=0,t=0;e<1024;e++){let n=y[e];y[e]=t,t+=n}for(let t=0;t<a;t++){let n=_[t];v[y[h[n]>>>e&1023]++]=n}[_,v]=[v,_]}return _}function le(e,t,n,r,i,a=3){let o=e.length/t,s=i?ce(e,t,i,n,a):null,c=new Int32Array(n).fill(-1),l=new Uint32Array(r),u=new Uint32Array(e.length),d=[],f=0,p=0,m=0,h=()=>{d.push({indices:u.slice(p,m),vertexMap:l.slice(0,f)});for(let e=0;e<f;e++)c[l[e]]=-1;f=0,p=m};for(let n=0;n<o;n++){let i=(s?s[n]:n)*t,a=0;for(let n=0;n<t;n++){let t=e[i+n];if(c[t]>=0)continue;let r=!1;for(let a=0;a<n;a++)e[i+a]===t&&(r=!0);r||a++}f+a>r&&h();for(let n=0;n<t;n++){let t=e[i+n];c[t]<0&&(c[t]=f,l[f++]=t),u[m++]=c[t]}}return m>p&&h(),d}var ue,E,D=t((()=>{ue=262144,E=16777216})),de,fe,pe=t((()=>{de=e=>!!e?.extensions&&typeof e.extensions==`object`&&`KHR_gaussian_splatting`in e.extensions,fe=e=>!!e.meshes?.some(e=>e?.primitives?.some(de))})),me,he=t((()=>{me=(e,t)=>Object.assign(Error(e,t===void 0?void 0:{cause:t}),{name:`MargoError`,code:`failed`})}));function ge(e){for(let t of e.doc.meshes??[])for(let e of t.primitives??[])if(e.extensions?.KHR_draco_mesh_compression)return!0;return!1}function _e(e,t){if(!t.extensions?.KHR_draco_mesh_compression)return;let n=O.get(e)?.get(t);if(!n)throw i(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);return n}var O,ve=t((()=>{s(),O=new WeakMap}));async function ye(){throw TypeError(`createImageBitmap is not available in this worker; load the model on the page or in Node to decode its images`)}var be=t((()=>{}));function xe(e,t,n){return e===`ATTRIBUTES`?256*(Math.floor(4*t/n)+1):e===`TRIANGLES`?3*t:e===`INDICES`?t:1/0}var Se=t((()=>{})),Ce=n({MeshoptDecoder:()=>Ke,meshoptDecodeGltfBuffer:()=>Ie,meshoptDecodeIndexBuffer:()=>ke,meshoptDecodeIndexSequence:()=>Ae,meshoptDecodeVertexBuffer:()=>Te});function we(e,t,n,r,i){if(n===0)return r.fill(0,i,i+16),t;if(n===8){for(let n=0;n<16;n++)r[i+n]=e[t+n];return t+16}let a=t+n*2;if(n===1)for(let n=0;n<16;n++){let o=e[t+(n>>3)]>>(n&7)&1;r[i+n]=o===1?e[a++]:0}else if(n===2)for(let n=0;n<16;n++){let o=e[t+(n>>2)]>>6-2*(n&3)&3;r[i+n]=o===3?e[a++]:o}else for(let n=0;n<16;n++){let o=e[t+(n>>1)]>>4-4*(n&1)&15;r[i+n]=o===15?e[a++]:o}return a}function Te(e,t,n,r){(!Number.isInteger(n)||n<1||n>256||n%4!=0)&&A(`invalid ATTRIBUTES byteStride ${n}`),(!Number.isSafeInteger(t)||t<0||e.length<t*n)&&j(`invalid count or output size`);let i=r.length;i<1+n&&A(`truncated vertex stream`);let a=r[0];a>>4!=10&&A(`bad vertex stream header`);let o=a&15;o>1&&A(`vertex codec version ${o} is not supported (only versions 0 and 1)`);let s=n>>2,c=o===1;c&&i<1+n+s&&A(`truncated vertex stream`);let l=c?Math.max(24,n+s):Math.max(32,n),u=i-n-(c?s:0),d=i-s,f=new Uint8Array(n);for(let e=0;e<n;e++)f[e]=r[u+e];let p=Math.min(Math.floor(8192/n)&-16,256),m=new Uint8Array(n*256),h=1,g=!1;for(let a=0;a<t;a+=p){let o=Math.min(t-a,p),l=o+15>>4,u=0;c&&(h+s>i&&A(`truncated vertex stream`),u=h,h+=s);for(let e=0;e<n;e++){let t=e*256,n=ze;if(c){let a=r[u+(e>>2)]>>(e&3)*2&3;if(a===2){m.fill(0,t,t+l*16);continue}if(a===3){i-h<o+Re&&A(`truncated vertex stream`);for(let e=0;e<o;e++)m[t+e]=r[h+e];h+=o;continue}n=Be[a]}let a=l+3>>2;h+a>i&&A(`truncated vertex stream`);let s=h;h+=a;for(let e=0;e<l;e++){i-h<Re&&A(`truncated vertex stream`);let a=r[s+(e>>2)]>>(e&3)*2&3;h=we(r,h,n[a],m,t+e*16)}}c&&!g&&(g=Ee(r,d,s));for(let t=0;t<o;t++){let i=(a+t)*n;for(let n=0;n<s;n++){let a=n*4,o=c?r[d+n]:0,s=o&15;if(s===0)for(let n=a;n<a+4;n++){let r=f[n]+Ve(m[n*256+t])&255;f[n]=r,e[i+n]=r}else if(s===1)for(let n=a;n<a+4;n+=2){let r=He(m[n*256+t]|m[(n+1)*256+t]<<8),a=f[n]+(f[n+1]<<8)+r&65535;f[n]=a&255,f[n+1]=a>>8,e[i+n]=a&255,e[i+n+1]=a>>8}else{let n=o>>4,r=(m[a*256+t]|m[(a+1)*256+t]<<8|m[(a+2)*256+t]<<16|m[(a+3)*256+t]<<24)>>>0,s=r>>>n|r<<(32-n&31);for(let t=0;t<4;t++){let n=f[a+t]^s>>>8*t&255;f[a+t]=n,e[i+a+t]=n}}}}}i-h!==l&&A(`vertex stream has trailing or missing data`),c&&!g&&Ee(r,d,s)}function Ee(e,t,n){for(let r=0;r<n;r++){let n=e[t+r],i=n&15;(i>2||i<2&&n>>4)&&A(`invalid vertex channel mode`)}return!0}function De(e,t){let n=0,r=0,i=t.pos;for(let t=0;;t++){i>=e.length&&A(`truncated index stream`);let a=e[i++];if(n|=(a&127)<<r,r+=7,a<128)break;t===4&&A(`index varint is longer than 5 bytes`)}return t.pos=i,n>>>0}function Oe(e,t){(!Number.isSafeInteger(t)||t<0||e.length<t)&&j(`invalid count or output size`)}function k(e,t){return t>65535&&e instanceof Uint16Array&&A(`index ${t} does not fit a 16-bit index buffer`),t}function ke(e,t,n){Oe(e,t),t%3!=0&&A(`TRIANGLES count must be a multiple of 3`);let r=t/3,i=n.length;i<1+r+16&&A(`truncated index stream`);let a=n[0];a>>4!=14&&A(`bad index stream header`);let o=a&15;o>1&&A(`index codec version ${o} is not supported`);let s=o===1?13:15,c=i-16;for(let e=0;e<16;e++){let t=n[c+e];(e>=14?t!==0:(t&15)==15||t>>4==15)&&A(`invalid codeaux table`)}let l=new Uint32Array(16),u=new Uint32Array(16),d=new Uint32Array(16),f=0,p=0,m=0,h=0,g=(e,t)=>{l[f]=e,u[f]=t,f=f+1&15,m<16&&m++},_=e=>{d[p]=e,p=p+1&15,h<16&&h++},v=e=>(e>=h&&A(`triangle code reads a vertex FIFO entry that was never written`),d[p-1-e&15]),y=0,b=0,x={pos:1+r},S=()=>{let e=De(n,x);return b=b+(e&1?~(e>>>1):e>>>1)>>>0,b};for(let t=0;t<r;t++){x.pos>c&&A(`truncated index stream`);let r=n[1+t],i=r>>4,a=r&15,o,d,p;if(i<15){i>=m&&A(`triangle code reads an edge FIFO entry that was never written`);let e=f-1-i&15;o=l[e],d=u[e],a===0?(p=y,y=y+1>>>0,_(p)):a<s?p=v(a):a<15?(p=(a===13?b-1:b+1)>>>0,b=p,_(p)):(p=S(),_(p)),g(p,d),g(o,p)}else{let e,t;if(a<14){let r=n[c+a];e=r>>4,t=r&15,o=y,y=y+1>>>0}else{let r=n[x.pos++];r===0&&(y=0),e=r>>4,t=r&15,a===14?(o=y,y=y+1>>>0):o=S()}e===0?(d=y,y=y+1>>>0):d=e<15?v(e-1):S(),t===0?(p=y,y=y+1>>>0):p=t<15?v(t-1):S(),g(d,o),g(p,d),g(o,p),_(o),(e===0||e===15)&&_(d),(t===0||t===15)&&_(p)}e[t*3]=k(e,o),e[t*3+1]=k(e,d),e[t*3+2]=k(e,p)}x.pos!==c&&A(`index stream has trailing or missing data`)}function Ae(e,t,n){Oe(e,t);let r=n.length;r<1+t+4&&A(`truncated index sequence`);let i=n[0];i>>4!=13&&A(`bad index sequence header`);let a=i&15;a>1&&A(`index sequence version ${a} is not supported`);let o=r-4,s=[0,0],c={pos:1};for(let r=0;r<t;r++){c.pos>=o&&A(`truncated index sequence`);let t=De(n,c),i=t&1,a=s[i]+(t&2?~(t>>>2):t>>>2)>>>0;s[i]=a,e[r]=k(e,a)}c.pos!==o&&A(`index sequence has trailing or missing data`)}function je(e,t,n){let r=n===8,i=r?32767:127,a=r?2:1,o=r?t=>e.getInt16(t,!0):t=>e.getInt8(t),s=r?(t,n)=>e.setInt16(t,n,!0):(t,n)=>e.setInt8(t,n);for(let e=0,r=0;e<t;e++,r+=n){let e=o(r),t=o(r+a),n=o(r+2*a)-Math.abs(e)-Math.abs(t);n<0&&(e+=e>=0?n:-n,t+=t>=0?n:-n);let c=M(M(e*e)+M(M(t*t)+M(n*n)));if(c===0){s(r,0),s(r+a,0),s(r+2*a,0);continue}let l=M(i/M(Math.sqrt(c)));s(r,P(M(e*l))),s(r+a,P(M(t*l))),s(r+2*a,P(M(n*l)))}}function Me(e,t){for(let n=0,r=0;n<t;n++,r+=8){let t=e.getInt16(r,!0),n=e.getInt16(r+2,!0),i=e.getInt16(r+4,!0),a=e.getInt16(r+6,!0),o=a&3,s=a|3,c=M(M(2*M(s*s))-M(M(t*t)+M(M(n*n)+M(i*i)))),l=M(Math.sqrt(Math.max(c,0))),u=M(Ge/s);e.setInt16(r+(o+1&3)*2,P(M(t*u)),!0),e.setInt16(r+(o+2&3)*2,P(M(n*u)),!0),e.setInt16(r+(o+3&3)*2,P(M(i*u)),!0),e.setInt16(r+o*2,P(M(l*u)),!0)}}function Ne(e,t){for(let n=0,r=0;n<t;n++,r+=4){let t=e.getInt32(r,!0);e.setFloat32(r,(t<<8>>8)*2**(t>>24),!0)}}function Pe(e,t,n){let r=n===8,i=r?65535:255,a=r?65535:255,o=r?2:1,s=r?t=>e.getUint16(t,!0):t=>e.getUint8(t),c=r?t=>e.getInt16(t,!0):t=>e.getInt8(t),l=r?(t,n)=>e.setUint16(t,n,!0):(t,n)=>e.setUint8(t,n);for(let e=0,r=0;e<t;e++,r+=n){let e=s(r),t=c(r+o),n=c(r+2*o),u=s(r+3*o),d=u===0?0:2**(32-Math.clz32(u))-1,f=M(i/d),p=e+t-n,m=e+n,h=e-t-n,g=u<<1&d|u&1;l(r,F(M(p*f))&a),l(r+o,F(M(m*f))&a),l(r+2*o,F(M(h*f))&a),l(r+3*o,F(M(g*f))&a)}}function Fe(e,t,n,r){let i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(r){case`OCTAHEDRAL`:n!==4&&n!==8&&A(`OCTAHEDRAL filter requires byteStride 4 or 8`),je(i,t,n);return;case`QUATERNION`:n!==8&&A(`QUATERNION filter requires byteStride 8`),Me(i,t);return;case`EXPONENTIAL`:Ne(i,t*n>>2);return;case`COLOR`:n!==4&&n!==8&&A(`COLOR filter requires byteStride 4 or 8`),Pe(i,t,n);return;default:A(`unknown filter '${r}'`)}}function Ie(e,t,n,r,i=`NONE`){(!Number.isSafeInteger(t)||t<0||!Number.isSafeInteger(n)||n<=0||t*n>2**31)&&j(`invalid count or byteStride`);let a=e.length;t>xe(r,a,n)&&j(`truncated stream (${t} elements cannot fit in ${a} bytes)`);let o;if(r===`ATTRIBUTES`)o=new Uint8Array(t*n),Te(o,t,n,e);else if(r===`TRIANGLES`||r===`INDICES`){n!==2&&n!==4&&A(`${r} byteStride must be 2 or 4`),o=new Uint8Array(t*n);let i=n===2?new Uint16Array(o.buffer,0,t):new Uint32Array(o.buffer,0,t);r===`TRIANGLES`?ke(i,t,e):Ae(i,t,e)}else return A(`unknown mode '${r}'`);return i&&i!==`NONE`&&(r!==`ATTRIBUTES`&&A(`filters only apply to ATTRIBUTES`),Fe(o,t,n,i)),o}var Le,A,j,Re,ze,Be,Ve,He,M,N,P,Ue,We,F,Ge,Ke,qe=t((()=>{he(),Se(),Le=`EXT_meshopt_compression: `,A=e=>{throw me(Le+e)},j=e=>{throw RangeError(Le+e)},Re=24,ze=[0,2,4,8],Be=[[0,1,2,4],[1,2,4,8]],Ve=e=>(e&1?~(e>>1):e>>1)&255,He=e=>(e&1?~(e>>1):e>>1)&65535,M=Math.fround,N=12582912,P=e=>M(e+N)-N,Ue=new Float32Array(1),We=new Uint32Array(Ue.buffer),F=e=>(Ue[0]=e+N,We[0]),Ge=M(32767/Math.SQRT2),Ke={supported:!0,ready:Promise.resolve(),decodeGltfBuffer(e,t,n,r,i,a){let o=Ie(r,t,n,i,a);e.byteLength<t*n&&j(`target buffer is too small`),e.set(o)}}})),Je=n({decompressPrimitives:()=>Ye});async function Ye(e,{signal:t,draco:n}={}){t?.throwIfAborted();let r,a=O.get(e)??new Map;O.set(e,a);try{for(let o of e.doc.meshes??[])for(let s of o.primitives??[]){let o=s.extensions?.KHR_draco_mesh_compression;if(!o||a.has(s))continue;if((s.mode??4)!==4)throw i(`unsupported`,`PBR requires triangle primitives; re-export the mesh with mode 4 (TRIANGLES)`);if(!o.attributes||typeof o.attributes!=`object`||Array.isArray(o.attributes))throw TypeError(`Invalid glTF Draco attributes; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let c={},l={},u={},d=z(e.doc.accessors,s.attributes?.POSITION,`Draco POSITION`),f=R(d.count,`Draco vertex count`,3);if(f>16777216)throw i(`unsupported`,`glTF primitive has more than ${E} vertices, the most one primitive may hold; split the mesh into several primitives`);if(d.type!==`VEC3`)throw RangeError(`Invalid glTF Draco POSITION size; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let p=0;for(let[t,n]of Object.entries(o.attributes)){let r=z(e.doc.accessors,s.attributes?.[t],`Draco attribute`),i=R(r.count,`Draco accessor count`,1),a=Object.hasOwn(L,r.type)?L[r.type]:void 0;if(!a||i!==f)throw RangeError(`Invalid glTF Draco accessor size; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);p+=i*a*4,c[t]=R(r.componentType,`Draco component type`),l[t]=R(n,`Draco attribute id`),u[t]=a}let m=s.indices===void 0?void 0:z(e.doc.accessors,s.indices,`Draco indices`);if(m){if(m.type!==`SCALAR`||![5121,5123,5125].includes(m.componentType)||m.normalized)throw TypeError(`Invalid glTF Draco indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let e=R(m.count,`Draco index count`,1);if(e>I||e%3)throw RangeError(`Invalid glTF Draco index count; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);p+=e*4}if(p>e.maxBytes*4)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);let h=e.view(o.bufferView);if(p>e.remainingDecodedBytes)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);let g=m?m.count:Math.min(I,Math.floor((e.remainingDecodedBytes-p)/4));if(g<3)throw RangeError(`Decoded glTF exceeds index byte budget; load a smaller model, or reduce its textures and meshes`);if(!n){let{DracoDecoder:i}=await st(e,`Draco`)();t?.throwIfAborted(),n=r=new i}let _=await n.decode(h,{attributeIds:l,componentTypes:c,signal:t,limits:{maxVertices:f,maxIndices:g,maxDecodedBytes:e.remainingDecodedBytes,attributeWidths:u}});t?.throwIfAborted();let v=R(_.vertexCount,`Draco vertex count`,3),y=_.indices;if(v>16777216||!(y instanceof Uint16Array||y instanceof Uint32Array)||!y.length||y.length>I||y.length%3||y.some(e=>e>=v)||m&&y.length!==m.count)throw RangeError(`Invalid glTF Draco triangle indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let t of Object.keys(l)){let n=s.attributes[t],r=z(e.doc.accessors,n,`Draco attribute`),i=Object.hasOwn(Xe,t)?Xe[t]:void 0,a=_.attributes?.[t],o=i?_[i]:a?.array;if(!ArrayBuffer.isView(o)||o instanceof DataView||r.count!==v||o.length!==v*L[r.type]||!i&&(a?.itemSize!==L[r.type]||a.componentType!==r.componentType))throw RangeError(`Mismatched glTF Draco attribute `+t+`; the accessor must match the Draco stream, re-export the model`);let c=Float32Array.from(o);if(r.normalized&&t!==`COLOR_0`){let e=Ze[r.componentType];if(!e)throw TypeError(`Invalid normalized Draco attribute; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let t=0;t<c.length;t++)c[t]=Math.max(-1,c[t]/e)}e.setDecodedAccessor(n,c)}s.indices===void 0&&e.reserveDecodedBytes(y.length*4);let b=Float32Array.from(y);s.indices!==void 0&&e.setDecodedAccessor(s.indices,b),a.set(s,s.indices===void 0?b:e.accessor(s.indices,`SCALAR`))}}finally{r?.dispose()}}var I,L,Xe,Ze,Qe=t((()=>{s(),vt(),ve(),D(),I=3*E,L={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Xe={POSITION:`positions`,NORMAL:`normals`,TEXCOORD_0:`uvs`,COLOR_0:`colors`},Ze={5120:127,5121:255,5122:32767,5123:65535}}));function $e(e,t){if(!(e.length<23)){for(let t=0;t<23;t++)if(e[t]!==dt.charCodeAt(t))return;throw i(`failed`,`${t} is a Git LFS pointer file, not the asset; run git lfs pull and serve the real file; see https://margoengine.com/errors#git-lfs`)}}function et(e=V){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`maxDownloadBytes must be a positive integer`);return e}function R(e,t,n=0){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<n)throw TypeError(`Invalid glTF `+t+`; re-export the file and check it with the glTF Validator`);return e}function z(e,t,n){let r=e?.[R(t,n)];if(!r||typeof r!=`object`||Array.isArray(r))throw TypeError(`Missing glTF `+n+`; re-export the file and check it with the glTF Validator`);return r}function tt(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{throw TypeError(`Invalid glTF JSON: not UTF-8; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}}function nt(e){let t=typeof e==`string`?e:tt(e);for(let e=0,n=0,r=!1;e<t.length;e++){let i=t.charCodeAt(e);if(r)i===92?e++:i===34&&(r=!1);else if(i===34)r=!0;else if(i===91||i===123){if(++n>256)throw TypeError(`Invalid glTF JSON: nested deeper than 256 levels; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}else(i===93||i===125)&&n--}try{return v(t)}catch(e){throw e instanceof SyntaxError?TypeError(`Invalid glTF JSON: `+e.message):e}}function rt(e){if(!e||typeof e!=`object`||!m(e.asset))throw TypeError(`Expected glTF 2.0`);let t=e;for(let e of mt)if(!K(t[e]))throw TypeError(`Invalid glTF `+e+`; re-export the file and check it with the glTF Validator`);for(let t of e.meshes??[])if(!K(t.primitives)||!(t.primitives??[]).every(e=>K(e.targets)))throw TypeError(`Invalid glTF primitives; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let t of e.animations??[])if(!K(t.samplers)||!K(t.channels))throw TypeError(`Invalid glTF animation; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let e of[`extensionsRequired`,`extensionsUsed`])if(t[e]!==void 0&&!Array.isArray(t[e]))throw TypeError(`Invalid glTF `+e+`; re-export the file and check it with the glTF Validator`)}function B(e,t=V){let n=/^data:[^;,]+;base64,([A-Za-z0-9+/]*={0,2})$/.exec(e);if(n&&n[1].length>t*4/3+4)throw H(`glTF exceeds download budget`,t);if(!n)throw TypeError(`Invalid glTF data URI; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let r;try{r=atob(n[1])}catch{throw TypeError(`Invalid glTF data URI; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}return Uint8Array.from(r,e=>e.charCodeAt(0))}function it(e,t=!1){let n=e.extensions,r=n?.[Y]!==void 0||!t||n?.MSFT_texture_dds===void 0?Y:`MSFT_texture_dds`,i=n?.[r];if(i!==void 0&&(!i||typeof i!=`object`||Array.isArray(i)))throw TypeError(`Invalid glTF ${r}; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return R(i===void 0?e.source:i.source,`image source`)}function at(e,t,n){let r=R(t,`accessor`),i=z(e.accessors,r,`accessor`);if(n&&i.type!==n)throw TypeError(`Invalid glTF accessor type; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let a=typeof i.componentType==`number`?d[i.componentType]:void 0,o=typeof i.type==`string`&&Object.hasOwn(q,i.type)?q[i.type]:void 0,s=R(i.count,`accessor count`,1);if(!a||!o||i.normalized!==void 0&&typeof i.normalized!=`boolean`||i.normalized&&[5125,5126].includes(i.componentType))throw TypeError(`Unsupported glTF accessor ${r} (componentType ${i.componentType}, type ${i.type}${i.normalized?`, normalized`:``}); re-export the model without it, or convert the texture format`);return{index:r,def:i,size:a,width:o,count:s}}function ot(e,t=!1){let n=new Set,r=new Set;for(let i of e.textures??[])i?.extensions?.[Y]!==void 0||t&&i?.extensions?.MSFT_texture_dds!==void 0?(r.add(it(i,t)),Number.isSafeInteger(i.source)&&i.source>=0&&n.add(i.source)):(Number.isSafeInteger(i?.source)&&i.source>=0&&r.add(i.source),!t&&i?.extensions?.MSFT_texture_dds&&n.add(R(i.extensions.MSFT_texture_dds.source,`DDS image`)));for(let e of r)n.delete(e);return n}function st(e,t){let n=e.hooks.decoderModule;if(!n)throw i(`unsupported`,t===`Draco`?`This file needs the Draco decoder; load it with loadGLTF from @margoengine/gltf/pbr, or pass decoders.decoderModule`:`This file needs the KTX2 decoder; load it with loadGLTF from @margoengine/gltf/pbr, or pass decoders.decoderModule`);return n}async function ct(e,t,n,r){r?.throwIfAborted();try{if(typeof createImageBitmap!=`function`)return await ye(e,r);let n=e.buffer instanceof ArrayBuffer?e:new Uint8Array(e);return await createImageBitmap(new Blob([n],{type:t}),{colorSpaceConversion:`none`,premultiplyAlpha:`none`})}catch(e){throw r?.throwIfAborted(),TypeError(`glTF image ${n} could not be decoded (${e instanceof Error?e.message:e}); check the file`)}}var lt,ut,V,H,dt,ft,U,W,pt,G,mt,K,q,ht,J,Y,gt,_t,vt=t((()=>{s(),h(),y(),se(),D(),l(),f(),pe(),ve(),be(),lt=e=>!!e.meshes?.some(e=>e?.primitives?.some(e=>e?.extensions?.KHR_draco_mesh_compression))||fe(e),ut=e=>lt(e)||!!e.textures?.some(e=>e?.extensions?.KHR_texture_basisu)||!!e.images?.some(e=>e?.mimeType===`image/ktx2`),V=536870912,H=(e,t)=>RangeError(`${e} (${t} bytes; raise the maxDownloadBytes option)`),dt=`version https://git-lfs`,ft=new Set(`KHR_mesh_quantization.KHR_texture_transform.KHR_materials_emissive_strength.KHR_materials_unlit.KHR_lights_punctual.KHR_node_visibility.KHR_materials_clearcoat.KHR_materials_transmission.KHR_materials_ior.KHR_materials_dispersion.KHR_materials_volume.KHR_materials_sheen.KHR_materials_specular.KHR_materials_variants.KHR_node_visibility.EXT_texture_webp.EXT_texture_avif.EXT_mesh_gpu_instancing.VRMC_materials_mtoon.VRMC_node_constraint.EXT_lights_ies.EXT_lights_image_based.KHR_physics_rigid_bodies.KHR_audio_emitter.MSFT_audio_emitter.KHR_interactivity.KHR_node_selectability.KHR_node_hoverability.KHR_implicit_shapes.KHR_xmp_json_ld.KHR_animation_pointer`.split(`.`)),U={KHR_draco_mesh_compression:`draco`,EXT_meshopt_compression:`meshopt`,KHR_meshopt_compression:`meshopt`,KHR_texture_basisu:`ktx2`,MSFT_texture_dds:`dds`,KHR_materials_iridescence:`materials`,KHR_materials_anisotropy:`materials`,KHR_materials_diffuse_transmission:`materials`,KHR_materials_diffuse_roughness:`materials`,EXT_materials_bump:`materials`,KHR_materials_volume_scatter:`materials`,KHR_gaussian_splatting:`splats`,KHR_gaussian_splatting_compression_spz_2:`splats`},pt=[`EXT_meshopt_compression`,`KHR_meshopt_compression`],G=e=>{let t=e?.extensions;if(t?.EXT_meshopt_compression!==void 0&&t?.KHR_meshopt_compression!==void 0)throw TypeError(`Invalid glTF meshopt extensions; use only EXT or KHR on each buffer or bufferView`);return t?.EXT_meshopt_compression??t?.KHR_meshopt_compression},mt=[`buffers`,`bufferViews`,`accessors`,`meshes`,`nodes`,`scenes`,`materials`,`textures`,`images`],mt.push(`samplers`,`skins`,`animations`,`cameras`),K=e=>e===void 0||Array.isArray(e)&&e.every(e=>!!e&&typeof e==`object`&&!Array.isArray(e)),q={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},ht=`EXT_meshopt_compression`,J=`KHR_draco_mesh_compression`,Y=`KHR_texture_basisu`,gt={5120:127,5121:255,5122:32767,5123:65535},_t=class{get remainingDecodedBytes(){return this.maxBytes*4-this.decoded}reserveDecodedBytes(e){if(R(e,`decoded byte length`),this.decoded+e>this.maxBytes*4)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);this.decoded+=e}constructor(e,t,n,r={},a=V,o=1e5){this.doc=e,this.hooks=r,this.maxBytes=a,this.maxNodes=o,this.cache=new Map,this.viewCache=new Map,this.decoded=0,this.partVertices=ue,et(a),ae(`maxNodes`,o),rt(e);let s=(e.extensionsRequired??[]).filter(e=>!ft.has(e)&&![J,ht,`KHR_meshopt_compression`,Y].includes(e)&&!r[U[e]]&&!(r.materials&&r.materials.extensions?.includes(e)));if(s.length)throw i(`unsupported`,`Required glTF extensions are unsupported: `+s.map(e=>U[e]?e+` (pass a `+U[e]+` decoder)`:e).join(`, `)+`; pass the listed decoders or re-export the model without them`);oe(`Too many glTF nodes`,e.nodes?.length??0,o,`maxNodes`);let l=0;this.buffers=(e.buffers??[]).map((r,i)=>{if(!r||typeof r!=`object`||Array.isArray(r))throw TypeError(`Invalid glTF buffer; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let o=R(r.byteLength,`buffer length`,1),s=G(r)?.fallback;if(s!==void 0&&typeof s!=`boolean`)throw TypeError(`Invalid glTF meshopt fallback; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let u=t[i],d=(!u||u.byteLength===0)&&!r.uri&&(i!==0||!n);if(s===!0||d&&pt.some(t=>e.extensionsRequired?.includes(t))){let t=pt.find(e=>r.extensions?.[e]!==void 0),n=(e.bufferViews??[]).filter(e=>e?.buffer===i);if(!n.length||n.some(e=>!G(e)||t!==void 0&&!e.extensions?.[t])||e.bufferViews?.some(e=>G(e)?.buffer===i))throw TypeError(`Invalid glTF meshopt fallback references; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return new Uint8Array}let f=u?u instanceof ArrayBuffer?new Uint8Array(u):new Uint8Array(u.buffer,u.byteOffset,u.byteLength):r.uri?B(r.uri,a):i===0?n:void 0;if(!f||o>f.length)throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`);if(i===0&&n&&(u===n||f===n)&&c(n.length,o),l+=f.byteLength,l>a)throw H(`glTF buffers exceed byte budget`,a);return f.subarray(0,o)})}view(e){let t=R(e,`bufferView`),n=z(this.doc.bufferViews,t,`bufferView`),r=R(n.buffer,`buffer reference`),a=this.buffers[r],o=R(n.byteOffset??0,`view offset`),s=R(n.byteLength,`view length`,1),c=R(z(this.doc.buffers,r,`buffer`).byteLength,`buffer length`,1);if(s>c||o>c-s)throw RangeError(`Invalid glTF bufferView bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let l=G(n);if(l!==void 0){let e=this.viewCache.get(t);if(e)return e;if(!l||typeof l!=`object`||Array.isArray(l))throw TypeError(`Invalid glTF meshopt extension; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let r=this.buffers[R(l.buffer,`meshopt buffer reference`)],a=R(l.byteOffset??0,`meshopt offset`),o=R(l.byteLength,`meshopt length`,1),c=R(l.count,`meshopt count`,1),u=R(l.byteStride,`meshopt stride`,1),d=l.mode,f=l.filter??`NONE`;if(!r||o>r.length||a>r.length-o)throw RangeError(`Invalid glTF meshopt source bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(!Number.isSafeInteger(c*u)||c*u!==s||n.byteStride!==void 0&&n.byteStride!==u)throw RangeError(`Invalid glTF meshopt decoded layout; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(d===`ATTRIBUTES`?u>256||u%4!=0:![`TRIANGLES`,`INDICES`].includes(d)||![2,4].includes(u)||d===`TRIANGLES`&&c%3!=0)throw TypeError(`Invalid glTF meshopt mode/stride/count; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(![`NONE`,`OCTAHEDRAL`,`QUATERNION`,`EXPONENTIAL`,`COLOR`].includes(f)||f!==`NONE`&&d!==`ATTRIBUTES`||[`OCTAHEDRAL`,`COLOR`].includes(f)&&![4,8].includes(u)||f===`QUATERNION`&&u!==8||f===`EXPONENTIAL`&&u%4!=0)throw TypeError(`Invalid glTF meshopt filter; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(this.decoded+s>this.maxBytes*4)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);let p=r.subarray(a,a+o),m;if(this.hooks.meshopt)m=new Uint8Array(s),this.hooks.meshopt.decodeGltfBuffer(m,c,u,p,d,f);else{if(!W)throw i(`state`,`Meshopt geometry requires parseGLTFAsync or loadGLTF, or a meshopt decoder passed in decoders (or asset.decode() first)`);m=W(p,c,u,d,f)}return this.reserveDecodedBytes(m.byteLength),this.viewCache.set(t,m),m}if(!a||o+s>a.length)throw RangeError(`Invalid glTF bufferView bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return a.subarray(o,o+s)}setDecodedAccessor(e,t){let{index:n,width:r,count:i}=at(this.doc,e);if(!(t instanceof Float32Array)||t.length!==i*r)throw RangeError(`Mismatched decoded glTF accessor; the file holds invalid numbers, re-export it and check it with the glTF Validator`);if(t.some(e=>!Number.isFinite(e)))throw RangeError(`Non-finite decoded glTF accessor; the file holds invalid numbers, re-export it and check it with the glTF Validator`);let a=this.cache.get(n);if(a){if(a!==t&&a.some((e,n)=>e!==t[n]))throw TypeError(`Conflicting decoded glTF accessor; the file holds invalid numbers, re-export it and check it with the glTF Validator`)}else this.reserveDecodedBytes(t.byteLength),this.cache.set(n,t)}async prepareMeshopt(){W||this.hooks.meshopt||this.doc.bufferViews?.some(e=>e?.extensions?.EXT_meshopt_compression||e?.extensions?.KHR_meshopt_compression)&&(W=(await Promise.resolve().then(()=>(qe(),Ce))).meshoptDecodeGltfBuffer)}async decode(e){if(await this.prepareMeshopt(),!ge(this))return e?.throwIfAborted();let{decompressPrimitives:t}=await Promise.resolve().then(()=>(Qe(),Je)),n=this.hooks.draco,r=n?{decode:async(e,t)=>{let r=await n.decode(e,t),i=r.vertexCount??r.positions?.length/3,a=r.attributes&&Object.fromEntries(Object.entries(r.attributes).map(([e,n])=>{let r=n;return[e,{...r,itemSize:r.itemSize??r.array.length/i,componentType:r.componentType??t.componentTypes[e]}]}));return{...r,vertexCount:i,attributes:a,indices:r.indices??(Number.isSafeInteger(i)&&i>=3&&i<=16777216?Uint32Array.from({length:i},(e,t)=>t):void 0)}}}:void 0;await t(this,{signal:e,draco:r})}accessor(e,t,n=!0){let{index:r,def:a,size:o,width:s,count:c}=at(this.doc,e,t),l=this.cache.get(r);if(l)return l;this.reserveDecodedBytes(c*s*4);let f=new Float32Array(c*s),p=(e,t,r,i,c)=>{if(t%o||r%o||t+(i-1)*r+s*o>e.length)throw RangeError(`Invalid glTF accessor bounds/alignment; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let l=new DataView(e.buffer,e.byteOffset,e.byteLength),d=a.componentType,p=a.normalized?gt[d]??1:0;for(let e=0;e<i;e++){let i=(c?c[e]:e)*s;for(let a=0,c=t+e*r;a<s;a++,c+=o){let e=u(l,c,d);if(p&&(e=Math.max(-1,e/p)),n&&!Number.isFinite(Math.fround(e)))throw RangeError(`Non-finite glTF accessor; the file holds invalid numbers, re-export it and check it with the glTF Validator`);f[i+a]=e}}};if(a.bufferView!==void 0){let e=z(this.doc.bufferViews,a.bufferView,`bufferView`),t=R(e.byteStride??o*s,`stride`,o*s);if(t>252||R(e.byteOffset??0,`view offset`)%o)throw RangeError(`Invalid glTF stride/alignment; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);p(this.view(a.bufferView),R(a.byteOffset??0,`accessor offset`),t,c)}else{if(this.doc.meshes?.some(e=>e?.primitives?.some(e=>e?.extensions?.[J]&&(e.indices===r||Object.keys(e.extensions[J].attributes??{}).some(t=>e.attributes?.[t]===r)))))throw i(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);if(a.byteOffset)throw TypeError(`Accessor has no data or invalid offset; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}if(a.sparse){let e=a.sparse,t=R(e.count,`sparse count`,1),n=e.indices,r=e.values,i=d[n?.componentType];if(t>c||![5121,5123,5125].includes(n?.componentType))throw TypeError(`Invalid glTF sparse indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let l=this.view(n.bufferView),u=R(n.byteOffset??0,`sparse offset`);if(u%i||u+t*i>l.length||z(this.doc.bufferViews,n.bufferView,`sparse indices`).byteStride!==void 0||z(this.doc.bufferViews,r?.bufferView,`sparse values`).byteStride!==void 0)throw RangeError(`Invalid sparse bounds/stride; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let f=new DataView(l.buffer,l.byteOffset,l.byteLength),m=[],h=-1;for(let e=0;e<t;e++){let t=u+e*i,n=i===1?f.getUint8(t):i===2?f.getUint16(t,!0):f.getUint32(t,!0);if(n<=h||n>=c)throw RangeError(`Invalid sparse index order/bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);m.push(n),h=n}p(this.view(r.bufferView),R(r.byteOffset??0,`sparse values offset`),o*s,t,m)}return n&&this.cache.set(r,f),f}}}));ve(),vt(),s(),D();function yt(e){if(!e||typeof e!=`object`)return!1;for(let[t,n]of Object.entries(e))if(t===`texCoord`?n>1:yt(n))return!0;return!1}function bt(e,t){let n=t.extensions?.KHR_materials_variants,r=[t.material,...(n?.mappings??[]).map(e=>e?.material)],i=new Set;for(let t=0;t<r.length;t++){let n=r[t];if(n===void 0||i.has(n))continue;i.add(n);let a=e.materials?.[n];if(yt(a))return!0;let o=(a?.extensions)?.MSFT_lod?.ids;if(Array.isArray(o))for(let t of o)Number.isInteger(t)&&t>=0&&t<(e.materials?.length??0)&&r.push(t)}return!1}function xt(e,t,n){_e(e,t);try{return Ct(e,t,n)}catch(n){let r=e.doc.meshes??[],i=r.findIndex(e=>e?.primitives?.includes?.(t));throw n instanceof Error&&i>=0&&(n.message=`glTF mesh ${i}${r[i].name?` "${r[i].name}"`:``} primitive ${r[i].primitives.indexOf(t)}: ${n.message}`),n}}function St(e,t){let n=e.length;if(t===2||t===3){let r=n<2?0:t===2?n:n-1,i=new Uint32Array(r*2);for(let t=0;t<r;t++)i[t*2]=e[t],i[t*2+1]=e[(t+1)%n];return i}if(t===5||t===6){let r=new Uint32Array(Math.max(n-2,0)*3);for(let i=0,a=0;i<n-2;i++,a+=3)t===5?(r[a]=e[i],r[a+1]=e[i+1+i%2],r[a+2]=e[i+2-i%2]):(r[a]=e[i+1],r[a+1]=e[i+2],r[a+2]=e[0]);return r}return e}function Ct(e,t,n){let r=t.mode??4,a=r===0?1:r<4?2:3;if(!Number.isInteger(r)||r<0||r>6)throw TypeError(`Invalid glTF primitive mode; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let o=t.attributes??{},s=(t,n,r)=>{try{return e.accessor(n,r)}catch(e){throw e instanceof Error&&(e.message=`${t} (accessor ${n}): ${e.message}`),e}};if(z(e.doc.accessors,o.POSITION,`POSITION`).count>16777216)throw i(`unsupported`,`glTF primitive has more than ${E} vertices, the most one primitive may hold; split the mesh into several primitives`);let c=s(`POSITION`,o.POSITION,`VEC3`),l=c.length/3,u=e.doc.extensionsUsed?.includes(`KHR_mesh_quantization`),d=e.partVertices;if(l<a)throw RangeError(`Expected bounded triangle geometry`);for(let t of[`POSITION`,`NORMAL`,`TANGENT`])if(o[t]!==void 0&&!u){let n=z(e.doc.accessors,o[t],`attribute`);if(n.componentType!==5126||n.normalized)throw TypeError(`Expected Float32 `+t)}for(let t of[`TEXCOORD_0`,`TEXCOORD_1`,`TEXCOORD_2`,`TEXCOORD_3`,`COLOR_0`])if(o[t]!==void 0&&!(u&&t!==`COLOR_0`)){let n=z(e.doc.accessors,o[t],`attribute`);if(![5126,5121,5123].includes(n.componentType)||n.componentType!==5126&&!n.normalized)throw TypeError(`Invalid normalized `+t+`; re-export the file and check it with the glTF Validator`)}let f=o.NORMAL===void 0?new Float32Array(c.length):s(`NORMAL`,o.NORMAL,`VEC3`),p=_e(e,t)??(t.indices===void 0?null:s(`indices`,t.indices,`SCALAR`));if(p)for(let e=0;e<p.length;e++){let t=p[e];if(!Number.isInteger(t)||t<0||t>=l)throw RangeError(`Invalid glTF triangle indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}let m=p?new Uint32Array(p):new Uint32Array(l);if(!p)for(let e=0;e<l;e++)m[e]=e;if(m=St(m,r),!m.length||m.length%a)throw RangeError(`Invalid glTF triangle indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(t.indices!==void 0&&(![5121,5123,5125].includes(z(e.doc.accessors,t.indices,`indices`).componentType)||e.doc.accessors[t.indices].normalized))throw TypeError(`Invalid index component type; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(o.NORMAL===void 0&&a===3)for(let e=0;e<m.length;e+=3){let t=m[e]*3,n=m[e+1]*3,r=m[e+2]*3,i=c[n]-c[t],a=c[n+1]-c[t+1],o=c[n+2]-c[t+2],s=c[r]-c[t],l=c[r+1]-c[t+1],u=c[r+2]-c[t+2],d=a*u-o*l,p=o*s-i*u,h=i*l-a*s;f[t]+=d,f[t+1]+=p,f[t+2]+=h,f[n]+=d,f[n+1]+=p,f[n+2]+=h,f[r]+=d,f[r+1]+=p,f[r+2]+=h}let h=e.doc.materials?.[t.material]?.alphaMode===`BLEND`,g=l>d?le(m,a,l,d,h?null:c):null;if(e.reorder&&a===3&&!h){if(!g)m=e.reorder(m,c,l);else for(let t of g){let n=t.vertexMap.length,r=new Float32Array(n*3);for(let e=0;e<n;e++){let n=t.vertexMap[e]*3;r[e*3]=c[n],r[e*3+1]=c[n+1],r[e*3+2]=c[n+2]}t.indices=e.reorder(t.indices,r,n)}}let _=o.TEXCOORD_0===void 0?null:s(`TEXCOORD_0`,o.TEXCOORD_0,`VEC2`),v=o.TEXCOORD_1===void 0?null:s(`TEXCOORD_1`,o.TEXCOORD_1,`VEC2`),y=bt(e.doc,t),b=!y||o.TEXCOORD_2===void 0?null:s(`TEXCOORD_2`,o.TEXCOORD_2,`VEC2`),x=!y||o.TEXCOORD_3===void 0?null:s(`TEXCOORD_3`,o.TEXCOORD_3,`VEC2`),S=o.TANGENT===void 0?null:s(`TANGENT`,o.TANGENT,`VEC4`),C=o.COLOR_0===void 0?null:s(`COLOR_0`,o.COLOR_0),w=C?C.length/l:0;if(f.length!==l*3||_&&_.length!==l*2||v&&v.length!==l*2||b&&b.length!==l*2||x&&x.length!==l*2||S&&S.length!==l*4||C&&![3,4].includes(w))throw RangeError(`Mismatched glTF attributes; the file holds invalid numbers, re-export it and check it with the glTF Validator`);let ee=(e,t,n)=>{let r=t*3,i=f[r],a=f[r+1],s=f[r+2],l=Math.hypot(i,a,s);if(e[n]=c[r],e[n+1]=c[r+1],e[n+2]=c[r+2],e[n+3]=1,!l||!Number.isFinite(l)){if(o.NORMAL!==void 0)throw RangeError(`Zero or non-finite glTF normal; the file holds invalid numbers, re-export it and check it with the glTF Validator`);e[n+6]=1}else e[n+4]=i/l,e[n+5]=a/l,e[n+6]=s/l;if(S){let r=t*4,i=Math.hypot(S[r],S[r+1],S[r+2]);i&&(e[n+8]=S[r]/i,e[n+9]=S[r+1]/i,e[n+10]=S[r+2]/i,e[n+11]=Math.sign(S[r+3]))}if(_&&(e[n+12]=_[t*2],e[n+13]=_[t*2+1]),v&&(e[n+14]=v[t*2],e[n+15]=v[t*2+1]),C){let r=t*w;e[n+16]=C[r],e[n+17]=C[r+1],e[n+18]=C[r+2],e[n+19]=w===3?1:C[r+3]}else e[n+16]=1,e[n+17]=1,e[n+18]=1,e[n+19]=1},T=(e,t,n)=>{b&&e.set(b.subarray(t*2,t*2+2),n),x&&e.set(x.subarray(t*2,t*2+2),n+2)},te=a<3?{topology:a===1?`point-list`:`line-list`}:{};if(!g){let e=new Float32Array(l*20),t=b||x?new Float32Array(l*4):void 0;for(let t=0;t<l;t++)ee(e,t,t*20);if(t)for(let e=0;e<l;e++)T(t,e,e*4);let r={vertices:e,indices:m,...te,...t?{uvs:t}:{}};return n?(n(r),[]):[r]}let ne=[];for(let e=0;e<g.length;e++){let{indices:t,vertexMap:r}=g[e],i=r.length,a=new Float32Array(i*20),o=b||x?new Float32Array(i*4):void 0;for(let e=0;e<i;e++)ee(a,r[e],e*20);if(o)for(let e=0;e<i;e++)T(o,r[e],e*4);let s={vertices:a,indices:t,...te,...o?{uvs:o}:{},part:{index:e,count:g.length,vertexMap:r}};n?n(s):ne.push(s)}return ne}function wt(e){let t=e.doc,n=[];for(let e of t.skins??[])n.push(e?.inverseBindMatrices);for(let e of t.meshes??[])for(let t of e?.primitives??[]){n.push(t?.attributes?.JOINTS_0,t?.attributes?.WEIGHTS_0);for(let e of t?.targets??[])n.push(e?.POSITION,e?.NORMAL)}for(let e of t.animations??[])for(let t of e?.samplers??[])n.push(t?.input,t?.output);for(let e of t.nodes??[])n.push(...Object.values(e?.extensions?.EXT_mesh_gpu_instancing?.attributes??{}));let r=[];for(let t of n)if(t!==void 0)try{r.push([t,e.accessor(t)])}catch{}return r}var Tt=e=>(e.meshes??[]).flatMap(e=>Array.isArray(e?.primitives)?e.primitives:[]);s(),l(),f(),vt(),D(),ee(),ie(),p();var Et=1<<20,X=262144,Dt=4;function Z(e,t,n){let r=[],i=!1;for(let a=0;a<e.length;a+=2){let o=e[a],s=e[a+1];s<t?r.push(o,s):o>n?(i||=(r.push(t,n),!0),r.push(o,s)):(t=Math.min(t,o),n=Math.max(n,s))}i||r.push(t,n),e.length=0;for(let t of r)e.push(t)}function Q(e,t,n){let r=[];for(let i=0;i<e.length&&t<n;i+=2)if(!(e[i+1]<=t)){if(e[i]>=n)break;e[i]>t&&r.push([t,e[i]]),t=Math.max(t,e[i+1])}return t<n&&r.push([t,n]),r}var $=(e,t,n)=>!Q(e,t,n).length,Ot=e=>{let{name:t=`Error`,code:n}=e??{};return{name:t,message:e instanceof Error?e.message:String(e),...typeof n==`string`?{code:n}:{}}},kt=class{constructor(e,t,n,r=V,i,a,o=!1,s=ue){this.url=e,this.post=t,this.signal=n,this.limit=r,this.maxNodes=i,this.allowedURLs=a,this.textures=o,this.partVertices=s,this.sources=[],this.map=[],this.needs=[],this.posted=new Set,this.waiters=[],this.inflight=0,this.pending=0,this.loaded=0,this.reported=0,this.base=e,n.addEventListener(`abort`,()=>this.notify(),{once:!0})}setOrder(e){this.order=e,this.notify()}notify(){for(let e of this.waiters.splice(0))e()}async next(){if(await new Promise(e=>this.waiters.push(e)),this.signal.throwIfAborted(),this.failure)throw this.failure}async run(){try{let e=await this.head();if(rt(e),(this.textures?lt(e):ut(e))||e.bufferViews?.some(e=>e?.extensions?.EXT_meshopt_compression||e?.extensions?.KHR_meshopt_compression)){this.post({type:`fallback`});return}for(this.post({type:`doc`,doc:e}),this.buffers(e);!this.order;)await this.next();await this.geometry(e),await this.images(e);for(let[e,t]of this.sources.entries())if(t.ranged!==!1){let n=Q(t.asked,0,t.data.length);for(let t=0;t<n.length;){let r=n[t][0],i=n[t++][1];for(;t<n.length&&n[t][0]-i<=X;)i=n[t++][1];this.request(e,r,i)}}for(;this.inflight||this.sources.some(e=>!$(e.got,0,e.data?.length??0));)await this.next();this.bytes(!0),this.post({type:`done`,buffers:this.asset.buffers,accessors:wt(this.asset)})}catch(e){this.signal.aborted||this.post({type:`error`,error:Ot(e)})}}bytes(e=!1){let t=Date.now();!e&&t-this.reported<100||(this.reported=t,this.post({type:`bytes`,loaded:this.loaded,total:this.sources.reduce((e,t)=>e+(t.size??0),0)}))}fetch(e,t,n=!1){if(![`http:`,`https:`].includes(e.url.protocol))throw TypeError(`glTF URL must use HTTP(S)`);return fetch(e.url,{signal:this.signal,headers:t}).then(e=>{if(n||C(e,this.base,this.allowedURLs,`glTF`),!e.ok)throw i(`failed`,`glTF download request failed: HTTP ${e.status}; check the URL and that the server allows the request`);return e})}allocate(e,t){if(!Number.isSafeInteger(t)||t>this.limit-this.sources.reduce((e,t)=>e+(t.data?.length??0),0))throw H(`glTF exceeds download budget`,this.limit);e.data=new Uint8Array(t),e.size??=t}async read(e,t,n,r={left:0}){let i=t.body.getReader(),a=()=>i.cancel().catch(()=>{});this.signal.addEventListener(`abort`,a,{once:!0});try{for(;;){let{done:t,value:o}=await i.read();if(this.signal.throwIfAborted(),t)break;let s=e.data.length-n,c=o.length>s?o.subarray(0,s):o;e.data.set(c,n),Z(e.got,n,n+c.length),this.loaded+=c.length,n+=c.length;let l=Math.min(c.length,r.left);if(r.left-=l,this.pending-=l,this.bytes(),this.notify(),n>=e.data.length){a();break}}}finally{this.signal.removeEventListener(`abort`,a)}}async head(){let e={url:this.url,got:[],asked:[]};this.sources.push(e);let t=await this.fetch(e,{Range:`bytes=0-65535`},!0),n=/^bytes 0-\d+\/(\d+|\*)$/.exec(t.headers.get(`content-range`)??``),r=n&&n[1]!==`*`?Number(n[1]):void 0;t.url&&(e.url=this.base=new URL(t.url)),e.ranged=t.status===206&&!!n;let i=t.body.getReader(),a=[],o=0;for(;o<12;){let{done:e,value:t}=await i.read();if(e)break;a.push(t),o+=t.length}let s=new Uint8Array(o);a.reduce((e,t)=>(s.set(t,e),e+t.length),0);let c=new DataView(s.buffer);if(o<12||c.getUint32(0,!0)!==1179937895){for(let e;!(e=await i.read()).done;)if(a.push(e.value),(o+=e.value.length)>this.limit)throw i.cancel().catch(()=>{}),H(`glTF JSON exceeds byte budget`,this.limit);let t=r===void 0?o-1:o;e.ranged&&(r===void 0?o>=65536:r>o)&&a.push((await re(await this.fetch(e,{Range:`bytes=${t}-`}),{maxBytes:this.limit-t,signal:this.signal,label:`glTF JSON`}).catch(e=>{throw e instanceof RangeError?H(`glTF JSON exceeds byte budget`,this.limit):e})).subarray(o-t));let n=new Uint8Array(a.reduce((e,t)=>e+t.length,0));if(a.reduce((e,t)=>(n.set(t,e),e+t.length),0),this.loaded+=n.length,n.length>this.limit)throw H(`glTF JSON exceeds byte budget`,this.limit);return this.sources.length=0,$e(n,e.url.href),nt(n)}let l=c.getUint32(8,!0);if(c.getUint32(4,!0)!==2||l<20||r!==void 0&&r!==l)throw TypeError(`Invalid GLB header; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);this.allocate(e,l),e.data.set(s.subarray(0,l)),Z(e.got,0,Math.min(o,l)),this.loaded+=o;let u=o,d=(async()=>{try{for(;;){let{done:t,value:n}=await i.read();if(this.signal.throwIfAborted(),t)break;let r=n.subarray(0,Math.max(0,l-u));e.data.set(r,u),Z(e.got,u,u+r.length),this.loaded+=r.length,u+=r.length,this.bytes(),this.notify()}if(!e.ranged&&u<l)throw RangeError(`Truncated GLB; download the file again, it is incomplete`)}catch(e){this.failure??=e,this.notify()}})();if(Z(e.asked,0,e.ranged?Math.min(65536,l):l),e.ranged&&(await d,!this.failure&&!$(e.got,0,Math.min(65536,l))))throw RangeError(`Truncated glTF range response; download the file again, it is incomplete`);let f=()=>new DataView(e.data.buffer).getUint32(12,!0),p=()=>Math.min(l,28+f());for(;!$(e.got,0,20);)await this.next();if(f()%4||20+f()>l||new DataView(e.data.buffer).getUint32(16,!0)!==1313821514)throw TypeError(`Invalid GLB chunk; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(e.ranged)for(let[t,n]of Q(e.got,0,p()))this.request(0,t,n);for(;!$(e.got,0,p());)await this.next();return nt(e.data.subarray(20,20+f()))}buffers(e){let t=this.sources[0],n=new Map,r=0,i=0,a=0;if(t){let e=t.data,n=new DataView(e.buffer),o=20+n.getUint32(12,!0);o+8<=e.length&&$(t.got,o,o+8)&&n.getUint32(o+4,!0)===5130562&&(r=o+8,a=n.getUint32(o,!0),i=Math.min(a,e.length-r))}let o=(e.buffers??[]).map((e,o)=>{if(e?.uri===void 0)return o===0&&t&&i?(c(a,e.byteLength),this.map.push({source:0,offset:r}),t.data.subarray(r,r+i)):(this.map.push({source:-1,offset:0}),new Uint8Array);if(typeof e.uri==`string`&&e.uri.startsWith(`data:`)){this.map.push({source:-1,offset:0});let t=B(e.uri,this.limit);return this.loaded+=t.length,t}let s=S(e.uri,this.base,this.allowedURLs,`glTF`).href,l=n.get(s);if(l===void 0){l=this.sources.length,n.set(s,l);let t={url:new URL(s),got:[],asked:[]};this.sources.push(t),this.allocate(t,Number.isSafeInteger(e.byteLength)&&e.byteLength>0?e.byteLength:0)}return this.map.push({source:l,offset:0}),this.sources[l].data});this.asset=new _t(e,o,void 0,{},this.limit,this.maxNodes),this.asset.partVertices=this.partVertices,this.needs=Tt(e).map(t=>{let n=[],r=t?.attributes??{};try{let i=bt(e,t)?[r.TEXCOORD_2,r.TEXCOORD_3]:[];for(let a of[r.POSITION,r.NORMAL,r.TANGENT,r.TEXCOORD_0,r.TEXCOORD_1,...i,r.COLOR_0,t.indices])a!==void 0&&this.ranges(e,a,n)}catch{for(let[e,t]of this.map.entries())t.source>=0&&n.push([t.source,t.offset,t.offset+this.asset.buffers[e].length])}return n})}ranges(e,t,n){let r=z(e.accessors,t,`accessor`),i=d[r.componentType],a=q[r.type],o=r.count,s=(t,r,i)=>{let a=z(e.bufferViews,t,`bufferView`),o=this.map[a.buffer],s=(a.byteOffset??0)+r,c=(a.byteOffset??0)+a.byteLength;if(!o||!Number.isSafeInteger(s)||s<0||!Number.isSafeInteger(c)||!(i>0))throw TypeError(`range; pass a { start, end } byte range`);let l=Math.min(s+i,c,this.asset.buffers[a.buffer].length);o.source>=0&&s<l&&n.push([o.source,o.offset+s,o.offset+l])};if(r.bufferView!==void 0&&s(r.bufferView,r.byteOffset??0,(o-1)*(z(e.bufferViews,r.bufferView,`bufferView`).byteStride??i*a)+i*a),r.sparse){let e=r.sparse.count;s(r.sparse.indices.bufferView,r.sparse.indices.byteOffset??0,e*d[r.sparse.indices.componentType]),s(r.sparse.values.bufferView,r.sparse.values.byteOffset??0,e*i*a)}}request(e,t,n){let r=this.sources[e],i={left:n-t};Z(r.asked,t,n),this.inflight++,this.pending+=n-t,r.ranged===void 0&&(r.probing=!0),(async()=>{let e=await this.fetch(r,{Range:`bytes=${t}-${n-1}`}),a=/^bytes (\d+)-\d+\/(\d+|\*)$/.exec(e.headers.get(`content-range`)??``);if(e.status===206&&a&&+a[1]===t){if(r.ranged===void 0&&a[2]!==`*`&&+a[2]<r.data.length)throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`);if(r.ranged=!0,await this.read(r,e,t,i),!$(r.got,t,Math.min(n,r.data.length)))throw RangeError(`Truncated glTF range response; download the file again, it is incomplete`)}else if(r.ranged=!1,Z(r.asked,0,r.data.length),await this.read(r,e,0,i),!$(r.got,0,r.data.length))throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`)})().catch(e=>{this.failure??=e}).finally(()=>{this.inflight--,this.pending-=i.left,r.probing=!1,this.notify()})}ready(e){return this.needs[e].every(([e,t,n])=>$(this.sources[e].got,t,n))}async geometry(e){let t=Tt(e);for(;;){if(this.failure)throw this.failure;let e=this.order.filter(e=>!this.posted.has(e));for(let n of e)if(this.ready(n)){this.posted.add(n);try{xt(this.asset,t[n],({vertices:e,indices:t,uvs:r,part:i})=>this.post({type:`geometry`,key:n,vertices:e,indices:t,uvs:r,...i?{part:i}:{}}))}catch(e){this.post({type:`geometry`,key:n,error:Ot(e)})}}if(this.order.every(e=>this.posted.has(e)))return;let n=Et,r=[];for(let t of e){if(this.inflight>=Dt||n<=0||this.pending>=Et)break;for(let[e,i,a]of this.needs[t]){let t=this.sources[e];if(!(t.ranged===!1||t.probing)){for(let[o,s]of Q(t.asked,i-i%X,Math.min(t.data.length,Math.ceil(a/X)*X)))if(r.push([e,o,s]),Z(t.asked,o,s),n-=s-o,t.ranged===void 0){t.probing=!0;break}}}}r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);for(let e=0;e<r.length;){let[t,n,i]=r[e++];for(;e<r.length&&r[e][0]===t&&r[e][1]<=i;)i=Math.max(i,r[e++][2]);this.request(t,n,i)}r.length||await this.next()}}async textureSource(e,t){if(t.bufferView===void 0){if(typeof t.uri!=`string`)throw TypeError(`Invalid glTF image; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return t.uri.startsWith(`data:`)?{bytes:B(t.uri,this.limit)}:{url:S(t.uri,this.base,this.allowedURLs,`glTF`).href}}this.asset.view(t.bufferView);let n=z(e.bufferViews,t.bufferView,`bufferView`),r=this.map[n.buffer];if(r?.source>=0){let e=this.sources[r.source],t=r.offset+(n.byteOffset??0),i=t+n.byteLength;for(;e.ranged===void 0;)e.probing||this.request(r.source,t,Math.min(i,t+1)),await this.next();if(e.ranged)return Z(e.asked,t,i),Z(e.got,t,i),{url:e.url.href,offset:t,length:n.byteLength};for(;!$(e.got,t,Math.min(i,e.data.length));)await this.next()}return{bytes:this.asset.view(t.bufferView).slice()}}async images(e){let t=Tt(e),n=[],r=e.images??[],i=t=>e.materials?.[t?.material],a=(e,t=[],n=0)=>{if(e&&typeof e==`object`&&n<8){let r=e.index;typeof r==`number`&&Number.isSafeInteger(r)&&r>=0&&t.push(r);for(let r of Object.values(e))a(r,t,n+1)}return t};for(let r of this.order)for(let o of a(i(t[r]))){let t=e.textures?.[o];for(let e of[t?.source,...Object.values(t?.extensions??{}).map(e=>e?.source)])Number.isInteger(e)&&!n.includes(e)&&n.push(e)}let o=[...n,...r.map((e,t)=>t).filter(e=>!n.includes(e))].filter(e=>e<r.length),s=0,c=this.textures?ot(e):new Set,l=async t=>{let n=r[t],i=n.mimeType===`image/ktx2`||/\.ktx2$/i.test(n.uri??``);if(i&&this.textures){this.post({type:`image`,index:t,source:await this.textureSource(e,n)});return}if(i||c.has(t)){this.post({type:`image`,index:t});return}let a;if(n.bufferView!==void 0){this.asset.view(n.bufferView);let t=z(e.bufferViews,n.bufferView,`bufferView`),r=this.map[t.buffer];if(r?.source>=0){let e=this.sources[r.source],n=r.offset+(t.byteOffset??0),i=n+t.byteLength;if(e.ranged){let t=Q(e.asked,n,i);for(let[e,n]of t)this.request(r.source,e,n)}for(;!$(e.got,n,Math.min(i,e.data.length));)e.ranged===void 0&&!e.probing&&this.request(r.source,n,i),await this.next()}a=this.asset.view(n.bufferView)}else if(typeof n.uri==`string`&&n.uri.startsWith(`data:`))a=B(n.uri,this.limit);else if(typeof n.uri==`string`)a=await re(await this.fetch({url:S(n.uri,this.base,this.allowedURLs,`glTF`),got:[],asked:[]}),{maxBytes:Math.max(0,this.limit-this.loaded),signal:this.signal,label:`glTF image`}).catch(e=>{throw e instanceof RangeError?H(`glTF exceeds download budget`,this.limit):e}),this.loaded+=a.length;else throw TypeError(`Invalid glTF image; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let o=await ct(a,n.mimeType,t,this.signal);if(s+=o.width*o.height*4,o.width*o.height>67108864)throw`close`in o&&o.close(),RangeError(`glTF images exceed decoded size limit; load a smaller model, or reduce its textures and meshes`);if(s>this.limit*4)throw`close`in o&&o.close(),H(`glTF images exceed decoded size limit`,this.limit*4);this.post({type:`image`,index:t,image:o})},u=Array.from({length:Dt},async()=>{for(let e;(e=o.shift())!==void 0;)await l(e)});await Promise.all(u)}},At=self,jt;At.onmessage=({data:e})=>{if(!e||typeof e!=`object`)return;let t=e;Array.isArray(t.order)?t.order.every(Number.isSafeInteger)&&jt?.setOrder(t.order):!jt&&typeof t.url==`string`&&(jt=new kt(new URL(t.url),e=>At.postMessage(e,[...r(e)]),new AbortController().signal,t.maxDownloadBytes,t.maxNodes,t.allowedURLs,t.textures===!0,t.maxPartVertices)).run()}})();
|
|
1
|
+
(function(){var e=Object.defineProperty,t=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},n=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};function r(e,t=new Set,n=new Set){let r=[e];for(;r.length;){let e=r.pop();if(e&&typeof e==`object`&&!n.has(e)){if(n.add(e),ArrayBuffer.isView(e))e.buffer instanceof ArrayBuffer&&t.add(e.buffer);else if(e instanceof ArrayBuffer)t.add(e);else if(typeof ImageBitmap<`u`&&e instanceof ImageBitmap)t.add(e);else if(e instanceof Map)for(let[t,n]of e)r.push(t,n);else for(let t in e)r.push(e[t])}}return t}var i,a,o,s=t((()=>{i=(e,t)=>Object.assign(Error(t),{name:`MargoError`,code:e}),a=(e,t)=>`${e}; see https://margoengine.com/errors#${t}`,o=(e,t,n=e)=>i(e,a(t,n))}));function c(e,t){if(Number.isSafeInteger(t)&&e>t+3)throw o(`failed`,`GLB BIN chunk holds ${e} bytes, more than buffer 0's byteLength ${t} plus 3 padding bytes; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}var l=t((()=>{s()}));function u(e,t,n){return n===5126?e.getFloat32(t,!0):n===5125?e.getUint32(t,!0):n===5123?e.getUint16(t,!0):n===5122?e.getInt16(t,!0):n===5121?e.getUint8(t):e.getInt8(t)}var d,f=t((()=>{d={__proto__:null,5120:1,5121:1,5122:2,5123:2,5125:4,5126:4}})),p=t((()=>{}));function m(e){let t=/^(\d+)\.(\d+)$/,n=typeof e?.version==`string`?t.exec(e.version):null;if(!n||n[1]!==`2`)return!1;if(e.minVersion===void 0)return!0;let r=typeof e.minVersion==`string`?t.exec(e.minVersion):null;return!!r&&r[1]===`2`&&r[2]===`0`}var h=t((()=>{})),g,_,v,y=t((()=>{g=/"(?:__proto__|constructor|prototype)"|\\u/,_=(e,t)=>e===`__proto__`||e===`constructor`||e===`prototype`?void 0:t,v=e=>g.test(e)?JSON.parse(e,_):JSON.parse(e)}));function b(e){for(let t=0;t<8;t++){if(w.test(e))return!0;let t=e.replace(/%[\da-f]{2}/gi,e=>String.fromCharCode(`0x${e.slice(1)}`));if(t===e)return!1;e=t}return!0}function x(e,t){let n;try{n=new URL(t)}catch{throw TypeError(`allowedURLs entry ${String(t)} is not an absolute URL; pass a full http(s) URL`)}if(n.origin!==e.origin||n.protocol!==`http:`&&n.protocol!==`https:`||n.search&&n.search!==e.search)return!1;let r=n.pathname;return r.endsWith(`/`)?e.pathname.startsWith(r):e.pathname===r||e.pathname.startsWith(`${r}/`)}function S(e,t,n=[],r=`Asset`){if(typeof e!=`string`||!e||e.length>8192)throw TypeError(`Invalid ${r} URI; pass a shorter string`);let i;try{i=new URL(e,t)}catch{throw TypeError(`Invalid ${r} URI; pass a valid URL`)}if((i.protocol===`http:`||i.protocol===`https:`)&&!b(i.pathname)){for(let e of n)if(x(i,e))return i;let e=t===void 0?void 0:new URL(`.`,t);if(e&&i.origin===e.origin&&i.pathname.startsWith(e.pathname))return i}throw TypeError(`${r} URI ${i.href} leaves the model's directory; add its prefix to allowedURLs to load it`)}function C(e,t,n=[],r=`Asset`){if(!e.url)return e;try{S(e.url,t,n,r)}catch{throw e.body?.cancel().catch(()=>{}),TypeError(`${r} URI redirected to ${e.url}, which leaves the model's directory; add its prefix to allowedURLs to load it`)}return e}var w,ee=t((()=>{w=/%2f|%5c|%00|\u0000|(^|\/)(\.|%2e){1,2}(\/|$)/i})),T,te=t((()=>{T=class{constructor(...e){this.failed=e.length>0,this.error=e[0]}run(e){try{e()}catch(e){this.failed||(this.error=e),this.failed=!0}return this}finish(){if(this.failed)throw this.error}}}));async function ne(e,{maxBytes:t,signal:n,label:r=`Asset`,output:i=null,expected:a=0}){if(!Number.isSafeInteger(t)||t<0||i!==null&&(!(i instanceof Uint8Array)||i.length!==t))throw RangeError(`Invalid asset byte budget; pass maxBytes as an integer`);if(n?.throwIfAborted(),!e)throw TypeError(`Empty ${r} response; check the URL`);let o=e.getReader(),s=[],c=0,l=i,u=new T,d=e=>{try{Promise.resolve(o.cancel(e)).catch(()=>{})}catch{}},f=()=>d(n.reason);n?.addEventListener(`abort`,f,{once:!0});try{for(!i&&Number.isSafeInteger(a)&&a>0&&a<=t&&(l=new Uint8Array(a));;){n?.throwIfAborted();let{done:e,value:i}=await o.read();if(n?.throwIfAborted(),e)break;if(!(i instanceof Uint8Array))throw TypeError(`${r} stream requires byte chunks`);if(i.byteLength>t-c)throw RangeError(`${r} byte budget exceeded; raise maxBytes`);l&&i.length<=l.length-c?l.set(i,c):(l&&s.push(l.subarray(0,c)),l=null,s.push(i.length<i.buffer.byteLength||!(i.buffer instanceof ArrayBuffer)?i.slice():i)),c+=i.byteLength}}catch(e){d(e),u=new T(e)}if(u.run(()=>n?.removeEventListener(`abort`,f)).run(()=>o.releaseLock()).finish(),i)return i.subarray(0,c);if(l)return c<l.length?l.slice(0,c):l;let p=new Uint8Array(c),m=0;for(let e of s)p.set(e,m),m+=e.length;return p}async function re(e,t){try{if(t.signal?.throwIfAborted(),!e.ok)throw i(`failed`,`${t.label??`Asset`} request failed: HTTP ${e.status}; check the URL and that the server serves it`);let n=Number(e.headers.get(`content-length`));if(Number.isFinite(n)&&n>t.maxBytes)throw RangeError(`${t.label??`Asset`} byte budget exceeded; raise maxBytes`);let r=e.headers.get(`content-encoding`);(!r||r===`identity`)&&(t={...t,expected:n})}catch(t){try{Promise.resolve(e.body?.cancel(t)).catch(()=>{})}catch{}throw t}return ne(e.body,t)}var ie=t((()=>{s(),te()}));function ae(e,t=1e5){if(!Number.isSafeInteger(t)||t<1||t>8388608)throw RangeError(`${e} must be an integer from 1 to 8388608`);return t}function oe(e,t,n,r){if(t>n)throw RangeError(`${e} (${t} > ${n}; raise the ${r} option)`)}var se=t((()=>{}));function ce(e,t,n,r,i){let a=e.length/t,o=1/0,s=1/0,c=1/0,l=-1/0,u=-1/0,d=-1/0;for(let e=0;e<r*i;e+=i){let t=n[e],r=n[e+1],i=n[e+2];t<o&&(o=t),t>l&&(l=t),r<s&&(s=r),r>u&&(u=r),i<c&&(c=i),i>d&&(d=i)}let f=1023.999/(Math.max(l-o,u-s,d-c)||1),p=f,m=f,h=new Uint32Array(a),g=e=>(e=(e|e<<16)&50331903,e=(e|e<<8)&50393103,e=(e|e<<4)&51130563,(e|e<<2)&153391689);for(let r=0,l=0;r<a;r++,l+=t){let a=0,u=0,d=0;for(let r=0;r<t;r++){let t=e[l+r]*i;a+=n[t],u+=n[t+1],d+=n[t+2]}h[r]=(g((a/t-o)*f|0)<<2|g((u/t-s)*p|0)<<1|g((d/t-c)*m|0))>>>0}let _=new Uint32Array(a),v=new Uint32Array(a);for(let e=0;e<a;e++)_[e]=e;let y=new Uint32Array(1024);for(let e=0;e<30;e+=10){y.fill(0);for(let t=0;t<a;t++)y[h[t]>>>e&1023]++;for(let e=0,t=0;e<1024;e++){let n=y[e];y[e]=t,t+=n}for(let t=0;t<a;t++){let n=_[t];v[y[h[n]>>>e&1023]++]=n}[_,v]=[v,_]}return _}function le(e,t,n,r,i,a=3){let o=e.length/t,s=i?ce(e,t,i,n,a):null,c=new Int32Array(n).fill(-1),l=new Uint32Array(r),u=new Uint32Array(e.length),d=[],f=0,p=0,m=0,h=()=>{d.push({indices:u.slice(p,m),vertexMap:l.slice(0,f)});for(let e=0;e<f;e++)c[l[e]]=-1;f=0,p=m};for(let n=0;n<o;n++){let i=(s?s[n]:n)*t,a=0;for(let n=0;n<t;n++){let t=e[i+n];if(c[t]>=0)continue;let r=!1;for(let a=0;a<n;a++)e[i+a]===t&&(r=!0);r||a++}f+a>r&&h();for(let n=0;n<t;n++){let t=e[i+n];c[t]<0&&(c[t]=f,l[f++]=t),u[m++]=c[t]}}return m>p&&h(),d}var ue,E,de=t((()=>{ue=262144,E=16777216})),fe,pe,me=t((()=>{fe=e=>!!e?.extensions&&typeof e.extensions==`object`&&`KHR_gaussian_splatting`in e.extensions,pe=e=>!!e.meshes?.some(e=>e?.primitives?.some(fe))})),he,ge=t((()=>{he=(e,t)=>Object.assign(Error(e,t===void 0?void 0:{cause:t}),{name:`MargoError`,code:`failed`})}));function _e(e){for(let t of e.doc.meshes??[])for(let e of t.primitives??[])if(e.extensions?.KHR_draco_mesh_compression)return!0;return!1}function ve(e,t){if(!t.extensions?.KHR_draco_mesh_compression)return;let n=D.get(e)?.get(t);if(!n)throw i(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);return n}var D,ye=t((()=>{s(),D=new WeakMap}));async function be(){throw TypeError(`createImageBitmap is not available in this worker; load the model on the page or in Node to decode its images`)}var xe=t((()=>{}));function Se(e,t,n){return e===`ATTRIBUTES`?256*(Math.floor(4*t/n)+1):e===`TRIANGLES`?3*t:e===`INDICES`?t:1/0}var Ce=t((()=>{})),we=n({MeshoptDecoder:()=>qe,meshoptDecodeGltfBuffer:()=>Le,meshoptDecodeIndexBuffer:()=>Ae,meshoptDecodeIndexSequence:()=>je,meshoptDecodeVertexBuffer:()=>Ee});function Te(e,t,n,r,i){if(n===0)return r.fill(0,i,i+16),t;if(n===8){for(let n=0;n<16;n++)r[i+n]=e[t+n];return t+16}let a=t+n*2;if(n===1)for(let n=0;n<16;n++){let o=e[t+(n>>3)]>>(n&7)&1;r[i+n]=o===1?e[a++]:0}else if(n===2)for(let n=0;n<16;n++){let o=e[t+(n>>2)]>>6-2*(n&3)&3;r[i+n]=o===3?e[a++]:o}else for(let n=0;n<16;n++){let o=e[t+(n>>1)]>>4-4*(n&1)&15;r[i+n]=o===15?e[a++]:o}return a}function Ee(e,t,n,r){(!Number.isInteger(n)||n<1||n>256||n%4!=0)&&k(`invalid ATTRIBUTES byteStride ${n}`),(!Number.isSafeInteger(t)||t<0||e.length<t*n)&&A(`invalid count or output size`);let i=r.length;i<1+n&&k(`truncated vertex stream`);let a=r[0];a>>4!=10&&k(`bad vertex stream header`);let o=a&15;o>1&&k(`vertex codec version ${o} is not supported (only versions 0 and 1)`);let s=n>>2,c=o===1;c&&i<1+n+s&&k(`truncated vertex stream`);let l=c?Math.max(24,n+s):Math.max(32,n),u=i-n-(c?s:0),d=i-s,f=new Uint8Array(n);for(let e=0;e<n;e++)f[e]=r[u+e];let p=Math.min(Math.floor(8192/n)&-16,256),m=new Uint8Array(n*256),h=1,g=!1;for(let a=0;a<t;a+=p){let o=Math.min(t-a,p),l=o+15>>4,u=0;c&&(h+s>i&&k(`truncated vertex stream`),u=h,h+=s);for(let e=0;e<n;e++){let t=e*256,n=Be;if(c){let a=r[u+(e>>2)]>>(e&3)*2&3;if(a===2){m.fill(0,t,t+l*16);continue}if(a===3){i-h<o+ze&&k(`truncated vertex stream`);for(let e=0;e<o;e++)m[t+e]=r[h+e];h+=o;continue}n=Ve[a]}let a=l+3>>2;h+a>i&&k(`truncated vertex stream`);let s=h;h+=a;for(let e=0;e<l;e++){i-h<ze&&k(`truncated vertex stream`);let a=r[s+(e>>2)]>>(e&3)*2&3;h=Te(r,h,n[a],m,t+e*16)}}c&&!g&&(g=De(r,d,s));for(let t=0;t<o;t++){let i=(a+t)*n;for(let n=0;n<s;n++){let a=n*4,o=c?r[d+n]:0,s=o&15;if(s===0)for(let n=a;n<a+4;n++){let r=f[n]+He(m[n*256+t])&255;f[n]=r,e[i+n]=r}else if(s===1)for(let n=a;n<a+4;n+=2){let r=Ue(m[n*256+t]|m[(n+1)*256+t]<<8),a=f[n]+(f[n+1]<<8)+r&65535;f[n]=a&255,f[n+1]=a>>8,e[i+n]=a&255,e[i+n+1]=a>>8}else{let n=o>>4,r=(m[a*256+t]|m[(a+1)*256+t]<<8|m[(a+2)*256+t]<<16|m[(a+3)*256+t]<<24)>>>0,s=r>>>n|r<<(32-n&31);for(let t=0;t<4;t++){let n=f[a+t]^s>>>8*t&255;f[a+t]=n,e[i+a+t]=n}}}}}i-h!==l&&k(`vertex stream has trailing or missing data`),c&&!g&&De(r,d,s)}function De(e,t,n){for(let r=0;r<n;r++){let n=e[t+r],i=n&15;(i>2||i<2&&n>>4)&&k(`invalid vertex channel mode`)}return!0}function Oe(e,t){let n=0,r=0,i=t.pos;for(let t=0;;t++){i>=e.length&&k(`truncated index stream`);let a=e[i++];if(n|=(a&127)<<r,r+=7,a<128)break;t===4&&k(`index varint is longer than 5 bytes`)}return t.pos=i,n>>>0}function ke(e,t){(!Number.isSafeInteger(t)||t<0||e.length<t)&&A(`invalid count or output size`)}function O(e,t){return t>65535&&e instanceof Uint16Array&&k(`index ${t} does not fit a 16-bit index buffer`),t}function Ae(e,t,n){ke(e,t),t%3!=0&&k(`TRIANGLES count must be a multiple of 3`);let r=t/3,i=n.length;i<1+r+16&&k(`truncated index stream`);let a=n[0];a>>4!=14&&k(`bad index stream header`);let o=a&15;o>1&&k(`index codec version ${o} is not supported`);let s=o===1?13:15,c=i-16;for(let e=0;e<16;e++){let t=n[c+e];(e>=14?t!==0:(t&15)==15||t>>4==15)&&k(`invalid codeaux table`)}let l=new Uint32Array(16),u=new Uint32Array(16),d=new Uint32Array(16),f=0,p=0,m=0,h=0,g=(e,t)=>{l[f]=e,u[f]=t,f=f+1&15,m<16&&m++},_=e=>{d[p]=e,p=p+1&15,h<16&&h++},v=e=>(e>=h&&k(`triangle code reads a vertex FIFO entry that was never written`),d[p-1-e&15]),y=0,b=0,x={pos:1+r},S=()=>{let e=Oe(n,x);return b=b+(e&1?~(e>>>1):e>>>1)>>>0,b};for(let t=0;t<r;t++){x.pos>c&&k(`truncated index stream`);let r=n[1+t],i=r>>4,a=r&15,o,d,p;if(i<15){i>=m&&k(`triangle code reads an edge FIFO entry that was never written`);let e=f-1-i&15;o=l[e],d=u[e],a===0?(p=y,y=y+1>>>0,_(p)):a<s?p=v(a):a<15?(p=(a===13?b-1:b+1)>>>0,b=p,_(p)):(p=S(),_(p)),g(p,d),g(o,p)}else{let e,t;if(a<14){let r=n[c+a];e=r>>4,t=r&15,o=y,y=y+1>>>0}else{let r=n[x.pos++];r===0&&(y=0),e=r>>4,t=r&15,a===14?(o=y,y=y+1>>>0):o=S()}e===0?(d=y,y=y+1>>>0):d=e<15?v(e-1):S(),t===0?(p=y,y=y+1>>>0):p=t<15?v(t-1):S(),g(d,o),g(p,d),g(o,p),_(o),(e===0||e===15)&&_(d),(t===0||t===15)&&_(p)}e[t*3]=O(e,o),e[t*3+1]=O(e,d),e[t*3+2]=O(e,p)}x.pos!==c&&k(`index stream has trailing or missing data`)}function je(e,t,n){ke(e,t);let r=n.length;r<1+t+4&&k(`truncated index sequence`);let i=n[0];i>>4!=13&&k(`bad index sequence header`);let a=i&15;a>1&&k(`index sequence version ${a} is not supported`);let o=r-4,s=[0,0],c={pos:1};for(let r=0;r<t;r++){c.pos>=o&&k(`truncated index sequence`);let t=Oe(n,c),i=t&1,a=s[i]+(t&2?~(t>>>2):t>>>2)>>>0;s[i]=a,e[r]=O(e,a)}c.pos!==o&&k(`index sequence has trailing or missing data`)}function Me(e,t,n){let r=n===8,i=r?32767:127,a=r?2:1,o=r?t=>e.getInt16(t,!0):t=>e.getInt8(t),s=r?(t,n)=>e.setInt16(t,n,!0):(t,n)=>e.setInt8(t,n);for(let e=0,r=0;e<t;e++,r+=n){let e=o(r),t=o(r+a),n=o(r+2*a)-Math.abs(e)-Math.abs(t);n<0&&(e+=e>=0?n:-n,t+=t>=0?n:-n);let c=j(j(e*e)+j(j(t*t)+j(n*n)));if(c===0){s(r,0),s(r+a,0),s(r+2*a,0);continue}let l=j(i/j(Math.sqrt(c)));s(r,N(j(e*l))),s(r+a,N(j(t*l))),s(r+2*a,N(j(n*l)))}}function Ne(e,t){for(let n=0,r=0;n<t;n++,r+=8){let t=e.getInt16(r,!0),n=e.getInt16(r+2,!0),i=e.getInt16(r+4,!0),a=e.getInt16(r+6,!0),o=a&3,s=a|3,c=j(j(2*j(s*s))-j(j(t*t)+j(j(n*n)+j(i*i)))),l=j(Math.sqrt(Math.max(c,0))),u=j(Ke/s);e.setInt16(r+(o+1&3)*2,N(j(t*u)),!0),e.setInt16(r+(o+2&3)*2,N(j(n*u)),!0),e.setInt16(r+(o+3&3)*2,N(j(i*u)),!0),e.setInt16(r+o*2,N(j(l*u)),!0)}}function Pe(e,t){for(let n=0,r=0;n<t;n++,r+=4){let t=e.getInt32(r,!0);e.setFloat32(r,(t<<8>>8)*2**(t>>24),!0)}}function Fe(e,t,n){let r=n===8,i=r?65535:255,a=r?65535:255,o=r?2:1,s=r?t=>e.getUint16(t,!0):t=>e.getUint8(t),c=r?t=>e.getInt16(t,!0):t=>e.getInt8(t),l=r?(t,n)=>e.setUint16(t,n,!0):(t,n)=>e.setUint8(t,n);for(let e=0,r=0;e<t;e++,r+=n){let e=s(r),t=c(r+o),n=c(r+2*o),u=s(r+3*o),d=u===0?0:2**(32-Math.clz32(u))-1,f=j(i/d),p=e+t-n,m=e+n,h=e-t-n,g=u<<1&d|u&1;l(r,P(j(p*f))&a),l(r+o,P(j(m*f))&a),l(r+2*o,P(j(h*f))&a),l(r+3*o,P(j(g*f))&a)}}function Ie(e,t,n,r){let i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(r){case`OCTAHEDRAL`:n!==4&&n!==8&&k(`OCTAHEDRAL filter requires byteStride 4 or 8`),Me(i,t,n);return;case`QUATERNION`:n!==8&&k(`QUATERNION filter requires byteStride 8`),Ne(i,t);return;case`EXPONENTIAL`:Pe(i,t*n>>2);return;case`COLOR`:n!==4&&n!==8&&k(`COLOR filter requires byteStride 4 or 8`),Fe(i,t,n);return;default:k(`unknown filter '${r}'`)}}function Le(e,t,n,r,i=`NONE`){(!Number.isSafeInteger(t)||t<0||!Number.isSafeInteger(n)||n<=0||t*n>2**31)&&A(`invalid count or byteStride`);let a=e.length;t>Se(r,a,n)&&A(`truncated stream (${t} elements cannot fit in ${a} bytes)`);let o;if(r===`ATTRIBUTES`)o=new Uint8Array(t*n),Ee(o,t,n,e);else if(r===`TRIANGLES`||r===`INDICES`){n!==2&&n!==4&&k(`${r} byteStride must be 2 or 4`),o=new Uint8Array(t*n);let i=n===2?new Uint16Array(o.buffer,0,t):new Uint32Array(o.buffer,0,t);r===`TRIANGLES`?Ae(i,t,e):je(i,t,e)}else return k(`unknown mode '${r}'`);return i&&i!==`NONE`&&(r!==`ATTRIBUTES`&&k(`filters only apply to ATTRIBUTES`),Ie(o,t,n,i)),o}var Re,k,A,ze,Be,Ve,He,Ue,j,M,N,We,Ge,P,Ke,qe,Je=t((()=>{ge(),Ce(),Re=`EXT_meshopt_compression: `,k=e=>{throw he(Re+e)},A=e=>{throw RangeError(Re+e)},ze=24,Be=[0,2,4,8],Ve=[[0,1,2,4],[1,2,4,8]],He=e=>(e&1?~(e>>1):e>>1)&255,Ue=e=>(e&1?~(e>>1):e>>1)&65535,j=Math.fround,M=12582912,N=e=>j(e+M)-M,We=new Float32Array(1),Ge=new Uint32Array(We.buffer),P=e=>(We[0]=e+M,Ge[0]),Ke=j(32767/Math.SQRT2),qe={supported:!0,ready:Promise.resolve(),decodeGltfBuffer(e,t,n,r,i,a){let o=Le(r,t,n,i,a);e.byteLength<t*n&&A(`target buffer is too small`),e.set(o)}}})),Ye=n({decompressPrimitive:()=>Ze,decompressPrimitives:()=>Xe});async function Xe(e,{signal:t,draco:n}={}){t?.throwIfAborted();let r,i=async()=>{if(!n){let{DracoDecoder:i}=await ft(e,`Draco`)();t?.throwIfAborted(),n=r=new i}return n};try{for(let n of e.doc.meshes??[])for(let r of n.primitives??[])await Ze(e,r,i,t)}finally{r?.dispose()}}async function Ze(e,t,n,r){let a=D.get(e)??new Map;D.set(e,a);let o=t.extensions?.KHR_draco_mesh_compression;if(!o||a.has(t))return;if((t.mode??4)!==4)throw i(`unsupported`,`PBR requires triangle primitives; re-export the mesh with mode 4 (TRIANGLES)`);if(!o.attributes||typeof o.attributes!=`object`||Array.isArray(o.attributes))throw TypeError(`Invalid glTF Draco attributes; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let s={},c={},l={},u=L(e.doc.accessors,t.attributes?.POSITION,`Draco POSITION`),d=I(u.count,`Draco vertex count`,3);if(d>16777216)throw i(`unsupported`,`glTF primitive has more than ${E} vertices, the most one primitive may hold; split the mesh into several primitives`);if(u.type!==`VEC3`)throw RangeError(`Invalid glTF Draco POSITION size; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let f=0;for(let[n,r]of Object.entries(o.attributes)){let i=L(e.doc.accessors,t.attributes?.[n],`Draco attribute`),a=I(i.count,`Draco accessor count`,1),o=Object.hasOwn(F,i.type)?F[i.type]:void 0;if(!o||a!==d)throw RangeError(`Invalid glTF Draco accessor size; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);f+=a*o*4,s[n]=I(i.componentType,`Draco component type`),c[n]=I(r,`Draco attribute id`),l[n]=o}let p=t.indices===void 0?void 0:L(e.doc.accessors,t.indices,`Draco indices`);if(p){if(p.type!==`SCALAR`||![5121,5123,5125].includes(p.componentType)||p.normalized)throw TypeError(`Invalid glTF Draco indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let e=I(p.count,`Draco index count`,1);if(e>Qe||e%3)throw RangeError(`Invalid glTF Draco index count; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);f+=e*4}if(f>e.maxBytes*4)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);let m=e.view(o.bufferView);if(f>e.remainingDecodedBytes)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);let h=p?p.count:Math.min(Qe,Math.floor((e.remainingDecodedBytes-f)/4));if(h<3)throw RangeError(`Decoded glTF exceeds index byte budget; load a smaller model, or reduce its textures and meshes`);let g=await n();r?.throwIfAborted();let _=await g.decode(m,{attributeIds:c,componentTypes:s,signal:r,limits:{maxVertices:d,maxIndices:h,maxDecodedBytes:e.remainingDecodedBytes,attributeWidths:l}});r?.throwIfAborted();let v=I(_.vertexCount,`Draco vertex count`,3),y=_.indices;if(v>16777216||!(y instanceof Uint16Array||y instanceof Uint32Array)||!y.length||y.length>Qe||y.length%3||y.some(e=>e>=v)||p&&y.length!==p.count)throw RangeError(`Invalid glTF Draco triangle indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let n of Object.keys(c)){let r=t.attributes[n],i=L(e.doc.accessors,r,`Draco attribute`),a=Object.hasOwn($e,n)?$e[n]:void 0,o=_.attributes?.[n],s=a?_[a]:o?.array;if(!ArrayBuffer.isView(s)||s instanceof DataView||i.count!==v||s.length!==v*F[i.type]||!a&&(o?.itemSize!==F[i.type]||o.componentType!==i.componentType))throw RangeError(`Mismatched glTF Draco attribute `+n+`; the accessor must match the Draco stream, re-export the model`);let c=Float32Array.from(s);if(i.normalized&&n!==`COLOR_0`){let e=et[i.componentType];if(!e)throw TypeError(`Invalid normalized Draco attribute; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let t=0;t<c.length;t++)c[t]=Math.max(-1,c[t]/e)}e.setDecodedAccessor(r,c)}t.indices===void 0&&e.reserveDecodedBytes(y.length*4);let b=Float32Array.from(y);t.indices!==void 0&&e.setDecodedAccessor(t.indices,b),a.set(t,t.indices===void 0?b:e.accessor(t.indices,`SCALAR`))}var Qe,F,$e,et,tt=t((()=>{s(),xt(),ye(),de(),Qe=3*E,F={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},$e={POSITION:`positions`,NORMAL:`normals`,TEXCOORD_0:`uvs`,COLOR_0:`colors`},et={5120:127,5121:255,5122:32767,5123:65535}}));function nt(e){return{decode:async(t,n)=>{let r=await e.decode(t,n),i=r.vertexCount??r.positions?.length/3,a=r.attributes&&Object.fromEntries(Object.entries(r.attributes).map(([e,t])=>{let r=t;return[e,{...r,itemSize:r.itemSize??r.array.length/i,componentType:r.componentType??n.componentTypes[e]}]}));return{...r,vertexCount:i,attributes:a,indices:r.indices??(Number.isSafeInteger(i)&&i>=3&&i<=16777216?Uint32Array.from({length:i},(e,t)=>t):void 0)}}}}function rt(e,t){if(!(e.length<23)){for(let t=0;t<23;t++)if(e[t]!==mt.charCodeAt(t))return;throw i(`failed`,`${t} is a Git LFS pointer file, not the asset; run git lfs pull and serve the real file; see https://margoengine.com/errors#git-lfs`)}}function it(e=z){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`maxDownloadBytes must be a positive integer`);return e}function I(e,t,n=0){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<n)throw TypeError(`Invalid glTF `+t+`; re-export the file and check it with the glTF Validator`);return e}function L(e,t,n){let r=e?.[I(t,n)];if(!r||typeof r!=`object`||Array.isArray(r))throw TypeError(`Missing glTF `+n+`; re-export the file and check it with the glTF Validator`);return r}function at(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{throw TypeError(`Invalid glTF JSON: not UTF-8; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}}function ot(e){let t=typeof e==`string`?e:at(e);for(let e=0,n=0,r=!1;e<t.length;e++){let i=t.charCodeAt(e);if(r)i===92?e++:i===34&&(r=!1);else if(i===34)r=!0;else if(i===91||i===123){if(++n>256)throw TypeError(`Invalid glTF JSON: nested deeper than 256 levels; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}else(i===93||i===125)&&n--}try{return v(t)}catch(e){throw e instanceof SyntaxError?TypeError(`Invalid glTF JSON: `+e.message):e}}function st(e){if(!e||typeof e!=`object`||!m(e.asset))throw TypeError(`Expected glTF 2.0`);let t=e;for(let e of _t)if(!W(t[e]))throw TypeError(`Invalid glTF `+e+`; re-export the file and check it with the glTF Validator`);for(let t of e.meshes??[])if(!W(t.primitives)||!(t.primitives??[]).every(e=>W(e.targets)))throw TypeError(`Invalid glTF primitives; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let t of e.animations??[])if(!W(t.samplers)||!W(t.channels))throw TypeError(`Invalid glTF animation; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let e of[`extensionsRequired`,`extensionsUsed`])if(t[e]!==void 0&&!Array.isArray(t[e]))throw TypeError(`Invalid glTF `+e+`; re-export the file and check it with the glTF Validator`)}function R(e,t=z){let n=/^data:[^;,]+;base64,([A-Za-z0-9+/]*={0,2})$/.exec(e);if(n&&n[1].length>t*4/3+4)throw B(`glTF exceeds download budget`,t);if(!n)throw TypeError(`Invalid glTF data URI; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let r;try{r=atob(n[1])}catch{throw TypeError(`Invalid glTF data URI; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}return Uint8Array.from(r,e=>e.charCodeAt(0))}function ct(e,t=!1){let n=e.extensions,r=n?.[q]!==void 0||!t||n?.MSFT_texture_dds===void 0?q:`MSFT_texture_dds`,i=n?.[r];if(i!==void 0&&(!i||typeof i!=`object`||Array.isArray(i)))throw TypeError(`Invalid glTF ${r}; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return I(i===void 0?e.source:i.source,`image source`)}function lt(e,t,n){let r=I(t,`accessor`),i=L(e.accessors,r,`accessor`);if(n&&i.type!==n)throw TypeError(`Invalid glTF accessor type; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let a=typeof i.componentType==`number`?d[i.componentType]:void 0,o=typeof i.type==`string`&&Object.hasOwn(G,i.type)?G[i.type]:void 0,s=I(i.count,`accessor count`,1);if(!a||!o||i.normalized!==void 0&&typeof i.normalized!=`boolean`||i.normalized&&[5125,5126].includes(i.componentType))throw TypeError(`Unsupported glTF accessor ${r} (componentType ${i.componentType}, type ${i.type}${i.normalized?`, normalized`:``}); re-export the model without it, or convert the texture format`);return{index:r,def:i,size:a,width:o,count:s}}function ut(e,t,n,r,i,a,o,s,c,l){if(a%t||o%t||a+(s-1)*o+n*t>i.length)throw RangeError(`Invalid glTF accessor bounds/alignment; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let d=new DataView(i.buffer,i.byteOffset,i.byteLength),f=e.componentType,p=e.normalized?yt[f]??1:0;for(let e=0;e<s;e++){let i=(l?l[e]:e)*n;for(let s=0,l=a+e*o;s<n;s++,l+=t){let e=u(d,l,f);if(p&&(e=Math.max(-1,e/p)),c&&!Number.isFinite(Math.fround(e)))throw RangeError(`Non-finite glTF accessor; the file holds invalid numbers, re-export it and check it with the glTF Validator`);r[i+s]=e}}}function dt(e,t=!1){let n=new Set,r=new Set;for(let i of e.textures??[])i?.extensions?.[q]!==void 0||t&&i?.extensions?.MSFT_texture_dds!==void 0?(r.add(ct(i,t)),Number.isSafeInteger(i.source)&&i.source>=0&&n.add(i.source)):(Number.isSafeInteger(i?.source)&&i.source>=0&&r.add(i.source),!t&&i?.extensions?.MSFT_texture_dds&&n.add(I(i.extensions.MSFT_texture_dds.source,`DDS image`)));for(let e of r)n.delete(e);return n}function ft(e,t){let n=e.hooks.decoderModule;if(!n)throw i(`unsupported`,t===`Draco`?`This file needs the Draco decoder; load it with loadGLTF from @margoengine/gltf/pbr, or pass decoders.decoderModule`:`This file needs the KTX2 decoder; load it with loadGLTF from @margoengine/gltf/pbr, or pass decoders.decoderModule`);return n}async function pt(e,t,n,r){r?.throwIfAborted();try{if(typeof createImageBitmap!=`function`)return await be(e,r);let n=e.buffer instanceof ArrayBuffer?e:new Uint8Array(e);return await createImageBitmap(new Blob([n],{type:t}),{colorSpaceConversion:`none`,premultiplyAlpha:`none`})}catch(e){throw r?.throwIfAborted(),TypeError(`glTF image ${n} could not be decoded (${e instanceof Error?e.message:e}); check the file`)}}var z,B,mt,ht,V,H,gt,U,_t,W,G,vt,K,q,yt,bt,xt=t((()=>{s(),h(),y(),se(),de(),l(),f(),ye(),xe(),z=536870912,B=(e,t)=>RangeError(`${e} (${t} bytes; raise the maxDownloadBytes option)`),mt=`version https://git-lfs`,ht=new Set(`KHR_mesh_quantization.KHR_texture_transform.KHR_materials_emissive_strength.KHR_materials_unlit.KHR_lights_punctual.KHR_node_visibility.KHR_materials_clearcoat.KHR_materials_transmission.KHR_materials_ior.KHR_materials_dispersion.KHR_materials_volume.KHR_materials_sheen.KHR_materials_specular.KHR_materials_variants.KHR_node_visibility.EXT_texture_webp.EXT_texture_avif.EXT_mesh_gpu_instancing.VRMC_materials_mtoon.VRMC_node_constraint.EXT_lights_ies.EXT_lights_image_based.KHR_physics_rigid_bodies.KHR_audio_emitter.MSFT_audio_emitter.KHR_interactivity.KHR_node_selectability.KHR_node_hoverability.KHR_implicit_shapes.KHR_xmp_json_ld.KHR_animation_pointer`.split(`.`)),V={KHR_draco_mesh_compression:`draco`,EXT_meshopt_compression:`meshopt`,KHR_meshopt_compression:`meshopt`,KHR_texture_basisu:`ktx2`,MSFT_texture_dds:`dds`,KHR_materials_iridescence:`materials`,KHR_materials_anisotropy:`materials`,KHR_materials_diffuse_transmission:`materials`,KHR_materials_diffuse_roughness:`materials`,EXT_materials_bump:`materials`,KHR_materials_volume_scatter:`materials`,KHR_gaussian_splatting:`splats`,KHR_gaussian_splatting_compression_spz_2:`splats`},gt=[`EXT_meshopt_compression`,`KHR_meshopt_compression`],U=e=>{let t=e?.extensions;if(t?.EXT_meshopt_compression!==void 0&&t?.KHR_meshopt_compression!==void 0)throw TypeError(`Invalid glTF meshopt extensions; use only EXT or KHR on each buffer or bufferView`);return t?.EXT_meshopt_compression??t?.KHR_meshopt_compression},_t=[`buffers`,`bufferViews`,`accessors`,`meshes`,`nodes`,`scenes`,`materials`,`textures`,`images`],_t.push(`samplers`,`skins`,`animations`,`cameras`),W=e=>e===void 0||Array.isArray(e)&&e.every(e=>!!e&&typeof e==`object`&&!Array.isArray(e)),G={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},vt=`EXT_meshopt_compression`,K=`KHR_draco_mesh_compression`,q=`KHR_texture_basisu`,yt={5120:127,5121:255,5122:32767,5123:65535},bt=class{get remainingDecodedBytes(){return this.maxBytes*4-this.decoded}reserveDecodedBytes(e){if(I(e,`decoded byte length`),this.decoded+e>this.maxBytes*4)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);this.decoded+=e}constructor(e,t,n,r={},a=z,o=1e5){this.doc=e,this.hooks=r,this.maxBytes=a,this.maxNodes=o,this.cache=new Map,this.viewCache=new Map,this.decoded=0,this.partVertices=ue,it(a),ae(`maxNodes`,o),st(e);let s=(e.extensionsRequired??[]).filter(e=>!ht.has(e)&&![K,vt,`KHR_meshopt_compression`,q].includes(e)&&!r[V[e]]&&!(r.materials&&r.materials.extensions?.includes(e)));if(s.length)throw i(`unsupported`,`Required glTF extensions are unsupported: `+s.map(e=>V[e]?e+` (pass a `+V[e]+` decoder)`:e).join(`, `)+`; pass the listed decoders or re-export the model without them`);oe(`Too many glTF nodes`,e.nodes?.length??0,o,`maxNodes`);let l=0;this.buffers=(e.buffers??[]).map((r,i)=>{if(!r||typeof r!=`object`||Array.isArray(r))throw TypeError(`Invalid glTF buffer; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let o=I(r.byteLength,`buffer length`,1),s=U(r)?.fallback;if(s!==void 0&&typeof s!=`boolean`)throw TypeError(`Invalid glTF meshopt fallback; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let u=t[i],d=(!u||u.byteLength===0)&&!r.uri&&(i!==0||!n);if(s===!0||d&>.some(t=>e.extensionsRequired?.includes(t))){let t=gt.find(e=>r.extensions?.[e]!==void 0),n=(e.bufferViews??[]).filter(e=>e?.buffer===i);if(!n.length||n.some(e=>!U(e)||t!==void 0&&!e.extensions?.[t])||e.bufferViews?.some(e=>U(e)?.buffer===i))throw TypeError(`Invalid glTF meshopt fallback references; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return new Uint8Array}let f=u?u instanceof ArrayBuffer?new Uint8Array(u):new Uint8Array(u.buffer,u.byteOffset,u.byteLength):r.uri?R(r.uri,a):i===0?n:void 0;if(!f||o>f.length)throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`);if(i===0&&n&&(u===n||f===n)&&c(n.length,o),l+=f.byteLength,l>a)throw B(`glTF buffers exceed byte budget`,a);return f.subarray(0,o)})}view(e){let t=I(e,`bufferView`),n=L(this.doc.bufferViews,t,`bufferView`),r=I(n.buffer,`buffer reference`),a=this.buffers[r],o=I(n.byteOffset??0,`view offset`),s=I(n.byteLength,`view length`,1),c=I(L(this.doc.buffers,r,`buffer`).byteLength,`buffer length`,1);if(s>c||o>c-s)throw RangeError(`Invalid glTF bufferView bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let l=U(n);if(l!==void 0){let e=this.viewCache.get(t);if(e)return e;if(!l||typeof l!=`object`||Array.isArray(l))throw TypeError(`Invalid glTF meshopt extension; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let r=this.buffers[I(l.buffer,`meshopt buffer reference`)],a=I(l.byteOffset??0,`meshopt offset`),o=I(l.byteLength,`meshopt length`,1),c=I(l.count,`meshopt count`,1),u=I(l.byteStride,`meshopt stride`,1),d=l.mode,f=l.filter??`NONE`;if(!r||o>r.length||a>r.length-o)throw RangeError(`Invalid glTF meshopt source bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(!Number.isSafeInteger(c*u)||c*u!==s||n.byteStride!==void 0&&n.byteStride!==u)throw RangeError(`Invalid glTF meshopt decoded layout; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(d===`ATTRIBUTES`?u>256||u%4!=0:![`TRIANGLES`,`INDICES`].includes(d)||![2,4].includes(u)||d===`TRIANGLES`&&c%3!=0)throw TypeError(`Invalid glTF meshopt mode/stride/count; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(![`NONE`,`OCTAHEDRAL`,`QUATERNION`,`EXPONENTIAL`,`COLOR`].includes(f)||f!==`NONE`&&d!==`ATTRIBUTES`||[`OCTAHEDRAL`,`COLOR`].includes(f)&&![4,8].includes(u)||f===`QUATERNION`&&u!==8||f===`EXPONENTIAL`&&u%4!=0)throw TypeError(`Invalid glTF meshopt filter; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(this.decoded+s>this.maxBytes*4)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);let p=r.subarray(a,a+o),m;if(this.hooks.meshopt)m=new Uint8Array(s),this.hooks.meshopt.decodeGltfBuffer(m,c,u,p,d,f);else{if(!H)throw i(`state`,`Meshopt geometry requires parseGLTFAsync or loadGLTF, or a meshopt decoder passed in decoders (or asset.decode() first)`);m=H(p,c,u,d,f)}return this.reserveDecodedBytes(m.byteLength),this.viewCache.set(t,m),m}if(!a||o+s>a.length)throw RangeError(`Invalid glTF bufferView bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return a.subarray(o,o+s)}setDecodedAccessor(e,t){let{index:n,width:r,count:i}=lt(this.doc,e);if(!(t instanceof Float32Array)||t.length!==i*r)throw RangeError(`Mismatched decoded glTF accessor; the file holds invalid numbers, re-export it and check it with the glTF Validator`);if(t.some(e=>!Number.isFinite(e)))throw RangeError(`Non-finite decoded glTF accessor; the file holds invalid numbers, re-export it and check it with the glTF Validator`);let a=this.cache.get(n);if(a){if(a!==t&&a.some((e,n)=>e!==t[n]))throw TypeError(`Conflicting decoded glTF accessor; the file holds invalid numbers, re-export it and check it with the glTF Validator`)}else this.reserveDecodedBytes(t.byteLength),this.cache.set(n,t)}async prepareMeshopt(){H||this.hooks.meshopt||this.doc.bufferViews?.some(e=>e?.extensions?.EXT_meshopt_compression||e?.extensions?.KHR_meshopt_compression)&&(H=(await Promise.resolve().then(()=>(Je(),we))).meshoptDecodeGltfBuffer)}async decode(e){if(await this.prepareMeshopt(),!_e(this))return e?.throwIfAborted();let{decompressPrimitives:t}=await Promise.resolve().then(()=>(tt(),Ye));await t(this,{signal:e,draco:this.hooks.draco&&nt(this.hooks.draco)})}accessor(e,t,n=!0){let{index:r,def:a,size:o,width:s,count:c}=lt(this.doc,e,t),l=this.cache.get(r);if(l)return l;this.reserveDecodedBytes(c*s*4);let u=new Float32Array(c*s);if(a.bufferView!==void 0){let e=L(this.doc.bufferViews,a.bufferView,`bufferView`),t=I(e.byteStride??o*s,`stride`,o*s);if(t>252||I(e.byteOffset??0,`view offset`)%o)throw RangeError(`Invalid glTF stride/alignment; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);ut(a,o,s,u,this.view(a.bufferView),I(a.byteOffset??0,`accessor offset`),t,c,n)}else{if(this.dracoOwned(r))throw i(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);if(a.byteOffset)throw TypeError(`Accessor has no data or invalid offset; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}if(a.sparse){let e=this.sparseIds(a,c),t=a.sparse.values;ut(a,o,s,u,this.view(t.bufferView),I(t.byteOffset??0,`sparse values offset`),o*s,e.length,n,e)}return n&&this.cache.set(r,u),u}sparseAccessor(e,t){let{index:n,def:r,size:i,width:a,count:o}=lt(this.doc,e,t);if(!r.sparse&&r.bufferView===void 0&&!r.byteOffset&&!this.cache.has(n)&&!this.dracoOwned(n))return{count:o,width:a,rows:new Uint32Array,values:new Float32Array};if(r.bufferView===void 0&&r.sparse&&!r.byteOffset&&!this.cache.has(n)){let e=Uint32Array.from(this.sparseIds(r,o)),t=new Float32Array(e.length*a),n=r.sparse.values;return ut(r,i,a,t,this.view(n.bufferView),I(n.byteOffset??0,`sparse values offset`),i*a,e.length,!0),{count:o,width:a,rows:e,values:t}}let s=this.accessor(e,t),c=[];for(let e=0;e<o;e++)for(let t=0;t<a;t++)if(s[e*a+t]!==0){c.push(e);break}let l=Uint32Array.from(c),u=new Float32Array(l.length*a);return l.forEach((e,t)=>u.set(s.subarray(e*a,e*a+a),t*a)),{count:o,width:a,rows:l,values:u}}dracoOwned(e){return!!this.doc.meshes?.some(t=>t?.primitives?.some(t=>t?.extensions?.[K]&&(t.indices===e||Object.keys(t.extensions[K].attributes??{}).some(n=>t.attributes?.[n]===e))))}sparseIds(e,t){let n=e.sparse,r=I(n.count,`sparse count`,1),i=n.indices,a=n.values,o=d[i?.componentType];if(r>t||![5121,5123,5125].includes(i?.componentType))throw TypeError(`Invalid glTF sparse indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let s=this.view(i.bufferView),c=I(i.byteOffset??0,`sparse offset`);if(c%o||c+r*o>s.length||L(this.doc.bufferViews,i.bufferView,`sparse indices`).byteStride!==void 0||L(this.doc.bufferViews,a?.bufferView,`sparse values`).byteStride!==void 0)throw RangeError(`Invalid sparse bounds/stride; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let l=new DataView(s.buffer,s.byteOffset,s.byteLength),u=[],f=-1;for(let e=0;e<r;e++){let n=c+e*o,r=o===1?l.getUint8(n):o===2?l.getUint16(n,!0):l.getUint32(n,!0);if(r<=f||r>=t)throw RangeError(`Invalid sparse index order/bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);u.push(r),f=r}return u}}}));ye(),xt(),s(),de();function St(e){if(!e||typeof e!=`object`)return!1;for(let[t,n]of Object.entries(e))if(t===`texCoord`?n>1:St(n))return!0;return!1}function Ct(e,t){let n=t.extensions?.KHR_materials_variants,r=[t.material,...(n?.mappings??[]).map(e=>e?.material)],i=new Set;for(let t=0;t<r.length;t++){let n=r[t];if(n===void 0||i.has(n))continue;i.add(n);let a=e.materials?.[n];if(St(a))return!0;let o=(a?.extensions)?.MSFT_lod?.ids;if(Array.isArray(o))for(let t of o)Number.isInteger(t)&&t>=0&&t<(e.materials?.length??0)&&r.push(t)}return!1}function wt(e,t,n){ve(e,t);try{return Et(e,t,n)}catch(n){let r=e.doc.meshes??[],i=r.findIndex(e=>e?.primitives?.includes?.(t));throw n instanceof Error&&i>=0&&(n.message=`glTF mesh ${i}${r[i].name?` "${r[i].name}"`:``} primitive ${r[i].primitives.indexOf(t)}: ${n.message}`),n}}function Tt(e,t){let n=e.length;if(t===2||t===3){let r=n<2?0:t===2?n:n-1,i=new Uint32Array(r*2);for(let t=0;t<r;t++)i[t*2]=e[t],i[t*2+1]=e[(t+1)%n];return i}if(t===5||t===6){let r=new Uint32Array(Math.max(n-2,0)*3);for(let i=0,a=0;i<n-2;i++,a+=3)t===5?(r[a]=e[i],r[a+1]=e[i+1+i%2],r[a+2]=e[i+2-i%2]):(r[a]=e[i+1],r[a+1]=e[i+2],r[a+2]=e[0]);return r}return e}function Et(e,t,n){let r=t.mode??4,a=r===0?1:r<4?2:3;if(!Number.isInteger(r)||r<0||r>6)throw TypeError(`Invalid glTF primitive mode; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let o=t.attributes??{},s=(t,n,r)=>{try{return e.accessor(n,r)}catch(e){throw e instanceof Error&&(e.message=`${t} (accessor ${n}): ${e.message}`),e}};if(L(e.doc.accessors,o.POSITION,`POSITION`).count>16777216)throw i(`unsupported`,`glTF primitive has more than ${E} vertices, the most one primitive may hold; split the mesh into several primitives`);let c=s(`POSITION`,o.POSITION,`VEC3`),l=c.length/3,u=e.doc.extensionsUsed?.includes(`KHR_mesh_quantization`),d=e.partVertices;if(l<a)throw RangeError(`Expected bounded triangle geometry`);for(let t of[`POSITION`,`NORMAL`,`TANGENT`])if(o[t]!==void 0&&!u){let n=L(e.doc.accessors,o[t],`attribute`);if(n.componentType!==5126||n.normalized)throw TypeError(`Expected Float32 `+t)}for(let t of[`TEXCOORD_0`,`TEXCOORD_1`,`TEXCOORD_2`,`TEXCOORD_3`,`COLOR_0`])if(o[t]!==void 0&&!(u&&t!==`COLOR_0`)){let n=L(e.doc.accessors,o[t],`attribute`);if(![5126,5121,5123].includes(n.componentType)||n.componentType!==5126&&!n.normalized)throw TypeError(`Invalid normalized `+t+`; re-export the file and check it with the glTF Validator`)}let f=o.NORMAL===void 0?new Float32Array(c.length):s(`NORMAL`,o.NORMAL,`VEC3`),p=ve(e,t)??(t.indices===void 0?null:s(`indices`,t.indices,`SCALAR`));if(p)for(let e=0;e<p.length;e++){let t=p[e];if(!Number.isInteger(t)||t<0||t>=l)throw RangeError(`Invalid glTF triangle indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}let m=p?new Uint32Array(p):new Uint32Array(l);if(!p)for(let e=0;e<l;e++)m[e]=e;if(m=Tt(m,r),!m.length||m.length%a)throw RangeError(`Invalid glTF triangle indices; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(t.indices!==void 0&&(![5121,5123,5125].includes(L(e.doc.accessors,t.indices,`indices`).componentType)||e.doc.accessors[t.indices].normalized))throw TypeError(`Invalid index component type; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(o.NORMAL===void 0&&a===3)for(let e=0;e<m.length;e+=3){let t=m[e]*3,n=m[e+1]*3,r=m[e+2]*3,i=c[n]-c[t],a=c[n+1]-c[t+1],o=c[n+2]-c[t+2],s=c[r]-c[t],l=c[r+1]-c[t+1],u=c[r+2]-c[t+2],d=a*u-o*l,p=o*s-i*u,h=i*l-a*s;f[t]+=d,f[t+1]+=p,f[t+2]+=h,f[n]+=d,f[n+1]+=p,f[n+2]+=h,f[r]+=d,f[r+1]+=p,f[r+2]+=h}let h=e.doc.materials?.[t.material]?.alphaMode===`BLEND`,g=l>d?le(m,a,l,d,h?null:c):null;if(e.reorder&&a===3&&!h){if(!g)m=e.reorder(m,c,l);else for(let t of g){let n=t.vertexMap.length,r=new Float32Array(n*3);for(let e=0;e<n;e++){let n=t.vertexMap[e]*3;r[e*3]=c[n],r[e*3+1]=c[n+1],r[e*3+2]=c[n+2]}t.indices=e.reorder(t.indices,r,n)}}let _=o.TEXCOORD_0===void 0?null:s(`TEXCOORD_0`,o.TEXCOORD_0,`VEC2`),v=o.TEXCOORD_1===void 0?null:s(`TEXCOORD_1`,o.TEXCOORD_1,`VEC2`),y=Ct(e.doc,t),b=!y||o.TEXCOORD_2===void 0?null:s(`TEXCOORD_2`,o.TEXCOORD_2,`VEC2`),x=!y||o.TEXCOORD_3===void 0?null:s(`TEXCOORD_3`,o.TEXCOORD_3,`VEC2`),S=o.TANGENT===void 0?null:s(`TANGENT`,o.TANGENT,`VEC4`),C=o.COLOR_0===void 0?null:s(`COLOR_0`,o.COLOR_0),w=C?C.length/l:0;if(f.length!==l*3||_&&_.length!==l*2||v&&v.length!==l*2||b&&b.length!==l*2||x&&x.length!==l*2||S&&S.length!==l*4||C&&![3,4].includes(w))throw RangeError(`Mismatched glTF attributes; the file holds invalid numbers, re-export it and check it with the glTF Validator`);let ee=(e,t,n)=>{let r=t*3,i=f[r],a=f[r+1],s=f[r+2],l=Math.hypot(i,a,s);if(e[n]=c[r],e[n+1]=c[r+1],e[n+2]=c[r+2],e[n+3]=1,!l||!Number.isFinite(l)){if(o.NORMAL!==void 0)throw RangeError(`Zero or non-finite glTF normal; the file holds invalid numbers, re-export it and check it with the glTF Validator`);e[n+6]=1}else e[n+4]=i/l,e[n+5]=a/l,e[n+6]=s/l;if(S){let r=t*4,i=Math.hypot(S[r],S[r+1],S[r+2]);i&&(e[n+8]=S[r]/i,e[n+9]=S[r+1]/i,e[n+10]=S[r+2]/i,e[n+11]=Math.sign(S[r+3]))}if(_&&(e[n+12]=_[t*2],e[n+13]=_[t*2+1]),v&&(e[n+14]=v[t*2],e[n+15]=v[t*2+1]),C){let r=t*w;e[n+16]=C[r],e[n+17]=C[r+1],e[n+18]=C[r+2],e[n+19]=w===3?1:C[r+3]}else e[n+16]=1,e[n+17]=1,e[n+18]=1,e[n+19]=1},T=(e,t,n)=>{b&&e.set(b.subarray(t*2,t*2+2),n),x&&e.set(x.subarray(t*2,t*2+2),n+2)},te=a<3?{topology:a===1?`point-list`:`line-list`}:{};if(!g){let e=new Float32Array(l*20),t=b||x?new Float32Array(l*4):void 0;for(let t=0;t<l;t++)ee(e,t,t*20);if(t)for(let e=0;e<l;e++)T(t,e,e*4);let r={vertices:e,indices:m,...te,...t?{uvs:t}:{}};return n?(n(r),[]):[r]}let ne=[];for(let e=0;e<g.length;e++){let{indices:t,vertexMap:r}=g[e],i=r.length,a=new Float32Array(i*20),o=b||x?new Float32Array(i*4):void 0;for(let e=0;e<i;e++)ee(a,r[e],e*20);if(o)for(let e=0;e<i;e++)T(o,r[e],e*4);let s={vertices:a,indices:t,...te,...o?{uvs:o}:{},part:{index:e,count:g.length,vertexMap:r}};n?n(s):ne.push(s)}return ne}function Dt(e){let t=e.doc,n=[];for(let e of t.skins??[])n.push(e?.inverseBindMatrices);for(let e of t.meshes??[])for(let t of e?.primitives??[]){n.push(t?.attributes?.JOINTS_0,t?.attributes?.WEIGHTS_0);for(let e of t?.targets??[])n.push(e?.POSITION,e?.NORMAL)}for(let e of t.animations??[])for(let t of e?.samplers??[])n.push(t?.input,t?.output);for(let e of t.nodes??[])n.push(...Object.values(e?.extensions?.EXT_mesh_gpu_instancing?.attributes??{}));let r=[];for(let t of n)if(t!==void 0)try{r.push([t,e.accessor(t)])}catch{}return r}var J=e=>(e.meshes??[]).flatMap(e=>Array.isArray(e?.primitives)?e.primitives:[]);s(),l(),f(),xt(),me(),ye(),de(),ee(),ie(),p();function Y(e,t){let n=L(e.bufferViews,t,`bufferView`),r=n.extensions?.EXT_meshopt_compression??n.extensions?.KHR_meshopt_compression,i=r??n;return{buffer:i.buffer,offset:i.byteOffset??0,length:i.byteLength,packed:!!r}}var Ot=1<<20,X=262144,kt=4;function Z(e,t,n){let r=[],i=!1;for(let a=0;a<e.length;a+=2){let o=e[a],s=e[a+1];s<t?r.push(o,s):o>n?(i||=(r.push(t,n),!0),r.push(o,s)):(t=Math.min(t,o),n=Math.max(n,s))}i||r.push(t,n),e.length=0;for(let t of r)e.push(t)}function Q(e,t,n){let r=[];for(let i=0;i<e.length&&t<n;i+=2)if(!(e[i+1]<=t)){if(e[i]>=n)break;e[i]>t&&r.push([t,e[i]]),t=Math.max(t,e[i+1])}return t<n&&r.push([t,n]),r}var $=(e,t,n)=>!Q(e,t,n).length,At=e=>{let{name:t=`Error`,code:n}=e??{};return{name:t,message:e instanceof Error?e.message:String(e),...typeof n==`string`?{code:n}:{}}},jt=class{constructor(e,t,n,r=z,i,a,o=!1,s=ue,c={}){this.url=e,this.post=t,this.signal=n,this.limit=r,this.maxNodes=i,this.allowedURLs=a,this.textures=o,this.partVertices=s,this.decoders=c,this.sources=[],this.map=[],this.needs=[],this.posted=new Set,this.waiters=[],this.inflight=0,this.pending=0,this.loaded=0,this.reported=0,this.decoding=Promise.resolve(),this.base=e,n.addEventListener(`abort`,()=>this.notify(),{once:!0})}setOrder(e){this.order=e,this.notify()}notify(){for(let e of this.waiters.splice(0))e()}async next(){if(await new Promise(e=>this.waiters.push(e)),this.signal.throwIfAborted(),this.failure)throw this.failure}async run(){try{let e=await this.head();if(st(e),pe(e)||e.meshes?.some(e=>e?.primitives?.some(e=>(e?.mode??4)<4))||e.textures?.some(e=>e?.extensions?.MSFT_texture_dds)||!this.textures&&(e.textures?.some(e=>e?.extensions?.KHR_texture_basisu)||e.images?.some(e=>e?.mimeType===`image/ktx2`))||!this.decoders.draco&&e.meshes?.some(e=>e?.primitives?.some(e=>e?.extensions?.KHR_draco_mesh_compression))){this.post({type:`fallback`});return}for(this.post({type:`doc`,doc:e}),this.buffers(e),await this.asset.prepareMeshopt();!this.order;)await this.next();await this.geometry(e),await this.images(e);for(let[e,t]of this.sources.entries())if(t.ranged!==!1){let n=Q(t.asked,0,t.data.length);for(let t=0;t<n.length;){let r=n[t][0],i=n[t++][1];for(;t<n.length&&n[t][0]-i<=X;)i=n[t++][1];this.request(e,r,i)}}for(;this.inflight||this.sources.some(e=>!$(e.got,0,e.data?.length??0));)await this.next();this.bytes(!0);let t=new Map(Dt(this.asset)),n=[];J(e).forEach((e,r)=>{let i=D.get(this.asset)?.get(e);if(!i)return;n.push([r,i]);let a=e.extensions.KHR_draco_mesh_compression;for(let n of[...Object.keys(a.attributes).map(t=>e.attributes[t]),e.indices])n!==void 0&&t.set(n,this.asset.accessor(n))}),this.post({type:`done`,buffers:this.asset.buffers,accessors:[...t],...n.length?{draco:n}:{}})}catch(e){this.signal.aborted||this.post({type:`error`,error:At(e)})}}bytes(e=!1){let t=Date.now();!e&&t-this.reported<100||(this.reported=t,this.post({type:`bytes`,loaded:this.loaded,total:this.sources.reduce((e,t)=>e+(t.size??0),0)}))}fetch(e,t,n=!1){if(![`http:`,`https:`].includes(e.url.protocol))throw TypeError(`glTF URL must use HTTP(S); for a blob: or file: source, read its bytes (await file.arrayBuffer()) and pass them to parseGLTFAsync`);return fetch(e.url,{signal:this.signal,headers:t}).then(e=>{if(n||C(e,this.base,this.allowedURLs,`glTF`),!e.ok)throw i(`failed`,`glTF download request failed: HTTP ${e.status}; check the URL and that the server allows the request`);return e})}allocate(e,t){if(!Number.isSafeInteger(t)||t>this.limit-this.sources.reduce((e,t)=>e+(t.data?.length??0),0))throw B(`glTF exceeds download budget`,this.limit);e.data=new Uint8Array(t),e.size??=t}async read(e,t,n,r={left:0}){let i=t.body.getReader(),a=()=>i.cancel().catch(()=>{});this.signal.addEventListener(`abort`,a,{once:!0});try{for(;;){let{done:t,value:o}=await i.read();if(this.signal.throwIfAborted(),t)break;let s=e.data.length-n,c=o.length>s?o.subarray(0,s):o;e.data.set(c,n),Z(e.got,n,n+c.length),this.loaded+=c.length,n+=c.length;let l=Math.min(c.length,r.left);if(r.left-=l,this.pending-=l,this.bytes(),this.notify(),n>=e.data.length){a();break}}}finally{this.signal.removeEventListener(`abort`,a)}}async head(){let e={url:this.url,got:[],asked:[]};this.sources.push(e);let t=await this.fetch(e,{Range:`bytes=0-65535`},!0),n=/^bytes 0-\d+\/(\d+|\*)$/.exec(t.headers.get(`content-range`)??``),r=n&&n[1]!==`*`?Number(n[1]):void 0;t.url&&(e.url=this.base=new URL(t.url)),e.ranged=t.status===206&&!!n;let i=t.body.getReader(),a=[],o=0;for(;o<12;){let{done:e,value:t}=await i.read();if(e)break;a.push(t),o+=t.length}let s=new Uint8Array(o);a.reduce((e,t)=>(s.set(t,e),e+t.length),0);let c=new DataView(s.buffer);if(o<12||c.getUint32(0,!0)!==1179937895){for(let e;!(e=await i.read()).done;)if(a.push(e.value),(o+=e.value.length)>this.limit)throw i.cancel().catch(()=>{}),B(`glTF JSON exceeds byte budget`,this.limit);let t=r===void 0?o-1:o;e.ranged&&(r===void 0?o>=65536:r>o)&&a.push((await re(await this.fetch(e,{Range:`bytes=${t}-`}),{maxBytes:this.limit-t,signal:this.signal,label:`glTF JSON`}).catch(e=>{throw e instanceof RangeError?B(`glTF JSON exceeds byte budget`,this.limit):e})).subarray(o-t));let n=new Uint8Array(a.reduce((e,t)=>e+t.length,0));if(a.reduce((e,t)=>(n.set(t,e),e+t.length),0),this.loaded+=n.length,n.length>this.limit)throw B(`glTF JSON exceeds byte budget`,this.limit);return this.sources.length=0,rt(n,e.url.href),ot(n)}let l=c.getUint32(8,!0);if(c.getUint32(4,!0)!==2||l<20||r!==void 0&&r!==l)throw TypeError(`Invalid GLB header; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);this.allocate(e,l),e.data.set(s.subarray(0,l)),Z(e.got,0,Math.min(o,l)),this.loaded+=o;let u=o,d=(async()=>{try{for(;;){let{done:t,value:n}=await i.read();if(this.signal.throwIfAborted(),t)break;let r=n.subarray(0,Math.max(0,l-u));e.data.set(r,u),Z(e.got,u,u+r.length),this.loaded+=r.length,u+=r.length,this.bytes(),this.notify()}if(!e.ranged&&u<l)throw RangeError(`Truncated GLB; download the file again, it is incomplete`)}catch(e){this.failure??=e,this.notify()}})();if(Z(e.asked,0,e.ranged?Math.min(65536,l):l),e.ranged&&(await d,!this.failure&&!$(e.got,0,Math.min(65536,l))))throw RangeError(`Truncated glTF range response; download the file again, it is incomplete`);let f=()=>new DataView(e.data.buffer).getUint32(12,!0),p=()=>Math.min(l,28+f());for(;!$(e.got,0,20);)await this.next();if(f()%4||20+f()>l||new DataView(e.data.buffer).getUint32(16,!0)!==1313821514)throw TypeError(`Invalid GLB chunk; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(e.ranged)for(let[t,n]of Q(e.got,0,p()))this.request(0,t,n);for(;!$(e.got,0,p());)await this.next();return ot(e.data.subarray(20,20+f()))}buffers(e){let t=this.sources[0],n=new Map,r=0,i=0,a=0;if(t){let e=t.data,n=new DataView(e.buffer),o=20+n.getUint32(12,!0);o+8<=e.length&&$(t.got,o,o+8)&&n.getUint32(o+4,!0)===5130562&&(r=o+8,a=n.getUint32(o,!0),i=Math.min(a,e.length-r))}let o=(e.buffers??[]).map((e,o)=>{let s=e?.extensions;if((s?.EXT_meshopt_compression??s?.KHR_meshopt_compression)?.fallback===!0)return this.map.push({source:-1,offset:0}),new Uint8Array;if(e?.uri===void 0)return o===0&&t&&i?(c(a,e.byteLength),this.map.push({source:0,offset:r}),t.data.subarray(r,r+i)):(this.map.push({source:-1,offset:0}),new Uint8Array);if(typeof e.uri==`string`&&e.uri.startsWith(`data:`)){this.map.push({source:-1,offset:0});let t=R(e.uri,this.limit);return this.loaded+=t.length,t}let l=S(e.uri,this.base,this.allowedURLs,`glTF`).href,u=n.get(l);if(u===void 0){u=this.sources.length,n.set(l,u);let t={url:new URL(l),got:[],asked:[]};this.sources.push(t),this.allocate(t,Number.isSafeInteger(e.byteLength)&&e.byteLength>0?e.byteLength:0)}return this.map.push({source:u,offset:0}),this.sources[u].data}),{meshopt:s}=this.decoders;this.asset=new bt(e,o,void 0,s?{meshopt:s}:{},this.limit,this.maxNodes),this.asset.partVertices=this.partVertices,this.needs=J(e).map(t=>{let n=[],r=t?.attributes??{},i=t?.extensions?.KHR_draco_mesh_compression;try{let a=[`POSITION`,`NORMAL`,`TANGENT`,`TEXCOORD_0`,`TEXCOORD_1`,...Ct(e,t)?[`TEXCOORD_2`,`TEXCOORD_3`]:[],`COLOR_0`];i&&this.whole(e,i.bufferView,n);for(let o of[...a.filter(e=>!(i?.attributes&&e in i.attributes)).map(e=>r[e]),i?void 0:t.indices])o!==void 0&&this.ranges(e,o,n)}catch{for(let[e,t]of this.map.entries())t.source>=0&&n.push([t.source,t.offset,t.offset+this.asset.buffers[e].length])}return n})}ranges(e,t,n){let r=L(e.accessors,t,`accessor`),i=d[r.componentType],a=G[r.type],o=r.count,s=(t,r,i)=>{if(Y(e,t).packed)return this.whole(e,t,n);let a=L(e.bufferViews,t,`bufferView`),o=this.map[a.buffer],s=(a.byteOffset??0)+r,c=(a.byteOffset??0)+a.byteLength;if(!o||!Number.isSafeInteger(s)||s<0||!Number.isSafeInteger(c)||!(i>0))throw TypeError(`range; pass a { start, end } byte range`);let l=Math.min(s+i,c,this.asset.buffers[a.buffer].length);o.source>=0&&s<l&&n.push([o.source,o.offset+s,o.offset+l])};if(r.bufferView!==void 0&&s(r.bufferView,r.byteOffset??0,(o-1)*(L(e.bufferViews,r.bufferView,`bufferView`).byteStride??i*a)+i*a),r.sparse){let e=r.sparse.count;s(r.sparse.indices.bufferView,r.sparse.indices.byteOffset??0,e*d[r.sparse.indices.componentType]),s(r.sparse.values.bufferView,r.sparse.values.byteOffset??0,e*i*a)}}whole(e,t,n){let{buffer:r,offset:i,length:a}=Y(e,t),o=this.map[r],s=i+a;if(!o||!Number.isSafeInteger(i)||i<0||!Number.isSafeInteger(s)||!(a>0))throw TypeError(`range; pass a { start, end } byte range`);let c=Math.min(s,this.asset.buffers[r].length);o.source>=0&&i<c&&n.push([o.source,o.offset+i,o.offset+c])}request(e,t,n){let r=this.sources[e],i={left:n-t};Z(r.asked,t,n),this.inflight++,this.pending+=n-t,r.ranged===void 0&&(r.probing=!0),(async()=>{let e=await this.fetch(r,{Range:`bytes=${t}-${n-1}`}),a=/^bytes (\d+)-\d+\/(\d+|\*)$/.exec(e.headers.get(`content-range`)??``);if(e.status===206&&a&&+a[1]===t){if(r.ranged===void 0&&a[2]!==`*`&&+a[2]<r.data.length)throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`);if(r.ranged=!0,await this.read(r,e,t,i),!$(r.got,t,Math.min(n,r.data.length)))throw RangeError(`Truncated glTF range response; download the file again, it is incomplete`)}else if(r.ranged=!1,Z(r.asked,0,r.data.length),await this.read(r,e,0,i),!$(r.got,0,r.data.length))throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`)})().catch(e=>{this.failure??=e}).finally(()=>{this.inflight--,this.pending-=i.left,r.probing=!1,this.notify()})}ready(e){return this.needs[e].every(([e,t,n])=>$(this.sources[e].got,t,n))}async geometry(e){let t=J(e);for(;;){if(this.failure)throw this.failure;let e=this.order.filter(e=>!this.posted.has(e));for(let n of e)this.ready(n)&&(this.posted.add(n),t[n]?.extensions?.KHR_draco_mesh_compression?this.decoding=this.decoding.then(()=>this.decompress(n,t[n])):this.pack(n,t[n]));if(this.order.every(e=>this.posted.has(e)))return this.decoding;let n=Ot,r=[];for(let t of e){if(this.inflight>=kt||n<=0||this.pending>=Ot)break;for(let[e,i,a]of this.needs[t]){let t=this.sources[e];if(!(t.ranged===!1||t.probing)){for(let[o,s]of Q(t.asked,i-i%X,Math.min(t.data.length,Math.ceil(a/X)*X)))if(r.push([e,o,s]),Z(t.asked,o,s),n-=s-o,t.ranged===void 0){t.probing=!0;break}}}}r.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);for(let e=0;e<r.length;){let[t,n,i]=r[e++];for(;e<r.length&&r[e][0]===t&&r[e][1]<=i;)i=Math.max(i,r[e++][2]);this.request(t,n,i)}r.length||await this.next()}}pack(e,t){try{wt(this.asset,t,({vertices:t,indices:n,uvs:r,part:i})=>this.post({type:`geometry`,key:e,vertices:t,indices:n,uvs:r,...i?{part:i}:{}}))}catch(t){this.post({type:`geometry`,key:e,error:At(t)})}}async decompress(e,t){try{let{decompressPrimitive:e}=await Promise.resolve().then(()=>(tt(),Ye));this.signal.throwIfAborted(),await e(this.asset,t,async()=>this.decoders.draco,this.signal),this.signal.throwIfAborted()}catch(t){this.signal.aborted||this.post({type:`geometry`,key:e,error:At(t)});return}this.pack(e,t)}async textureSource(e,t){if(t.bufferView===void 0){if(typeof t.uri!=`string`)throw TypeError(`Invalid glTF image; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return t.uri.startsWith(`data:`)?{bytes:R(t.uri,this.limit)}:{url:S(t.uri,this.base,this.allowedURLs,`glTF`).href}}let n=Y(e,t.bufferView),r=this.map[n.buffer];if(n.packed||this.asset.view(t.bufferView),r?.source>=0){let e=this.sources[r.source],t=r.offset+n.offset,i=t+n.length;for(;e.ranged===void 0;)e.probing||this.request(r.source,t,Math.min(i,t+1)),await this.next();if(e.ranged&&!n.packed)return Z(e.asked,t,i),Z(e.got,t,i),{url:e.url.href,offset:t,length:n.length};if(e.ranged)for(let[n,a]of Q(e.asked,t,Math.min(i,e.data.length)))this.request(r.source,n,a);for(;!$(e.got,t,Math.min(i,e.data.length));)await this.next()}return{bytes:this.asset.view(t.bufferView).slice()}}async images(e){let t=J(e),n=[],r=e.images??[],i=t=>e.materials?.[t?.material],a=(e,t=[],n=0)=>{if(e&&typeof e==`object`&&n<8){let r=e.index;typeof r==`number`&&Number.isSafeInteger(r)&&r>=0&&t.push(r);for(let r of Object.values(e))a(r,t,n+1)}return t};for(let r of this.order)for(let o of a(i(t[r]))){let t=e.textures?.[o];for(let e of[t?.source,...Object.values(t?.extensions??{}).map(e=>e?.source)])Number.isInteger(e)&&!n.includes(e)&&n.push(e)}let o=[...n,...r.map((e,t)=>t).filter(e=>!n.includes(e))].filter(e=>e<r.length),s=0,c=this.textures?dt(e):new Set,l=async t=>{let n=r[t],i=n.mimeType===`image/ktx2`||/\.ktx2$/i.test(n.uri??``);if(i&&this.textures){this.post({type:`image`,index:t,source:await this.textureSource(e,n)});return}if(i||c.has(t)){this.post({type:`image`,index:t});return}let a;if(n.bufferView!==void 0){let t=Y(e,n.bufferView),r=this.map[t.buffer];if(t.packed||this.asset.view(n.bufferView),r?.source>=0){let e=this.sources[r.source],n=r.offset+t.offset,i=Math.min(n+t.length,e.data.length);if(e.ranged){let t=Q(e.asked,n,i);for(let[e,n]of t)this.request(r.source,e,n)}for(;!$(e.got,n,Math.min(i,e.data.length));)e.ranged===void 0&&!e.probing&&this.request(r.source,n,i),await this.next()}a=this.asset.view(n.bufferView)}else if(typeof n.uri==`string`&&n.uri.startsWith(`data:`))a=R(n.uri,this.limit);else if(typeof n.uri==`string`)a=await re(await this.fetch({url:S(n.uri,this.base,this.allowedURLs,`glTF`),got:[],asked:[]}),{maxBytes:Math.max(0,this.limit-this.loaded),signal:this.signal,label:`glTF image`}).catch(e=>{throw e instanceof RangeError?B(`glTF exceeds download budget`,this.limit):e}),this.loaded+=a.length;else throw TypeError(`Invalid glTF image; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let o=await pt(a,n.mimeType,t,this.signal);if(s+=o.width*o.height*4,o.width*o.height>67108864)throw`close`in o&&o.close(),RangeError(`glTF images exceed decoded size limit; load a smaller model, or reduce its textures and meshes`);if(s>this.limit*4)throw`close`in o&&o.close(),B(`glTF images exceed decoded size limit`,this.limit*4);this.post({type:`image`,index:t,image:o})},u=Array.from({length:kt},async()=>{for(let e;(e=o.shift())!==void 0;)await l(e)});await Promise.all(u)}},Mt=self,Nt,Pt=new Map,Ft=0,It={decode(e,{signal:t,...n}){let r=++Ft,i=e.slice();return new Promise((e,t)=>{Pt.set(r,{resolve:e,reject:t}),Mt.postMessage({type:`draco`,id:r,data:i,options:n},[i.buffer])})}};Mt.onmessage=({data:e})=>{if(!e||typeof e!=`object`)return;let t=e;if(typeof t.draco==`number`){let e=Pt.get(t.draco),n=t.error;Pt.delete(t.draco),n?e?.reject(Object.assign(Error(n.message),{name:n.name,code:n.code})):e?.resolve(t.result)}else Array.isArray(t.order)?t.order.every(Number.isSafeInteger)&&Nt?.setOrder(t.order):!Nt&&typeof t.url==`string`&&(Nt=new jt(new URL(t.url),e=>Mt.postMessage(e,[...r(e)]),new AbortController().signal,t.maxDownloadBytes,t.maxNodes,t.allowedURLs,t.textures===!0,t.maxPartVertices,{draco:It})).run()}})();
|