@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
package/dist/workers/gltf.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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}function i(e){self.onmessage=async({data:t})=>{try{if(!t||typeof t!=`object`)throw TypeError(`Invalid parser worker job; post an object`);let n=await e(t);self.postMessage({result:n},[...r(n)])}catch(e){let t={name:e?.name??`Error`,message:e instanceof Error?e.message:String(e)};try{self.postMessage({error:{...e,...t}})}catch{self.postMessage({error:t})}}}}var a,o,s,c,l=t((()=>{a=(e,t)=>Object.assign(Error(t),{name:`MargoError`,code:e}),o=(e,t)=>`${e}; see https://margoengine.com/errors#${t}`,s=(e,t,n=e)=>a(e,o(t,n)),c=(e,t)=>TypeError(o(e,t))})),u=t((()=>{}));function d(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 f=t((()=>{})),p,m,h,g=t((()=>{p=/"(?:__proto__|constructor|prototype)"|\\u/,m=(e,t)=>e===`__proto__`||e===`constructor`||e===`prototype`?void 0:t,h=e=>p.test(e)?JSON.parse(e,m):JSON.parse(e)}));function _(e){for(let t=0;t<8;t++){if(x.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 v(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 y(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:`)&&!_(i.pathname)){for(let e of n)if(v(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 b(e,t,n=[],r=`Asset`){if(!e.url)return e;try{y(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 x,S=t((()=>{x=/%2f|%5c|%00|\u0000|(^|\/)(\.|%2e){1,2}(\/|$)/i})),C,w=t((()=>{C=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 T(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 C,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 C(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 E(e,t){try{if(t.signal?.throwIfAborted(),!e.ok)throw a(`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 T(e.body,t)}var D=t((()=>{l(),w()}));function O(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 ee(e,t,n,r){if(t>n)throw RangeError(`${e} (${t} > ${n}; raise the ${r} option)`)}var te=t((()=>{}));function ne(e=j){if(!Number.isInteger(e)||e<1024||e>1048576)throw RangeError(`maxPartVertices must be an integer from ${M} to ${re} (default ${j})`);return e}function k(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 A(e,t,n,r,i,a=3){let o=e.length/t,s=i?k(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 j,M,re,ie,N=t((()=>{j=262144,M=1024,re=1048576,ie=16777216}));function ae(e,t){if(Number.isSafeInteger(t)&&e>t+3)throw s(`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`)}function oe(e){if(e.length<20)throw P(`needs at least 20 bytes for its 12-byte file header and 8-byte JSON chunk header; received ${e.length}`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0,!0),r=t.getUint32(4,!0),i=t.getUint32(8,!0);if(n!==1179937895)throw P(`header magic 0x${n.toString(16)} is not glTF (0x46546c67)`);if(r!==2)throw P(`header version ${r} is unsupported; use version 2`);if(i!==e.length)throw P(`header total length ${i} bytes differs from the received ${e.length} bytes`);let a=[];for(let n=12;n<e.length;){if(n+8>e.length)throw P(`ends inside the 8-byte chunk header at byte ${n}`);let r=t.getUint32(n,!0),i=t.getUint32(n+4,!0),o=n+8+r;if(r%4)throw P(`chunk length ${r} at byte ${n} must have 4-byte alignment`);if(o>e.length)throw P(`chunk length ${r} at byte ${n} extends past the ${e.length}-byte file`);if(a.length===0!=(i===1313821514)||i===5130562&&a.length!==1)throw P(`chunks must be JSON first, then at most one BIN second; export the file again`);a.push({type:i,data:e.subarray(n+8,o)}),n=o}return a}var P,se,ce=t((()=>{l(),P=e=>c(`GLB ${e}; pass a whole glTF 2.0 GLB file`,`failed`),se=e=>e.length>=4&&new DataView(e.buffer,e.byteOffset,4).getUint32(0,!0)===1179937895}));function le(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 ue,de=t((()=>{ue={__proto__:null,5120:1,5121:1,5122:2,5123:2,5125:4,5126:4}})),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))})),F,he,ge=t((()=>{F=(e,t)=>Object.assign(Error(e,t===void 0?void 0:{cause:t}),{name:`MargoError`,code:`failed`}),he=e=>Object.assign(Error(e),{name:`MargoError`,code:`unsupported`})}));function _e(e){if(xe[e])return[1,1,xe[e]];if(/^bc[1-7]h?-/.test(e))return[4,4,/^bc[14]-/.test(e)?8:16,`texture-compression-bc`];if(/^(etc2|eac)-/.test(e))return[4,4,/^(etc2-rgb8|eac-r11)/.test(e)?8:16,`texture-compression-etc2`];let t=/^astc-(\d+)x(\d+)-/.exec(e);if(t)return[+t[1],+t[2],16,`texture-compression-astc`]}function ve(e,t,n){let r=Math.ceil(t/e[0])*e[2];return[r*Math.ceil(n/e[1]),r]}function ye(e,t,n){return e[0].map((r,i)=>{let a=e[0][i].length,o=new Uint8Array(a*e.length);return e.forEach((e,t)=>o.set(e[i],t*a)),{data:o,width:Math.max(1,t>>i),height:Math.max(1,n>>i),byteLength:o.byteLength}})}function be(e,t,n={}){let r=_e(t.format);if(!r)throw TypeError(`Texture format ${String(t.format)} is unknown; pass a parseDDS or parseKTX result`);let[i,a,,o]=r;if(o&&!e.features.has(o))throw he(`Texture format ${t.format} needs the device feature ${o}; request it with adapter.requestDevice({requiredFeatures: ['${o}']}) where adapter.features has it, or convert the file to an uncompressed format`);if(t.width%i||t.height%a)throw RangeError(`Texture ${t.width}x${t.height} is not a whole number of ${i}x${a} ${t.format} blocks; resize the source to a multiple of ${i}x${a}`);if(Math.max(t.width,t.height)>e.limits.maxTextureDimension2D)throw RangeError(`Texture ${t.width}x${t.height} exceeds the device's maxTextureDimension2D; use a smaller file`);if(t.layers>e.limits.maxTextureArrayLayers)throw RangeError(`Texture of ${t.layers} layers exceeds the device's maxTextureArrayLayers; request a higher limit or use fewer layers`);let s=e.createTexture({label:n.label,size:[t.width,t.height,t.layers],mipLevelCount:t.mipmaps.length,format:t.format,usage:n.usage??GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST});try{for(let[n,o]of t.mipmaps.entries()){let c=Math.ceil(o.height/a);e.queue.writeTexture({texture:s,mipLevel:n},o.data,{bytesPerRow:ve(r,o.width,o.height)[1],rowsPerImage:c},[Math.ceil(o.width/i)*i,c*a,t.layers])}}catch(e){throw s.destroy(),e}return s}var xe,Se=t((()=>{ge(),xe={r8unorm:1,r8snorm:1,rg8unorm:2,rg8snorm:2,rgba8unorm:4,"rgba8unorm-srgb":4,rgba8snorm:4,bgra8unorm:4,"bgra8unorm-srgb":4,r16float:2,rg16float:4,rgba16float:8,r32float:4,rg32float:8,rgba32float:16,rgb10a2unorm:4,rg11b10ufloat:4,rgb9e5ufloat:4}}));function Ce(e,t,n,r,i){let a=new Uint8Array(t*4),o=[0,1,2,3].map(e=>r[i&&e<3?0:e]>>>0);for(let r=0;r<t;r++){let t=0;for(let i=0;i<n;i++)t+=e[r*n+i]*2**(8*i);for(let e=0;e<4;e++){let n=o[e];a[r*4+e]=n?Math.round(((t&n)>>>0)/n*255):e===3?255:0}}return a}function we(e){if(!(e instanceof Uint8Array))throw TypeError(`parseDDS needs the DDS file as a Uint8Array`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=e=>t.getUint32(e,!0);if(e.length<128||n(0)!==542327876||n(4)!==124||n(76)!==32)throw I(`header is missing`);let r=n(12),i=n(16),a=n(80),o=n(112),s=String.fromCharCode(e[84],e[85],e[86],e[87]),c=Math.max(1,n(28));if(!i||!r||i>65536||r>65536)throw I(`size ${i}x${r} is invalid`);if(c>32-Math.clz32(Math.max(i,r)))throw I(`has ${c} mip levels, too many for its size`);if(o&2097152||n(8)&8388608&&n(24)>1)throw L(`volume texture`);let l,u,d=0,f=!1,p=!0,m=!!(o&512),h=1,g=128;if(m&&(o&64512)!=64512)throw L(`cube map without all six faces`);if(a&4&&s===`DX10`){if(e.length<148)throw I(`DX10 header is missing`);let t=n(128),r=De[t];if(n(132)!==3&&n(132)!==0)throw L(`resource dimension ${n(132)} (only 2D textures)`);if(m=!!(n(136)&4),h=n(140)||1,p=(n(144)&7)!=3,g=148,r?([d]=r,d/=8,u=r.slice(1,5),l=r[5]?`rgba8unorm-srgb`:`rgba8unorm`,p&&=!!r[4]):l=Ee[t],!l)throw L(`DXGI format ${t}`)}else if(a&4){let e=/^[\x20-\x7e]{4}$/.test(s)?s:String(n(84));if(l=Te[e],!l)throw L(`FourCC ${e}`)}else if(a&131138){let e=n(88),t=a&3?n(104):0;if(f=!!(a&131072),u=a&131136?[n(92),n(96),n(100),t]:[0,0,0,t],![8,16,24,32].includes(e)||u.every(e=>!e))throw I(`pixel format of ${e} bits is invalid`);d=e/8,p=!!t,l=`rgba8unorm`,e===32&&!f&&u.join()===[255,65280,16711680,t?4278190080:0].join()&&t&&(u=void 0)}else throw L(`pixel format (YUV or unknown)`);let _=_e(l),v=h*(m?6:1),y=[];(/^bc[456]/.test(l)||/^(r|rg)\d/.test(l))&&(p=!1);for(let t=0;t<v;t++){let n=[];for(let a=0;a<c;a++){let o=Math.max(1,i>>a),s=Math.max(1,r>>a),c=u?o*s*d:ve(_,o,s)[0];if(g+c>e.length)throw I(`ends inside layer ${t} mip ${a}`);let l=e.subarray(g,g+=c);n.push(u?Ce(l,o*s,d,u,f):l)}y.push(n)}return{width:i,height:r,layers:v,dimension:m?h>1?`cube-array`:`cube`:v>1?`2d-array`:`2d`,mipmaps:ye(y,i,r),format:l,..._[3]?{feature:_[3]}:{},target:`dds`,srgb:l.endsWith(`-srgb`),hasAlpha:p}}var Te,Ee,De,I,L,Oe=t((()=>{ge(),Se(),Te={DXT1:`bc1-rgba-unorm`,DXT2:`bc2-rgba-unorm`,DXT3:`bc2-rgba-unorm`,DXT4:`bc3-rgba-unorm`,DXT5:`bc3-rgba-unorm`,ATI1:`bc4-r-unorm`,BC4U:`bc4-r-unorm`,BC4S:`bc4-r-snorm`,ATI2:`bc5-rg-unorm`,BC5U:`bc5-rg-unorm`,BC5S:`bc5-rg-snorm`,111:`r16float`,112:`rg16float`,113:`rgba16float`,114:`r32float`,115:`rg32float`,116:`rgba32float`},Ee={2:`rgba32float`,10:`rgba16float`,16:`rg32float`,24:`rgb10a2unorm`,26:`rg11b10ufloat`,28:`rgba8unorm`,29:`rgba8unorm-srgb`,31:`rgba8snorm`,34:`rg16float`,41:`r32float`,49:`rg8unorm`,51:`rg8snorm`,54:`r16float`,61:`r8unorm`,63:`r8snorm`,67:`rgb9e5ufloat`,71:`bc1-rgba-unorm`,72:`bc1-rgba-unorm-srgb`,74:`bc2-rgba-unorm`,75:`bc2-rgba-unorm-srgb`,77:`bc3-rgba-unorm`,78:`bc3-rgba-unorm-srgb`,80:`bc4-r-unorm`,81:`bc4-r-snorm`,83:`bc5-rg-unorm`,84:`bc5-rg-snorm`,95:`bc6h-rgb-ufloat`,96:`bc6h-rgb-float`,98:`bc7-rgba-unorm`,99:`bc7-rgba-unorm-srgb`},De={85:[16,63488,2016,31,0],86:[16,31744,992,31,32768],87:[32,16711680,65280,255,4278190080],88:[32,16711680,65280,255,0],91:[32,16711680,65280,255,4278190080,!0],93:[32,16711680,65280,255,0,!0],115:[16,3840,240,15,61440]},I=e=>F(`DDS ${e}; pass the complete bytes of a valid DDS file`),L=e=>F(`DDS ${e} is not supported; convert the file to a 2D, cube or array texture in a WebGPU format`)})),ke,Ae,je,Me,Ne,Pe=t((()=>{ke=`0011001100110011000100010001000101110111011101110001001100110111000000010001001100110111011111110001001101111111000000010011011100000000000100110011011111111111000000010111111100000000000101110001011111111111000000001111111100001111111111110000000000001111000010001110111101110001000000000000000010001110011100110001000000110001000000000000100011001110000000001000110001110011001100010011000100010000000010001000110001100110011001100011011001101100000101111110100000001111111100000111000110001110001110011001110001010101010101010000111100001111010110100101101000110011110011000011110000111100010101011010101001101001011010010101101010100101011100111100111000010011110010000011001001001100001110111101110001101001100101100011110011000011011001101001100100000110011000000100111001000000001001110010000000000010011100100000010011100100011011001001001100110110110010010110001110011100001110011100011001101100110010010110001100111001011111101000000100011000111001110000111100110011001100111111000000100010111011100100010001110111`,Ae=`0011001102212222000100112211222100002001221122110222002200110111000000001122112200110011002200220022002211111111001100112211221100000000111122220000111111112222000011112222222200120012001200120112011201120112012201220122012200110112112212220011200122002220000100110112112201110011200122000000112211221122002200220022111101110111022202220001000122212221000000110122012200001100221022100122012200110000001200121122222201101221122101100000011012211221002211021102002201100110200222220011012201220011000020002211222100000002112212220222002200120011001100120022022201200120012001200000111122220000012012012012012001202012120101200011220011220011001111222200001101010101222222220000000021212121002211220022112200220011002200110220122102201221010122222222010100002121212121210101010101012222022201110222011100021112000211120000211221122112022201110111022200021112111200020110011001102222000000002112211201100110222222220022001100110022002211221122002200000000000021120002000100020001022212220222122201012222222222220111201122012220`,je=[15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,2,8,2,2,8,8,15,2,8,2,2,8,8,2,2,15,15,6,8,2,8,15,15,2,8,2,2,2,15,15,6,6,2,6,8,15,15,2,2,15,15,15,15,15,2,2,15],Me=[3,3,15,15,8,3,15,15,8,8,6,6,6,5,3,3,3,3,8,15,3,3,6,10,5,8,8,6,8,5,15,15,8,15,3,5,6,10,8,15,15,3,15,5,15,15,15,15,3,15,5,5,5,8,5,10,5,10,8,13,15,12,3,3],Ne=[15,8,8,3,15,15,3,8,15,15,15,15,15,15,15,8,15,8,15,3,15,8,15,8,3,15,6,10,15,15,10,8,15,3,15,10,10,8,9,10,6,15,8,15,3,6,6,8,15,3,15,15,15,15,15,15,15,15,15,15,3,15,15,8]}));function Fe(e,t,n,r){let i=e[t]|e[t+1]<<8,a=e[t+2]|e[t+3]<<8,o=[He(i>>11),Ue(i>>5&63),He(i&31),255,He(a>>11),Ue(a>>5&63),He(a&31),255],s=!r||i>a;for(let e=0;e<3;e++){let t=o[e],n=o[4+e];s?(o[8+e]=Math.round((2*t+n)/3),o[12+e]=Math.round((t+2*n)/3)):(o[8+e]=t+n+1>>1,o[12+e]=0)}o[11]=255,o[15]=s?255:0;for(let r=0;r<16;r++){let i=(e[t+4+(r>>2)]>>(r&3)*2&3)*4;n[r*4]=o[i],n[r*4+1]=o[i+1],n[r*4+2]=o[i+2],n[r*4+3]=o[i+3]}}function Ie(e,t,n,r,i){let a=e=>i?Math.max(e<<24>>24,-127):e,o=a(e[t]),s=a(e[t+1]),c=[o,s,0,0,0,0,0,0],l=i?127:255,u=i?-127:0;if(o>s)for(let e=1;e<7;e++)c[e+1]=((7-e)*o+e*s)/7;else{for(let e=1;e<5;e++)c[e+1]=((5-e)*o+e*s)/5;c[6]=u,c[7]=l}for(let a=0;a<16;a++){let o=a*3,s=t+2+(o>>3),u=c[(e[s]|e[s+1]<<8)>>(o&7)&7];n[a*4+r]=n instanceof Float32Array?u/l:i?Ve(u):Math.round(u)}}function R(e,t,n,r){let i=0;for(let a=0;a<r;a++,n++)i|=(e[t+(n>>3)]>>(n&7)&1)<<a;return i}function Le(e){let t=tt.get(e);return t||(t=$e[e].split(` `).map(e=>{let[,t,n,r,i]=/^([RGB])(\d)(\d+)(?:\.\.(\d+))?$/.exec(e),a=Number(i??r),o=Number(r),s=[];for(let e=a;s.push(e),e!==o;e+=o>=a?1:-1);return[Number(n),`RGB`.indexOf(t),s]}),tt.set(e,t)),t}function Re(e,t,n){if(!n)return t>=15?e:e===0?0:e===(1<<t)-1?65535:(e<<15)+16384>>t-1;if(t>=16)return e;let r=e<0,i=r?-e:e,a;return a=i===0?0:i>=(1<<t-1)-1?32767:(i<<15)+16384>>t-1,r?-a:a}function ze(e,t,n,r){let i=e.replace(/-unorm(-srgb)?$/,t=>/^bc[45]/.test(e)?t:``),a=ot[i];if(!a)throw TypeError(`${e} is not a BC format; pass one of bc1-rgba-unorm to bc7-rgba-unorm-srgb`);let[o,s]=a,c=n+3>>2,l=r+3>>2;if(t.length<c*l*s)throw F(`${e}: ${t.length} bytes hold too few blocks for ${n}x${r}; pass the whole level`);let u=new Uint8Array(n*r*4),d=new Uint8Array(64);for(let e=0;e<l;e++)for(let i=0;i<c;i++){o(t,(e*c+i)*s,d);for(let t=0;t<4&&e*4+t<r;t++){let r=Math.min(4,n-i*4);u.set(d.subarray(t*16,t*16+r*4),((e*4+t)*n+i*4)*4)}}return{width:n,height:r,data:u}}function Be(e,t,n,r){if(!/^bc[456]/.test(e)){let i=ze(e,t,n,r);return{width:n,height:r,data:Float32Array.from(i.data,e=>e/255)}}let i=ot[e];if(!i)throw TypeError(`Unknown BC float format `+e+`; pass a BC4, BC5 or BC6H WebGPU format`);let[a,o]=i,s=Math.ceil(n/4),c=Math.ceil(r/4);if(t.length<s*c*o)throw F(`BC float image has too few blocks; pass the complete mip level`);let l=new Float32Array(n*r*4),u=new Float32Array(64);for(let e=0;e<c;e++)for(let i=0;i<s;i++){a(t,(e*s+i)*o,u);for(let t=0;t<4&&e*4+t<r;t++){let r=Math.min(4,n-i*4);l.set(u.subarray(t*16,t*16+r*4),((e*4+t)*n+i*4)*4)}}return{width:n,height:r,data:l}}var Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et,tt,nt,rt,it,at,ot,st=t((()=>{Pe(),ge(),Ve=e=>Math.round((Math.max(e,-127)+127)/254*255),He=e=>e<<3|e>>2,Ue=e=>e<<2|e>>4,We=(e,t,n)=>Fe(e,t,n,!0),Ge=(e,t,n)=>{Fe(e,t+8,n,!1);for(let r=0;r<16;r++)n[r*4+3]=(e[t+(r>>1)]>>(r&1)*4&15)*17},Ke=(e,t,n)=>{Fe(e,t+8,n,!1),Ie(e,t,n,3,!1)},qe=e=>(t,n,r)=>{Ie(t,n,r,0,e);for(let t=0;t<16;t++)r[t*4+1]=r[t*4+2]=r instanceof Float32Array?0:e?128:0,r[t*4+3]=r instanceof Float32Array?1:255},Je=e=>(t,n,r)=>{Ie(t,n,r,0,e),Ie(t,n+8,r,1,e);for(let t=0;t<16;t++)r[t*4+2]=r instanceof Float32Array?0:e?128:0,r[t*4+3]=r instanceof Float32Array?1:255},Ye={2:[0,21,43,64],3:[0,9,18,27,37,46,55,64],4:[0,4,9,13,17,21,26,30,34,38,43,47,51,55,60,64]},Xe=[[3,4,0,0,4,0,1,0,3,0],[2,6,0,0,6,0,0,1,3,0],[3,6,0,0,5,0,0,0,2,0],[2,6,0,0,7,0,1,0,2,0],[1,0,2,1,5,6,0,0,2,3],[1,0,2,0,7,8,0,0,2,2],[1,0,0,0,7,7,1,0,4,0],[2,6,0,0,5,5,1,0,2,0]],Ze=(e,t)=>{let n=e<<8-t;return n|n>>t},Qe=(e,t,n)=>{let r=0;for(;r<8&&!(e[t]>>r&1);)r++;if(r===8){n.fill(0);return}let[i,a,o,s,c,l,u,d,f,p]=Xe[r],m=r+1,h=n=>{let r=R(e,t,m,n);return m+=n,r},g=h(a),_=h(o),v=h(s),y=i*2,b=new Uint8Array(y*4);for(let e=0;e<3;e++)for(let t=0;t<y;t++)b[t*4+e]=h(c);if(l)for(let e=0;e<y;e++)b[e*4+3]=h(l);let x=new Uint8Array(y);if(u)for(let e=0;e<y;e++)x[e]=h(1);if(d)for(let e=0;e<i;e++)x[e*2]=x[e*2+1]=h(1);let S=u||d?1:0;for(let e=0;e<y;e++)for(let t=0;t<4;t++){if(t===3&&!l){b[e*4+3]=255;continue}let n=(t===3?l:c)+S;b[e*4+t]=Ze(S?b[e*4+t]<<1|x[e]:b[e*4+t],n)}let C=e=>i===1?0:(i===2?ke:Ae).charCodeAt(g*16+e)-48,w=e=>e===0||i===2&&e===je[g]||i===3&&(e===Me[g]||e===Ne[g]),T=new Uint8Array(16),E=new Uint8Array(16);for(let e=0;e<16;e++)T[e]=h(w(e)?f-1:f);if(p)for(let e=0;e<16;e++)E[e]=h(e===0?p-1:p);let D=v?E:T,O=v?T:p?E:T,ee=Ye[v?p:f],te=Ye[v?f:p||f];for(let e=0;e<16;e++){let t=C(e)*8,r=ee[D[e]],i=te[O[e]],a=(e,n)=>(64-n)*b[t+e]+n*b[t+4+e]+32>>6,o=a(0,r),s=a(1,r),c=a(2,r),l=a(3,i),u=e*4;n[u]=_===1?l:o,n[u+1]=_===2?l:s,n[u+2]=_===3?l:c,n[u+3]=_===1?o:_===2?s:_===3?c:l}},$e={0:`G24 B24 B34 R09..0 G09..0 B09..0 R14..0 G34 G23..0 G14..0 B30 G33..0 B14..0 B31 B23..0 R24..0 B32 R34..0 B33`,1:`G25 G34 G35 R06..0 B30 B31 B24 G06..0 B25 B32 G24 B06..0 B33 B35 B34 R15..0 G23..0 G15..0 G33..0 B15..0 B23..0 R25..0 R35..0`,2:`R09..0 G09..0 B09..0 R14..0 R010 G23..0 G13..0 G010 B30 G33..0 B13..0 B010 B31 B23..0 R24..0 B32 R34..0 B33`,6:`R09..0 G09..0 B09..0 R13..0 R010 G34 G23..0 G14..0 G010 G33..0 B13..0 B010 B31 B23..0 R23..0 B30 B32 R33..0 G24 B33`,10:`R09..0 G09..0 B09..0 R13..0 R010 B24 G23..0 G13..0 G010 B30 G33..0 B14..0 B010 B23..0 R23..0 B31 B32 R33..0 B34 B33`,14:`R08..0 B24 G08..0 G24 B08..0 B34 R14..0 G34 G23..0 G14..0 B30 G33..0 B14..0 B31 B23..0 R24..0 B32 R34..0 B33`,18:`R07..0 G34 B24 G07..0 B32 G24 B07..0 B33 B34 R15..0 G23..0 G14..0 B30 G33..0 B14..0 B31 B23..0 R25..0 R35..0`,22:`R07..0 B30 B24 G07..0 G25 G24 B07..0 G35 B34 R14..0 G34 G23..0 G15..0 G33..0 B14..0 B31 B23..0 R24..0 B32 R34..0 B33`,26:`R07..0 B31 B24 G07..0 B25 G24 B07..0 B35 B34 R14..0 G34 G23..0 G14..0 B30 G33..0 B15..0 B23..0 R24..0 B32 R34..0 B33`,30:`R05..0 G34 B30 B31 B24 G05..0 G25 B25 B32 G24 B05..0 G35 B33 B35 B34 R15..0 G23..0 G15..0 G33..0 B15..0 B23..0 R25..0 R35..0`,3:`R09..0 G09..0 B09..0 R19..0 G19..0 B19..0`,7:`R09..0 G09..0 B09..0 R18..0 R010 G18..0 G010 B18..0 B010`,11:`R09..0 G09..0 B09..0 R17..0 R010..11 G17..0 G010..11 B17..0 B010..11`,15:`R09..0 G09..0 B09..0 R13..0 R010..15 G13..0 G010..15 B13..0 B010..15`},et={0:[!0,10,5,5,5],1:[!0,7,6,6,6],2:[!0,11,5,4,4],6:[!0,11,4,5,4],10:[!0,11,4,4,5],14:[!0,9,5,5,5],18:[!0,8,6,5,5],22:[!0,8,5,6,5],26:[!0,8,5,5,6],30:[!1,6,6,6,6],3:[!1,10,10,10,10],7:[!0,11,9,9,9],11:[!0,12,8,8,8],15:[!0,16,4,4,4]},tt=new Map,nt=(e,t)=>t>=32?e:e<<32-t>>32-t,rt=e=>{let t=e>>10&31,n=e&1023,r=t===0?n/16777216:t===31?n?NaN:1/0:(1+n/1024)*2**(t-15);return e&32768?-r:r},it=e=>{let t=e<=0?0:e>=1?1:e;return Math.round((t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055)*255)},at=e=>(t,n,r)=>{let i=R(t,n,0,2),a=i<2?i:R(t,n,0,5),o=et[a];if(!o){for(let e=0;e<16;e++)r.set([0,0,0,r instanceof Float32Array?1:255],e*4);return}let[s,c,...l]=o,u=a<3||(a&3)==2,d=new Int32Array(12),f=i<2?2:5;for(let[e,r,i]of Le(a))for(let a of i)t[n+(f>>3)]>>(f&7)&1&&(d[e*3+r]|=1<<a),f++;let p=u?R(t,n,f,5):0;f+=u?5:0;let m=u?4:2;for(let t=0;t<3;t++){e&&(d[t]=nt(d[t],c));for(let n=1;n<m;n++){let r=n*3+t;s&&(d[r]=nt(d[r],l[t])+d[t]&(1<<c)-1),e&&(d[r]=nt(d[r],c))}for(let n=0;n<m;n++)d[n*3+t]=Re(d[n*3+t],c,e)}let h=u?3:4,g=Ye[h];for(let i=0;i<16;i++){let a=u?ke.charCodeAt(p*16+i)-48:0,o=i===0||u&&i===je[p]?h-1:h,s=g[R(t,n,f,o)];f+=o;for(let t=0;t<3;t++){let n=d[a*6+t],o=d[a*6+3+t],c=(64-s)*n+s*o+32>>6,l=e?c<0?-c*31>>5|32768:c*31>>5:c*31>>6;r[i*4+t]=r instanceof Float32Array?rt(l):it(rt(l))}r[i*4+3]=r instanceof Float32Array?1:255}},ot={"bc1-rgba":[We,8],"bc2-rgba":[Ge,16],"bc3-rgba":[Ke,16],"bc4-r-unorm":[qe(!1),8],"bc4-r-snorm":[qe(!0),8],"bc5-rg-unorm":[Je(!1),16],"bc5-rg-snorm":[Je(!0),16],"bc6h-rgb-ufloat":[at(!1),16],"bc6h-rgb-float":[at(!0),16],"bc7-rgba":[Qe,16]}})),ct=n({ddsTextures:()=>dt,decodeDDSImage:()=>ut});function lt(e){let t=e<0?32768:0,n=Math.abs(e);if(!n)return t;let r=Math.max(-14,Math.floor(Math.log2(n))),i=n*2**(10-r),a=Math.floor(i),o=a+(i-a>.5||i-a===.5&&a%2?1:0);return t|(r===-14&&o<1024?o:(r+14<<10)+o)}function ut(e,t={}){t.signal?.throwIfAborted();let n=we(e);if(n.dimension!==`2d`||n.layers!==1)throw a(`unsupported`,`glTF material DDS images must be single-layer 2D textures; export a 2D image`);if(n.width*n.height>67108864)throw RangeError(`glTF DDS image exceeds decoded size limit; export a smaller texture`);let r,i=e=>{if(!n.feature||e.features.has(n.feature)&&n.width%4==0&&n.height%4==0)return n;if(!r){let e=/^bc[456]/.test(n.format),t=n.mipmaps.map(t=>{let r=e?Be(n.format,t.data,t.width,t.height):ze(n.format,t.data,t.width,t.height),i=e?Uint16Array.from(r.data,lt):r.data,a=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);return{...t,data:a,byteLength:a.length}});r={...n,format:e?`rgba16float`:`rgba8unorm`,feature:void 0,mipmaps:t}}return r},o=(e,t)=>{let n=i(e).format.replace(/-srgb$/,``);return n+(t&&/^(rgba8unorm|bc[1237]-)/.test(n)?`-srgb`:``)};return{width:n.width,height:n.height,format:n.format,mipmaps:n.mipmaps,gpuFormat:o,upload(e,t){let n=i(e),r=o(e,t);if(/^(r|rg|rgba)32float$/.test(r)&&!e.features.has(`float32-filterable`))throw a(`unsupported`,`32-bit float DDS material textures require float32-filterable; request that device feature or export 16-bit float DDS`);return be(e,{...n,format:r})}}}var dt,ft=t((()=>{Oe(),st(),l(),u(),dt={decode:ut}}));function pt(e){let t;if(typeof e?.sceneOf==`function`){for(let n of e.plugins?.values()??[])if(t=e.sceneOf(n))break;if(!t){let n={name:gt(e,`scene-scope:`),setup(){t=e.sceneOf(n)}};e.use(n),e.removePlugin(n.name)}}return mt(e,t)}function mt(e,t){return{scene:t,run(n){if(!t)return n();let r,i={name:gt(e,`scene-scope:`),setup(){r=n()}};return t.use(i),t.removePlugin(i.name),r}}}var ht,gt,_t=t((()=>{ht=0,gt=(e,t)=>{let n=t+ht++;for(;e.plugins?.has(n);)n+=`:`;return n}})),vt=n({}),yt=t((()=>{})),bt=n({gaussianSplats:()=>It,readGaussianSplats:()=>St});function xt(e,t,n,r,i,a){let o=t[n];if(o===void 0)throw B(`primitive: ${n} is missing`);let s=e.doc.accessors?.[o];if(!i.some(([e,t])=>e===s?.componentType&&t===!!s?.normalized))throw B(`accessor for ${n}: componentType ${s?.componentType}${s?.normalized?` normalized`:``}`);let c=e.accessor(o,r);if(s?.count!==a)throw B(`accessor for ${n}: its count differs from POSITION`);return c}async function St(e,t,{signal:n}={}){let r=t.extensions?.[z],i=t.attributes??{};if(!r||typeof r!=`object`||Array.isArray(r))throw B(`extension`);if(t.mode!==0)throw B(`primitive: its mode must be POINTS`);let{kernel:o=`ellipse`,colorSpace:s=`srgb_rec709_display`}=r;if(o!==`ellipse`)throw a(`unsupported`,`${z} kernel ${o} is not supported; re-export the file with "ellipse"`);if(s!==`srgb_rec709_display`&&s!==`lin_rec709_display`)throw a(`unsupported`,`${z} color space ${s} is not supported; re-export the file in rec709`);let{parseSpz:c,splatsFromAttributes:l}=await Pt(Promise.resolve().then(()=>(yt(),vt)));n?.throwIfAborted();let u=r.extensions?.[Tt];if(u){if(s!==`srgb_rec709_display`)throw B(`primitive: SPZ colour is srgb_rec709_display`);return c(e.view(u.bufferView),{signal:n})}let d=e.accessor(i.POSITION,`VEC3`),f=d.length/3,p=(t,n,r)=>xt(e,i,`${z}:${t}`,n,r,f),m=p(`ROTATION`,`VEC4`,At),h=p(`SCALE`,`VEC3`,jt),g=p(`OPACITY`,`SCALAR`,Mt),_=p(`SH_DEGREE_0_COEF_0`,`VEC3`,Nt),v=[],y=!1;Dt.forEach((e,t)=>{let n=Array.from({length:e},(e,n)=>`SH_DEGREE_${t+1}_COEF_${n}`),r=n.filter(e=>`${z}:${e}`in i).length;if(r&&(r!==e||y))throw B(`primitive: spherical harmonics degree ${t+1}`);if(r)for(let e of n)v.push(p(e,`VEC3`,Nt));else y=!0});let b={count:f,positions:d,logScales:h.map(Math.log),rotations:new Float32Array(f*4),dc:_,alphas:g};for(let e=0;e<f;e++)b.rotations[e*4]=m[e*4+3],b.rotations.set(m.subarray(e*4,e*4+3),e*4+1);if(v.length){let e=new Float32Array(f*v.length*3);v.forEach((t,n)=>{for(let r=0;r<f;r++)e.set(t.subarray(r*3,r*3+3),(r*v.length+n)*3)}),b.rest=e}return l(b,{linear:s===`lin_rec709_display`})}function Ct(e,t){let n=Ft(e);if(n===t)return e;let r=e.positions.length/3,i=new Float32Array(r*t*3);for(let a=0;a<r;a++)if(n)i.set(e.sphericalHarmonics.subarray(a*n*3,(a+1)*n*3),a*t*3);else for(let n=0;n<3;n++)i[a*t*3+n]=(e.colors[a*4+n]-.5)/kt;return{...e,sphericalHarmonics:i}}function wt({positions:e}){let t=new Float32Array([1/0,1/0,1/0,-1/0,-1/0,-1/0]);for(let n=0;n<e.length;n+=3)for(let r=0;r<3;r++)t[r]=Math.min(t[r],e[n+r]),t[r+3]=Math.max(t[r+3],e[n+r]);return t}var z,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,B,Pt,Ft,It,Lt=t((()=>{l(),_t(),z=`KHR_gaussian_splatting`,Tt=`KHR_gaussian_splatting_compression_spz_2`,Et=5126,Dt=[3,5,7],Ot=3e6,kt=.2820947917738781,At=[[Et,!1],[5120,!0],[5122,!0]],jt=[[Et,!1],[5121,!1],[5121,!0],[5123,!1],[5123,!0]],Mt=[[Et,!1],[5121,!0],[5123,!0]],Nt=[[Et,!1]],B=e=>TypeError(`Invalid glTF ${z} ${e}; the file is not valid, re-export it and check it with the glTF Validator`),Pt=e=>e.catch(e=>{throw a(`unsupported`,`${z} needs @margoengine/splats (${e instanceof Error?e.message:e}): install it, or pass decoders: {splats: false} for the point cloud fallback`)}),Ft=e=>e.sphericalHarmonics?e.sphericalHarmonics.length/(e.positions.length/3)/3:0,It={async attach(e,t,n,r){let i=pt(e),{Splats:a,mergeSplats:o,transformSplats:s}=await Pt(Promise.resolve().then(()=>(yt(),vt))),c=[];for(let{primitive:e,matrix:i}of n)c.push(s(await St(t,e,{signal:r}),i));let l=Math.max(...c.map(Ft)),u=[],d=Ot;for(let e of c){let t=e.positions.length/3;d+t>Ot&&(u.push([]),d=0),u[u.length-1].push(l?Ct(e,l):e),d+=t}let f=[];try{for(let t of u){r?.throwIfAborted();let n=t.length>1?o(...t):t[0],s=new a(n);i.run(()=>e.use(s)),f.push({cloud:s,bounds:wt(n)})}}catch(e){for(let{cloud:e}of f)e.dispose();throw e}return f}}}));function Rt(e){let t=[`base`,`mr`,`normal`,`ao`,`emissive`];for(let n=0;n<t.length;n++){let r=t[n];e=e.replace(`@group(1) @binding(${n*2}) var ${r}Map:texture_2d<f32>;`,``).replace(`@group(1) @binding(${n*2+1}) var ${r}Sampler:sampler;`,``).replaceAll(`textureSample(${r}Map,${r}Sampler,`,`margoBaseSample(${n},`)}return zt+e}var zt,Bt=t((()=>{zt=`
|
|
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}function i(e){self.onmessage=async({data:t})=>{try{if(!t||typeof t!=`object`)throw TypeError(`Invalid parser worker job; post an object`);let n=await e(t);self.postMessage({result:n},[...r(n)])}catch(e){let t={name:e?.name??`Error`,message:e instanceof Error?e.message:String(e)};try{self.postMessage({error:{...e,...t}})}catch{self.postMessage({error:t})}}}}var a,o,s,c,l=t((()=>{a=(e,t)=>Object.assign(Error(t),{name:`MargoError`,code:e}),o=(e,t)=>`${e}; see https://margoengine.com/errors#${t}`,s=(e,t,n=e)=>a(e,o(t,n)),c=(e,t)=>TypeError(o(e,t))})),u=t((()=>{}));function d(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 f=t((()=>{})),p,m,h,g=t((()=>{p=/"(?:__proto__|constructor|prototype)"|\\u/,m=(e,t)=>e===`__proto__`||e===`constructor`||e===`prototype`?void 0:t,h=e=>p.test(e)?JSON.parse(e,m):JSON.parse(e)}));function _(e){for(let t=0;t<8;t++){if(x.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 v(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 y(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:`)&&!_(i.pathname)){for(let e of n)if(v(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 b(e,t,n=[],r=`Asset`){if(!e.url)return e;try{y(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 x,S=t((()=>{x=/%2f|%5c|%00|\u0000|(^|\/)(\.|%2e){1,2}(\/|$)/i})),C,w=t((()=>{C=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 T(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 C,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 C(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 E(e,t){try{if(t.signal?.throwIfAborted(),!e.ok)throw a(`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 T(e.body,t)}var D=t((()=>{l(),w()}));function O(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 k(e,t,n,r){if(t>n)throw RangeError(`${e} (${t} > ${n}; raise the ${r} option)`)}var ee=t((()=>{}));function te(e=j){if(!Number.isInteger(e)||e<1024||e>1048576)throw RangeError(`maxPartVertices must be an integer from ${M} to ${N} (default ${j})`);return e}function ne(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 A(e,t,n,r,i,a=3){let o=e.length/t,s=i?ne(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 j,M,N,P,re=t((()=>{j=262144,M=1024,N=1048576,P=16777216}));function ie(e,t){if(Number.isSafeInteger(t)&&e>t+3)throw s(`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`)}function ae(e){if(e.length<20)throw F(`needs at least 20 bytes for its 12-byte file header and 8-byte JSON chunk header; received ${e.length}`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0,!0),r=t.getUint32(4,!0),i=t.getUint32(8,!0);if(n!==1179937895)throw F(`header magic 0x${n.toString(16)} is not glTF (0x46546c67)`);if(r!==2)throw F(`header version ${r} is unsupported; use version 2`);if(i!==e.length)throw F(`header total length ${i} bytes differs from the received ${e.length} bytes`);let a=[];for(let n=12;n<e.length;){if(n+8>e.length)throw F(`ends inside the 8-byte chunk header at byte ${n}`);let r=t.getUint32(n,!0),i=t.getUint32(n+4,!0),o=n+8+r;if(r%4)throw F(`chunk length ${r} at byte ${n} must have 4-byte alignment`);if(o>e.length)throw F(`chunk length ${r} at byte ${n} extends past the ${e.length}-byte file`);if(a.length===0!=(i===1313821514)||i===5130562&&a.length!==1)throw F(`chunks must be JSON first, then at most one BIN second; export the file again`);a.push({type:i,data:e.subarray(n+8,o)}),n=o}return a}var F,oe,se=t((()=>{l(),F=e=>c(`GLB ${e}; pass a whole glTF 2.0 GLB file`,`failed`),oe=e=>e.length>=4&&new DataView(e.buffer,e.byteOffset,4).getUint32(0,!0)===1179937895}));function ce(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 le,ue=t((()=>{le={__proto__:null,5120:1,5121:1,5122:2,5123:2,5125:4,5126:4}})),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))}));function me(e,t){let n=t?.mode??4;if(n>3)return;let r=n===0?`points`:`lines`,i=t.extras,a=i?.[r===`points`?`pointSize`:`lineWidth`],o=i?.[r===`points`?`pointSizeUnits`:`lineWidthUnits`]??`pixels`;if(_e(a)&&(o===`pixels`||o===`world`))return{kind:r,size:a,units:o,bentley:!1};let s=(t.material===void 0?void 0:e.materials?.[t.material])?.extensions?.[r===`points`?ge:he]?.[r===`points`?`diameter`:`width`];return _e(s)?{kind:r,size:s,units:`pixels`,bentley:!0}:void 0}var he,ge,_e,ve,ye=t((()=>{he=`BENTLEY_materials_line_style`,ge=`BENTLEY_materials_point_style`,_e=e=>typeof e==`number`&&Number.isFinite(e)&&e>0,ve=e=>!!e.meshes?.some(t=>t?.primitives?.some(t=>me(e,t)!==void 0))})),I,be,xe=t((()=>{I=(e,t)=>Object.assign(Error(e,t===void 0?void 0:{cause:t}),{name:`MargoError`,code:`failed`}),be=e=>Object.assign(Error(e),{name:`MargoError`,code:`unsupported`})}));function Se(e){if(Ee[e])return[1,1,Ee[e]];if(/^bc[1-7]h?-/.test(e))return[4,4,/^bc[14]-/.test(e)?8:16,`texture-compression-bc`];if(/^(etc2|eac)-/.test(e))return[4,4,/^(etc2-rgb8|eac-r11)/.test(e)?8:16,`texture-compression-etc2`];let t=/^astc-(\d+)x(\d+)-/.exec(e);if(t)return[+t[1],+t[2],16,`texture-compression-astc`]}function Ce(e,t,n){let r=Math.ceil(t/e[0])*e[2];return[r*Math.ceil(n/e[1]),r]}function we(e,t,n){return e[0].map((r,i)=>{let a=e[0][i].length,o=new Uint8Array(a*e.length);return e.forEach((e,t)=>o.set(e[i],t*a)),{data:o,width:Math.max(1,t>>i),height:Math.max(1,n>>i),byteLength:o.byteLength}})}function Te(e,t,n={}){let r=Se(t.format);if(!r)throw TypeError(`Texture format ${String(t.format)} is unknown; pass a parseDDS or parseKTX result`);let[i,a,,o]=r;if(o&&!e.features.has(o))throw be(`Texture format ${t.format} needs the device feature ${o}; request it with adapter.requestDevice({requiredFeatures: ['${o}']}) where adapter.features has it, or convert the file to an uncompressed format`);if(t.width%i||t.height%a)throw RangeError(`Texture ${t.width}x${t.height} is not a whole number of ${i}x${a} ${t.format} blocks; resize the source to a multiple of ${i}x${a}`);if(Math.max(t.width,t.height)>e.limits.maxTextureDimension2D)throw RangeError(`Texture ${t.width}x${t.height} exceeds the device's maxTextureDimension2D; use a smaller file`);if(t.layers>e.limits.maxTextureArrayLayers)throw RangeError(`Texture of ${t.layers} layers exceeds the device's maxTextureArrayLayers; request a higher limit or use fewer layers`);let s=e.createTexture({label:n.label,size:[t.width,t.height,t.layers],mipLevelCount:t.mipmaps.length,format:t.format,usage:n.usage??GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST});try{for(let[n,o]of t.mipmaps.entries()){let c=Math.ceil(o.height/a);e.queue.writeTexture({texture:s,mipLevel:n},o.data,{bytesPerRow:Ce(r,o.width,o.height)[1],rowsPerImage:c},[Math.ceil(o.width/i)*i,c*a,t.layers])}}catch(e){throw s.destroy(),e}return s}var Ee,De=t((()=>{xe(),Ee={r8unorm:1,r8snorm:1,rg8unorm:2,rg8snorm:2,rgba8unorm:4,"rgba8unorm-srgb":4,rgba8snorm:4,bgra8unorm:4,"bgra8unorm-srgb":4,r16float:2,rg16float:4,rgba16float:8,r32float:4,rg32float:8,rgba32float:16,rgb10a2unorm:4,rg11b10ufloat:4,rgb9e5ufloat:4}}));function Oe(e,t,n,r,i){let a=new Uint8Array(t*4),o=[0,1,2,3].map(e=>r[i&&e<3?0:e]>>>0);for(let r=0;r<t;r++){let t=0;for(let i=0;i<n;i++)t+=e[r*n+i]*2**(8*i);for(let e=0;e<4;e++){let n=o[e];a[r*4+e]=n?Math.round(((t&n)>>>0)/n*255):e===3?255:0}}return a}function ke(e){if(!(e instanceof Uint8Array))throw TypeError(`parseDDS needs the DDS file as a Uint8Array`);let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=e=>t.getUint32(e,!0);if(e.length<128||n(0)!==542327876||n(4)!==124||n(76)!==32)throw L(`header is missing`);let r=n(12),i=n(16),a=n(80),o=n(112),s=String.fromCharCode(e[84],e[85],e[86],e[87]),c=Math.max(1,n(28));if(!i||!r||i>65536||r>65536)throw L(`size ${i}x${r} is invalid`);if(c>32-Math.clz32(Math.max(i,r)))throw L(`has ${c} mip levels, too many for its size`);if(o&2097152||n(8)&8388608&&n(24)>1)throw R(`volume texture`);let l,u,d=0,f=!1,p=!0,m=!!(o&512),h=1,g=128;if(m&&(o&64512)!=64512)throw R(`cube map without all six faces`);if(a&4&&s===`DX10`){if(e.length<148)throw L(`DX10 header is missing`);let t=n(128),r=Me[t];if(n(132)!==3&&n(132)!==0)throw R(`resource dimension ${n(132)} (only 2D textures)`);if(m=!!(n(136)&4),h=n(140)||1,p=(n(144)&7)!=3,g=148,r?([d]=r,d/=8,u=r.slice(1,5),l=r[5]?`rgba8unorm-srgb`:`rgba8unorm`,p&&=!!r[4]):l=je[t],!l)throw R(`DXGI format ${t}`)}else if(a&4){let e=/^[\x20-\x7e]{4}$/.test(s)?s:String(n(84));if(l=Ae[e],!l)throw R(`FourCC ${e}`)}else if(a&131138){let e=n(88),t=a&3?n(104):0;if(f=!!(a&131072),u=a&131136?[n(92),n(96),n(100),t]:[0,0,0,t],![8,16,24,32].includes(e)||u.every(e=>!e))throw L(`pixel format of ${e} bits is invalid`);d=e/8,p=!!t,l=`rgba8unorm`,e===32&&!f&&u.join()===[255,65280,16711680,t?4278190080:0].join()&&t&&(u=void 0)}else throw R(`pixel format (YUV or unknown)`);let _=Se(l),v=h*(m?6:1),y=[];(/^bc[456]/.test(l)||/^(r|rg)\d/.test(l))&&(p=!1);for(let t=0;t<v;t++){let n=[];for(let a=0;a<c;a++){let o=Math.max(1,i>>a),s=Math.max(1,r>>a),c=u?o*s*d:Ce(_,o,s)[0];if(g+c>e.length)throw L(`ends inside layer ${t} mip ${a}`);let l=e.subarray(g,g+=c);n.push(u?Oe(l,o*s,d,u,f):l)}y.push(n)}return{width:i,height:r,layers:v,dimension:m?h>1?`cube-array`:`cube`:v>1?`2d-array`:`2d`,mipmaps:we(y,i,r),format:l,..._[3]?{feature:_[3]}:{},target:`dds`,srgb:l.endsWith(`-srgb`),hasAlpha:p}}var Ae,je,Me,L,R,Ne=t((()=>{xe(),De(),Ae={DXT1:`bc1-rgba-unorm`,DXT2:`bc2-rgba-unorm`,DXT3:`bc2-rgba-unorm`,DXT4:`bc3-rgba-unorm`,DXT5:`bc3-rgba-unorm`,ATI1:`bc4-r-unorm`,BC4U:`bc4-r-unorm`,BC4S:`bc4-r-snorm`,ATI2:`bc5-rg-unorm`,BC5U:`bc5-rg-unorm`,BC5S:`bc5-rg-snorm`,111:`r16float`,112:`rg16float`,113:`rgba16float`,114:`r32float`,115:`rg32float`,116:`rgba32float`},je={2:`rgba32float`,10:`rgba16float`,16:`rg32float`,24:`rgb10a2unorm`,26:`rg11b10ufloat`,28:`rgba8unorm`,29:`rgba8unorm-srgb`,31:`rgba8snorm`,34:`rg16float`,41:`r32float`,49:`rg8unorm`,51:`rg8snorm`,54:`r16float`,61:`r8unorm`,63:`r8snorm`,67:`rgb9e5ufloat`,71:`bc1-rgba-unorm`,72:`bc1-rgba-unorm-srgb`,74:`bc2-rgba-unorm`,75:`bc2-rgba-unorm-srgb`,77:`bc3-rgba-unorm`,78:`bc3-rgba-unorm-srgb`,80:`bc4-r-unorm`,81:`bc4-r-snorm`,83:`bc5-rg-unorm`,84:`bc5-rg-snorm`,95:`bc6h-rgb-ufloat`,96:`bc6h-rgb-float`,98:`bc7-rgba-unorm`,99:`bc7-rgba-unorm-srgb`},Me={85:[16,63488,2016,31,0],86:[16,31744,992,31,32768],87:[32,16711680,65280,255,4278190080],88:[32,16711680,65280,255,0],91:[32,16711680,65280,255,4278190080,!0],93:[32,16711680,65280,255,0,!0],115:[16,3840,240,15,61440]},L=e=>I(`DDS ${e}; pass the complete bytes of a valid DDS file`),R=e=>I(`DDS ${e} is not supported; convert the file to a 2D, cube or array texture in a WebGPU format`)})),Pe,Fe,Ie,Le,Re,ze=t((()=>{Pe=`0011001100110011000100010001000101110111011101110001001100110111000000010001001100110111011111110001001101111111000000010011011100000000000100110011011111111111000000010111111100000000000101110001011111111111000000001111111100001111111111110000000000001111000010001110111101110001000000000000000010001110011100110001000000110001000000000000100011001110000000001000110001110011001100010011000100010000000010001000110001100110011001100011011001101100000101111110100000001111111100000111000110001110001110011001110001010101010101010000111100001111010110100101101000110011110011000011110000111100010101011010101001101001011010010101101010100101011100111100111000010011110010000011001001001100001110111101110001101001100101100011110011000011011001101001100100000110011000000100111001000000001001110010000000000010011100100000010011100100011011001001001100110110110010010110001110011100001110011100011001101100110010010110001100111001011111101000000100011000111001110000111100110011001100111111000000100010111011100100010001110111`,Fe=`0011001102212222000100112211222100002001221122110222002200110111000000001122112200110011002200220022002211111111001100112211221100000000111122220000111111112222000011112222222200120012001200120112011201120112012201220122012200110112112212220011200122002220000100110112112201110011200122000000112211221122002200220022111101110111022202220001000122212221000000110122012200001100221022100122012200110000001200121122222201101221122101100000011012211221002211021102002201100110200222220011012201220011000020002211222100000002112212220222002200120011001100120022022201200120012001200000111122220000012012012012012001202012120101200011220011220011001111222200001101010101222222220000000021212121002211220022112200220011002200110220122102201221010122222222010100002121212121210101010101012222022201110222011100021112000211120000211221122112022201110111022200021112111200020110011001102222000000002112211201100110222222220022001100110022002211221122002200000000000021120002000100020001022212220222122201012222222222220111201122012220`,Ie=[15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,2,8,2,2,8,8,15,2,8,2,2,8,8,2,2,15,15,6,8,2,8,15,15,2,8,2,2,2,15,15,6,6,2,6,8,15,15,2,2,15,15,15,15,15,2,2,15],Le=[3,3,15,15,8,3,15,15,8,8,6,6,6,5,3,3,3,3,8,15,3,3,6,10,5,8,8,6,8,5,15,15,8,15,3,5,6,10,8,15,15,3,15,5,15,15,15,15,3,15,5,5,5,8,5,10,5,10,8,13,15,12,3,3],Re=[15,8,8,3,15,15,3,8,15,15,15,15,15,15,15,8,15,8,15,3,15,8,15,8,3,15,6,10,15,15,10,8,15,3,15,10,10,8,9,10,6,15,8,15,3,6,6,8,15,3,15,15,15,15,15,15,15,15,15,15,3,15,15,8]}));function Be(e,t,n,r){let i=e[t]|e[t+1]<<8,a=e[t+2]|e[t+3]<<8,o=[Je(i>>11),Ye(i>>5&63),Je(i&31),255,Je(a>>11),Ye(a>>5&63),Je(a&31),255],s=!r||i>a;for(let e=0;e<3;e++){let t=o[e],n=o[4+e];s?(o[8+e]=Math.round((2*t+n)/3),o[12+e]=Math.round((t+2*n)/3)):(o[8+e]=t+n+1>>1,o[12+e]=0)}o[11]=255,o[15]=s?255:0;for(let r=0;r<16;r++){let i=(e[t+4+(r>>2)]>>(r&3)*2&3)*4;n[r*4]=o[i],n[r*4+1]=o[i+1],n[r*4+2]=o[i+2],n[r*4+3]=o[i+3]}}function Ve(e,t,n,r,i){let a=e=>i?Math.max(e<<24>>24,-127):e,o=a(e[t]),s=a(e[t+1]),c=[o,s,0,0,0,0,0,0],l=i?127:255,u=i?-127:0;if(o>s)for(let e=1;e<7;e++)c[e+1]=((7-e)*o+e*s)/7;else{for(let e=1;e<5;e++)c[e+1]=((5-e)*o+e*s)/5;c[6]=u,c[7]=l}for(let a=0;a<16;a++){let o=a*3,s=t+2+(o>>3),u=c[(e[s]|e[s+1]<<8)>>(o&7)&7];n[a*4+r]=n instanceof Float32Array?u/l:i?qe(u):Math.round(u)}}function He(e,t,n,r){let i=0;for(let a=0;a<r;a++,n++)i|=(e[t+(n>>3)]>>(n&7)&1)<<a;return i}function Ue(e){let t=st.get(e);return t||(t=at[e].split(` `).map(e=>{let[,t,n,r,i]=/^([RGB])(\d)(\d+)(?:\.\.(\d+))?$/.exec(e),a=Number(i??r),o=Number(r),s=[];for(let e=a;s.push(e),e!==o;e+=o>=a?1:-1);return[Number(n),`RGB`.indexOf(t),s]}),st.set(e,t)),t}function We(e,t,n){if(!n)return t>=15?e:e===0?0:e===(1<<t)-1?65535:(e<<15)+16384>>t-1;if(t>=16)return e;let r=e<0,i=r?-e:e,a;return a=i===0?0:i>=(1<<t-1)-1?32767:(i<<15)+16384>>t-1,r?-a:a}function Ge(e,t,n,r){let i=e.replace(/-unorm(-srgb)?$/,t=>/^bc[45]/.test(e)?t:``),a=ft[i];if(!a)throw TypeError(`${e} is not a BC format; pass one of bc1-rgba-unorm to bc7-rgba-unorm-srgb`);let[o,s]=a,c=n+3>>2,l=r+3>>2;if(t.length<c*l*s)throw I(`${e}: ${t.length} bytes hold too few blocks for ${n}x${r}; pass the whole level`);let u=new Uint8Array(n*r*4),d=new Uint8Array(64);for(let e=0;e<l;e++)for(let i=0;i<c;i++){o(t,(e*c+i)*s,d);for(let t=0;t<4&&e*4+t<r;t++){let r=Math.min(4,n-i*4);u.set(d.subarray(t*16,t*16+r*4),((e*4+t)*n+i*4)*4)}}return{width:n,height:r,data:u}}function Ke(e,t,n,r){if(!/^bc[456]/.test(e)){let i=Ge(e,t,n,r);return{width:n,height:r,data:Float32Array.from(i.data,e=>e/255)}}let i=ft[e];if(!i)throw TypeError(`Unknown BC float format `+e+`; pass a BC4, BC5 or BC6H WebGPU format`);let[a,o]=i,s=Math.ceil(n/4),c=Math.ceil(r/4);if(t.length<s*c*o)throw I(`BC float image has too few blocks; pass the complete mip level`);let l=new Float32Array(n*r*4),u=new Float32Array(64);for(let e=0;e<c;e++)for(let i=0;i<s;i++){a(t,(e*s+i)*o,u);for(let t=0;t<4&&e*4+t<r;t++){let r=Math.min(4,n-i*4);l.set(u.subarray(t*16,t*16+r*4),((e*4+t)*n+i*4)*4)}}return{width:n,height:r,data:l}}var qe,Je,Ye,Xe,Ze,Qe,$e,et,tt,nt,rt,it,at,ot,st,ct,lt,ut,dt,ft,pt=t((()=>{ze(),xe(),qe=e=>Math.round((Math.max(e,-127)+127)/254*255),Je=e=>e<<3|e>>2,Ye=e=>e<<2|e>>4,Xe=(e,t,n)=>Be(e,t,n,!0),Ze=(e,t,n)=>{Be(e,t+8,n,!1);for(let r=0;r<16;r++)n[r*4+3]=(e[t+(r>>1)]>>(r&1)*4&15)*17},Qe=(e,t,n)=>{Be(e,t+8,n,!1),Ve(e,t,n,3,!1)},$e=e=>(t,n,r)=>{Ve(t,n,r,0,e);for(let t=0;t<16;t++)r[t*4+1]=r[t*4+2]=r instanceof Float32Array?0:e?128:0,r[t*4+3]=r instanceof Float32Array?1:255},et=e=>(t,n,r)=>{Ve(t,n,r,0,e),Ve(t,n+8,r,1,e);for(let t=0;t<16;t++)r[t*4+2]=r instanceof Float32Array?0:e?128:0,r[t*4+3]=r instanceof Float32Array?1:255},tt={2:[0,21,43,64],3:[0,9,18,27,37,46,55,64],4:[0,4,9,13,17,21,26,30,34,38,43,47,51,55,60,64]},nt=[[3,4,0,0,4,0,1,0,3,0],[2,6,0,0,6,0,0,1,3,0],[3,6,0,0,5,0,0,0,2,0],[2,6,0,0,7,0,1,0,2,0],[1,0,2,1,5,6,0,0,2,3],[1,0,2,0,7,8,0,0,2,2],[1,0,0,0,7,7,1,0,4,0],[2,6,0,0,5,5,1,0,2,0]],rt=(e,t)=>{let n=e<<8-t;return n|n>>t},it=(e,t,n)=>{let r=0;for(;r<8&&!(e[t]>>r&1);)r++;if(r===8){n.fill(0);return}let[i,a,o,s,c,l,u,d,f,p]=nt[r],m=r+1,h=n=>{let r=He(e,t,m,n);return m+=n,r},g=h(a),_=h(o),v=h(s),y=i*2,b=new Uint8Array(y*4);for(let e=0;e<3;e++)for(let t=0;t<y;t++)b[t*4+e]=h(c);if(l)for(let e=0;e<y;e++)b[e*4+3]=h(l);let x=new Uint8Array(y);if(u)for(let e=0;e<y;e++)x[e]=h(1);if(d)for(let e=0;e<i;e++)x[e*2]=x[e*2+1]=h(1);let S=u||d?1:0;for(let e=0;e<y;e++)for(let t=0;t<4;t++){if(t===3&&!l){b[e*4+3]=255;continue}let n=(t===3?l:c)+S;b[e*4+t]=rt(S?b[e*4+t]<<1|x[e]:b[e*4+t],n)}let C=e=>i===1?0:(i===2?Pe:Fe).charCodeAt(g*16+e)-48,w=e=>e===0||i===2&&e===Ie[g]||i===3&&(e===Le[g]||e===Re[g]),T=new Uint8Array(16),E=new Uint8Array(16);for(let e=0;e<16;e++)T[e]=h(w(e)?f-1:f);if(p)for(let e=0;e<16;e++)E[e]=h(e===0?p-1:p);let D=v?E:T,O=v?T:p?E:T,k=tt[v?p:f],ee=tt[v?f:p||f];for(let e=0;e<16;e++){let t=C(e)*8,r=k[D[e]],i=ee[O[e]],a=(e,n)=>(64-n)*b[t+e]+n*b[t+4+e]+32>>6,o=a(0,r),s=a(1,r),c=a(2,r),l=a(3,i),u=e*4;n[u]=_===1?l:o,n[u+1]=_===2?l:s,n[u+2]=_===3?l:c,n[u+3]=_===1?o:_===2?s:_===3?c:l}},at={0:`G24 B24 B34 R09..0 G09..0 B09..0 R14..0 G34 G23..0 G14..0 B30 G33..0 B14..0 B31 B23..0 R24..0 B32 R34..0 B33`,1:`G25 G34 G35 R06..0 B30 B31 B24 G06..0 B25 B32 G24 B06..0 B33 B35 B34 R15..0 G23..0 G15..0 G33..0 B15..0 B23..0 R25..0 R35..0`,2:`R09..0 G09..0 B09..0 R14..0 R010 G23..0 G13..0 G010 B30 G33..0 B13..0 B010 B31 B23..0 R24..0 B32 R34..0 B33`,6:`R09..0 G09..0 B09..0 R13..0 R010 G34 G23..0 G14..0 G010 G33..0 B13..0 B010 B31 B23..0 R23..0 B30 B32 R33..0 G24 B33`,10:`R09..0 G09..0 B09..0 R13..0 R010 B24 G23..0 G13..0 G010 B30 G33..0 B14..0 B010 B23..0 R23..0 B31 B32 R33..0 B34 B33`,14:`R08..0 B24 G08..0 G24 B08..0 B34 R14..0 G34 G23..0 G14..0 B30 G33..0 B14..0 B31 B23..0 R24..0 B32 R34..0 B33`,18:`R07..0 G34 B24 G07..0 B32 G24 B07..0 B33 B34 R15..0 G23..0 G14..0 B30 G33..0 B14..0 B31 B23..0 R25..0 R35..0`,22:`R07..0 B30 B24 G07..0 G25 G24 B07..0 G35 B34 R14..0 G34 G23..0 G15..0 G33..0 B14..0 B31 B23..0 R24..0 B32 R34..0 B33`,26:`R07..0 B31 B24 G07..0 B25 G24 B07..0 B35 B34 R14..0 G34 G23..0 G14..0 B30 G33..0 B15..0 B23..0 R24..0 B32 R34..0 B33`,30:`R05..0 G34 B30 B31 B24 G05..0 G25 B25 B32 G24 B05..0 G35 B33 B35 B34 R15..0 G23..0 G15..0 G33..0 B15..0 B23..0 R25..0 R35..0`,3:`R09..0 G09..0 B09..0 R19..0 G19..0 B19..0`,7:`R09..0 G09..0 B09..0 R18..0 R010 G18..0 G010 B18..0 B010`,11:`R09..0 G09..0 B09..0 R17..0 R010..11 G17..0 G010..11 B17..0 B010..11`,15:`R09..0 G09..0 B09..0 R13..0 R010..15 G13..0 G010..15 B13..0 B010..15`},ot={0:[!0,10,5,5,5],1:[!0,7,6,6,6],2:[!0,11,5,4,4],6:[!0,11,4,5,4],10:[!0,11,4,4,5],14:[!0,9,5,5,5],18:[!0,8,6,5,5],22:[!0,8,5,6,5],26:[!0,8,5,5,6],30:[!1,6,6,6,6],3:[!1,10,10,10,10],7:[!0,11,9,9,9],11:[!0,12,8,8,8],15:[!0,16,4,4,4]},st=new Map,ct=(e,t)=>t>=32?e:e<<32-t>>32-t,lt=e=>{let t=e>>10&31,n=e&1023,r=t===0?n/16777216:t===31?n?NaN:1/0:(1+n/1024)*2**(t-15);return e&32768?-r:r},ut=e=>{let t=e<=0?0:e>=1?1:e;return Math.round((t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055)*255)},dt=e=>(t,n,r)=>{let i=He(t,n,0,2),a=i<2?i:He(t,n,0,5),o=ot[a];if(!o){for(let e=0;e<16;e++)r.set([0,0,0,r instanceof Float32Array?1:255],e*4);return}let[s,c,...l]=o,u=a<3||(a&3)==2,d=new Int32Array(12),f=i<2?2:5;for(let[e,r,i]of Ue(a))for(let a of i)t[n+(f>>3)]>>(f&7)&1&&(d[e*3+r]|=1<<a),f++;let p=u?He(t,n,f,5):0;f+=u?5:0;let m=u?4:2;for(let t=0;t<3;t++){e&&(d[t]=ct(d[t],c));for(let n=1;n<m;n++){let r=n*3+t;s&&(d[r]=ct(d[r],l[t])+d[t]&(1<<c)-1),e&&(d[r]=ct(d[r],c))}for(let n=0;n<m;n++)d[n*3+t]=We(d[n*3+t],c,e)}let h=u?3:4,g=tt[h];for(let i=0;i<16;i++){let a=u?Pe.charCodeAt(p*16+i)-48:0,o=i===0||u&&i===Ie[p]?h-1:h,s=g[He(t,n,f,o)];f+=o;for(let t=0;t<3;t++){let n=d[a*6+t],o=d[a*6+3+t],c=(64-s)*n+s*o+32>>6,l=e?c<0?-c*31>>5|32768:c*31>>5:c*31>>6;r[i*4+t]=r instanceof Float32Array?lt(l):ut(lt(l))}r[i*4+3]=r instanceof Float32Array?1:255}},ft={"bc1-rgba":[Xe,8],"bc2-rgba":[Ze,16],"bc3-rgba":[Qe,16],"bc4-r-unorm":[$e(!1),8],"bc4-r-snorm":[$e(!0),8],"bc5-rg-unorm":[et(!1),16],"bc5-rg-snorm":[et(!0),16],"bc6h-rgb-ufloat":[dt(!1),16],"bc6h-rgb-float":[dt(!0),16],"bc7-rgba":[it,16]}})),mt=n({ddsTextures:()=>_t,decodeDDSImage:()=>gt});function ht(e){let t=e<0?32768:0,n=Math.abs(e);if(!n)return t;let r=Math.max(-14,Math.floor(Math.log2(n))),i=n*2**(10-r),a=Math.floor(i),o=a+(i-a>.5||i-a===.5&&a%2?1:0);return t|(r===-14&&o<1024?o:(r+14<<10)+o)}function gt(e,t={}){t.signal?.throwIfAborted();let n=ke(e);if(n.dimension!==`2d`||n.layers!==1)throw a(`unsupported`,`glTF material DDS images must be single-layer 2D textures; export a 2D image`);if(n.width*n.height>67108864)throw RangeError(`glTF DDS image exceeds decoded size limit; export a smaller texture`);let r,i=e=>{if(!n.feature||e.features.has(n.feature)&&n.width%4==0&&n.height%4==0)return n;if(!r){let e=/^bc[456]/.test(n.format),t=n.mipmaps.map(t=>{let r=e?Ke(n.format,t.data,t.width,t.height):Ge(n.format,t.data,t.width,t.height),i=e?Uint16Array.from(r.data,ht):r.data,a=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);return{...t,data:a,byteLength:a.length}});r={...n,format:e?`rgba16float`:`rgba8unorm`,feature:void 0,mipmaps:t}}return r},o=(e,t)=>{let n=i(e).format.replace(/-srgb$/,``);return n+(t&&/^(rgba8unorm|bc[1237]-)/.test(n)?`-srgb`:``)};return{width:n.width,height:n.height,format:n.format,mipmaps:n.mipmaps,gpuFormat:o,upload(e,t){let n=i(e),r=o(e,t);if(/^(r|rg|rgba)32float$/.test(r)&&!e.features.has(`float32-filterable`))throw a(`unsupported`,`32-bit float DDS material textures require float32-filterable; request that device feature or export 16-bit float DDS`);return Te(e,{...n,format:r})}}}var _t,vt=t((()=>{Ne(),pt(),l(),u(),_t={decode:gt}}));function yt(e){let t;if(typeof e?.sceneOf==`function`){for(let n of e.plugins?.values()??[])if(t=e.sceneOf(n))break;if(!t){let n={name:St(e,`scene-scope:`),setup(){t=e.sceneOf(n)}};e.use(n),e.removePlugin(n.name)}}return bt(e,t)}function bt(e,t){return{scene:t,run(n){if(!t)return n();let r,i={name:St(e,`scene-scope:`),setup(){r=n()}};return t.use(i),t.removePlugin(i.name),r}}}var xt,St,Ct=t((()=>{xt=0,St=(e,t)=>{let n=t+xt++;for(;e.plugins?.has(n);)n+=`:`;return n}})),wt=n({}),Tt=t((()=>{})),Et=n({gaussianSplats:()=>Vt,readGaussianSplats:()=>Ot});function Dt(e,t,n,r,i,a){let o=t[n];if(o===void 0)throw V(`primitive: ${n} is missing`);let s=e.doc.accessors?.[o];if(!i.some(([e,t])=>e===s?.componentType&&t===!!s?.normalized))throw V(`accessor for ${n}: componentType ${s?.componentType}${s?.normalized?` normalized`:``}`);let c=e.accessor(o,r);if(s?.count!==a)throw V(`accessor for ${n}: its count differs from POSITION`);return c}async function Ot(e,t,{signal:n}={}){let r=t.extensions?.[z],i=t.attributes??{};if(!r||typeof r!=`object`||Array.isArray(r))throw V(`extension`);if(t.mode!==0)throw V(`primitive: its mode must be POINTS`);let{kernel:o=`ellipse`,colorSpace:s=`srgb_rec709_display`}=r;if(o!==`ellipse`)throw a(`unsupported`,`${z} kernel ${o} is not supported; re-export the file with "ellipse"`);if(s!==`srgb_rec709_display`&&s!==`lin_rec709_display`)throw a(`unsupported`,`${z} color space ${s} is not supported; re-export the file in rec709`);let{parseSpz:c,splatsFromAttributes:l}=await zt(Promise.resolve().then(()=>(Tt(),wt)));n?.throwIfAborted();let u=r.extensions?.[jt];if(u){if(s!==`srgb_rec709_display`)throw V(`primitive: SPZ colour is srgb_rec709_display`);return c(e.view(u.bufferView),{signal:n})}let d=e.accessor(i.POSITION,`VEC3`),f=d.length/3,p=(t,n,r)=>Dt(e,i,`${z}:${t}`,n,r,f),m=p(`ROTATION`,`VEC4`,Ft),h=p(`SCALE`,`VEC3`,It),g=p(`OPACITY`,`SCALAR`,Lt),_=p(`SH_DEGREE_0_COEF_0`,`VEC3`,Rt),v=[],y=!1;Mt.forEach((e,t)=>{let n=Array.from({length:e},(e,n)=>`SH_DEGREE_${t+1}_COEF_${n}`),r=n.filter(e=>`${z}:${e}`in i).length;if(r&&(r!==e||y))throw V(`primitive: spherical harmonics degree ${t+1}`);if(r)for(let e of n)v.push(p(e,`VEC3`,Rt));else y=!0});let b={count:f,positions:d,logScales:h.map(Math.log),rotations:new Float32Array(f*4),dc:_,alphas:g};for(let e=0;e<f;e++)b.rotations[e*4]=m[e*4+3],b.rotations.set(m.subarray(e*4,e*4+3),e*4+1);if(v.length){let e=new Float32Array(f*v.length*3);v.forEach((t,n)=>{for(let r=0;r<f;r++)e.set(t.subarray(r*3,r*3+3),(r*v.length+n)*3)}),b.rest=e}return l(b,{linear:s===`lin_rec709_display`})}function kt(e,t){let n=Bt(e);if(n===t)return e;let r=e.positions.length/3,i=new Float32Array(r*t*3);for(let a=0;a<r;a++)if(n)i.set(e.sphericalHarmonics.subarray(a*n*3,(a+1)*n*3),a*t*3);else for(let n=0;n<3;n++)i[a*t*3+n]=(e.colors[a*4+n]-.5)/Pt;return{...e,sphericalHarmonics:i}}function At({positions:e}){let t=new Float32Array([1/0,1/0,1/0,-1/0,-1/0,-1/0]);for(let n=0;n<e.length;n+=3)for(let r=0;r<3;r++)t[r]=Math.min(t[r],e[n+r]),t[r+3]=Math.max(t[r+3],e[n+r]);return t}var z,jt,B,Mt,Nt,Pt,Ft,It,Lt,Rt,V,zt,Bt,Vt,Ht=t((()=>{l(),Ct(),z=`KHR_gaussian_splatting`,jt=`KHR_gaussian_splatting_compression_spz_2`,B=5126,Mt=[3,5,7],Nt=3e6,Pt=.2820947917738781,Ft=[[B,!1],[5120,!0],[5122,!0]],It=[[B,!1],[5121,!1],[5121,!0],[5123,!1],[5123,!0]],Lt=[[B,!1],[5121,!0],[5123,!0]],Rt=[[B,!1]],V=e=>TypeError(`Invalid glTF ${z} ${e}; the file is not valid, re-export it and check it with the glTF Validator`),zt=e=>e.catch(e=>{throw a(`unsupported`,`${z} needs @margoengine/splats (${e instanceof Error?e.message:e}): install it, or pass decoders: {splats: false} for the point cloud fallback`)}),Bt=e=>e.sphericalHarmonics?e.sphericalHarmonics.length/(e.positions.length/3)/3:0,Vt={async attach(e,t,n,r){let i=yt(e),{Splats:a,mergeSplats:o,transformSplats:s}=await zt(Promise.resolve().then(()=>(Tt(),wt))),c=[];for(let{primitive:e,matrix:i}of n)c.push(s(await Ot(t,e,{signal:r}),i));let l=Math.max(...c.map(Bt)),u=[],d=Nt;for(let e of c){let t=e.positions.length/3;d+t>Nt&&(u.push([]),d=0),u[u.length-1].push(l?kt(e,l):e),d+=t}let f=[];try{for(let t of u){r?.throwIfAborted();let n=t.length>1?o(...t):t[0],s=new a(n);i.run(()=>e.use(s)),f.push({cloud:s,bounds:At(n)})}}catch(e){for(let{cloud:e}of f)e.dispose();throw e}return f}}}));function Ut(e){let t=[`base`,`mr`,`normal`,`ao`,`emissive`];for(let n=0;n<t.length;n++){let r=t[n];e=e.replace(`@group(1) @binding(${n*2}) var ${r}Map:texture_2d<f32>;`,``).replace(`@group(1) @binding(${n*2+1}) var ${r}Sampler:sampler;`,``).replaceAll(`textureSample(${r}Map,${r}Sampler,`,`margoBaseSample(${n},`)}return Wt+e}var Wt,Gt=t((()=>{Wt=`
|
|
2
2
|
struct MargoBaseInfo {rows:array<vec4f,10>}
|
|
3
3
|
@group(1) @binding(0) var margoBaseMaps:texture_2d_array<f32>;
|
|
4
4
|
@group(1) @binding(1) var<uniform> margoBaseInfo:MargoBaseInfo;
|
|
@@ -35,7 +35,7 @@ fn margoBaseSample(slot:i32,at:vec2f)->vec4f {
|
|
|
35
35
|
let lo=i32(floor(l));let hi=min(lo+1,i32(a.z)-1);
|
|
36
36
|
return mix(margoBaseLevel(slot,at,lo,linear),margoBaseLevel(slot,at,hi,linear),fract(l));
|
|
37
37
|
}
|
|
38
|
-
`})),
|
|
38
|
+
`})),Kt,qt=t((()=>{Kt=`fn margoFilmSpectrum(opd:f32,shift:vec3f)->vec3f {
|
|
39
39
|
let k=6.28318531e-9*opd;
|
|
40
40
|
var xyz=vec3f(0.84659,1.0002219,1.0011225)*cos(vec3f(1.6810e6,1.7953e6,2.2084e6)*k+shift)*exp(-k*k*vec3f(4.3278e9,9.3046e9,6.6121e9));
|
|
41
41
|
xyz.x+=0.15386831*cos(2.2399e6*k+shift.x)*exp(-4.5282e9*k*k);
|
|
@@ -51,8 +51,8 @@ fn margoIridescence(f0:vec3f,c1:f32,thickness:f32,film:f32)->vec3f {
|
|
|
51
51
|
let order=2*(inner-t);
|
|
52
52
|
return max(r12+inner+order*sqrt(r123)*margoFilmSpectrum(opd,phase)+order*r123*margoFilmSpectrum(2*opd,2*phase),vec3f(0));
|
|
53
53
|
}
|
|
54
|
-
`})),
|
|
55
|
-
`,`${
|
|
54
|
+
`})),Jt,Yt=t((()=>{Jt=`var<private> margoDirectVisible:vec3f=vec3f(1);`})),Xt,Zt=t((()=>{Xt=`fn pbrNeutral(input:vec3f)->vec3f {let x=min(input.r,min(input.g,input.b));let offset=select(0.04,x-6.25*x*x,x<0.08);var v=input-offset;let peak=max(v.r,max(v.g,v.b));if(peak<0.76){return v;}let newPeak=1.0-0.24*0.24/(peak+0.24-0.76);v*=newPeak/peak;return mix(v,vec3f(newPeak),1.0-1.0/(0.15*(peak-newPeak)+1.0));}
|
|
55
|
+
`,`${Xt}`})),Qt,$t=t((()=>{Qt=[[`s.base.rgb*(1-s.metal)+`,`s.base.rgb*(1-s.metal)*(1-s.tr)+`],[`(1-s.metal)*s.base.rgb/`,`(1-s.metal)*(1-s.tr)*s.base.rgb/`]]})),en,tn=t((()=>{en=`fn margoCotangentFrame(n:vec3f,dp1:vec3f,dp2:vec3f,duv1:vec2f,duv2:vec2f)->mat3x3f {
|
|
56
56
|
let ps=max(max(max(abs(dp1.x),abs(dp1.y)),max(abs(dp1.z),abs(dp2.x))),max(abs(dp2.y),abs(dp2.z)));
|
|
57
57
|
let us=max(max(abs(duv1.x),abs(duv1.y)),max(abs(duv2.x),abs(duv2.y)));
|
|
58
58
|
if(ps>0.0&&us>0.0){
|
|
@@ -65,7 +65,7 @@ fn margoIridescence(f0:vec3f,c1:f32,thickness:f32,film:f32)->vec3f {
|
|
|
65
65
|
let axis=select(vec3f(1,0,0),vec3f(0,0,1),abs(n.x)>0.5);let t=normalize(axis-n*dot(n,axis));
|
|
66
66
|
return mat3x3f(t,cross(n,t),n);
|
|
67
67
|
}
|
|
68
|
-
`})),
|
|
68
|
+
`})),nn,rn,an,on=t((()=>{nn=(e,t)=>`a2/(3.14159265*pow(max(dot(cross(${e},${t}),cross(${e},${t})),step(nh,0.0))+a2*nh*nh,2.0))`,rn=`a2/(3.14159265*pow(max(dot(cross(n,h),cross(n,h)),step(nh,0.0))+a2*nh*nh,2.0))`,an=`2*nl*nv/max(nl*sqrt(a2+(1-a2)*nv*nv)+nv*sqrt(a2+(1-a2)*nl*nl),1e-30)`})),sn,cn,ln,un,dn,fn=t((()=>{sn=e=>`fn ${e}L(x:f32,w:f32)->f32 {
|
|
69
69
|
let p=mix(vec4f(21.5473,3.82987,0.19823,-1.9776),vec4f(25.3245,3.32435,0.16801,-1.27393),w);
|
|
70
70
|
return p.x/(1.0+p.y*pow(max(x,1e-12),p.z))+p.w*x+mix(-4.32054,-4.85967,w);
|
|
71
71
|
}
|
|
@@ -76,35 +76,35 @@ fn ${e}(roughness:f32,nl:f32,nv:f32,nh:f32)->f32 {
|
|
|
76
76
|
let sheenW=(1.0-sheenAlpha)*(1.0-sheenAlpha);
|
|
77
77
|
return sheenD/max((1.0+${e}Lambda(nv,sheenW)+${e}Lambda(nl,sheenW))*4.0*nl*nv,0.000001);
|
|
78
78
|
}
|
|
79
|
-
`,
|
|
80
|
-
`,
|
|
79
|
+
`,cn=e=>`fn ${e}(nv:f32,nl:f32,v:vec3f,l:vec3f)->f32 {return clamp((nv+nl)/max(length(v+l),0.0001),0.0,1.0);}
|
|
80
|
+
`,ln={size:16,k:.1,p:.45},un=[-3.22,-3.22,-3.22,-3.22,-3.22,-3.22,-3.88,-4.89,-6.25,-8.85,-12.09,-21.05,-24,-24,-24,-24,-1.75,-1.75,-1.85,-2.07,-2.41,-2.9,-3.58,-4.31,-5.96,-8.09,-11.84,-18.65,-24,-24,-24,-24,-1.7,-1.68,-1.75,-1.95,-2.27,-2.71,-3.3,-4.1,-5.24,-6.67,-9.55,-14.09,-22.96,-24,-24,-24,-1.69,-1.63,-1.68,-1.86,-2.14,-2.52,-2.99,-3.64,-4.47,-5.72,-7.48,-10.23,-14.98,-24,-24,-24,-1.67,-1.59,-1.62,-1.78,-2.02,-2.33,-2.73,-3.23,-3.88,-4.74,-5.93,-7.64,-10.31,-14.93,-24,-24,-1.65,-1.55,-1.57,-1.7,-1.9,-2.16,-2.48,-2.88,-3.37,-4.01,-4.84,-5.97,-7.6,-10.17,-14.96,-24,-1.62,-1.49,-1.5,-1.62,-1.79,-2,-2.27,-2.59,-2.97,-3.45,-4.05,-4.84,-5.92,-7.52,-10.24,-19.62,-1.61,-1.43,-1.42,-1.52,-1.66,-1.85,-2.07,-2.33,-2.63,-3,-3.46,-4.04,-4.8,-5.87,-7.58,-12.5,-1.53,-1.33,-1.31,-1.4,-1.53,-1.68,-1.87,-2.08,-2.33,-2.63,-2.98,-3.42,-3.99,-4.75,-5.9,-8.73,-1.42,-1.21,-1.18,-1.26,-1.37,-1.5,-1.66,-1.84,-2.05,-2.29,-2.57,-2.92,-3.36,-3.91,-4.73,-6.47,-1.27,-1.05,-1.02,-1.08,-1.18,-1.3,-1.44,-1.59,-1.77,-1.97,-2.2,-2.49,-2.83,-3.26,-3.86,-4.98,-1.09,-.86,-.83,-.88,-.97,-1.08,-1.2,-1.34,-1.49,-1.66,-1.86,-2.1,-2.38,-2.71,-3.17,-3.93,-.87,-.65,-.61,-.66,-.75,-.85,-.96,-1.08,-1.22,-1.37,-1.54,-1.75,-1.98,-2.26,-2.62,-3.16,-.64,-.43,-.39,-.44,-.52,-.62,-.72,-.84,-.97,-1.1,-1.26,-1.44,-1.65,-1.88,-2.17,-2.58,-.43,-.22,-.18,-.24,-.32,-.41,-.51,-.62,-.74,-.87,-1.02,-1.18,-1.37,-1.57,-1.82,-2.13,-.28,-.09,-.05,-.1,-.18,-.27,-.37,-.48,-.59,-.71,-.85,-1,-1.16,-1.34,-1.55,-1.81],dn=(e,t=un)=>`const ${e}Table=array<f32,256>(${t.map(e=>Number.isInteger(e)?e+`.0`:e).join(`,`)});
|
|
81
81
|
fn ${e}(mu:f32,roughness:f32)->f32 {
|
|
82
82
|
let sheenR=clamp(roughness,0.0001,1.0);let sheenMu=clamp(mu,0.0001,1.0);
|
|
83
|
-
let sheenU=pow(sheenMu*(sheenR+${
|
|
83
|
+
let sheenU=pow(sheenMu*(sheenR+${ln.k})/(sheenR+${ln.k}*sheenMu),${ln.p})*15.0;let sheenV=sqrt(clamp(roughness,0.0,1.0))*15.0;
|
|
84
84
|
let sheenI=min(u32(sheenU),14u);let sheenJ=min(u32(sheenV),14u);let sheenS=sheenU-f32(sheenI);let sheenT=sheenV-f32(sheenJ);
|
|
85
85
|
let sheenN=sheenJ*16u+sheenI;
|
|
86
86
|
let sheenLog=mix(mix(${e}Table[sheenN],${e}Table[sheenN+1u],sheenS),mix(${e}Table[sheenN+16u],${e}Table[sheenN+17u],sheenS),sheenT);
|
|
87
87
|
return clamp(exp(sheenLog)/sheenR,0.0,1.0);
|
|
88
88
|
}
|
|
89
|
-
`})),
|
|
89
|
+
`})),pn,mn=t((()=>{pn=`fn margoDielectricFresnel(f0:vec3f,weight:f32,c:f32)->vec3f {return f0+(weight-f0)*pow(1.0-c,5.0);}
|
|
90
90
|
fn margoFresnelPeak(fresnel:vec3f)->f32 {return max(fresnel.r,max(fresnel.g,fresnel.b));}
|
|
91
|
-
`})),
|
|
91
|
+
`})),hn,gn=t((()=>{hn=`fn margoBumpGradient(n:vec3f,p:vec3f,dhdx:f32,dhdy:f32,facing:bool)->vec3f {
|
|
92
92
|
let sx=dpdx(p); let sy=dpdy(p); let r1=cross(sy,n); let r2=cross(n,sx);
|
|
93
93
|
let det=dot(sx,r1)*select(-1.0,1.0,facing); let o=abs(det)*n-sign(det)*(dhdx*r1+dhdy*r2);
|
|
94
94
|
return select(n,normalize(o),dot(o,o)>0.0);
|
|
95
95
|
}
|
|
96
|
-
`})),
|
|
96
|
+
`})),_n,vn,yn=t((()=>{_n=(e,t)=>t===1/0?0:Math.min(-Math.log(Math.max(e,1e-6))/t,1e30),vn=`fn margoScatterShares(extinction:vec3f,color:vec3f,anisotropy:f32,depth:f32)->mat2x3f {
|
|
97
97
|
let m=clamp(color,vec3f(0),vec3f(1)); let d=4.09712+4.20863*m-sqrt(9.59217+41.6808*m+17.7126*m*m);
|
|
98
98
|
let absorbed=extinction*d*d; let scattered=max(min((extinction-absorbed)*(1-anisotropy),extinction),vec3f(0));
|
|
99
99
|
return mat2x3f(1-exp(-scattered*depth),exp(-(absorbed+scattered)*depth));
|
|
100
100
|
}
|
|
101
|
-
`}));function
|
|
102
|
-
`);return n=
|
|
101
|
+
`}));function bn(e,t){for(let[n,r]of t){if(typeof n==`string`?!e.includes(n):!n.test(e))throw a(`failed`,`PBR shader patch target missing: `+n+`; the shader source changed, update the patch`);e=typeof n==`string`?e.replaceAll(n,r):e.replace(n,r)}return e}function xn(e,t,n=e.length){let r=t=>e[t]?.index,i=r(t);if(!e[t])return-1;if(typeof i!=`number`)return t;let a=-1,o=-1,s=-1;for(let t=5;t<n;t++)e[t]&&r(t)===i&&(On.includes(t)?a=a<0?t:a:(o=o<0?t:o,s<0&&!kn.includes(t)&&(s=t)));return On.includes(t)?a:kn.includes(t)?a>=0?a:o:a>=0?s:o}function Sn(e,t){let n=[];return{slots:Array.from({length:Math.max(21,e.length)},(t,r)=>{if(r<5||!e[r])return-1;let i=xn(e,r),a=n.indexOf(i);return a>=0?a:n.length===8?-1:n.push(i)-1}),...t}}function Cn(e){let t=e.slots.join()+ +e.iridescence+ +e.anisotropy+ +e.diffuseTransmission+ +!!e.bump+ +!!e.scatter+ +!!e.packedBase+ +!!e.diffuseRoughness,n=Rn.get(t);if(n!==void 0)return n;let r=[...En,...Dn],i=Math.max(-1,...e.slots)+1,a=(t,n)=>{let i=r.indexOf(t)+5,a=e.slots[i];return a>=0?`textureSample(margoMap${a},margoSampler${a},${n??`uv(i,${i})`})`:t===`clearcoatNormal`?`vec4f(0.5,0.5,1,1)`:t===`anisotropy`?`vec4f(1,0.5,1,1)`:`vec4f(1)`},o=Array.from({length:i},(e,t)=>`@group(1) @binding(${10+t*2}) var margoMap${t}:texture_2d<f32>;\n@group(1) @binding(${11+t*2}) var margoSampler${t}:sampler;`).join(`
|
|
102
|
+
`);return n=bn(Tn,[...jn(a,o),[`uvt:array<vec4f,26>`,`uvt:array<vec4f,${e.slots.length*2}>`],[`sheen:vec4f
|
|
103
103
|
}`,`sheen:vec4f, iri:vec4f, aniso:vec4f, dtr:vec4f, bump:vec4f, scatter:vec4f, extinction:vec4f
|
|
104
|
-
}`],[`sh:vec4f}`,`sh:vec4f, ir:vec4f, at:vec4f, dt:vec4f${e.scatter?`, sc:vec3f`:``}${e.diffuseRoughness?`, dr:vec2f`:``}}`],[` if(margoFaceTest&&!facing&&f.settings.z<0.5){discard;}`,`${e.bump?
|
|
104
|
+
}`],[`sh:vec4f}`,`sh:vec4f, ir:vec4f, at:vec4f, dt:vec4f${e.scatter?`, sc:vec3f`:``}${e.diffuseRoughness?`, dr:vec2f`:``}}`],[` if(margoFaceTest&&!facing&&f.settings.z<0.5){discard;}`,`${e.bump?In(a):``} s.ir=${e.iridescence?`vec4f(margoIridescence(mix(s.f0,s.base.rgb,s.metal),clamp(dot(s.n,normalize(f.eye.xyz-i.position)),0.0,1.0),mix(f.iri.z,f.iri.w,${a(`iridescenceThickness`)}.g),f.iri.y),f.iri.x*${a(`iridescence`)}.r)`:`vec4f(0)`};
|
|
105
105
|
s.at=${e.anisotropy?`margoAnisotropy(s.n,t,b,${a(`anisotropy`)}.xyz)`:`vec4f(0)`};
|
|
106
106
|
s.dt=${e.diffuseTransmission?`vec4f(f.dtr.yzw*${a(`diffuseTransmissionColor`)}.rgb,f.dtr.x*${a(`diffuseTransmission`)}.a)`:`vec4f(0)`};
|
|
107
|
-
${e.scatter?
|
|
107
|
+
${e.scatter?Ln(a):``}${e.diffuseRoughness?` s.dr=vec2f(f.aniso.w*${a(`diffuseRoughness`)}.r,clamp(dot(s.n,normalize(f.eye.xyz-i.position)),0.0001,1.0));\n`:``} if(margoFaceTest&&!facing&&f.settings.z<0.5){discard;}`],[/fn ambient\(s:Surface\)->vec3f \{[^}]*\}/,`fn ambient(s:Surface)->vec3f {return margoHemisphere(s);}`],[`return ((1-margoFresnelPeak(margoDielectricFresnel(s.f0,s.sw,vh)))*(1-s.metal)*(1-s.tr)*s.base.rgb/3.14159265+d*g*fresnel/max(4*nl*nv,0.0001))*nl*`,`return margoDirect(s,v,l)*`],[`@fragment fn fragment(`,(e.bump?hn:``)+(e.iridescence?Kt:``)+(e.anisotropy?Mn:``)+(e.scatter?vn:``)+(e.diffuseRoughness?Nn:``)+Pn(e.anisotropy,e.scatter,e.diffuseRoughness)+Fn(e)+`@fragment fn fragment(`]])+`fn margoThickness(i:Out)->f32 {return ${a(`thickness`)}.g;}fn margoVolumeThickness(i:Out)->f32 {return ${a(`thickness`)}.g;}fn margoTintFresnel(s:Surface,nv:f32)->vec3f {return ${e.iridescence?`mix(margoDielectricFresnel(s.f0,s.sw,nv),s.ir.rgb,s.ir.w)`:`margoDielectricFresnel(s.f0,s.sw,nv)`};}`+An,e.packedBase&&(n=Ut(n)),Rn.size>=64&&Rn.clear(),Rn.set(t,n),n}var wn,Tn,En,Dn,On,kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn=t((()=>{Gt(),qt(),l(),Yt(),Zt(),$t(),tn(),on(),fn(),mn(),gn(),yn(),wn=`fn hemisphere_ambient(s:Surface)->vec3f {
|
|
108
108
|
let f0=mix(vec3f(0.04),s.base.rgb,s.metal);
|
|
109
109
|
let hemisphere=mix(vec3f(0.35,0.3,0.25),vec3f(1),clamp(s.n.y*0.5+0.5,0.0,1.0));
|
|
110
110
|
return (s.base.rgb*(1-s.metal)+f0*0.5)*hemisphere*f.radiance.w*s.occlusion;
|
|
@@ -116,14 +116,14 @@ fn ambient(s:Surface)->vec3f {
|
|
|
116
116
|
fn direct_light(s:Surface,v:vec3f,l:vec3f)->vec3f {
|
|
117
117
|
let h=(v+l)/max(length(v+l),0.0001);
|
|
118
118
|
let nl=clamp(dot(s.n,l),0.0,1.0); let nv=clamp(dot(s.n,v),0.0001,1.0); let nh=clamp(dot(s.n,h),0.0,1.0); let vh=clamp(dot(v,h),0.0,1.0);
|
|
119
|
-
let a=s.roughness*s.roughness; let a2=a*a; let d=${
|
|
120
|
-
let g=${
|
|
119
|
+
let a=s.roughness*s.roughness; let a2=a*a; let d=${nn(`s.n`,`h`)};
|
|
120
|
+
let g=${an};
|
|
121
121
|
let dielectric=vec3f(0.04); let f0=mix(vec3f(0.04),s.base.rgb,s.metal); let fresnel=f0+(1-f0)*pow(1-vh,5.0);
|
|
122
122
|
return ((1-(dielectric+(1-dielectric)*pow(1-vh,5.0)))*(1-s.metal)*s.base.rgb/3.14159265+d*g*fresnel/max(4*nl*nv,0.0001))*nl*f.radiance.rgb*f.light.w;
|
|
123
123
|
}
|
|
124
|
-
`,`${
|
|
125
|
-
${
|
|
126
|
-
${
|
|
124
|
+
`,`${Xt}${en}${wn}`,Tn=`
|
|
125
|
+
${Xt}
|
|
126
|
+
${en}
|
|
127
127
|
struct Frame {
|
|
128
128
|
camera:mat4x4f, model:mat4x4f, normalMatrix:mat4x4f, view:mat4x4f,
|
|
129
129
|
eye:vec4f, light:vec4f, radiance:vec4f, base:vec4f, factors:vec4f, emissive:vec4f,
|
|
@@ -184,7 +184,7 @@ fn surface(i:Out,front:bool)->Surface {
|
|
|
184
184
|
if(margoAlphaTest&&f.settings.x>0.5&&f.settings.x<1.5&&s.base.a<f.settings.y){discard;}
|
|
185
185
|
return s;
|
|
186
186
|
}
|
|
187
|
-
${
|
|
187
|
+
${wn}@fragment fn fragment(i:Out,@builtin(front_facing) front:bool)->@location(0) vec4f {
|
|
188
188
|
let s=surface(i,front); let v=normalize(f.eye.xyz-i.position); let l=f.light.xyz;
|
|
189
189
|
let direct=direct_light(s,v,l);
|
|
190
190
|
var color=direct+ambient(s)+s.emissive;
|
|
@@ -198,7 +198,7 @@ ${yn}@fragment fn fragment(i:Out,@builtin(front_facing) front:bool)->@location(0
|
|
|
198
198
|
@fragment fn ambientFragment(i:Out,@builtin(front_facing) front:bool)->@location(0) vec4f {
|
|
199
199
|
let s=surface(i,front); return vec4f(ambient(s),select(1.0,s.base.a,f.settings.x>1.5));
|
|
200
200
|
}
|
|
201
|
-
`,
|
|
201
|
+
`,En=[`clearcoat`,`clearcoatRoughness`,`clearcoatNormal`,`transmission`,`sheenColor`,`sheenRoughness`,`specular`,`specularColor`],Dn=[`iridescence`,`iridescenceThickness`,`anisotropy`,`diffuseTransmission`,`diffuseTransmissionColor`,`bump`,`multiscatter`,`thickness`,`diffuseRoughness`],On=[0,4,9,12,17,19],kn=[10,11,16],An=`
|
|
202
202
|
fn margoTintShare(i:Out,tint:vec3f)->vec4f {
|
|
203
203
|
let nv=clamp(abs(dot(normalize(i.normal),normalize(f.eye.xyz-i.position))),0.0001,1.0); let w=pow(1-nv,5.0);
|
|
204
204
|
let ior=(f.ext.y-1)/(f.ext.y+1); let f0=min(ior*ior*f.specular.rgb,vec3f(1)); let fr=f0+(1-f0)*w;
|
|
@@ -213,22 +213,22 @@ fn margoTintSurface(i:Out,s:Surface,tint:vec3f)->vec4f {
|
|
|
213
213
|
return margoTintEncode(tint*(1-s.metal)*(1-margoFresnelPeak(fr))*(1-max(s.sh.r,max(s.sh.g,s.sh.b))*margoSheenAlbedo(nv,s.sh.w))*(1-s.cc*(0.04+0.96*pow(1-nv,5.0))));
|
|
214
214
|
}
|
|
215
215
|
@fragment fn margoTint(i:Out)->@location(0) vec4f {return margoTintShare(i,vec3f(f.coordsB.zw,f.ext.z));}
|
|
216
|
-
`,
|
|
216
|
+
`,jn=(e,t)=>[[`emissive:vec3f}`,`emissive:vec3f, f0:vec3f, sw:f32, tr:f32, th:f32, cn:vec3f, cc:f32, cr:f32, sh:vec4f}`],[`var emissiveSampler:sampler;`,`var emissiveSampler:sampler;
|
|
217
217
|
`+t],[` if(margoFaceTest&&!facing&&f.settings.z<0.5){discard;}`,` let ior=(f.ext.y-1)/(f.ext.y+1); s.sw=f.specular.w*${e(`specular`)}.a; s.f0=min(ior*ior*f.specular.rgb*${e(`specularColor`)}.rgb,vec3f(1))*s.sw;
|
|
218
218
|
s.tr=f.coat.w*${e(`transmission`)}.r; s.th=1; let cm=${e(`clearcoatNormal`)}.xyz*2-1; s.cn=normalize(t*cm.x*f.coat.z+b*cm.y*f.coat.z+n*cm.z);
|
|
219
219
|
s.cc=f.coat.x*${e(`clearcoat`)}.r; s.cr=clamp(f.coat.y*${e(`clearcoatRoughness`)}.g,0.045,1.0);
|
|
220
220
|
// Sheen: linear colour (factor x map rgb) and roughness (factor x map alpha), no floor (KB3297d).
|
|
221
221
|
s.sh=vec4f(f.sheen.rgb*${e(`sheenColor`)}.rgb,clamp(f.sheen.w*${e(`sheenRoughness`)}.a,0.0,1.0));
|
|
222
|
-
if(margoFaceTest&&!facing&&f.settings.z<0.5){discard;}`],[`mix(vec3f(0.04),s.base.rgb,s.metal)`,`mix(s.f0,s.base.rgb,s.metal)`],...
|
|
222
|
+
if(margoFaceTest&&!facing&&f.settings.z<0.5){discard;}`],[`mix(vec3f(0.04),s.base.rgb,s.metal)`,`mix(s.f0,s.base.rgb,s.metal)`],...Qt,[`let fresnel=f0+(1-f0)*pow(1-vh,5.0);`,`let fresnel=f0+(mix(vec3f(s.sw),vec3f(1),s.metal)-f0)*pow(1-vh,5.0);`],[`return ((1-(dielectric+(1-dielectric)*pow(1-vh,5.0)))*(1-s.metal)`,`return ((1-margoFresnelPeak(margoDielectricFresnel(s.f0,s.sw,vh)))*(1-s.metal)`],[`@fragment fn fragment(`,`${Jt}\n${pn}fn ggx(n:vec3f,v:vec3f,l:vec3f,r:f32)->f32 {
|
|
223
223
|
let h=normalize(v+l); let nl=clamp(dot(n,l),0.0,1.0); let nv=clamp(dot(n,v),0.0001,1.0); let nh=clamp(dot(n,h),0.0,1.0);
|
|
224
|
-
let a2=pow(r,4.0); let d=${
|
|
224
|
+
let a2=pow(r,4.0); let d=${rn}; let g=${an};
|
|
225
225
|
return d*g/max(4*nl*nv,0.0001)*nl;
|
|
226
226
|
}
|
|
227
227
|
fn margoLayerSky(s:Surface)->vec3f {return mix(vec3f(0.35,0.3,0.25),vec3f(1),clamp(s.cn.y*0.5+0.5,0.0,1.0))*f.radiance.w*s.occlusion;}
|
|
228
228
|
// Ambient light of the clearcoat (before its Fresnel) and of the sheen (before its colour); lighting effects with an
|
|
229
229
|
// environment replace them (PBRHooks coat and sheen), the defaults are the hemisphere.
|
|
230
230
|
fn margoCoatAmbient(s:Surface,v:vec3f)->vec3f {return 0.5*margoLayerSky(s);}
|
|
231
|
-
${
|
|
231
|
+
${sn(`margoSheenBRDF`)}${cn(`margoSheenHalf`)}${dn(`margoSheenAlbedo`)}fn margoSheenAmbient(s:Surface,v:vec3f)->vec3f {return margoSheenAlbedo(clamp(dot(s.n,v),0.0001,1.0),s.sh.w)*mix(vec3f(0.35,0.3,0.25),vec3f(1),clamp(s.n.y*0.5+0.5,0.0,1.0))*f.radiance.w*s.occlusion;}
|
|
232
232
|
// What the direct hook is asked about: the base's light, or a coat or sheen lobe with light of its own. Fragments with
|
|
233
233
|
// none of these stay zero, so a shadow hook skips them as it does on any other shader.
|
|
234
234
|
fn margoLit(s:Surface,l:vec3f,direct:vec3f)->vec3f {return vec3f(select(0.0,1.0,any(direct!=vec3f(0))||(f.light.w>0.0&&((s.cc>0.0&&dot(s.cn,l)>0.0)||(any(s.sh.rgb>vec3f(0))&&dot(s.n,l)>0.0)))));}
|
|
@@ -248,32 +248,32 @@ fn layers(s:Surface,v:vec3f,l:vec3f,under:vec3f)->vec3f {
|
|
|
248
248
|
}
|
|
249
249
|
@fragment fn fragment(`],[` if(f.ext.x>0.5){color=s.base.rgb;}`,` margoSheenSun=direct;
|
|
250
250
|
color=layers(s,v,l,color);
|
|
251
|
-
if(f.ext.x>0.5){color=s.base.rgb;}`]],
|
|
251
|
+
if(f.ext.x>0.5){color=s.base.rgb;}`]],Mn=`fn margoAnisotropy(n:vec3f,t:vec3f,b:vec3f,a:vec3f)->vec4f {
|
|
252
252
|
let d=a.xy*2-1; let dir=select(vec2f(1,0),d/length(d),dot(d,d)>1e-8); let r=vec2f(f.aniso.y*dir.x-f.aniso.z*dir.y,f.aniso.z*dir.x+f.aniso.y*dir.y);
|
|
253
253
|
let ta=t*r.x+b*r.y; let o=ta-n*dot(n,ta); return vec4f(o/max(length(o),1e-6),f.aniso.x*a.z);
|
|
254
254
|
}
|
|
255
255
|
fn margoBent(s:Surface,v:vec3f)->vec3f {
|
|
256
256
|
let b=cross(s.n,s.at.xyz); let bent=normalize(cross(cross(b,v),b)); return normalize(mix(bent,s.n,pow(1-s.at.w*(1-s.roughness),4.0)));
|
|
257
257
|
}
|
|
258
|
-
`,
|
|
258
|
+
`,Nn=`fn margoEONE(mu:f32,r:f32)->f32 {let m=1-mu; return (1+r*m*(0.0571085289+m*(0.491881867+m*(-0.332181442+m*0.0714429953))))/(1+0.28779341*r);}
|
|
259
259
|
fn margoEONScatter(rho:vec3f,r:f32)->vec4f {let avg=(1+0.07248822*r)/(1+0.28779341*r); let c=clamp(rho,vec3f(0),vec3f(1)); return vec4f(c*c*avg/(1-c*(1-avg)),avg);}
|
|
260
260
|
fn margoEON(rho:vec3f,r:f32,nl:f32,nv:f32,st:f32)->vec3f {
|
|
261
261
|
let t=st/select(1.0,max(max(nl,nv),0.0001),st>0.0); let m=margoEONScatter(rho,r);
|
|
262
262
|
return rho*((1+r*t)/(1+0.28779341*r))+m.rgb*(max(1-margoEONE(nv,r),0.0)*max(1-margoEONE(nl,r),0.0)/max(1-m.a,0.0000001));
|
|
263
263
|
}
|
|
264
264
|
fn margoEONAlbedo(rho:vec3f,r:f32,nv:f32)->vec3f {let e=margoEONE(nv,r); return rho*e+margoEONScatter(rho,r).rgb*(1-e);}
|
|
265
|
-
`,
|
|
265
|
+
`,Pn=(e,t=!1,n=!1)=>`fn margoDirect(s:Surface,v:vec3f,l:vec3f)->vec3f {
|
|
266
266
|
let h=normalize(v+l); let nl=clamp(dot(s.n,l),0.0,1.0); let nv=clamp(dot(s.n,v),0.0001,1.0); let nh=clamp(dot(s.n,h),0.0,1.0); let vh=clamp(dot(v,h),0.0,1.0);
|
|
267
267
|
let f0=mix(s.f0,s.base.rgb,s.metal); let schlick=f0+(mix(vec3f(s.sw),vec3f(1),s.metal)-f0)*pow(1-vh,5.0);
|
|
268
268
|
let fr=mix(schlick,s.ir.rgb,s.ir.w); let kd=mix(vec3f(1-margoFresnelPeak(margoDielectricFresnel(s.f0,s.sw,vh))),vec3f(1-max(s.ir.r,max(s.ir.g,s.ir.b))),s.ir.w); let a=s.roughness*s.roughness;
|
|
269
269
|
${e?`let t=s.at.xyz; let b=cross(s.n,t); let alt=mix(a,1.0,s.at.w*s.at.w); let a2=alt*a;
|
|
270
270
|
let q=vec3f(a*dot(t,h),alt*dot(b,h),a2*nh); let w2=a2/max(dot(q,q),1e-12);
|
|
271
|
-
let spec=a2*w2*w2/3.14159265*clamp(0.5/max(nl*length(vec3f(alt*dot(t,v),a*dot(b,v),nv))+nv*length(vec3f(alt*dot(t,l),a*dot(b,l),nl)),1e-6),0.0,1.0);`:`let a2=a*a; let spec=${
|
|
271
|
+
let spec=a2*w2*w2/3.14159265*clamp(0.5/max(nl*length(vec3f(alt*dot(t,v),a*dot(b,v),nv))+nv*length(vec3f(alt*dot(t,l),a*dot(b,l),nl)),1e-6),0.0,1.0);`:`let a2=a*a; let spec=${nn(`s.n`,`h`)}*0.5/max(nl*sqrt(a2+(1-a2)*nv*nv)+nv*sqrt(a2+(1-a2)*nl*nl),0.00005);`}
|
|
272
272
|
${n?` let st=dot(v,l)-dot(s.n,v)*dot(s.n,l); let back=clamp(-dot(s.n,l),0.0,1.0);
|
|
273
273
|
`:``} let diffuse=kd*(1-s.metal)*((1-s.tr)*(${n?`margoEON(s.base.rgb,s.dr.x,nl,nv,st)`:`s.base.rgb`}*(1-s.dt.w)*nl+${n?`margoEON(s.dt.rgb,s.dr.x,back,nv,st)*s.dt.w*back`:`s.dt.rgb*s.dt.w*clamp(-dot(s.n,l),0.0,1.0)`})${t?`+s.sc*nl`:``})/3.14159265;
|
|
274
274
|
return diffuse+spec*fr*nl;
|
|
275
275
|
}
|
|
276
|
-
`,
|
|
276
|
+
`,Fn=e=>{let t=t=>e.diffuseRoughness?`margoEONAlbedo(${t},s.dr.x,s.dr.y)`:t;return`${e.diffuseTransmission?`fn margoLightSide(n:vec3f,l:vec3f)->vec3f {return select(n,-n,dot(n,l)<0.0);}
|
|
277
277
|
`:``}fn margoSky(n:vec3f)->vec3f {return mix(vec3f(0.35,0.3,0.25),vec3f(1),clamp(n.y*0.5+0.5,0.0,1.0));}
|
|
278
278
|
fn margoFront(s:Surface)->Surface {var o=s; o.base=vec4f(s.base.rgb*(1-s.tr)*(1-s.dt.w)${e.scatter?`+s.sc`:``},s.base.a); return o;}
|
|
279
279
|
fn margoHemisphere(s:Surface)->vec3f {
|
|
@@ -290,19 +290,19 @@ fn margoAmbientLayers(i:Out,s:Surface,v:vec3f)->vec3f {
|
|
|
290
290
|
back.base=vec4f(0,0,0,1); sum-=k*margoAmbientTerm(i,back,-v);`:``}
|
|
291
291
|
return sum;
|
|
292
292
|
}
|
|
293
|
-
`},
|
|
293
|
+
`},In=e=>` {
|
|
294
294
|
let bumpUV=uv(i,18); let bumpBase=${e(`bump`,`bumpUV`)}.r;
|
|
295
295
|
let bumpScale=f.bump.x*select(1.0,length(n*mat3x3f(f.model[0].xyz,f.model[1].xyz,f.model[2].xyz)),f.bump.y>0.5);
|
|
296
296
|
s.n=margoBumpGradient(s.n,i.position,(${e(`bump`,`bumpUV+dpdx(bumpUV)`)}.r-bumpBase)*bumpScale,(${e(`bump`,`bumpUV+dpdy(bumpUV)`)}.r-bumpBase)*bumpScale,facing);
|
|
297
297
|
}
|
|
298
|
-
`,
|
|
298
|
+
`,Ln=e=>` {
|
|
299
299
|
let scatterColor=f.scatter.rgb*${e(`multiscatter`)}.rgb;
|
|
300
300
|
let scatterDepth=f.extinction.w*${e(`thickness`)}.g*length(n*mat3x3f(f.model[0].xyz,f.model[1].xyz,f.model[2].xyz));
|
|
301
301
|
let scatterShares=margoScatterShares(f.extinction.rgb,scatterColor,f.scatter.w,scatterDepth);
|
|
302
302
|
s.sc=(s.tr+(1-s.tr)*s.dt.w)*scatterShares[0]*clamp(scatterColor,vec3f(0),vec3f(1));
|
|
303
303
|
s.dt=vec4f(s.dt.rgb*scatterShares[1],s.dt.w);
|
|
304
304
|
}
|
|
305
|
-
`,
|
|
305
|
+
`,Rn=new Map})),Bn=n({extendedMaterials:()=>Vn}),H,Vn,Hn=t((()=>{zn(),yn(),H=(e,t,n,r,i)=>{let a=e??t;if(typeof a!=`number`||!Number.isFinite(Math.fround(a))||a<n||a>r)throw TypeError(`Invalid glTF `+i+`; re-export the file and check it with the glTF Validator`);return a},Vn={parse(e){let t=e.KHR_materials_iridescence,n=e.KHR_materials_anisotropy,r=e.KHR_materials_diffuse_transmission,i=e.EXT_materials_bump,a=e.KHR_materials_volume,o=e.KHR_materials_volume_scatter,s=e.KHR_materials_unlit||e.KHR_materials_pbrSpecularGlossiness?void 0:e.KHR_materials_diffuse_roughness,c=H(s?.diffuseRoughnessFactor,0,0,1,`diffuse roughness`),l=H(t?.iridescenceFactor,0,0,1,`iridescence`),u=H(n?.anisotropyStrength,0,0,1,`anisotropy strength`),d=H(r?.diffuseTransmissionFactor,0,0,1,`diffuse transmission`),f=H(i?.bumpFactor,1,-1/0,1/0,`bump factor`),p=!!i?.bumpTexture&&f!==0;if(i?.heightSpace!==void 0&&i.heightSpace!==`world`&&i.heightSpace!==`object`)throw TypeError(`Invalid glTF bump height space; use "world" or "object", re-export the file and check it with the glTF Validator`);let m=o?.multiscatterColorFactor??[0,0,0],h=a?.attenuationDistance??1/0,g=a?.thicknessFactor??0,_=a?.attenuationColor??[1,1,1];if(!Array.isArray(m)||m.length!==3)throw TypeError(`Invalid glTF multi-scatter color; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let v=m.map(e=>H(e,0,0,1,`multi-scatter color`)),y=_.map(e=>_n(e,h)),b=!!o&&v.some(e=>e>0)&&g>0&&y.some(e=>e>0)&&(!!d||!!e.KHR_materials_transmission?.transmissionFactor),x=!!a?.thicknessTexture&&!!e.KHR_materials_transmission;if(!l&&!u&&!d&&!p&&!b&&!c&&!x)return;let S=r?.diffuseTransmissionColorFactor??[1,1,1],C=H(n?.anisotropyRotation,0,-1/0,1/0,`anisotropy rotation`);if(!Array.isArray(S)||S.length!==3)throw TypeError(`Invalid glTF diffuse transmission color; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return{features:{iridescence:!!l,anisotropy:!!u,diffuseTransmission:!!d,bump:p,scatter:b,...c?{diffuseRoughness:!0}:void 0},maps:[l?t.iridescenceTexture:void 0,l?t.iridescenceThicknessTexture:void 0,u?n.anisotropyTexture:void 0,d?r.diffuseTransmissionTexture:void 0,d?r.diffuseTransmissionColorTexture:void 0,p?i.bumpTexture:void 0,b?o.multiscatterColorTexture:void 0,b||x?a.thicknessTexture:void 0,...c&&s.diffuseRoughnessTexture?[s.diffuseRoughnessTexture]:[]],rows:[l,H(t?.iridescenceIor,1.3,1,1/0,`iridescence IOR`),H(t?.iridescenceThicknessMinimum,100,0,1/0,`iridescence thickness`),H(t?.iridescenceThicknessMaximum,400,0,1/0,`iridescence thickness`),u,Math.cos(C),Math.sin(C),c,d,...S.map(e=>H(e,0,0,1,`diffuse transmission color`)),f,+(i?.heightSpace===`object`),0,0,...v,H(o?.scatterAnisotropy,0,-1,1,`scatter anisotropy`),...y,g]}},plan:Sn,shader:Cn}}));function Un(e){if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`Invalid texture coordinates; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let t=e?.extensions?.KHR_texture_transform;if(t!==void 0&&(!t||typeof t!=`object`||Array.isArray(t)))throw TypeError(`Invalid KHR_texture_transform; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let n=t?.texCoord===void 0?e.texCoord===void 0?0:e.texCoord:t.texCoord;if(n!==0&&n!==1&&n!==2&&n!==3)throw RangeError(`Texture requires TEXCOORD_0 to TEXCOORD_3`);if(t===void 0)return{texCoord:n};let r=(e,t,n)=>{if(e===void 0)return t;if(!Array.isArray(e)||e.length!==2||Array.from(e).some(e=>typeof e!=`number`||!Number.isFinite(Math.fround(e))))throw TypeError(`Invalid texture transform `+n+`; re-export the file and check it with the glTF Validator`);return e},i=r(t.offset,[0,0],`offset`),a=r(t.scale,[1,1],`scale`),o=t.rotation===void 0?0:t.rotation;if(typeof o!=`number`||!Number.isFinite(Math.fround(o)))throw TypeError(`Invalid texture transform rotation; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(o===0&&i[0]===0&&i[1]===0&&a[0]===1&&a[1]===1)return{texCoord:n};let s=Math.cos(o),c=Math.sin(o);return{texCoord:n,transform:new Float32Array([s*a[0],c*a[1],i[0],0,-c*a[0],s*a[1],i[1],0])}}var Wn=t((()=>{})),Gn=n({convertSpecGlossMaterial:()=>qn,specGlossMaterials:()=>Qn,specGlossToMetalRough:()=>Kn});function Kn(e=[1,1,1,1],t=[1,1,1],n=1){let r=U(e,4,`diffuse`),i=U(t,3,`specular`),a=e=>Math.sqrt(.299*e[0]**2+.587*e[1]**2+.114*e[2]**2),o=a(r),s=a(i),c=1-Math.max(...i),l=o*c/.96+s-.08,u=s<.04?0:Math.min(1,Math.max(0,(-l+Math.sqrt(l*l-.16*(.04-s)))/.08));return{baseColor:[...i.map((e,t)=>{let n=r[t]*c/(.96*Math.max(1-u,1e-6)),i=(e-.04*(1-u))/Math.max(u,1e-6);return Math.min(1,Math.max(0,n*(1-u*u)+i*u*u))}),r[3]],metallic:u,roughness:1-Yn(n,`glossiness`)}}function qn(e){let t=e.extensions?.[Jn];if(t===void 0)return e;if(!t||typeof t!=`object`||Array.isArray(t))throw TypeError(`Invalid glTF spec/gloss extension; pass a material extension object`);let n=t,r=U(n.diffuseFactor===void 0?[1,1,1,1]:n.diffuseFactor,4,`diffuse`),i=U(n.specularFactor===void 0?[1,1,1]:n.specularFactor,3,`specular`),a=Yn(n.glossinessFactor===void 0?1:n.glossinessFactor,`glossiness`);return{...e,pbrMetallicRoughness:{baseColorFactor:r,baseColorTexture:Xn(n.diffuseTexture),roughnessFactor:a,metallicFactor:0},extensions:{...e.extensions,KHR_materials_specular:{specularColorFactor:i.map(e=>e*25),specularColorTexture:Xn(n.specularGlossinessTexture)},KHR_materials_ior:{ior:1.5}}}}var Jn,Yn,U,Xn,Zn,Qn,$n=t((()=>{Hn(),zn(),Wn(),l(),Jn=`KHR_materials_pbrSpecularGlossiness`,Yn=(e,t)=>{if(typeof e!=`number`||!Number.isFinite(e)||e<0||e>1)throw TypeError(`Invalid glTF spec/gloss ${t}; pass a finite number from 0 to 1`);return e},U=(e,t,n)=>{if(!Array.isArray(e)||e.length!==t||Array.from(e).some(e=>typeof e!=`number`))throw TypeError(`Invalid glTF spec/gloss ${n}; pass ${t} finite components from 0 to 1`);return Array.from(e,e=>Yn(e,n))},Xn=e=>{if(e!==void 0){if(!e||typeof e!=`object`||Array.isArray(e)||!Number.isSafeInteger(e.index)||e.index<0)throw TypeError(`Invalid glTF spec/gloss texture; pass a textureInfo with a nonnegative integer index`);return Un(e),e}},Zn=`
|
|
306
306
|
fn margoSpecGloss(d:vec3f,s:vec3f)->vec4f {
|
|
307
307
|
let weights=vec3f(0.299,0.587,0.114);
|
|
308
308
|
let db=sqrt(dot(d*d,weights)); let sb=sqrt(dot(s*s,weights));
|
|
@@ -312,11 +312,11 @@ fn margoSpecGloss(d:vec3f,s:vec3f)->vec4f {
|
|
|
312
312
|
let bs=(s-vec3f(0.04*(1-metal)))/max(metal,0.000001);
|
|
313
313
|
return vec4f(clamp(mix(bd,bs,metal*metal),vec3f(0),vec3f(1)),metal);
|
|
314
314
|
}
|
|
315
|
-
`,
|
|
315
|
+
`,Qn={extensions:[Jn],convert:qn,parse(e){let t=Vn.parse(e);return e[Jn]===void 0?t:{features:{iridescence:!1,anisotropy:!1,diffuseTransmission:!1,...t?.features,specularGlossiness:!0},maps:t?.maps??Array(8).fill(void 0),rows:t?.rows??Array(24).fill(0)}},plan:Sn,shader(e){let t=Cn(e);if(!e.specularGlossiness)return t;let n=e.slots[12],r=n>=0?`textureSample(margoMap${n},margoSampler${n},uv(i,12)).a`:`1.0`,i=` return s;`;if(t.split(i).length!==2)throw a(`failed`,`Spec/gloss surface conversion anchor changed; update the optional material shader`);return Zn+t.replace(i,`
|
|
316
316
|
if(f.ext.x<0.5){
|
|
317
317
|
let converted=margoSpecGloss(s.base.rgb,s.f0);
|
|
318
318
|
s.base=vec4f(converted.rgb,s.base.a); s.metal=converted.a;
|
|
319
319
|
s.roughness=clamp(1-f.factors.x*${r},0.045,1.0);
|
|
320
320
|
s.f0=vec3f(0.04); s.sw=1;
|
|
321
321
|
}
|
|
322
|
-
${i}`)}}}));async function Jn(e,t={}){return t.dds===void 0&&e.textures?.some(e=>e?.extensions?.MSFT_texture_dds!==void 0)&&(t={...t,dds:(await Promise.resolve().then(()=>(ft(),ct))).ddsTextures}),t.splats===void 0&&pe(e)?t={...t,splats:(await Promise.resolve().then(()=>(Lt(),bt))).gaussianSplats}:t.splats===!1&&(t={...t,splats:void 0}),t.materials===void 0?e.materials?.some(e=>e?.extensions?.KHR_materials_pbrSpecularGlossiness!==void 0)?{...t,materials:(await Promise.resolve().then(()=>(qn(),zn))).specGlossMaterials}:(e.materials??[]).some(e=>!!e?.extensions&&typeof e.extensions==`object`&&Yn.some(t=>t in e.extensions))?{...t,materials:(await Promise.resolve().then(()=>(In(),Pn))).extendedMaterials}:t:t.materials?t:{...t,materials:void 0}}var Yn,Xn=t((()=>{me(),Yn=[`KHR_materials_clearcoat`,`KHR_materials_transmission`,`KHR_materials_ior`,`KHR_materials_dispersion`,`KHR_materials_volume`,`KHR_materials_sheen`,`KHR_materials_specular`,`KHR_materials_iridescence`,`KHR_materials_anisotropy`,`KHR_materials_diffuse_transmission`,`KHR_materials_diffuse_roughness`,`EXT_materials_bump`,`KHR_materials_volume_scatter`]}));function Zn(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 Qn(e,t){if(!t.extensions?.KHR_draco_mesh_compression)return;let n=$n.get(e)?.get(t);if(!n)throw a(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);return n}var $n,er=t((()=>{l(),$n=new WeakMap}));async function tr(){throw TypeError(`createImageBitmap is not available in this worker; load the model on the page or in Node to decode its images`)}var nr=t((()=>{}));function rr(e,t,n){return e===`ATTRIBUTES`?256*(Math.floor(4*t/n)+1):e===`TRIANGLES`?3*t:e===`INDICES`?t:1/0}var ir=t((()=>{})),ar=n({MeshoptDecoder:()=>jr,meshoptDecodeGltfBuffer:()=>yr,meshoptDecodeIndexBuffer:()=>fr,meshoptDecodeIndexSequence:()=>pr,meshoptDecodeVertexBuffer:()=>sr});function or(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 sr(e,t,n,r){(!Number.isInteger(n)||n<1||n>256||n%4!=0)&&W(`invalid ATTRIBUTES byteStride ${n}`),(!Number.isSafeInteger(t)||t<0||e.length<t*n)&&G(`invalid count or output size`);let i=r.length;i<1+n&&W(`truncated vertex stream`);let a=r[0];a>>4!=10&&W(`bad vertex stream header`);let o=a&15;o>1&&W(`vertex codec version ${o} is not supported (only versions 0 and 1)`);let s=n>>2,c=o===1;c&&i<1+n+s&&W(`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&&W(`truncated vertex stream`),u=h,h+=s);for(let e=0;e<n;e++){let t=e*256,n=Sr;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+xr&&W(`truncated vertex stream`);for(let e=0;e<o;e++)m[t+e]=r[h+e];h+=o;continue}n=Cr[a]}let a=l+3>>2;h+a>i&&W(`truncated vertex stream`);let s=h;h+=a;for(let e=0;e<l;e++){i-h<xr&&W(`truncated vertex stream`);let a=r[s+(e>>2)]>>(e&3)*2&3;h=or(r,h,n[a],m,t+e*16)}}c&&!g&&(g=cr(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]+wr(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=Tr(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&&W(`vertex stream has trailing or missing data`),c&&!g&&cr(r,d,s)}function cr(e,t,n){for(let r=0;r<n;r++){let n=e[t+r],i=n&15;(i>2||i<2&&n>>4)&&W(`invalid vertex channel mode`)}return!0}function lr(e,t){let n=0,r=0,i=t.pos;for(let t=0;;t++){i>=e.length&&W(`truncated index stream`);let a=e[i++];if(n|=(a&127)<<r,r+=7,a<128)break;t===4&&W(`index varint is longer than 5 bytes`)}return t.pos=i,n>>>0}function ur(e,t){(!Number.isSafeInteger(t)||t<0||e.length<t)&&G(`invalid count or output size`)}function dr(e,t){return t>65535&&e instanceof Uint16Array&&W(`index ${t} does not fit a 16-bit index buffer`),t}function fr(e,t,n){ur(e,t),t%3!=0&&W(`TRIANGLES count must be a multiple of 3`);let r=t/3,i=n.length;i<1+r+16&&W(`truncated index stream`);let a=n[0];a>>4!=14&&W(`bad index stream header`);let o=a&15;o>1&&W(`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)&&W(`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&&W(`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=lr(n,x);return b=b+(e&1?~(e>>>1):e>>>1)>>>0,b};for(let t=0;t<r;t++){x.pos>c&&W(`truncated index stream`);let r=n[1+t],i=r>>4,a=r&15,o,d,p;if(i<15){i>=m&&W(`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]=dr(e,o),e[t*3+1]=dr(e,d),e[t*3+2]=dr(e,p)}x.pos!==c&&W(`index stream has trailing or missing data`)}function pr(e,t,n){ur(e,t);let r=n.length;r<1+t+4&&W(`truncated index sequence`);let i=n[0];i>>4!=13&&W(`bad index sequence header`);let a=i&15;a>1&&W(`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&&W(`truncated index sequence`);let t=lr(n,c),i=t&1,a=s[i]+(t&2?~(t>>>2):t>>>2)>>>0;s[i]=a,e[r]=dr(e,a)}c.pos!==o&&W(`index sequence has trailing or missing data`)}function mr(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=K(K(e*e)+K(K(t*t)+K(n*n)));if(c===0){s(r,0),s(r+a,0),s(r+2*a,0);continue}let l=K(i/K(Math.sqrt(c)));s(r,q(K(e*l))),s(r+a,q(K(t*l))),s(r+2*a,q(K(n*l)))}}function hr(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=K(K(2*K(s*s))-K(K(t*t)+K(K(n*n)+K(i*i)))),l=K(Math.sqrt(Math.max(c,0))),u=K(Ar/s);e.setInt16(r+(o+1&3)*2,q(K(t*u)),!0),e.setInt16(r+(o+2&3)*2,q(K(n*u)),!0),e.setInt16(r+(o+3&3)*2,q(K(i*u)),!0),e.setInt16(r+o*2,q(K(l*u)),!0)}}function gr(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 _r(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=K(i/d),p=e+t-n,m=e+n,h=e-t-n,g=u<<1&d|u&1;l(r,kr(K(p*f))&a),l(r+o,kr(K(m*f))&a),l(r+2*o,kr(K(h*f))&a),l(r+3*o,kr(K(g*f))&a)}}function vr(e,t,n,r){let i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(r){case`OCTAHEDRAL`:n!==4&&n!==8&&W(`OCTAHEDRAL filter requires byteStride 4 or 8`),mr(i,t,n);return;case`QUATERNION`:n!==8&&W(`QUATERNION filter requires byteStride 8`),hr(i,t);return;case`EXPONENTIAL`:gr(i,t*n>>2);return;case`COLOR`:n!==4&&n!==8&&W(`COLOR filter requires byteStride 4 or 8`),_r(i,t,n);return;default:W(`unknown filter '${r}'`)}}function yr(e,t,n,r,i=`NONE`){(!Number.isSafeInteger(t)||t<0||!Number.isSafeInteger(n)||n<=0||t*n>2**31)&&G(`invalid count or byteStride`);let a=e.length;t>rr(r,a,n)&&G(`truncated stream (${t} elements cannot fit in ${a} bytes)`);let o;if(r===`ATTRIBUTES`)o=new Uint8Array(t*n),sr(o,t,n,e);else if(r===`TRIANGLES`||r===`INDICES`){n!==2&&n!==4&&W(`${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`?fr(i,t,e):pr(i,t,e)}else return W(`unknown mode '${r}'`);return i&&i!==`NONE`&&(r!==`ATTRIBUTES`&&W(`filters only apply to ATTRIBUTES`),vr(o,t,n,i)),o}var br,W,G,xr,Sr,Cr,wr,Tr,K,Er,q,Dr,Or,kr,Ar,jr,Mr=t((()=>{ge(),ir(),br=`EXT_meshopt_compression: `,W=e=>{throw F(br+e)},G=e=>{throw RangeError(br+e)},xr=24,Sr=[0,2,4,8],Cr=[[0,1,2,4],[1,2,4,8]],wr=e=>(e&1?~(e>>1):e>>1)&255,Tr=e=>(e&1?~(e>>1):e>>1)&65535,K=Math.fround,Er=12582912,q=e=>K(e+Er)-Er,Dr=new Float32Array(1),Or=new Uint32Array(Dr.buffer),kr=e=>(Dr[0]=e+Er,Or[0]),Ar=K(32767/Math.SQRT2),jr={supported:!0,ready:Promise.resolve(),decodeGltfBuffer(e,t,n,r,i,a){let o=yr(r,t,n,i,a);e.byteLength<t*n&&G(`target buffer is too small`),e.set(o)}}})),Nr=n({decompressPrimitives:()=>Pr});async function Pr(e,{signal:t,draco:n}={}){t?.throwIfAborted();let r,i=$n.get(e)??new Map;$n.set(e,i);try{for(let o of e.doc.meshes??[])for(let s of o.primitives??[]){let o=s.extensions?.KHR_draco_mesh_compression;if(!o||i.has(s))continue;if((s.mode??4)!==4)throw a(`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=Y(e.doc.accessors,s.attributes?.POSITION,`Draco POSITION`),f=J(d.count,`Draco vertex count`,3);if(f>16777216)throw a(`unsupported`,`glTF primitive has more than ${ie} 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=Y(e.doc.accessors,s.attributes?.[t],`Draco attribute`),i=J(r.count,`Draco accessor count`,1),a=Object.hasOwn(Ir,r.type)?Ir[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]=J(r.componentType,`Draco component type`),l[t]=J(n,`Draco attribute id`),u[t]=a}let m=s.indices===void 0?void 0:Y(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=J(m.count,`Draco index count`,1);if(e>Fr||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(Fr,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 fi(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=J(_.vertexCount,`Draco vertex count`,3),y=_.indices;if(v>16777216||!(y instanceof Uint16Array||y instanceof Uint32Array)||!y.length||y.length>Fr||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=Y(e.doc.accessors,n,`Draco attribute`),i=Object.hasOwn(Lr,t)?Lr[t]:void 0,a=_.attributes?.[t],o=i?_[i]:a?.array;if(!ArrayBuffer.isView(o)||o instanceof DataView||r.count!==v||o.length!==v*Ir[r.type]||!i&&(a?.itemSize!==Ir[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=Rr[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),i.set(s,s.indices===void 0?b:e.accessor(s.indices,`SCALAR`))}}finally{r?.dispose()}}var Fr,Ir,Lr,Rr,zr=t((()=>{l(),Pi(),er(),N(),Fr=3*ie,Ir={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Lr={POSITION:`positions`,NORMAL:`normals`,TEXCOORD_0:`uvs`,COLOR_0:`colors`},Rr={5120:127,5121:255,5122:32767,5123:65535}})),Br=n({analyzeVertexCache:()=>Ur,optimizeMesh:()=>Yr,optimizeOverdraw:()=>Kr,optimizeVertexCache:()=>Gr,optimizeVertexFetch:()=>Jr,vertexFetchRemap:()=>qr});function Vr(e,t,n){if(e.length%3)throw RangeError(`${n} needs whole triangles; pass 3 indices per face`);if(t!==void 0&&!(Number.isInteger(t)&&t>=0))throw RangeError(`${n} vertex count ${t} is invalid; pass an integer >= 0`);let r=-1;for(let t=0;t<e.length;t++){let i=e[t];if(!Number.isInteger(i)||i<0)throw RangeError(`${n} index ${i} is invalid; pass integers >= 0`);i>r&&(r=i)}if(t!==void 0&&r>=t)throw RangeError(`${n} index ${r} is past ${t} vertices; fix the indices`);return t??r+1}function Hr(e,t){if(!Number.isInteger(e)||e<3)throw RangeError(`${t} cache size ${e} is invalid; pass an integer >= 3`)}function Ur(e,t,n=16){let r=Vr(e,t,`analyzeVertexCache`);Hr(n,`analyzeVertexCache`);let i=new Float64Array(r).fill(-1/0),a=new Uint8Array(r),o=0,s=0,c=0;for(let t=0;t<e.length;t++){let r=e[t];a[r]||(a[r]=1,c++),!(o-i[r]<=n)&&(i[r]=++o,s++)}return{misses:s,acmr:e.length?s/(e.length/3):0,atvr:c?s/c:0}}function Wr(e,t){return t===0?-1:(e<0?0:Zr[e])+2/Math.sqrt(t)}function Gr(e,t){let n=Vr(e,t,`optimizeVertexCache`),r=e.length/3,i=new Uint32Array(e.length),a=new Uint32Array(n+1),o=new Uint32Array(n);for(let t=0;t<e.length;t++)a[e[t]+1]++;for(let e=0;e<n;e++)a[e+1]+=a[e];let s=new Uint32Array(e.length),c=a.slice(0,n);for(let t=0;t<e.length;t++){let n=e[t];s[c[n]++]=t/3|0,o[n]++}let l=new Float64Array(n),u=new Float64Array(r),d=new Uint8Array(r);for(let e=0;e<n;e++)l[e]=Wr(-1,o[e]);for(let t=0;t<r;t++)u[t]=l[e[t*3]]+l[e[t*3+1]]+l[e[t*3+2]];let f=new Int32Array(35),p=new Int32Array(35),m=0,h=0,g=-1;for(let t=0;t<r;t++){if(g<0){for(;d[h];)h++;g=h}let n=e[g*3],r=e[g*3+1],c=e[g*3+2];i[t*3]=n,i[t*3+1]=r,i[t*3+2]=c,d[g]=1;for(let t=0;t<3;t++){let n=e[g*3+t],r=a[n],i=r+o[n]-1;for(let e=r;e<=i;e++)if(s[e]===g){s[e]=s[i];break}o[n]--}let _=0;p[_++]=n,r!==n&&(p[_++]=r),c!==n&&c!==r&&(p[_++]=c);for(let e=0;e<m;e++){let t=f[e];if(t!==n&&t!==r&&t!==c&&(p[_++]=t),_===p.length)break}let v=f;f=p,p=v,m=_;for(let e=0;e<m;e++){let t=f[e],n=Wr(e<Xr?e:-1,o[t]),r=n-l[t];l[t]=n;for(let e=a[t],n=e+o[t];e<n;e++)u[s[e]]+=r}m>Xr&&(m=Xr);let y=-1/0;g=-1;for(let e=0;e<m;e++){let t=f[e];for(let e=a[t],n=e+o[t];e<n;e++)u[s[e]]>y&&(y=u[s[e]],g=s[e])}}return i}function Kr(e,t,n={}){let{threshold:r=1.05,cacheSize:i=16}=n;if(t.length%3)throw RangeError(`optimizeOverdraw positions must be xyz per vertex; fix the array`);let a=Vr(e,t.length/3,`optimizeOverdraw`);if(Hr(i,`optimizeOverdraw`),!(r>=1&&r<1/0))throw RangeError(`optimizeOverdraw threshold ${r} is invalid; pass a finite number >= 1`);let o=e.length/3,s=Ur(e,a,i).acmr*r,c=new Float64Array(a).fill(-1/0),l=[],u=0,d=0,f=0;for(let t=0;t<o;t++){t-f>=16&&d/(t-f)<=s&&(l.push(t),f=t,d=0,u+=i+1);let n=0;for(let r=0;r<3;r++){let a=e[t*3+r];u-c[a]<=i||(c[a]=++u,n++)}(t===0||t>f&&n===3)&&(l.push(t),f=t,d=0),d+=n}let p=l.length,m=new Float64Array(p*3),h=new Float64Array(p*3),g=new Float64Array(p),_=[0,0,0],v=0;for(let n=0;n<p;n++){let r=n+1<p?l[n+1]:o;for(let i=l[n];i<r;i++){let r=e[i*3]*3,a=e[i*3+1]*3,o=e[i*3+2]*3,s=t[a]-t[r],c=t[a+1]-t[r+1],l=t[a+2]-t[r+2],u=t[o]-t[r],d=t[o+1]-t[r+1],f=t[o+2]-t[r+2],p=c*f-l*d,y=l*u-s*f,b=s*d-c*u,x=Math.hypot(p,y,b);h[n*3]+=p,h[n*3+1]+=y,h[n*3+2]+=b,g[n]+=x;for(let e=0;e<3;e++){let i=(t[r+e]+t[a+e]+t[o+e])/3;m[n*3+e]+=i*x,_[e]+=i*x}v+=x}}let y=new Float64Array(p),b=Array.from({length:p},(e,t)=>t);for(let e=0;e<p;e++){let t=Math.hypot(h[e*3],h[e*3+1],h[e*3+2]);if(!(t>0&&g[e]>0&&v>0))continue;let n=0;for(let t=0;t<3;t++)n+=(m[e*3+t]/g[e]-_[t]/v)*h[e*3+t];y[e]=n/t}b.sort((e,t)=>y[t]-y[e]||e-t);let x=new Uint32Array(e.length),S=0;for(let t of b){let n=(t+1<p?l[t+1]:o)*3;for(let r=l[t]*3;r<n;r++)x[S++]=e[r]}return x}function qr(e,t){let n=Vr(e,t,`vertexFetchRemap`),r=new Uint32Array(n).fill(4294967295),i=0;for(let t=0;t<e.length;t++)r[e[t]]===4294967295&&(r[e[t]]=i++);return r}function Jr(e){let t=e.positions.length/3,n=qr(e.indices,t),r=0;for(let e=0;e<t;e++)n[e]!==4294967295&&r++;let i=(e,i)=>{if(e.length!==t*i)return e.slice();let a=new Float32Array(r*i);for(let r=0;r<t;r++)if(n[r]!==4294967295)for(let t=0;t<i;t++)a[n[r]*i+t]=e[r*i+t];return a},a=new Uint32Array(e.indices.length);for(let t=0;t<a.length;t++)a[t]=n[e.indices[t]];let o={positions:i(e.positions,3),normals:i(e.normals,3),uvs:i(e.uvs,2),indices:a};return e.tangents&&(o.tangents=i(e.tangents,4)),e.groups&&(o.groups=e.groups.map(e=>({...e}))),o}function Yr(e,t={}){let{overdraw:n=!0,...r}=t,i=e.indices.length,a=e.positions.length/3,o=new Set([0,i]);for(let{start:t,count:n}of e.groups??[]){let e=t+n;if(!(Number.isInteger(t)&&Number.isInteger(e)&&t>=0&&e<=i)||t%3||e%3)throw RangeError(`optimizeMesh group ${t}+${n} is invalid; groups must cover whole triangles`);o.add(t).add(e)}let s=[...o].sort((e,t)=>e-t),c=new Uint32Array(i);for(let t=0;t+1<s.length;t++){let i=Gr(e.indices.subarray(s[t],s[t+1]),a);n&&(i=Kr(i,e.positions,r)),c.set(i,s[t])}return Jr({...e,indices:c})}var Xr,Zr,Qr=t((()=>{Xr=32,Zr=Float64Array.from({length:Xr},(e,t)=>t<3?.75:(1-(t-3)/29)**1.5)}));function $r(e,t){if(!(e.length<23)){for(let t=0;t<23;t++)if(e[t]!==xi.charCodeAt(t))return;throw a(`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 ei(e=bi){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`maxDownloadBytes must be a positive integer`);return e}function J(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 Y(e,t,n){let r=e?.[J(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 ti(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 ni(e){let t=typeof e==`string`?e:ti(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 h(t)}catch(e){throw e instanceof SyntaxError?TypeError(`Invalid glTF JSON: `+e.message):e}}function ri(e){if(!e||typeof e!=`object`||!d(e.asset))throw TypeError(`Expected glTF 2.0`);let t=e;for(let e of Ei)if(!Q(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(!Q(t.primitives)||!(t.primitives??[]).every(e=>Q(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(!Q(t.samplers)||!Q(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 ii(e,t=bi){if(typeof e==`string`){if(e.length>t)throw X(`glTF JSON exceeds byte budget`,t);let n=new TextEncoder().encode(e).byteLength;if(n>t)throw X(`glTF JSON exceeds byte budget`,t);return{doc:ni(e),sourceBytes:n}}if(!(e instanceof ArrayBuffer)&&!ArrayBuffer.isView(e))return{doc:e,sourceBytes:0};let n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if($r(n,`The glTF input`),n.length>=4&&!se(n)){if(n.length>t)throw X(`glTF JSON exceeds byte budget`,t);return{...ii(ti(n),t),sourceBytes:n.byteLength}}if(n.length>t)throw X(`glTF exceeds download budget`,t);let r=oe(n);return{doc:ni(r[0].data),binary:r[1]?.type===5130562?r[1].data:void 0,sourceBytes:n.byteLength}}function ai(e,t=bi){let n=/^data:[^;,]+;base64,([A-Za-z0-9+/]*={0,2})$/.exec(e);if(n&&n[1].length>t*4/3+4)throw X(`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 oi(e,t=!1){let n=e.extensions,r=n?.[$]!==void 0||!t||n?.MSFT_texture_dds===void 0?$:`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 J(i===void 0?e.source:i.source,`image source`)}function si(e,t,n){let r=J(t,`accessor`),i=Y(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`?ue[i.componentType]:void 0,o=typeof i.type==`string`&&Object.hasOwn(Di,i.type)?Di[i.type]:void 0,s=J(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 ci(e){let t=new Set;for(let n of e.textures??[])if(n?.extensions?.[$]!==void 0){let r=oi(n),i=Y(e.images,r,`KTX2 image`);if(i.mimeType!==void 0&&i.mimeType!==`image/ktx2`||i.bufferView!==void 0&&i.mimeType!==`image/ktx2`)throw TypeError(`KHR_texture_basisu requires image/ktx2`);t.add(r)}for(let n=0;n<(e.images?.length??0);n++)e.images[n]?.mimeType===`image/ktx2`&&t.add(n);return t}function li(e,t=!1){let n=new Set,r=new Set;for(let i of e.textures??[])i?.extensions?.[$]!==void 0||t&&i?.extensions?.MSFT_texture_dds!==void 0?(r.add(oi(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(J(i.extensions.MSFT_texture_dds.source,`DDS image`)));for(let e of r)n.delete(e);return n}function ui(e,t,n){if(e.length<80||[171,75,84,88,32,50,48,187,13,10,26,10].some((t,n)=>e[n]!==t))throw TypeError(`Invalid glTF KTX2 header; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=r.getUint32(20,!0),a=r.getUint32(24,!0),o=r.getUint32(40,!0);if(!i||!a||i%4||a%4||i*a>67108864||i>(n?.limits.maxTextureDimension2D??16384)||a>(n?.limits.maxTextureDimension2D??16384)||r.getUint32(28,!0)||r.getUint32(32,!0)||r.getUint32(36,!0)!==1||!o||o>Math.floor(Math.log2(Math.max(i,a)))+1)throw RangeError(`Invalid glTF KTX2 dimensions or mip levels; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let s=0;for(let e=0;e<o;e++)s+=Math.max(1,i>>e)*Math.max(1,a>>e)*4;if(s>t.remainingDecodedBytes)throw RangeError(`glTF KTX2 exceeds decoded byte budget; load a smaller model, or reduce its textures and meshes`);return{width:i,height:a,levels:o}}function di(e,t,n){let r={rgba8:[`rgba8unorm`,1,4],bc7:[`bc7-rgba-unorm`,4,16],"astc-4x4":[`astc-4x4-unorm`,4,16],etc2:[`etc2-rgba8unorm`,4,16]},i=e&&Object.hasOwn(r,e.target)?r[e.target]:void 0,a=typeof e?.format==`string`?e.format.replace(/-srgb$/,``):void 0;if(!i||a!==i[0]||e.width!==t.width||e.height!==t.height||!Array.isArray(e.mipmaps)||e.mipmaps.length!==t.levels||typeof e.srgb!=`boolean`||typeof e.hasAlpha!=`boolean`)throw TypeError(`Invalid transcoded glTF KTX2 image; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let o=0;for(let n=0;n<e.mipmaps.length;n++){let r=e.mipmaps[n],a=Math.max(1,t.width>>n),s=Math.max(1,t.height>>n),c=Math.ceil(a/i[1])*Math.ceil(s/i[1])*i[2];if(!r||r.width!==a||r.height!==s||!(r.data instanceof Uint8Array)||r.data.byteLength!==c||r.byteLength!==c)throw RangeError(`Invalid transcoded glTF KTX2 mip; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);o+=c}return n.reserveDecodedBytes(o),{ktx2:e,width:e.width,height:e.height,close(){}}}function fi(e,t){let n=e.hooks.decoderModule;if(!n)throw a(`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}function pi(e,t){let n=t.ktx2,r;return{async decode(i){t.signal?.throwIfAborted();let a=ui(i,e,t.device);if(!n){let{KTX2Decoder:i}=await fi(e,`KTX2`)();t.signal?.throwIfAborted(),n=r=new i({device:t.device})}let o=await n.transcode(i,{signal:t.signal});return t.signal?.throwIfAborted(),di(o,a,e)},close(){r?.dispose()}}}async function mi(){let{optimizeOverdraw:e,optimizeVertexCache:t}=await Promise.resolve().then(()=>(Qr(),Br));return(n,r,i)=>e(t(n,i),r)}async function hi(e,t={},n,r={},i=!1,o=0){let s=`aborted`in t?{signal:t}:t,{signal:c,decoders:l={},buffers:u=[],fetch:d=globalThis.fetch,maxDownloadBytes:f,maxNodes:p,optimize:m,allowedURLs:h,maxPartVertices:g}=s,_=typeof n==`function`?n:void 0,v=typeof n==`function`?void 0:n,x=ei(f),S=ne(g);c?.throwIfAborted();let C=e===void 0?s.baseURL===void 0?void 0:new URL(s.baseURL,globalThis.location?.href):new URL(e,globalThis.location?.href),w=o,T=async(e,t=!1)=>{if(![`http:`,`https:`].includes(e.protocol))throw TypeError(`glTF URL must use HTTP(S)`);let n=await d(e,{signal:c});t&&n.url?C=new URL(n.url):t||b(n,C??globalThis.location?.href,h,`glTF resource`);let r=await E(n,{maxBytes:x-w,signal:c,label:`glTF download`}).catch(e=>{throw e instanceof RangeError?X(e.message,x):e});return $r(r,e.href),w+=r.length,r},D=t=>{if(C===void 0&&e===void 0)throw a(`state`,`glTF URI ${t} needs the file location, which a file in memory does not have; pass the baseURL option to parseGLTFAsync or load the file with loadGLTF`);return y(t,C??globalThis.location?.href,h,`glTF resource`)},{doc:O,binary:ee,sourceBytes:te}=ii(v??await T(C,!0),x),k=[],A=[];if(v!=null){if(te>x-w)throw X(`glTF exceeds download budget`,x);w+=te}ri(O);for(let e=0;e<(O.buffers?.length??0);e++){let t=Y(O.buffers,e,`buffer`);if(u[e]){let t=u[e];k[e]=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}else if(Z(t)?.fallback!==!0){if(!t.uri)e===0&&ee&&(k[e]=ee);else if(typeof t.uri!=`string`)throw TypeError(`Invalid glTF buffer uri; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);else if(t.uri.startsWith(`data:`)){let n=ai(t.uri,x);if(w+=n.length,w>x)throw X(`glTF exceeds download budget`,x);k[e]=n}else k[e]=await T(D(t.uri))}}let j=new ji(O,k,ee,await Jn(O,l),x,p),M=j.hooks;if(j.baseURL=C?.href,j.partVertices=S,m&&(j.reorder=await mi()),i&&yi(O))return{asset:j,images:A,deferred:!0,baseURL:C?.href,downloadedBytes:w};let re=ci(O),ie=li(O,!!M.dds),N=pi(j,{...r,ktx2:r.ktx2??M.ktx2,signal:c}),ae=0;await j.decode(c);try{c?.throwIfAborted(),await _?.(j),c?.throwIfAborted();let e=[],t=async()=>{let[t,n]=e.shift(),r=await n;if(A[t]=r,ae+=r.width*r.height*4,r.width*r.height>67108864||ae>x*4)throw RangeError(`glTF images exceed decoded size limit; load a smaller model, or reduce its textures and meshes`);c?.throwIfAborted()};try{for(let n=0;n<(O.images?.length??0);n++){if(ie.has(n))continue;let r=Y(O.images,n,`image`);if(re.has(n)&&M.textureStream){A[n]=await M.textureStream.open(r.bufferView===void 0?typeof r.uri==`string`&&r.uri.startsWith(`data:`)?{bytes:ai(r.uri,x)}:{url:D(r.uri).href}:{bytes:j.view(r.bufferView)},n);continue}let i;if(r.bufferView!==void 0)i=j.view(r.bufferView);else if(typeof r.uri==`string`&&r.uri.startsWith(`data:`)){if(i=ai(r.uri,x),w+=i.length,w>x)throw X(`glTF exceeds download budget`,x)}else if(typeof r.uri==`string`)i=await T(D(r.uri));else throw TypeError(`Invalid glTF image; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(M.dds&&O.textures?.some(e=>!e.extensions?.KHR_texture_basisu&&e.extensions?.MSFT_texture_dds?.source===n)){if(r.mimeType!==void 0&&r.mimeType!==`image/vnd-ms.dds`||r.bufferView!==void 0&&r.mimeType!==`image/vnd-ms.dds`)throw TypeError(`MSFT_texture_dds requires image/vnd-ms.dds`);for(;e.length;)await t();e.push([n,Promise.resolve(M.dds.decode(i,{signal:c}))]),await t()}else if(re.has(n)){for(;e.length;)await t();e.push([n,N.decode(i)]),await t()}else{let a=gi(i,r.mimeType,n,c);a.catch(()=>{}),e.push([n,a]),e.length>=Mi&&await t()}}for(;e.length;)await t()}finally{for(let[,t]of e.splice(0))t.then(e=>_i([e]),()=>{})}return{asset:j,images:A}}catch(e){throw _i(A),e}finally{N.close()}}async function gi(e,t,n,r){r?.throwIfAborted();try{if(typeof createImageBitmap!=`function`)return await tr(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`)}}function _i(e){for(let t of e){if(!t)continue;let e=Ni.get(t);e?Ni.set(t,e-1):`close`in t&&t.close?.()}}var vi,yi,bi,X,xi,Si,Ci,wi,Ti,Z,Ei,Q,Di,Oi,ki,$,Ai,ji,Mi,Ni,Pi=t((()=>{l(),u(),f(),g(),S(),D(),te(),N(),ce(),de(),Xn(),me(),er(),nr(),vi=e=>!!e.meshes?.some(e=>e?.primitives?.some(e=>e?.extensions?.KHR_draco_mesh_compression))||pe(e),yi=e=>vi(e)||!!e.textures?.some(e=>e?.extensions?.KHR_texture_basisu)||!!e.images?.some(e=>e?.mimeType===`image/ktx2`),bi=536870912,X=(e,t)=>RangeError(`${e} (${t} bytes; raise the maxDownloadBytes option)`),xi=`version https://git-lfs`,Si=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(`.`)),Ci={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`},Ti=[`EXT_meshopt_compression`,`KHR_meshopt_compression`],Z=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},Ei=[`buffers`,`bufferViews`,`accessors`,`meshes`,`nodes`,`scenes`,`materials`,`textures`,`images`],Ei.push(`samplers`,`skins`,`animations`,`cameras`),Q=e=>e===void 0||Array.isArray(e)&&e.every(e=>!!e&&typeof e==`object`&&!Array.isArray(e)),Di={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Oi=`EXT_meshopt_compression`,ki=`KHR_draco_mesh_compression`,$=`KHR_texture_basisu`,Ai={5120:127,5121:255,5122:32767,5123:65535},ji=class{get remainingDecodedBytes(){return this.maxBytes*4-this.decoded}reserveDecodedBytes(e){if(J(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={},i=bi,o=1e5){this.doc=e,this.hooks=r,this.maxBytes=i,this.maxNodes=o,this.cache=new Map,this.viewCache=new Map,this.decoded=0,this.partVertices=j,ei(i),O(`maxNodes`,o),ri(e);let s=(e.extensionsRequired??[]).filter(e=>!Si.has(e)&&![ki,Oi,`KHR_meshopt_compression`,$].includes(e)&&!r[Ci[e]]&&!(r.materials&&r.materials.extensions?.includes(e)));if(s.length)throw a(`unsupported`,`Required glTF extensions are unsupported: `+s.map(e=>Ci[e]?e+` (pass a `+Ci[e]+` decoder)`:e).join(`, `)+`; pass the listed decoders or re-export the model without them`);ee(`Too many glTF nodes`,e.nodes?.length??0,o,`maxNodes`);let c=0;this.buffers=(e.buffers??[]).map((r,a)=>{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=J(r.byteLength,`buffer length`,1),s=Z(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 l=t[a],u=(!l||l.byteLength===0)&&!r.uri&&(a!==0||!n);if(s===!0||u&&Ti.some(t=>e.extensionsRequired?.includes(t))){let t=Ti.find(e=>r.extensions?.[e]!==void 0),n=(e.bufferViews??[]).filter(e=>e?.buffer===a);if(!n.length||n.some(e=>!Z(e)||t!==void 0&&!e.extensions?.[t])||e.bufferViews?.some(e=>Z(e)?.buffer===a))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 d=l?l instanceof ArrayBuffer?new Uint8Array(l):new Uint8Array(l.buffer,l.byteOffset,l.byteLength):r.uri?ai(r.uri,i):a===0?n:void 0;if(!d||o>d.length)throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`);if(a===0&&n&&(l===n||d===n)&&ae(n.length,o),c+=d.byteLength,c>i)throw X(`glTF buffers exceed byte budget`,i);return d.subarray(0,o)})}view(e){let t=J(e,`bufferView`),n=Y(this.doc.bufferViews,t,`bufferView`),r=J(n.buffer,`buffer reference`),i=this.buffers[r],o=J(n.byteOffset??0,`view offset`),s=J(n.byteLength,`view length`,1),c=J(Y(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=Z(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[J(l.buffer,`meshopt buffer reference`)],i=J(l.byteOffset??0,`meshopt offset`),o=J(l.byteLength,`meshopt length`,1),c=J(l.count,`meshopt count`,1),u=J(l.byteStride,`meshopt stride`,1),d=l.mode,f=l.filter??`NONE`;if(!r||o>r.length||i>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(i,i+o),m;if(this.hooks.meshopt)m=new Uint8Array(s),this.hooks.meshopt.decodeGltfBuffer(m,c,u,p,d,f);else{if(!wi)throw a(`state`,`Meshopt geometry requires parseGLTFAsync or loadGLTF, or a meshopt decoder passed in decoders (or asset.decode() first)`);m=wi(p,c,u,d,f)}return this.reserveDecodedBytes(m.byteLength),this.viewCache.set(t,m),m}if(!i||o+s>i.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 i.subarray(o,o+s)}setDecodedAccessor(e,t){let{index:n,width:r,count:i}=si(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(){wi||this.hooks.meshopt||this.doc.bufferViews?.some(e=>e?.extensions?.EXT_meshopt_compression||e?.extensions?.KHR_meshopt_compression)&&(wi=(await Promise.resolve().then(()=>(Mr(),ar))).meshoptDecodeGltfBuffer)}async decode(e){if(await this.prepareMeshopt(),!Zn(this))return e?.throwIfAborted();let{decompressPrimitives:t}=await Promise.resolve().then(()=>(zr(),Nr)),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:i,size:o,width:s,count:c}=si(this.doc,e,t),l=this.cache.get(r);if(l)return l;this.reserveDecodedBytes(c*s*4);let u=new Float32Array(c*s),d=(e,t,r,a,c)=>{if(t%o||r%o||t+(a-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=i.componentType,f=i.normalized?Ai[d]??1:0;for(let e=0;e<a;e++){let i=(c?c[e]:e)*s;for(let a=0,c=t+e*r;a<s;a++,c+=o){let e=le(l,c,d);if(f&&(e=Math.max(-1,e/f)),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`);u[i+a]=e}}};if(i.bufferView!==void 0){let e=Y(this.doc.bufferViews,i.bufferView,`bufferView`),t=J(e.byteStride??o*s,`stride`,o*s);if(t>252||J(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`);d(this.view(i.bufferView),J(i.byteOffset??0,`accessor offset`),t,c)}else{if(this.doc.meshes?.some(e=>e?.primitives?.some(e=>e?.extensions?.[ki]&&(e.indices===r||Object.keys(e.extensions[ki].attributes??{}).some(t=>e.attributes?.[t]===r)))))throw a(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);if(i.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(i.sparse){let e=i.sparse,t=J(e.count,`sparse count`,1),n=e.indices,r=e.values,a=ue[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=J(n.byteOffset??0,`sparse offset`);if(u%a||u+t*a>l.length||Y(this.doc.bufferViews,n.bufferView,`sparse indices`).byteStride!==void 0||Y(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),p=[],m=-1;for(let e=0;e<t;e++){let t=u+e*a,n=a===1?f.getUint8(t):a===2?f.getUint16(t,!0):f.getUint32(t,!0);if(n<=m||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`);p.push(n),m=n}d(this.view(r.bufferView),J(r.byteOffset??0,`sparse values offset`),o*s,t,p)}return n&&this.cache.set(r,u),u}},Mi=8,Ni=new WeakMap}));er(),Pi(),l(),N();function Fi(e){if(!e||typeof e!=`object`)return!1;for(let[t,n]of Object.entries(e))if(t===`texCoord`?n>1:Fi(n))return!0;return!1}function Ii(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(Fi(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 Li(e,t,n){Qn(e,t);try{return zi(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 Ri(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 zi(e,t,n){let r=t.mode??4,i=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(Y(e.doc.accessors,o.POSITION,`POSITION`).count>16777216)throw a(`unsupported`,`glTF primitive has more than ${ie} 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<i)throw RangeError(`Expected bounded triangle geometry`);for(let t of[`POSITION`,`NORMAL`,`TANGENT`])if(o[t]!==void 0&&!u){let n=Y(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=Y(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=Qn(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=Ri(m,r),!m.length||m.length%i)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(Y(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&&i===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?A(m,i,l,d,h?null:c):null;if(e.reorder&&i===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=Ii(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 T=(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},E=(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)},D=i<3?{topology:i===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++)T(e,t,t*20);if(t)for(let e=0;e<l;e++)E(t,e,e*4);let r={vertices:e,indices:m,...D,...t?{uvs:t}:{}};return n?(n(r),[]):[r]}let O=[];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++)T(a,r[e],e*20);if(o)for(let e=0;e<i;e++)E(o,r[e],e*4);let s={vertices:a,indices:t,...D,...o?{uvs:o}:{},part:{index:e,count:g.length,vertexMap:r}};n?n(s):O.push(s)}return O}function Bi(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}Pi();function Vi(e,t){let n=e.doc,r=e=>{try{return e()}catch{return null}},i=0,a=(n.meshes??[]).map(t=>(Array.isArray(t?.primitives)?t.primitives:[]).map(t=>{let n=r(()=>Li(e,t));for(let e of n??[])i+=e.vertices.byteLength+e.indices.byteLength+(e.uvs?.byteLength??0);if(i>e.maxBytes*4)throw X(`Decoded glTF geometry exceeds byte budget`,e.maxBytes*4);return n&&n.length===1?n[0]:n}));return Bi(e),{doc:n,buffers:e.buffers,images:t,geometry:a,accessors:[...e.cache],maxDownloadBytes:e.maxBytes,maxNodes:e.maxNodes,maxPartVertices:e.partVertices}}async function Hi(e,t,n,r,i,a,o,s){let{asset:c,images:l,deferred:u,baseURL:d,downloadedBytes:f}=await hi(e,{buffers:n,maxDownloadBytes:r,maxNodes:i,allowedURLs:a,optimize:o,maxPartVertices:s},t,{},!0);return u?{doc:c.doc,buffers:c.buffers,images:l,geometry:[],accessors:[],maxDownloadBytes:c.maxBytes,maxNodes:c.maxNodes,maxPartVertices:c.partVertices,deferred:u,baseURL:d,downloadedBytes:f}:Vi(c,l)}i(({url:e,input:t,buffers:n,maxDownloadBytes:r,maxNodes:i,allowedURLs:a,maxPartVertices:o})=>Hi(e,t,n,r,i,a,void 0,o))})();
|
|
322
|
+
${i}`)}}}));async function er(e,t={}){return t.dds===void 0&&e.textures?.some(e=>e?.extensions?.MSFT_texture_dds!==void 0)&&(t={...t,dds:(await Promise.resolve().then(()=>(vt(),mt))).ddsTextures}),t.splats===void 0&&fe(e)?t={...t,splats:(await Promise.resolve().then(()=>(Ht(),Et))).gaussianSplats}:t.splats===!1&&(t={...t,splats:void 0}),t.strokes===void 0&&ve(e)?t={...t,strokes:(await Promise.resolve().then(()=>(Tt(),wt))).wideStrokes}:t.strokes===!1&&(t={...t,strokes:void 0}),t.materials===void 0?e.materials?.some(e=>e?.extensions?.KHR_materials_pbrSpecularGlossiness!==void 0)?{...t,materials:(await Promise.resolve().then(()=>($n(),Gn))).specGlossMaterials}:(e.materials??[]).some(e=>!!e?.extensions&&typeof e.extensions==`object`&&tr.some(t=>t in e.extensions))?{...t,materials:(await Promise.resolve().then(()=>(Hn(),Bn))).extendedMaterials}:t:t.materials?t:{...t,materials:void 0}}var tr,nr=t((()=>{pe(),ye(),tr=[`KHR_materials_clearcoat`,`KHR_materials_transmission`,`KHR_materials_ior`,`KHR_materials_dispersion`,`KHR_materials_volume`,`KHR_materials_sheen`,`KHR_materials_specular`,`KHR_materials_iridescence`,`KHR_materials_anisotropy`,`KHR_materials_diffuse_transmission`,`KHR_materials_diffuse_roughness`,`EXT_materials_bump`,`KHR_materials_volume_scatter`]}));function rr(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 ir(e,t){if(!t.extensions?.KHR_draco_mesh_compression)return;let n=ar.get(e)?.get(t);if(!n)throw a(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);return n}var ar,or=t((()=>{l(),ar=new WeakMap}));async function sr(){throw TypeError(`createImageBitmap is not available in this worker; load the model on the page or in Node to decode its images`)}var cr=t((()=>{}));function lr(e,t,n){return e===`ATTRIBUTES`?256*(Math.floor(4*t/n)+1):e===`TRIANGLES`?3*t:e===`INDICES`?t:1/0}var ur=t((()=>{})),dr=n({MeshoptDecoder:()=>Lr,meshoptDecodeGltfBuffer:()=>Tr,meshoptDecodeIndexBuffer:()=>vr,meshoptDecodeIndexSequence:()=>yr,meshoptDecodeVertexBuffer:()=>pr});function fr(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 pr(e,t,n,r){(!Number.isInteger(n)||n<1||n>256||n%4!=0)&&W(`invalid ATTRIBUTES byteStride ${n}`),(!Number.isSafeInteger(t)||t<0||e.length<t*n)&&G(`invalid count or output size`);let i=r.length;i<1+n&&W(`truncated vertex stream`);let a=r[0];a>>4!=10&&W(`bad vertex stream header`);let o=a&15;o>1&&W(`vertex codec version ${o} is not supported (only versions 0 and 1)`);let s=n>>2,c=o===1;c&&i<1+n+s&&W(`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&&W(`truncated vertex stream`),u=h,h+=s);for(let e=0;e<n;e++){let t=e*256,n=Or;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+Dr&&W(`truncated vertex stream`);for(let e=0;e<o;e++)m[t+e]=r[h+e];h+=o;continue}n=kr[a]}let a=l+3>>2;h+a>i&&W(`truncated vertex stream`);let s=h;h+=a;for(let e=0;e<l;e++){i-h<Dr&&W(`truncated vertex stream`);let a=r[s+(e>>2)]>>(e&3)*2&3;h=fr(r,h,n[a],m,t+e*16)}}c&&!g&&(g=mr(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]+Ar(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=jr(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&&W(`vertex stream has trailing or missing data`),c&&!g&&mr(r,d,s)}function mr(e,t,n){for(let r=0;r<n;r++){let n=e[t+r],i=n&15;(i>2||i<2&&n>>4)&&W(`invalid vertex channel mode`)}return!0}function hr(e,t){let n=0,r=0,i=t.pos;for(let t=0;;t++){i>=e.length&&W(`truncated index stream`);let a=e[i++];if(n|=(a&127)<<r,r+=7,a<128)break;t===4&&W(`index varint is longer than 5 bytes`)}return t.pos=i,n>>>0}function gr(e,t){(!Number.isSafeInteger(t)||t<0||e.length<t)&&G(`invalid count or output size`)}function _r(e,t){return t>65535&&e instanceof Uint16Array&&W(`index ${t} does not fit a 16-bit index buffer`),t}function vr(e,t,n){gr(e,t),t%3!=0&&W(`TRIANGLES count must be a multiple of 3`);let r=t/3,i=n.length;i<1+r+16&&W(`truncated index stream`);let a=n[0];a>>4!=14&&W(`bad index stream header`);let o=a&15;o>1&&W(`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)&&W(`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&&W(`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=hr(n,x);return b=b+(e&1?~(e>>>1):e>>>1)>>>0,b};for(let t=0;t<r;t++){x.pos>c&&W(`truncated index stream`);let r=n[1+t],i=r>>4,a=r&15,o,d,p;if(i<15){i>=m&&W(`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]=_r(e,o),e[t*3+1]=_r(e,d),e[t*3+2]=_r(e,p)}x.pos!==c&&W(`index stream has trailing or missing data`)}function yr(e,t,n){gr(e,t);let r=n.length;r<1+t+4&&W(`truncated index sequence`);let i=n[0];i>>4!=13&&W(`bad index sequence header`);let a=i&15;a>1&&W(`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&&W(`truncated index sequence`);let t=hr(n,c),i=t&1,a=s[i]+(t&2?~(t>>>2):t>>>2)>>>0;s[i]=a,e[r]=_r(e,a)}c.pos!==o&&W(`index sequence has trailing or missing data`)}function br(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=K(K(e*e)+K(K(t*t)+K(n*n)));if(c===0){s(r,0),s(r+a,0),s(r+2*a,0);continue}let l=K(i/K(Math.sqrt(c)));s(r,q(K(e*l))),s(r+a,q(K(t*l))),s(r+2*a,q(K(n*l)))}}function xr(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=K(K(2*K(s*s))-K(K(t*t)+K(K(n*n)+K(i*i)))),l=K(Math.sqrt(Math.max(c,0))),u=K(Ir/s);e.setInt16(r+(o+1&3)*2,q(K(t*u)),!0),e.setInt16(r+(o+2&3)*2,q(K(n*u)),!0),e.setInt16(r+(o+3&3)*2,q(K(i*u)),!0),e.setInt16(r+o*2,q(K(l*u)),!0)}}function Sr(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 Cr(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=K(i/d),p=e+t-n,m=e+n,h=e-t-n,g=u<<1&d|u&1;l(r,Fr(K(p*f))&a),l(r+o,Fr(K(m*f))&a),l(r+2*o,Fr(K(h*f))&a),l(r+3*o,Fr(K(g*f))&a)}}function wr(e,t,n,r){let i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(r){case`OCTAHEDRAL`:n!==4&&n!==8&&W(`OCTAHEDRAL filter requires byteStride 4 or 8`),br(i,t,n);return;case`QUATERNION`:n!==8&&W(`QUATERNION filter requires byteStride 8`),xr(i,t);return;case`EXPONENTIAL`:Sr(i,t*n>>2);return;case`COLOR`:n!==4&&n!==8&&W(`COLOR filter requires byteStride 4 or 8`),Cr(i,t,n);return;default:W(`unknown filter '${r}'`)}}function Tr(e,t,n,r,i=`NONE`){(!Number.isSafeInteger(t)||t<0||!Number.isSafeInteger(n)||n<=0||t*n>2**31)&&G(`invalid count or byteStride`);let a=e.length;t>lr(r,a,n)&&G(`truncated stream (${t} elements cannot fit in ${a} bytes)`);let o;if(r===`ATTRIBUTES`)o=new Uint8Array(t*n),pr(o,t,n,e);else if(r===`TRIANGLES`||r===`INDICES`){n!==2&&n!==4&&W(`${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`?vr(i,t,e):yr(i,t,e)}else return W(`unknown mode '${r}'`);return i&&i!==`NONE`&&(r!==`ATTRIBUTES`&&W(`filters only apply to ATTRIBUTES`),wr(o,t,n,i)),o}var Er,W,G,Dr,Or,kr,Ar,jr,K,Mr,q,Nr,Pr,Fr,Ir,Lr,Rr=t((()=>{xe(),ur(),Er=`EXT_meshopt_compression: `,W=e=>{throw I(Er+e)},G=e=>{throw RangeError(Er+e)},Dr=24,Or=[0,2,4,8],kr=[[0,1,2,4],[1,2,4,8]],Ar=e=>(e&1?~(e>>1):e>>1)&255,jr=e=>(e&1?~(e>>1):e>>1)&65535,K=Math.fround,Mr=12582912,q=e=>K(e+Mr)-Mr,Nr=new Float32Array(1),Pr=new Uint32Array(Nr.buffer),Fr=e=>(Nr[0]=e+Mr,Pr[0]),Ir=K(32767/Math.SQRT2),Lr={supported:!0,ready:Promise.resolve(),decodeGltfBuffer(e,t,n,r,i,a){let o=Tr(r,t,n,i,a);e.byteLength<t*n&&G(`target buffer is too small`),e.set(o)}}})),zr=n({decompressPrimitive:()=>Vr,decompressPrimitives:()=>Br});async function Br(e,{signal:t,draco:n}={}){t?.throwIfAborted();let r,i=async()=>{if(!n){let{DracoDecoder:i}=await xi(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 Vr(e,r,i,t)}finally{r?.dispose()}}async function Vr(e,t,n,r){let i=ar.get(e)??new Map;ar.set(e,i);let o=t.extensions?.KHR_draco_mesh_compression;if(!o||i.has(t))return;if((t.mode??4)!==4)throw a(`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=Y(e.doc.accessors,t.attributes?.POSITION,`Draco POSITION`),d=J(u.count,`Draco vertex count`,3);if(d>16777216)throw a(`unsupported`,`glTF primitive has more than ${P} 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=Y(e.doc.accessors,t.attributes?.[n],`Draco attribute`),a=J(i.count,`Draco accessor count`,1),o=Object.hasOwn(Ur,i.type)?Ur[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]=J(i.componentType,`Draco component type`),c[n]=J(r,`Draco attribute id`),l[n]=o}let p=t.indices===void 0?void 0:Y(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=J(p.count,`Draco index count`,1);if(e>Hr||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(Hr,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=J(_.vertexCount,`Draco vertex count`,3),y=_.indices;if(v>16777216||!(y instanceof Uint16Array||y instanceof Uint32Array)||!y.length||y.length>Hr||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=Y(e.doc.accessors,r,`Draco attribute`),a=Object.hasOwn(Wr,n)?Wr[n]:void 0,o=_.attributes?.[n],s=a?_[a]:o?.array;if(!ArrayBuffer.isView(s)||s instanceof DataView||i.count!==v||s.length!==v*Ur[i.type]||!a&&(o?.itemSize!==Ur[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=Gr[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),i.set(t,t.indices===void 0?b:e.accessor(t.indices,`SCALAR`))}var Hr,Ur,Wr,Gr,Kr=t((()=>{l(),Gi(),or(),re(),Hr=3*P,Ur={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Wr={POSITION:`positions`,NORMAL:`normals`,TEXCOORD_0:`uvs`,COLOR_0:`colors`},Gr={5120:127,5121:255,5122:32767,5123:65535}})),qr=n({analyzeVertexCache:()=>Xr,optimizeMesh:()=>ni,optimizeOverdraw:()=>$r,optimizeVertexCache:()=>Qr,optimizeVertexFetch:()=>ti,vertexFetchRemap:()=>ei});function Jr(e,t,n){if(e.length%3)throw RangeError(`${n} needs whole triangles; pass 3 indices per face`);if(t!==void 0&&!(Number.isInteger(t)&&t>=0))throw RangeError(`${n} vertex count ${t} is invalid; pass an integer >= 0`);let r=-1;for(let t=0;t<e.length;t++){let i=e[t];if(!Number.isInteger(i)||i<0)throw RangeError(`${n} index ${i} is invalid; pass integers >= 0`);i>r&&(r=i)}if(t!==void 0&&r>=t)throw RangeError(`${n} index ${r} is past ${t} vertices; fix the indices`);return t??r+1}function Yr(e,t){if(!Number.isInteger(e)||e<3)throw RangeError(`${t} cache size ${e} is invalid; pass an integer >= 3`)}function Xr(e,t,n=16){let r=Jr(e,t,`analyzeVertexCache`);Yr(n,`analyzeVertexCache`);let i=new Float64Array(r).fill(-1/0),a=new Uint8Array(r),o=0,s=0,c=0;for(let t=0;t<e.length;t++){let r=e[t];a[r]||(a[r]=1,c++),!(o-i[r]<=n)&&(i[r]=++o,s++)}return{misses:s,acmr:e.length?s/(e.length/3):0,atvr:c?s/c:0}}function Zr(e,t){return t===0?-1:(e<0?0:ii[e])+2/Math.sqrt(t)}function Qr(e,t){let n=Jr(e,t,`optimizeVertexCache`),r=e.length/3,i=new Uint32Array(e.length),a=new Uint32Array(n+1),o=new Uint32Array(n);for(let t=0;t<e.length;t++)a[e[t]+1]++;for(let e=0;e<n;e++)a[e+1]+=a[e];let s=new Uint32Array(e.length),c=a.slice(0,n);for(let t=0;t<e.length;t++){let n=e[t];s[c[n]++]=t/3|0,o[n]++}let l=new Float64Array(n),u=new Float64Array(r),d=new Uint8Array(r);for(let e=0;e<n;e++)l[e]=Zr(-1,o[e]);for(let t=0;t<r;t++)u[t]=l[e[t*3]]+l[e[t*3+1]]+l[e[t*3+2]];let f=new Int32Array(35),p=new Int32Array(35),m=0,h=0,g=-1;for(let t=0;t<r;t++){if(g<0){for(;d[h];)h++;g=h}let n=e[g*3],r=e[g*3+1],c=e[g*3+2];i[t*3]=n,i[t*3+1]=r,i[t*3+2]=c,d[g]=1;for(let t=0;t<3;t++){let n=e[g*3+t],r=a[n],i=r+o[n]-1;for(let e=r;e<=i;e++)if(s[e]===g){s[e]=s[i];break}o[n]--}let _=0;p[_++]=n,r!==n&&(p[_++]=r),c!==n&&c!==r&&(p[_++]=c);for(let e=0;e<m;e++){let t=f[e];if(t!==n&&t!==r&&t!==c&&(p[_++]=t),_===p.length)break}let v=f;f=p,p=v,m=_;for(let e=0;e<m;e++){let t=f[e],n=Zr(e<ri?e:-1,o[t]),r=n-l[t];l[t]=n;for(let e=a[t],n=e+o[t];e<n;e++)u[s[e]]+=r}m>ri&&(m=ri);let y=-1/0;g=-1;for(let e=0;e<m;e++){let t=f[e];for(let e=a[t],n=e+o[t];e<n;e++)u[s[e]]>y&&(y=u[s[e]],g=s[e])}}return i}function $r(e,t,n={}){let{threshold:r=1.05,cacheSize:i=16}=n;if(t.length%3)throw RangeError(`optimizeOverdraw positions must be xyz per vertex; fix the array`);let a=Jr(e,t.length/3,`optimizeOverdraw`);if(Yr(i,`optimizeOverdraw`),!(r>=1&&r<1/0))throw RangeError(`optimizeOverdraw threshold ${r} is invalid; pass a finite number >= 1`);let o=e.length/3,s=Xr(e,a,i).acmr*r,c=new Float64Array(a).fill(-1/0),l=[],u=0,d=0,f=0;for(let t=0;t<o;t++){t-f>=16&&d/(t-f)<=s&&(l.push(t),f=t,d=0,u+=i+1);let n=0;for(let r=0;r<3;r++){let a=e[t*3+r];u-c[a]<=i||(c[a]=++u,n++)}(t===0||t>f&&n===3)&&(l.push(t),f=t,d=0),d+=n}let p=l.length,m=new Float64Array(p*3),h=new Float64Array(p*3),g=new Float64Array(p),_=[0,0,0],v=0;for(let n=0;n<p;n++){let r=n+1<p?l[n+1]:o;for(let i=l[n];i<r;i++){let r=e[i*3]*3,a=e[i*3+1]*3,o=e[i*3+2]*3,s=t[a]-t[r],c=t[a+1]-t[r+1],l=t[a+2]-t[r+2],u=t[o]-t[r],d=t[o+1]-t[r+1],f=t[o+2]-t[r+2],p=c*f-l*d,y=l*u-s*f,b=s*d-c*u,x=Math.hypot(p,y,b);h[n*3]+=p,h[n*3+1]+=y,h[n*3+2]+=b,g[n]+=x;for(let e=0;e<3;e++){let i=(t[r+e]+t[a+e]+t[o+e])/3;m[n*3+e]+=i*x,_[e]+=i*x}v+=x}}let y=new Float64Array(p),b=Array.from({length:p},(e,t)=>t);for(let e=0;e<p;e++){let t=Math.hypot(h[e*3],h[e*3+1],h[e*3+2]);if(!(t>0&&g[e]>0&&v>0))continue;let n=0;for(let t=0;t<3;t++)n+=(m[e*3+t]/g[e]-_[t]/v)*h[e*3+t];y[e]=n/t}b.sort((e,t)=>y[t]-y[e]||e-t);let x=new Uint32Array(e.length),S=0;for(let t of b){let n=(t+1<p?l[t+1]:o)*3;for(let r=l[t]*3;r<n;r++)x[S++]=e[r]}return x}function ei(e,t){let n=Jr(e,t,`vertexFetchRemap`),r=new Uint32Array(n).fill(4294967295),i=0;for(let t=0;t<e.length;t++)r[e[t]]===4294967295&&(r[e[t]]=i++);return r}function ti(e){let t=e.positions.length/3,n=ei(e.indices,t),r=0;for(let e=0;e<t;e++)n[e]!==4294967295&&r++;let i=(e,i)=>{if(e.length!==t*i)return e.slice();let a=new Float32Array(r*i);for(let r=0;r<t;r++)if(n[r]!==4294967295)for(let t=0;t<i;t++)a[n[r]*i+t]=e[r*i+t];return a},a=new Uint32Array(e.indices.length);for(let t=0;t<a.length;t++)a[t]=n[e.indices[t]];let o={positions:i(e.positions,3),normals:i(e.normals,3),uvs:i(e.uvs,2),indices:a};return e.tangents&&(o.tangents=i(e.tangents,4)),e.groups&&(o.groups=e.groups.map(e=>({...e}))),o}function ni(e,t={}){let{overdraw:n=!0,...r}=t,i=e.indices.length,a=e.positions.length/3,o=new Set([0,i]);for(let{start:t,count:n}of e.groups??[]){let e=t+n;if(!(Number.isInteger(t)&&Number.isInteger(e)&&t>=0&&e<=i)||t%3||e%3)throw RangeError(`optimizeMesh group ${t}+${n} is invalid; groups must cover whole triangles`);o.add(t).add(e)}let s=[...o].sort((e,t)=>e-t),c=new Uint32Array(i);for(let t=0;t+1<s.length;t++){let i=Qr(e.indices.subarray(s[t],s[t+1]),a);n&&(i=$r(i,e.positions,r)),c.set(i,s[t])}return ti({...e,indices:c})}var ri,ii,ai=t((()=>{ri=32,ii=Float64Array.from({length:ri},(e,t)=>t<3?.75:(1-(t-3)/29)**1.5)}));function oi(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 si(e,t){if(!(e.length<23)){for(let t=0;t<23;t++)if(e[t]!==ji.charCodeAt(t))return;throw a(`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 ci(e=Ai){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`maxDownloadBytes must be a positive integer`);return e}function J(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 Y(e,t,n){let r=e?.[J(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 li(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 ui(e){let t=typeof e==`string`?e:li(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 h(t)}catch(e){throw e instanceof SyntaxError?TypeError(`Invalid glTF JSON: `+e.message):e}}function di(e){if(!e||typeof e!=`object`||!d(e.asset))throw TypeError(`Expected glTF 2.0`);let t=e;for(let e of Ii)if(!Q(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(!Q(t.primitives)||!(t.primitives??[]).every(e=>Q(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(!Q(t.samplers)||!Q(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 fi(e,t=Ai){if(typeof e==`string`){if(e.length>t)throw X(`glTF JSON exceeds byte budget`,t);let n=new TextEncoder().encode(e).byteLength;if(n>t)throw X(`glTF JSON exceeds byte budget`,t);return{doc:ui(e),sourceBytes:n}}if(!(e instanceof ArrayBuffer)&&!ArrayBuffer.isView(e))return{doc:e,sourceBytes:0};let n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(si(n,`The glTF input`),n.length>=4&&!oe(n)){if(n.length>t)throw X(`glTF JSON exceeds byte budget`,t);return{...fi(li(n),t),sourceBytes:n.byteLength}}if(n.length>t)throw X(`glTF exceeds download budget`,t);let r=ae(n);return{doc:ui(r[0].data),binary:r[1]?.type===5130562?r[1].data:void 0,sourceBytes:n.byteLength}}function pi(e,t=Ai){let n=/^data:[^;,]+;base64,([A-Za-z0-9+/]*={0,2})$/.exec(e);if(n&&n[1].length>t*4/3+4)throw X(`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 mi(e,t=!1){let n=e.extensions,r=n?.[$]!==void 0||!t||n?.MSFT_texture_dds===void 0?$:`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 J(i===void 0?e.source:i.source,`image source`)}function hi(e,t,n){let r=J(t,`accessor`),i=Y(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`?le[i.componentType]:void 0,o=typeof i.type==`string`&&Object.hasOwn(Li,i.type)?Li[i.type]:void 0,s=J(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 gi(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 u=new DataView(i.buffer,i.byteOffset,i.byteLength),d=e.componentType,f=e.normalized?Bi[d]??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=ce(u,l,d);if(f&&(e=Math.max(-1,e/f)),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 _i(e){let t=new Set;for(let n of e.textures??[])if(n?.extensions?.[$]!==void 0){let r=mi(n),i=Y(e.images,r,`KTX2 image`);if(i.mimeType!==void 0&&i.mimeType!==`image/ktx2`||i.bufferView!==void 0&&i.mimeType!==`image/ktx2`)throw TypeError(`KHR_texture_basisu requires image/ktx2`);t.add(r)}for(let n=0;n<(e.images?.length??0);n++)e.images[n]?.mimeType===`image/ktx2`&&t.add(n);return t}function vi(e,t=!1){let n=new Set,r=new Set;for(let i of e.textures??[])i?.extensions?.[$]!==void 0||t&&i?.extensions?.MSFT_texture_dds!==void 0?(r.add(mi(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(J(i.extensions.MSFT_texture_dds.source,`DDS image`)));for(let e of r)n.delete(e);return n}function yi(e,t,n){if(e.length<80||[171,75,84,88,32,50,48,187,13,10,26,10].some((t,n)=>e[n]!==t))throw TypeError(`Invalid glTF KTX2 header; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=r.getUint32(20,!0),a=r.getUint32(24,!0),o=r.getUint32(40,!0);if(!i||!a||i%4||a%4||i*a>67108864||i>(n?.limits.maxTextureDimension2D??16384)||a>(n?.limits.maxTextureDimension2D??16384)||r.getUint32(28,!0)||r.getUint32(32,!0)||r.getUint32(36,!0)!==1||!o||o>Math.floor(Math.log2(Math.max(i,a)))+1)throw RangeError(`Invalid glTF KTX2 dimensions or mip levels; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let s=0;for(let e=0;e<o;e++)s+=Math.max(1,i>>e)*Math.max(1,a>>e)*4;if(s>t.remainingDecodedBytes)throw RangeError(`glTF KTX2 exceeds decoded byte budget; load a smaller model, or reduce its textures and meshes`);return{width:i,height:a,levels:o}}function bi(e,t,n){let r={rgba8:[`rgba8unorm`,1,4],bc7:[`bc7-rgba-unorm`,4,16],"astc-4x4":[`astc-4x4-unorm`,4,16],etc2:[`etc2-rgba8unorm`,4,16]},i=e&&Object.hasOwn(r,e.target)?r[e.target]:void 0,a=typeof e?.format==`string`?e.format.replace(/-srgb$/,``):void 0;if(!i||a!==i[0]||e.width!==t.width||e.height!==t.height||!Array.isArray(e.mipmaps)||e.mipmaps.length!==t.levels||typeof e.srgb!=`boolean`||typeof e.hasAlpha!=`boolean`)throw TypeError(`Invalid transcoded glTF KTX2 image; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let o=0;for(let n=0;n<e.mipmaps.length;n++){let r=e.mipmaps[n],a=Math.max(1,t.width>>n),s=Math.max(1,t.height>>n),c=Math.ceil(a/i[1])*Math.ceil(s/i[1])*i[2];if(!r||r.width!==a||r.height!==s||!(r.data instanceof Uint8Array)||r.data.byteLength!==c||r.byteLength!==c)throw RangeError(`Invalid transcoded glTF KTX2 mip; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);o+=c}return n.reserveDecodedBytes(o),{ktx2:e,width:e.width,height:e.height,close(){}}}function xi(e,t){let n=e.hooks.decoderModule;if(!n)throw a(`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}function Si(e,t){let n=t.ktx2,r;return{async decode(i){t.signal?.throwIfAborted();let a=yi(i,e,t.device);if(!n){let{KTX2Decoder:i}=await xi(e,`KTX2`)();t.signal?.throwIfAborted(),n=r=new i({device:t.device})}let o=await n.transcode(i,{signal:t.signal});return t.signal?.throwIfAborted(),bi(o,a,e)},close(){r?.dispose()}}}function Ci(e=1){if(!Number.isInteger(e)||e<1||e>16)throw a(`unsupported`,`Invalid glTF maxAnisotropy; pass an integer from 1 to 16, or omit it for 1`);return e}async function wi(){let{optimizeOverdraw:e,optimizeVertexCache:t}=await Promise.resolve().then(()=>(ai(),qr));return(n,r,i)=>e(t(n,i),r)}async function Ti(e,t={},n,r={},i=!1,o=0){let s=`aborted`in t?{signal:t}:t,{signal:c,decoders:l={},buffers:u=[],fetch:d=globalThis.fetch,maxDownloadBytes:f,maxNodes:p,optimize:m,allowedURLs:h,maxPartVertices:g}=s,_=typeof n==`function`?n:void 0,v=typeof n==`function`?void 0:n,x=ci(f),S=te(g),C=Ci(s.maxAnisotropy);c?.throwIfAborted();let w=e===void 0?s.baseURL===void 0?void 0:new URL(s.baseURL,globalThis.location?.href):new URL(e,globalThis.location?.href),T=o,D=async(e,t=!1)=>{if(![`http:`,`https:`].includes(e.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`);let n=await d(e,{signal:c});t&&n.url?w=new URL(n.url):t||b(n,w??globalThis.location?.href,h,`glTF resource`);let r=await E(n,{maxBytes:x-T,signal:c,label:`glTF download`}).catch(e=>{throw e instanceof RangeError?X(e.message,x):e});return si(r,e.href),T+=r.length,r},O=t=>{if(w===void 0&&e===void 0)throw a(`state`,`glTF URI ${t} needs the file location, which a file in memory does not have; pass the baseURL option to parseGLTFAsync or load the file with loadGLTF`);return y(t,w??globalThis.location?.href,h,`glTF resource`)},{doc:k,binary:ee,sourceBytes:ne}=fi(v??await D(w,!0),x),A=[],j=[];if(v!=null){if(ne>x-T)throw X(`glTF exceeds download budget`,x);T+=ne}di(k);for(let e=0;e<(k.buffers?.length??0);e++){let t=Y(k.buffers,e,`buffer`);if(u[e]){let t=u[e];A[e]=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}else if(Z(t)?.fallback!==!0){if(!t.uri)e===0&&ee&&(A[e]=ee);else if(typeof t.uri!=`string`)throw TypeError(`Invalid glTF buffer uri; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);else if(t.uri.startsWith(`data:`)){let n=pi(t.uri,x);if(T+=n.length,T>x)throw X(`glTF exceeds download budget`,x);A[e]=n}else A[e]=await D(O(t.uri))}}let M=new Vi(k,A,ee,await er(k,l),x,p);Hi.set(M,C);let N=M.hooks;if(M.baseURL=w?.href,M.partVertices=S,m&&(M.reorder=await wi()),i&&ki(k))return{asset:M,images:j,deferred:!0,baseURL:w?.href,downloadedBytes:T};let P=_i(k),re=vi(k,!!N.dds),ie=Si(M,{...r,ktx2:r.ktx2??N.ktx2,signal:c}),ae=0;await M.decode(c);try{c?.throwIfAborted(),await _?.(M),c?.throwIfAborted();let e=[],t=async()=>{let[t,n]=e.shift(),r=await n;if(j[t]=r,ae+=r.width*r.height*4,r.width*r.height>67108864||ae>x*4)throw RangeError(`glTF images exceed decoded size limit; load a smaller model, or reduce its textures and meshes`);c?.throwIfAborted()};try{for(let n=0;n<(k.images?.length??0);n++){if(re.has(n))continue;let r=Y(k.images,n,`image`);if(P.has(n)&&N.textureStream){j[n]=await N.textureStream.open(r.bufferView===void 0?typeof r.uri==`string`&&r.uri.startsWith(`data:`)?{bytes:pi(r.uri,x)}:{url:O(r.uri).href}:{bytes:M.view(r.bufferView)},n);continue}let i;if(r.bufferView!==void 0)i=M.view(r.bufferView);else if(typeof r.uri==`string`&&r.uri.startsWith(`data:`)){if(i=pi(r.uri,x),T+=i.length,T>x)throw X(`glTF exceeds download budget`,x)}else if(typeof r.uri==`string`)i=await D(O(r.uri));else throw TypeError(`Invalid glTF image; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);if(N.dds&&k.textures?.some(e=>!e.extensions?.KHR_texture_basisu&&e.extensions?.MSFT_texture_dds?.source===n)){if(r.mimeType!==void 0&&r.mimeType!==`image/vnd-ms.dds`||r.bufferView!==void 0&&r.mimeType!==`image/vnd-ms.dds`)throw TypeError(`MSFT_texture_dds requires image/vnd-ms.dds`);for(;e.length;)await t();e.push([n,Promise.resolve(N.dds.decode(i,{signal:c}))]),await t()}else if(P.has(n)){for(;e.length;)await t();e.push([n,ie.decode(i)]),await t()}else{let a=Ei(i,r.mimeType,n,c);a.catch(()=>{}),e.push([n,a]),e.length>=Ui&&await t()}}for(;e.length;)await t()}finally{for(let[,t]of e.splice(0))t.then(e=>Di([e]),()=>{})}return{asset:M,images:j}}catch(e){throw Di(j),e}finally{ie.close()}}async function Ei(e,t,n,r){r?.throwIfAborted();try{if(typeof createImageBitmap!=`function`)return await sr(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`)}}function Di(e){for(let t of e){if(!t)continue;let e=Wi.get(t);e?Wi.set(t,e-1):`close`in t&&t.close?.()}}var Oi,ki,Ai,X,ji,Mi,Ni,Pi,Fi,Z,Ii,Q,Li,Ri,zi,$,Bi,Vi,Hi,Ui,Wi,Gi=t((()=>{l(),u(),f(),g(),S(),D(),ee(),re(),se(),ue(),nr(),pe(),or(),cr(),Oi=e=>!!e.meshes?.some(e=>e?.primitives?.some(e=>e?.extensions?.KHR_draco_mesh_compression))||fe(e),ki=e=>Oi(e)||!!e.textures?.some(e=>e?.extensions?.KHR_texture_basisu)||!!e.images?.some(e=>e?.mimeType===`image/ktx2`),Ai=536870912,X=(e,t)=>RangeError(`${e} (${t} bytes; raise the maxDownloadBytes option)`),ji=`version https://git-lfs`,Mi=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(`.`)),Ni={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`},Fi=[`EXT_meshopt_compression`,`KHR_meshopt_compression`],Z=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},Ii=[`buffers`,`bufferViews`,`accessors`,`meshes`,`nodes`,`scenes`,`materials`,`textures`,`images`],Ii.push(`samplers`,`skins`,`animations`,`cameras`),Q=e=>e===void 0||Array.isArray(e)&&e.every(e=>!!e&&typeof e==`object`&&!Array.isArray(e)),Li={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},Ri=`EXT_meshopt_compression`,zi=`KHR_draco_mesh_compression`,$=`KHR_texture_basisu`,Bi={5120:127,5121:255,5122:32767,5123:65535},Vi=class{get remainingDecodedBytes(){return this.maxBytes*4-this.decoded}reserveDecodedBytes(e){if(J(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={},i=Ai,o=1e5){this.doc=e,this.hooks=r,this.maxBytes=i,this.maxNodes=o,this.cache=new Map,this.viewCache=new Map,this.decoded=0,this.partVertices=j,ci(i),O(`maxNodes`,o),di(e);let s=(e.extensionsRequired??[]).filter(e=>!Mi.has(e)&&![zi,Ri,`KHR_meshopt_compression`,$].includes(e)&&!r[Ni[e]]&&!(r.materials&&r.materials.extensions?.includes(e)));if(s.length)throw a(`unsupported`,`Required glTF extensions are unsupported: `+s.map(e=>Ni[e]?e+` (pass a `+Ni[e]+` decoder)`:e).join(`, `)+`; pass the listed decoders or re-export the model without them`);k(`Too many glTF nodes`,e.nodes?.length??0,o,`maxNodes`);let c=0;this.buffers=(e.buffers??[]).map((r,a)=>{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=J(r.byteLength,`buffer length`,1),s=Z(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 l=t[a],u=(!l||l.byteLength===0)&&!r.uri&&(a!==0||!n);if(s===!0||u&&Fi.some(t=>e.extensionsRequired?.includes(t))){let t=Fi.find(e=>r.extensions?.[e]!==void 0),n=(e.bufferViews??[]).filter(e=>e?.buffer===a);if(!n.length||n.some(e=>!Z(e)||t!==void 0&&!e.extensions?.[t])||e.bufferViews?.some(e=>Z(e)?.buffer===a))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 d=l?l instanceof ArrayBuffer?new Uint8Array(l):new Uint8Array(l.buffer,l.byteOffset,l.byteLength):r.uri?pi(r.uri,i):a===0?n:void 0;if(!d||o>d.length)throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`);if(a===0&&n&&(l===n||d===n)&&ie(n.length,o),c+=d.byteLength,c>i)throw X(`glTF buffers exceed byte budget`,i);return d.subarray(0,o)})}view(e){let t=J(e,`bufferView`),n=Y(this.doc.bufferViews,t,`bufferView`),r=J(n.buffer,`buffer reference`),i=this.buffers[r],o=J(n.byteOffset??0,`view offset`),s=J(n.byteLength,`view length`,1),c=J(Y(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=Z(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[J(l.buffer,`meshopt buffer reference`)],i=J(l.byteOffset??0,`meshopt offset`),o=J(l.byteLength,`meshopt length`,1),c=J(l.count,`meshopt count`,1),u=J(l.byteStride,`meshopt stride`,1),d=l.mode,f=l.filter??`NONE`;if(!r||o>r.length||i>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(i,i+o),m;if(this.hooks.meshopt)m=new Uint8Array(s),this.hooks.meshopt.decodeGltfBuffer(m,c,u,p,d,f);else{if(!Pi)throw a(`state`,`Meshopt geometry requires parseGLTFAsync or loadGLTF, or a meshopt decoder passed in decoders (or asset.decode() first)`);m=Pi(p,c,u,d,f)}return this.reserveDecodedBytes(m.byteLength),this.viewCache.set(t,m),m}if(!i||o+s>i.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 i.subarray(o,o+s)}setDecodedAccessor(e,t){let{index:n,width:r,count:i}=hi(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(){Pi||this.hooks.meshopt||this.doc.bufferViews?.some(e=>e?.extensions?.EXT_meshopt_compression||e?.extensions?.KHR_meshopt_compression)&&(Pi=(await Promise.resolve().then(()=>(Rr(),dr))).meshoptDecodeGltfBuffer)}async decode(e){if(await this.prepareMeshopt(),!rr(this))return e?.throwIfAborted();let{decompressPrimitives:t}=await Promise.resolve().then(()=>(Kr(),zr));await t(this,{signal:e,draco:this.hooks.draco&&oi(this.hooks.draco)})}accessor(e,t,n=!0){let{index:r,def:i,size:o,width:s,count:c}=hi(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(i.bufferView!==void 0){let e=Y(this.doc.bufferViews,i.bufferView,`bufferView`),t=J(e.byteStride??o*s,`stride`,o*s);if(t>252||J(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`);gi(i,o,s,u,this.view(i.bufferView),J(i.byteOffset??0,`accessor offset`),t,c,n)}else{if(this.dracoOwned(r))throw a(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);if(i.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(i.sparse){let e=this.sparseIds(i,c),t=i.sparse.values;gi(i,o,s,u,this.view(t.bufferView),J(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}=hi(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 gi(r,i,a,t,this.view(n.bufferView),J(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?.[zi]&&(t.indices===e||Object.keys(t.extensions[zi].attributes??{}).some(n=>t.attributes?.[n]===e))))}sparseIds(e,t){let n=e.sparse,r=J(n.count,`sparse count`,1),i=n.indices,a=n.values,o=le[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=J(i.byteOffset??0,`sparse offset`);if(c%o||c+r*o>s.length||Y(this.doc.bufferViews,i.bufferView,`sparse indices`).byteStride!==void 0||Y(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=[],d=-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<=d||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),d=r}return u}},Hi=new WeakMap,Ui=8,Wi=new WeakMap}));or(),Gi(),l(),re();function Ki(e){if(!e||typeof e!=`object`)return!1;for(let[t,n]of Object.entries(e))if(t===`texCoord`?n>1:Ki(n))return!0;return!1}function qi(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(Ki(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 Ji(e,t,n){ir(e,t);try{return Xi(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 Yi(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 Xi(e,t,n){let r=t.mode??4,i=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(Y(e.doc.accessors,o.POSITION,`POSITION`).count>16777216)throw a(`unsupported`,`glTF primitive has more than ${P} 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<i)throw RangeError(`Expected bounded triangle geometry`);for(let t of[`POSITION`,`NORMAL`,`TANGENT`])if(o[t]!==void 0&&!u){let n=Y(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=Y(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=ir(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=Yi(m,r),!m.length||m.length%i)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(Y(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&&i===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?A(m,i,l,d,h?null:c):null;if(e.reorder&&i===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=qi(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 T=(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},E=(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)},D=i<3?{topology:i===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++)T(e,t,t*20);if(t)for(let e=0;e<l;e++)E(t,e,e*4);let r={vertices:e,indices:m,...D,...t?{uvs:t}:{}};return n?(n(r),[]):[r]}let O=[];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++)T(a,r[e],e*20);if(o)for(let e=0;e<i;e++)E(o,r[e],e*4);let s={vertices:a,indices:t,...D,...o?{uvs:o}:{},part:{index:e,count:g.length,vertexMap:r}};n?n(s):O.push(s)}return O}function Zi(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}Gi();function Qi(e,t){let n=e.doc,r=e=>{try{return e()}catch{return null}},i=0,a=(n.meshes??[]).map(t=>(Array.isArray(t?.primitives)?t.primitives:[]).map(t=>{let n=r(()=>Ji(e,t));for(let e of n??[])i+=e.vertices.byteLength+e.indices.byteLength+(e.uvs?.byteLength??0);if(i>e.maxBytes*4)throw X(`Decoded glTF geometry exceeds byte budget`,e.maxBytes*4);return n&&n.length===1?n[0]:n}));return Zi(e),{doc:n,buffers:e.buffers,images:t,geometry:a,accessors:[...e.cache],maxDownloadBytes:e.maxBytes,maxNodes:e.maxNodes,maxPartVertices:e.partVertices}}async function $i(e,t,n,r,i,a,o,s){let{asset:c,images:l,deferred:u,baseURL:d,downloadedBytes:f}=await Ti(e,{buffers:n,maxDownloadBytes:r,maxNodes:i,allowedURLs:a,optimize:o,maxPartVertices:s},t,{},!0);return u?{doc:c.doc,buffers:c.buffers,images:l,geometry:[],accessors:[],maxDownloadBytes:c.maxBytes,maxNodes:c.maxNodes,maxPartVertices:c.partVertices,deferred:u,baseURL:d,downloadedBytes:f}:Qi(c,l)}i(({url:e,input:t,buffers:n,maxDownloadBytes:r,maxNodes:i,allowedURLs:a,maxPartVertices:o})=>$i(e,t,n,r,i,a,void 0,o))})();
|