@loaders.gl/gltf 4.0.0-alpha.6 → 4.0.0-alpha.8

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 (194) hide show
  1. package/dist/dist.min.js +1661 -1459
  2. package/dist/es5/glb-loader.js +2 -2
  3. package/dist/es5/glb-loader.js.map +1 -1
  4. package/dist/es5/glb-writer.js +3 -4
  5. package/dist/es5/glb-writer.js.map +1 -1
  6. package/dist/es5/gltf-loader.js +3 -3
  7. package/dist/es5/gltf-loader.js.map +1 -1
  8. package/dist/es5/index.js +9 -3
  9. package/dist/es5/index.js.map +1 -1
  10. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  11. package/dist/es5/lib/api/gltf-scenegraph.js +52 -32
  12. package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
  13. package/dist/es5/lib/api/post-process-gltf.js +164 -116
  14. package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
  15. package/dist/es5/lib/encoders/encode-glb.js +1 -1
  16. package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
  17. package/dist/es5/lib/encoders/encode-gltf.js +2 -3
  18. package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
  19. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +3 -5
  20. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  21. package/dist/es5/lib/extensions/EXT_texture_webp.js +2 -3
  22. package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
  23. package/dist/es5/lib/extensions/KHR_binary_gltf.js +2 -3
  24. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
  25. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -5
  26. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  27. package/dist/es5/lib/extensions/KHR_texture_basisu.js +3 -4
  28. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
  29. package/dist/es5/lib/extensions/KHR_texture_transform.js +9 -8
  30. package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
  31. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +195 -17
  32. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  33. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +3 -3
  34. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
  35. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +3 -3
  36. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
  37. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -2
  38. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
  39. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
  40. package/dist/es5/lib/gltf-utils/gltf-utils.js +24 -0
  41. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  42. package/dist/es5/lib/parsers/parse-glb.js +10 -10
  43. package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
  44. package/dist/es5/lib/parsers/parse-gltf.js +18 -25
  45. package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
  46. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
  47. package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -1
  48. package/dist/es5/lib/types/gltf-types.js.map +1 -1
  49. package/dist/es5/lib/utils/version.js +1 -1
  50. package/dist/esm/glb-loader.js +1 -1
  51. package/dist/esm/glb-loader.js.map +1 -1
  52. package/dist/esm/glb-writer.js +1 -1
  53. package/dist/esm/glb-writer.js.map +1 -1
  54. package/dist/esm/gltf-loader.js +3 -3
  55. package/dist/esm/gltf-loader.js.map +1 -1
  56. package/dist/esm/index.js +2 -1
  57. package/dist/esm/index.js.map +1 -1
  58. package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
  59. package/dist/esm/lib/api/gltf-scenegraph.js +45 -31
  60. package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
  61. package/dist/esm/lib/api/post-process-gltf.js +167 -112
  62. package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
  63. package/dist/esm/lib/encoders/encode-glb.js +1 -1
  64. package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
  65. package/dist/esm/lib/encoders/encode-gltf.js +1 -1
  66. package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
  67. package/dist/esm/lib/extensions/EXT_meshopt_compression.js +2 -3
  68. package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  69. package/dist/esm/lib/extensions/EXT_texture_webp.js +1 -1
  70. package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
  71. package/dist/esm/lib/extensions/KHR_binary_gltf.js +1 -1
  72. package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
  73. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +5 -4
  74. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  75. package/dist/esm/lib/extensions/KHR_texture_basisu.js +2 -2
  76. package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
  77. package/dist/esm/lib/extensions/KHR_texture_transform.js +7 -6
  78. package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
  79. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +161 -15
  80. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  81. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +1 -1
  82. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
  83. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +1 -1
  84. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
  85. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +1 -1
  86. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
  87. package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
  88. package/dist/esm/lib/gltf-utils/gltf-utils.js +20 -0
  89. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
  90. package/dist/esm/lib/parsers/parse-glb.js +10 -10
  91. package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
  92. package/dist/esm/lib/parsers/parse-gltf.js +7 -12
  93. package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
  94. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
  95. package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -1
  96. package/dist/esm/lib/types/gltf-types.js.map +1 -1
  97. package/dist/esm/lib/utils/version.js +1 -1
  98. package/dist/glb-loader.d.ts +2 -2
  99. package/dist/glb-loader.js +2 -5
  100. package/dist/glb-writer.d.ts.map +1 -1
  101. package/dist/glb-writer.js +4 -6
  102. package/dist/gltf-loader.d.ts +5 -5
  103. package/dist/gltf-loader.d.ts.map +1 -1
  104. package/dist/gltf-loader.js +3 -3
  105. package/dist/index.d.ts +8 -5
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js +12 -5
  108. package/dist/lib/api/gltf-extensions.d.ts +1 -1
  109. package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
  110. package/dist/lib/api/gltf-extensions.js +1 -1
  111. package/dist/lib/api/gltf-scenegraph.d.ts +8 -5
  112. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
  113. package/dist/lib/api/gltf-scenegraph.js +47 -33
  114. package/dist/lib/api/post-process-gltf.d.ts +4 -1
  115. package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
  116. package/dist/lib/api/post-process-gltf.js +186 -123
  117. package/dist/lib/encoders/encode-glb.d.ts +13 -1
  118. package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
  119. package/dist/lib/encoders/encode-glb.js +15 -4
  120. package/dist/lib/encoders/encode-gltf.js +2 -5
  121. package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -1
  122. package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
  123. package/dist/lib/extensions/EXT_meshopt_compression.js +3 -7
  124. package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -1
  125. package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
  126. package/dist/lib/extensions/EXT_texture_webp.js +2 -5
  127. package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
  128. package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
  129. package/dist/lib/extensions/KHR_binary_gltf.js +2 -5
  130. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
  131. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
  132. package/dist/lib/extensions/KHR_draco_mesh_compression.js +5 -8
  133. package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -1
  134. package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
  135. package/dist/lib/extensions/KHR_texture_basisu.js +3 -6
  136. package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
  137. package/dist/lib/extensions/KHR_texture_transform.js +7 -10
  138. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +3 -2
  139. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  140. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +195 -23
  141. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
  142. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
  143. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +3 -6
  144. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
  145. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
  146. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +3 -6
  147. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
  148. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
  149. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -5
  150. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
  151. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
  152. package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
  153. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  154. package/dist/lib/gltf-utils/gltf-utils.js +28 -1
  155. package/dist/lib/parsers/parse-glb.d.ts +15 -3
  156. package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
  157. package/dist/lib/parsers/parse-glb.js +43 -18
  158. package/dist/lib/parsers/parse-gltf.d.ts +8 -4
  159. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
  160. package/dist/lib/parsers/parse-gltf.js +17 -41
  161. package/dist/lib/types/gltf-json-schema.d.ts +153 -139
  162. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  163. package/dist/lib/types/gltf-postprocessed-schema.d.ts +174 -209
  164. package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
  165. package/dist/lib/types/gltf-postprocessed-schema.js +1 -1
  166. package/dist/lib/types/gltf-types.d.ts +18 -6
  167. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  168. package/package.json +6 -6
  169. package/src/glb-loader.ts +3 -3
  170. package/src/glb-writer.ts +3 -1
  171. package/src/gltf-loader.ts +12 -8
  172. package/src/index.ts +32 -13
  173. package/src/lib/api/gltf-extensions.ts +1 -1
  174. package/src/lib/api/gltf-scenegraph.ts +60 -41
  175. package/src/lib/api/post-process-gltf.ts +275 -150
  176. package/src/lib/encoders/encode-glb.ts +15 -5
  177. package/src/lib/encoders/encode-gltf.ts +1 -1
  178. package/src/lib/extensions/EXT_meshopt_compression.ts +4 -6
  179. package/src/lib/extensions/EXT_texture_webp.ts +2 -2
  180. package/src/lib/extensions/KHR_binary_gltf.ts +2 -2
  181. package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
  182. package/src/lib/extensions/KHR_texture_basisu.ts +3 -3
  183. package/src/lib/extensions/KHR_texture_transform.ts +22 -19
  184. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +264 -23
  185. package/src/lib/extensions/deprecated/KHR_lights_punctual.ts +2 -2
  186. package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +2 -2
  187. package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +2 -2
  188. package/src/lib/gltf-utils/gltf-attribute-utils.ts +1 -1
  189. package/src/lib/gltf-utils/gltf-utils.ts +31 -0
  190. package/src/lib/parsers/parse-glb.ts +50 -24
  191. package/src/lib/parsers/parse-gltf.ts +26 -25
  192. package/src/lib/types/gltf-json-schema.ts +168 -138
  193. package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
  194. package/src/lib/types/gltf-types.ts +35 -59
package/dist/dist.min.js CHANGED
@@ -200,7 +200,6 @@
200
200
  // ../worker-utils/src/index.ts
201
201
  var init_src = __esm({
202
202
  "../worker-utils/src/index.ts"() {
203
- init_globals2();
204
203
  init_library_utils();
205
204
  }
206
205
  });
@@ -321,788 +320,325 @@
321
320
  }
322
321
  });
323
322
 
324
- // ../textures/src/lib/utils/version.ts
323
+ // ../images/src/lib/utils/version.ts
325
324
  var VERSION4;
