@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
package/dist/dds.js ADDED
@@ -0,0 +1 @@
1
+ import{n as e}from"./errors-THVaUwlL.js";import"./image-limit-DvFSfR5T.js";var t=(e,t)=>Object.assign(Error(e,t===void 0?void 0:{cause:t}),{name:`MargoError`,code:`failed`}),n=e=>Object.assign(Error(e),{name:`MargoError`,code:`unsupported`}),r={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 i(e){if(r[e])return[1,1,r[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 a(e,t,n){let r=Math.ceil(t/e[0])*e[2];return[r*Math.ceil(n/e[1]),r]}function o(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 s(e,t,r={}){let o=i(t.format);if(!o)throw TypeError(`Texture format ${String(t.format)} is unknown; pass a parseDDS or parseKTX result`);let[s,c,,l]=o;if(l&&!e.features.has(l))throw n(`Texture format ${t.format} needs the device feature ${l}; request it with adapter.requestDevice({requiredFeatures: ['${l}']}) where adapter.features has it, or convert the file to an uncompressed format`);if(t.width%s||t.height%c)throw RangeError(`Texture ${t.width}x${t.height} is not a whole number of ${s}x${c} ${t.format} blocks; resize the source to a multiple of ${s}x${c}`);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 u=e.createTexture({label:r.label,size:[t.width,t.height,t.layers],mipLevelCount:t.mipmaps.length,format:t.format,usage:r.usage??GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST});try{for(let[n,r]of t.mipmaps.entries()){let i=Math.ceil(r.height/c);e.queue.writeTexture({texture:u,mipLevel:n},r.data,{bytesPerRow:a(o,r.width,r.height)[1],rowsPerImage:i},[Math.ceil(r.width/s)*s,i*c,t.layers])}}catch(e){throw u.destroy(),e}return u}var c={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`},l={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`},u={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]},d=e=>t(`DDS ${e}; pass the complete bytes of a valid DDS file`),f=e=>t(`DDS ${e} is not supported; convert the file to a 2D, cube or array texture in a WebGPU format`);function p(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 m(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 d(`header is missing`);let r=n(12),s=n(16),m=n(80),h=n(112),g=String.fromCharCode(e[84],e[85],e[86],e[87]),_=Math.max(1,n(28));if(!s||!r||s>65536||r>65536)throw d(`size ${s}x${r} is invalid`);if(_>32-Math.clz32(Math.max(s,r)))throw d(`has ${_} mip levels, too many for its size`);if(h&2097152||n(8)&8388608&&n(24)>1)throw f(`volume texture`);let v,y,b=0,x=!1,S=!0,C=!!(h&512),w=1,T=128;if(C&&(h&64512)!=64512)throw f(`cube map without all six faces`);if(m&4&&g===`DX10`){if(e.length<148)throw d(`DX10 header is missing`);let t=n(128),r=u[t];if(n(132)!==3&&n(132)!==0)throw f(`resource dimension ${n(132)} (only 2D textures)`);if(C=!!(n(136)&4),w=n(140)||1,S=(n(144)&7)!=3,T=148,r?([b]=r,b/=8,y=r.slice(1,5),v=r[5]?`rgba8unorm-srgb`:`rgba8unorm`,S&&=!!r[4]):v=l[t],!v)throw f(`DXGI format ${t}`)}else if(m&4){let e=/^[\x20-\x7e]{4}$/.test(g)?g:String(n(84));if(v=c[e],!v)throw f(`FourCC ${e}`)}else if(m&131138){let e=n(88),t=m&3?n(104):0;if(x=!!(m&131072),y=m&131136?[n(92),n(96),n(100),t]:[0,0,0,t],![8,16,24,32].includes(e)||y.every(e=>!e))throw d(`pixel format of ${e} bits is invalid`);b=e/8,S=!!t,v=`rgba8unorm`,e===32&&!x&&y.join()===[255,65280,16711680,t?4278190080:0].join()&&t&&(y=void 0)}else throw f(`pixel format (YUV or unknown)`);let E=i(v),D=w*(C?6:1),O=[];(/^bc[456]/.test(v)||/^(r|rg)\d/.test(v))&&(S=!1);for(let t=0;t<D;t++){let n=[];for(let i=0;i<_;i++){let o=Math.max(1,s>>i),c=Math.max(1,r>>i),l=y?o*c*b:a(E,o,c)[0];if(T+l>e.length)throw d(`ends inside layer ${t} mip ${i}`);let u=e.subarray(T,T+=l);n.push(y?p(u,o*c,b,y,x):u)}O.push(n)}return{width:s,height:r,layers:D,dimension:C?w>1?`cube-array`:`cube`:D>1?`2d-array`:`2d`,mipmaps:o(O,s,r),format:v,...E[3]?{feature:E[3]}:{},target:`dds`,srgb:v.endsWith(`-srgb`),hasAlpha:S}}var h=`0011001100110011000100010001000101110111011101110001001100110111000000010001001100110111011111110001001101111111000000010011011100000000000100110011011111111111000000010111111100000000000101110001011111111111000000001111111100001111111111110000000000001111000010001110111101110001000000000000000010001110011100110001000000110001000000000000100011001110000000001000110001110011001100010011000100010000000010001000110001100110011001100011011001101100000101111110100000001111111100000111000110001110001110011001110001010101010101010000111100001111010110100101101000110011110011000011110000111100010101011010101001101001011010010101101010100101011100111100111000010011110010000011001001001100001110111101110001101001100101100011110011000011011001101001100100000110011000000100111001000000001001110010000000000010011100100000010011100100011011001001001100110110110010010110001110011100001110011100011001101100110010010110001100111001011111101000000100011000111001110000111100110011001100111111000000100010111011100100010001110111`,g=`0011001102212222000100112211222100002001221122110222002200110111000000001122112200110011002200220022002211111111001100112211221100000000111122220000111111112222000011112222222200120012001200120112011201120112012201220122012200110112112212220011200122002220000100110112112201110011200122000000112211221122002200220022111101110111022202220001000122212221000000110122012200001100221022100122012200110000001200121122222201101221122101100000011012211221002211021102002201100110200222220011012201220011000020002211222100000002112212220222002200120011001100120022022201200120012001200000111122220000012012012012012001202012120101200011220011220011001111222200001101010101222222220000000021212121002211220022112200220011002200110220122102201221010122222222010100002121212121210101010101012222022201110222011100021112000211120000211221122112022201110111022200021112111200020110011001102222000000002112211201100110222222220022001100110022002211221122002200000000000021120002000100020001022212220222122201012222222222220111201122012220`,_=[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],v=[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],y=[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],b=e=>Math.round((Math.max(e,-127)+127)/254*255),x=e=>e<<3|e>>2,S=e=>e<<2|e>>4;function C(e,t,n,r){let i=e[t]|e[t+1]<<8,a=e[t+2]|e[t+3]<<8,o=[x(i>>11),S(i>>5&63),x(i&31),255,x(a>>11),S(a>>5&63),x(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 w(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?b(u):Math.round(u)}}var T=(e,t,n)=>C(e,t,n,!0),E=(e,t,n)=>{C(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},D=(e,t,n)=>{C(e,t+8,n,!1),w(e,t,n,3,!1)},O=e=>(t,n,r)=>{w(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},k=e=>(t,n,r)=>{w(t,n,r,0,e),w(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};function A(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}var j={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]},M=[[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]],N=(e,t)=>{let n=e<<8-t;return n|n>>t},P=(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]=M[r],m=r+1,b=n=>{let r=A(e,t,m,n);return m+=n,r},x=b(a),S=b(o),C=b(s),w=i*2,T=new Uint8Array(w*4);for(let e=0;e<3;e++)for(let t=0;t<w;t++)T[t*4+e]=b(c);if(l)for(let e=0;e<w;e++)T[e*4+3]=b(l);let E=new Uint8Array(w);if(u)for(let e=0;e<w;e++)E[e]=b(1);if(d)for(let e=0;e<i;e++)E[e*2]=E[e*2+1]=b(1);let D=u||d?1:0;for(let e=0;e<w;e++)for(let t=0;t<4;t++){if(t===3&&!l){T[e*4+3]=255;continue}let n=(t===3?l:c)+D;T[e*4+t]=N(D?T[e*4+t]<<1|E[e]:T[e*4+t],n)}let O=e=>i===1?0:(i===2?h:g).charCodeAt(x*16+e)-48,k=e=>e===0||i===2&&e===_[x]||i===3&&(e===v[x]||e===y[x]),P=/* @__PURE__ */ new Uint8Array(16),F=/* @__PURE__ */ new Uint8Array(16);for(let e=0;e<16;e++)P[e]=b(k(e)?f-1:f);if(p)for(let e=0;e<16;e++)F[e]=b(e===0?p-1:p);let I=C?F:P,L=C?P:p?F:P,R=j[C?p:f],z=j[C?f:p||f];for(let e=0;e<16;e++){let t=O(e)*8,r=R[I[e]],i=z[L[e]],a=(e,n)=>(64-n)*T[t+e]+n*T[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]=S===1?l:o,n[u+1]=S===2?l:s,n[u+2]=S===3?l:c,n[u+3]=S===1?o:S===2?s:S===3?c:l}},F={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`},I={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]},L=/* @__PURE__ */ new Map;function R(e){let t=L.get(e);return t||(t=F[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]}),L.set(e,t)),t}var z=(e,t)=>t>=32?e:e<<32-t>>32-t;function B(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}var V=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},H=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)},U=e=>(t,n,r)=>{let i=A(t,n,0,2),a=i<2?i:A(t,n,0,5),o=I[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=/* @__PURE__ */ new Int32Array(12),f=i<2?2:5;for(let[e,r,i]of R(a))for(let a of i)t[n+(f>>3)]>>(f&7)&1&&(d[e*3+r]|=1<<a),f++;let p=u?A(t,n,f,5):0;f+=u?5:0;let m=u?4:2;for(let t=0;t<3;t++){e&&(d[t]=z(d[t],c));for(let n=1;n<m;n++){let r=n*3+t;s&&(d[r]=z(d[r],l[t])+d[t]&(1<<c)-1),e&&(d[r]=z(d[r],c))}for(let n=0;n<m;n++)d[n*3+t]=B(d[n*3+t],c,e)}let g=u?3:4,v=j[g];for(let i=0;i<16;i++){let a=u?h.charCodeAt(p*16+i)-48:0,o=i===0||u&&i===_[p]?g-1:g,s=v[A(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?V(l):H(V(l))}r[i*4+3]=r instanceof Float32Array?1:255}},W={"bc1-rgba":[T,8],"bc2-rgba":[E,16],"bc3-rgba":[D,16],"bc4-r-unorm":[O(!1),8],"bc4-r-snorm":[O(!0),8],"bc5-rg-unorm":[k(!1),16],"bc5-rg-snorm":[k(!0),16],"bc6h-rgb-ufloat":[U(!1),16],"bc6h-rgb-float":[U(!0),16],"bc7-rgba":[P,16]};function G(e,n,r,i){let a=W[e.replace(/-unorm(-srgb)?$/,t=>/^bc[45]/.test(e)?t:``)];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=r+3>>2,l=i+3>>2;if(n.length<c*l*s)throw t(`${e}: ${n.length} bytes hold too few blocks for ${r}x${i}; pass the whole level`);let u=new Uint8Array(r*i*4),d=/* @__PURE__ */ new Uint8Array(64);for(let e=0;e<l;e++)for(let t=0;t<c;t++){o(n,(e*c+t)*s,d);for(let n=0;n<4&&e*4+n<i;n++){let i=Math.min(4,r-t*4);u.set(d.subarray(n*16,n*16+i*4),((e*4+n)*r+t*4)*4)}}return{width:r,height:i,data:u}}function K(e,n,r,i){if(!/^bc[456]/.test(e)){let t=G(e,n,r,i);return{width:r,height:i,data:Float32Array.from(t.data,e=>e/255)}}let a=W[e];if(!a)throw TypeError(`Unknown BC float format `+e+`; pass a BC4, BC5 or BC6H WebGPU format`);let[o,s]=a,c=Math.ceil(r/4),l=Math.ceil(i/4);if(n.length<c*l*s)throw t(`BC float image has too few blocks; pass the complete mip level`);let u=new Float32Array(r*i*4),d=/* @__PURE__ */ new Float32Array(64);for(let e=0;e<l;e++)for(let t=0;t<c;t++){o(n,(e*c+t)*s,d);for(let n=0;n<4&&e*4+n<i;n++){let i=Math.min(4,r-t*4);u.set(d.subarray(n*16,n*16+i*4),((e*4+n)*r+t*4)*4)}}return{width:r,height:i,data:u}}function q(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 J(t,n={}){n.signal?.throwIfAborted();let r=m(t);if(r.dimension!==`2d`||r.layers!==1)throw e(`unsupported`,`glTF material DDS images must be single-layer 2D textures; export a 2D image`);if(r.width*r.height>67108864)throw RangeError(`glTF DDS image exceeds decoded size limit; export a smaller texture`);let i,a=e=>{if(!r.feature||e.features.has(r.feature)&&r.width%4==0&&r.height%4==0)return r;if(!i){let e=/^bc[456]/.test(r.format),t=r.mipmaps.map(t=>{let n=e?K(r.format,t.data,t.width,t.height):G(r.format,t.data,t.width,t.height),i=e?Uint16Array.from(n.data,q):n.data,a=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);return{...t,data:a,byteLength:a.length}});i={...r,format:e?`rgba16float`:`rgba8unorm`,feature:void 0,mipmaps:t}}return i},o=(e,t)=>{let n=a(e).format.replace(/-srgb$/,``);return n+(t&&/^(rgba8unorm|bc[1237]-)/.test(n)?`-srgb`:``)};return{width:r.width,height:r.height,format:r.format,mipmaps:r.mipmaps,gpuFormat:o,upload(t,n){let r=a(t),i=o(t,n);if(/^(r|rg|rgba)32float$/.test(i)&&!t.features.has(`float32-filterable`))throw e(`unsupported`,`32-bit float DDS material textures require float32-filterable; request that device feature or export 16-bit float DDS`);return s(t,{...r,format:i})}}}var Y={decode:J};export{Y as ddsTextures,J as decodeDDSImage};
@@ -0,0 +1 @@
1
+ var e=()=>import(`@margoengine/decoders`),t=t=>({...t,decoders:{decoderModule:e,...t.decoders}});export{t};
@@ -0,0 +1,5 @@
1
+ import type { GLTFDecoderHooks } from './asset.js';
2
+ /** The options with a way to the built-in decoders, unless the caller gave one. */
3
+ export declare const withDecoders: <T extends {
4
+ decoders?: GLTFDecoderHooks;
5
+ }>(options: T) => T;
@@ -0,0 +1,8 @@
1
+ import type { GLTFDocument } from './shared/gltf.js';
2
+ import type { GLTFDecoderHooks } from './asset.js';
3
+ /**
4
+ * Decoders with the physical material shader added when the file uses a physical material extension and the caller
5
+ * did not choose (`materials` undefined): imported on first need, so apps that never load such a file ship none of its
6
+ * WGSL. `materials: false` is kept as no shader. The same goes for `splats`, added when the file holds Gaussian splats.
7
+ */
8
+ export declare function withMaterials(doc: GLTFDocument, decoders?: GLTFDecoderHooks): Promise<GLTFDecoderHooks>;
@@ -0,0 +1,7 @@
1
+ import type { GLTFPrimitive } from './shared/gltf.js';
2
+ import type { GLTFAsset } from './asset.js';
3
+ export declare const decoded: WeakMap<GLTFAsset, Map<object, Float32Array<ArrayBufferLike>>>;
4
+ /** Whether any mesh primitive of the asset uses KHR_draco_mesh_compression (walked like decompressPrimitives). */
5
+ export declare function hasDraco(asset: GLTFAsset): boolean;
6
+ /** Draco topology belongs to the primitive, including when no index accessor is declared. */
7
+ export declare function compressedIndices(asset: GLTFAsset, primitive: GLTFPrimitive): Float32Array | undefined;
@@ -0,0 +1,83 @@
1
+ import type { UniformSlot } from './uniform-arena.js';
2
+ /**
3
+ * What gltf/pbr's derivation reads of a batch's instancing (as of a `PBRInstances`): the instance layout, the
4
+ * instanced vertex stage and whether the rows are mirrored. One per handedness, shared by every batch, so every batch
5
+ * of a material shares one derivation and pipeline.
6
+ */
7
+ export declare class BatchKind {
8
+ readonly mirrored: boolean;
9
+ readonly rows: boolean;
10
+ readonly layout: GPUVertexBufferLayout;
11
+ /**
12
+ * @param rows - Each instance reads its own uniform block (`rowsShader`, applied by the derivation once the shader is
13
+ * finished): a batch of meshes whose materials share a pipeline and group 2 but not their uniform rows.
14
+ */
15
+ constructor(mirrored: boolean, rows?: boolean);
16
+ shader(code: string): string;
17
+ }
18
+ /** The batch kind for draws whose node matrices are mirrored (negative determinant) or not; `rows`: see `BatchKind`. */
19
+ export declare const batchKind: (mirrored: boolean, rows?: boolean) => BatchKind;
20
+ /**
21
+ * The uniform blocks of a rows batch (`BatchKind.rows`), one per instance in draw order: `perBinding` blocks per
22
+ * binding, each binding 256-byte aligned. A block is written again only when its slot changes hands or its
23
+ * derivation's version changes (NaN versions compare the values).
24
+ */
25
+ export declare class BatchRows {
26
+ data: Float32Array<ArrayBuffer>;
27
+ buffer?: GPUBuffer;
28
+ /** One binding per `perBinding` blocks; replaced (with the buffer) when the buffer grows. */
29
+ bindings: GPUBufferBinding[];
30
+ private floats;
31
+ private perBinding;
32
+ /** Floats from one binding's start to the next. */
33
+ private stride;
34
+ private readonly owners;
35
+ private readonly versions;
36
+ /**
37
+ * Writes block `blocks[i]` (with identity model rows and determinant 1: the instance rows place each mesh) into slot
38
+ * `i` and uploads what changed. `owners[i]` and `versions[i]` name where the block came from.
39
+ */
40
+ write(device: GPUDevice, blocks: readonly Float32Array[], owners: readonly object[], versions: readonly number[], floats: number, perBinding: number): void;
41
+ destroy(device: GPUDevice): void;
42
+ }
43
+ /** The instance rows of a batch of several meshes. */
44
+ export declare class BatchInstances {
45
+ /** 24 floats a row: world matrix, tint (1), UV scale (1) and offset (0). */
46
+ data: Float32Array<ArrayBuffer>;
47
+ buffer?: GPUBuffer;
48
+ /** Rows the GPU buffer holds as uploaded. */
49
+ private uploaded;
50
+ /** True when the rows hold exactly `matrices` and `tints` (see `write`), as uploaded. */
51
+ holds(matrices: readonly ArrayLike<number>[], tints?: readonly ArrayLike<number>[]): boolean;
52
+ /**
53
+ * Writes the rows' world matrices and tints (each member's base colour when the batch folds several materials, else
54
+ * 1) and uploads the changed range. Returns the vertex buffer.
55
+ */
56
+ write(device: GPUDevice, matrices: readonly ArrayLike<number>[], tints?: readonly ArrayLike<number>[]): GPUBuffer;
57
+ destroy(device: GPUDevice): void;
58
+ }
59
+ /** A batch's group 0 by pipeline, uniform binding and view block (index.ts `batchGroup`). */
60
+ export type BatchGroups = Map<GPURenderPipeline, Map<GPUBufferBinding, Map<GPUBufferBinding, GPUBindGroup>>>;
61
+ /** A rows batch's GPU state (`BatchKind.rows`), kept like `BatchState`. */
62
+ export interface RowsState {
63
+ instances: BatchInstances;
64
+ rows: BatchRows;
65
+ /** Group 0 by pipeline, rows binding and view block. */
66
+ groups: BatchGroups;
67
+ /** Group 1 by pipeline, made from the leading resource's texture views `texturesOf`. */
68
+ textures: Map<GPURenderPipeline, GPUBindGroup>;
69
+ texturesOf?: object;
70
+ frame: number;
71
+ view: object;
72
+ }
73
+ /** A batch's GPU state, kept on its first draw's resource across frames (one per derivation and view). */
74
+ export interface BatchState {
75
+ instances: BatchInstances;
76
+ /** The batch's uniform: the derivation's rows with identity model rows. */
77
+ uniform: UniformSlot;
78
+ /** Group 0 by pipeline, uniform binding and view block. */
79
+ groups: BatchGroups;
80
+ /** The frame and view that last drew it. */
81
+ frame: number;
82
+ view: object;
83
+ }
@@ -0,0 +1,136 @@
1
+ import type { LightingEffect, PBRRenderState } from './pbr.js';
2
+ import type { PBRInstances } from './pbr-instancing.js';
3
+ import type { BatchKind, BatchState, RowsState } from './draw-batch.js';
4
+ import type { MaterialExtension } from './material-extension.js';
5
+ import type { GLTFExtendedMaterials } from './asset.js';
6
+ /** The context every primitive of one draw call shares, compared field by field to share derivations between calls. */
7
+ export interface DrawFrame {
8
+ mode: string;
9
+ depthCompare: GPUCompareFunction | undefined;
10
+ format: GPUTextureFormat;
11
+ samples: number | undefined;
12
+ depthFormat: GPUTextureFormat;
13
+ section: GPUBuffer | undefined;
14
+ /** The transparency or transmission hook, the capture hook and the asset's extended-material hooks. */
15
+ oit: object | undefined;
16
+ hook: object | undefined;
17
+ hooks: GLTFExtendedMaterials | undefined;
18
+ /** The model's lighting effects in order. */
19
+ lighting: readonly LightingEffect[];
20
+ /**
21
+ * True when a native glass capture lends this target its per-surface snapshot (materials native-glass.js). Part of
22
+ * the context: a derivation made before the capture began (blendSpace 'linear' first seen) is not reused once it has.
23
+ */
24
+ glass: boolean;
25
+ }
26
+ /** A derivation, valid for draws under `frame` (identity: the same call or run); see the file comment. */
27
+ export interface DrawDerivation {
28
+ nativeGlass?: boolean;
29
+ frame: DrawFrame;
30
+ source: MaterialExtension | undefined;
31
+ instances: PBRInstances | BatchKind | undefined;
32
+ topology: GPUPrimitiveTopology | undefined;
33
+ /** Sign of the node matrix determinant: mirrored nodes cull the other face. */
34
+ sign: number;
35
+ /** False when derived for a batch member: no pipeline built and no lighting group (draw-batch.ts). */
36
+ complete: boolean;
37
+ compact: boolean;
38
+ floatCount: number;
39
+ replacesTextures: boolean;
40
+ /** Set when the primitive has a material extension: those draws keep per-resource state and never share. */
41
+ extension: MaterialExtension | undefined;
42
+ pipeline: GPURenderPipeline;
43
+ /** Transmission's tint pipeline (multiplies what is behind) when the draw is tinted. */
44
+ tint: GPURenderPipeline | undefined;
45
+ /** True when the draw first multiplies what is behind by its tint (transmission). */
46
+ tinted: boolean;
47
+ blend: boolean;
48
+ state: PBRRenderState | undefined;
49
+ /** True when group 2 (shading, lighting and transparency bindings) is bound. */
50
+ effectBindings: boolean;
51
+ effect: {
52
+ entries: GPUBindGroupEntry[];
53
+ group: GPUBindGroup;
54
+ } | undefined;
55
+ tintEffect: {
56
+ entries: GPUBindGroupEntry[];
57
+ group: GPUBindGroup;
58
+ } | undefined;
59
+ mappedTint: boolean;
60
+ /** @internal Whether it was derived for all-white instanced vertices (index.ts `whiteDraw`): part of its context. */
61
+ white?: boolean;
62
+ /** False when the finished shader reads the model rows itself, so instanced batches cannot draw it. */
63
+ modelFree: boolean;
64
+ /** True when the finished shader reads the base colour only as the vertex colour's factor (index.ts `tintableCode`). */
65
+ tintable?: boolean;
66
+ /** @internal The GPU states of this derivation's blended batches, one per batch drawn in a frame (index.ts `drawBatch`). */
67
+ blendStates?: BatchState[];
68
+ /** @internal The same for its blended rows batches (`BatchKind.rows`). */
69
+ blendRows?: RowsState[];
70
+ /**
71
+ * @internal What draws of other material records may share an instanced draw with this one's, each reading its own
72
+ * uniform block (`BatchKind.rows`): the same object for derivations with the same pipeline and group 2 resources
73
+ * (`drawGroup`); undefined until the derivation is complete.
74
+ */
75
+ group?: object;
76
+ /**
77
+ * @internal Whether this derivation's rows variant drew as `rowsOf` (another record's rows variant) does, checked at
78
+ * this derivation's version `rowsAt` and `rowsOf`'s version `rowsOfAt` (index.ts `rowsFit`).
79
+ */
80
+ rowsOf?: DrawDerivation;
81
+ rowsAt?: number;
82
+ rowsOfAt?: number;
83
+ rowsOk?: boolean;
84
+ /** @internal The batch (draw-batch.ts) this derivation's last draw joined in run `joinedRun`, until that run draws it. */
85
+ joined?: object;
86
+ joinedRun?: object;
87
+ /** The whole uniform as derived; draws copy it and write their own node rows (16-47) and determinant (97). */
88
+ block: Float32Array;
89
+ /**
90
+ * @internal What the shader and pipeline were composed from, beyond the context (`frame`) and the fields above: the
91
+ * record's `shading.shaderRevision`, its shading object and render state, and `structure` (structureFlags). A later
92
+ * frame whose draw finds all of them unchanged keeps `pipeline` and `tint` (see `PBRModel.derive`).
93
+ */
94
+ revision?: number;
95
+ shading?: object;
96
+ renderState?: object;
97
+ structure?: number;
98
+ /** `plainShape` of a compact record with no hook (index.ts), -1 otherwise: its stand-in for `revision`. */
99
+ plain?: number;
100
+ /**
101
+ * @internal The record's `shading.version` when this derivation was last made complete under the conditions that
102
+ * keep its pipeline (no lighting effects, a beauty-like pass); NaN otherwise. A later frame whose record reports the
103
+ * same version reuses the derivation whole (`steadyDerivation`).
104
+ */
105
+ version?: number;
106
+ }
107
+ /**
108
+ * The record fields beyond the shading hooks that decide a draw's shader text and pipeline, as one number: alpha mode,
109
+ * side flag, the tangent-frame switch, transmission tint, physical rows and their map count, and the shading's
110
+ * texture flags. Two derivations with equal flags (and equal revision, shading, render state and context) compose the
111
+ * same shader and pipeline.
112
+ */
113
+ export declare function structureFlags(alphaMode: number, side: number, tangent: boolean, tint: boolean, physical: boolean, physicalMaps: boolean, texturedTint: boolean, replacesTextures: boolean, laterUV: boolean): number;
114
+ /** Per device: shader ids, pipelines and derivations by material record, shared by every model on the device. */
115
+ export interface DeviceDraws {
116
+ codes: Map<string, number>;
117
+ codeCount: number;
118
+ pipelines: Map<string, GPURenderPipeline>;
119
+ derivations: WeakMap<object, DrawDerivation[]>;
120
+ /** Draw groups (`DrawDerivation.group`) by pipeline and group 2 resources. */
121
+ groups: Map<string, object>;
122
+ }
123
+ export declare function deviceDraws(device: GPUDevice): DeviceDraws;
124
+ /**
125
+ * The draw group (`DrawDerivation.group`) of complete derivation `d`: one object per pipeline, uniform size, texture
126
+ * replacement and group 2 resources, so derivations of different material records that draw alike share it.
127
+ */
128
+ export declare function drawGroup(draws: DeviceDraws, d: DrawDerivation): object;
129
+ /** A small stable number for `value` (pipeline keys name hooks and layouts by it). */
130
+ export declare function objectId(value: object | undefined): number;
131
+ /** True when `a` and `b` describe the same draw context. */
132
+ export declare function sameFrame(a: DrawFrame, b: DrawFrame): boolean;
133
+ /** True when two models' lighting lists hold the same effects in order. */
134
+ export declare function sameLighting(a: readonly LightingEffect[], b: readonly LightingEffect[]): boolean;
135
+ /** Most recent first; bounded so animated contexts (probe faces, resizes) cannot grow a material's list forever. */
136
+ export declare const derivationLimit = 32;
@@ -0,0 +1 @@
1
+ var e=(e,t)=>Object.assign(Error(t),{name:`MargoError`,code:e}),t=(e,t)=>`${e}; see https://margoengine.com/errors#${t}`,n=(n,r,i=n)=>e(n,t(r,i)),r=(e,n)=>TypeError(t(e,n));export{e as n,r,n as t};
@@ -0,0 +1,12 @@
1
+ import type { GLTFExtendedMaterials } from './asset.js';
2
+ export type { ExtendedPlan } from './shader.js';
3
+ export type { GLTFExtendedMaterials } from './asset.js';
4
+ /**
5
+ * KHR_materials_iridescence, KHR_materials_anisotropy, KHR_materials_diffuse_transmission,
6
+ * KHR_materials_diffuse_roughness (draft), EXT_materials_bump (draft)
7
+ * and KHR_materials_volume_scatter (draft)
8
+ * for gltf/pbr, passed like a decoder: `loadGLTF(engine, url, {decoders: {materials: extendedMaterials}})` (also parseGLTF, parseGLTFAsync, the worker
9
+ * and progressive loaders). Without it gltf/pbr ignores those extensions (a file that requires one is rejected), so apps
10
+ * that never load them ship none of this WGSL. README "Extended materials".
11
+ */
12
+ export declare const extendedMaterials: GLTFExtendedMaterials;
@@ -0,0 +1 @@
1
+ import{a as e,i as t,y as n}from"./shader-DPqfUcmp.js";var r=(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},i={parse(e){let t=e.KHR_materials_iridescence,i=e.KHR_materials_anisotropy,a=e.KHR_materials_diffuse_transmission,o=e.EXT_materials_bump,s=e.KHR_materials_volume,c=e.KHR_materials_volume_scatter,l=e.KHR_materials_unlit||e.KHR_materials_pbrSpecularGlossiness?void 0:e.KHR_materials_diffuse_roughness,u=r(l?.diffuseRoughnessFactor,0,0,1,`diffuse roughness`),d=r(t?.iridescenceFactor,0,0,1,`iridescence`),f=r(i?.anisotropyStrength,0,0,1,`anisotropy strength`),p=r(a?.diffuseTransmissionFactor,0,0,1,`diffuse transmission`),m=r(o?.bumpFactor,1,-1/0,1/0,`bump factor`),h=!!o?.bumpTexture&&m!==0;if(o?.heightSpace!==void 0&&o.heightSpace!==`world`&&o.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 g=c?.multiscatterColorFactor??[0,0,0],_=s?.attenuationDistance??1/0,v=s?.thicknessFactor??0,y=s?.attenuationColor??[1,1,1];if(!Array.isArray(g)||g.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 b=g.map(e=>r(e,0,0,1,`multi-scatter color`)),x=y.map(e=>n(e,_)),S=!!c&&b.some(e=>e>0)&&v>0&&x.some(e=>e>0)&&(!!p||!!e.KHR_materials_transmission?.transmissionFactor),C=!!s?.thicknessTexture&&!!e.KHR_materials_transmission;if(!d&&!f&&!p&&!h&&!S&&!u&&!C)return;let w=a?.diffuseTransmissionColorFactor??[1,1,1],T=r(i?.anisotropyRotation,0,-1/0,1/0,`anisotropy rotation`);if(!Array.isArray(w)||w.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:!!d,anisotropy:!!f,diffuseTransmission:!!p,bump:h,scatter:S,...u?{diffuseRoughness:!0}:void 0},maps:[d?t.iridescenceTexture:void 0,d?t.iridescenceThicknessTexture:void 0,f?i.anisotropyTexture:void 0,p?a.diffuseTransmissionTexture:void 0,p?a.diffuseTransmissionColorTexture:void 0,h?o.bumpTexture:void 0,S?c.multiscatterColorTexture:void 0,S||C?s.thicknessTexture:void 0,...u&&l.diffuseRoughnessTexture?[l.diffuseRoughnessTexture]:[]],rows:[d,r(t?.iridescenceIor,1.3,1,1/0,`iridescence IOR`),r(t?.iridescenceThicknessMinimum,100,0,1/0,`iridescence thickness`),r(t?.iridescenceThicknessMaximum,400,0,1/0,`iridescence thickness`),f,Math.cos(T),Math.sin(T),u,p,...w.map(e=>r(e,0,0,1,`diffuse transmission color`)),m,+(o?.heightSpace===`object`),0,0,...b,r(c?.scatterAnisotropy,0,-1,1,`scatter anisotropy`),...x,v]}},plan:t,shader:e};export{i as extendedMaterials};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Bind group `index` of an auto-layout pipeline. With no entries it is one empty group of an explicit layout: WebKit gives
3
+ * an invalid layout for a group past the last one the shader uses, which a material without textures reaches, and the
4
+ * draw then fails. Every browser accepts the explicit empty group at any index.
5
+ */
6
+ export declare function pipelineGroup(device: GPUDevice, pipeline: GPURenderPipeline, index: number, entries: GPUBindGroupEntry[]): GPUBindGroup;
@@ -0,0 +1 @@
1
+ var e=67108864;export{e as t};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Most pixels one glTF image may decode to: 8192 x 8192 (256 MiB as RGBA8), the side every WebGPU device supports
3
+ * (`maxTextureDimension2D` 8192). A film close-up's 8K map loads; a side over the device's limit is still refused at
4
+ * upload, and all images together stay within the decoded budget (4x `maxDownloadBytes`). 4096 x 4096 before 2026-11-17.
5
+ */
6
+ export declare const MAX_IMAGE_PIXELS = 67108864;
@@ -0,0 +1,84 @@
1
+ import type { EngineKernel, Mesh as MeshHandle } from '@margoengine/core';
2
+ import { Geometry, type Engine } from '@margoengine/core/extension';
3
+ import type { GLTFDocument as Document, GLTFPrimitive } from './shared/gltf.js';
4
+ /** A parsed glTF scene: the root mesh handle, every mesh and node handle, and dispose() to release them. */
5
+ export interface Model {
6
+ root: MeshHandle;
7
+ meshes: readonly MeshHandle[];
8
+ nodes: readonly MeshHandle[];
9
+ dispose(): void;
10
+ }
11
+ /** A file on its way through the loader. An extension may replace `doc` and `buffers`, never change what they hold. */
12
+ export interface GLTFFile {
13
+ doc: Document;
14
+ /** Buffer data, in document order. */
15
+ buffers: readonly Uint8Array[];
16
+ /** The `maxNodes` option, if set. */
17
+ maxNodes?: number;
18
+ /** Fetches a URI found in the file, under `loadGLTF`'s rules. Absent when the file came from memory. */
19
+ fetch?(uri: string): Promise<Uint8Array>;
20
+ }
21
+ /** What the loader made of a file, for `GLTFExtension.finish`. */
22
+ export interface GLTFBuilt {
23
+ engine: Engine;
24
+ /** Each primitive in the file. `expanded` holds the source vertex of each geometry vertex when normals were generated. */
25
+ primitives: readonly {
26
+ geometry: Geometry;
27
+ source: GLTFPrimitive;
28
+ expanded?: Uint32Array;
29
+ }[];
30
+ /** The mesh of each node by node index; empty where a node is not in the loaded scene. */
31
+ nodes: readonly (MeshHandle | undefined)[];
32
+ }
33
+ /**
34
+ * One optional feature of the light loader, passed in `GLTFOptions.extensions`. Each lives in its own entry, so a file
35
+ * that needs none of them costs none of their bytes.
36
+ */
37
+ export interface GLTFExtension {
38
+ /** The glTF extension names this one implements: `extensionsRequired` may list them. */
39
+ readonly handles: readonly string[];
40
+ /** Accept scenes without renderable meshes, for data-only imports. Default false. */
41
+ readonly allowEmptyScene?: boolean;
42
+ /** Reads vertex attribute `semantic` from accessor `id`, as float xyz; undefined leaves it to the loader. */
43
+ attribute?(file: GLTFFile, semantic: string, id: number): Float32Array | undefined;
44
+ /** Asynchronous work before anything is built. An extension with `load` needs `parseGLTFAsync` or `loadGLTF`. */
45
+ load?(file: GLTFFile, signal?: AbortSignal): Promise<void>;
46
+ /** Runs after every `load`, before the loader reads the document. */
47
+ read?(file: GLTFFile): void;
48
+ /** Runs on the finished model; may wrap `model.dispose`. A throw rolls the model back. */
49
+ finish?(model: Model, file: GLTFFile, built: GLTFBuilt): void;
50
+ /**
51
+ * Runs when an asynchronous load fails or is aborted after `load` ran: an extension releases what `load` holds for a
52
+ * model that will never take it (decoded images, for example). Not called after a load that succeeded.
53
+ */
54
+ abandon?(file: GLTFFile): void;
55
+ }
56
+ /** Options for parseGLTF and loadGLTF. */
57
+ export interface GLTFOptions {
58
+ /** Optional features from the `@margoengine/gltf/*` entries, for example `[quantized]`. Default none. */
59
+ extensions?: readonly GLTFExtension[];
60
+ /** Most glTF nodes the file may have, each one a core mesh (default 100,000; up to core's 8,388,608 entities). */
61
+ maxNodes?: number;
62
+ /**
63
+ * URL prefixes (for example `https://cdn.example.com/models/`) that buffer URIs inside the file may point to besides
64
+ * the file's own directory, matched on a path-segment boundary. Default none: absolute, cross-origin and
65
+ * `../`-escaping URIs throw a TypeError, and so does a redirect that ends outside these places.
66
+ */
67
+ allowedURLs?: readonly string[];
68
+ }
69
+ /**
70
+ * Parses glTF JSON, an object or GLB bytes into core meshes, one per node. Rejects absolute, cross-origin and `../` buffer URIs unless allowed. @throws TypeError for a malformed file; RangeError over the size limits.
71
+ */
72
+ export declare function parseGLTF(instance: EngineKernel, input: string | object | ArrayBuffer | ArrayBufferView, suppliedBuffers?: Array<ArrayBuffer | ArrayBufferView>, options?: GLTFOptions): Model;
73
+ /** parseGLTF for extensions with asynchronous work, such as `textured`. Aborts with `signal`. */
74
+ export declare function parseGLTFAsync(instance: EngineKernel, input: string | object | ArrayBuffer | ArrayBufferView, suppliedBuffers?: Array<ArrayBuffer | ArrayBufferView>, { signal, ...options }?: GLTFOptions & {
75
+ signal?: AbortSignal;
76
+ }): Promise<Model>;
77
+ /**
78
+ * Fetches a .gltf or .glb over HTTP(S), and its external buffers relative to it, through `fetch` (default
79
+ * `globalThis.fetch`; for example an AssetCache's or a LoadingManager's `fetch`), then parses it like parseGLTF.
80
+ */
81
+ export declare function loadGLTF(engine: EngineKernel, url: string | URL, { signal, maxNodes, allowedURLs, extensions, fetch: get, }?: GLTFOptions & {
82
+ signal?: AbortSignal;
83
+ fetch?: typeof fetch;
84
+ }): Promise<Model>;
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export{t as loadGLTF,n as parseGLTF,r as parseGLTFAsync}from"./src-WMRHArDp.js";
@@ -0,0 +1,5 @@
1
+ import{n as e}from"./errors-THVaUwlL.js";var t={arrayStride:96,stepMode:`instance`,attributes:[5,6,7,8,9,10].map((e,t)=>({shaderLocation:e,offset:t*16,format:`float32x4`}))};function n(e,t,n,r){let i=n*24;for(let n=0;n<4;n++)for(let a=0;a<4;a++)r[n*4+a]=e[a]*t[i+n*4]+e[4+a]*t[i+n*4+1]+e[8+a]*t[i+n*4+2]+e[12+a]*t[i+n*4+3];return r}var r=/* @__PURE__ */ new Map;function i(t){let n=r.get(t);if(n!==void 0)return n;let i=(t,r)=>{let i=n.replace(t,r);if(i===n)throw e(`failed`,`PBR instancing patch target missing; the shader source changed, update the patch: `+t);n=i};return n=t,i(/(struct Out \{[^}]*?)\n\}/,`$1, @location(5) @interpolate(flat) mirror:f32
2
+ }`),i(`@vertex fn vertex(i:Input)->Out {`,`struct Instance {@location(5) m0:vec4f, @location(6) m1:vec4f, @location(7) m2:vec4f, @location(8) m3:vec4f, @location(9) tint:vec4f, @location(10) uvt:vec4f}
3
+ @vertex fn vertex(i:Input,k:Instance)->Out {
4
+ let margoInstanceMatrix=mat4x4f(k.m0,k.m1,k.m2,k.m3);${t.includes(`margoInstanceColor`)?` let margoInstanceColor=k.tint;`:``}${t.includes(`margoInstanceUV`)?` let margoInstanceUV=k.uvt;`:``}
5
+ let margoI=f.model*margoInstanceMatrix; let margoS=select(-1.0,1.0,dot(margoI[0].xyz,cross(margoI[1].xyz,margoI[2].xyz))>=0);`),i(`let p=f.model*vec4f(`,`let p=margoI*vec4f(`),n=n.replace(`let margoObjectModel=f.model;`,`let margoObjectModel=margoI;`),i(/o\.normal=\(f\.normalMatrix\*vec4f\((i\.normal\.xyz|margoNormal),0\)\)\.xyz;/,`o.normal=mat3x3f(cross(margoI[1].xyz,margoI[2].xyz),cross(margoI[2].xyz,margoI[0].xyz),cross(margoI[0].xyz,margoI[1].xyz))*$1*margoS;`),i(`(f.model*vec4f(i.tangent.xyz,0)).xyz,i.tangent.w*f.coordsB.y)`,`(margoI*vec4f(i.tangent.xyz,0)).xyz,i.tangent.w*margoS)`),i(/o\.uv=i\.uv; o\.color=(i\.color|vec4f\(1\));/,`o.uv=i.uv*k.uvt.xyxy+k.uvt.zwzw; o.color=$1*k.tint; o.mirror=margoS;`),i(`let facing=front==(f.coordsB.y>0);`,`let facing=front==(i.mirror>0);`),r.size>=64&&r.clear(),r.set(t,n),n}var a=e=>Math.floor(65536/(e*4)),o=/* @__PURE__ */ new Map,s=`@group(0) @binding(0) var<uniform> f:Frame;`;function c(t,n){let r=n+`:`+t,i=o.get(r);if(i!==void 0)return i||void 0;if(i=t.includes(s)?t.replace(/(?<![\w.])f\.(?=[A-Za-z_])/g,`margoRows[margoK].`):``,i&&/(?<![\w.])f(?!\w)/.test(i.replace(s,``))&&(i=``),i){let t=(t,n)=>{let r=i.replace(t,n);if(r===i)throw e(`failed`,`PBR instance rows patch target missing; the shader source changed, update the patch: `+t);i=r};t(s,`@group(0) @binding(0) var<uniform> margoRows:array<Frame,${n}>;\nvar<private> margoK:u32;`),t(/(struct Out \{[^}]*?)\n\}/,(e,t)=>{let n=0;for(let[,e]of t.matchAll(/@location\((\d+)\)/g))n=Math.max(n,+e+1);return`${t}, @location(${n}) @interpolate(flat) margoK:u32\n}`}),t(`@vertex fn vertex(i:Input,k:Instance)->Out {`,i.includes(`ndInstance:u32`)?`@vertex fn vertex(i:Input,k:Instance)->Out {margoK=i.ndInstance%${n}u;`:`@vertex fn vertex(i:Input,k:Instance,@builtin(instance_index) margoN:u32)->Out {margoK=margoN%${n}u;`),t(`o.mirror=margoS;`,`o.mirror=margoS; o.margoK=margoK;`),t(/@fragment fn \w+\(i:Out[^)]*\)[^{]*\{/g,e=>e+`margoK=i.margoK;`)}return o.size>=64&&o.clear(),o.set(r,i),i||void 0}export{n as a,t as i,a as n,c as r,i as t};
@@ -0,0 +1,14 @@
1
+ /** Patches a PBR shader's WGSL source so it reads per-instance transforms; results are cached by source text. */
2
+ export declare function instancedShader(code: string): string;
3
+ /** Uniform blocks of `floats` floats one 64 KiB uniform binding holds (the WebGPU minimum of maxUniformBufferBindingSize). */
4
+ export declare const rowsPerBinding: (floats: number) => number;
5
+ /**
6
+ * Patches a finished instanced PBR shader (`instancedShader`, then every later edit) so each instance reads its own
7
+ * uniform block: binding 0 becomes an array of `count` blocks, every `f.` read becomes a read of block `margoK`, and
8
+ * the vertex stage and every fragment entry set `margoK` (`instance_index % count`, passed flat). A draw of more
9
+ * instances binds one array per `count` of them and starts each at a multiple of `count` (`firstInstance`). The reads
10
+ * go to the uniform array itself: copying the block into a private struct put its dynamically indexed UV rows in local
11
+ * memory and cost 1.5 ms of GPU time on 4,096 boxes. Undefined when the shader uses `f` other than as `f.field` (a
12
+ * local of that name, or `f` passed whole): such draws keep their own uniforms.
13
+ */
14
+ export declare function rowsShader(code: string, count: number): string | undefined;
@@ -0,0 +1,9 @@
1
+ import type { GLTFExtension } from './index.js';
2
+ /**
3
+ * Lets the light loader read `EXT_mesh_gpu_instancing`: each instance becomes a child node of the instanced node, on the
4
+ * shared mesh, and core draws all of them as one instanced draw per primitive. TRANSLATION, ROTATION and SCALE are read,
5
+ * in float or quantized form; custom attributes are ignored. An instance costs one core mesh plus one per primitive, and
6
+ * every instance counts toward `maxNodes`. Instances show up in `model.meshes` and `model.nodes` like any node.
7
+ * @example const model = await loadGLTF(engine, '/forest.glb', { extensions: [instancing], maxNodes: 500_000 });
8
+ */
9
+ export declare const instancing: GLTFExtension;
@@ -0,0 +1 @@
1
+ import{n as e}from"./limits-_LZ441oV.js";import{r as t}from"./accessor-nVsu_f1L.js";import{MargoError as n}from"@margoengine/math/errors";var r=`EXT_mesh_gpu_instancing`,i=e=>/* @__PURE__ */ TypeError(`Invalid glTF ${e}; the file is not valid glTF 2.0, re-export it and check it with the glTF Validator`),a=e=>e.type===`VEC3`&&[5126,5120,5121,5122,5123].includes(e.componentType),o=e=>e.type===`VEC4`&&(e.componentType===5126||e.normalized===!0&&[5120,5122].includes(e.componentType));function s(e,n,r,a){if(n===void 0)return;let o=t(e,n,r,a);if(!o.every(Number.isFinite))throw i(`instance attributes`);return o}function c(e,t,c,l){let{attributes:u}=t.extensions[r];if(t.mesh===void 0||!u)throw i(`instanced node`);let d=s(e,u.TRANSLATION,3,a),f=s(e,u.ROTATION,4,o),p=s(e,u.SCALE,3,a),m=d?d.length/3:f?f.length/4:p?p.length/3:0;if(!m||d&&d.length!==m*3||f&&f.length!==m*4||p&&p.length!==m*3)throw i(`instance attributes`);if(c+m>l)throw new n(`unsupported`,`Too many glTF nodes (${c+m} > ${l}; raise the maxNodes option, or load it with @margoengine/gltf/pbr, which draws instances without nodes)`);let h=[];for(let e=0;e<m;e++){let n={mesh:t.mesh};if(d&&(n.translation=[...d.subarray(e*3,e*3+3)]),p&&(n.scale=[...p.subarray(e*3,e*3+3)]),f){let t=f.subarray(e*4,e*4+4),r=Math.hypot(...t);if(!(r>0))throw i(`instance rotation`);n.rotation=[...t].map(e=>e/r)}h.push(n)}let{mesh:g,extensions:_,...v}=t,{[r]:y,...b}=_,x={...v,children:[...t.children??[],...h.map((e,t)=>c+t)]};return Object.keys(b).length&&(x.extensions=b),{node:x,instances:h}}var l={handles:[r],read(t){let n=[...t.doc.nodes??[]],i=e(`maxNodes`,t.maxNodes);for(let e=0,a=n.length;e<a;e++){if(!n[e]?.extensions?.[r])continue;let{node:a,instances:o}=c(t,n[e],n.length,i);n[e]=a;for(let e of o)n.push(e)}t.doc={...t.doc,nodes:n}}};export{l as instancing};