@margoengine/gltf 0.0.0-stage → 0.1.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.
Files changed (129) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +1438 -3
  4. package/dist/accessor-DuqjpuxI.js +1 -0
  5. package/dist/accessor-nVsu_f1L.js +1 -0
  6. package/dist/accessor.d.ts +12 -0
  7. package/dist/asset-1b8ejkZX.js +4 -0
  8. package/dist/asset-entry.d.ts +1 -0
  9. package/dist/asset-entry.js +1 -0
  10. package/dist/asset.d.ts +319 -0
  11. package/dist/audio.d.ts +47 -0
  12. package/dist/audio.js +1 -0
  13. package/dist/auto.d.ts +29 -0
  14. package/dist/auto.js +1 -0
  15. package/dist/base-textures.d.ts +20 -0
  16. package/dist/coalesce.d.ts +29 -0
  17. package/dist/compression-D4IkO5vE.js +1 -0
  18. package/dist/compression.d.ts +15 -0
  19. package/dist/coordinates.d.ts +1 -0
  20. package/dist/coordinates.js +1 -0
  21. package/dist/dds.d.ts +7 -0
  22. package/dist/dds.js +1 -0
  23. package/dist/decoder-default-CxLH8Vz0.js +1 -0
  24. package/dist/decoder-default.d.ts +5 -0
  25. package/dist/default-materials.d.ts +8 -0
  26. package/dist/draco-state.d.ts +7 -0
  27. package/dist/draw-batch.d.ts +83 -0
  28. package/dist/draw-memo.d.ts +136 -0
  29. package/dist/errors-THVaUwlL.js +1 -0
  30. package/dist/extended.d.ts +12 -0
  31. package/dist/extended.js +1 -0
  32. package/dist/gltf.worker.d.ts +1 -0
  33. package/dist/group.d.ts +6 -0
  34. package/dist/image-limit-DvFSfR5T.js +1 -0
  35. package/dist/image-limit.d.ts +6 -0
  36. package/dist/index.d.ts +84 -0
  37. package/dist/index.js +1 -0
  38. package/dist/instanced-shader-BebTnbkj.js +5 -0
  39. package/dist/instanced-shader.d.ts +14 -0
  40. package/dist/instancing.d.ts +9 -0
  41. package/dist/instancing.js +1 -0
  42. package/dist/interactivity-graph.d.ts +193 -0
  43. package/dist/interactivity-model.d.ts +94 -0
  44. package/dist/interactivity-ops.d.ts +20 -0
  45. package/dist/interactivity.d.ts +33 -0
  46. package/dist/interactivity.js +1 -0
  47. package/dist/lights.d.ts +98 -0
  48. package/dist/lights.js +1 -0
  49. package/dist/limits-_LZ441oV.js +1 -0
  50. package/dist/material-draw-state-BHeTb1FP.js +1 -0
  51. package/dist/material-draw-state.d.ts +7 -0
  52. package/dist/material-draw.d.ts +18 -0
  53. package/dist/material-draw.js +1 -0
  54. package/dist/material-extension.d.ts +96 -0
  55. package/dist/mesh-source-DvU8YvMc.js +1 -0
  56. package/dist/meshopt.d.ts +9 -0
  57. package/dist/meshopt.js +1 -0
  58. package/dist/metadata.d.ts +114 -0
  59. package/dist/metadata.js +1 -0
  60. package/dist/model-entry.d.ts +2 -0
  61. package/dist/model-entry.js +1 -0
  62. package/dist/model-iRvuj19h.js +39 -0
  63. package/dist/model.d.ts +1011 -0
  64. package/dist/node-image-decode.d.ts +6 -0
  65. package/dist/node-matrix-R9BipGnp.js +1 -0
  66. package/dist/node-matrix.d.ts +16 -0
  67. package/dist/occlusion.d.ts +8 -0
  68. package/dist/optimize-7SEzNA23.js +1 -0
  69. package/dist/pack-BVDYuqZe.js +1 -0
  70. package/dist/pack.d.ts +27 -0
  71. package/dist/parts.d.ts +54 -0
  72. package/dist/pbr-instancing.d.ts +83 -0
  73. package/dist/pbr-instancing.js +1 -0
  74. package/dist/pbr.d.ts +13 -0
  75. package/dist/pbr.js +1 -0
  76. package/dist/physics.d.ts +148 -0
  77. package/dist/physics.js +1 -0
  78. package/dist/prepare.d.ts +26 -0
  79. package/dist/prepare.js +1 -0
  80. package/dist/progressive.d.ts +59 -0
  81. package/dist/progressive.js +4 -0
  82. package/dist/progressive.worker.d.ts +1 -0
  83. package/dist/quantized.d.ts +8 -0
  84. package/dist/quantized.js +1 -0
  85. package/dist/render-state.d.ts +18 -0
  86. package/dist/replica.d.ts +37 -0
  87. package/dist/report.d.ts +128 -0
  88. package/dist/report.js +1 -0
  89. package/dist/scene-data.d.ts +61 -0
  90. package/dist/scene-data.js +1 -0
  91. package/dist/scene-scope-CZDEkd24.js +4 -0
  92. package/dist/scene.d.ts +61 -0
  93. package/dist/scene.js +4 -0
  94. package/dist/shader-DPqfUcmp.js +405 -0
  95. package/dist/shader.d.ts +222 -0
  96. package/dist/shared/caster.d.ts +152 -0
  97. package/dist/shared/gltf.d.ts +257 -0
  98. package/dist/shared/iridescence.d.ts +2 -0
  99. package/dist/shared/prepared-geometry.d.ts +8 -0
  100. package/dist/side-shader.d.ts +1 -0
  101. package/dist/soft-mesh.d.ts +94 -0
  102. package/dist/soft-mesh.js +4 -0
  103. package/dist/spec-gloss.d.ts +21 -0
  104. package/dist/spec-gloss.js +18 -0
  105. package/dist/splat-state.d.ts +7 -0
  106. package/dist/splats.d.ts +18 -0
  107. package/dist/splats.js +1 -0
  108. package/dist/src-WMRHArDp.js +4 -0
  109. package/dist/stream-C3bKMy1B.js +1 -0
  110. package/dist/stream.d.ts +87 -0
  111. package/dist/texture-coordinates-XFsEMdU6.js +2 -0
  112. package/dist/texture-coordinates.d.ts +26 -0
  113. package/dist/texture-stream-Cu_XpyVO.js +4 -0
  114. package/dist/texture-stream.d.ts +88 -0
  115. package/dist/textured.d.ts +34 -0
  116. package/dist/textured.js +5 -0
  117. package/dist/uniform-arena.d.ts +78 -0
  118. package/dist/unit-light-DvtsuFYP.js +109 -0
  119. package/dist/version-BmU1nesQ.js +1 -0
  120. package/dist/version.d.ts +8 -0
  121. package/dist/vertex-inputs.d.ts +47 -0
  122. package/dist/view-uniform.d.ts +13 -0
  123. package/dist/visibility-C_Oqz9Sr.js +1 -0
  124. package/dist/worker-CY1TQnYX.js +1 -0
  125. package/dist/worker.d.ts +21 -0
  126. package/dist/worker.js +4 -0
  127. package/dist/workers/gltf.js +322 -0
  128. package/dist/workers/progressive.js +1 -0
  129. package/package.json +213 -6