326
325
  var init_version3 = __esm({
327
- "../textures/src/lib/utils/version.ts"() {
328
- VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
326
+ "../images/src/lib/utils/version.ts"() {
327
+ VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
329
328
  }
330
329
  });
331
330
 
332
- // ../textures/src/lib/parsers/basis-module-loader.ts
333
- async function loadBasisTrascoderModule(options) {
334
- const modules = options.modules || {};
335
- if (modules.basis) {
336
- return modules.basis;
331
+ // ../images/src/lib/category-api/image-type.ts
332
+ function isImageTypeSupported(type) {
333
+ switch (type) {
334
+ case "auto":
335
+ return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
336
+ case "imagebitmap":
337
+ return IMAGE_BITMAP_SUPPORTED;
338
+ case "image":
339
+ return IMAGE_SUPPORTED;
340
+ case "data":
341
+ return DATA_SUPPORTED;
342
+ default:
343
+ throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
337
344
  }
338
- loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTrascoder(options);
339
- return await loadBasisTranscoderPromise;
340
- }
341
- async function loadBasisTrascoder(options) {
342
- let BASIS = null;
343
- let wasmBinary = null;
344
- [BASIS, wasmBinary] = await Promise.all([
345
- await loadLibrary("basis_transcoder.js", "textures", options),
346
- await loadLibrary("basis_transcoder.wasm", "textures", options)
347
- ]);
348
- BASIS = BASIS || globalThis.BASIS;
349
- return await initializeBasisTrascoderModule(BASIS, wasmBinary);
350
345
  }
351
- function initializeBasisTrascoderModule(BasisModule, wasmBinary) {
352
- const options = {};
353
- if (wasmBinary) {
354
- options.wasmBinary = wasmBinary;
346
+ function getDefaultImageType() {
347
+ if (IMAGE_BITMAP_SUPPORTED) {
348
+ return "imagebitmap";
355
349
  }
356
- return new Promise((resolve) => {
357
- BasisModule(options).then((module) => {
358
- const { BasisFile, initializeBasis } = module;
359
- initializeBasis();
360
- resolve({ BasisFile });
361
- });
362
- });
363
- }
364
- async function loadBasisEncoderModule(options) {
365
- const modules = options.modules || {};
366
- if (modules.basisEncoder) {
367
- return modules.basisEncoder;
350
+ if (IMAGE_SUPPORTED) {
351
+ return "image";
368
352
  }
369
- loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options);
370
- return await loadBasisEncoderPromise;
371
- }
372
- async function loadBasisEncoder(options) {
373
- let BASIS_ENCODER = null;
374
- let wasmBinary = null;
375
- [BASIS_ENCODER, wasmBinary] = await Promise.all([
376
- await loadLibrary(BASIS_CDN_ENCODER_JS, "textures", options),
377
- await loadLibrary(BASIS_CDN_ENCODER_WASM, "textures", options)
378
- ]);
379
- BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
380
- return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
381
- }
382
- function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {
383
- const options = {};
384
- if (wasmBinary) {
385
- options.wasmBinary = wasmBinary;
353
+ if (DATA_SUPPORTED) {
354
+ return "data";
386
355
  }
387
- return new Promise((resolve) => {
388
- BasisEncoderModule(options).then((module) => {
389
- const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module;
390
- initializeBasis();
391
- resolve({ BasisFile, KTX2File, BasisEncoder });
392
- });
393
- });
356
+ throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
394
357
  }
395
- var VERSION5, BASIS_CDN_ENCODER_WASM, BASIS_CDN_ENCODER_JS, loadBasisTranscoderPromise, loadBasisEncoderPromise;
396
- var init_basis_module_loader = __esm({
397
- "../textures/src/lib/parsers/basis-module-loader.ts"() {
398
- init_src();
399
- VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
400
- BASIS_CDN_ENCODER_WASM = `https://unpkg.com/@loaders.gl/textures@${VERSION5}/dist/libs/basis_encoder.wasm`;
401
- BASIS_CDN_ENCODER_JS = `https://unpkg.com/@loaders.gl/textures@${VERSION5}/dist/libs/basis_encoder.js`;
358
+ var _parseImageNode, IMAGE_SUPPORTED, IMAGE_BITMAP_SUPPORTED, NODE_IMAGE_SUPPORTED, DATA_SUPPORTED;
359
+ var init_image_type = __esm({
360
+ "../images/src/lib/category-api/image-type.ts"() {
361
+ init_src2();
362
+ ({ _parseImageNode } = globalThis);
363
+ IMAGE_SUPPORTED = typeof Image !== "undefined";
364
+ IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
365
+ NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
366
+ DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
402
367
  }
403
368
  });
404
369
 
405
- // ../textures/src/lib/gl-extensions.ts
406
- var GL_EXTENSIONS_CONSTANTS;
407
- var init_gl_extensions = __esm({
408
- "../textures/src/lib/gl-extensions.ts"() {
409
- GL_EXTENSIONS_CONSTANTS = {
410
- COMPRESSED_RGB_S3TC_DXT1_EXT: 33776,
411
- COMPRESSED_RGBA_S3TC_DXT1_EXT: 33777,
412
- COMPRESSED_RGBA_S3TC_DXT3_EXT: 33778,
413
- COMPRESSED_RGBA_S3TC_DXT5_EXT: 33779,
414
- COMPRESSED_R11_EAC: 37488,
415
- COMPRESSED_SIGNED_R11_EAC: 37489,
416
- COMPRESSED_RG11_EAC: 37490,
417
- COMPRESSED_SIGNED_RG11_EAC: 37491,
418
- COMPRESSED_RGB8_ETC2: 37492,
419
- COMPRESSED_RGBA8_ETC2_EAC: 37493,
420
- COMPRESSED_SRGB8_ETC2: 37494,
421
- COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 37495,
422
- COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37496,
423
- COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37497,
424
- COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 35840,
425
- COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 35842,
426
- COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 35841,
427
- COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 35843,
428
- COMPRESSED_RGB_ETC1_WEBGL: 36196,
429
- COMPRESSED_RGB_ATC_WEBGL: 35986,
430
- COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 35987,
431
- COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 34798,
432
- COMPRESSED_RGBA_ASTC_4X4_KHR: 37808,
433
- COMPRESSED_RGBA_ASTC_5X4_KHR: 37809,
434
- COMPRESSED_RGBA_ASTC_5X5_KHR: 37810,
435
- COMPRESSED_RGBA_ASTC_6X5_KHR: 37811,
436
- COMPRESSED_RGBA_ASTC_6X6_KHR: 37812,
437
- COMPRESSED_RGBA_ASTC_8X5_KHR: 37813,
438
- COMPRESSED_RGBA_ASTC_8X6_KHR: 37814,
439
- COMPRESSED_RGBA_ASTC_8X8_KHR: 37815,
440
- COMPRESSED_RGBA_ASTC_10X5_KHR: 37816,
441
- COMPRESSED_RGBA_ASTC_10X6_KHR: 37817,
442
- COMPRESSED_RGBA_ASTC_10X8_KHR: 37818,
443
- COMPRESSED_RGBA_ASTC_10X10_KHR: 37819,
444
- COMPRESSED_RGBA_ASTC_12X10_KHR: 37820,
445
- COMPRESSED_RGBA_ASTC_12X12_KHR: 37821,
446
- COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 37840,
447
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 37841,
448
- COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 37842,
449
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 37843,
450
- COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 37844,
451
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 37845,
452
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 37846,
453
- COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 37847,
454
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 37848,
455
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 37849,
456
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 37850,
457
- COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 37851,
458
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 37852,
459
- COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 37853,
460
- COMPRESSED_RED_RGTC1_EXT: 36283,
461
- COMPRESSED_SIGNED_RED_RGTC1_EXT: 36284,
462
- COMPRESSED_RED_GREEN_RGTC2_EXT: 36285,
463
- COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 36286,
464
- COMPRESSED_SRGB_S3TC_DXT1_EXT: 35916,
465
- COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 35917,
466
- COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 35918,
467
- COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 35919
468
- };
370
+ // ../images/src/lib/category-api/parsed-image-api.ts
371
+ function getImageType(image) {
372
+ const format = getImageTypeOrNull(image);
373
+ if (!format) {
374
+ throw new Error("Not an image");
469
375
  }
470
- });
471
-
472
- // ../textures/src/lib/utils/texture-formats.ts
473
- function getSupportedGPUTextureFormats(gl) {
474
- if (!formats) {
475
- gl = gl || getWebGLContext() || void 0;
476
- formats = new Set();
477
- for (const prefix of BROWSER_PREFIXES) {
478
- for (const extension in WEBGL_EXTENSIONS) {
479
- if (gl && gl.getExtension(`${prefix}${extension}`)) {
480
- const gpuTextureFormat = WEBGL_EXTENSIONS[extension];
481
- formats.add(gpuTextureFormat);
482
- }
376
+ return format;
377
+ }
378
+ function getImageData(image) {
379
+ switch (getImageType(image)) {
380
+ case "data":
381
+ return image;
382
+ case "image":
383
+ case "imagebitmap":
384
+ const canvas = document.createElement("canvas");
385
+ const context = canvas.getContext("2d");
386
+ if (!context) {
387
+ throw new Error("getImageData");
483
388
  }
484
- }
389
+ canvas.width = image.width;
390
+ canvas.height = image.height;
391
+ context.drawImage(image, 0, 0);
392
+ return context.getImageData(0, 0, image.width, image.height);
393
+ default:
394
+ throw new Error("getImageData");
485
395
  }
486
- return formats;
487
396
  }
488
- function getWebGLContext() {
489
- try {
490
- const canvas = document.createElement("canvas");
491
- return canvas.getContext("webgl");
492
- } catch (error) {
493
- return null;
397
+ function getImageTypeOrNull(image) {
398
+ if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
399
+ return "imagebitmap";
494
400
  }
495
- }
496
- var BROWSER_PREFIXES, WEBGL_EXTENSIONS, formats;
497
- var init_texture_formats = __esm({
498
- "../textures/src/lib/utils/texture-formats.ts"() {
499
- BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
500
- WEBGL_EXTENSIONS = {
501
- WEBGL_compressed_texture_s3tc: "dxt",
502
- WEBGL_compressed_texture_s3tc_srgb: "dxt-srgb",
503
- WEBGL_compressed_texture_etc1: "etc1",
504
- WEBGL_compressed_texture_etc: "etc2",
505
- WEBGL_compressed_texture_pvrtc: "pvrtc",
506
- WEBGL_compressed_texture_atc: "atc",
507
- WEBGL_compressed_texture_astc: "astc",
508
- EXT_texture_compression_rgtc: "rgtc"
509
- };
510
- formats = null;
401
+ if (typeof Image !== "undefined" && image instanceof Image) {
402
+ return "image";
511
403
  }
512
- });
513
-
514
- // ../../node_modules/ktx-parse/dist/ktx-parse.modern.js
515
- var t, n, i, s, a, r, o, l, f;
516
- var init_ktx_parse_modern = __esm({
517
- "../../node_modules/ktx-parse/dist/ktx-parse.modern.js"() {
518
- t = new Uint8Array([0]);
519
- !function(t2) {
520
- t2[t2.NONE = 0] = "NONE", t2[t2.BASISLZ = 1] = "BASISLZ", t2[t2.ZSTD = 2] = "ZSTD", t2[t2.ZLIB = 3] = "ZLIB";
521
- }(n || (n = {})), function(t2) {
522
- t2[t2.BASICFORMAT = 0] = "BASICFORMAT";
523
- }(i || (i = {})), function(t2) {
524
- t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.ETC1S = 163] = "ETC1S", t2[t2.UASTC = 166] = "UASTC";
525
- }(s || (s = {})), function(t2) {
526
- t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.SRGB = 1] = "SRGB";
527
- }(a || (a = {})), function(t2) {
528
- t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.LINEAR = 1] = "LINEAR", t2[t2.SRGB = 2] = "SRGB", t2[t2.ITU = 3] = "ITU", t2[t2.NTSC = 4] = "NTSC", t2[t2.SLOG = 5] = "SLOG", t2[t2.SLOG2 = 6] = "SLOG2";
529
- }(r || (r = {})), function(t2) {
530
- t2[t2.ALPHA_STRAIGHT = 0] = "ALPHA_STRAIGHT", t2[t2.ALPHA_PREMULTIPLIED = 1] = "ALPHA_PREMULTIPLIED";
531
- }(o || (o = {})), function(t2) {
532
- t2[t2.RGB = 0] = "RGB", t2[t2.RRR = 3] = "RRR", t2[t2.GGG = 4] = "GGG", t2[t2.AAA = 15] = "AAA";
533
- }(l || (l = {})), function(t2) {
534
- t2[t2.RGB = 0] = "RGB", t2[t2.RGBA = 3] = "RGBA", t2[t2.RRR = 4] = "RRR", t2[t2.RRRG = 5] = "RRRG";
535
- }(f || (f = {}));
404
+ if (image && typeof image === "object" && image.data && image.width && image.height) {
405
+ return "data";
406
+ }
407
+ return null;
408
+ }
409
+ var init_parsed_image_api = __esm({
410
+ "../images/src/lib/category-api/parsed-image-api.ts"() {
536
411
  }
537
412
  });
538
413
 
539
- // ../textures/src/lib/parsers/parse-ktx.ts
540
- function isKTX(data) {
541
- const id = new Uint8Array(data);
542
- const notKTX = id.byteLength < KTX2_ID.length || id[0] !== KTX2_ID[0] || id[1] !== KTX2_ID[1] || id[2] !== KTX2_ID[2] || id[3] !== KTX2_ID[3] || id[4] !== KTX2_ID[4] || id[5] !== KTX2_ID[5] || id[6] !== KTX2_ID[6] || id[7] !== KTX2_ID[7] || id[8] !== KTX2_ID[8] || id[9] !== KTX2_ID[9] || id[10] !== KTX2_ID[10] || id[11] !== KTX2_ID[11];
543
- return !notKTX;
414
+ // ../images/src/lib/parsers/svg-utils.ts
415
+ function isSVG(url) {
416
+ return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
544
417
  }
545
- var KTX2_ID;
546
- var init_parse_ktx = __esm({
547
- "../textures/src/lib/parsers/parse-ktx.ts"() {
548
- init_ktx_parse_modern();
549
- KTX2_ID = [
550
- 171,
551
- 75,
552
- 84,
553
- 88,
554
- 32,
555
- 50,
556
- 48,
557
- 187,
558
- 13,
559
- 10,
560
- 26,
561
- 10
562
- ];
563
- }
564
- });
565
-
566
- // ../textures/src/lib/parsers/parse-basis.ts
567
- async function parseBasis(data, options) {
568
- if (options.basis.containerFormat === "auto") {
569
- if (isKTX(data)) {
570
- const fileConstructors = await loadBasisEncoderModule(options);
571
- return parseKTX2File(fileConstructors.KTX2File, data, options);
418
+ function getBlobOrSVGDataUrl(arrayBuffer, url) {
419
+ if (isSVG(url)) {
420
+ const textDecoder = new TextDecoder();
421
+ let xmlText = textDecoder.decode(arrayBuffer);
422
+ try {
423
+ if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
424
+ xmlText = unescape(encodeURIComponent(xmlText));
425
+ }
426
+ } catch (error) {
427
+ throw new Error(error.message);
572
428
  }
573
- const { BasisFile } = await loadBasisTrascoderModule(options);
574
- return parseBasisFile(BasisFile, data, options);
429
+ const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
430
+ return src;
575
431
  }
576
- switch (options.basis.module) {
577
- case "encoder":
578
- const fileConstructors = await loadBasisEncoderModule(options);
579
- switch (options.basis.containerFormat) {
580
- case "ktx2":
581
- return parseKTX2File(fileConstructors.KTX2File, data, options);
582
- case "basis":
583
- default:
584
- return parseBasisFile(fileConstructors.BasisFile, data, options);
585
- }
586
- case "transcoder":
587
- default:
588
- const { BasisFile } = await loadBasisTrascoderModule(options);
589
- return parseBasisFile(BasisFile, data, options);
432
+ return getBlob(arrayBuffer, url);
433
+ }
434
+ function getBlob(arrayBuffer, url) {
435
+ if (isSVG(url)) {
436
+ throw new Error("SVG cannot be parsed directly to imagebitmap");
590
437
  }
438
+ return new Blob([new Uint8Array(arrayBuffer)]);
591
439
  }
592
- function parseBasisFile(BasisFile, data, options) {
593
- const basisFile = new BasisFile(new Uint8Array(data));
440
+ var SVG_DATA_URL_PATTERN, SVG_URL_PATTERN;
441
+ var init_svg_utils = __esm({
442
+ "../images/src/lib/parsers/svg-utils.ts"() {
443
+ SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
444
+ SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
445
+ }
446
+ });
447
+
448
+ // ../images/src/lib/parsers/parse-to-image.ts
449
+ async function parseToImage(arrayBuffer, options, url) {
450
+ const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
451
+ const URL = self.URL || self.webkitURL;
452
+ const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
594
453
  try {
595
- if (!basisFile.startTranscoding()) {
596
- throw new Error("Failed to start basis transcoding");
597
- }
598
- const imageCount = basisFile.getNumImages();
599
- const images = [];
600
- for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
601
- const levelsCount = basisFile.getNumLevels(imageIndex);
602
- const levels = [];
603
- for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
604
- levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
605
- }
606
- images.push(levels);
607
- }
608
- return images;
454
+ return await loadToImage(objectUrl || blobOrDataUrl, options);
609
455
  } finally {
610
- basisFile.close();
611
- basisFile.delete();
456
+ if (objectUrl) {
457
+ URL.revokeObjectURL(objectUrl);
458
+ }
612
459
  }
613
460
  }
614
- function transcodeImage(basisFile, imageIndex, levelIndex, options) {
615
- const width = basisFile.getImageWidth(imageIndex, levelIndex);
616
- const height = basisFile.getImageHeight(imageIndex, levelIndex);
617
- const hasAlpha = basisFile.getHasAlpha();
618
- const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha);
619
- const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
620
- const decodedData = new Uint8Array(decodedSize);
621
- if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
622
- throw new Error("failed to start Basis transcoding");
461
+ async function loadToImage(url, options) {
462
+ const image = new Image();
463
+ image.src = url;
464
+ if (options.image && options.image.decode && image.decode) {
465
+ await image.decode();
466
+ return image;
623
467
  }
624
- return {
625
- width,
626
- height,
627
- data: decodedData,
628
- compressed,
629
- format,
630
- hasAlpha
631
- };
632
- }
633
- function parseKTX2File(KTX2File, data, options) {
634
- const ktx2File = new KTX2File(new Uint8Array(data));
635
- try {
636
- if (!ktx2File.startTranscoding()) {
637
- throw new Error("failed to start KTX2 transcoding");
468
+ return await new Promise((resolve, reject) => {
469
+ try {
470
+ image.onload = () => resolve(image);
471
+ image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
472
+ } catch (error) {
473
+ reject(error);
638
474
  }
639
- const levelsCount = ktx2File.getLevels();
640
- const levels = [];
641
- for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
642
- levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
643
- break;
475
+ });
476
+ }
477
+ var init_parse_to_image = __esm({
478
+ "../images/src/lib/parsers/parse-to-image.ts"() {
479
+ init_svg_utils();
480
+ }
481
+ });
482
+
483
+ // ../images/src/lib/parsers/parse-to-image-bitmap.ts
484
+ async function parseToImageBitmap(arrayBuffer, options, url) {
485
+ let blob;
486
+ if (isSVG(url)) {
487
+ const image = await parseToImage(arrayBuffer, options, url);
488
+ blob = image;
489
+ } else {
490
+ blob = getBlob(arrayBuffer, url);
491
+ }
492
+ const imagebitmapOptions = options && options.imagebitmap;
493
+ return await safeCreateImageBitmap(blob, imagebitmapOptions);
494
+ }
495
+ async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
496
+ if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
497
+ imagebitmapOptions = null;
498
+ }
499
+ if (imagebitmapOptions) {
500
+ try {
501
+ return await createImageBitmap(blob, imagebitmapOptions);
502
+ } catch (error) {
503
+ console.warn(error);
504
+ imagebitmapOptionsSupported = false;
644
505
  }
645
- return [levels];
646
- } finally {
647
- ktx2File.close();
648
- ktx2File.delete();
649
506
  }
507
+ return await createImageBitmap(blob);
650
508
  }
651
- function transcodeKTX2Image(ktx2File, levelIndex, options) {
652
- const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
653
- const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag);
654
- const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0, 0, basisFormat);
655
- const decodedData = new Uint8Array(decodedSize);
656
- if (!ktx2File.transcodeImage(decodedData, levelIndex, 0, 0, basisFormat, 0, -1, -1)) {
657
- throw new Error("Failed to transcode KTX2 image");
509
+ function isEmptyObject(object) {
510
+ for (const key in object || EMPTY_OBJECT) {
511
+ return false;
658
512
  }
659
- return {
660
- width,
661
- height,
662
- data: decodedData,
663
- compressed,
664
- levelSize: decodedSize,
665
- hasAlpha: alphaFlag,
666
- format
667
- };
513
+ return true;
668
514
  }
669
- function getBasisOptions(options, hasAlpha) {
670
- let format = options && options.basis && options.basis.format;
671
- if (format === "auto") {
672
- format = selectSupportedBasisFormat();
515
+ var EMPTY_OBJECT, imagebitmapOptionsSupported;
516
+ var init_parse_to_image_bitmap = __esm({
517
+ "../images/src/lib/parsers/parse-to-image-bitmap.ts"() {
518
+ init_svg_utils();
519
+ init_parse_to_image();
520
+ EMPTY_OBJECT = {};
521
+ imagebitmapOptionsSupported = true;
673
522
  }
674
- if (typeof format === "object") {
675
- format = hasAlpha ? format.alpha : format.noAlpha;
523
+ });
524
+
525
+ // ../images/src/lib/category-api/parse-isobmff-binary.ts
526
+ function getISOBMFFMediaType(buffer) {
527
+ if (!checkString(buffer, "ftyp", 4)) {
528
+ return null;
676
529
  }
677
- format = format.toLowerCase();
678
- return OutputFormat[format];
530
+ if ((buffer[8] & 96) === 0) {
531
+ return null;
532
+ }
533
+ return decodeMajorBrand(buffer);
679
534
  }
680
- function selectSupportedBasisFormat() {
681
- const supportedFormats = getSupportedGPUTextureFormats();
682
- if (supportedFormats.has("astc")) {
683
- return "astc-4x4";
684
- } else if (supportedFormats.has("dxt")) {
685
- return {
686
- alpha: "bc3",
687
- noAlpha: "bc1"
688
- };
689
- } else if (supportedFormats.has("pvrtc")) {
690
- return {
691
- alpha: "pvrtc1-4-rgba",
692
- noAlpha: "pvrtc1-4-rgb"
693
- };
694
- } else if (supportedFormats.has("etc1")) {
695
- return "etc1";
696
- } else if (supportedFormats.has("etc2")) {
697
- return "etc2";
535
+ function decodeMajorBrand(buffer) {
536
+ const brandMajor = getUTF8String(buffer, 8, 12).replace("\0", " ").trim();
537
+ switch (brandMajor) {
538
+ case "avif":
539
+ case "avis":
540
+ return { extension: "avif", mimeType: "image/avif" };
541
+ default:
542
+ return null;
698
543
  }
699
- return "rgb565";
700
544
  }
701
- var OutputFormat;
702
- var init_parse_basis = __esm({
703
- "../textures/src/lib/parsers/parse-basis.ts"() {
704
- init_basis_module_loader();
705
- init_gl_extensions();
706
- init_texture_formats();
707
- init_parse_ktx();
708
- OutputFormat = {
709
- etc1: {
710
- basisFormat: 0,
711
- compressed: true,
712
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
713
- },
714
- etc2: { basisFormat: 1, compressed: true },
715
- bc1: {
716
- basisFormat: 2,
717
- compressed: true,
718
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
719
- },
720
- bc3: {
721
- basisFormat: 3,
722
- compressed: true,
723
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
724
- },
725
- bc4: { basisFormat: 4, compressed: true },
726
- bc5: { basisFormat: 5, compressed: true },
727
- "bc7-m6-opaque-only": { basisFormat: 6, compressed: true },
728
- "bc7-m5": { basisFormat: 7, compressed: true },
729
- "pvrtc1-4-rgb": {
730
- basisFormat: 8,
731
- compressed: true,
732
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
733
- },
734
- "pvrtc1-4-rgba": {
735
- basisFormat: 9,
736
- compressed: true,
737
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
738
- },
739
- "astc-4x4": {
740
- basisFormat: 10,
741
- compressed: true,
742
- format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
743
- },
744
- "atc-rgb": { basisFormat: 11, compressed: true },
745
- "atc-rgba-interpolated-alpha": { basisFormat: 12, compressed: true },
746
- rgba32: { basisFormat: 13, compressed: false },
747
- rgb565: { basisFormat: 14, compressed: false },
748
- bgr565: { basisFormat: 15, compressed: false },
749
- rgba4444: { basisFormat: 16, compressed: false }
750
- };
751
- }
752
- });
753
-
754
- // ../textures/src/basis-loader.ts
755
- var BasisWorkerLoader, BasisLoader;
756
- var init_basis_loader = __esm({
757
- "../textures/src/basis-loader.ts"() {
758
- init_src();
759
- init_version3();
760
- init_parse_basis();
761
- BasisWorkerLoader = {
762
- name: "Basis",
763
- id: isBrowser2 ? "basis" : "basis-nodejs",
764
- module: "textures",
765
- version: VERSION4,
766
- worker: true,
767
- extensions: ["basis", "ktx2"],
768
- mimeTypes: ["application/octet-stream", "image/ktx2"],
769
- tests: ["sB"],
770
- binary: true,
771
- options: {
772
- basis: {
773
- format: "auto",
774
- libraryPath: "libs/",
775
- containerFormat: "auto",
776
- module: "transcoder"
777
- }
778
- }
779
- };
780
- BasisLoader = {
781
- ...BasisWorkerLoader,
782
- parse: parseBasis
783
- };
784
- }
785
- });
786
-
787
- // ../images/src/lib/utils/version.ts
788
- var VERSION6;
789
- var init_version4 = __esm({
790
- "../images/src/lib/utils/version.ts"() {
791
- VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
792
- }
793
- });
794
-
795
- // ../images/src/lib/category-api/image-type.ts
796
- function isImageTypeSupported(type) {
797
- switch (type) {
798
- case "auto":
799
- return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
800
- case "imagebitmap":
801
- return IMAGE_BITMAP_SUPPORTED;
802
- case "image":
803
- return IMAGE_SUPPORTED;
804
- case "data":
805
- return DATA_SUPPORTED;
806
- default:
807
- throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
808
- }
545
+ function getUTF8String(array, start, end) {
546
+ return String.fromCharCode(...array.slice(start, end));
809
547
  }
810
- function getDefaultImageType() {
811
- if (IMAGE_BITMAP_SUPPORTED) {
812
- return "imagebitmap";
813
- }
814
- if (IMAGE_SUPPORTED) {
815
- return "image";
816
- }
817
- if (DATA_SUPPORTED) {
818
- return "data";
548
+ function stringToBytes(string) {
549
+ return [...string].map((character) => character.charCodeAt(0));
550
+ }
551
+ function checkString(buffer, header, offset = 0) {
552
+ const headerBytes = stringToBytes(header);
553
+ for (let i2 = 0; i2 < headerBytes.length; ++i2) {
554
+ if (headerBytes[i2] !== buffer[i2 + offset]) {
555
+ return false;
556
+ }
819
557
  }
820
- throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
558
+ return true;
821
559
  }
822
- var _parseImageNode, IMAGE_SUPPORTED, IMAGE_BITMAP_SUPPORTED, NODE_IMAGE_SUPPORTED, DATA_SUPPORTED;
823
- var init_image_type = __esm({
824
- "../images/src/lib/category-api/image-type.ts"() {
825
- init_src2();
826
- ({ _parseImageNode } = globalThis);
827
- IMAGE_SUPPORTED = typeof Image !== "undefined";
828
- IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
829
- NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
830
- DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
560
+ var init_parse_isobmff_binary = __esm({
561
+ "../images/src/lib/category-api/parse-isobmff-binary.ts"() {
831
562
  }
832
563
  });
833
564
 
834
- // ../images/src/lib/category-api/parsed-image-api.ts
835
- function getImageType(image) {
836
- const format = getImageTypeOrNull(image);
837
- if (!format) {
838
- throw new Error("Not an image");
839
- }
840
- return format;
565
+ // ../images/src/lib/category-api/binary-image-api.ts
566
+ function getBinaryImageMetadata(binaryData) {
567
+ const dataView = toDataView(binaryData);
568
+ return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
841
569
  }
842
- function getImageData(image) {
843
- switch (getImageType(image)) {
844
- case "data":
845
- return image;
846
- case "image":
847
- case "imagebitmap":
848
- const canvas = document.createElement("canvas");
849
- const context = canvas.getContext("2d");
850
- if (!context) {
851
- throw new Error("getImageData");
852
- }
853
- canvas.width = image.width;
854
- canvas.height = image.height;
855
- context.drawImage(image, 0, 0);
856
- return context.getImageData(0, 0, image.width, image.height);
857
- default:
858
- throw new Error("getImageData");
570
+ function getISOBMFFMetadata(binaryData) {
571
+ const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
572
+ const mediaType = getISOBMFFMediaType(buffer);
573
+ if (!mediaType) {
574
+ return null;
859
575
  }
576
+ return {
577
+ mimeType: mediaType.mimeType,
578
+ width: 0,
579
+ height: 0
580
+ };
860
581
  }
861
- function getImageTypeOrNull(image) {
862
- if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
863
- return "imagebitmap";
864
- }
865
- if (typeof Image !== "undefined" && image instanceof Image) {
866
- return "image";
582
+ function getPngMetadata(binaryData) {
583
+ const dataView = toDataView(binaryData);
584
+ const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
585
+ if (!isPng) {
586
+ return null;
867
587
  }
868
- if (image && typeof image === "object" && image.data && image.width && image.height) {
869
- return "data";
588
+ return {
589
+ mimeType: "image/png",
590
+ width: dataView.getUint32(16, BIG_ENDIAN),
591
+ height: dataView.getUint32(20, BIG_ENDIAN)
592
+ };
593
+ }
594
+ function getGifMetadata(binaryData) {
595
+ const dataView = toDataView(binaryData);
596
+ const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
597
+ if (!isGif) {
598
+ return null;
870
599
  }
871
- return null;
600
+ return {
601
+ mimeType: "image/gif",
602
+ width: dataView.getUint16(6, LITTLE_ENDIAN),
603
+ height: dataView.getUint16(8, LITTLE_ENDIAN)
604
+ };
872
605
  }
873
- var init_parsed_image_api = __esm({
874
- "../images/src/lib/category-api/parsed-image-api.ts"() {
606
+ function getBmpMetadata(binaryData) {
607
+ const dataView = toDataView(binaryData);
608
+ const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
609
+ if (!isBmp) {
610
+ return null;
875
611
  }
876
- });
877
-
878
- // ../images/src/lib/parsers/svg-utils.ts
879
- function isSVG(url) {
880
- return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
612
+ return {
613
+ mimeType: "image/bmp",
614
+ width: dataView.getUint32(18, LITTLE_ENDIAN),
615
+ height: dataView.getUint32(22, LITTLE_ENDIAN)
616
+ };
881
617
  }
882
- function getBlobOrSVGDataUrl(arrayBuffer, url) {
883
- if (isSVG(url)) {
884
- const textDecoder = new TextDecoder();
885
- let xmlText = textDecoder.decode(arrayBuffer);
886
- try {
887
- if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
888
- xmlText = unescape(encodeURIComponent(xmlText));
889
- }
890
- } catch (error) {
891
- throw new Error(error.message);
618
+ function getJpegMetadata(binaryData) {
619
+ const dataView = toDataView(binaryData);
620
+ const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
621
+ if (!isJpeg) {
622
+ return null;
623
+ }
624
+ const { tableMarkers, sofMarkers } = getJpegMarkers();
625
+ let i2 = 2;
626
+ while (i2 + 9 < dataView.byteLength) {
627
+ const marker = dataView.getUint16(i2, BIG_ENDIAN);
628
+ if (sofMarkers.has(marker)) {
629
+ return {
630
+ mimeType: "image/jpeg",
631
+ height: dataView.getUint16(i2 + 5, BIG_ENDIAN),
632
+ width: dataView.getUint16(i2 + 7, BIG_ENDIAN)
633
+ };
892
634
  }
893
- const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
894
- return src;
635
+ if (!tableMarkers.has(marker)) {
636
+ return null;
637
+ }
638
+ i2 += 2;
639
+ i2 += dataView.getUint16(i2, BIG_ENDIAN);
895
640
  }
896
- return getBlob(arrayBuffer, url);
897
- }
898
- function getBlob(arrayBuffer, url) {
899
- if (isSVG(url)) {
900
- throw new Error("SVG cannot be parsed directly to imagebitmap");
901
- }
902
- return new Blob([new Uint8Array(arrayBuffer)]);
903
- }
904
- var SVG_DATA_URL_PATTERN, SVG_URL_PATTERN;
905
- var init_svg_utils = __esm({
906
- "../images/src/lib/parsers/svg-utils.ts"() {
907
- SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
908
- SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
909
- }
910
- });
911
-
912
- // ../images/src/lib/parsers/parse-to-image.ts
913
- async function parseToImage(arrayBuffer, options, url) {
914
- const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
915
- const URL = self.URL || self.webkitURL;
916
- const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
917
- try {
918
- return await loadToImage(objectUrl || blobOrDataUrl, options);
919
- } finally {
920
- if (objectUrl) {
921
- URL.revokeObjectURL(objectUrl);
922
- }
923
- }
924
- }
925
- async function loadToImage(url, options) {
926
- const image = new Image();
927
- image.src = url;
928
- if (options.image && options.image.decode && image.decode) {
929
- await image.decode();
930
- return image;
931
- }
932
- return await new Promise((resolve, reject) => {
933
- try {
934
- image.onload = () => resolve(image);
935
- image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
936
- } catch (error) {
937
- reject(error);
938
- }
939
- });
940
- }
941
- var init_parse_to_image = __esm({
942
- "../images/src/lib/parsers/parse-to-image.ts"() {
943
- init_svg_utils();
944
- }
945
- });
946
-
947
- // ../images/src/lib/parsers/parse-to-image-bitmap.ts
948
- async function parseToImageBitmap(arrayBuffer, options, url) {
949
- let blob;
950
- if (isSVG(url)) {
951
- const image = await parseToImage(arrayBuffer, options, url);
952
- blob = image;
953
- } else {
954
- blob = getBlob(arrayBuffer, url);
955
- }
956
- const imagebitmapOptions = options && options.imagebitmap;
957
- return await safeCreateImageBitmap(blob, imagebitmapOptions);
958
- }
959
- async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
960
- if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
961
- imagebitmapOptions = null;
962
- }
963
- if (imagebitmapOptions) {
964
- try {
965
- return await createImageBitmap(blob, imagebitmapOptions);
966
- } catch (error) {
967
- console.warn(error);
968
- imagebitmapOptionsSupported = false;
969
- }
970
- }
971
- return await createImageBitmap(blob);
972
- }
973
- function isEmptyObject(object) {
974
- for (const key in object || EMPTY_OBJECT) {
975
- return false;
976
- }
977
- return true;
978
- }
979
- var EMPTY_OBJECT, imagebitmapOptionsSupported;
980
- var init_parse_to_image_bitmap = __esm({
981
- "../images/src/lib/parsers/parse-to-image-bitmap.ts"() {
982
- init_svg_utils();
983
- init_parse_to_image();
984
- EMPTY_OBJECT = {};
985
- imagebitmapOptionsSupported = true;
986
- }
987
- });
988
-
989
- // ../images/src/lib/category-api/parse-isobmff-binary.ts
990
- function getISOBMFFMediaType(buffer) {
991
- if (!checkString(buffer, "ftyp", 4)) {
992
- return null;
993
- }
994
- if ((buffer[8] & 96) === 0) {
995
- return null;
996
- }
997
- return decodeMajorBrand(buffer);
998
- }
999
- function decodeMajorBrand(buffer) {
1000
- const brandMajor = getUTF8String(buffer, 8, 12).replace("\0", " ").trim();
1001
- switch (brandMajor) {
1002
- case "avif":
1003
- case "avis":
1004
- return { extension: "avif", mimeType: "image/avif" };
1005
- default:
1006
- return null;
1007
- }
1008
- }
1009
- function getUTF8String(array, start, end) {
1010
- return String.fromCharCode(...array.slice(start, end));
1011
- }
1012
- function stringToBytes(string) {
1013
- return [...string].map((character) => character.charCodeAt(0));
1014
- }
1015
- function checkString(buffer, header, offset = 0) {
1016
- const headerBytes = stringToBytes(header);
1017
- for (let i2 = 0; i2 < headerBytes.length; ++i2) {
1018
- if (headerBytes[i2] !== buffer[i2 + offset]) {
1019
- return false;
1020
- }
1021
- }
1022
- return true;
1023
- }
1024
- var init_parse_isobmff_binary = __esm({
1025
- "../images/src/lib/category-api/parse-isobmff-binary.ts"() {
1026
- }
1027
- });
1028
-
1029
- // ../images/src/lib/category-api/binary-image-api.ts
1030
- function getBinaryImageMetadata(binaryData) {
1031
- const dataView = toDataView(binaryData);
1032
- return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
1033
- }
1034
- function getISOBMFFMetadata(binaryData) {
1035
- const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
1036
- const mediaType = getISOBMFFMediaType(buffer);
1037
- if (!mediaType) {
1038
- return null;
1039
- }
1040
- return {
1041
- mimeType: mediaType.mimeType,
1042
- width: 0,
1043
- height: 0
1044
- };
1045
- }
1046
- function getPngMetadata(binaryData) {
1047
- const dataView = toDataView(binaryData);
1048
- const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
1049
- if (!isPng) {
1050
- return null;
1051
- }
1052
- return {
1053
- mimeType: "image/png",
1054
- width: dataView.getUint32(16, BIG_ENDIAN),
1055
- height: dataView.getUint32(20, BIG_ENDIAN)
1056
- };
1057
- }
1058
- function getGifMetadata(binaryData) {
1059
- const dataView = toDataView(binaryData);
1060
- const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
1061
- if (!isGif) {
1062
- return null;
1063
- }
1064
- return {
1065
- mimeType: "image/gif",
1066
- width: dataView.getUint16(6, LITTLE_ENDIAN),
1067
- height: dataView.getUint16(8, LITTLE_ENDIAN)
1068
- };
1069
- }
1070
- function getBmpMetadata(binaryData) {
1071
- const dataView = toDataView(binaryData);
1072
- const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
1073
- if (!isBmp) {
1074
- return null;
1075
- }
1076
- return {
1077
- mimeType: "image/bmp",
1078
- width: dataView.getUint32(18, LITTLE_ENDIAN),
1079
- height: dataView.getUint32(22, LITTLE_ENDIAN)
1080
- };
1081
- }
1082
- function getJpegMetadata(binaryData) {
1083
- const dataView = toDataView(binaryData);
1084
- const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
1085
- if (!isJpeg) {
1086
- return null;
1087
- }
1088
- const { tableMarkers, sofMarkers } = getJpegMarkers();
1089
- let i2 = 2;
1090
- while (i2 + 9 < dataView.byteLength) {
1091
- const marker = dataView.getUint16(i2, BIG_ENDIAN);
1092
- if (sofMarkers.has(marker)) {
1093
- return {
1094
- mimeType: "image/jpeg",
1095
- height: dataView.getUint16(i2 + 5, BIG_ENDIAN),
1096
- width: dataView.getUint16(i2 + 7, BIG_ENDIAN)
1097
- };
1098
- }
1099
- if (!tableMarkers.has(marker)) {
1100
- return null;
1101
- }
1102
- i2 += 2;
1103
- i2 += dataView.getUint16(i2, BIG_ENDIAN);
1104
- }
1105
- return null;
641
+ return null;
1106
642
  }
1107
643
  function getJpegMarkers() {
1108
644
  const tableMarkers = new Set([65499, 65476, 65484, 65501, 65534]);
@@ -1148,150 +684,613 @@
1148
684
  }
1149
685
  });
1150
686
 
1151
- // ../images/src/lib/parsers/parse-to-node-image.ts
1152
- async function parseToNodeImage(arrayBuffer, options) {
1153
- const { mimeType } = getBinaryImageMetadata(arrayBuffer) || {};
1154
- const _parseImageNode2 = globalThis._parseImageNode;
1155
- assert(_parseImageNode2);
1156
- return await _parseImageNode2(arrayBuffer, mimeType);
687
+ // ../images/src/lib/parsers/parse-to-node-image.ts
688
+ async function parseToNodeImage(arrayBuffer, options) {
689
+ const { mimeType } = getBinaryImageMetadata(arrayBuffer) || {};
690
+ const _parseImageNode2 = globalThis._parseImageNode;
691
+ assert(_parseImageNode2);
692
+ return await _parseImageNode2(arrayBuffer, mimeType);
693
+ }
694
+ var init_parse_to_node_image = __esm({
695
+ "../images/src/lib/parsers/parse-to-node-image.ts"() {
696
+ init_src2();
697
+ init_binary_image_api();
698
+ }
699
+ });
700
+
701
+ // ../images/src/lib/parsers/parse-image.ts
702
+ async function parseImage(arrayBuffer, options, context) {
703
+ options = options || {};
704
+ const imageOptions = options.image || {};
705
+ const imageType = imageOptions.type || "auto";
706
+ const { url } = context || {};
707
+ const loadType = getLoadableImageType(imageType);
708
+ let image;
709
+ switch (loadType) {
710
+ case "imagebitmap":
711
+ image = await parseToImageBitmap(arrayBuffer, options, url);
712
+ break;
713
+ case "image":
714
+ image = await parseToImage(arrayBuffer, options, url);
715
+ break;
716
+ case "data":
717
+ image = await parseToNodeImage(arrayBuffer, options);
718
+ break;
719
+ default:
720
+ assert(false);
721
+ }
722
+ if (imageType === "data") {
723
+ image = getImageData(image);
724
+ }
725
+ return image;
726
+ }
727
+ function getLoadableImageType(type) {
728
+ switch (type) {
729
+ case "auto":
730
+ case "data":
731
+ return getDefaultImageType();
732
+ default:
733
+ isImageTypeSupported(type);
734
+ return type;
735
+ }
736
+ }
737
+ var init_parse_image = __esm({
738
+ "../images/src/lib/parsers/parse-image.ts"() {
739
+ init_src2();
740
+ init_image_type();
741
+ init_parsed_image_api();
742
+ init_parse_to_image();
743
+ init_parse_to_image_bitmap();
744
+ init_parse_to_node_image();
745
+ }
746
+ });
747
+
748
+ // ../images/src/image-loader.ts
749
+ var EXTENSIONS, MIME_TYPES, DEFAULT_IMAGE_LOADER_OPTIONS, ImageLoader;
750
+ var init_image_loader = __esm({
751
+ "../images/src/image-loader.ts"() {
752
+ init_version3();
753
+ init_parse_image();
754
+ init_binary_image_api();
755
+ EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
756
+ MIME_TYPES = [
757
+ "image/png",
758
+ "image/jpeg",
759
+ "image/gif",
760
+ "image/webp",
761
+ "image/avif",
762
+ "image/bmp",
763
+ "image/vnd.microsoft.icon",
764
+ "image/svg+xml"
765
+ ];
766
+ DEFAULT_IMAGE_LOADER_OPTIONS = {
767
+ image: {
768
+ type: "auto",
769
+ decode: true
770
+ }
771
+ };
772
+ ImageLoader = {
773
+ id: "image",
774
+ module: "images",
775
+ name: "Images",
776
+ version: VERSION4,
777
+ mimeTypes: MIME_TYPES,
778
+ extensions: EXTENSIONS,
779
+ parse: parseImage,
780
+ tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
781
+ options: DEFAULT_IMAGE_LOADER_OPTIONS
782
+ };
783
+ }
784
+ });
785
+
786
+ // ../images/src/lib/category-api/image-format.ts
787
+ function isImageFormatSupported(mimeType) {
788
+ if (mimeTypeSupportedSync[mimeType] === void 0) {
789
+ const supported = isBrowser ? checkBrowserImageFormatSupport(mimeType) : checkNodeImageFormatSupport(mimeType);
790
+ mimeTypeSupportedSync[mimeType] = supported;
791
+ }
792
+ return mimeTypeSupportedSync[mimeType];
793
+ }
794
+ function checkNodeImageFormatSupport(mimeType) {
795
+ const NODE_FORMAT_SUPPORT = ["image/png", "image/jpeg", "image/gif"];
796
+ const { _parseImageNode: _parseImageNode2, _imageFormatsNode = NODE_FORMAT_SUPPORT } = globalThis;
797
+ return Boolean(_parseImageNode2) && _imageFormatsNode.includes(mimeType);
798
+ }
799
+ function checkBrowserImageFormatSupport(mimeType) {
800
+ switch (mimeType) {
801
+ case "image/avif":
802
+ case "image/webp":
803
+ return testBrowserImageFormatSupport(mimeType);
804
+ default:
805
+ return true;
806
+ }
807
+ }
808
+ function testBrowserImageFormatSupport(mimeType) {
809
+ try {
810
+ const element = document.createElement("canvas");
811
+ const dataURL = element.toDataURL(mimeType);
812
+ return dataURL.indexOf(`data:${mimeType}`) === 0;
813
+ } catch {
814
+ return false;
815
+ }
816
+ }
817
+ var mimeTypeSupportedSync;
818
+ var init_image_format = __esm({
819
+ "../images/src/lib/category-api/image-format.ts"() {
820
+ init_src2();
821
+ mimeTypeSupportedSync = {};
822
+ }
823
+ });
824
+
825
+ // ../images/src/index.ts
826
+ var init_src3 = __esm({
827
+ "../images/src/index.ts"() {
828
+ init_image_loader();
829
+ init_binary_image_api();
830
+ init_parsed_image_api();
831
+ init_image_format();
832
+ }
833
+ });
834
+
835
+ // ../textures/src/lib/utils/version.ts
836
+ var VERSION5;
837
+ var init_version4 = __esm({
838
+ "../textures/src/lib/utils/version.ts"() {
839
+ VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
840
+ }
841
+ });
842
+
843
+ // ../textures/src/lib/parsers/basis-module-loader.ts
844
+ async function loadBasisTrascoderModule(options) {
845
+ const modules = options.modules || {};
846
+ if (modules.basis) {
847
+ return modules.basis;
848
+ }
849
+ loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTrascoder(options);
850
+ return await loadBasisTranscoderPromise;
851
+ }
852
+ async function loadBasisTrascoder(options) {
853
+ let BASIS = null;
854
+ let wasmBinary = null;
855
+ [BASIS, wasmBinary] = await Promise.all([
856
+ await loadLibrary("basis_transcoder.js", "textures", options),
857
+ await loadLibrary("basis_transcoder.wasm", "textures", options)
858
+ ]);
859
+ BASIS = BASIS || globalThis.BASIS;
860
+ return await initializeBasisTrascoderModule(BASIS, wasmBinary);
861
+ }
862
+ function initializeBasisTrascoderModule(BasisModule, wasmBinary) {
863
+ const options = {};
864
+ if (wasmBinary) {
865
+ options.wasmBinary = wasmBinary;
866
+ }
867
+ return new Promise((resolve) => {
868
+ BasisModule(options).then((module) => {
869
+ const { BasisFile, initializeBasis } = module;
870
+ initializeBasis();
871
+ resolve({ BasisFile });
872
+ });
873
+ });
874
+ }
875
+ async function loadBasisEncoderModule(options) {
876
+ const modules = options.modules || {};
877
+ if (modules.basisEncoder) {
878
+ return modules.basisEncoder;
879
+ }
880
+ loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options);
881
+ return await loadBasisEncoderPromise;
882
+ }
883
+ async function loadBasisEncoder(options) {
884
+ let BASIS_ENCODER = null;
885
+ let wasmBinary = null;
886
+ [BASIS_ENCODER, wasmBinary] = await Promise.all([
887
+ await loadLibrary(BASIS_CDN_ENCODER_JS, "textures", options),
888
+ await loadLibrary(BASIS_CDN_ENCODER_WASM, "textures", options)
889
+ ]);
890
+ BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
891
+ return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
892
+ }
893
+ function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {
894
+ const options = {};
895
+ if (wasmBinary) {
896
+ options.wasmBinary = wasmBinary;
897
+ }
898
+ return new Promise((resolve) => {
899
+ BasisEncoderModule(options).then((module) => {
900
+ const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module;
901
+ initializeBasis();
902
+ resolve({ BasisFile, KTX2File, BasisEncoder });
903
+ });
904
+ });
905
+ }
906
+ var VERSION6, BASIS_CDN_ENCODER_WASM, BASIS_CDN_ENCODER_JS, loadBasisTranscoderPromise, loadBasisEncoderPromise;
907
+ var init_basis_module_loader = __esm({
908
+ "../textures/src/lib/parsers/basis-module-loader.ts"() {
909
+ init_src();
910
+ VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
911
+ BASIS_CDN_ENCODER_WASM = `https://unpkg.com/@loaders.gl/textures@${VERSION6}/dist/libs/basis_encoder.wasm`;
912
+ BASIS_CDN_ENCODER_JS = `https://unpkg.com/@loaders.gl/textures@${VERSION6}/dist/libs/basis_encoder.js`;
913
+ }
914
+ });
915
+
916
+ // ../textures/src/lib/gl-extensions.ts
917
+ var GL_EXTENSIONS_CONSTANTS;
918
+ var init_gl_extensions = __esm({
919
+ "../textures/src/lib/gl-extensions.ts"() {
920
+ GL_EXTENSIONS_CONSTANTS = {
921
+ COMPRESSED_RGB_S3TC_DXT1_EXT: 33776,
922
+ COMPRESSED_RGBA_S3TC_DXT1_EXT: 33777,
923
+ COMPRESSED_RGBA_S3TC_DXT3_EXT: 33778,
924
+ COMPRESSED_RGBA_S3TC_DXT5_EXT: 33779,
925
+ COMPRESSED_R11_EAC: 37488,
926
+ COMPRESSED_SIGNED_R11_EAC: 37489,
927
+ COMPRESSED_RG11_EAC: 37490,
928
+ COMPRESSED_SIGNED_RG11_EAC: 37491,
929
+ COMPRESSED_RGB8_ETC2: 37492,
930
+ COMPRESSED_RGBA8_ETC2_EAC: 37493,
931
+ COMPRESSED_SRGB8_ETC2: 37494,
932
+ COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 37495,
933
+ COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37496,
934
+ COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37497,
935
+ COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 35840,
936
+ COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 35842,
937
+ COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 35841,
938
+ COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 35843,
939
+ COMPRESSED_RGB_ETC1_WEBGL: 36196,
940
+ COMPRESSED_RGB_ATC_WEBGL: 35986,
941
+ COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 35987,
942
+ COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 34798,
943
+ COMPRESSED_RGBA_ASTC_4X4_KHR: 37808,
944
+ COMPRESSED_RGBA_ASTC_5X4_KHR: 37809,
945
+ COMPRESSED_RGBA_ASTC_5X5_KHR: 37810,
946
+ COMPRESSED_RGBA_ASTC_6X5_KHR: 37811,
947
+ COMPRESSED_RGBA_ASTC_6X6_KHR: 37812,
948
+ COMPRESSED_RGBA_ASTC_8X5_KHR: 37813,
949
+ COMPRESSED_RGBA_ASTC_8X6_KHR: 37814,
950
+ COMPRESSED_RGBA_ASTC_8X8_KHR: 37815,
951
+ COMPRESSED_RGBA_ASTC_10X5_KHR: 37816,
952
+ COMPRESSED_RGBA_ASTC_10X6_KHR: 37817,
953
+ COMPRESSED_RGBA_ASTC_10X8_KHR: 37818,
954
+ COMPRESSED_RGBA_ASTC_10X10_KHR: 37819,
955
+ COMPRESSED_RGBA_ASTC_12X10_KHR: 37820,
956
+ COMPRESSED_RGBA_ASTC_12X12_KHR: 37821,
957
+ COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 37840,
958
+ COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 37841,
959
+ COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 37842,
960
+ COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 37843,
961
+ COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 37844,
962
+ COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 37845,
963
+ COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 37846,
964
+ COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 37847,
965
+ COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 37848,
966
+ COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 37849,
967
+ COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 37850,
968
+ COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 37851,
969
+ COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 37852,
970
+ COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 37853,
971
+ COMPRESSED_RED_RGTC1_EXT: 36283,
972
+ COMPRESSED_SIGNED_RED_RGTC1_EXT: 36284,
973
+ COMPRESSED_RED_GREEN_RGTC2_EXT: 36285,
974
+ COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 36286,
975
+ COMPRESSED_SRGB_S3TC_DXT1_EXT: 35916,
976
+ COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 35917,
977
+ COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 35918,
978
+ COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 35919
979
+ };
980
+ }
981
+ });
982
+
983
+ // ../textures/src/lib/utils/texture-formats.ts
984
+ function getSupportedGPUTextureFormats(gl) {
985
+ if (!formats) {
986
+ gl = gl || getWebGLContext() || void 0;
987
+ formats = new Set();
988
+ for (const prefix of BROWSER_PREFIXES) {
989
+ for (const extension in WEBGL_EXTENSIONS) {
990
+ if (gl && gl.getExtension(`${prefix}${extension}`)) {
991
+ const gpuTextureFormat = WEBGL_EXTENSIONS[extension];
992
+ formats.add(gpuTextureFormat);
993
+ }
994
+ }
995
+ }
996
+ }
997
+ return formats;
998
+ }
999
+ function getWebGLContext() {
1000
+ try {
1001
+ const canvas = document.createElement("canvas");
1002
+ return canvas.getContext("webgl");
1003
+ } catch (error) {
1004
+ return null;
1005
+ }
1006
+ }
1007
+ var BROWSER_PREFIXES, WEBGL_EXTENSIONS, formats;
1008
+ var init_texture_formats = __esm({
1009
+ "../textures/src/lib/utils/texture-formats.ts"() {
1010
+ BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
1011
+ WEBGL_EXTENSIONS = {
1012
+ WEBGL_compressed_texture_s3tc: "dxt",
1013
+ WEBGL_compressed_texture_s3tc_srgb: "dxt-srgb",
1014
+ WEBGL_compressed_texture_etc1: "etc1",
1015
+ WEBGL_compressed_texture_etc: "etc2",
1016
+ WEBGL_compressed_texture_pvrtc: "pvrtc",
1017
+ WEBGL_compressed_texture_atc: "atc",
1018
+ WEBGL_compressed_texture_astc: "astc",
1019
+ EXT_texture_compression_rgtc: "rgtc"
1020
+ };
1021
+ formats = null;
1022
+ }
1023
+ });
1024
+
1025
+ // ../../node_modules/ktx-parse/dist/ktx-parse.modern.js
1026
+ var t, n, i, s, a, r, o, l, f;
1027
+ var init_ktx_parse_modern = __esm({
1028
+ "../../node_modules/ktx-parse/dist/ktx-parse.modern.js"() {
1029
+ t = new Uint8Array([0]);
1030
+ !function(t2) {
1031
+ t2[t2.NONE = 0] = "NONE", t2[t2.BASISLZ = 1] = "BASISLZ", t2[t2.ZSTD = 2] = "ZSTD", t2[t2.ZLIB = 3] = "ZLIB";
1032
+ }(n || (n = {})), function(t2) {
1033
+ t2[t2.BASICFORMAT = 0] = "BASICFORMAT";
1034
+ }(i || (i = {})), function(t2) {
1035
+ t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.ETC1S = 163] = "ETC1S", t2[t2.UASTC = 166] = "UASTC";
1036
+ }(s || (s = {})), function(t2) {
1037
+ t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.SRGB = 1] = "SRGB";
1038
+ }(a || (a = {})), function(t2) {
1039
+ t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.LINEAR = 1] = "LINEAR", t2[t2.SRGB = 2] = "SRGB", t2[t2.ITU = 3] = "ITU", t2[t2.NTSC = 4] = "NTSC", t2[t2.SLOG = 5] = "SLOG", t2[t2.SLOG2 = 6] = "SLOG2";
1040
+ }(r || (r = {})), function(t2) {
1041
+ t2[t2.ALPHA_STRAIGHT = 0] = "ALPHA_STRAIGHT", t2[t2.ALPHA_PREMULTIPLIED = 1] = "ALPHA_PREMULTIPLIED";
1042
+ }(o || (o = {})), function(t2) {
1043
+ t2[t2.RGB = 0] = "RGB", t2[t2.RRR = 3] = "RRR", t2[t2.GGG = 4] = "GGG", t2[t2.AAA = 15] = "AAA";
1044
+ }(l || (l = {})), function(t2) {
1045
+ t2[t2.RGB = 0] = "RGB", t2[t2.RGBA = 3] = "RGBA", t2[t2.RRR = 4] = "RRR", t2[t2.RRRG = 5] = "RRRG";
1046
+ }(f || (f = {}));
1047
+ }
1048
+ });
1049
+
1050
+ // ../textures/src/lib/parsers/parse-ktx.ts
1051
+ function isKTX(data) {
1052
+ const id = new Uint8Array(data);
1053
+ const notKTX = id.byteLength < KTX2_ID.length || id[0] !== KTX2_ID[0] || id[1] !== KTX2_ID[1] || id[2] !== KTX2_ID[2] || id[3] !== KTX2_ID[3] || id[4] !== KTX2_ID[4] || id[5] !== KTX2_ID[5] || id[6] !== KTX2_ID[6] || id[7] !== KTX2_ID[7] || id[8] !== KTX2_ID[8] || id[9] !== KTX2_ID[9] || id[10] !== KTX2_ID[10] || id[11] !== KTX2_ID[11];
1054
+ return !notKTX;
1157
1055
  }
1158
- var init_parse_to_node_image = __esm({
1159
- "../images/src/lib/parsers/parse-to-node-image.ts"() {
1160
- init_src2();
1161
- init_binary_image_api();
1056
+ var KTX2_ID;
1057
+ var init_parse_ktx = __esm({
1058
+ "../textures/src/lib/parsers/parse-ktx.ts"() {
1059
+ init_ktx_parse_modern();
1060
+ KTX2_ID = [
1061
+ 171,
1062
+ 75,
1063
+ 84,
1064
+ 88,
1065
+ 32,
1066
+ 50,
1067
+ 48,
1068
+ 187,
1069
+ 13,
1070
+ 10,
1071
+ 26,
1072
+ 10
1073
+ ];
1162
1074
  }
1163
1075
  });
1164
1076
 
1165
- // ../images/src/lib/parsers/parse-image.ts
1166
- async function parseImage(arrayBuffer, options, context) {
1167
- options = options || {};
1168
- const imageOptions = options.image || {};
1169
- const imageType = imageOptions.type || "auto";
1170
- const { url } = context || {};
1171
- const loadType = getLoadableImageType(imageType);
1172
- let image;
1173
- switch (loadType) {
1174
- case "imagebitmap":
1175
- image = await parseToImageBitmap(arrayBuffer, options, url);
1176
- break;
1177
- case "image":
1178
- image = await parseToImage(arrayBuffer, options, url);
1179
- break;
1180
- case "data":
1181
- image = await parseToNodeImage(arrayBuffer, options);
1182
- break;
1183
- default:
1184
- assert(false);
1185
- }
1186
- if (imageType === "data") {
1187
- image = getImageData(image);
1077
+ // ../textures/src/lib/parsers/parse-basis.ts
1078
+ async function parseBasis(data, options) {
1079
+ if (options.basis.containerFormat === "auto") {
1080
+ if (isKTX(data)) {
1081
+ const fileConstructors = await loadBasisEncoderModule(options);
1082
+ return parseKTX2File(fileConstructors.KTX2File, data, options);
1083
+ }
1084
+ const { BasisFile } = await loadBasisTrascoderModule(options);
1085
+ return parseBasisFile(BasisFile, data, options);
1188
1086
  }
1189
- return image;
1190
- }
1191
- function getLoadableImageType(type) {
1192
- switch (type) {
1193
- case "auto":
1194
- case "data":
1195
- return getDefaultImageType();
1087
+ switch (options.basis.module) {
1088
+ case "encoder":
1089
+ const fileConstructors = await loadBasisEncoderModule(options);
1090
+ switch (options.basis.containerFormat) {
1091
+ case "ktx2":
1092
+ return parseKTX2File(fileConstructors.KTX2File, data, options);
1093
+ case "basis":
1094
+ default:
1095
+ return parseBasisFile(fileConstructors.BasisFile, data, options);
1096
+ }
1097
+ case "transcoder":
1196
1098
  default:
1197
- isImageTypeSupported(type);
1198
- return type;
1099
+ const { BasisFile } = await loadBasisTrascoderModule(options);
1100
+ return parseBasisFile(BasisFile, data, options);
1199
1101
  }
1200
1102
  }
1201
- var init_parse_image = __esm({
1202
- "../images/src/lib/parsers/parse-image.ts"() {
1203
- init_src2();
1204
- init_image_type();
1205
- init_parsed_image_api();
1206
- init_parse_to_image();
1207
- init_parse_to_image_bitmap();
1208
- init_parse_to_node_image();
1209
- }
1210
- });
1211
-
1212
- // ../images/src/image-loader.ts
1213
- var EXTENSIONS, MIME_TYPES, DEFAULT_IMAGE_LOADER_OPTIONS, ImageLoader;
1214
- var init_image_loader = __esm({
1215
- "../images/src/image-loader.ts"() {
1216
- init_version4();
1217
- init_parse_image();
1218
- init_binary_image_api();
1219
- EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
1220
- MIME_TYPES = [
1221
- "image/png",
1222
- "image/jpeg",
1223
- "image/gif",
1224
- "image/webp",
1225
- "image/avif",
1226
- "image/bmp",
1227
- "image/vnd.microsoft.icon",
1228
- "image/svg+xml"
1229
- ];
1230
- DEFAULT_IMAGE_LOADER_OPTIONS = {
1231
- image: {
1232
- type: "auto",
1233
- decode: true
1103
+ function parseBasisFile(BasisFile, data, options) {
1104
+ const basisFile = new BasisFile(new Uint8Array(data));
1105
+ try {
1106
+ if (!basisFile.startTranscoding()) {
1107
+ throw new Error("Failed to start basis transcoding");
1108
+ }
1109
+ const imageCount = basisFile.getNumImages();
1110
+ const images = [];
1111
+ for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
1112
+ const levelsCount = basisFile.getNumLevels(imageIndex);
1113
+ const levels = [];
1114
+ for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
1115
+ levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
1234
1116
  }
1235
- };
1236
- ImageLoader = {
1237
- id: "image",
1238
- module: "images",
1239
- name: "Images",
1240
- version: VERSION6,
1241
- mimeTypes: MIME_TYPES,
1242
- extensions: EXTENSIONS,
1243
- parse: parseImage,
1244
- tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
1245
- options: DEFAULT_IMAGE_LOADER_OPTIONS
1246
- };
1117
+ images.push(levels);
1118
+ }
1119
+ return images;
1120
+ } finally {
1121
+ basisFile.close();
1122
+ basisFile.delete();
1247
1123
  }
1248
- });
1249
-
1250
- // ../images/src/lib/category-api/image-format.ts
1251
- function isImageFormatSupported(mimeType) {
1252
- if (mimeTypeSupportedSync[mimeType] === void 0) {
1253
- const supported = isBrowser ? checkBrowserImageFormatSupport(mimeType) : checkNodeImageFormatSupport(mimeType);
1254
- mimeTypeSupportedSync[mimeType] = supported;
1124
+ }
1125
+ function transcodeImage(basisFile, imageIndex, levelIndex, options) {
1126
+ const width = basisFile.getImageWidth(imageIndex, levelIndex);
1127
+ const height = basisFile.getImageHeight(imageIndex, levelIndex);
1128
+ const hasAlpha = basisFile.getHasAlpha();
1129
+ const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha);
1130
+ const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
1131
+ const decodedData = new Uint8Array(decodedSize);
1132
+ if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
1133
+ throw new Error("failed to start Basis transcoding");
1255
1134
  }
1256
- return mimeTypeSupportedSync[mimeType];
1135
+ return {
1136
+ width,
1137
+ height,
1138
+ data: decodedData,
1139
+ compressed,
1140
+ format,
1141
+ hasAlpha
1142
+ };
1257
1143
  }
1258
- function checkNodeImageFormatSupport(mimeType) {
1259
- const NODE_FORMAT_SUPPORT = ["image/png", "image/jpeg", "image/gif"];
1260
- const { _parseImageNode: _parseImageNode2, _imageFormatsNode = NODE_FORMAT_SUPPORT } = globalThis;
1261
- return Boolean(_parseImageNode2) && _imageFormatsNode.includes(mimeType);
1144
+ function parseKTX2File(KTX2File, data, options) {
1145
+ const ktx2File = new KTX2File(new Uint8Array(data));
1146
+ try {
1147
+ if (!ktx2File.startTranscoding()) {
1148
+ throw new Error("failed to start KTX2 transcoding");
1149
+ }
1150
+ const levelsCount = ktx2File.getLevels();
1151
+ const levels = [];
1152
+ for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
1153
+ levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
1154
+ break;
1155
+ }
1156
+ return [levels];
1157
+ } finally {
1158
+ ktx2File.close();
1159
+ ktx2File.delete();
1160
+ }
1262
1161
  }
1263
- function checkBrowserImageFormatSupport(mimeType) {
1264
- switch (mimeType) {
1265
- case "image/avif":
1266
- case "image/webp":
1267
- return testBrowserImageFormatSupport(mimeType);
1268
- default:
1269
- return true;
1162
+ function transcodeKTX2Image(ktx2File, levelIndex, options) {
1163
+ const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
1164
+ const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag);
1165
+ const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0, 0, basisFormat);
1166
+ const decodedData = new Uint8Array(decodedSize);
1167
+ if (!ktx2File.transcodeImage(decodedData, levelIndex, 0, 0, basisFormat, 0, -1, -1)) {
1168
+ throw new Error("Failed to transcode KTX2 image");
1270
1169
  }
1170
+ return {
1171
+ width,
1172
+ height,
1173
+ data: decodedData,
1174
+ compressed,
1175
+ levelSize: decodedSize,
1176
+ hasAlpha: alphaFlag,
1177
+ format
1178
+ };
1271
1179
  }
1272
- function testBrowserImageFormatSupport(mimeType) {
1273
- try {
1274
- const element = document.createElement("canvas");
1275
- const dataURL = element.toDataURL(mimeType);
1276
- return dataURL.indexOf(`data:${mimeType}`) === 0;
1277
- } catch {
1278
- return false;
1180
+ function getBasisOptions(options, hasAlpha) {
1181
+ let format = options && options.basis && options.basis.format;
1182
+ if (format === "auto") {
1183
+ format = selectSupportedBasisFormat();
1184
+ }
1185
+ if (typeof format === "object") {
1186
+ format = hasAlpha ? format.alpha : format.noAlpha;
1187
+ }
1188
+ format = format.toLowerCase();
1189
+ return OutputFormat[format];
1190
+ }
1191
+ function selectSupportedBasisFormat() {
1192
+ const supportedFormats = getSupportedGPUTextureFormats();
1193
+ if (supportedFormats.has("astc")) {
1194
+ return "astc-4x4";
1195
+ } else if (supportedFormats.has("dxt")) {
1196
+ return {
1197
+ alpha: "bc3",
1198
+ noAlpha: "bc1"
1199
+ };
1200
+ } else if (supportedFormats.has("pvrtc")) {
1201
+ return {
1202
+ alpha: "pvrtc1-4-rgba",
1203
+ noAlpha: "pvrtc1-4-rgb"
1204
+ };
1205
+ } else if (supportedFormats.has("etc1")) {
1206
+ return "etc1";
1207
+ } else if (supportedFormats.has("etc2")) {
1208
+ return "etc2";
1279
1209
  }
1210
+ return "rgb565";
1280
1211
  }
1281
- var mimeTypeSupportedSync;
1282
- var init_image_format = __esm({
1283
- "../images/src/lib/category-api/image-format.ts"() {
1284
- init_src2();
1285
- mimeTypeSupportedSync = {};
1212
+ var OutputFormat;
1213
+ var init_parse_basis = __esm({
1214
+ "../textures/src/lib/parsers/parse-basis.ts"() {
1215
+ init_basis_module_loader();
1216
+ init_gl_extensions();
1217
+ init_texture_formats();
1218
+ init_parse_ktx();
1219
+ OutputFormat = {
1220
+ etc1: {
1221
+ basisFormat: 0,
1222
+ compressed: true,
1223
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
1224
+ },
1225
+ etc2: { basisFormat: 1, compressed: true },
1226
+ bc1: {
1227
+ basisFormat: 2,
1228
+ compressed: true,
1229
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
1230
+ },
1231
+ bc3: {
1232
+ basisFormat: 3,
1233
+ compressed: true,
1234
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
1235
+ },
1236
+ bc4: { basisFormat: 4, compressed: true },
1237
+ bc5: { basisFormat: 5, compressed: true },
1238
+ "bc7-m6-opaque-only": { basisFormat: 6, compressed: true },
1239
+ "bc7-m5": { basisFormat: 7, compressed: true },
1240
+ "pvrtc1-4-rgb": {
1241
+ basisFormat: 8,
1242
+ compressed: true,
1243
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
1244
+ },
1245
+ "pvrtc1-4-rgba": {
1246
+ basisFormat: 9,
1247
+ compressed: true,
1248
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
1249
+ },
1250
+ "astc-4x4": {
1251
+ basisFormat: 10,
1252
+ compressed: true,
1253
+ format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
1254
+ },
1255
+ "atc-rgb": { basisFormat: 11, compressed: true },
1256
+ "atc-rgba-interpolated-alpha": { basisFormat: 12, compressed: true },
1257
+ rgba32: { basisFormat: 13, compressed: false },
1258
+ rgb565: { basisFormat: 14, compressed: false },
1259
+ bgr565: { basisFormat: 15, compressed: false },
1260
+ rgba4444: { basisFormat: 16, compressed: false }
1261
+ };
1286
1262
  }
1287
1263
  });
1288
1264
 
1289
- // ../images/src/index.ts
1290
- var init_src3 = __esm({
1291
- "../images/src/index.ts"() {
1292
- init_image_loader();
1293
- init_binary_image_api();
1294
- init_image_format();
1265
+ // ../textures/src/basis-loader.ts
1266
+ var BasisWorkerLoader, BasisLoader;
1267
+ var init_basis_loader = __esm({
1268
+ "../textures/src/basis-loader.ts"() {
1269
+ init_version4();
1270
+ init_parse_basis();
1271
+ BasisWorkerLoader = {
1272
+ name: "Basis",
1273
+ id: "basis",
1274
+ module: "textures",
1275
+ version: VERSION5,
1276
+ worker: true,
1277
+ extensions: ["basis", "ktx2"],
1278
+ mimeTypes: ["application/octet-stream", "image/ktx2"],
1279
+ tests: ["sB"],
1280
+ binary: true,
1281
+ options: {
1282
+ basis: {
1283
+ format: "auto",
1284
+ libraryPath: "libs/",
1285
+ containerFormat: "auto",
1286
+ module: "transcoder"
1287
+ }
1288
+ }
1289
+ };
1290
+ BasisLoader = {
1291
+ ...BasisWorkerLoader,
1292
+ parse: parseBasis
1293
+ };
1295
1294
  }
1296
1295
  });
1297
1296
 
@@ -1314,6 +1313,119 @@
1314
1313
  }
1315
1314
  });
1316
1315
 
1316
+ // src/lib/parsers/parse-glb.ts
1317
+ function getMagicString2(dataView, byteOffset = 0) {
1318
+ return `${String.fromCharCode(dataView.getUint8(byteOffset + 0))}${String.fromCharCode(dataView.getUint8(byteOffset + 1))}${String.fromCharCode(dataView.getUint8(byteOffset + 2))}${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
1319
+ }
1320
+ function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
1321
+ const dataView = new DataView(arrayBuffer);
1322
+ const { magic = MAGIC_glTF } = options;
1323
+ const magic1 = dataView.getUint32(byteOffset, false);
1324
+ return magic1 === magic || magic1 === MAGIC_glTF;
1325
+ }
1326
+ function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
1327
+ const dataView = new DataView(arrayBuffer);
1328
+ const type = getMagicString2(dataView, byteOffset + 0);
1329
+ const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN2);
1330
+ const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN2);
1331
+ Object.assign(glb, {
1332
+ header: {
1333
+ byteOffset,
1334
+ byteLength,
1335
+ hasBinChunk: false
1336
+ },
1337
+ type,
1338
+ version,
1339
+ json: {},
1340
+ binChunks: []
1341
+ });
1342
+ byteOffset += GLB_FILE_HEADER_SIZE;
1343
+ switch (glb.version) {
1344
+ case 1:
1345
+ return parseGLBV1(glb, dataView, byteOffset);
1346
+ case 2:
1347
+ return parseGLBV2(glb, dataView, byteOffset, options = {});
1348
+ default:
1349
+ throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`);
1350
+ }
1351
+ }
1352
+ function parseGLBV1(glb, dataView, byteOffset) {
1353
+ assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
1354
+ const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN2);
1355
+ const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN2);
1356
+ byteOffset += GLB_CHUNK_HEADER_SIZE;
1357
+ assert(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
1358
+ parseJSONChunk(glb, dataView, byteOffset, contentLength);
1359
+ byteOffset += contentLength;
1360
+ byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
1361
+ return byteOffset;
1362
+ }
1363
+ function parseGLBV2(glb, dataView, byteOffset, options) {
1364
+ assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
1365
+ parseGLBChunksSync(glb, dataView, byteOffset, options);
1366
+ return byteOffset + glb.header.byteLength;
1367
+ }
1368
+ function parseGLBChunksSync(glb, dataView, byteOffset, options) {
1369
+ while (byteOffset + 8 <= glb.header.byteLength) {
1370
+ const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN2);
1371
+ const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN2);
1372
+ byteOffset += GLB_CHUNK_HEADER_SIZE;
1373
+ switch (chunkFormat) {
1374
+ case GLB_CHUNK_TYPE_JSON:
1375
+ parseJSONChunk(glb, dataView, byteOffset, chunkLength);
1376
+ break;
1377
+ case GLB_CHUNK_TYPE_BIN:
1378
+ parseBINChunk(glb, dataView, byteOffset, chunkLength);
1379
+ break;
1380
+ case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
1381
+ if (!options.strict) {
1382
+ parseJSONChunk(glb, dataView, byteOffset, chunkLength);
1383
+ }
1384
+ break;
1385
+ case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:
1386
+ if (!options.strict) {
1387
+ parseBINChunk(glb, dataView, byteOffset, chunkLength);
1388
+ }
1389
+ break;
1390
+ default:
1391
+ break;
1392
+ }
1393
+ byteOffset += padToNBytes(chunkLength, 4);
1394
+ }
1395
+ return byteOffset;
1396
+ }
1397
+ function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
1398
+ const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
1399
+ const textDecoder = new TextDecoder("utf8");
1400
+ const jsonText = textDecoder.decode(jsonChunk);
1401
+ glb.json = JSON.parse(jsonText);
1402
+ return padToNBytes(chunkLength, 4);
1403
+ }
1404
+ function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
1405
+ glb.header.hasBinChunk = true;
1406
+ glb.binChunks.push({
1407
+ byteOffset,
1408
+ byteLength: chunkLength,
1409
+ arrayBuffer: dataView.buffer
1410
+ });
1411
+ return padToNBytes(chunkLength, 4);
1412
+ }
1413
+ var LITTLE_ENDIAN2, MAGIC_glTF, GLB_FILE_HEADER_SIZE, GLB_CHUNK_HEADER_SIZE, GLB_CHUNK_TYPE_JSON, GLB_CHUNK_TYPE_BIN, GLB_V1_CONTENT_FORMAT_JSON, GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED, GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED;
1414
+ var init_parse_glb = __esm({
1415
+ "src/lib/parsers/parse-glb.ts"() {
1416
+ init_src2();
1417
+ LITTLE_ENDIAN2 = true;
1418
+ MAGIC_glTF = 1735152710;
1419
+ GLB_FILE_HEADER_SIZE = 12;
1420
+ GLB_CHUNK_HEADER_SIZE = 8;
1421
+ GLB_CHUNK_TYPE_JSON = 1313821514;
1422
+ GLB_CHUNK_TYPE_BIN = 5130562;
1423
+ GLB_V1_CONTENT_FORMAT_JSON = 0;
1424
+ GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
1425
+ GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
1426
+ }
1427
+ });
1428
+
1317
1429
  // src/lib/gltf-utils/resolve-url.ts
1318
1430
  function resolveUrl(url, options) {
1319
1431
  const absolute = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:");
@@ -1368,10 +1480,24 @@
1368
1480
  assert3(byteLength >= 0 && byteLength <= bufferView.byteLength);
1369
1481
  return { ArrayType, length, byteLength };
1370
1482
  }
1371
- var TYPES, ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT, ARRAY_TO_COMPONENT_TYPE, ATTRIBUTE_TYPE_TO_COMPONENTS, ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE, ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY;
1483
+ function getMemoryUsageGLTF(gltf) {
1484
+ let { images, bufferViews } = gltf;
1485
+ images = images || [];
1486
+ bufferViews = bufferViews || [];
1487
+ const imageBufferViews = images.map((i2) => i2.bufferView);
1488
+ bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view));
1489
+ const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
1490
+ const pixelCount = images.reduce((acc, image) => {
1491
+ const { width, height } = image.image;
1492
+ return acc + width * height;
1493
+ }, 0);
1494
+ return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);
1495
+ }
1496
+ var MIPMAP_FACTOR, TYPES, ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT, ARRAY_TO_COMPONENT_TYPE, ATTRIBUTE_TYPE_TO_COMPONENTS, ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE, ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY;
1372
1497
  var init_gltf_utils = __esm({
1373
1498
  "src/lib/gltf-utils/gltf-utils.ts"() {
1374
1499
  init_assert3();
1500
+ MIPMAP_FACTOR = 1.33;
1375
1501
  TYPES = ["SCALAR", "VEC2", "VEC3", "VEC4"];
1376
1502
  ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
1377
1503
  [Int8Array, 5120],
@@ -1412,25 +1538,31 @@
1412
1538
  });
1413
1539
 
1414
1540
  // src/lib/api/gltf-scenegraph.ts
1415
- var DEFAULT_GLTF_JSON, GLTFScenegraph;
1541
+ function makeDefaultGLTFJson() {
1542
+ return {
1543
+ asset: {
1544
+ version: "2.0",
1545
+ generator: "loaders.gl"
1546
+ },
1547
+ buffers: [],
1548
+ extensions: {},
1549
+ extensionsRequired: [],
1550
+ extensionsUsed: []
1551
+ };
1552
+ }
1553
+ var GLTFScenegraph;
1416
1554
  var init_gltf_scenegraph = __esm({
1417
1555
  "src/lib/api/gltf-scenegraph.ts"() {
1418
1556
  init_src3();
1419
1557
  init_src2();
1420
1558
  init_assert3();
1421
1559
  init_gltf_utils();
1422
- DEFAULT_GLTF_JSON = {
1423
- asset: {
1424
- version: "2.0",
1425
- generator: "loaders.gl"
1426
- },
1427
- buffers: []
1428
- };
1429
1560
  GLTFScenegraph = class {
1430
1561
  constructor(gltf) {
1431
- this.gltf = gltf || {
1432
- json: { ...DEFAULT_GLTF_JSON },
1433
- buffers: []
1562
+ this.gltf = {
1563
+ json: gltf?.json || makeDefaultGLTFJson(),
1564
+ buffers: gltf?.buffers || [],
1565
+ images: gltf?.images || []
1434
1566
  };
1435
1567
  this.sourceBuffers = [];
1436
1568
  this.byteLength = 0;
@@ -1450,10 +1582,15 @@
1450
1582
  const extras = this.json.extras || {};
1451
1583
  return extras[key];
1452
1584
  }
1585
+ hasExtension(extensionName) {
1586
+ const isUsedExtension = this.getUsedExtensions().find((name10) => name10 === extensionName);
1587
+ const isRequiredExtension = this.getRequiredExtensions().find((name10) => name10 === extensionName);
1588
+ return typeof isUsedExtension === "string" || typeof isRequiredExtension === "string";
1589
+ }
1453
1590
  getExtension(extensionName) {
1454
1591
  const isExtension = this.getUsedExtensions().find((name10) => name10 === extensionName);
1455
1592
  const extensions = this.json.extensions || {};
1456
- return isExtension ? extensions[extensionName] || true : null;
1593
+ return isExtension ? extensions[extensionName] : null;
1457
1594
  }
1458
1595
  getRequiredExtension(extensionName) {
1459
1596
  const isRequired = this.getRequiredExtensions().find((name10) => name10 === extensionName);
@@ -1560,10 +1697,15 @@
1560
1697
  extensions[extensionName] = data;
1561
1698
  }
1562
1699
  removeObjectExtension(object, extensionName) {
1563
- const extensions = object.extensions || {};
1564
- const extension = extensions[extensionName];
1700
+ const extensions = object?.extensions || {};
1701
+ if (extensions[extensionName]) {
1702
+ this.json.extensionsRemoved = this.json.extensionsRemoved || [];
1703
+ const extensionsRemoved = this.json.extensionsRemoved;
1704
+ if (!extensionsRemoved.includes(extensionName)) {
1705
+ extensionsRemoved.push(extensionName);
1706
+ }
1707
+ }
1565
1708
  delete extensions[extensionName];
1566
- return extension;
1567
1709
  }
1568
1710
  addExtension(extensionName, extensionData = {}) {
1569
1711
  assert3(extensionData);
@@ -1592,8 +1734,15 @@
1592
1734
  }
1593
1735
  }
1594
1736
  removeExtension(extensionName) {
1595
- if (!this.getExtension(extensionName)) {
1596
- return;
1737
+ if (this.json.extensions?.[extensionName]) {
1738
+ this.json.extensionsRemoved = this.json.extensionsRemoved || [];
1739
+ const extensionsRemoved = this.json.extensionsRemoved;
1740
+ if (!extensionsRemoved.includes(extensionName)) {
1741
+ extensionsRemoved.push(extensionName);
1742
+ }
1743
+ }
1744
+ if (this.json.extensions) {
1745
+ delete this.json.extensions[extensionName];
1597
1746
  }
1598
1747
  if (this.json.extensionsRequired) {
1599
1748
  this._removeStringFromArray(this.json.extensionsRequired, extensionName);
@@ -1601,16 +1750,6 @@
1601
1750
  if (this.json.extensionsUsed) {
1602
1751
  this._removeStringFromArray(this.json.extensionsUsed, extensionName);
1603
1752
  }
1604
- if (this.json.extensions) {
1605
- delete this.json.extensions[extensionName];
1606
- }
1607
- if (!Array.isArray(this.json.extensionsRemoved)) {
1608
- this.json.extensionsRemoved = [];
1609
- }
1610
- const extensionsRemoved = this.json.extensionsRemoved;
1611
- if (!extensionsRemoved.includes(extensionName)) {
1612
- extensionsRemoved.push(extensionName);
1613
- }
1614
1753
  }
1615
1754
  setDefaultScene(sceneIndex) {
1616
1755
  this.json.scene = sceneIndex;
@@ -1679,14 +1818,14 @@
1679
1818
  this.json.images.push(glTFImage);
1680
1819
  return this.json.images.length - 1;
1681
1820
  }
1682
- addBufferView(buffer) {
1821
+ addBufferView(buffer, bufferIndex = 0, byteOffset = this.byteLength) {
1683
1822
  const byteLength = buffer.byteLength;
1684
1823
  assert3(Number.isFinite(byteLength));
1685
1824
  this.sourceBuffers = this.sourceBuffers || [];
1686
1825
  this.sourceBuffers.push(buffer);
1687
1826
  const glTFBufferView = {
1688
- buffer: 0,
1689
- byteOffset: this.byteLength,
1827
+ buffer: bufferIndex,
1828
+ byteOffset,
1690
1829
  byteLength
1691
1830
  };
1692
1831
  this.byteLength += padToNBytes(byteLength, 4);
@@ -2045,9 +2184,8 @@
2045
2184
  const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
2046
2185
  const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength);
2047
2186
  await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);
2048
- return result;
2187
+ scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
2049
2188
  }
2050
- return null;
2051
2189
  }
2052
2190
  var EXT_MESHOPT_COMPRESSION, name;
2053
2191
  var init_EXT_meshopt_compression = __esm({
@@ -2106,8 +2244,8 @@
2106
2244
  const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
2107
2245
  if (extension) {
2108
2246
  texture.source = extension.source;
2247
+ scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
2109
2248
  }
2110
- scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
2111
2249
  }
2112
2250
  scene.removeExtension(KHR_TEXTURE_BASISU);
2113
2251
  }
@@ -2132,7 +2270,6 @@
2132
2270
  var DEFAULT_DRACO_OPTIONS, DracoLoader;
2133
2271
  var init_draco_loader = __esm({
2134
2272
  "../draco/src/draco-loader.ts"() {
2135
- init_src();
2136
2273
  init_version5();
2137
2274
  DEFAULT_DRACO_OPTIONS = {
2138
2275
  draco: {
@@ -2144,7 +2281,7 @@
2144
2281
  };
2145
2282
  DracoLoader = {
2146
2283
  name: "Draco",
2147
- id: isBrowser2 ? "draco" : "draco-nodejs",
2284
+ id: "draco",
2148
2285
  module: "draco",
2149
2286
  version: VERSION7,
2150
2287
  worker: true,
@@ -2843,6 +2980,7 @@
2843
2980
  if (decodedData.indices) {
2844
2981
  primitive.indices = getGLTFAccessor(decodedData.indices);
2845
2982
  }
2983
+ scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
2846
2984
  checkPrimitive(primitive);
2847
2985
  }
2848
2986
  function compressMesh(attributes, indices, mode = 4, options, context) {
@@ -4082,8 +4220,8 @@
4082
4220
  });
4083
4221
  async function decode4(gltfData, options) {
4084
4222
  const gltfScenegraph = new GLTFScenegraph(gltfData);
4085
- const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);
4086
- if (!extension) {
4223
+ const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
4224
+ if (!hasExtension) {
4087
4225
  return;
4088
4226
  }
4089
4227
  const materials = gltfData.json.materials || [];
@@ -4217,10 +4355,10 @@
4217
4355
  }
4218
4356
  function makeTransformationMatrix(extensionData) {
4219
4357
  const { offset = [0, 0], rotation = 0, scale: scale2 = [1, 1] } = extensionData;
4220
- const translationMatirx = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
4221
- const rotationMatirx = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
4358
+ const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
4359
+ const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
4222
4360
  const scaleMatrix = scratchScaleMatrix.set(scale2[0], 0, 0, 0, scale2[1], 0, 0, 0, 1);
4223
- return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);
4361
+ return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
4224
4362
  }
4225
4363
  var EXT_MESHOPT_TRANSFORM, name5, scratchVector, scratchRotationMatrix, scratchScaleMatrix;
4226
4364
  var init_KHR_texture_transform = __esm({
@@ -4402,18 +4540,16 @@
4402
4540
  decode: () => decode8,
4403
4541
  name: () => name9
4404
4542
  });
4405
- async function decode8(gltfData) {
4543
+ async function decode8(gltfData, options) {
4406
4544
  const scenegraph = new GLTFScenegraph(gltfData);
4407
- decodeExtFeatureMetadata(scenegraph);
4545
+ decodeExtFeatureMetadata(scenegraph, options);
4408
4546
  }
4409
- function decodeExtFeatureMetadata(scenegraph) {
4547
+ function decodeExtFeatureMetadata(scenegraph, options) {
4410
4548
  const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
4411
- const schemaClasses = extension?.schema?.classes;
4412
- const featureTables = extension?.featureTables;
4413
- const featureTextures = extension?.featureTextures;
4414
- if (featureTextures) {
4415
- console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
4416
- }
4549
+ if (!extension)
4550
+ return;
4551
+ const schemaClasses = extension.schema?.classes;
4552
+ const { featureTables } = extension;
4417
4553
  if (schemaClasses && featureTables) {
4418
4554
  for (const schemaName in schemaClasses) {
4419
4555
  const schemaClass = schemaClasses[schemaName];
@@ -4423,6 +4559,16 @@
4423
4559
  }
4424
4560
  }
4425
4561
  }
4562
+ const { featureTextures } = extension;
4563
+ if (schemaClasses && featureTextures && options.gltf?.loadImages) {
4564
+ for (const schemaName in schemaClasses) {
4565
+ const schemaClass = schemaClasses[schemaName];
4566
+ const featureTexture = findFeatureTextureByName(featureTextures, schemaName);
4567
+ if (featureTexture) {
4568
+ handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
4569
+ }
4570
+ }
4571
+ }
4426
4572
  }
4427
4573
  function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
4428
4574
  for (const propertyName in schemaClass.properties) {
@@ -4435,23 +4581,141 @@
4435
4581
  }
4436
4582
  }
4437
4583
  }
4584
+ function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
4585
+ const attributeName = featureTexture.class;
4586
+ for (const propertyName in schemaClass.properties) {
4587
+ const featureTextureProperty = featureTexture?.properties?.[propertyName];
4588
+ if (featureTextureProperty) {
4589
+ const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
4590
+ featureTextureProperty.data = data;
4591
+ }
4592
+ }
4593
+ }
4438
4594
  function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
4439
4595
  const bufferView = featureTableProperty.bufferView;
4440
- let data = scenegraph.getTypedArrayForBufferView(bufferView);
4596
+ const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
4441
4597
  switch (schemaProperty.type) {
4442
4598
  case "STRING": {
4443
4599
  const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
4444
4600
  const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
4445
- data = getStringAttributes(data, offsetsData, numberOfFeatures);
4446
- break;
4601
+ return getStringAttributes(dataArray, offsetsData, numberOfFeatures);
4602
+ }
4603
+ default:
4604
+ }
4605
+ return dataArray;
4606
+ }
4607
+ function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
4608
+ const json = scenegraph.gltf.json;
4609
+ if (!json.meshes) {
4610
+ return [];
4611
+ }
4612
+ const featureTextureTable = [];
4613
+ for (const mesh of json.meshes) {
4614
+ for (const primitive of mesh.primitives) {
4615
+ processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
4616
+ }
4617
+ }
4618
+ return featureTextureTable;
4619
+ }
4620
+ function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
4621
+ const json = scenegraph.gltf.json;
4622
+ const textureData = [];
4623
+ const texCoordAccessorKey = `TEXCOORD_${featureTextureProperty.texture.texCoord}`;
4624
+ const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
4625
+ const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
4626
+ const texCoordArray = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
4627
+ const textureCoordinates = new Float32Array(texCoordArray.buffer, texCoordArray.byteOffset, texCoordArray.length / 4);
4628
+ const textureIndex = featureTextureProperty.texture.index;
4629
+ const texture = json.textures?.[textureIndex];
4630
+ const imageIndex = texture?.source;
4631
+ if (typeof imageIndex !== "undefined") {
4632
+ const image = json.images?.[imageIndex];
4633
+ const mimeType = image?.mimeType;
4634
+ const parsedImage = scenegraph.gltf.images?.[imageIndex];
4635
+ if (parsedImage) {
4636
+ for (let index = 0; index < textureCoordinates.length; index += 2) {
4637
+ const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, featureTextureProperty.channels);
4638
+ textureData.push(value);
4639
+ }
4640
+ }
4641
+ }
4642
+ const featureIndices = [];
4643
+ for (const texelData of textureData) {
4644
+ let index = featureTextureTable.findIndex((item) => item === texelData);
4645
+ if (index === -1) {
4646
+ index = featureTextureTable.push(texelData) - 1;
4647
+ }
4648
+ featureIndices.push(index);
4649
+ }
4650
+ const typedArray = new Uint32Array(featureIndices);
4651
+ const bufferIndex = scenegraph.gltf.buffers.push({
4652
+ arrayBuffer: typedArray.buffer,
4653
+ byteOffset: 0,
4654
+ byteLength: typedArray.byteLength
4655
+ }) - 1;
4656
+ const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
4657
+ const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
4658
+ size: 1,
4659
+ componentType: getComponentTypeFromArray(typedArray),
4660
+ count: typedArray.length
4661
+ });
4662
+ primitive.attributes[attributeName] = accessorIndex;
4663
+ }
4664
+ function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels) {
4665
+ const CHANNELS_MAP = {
4666
+ r: { offset: 0, shift: 0 },
4667
+ g: { offset: 1, shift: 8 },
4668
+ b: { offset: 2, shift: 16 },
4669
+ a: { offset: 3, shift: 24 }
4670
+ };
4671
+ const u = textureCoordinates[index];
4672
+ const v = textureCoordinates[index + 1];
4673
+ let components = 1;
4674
+ if (mimeType && (mimeType.indexOf("image/jpeg") !== -1 || mimeType.indexOf("image/png") !== -1))
4675
+ components = 4;
4676
+ const offset = coordinatesToOffset(u, v, parsedImage, components);
4677
+ let value = 0;
4678
+ for (const c of channels) {
4679
+ const map = CHANNELS_MAP[c];
4680
+ const val = getVal(parsedImage, offset + map.offset);
4681
+ value |= val << map.shift;
4682
+ }
4683
+ return value;
4684
+ }
4685
+ function getVal(parsedImage, offset) {
4686
+ const imageData = getImageData(parsedImage);
4687
+ if (imageData.data.length <= offset) {
4688
+ throw new Error(`${imageData.data.length} <= ${offset}`);
4689
+ }
4690
+ return imageData.data[offset];
4691
+ }
4692
+ function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) {
4693
+ const w = parsedImage.width;
4694
+ const iX = emod(u) * (w - 1);
4695
+ const indX = Math.round(iX);
4696
+ const h = parsedImage.height;
4697
+ const iY = emod(v) * (h - 1);
4698
+ const indY = Math.round(iY);
4699
+ const components = parsedImage.components ? parsedImage.components : componentsCount;
4700
+ const offset = (indY * w + indX) * components;
4701
+ return offset;
4702
+ }
4703
+ function emod(n2) {
4704
+ const a2 = (n2 % 1 + 1) % 1;
4705
+ return a2;
4706
+ }
4707
+ function findFeatureTableByName(featureTables, schemaClassName) {
4708
+ for (const featureTableName in featureTables) {
4709
+ const featureTable = featureTables[featureTableName];
4710
+ if (featureTable.class === schemaClassName) {
4711
+ return featureTable;
4447
4712
  }
4448
- default:
4449
4713
  }
4450
- return data;
4714
+ return null;
4451
4715
  }
4452
- function findFeatureTableByName(featureTables, schemaClassName) {
4453
- for (const featureTableName in featureTables) {
4454
- const featureTable = featureTables[featureTableName];
4716
+ function findFeatureTextureByName(featureTextures, schemaClassName) {
4717
+ for (const featureTexturesName in featureTextures) {
4718
+ const featureTable = featureTextures[featureTexturesName];
4455
4719
  if (featureTable.class === schemaClassName) {
4456
4720
  return featureTable;
4457
4721
  }
@@ -4476,6 +4740,8 @@
4476
4740
  var init_EXT_feature_metadata = __esm({
4477
4741
  "src/lib/extensions/deprecated/EXT_feature_metadata.ts"() {
4478
4742
  init_gltf_scenegraph();
4743
+ init_src3();
4744
+ init_gltf_utils();
4479
4745
  EXT_FEATURE_METADATA = "EXT_feature_metadata";
4480
4746
  name9 = EXT_FEATURE_METADATA;
4481
4747
  }
@@ -4627,560 +4893,125 @@
4627
4893
  this._updateMaterial(json);
4628
4894
  }
4629
4895
  _addAsset(json) {
4630
- json.asset = json.asset || {};
4631
- json.asset.version = "2.0";
4632
- json.asset.generator = json.asset.generator || "Normalized to glTF 2.0 by loaders.gl";
4633
- }
4634
- _convertTopLevelObjectsToArrays(json) {
4635
- for (const arrayName in GLTF_ARRAYS) {
4636
- this._convertTopLevelObjectToArray(json, arrayName);
4637
- }
4638
- }
4639
- _convertTopLevelObjectToArray(json, mapName) {
4640
- const objectMap = json[mapName];
4641
- if (!objectMap || Array.isArray(objectMap)) {
4642
- return;
4643
- }
4644
- json[mapName] = [];
4645
- for (const id in objectMap) {
4646
- const object = objectMap[id];
4647
- object.id = object.id || id;
4648
- const index = json[mapName].length;
4649
- json[mapName].push(object);
4650
- this.idToIndexMap[mapName][id] = index;
4651
- }
4652
- }
4653
- _convertObjectIdsToArrayIndices(json) {
4654
- for (const arrayName in GLTF_ARRAYS) {
4655
- this._convertIdsToIndices(json, arrayName);
4656
- }
4657
- if ("scene" in json) {
4658
- json.scene = this._convertIdToIndex(json.scene, "scene");
4659
- }
4660
- for (const texture of json.textures) {
4661
- this._convertTextureIds(texture);
4662
- }
4663
- for (const mesh of json.meshes) {
4664
- this._convertMeshIds(mesh);
4665
- }
4666
- for (const node2 of json.nodes) {
4667
- this._convertNodeIds(node2);
4668
- }
4669
- for (const node2 of json.scenes) {
4670
- this._convertSceneIds(node2);
4671
- }
4672
- }
4673
- _convertTextureIds(texture) {
4674
- if (texture.source) {
4675
- texture.source = this._convertIdToIndex(texture.source, "image");
4676
- }
4677
- }
4678
- _convertMeshIds(mesh) {
4679
- for (const primitive of mesh.primitives) {
4680
- const { attributes, indices, material } = primitive;
4681
- for (const attributeName in attributes) {
4682
- attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], "accessor");
4683
- }
4684
- if (indices) {
4685
- primitive.indices = this._convertIdToIndex(indices, "accessor");
4686
- }
4687
- if (material) {
4688
- primitive.material = this._convertIdToIndex(material, "material");
4689
- }
4690
- }
4691
- }
4692
- _convertNodeIds(node2) {
4693
- if (node2.children) {
4694
- node2.children = node2.children.map((child) => this._convertIdToIndex(child, "node"));
4695
- }
4696
- if (node2.meshes) {
4697
- node2.meshes = node2.meshes.map((mesh) => this._convertIdToIndex(mesh, "mesh"));
4698
- }
4699
- }
4700
- _convertSceneIds(scene) {
4701
- if (scene.nodes) {
4702
- scene.nodes = scene.nodes.map((node2) => this._convertIdToIndex(node2, "node"));
4703
- }
4704
- }
4705
- _convertIdsToIndices(json, topLevelArrayName) {
4706
- if (!json[topLevelArrayName]) {
4707
- console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`);
4708
- json[topLevelArrayName] = [];
4709
- }
4710
- for (const object of json[topLevelArrayName]) {
4711
- for (const key in object) {
4712
- const id = object[key];
4713
- const index = this._convertIdToIndex(id, key);
4714
- object[key] = index;
4715
- }
4716
- }
4717
- }
4718
- _convertIdToIndex(id, key) {
4719
- const arrayName = GLTF_KEYS[key];
4720
- if (arrayName in this.idToIndexMap) {
4721
- const index = this.idToIndexMap[arrayName][id];
4722
- if (!Number.isFinite(index)) {
4723
- throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);
4724
- }
4725
- return index;
4726
- }
4727
- return id;
4728
- }
4729
- _updateObjects(json) {
4730
- for (const buffer of this.json.buffers) {
4731
- delete buffer.type;
4732
- }
4733
- }
4734
- _updateMaterial(json) {
4735
- for (const material of json.materials) {
4736
- material.pbrMetallicRoughness = {
4737
- baseColorFactor: [1, 1, 1, 1],
4738
- metallicFactor: 1,
4739
- roughnessFactor: 1
4740
- };
4741
- const textureId = material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;
4742
- const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);
4743
- if (textureIndex !== -1) {
4744
- material.pbrMetallicRoughness.baseColorTexture = { index: textureIndex };
4745
- }
4746
- }
4747
- }
4748
- };
4749
- }
4750
- });
4751
-
4752
- // src/lib/api/post-process-gltf.ts
4753
- function getBytesFromComponentType(componentType) {
4754
- return BYTES2[componentType];
4755
- }
4756
- function getSizeFromAccessorType(type) {
4757
- return COMPONENTS2[type];
4758
- }
4759
- function postProcessGLTF(gltf, options) {
4760
- return new GLTFPostProcessor().postProcess(gltf, options);
4761
- }
4762
- var COMPONENTS2, BYTES2, GL_SAMPLER, SAMPLER_PARAMETER_GLTF_TO_GL, DEFAULT_SAMPLER, GLTFPostProcessor;
4763
- var init_post_process_gltf = __esm({
4764
- "src/lib/api/post-process-gltf.ts"() {
4765
- init_assert3();
4766
- init_gltf_utils();
4767
- COMPONENTS2 = {
4768
- SCALAR: 1,
4769
- VEC2: 2,
4770
- VEC3: 3,
4771
- VEC4: 4,
4772
- MAT2: 4,
4773
- MAT3: 9,
4774
- MAT4: 16
4775
- };
4776
- BYTES2 = {
4777
- 5120: 1,
4778
- 5121: 1,
4779
- 5122: 2,
4780
- 5123: 2,
4781
- 5125: 4,
4782
- 5126: 4
4783
- };
4784
- GL_SAMPLER = {
4785
- TEXTURE_MAG_FILTER: 10240,
4786
- TEXTURE_MIN_FILTER: 10241,
4787
- TEXTURE_WRAP_S: 10242,
4788
- TEXTURE_WRAP_T: 10243,
4789
- REPEAT: 10497,
4790
- LINEAR: 9729,
4791
- NEAREST_MIPMAP_LINEAR: 9986
4792
- };
4793
- SAMPLER_PARAMETER_GLTF_TO_GL = {
4794
- magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
4795
- minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
4796
- wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
4797
- wrapT: GL_SAMPLER.TEXTURE_WRAP_T
4798
- };
4799
- DEFAULT_SAMPLER = {
4800
- [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
4801
- [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
4802
- [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
4803
- [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
4804
- };
4805
- GLTFPostProcessor = class {
4806
- constructor() {
4807
- this.baseUri = "";
4808
- this.json = {};
4809
- this.buffers = [];
4810
- this.images = [];
4811
- }
4812
- postProcess(gltf, options = {}) {
4813
- const { json, buffers = [], images = [], baseUri = "" } = gltf;
4814
- assert3(json);
4815
- this.baseUri = baseUri;
4816
- this.json = json;
4817
- this.buffers = buffers;
4818
- this.images = images;
4819
- this._resolveTree(this.json, options);
4820
- return this.json;
4821
- }
4822
- _resolveTree(json, options = {}) {
4823
- if (json.bufferViews) {
4824
- json.bufferViews = json.bufferViews.map((bufView, i2) => this._resolveBufferView(bufView, i2));
4825
- }
4826
- if (json.images) {
4827
- json.images = json.images.map((image, i2) => this._resolveImage(image, i2));
4828
- }
4829
- if (json.samplers) {
4830
- json.samplers = json.samplers.map((sampler, i2) => this._resolveSampler(sampler, i2));
4831
- }
4832
- if (json.textures) {
4833
- json.textures = json.textures.map((texture, i2) => this._resolveTexture(texture, i2));
4834
- }
4835
- if (json.accessors) {
4836
- json.accessors = json.accessors.map((accessor, i2) => this._resolveAccessor(accessor, i2));
4837
- }
4838
- if (json.materials) {
4839
- json.materials = json.materials.map((material, i2) => this._resolveMaterial(material, i2));
4840
- }
4841
- if (json.meshes) {
4842
- json.meshes = json.meshes.map((mesh, i2) => this._resolveMesh(mesh, i2));
4843
- }
4844
- if (json.nodes) {
4845
- json.nodes = json.nodes.map((node2, i2) => this._resolveNode(node2, i2));
4846
- }
4847
- if (json.skins) {
4848
- json.skins = json.skins.map((skin, i2) => this._resolveSkin(skin, i2));
4849
- }
4850
- if (json.scenes) {
4851
- json.scenes = json.scenes.map((scene, i2) => this._resolveScene(scene, i2));
4852
- }
4853
- if (json.scene !== void 0) {
4854
- json.scene = json.scenes[this.json.scene];
4855
- }
4856
- }
4857
- getScene(index) {
4858
- return this._get("scenes", index);
4859
- }
4860
- getNode(index) {
4861
- return this._get("nodes", index);
4862
- }
4863
- getSkin(index) {
4864
- return this._get("skins", index);
4865
- }
4866
- getMesh(index) {
4867
- return this._get("meshes", index);
4868
- }
4869
- getMaterial(index) {
4870
- return this._get("materials", index);
4871
- }
4872
- getAccessor(index) {
4873
- return this._get("accessors", index);
4874
- }
4875
- getCamera(index) {
4876
- return null;
4877
- }
4878
- getTexture(index) {
4879
- return this._get("textures", index);
4880
- }
4881
- getSampler(index) {
4882
- return this._get("samplers", index);
4883
- }
4884
- getImage(index) {
4885
- return this._get("images", index);
4886
- }
4887
- getBufferView(index) {
4888
- return this._get("bufferViews", index);
4889
- }
4890
- getBuffer(index) {
4891
- return this._get("buffers", index);
4892
- }
4893
- _get(array, index) {
4894
- if (typeof index === "object") {
4895
- return index;
4896
- }
4897
- const object = this.json[array] && this.json[array][index];
4898
- if (!object) {
4899
- console.warn(`glTF file error: Could not find ${array}[${index}]`);
4900
- }
4901
- return object;
4902
- }
4903
- _resolveScene(scene, index) {
4904
- scene.id = scene.id || `scene-${index}`;
4905
- scene.nodes = (scene.nodes || []).map((node2) => this.getNode(node2));
4906
- return scene;
4907
- }
4908
- _resolveNode(node2, index) {
4909
- node2.id = node2.id || `node-${index}`;
4910
- if (node2.children) {
4911
- node2.children = node2.children.map((child) => this.getNode(child));
4912
- }
4913
- if (node2.mesh !== void 0) {
4914
- node2.mesh = this.getMesh(node2.mesh);
4915
- } else if (node2.meshes !== void 0 && node2.meshes.length) {
4916
- node2.mesh = node2.meshes.reduce((accum, meshIndex) => {
4917
- const mesh = this.getMesh(meshIndex);
4918
- accum.id = mesh.id;
4919
- accum.primitives = accum.primitives.concat(mesh.primitives);
4920
- return accum;
4921
- }, { primitives: [] });
4922
- }
4923
- if (node2.camera !== void 0) {
4924
- node2.camera = this.getCamera(node2.camera);
4925
- }
4926
- if (node2.skin !== void 0) {
4927
- node2.skin = this.getSkin(node2.skin);
4928
- }
4929
- return node2;
4896
+ json.asset = json.asset || {};
4897
+ json.asset.version = "2.0";
4898
+ json.asset.generator = json.asset.generator || "Normalized to glTF 2.0 by loaders.gl";
4930
4899
  }
4931
- _resolveSkin(skin, index) {
4932
- skin.id = skin.id || `skin-${index}`;
4933
- skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
4934
- return skin;
4935
- }
4936
- _resolveMesh(mesh, index) {
4937
- mesh.id = mesh.id || `mesh-${index}`;
4938
- if (mesh.primitives) {
4939
- mesh.primitives = mesh.primitives.map((primitive) => {
4940
- primitive = { ...primitive };
4941
- const attributes = primitive.attributes;
4942
- primitive.attributes = {};
4943
- for (const attribute in attributes) {
4944
- primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
4945
- }
4946
- if (primitive.indices !== void 0) {
4947
- primitive.indices = this.getAccessor(primitive.indices);
4948
- }
4949
- if (primitive.material !== void 0) {
4950
- primitive.material = this.getMaterial(primitive.material);
4951
- }
4952
- return primitive;
4953
- });
4900
+ _convertTopLevelObjectsToArrays(json) {
4901
+ for (const arrayName in GLTF_ARRAYS) {
4902
+ this._convertTopLevelObjectToArray(json, arrayName);
4954
4903
  }
4955
- return mesh;
4956
4904
  }
4957
- _resolveMaterial(material, index) {
4958
- material.id = material.id || `material-${index}`;
4959
- if (material.normalTexture) {
4960
- material.normalTexture = { ...material.normalTexture };
4961
- material.normalTexture.texture = this.getTexture(material.normalTexture.index);
4905
+ _convertTopLevelObjectToArray(json, mapName) {
4906
+ const objectMap = json[mapName];
4907
+ if (!objectMap || Array.isArray(objectMap)) {
4908
+ return;
4962
4909
  }
4963
- if (material.occlusionTexture) {
4964
- material.occlustionTexture = { ...material.occlustionTexture };
4965
- material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
4910
+ json[mapName] = [];
4911
+ for (const id in objectMap) {
4912
+ const object = objectMap[id];
4913
+ object.id = object.id || id;
4914
+ const index = json[mapName].length;
4915
+ json[mapName].push(object);
4916
+ this.idToIndexMap[mapName][id] = index;
4966
4917
  }
4967
- if (material.emissiveTexture) {
4968
- material.emmisiveTexture = { ...material.emmisiveTexture };
4969
- material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
4918
+ }
4919
+ _convertObjectIdsToArrayIndices(json) {
4920
+ for (const arrayName in GLTF_ARRAYS) {
4921
+ this._convertIdsToIndices(json, arrayName);
4970
4922
  }
4971
- if (!material.emissiveFactor) {
4972
- material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];
4923
+ if ("scene" in json) {
4924
+ json.scene = this._convertIdToIndex(json.scene, "scene");
4973
4925
  }
4974
- if (material.pbrMetallicRoughness) {
4975
- material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness };
4976
- const mr = material.pbrMetallicRoughness;
4977
- if (mr.baseColorTexture) {
4978
- mr.baseColorTexture = { ...mr.baseColorTexture };
4979
- mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
4980
- }
4981
- if (mr.metallicRoughnessTexture) {
4982
- mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture };
4983
- mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
4984
- }
4926
+ for (const texture of json.textures) {
4927
+ this._convertTextureIds(texture);
4985
4928
  }
4986
- return material;
4987
- }
4988
- _resolveAccessor(accessor, index) {
4989
- accessor.id = accessor.id || `accessor-${index}`;
4990
- if (accessor.bufferView !== void 0) {
4991
- accessor.bufferView = this.getBufferView(accessor.bufferView);
4929
+ for (const mesh of json.meshes) {
4930
+ this._convertMeshIds(mesh);
4992
4931
  }
4993
- accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);
4994
- accessor.components = getSizeFromAccessorType(accessor.type);
4995
- accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
4996
- if (accessor.bufferView) {
4997
- const buffer = accessor.bufferView.buffer;
4998
- const { ArrayType, byteLength } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
4999
- const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
5000
- let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
5001
- if (accessor.bufferView.byteStride) {
5002
- cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
5003
- }
5004
- accessor.value = new ArrayType(cutBuffer);
4932
+ for (const node2 of json.nodes) {
4933
+ this._convertNodeIds(node2);
5005
4934
  }
5006
- return accessor;
5007
- }
5008
- _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
5009
- const result = new Uint8Array(count * bytesPerElement);
5010
- for (let i2 = 0; i2 < count; i2++) {
5011
- const elementOffset = byteOffset + i2 * byteStride;
5012
- result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i2 * bytesPerElement);
4935
+ for (const node2 of json.scenes) {
4936
+ this._convertSceneIds(node2);
5013
4937
  }
5014
- return result.buffer;
5015
4938
  }
5016
- _resolveTexture(texture, index) {
5017
- texture.id = texture.id || `texture-${index}`;
5018
- texture.sampler = "sampler" in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
5019
- texture.source = this.getImage(texture.source);
5020
- return texture;
4939
+ _convertTextureIds(texture) {
4940
+ if (texture.source) {
4941
+ texture.source = this._convertIdToIndex(texture.source, "image");
4942
+ }
5021
4943
  }
5022
- _resolveSampler(sampler, index) {
5023
- sampler.id = sampler.id || `sampler-${index}`;
5024
- sampler.parameters = {};
5025
- for (const key in sampler) {
5026
- const glEnum = this._enumSamplerParameter(key);
5027
- if (glEnum !== void 0) {
5028
- sampler.parameters[glEnum] = sampler[key];
4944
+ _convertMeshIds(mesh) {
4945
+ for (const primitive of mesh.primitives) {
4946
+ const { attributes, indices, material } = primitive;
4947
+ for (const attributeName in attributes) {
4948
+ attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], "accessor");
4949
+ }
4950
+ if (indices) {
4951
+ primitive.indices = this._convertIdToIndex(indices, "accessor");
4952
+ }
4953
+ if (material) {
4954
+ primitive.material = this._convertIdToIndex(material, "material");
5029
4955
  }
5030
4956
  }
5031
- return sampler;
5032
- }
5033
- _enumSamplerParameter(key) {
5034
- return SAMPLER_PARAMETER_GLTF_TO_GL[key];
5035
4957
  }
5036
- _resolveImage(image, index) {
5037
- image.id = image.id || `image-${index}`;
5038
- if (image.bufferView !== void 0) {
5039
- image.bufferView = this.getBufferView(image.bufferView);
4958
+ _convertNodeIds(node2) {
4959
+ if (node2.children) {
4960
+ node2.children = node2.children.map((child) => this._convertIdToIndex(child, "node"));
5040
4961
  }
5041
- const preloadedImage = this.images[index];
5042
- if (preloadedImage) {
5043
- image.image = preloadedImage;
4962
+ if (node2.meshes) {
4963
+ node2.meshes = node2.meshes.map((mesh) => this._convertIdToIndex(mesh, "mesh"));
5044
4964
  }
5045
- return image;
5046
4965
  }
5047
- _resolveBufferView(bufferView, index) {
5048
- const bufferIndex = bufferView.buffer;
5049
- const result = {
5050
- id: `bufferView-${index}`,
5051
- ...bufferView,
5052
- buffer: this.buffers[bufferIndex]
5053
- };
5054
- const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
5055
- let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
5056
- if ("byteOffset" in bufferView) {
5057
- byteOffset += bufferView.byteOffset;
4966
+ _convertSceneIds(scene) {
4967
+ if (scene.nodes) {
4968
+ scene.nodes = scene.nodes.map((node2) => this._convertIdToIndex(node2, "node"));
5058
4969
  }
5059
- result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
5060
- return result;
5061
4970
  }
5062
- _resolveCamera(camera, index) {
5063
- camera.id = camera.id || `camera-${index}`;
5064
- if (camera.perspective) {
4971
+ _convertIdsToIndices(json, topLevelArrayName) {
4972
+ if (!json[topLevelArrayName]) {
4973
+ console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`);
4974
+ json[topLevelArrayName] = [];
5065
4975
  }
5066
- if (camera.orthographic) {
4976
+ for (const object of json[topLevelArrayName]) {
4977
+ for (const key in object) {
4978
+ const id = object[key];
4979
+ const index = this._convertIdToIndex(id, key);
4980
+ object[key] = index;
4981
+ }
5067
4982
  }
5068
- return camera;
5069
4983
  }
5070
- };
5071
- }
5072
- });
5073
-
5074
- // src/lib/parsers/parse-glb.ts
5075
- function getMagicString2(dataView, byteOffset = 0) {
5076
- return `${String.fromCharCode(dataView.getUint8(byteOffset + 0))}${String.fromCharCode(dataView.getUint8(byteOffset + 1))}${String.fromCharCode(dataView.getUint8(byteOffset + 2))}${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
5077
- }
5078
- function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
5079
- const dataView = new DataView(arrayBuffer);
5080
- const { magic = MAGIC_glTF } = options;
5081
- const magic1 = dataView.getUint32(byteOffset, false);
5082
- return magic1 === magic || magic1 === MAGIC_glTF;
5083
- }
5084
- function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
5085
- const dataView = new DataView(arrayBuffer);
5086
- const type = getMagicString2(dataView, byteOffset + 0);
5087
- const version = dataView.getUint32(byteOffset + 4, LE);
5088
- const byteLength = dataView.getUint32(byteOffset + 8, LE);
5089
- Object.assign(glb, {
5090
- header: {
5091
- byteOffset,
5092
- byteLength,
5093
- hasBinChunk: false
5094
- },
5095
- type,
5096
- version,
5097
- json: {},
5098
- binChunks: []
5099
- });
5100
- byteOffset += GLB_FILE_HEADER_SIZE;
5101
- switch (glb.version) {
5102
- case 1:
5103
- return parseGLBV1(glb, dataView, byteOffset);
5104
- case 2:
5105
- return parseGLBV2(glb, dataView, byteOffset, options = {});
5106
- default:
5107
- throw new Error(`Invalid GLB version ${glb.version}. Only supports v1 and v2.`);
5108
- }
5109
- }
5110
- function parseGLBV1(glb, dataView, byteOffset) {
5111
- assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
5112
- const contentLength = dataView.getUint32(byteOffset + 0, LE);
5113
- const contentFormat = dataView.getUint32(byteOffset + 4, LE);
5114
- byteOffset += GLB_CHUNK_HEADER_SIZE;
5115
- assert(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
5116
- parseJSONChunk(glb, dataView, byteOffset, contentLength);
5117
- byteOffset += contentLength;
5118
- byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
5119
- return byteOffset;
5120
- }
5121
- function parseGLBV2(glb, dataView, byteOffset, options) {
5122
- assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
5123
- parseGLBChunksSync(glb, dataView, byteOffset, options);
5124
- return byteOffset + glb.header.byteLength;
5125
- }
5126
- function parseGLBChunksSync(glb, dataView, byteOffset, options) {
5127
- while (byteOffset + 8 <= glb.header.byteLength) {
5128
- const chunkLength = dataView.getUint32(byteOffset + 0, LE);
5129
- const chunkFormat = dataView.getUint32(byteOffset + 4, LE);
5130
- byteOffset += GLB_CHUNK_HEADER_SIZE;
5131
- switch (chunkFormat) {
5132
- case GLB_CHUNK_TYPE_JSON:
5133
- parseJSONChunk(glb, dataView, byteOffset, chunkLength);
5134
- break;
5135
- case GLB_CHUNK_TYPE_BIN:
5136
- parseBINChunk(glb, dataView, byteOffset, chunkLength);
5137
- break;
5138
- case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
5139
- if (!options.strict) {
5140
- parseJSONChunk(glb, dataView, byteOffset, chunkLength);
4984
+ _convertIdToIndex(id, key) {
4985
+ const arrayName = GLTF_KEYS[key];
4986
+ if (arrayName in this.idToIndexMap) {
4987
+ const index = this.idToIndexMap[arrayName][id];
4988
+ if (!Number.isFinite(index)) {
4989
+ throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);
4990
+ }
4991
+ return index;
5141
4992
  }
5142
- break;
5143
- case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:
5144
- if (!options.strict) {
5145
- parseBINChunk(glb, dataView, byteOffset, chunkLength);
4993
+ return id;
4994
+ }
4995
+ _updateObjects(json) {
4996
+ for (const buffer of this.json.buffers) {
4997
+ delete buffer.type;
5146
4998
  }
5147
- break;
5148
- default:
5149
- break;
5150
- }
5151
- byteOffset += padToNBytes(chunkLength, 4);
5152
- }
5153
- return byteOffset;
5154
- }
5155
- function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
5156
- const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
5157
- const textDecoder = new TextDecoder("utf8");
5158
- const jsonText = textDecoder.decode(jsonChunk);
5159
- glb.json = JSON.parse(jsonText);
5160
- return padToNBytes(chunkLength, 4);
5161
- }
5162
- function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
5163
- glb.header.hasBinChunk = true;
5164
- glb.binChunks.push({
5165
- byteOffset,
5166
- byteLength: chunkLength,
5167
- arrayBuffer: dataView.buffer
5168
- });
5169
- return padToNBytes(chunkLength, 4);
5170
- }
5171
- var MAGIC_glTF, GLB_FILE_HEADER_SIZE, GLB_CHUNK_HEADER_SIZE, GLB_CHUNK_TYPE_JSON, GLB_CHUNK_TYPE_BIN, GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED, GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED, GLB_V1_CONTENT_FORMAT_JSON, LE;
5172
- var init_parse_glb = __esm({
5173
- "src/lib/parsers/parse-glb.ts"() {
5174
- init_src2();
5175
- MAGIC_glTF = 1735152710;
5176
- GLB_FILE_HEADER_SIZE = 12;
5177
- GLB_CHUNK_HEADER_SIZE = 8;
5178
- GLB_CHUNK_TYPE_JSON = 1313821514;
5179
- GLB_CHUNK_TYPE_BIN = 5130562;
5180
- GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
5181
- GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
5182
- GLB_V1_CONTENT_FORMAT_JSON = 0;
5183
- LE = true;
4999
+ }
5000
+ _updateMaterial(json) {
5001
+ for (const material of json.materials) {
5002
+ material.pbrMetallicRoughness = {
5003
+ baseColorFactor: [1, 1, 1, 1],
5004
+ metallicFactor: 1,
5005
+ roughnessFactor: 1
5006
+ };
5007
+ const textureId = material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;
5008
+ const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);
5009
+ if (textureIndex !== -1) {
5010
+ material.pbrMetallicRoughness.baseColorTexture = { index: textureIndex };
5011
+ }
5012
+ }
5013
+ }
5014
+ };
5184
5015
  }
5185
5016
  });
5186
5017
 
@@ -5189,18 +5020,14 @@
5189
5020
  parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);
5190
5021
  normalizeGLTFV1(gltf, { normalize: options?.gltf?.normalize });
5191
5022
  preprocessExtensions(gltf, options, context);
5192
- const promises = [];
5193
5023
  if (options?.gltf?.loadBuffers && gltf.json.buffers) {
5194
5024
  await loadBuffers(gltf, options, context);
5195
5025
  }
5196
5026
  if (options?.gltf?.loadImages) {
5197
- const promise2 = loadImages(gltf, options, context);
5198
- promises.push(promise2);
5027
+ await loadImages(gltf, options, context);
5199
5028
  }
5200
- const promise = decodeExtensions(gltf, options, context);
5201
- promises.push(promise);
5202
- await Promise.all(promises);
5203
- return options?.gltf?.postProcess ? postProcessGLTF(gltf, options) : gltf;
5029
+ await decodeExtensions(gltf, options, context);
5030
+ return gltf;
5204
5031
  }
5205
5032
  function parseGLTFContainerSync(gltf, data, byteOffset, options) {
5206
5033
  if (options.uri) {
@@ -5309,16 +5136,15 @@
5309
5136
  }
5310
5137
  var init_parse_gltf = __esm({
5311
5138
  "src/lib/parsers/parse-gltf.ts"() {
5312
- init_src4();
5313
- init_src3();
5314
5139
  init_src2();
5140
+ init_src3();
5141
+ init_src4();
5315
5142
  init_assert3();
5143
+ init_parse_glb();
5316
5144
  init_resolve_url();
5317
5145
  init_get_typed_array();
5318
5146
  init_gltf_extensions();
5319
5147
  init_normalize_gltf_v1();
5320
- init_post_process_gltf();
5321
- init_parse_glb();
5322
5148
  }
5323
5149
  });
5324
5150
 
@@ -5351,8 +5177,7 @@
5351
5177
  normalize: true,
5352
5178
  loadBuffers: true,
5353
5179
  loadImages: true,
5354
- decompressMeshes: true,
5355
- postProcess: true
5180
+ decompressMeshes: true
5356
5181
  },
5357
5182
  log: console
5358
5183
  },
@@ -5362,7 +5187,8 @@
5362
5187
  decompress: "gltf.decompressMeshes",
5363
5188
  postProcess: "gltf.postProcess",
5364
5189
  gltf: {
5365
- decompress: "gltf.decompressMeshes"
5190
+ decompress: "gltf.decompressMeshes",
5191
+ postProcess: "removed in v4"
5366
5192
  }
5367
5193
  }
5368
5194
  };
@@ -5374,51 +5200,51 @@
5374
5200
  const { magic = MAGIC_glTF2, version = 2, json = {}, binary } = glb;
5375
5201
  const byteOffsetStart = byteOffset;
5376
5202
  if (dataView) {
5377
- dataView.setUint32(byteOffset + 0, magic, LE2);
5378
- dataView.setUint32(byteOffset + 4, version, LE2);
5379
- dataView.setUint32(byteOffset + 8, 0, LE2);
5203
+ dataView.setUint32(byteOffset + 0, magic, LE);
5204
+ dataView.setUint32(byteOffset + 4, version, LE);
5205
+ dataView.setUint32(byteOffset + 8, 0, LE);
5380
5206
  }
5381
5207
  const byteOffsetFileLength = byteOffset + 8;
5382
5208
  byteOffset += 12;
5383
5209
  const byteOffsetJsonHeader = byteOffset;
5384
5210
  if (dataView) {
5385
- dataView.setUint32(byteOffset + 0, 0, LE2);
5386
- dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE2);
5211
+ dataView.setUint32(byteOffset + 0, 0, LE);
5212
+ dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE);
5387
5213
  }
5388
5214
  byteOffset += 8;
5389
5215
  const jsonString = JSON.stringify(json);
5390
5216
  byteOffset = copyPaddedStringToDataView(dataView, byteOffset, jsonString, 4);
5391
5217
  if (dataView) {
5392
5218
  const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8;
5393
- dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE2);
5219
+ dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE);
5394
5220
  }
5395
5221
  if (binary) {
5396
5222
  const byteOffsetBinHeader = byteOffset;
5397
5223
  if (dataView) {
5398
- dataView.setUint32(byteOffset + 0, 0, LE2);
5399
- dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE2);
5224
+ dataView.setUint32(byteOffset + 0, 0, LE);
5225
+ dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE);
5400
5226
  }
5401
5227
  byteOffset += 8;
5402
5228
  byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, binary, 4);
5403
5229
  if (dataView) {
5404
5230
  const binByteLength = byteOffset - byteOffsetBinHeader - 8;
5405
- dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE2);
5231
+ dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE);
5406
5232
  }
5407
5233
  }
5408
5234
  if (dataView) {
5409
5235
  const fileByteLength = byteOffset - byteOffsetStart;
5410
- dataView.setUint32(byteOffsetFileLength, fileByteLength, LE2);
5236
+ dataView.setUint32(byteOffsetFileLength, fileByteLength, LE);
5411
5237
  }
5412
5238
  return byteOffset;
5413
5239
  }
5414
- var MAGIC_glTF2, MAGIC_JSON, MAGIC_BIN, LE2;
5240
+ var MAGIC_glTF2, MAGIC_JSON, MAGIC_BIN, LE;
5415
5241
  var init_encode_glb = __esm({
5416
5242
  "src/lib/encoders/encode-glb.ts"() {
5417
5243
  init_src2();
5418
5244
  MAGIC_glTF2 = 1179937895;
5419
5245
  MAGIC_JSON = 1313821514;
5420
5246
  MAGIC_BIN = 5130562;
5421
- LE2 = true;
5247
+ LE = true;
5422
5248
  }
5423
5249
  });
5424
5250
 
@@ -5532,6 +5358,380 @@
5532
5358
  }
5533
5359
  });
5534
5360
 
5361
+ // src/lib/api/post-process-gltf.ts
5362
+ function makeDefaultSampler() {
5363
+ return {
5364
+ id: "default-sampler",
5365
+ parameters: DEFAULT_SAMPLER_PARAMETERS
5366
+ };
5367
+ }
5368
+ function getBytesFromComponentType(componentType) {
5369
+ return BYTES2[componentType];
5370
+ }
5371
+ function getSizeFromAccessorType(type) {
5372
+ return COMPONENTS2[type];
5373
+ }
5374
+ function postProcessGLTF(gltf, options) {
5375
+ return new GLTFPostProcessor().postProcess(gltf, options);
5376
+ }
5377
+ var COMPONENTS2, BYTES2, GL_SAMPLER, SAMPLER_PARAMETER_GLTF_TO_GL, DEFAULT_SAMPLER_PARAMETERS, GLTFPostProcessor;
5378
+ var init_post_process_gltf = __esm({
5379
+ "src/lib/api/post-process-gltf.ts"() {
5380
+ init_assert3();
5381
+ init_gltf_utils();
5382
+ COMPONENTS2 = {
5383
+ SCALAR: 1,
5384
+ VEC2: 2,
5385
+ VEC3: 3,
5386
+ VEC4: 4,
5387
+ MAT2: 4,
5388
+ MAT3: 9,
5389
+ MAT4: 16
5390
+ };
5391
+ BYTES2 = {
5392
+ 5120: 1,
5393
+ 5121: 1,
5394
+ 5122: 2,
5395
+ 5123: 2,
5396
+ 5125: 4,
5397
+ 5126: 4
5398
+ };
5399
+ GL_SAMPLER = {
5400
+ TEXTURE_MAG_FILTER: 10240,
5401
+ TEXTURE_MIN_FILTER: 10241,
5402
+ TEXTURE_WRAP_S: 10242,
5403
+ TEXTURE_WRAP_T: 10243,
5404
+ REPEAT: 10497,
5405
+ LINEAR: 9729,
5406
+ NEAREST_MIPMAP_LINEAR: 9986
5407
+ };
5408
+ SAMPLER_PARAMETER_GLTF_TO_GL = {
5409
+ magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
5410
+ minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
5411
+ wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
5412
+ wrapT: GL_SAMPLER.TEXTURE_WRAP_T
5413
+ };
5414
+ DEFAULT_SAMPLER_PARAMETERS = {
5415
+ [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
5416
+ [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
5417
+ [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
5418
+ [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
5419
+ };
5420
+ GLTFPostProcessor = class {
5421
+ constructor() {
5422
+ this.baseUri = "";
5423
+ this.buffers = [];
5424
+ this.images = [];
5425
+ }
5426
+ postProcess(gltf, options = {}) {
5427
+ const { json, buffers = [], images = [] } = gltf;
5428
+ const { baseUri = "" } = gltf;
5429
+ assert3(json);
5430
+ this.baseUri = baseUri;
5431
+ this.buffers = buffers;
5432
+ this.images = images;
5433
+ this.jsonUnprocessed = json;
5434
+ this.json = this._resolveTree(gltf.json, options);
5435
+ return this.json;
5436
+ }
5437
+ _resolveTree(gltf, options = {}) {
5438
+ const json = { ...gltf };
5439
+ this.json = json;
5440
+ if (gltf.bufferViews) {
5441
+ json.bufferViews = gltf.bufferViews.map((bufView, i2) => this._resolveBufferView(bufView, i2));
5442
+ }
5443
+ if (gltf.images) {
5444
+ json.images = gltf.images.map((image, i2) => this._resolveImage(image, i2));
5445
+ }
5446
+ if (gltf.samplers) {
5447
+ json.samplers = gltf.samplers.map((sampler, i2) => this._resolveSampler(sampler, i2));
5448
+ }
5449
+ if (gltf.textures) {
5450
+ json.textures = gltf.textures.map((texture, i2) => this._resolveTexture(texture, i2));
5451
+ }
5452
+ if (gltf.accessors) {
5453
+ json.accessors = gltf.accessors.map((accessor, i2) => this._resolveAccessor(accessor, i2));
5454
+ }
5455
+ if (gltf.materials) {
5456
+ json.materials = gltf.materials.map((material, i2) => this._resolveMaterial(material, i2));
5457
+ }
5458
+ if (gltf.meshes) {
5459
+ json.meshes = gltf.meshes.map((mesh, i2) => this._resolveMesh(mesh, i2));
5460
+ }
5461
+ if (gltf.nodes) {
5462
+ json.nodes = gltf.nodes.map((node2, i2) => this._resolveNode(node2, i2));
5463
+ json.nodes = json.nodes.map((node2, i2) => this._resolveNodeChildren(node2));
5464
+ }
5465
+ if (gltf.skins) {
5466
+ json.skins = gltf.skins.map((skin, i2) => this._resolveSkin(skin, i2));
5467
+ }
5468
+ if (gltf.scenes) {
5469
+ json.scenes = gltf.scenes.map((scene, i2) => this._resolveScene(scene, i2));
5470
+ }
5471
+ if (typeof this.json.scene === "number" && json.scenes) {
5472
+ json.scene = json.scenes[this.json.scene];
5473
+ }
5474
+ return json;
5475
+ }
5476
+ getScene(index) {
5477
+ return this._get(this.json.scenes, index);
5478
+ }
5479
+ getNode(index) {
5480
+ return this._get(this.json.nodes, index);
5481
+ }
5482
+ getSkin(index) {
5483
+ return this._get(this.json.skins, index);
5484
+ }
5485
+ getMesh(index) {
5486
+ return this._get(this.json.meshes, index);
5487
+ }
5488
+ getMaterial(index) {
5489
+ return this._get(this.json.materials, index);
5490
+ }
5491
+ getAccessor(index) {
5492
+ return this._get(this.json.accessors, index);
5493
+ }
5494
+ getCamera(index) {
5495
+ return this._get(this.json.cameras, index);
5496
+ }
5497
+ getTexture(index) {
5498
+ return this._get(this.json.textures, index);
5499
+ }
5500
+ getSampler(index) {
5501
+ return this._get(this.json.samplers, index);
5502
+ }
5503
+ getImage(index) {
5504
+ return this._get(this.json.images, index);
5505
+ }
5506
+ getBufferView(index) {
5507
+ return this._get(this.json.bufferViews, index);
5508
+ }
5509
+ getBuffer(index) {
5510
+ return this._get(this.json.buffers, index);
5511
+ }
5512
+ _get(array, index) {
5513
+ if (typeof index === "object") {
5514
+ return index;
5515
+ }
5516
+ const object = array && array[index];
5517
+ if (!object) {
5518
+ console.warn(`glTF file error: Could not find ${array}[${index}]`);
5519
+ }
5520
+ return object;
5521
+ }
5522
+ _resolveScene(scene, index) {
5523
+ return {
5524
+ ...scene,
5525
+ id: scene.id || `scene-${index}`,
5526
+ nodes: (scene.nodes || []).map((node2) => this.getNode(node2))
5527
+ };
5528
+ }
5529
+ _resolveNode(gltfNode, index) {
5530
+ const node2 = {
5531
+ ...gltfNode,
5532
+ id: gltfNode?.id || `node-${index}`
5533
+ };
5534
+ if (gltfNode.mesh !== void 0) {
5535
+ node2.mesh = this.getMesh(gltfNode.mesh);
5536
+ }
5537
+ if (gltfNode.camera !== void 0) {
5538
+ node2.camera = this.getCamera(gltfNode.camera);
5539
+ }
5540
+ if (gltfNode.skin !== void 0) {
5541
+ node2.skin = this.getSkin(gltfNode.skin);
5542
+ }
5543
+ if (gltfNode.meshes !== void 0 && gltfNode.meshes.length) {
5544
+ node2.mesh = gltfNode.meshes.reduce((accum, meshIndex) => {
5545
+ const mesh = this.getMesh(meshIndex);
5546
+ accum.id = mesh.id;
5547
+ accum.primitives = accum.primitives.concat(mesh.primitives);
5548
+ return accum;
5549
+ }, { primitives: [] });
5550
+ }
5551
+ return node2;
5552
+ }
5553
+ _resolveNodeChildren(node2) {
5554
+ if (node2.children) {
5555
+ node2.children = node2.children.map((child) => this.getNode(child));
5556
+ }
5557
+ return node2;
5558
+ }
5559
+ _resolveSkin(gltfSkin, index) {
5560
+ const inverseBindMatrices = typeof gltfSkin.inverseBindMatrices === "number" ? this.getAccessor(gltfSkin.inverseBindMatrices) : void 0;
5561
+ return {
5562
+ ...gltfSkin,
5563
+ id: gltfSkin.id || `skin-${index}`,
5564
+ inverseBindMatrices
5565
+ };
5566
+ }
5567
+ _resolveMesh(gltfMesh, index) {
5568
+ const mesh = {
5569
+ ...gltfMesh,
5570
+ id: gltfMesh.id || `mesh-${index}`,
5571
+ primitives: []
5572
+ };
5573
+ if (gltfMesh.primitives) {
5574
+ mesh.primitives = gltfMesh.primitives.map((gltfPrimitive) => {
5575
+ const primitive = {
5576
+ ...gltfPrimitive,
5577
+ attributes: {},
5578
+ indices: void 0,
5579
+ material: void 0
5580
+ };
5581
+ const attributes = gltfPrimitive.attributes;
5582
+ for (const attribute in attributes) {
5583
+ primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
5584
+ }
5585
+ if (gltfPrimitive.indices !== void 0) {
5586
+ primitive.indices = this.getAccessor(gltfPrimitive.indices);
5587
+ }
5588
+ if (gltfPrimitive.material !== void 0) {
5589
+ primitive.material = this.getMaterial(gltfPrimitive.material);
5590
+ }
5591
+ return primitive;
5592
+ });
5593
+ }
5594
+ return mesh;
5595
+ }
5596
+ _resolveMaterial(gltfMaterial, index) {
5597
+ const material = {
5598
+ ...gltfMaterial,
5599
+ id: gltfMaterial.id || `material-${index}`
5600
+ };
5601
+ if (material.normalTexture) {
5602
+ material.normalTexture = { ...material.normalTexture };
5603
+ material.normalTexture.texture = this.getTexture(material.normalTexture.index);
5604
+ }
5605
+ if (material.occlusionTexture) {
5606
+ material.occlusionTexture = { ...material.occlusionTexture };
5607
+ material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
5608
+ }
5609
+ if (material.emissiveTexture) {
5610
+ material.emissiveTexture = { ...material.emissiveTexture };
5611
+ material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
5612
+ }
5613
+ if (!material.emissiveFactor) {
5614
+ material.emissiveFactor = material.emissiveTexture ? [1, 1, 1] : [0, 0, 0];
5615
+ }
5616
+ if (material.pbrMetallicRoughness) {
5617
+ material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness };
5618
+ const mr = material.pbrMetallicRoughness;
5619
+ if (mr.baseColorTexture) {
5620
+ mr.baseColorTexture = { ...mr.baseColorTexture };
5621
+ mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
5622
+ }
5623
+ if (mr.metallicRoughnessTexture) {
5624
+ mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture };
5625
+ mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
5626
+ }
5627
+ }
5628
+ return material;
5629
+ }
5630
+ _resolveAccessor(gltfAccessor, index) {
5631
+ const bytesPerComponent = getBytesFromComponentType(gltfAccessor.componentType);
5632
+ const components = getSizeFromAccessorType(gltfAccessor.type);
5633
+ const bytesPerElement = bytesPerComponent * components;
5634
+ const accessor = {
5635
+ ...gltfAccessor,
5636
+ id: gltfAccessor.id || `accessor-${index}`,
5637
+ bytesPerComponent,
5638
+ components,
5639
+ bytesPerElement,
5640
+ value: void 0,
5641
+ bufferView: void 0,
5642
+ sparse: void 0
5643
+ };
5644
+ if (gltfAccessor.bufferView !== void 0) {
5645
+ accessor.bufferView = this.getBufferView(gltfAccessor.bufferView);
5646
+ }
5647
+ if (accessor.bufferView) {
5648
+ const buffer = accessor.bufferView.buffer;
5649
+ const { ArrayType, byteLength } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
5650
+ const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
5651
+ let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
5652
+ if (accessor.bufferView.byteStride) {
5653
+ cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
5654
+ }
5655
+ accessor.value = new ArrayType(cutBuffer);
5656
+ }
5657
+ return accessor;
5658
+ }
5659
+ _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
5660
+ const result = new Uint8Array(count * bytesPerElement);
5661
+ for (let i2 = 0; i2 < count; i2++) {
5662
+ const elementOffset = byteOffset + i2 * byteStride;
5663
+ result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i2 * bytesPerElement);
5664
+ }
5665
+ return result.buffer;
5666
+ }
5667
+ _resolveTexture(gltfTexture, index) {
5668
+ return {
5669
+ ...gltfTexture,
5670
+ id: gltfTexture.id || `texture-${index}`,
5671
+ sampler: typeof gltfTexture.sampler === "number" ? this.getSampler(gltfTexture.sampler) : makeDefaultSampler(),
5672
+ source: typeof gltfTexture.source === "number" ? this.getImage(gltfTexture.source) : void 0
5673
+ };
5674
+ }
5675
+ _resolveSampler(gltfSampler, index) {
5676
+ const sampler = {
5677
+ id: gltfSampler.id || `sampler-${index}`,
5678
+ ...gltfSampler,
5679
+ parameters: {}
5680
+ };
5681
+ for (const key in sampler) {
5682
+ const glEnum = this._enumSamplerParameter(key);
5683
+ if (glEnum !== void 0) {
5684
+ sampler.parameters[glEnum] = sampler[key];
5685
+ }
5686
+ }
5687
+ return sampler;
5688
+ }
5689
+ _enumSamplerParameter(key) {
5690
+ return SAMPLER_PARAMETER_GLTF_TO_GL[key];
5691
+ }
5692
+ _resolveImage(gltfImage, index) {
5693
+ const image = {
5694
+ ...gltfImage,
5695
+ id: gltfImage.id || `image-${index}`,
5696
+ image: null,
5697
+ bufferView: gltfImage.bufferView !== void 0 ? this.getBufferView(gltfImage.bufferView) : void 0
5698
+ };
5699
+ const preloadedImage = this.images[index];
5700
+ if (preloadedImage) {
5701
+ image.image = preloadedImage;
5702
+ }
5703
+ return image;
5704
+ }
5705
+ _resolveBufferView(gltfBufferView, index) {
5706
+ const bufferIndex = gltfBufferView.buffer;
5707
+ const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
5708
+ let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
5709
+ if (gltfBufferView.byteOffset) {
5710
+ byteOffset += gltfBufferView.byteOffset;
5711
+ }
5712
+ const bufferView = {
5713
+ id: `bufferView-${index}`,
5714
+ ...gltfBufferView,
5715
+ buffer: this.buffers[bufferIndex],
5716
+ data: new Uint8Array(arrayBuffer, byteOffset, gltfBufferView.byteLength)
5717
+ };
5718
+ return bufferView;
5719
+ }
5720
+ _resolveCamera(gltfCamera, index) {
5721
+ const camera = {
5722
+ ...gltfCamera,
5723
+ id: gltfCamera.id || `camera-${index}`
5724
+ };
5725
+ if (camera.perspective) {
5726
+ }
5727
+ if (camera.orthographic) {
5728
+ }
5729
+ return camera;
5730
+ }
5731
+ };
5732
+ }
5733
+ });
5734
+
5535
5735
  // src/index.ts
5536
5736
  var src_exports = {};
5537
5737
  __export(src_exports, {
@@ -5540,6 +5740,7 @@
5540
5740
  GLTFLoader: () => GLTFLoader,
5541
5741
  GLTFScenegraph: () => GLTFScenegraph,
5542
5742
  GLTFWriter: () => GLTFWriter,
5743
+ _getMemoryUsageGLTF: () => getMemoryUsageGLTF,
5543
5744
  postProcessGLTF: () => postProcessGLTF
5544
5745
  });
5545
5746
  var init_src7 = __esm({
@@ -5550,6 +5751,7 @@
5550
5751
  init_glb_writer();
5551
5752
  init_gltf_scenegraph();
5552
5753
  init_post_process_gltf();
5754
+ init_gltf_utils();
5553
5755
  }
5554
5756
  });
5555
5757