@@ -0,0 +1 @@
1
+ var e={__proto__:null,5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function t(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)}export{t as n,e as t};
@@ -0,0 +1 @@
1
+ import{n as e,t}from"./accessor-DuqjpuxI.js";import{MargoError as n}from"@margoengine/math/errors";var r=(e,t,n=0)=>{if(typeof e!=`number`||!Number.isSafeInteger(e)||e<n)throw TypeError(`Invalid glTF ${t}; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return e},i=(e,t,n)=>{let i=e?.[r(t,n)];if(!i||typeof i!=`object`||Array.isArray(i))throw TypeError(`Missing glTF ${n}; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return i},a=/* @__PURE__ */ new Map([[5120,127],[5121,255],[5122,32767],[5123,65535]]);function o({doc:o,buffers:s},c,l,u,d=!1){let f=i(o.accessors,c,`accessor`);if(f.bufferView===void 0&&!f.sparse){if(!u(f))throw new n(`unsupported`,`Unsupported glTF accessor; use float positions and unsigned integer indices, add @margoengine/gltf/quantized for quantized meshes, or use @margoengine/gltf/pbr`);let e=r(f.count,`accessor count`,1);if(e>1e6)throw new n(`unsupported`,`glTF accessor holds over one million values, the limit of the light loader; use @margoengine/gltf/pbr`);return d?new Uint32Array(e):new Float32Array(e*l)}let p=i(o.bufferViews,f.bufferView,`bufferView`),m=s[r(p.buffer,`buffer reference`)];if(!m||f.sparse||!u(f))throw new n(`unsupported`,`Unsupported glTF accessor; use float positions and unsigned integer indices, add @margoengine/gltf/quantized for quantized meshes, or use @margoengine/gltf/pbr`);let h=t[f.componentType],g=r(f.count,`accessor count`,1),_=r(f.byteOffset??0,`accessor offset`),v=r(p.byteOffset??0,`view offset`),y=r(p.byteLength,`view length`,1),b=r(p.byteStride??h*l,`stride`,h*l);if(g>1e6)throw new n(`unsupported`,`glTF accessor holds over one million values, the limit of the light loader; use @margoengine/gltf/pbr`);if(v+y>m.length||_+(g-1)*b+l*h>y||v%h||_%h||b%h||b>252||d&&p.byteStride!==void 0)throw RangeError(`Invalid glTF accessor bounds/stride; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let x=new DataView(m.buffer,m.byteOffset+v,y),S=d?new Uint32Array(g):new Float32Array(g*l),C=f.normalized?a.get(f.componentType):void 0;for(let t=0;t<g;t++)for(let n=0;n<l;n++){let r=e(x,_+t*b+n*h,f.componentType);S[t*l+n]=C?Math.max(r/C,-1):r}return S}export{r as n,o as r,i as t};
@@ -0,0 +1,12 @@
1
+ import type { GLTFAccessor, GLTFDocument } from './shared/gltf.js';
2
+ export declare const integer: (value: unknown, label: string, min?: number) => number;
3
+ export declare const entry: <T>(array: readonly T[] | undefined, id: unknown, label: string) => T;
4
+ /**
5
+ * The `components` values of each element of accessor `id`, bounds checked. `accepts` says which accessors the caller
6
+ * takes; anything else is an `'unsupported'` MargoError. A normalized integer reads as a float in -1..1 or 0..1.
7
+ * @throws RangeError for bounds or a stride outside the view.
8
+ */
9
+ export declare function readAccessor({ doc, buffers }: {
10
+ doc: GLTFDocument;
11
+ buffers: readonly Uint8Array[];
12
+ }, id: unknown, components: number, accepts: (accessor: GLTFAccessor) => boolean, index?: boolean): Float32Array | Uint32Array;
@@ -0,0 +1,4 @@
1
+ import{n as e}from"./errors-THVaUwlL.js";import{a as t,c as n,d as r,l as i,o as a,s as o,t as s,u as c}from"./version-BmU1nesQ.js";import{n as l,t as u}from"./limits-_LZ441oV.js";import{n as d,t as f}from"./accessor-DuqjpuxI.js";import"./image-limit-DvFSfR5T.js";var p=262144,m=1024,h=1048576,g=16777216;function _(e=p){if(!Number.isInteger(e)||e<1024||e>1048576)throw RangeError(`maxPartVertices must be an integer from ${m} to ${h} (default ${p})`);return e}function v(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=/* @__PURE__ */ 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 y(e,t,n,r,i,a=3){let o=e.length/t,s=i?v(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}function b(e,t,n=!1){let{vertices:r,indices:i,uvs:a}=e,o=r.length/20;if(!(o>t)||!(r instanceof Float32Array)||!(i instanceof Uint32Array)||i.length%3)return[e];if(o>16777216)throw RangeError(`Prepared PBR geometry has more than ${g} vertices; split it into several primitives`);for(let e=0;e<i.length;e++)if(i[e]>=o)throw RangeError(`Invalid prepared PBR geometry; run prepareAsset again`);let s=y(i,3,o,t,n?null:r,20);return s.map(({indices:t,vertexMap:n},i)=>{let o=n.length,c=new Float32Array(o*20),l=a?new Float32Array(o*4):void 0;for(let e=0;e<o;e++)c.set(r.subarray(n[e]*20,n[e]*20+20),e*20),l&&l.set(a.subarray(n[e]*4,n[e]*4+4),e*4);return{...e.interpolatedDirections?{interpolatedDirections:!0}:{},vertices:c,indices:t,...e.topology?{topology:e.topology}:{},...l?{uvs:l}:{},part:{index:i,count:s.length,vertexMap:n}}})}var x=e=>!!e?.extensions&&typeof e.extensions==`object`&&`KHR_gaussian_splatting`in e.extensions,S=e=>!!e.meshes?.some(e=>e?.primitives?.some(x)),C=[`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`];async function ee(e,t={}){return t.dds===void 0&&e.textures?.some(e=>e?.extensions?.MSFT_texture_dds!==void 0)&&(t={...t,dds:(await import(`./dds.js`)).ddsTextures}),t.splats===void 0&&S(e)?t={...t,splats:(await import(`./splats.js`)).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 import(`./spec-gloss.js`)).specGlossMaterials}:(e.materials??[]).some(e=>!!e?.extensions&&typeof e.extensions==`object`&&C.some(t=>t in e.extensions))?{...t,materials:(await import(`./extended.js`)).extendedMaterials}:t:t.materials?t:{...t,materials:void 0}}var w=/* @__PURE__ */ new WeakMap;function T(e){for(let t of e.doc.meshes??[])for(let e of t.primitives??[])if(e.extensions?.KHR_draco_mesh_compression)return!0;return!1}function E(t,n){if(!n.extensions?.KHR_draco_mesh_compression)return;let r=w.get(t)?.get(n);if(!r)throw e(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);return r}async function D(e,t){let{decodeImage:n}=await import(
2
+ /* @vite-ignore */
3
+ /* webpackIgnore: true */
4
+ `@margoengine/decoders/image`);return n(e,{signal:t})}var O=e=>!!e.meshes?.some(e=>e?.primitives?.some(e=>e?.extensions?.KHR_draco_mesh_compression))||S(e),te=e=>O(e)||!!e.textures?.some(e=>e?.extensions?.KHR_texture_basisu)||!!e.images?.some(e=>e?.mimeType===`image/ktx2`),k=536870912,A=(e,t)=>/* @__PURE__ */ RangeError(`${e} (${t} bytes; raise the maxDownloadBytes option)`),j=`version https://git-lfs`;function M(t,n){if(!(t.length<23)){for(let e=0;e<23;e++)if(t[e]!==j.charCodeAt(e))return;throw e(`failed`,`${n} 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 N(e=k){if(!Number.isSafeInteger(e)||e<=0)throw RangeError(`maxDownloadBytes must be a positive integer`);return e}var P=/* @__PURE__ */ new Set(/* @__PURE__ */ `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(`.`)),F={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`},I,L=[`EXT_meshopt_compression`,`KHR_meshopt_compression`],R=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};function z(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 B(e,t,n){let r=e?.[z(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 V(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 H(e){let t=typeof e==`string`?e:V(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 c(t)}catch(e){throw e instanceof SyntaxError?/* @__PURE__ */ TypeError(`Invalid glTF JSON: `+e.message):e}}var U=[`buffers`,`bufferViews`,`accessors`,`meshes`,`nodes`,`scenes`,`materials`,`textures`,`images`];U.push(`samplers`,`skins`,`animations`,`cameras`);var W=e=>e===void 0||Array.isArray(e)&&e.every(e=>!!e&&typeof e==`object`&&!Array.isArray(e));function G(e){if(!e||typeof e!=`object`||!s(e.asset))throw TypeError(`Expected glTF 2.0`);let t=e;for(let e of U)if(!W(t[e]))throw TypeError(`Invalid glTF `+e+`; re-export the file and check it with the glTF Validator`);for(let t of e.meshes??[])if(!W(t.primitives)||!(t.primitives??[]).every(e=>W(e.targets)))throw TypeError(`Invalid glTF primitives; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let t of e.animations??[])if(!W(t.samplers)||!W(t.channels))throw TypeError(`Invalid glTF animation; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);for(let e of[`extensionsRequired`,`extensionsUsed`])if(t[e]!==void 0&&!Array.isArray(t[e]))throw TypeError(`Invalid glTF `+e+`; re-export the file and check it with the glTF Validator`)}function K(e,t=k){if(typeof e==`string`){if(e.length>t)throw A(`glTF JSON exceeds byte budget`,t);let n=new TextEncoder().encode(e).byteLength;if(n>t)throw A(`glTF JSON exceeds byte budget`,t);return{doc:H(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(M(n,`The glTF input`),n.length>=4&&!o(n)){if(n.length>t)throw A(`glTF JSON exceeds byte budget`,t);return{...K(V(n),t),sourceBytes:n.byteLength}}if(n.length>t)throw A(`glTF exceeds download budget`,t);let r=a(n);return{doc:H(r[0].data),binary:r[1]?.type===5130562?r[1].data:void 0,sourceBytes:n.byteLength}}function q(e,t=k){let n=/^data:[^;,]+;base64,([A-Za-z0-9+/]*={0,2})$/.exec(e);if(n&&n[1].length>t*4/3+4)throw A(`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))}var J={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},ne=`EXT_meshopt_compression`,Y=`KHR_draco_mesh_compression`,X=`KHR_texture_basisu`;function Z(e,t=!1){let n=e.extensions,r=n?.[X]!==void 0||!t||n?.MSFT_texture_dds===void 0?X:`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 z(i===void 0?e.source:i.source,`image source`)}function re(e,t,n){let r=z(t,`accessor`),i=B(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`?f[i.componentType]:void 0,o=typeof i.type==`string`&&Object.hasOwn(J,i.type)?J[i.type]:void 0,s=z(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}}var ie={5120:127,5121:255,5122:32767,5123:65535},ae=class{get remainingDecodedBytes(){return this.maxBytes*4-this.decoded}reserveDecodedBytes(e){if(z(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(n,r,i,a={},o=k,s=1e5){this.doc=n,this.hooks=a,this.maxBytes=o,this.maxNodes=s,this.cache=/* @__PURE__ */ new Map,this.viewCache=/* @__PURE__ */ new Map,this.decoded=0,this.partVertices=p,N(o),l(`maxNodes`,s),G(n);let c=(n.extensionsRequired??[]).filter(e=>!P.has(e)&&![Y,ne,`KHR_meshopt_compression`,X].includes(e)&&!a[F[e]]&&!(a.materials&&a.materials.extensions?.includes(e)));if(c.length)throw e(`unsupported`,`Required glTF extensions are unsupported: `+c.map(e=>F[e]?e+` (pass a `+F[e]+` decoder)`:e).join(`, `)+`; pass the listed decoders or re-export the model without them`);u(`Too many glTF nodes`,n.nodes?.length??0,s,`maxNodes`);let d=0;this.buffers=(n.buffers??[]).map((e,a)=>{if(!e||typeof e!=`object`||Array.isArray(e))throw TypeError(`Invalid glTF buffer; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);let s=z(e.byteLength,`buffer length`,1),c=R(e)?.fallback;if(c!==void 0&&typeof c!=`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=r[a],u=(!l||l.byteLength===0)&&!e.uri&&(a!==0||!i);if(c===!0||u&&L.some(e=>n.extensionsRequired?.includes(e))){let t=L.find(t=>e.extensions?.[t]!==void 0),r=(n.bufferViews??[]).filter(e=>e?.buffer===a);if(!r.length||r.some(e=>!R(e)||t!==void 0&&!e.extensions?.[t])||n.bufferViews?.some(e=>R(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/* @__PURE__ */ new Uint8Array}let f=l?l instanceof ArrayBuffer?new Uint8Array(l):new Uint8Array(l.buffer,l.byteOffset,l.byteLength):e.uri?q(e.uri,o):a===0?i:void 0;if(!f||s>f.length)throw RangeError(`Truncated glTF buffer; download the file again, it is incomplete`);if(a===0&&i&&(l===i||f===i)&&t(i.length,s),d+=f.byteLength,d>o)throw A(`glTF buffers exceed byte budget`,o);return f.subarray(0,s)})}view(t){let n=z(t,`bufferView`),r=B(this.doc.bufferViews,n,`bufferView`),i=z(r.buffer,`buffer reference`),a=this.buffers[i],o=z(r.byteOffset??0,`view offset`),s=z(r.byteLength,`view length`,1),c=z(B(this.doc.buffers,i,`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=R(r);if(l!==void 0){let t=this.viewCache.get(n);if(t)return t;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 i=this.buffers[z(l.buffer,`meshopt buffer reference`)],a=z(l.byteOffset??0,`meshopt offset`),o=z(l.byteLength,`meshopt length`,1),c=z(l.count,`meshopt count`,1),u=z(l.byteStride,`meshopt stride`,1),d=l.mode,f=l.filter??`NONE`;if(!i||o>i.length||a>i.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||r.byteStride!==void 0&&r.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=i.subarray(a,a+o),m;if(this.hooks.meshopt)m=new Uint8Array(s),this.hooks.meshopt.decodeGltfBuffer(m,c,u,p,d,f);else{if(!I)throw e(`state`,`Meshopt geometry requires parseGLTFAsync or loadGLTF, or a meshopt decoder passed in decoders (or asset.decode() first)`);m=I(p,c,u,d,f)}return this.reserveDecodedBytes(m.byteLength),this.viewCache.set(n,m),m}if(!a||o+s>a.length)throw RangeError(`Invalid glTF bufferView bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);return a.subarray(o,o+s)}setDecodedAccessor(e,t){let{index:n,width:r,count:i}=re(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(){I||this.hooks.meshopt||this.doc.bufferViews?.some(e=>e?.extensions?.EXT_meshopt_compression||e?.extensions?.KHR_meshopt_compression)&&(I=(await import(`@margoengine/decoders/meshopt`)).meshoptDecodeGltfBuffer)}async decode(e){if(await this.prepareMeshopt(),!T(this))return e?.throwIfAborted();let{decompressPrimitives:t}=await import(`./compression-D4IkO5vE.js`),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(t,n,r=!0){let{index:i,def:a,size:o,width:s,count:c}=re(this.doc,t,n),l=this.cache.get(i);if(l)return l;this.reserveDecodedBytes(c*s*4);let u=new Float32Array(c*s),p=(e,t,n,i,c)=>{if(t%o||n%o||t+(i-1)*n+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),f=a.componentType,p=a.normalized?ie[f]??1:0;for(let e=0;e<i;e++){let i=(c?c[e]:e)*s;for(let a=0,c=t+e*n;a<s;a++,c+=o){let e=d(l,c,f);if(p&&(e=Math.max(-1,e/p)),r&&!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(a.bufferView!==void 0){let e=B(this.doc.bufferViews,a.bufferView,`bufferView`),t=z(e.byteStride??o*s,`stride`,o*s);if(t>252||z(e.byteOffset??0,`view offset`)%o)throw RangeError(`Invalid glTF stride/alignment; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);p(this.view(a.bufferView),z(a.byteOffset??0,`accessor offset`),t,c)}else{if(this.doc.meshes?.some(e=>e?.primitives?.some(e=>e?.extensions?.[Y]&&(e.indices===i||Object.keys(e.extensions[Y].attributes??{}).some(t=>e.attributes?.[t]===i)))))throw e(`state`,`Draco geometry requires parseGLTFAsync or loadGLTF`);if(a.byteOffset)throw TypeError(`Accessor has no data or invalid offset; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}if(a.sparse){let e=a.sparse,t=z(e.count,`sparse count`,1),n=e.indices,r=e.values,i=f[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=z(n.byteOffset??0,`sparse offset`);if(u%i||u+t*i>l.length||B(this.doc.bufferViews,n.bufferView,`sparse indices`).byteStride!==void 0||B(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 d=new DataView(l.buffer,l.byteOffset,l.byteLength),m=[],h=-1;for(let e=0;e<t;e++){let t=u+e*i,n=i===1?d.getUint8(t):i===2?d.getUint16(t,!0):d.getUint32(t,!0);if(n<=h||n>=c)throw RangeError(`Invalid sparse index order/bounds; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`);m.push(n),h=n}p(this.view(r.bufferView),z(r.byteOffset??0,`sparse values offset`),o*s,t,m)}return r&&this.cache.set(i,u),u}};function oe(e){let t=/* @__PURE__ */ new Set;for(let n of e.textures??[])if(n?.extensions?.[X]!==void 0){let r=Z(n),i=B(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 se(e,t=!1){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set;for(let i of e.textures??[])i?.extensions?.[X]!==void 0||t&&i?.extensions?.MSFT_texture_dds!==void 0?(r.add(Z(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(z(i.extensions.MSFT_texture_dds.source,`DDS image`)));for(let e of r)n.delete(e);return n}function ce(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 le(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 ue(t,n){let r=t.hooks.decoderModule;if(!r)throw e(`unsupported`,n===`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 r}function de(e,t){let n=t.ktx2,r;return{async decode(i){t.signal?.throwIfAborted();let a=ce(i,e,t.device);if(!n){let{KTX2Decoder:i}=await ue(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(),le(o,a,e)},close(){r?.dispose()}}}async function fe(t,n=[],r={}){r.signal?.throwIfAborted();let i=oe(t.doc),a=/* @__PURE__ */ new Set;if(t.hooks.dds)for(let e of t.doc.textures??[])!e.extensions?.KHR_texture_basisu&&e.extensions?.MSFT_texture_dds!==void 0&&a.add(Z(e,!0));if(!i.size&&!a.size)return n;let o=n.slice(),s=de(t,r);try{for(let n of a){if(r.signal?.throwIfAborted(),o[n])continue;let i=B(t.doc.images,n,`DDS image`);if(i.mimeType!==void 0&&i.mimeType!==`image/vnd-ms.dds`||i.bufferView!==void 0&&i.mimeType!==`image/vnd-ms.dds`)throw TypeError(`MSFT_texture_dds requires image/vnd-ms.dds`);let a=i.bufferView===void 0?typeof i.uri==`string`&&i.uri.startsWith(`data:`)?q(i.uri,t.maxBytes):void 0:t.view(i.bufferView);if(!a)throw e(`state`,`External DDS images require loadGLTF`);o[n]=t.hooks.dds.decode(a,r)}for(let n of i){if(o[n]){if(!(`ktx2`in o[n]))throw TypeError(`KHR_texture_basisu requires decoded KTX2 images`);continue}let r=B(t.doc.images,n,`KTX2 image`),i=r.bufferView===void 0?typeof r.uri==`string`&&r.uri.startsWith(`data:`)?q(r.uri,t.maxBytes):void 0:t.view(r.bufferView);if(!i)throw e(`state`,`External KTX2 images require loadGLTF`);o[n]=await s.decode(i)}return o}finally{s.close()}}async function pe(){let{optimizeOverdraw:e,optimizeVertexCache:t}=await import(`./optimize-7SEzNA23.js`);return(n,r,i)=>e(t(n,i),r)}async function me(t,a={},o,s={},c=!1,l=0){let u=`aborted`in a?{signal:a}:a,{signal:d,decoders:f={},buffers:p=[],fetch:m=globalThis.fetch,maxDownloadBytes:h,maxNodes:g,optimize:v,allowedURLs:y,maxPartVertices:b}=u,x=typeof o==`function`?o:void 0,S=typeof o==`function`?void 0:o,C=N(h),w=_(b);d?.throwIfAborted();let T=t===void 0?u.baseURL===void 0?void 0:new URL(u.baseURL,globalThis.location?.href):new URL(t,globalThis.location?.href),E=l,D=async(e,t=!1)=>{if(![`http:`,`https:`].includes(e.protocol))throw TypeError(`glTF URL must use HTTP(S)`);let n=await m(e,{signal:d});t&&n.url?T=new URL(n.url):t||i(n,T??globalThis.location?.href,y,`glTF resource`);let a=await r(n,{maxBytes:C-E,signal:d,label:`glTF download`}).catch(e=>{throw e instanceof RangeError?A(e.message,C):e});return M(a,e.href),E+=a.length,a},O=r=>{if(T===void 0&&t===void 0)throw e(`state`,`glTF URI ${r} 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 n(r,T??globalThis.location?.href,y,`glTF resource`)},{doc:k,binary:j,sourceBytes:P}=K(S??await D(T,!0),C),F=[],I=[];if(S!=null){if(P>C-E)throw A(`glTF exceeds download budget`,C);E+=P}G(k);for(let e=0;e<(k.buffers?.length??0);e++){let t=B(k.buffers,e,`buffer`);if(p[e]){let t=p[e];F[e]=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}else if(R(t)?.fallback!==!0){if(!t.uri)e===0&&j&&(F[e]=j);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=q(t.uri,C);if(E+=n.length,E>C)throw A(`glTF exceeds download budget`,C);F[e]=n}else F[e]=await D(O(t.uri))}}let L=new ae(k,F,j,await ee(k,f),C,g),z=L.hooks;if(L.baseURL=T?.href,L.partVertices=w,v&&(L.reorder=await pe()),c&&te(k))return{asset:L,images:I,deferred:!0,baseURL:T?.href,downloadedBytes:E};let V=oe(k),H=se(k,!!z.dds),U=de(L,{...s,ktx2:s.ktx2??z.ktx2,signal:d}),W=0;await L.decode(d);try{d?.throwIfAborted(),await x?.(L),d?.throwIfAborted();let e=[],t=async()=>{let[t,n]=e.shift(),r=await n;if(I[t]=r,W+=r.width*r.height*4,r.width*r.height>67108864||W>C*4)throw RangeError(`glTF images exceed decoded size limit; load a smaller model, or reduce its textures and meshes`);d?.throwIfAborted()};try{for(let n=0;n<(k.images?.length??0);n++){if(H.has(n))continue;let r=B(k.images,n,`image`);if(V.has(n)&&z.textureStream){I[n]=await z.textureStream.open(r.bufferView===void 0?typeof r.uri==`string`&&r.uri.startsWith(`data:`)?{bytes:q(r.uri,C)}:{url:O(r.uri).href}:{bytes:L.view(r.bufferView)},n);continue}let i;if(r.bufferView!==void 0)i=L.view(r.bufferView);else if(typeof r.uri==`string`&&r.uri.startsWith(`data:`)){if(i=q(r.uri,C),E+=i.length,E>C)throw A(`glTF exceeds download budget`,C)}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(z.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(z.dds.decode(i,{signal:d}))]),await t()}else if(V.has(n)){for(;e.length;)await t();e.push([n,U.decode(i)]),await t()}else{let a=ge(i,r.mimeType,n,d);a.catch(()=>{}),e.push([n,a]),e.length>=he&&await t()}}for(;e.length;)await t()}finally{for(let[,t]of e.splice(0))t.then(e=>$([e]),()=>{})}return{asset:L,images:I}}catch(e){throw $(I),e}finally{U.close()}}var he=8;async function ge(e,t,n,r){r?.throwIfAborted();try{if(typeof createImageBitmap!=`function`)return await D(e,r);let n=e.buffer instanceof ArrayBuffer?e:new Uint8Array(e);return await createImageBitmap(new Blob([n],{type:t}),{colorSpaceConversion:`none`,premultiplyAlpha:`none`})}catch(e){throw r?.throwIfAborted(),TypeError(`glTF image ${n} could not be decoded (${e instanceof Error?e.message:e}); check the file`)}}var Q=/* @__PURE__ */ new WeakMap;function _e(e){for(let t of e)t&&Q.set(t,(Q.get(t)??0)+1)}function $(e){for(let t of e){if(!t)continue;let e=Q.get(t);e?Q.set(t,e-1):`close`in t&&t.close?.()}}export{_ as A,E as C,x as D,ee as E,b as M,p as O,se as S,T,A as _,G as a,_e as b,K as c,ue as d,N as f,me as g,z as h,O as i,y as j,g as k,ge as l,B as m,k as n,$ as o,q as p,te as r,J as s,ae as t,fe as u,H as v,w,pe as x,M as y};
@@ -0,0 +1 @@
1
+ export { GLTFAsset, type GLTFDocument } from './asset.js';
@@ -0,0 +1 @@
1
+ export{t as GLTFAsset}from"./asset-1b8ejkZX.js";
@@ -0,0 +1,319 @@
1
+ import type { DracoDecodeOptions, TranscodedKTX2Result } from '@margoengine/decoders';
2
+ import type { PBRInstances } from './pbr-instancing.js';
3
+ import type { Engine } from '@margoengine/core/extension';
4
+ // @ts-ignore optional peer: its types apply when it is installed
5
+ import type { Splats } from '@margoengine/splats';
6
+ import type { ExtendedPlan } from './shader.js';
7
+ import type { GLTFDocument, GLTFTexture, GLTFInstancing, GLTFExtensions, GLTFPrimitive, GLTFTextureInfo, GLTFMaterial } from './shared/gltf.js';
8
+ export type { GLTFDocument } from './shared/gltf.js';
9
+ /** Retained mip bytes let compressed textures upload again after device restoration. */
10
+ export interface KTX2Image {
11
+ readonly ktx2: TranscodedKTX2Result;
12
+ readonly width: number;
13
+ readonly height: number;
14
+ close(): void;
15
+ }
16
+ /**
17
+ * A texture that streams its mip levels (`textures` of @margoengine/gltf/progressive): its GPU texture replaces itself
18
+ * as levels arrive and leave, so a model asks for the current view and rebinds through `users`.
19
+ */
20
+ export interface GLTFStreamedImage {
21
+ readonly streamed: true;
22
+ readonly width: number;
23
+ readonly height: number;
24
+ /** The models drawing it; each is told when the texture is replaced. */
25
+ readonly users: Set<{
26
+ rebindStreamed(image: GLTFStreamedImage): void;
27
+ }>;
28
+ /** The current view on `device` in the colour space a map slot reads, or undefined while no texture lives there. */
29
+ view(device: GPUDevice, srgb: boolean): GPUTextureView | undefined;
30
+ /** Actual resident view size, when a stream rebases level zero while keeping its authored width/height. */
31
+ viewSize?(): {
32
+ width: number;
33
+ height: number;
34
+ levels: number;
35
+ } | undefined;
36
+ close(): void;
37
+ }
38
+ /**
39
+ * A decoded glTF image: a bitmap, retained RGBA8 pixels, a transcoded/compressed image or a streamed image.
40
+ */
41
+ export type GLTFImage = ImageBitmap | GLTFPixelImage | KTX2Image | GLTFCompressedImage | GLTFStreamedImage | undefined;
42
+ /** Retained RGBA8 rows, top row first, with straight alpha and no embedded colour-space conversion. */
43
+ export interface GLTFPixelImage {
44
+ readonly width: number;
45
+ readonly height: number;
46
+ readonly data: Uint8Array;
47
+ }
48
+ export interface GLTFImageOptions {
49
+ signal?: AbortSignal;
50
+ device?: GPUDevice;
51
+ ktx2?: {
52
+ transcode(data: Uint8Array, options?: {
53
+ signal?: AbortSignal;
54
+ }): Promise<GLTFCompressedImage | TranscodedKTX2Result>;
55
+ };
56
+ }
57
+ /** Async codecs stay on the owning thread; meshopt is synchronous and can be packed in a parser worker. */
58
+ export declare const asyncGeometry: (doc: GLTFDocument) => boolean;
59
+ export declare const asyncCompression: (doc: GLTFDocument) => boolean;
60
+ /**
61
+ * Default `maxDownloadBytes`: 512 MiB, so a 10M-triangle scan (about 300 MB raw) loads with no options; decoded data may
62
+ * use 4x (2 GiB), which a 40 MB Draco scan needs (about 800 MB decoded).
63
+ */
64
+ export declare const assetLimit: number;
65
+ /** A byte budget derived from `maxDownloadBytes` was exceeded: the error names the option to raise. */
66
+ export declare const overBudget: (message: string, bytes: number) => RangeError;
67
+ /**
68
+ * Throws a coded error when `bytes` are a Git LFS pointer file (a small text stub committed in place of the asset when
69
+ * the repository was cloned without LFS), which would otherwise fail later as invalid JSON or a truncated buffer.
70
+ */
71
+ export declare function rejectLFSPointer(bytes: Uint8Array, name: string): void;
72
+ /** Validates a `maxDownloadBytes` option (default assetLimit). */
73
+ export declare function downloadLimit(bytes?: number): number;
74
+ /** A transcoded texture, such as a KTX2Decoder result: every mip level, in a format the device has enabled. */
75
+ export interface GLTFCompressedImage {
76
+ width: number;
77
+ height: number;
78
+ format: GPUTextureFormat;
79
+ mipmaps: readonly {
80
+ data: Uint8Array;
81
+ width: number;
82
+ height: number;
83
+ }[];
84
+ /** Optional format-specific uploader, retaining all mip bytes for restoration and other devices. */
85
+ upload?(device: GPUDevice, srgb: boolean): GPUTexture;
86
+ gpuFormat?(device: GPUDevice, srgb: boolean): GPUTextureFormat;
87
+ }
88
+ /** A decoded glTF image slot; undefined when a KTX2 image was skipped because no ktx2 decoder was passed. */
89
+ /** Where a streamed KTX2 image is: a URL (with `offset` and `length` when it sits inside a larger file), or its bytes. */
90
+ export type GLTFStreamSource = {
91
+ url: string;
92
+ offset?: number;
93
+ length?: number;
94
+ } | {
95
+ bytes: Uint8Array;
96
+ };
97
+ /** Opens one KTX2 image as a stream, resolving once its smallest levels are on the GPU. */
98
+ export interface GLTFTextureOpener {
99
+ open(source: GLTFStreamSource, index: number): Promise<GLTFStreamedImage>;
100
+ }
101
+ /** Optional decoders. Structurally matches @margoengine/decoders (DracoDecoder, MeshoptDecoder, KTX2Decoder) without importing it. */
102
+ export interface GLTFDecoderHooks {
103
+ /** MSFT_texture_dds reader from @margoengine/gltf/dds. */
104
+ dds?: {
105
+ decode(data: Uint8Array, options?: {
106
+ signal?: AbortSignal;
107
+ }): GLTFCompressedImage;
108
+ };
109
+ draco?: {
110
+ decode(data: Uint8Array, options: GLTFDracoDecodeOptions): Promise<GLTFDracoGeometry>;
111
+ };
112
+ meshopt?: {
113
+ decodeGltfBuffer(target: Uint8Array, count: number, stride: number, source: Uint8Array, mode: string, filter?: string): void;
114
+ };
115
+ ktx2?: {
116
+ transcode(data: Uint8Array, options?: {
117
+ signal?: AbortSignal;
118
+ }): Promise<GLTFCompressedImage>;
119
+ };
120
+ /**
121
+ * Where the built-in Draco and KTX2 decoders come from when `draco` or `ktx2` is not given. `loadGLTF` and
122
+ * `parseGLTFAsync` of the package root set `() => import('@margoengine/decoders')`; nothing else names that module,
123
+ * so a bundler that only reads @margoengine/gltf/pbr-model copies no Wasm file.
124
+ */
125
+ decoderModule?: () => Promise<typeof import('@margoengine/decoders')>;
126
+ /** Streams KTX2 images instead of decoding them whole; `loadGLTFProgressive` sets it from its `textures` option. */
127
+ textureStream?: GLTFTextureOpener;
128
+ /** EXT_mesh_gpu_instancing: `instancing` from @margoengine/gltf/pbr-instancing. */
129
+ instancing?: {
130
+ read(asset: GLTFAsset, extension: GLTFInstancing): PBRInstances | undefined;
131
+ };
132
+ /**
133
+ * The physical material shader (`extendedMaterials` from @margoengine/gltf/extended-materials): clearcoat, sheen,
134
+ * transmission, volume, IOR, specular, dispersion, iridescence, anisotropy, diffuse transmission and diffuse roughness. `loadGLTF` and
135
+ * `parseGLTFAsync` import it on their own when a file uses one of those extensions; `false` keeps the base shader
136
+ * (the extensions are then ignored, as glTF allows). Synchronous `parseGLTF` uses it only when passed.
137
+ */
138
+ materials?: GLTFExtendedMaterials | false;
139
+ /**
140
+ * KHR_gaussian_splatting (`gaussianSplats` from @margoengine/gltf/splats): `loadGLTF` and `parseGLTFAsync` import it
141
+ * on their own when a file holds splats, and the clouds go to @margoengine/splats as `model.splats`. `false` keeps the
142
+ * point cloud fallback the extension defines. Synchronous `parseGLTF` draws the fallback.
143
+ */
144
+ splats?: GLTFSplatReader | false;
145
+ }
146
+ /** One Gaussian cloud of a file, attached to the engine; `bounds` holds min xyz, max xyz of its centres in world space. */
147
+ export interface GLTFSplatCloud {
148
+ readonly cloud: Splats;
149
+ readonly bounds: Float32Array;
150
+ }
151
+ /** What gltf/pbr needs to read Gaussian splats (`gaussianSplats` from @margoengine/gltf/splats implements it). */
152
+ export interface GLTFSplatReader {
153
+ /** Reads `primitives`, each placed by its column-major world `matrix`, and attaches their clouds to `engine`. */
154
+ attach(engine: Engine, asset: GLTFAsset, primitives: readonly {
155
+ primitive: GLTFPrimitive;
156
+ matrix: Float32Array;
157
+ }[], signal?: AbortSignal): Promise<GLTFSplatCloud[]>;
158
+ }
159
+ /** Structural decoder boundary; supplied hooks may omit metadata derived from accessor declarations. */
160
+ export interface GLTFDracoDecodeOptions extends DracoDecodeOptions {
161
+ attributeIds: Record<string, number>;
162
+ componentTypes: Record<string, number>;
163
+ }
164
+ export interface GLTFDracoGeometry {
165
+ vertexCount?: number;
166
+ positions?: ArrayLike<number>;
167
+ normals?: ArrayLike<number>;
168
+ uvs?: ArrayLike<number>;
169
+ colors?: ArrayLike<number>;
170
+ indices?: ArrayLike<number>;
171
+ attributes?: Record<string, {
172
+ array: ArrayLike<number>;
173
+ itemSize?: number;
174
+ componentType?: number;
175
+ }>;
176
+ }
177
+ /** What gltf/pbr needs to shade extended materials (`extendedMaterials` from @margoengine/gltf/extended-materials implements it). */
178
+ export interface GLTFExtendedMaterials {
179
+ /** Additional required extensions implemented by this optional material reader. Defaults to none. */
180
+ readonly extensions?: readonly string[];
181
+ /** Converts an authored material before packing its factors and maps. Defaults to the original material. */
182
+ convert?(material: GLTFMaterial): GLTFMaterial;
183
+ /**
184
+ * A glTF material's `extensions` read for its thin film, anisotropy, diffuse transmission and bump, or undefined when
185
+ * none is in use (every factor 0): the features, map slots 13-20 (texture infos, then slot 21 for a diffuse roughness
186
+ * texture) and 24 uniform floats (rows iri, aniso, dtr, bump, scatter, extinction).
187
+ */
188
+ parse(extensions: GLTFExtensions): {
189
+ features: Omit<ExtendedPlan, 'slots'>;
190
+ maps: (GLTFTextureInfo | undefined)[];
191
+ rows: number[];
192
+ } | undefined;
193
+ /** The binding plan for a material's map slots (`extendedPlan`). */
194
+ plan(maps: readonly ({
195
+ index: number;
196
+ } | undefined)[], features: Omit<ExtendedPlan, 'slots'>): ExtendedPlan;
197
+ /** The extended physical shader for a plan (`extendedShader`). */
198
+ shader(plan: ExtendedPlan): string;
199
+ }
200
+ export declare function integer(value: unknown, label: string, min?: number): number;
201
+ export declare function entry<T>(array: readonly T[] | undefined, id: unknown, label: string): T;
202
+ /**
203
+ * glTF JSON text (or UTF-8 bytes) as a document. Malformed JSON throws TypeError('Invalid glTF JSON: ...'), not
204
+ * SyntaxError, and nesting deeper than 256 levels is refused before parsing: structured clone (worker replies) and
205
+ * recursive readers would overflow the stack on a document nested thousands deep. No real glTF comes close.
206
+ */
207
+ export declare function parseJSON(source: string | Uint8Array): GLTFDocument;
208
+ /**
209
+ * The trust-boundary check every load runs before reading a document: glTF 2.0, every top-level list an array of
210
+ * objects (so later reads never meet null or a number), the nested lists loaders iterate (primitives and their morph
211
+ * targets, animation samplers and channels) too, and the extension name lists arrays.
212
+ */
213
+ export declare function checkDocument(doc: GLTFDocument): void;
214
+ export declare function container(input: string | object | ArrayBuffer | ArrayBufferView, limit?: number): {
215
+ doc: GLTFDocument;
216
+ binary?: Uint8Array;
217
+ sourceBytes: number;
218
+ };
219
+ export declare function embedded(uri: string, limit?: number): Uint8Array;
220
+ export declare const components: Record<string, number>;
221
+ /** Basis Universal replaces the ordinary PNG/JPEG source, including optional fallbacks. */
222
+ export declare function textureSource(def: GLTFTexture, dds?: boolean): number;
223
+ /**
224
+ * A parsed glTF or GLB: its JSON document and binary buffers, with decoded accessor data cached under a byte budget.
225
+ */
226
+ export declare class GLTFAsset {
227
+ readonly doc: GLTFDocument;
228
+ readonly hooks: GLTFDecoderHooks;
229
+ readonly maxBytes: number;
230
+ readonly maxNodes: number;
231
+ readonly buffers: Uint8Array[];
232
+ private readonly cache;
233
+ private readonly viewCache;
234
+ /** Where `loadGLTF` read the file from, for files named relative to it; unset for a parsed document. */
235
+ baseURL?: string;
236
+ private decoded;
237
+ /** @internal Remaining retained decode budget, checked before decoder output allocation. */
238
+ get remainingDecodedBytes(): number;
239
+ /** @internal The triangle order of the `optimize` option, for primitives packed from here on. */
240
+ reorder?: (indices: Uint32Array, positions: ArrayLike<number>, count: number) => Uint32Array;
241
+ /** @internal Most vertices a packed part holds (the `maxPartVertices` option); larger primitives split into parts. */
242
+ partVertices: number;
243
+ /** @internal Account for retained decoded data, including topology without an accessor. */
244
+ reserveDecodedBytes(byteLength: number): void;
245
+ constructor(doc: GLTFDocument, buffers: Array<ArrayBuffer | ArrayBufferView>, binary?: Uint8Array, hooks?: GLTFDecoderHooks, maxBytes?: number, maxNodes?: number);
246
+ view(id: unknown): Uint8Array;
247
+ /** Supply already normalized Draco data before constructing a PBR model. */
248
+ setDecodedAccessor(id: unknown, values: Float32Array): void;
249
+ /** Loads the built-in meshopt decoder, only when a buffer view declares a meshopt extension and no `meshopt` hook is set. */
250
+ prepareMeshopt(): Promise<void>;
251
+ decode(signal?: AbortSignal): Promise<void>;
252
+ /**
253
+ * The accessor's values as floats (normalized integers scaled, sparse values applied), cached. A NaN or infinity
254
+ * throws, unless `finite` is false: then the values come back as they are and are not cached, for a checker that
255
+ * reports them (gltf/report).
256
+ */
257
+ accessor(id: unknown, type?: string, finite?: boolean): Float32Array;
258
+ }
259
+ export declare function unusedBasisuFallbacks(doc: GLTFDocument, dds?: boolean): Set<number>;
260
+ /** The module holding the built-in decoders; a file that needs one without a way to reach it is refused by name. */
261
+ export declare function decoderSource(asset: GLTFAsset, format: string): NonNullable<GLTFDecoderHooks['decoderModule']>;
262
+ /** Async only for requested KTX2 images; caller-supplied ordinary bitmaps retain their synchronous path. */
263
+ export declare function decodeKTX2Images(asset: GLTFAsset, images?: readonly GLTFImage[], options?: GLTFImageOptions): Promise<GLTFImage[]>;
264
+ export interface AssetOptions {
265
+ signal?: AbortSignal;
266
+ decoders?: GLTFDecoderHooks;
267
+ buffers?: Array<ArrayBuffer | ArrayBufferView>;
268
+ /** Fetch for the file and its external buffers and images, for example `@margoengine/cache`'s `cache.fetch`. Default `globalThis.fetch`. */
269
+ fetch?: typeof fetch;
270
+ /**
271
+ * URL prefixes (for example `https://cdn.example.com/models/`) that buffer and image URIs may point to besides the
272
+ * file's own directory, matched on a path-segment boundary. Default none: absolute, cross-origin and `../`-escaping
273
+ * URIs throw a TypeError, and so does a redirect that ends outside these places.
274
+ */
275
+ allowedURLs?: readonly string[];
276
+ /**
277
+ * The URL external buffer and image URIs are resolved against when the file is parsed from memory
278
+ * (`parseGLTFAsync`), for example `https://cdn.example.com/models/car.gltf`. A file in memory has no location of its
279
+ * own, so without this option a URI that is not a `data:` URI is refused with a coded error (KB-GLTFA B7); `loadGLTF`
280
+ * and the other loaders that fetch the file know its location and ignore this option.
281
+ */
282
+ baseURL?: string | URL;
283
+ /**
284
+ * Most bytes the file, its buffers and embedded or external images may total (default 512 MiB, `assetLimit`). Decoded accessors,
285
+ * packed geometry and decoded images may each use 4x this. Exceeding it throws a RangeError naming this option.
286
+ */
287
+ maxDownloadBytes?: number;
288
+ /** Most glTF nodes the file may have, each one a core mesh (default 100,000; up to core's 8,388,608 entities). */
289
+ maxNodes?: number;
290
+ /**
291
+ * Reorders each opaque primitive's triangles for the GPU's vertex cache and for early depth rejection, as
292
+ * `@margoengine/geometry/optimize` does (needs that package). Same triangles, same picture, more time spent loading.
293
+ * `BLEND` primitives keep the file's order, which decides how they layer. Default false: most exporters already
294
+ * order their meshes, and `margo-convert` does it once, offline.
295
+ */
296
+ optimize?: boolean;
297
+ /**
298
+ * Most vertices one GPU part holds (default 262,144, from 1,024 to 1,048,576). A primitive with more vertices loads as
299
+ * several parts of its node, each drawn, culled and picked on its own (`PBRPrimitive.part`); shared vertices stay
300
+ * shared inside a part. Up to 16,777,216 vertices per primitive; skinned and morphed primitives must fit one part.
301
+ */
302
+ maxPartVertices?: number;
303
+ }
304
+ /** @internal The triangle order `optimize` asks for, loaded only then. */
305
+ export declare function triangleOrder(): Promise<NonNullable<GLTFAsset['reorder']>>;
306
+ /** Fetch (url) or parse (input) a glTF, decode compressed geometry and images. External URIs resolve against url, else `baseURL` (none: refused). */
307
+ export declare function loadAsset(url: string | URL | undefined, options?: AssetOptions | AbortSignal, inputOrPrepare?: string | object | ArrayBuffer | ArrayBufferView | ((asset: GLTFAsset) => Promise<void>), imageOptions?: GLTFImageOptions, deferCompression?: boolean, downloadedBytes?: number): Promise<{
308
+ asset: GLTFAsset;
309
+ images: GLTFImage[];
310
+ deferred?: boolean;
311
+ baseURL?: string;
312
+ downloadedBytes?: number;
313
+ }>;
314
+ /** Image bytes as a bitmap, or retained pixels without browser decoding; invalid bytes name their image index. */
315
+ export declare function decodeImage(data: Uint8Array, type: string | undefined, index: number, signal?: AbortSignal): Promise<ImageBitmap | GLTFPixelImage>;
316
+ /** Counts one more model in on `images`: each closes only when its last holder calls `closeImages`. */
317
+ export declare function retainImages(images: readonly GLTFImage[]): void;
318
+ /** Lets go of `images` for one holder: each closes unless `retainImages` or `PBRModel.shareImages` counted another. */
319
+ export declare function closeImages(images: readonly GLTFImage[]): void;
@@ -0,0 +1,47 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ // @ts-ignore optional peer: its types apply when it is installed
3
+ import type { AudioListener, Audio as Sound } from '@margoengine/audio';
4
+ import type { PBRModel } from './model.js';
5
+ type Extension = 'KHR_audio_emitter' | 'MSFT_audio_emitter';
6
+ /** Loading and scene selection for applyGLTFAudio. */
7
+ export interface GLTFAudioOptions {
8
+ /** Default the model's source URL. */
9
+ baseURL?: string | URL;
10
+ /** Default globalThis.fetch. */
11
+ fetch?: typeof globalThis.fetch;
12
+ signal?: AbortSignal;
13
+ /** Audio download budget, default 64 MiB; decoded PCM has four times this budget. */
14
+ maxDownloadBytes?: number;
15
+ /** Maximum simultaneous source objects created by this attachment, default 256. */
16
+ maxSources?: number;
17
+ /** Default doc.scene or zero. Only that scene's node and global emitter instances are created. */
18
+ scene?: number;
19
+ /** Default honor KHR source autoPlay, with MSFT emitters initially stopped. False disables auto play. */
20
+ autoplay?: boolean;
21
+ /** Random number in [0,1), used for MSFT weighted clip selection on each new play trigger. Default Math.random. */
22
+ random?: () => number;
23
+ /** Additional allowed external URL prefixes, default none. */
24
+ allowedURLs?: readonly string[];
25
+ }
26
+ /** One emitter instance; a shared definition may be instantiated on several nodes. */
27
+ export interface GLTFAudioEmitter {
28
+ readonly extension: Extension;
29
+ readonly emitterIndex: number;
30
+ readonly nodeIndex?: number;
31
+ readonly name: string;
32
+ readonly sources: readonly Sound[];
33
+ play(offset?: number): void;
34
+ pause(): void;
35
+ stop(): void;
36
+ }
37
+ /** Audio owned by one glTF model. Dispose detaches sounds, without disposing the caller's listener/context. */
38
+ export interface GLTFAudio {
39
+ readonly emitters: readonly GLTFAudioEmitter[];
40
+ /** Follow MSFT animation events, including skipped frames, backward seeks, pauses and resumed offsets. Call each animation tick. */
41
+ sync(time: number, playing: boolean, animation?: number): void;
42
+ dispose(): void;
43
+ [Symbol.dispose](): void;
44
+ }
45
+ /** Read draft KHR and MSFT audio emitters into the audio package's global and positional sources. */
46
+ export declare function applyGLTFAudio(model: PBRModel, listener: AudioListener, options?: GLTFAudioOptions): Promise<GLTFAudio>;
47
+ export {};
package/dist/audio.js ADDED
@@ -0,0 +1 @@
1
+ import{n as e}from"./errors-THVaUwlL.js";import{c as t,d as n,l as r}from"./version-BmU1nesQ.js";import{n as i,p as a}from"./asset-1b8ejkZX.js";var o=e=>/* @__PURE__ */ TypeError(`Invalid glTF audio `+e+`; re-export the file and check its audio extension`),s=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))throw o(t);return e},c=(e,t)=>{if(!Array.isArray(e))throw o(t);return e},l=(e,t,n,r=1/0)=>{let i=e??t;if(typeof i!=`number`||!Number.isFinite(i)||i<0||i>r)throw o(n);return i},u=(e,t)=>{if(e!==void 0&&typeof e!=`boolean`)throw o(t);return e===!0},d=(e,t)=>{let n=l(e,-1,t);if(!Number.isSafeInteger(n))throw o(t);return n},f=(e,t,n)=>s(c(e,n)[d(t,n)],n);async function p(e,t){if(t?.throwIfAborted(),!t)return e;let n=()=>{};try{return await new Promise((r,i)=>{n=()=>i(t.reason),t.addEventListener(`abort`,n,{once:!0}),e.then(r,i)})}finally{t.removeEventListener(`abort`,n)}}async function m(m,h,g={}){if(g.signal?.throwIfAborted(),m.disposed)throw e(`disposed`,`Cannot attach audio to a disposed model; load it again`);let{Audio:_,PositionalAudio:v,decodeAudio:y}=await import(`@margoengine/audio`).catch(t=>{throw e(`unsupported`,`glTF audio needs @margoengine/audio (${t instanceof Error?t.message:t}); install that optional package`)});g.signal?.throwIfAborted();let b=m.asset.doc,x=l(g.maxDownloadBytes,i,`maxDownloadBytes`);if(!Number.isSafeInteger(x)||x<1)throw o(`maxDownloadBytes`);let S=l(g.maxSources,256,`maxSources`);if(!Number.isSafeInteger(S)||S<1)throw o(`maxSources`);g.autoplay!==void 0&&u(g.autoplay,`autoplay`);let C=g.random??Math.random;if(typeof C!=`function`)throw o(`random`);let w=[],T=[],E=[],D=[],O=0,k=0,A=!1,j=/* @__PURE__ */ new Map,M=d(g.scene??b.scene??0,`scene`),N=b.scenes?.length?s(b.scenes[M],`scene`):void 0,P=/* @__PURE__ */ new Set,F=e=>{let t=d(e,`node`);if(P.has(t))return;P.add(t);let n=s(b.nodes?.[t],`node`);for(let e of n.children===void 0?[]:c(n.children,`children`))F(e)};if(N)for(let e of N.nodes===void 0?[]:c(N.nodes,`scene nodes`))F(e);else for(let e=0;e<(b.nodes?.length??0);e++)P.add(e);let I=(e,i,s)=>{let c=d(s,`clip`),l=e+`:`+c,u=j.get(l);return u||(u=(async()=>{let s=f(e===`KHR_audio_emitter`?i.audio:i.clips,c,`audio data`),l=s.mimeType;if(s.bufferView!==void 0&&typeof l!=`string`||l!==void 0&&![`audio/wav`,`audio/mpeg`].includes(String(l)))throw o(`MIME type`);let u;if(s.bufferView!==void 0)u=m.asset.view(d(s.bufferView,`bufferView`));else if(typeof s.uri!=`string`)throw o(`URI`);else if(s.uri.startsWith(`data:`))u=a(s.uri,x-O);else{let e=g.baseURL??m.asset.baseURL,i=t(s.uri,e?.toString(),g.allowedURLs,`glTF audio`),a=await(g.fetch??globalThis.fetch)(i,{signal:g.signal});r(a,e?.toString(),g.allowedURLs,`glTF audio`),u=await n(a,{maxBytes:x-O,signal:g.signal,label:`glTF audio`})}if(O+=u.length,O>x)throw RangeError(`glTF audio exceeds download budget; raise maxDownloadBytes`);let _=new Uint8Array(u).buffer,v=await p(y(h.context,_),g.signal);if(k+=v.length*v.numberOfChannels*4,k>x*4)throw RangeError(`glTF audio exceeds decoded PCM budget; raise maxDownloadBytes`);return v})(),j.set(l,u),u)},L=async(t,n,r,i)=>{g.signal?.throwIfAborted();let a=d(r,`emitter`),p=f(n.emitters,a,`emitter`),y=t===`KHR_audio_emitter`,b=y?p.type===`positional`:i!==void 0;if(y&&p.type!==`positional`&&p.type!==`global`)throw o(`emitter type`);if(b&&i===void 0)throw o(`positional scene emitter`);let x=y?p.positional===void 0?{}:s(p.positional,`positional`):p;if(!b&&(y?p.positional!==void 0:[`distanceModel`,`refDistance`,`maxDistance`,`rolloffFactor`,`innerAngle`,`outerAngle`].some(e=>p[e]!==void 0)))throw o(`global emitter spatial properties`);let O=l(y?p.gain:p.volume,1,`emitter gain`),k=x.distanceModel??(y?`inverse`:`exponential`);if(![`linear`,`inverse`,`exponential`].includes(String(k)))throw o(`distance model`);let j=l(x.refDistance,1,`reference distance`);if(!j)throw o(`reference distance`);let M=l(x.maxDistance,y?0:256,`maximum distance`)||34028234663852886e22;if(k===`linear`&&M<=j)throw o(`linear maximum distance`);let N=l(x.rolloffFactor,1,`rolloff`,k===`linear`?1:1/0),P=x.shapeType??`omnidirectional`;if(y&&![`cone`,`omnidirectional`].includes(String(P)))throw o(`emitter shape`);let F=y?P===`cone`:x.innerAngle!==void 0||x.outerAngle!==void 0,L=y?180/Math.PI:360/Math.PI,R=y?Math.PI*2:Math.PI,z=F?l(y?x.coneInnerAngle:x.innerAngle,R,`inner cone angle`,R)*L:360,B=F?l(y?x.coneOuterAngle:x.outerAngle,R,`outer cone angle`,R)*L:360;if(B<z)throw o(`cone angle order`);let V={volume:O,direction:y?[0,0,-1]:[0,0,1],mesh:i===void 0?void 0:m.nodes[i],distanceModel:k,refDistance:j,maxDistance:M,rolloffFactor:N,coneInnerAngle:z,coneOuterAngle:B,coneOuterGain:y?l(x.coneOuterGain,0,`cone outer gain`,1):0},H=c(y?p.sources??[]:p.clips,`emitter sources`);if((y?H.length:1)>S-E.length)throw RangeError(`glTF audio exceeds source budget; raise maxSources`);if(!y&&!H.length)throw o(`empty MSFT clips`);let U=y?H.map(e=>f(n.sources,e,`source`)):H.map(e=>s(e,`clip reference`)),W=[];for(let e of U)W.push(await I(t,n,y?e.audio:e.clip));let G=y?[]:U.map(e=>l(e.weight,1,`clip weight`)),K=G.reduce((e,t)=>e+t,0);if(!y&&(!Number.isFinite(K)||K<=0))throw o(`clip weights`);let q=[];for(let e=0;e<(y?U.length:1);e++){let t=U[e],n={...V,loop:u(y?t.loop:p.loop,`loop`),volume:O*(y?l(t.gain,1,`source gain`):1)},r=b?new v(h,n):new _(h,n);E.push(r),q.push(r),r.setBuffer(W[e])}let J=/* @__PURE__ */ new WeakMap,Y=e=>{if(y)return;let t=e&&J.get(e);if(t===void 0){let n=C();if(!Number.isFinite(n)||n<0||n>=1)throw o(`random sample`);let r=n*K,i=0;for(t=G.length-1;G[t]===0;)t--;for(let e=0;e<G.length;e++)if(r<(i+=G[e])){t=e;break}e&&J.set(e,t)}q[0].buffer!==W[t]&&(q[0].stop(),q[0].setBuffer(W[t]))},X=()=>{if(A)throw e(`disposed`,`glTF audio is disposed; apply the audio extension again`)},Z={extension:t,emitterIndex:a,nodeIndex:i,name:typeof p.name==`string`?p.name:``,sources:q,play(e=0){X(),l(e,0,`play offset`),Y();for(let t of q)t.stop(),t.offset=e,t.play()},pause(){X();for(let e of q)e.pause()},stop(){X();for(let e of q)e.stop()}};T.push(Z),D.push({emitter:Z,choose:Y});for(let e=0;e<q.length;e++){let t=y&&u(U[e].autoPlay,`autoPlay`);g.autoplay!==!1&&(g.autoplay===!0||t)&&w.push({sound:q[e],choose:y?void 0:Y})}},R=()=>{},z=()=>{if(!A){A=!0,R();for(let e of E)e.dispose();j.clear()}};try{for(let e of[`KHR_audio_emitter`,`MSFT_audio_emitter`]){let t=b.extensions?.[e];if(t===void 0)continue;let n=s(t,e);for(let t of P){let r=b.nodes?.[t]?.extensions?.[e];if(r===void 0)continue;let i=s(r,`node emitter`),a=e===`KHR_audio_emitter`?[i.emitter]:c(i.emitters,`node emitters`);for(let r of a)await L(e,n,r,t)}let r=N&&N.extensions?.[e];if(r!==void 0)for(let t of c(s(r,`scene emitter`).emitters,`scene emitters`))await L(e,n,t)}if(g.signal?.throwIfAborted(),m.disposed)throw e(`disposed`,`Model was disposed while audio loaded; load it again`);let t={emitters:T,dispose:z,[Symbol.dispose]:z,sync(t,n,r=0){if(A)throw e(`disposed`,`glTF audio is disposed; apply the audio extension again`);if(l(t,0,`timeline time`),typeof n!=`boolean`)throw o(`playing`);let i=(b.animations?.[d(r,`animation`)])?.extensions?.MSFT_audio_emitter,a=(i===void 0?[]:c(s(i,`animation events`).events,`events`).map(e=>s(e,`event`))).map((e,t)=>({event:e,order:t,time:l(e.time,NaN,`event time`)})).sort((e,t)=>e.time-t.time||e.order-t.order);for(let{emitter:e,choose:r}of D){if(e.extension!==`MSFT_audio_emitter`)continue;let i=!1,c=!1,u=0,p=0,m;for(let{event:n,time:r}of a){let a=d(n.emitter,`event emitter`);if(f(s(b.extensions?.MSFT_audio_emitter,`MSFT_audio_emitter`).emitters,a,`event emitter`),![`play`,`pause`,`stop`].includes(String(n.action)))throw o(`event action`);r>t||a!==e.emitterIndex||(n.action===`play`?(c||(u=l(n.startOffset,0,`start offset`),m=n),i=!0,c=!1,p=r):n.action===`pause`?(i&&(u+=r-p),i=!1,c=!0):(u=0,i=!1,c=!1,m=void 0))}i&&(u+=t-p),m&&r(m);for(let t of e.sources)t.offset=0,t.sync(u,i&&n)}}};R=m.onDispose(z);for(let{sound:e,choose:t}of w)t?.(),e.play();return t}catch(e){throw z(),e}}export{m as applyGLTFAudio};
package/dist/auto.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ import type { EngineKernel } from '@margoengine/core';
2
+ import type { PBRModel } from '@margoengine/gltf/pbr';
3
+ import { type GLTFOptions, type Model } from './index.js';
4
+ /** Options for {@link loadAuto}: those of `loadGLTF`, minus `extensions`, which the file decides. */
5
+ export interface AutoOptions extends Omit<GLTFOptions, 'extensions'> {
6
+ signal?: AbortSignal;
7
+ /** Fetch for the file and what it refers to. Default `globalThis.fetch`. Each URL is fetched once, whichever loader runs. */
8
+ fetch?: typeof fetch;
9
+ }
10
+ /** What {@link loadAuto} loaded, tagged by the loader that took it. */
11
+ export type AutoModel = {
12
+ loader: 'gltf';
13
+ model: Model;
14
+ } | {
15
+ loader: 'gltf/pbr';
16
+ model: PBRModel;
17
+ /** Why the light loader refused the file. */
18
+ reason: string;
19
+ };
20
+ /**
21
+ * Loads a .gltf or .glb without having to know what it holds. The light loader runs with only the `@margoengine/gltf/*`
22
+ * entries the file calls for; if it refuses the file as unsupported, which includes passing a limit only the light loader
23
+ * has (one million vertices, instances past `maxNodes`, 64 MiB of downloads), `@margoengine/gltf/pbr` is imported and loads it from the bytes
24
+ * already downloaded, instances included. A malformed file throws either way.
25
+ * @example
26
+ * const { model, loader } = await loadAuto(engine, '/any.glb');
27
+ * // On teardown: model.dispose();
28
+ */
29
+ export declare function loadAuto(engine: EngineKernel, url: string | URL, { signal, fetch: get, maxNodes, allowedURLs }?: AutoOptions): Promise<AutoModel>;
package/dist/auto.js ADDED
@@ -0,0 +1 @@
1
+ import{d as e,o as t,s as n,u as r}from"./version-BmU1nesQ.js";import{i,t as a}from"./src-WMRHArDp.js";import{t as o}from"./scene-scope-CZDEkd24.js";import{MargoError as s}from"@margoengine/math/errors";var c=e=>Array.isArray(e)?e:[],l=(e,t)=>c(e.extensionsUsed).includes(t)||c(e.extensionsRequired).includes(t);async function u(e){let t=c(e.meshes).flatMap(e=>c(e?.primitives)),n=[];return(l(e,`EXT_meshopt_compression`)||l(e,`KHR_meshopt_compression`)||c(e.bufferViews).some(e=>e?.extensions))&&n.push(import(`./meshopt.js`).then(e=>e.meshopt)),(l(e,`KHR_mesh_quantization`)||t.some(t=>[t?.attributes?.POSITION,t?.attributes?.NORMAL].some(t=>t!==void 0&&c(e.accessors)[t]?.componentType!==5126)))&&n.push(import(`./quantized.js`).then(e=>e.quantized)),c(e.materials).some(e=>e?.pbrMetallicRoughness?.baseColorTexture||e?.alphaMode===`MASK`)&&n.push(import(`./textured.js`).then(e=>e.textured)),l(e,`EXT_mesh_gpu_instancing`)&&n.push(import(`./instancing.js`).then(e=>e.instancing)),(l(e,`KHR_lights_punctual`)||c(e.nodes).some(e=>e?.camera!==void 0))&&n.push(import(`./scene-data.js`).then(e=>e.sceneExtras)),Promise.all(n)}function d(e){let i=n(e)?t(e)[0].data:e;try{return r(new TextDecoder().decode(i))??{}}catch(e){throw TypeError(`Invalid glTF JSON: ${e.message}; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`)}}var f=536870912,p=()=>/* @__PURE__ */ RangeError(`glTF download byte budget exceeded; raise maxBytes`);function m({response:e,chunks:t,error:n},r){let i=0,a=e.body===null||[204,205,304].includes(e.status)?null:new ReadableStream({pull(e){i<t.length?(e.enqueue(t[i]),r&&(t[i]=void 0),i++):n===void 0?e.close():e.error(n)}}),o=new Response(a,{status:e.status,statusText:e.statusText,headers:e.headers});return Object.defineProperties(o,{url:{value:e.url},redirected:{value:e.redirected}})}function h(e){let t=/* @__PURE__ */ new Map,n=0,r=!0,i=async(t,r)=>{let i=await e(t,r),a={response:i,chunks:[],size:0};if(!i.ok||!i.body)return i.body?.cancel().catch(()=>{}),a;let o=i.body.getReader(),s=r?.signal??void 0,c=()=>o.cancel(s?.reason).catch(()=>{});s?.addEventListener(`abort`,c,{once:!0});try{if(Number(i.headers.get(`content-length`))>f-n)throw p();for(let e=await o.read();!e.done;e=await o.read()){if(s?.throwIfAborted(),!(e.value instanceof Uint8Array))throw TypeError(`glTF download stream requires byte chunks; have fetch return a Response whose body yields Uint8Array`);if(e.value.byteLength>f-n-a.size)throw p();a.chunks.push(e.value),a.size+=e.value.byteLength}s?.throwIfAborted(),n+=a.size}catch(e){o.cancel(e).catch(()=>{}),a.error=e,a.chunks=[],a.size=0}finally{s?.removeEventListener(`abort`,c)}return a};return Object.assign((n,a)=>{let o=String(n instanceof Request?n.url:n),s=t.get(o);if(!s){if(!r)return e(n,a);t.set(o,s=i(n,a))}let c=!r;return c&&t.delete(o),s.then(e=>m(e,c))},{release(e){r=!1,e&&t.clear()}})}async function g(e,t,{signal:n,fetch:r=globalThis.fetch,maxNodes:i,allowedURLs:a}={}){n?.throwIfAborted();let s=new URL(t,globalThis.location?.href);if(![`http:`,`https:`].includes(s.protocol))throw TypeError(`glTF URL must use HTTP(S)`);let c=h(r);try{return await _(e,s,o(e),{signal:n,fetch:c,maxNodes:i,allowedURLs:a})}finally{c.release(!0)}}async function _(t,n,r,o){let{signal:c,fetch:f}=o,p=async(e,i)=>{f.release(!1);let a=await import(`@margoengine/gltf/pbr`),c=!i||l(i,`EXT_mesh_gpu_instancing`)?{instancing:(await import(`@margoengine/gltf/pbr-instancing`)).instancing}:void 0;try{return{loader:`gltf/pbr`,model:await r.run(()=>a.loadGLTF(t,n,c?{...o,decoders:c}:o)),reason:e}}catch(t){throw t instanceof s&&t.code===`unsupported`&&!t.message.includes(e)?new s(`unsupported`,`${e}; gltf/pbr cannot load it here either: ${t.message}`):t}},m;try{m=await e(await f(n,{signal:c}),{maxBytes:67108864,signal:c,label:`glTF download`})}catch(e){if(!(e instanceof RangeError))throw e;return p(`The file is over the light loader's 64 MiB`)}i(m,n.href);let h=d(m);try{let e=await u(h);return{loader:`gltf`,model:await r.run(()=>a(t,n,{...o,extensions:e}))}}catch(e){if(!(e instanceof s)||e.code!==`unsupported`)throw e;return p(e.message,h)}}export{g as loadAuto};
@@ -0,0 +1,20 @@
1
+ export interface BaseTextureSource {
2
+ view: GPUTextureView;
3
+ width: number;
4
+ height: number;
5
+ levels: number;
6
+ sampler: {
7
+ magFilter?: number;
8
+ minFilter?: number;
9
+ wrapS?: number;
10
+ wrapT?: number;
11
+ };
12
+ }
13
+ export interface PackedBaseTextures {
14
+ texture: GPUTexture;
15
+ view: GPUTextureView;
16
+ params: GPUBuffer;
17
+ destroy(): void;
18
+ }
19
+ /** Internal: preserve original linear texels at each logical mip size in independently addressed array layers. */
20
+ export declare function packBaseTextures(device: GPUDevice, sources: readonly BaseTextureSource[]): PackedBaseTextures;
@@ -0,0 +1,29 @@
1
+ import type { Mesh } from '@margoengine/core/extension';
2
+ import type { PBRMaterial, PBRPrimitive } from './pbr.js';
3
+ /** One static part baked into a material batch, with the root-relative matrix and source arrays captured at bake time. */
4
+ export interface BatchPart {
5
+ primitive: PBRPrimitive;
6
+ stamp: Float32Array;
7
+ vertices: Float32Array;
8
+ indices: Uint32Array;
9
+ }
10
+ /**
11
+ * Several unskinned, unmorphed, non-instanced primitives that share one material, drawn as one mesh parented to the
12
+ * model root. Vertices are copied into root space. Callers draw the originals again when a part moves, hides, or
13
+ * changes material.
14
+ */
15
+ export interface StaticBatch {
16
+ node: Mesh;
17
+ material: PBRMaterial;
18
+ primitive: PBRPrimitive;
19
+ parts: BatchPart[];
20
+ }
21
+ /** True for a primitive a static batch can hold, whatever it shares a material with. */
22
+ export declare function eligible(p: PBRPrimitive): boolean;
23
+ /**
24
+ * Batches of a copy from `source`'s: the same baked arrays and part poses, with the copy's own primitives and nodes.
25
+ * `own` gives the copy's primitive for a source primitive.
26
+ */
27
+ export declare function copyStaticBatches(source: readonly StaticBatch[], own: (primitive: PBRPrimitive) => PBRPrimitive, createNode: () => Mesh): StaticBatch[];
28
+ /** Groups of two or more static primitives that can share one draw. World matrices must already be published. */
29
+ export declare function buildStaticBatches(primitives: readonly PBRPrimitive[], root: Mesh, createNode: () => Mesh): StaticBatch[];
@@ -0,0 +1 @@
1
+ import{n as e}from"./errors-THVaUwlL.js";import{d as t,h as n,k as r,m as i,w as a}from"./asset-1b8ejkZX.js";var o=3*r,s={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT4:16},c={POSITION:`positions`,NORMAL:`normals`,TEXCOORD_0:`uvs`,COLOR_0:`colors`},l={5120:127,5121:255,5122:32767,5123:65535};async function u(u,{signal:d,draco:f}={}){d?.throwIfAborted();let p,m=a.get(u)??/* @__PURE__ */ new Map;a.set(u,m);try{for(let a of u.doc.meshes??[])for(let h of a.primitives??[]){let a=h.extensions?.KHR_draco_mesh_compression;if(!a||m.has(h))continue;if((h.mode??4)!==4)throw e(`unsupported`,`PBR requires triangle primitives; re-export the mesh with mode 4 (TRIANGLES)`);if(!a.attributes||typeof a.attributes!=`object`||Array.isArray(a.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 g={},_={},v={},y=i(u.doc.accessors,h.attributes?.POSITION,`Draco POSITION`),b=n(y.count,`Draco vertex count`,3);if(b>16777216)throw e(`unsupported`,`glTF primitive has more than ${r} vertices, the most one primitive may hold; split the mesh into several primitives`);if(y.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 x=0;for(let[e,t]of Object.entries(a.attributes)){let r=i(u.doc.accessors,h.attributes?.[e],`Draco attribute`),a=n(r.count,`Draco accessor count`,1),o=Object.hasOwn(s,r.type)?s[r.type]:void 0;if(!o||a!==b)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`);x+=a*o*4,g[e]=n(r.componentType,`Draco component type`),_[e]=n(t,`Draco attribute id`),v[e]=o}let S=h.indices===void 0?void 0:i(u.doc.accessors,h.indices,`Draco indices`);if(S){if(S.type!==`SCALAR`||![5121,5123,5125].includes(S.componentType)||S.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=n(S.count,`Draco index count`,1);if(e>o||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`);x+=e*4}if(x>u.maxBytes*4)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);let C=u.view(a.bufferView);if(x>u.remainingDecodedBytes)throw RangeError(`Decoded glTF exceeds byte budget; load a smaller model, or reduce its textures and meshes`);let w=S?S.count:Math.min(o,Math.floor((u.remainingDecodedBytes-x)/4));if(w<3)throw RangeError(`Decoded glTF exceeds index byte budget; load a smaller model, or reduce its textures and meshes`);if(!f){let{DracoDecoder:e}=await t(u,`Draco`)();d?.throwIfAborted(),f=p=new e}let T=await f.decode(C,{attributeIds:_,componentTypes:g,signal:d,limits:{maxVertices:b,maxIndices:w,maxDecodedBytes:u.remainingDecodedBytes,attributeWidths:v}});d?.throwIfAborted();let E=n(T.vertexCount,`Draco vertex count`,3),D=T.indices;if(E>16777216||!(D instanceof Uint16Array||D instanceof Uint32Array)||!D.length||D.length>o||D.length%3||D.some(e=>e>=E)||S&&D.length!==S.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 e of Object.keys(_)){let t=h.attributes[e],n=i(u.doc.accessors,t,`Draco attribute`),r=Object.hasOwn(c,e)?c[e]:void 0,a=T.attributes?.[e],o=r?T[r]:a?.array;if(!ArrayBuffer.isView(o)||o instanceof DataView||n.count!==E||o.length!==E*s[n.type]||!r&&(a?.itemSize!==s[n.type]||a.componentType!==n.componentType))throw RangeError(`Mismatched glTF Draco attribute `+e+`; the accessor must match the Draco stream, re-export the model`);let d=Float32Array.from(o);if(n.normalized&&e!==`COLOR_0`){let e=l[n.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<d.length;t++)d[t]=Math.max(-1,d[t]/e)}u.setDecodedAccessor(t,d)}h.indices===void 0&&u.reserveDecodedBytes(D.length*4);let O=Float32Array.from(D);h.indices!==void 0&&u.setDecodedAccessor(h.indices,O),m.set(h,h.indices===void 0?O:u.accessor(h.indices,`SCALAR`))}}finally{p?.dispose()}}export{u as decompressPrimitives};
@@ -0,0 +1,15 @@
1
+ import type { KTX2Decoder } from '@margoengine/decoders';
2
+ import { type GLTFAsset } from './asset.js';
3
+ /**
4
+ * Options for loading compressed glTF: an AbortSignal and optional reusable Draco, meshopt and KTX2 decoders the caller owns.
5
+ */
6
+ export interface GLTFLoadOptions {
7
+ signal?: AbortSignal;
8
+ /** Optional reusable decoder. The caller retains ownership; otherwise a decoder is created and disposed per load. */
9
+ draco?: {
10
+ decode(data: Uint8Array, options: import('./asset.js').GLTFDracoDecodeOptions): Promise<import('./asset.js').GLTFDracoGeometry>;
11
+ };
12
+ /** Optional reusable Basis transcoder. Only files with KTX2 images create an automatic decoder. */
13
+ ktx2?: Pick<KTX2Decoder, 'transcode'>;
14
+ }
15
+ export declare function decompressPrimitives(asset: GLTFAsset, { signal, draco }?: GLTFLoadOptions): Promise<void>;
@@ -0,0 +1 @@
1
+ export { textureCoordinates, type TextureTransform, type UVSet } from './texture-coordinates.js';
@@ -0,0 +1 @@
1
+ export{r as textureCoordinates}from"./texture-coordinates-XFsEMdU6.js";
package/dist/dds.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { GLTFCompressedImage, GLTFDecoderHooks } from './asset.js';
2
+ /** Parse a single-layer 2D DDS, retaining every mip for upload, device restoration and model clones. */
3
+ export declare function decodeDDSImage(data: Uint8Array, options?: {
4
+ signal?: AbortSignal;
5
+ }): GLTFCompressedImage;
6
+ /** MSFT_texture_dds decoder hook. Async glTF loaders select it lazily when a file uses the extension. */
7
+ export declare const ddsTextures: NonNullable<GLTFDecoderHooks['dds']>;