@loaders.gl/gltf 4.0.0-beta.2 → 4.0.0-beta.4

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 (247) hide show
  1. package/dist/{dist.min.js → dist.dev.js} +3016 -3442
  2. package/dist/{esm/glb-loader.js → glb-loader.js} +2 -2
  3. package/dist/glb-loader.js.map +1 -0
  4. package/dist/{esm/glb-writer.js → glb-writer.js} +2 -2
  5. package/dist/glb-writer.js.map +1 -0
  6. package/dist/{esm/gltf-loader.js → gltf-loader.js} +2 -2
  7. package/dist/gltf-loader.js.map +1 -0
  8. package/dist/{esm/gltf-writer.js → gltf-writer.js} +2 -2
  9. package/dist/gltf-writer.js.map +1 -0
  10. package/dist/index.cjs +3558 -0
  11. package/dist/index.js +13 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/{esm/lib → lib}/api/gltf-extensions.js +11 -11
  14. package/dist/lib/api/gltf-extensions.js.map +1 -0
  15. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
  16. package/dist/{esm/lib → lib}/api/gltf-scenegraph.js +9 -17
  17. package/dist/lib/api/gltf-scenegraph.js.map +1 -0
  18. package/dist/{esm/lib → lib}/api/normalize-gltf-v1.js +7 -8
  19. package/dist/lib/api/normalize-gltf-v1.js.map +1 -0
  20. package/dist/{esm/lib → lib}/api/post-process-gltf.js +19 -20
  21. package/dist/lib/api/post-process-gltf.js.map +1 -0
  22. package/dist/lib/encoders/encode-glb.js.map +1 -0
  23. package/dist/{esm/lib → lib}/encoders/encode-gltf.js +1 -1
  24. package/dist/lib/encoders/encode-gltf.js.map +1 -0
  25. package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
  26. package/dist/{esm/lib → lib}/extensions/EXT_mesh_features.js +7 -5
  27. package/dist/lib/extensions/EXT_mesh_features.js.map +1 -0
  28. package/dist/{esm/lib → lib}/extensions/EXT_meshopt_compression.js +2 -2
  29. package/dist/lib/extensions/EXT_meshopt_compression.js.map +1 -0
  30. package/dist/{esm/lib → lib}/extensions/EXT_structural_metadata.js +7 -7
  31. package/dist/lib/extensions/EXT_structural_metadata.js.map +1 -0
  32. package/dist/{esm/lib → lib}/extensions/EXT_texture_webp.js +2 -2
  33. package/dist/lib/extensions/EXT_texture_webp.js.map +1 -0
  34. package/dist/{esm/lib → lib}/extensions/KHR_binary_gltf.js +1 -1
  35. package/dist/lib/extensions/KHR_binary_gltf.js.map +1 -0
  36. package/dist/{esm/lib → lib}/extensions/KHR_draco_mesh_compression.js +2 -2
  37. package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
  38. package/dist/{esm/lib → lib}/extensions/KHR_texture_basisu.js +1 -1
  39. package/dist/lib/extensions/KHR_texture_basisu.js.map +1 -0
  40. package/dist/{esm/lib → lib}/extensions/KHR_texture_transform.js +6 -6
  41. package/dist/lib/extensions/KHR_texture_transform.js.map +1 -0
  42. package/dist/{esm/lib → lib}/extensions/deprecated/EXT_feature_metadata.js +3 -3
  43. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
  44. package/dist/{esm/lib → lib}/extensions/deprecated/KHR_lights_punctual.js +2 -2
  45. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
  46. package/dist/{esm/lib → lib}/extensions/deprecated/KHR_materials_unlit.js +1 -1
  47. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
  48. package/dist/{esm/lib → lib}/extensions/deprecated/KHR_techniques_webgl.js +1 -1
  49. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
  50. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +1 -1
  51. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
  52. package/dist/{esm/lib → lib}/extensions/utils/3d-tiles-utils.js +6 -9
  53. package/dist/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  54. package/dist/lib/gltf-utils/get-typed-array.d.ts +10 -0
  55. package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
  56. package/dist/lib/gltf-utils/get-typed-array.js +51 -0
  57. package/dist/lib/gltf-utils/get-typed-array.js.map +1 -0
  58. package/dist/{esm/lib → lib}/gltf-utils/gltf-attribute-utils.js +1 -1
  59. package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
  60. package/dist/lib/gltf-utils/gltf-constants.js.map +1 -0
  61. package/dist/lib/gltf-utils/gltf-utils.d.ts +2 -2
  62. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  63. package/dist/{esm/lib → lib}/gltf-utils/gltf-utils.js +7 -32
  64. package/dist/lib/gltf-utils/gltf-utils.js.map +1 -0
  65. package/dist/{esm/lib → lib}/gltf-utils/resolve-url.js +1 -1
  66. package/dist/lib/gltf-utils/resolve-url.js.map +1 -0
  67. package/dist/{esm/lib → lib}/parsers/parse-glb.js +6 -2
  68. package/dist/lib/parsers/parse-glb.js.map +1 -0
  69. package/dist/{esm/lib → lib}/parsers/parse-gltf.js +7 -7
  70. package/dist/lib/parsers/parse-gltf.js.map +1 -0
  71. package/dist/lib/types/glb-types.js.map +1 -0
  72. package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  73. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +3 -1
  74. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
  75. package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
  76. package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
  77. package/dist/lib/types/gltf-json-schema.d.ts +7 -0
  78. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  79. package/dist/lib/types/gltf-json-schema.js.map +1 -0
  80. package/dist/lib/types/gltf-postprocessed-schema.js.map +1 -0
  81. package/dist/lib/types/gltf-types.d.ts +1 -1
  82. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  83. package/dist/lib/types/gltf-types.js.map +1 -0
  84. package/dist/lib/utils/assert.js.map +1 -0
  85. package/dist/lib/utils/version.js +2 -0
  86. package/dist/lib/utils/version.js.map +1 -0
  87. package/dist/{esm/meshopt → meshopt}/meshopt-decoder.js +1 -1
  88. package/dist/meshopt/meshopt-decoder.js.map +1 -0
  89. package/dist/{esm/webp → webp}/webp.js +1 -1
  90. package/dist/webp/webp.js.map +1 -0
  91. package/package.json +19 -11
  92. package/src/lib/api/gltf-scenegraph.ts +5 -17
  93. package/src/lib/extensions/EXT_mesh_features.ts +4 -2
  94. package/src/lib/extensions/utils/3d-tiles-utils.ts +17 -17
  95. package/src/lib/gltf-utils/get-typed-array.ts +53 -14
  96. package/src/lib/gltf-utils/gltf-utils.ts +3 -39
  97. package/src/lib/types/gltf-ext-mesh-features-schema.ts +3 -1
  98. package/src/lib/types/gltf-json-schema.ts +7 -0
  99. package/src/lib/types/gltf-types.ts +1 -1
  100. package/dist/bundle.d.ts +0 -2
  101. package/dist/bundle.d.ts.map +0 -1
  102. package/dist/es5/bundle.js +0 -6
  103. package/dist/es5/bundle.js.map +0 -1
  104. package/dist/es5/glb-loader.js +0 -54
  105. package/dist/es5/glb-loader.js.map +0 -1
  106. package/dist/es5/glb-writer.js +0 -34
  107. package/dist/es5/glb-writer.js.map +0 -1
  108. package/dist/es5/gltf-loader.js +0 -81
  109. package/dist/es5/gltf-loader.js.map +0 -1
  110. package/dist/es5/gltf-writer.js +0 -35
  111. package/dist/es5/gltf-writer.js.map +0 -1
  112. package/dist/es5/index.js +0 -88
  113. package/dist/es5/index.js.map +0 -1
  114. package/dist/es5/lib/api/gltf-extensions.js +0 -111
  115. package/dist/es5/lib/api/gltf-extensions.js.map +0 -1
  116. package/dist/es5/lib/api/gltf-scenegraph.js +0 -598
  117. package/dist/es5/lib/api/gltf-scenegraph.js.map +0 -1
  118. package/dist/es5/lib/api/normalize-gltf-v1.js +0 -331
  119. package/dist/es5/lib/api/normalize-gltf-v1.js.map +0 -1
  120. package/dist/es5/lib/api/post-process-gltf.js +0 -470
  121. package/dist/es5/lib/api/post-process-gltf.js.map +0 -1
  122. package/dist/es5/lib/encoders/encode-glb.js +0 -61
  123. package/dist/es5/lib/encoders/encode-glb.js.map +0 -1
  124. package/dist/es5/lib/encoders/encode-gltf.js +0 -20
  125. package/dist/es5/lib/encoders/encode-gltf.js.map +0 -1
  126. package/dist/es5/lib/extensions/EXT_mesh_features.js +0 -99
  127. package/dist/es5/lib/extensions/EXT_mesh_features.js.map +0 -1
  128. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +0 -94
  129. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +0 -1
  130. package/dist/es5/lib/extensions/EXT_structural_metadata.js +0 -375
  131. package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +0 -1
  132. package/dist/es5/lib/extensions/EXT_texture_webp.js +0 -43
  133. package/dist/es5/lib/extensions/EXT_texture_webp.js.map +0 -1
  134. package/dist/es5/lib/extensions/KHR_binary_gltf.js +0 -39
  135. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +0 -1
  136. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +0 -246
  137. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
  138. package/dist/es5/lib/extensions/KHR_texture_basisu.js +0 -36
  139. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +0 -1
  140. package/dist/es5/lib/extensions/KHR_texture_transform.js +0 -231
  141. package/dist/es5/lib/extensions/KHR_texture_transform.js.map +0 -1
  142. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +0 -260
  143. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
  144. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +0 -99
  145. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
  146. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +0 -76
  147. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
  148. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -113
  149. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
  150. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js +0 -254
  151. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
  152. package/dist/es5/lib/gltf-utils/get-typed-array.js +0 -23
  153. package/dist/es5/lib/gltf-utils/get-typed-array.js.map +0 -1
  154. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +0 -68
  155. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
  156. package/dist/es5/lib/gltf-utils/gltf-constants.js +0 -48
  157. package/dist/es5/lib/gltf-utils/gltf-constants.js.map +0 -1
  158. package/dist/es5/lib/gltf-utils/gltf-utils.js +0 -115
  159. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +0 -1
  160. package/dist/es5/lib/gltf-utils/resolve-url.js +0 -18
  161. package/dist/es5/lib/gltf-utils/resolve-url.js.map +0 -1
  162. package/dist/es5/lib/parsers/parse-glb.js +0 -120
  163. package/dist/es5/lib/parsers/parse-glb.js.map +0 -1
  164. package/dist/es5/lib/parsers/parse-gltf.js +0 -283
  165. package/dist/es5/lib/parsers/parse-gltf.js.map +0 -1
  166. package/dist/es5/lib/types/glb-types.js +0 -2
  167. package/dist/es5/lib/types/glb-types.js.map +0 -1
  168. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js +0 -2
  169. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
  170. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js +0 -2
  171. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
  172. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js +0 -2
  173. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
  174. package/dist/es5/lib/types/gltf-json-schema.js +0 -2
  175. package/dist/es5/lib/types/gltf-json-schema.js.map +0 -1
  176. package/dist/es5/lib/types/gltf-postprocessed-schema.js +0 -2
  177. package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +0 -1
  178. package/dist/es5/lib/types/gltf-types.js +0 -2
  179. package/dist/es5/lib/types/gltf-types.js.map +0 -1
  180. package/dist/es5/lib/utils/assert.js +0 -12
  181. package/dist/es5/lib/utils/assert.js.map +0 -1
  182. package/dist/es5/lib/utils/version.js +0 -9
  183. package/dist/es5/lib/utils/version.js.map +0 -1
  184. package/dist/es5/meshopt/meshopt-decoder.js +0 -215
  185. package/dist/es5/meshopt/meshopt-decoder.js.map +0 -1
  186. package/dist/es5/webp/webp.js +0 -83
  187. package/dist/es5/webp/webp.js.map +0 -1
  188. package/dist/esm/bundle.js +0 -4
  189. package/dist/esm/bundle.js.map +0 -1
  190. package/dist/esm/glb-loader.js.map +0 -1
  191. package/dist/esm/glb-writer.js.map +0 -1
  192. package/dist/esm/gltf-loader.js.map +0 -1
  193. package/dist/esm/gltf-writer.js.map +0 -1
  194. package/dist/esm/index.js +0 -13
  195. package/dist/esm/index.js.map +0 -1
  196. package/dist/esm/lib/api/gltf-extensions.js.map +0 -1
  197. package/dist/esm/lib/api/gltf-scenegraph.js.map +0 -1
  198. package/dist/esm/lib/api/normalize-gltf-v1.js.map +0 -1
  199. package/dist/esm/lib/api/post-process-gltf.js.map +0 -1
  200. package/dist/esm/lib/encoders/encode-glb.js.map +0 -1
  201. package/dist/esm/lib/encoders/encode-gltf.js.map +0 -1
  202. package/dist/esm/lib/extensions/EXT_mesh_features.js.map +0 -1
  203. package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +0 -1
  204. package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +0 -1
  205. package/dist/esm/lib/extensions/EXT_texture_webp.js.map +0 -1
  206. package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +0 -1
  207. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
  208. package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +0 -1
  209. package/dist/esm/lib/extensions/KHR_texture_transform.js.map +0 -1
  210. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
  211. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
  212. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
  213. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
  214. package/dist/esm/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
  215. package/dist/esm/lib/gltf-utils/get-typed-array.js +0 -16
  216. package/dist/esm/lib/gltf-utils/get-typed-array.js.map +0 -1
  217. package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
  218. package/dist/esm/lib/gltf-utils/gltf-constants.js.map +0 -1
  219. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +0 -1
  220. package/dist/esm/lib/gltf-utils/resolve-url.js.map +0 -1
  221. package/dist/esm/lib/parsers/parse-glb.js.map +0 -1
  222. package/dist/esm/lib/parsers/parse-gltf.js.map +0 -1
  223. package/dist/esm/lib/types/glb-types.js.map +0 -1
  224. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
  225. package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
  226. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
  227. package/dist/esm/lib/types/gltf-json-schema.js.map +0 -1
  228. package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +0 -1
  229. package/dist/esm/lib/types/gltf-types.js.map +0 -1
  230. package/dist/esm/lib/utils/assert.js.map +0 -1
  231. package/dist/esm/lib/utils/version.js +0 -2
  232. package/dist/esm/lib/utils/version.js.map +0 -1
  233. package/dist/esm/meshopt/meshopt-decoder.js.map +0 -1
  234. package/dist/esm/meshopt/meshopt-encoder.ts.disabled +0 -409
  235. package/dist/esm/webp/webp.js.map +0 -1
  236. package/src/bundle.ts +0 -4
  237. /package/dist/{esm/lib → lib}/encoders/encode-glb.js +0 -0
  238. /package/dist/{esm/lib → lib}/gltf-utils/gltf-constants.js +0 -0
  239. /package/dist/{esm/lib → lib}/types/glb-types.js +0 -0
  240. /package/dist/{esm/lib → lib}/types/gltf-ext-feature-metadata-schema.js +0 -0
  241. /package/dist/{esm/lib → lib}/types/gltf-ext-mesh-features-schema.js +0 -0
  242. /package/dist/{esm/lib → lib}/types/gltf-ext-structural-metadata-schema.js +0 -0
  243. /package/dist/{esm/lib → lib}/types/gltf-json-schema.js +0 -0
  244. /package/dist/{esm/lib → lib}/types/gltf-postprocessed-schema.js +0 -0
  245. /package/dist/{esm/lib → lib}/types/gltf-types.js +0 -0
  246. /package/dist/{esm/lib → lib}/utils/assert.js +0 -0
  247. /package/dist/{es5/meshopt → meshopt}/meshopt-encoder.ts.disabled +0 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,3558 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name12 in all)
8
+ __defProp(target, name12, { get: all[name12], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ EXT_FEATURE_METADATA: () => name3,
24
+ EXT_MESH_FEATURES: () => name,
25
+ EXT_STRUCTURAL_METADATA: () => name2,
26
+ GLBLoader: () => GLBLoader,
27
+ GLBWriter: () => GLBWriter,
28
+ GLTFLoader: () => GLTFLoader,
29
+ GLTFScenegraph: () => GLTFScenegraph,
30
+ GLTFWriter: () => GLTFWriter,
31
+ _getMemoryUsageGLTF: () => getMemoryUsageGLTF,
32
+ getPropertyTableFromExtFeatureMetadata: () => getPropertyTableFromExtFeatureMetadata,
33
+ getPropertyTableFromExtStructuralMetadata: () => getPropertyTableFromExtStructuralMetadata,
34
+ postProcessGLTF: () => postProcessGLTF
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/lib/extensions/EXT_mesh_features.ts
39
+ var EXT_mesh_features_exports = {};
40
+ __export(EXT_mesh_features_exports, {
41
+ decode: () => decode,
42
+ name: () => name
43
+ });
44
+
45
+ // src/lib/api/gltf-scenegraph.ts
46
+ var import_images = require("@loaders.gl/images");
47
+ var import_loader_utils = require("@loaders.gl/loader-utils");
48
+
49
+ // src/lib/utils/assert.ts
50
+ function assert(condition, message) {
51
+ if (!condition) {
52
+ throw new Error(message || "assert failed: gltf");
53
+ }
54
+ }
55
+
56
+ // src/lib/gltf-utils/gltf-constants.ts
57
+ var COMPONENTS = {
58
+ SCALAR: 1,
59
+ VEC2: 2,
60
+ VEC3: 3,
61
+ VEC4: 4,
62
+ MAT2: 4,
63
+ MAT3: 9,
64
+ MAT4: 16
65
+ };
66
+ var BYTES = {
67
+ 5120: 1,
68
+ // BYTE
69
+ 5121: 1,
70
+ // UNSIGNED_BYTE
71
+ 5122: 2,
72
+ // SHORT
73
+ 5123: 2,
74
+ // UNSIGNED_SHORT
75
+ 5125: 4,
76
+ // UNSIGNED_INT
77
+ 5126: 4
78
+ // FLOAT
79
+ };
80
+
81
+ // src/lib/gltf-utils/gltf-utils.ts
82
+ var MIPMAP_FACTOR = 1.33;
83
+ var TYPES = ["SCALAR", "VEC2", "VEC3", "VEC4"];
84
+ var ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
85
+ [Int8Array, 5120],
86
+ [Uint8Array, 5121],
87
+ [Int16Array, 5122],
88
+ [Uint16Array, 5123],
89
+ [Uint32Array, 5125],
90
+ [Float32Array, 5126],
91
+ [Float64Array, 5130]
92
+ ];
93
+ var ARRAY_TO_COMPONENT_TYPE = new Map(
94
+ ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT
95
+ );
96
+ var ATTRIBUTE_TYPE_TO_COMPONENTS = {
97
+ SCALAR: 1,
98
+ VEC2: 2,
99
+ VEC3: 3,
100
+ VEC4: 4,
101
+ MAT2: 4,
102
+ MAT3: 9,
103
+ MAT4: 16
104
+ };
105
+ var ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
106
+ 5120: 1,
107
+ 5121: 1,
108
+ 5122: 2,
109
+ 5123: 2,
110
+ 5125: 4,
111
+ 5126: 4
112
+ };
113
+ var ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
114
+ 5120: Int8Array,
115
+ 5121: Uint8Array,
116
+ 5122: Int16Array,
117
+ 5123: Uint16Array,
118
+ 5125: Uint32Array,
119
+ 5126: Float32Array
120
+ };
121
+ function getAccessorTypeFromSize(size) {
122
+ const type = TYPES[size - 1];
123
+ return type || TYPES[0];
124
+ }
125
+ function getComponentTypeFromArray(typedArray) {
126
+ const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);
127
+ if (!componentType) {
128
+ throw new Error("Illegal typed array");
129
+ }
130
+ return componentType;
131
+ }
132
+ function getAccessorArrayTypeAndLength(accessor, bufferView) {
133
+ const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
134
+ const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
135
+ const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];
136
+ const length = accessor.count * components;
137
+ const byteLength = accessor.count * components * bytesPerComponent;
138
+ assert(byteLength >= 0 && byteLength <= bufferView.byteLength);
139
+ const componentByteSize = BYTES[accessor.componentType];
140
+ const numberOfComponentsInElement = COMPONENTS[accessor.type];
141
+ return { ArrayType, length, byteLength, componentByteSize, numberOfComponentsInElement };
142
+ }
143
+ function getMemoryUsageGLTF(gltf) {
144
+ let { images, bufferViews } = gltf;
145
+ images = images || [];
146
+ bufferViews = bufferViews || [];
147
+ const imageBufferViews = images.map((i) => i.bufferView);
148
+ bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view));
149
+ const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
150
+ const pixelCount = images.reduce((acc, image) => {
151
+ const { width, height } = image.image;
152
+ return acc + width * height;
153
+ }, 0);
154
+ return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);
155
+ }
156
+
157
+ // src/lib/gltf-utils/get-typed-array.ts
158
+ function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {
159
+ const bufferView = json.bufferViews[bufferViewIndex];
160
+ assert(bufferView);
161
+ const bufferIndex = bufferView.buffer;
162
+ const binChunk = buffers[bufferIndex];
163
+ assert(binChunk);
164
+ const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
165
+ return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
166
+ }
167
+ function getTypedArrayForAccessor(json, buffers, accessor) {
168
+ var _a, _b;
169
+ const gltfAccessor = typeof accessor === "number" ? (_a = json.accessors) == null ? void 0 : _a[accessor] : accessor;
170
+ if (!gltfAccessor) {
171
+ throw new Error(`No gltf accessor ${accessor}`);
172
+ }
173
+ const bufferView = (_b = json.bufferViews) == null ? void 0 : _b[gltfAccessor.bufferView || 0];
174
+ if (!bufferView) {
175
+ throw new Error(`No gltf buffer view for accessor ${bufferView}`);
176
+ }
177
+ const { arrayBuffer, byteOffset: bufferByteOffset } = buffers[bufferView.buffer];
178
+ const byteOffset = (bufferByteOffset || 0) + (gltfAccessor.byteOffset || 0) + (bufferView.byteOffset || 0);
179
+ const { ArrayType, length, componentByteSize, numberOfComponentsInElement } = getAccessorArrayTypeAndLength(gltfAccessor, bufferView);
180
+ const elementByteSize = componentByteSize * numberOfComponentsInElement;
181
+ const elementAddressScale = bufferView.byteStride || elementByteSize;
182
+ if (typeof bufferView.byteStride === "undefined" || bufferView.byteStride === elementByteSize) {
183
+ const result2 = new ArrayType(arrayBuffer, byteOffset, length);
184
+ return result2;
185
+ }
186
+ const result = new ArrayType(length);
187
+ for (let i = 0; i < gltfAccessor.count; i++) {
188
+ const values = new ArrayType(
189
+ arrayBuffer,
190
+ byteOffset + i * elementAddressScale,
191
+ numberOfComponentsInElement
192
+ );
193
+ result.set(values, i * numberOfComponentsInElement);
194
+ }
195
+ return result;
196
+ }
197
+
198
+ // src/lib/api/gltf-scenegraph.ts
199
+ function makeDefaultGLTFJson() {
200
+ return {
201
+ asset: {
202
+ version: "2.0",
203
+ generator: "loaders.gl"
204
+ },
205
+ buffers: [],
206
+ extensions: {},
207
+ extensionsRequired: [],
208
+ extensionsUsed: []
209
+ };
210
+ }
211
+ var GLTFScenegraph = class {
212
+ // TODO - why is this not GLTFWithBuffers - what happens to images?
213
+ constructor(gltf) {
214
+ this.gltf = {
215
+ json: (gltf == null ? void 0 : gltf.json) || makeDefaultGLTFJson(),
216
+ buffers: (gltf == null ? void 0 : gltf.buffers) || [],
217
+ images: (gltf == null ? void 0 : gltf.images) || []
218
+ };
219
+ this.sourceBuffers = [];
220
+ this.byteLength = 0;
221
+ if (this.gltf.buffers && this.gltf.buffers[0]) {
222
+ this.byteLength = this.gltf.buffers[0].byteLength;
223
+ this.sourceBuffers = [this.gltf.buffers[0]];
224
+ }
225
+ }
226
+ // Accessors
227
+ get json() {
228
+ return this.gltf.json;
229
+ }
230
+ getApplicationData(key) {
231
+ const data = this.json[key];
232
+ return data;
233
+ }
234
+ getExtraData(key) {
235
+ const extras = this.json.extras || {};
236
+ return extras[key];
237
+ }
238
+ hasExtension(extensionName) {
239
+ const isUsedExtension = this.getUsedExtensions().find((name12) => name12 === extensionName);
240
+ const isRequiredExtension = this.getRequiredExtensions().find((name12) => name12 === extensionName);
241
+ return typeof isUsedExtension === "string" || typeof isRequiredExtension === "string";
242
+ }
243
+ getExtension(extensionName) {
244
+ const isExtension = this.getUsedExtensions().find((name12) => name12 === extensionName);
245
+ const extensions = this.json.extensions || {};
246
+ return isExtension ? extensions[extensionName] : null;
247
+ }
248
+ getRequiredExtension(extensionName) {
249
+ const isRequired = this.getRequiredExtensions().find((name12) => name12 === extensionName);
250
+ return isRequired ? this.getExtension(extensionName) : null;
251
+ }
252
+ getRequiredExtensions() {
253
+ return this.json.extensionsRequired || [];
254
+ }
255
+ getUsedExtensions() {
256
+ return this.json.extensionsUsed || [];
257
+ }
258
+ getRemovedExtensions() {
259
+ return this.json.extensionsRemoved || [];
260
+ }
261
+ getObjectExtension(object, extensionName) {
262
+ const extensions = object.extensions || {};
263
+ return extensions[extensionName];
264
+ }
265
+ getScene(index) {
266
+ return this.getObject("scenes", index);
267
+ }
268
+ getNode(index) {
269
+ return this.getObject("nodes", index);
270
+ }
271
+ getSkin(index) {
272
+ return this.getObject("skins", index);
273
+ }
274
+ getMesh(index) {
275
+ return this.getObject("meshes", index);
276
+ }
277
+ getMaterial(index) {
278
+ return this.getObject("materials", index);
279
+ }
280
+ getAccessor(index) {
281
+ return this.getObject("accessors", index);
282
+ }
283
+ // getCamera(index: number): object | null {
284
+ // return null; // TODO: fix thi: object as null;
285
+ // }
286
+ getTexture(index) {
287
+ return this.getObject("textures", index);
288
+ }
289
+ getSampler(index) {
290
+ return this.getObject("samplers", index);
291
+ }
292
+ getImage(index) {
293
+ return this.getObject("images", index);
294
+ }
295
+ getBufferView(index) {
296
+ return this.getObject("bufferViews", index);
297
+ }
298
+ getBuffer(index) {
299
+ return this.getObject("buffers", index);
300
+ }
301
+ getObject(array, index) {
302
+ if (typeof index === "object") {
303
+ return index;
304
+ }
305
+ const object = this.json[array] && this.json[array][index];
306
+ if (!object) {
307
+ throw new Error(`glTF file error: Could not find ${array}[${index}]`);
308
+ }
309
+ return object;
310
+ }
311
+ /**
312
+ * Accepts buffer view index or buffer view object
313
+ * @returns a `Uint8Array`
314
+ */
315
+ getTypedArrayForBufferView(bufferView) {
316
+ bufferView = this.getBufferView(bufferView);
317
+ const bufferIndex = bufferView.buffer;
318
+ const binChunk = this.gltf.buffers[bufferIndex];
319
+ assert(binChunk);
320
+ const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
321
+ return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
322
+ }
323
+ /** Accepts accessor index or accessor object
324
+ * @returns a typed array with type that matches the types
325
+ */
326
+ getTypedArrayForAccessor(accessor) {
327
+ const gltfAccessor = this.getAccessor(accessor);
328
+ return getTypedArrayForAccessor(this.gltf.json, this.gltf.buffers, gltfAccessor);
329
+ }
330
+ /** accepts accessor index or accessor object
331
+ * returns a `Uint8Array`
332
+ */
333
+ getTypedArrayForImageData(image) {
334
+ image = this.getAccessor(image);
335
+ const bufferView = this.getBufferView(image.bufferView);
336
+ const buffer = this.getBuffer(bufferView.buffer);
337
+ const arrayBuffer = buffer.data;
338
+ const byteOffset = bufferView.byteOffset || 0;
339
+ return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
340
+ }
341
+ // MODIFERS
342
+ /**
343
+ * Add an extra application-defined key to the top-level data structure
344
+ */
345
+ addApplicationData(key, data) {
346
+ this.json[key] = data;
347
+ return this;
348
+ }
349
+ /**
350
+ * `extras` - Standard GLTF field for storing application specific data
351
+ */
352
+ addExtraData(key, data) {
353
+ this.json.extras = this.json.extras || {};
354
+ this.json.extras[key] = data;
355
+ return this;
356
+ }
357
+ addObjectExtension(object, extensionName, data) {
358
+ object.extensions = object.extensions || {};
359
+ object.extensions[extensionName] = data;
360
+ this.registerUsedExtension(extensionName);
361
+ return this;
362
+ }
363
+ setObjectExtension(object, extensionName, data) {
364
+ const extensions = object.extensions || {};
365
+ extensions[extensionName] = data;
366
+ }
367
+ removeObjectExtension(object, extensionName) {
368
+ const extensions = (object == null ? void 0 : object.extensions) || {};
369
+ if (extensions[extensionName]) {
370
+ this.json.extensionsRemoved = this.json.extensionsRemoved || [];
371
+ const extensionsRemoved = this.json.extensionsRemoved;
372
+ if (!extensionsRemoved.includes(extensionName)) {
373
+ extensionsRemoved.push(extensionName);
374
+ }
375
+ }
376
+ delete extensions[extensionName];
377
+ }
378
+ /**
379
+ * Add to standard GLTF top level extension object, mark as used
380
+ */
381
+ addExtension(extensionName, extensionData = {}) {
382
+ assert(extensionData);
383
+ this.json.extensions = this.json.extensions || {};
384
+ this.json.extensions[extensionName] = extensionData;
385
+ this.registerUsedExtension(extensionName);
386
+ return extensionData;
387
+ }
388
+ /**
389
+ * Standard GLTF top level extension object, mark as used and required
390
+ */
391
+ addRequiredExtension(extensionName, extensionData = {}) {
392
+ assert(extensionData);
393
+ this.addExtension(extensionName, extensionData);
394
+ this.registerRequiredExtension(extensionName);
395
+ return extensionData;
396
+ }
397
+ /**
398
+ * Add extensionName to list of used extensions
399
+ */
400
+ registerUsedExtension(extensionName) {
401
+ this.json.extensionsUsed = this.json.extensionsUsed || [];
402
+ if (!this.json.extensionsUsed.find((ext) => ext === extensionName)) {
403
+ this.json.extensionsUsed.push(extensionName);
404
+ }
405
+ }
406
+ /**
407
+ * Add extensionName to list of required extensions
408
+ */
409
+ registerRequiredExtension(extensionName) {
410
+ this.registerUsedExtension(extensionName);
411
+ this.json.extensionsRequired = this.json.extensionsRequired || [];
412
+ if (!this.json.extensionsRequired.find((ext) => ext === extensionName)) {
413
+ this.json.extensionsRequired.push(extensionName);
414
+ }
415
+ }
416
+ /**
417
+ * Removes an extension from the top-level list
418
+ */
419
+ removeExtension(extensionName) {
420
+ var _a;
421
+ if ((_a = this.json.extensions) == null ? void 0 : _a[extensionName]) {
422
+ this.json.extensionsRemoved = this.json.extensionsRemoved || [];
423
+ const extensionsRemoved = this.json.extensionsRemoved;
424
+ if (!extensionsRemoved.includes(extensionName)) {
425
+ extensionsRemoved.push(extensionName);
426
+ }
427
+ }
428
+ if (this.json.extensions) {
429
+ delete this.json.extensions[extensionName];
430
+ }
431
+ if (this.json.extensionsRequired) {
432
+ this._removeStringFromArray(this.json.extensionsRequired, extensionName);
433
+ }
434
+ if (this.json.extensionsUsed) {
435
+ this._removeStringFromArray(this.json.extensionsUsed, extensionName);
436
+ }
437
+ }
438
+ /**
439
+ * Set default scene which is to be displayed at load time
440
+ */
441
+ setDefaultScene(sceneIndex) {
442
+ this.json.scene = sceneIndex;
443
+ }
444
+ /**
445
+ * @todo: add more properties for scene initialization:
446
+ * name`, `extensions`, `extras`
447
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-scene
448
+ */
449
+ addScene(scene) {
450
+ const { nodeIndices } = scene;
451
+ this.json.scenes = this.json.scenes || [];
452
+ this.json.scenes.push({ nodes: nodeIndices });
453
+ return this.json.scenes.length - 1;
454
+ }
455
+ /**
456
+ * @todo: add more properties for node initialization:
457
+ * `name`, `extensions`, `extras`, `camera`, `children`, `skin`, `rotation`, `scale`, `translation`, `weights`
458
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#node
459
+ */
460
+ addNode(node) {
461
+ const { meshIndex, matrix } = node;
462
+ this.json.nodes = this.json.nodes || [];
463
+ const nodeData = { mesh: meshIndex };
464
+ if (matrix) {
465
+ nodeData.matrix = matrix;
466
+ }
467
+ this.json.nodes.push(nodeData);
468
+ return this.json.nodes.length - 1;
469
+ }
470
+ /** Adds a mesh to the json part */
471
+ addMesh(mesh) {
472
+ const { attributes, indices, material, mode = 4 } = mesh;
473
+ const accessors = this._addAttributes(attributes);
474
+ const glTFMesh = {
475
+ primitives: [
476
+ {
477
+ attributes: accessors,
478
+ mode
479
+ }
480
+ ]
481
+ };
482
+ if (indices) {
483
+ const indicesAccessor = this._addIndices(indices);
484
+ glTFMesh.primitives[0].indices = indicesAccessor;
485
+ }
486
+ if (Number.isFinite(material)) {
487
+ glTFMesh.primitives[0].material = material;
488
+ }
489
+ this.json.meshes = this.json.meshes || [];
490
+ this.json.meshes.push(glTFMesh);
491
+ return this.json.meshes.length - 1;
492
+ }
493
+ addPointCloud(attributes) {
494
+ const accessorIndices = this._addAttributes(attributes);
495
+ const glTFMesh = {
496
+ primitives: [
497
+ {
498
+ attributes: accessorIndices,
499
+ mode: 0
500
+ // GL.POINTS
501
+ }
502
+ ]
503
+ };
504
+ this.json.meshes = this.json.meshes || [];
505
+ this.json.meshes.push(glTFMesh);
506
+ return this.json.meshes.length - 1;
507
+ }
508
+ /**
509
+ * Adds a binary image. Builds glTF "JSON metadata" and saves buffer reference
510
+ * Buffer will be copied into BIN chunk during "pack"
511
+ * Currently encodes as glTF image
512
+ * @param imageData
513
+ * @param mimeType
514
+ */
515
+ addImage(imageData, mimeTypeOpt) {
516
+ const metadata = (0, import_images.getBinaryImageMetadata)(imageData);
517
+ const mimeType = mimeTypeOpt || (metadata == null ? void 0 : metadata.mimeType);
518
+ const bufferViewIndex = this.addBufferView(imageData);
519
+ const glTFImage = {
520
+ bufferView: bufferViewIndex,
521
+ mimeType
522
+ };
523
+ this.json.images = this.json.images || [];
524
+ this.json.images.push(glTFImage);
525
+ return this.json.images.length - 1;
526
+ }
527
+ /**
528
+ * Add one untyped source buffer, create a matching glTF `bufferView`, and return its index
529
+ * @param buffer
530
+ */
531
+ addBufferView(buffer, bufferIndex = 0, byteOffset = this.byteLength) {
532
+ const byteLength = buffer.byteLength;
533
+ assert(Number.isFinite(byteLength));
534
+ this.sourceBuffers = this.sourceBuffers || [];
535
+ this.sourceBuffers.push(buffer);
536
+ const glTFBufferView = {
537
+ buffer: bufferIndex,
538
+ // Write offset from the start of the binary body
539
+ byteOffset,
540
+ byteLength
541
+ };
542
+ this.byteLength += (0, import_loader_utils.padToNBytes)(byteLength, 4);
543
+ this.json.bufferViews = this.json.bufferViews || [];
544
+ this.json.bufferViews.push(glTFBufferView);
545
+ return this.json.bufferViews.length - 1;
546
+ }
547
+ /**
548
+ * Adds an accessor to a bufferView
549
+ * @param bufferViewIndex
550
+ * @param accessor
551
+ */
552
+ addAccessor(bufferViewIndex, accessor) {
553
+ const glTFAccessor = {
554
+ bufferView: bufferViewIndex,
555
+ // @ts-ignore
556
+ type: getAccessorTypeFromSize(accessor.size),
557
+ // @ts-ignore
558
+ componentType: accessor.componentType,
559
+ // @ts-ignore
560
+ count: accessor.count,
561
+ // @ts-ignore
562
+ max: accessor.max,
563
+ // @ts-ignore
564
+ min: accessor.min
565
+ };
566
+ this.json.accessors = this.json.accessors || [];
567
+ this.json.accessors.push(glTFAccessor);
568
+ return this.json.accessors.length - 1;
569
+ }
570
+ /**
571
+ * Add a binary buffer. Builds glTF "JSON metadata" and saves buffer reference
572
+ * Buffer will be copied into BIN chunk during "pack"
573
+ * Currently encodes buffers as glTF accessors, but this could be optimized
574
+ * @param sourceBuffer
575
+ * @param accessor
576
+ */
577
+ addBinaryBuffer(sourceBuffer, accessor = { size: 3 }) {
578
+ const bufferViewIndex = this.addBufferView(sourceBuffer);
579
+ let minMax = { min: accessor.min, max: accessor.max };
580
+ if (!minMax.min || !minMax.max) {
581
+ minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
582
+ }
583
+ const accessorDefaults = {
584
+ // @ts-ignore
585
+ size: accessor.size,
586
+ componentType: getComponentTypeFromArray(sourceBuffer),
587
+ // @ts-ignore
588
+ count: Math.round(sourceBuffer.length / accessor.size),
589
+ min: minMax.min,
590
+ max: minMax.max
591
+ };
592
+ return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
593
+ }
594
+ /**
595
+ * Adds a texture to the json part
596
+ * @todo: add more properties for texture initialization
597
+ * `sampler`, `name`, `extensions`, `extras`
598
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture
599
+ */
600
+ addTexture(texture) {
601
+ const { imageIndex } = texture;
602
+ const glTFTexture = {
603
+ source: imageIndex
604
+ };
605
+ this.json.textures = this.json.textures || [];
606
+ this.json.textures.push(glTFTexture);
607
+ return this.json.textures.length - 1;
608
+ }
609
+ /** Adds a material to the json part */
610
+ addMaterial(pbrMaterialInfo) {
611
+ this.json.materials = this.json.materials || [];
612
+ this.json.materials.push(pbrMaterialInfo);
613
+ return this.json.materials.length - 1;
614
+ }
615
+ /** Pack the binary chunk */
616
+ createBinaryChunk() {
617
+ var _a, _b;
618
+ this.gltf.buffers = [];
619
+ const totalByteLength = this.byteLength;
620
+ const arrayBuffer = new ArrayBuffer(totalByteLength);
621
+ const targetArray = new Uint8Array(arrayBuffer);
622
+ let dstByteOffset = 0;
623
+ for (const sourceBuffer of this.sourceBuffers || []) {
624
+ dstByteOffset = (0, import_loader_utils.copyToArray)(sourceBuffer, targetArray, dstByteOffset);
625
+ }
626
+ if ((_b = (_a = this.json) == null ? void 0 : _a.buffers) == null ? void 0 : _b[0]) {
627
+ this.json.buffers[0].byteLength = totalByteLength;
628
+ } else {
629
+ this.json.buffers = [{ byteLength: totalByteLength }];
630
+ }
631
+ this.gltf.binary = arrayBuffer;
632
+ this.sourceBuffers = [arrayBuffer];
633
+ }
634
+ // PRIVATE
635
+ _removeStringFromArray(array, string) {
636
+ let found = true;
637
+ while (found) {
638
+ const index = array.indexOf(string);
639
+ if (index > -1) {
640
+ array.splice(index, 1);
641
+ } else {
642
+ found = false;
643
+ }
644
+ }
645
+ }
646
+ /**
647
+ * Add attributes to buffers and create `attributes` object which is part of `mesh`
648
+ */
649
+ _addAttributes(attributes = {}) {
650
+ const result = {};
651
+ for (const attributeKey in attributes) {
652
+ const attributeData = attributes[attributeKey];
653
+ const attrName = this._getGltfAttributeName(attributeKey);
654
+ const accessor = this.addBinaryBuffer(attributeData.value, attributeData);
655
+ result[attrName] = accessor;
656
+ }
657
+ return result;
658
+ }
659
+ /**
660
+ * Add indices to buffers
661
+ */
662
+ _addIndices(indices) {
663
+ return this.addBinaryBuffer(indices, { size: 1 });
664
+ }
665
+ /**
666
+ * Deduce gltf specific attribue name from input attribute name
667
+ */
668
+ _getGltfAttributeName(attributeName) {
669
+ switch (attributeName.toLowerCase()) {
670
+ case "position":
671
+ case "positions":
672
+ case "vertices":
673
+ return "POSITION";
674
+ case "normal":
675
+ case "normals":
676
+ return "NORMAL";
677
+ case "color":
678
+ case "colors":
679
+ return "COLOR_0";
680
+ case "texcoord":
681
+ case "texcoords":
682
+ return "TEXCOORD_0";
683
+ default:
684
+ return attributeName;
685
+ }
686
+ }
687
+ /**
688
+ * Calculate `min` and `max` arrays of accessor according to spec:
689
+ * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#reference-accessor
690
+ */
691
+ _getAccessorMinMax(buffer, size) {
692
+ const result = { min: null, max: null };
693
+ if (buffer.length < size) {
694
+ return result;
695
+ }
696
+ result.min = [];
697
+ result.max = [];
698
+ const initValues = buffer.subarray(0, size);
699
+ for (const value of initValues) {
700
+ result.min.push(value);
701
+ result.max.push(value);
702
+ }
703
+ for (let index = size; index < buffer.length; index += size) {
704
+ for (let componentIndex = 0; componentIndex < size; componentIndex++) {
705
+ result.min[0 + componentIndex] = Math.min(
706
+ // @ts-ignore
707
+ result.min[0 + componentIndex],
708
+ buffer[index + componentIndex]
709
+ );
710
+ result.max[0 + componentIndex] = Math.max(
711
+ // @ts-ignore
712
+ result.max[0 + componentIndex],
713
+ buffer[index + componentIndex]
714
+ );
715
+ }
716
+ }
717
+ return result;
718
+ }
719
+ };
720
+
721
+ // src/lib/extensions/utils/3d-tiles-utils.ts
722
+ var import_images2 = require("@loaders.gl/images");
723
+ var import_math = require("@loaders.gl/math");
724
+ var ATTRIBUTE_TYPE_TO_COMPONENTS2 = {
725
+ SCALAR: 1,
726
+ VEC2: 2,
727
+ VEC3: 3,
728
+ VEC4: 4,
729
+ MAT2: 4,
730
+ MAT3: 9,
731
+ MAT4: 16,
732
+ BOOLEAN: 1,
733
+ STRING: 1,
734
+ ENUM: 1
735
+ };
736
+ var ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2 = {
737
+ INT8: Int8Array,
738
+ UINT8: Uint8Array,
739
+ INT16: Int16Array,
740
+ UINT16: Uint16Array,
741
+ INT32: Int32Array,
742
+ UINT32: Uint32Array,
743
+ INT64: BigInt64Array,
744
+ UINT64: BigUint64Array,
745
+ FLOAT32: Float32Array,
746
+ FLOAT64: Float64Array
747
+ };
748
+ var ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2 = {
749
+ INT8: 1,
750
+ UINT8: 1,
751
+ INT16: 2,
752
+ UINT16: 2,
753
+ INT32: 4,
754
+ UINT32: 4,
755
+ INT64: 8,
756
+ UINT64: 8,
757
+ FLOAT32: 4,
758
+ FLOAT64: 8
759
+ };
760
+ function getArrayElementByteSize(attributeType, componentType) {
761
+ return ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType] * ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType];
762
+ }
763
+ function getOffsetsForProperty(scenegraph, bufferViewIndex, offsetType, numberOfElements) {
764
+ if (offsetType !== "UINT8" && offsetType !== "UINT16" && offsetType !== "UINT32" && offsetType !== "UINT64") {
765
+ return null;
766
+ }
767
+ const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(bufferViewIndex);
768
+ const arrayOffsets = convertRawBufferToMetadataArray(
769
+ arrayOffsetsBytes,
770
+ "SCALAR",
771
+ // offsets consist of ONE component
772
+ offsetType,
773
+ numberOfElements + 1
774
+ // The number of offsets is equal to the property table `count` plus one.
775
+ );
776
+ if (arrayOffsets instanceof BigInt64Array || arrayOffsets instanceof BigUint64Array) {
777
+ return null;
778
+ }
779
+ return arrayOffsets;
780
+ }
781
+ function convertRawBufferToMetadataArray(data, attributeType, componentType, elementCount = 1) {
782
+ const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS2[attributeType];
783
+ const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY2[componentType];
784
+ const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE2[componentType];
785
+ const length = elementCount * numberOfComponents;
786
+ const byteLength = length * size;
787
+ let buffer = data.buffer;
788
+ let offset = data.byteOffset;
789
+ if (offset % size !== 0) {
790
+ const bufferArray = new Uint8Array(buffer);
791
+ buffer = bufferArray.slice(offset, offset + byteLength).buffer;
792
+ offset = 0;
793
+ }
794
+ return new ArrayType(buffer, offset, length);
795
+ }
796
+ function getPrimitiveTextureData(scenegraph, textureInfo, primitive) {
797
+ var _a, _b, _c, _d, _e;
798
+ const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;
799
+ const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
800
+ const textureCoordinates = scenegraph.getTypedArrayForAccessor(texCoordAccessorIndex);
801
+ const json = scenegraph.gltf.json;
802
+ const textureIndex = textureInfo.index;
803
+ const imageIndex = (_b = (_a = json.textures) == null ? void 0 : _a[textureIndex]) == null ? void 0 : _b.source;
804
+ if (typeof imageIndex !== "undefined") {
805
+ const mimeType = (_d = (_c = json.images) == null ? void 0 : _c[imageIndex]) == null ? void 0 : _d.mimeType;
806
+ const parsedImage = (_e = scenegraph.gltf.images) == null ? void 0 : _e[imageIndex];
807
+ if (parsedImage && typeof parsedImage.width !== "undefined") {
808
+ const textureData = [];
809
+ for (let index = 0; index < textureCoordinates.length; index += 2) {
810
+ const value = getImageValueByCoordinates(
811
+ parsedImage,
812
+ mimeType,
813
+ textureCoordinates,
814
+ index,
815
+ textureInfo.channels
816
+ );
817
+ textureData.push(value);
818
+ }
819
+ return textureData;
820
+ }
821
+ }
822
+ return [];
823
+ }
824
+ function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) {
825
+ if (!(propertyData == null ? void 0 : propertyData.length)) {
826
+ return;
827
+ }
828
+ const featureIndices = [];
829
+ for (const texelData of propertyData) {
830
+ let index = featureTable.findIndex((item) => item === texelData);
831
+ if (index === -1) {
832
+ index = featureTable.push(texelData) - 1;
833
+ }
834
+ featureIndices.push(index);
835
+ }
836
+ const typedArray = new Uint32Array(featureIndices);
837
+ const bufferIndex = scenegraph.gltf.buffers.push({
838
+ arrayBuffer: typedArray.buffer,
839
+ byteOffset: typedArray.byteOffset,
840
+ byteLength: typedArray.byteLength
841
+ }) - 1;
842
+ const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
843
+ const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
844
+ size: 1,
845
+ componentType: getComponentTypeFromArray(typedArray),
846
+ count: typedArray.length
847
+ });
848
+ primitive.attributes[attributeName] = accessorIndex;
849
+ }
850
+ function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels = [0]) {
851
+ const CHANNELS_MAP = {
852
+ r: { offset: 0, shift: 0 },
853
+ g: { offset: 1, shift: 8 },
854
+ b: { offset: 2, shift: 16 },
855
+ a: { offset: 3, shift: 24 }
856
+ };
857
+ const u = textureCoordinates[index];
858
+ const v = textureCoordinates[index + 1];
859
+ let components = 1;
860
+ if (mimeType && (mimeType.indexOf("image/jpeg") !== -1 || mimeType.indexOf("image/png") !== -1))
861
+ components = 4;
862
+ const offset = coordinatesToOffset(u, v, parsedImage, components);
863
+ let value = 0;
864
+ for (const c of channels) {
865
+ const map = typeof c === "number" ? Object.values(CHANNELS_MAP)[c] : CHANNELS_MAP[c];
866
+ const imageOffset = offset + map.offset;
867
+ const imageData = (0, import_images2.getImageData)(parsedImage);
868
+ if (imageData.data.length <= imageOffset) {
869
+ throw new Error(`${imageData.data.length} <= ${imageOffset}`);
870
+ }
871
+ const imageValue = imageData.data[imageOffset];
872
+ value |= imageValue << map.shift;
873
+ }
874
+ return value;
875
+ }
876
+ function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) {
877
+ const w = parsedImage.width;
878
+ const iX = (0, import_math.emod)(u) * (w - 1);
879
+ const indX = Math.round(iX);
880
+ const h = parsedImage.height;
881
+ const iY = (0, import_math.emod)(v) * (h - 1);
882
+ const indY = Math.round(iY);
883
+ const components = parsedImage.components ? parsedImage.components : componentsCount;
884
+ const offset = (indY * w + indX) * components;
885
+ return offset;
886
+ }
887
+ function parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, valueSize) {
888
+ const attributeValueArray = [];
889
+ for (let index = 0; index < numberOfElements; index++) {
890
+ const arrayOffset = arrayOffsets[index];
891
+ const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
892
+ if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
893
+ break;
894
+ }
895
+ const typedArrayOffset = arrayOffset / valueSize;
896
+ const elementCount = arrayByteSize / valueSize;
897
+ attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount));
898
+ }
899
+ return attributeValueArray;
900
+ }
901
+ function parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount) {
902
+ const attributeValueArray = [];
903
+ for (let index = 0; index < numberOfElements; index++) {
904
+ const elementOffset = index * arrayCount;
905
+ attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount));
906
+ }
907
+ return attributeValueArray;
908
+ }
909
+ function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets) {
910
+ if (arrayOffsets) {
911
+ throw new Error("Not implemented - arrayOffsets for strings is specified");
912
+ }
913
+ if (stringOffsets) {
914
+ const stringsArray = [];
915
+ const textDecoder = new TextDecoder("utf8");
916
+ let stringOffset = 0;
917
+ for (let index = 0; index < numberOfElements; index++) {
918
+ const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];
919
+ if (stringByteSize + stringOffset <= valuesDataBytes.length) {
920
+ const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);
921
+ const stringAttribute = textDecoder.decode(stringData);
922
+ stringsArray.push(stringAttribute);
923
+ stringOffset += stringByteSize;
924
+ }
925
+ }
926
+ return stringsArray;
927
+ }
928
+ return [];
929
+ }
930
+
931
+ // src/lib/extensions/EXT_mesh_features.ts
932
+ var EXT_MESH_FEATURES_NAME = "EXT_mesh_features";
933
+ var name = EXT_MESH_FEATURES_NAME;
934
+ async function decode(gltfData, options) {
935
+ const scenegraph = new GLTFScenegraph(gltfData);
936
+ decodeExtMeshFeatures(scenegraph, options);
937
+ }
938
+ function decodeExtMeshFeatures(scenegraph, options) {
939
+ const json = scenegraph.gltf.json;
940
+ if (!json.meshes) {
941
+ return;
942
+ }
943
+ for (const mesh of json.meshes) {
944
+ for (const primitive of mesh.primitives) {
945
+ processMeshPrimitiveFeatures(scenegraph, primitive, options);
946
+ }
947
+ }
948
+ }
949
+ function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
950
+ var _a, _b, _c;
951
+ if (!((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.loadBuffers)) {
952
+ return;
953
+ }
954
+ const extension = (_b = primitive.extensions) == null ? void 0 : _b[EXT_MESH_FEATURES_NAME];
955
+ const featureIds = extension == null ? void 0 : extension.featureIds;
956
+ if (!featureIds) {
957
+ return;
958
+ }
959
+ for (const featureId of featureIds) {
960
+ let featureIdData;
961
+ if (typeof featureId.attribute !== "undefined") {
962
+ const accessorKey = `_FEATURE_ID_${featureId.attribute}`;
963
+ const accessorIndex = primitive.attributes[accessorKey];
964
+ featureIdData = scenegraph.getTypedArrayForAccessor(accessorIndex);
965
+ } else if (typeof featureId.texture !== "undefined" && ((_c = options == null ? void 0 : options.gltf) == null ? void 0 : _c.loadImages)) {
966
+ featureIdData = getPrimitiveTextureData(scenegraph, featureId.texture, primitive);
967
+ } else {
968
+ featureIdData = [];
969
+ }
970
+ featureId.data = featureIdData;
971
+ }
972
+ }
973
+
974
+ // src/lib/extensions/EXT_structural_metadata.ts
975
+ var EXT_structural_metadata_exports = {};
976
+ __export(EXT_structural_metadata_exports, {
977
+ decode: () => decode2,
978
+ getPropertyTableFromExtStructuralMetadata: () => getPropertyTableFromExtStructuralMetadata,
979
+ name: () => name2
980
+ });
981
+ var EXT_STRUCTURAL_METADATA_NAME = "EXT_structural_metadata";
982
+ var name2 = EXT_STRUCTURAL_METADATA_NAME;
983
+ async function decode2(gltfData, options) {
984
+ const scenegraph = new GLTFScenegraph(gltfData);
985
+ decodeExtStructuralMetadata(scenegraph, options);
986
+ }
987
+ function getPropertyTableFromExtStructuralMetadata(extension, metadataClass) {
988
+ if (extension.propertyTables) {
989
+ const firstPropertyTable = extension == null ? void 0 : extension.propertyTables[0];
990
+ const propertyTableWithData = {};
991
+ for (const propertyName in firstPropertyTable.properties) {
992
+ propertyTableWithData[propertyName] = firstPropertyTable.properties[propertyName].data;
993
+ }
994
+ return propertyTableWithData;
995
+ }
996
+ if (extension.propertyTextures) {
997
+ const firstPropertyTexture = extension == null ? void 0 : extension.propertyTextures[0];
998
+ const propertyTableWithData = {};
999
+ for (const propertyName in firstPropertyTexture.properties) {
1000
+ propertyTableWithData[propertyName] = firstPropertyTexture.properties[propertyName].data;
1001
+ }
1002
+ return propertyTableWithData;
1003
+ }
1004
+ console.warn(
1005
+ "Cannot get property table from EXT_structural_metadata extension. There is neither propertyTables, nor propertyTextures in the extension."
1006
+ );
1007
+ return null;
1008
+ }
1009
+ function decodeExtStructuralMetadata(scenegraph, options) {
1010
+ var _a, _b;
1011
+ if (!((_a = options.gltf) == null ? void 0 : _a.loadBuffers)) {
1012
+ return;
1013
+ }
1014
+ const extension = scenegraph.getExtension(
1015
+ EXT_STRUCTURAL_METADATA_NAME
1016
+ );
1017
+ if (!extension) {
1018
+ return;
1019
+ }
1020
+ if ((_b = options.gltf) == null ? void 0 : _b.loadImages) {
1021
+ decodePropertyTextures(scenegraph, extension);
1022
+ }
1023
+ decodePropertyTables(scenegraph, extension);
1024
+ }
1025
+ function decodePropertyTextures(scenegraph, extension) {
1026
+ const propertyTextures = extension.propertyTextures;
1027
+ const json = scenegraph.gltf.json;
1028
+ if (propertyTextures && json.meshes) {
1029
+ for (const mesh of json.meshes) {
1030
+ for (const primitive of mesh.primitives) {
1031
+ processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);
1032
+ }
1033
+ }
1034
+ }
1035
+ }
1036
+ function decodePropertyTables(scenegraph, extension) {
1037
+ const schema = extension.schema;
1038
+ if (!schema) {
1039
+ return;
1040
+ }
1041
+ const schemaClasses = schema.classes;
1042
+ const propertyTables = extension.propertyTables;
1043
+ if (schemaClasses && propertyTables) {
1044
+ for (const schemaName in schemaClasses) {
1045
+ const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
1046
+ if (propertyTable) {
1047
+ processPropertyTable(scenegraph, schema, propertyTable);
1048
+ }
1049
+ }
1050
+ }
1051
+ }
1052
+ function findPropertyTableByClass(propertyTables, schemaClassName) {
1053
+ for (const propertyTable of propertyTables) {
1054
+ if (propertyTable.class === schemaClassName) {
1055
+ return propertyTable;
1056
+ }
1057
+ }
1058
+ return null;
1059
+ }
1060
+ function processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension) {
1061
+ var _a;
1062
+ if (!propertyTextures) {
1063
+ return;
1064
+ }
1065
+ const primitiveExtension = (_a = primitive.extensions) == null ? void 0 : _a[EXT_STRUCTURAL_METADATA_NAME];
1066
+ const primitivePropertyTextureIndices = primitiveExtension == null ? void 0 : primitiveExtension.propertyTextures;
1067
+ if (!primitivePropertyTextureIndices) {
1068
+ return;
1069
+ }
1070
+ for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {
1071
+ const propertyTexture = propertyTextures[primitivePropertyTextureIndex];
1072
+ processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);
1073
+ }
1074
+ }
1075
+ function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension) {
1076
+ var _a;
1077
+ if (!propertyTexture.properties) {
1078
+ return;
1079
+ }
1080
+ if (!extension.dataAttributeNames) {
1081
+ extension.dataAttributeNames = [];
1082
+ }
1083
+ const className = propertyTexture.class;
1084
+ for (const propertyName in propertyTexture.properties) {
1085
+ const attributeName = `${className}_${propertyName}`;
1086
+ const textureInfoTopLevel = (_a = propertyTexture.properties) == null ? void 0 : _a[propertyName];
1087
+ if (!textureInfoTopLevel) {
1088
+ continue;
1089
+ }
1090
+ if (!textureInfoTopLevel.data) {
1091
+ textureInfoTopLevel.data = [];
1092
+ }
1093
+ const featureTextureTable = textureInfoTopLevel.data;
1094
+ const propertyData = getPrimitiveTextureData(
1095
+ scenegraph,
1096
+ textureInfoTopLevel,
1097
+ primitive
1098
+ );
1099
+ if (propertyData === null) {
1100
+ continue;
1101
+ }
1102
+ primitivePropertyDataToAttributes(
1103
+ scenegraph,
1104
+ attributeName,
1105
+ propertyData,
1106
+ featureTextureTable,
1107
+ primitive
1108
+ );
1109
+ textureInfoTopLevel.data = featureTextureTable;
1110
+ extension.dataAttributeNames.push(attributeName);
1111
+ }
1112
+ }
1113
+ function processPropertyTable(scenegraph, schema, propertyTable) {
1114
+ var _a, _b;
1115
+ const schemaClass = (_a = schema.classes) == null ? void 0 : _a[propertyTable.class];
1116
+ if (!schemaClass) {
1117
+ throw new Error(
1118
+ `Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`
1119
+ );
1120
+ }
1121
+ const numberOfElements = propertyTable.count;
1122
+ for (const propertyName in schemaClass.properties) {
1123
+ const classProperty = schemaClass.properties[propertyName];
1124
+ const propertyTableProperty = (_b = propertyTable.properties) == null ? void 0 : _b[propertyName];
1125
+ if (propertyTableProperty) {
1126
+ const data = getPropertyDataFromBinarySource(
1127
+ scenegraph,
1128
+ schema,
1129
+ classProperty,
1130
+ numberOfElements,
1131
+ propertyTableProperty
1132
+ );
1133
+ propertyTableProperty.data = data;
1134
+ }
1135
+ }
1136
+ }
1137
+ function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty) {
1138
+ let data = [];
1139
+ const valuesBufferView = propertyTableProperty.values;
1140
+ const valuesDataBytes = scenegraph.getTypedArrayForBufferView(valuesBufferView);
1141
+ const arrayOffsets = getArrayOffsetsForProperty(
1142
+ scenegraph,
1143
+ classProperty,
1144
+ propertyTableProperty,
1145
+ numberOfElements
1146
+ );
1147
+ const stringOffsets = getStringOffsetsForProperty(
1148
+ scenegraph,
1149
+ propertyTableProperty,
1150
+ numberOfElements
1151
+ );
1152
+ switch (classProperty.type) {
1153
+ case "SCALAR":
1154
+ case "VEC2":
1155
+ case "VEC3":
1156
+ case "VEC4":
1157
+ case "MAT2":
1158
+ case "MAT3":
1159
+ case "MAT4": {
1160
+ data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
1161
+ break;
1162
+ }
1163
+ case "BOOLEAN": {
1164
+ throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);
1165
+ }
1166
+ case "STRING": {
1167
+ data = getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets);
1168
+ break;
1169
+ }
1170
+ case "ENUM": {
1171
+ data = getPropertyDataENUM(
1172
+ schema,
1173
+ classProperty,
1174
+ numberOfElements,
1175
+ valuesDataBytes,
1176
+ arrayOffsets
1177
+ );
1178
+ break;
1179
+ }
1180
+ default:
1181
+ throw new Error(`Unknown classProperty type ${classProperty.type}`);
1182
+ }
1183
+ return data;
1184
+ }
1185
+ function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
1186
+ if (classProperty.array && // `count` is a number of array elements. May only be defined when `array` is true.
1187
+ // If `count` is NOT defined, it's a VARIABLE-length array
1188
+ typeof classProperty.count === "undefined" && // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.
1189
+ typeof propertyTableProperty.arrayOffsets !== "undefined") {
1190
+ return getOffsetsForProperty(
1191
+ scenegraph,
1192
+ propertyTableProperty.arrayOffsets,
1193
+ propertyTableProperty.arrayOffsetType || "UINT32",
1194
+ numberOfElements
1195
+ );
1196
+ }
1197
+ return null;
1198
+ }
1199
+ function getStringOffsetsForProperty(scenegraph, propertyTableProperty, numberOfElements) {
1200
+ if (typeof propertyTableProperty.stringOffsets !== "undefined") {
1201
+ return getOffsetsForProperty(
1202
+ scenegraph,
1203
+ propertyTableProperty.stringOffsets,
1204
+ propertyTableProperty.stringOffsetType || "UINT32",
1205
+ numberOfElements
1206
+ );
1207
+ }
1208
+ return null;
1209
+ }
1210
+ function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
1211
+ const isArray = classProperty.array;
1212
+ const arrayCount = classProperty.count;
1213
+ const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);
1214
+ const elementCount = valuesDataBytes.byteLength / elementSize;
1215
+ let valuesData;
1216
+ if (classProperty.componentType) {
1217
+ valuesData = convertRawBufferToMetadataArray(
1218
+ valuesDataBytes,
1219
+ classProperty.type,
1220
+ // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.
1221
+ classProperty.componentType,
1222
+ elementCount
1223
+ );
1224
+ } else {
1225
+ valuesData = valuesDataBytes;
1226
+ }
1227
+ if (isArray) {
1228
+ if (arrayOffsets) {
1229
+ return parseVariableLengthArrayNumeric(
1230
+ valuesData,
1231
+ numberOfElements,
1232
+ arrayOffsets,
1233
+ valuesDataBytes.length,
1234
+ elementSize
1235
+ );
1236
+ }
1237
+ if (arrayCount) {
1238
+ return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
1239
+ }
1240
+ return [];
1241
+ }
1242
+ return valuesData;
1243
+ }
1244
+ function getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
1245
+ var _a;
1246
+ const enumType = classProperty.enumType;
1247
+ if (!enumType) {
1248
+ throw new Error(
1249
+ "Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM"
1250
+ );
1251
+ }
1252
+ const enumEntry = (_a = schema.enums) == null ? void 0 : _a[enumType];
1253
+ if (!enumEntry) {
1254
+ throw new Error(
1255
+ `Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`
1256
+ );
1257
+ }
1258
+ const enumValueType = enumEntry.valueType || "UINT16";
1259
+ const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);
1260
+ const elementCount = valuesDataBytes.byteLength / elementSize;
1261
+ let valuesData = convertRawBufferToMetadataArray(
1262
+ valuesDataBytes,
1263
+ classProperty.type,
1264
+ enumValueType,
1265
+ elementCount
1266
+ );
1267
+ if (!valuesData) {
1268
+ valuesData = valuesDataBytes;
1269
+ }
1270
+ if (classProperty.array) {
1271
+ if (arrayOffsets) {
1272
+ return parseVariableLengthArrayENUM({
1273
+ valuesData,
1274
+ numberOfElements,
1275
+ arrayOffsets,
1276
+ valuesDataBytesLength: valuesDataBytes.length,
1277
+ elementSize,
1278
+ enumEntry
1279
+ });
1280
+ }
1281
+ const arrayCount = classProperty.count;
1282
+ if (arrayCount) {
1283
+ return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);
1284
+ }
1285
+ return [];
1286
+ }
1287
+ return getEnumsArray(valuesData, 0, numberOfElements, enumEntry);
1288
+ }
1289
+ function parseVariableLengthArrayENUM(params) {
1290
+ const {
1291
+ valuesData,
1292
+ numberOfElements,
1293
+ arrayOffsets,
1294
+ valuesDataBytesLength,
1295
+ elementSize,
1296
+ enumEntry
1297
+ } = params;
1298
+ const attributeValueArray = [];
1299
+ for (let index = 0; index < numberOfElements; index++) {
1300
+ const arrayOffset = arrayOffsets[index];
1301
+ const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
1302
+ if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
1303
+ break;
1304
+ }
1305
+ const typedArrayOffset = arrayOffset / elementSize;
1306
+ const elementCount = arrayByteSize / elementSize;
1307
+ const array = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry);
1308
+ attributeValueArray.push(array);
1309
+ }
1310
+ return attributeValueArray;
1311
+ }
1312
+ function parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry) {
1313
+ const attributeValueArray = [];
1314
+ for (let index = 0; index < numberOfElements; index++) {
1315
+ const elementOffset = arrayCount * index;
1316
+ const array = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry);
1317
+ attributeValueArray.push(array);
1318
+ }
1319
+ return attributeValueArray;
1320
+ }
1321
+ function getEnumsArray(valuesData, offset, count, enumEntry) {
1322
+ const array = [];
1323
+ for (let i = 0; i < count; i++) {
1324
+ if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) {
1325
+ array.push("");
1326
+ } else {
1327
+ const value = valuesData[offset + i];
1328
+ const enumObject = getEnumByValue(enumEntry, value);
1329
+ if (enumObject) {
1330
+ array.push(enumObject.name);
1331
+ } else {
1332
+ array.push("");
1333
+ }
1334
+ }
1335
+ }
1336
+ return array;
1337
+ }
1338
+ function getEnumByValue(enumEntry, value) {
1339
+ for (const enumValue of enumEntry.values) {
1340
+ if (enumValue.value === value) {
1341
+ return enumValue;
1342
+ }
1343
+ }
1344
+ return null;
1345
+ }
1346
+
1347
+ // src/lib/extensions/deprecated/EXT_feature_metadata.ts
1348
+ var EXT_feature_metadata_exports = {};
1349
+ __export(EXT_feature_metadata_exports, {
1350
+ decode: () => decode3,
1351
+ getPropertyTableFromExtFeatureMetadata: () => getPropertyTableFromExtFeatureMetadata,
1352
+ name: () => name3
1353
+ });
1354
+ var EXT_FEATURE_METADATA_NAME = "EXT_feature_metadata";
1355
+ var name3 = EXT_FEATURE_METADATA_NAME;
1356
+ async function decode3(gltfData, options) {
1357
+ const scenegraph = new GLTFScenegraph(gltfData);
1358
+ decodeExtFeatureMetadata(scenegraph, options);
1359
+ }
1360
+ function getPropertyTableFromExtFeatureMetadata(extension, metadataClass) {
1361
+ var _a;
1362
+ if (extension.featureTables) {
1363
+ const firstFeatureTableName = (_a = Object.keys(extension.featureTables)) == null ? void 0 : _a[0];
1364
+ if (firstFeatureTableName) {
1365
+ const featureTable = extension.featureTables[firstFeatureTableName];
1366
+ const propertyTable = {};
1367
+ for (const propertyName in featureTable.properties) {
1368
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
1369
+ }
1370
+ return propertyTable;
1371
+ }
1372
+ }
1373
+ if (extension.featureTextures) {
1374
+ let featureTexture;
1375
+ for (const textureKey in extension.featureTextures) {
1376
+ const texture = extension.featureTextures[textureKey];
1377
+ if (texture.class === metadataClass) {
1378
+ featureTexture = textureKey;
1379
+ }
1380
+ }
1381
+ if (typeof featureTexture === "string") {
1382
+ const featureTable = extension.featureTextures[featureTexture];
1383
+ const propertyTable = {};
1384
+ for (const propertyName in featureTable.properties) {
1385
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
1386
+ }
1387
+ return propertyTable;
1388
+ }
1389
+ }
1390
+ console.warn(
1391
+ "Cannot get property table from EXT_feature_metadata extension. There is neither featureTables, nor featureTextures in the extension."
1392
+ );
1393
+ return null;
1394
+ }
1395
+ function decodeExtFeatureMetadata(scenegraph, options) {
1396
+ var _a, _b;
1397
+ if (!((_a = options.gltf) == null ? void 0 : _a.loadBuffers)) {
1398
+ return;
1399
+ }
1400
+ const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
1401
+ if (!extension) {
1402
+ return;
1403
+ }
1404
+ if ((_b = options.gltf) == null ? void 0 : _b.loadImages) {
1405
+ decodePropertyTextures2(scenegraph, extension);
1406
+ }
1407
+ decodePropertyTables2(scenegraph, extension);
1408
+ }
1409
+ function decodePropertyTextures2(scenegraph, extension) {
1410
+ const schema = extension.schema;
1411
+ if (!schema) {
1412
+ return;
1413
+ }
1414
+ const schemaClasses = schema.classes;
1415
+ const { featureTextures } = extension;
1416
+ if (schemaClasses && featureTextures) {
1417
+ for (const schemaName in schemaClasses) {
1418
+ const schemaClass = schemaClasses[schemaName];
1419
+ const featureTexture = findFeatureTextureByClass(featureTextures, schemaName);
1420
+ if (featureTexture) {
1421
+ handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
1422
+ }
1423
+ }
1424
+ }
1425
+ }
1426
+ function decodePropertyTables2(scenegraph, extension) {
1427
+ const schema = extension.schema;
1428
+ if (!schema) {
1429
+ return;
1430
+ }
1431
+ const schemaClasses = schema.classes;
1432
+ const propertyTables = extension.featureTables;
1433
+ if (schemaClasses && propertyTables) {
1434
+ for (const schemaName in schemaClasses) {
1435
+ const propertyTable = findPropertyTableByClass2(propertyTables, schemaName);
1436
+ if (propertyTable) {
1437
+ processPropertyTable2(scenegraph, schema, propertyTable);
1438
+ }
1439
+ }
1440
+ }
1441
+ }
1442
+ function findPropertyTableByClass2(propertyTables, schemaClassName) {
1443
+ for (const propertyTableName in propertyTables) {
1444
+ const propertyTable = propertyTables[propertyTableName];
1445
+ if (propertyTable.class === schemaClassName) {
1446
+ return propertyTable;
1447
+ }
1448
+ }
1449
+ return null;
1450
+ }
1451
+ function findFeatureTextureByClass(featureTextures, schemaClassName) {
1452
+ for (const featureTexturesName in featureTextures) {
1453
+ const featureTable = featureTextures[featureTexturesName];
1454
+ if (featureTable.class === schemaClassName) {
1455
+ return featureTable;
1456
+ }
1457
+ }
1458
+ return null;
1459
+ }
1460
+ function processPropertyTable2(scenegraph, schema, propertyTable) {
1461
+ var _a, _b;
1462
+ if (!propertyTable.class) {
1463
+ return;
1464
+ }
1465
+ const schemaClass = (_a = schema.classes) == null ? void 0 : _a[propertyTable.class];
1466
+ if (!schemaClass) {
1467
+ throw new Error(
1468
+ `Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`
1469
+ );
1470
+ }
1471
+ const numberOfElements = propertyTable.count;
1472
+ for (const propertyName in schemaClass.properties) {
1473
+ const classProperty = schemaClass.properties[propertyName];
1474
+ const propertyTableProperty = (_b = propertyTable.properties) == null ? void 0 : _b[propertyName];
1475
+ if (propertyTableProperty) {
1476
+ const data = getPropertyDataFromBinarySource2(
1477
+ scenegraph,
1478
+ schema,
1479
+ classProperty,
1480
+ numberOfElements,
1481
+ propertyTableProperty
1482
+ );
1483
+ propertyTableProperty.data = data;
1484
+ }
1485
+ }
1486
+ }
1487
+ function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
1488
+ var _a;
1489
+ const attributeName = featureTexture.class;
1490
+ for (const propertyName in schemaClass.properties) {
1491
+ const featureTextureProperty = (_a = featureTexture == null ? void 0 : featureTexture.properties) == null ? void 0 : _a[propertyName];
1492
+ if (featureTextureProperty) {
1493
+ const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
1494
+ featureTextureProperty.data = data;
1495
+ }
1496
+ }
1497
+ }
1498
+ function getPropertyDataFromBinarySource2(scenegraph, schema, classProperty, numberOfFeatures, featureTableProperty) {
1499
+ let data = [];
1500
+ const bufferView = featureTableProperty.bufferView;
1501
+ const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
1502
+ const arrayOffsets = getArrayOffsetsForProperty2(
1503
+ scenegraph,
1504
+ classProperty,
1505
+ featureTableProperty,
1506
+ numberOfFeatures
1507
+ );
1508
+ const stringOffsets = getStringOffsetsForProperty2(
1509
+ scenegraph,
1510
+ classProperty,
1511
+ featureTableProperty,
1512
+ numberOfFeatures
1513
+ );
1514
+ if (classProperty.type === "STRING" || classProperty.componentType === "STRING") {
1515
+ data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets);
1516
+ } else if (isNumericProperty(classProperty)) {
1517
+ data = getPropertyDataNumeric2(classProperty, numberOfFeatures, dataArray, arrayOffsets);
1518
+ }
1519
+ return data;
1520
+ }
1521
+ function getArrayOffsetsForProperty2(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
1522
+ if (classProperty.type === "ARRAY" && // `componentCount` is a number of fixed-length array elements.
1523
+ // If `componentCount` is NOT defined, it's a VARIABLE-length array
1524
+ typeof classProperty.componentCount === "undefined" && // `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays.
1525
+ typeof propertyTableProperty.arrayOffsetBufferView !== "undefined") {
1526
+ return getOffsetsForProperty(
1527
+ scenegraph,
1528
+ propertyTableProperty.arrayOffsetBufferView,
1529
+ propertyTableProperty.offsetType || "UINT32",
1530
+ // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
1531
+ numberOfElements
1532
+ );
1533
+ }
1534
+ return null;
1535
+ }
1536
+ function getStringOffsetsForProperty2(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
1537
+ if (typeof propertyTableProperty.stringOffsetBufferView !== "undefined") {
1538
+ return getOffsetsForProperty(
1539
+ scenegraph,
1540
+ propertyTableProperty.stringOffsetBufferView,
1541
+ propertyTableProperty.offsetType || "UINT32",
1542
+ // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
1543
+ numberOfElements
1544
+ );
1545
+ }
1546
+ return null;
1547
+ }
1548
+ function isNumericProperty(schemaProperty) {
1549
+ const types = [
1550
+ "UINT8",
1551
+ "INT16",
1552
+ "UINT16",
1553
+ "INT32",
1554
+ "UINT32",
1555
+ "INT64",
1556
+ "UINT64",
1557
+ "FLOAT32",
1558
+ "FLOAT64"
1559
+ ];
1560
+ return types.includes(schemaProperty.type) || typeof schemaProperty.componentType !== "undefined" && types.includes(schemaProperty.componentType);
1561
+ }
1562
+ function getPropertyDataNumeric2(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
1563
+ const isArray = classProperty.type === "ARRAY";
1564
+ const arrayCount = classProperty.componentCount;
1565
+ const attributeType = "SCALAR";
1566
+ const componentType = classProperty.componentType || classProperty.type;
1567
+ const elementSize = getArrayElementByteSize(attributeType, componentType);
1568
+ const elementCount = valuesDataBytes.byteLength / elementSize;
1569
+ const valuesData = convertRawBufferToMetadataArray(
1570
+ valuesDataBytes,
1571
+ attributeType,
1572
+ componentType,
1573
+ elementCount
1574
+ );
1575
+ if (isArray) {
1576
+ if (arrayOffsets) {
1577
+ return parseVariableLengthArrayNumeric(
1578
+ valuesData,
1579
+ numberOfElements,
1580
+ arrayOffsets,
1581
+ valuesDataBytes.length,
1582
+ elementSize
1583
+ );
1584
+ }
1585
+ if (arrayCount) {
1586
+ return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
1587
+ }
1588
+ return [];
1589
+ }
1590
+ return valuesData;
1591
+ }
1592
+ function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
1593
+ const json = scenegraph.gltf.json;
1594
+ if (!json.meshes) {
1595
+ return [];
1596
+ }
1597
+ const featureTextureTable = [];
1598
+ for (const mesh of json.meshes) {
1599
+ for (const primitive of mesh.primitives) {
1600
+ processPrimitiveTextures(
1601
+ scenegraph,
1602
+ attributeName,
1603
+ featureTextureProperty,
1604
+ featureTextureTable,
1605
+ primitive
1606
+ );
1607
+ }
1608
+ }
1609
+ return featureTextureTable;
1610
+ }
1611
+ function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
1612
+ const textureInfoTopLevel = {
1613
+ channels: featureTextureProperty.channels,
1614
+ ...featureTextureProperty.texture
1615
+ };
1616
+ const propertyData = getPrimitiveTextureData(
1617
+ scenegraph,
1618
+ textureInfoTopLevel,
1619
+ primitive
1620
+ );
1621
+ if (!propertyData) {
1622
+ return;
1623
+ }
1624
+ primitivePropertyDataToAttributes(
1625
+ scenegraph,
1626
+ attributeName,
1627
+ propertyData,
1628
+ featureTextureTable,
1629
+ primitive
1630
+ );
1631
+ }
1632
+
1633
+ // src/lib/utils/version.ts
1634
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1635
+
1636
+ // src/lib/parsers/parse-gltf.ts
1637
+ var import_loader_utils4 = require("@loaders.gl/loader-utils");
1638
+ var import_images4 = require("@loaders.gl/images");
1639
+ var import_textures = require("@loaders.gl/textures");
1640
+
1641
+ // src/lib/parsers/parse-glb.ts
1642
+ var import_loader_utils2 = require("@loaders.gl/loader-utils");
1643
+ var LITTLE_ENDIAN = true;
1644
+ var MAGIC_glTF = 1735152710;
1645
+ var GLB_FILE_HEADER_SIZE = 12;
1646
+ var GLB_CHUNK_HEADER_SIZE = 8;
1647
+ var GLB_CHUNK_TYPE_JSON = 1313821514;
1648
+ var GLB_CHUNK_TYPE_BIN = 5130562;
1649
+ var GLB_V1_CONTENT_FORMAT_JSON = 0;
1650
+ var GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
1651
+ var GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
1652
+ function getMagicString(dataView, byteOffset = 0) {
1653
+ 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))}`;
1654
+ }
1655
+ function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
1656
+ const dataView = new DataView(arrayBuffer);
1657
+ const { magic = MAGIC_glTF } = options;
1658
+ const magic1 = dataView.getUint32(byteOffset, false);
1659
+ return magic1 === magic || magic1 === MAGIC_glTF;
1660
+ }
1661
+ function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
1662
+ const dataView = new DataView(arrayBuffer);
1663
+ const type = getMagicString(dataView, byteOffset + 0);
1664
+ const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN);
1665
+ const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN);
1666
+ Object.assign(glb, {
1667
+ // Put less important stuff in a header, to avoid clutter
1668
+ header: {
1669
+ byteOffset,
1670
+ // Byte offset into the initial arrayBuffer
1671
+ byteLength,
1672
+ hasBinChunk: false
1673
+ },
1674
+ type,
1675
+ version,
1676
+ json: {},
1677
+ binChunks: []
1678
+ });
1679
+ byteOffset += GLB_FILE_HEADER_SIZE;
1680
+ switch (glb.version) {
1681
+ case 1:
1682
+ return parseGLBV1(glb, dataView, byteOffset);
1683
+ case 2:
1684
+ return parseGLBV2(glb, dataView, byteOffset, options = {});
1685
+ default:
1686
+ throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`);
1687
+ }
1688
+ }
1689
+ function parseGLBV1(glb, dataView, byteOffset) {
1690
+ (0, import_loader_utils2.assert)(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
1691
+ const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN);
1692
+ const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN);
1693
+ byteOffset += GLB_CHUNK_HEADER_SIZE;
1694
+ (0, import_loader_utils2.assert)(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
1695
+ parseJSONChunk(glb, dataView, byteOffset, contentLength);
1696
+ byteOffset += contentLength;
1697
+ byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
1698
+ return byteOffset;
1699
+ }
1700
+ function parseGLBV2(glb, dataView, byteOffset, options) {
1701
+ (0, import_loader_utils2.assert)(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
1702
+ parseGLBChunksSync(glb, dataView, byteOffset, options);
1703
+ return byteOffset + glb.header.byteLength;
1704
+ }
1705
+ function parseGLBChunksSync(glb, dataView, byteOffset, options) {
1706
+ while (byteOffset + 8 <= glb.header.byteLength) {
1707
+ const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN);
1708
+ const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN);
1709
+ byteOffset += GLB_CHUNK_HEADER_SIZE;
1710
+ switch (chunkFormat) {
1711
+ case GLB_CHUNK_TYPE_JSON:
1712
+ parseJSONChunk(glb, dataView, byteOffset, chunkLength);
1713
+ break;
1714
+ case GLB_CHUNK_TYPE_BIN:
1715
+ parseBINChunk(glb, dataView, byteOffset, chunkLength);
1716
+ break;
1717
+ case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
1718
+ if (!options.strict) {
1719
+ parseJSONChunk(glb, dataView, byteOffset, chunkLength);
1720
+ }
1721
+ break;
1722
+ case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:
1723
+ if (!options.strict) {
1724
+ parseBINChunk(glb, dataView, byteOffset, chunkLength);
1725
+ }
1726
+ break;
1727
+ default:
1728
+ break;
1729
+ }
1730
+ byteOffset += (0, import_loader_utils2.padToNBytes)(chunkLength, 4);
1731
+ }
1732
+ return byteOffset;
1733
+ }
1734
+ function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
1735
+ const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
1736
+ const textDecoder = new TextDecoder("utf8");
1737
+ const jsonText = textDecoder.decode(jsonChunk);
1738
+ glb.json = JSON.parse(jsonText);
1739
+ return (0, import_loader_utils2.padToNBytes)(chunkLength, 4);
1740
+ }
1741
+ function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
1742
+ glb.header.hasBinChunk = true;
1743
+ glb.binChunks.push({
1744
+ byteOffset,
1745
+ byteLength: chunkLength,
1746
+ arrayBuffer: dataView.buffer
1747
+ // TODO - copy, or create typed array view?
1748
+ });
1749
+ return (0, import_loader_utils2.padToNBytes)(chunkLength, 4);
1750
+ }
1751
+
1752
+ // src/lib/gltf-utils/resolve-url.ts
1753
+ function resolveUrl(url, options) {
1754
+ const absolute = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:");
1755
+ if (absolute) {
1756
+ return url;
1757
+ }
1758
+ const baseUrl = options.baseUri || options.uri;
1759
+ if (!baseUrl) {
1760
+ throw new Error(`'baseUri' must be provided to resolve relative url ${url}`);
1761
+ }
1762
+ return baseUrl.substr(0, baseUrl.lastIndexOf("/") + 1) + url;
1763
+ }
1764
+
1765
+ // src/lib/extensions/EXT_meshopt_compression.ts
1766
+ var EXT_meshopt_compression_exports = {};
1767
+ __export(EXT_meshopt_compression_exports, {
1768
+ decode: () => decode5,
1769
+ name: () => name4
1770
+ });
1771
+
1772
+ // src/meshopt/meshopt-decoder.ts
1773
+ var wasm_base = "B9h9z9tFBBBF8fL9gBB9gLaaaaaFa9gEaaaB9gFaFa9gEaaaFaEMcBFFFGGGEIIILF9wFFFLEFBFKNFaFCx/IFMO/LFVK9tv9t9vq95GBt9f9f939h9z9t9f9j9h9s9s9f9jW9vq9zBBp9tv9z9o9v9wW9f9kv9j9v9kv9WvqWv94h919m9mvqBF8Z9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv94h919m9mvqBGy9tv9z9o9v9wW9f9kv9j9v9kv9J9u9kv949TvZ91v9u9jvBEn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9P9jWBIi9tv9z9o9v9wW9f9kv9j9v9kv69p9sWvq9R919hWBLn9tv9z9o9v9wW9f9kv9j9v9kv69p9sWv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OenHID8dBAGDBIBDyB+t+J83EBABCNJAID8dFAGDBIBDyF+t+J83EBALAVANDQNVi8ZcMpySQ8c8dfb8e8fHND8dBAGDBIBDyG+t+J83EBABCiJAND8dFAGDBIBDyE+t+J83EBABCAJRBAECIJHEAF9JQBMMM/3FGEaF978jUUUUBCoBlREGXAGCGrAF9sHIC98ZHL9FQBCBRGABRFEXAFAFDBBBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMBBAFCTJRFAGCIJHGAL9JQBMMGXALAI9PQBAEAICEZHGCGWHFqCBCoBAFl/8MBAEABALCGWJHLAF/8cBBGXAG9FQBAEAEDBIBHKCND+rFCND+sFD/6FAKCiD+sFCnD+rFCUUU/8EDtD+uFD/mFDMIBMALAEAF/8cBBMM9TFEaCBCB8oGUkUUBHFABCEJC98ZJHBjGUkUUBGXGXAB8/BCTWHGuQBCaREABAGlCggEJCTrXBCa6QFMAFREMAEMMMFBCUNMIT9tBB";
1775
+ var detector = new Uint8Array([
1776
+ 0,
1777
+ 97,
1778
+ 115,
1779
+ 109,
1780
+ 1,
1781
+ 0,
1782
+ 0,
1783
+ 0,
1784
+ 1,
1785
+ 4,
1786
+ 1,
1787
+ 96,
1788
+ 0,
1789
+ 0,
1790
+ 3,
1791
+ 3,
1792
+ 2,
1793
+ 0,
1794
+ 0,
1795
+ 5,
1796
+ 3,
1797
+ 1,
1798
+ 0,
1799
+ 1,
1800
+ 12,
1801
+ 1,
1802
+ 0,
1803
+ 10,
1804
+ 22,
1805
+ 2,
1806
+ 12,
1807
+ 0,
1808
+ 65,
1809
+ 0,
1810
+ 65,
1811
+ 0,
1812
+ 65,
1813
+ 0,
1814
+ 252,
1815
+ 10,
1816
+ 0,
1817
+ 0,
1818
+ 11,
1819
+ 7,
1820
+ 0,
1821
+ 65,
1822
+ 0,
1823
+ 253,
1824
+ 15,
1825
+ 26,
1826
+ 11
1827
+ ]);
1828
+ var wasmpack = new Uint8Array([
1829
+ 32,
1830
+ 0,
1831
+ 65,
1832
+ 253,
1833
+ 3,
1834
+ 1,
1835
+ 2,
1836
+ 34,
1837
+ 4,
1838
+ 106,
1839
+ 6,
1840
+ 5,
1841
+ 11,
1842
+ 8,
1843
+ 7,
1844
+ 20,
1845
+ 13,
1846
+ 33,
1847
+ 12,
1848
+ 16,
1849
+ 128,
1850
+ 9,
1851
+ 116,
1852
+ 64,
1853
+ 19,
1854
+ 113,
1855
+ 127,
1856
+ 15,
1857
+ 10,
1858
+ 21,
1859
+ 22,
1860
+ 14,
1861
+ 255,
1862
+ 66,
1863
+ 24,
1864
+ 54,
1865
+ 136,
1866
+ 107,
1867
+ 18,
1868
+ 23,
1869
+ 192,
1870
+ 26,
1871
+ 114,
1872
+ 118,
1873
+ 132,
1874
+ 17,
1875
+ 77,
1876
+ 101,
1877
+ 130,
1878
+ 144,
1879
+ 27,
1880
+ 87,
1881
+ 131,
1882
+ 44,
1883
+ 45,
1884
+ 74,
1885
+ 156,
1886
+ 154,
1887
+ 70,
1888
+ 167
1889
+ ]);
1890
+ var FILTERS = {
1891
+ // legacy index-based enums for glTF
1892
+ 0: "",
1893
+ 1: "meshopt_decodeFilterOct",
1894
+ 2: "meshopt_decodeFilterQuat",
1895
+ 3: "meshopt_decodeFilterExp",
1896
+ // string-based enums for glTF
1897
+ NONE: "",
1898
+ OCTAHEDRAL: "meshopt_decodeFilterOct",
1899
+ QUATERNION: "meshopt_decodeFilterQuat",
1900
+ EXPONENTIAL: "meshopt_decodeFilterExp"
1901
+ };
1902
+ var DECODERS = {
1903
+ // legacy index-based enums for glTF
1904
+ 0: "meshopt_decodeVertexBuffer",
1905
+ 1: "meshopt_decodeIndexBuffer",
1906
+ 2: "meshopt_decodeIndexSequence",
1907
+ // string-based enums for glTF
1908
+ ATTRIBUTES: "meshopt_decodeVertexBuffer",
1909
+ TRIANGLES: "meshopt_decodeIndexBuffer",
1910
+ INDICES: "meshopt_decodeIndexSequence"
1911
+ };
1912
+ async function meshoptDecodeGltfBuffer(target, count, size, source, mode, filter = "NONE") {
1913
+ const instance = await loadWasmInstance();
1914
+ decode4(
1915
+ instance,
1916
+ instance.exports[DECODERS[mode]],
1917
+ target,
1918
+ count,
1919
+ size,
1920
+ source,
1921
+ instance.exports[FILTERS[filter || "NONE"]]
1922
+ );
1923
+ }
1924
+ var wasmPromise;
1925
+ async function loadWasmInstance() {
1926
+ if (!wasmPromise) {
1927
+ wasmPromise = loadWasmModule();
1928
+ }
1929
+ return wasmPromise;
1930
+ }
1931
+ async function loadWasmModule() {
1932
+ let wasm = wasm_base;
1933
+ if (WebAssembly.validate(detector)) {
1934
+ wasm = wasm_simd;
1935
+ console.log("Warning: meshopt_decoder is using experimental SIMD support");
1936
+ }
1937
+ const result = await WebAssembly.instantiate(unpack(wasm), {});
1938
+ await result.instance.exports.__wasm_call_ctors();
1939
+ return result.instance;
1940
+ }
1941
+ function unpack(data) {
1942
+ const result = new Uint8Array(data.length);
1943
+ for (let i = 0; i < data.length; ++i) {
1944
+ const ch = data.charCodeAt(i);
1945
+ result[i] = ch > 96 ? ch - 71 : ch > 64 ? ch - 65 : ch > 47 ? ch + 4 : ch > 46 ? 63 : 62;
1946
+ }
1947
+ let write = 0;
1948
+ for (let i = 0; i < data.length; ++i) {
1949
+ result[write++] = result[i] < 60 ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i];
1950
+ }
1951
+ return result.buffer.slice(0, write);
1952
+ }
1953
+ function decode4(instance, fun, target, count, size, source, filter) {
1954
+ const sbrk = instance.exports.sbrk;
1955
+ const count4 = count + 3 & ~3;
1956
+ const tp = sbrk(count4 * size);
1957
+ const sp = sbrk(source.length);
1958
+ const heap = new Uint8Array(instance.exports.memory.buffer);
1959
+ heap.set(source, sp);
1960
+ const res = fun(tp, count, size, sp, source.length);
1961
+ if (res === 0 && filter) {
1962
+ filter(tp, count4, size);
1963
+ }
1964
+ target.set(heap.subarray(tp, tp + count * size));
1965
+ sbrk(tp - sbrk(0));
1966
+ if (res !== 0) {
1967
+ throw new Error(`Malformed buffer data: ${res}`);
1968
+ }
1969
+ }
1970
+
1971
+ // src/lib/extensions/EXT_meshopt_compression.ts
1972
+ var EXT_MESHOPT_COMPRESSION = "EXT_meshopt_compression";
1973
+ var name4 = EXT_MESHOPT_COMPRESSION;
1974
+ async function decode5(gltfData, options) {
1975
+ var _a, _b;
1976
+ const scenegraph = new GLTFScenegraph(gltfData);
1977
+ if (!((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.decompressMeshes) || !((_b = options.gltf) == null ? void 0 : _b.loadBuffers)) {
1978
+ return;
1979
+ }
1980
+ const promises = [];
1981
+ for (const bufferViewIndex of gltfData.json.bufferViews || []) {
1982
+ promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));
1983
+ }
1984
+ await Promise.all(promises);
1985
+ scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
1986
+ }
1987
+ async function decodeMeshoptBufferView(scenegraph, bufferView) {
1988
+ const meshoptExtension = scenegraph.getObjectExtension(
1989
+ bufferView,
1990
+ EXT_MESHOPT_COMPRESSION
1991
+ );
1992
+ if (meshoptExtension) {
1993
+ const {
1994
+ byteOffset = 0,
1995
+ byteLength = 0,
1996
+ byteStride,
1997
+ count,
1998
+ mode,
1999
+ filter = "NONE",
2000
+ buffer: bufferIndex
2001
+ } = meshoptExtension;
2002
+ const buffer = scenegraph.gltf.buffers[bufferIndex];
2003
+ const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
2004
+ const result = new Uint8Array(
2005
+ scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer,
2006
+ bufferView.byteOffset,
2007
+ bufferView.byteLength
2008
+ );
2009
+ await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);
2010
+ scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
2011
+ }
2012
+ }
2013
+
2014
+ // src/lib/extensions/EXT_texture_webp.ts
2015
+ var EXT_texture_webp_exports = {};
2016
+ __export(EXT_texture_webp_exports, {
2017
+ name: () => name5,
2018
+ preprocess: () => preprocess
2019
+ });
2020
+ var import_images3 = require("@loaders.gl/images");
2021
+ var EXT_TEXTURE_WEBP = "EXT_texture_webp";
2022
+ var name5 = EXT_TEXTURE_WEBP;
2023
+ function preprocess(gltfData, options) {
2024
+ const scenegraph = new GLTFScenegraph(gltfData);
2025
+ if (!(0, import_images3.isImageFormatSupported)("image/webp")) {
2026
+ if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
2027
+ throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
2028
+ }
2029
+ return;
2030
+ }
2031
+ const { json } = scenegraph;
2032
+ for (const texture of json.textures || []) {
2033
+ const extension = scenegraph.getObjectExtension(
2034
+ texture,
2035
+ EXT_TEXTURE_WEBP
2036
+ );
2037
+ if (extension) {
2038
+ texture.source = extension.source;
2039
+ }
2040
+ scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
2041
+ }
2042
+ scenegraph.removeExtension(EXT_TEXTURE_WEBP);
2043
+ }
2044
+
2045
+ // src/lib/extensions/KHR_texture_basisu.ts
2046
+ var KHR_texture_basisu_exports = {};
2047
+ __export(KHR_texture_basisu_exports, {
2048
+ name: () => name6,
2049
+ preprocess: () => preprocess2
2050
+ });
2051
+ var KHR_TEXTURE_BASISU = "KHR_texture_basisu";
2052
+ var name6 = KHR_TEXTURE_BASISU;
2053
+ function preprocess2(gltfData, options) {
2054
+ const scene = new GLTFScenegraph(gltfData);
2055
+ const { json } = scene;
2056
+ for (const texture of json.textures || []) {
2057
+ const extension = scene.getObjectExtension(
2058
+ texture,
2059
+ KHR_TEXTURE_BASISU
2060
+ );
2061
+ if (extension) {
2062
+ texture.source = extension.source;
2063
+ scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
2064
+ }
2065
+ }
2066
+ scene.removeExtension(KHR_TEXTURE_BASISU);
2067
+ }
2068
+
2069
+ // src/lib/extensions/KHR_draco_mesh_compression.ts
2070
+ var KHR_draco_mesh_compression_exports = {};
2071
+ __export(KHR_draco_mesh_compression_exports, {
2072
+ decode: () => decode6,
2073
+ encode: () => encode,
2074
+ name: () => name7,
2075
+ preprocess: () => preprocess3
2076
+ });
2077
+ var import_loader_utils3 = require("@loaders.gl/loader-utils");
2078
+ var import_draco = require("@loaders.gl/draco");
2079
+
2080
+ // src/lib/gltf-utils/gltf-attribute-utils.ts
2081
+ function getGLTFAccessors(attributes) {
2082
+ const accessors = {};
2083
+ for (const name12 in attributes) {
2084
+ const attribute = attributes[name12];
2085
+ if (name12 !== "indices") {
2086
+ const glTFAccessor = getGLTFAccessor(attribute);
2087
+ accessors[name12] = glTFAccessor;
2088
+ }
2089
+ }
2090
+ return accessors;
2091
+ }
2092
+ function getGLTFAccessor(attribute) {
2093
+ const { buffer, size, count } = getAccessorData(attribute);
2094
+ const glTFAccessor = {
2095
+ // glTF Accessor values
2096
+ // TODO: Instead of a bufferView index we could have an actual buffer (typed array)
2097
+ // bufferView: null,
2098
+ // TODO: Deprecate `value` in favor of bufferView?
2099
+ // @ts-ignore
2100
+ value: buffer,
2101
+ size,
2102
+ // Decoded `type` (e.g. SCALAR)
2103
+ byteOffset: 0,
2104
+ count,
2105
+ type: getAccessorTypeFromSize(size),
2106
+ componentType: getComponentTypeFromArray(buffer)
2107
+ };
2108
+ return glTFAccessor;
2109
+ }
2110
+ function getAccessorData(attribute) {
2111
+ let buffer = attribute;
2112
+ let size = 1;
2113
+ let count = 0;
2114
+ if (attribute && attribute.value) {
2115
+ buffer = attribute.value;
2116
+ size = attribute.size || 1;
2117
+ }
2118
+ if (buffer) {
2119
+ if (!ArrayBuffer.isView(buffer)) {
2120
+ buffer = toTypedArray(buffer, Float32Array);
2121
+ }
2122
+ count = buffer.length / size;
2123
+ }
2124
+ return { buffer, size, count };
2125
+ }
2126
+ function toTypedArray(array, ArrayType, convertTypedArrays = false) {
2127
+ if (!array) {
2128
+ return null;
2129
+ }
2130
+ if (Array.isArray(array)) {
2131
+ return new ArrayType(array);
2132
+ }
2133
+ if (convertTypedArrays && !(array instanceof ArrayType)) {
2134
+ return new ArrayType(array);
2135
+ }
2136
+ return array;
2137
+ }
2138
+
2139
+ // src/lib/extensions/KHR_draco_mesh_compression.ts
2140
+ var KHR_DRACO_MESH_COMPRESSION = "KHR_draco_mesh_compression";
2141
+ var name7 = KHR_DRACO_MESH_COMPRESSION;
2142
+ function preprocess3(gltfData, options, context) {
2143
+ const scenegraph = new GLTFScenegraph(gltfData);
2144
+ for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
2145
+ if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
2146
+ }
2147
+ }
2148
+ }
2149
+ async function decode6(gltfData, options, context) {
2150
+ var _a;
2151
+ if (!((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.decompressMeshes)) {
2152
+ return;
2153
+ }
2154
+ const scenegraph = new GLTFScenegraph(gltfData);
2155
+ const promises = [];
2156
+ for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
2157
+ if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
2158
+ promises.push(decompressPrimitive(scenegraph, primitive, options, context));
2159
+ }
2160
+ }
2161
+ await Promise.all(promises);
2162
+ scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
2163
+ }
2164
+ function encode(gltfData, options = {}) {
2165
+ const scenegraph = new GLTFScenegraph(gltfData);
2166
+ for (const mesh of scenegraph.json.meshes || []) {
2167
+ compressMesh(mesh, options);
2168
+ scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);
2169
+ }
2170
+ }
2171
+ async function decompressPrimitive(scenegraph, primitive, options, context) {
2172
+ const dracoExtension = scenegraph.getObjectExtension(
2173
+ primitive,
2174
+ KHR_DRACO_MESH_COMPRESSION
2175
+ );
2176
+ if (!dracoExtension) {
2177
+ return;
2178
+ }
2179
+ const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);
2180
+ const bufferCopy = (0, import_loader_utils3.sliceArrayBuffer)(buffer.buffer, buffer.byteOffset);
2181
+ const dracoOptions = { ...options };
2182
+ delete dracoOptions["3d-tiles"];
2183
+ const decodedData = await (0, import_loader_utils3.parseFromContext)(bufferCopy, import_draco.DracoLoader, dracoOptions, context);
2184
+ const decodedAttributes = getGLTFAccessors(decodedData.attributes);
2185
+ for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {
2186
+ if (attributeName in primitive.attributes) {
2187
+ const accessorIndex = primitive.attributes[attributeName];
2188
+ const accessor = scenegraph.getAccessor(accessorIndex);
2189
+ if ((accessor == null ? void 0 : accessor.min) && (accessor == null ? void 0 : accessor.max)) {
2190
+ decodedAttribute.min = accessor.min;
2191
+ decodedAttribute.max = accessor.max;
2192
+ }
2193
+ }
2194
+ }
2195
+ primitive.attributes = decodedAttributes;
2196
+ if (decodedData.indices) {
2197
+ primitive.indices = getGLTFAccessor(decodedData.indices);
2198
+ }
2199
+ scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
2200
+ checkPrimitive(primitive);
2201
+ }
2202
+ function compressMesh(attributes, indices, mode = 4, options, context) {
2203
+ var _a;
2204
+ if (!options.DracoWriter) {
2205
+ throw new Error("options.gltf.DracoWriter not provided");
2206
+ }
2207
+ const compressedData = options.DracoWriter.encodeSync({ attributes });
2208
+ const decodedData = (_a = context == null ? void 0 : context.parseSync) == null ? void 0 : _a.call(context, { attributes });
2209
+ const fauxAccessors = options._addFauxAttributes(decodedData.attributes);
2210
+ const bufferViewIndex = options.addBufferView(compressedData);
2211
+ const glTFMesh = {
2212
+ primitives: [
2213
+ {
2214
+ attributes: fauxAccessors,
2215
+ // TODO - verify with spec
2216
+ mode,
2217
+ // GL.POINTS
2218
+ extensions: {
2219
+ [KHR_DRACO_MESH_COMPRESSION]: {
2220
+ bufferView: bufferViewIndex,
2221
+ attributes: fauxAccessors
2222
+ // TODO - verify with spec
2223
+ }
2224
+ }
2225
+ }
2226
+ ]
2227
+ };
2228
+ return glTFMesh;
2229
+ }
2230
+ function checkPrimitive(primitive) {
2231
+ if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {
2232
+ throw new Error("glTF: Empty primitive detected: Draco decompression failure?");
2233
+ }
2234
+ }
2235
+ function* makeMeshPrimitiveIterator(scenegraph) {
2236
+ for (const mesh of scenegraph.json.meshes || []) {
2237
+ for (const primitive of mesh.primitives) {
2238
+ yield primitive;
2239
+ }
2240
+ }
2241
+ }
2242
+
2243
+ // src/lib/extensions/KHR_texture_transform.ts
2244
+ var KHR_texture_transform_exports = {};
2245
+ __export(KHR_texture_transform_exports, {
2246
+ decode: () => decode7,
2247
+ name: () => name8
2248
+ });
2249
+ var import_core = require("@math.gl/core");
2250
+ var EXT_MESHOPT_TRANSFORM = "KHR_texture_transform";
2251
+ var name8 = EXT_MESHOPT_TRANSFORM;
2252
+ var scratchVector = new import_core.Vector3();
2253
+ var scratchRotationMatrix = new import_core.Matrix3();
2254
+ var scratchScaleMatrix = new import_core.Matrix3();
2255
+ async function decode7(gltfData, options) {
2256
+ var _a;
2257
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
2258
+ const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
2259
+ if (!hasExtension || !((_a = options.gltf) == null ? void 0 : _a.loadBuffers)) {
2260
+ return;
2261
+ }
2262
+ const materials = gltfData.json.materials || [];
2263
+ for (let i = 0; i < materials.length; i++) {
2264
+ transformTexCoords(i, gltfData);
2265
+ }
2266
+ }
2267
+ function transformTexCoords(materialIndex, gltfData) {
2268
+ var _a, _b, _c;
2269
+ const processedTexCoords = [];
2270
+ const material = (_a = gltfData.json.materials) == null ? void 0 : _a[materialIndex];
2271
+ const baseColorTexture = (_b = material == null ? void 0 : material.pbrMetallicRoughness) == null ? void 0 : _b.baseColorTexture;
2272
+ if (baseColorTexture) {
2273
+ transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
2274
+ }
2275
+ const emisiveTexture = material == null ? void 0 : material.emissiveTexture;
2276
+ if (emisiveTexture) {
2277
+ transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
2278
+ }
2279
+ const normalTexture = material == null ? void 0 : material.normalTexture;
2280
+ if (normalTexture) {
2281
+ transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
2282
+ }
2283
+ const occlusionTexture = material == null ? void 0 : material.occlusionTexture;
2284
+ if (occlusionTexture) {
2285
+ transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
2286
+ }
2287
+ const metallicRoughnessTexture = (_c = material == null ? void 0 : material.pbrMetallicRoughness) == null ? void 0 : _c.metallicRoughnessTexture;
2288
+ if (metallicRoughnessTexture) {
2289
+ transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
2290
+ }
2291
+ }
2292
+ function transformPrimitives(gltfData, materialIndex, texture, processedTexCoords) {
2293
+ const transformParameters = getTransformParameters(texture, processedTexCoords);
2294
+ if (!transformParameters) {
2295
+ return;
2296
+ }
2297
+ const meshes = gltfData.json.meshes || [];
2298
+ for (const mesh of meshes) {
2299
+ for (const primitive of mesh.primitives) {
2300
+ const material = primitive.material;
2301
+ if (Number.isFinite(material) && materialIndex === material) {
2302
+ transformPrimitive(gltfData, primitive, transformParameters);
2303
+ }
2304
+ }
2305
+ }
2306
+ }
2307
+ function getTransformParameters(texture, processedTexCoords) {
2308
+ var _a;
2309
+ const textureInfo = (_a = texture.extensions) == null ? void 0 : _a[EXT_MESHOPT_TRANSFORM];
2310
+ const { texCoord: originalTexCoord = 0 } = texture;
2311
+ const { texCoord = originalTexCoord } = textureInfo;
2312
+ const isProcessed = processedTexCoords.findIndex(
2313
+ ([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord
2314
+ ) !== -1;
2315
+ if (!isProcessed) {
2316
+ const matrix = makeTransformationMatrix(textureInfo);
2317
+ if (originalTexCoord !== texCoord) {
2318
+ texture.texCoord = texCoord;
2319
+ }
2320
+ processedTexCoords.push([originalTexCoord, texCoord]);
2321
+ return { originalTexCoord, texCoord, matrix };
2322
+ }
2323
+ return null;
2324
+ }
2325
+ function transformPrimitive(gltfData, primitive, transformParameters) {
2326
+ var _a, _b;
2327
+ const { originalTexCoord, texCoord, matrix } = transformParameters;
2328
+ const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
2329
+ if (Number.isFinite(texCoordAccessor)) {
2330
+ const accessor = (_a = gltfData.json.accessors) == null ? void 0 : _a[texCoordAccessor];
2331
+ if (accessor && accessor.bufferView) {
2332
+ const bufferView = (_b = gltfData.json.bufferViews) == null ? void 0 : _b[accessor.bufferView];
2333
+ if (bufferView) {
2334
+ const { arrayBuffer, byteOffset: bufferByteOffset } = gltfData.buffers[bufferView.buffer];
2335
+ const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
2336
+ const { ArrayType, length } = getAccessorArrayTypeAndLength(accessor, bufferView);
2337
+ const bytes = BYTES[accessor.componentType];
2338
+ const components = COMPONENTS[accessor.type];
2339
+ const elementAddressScale = bufferView.byteStride || bytes * components;
2340
+ const result = new Float32Array(length);
2341
+ for (let i = 0; i < accessor.count; i++) {
2342
+ const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
2343
+ scratchVector.set(uv[0], uv[1], 1);
2344
+ scratchVector.transformByMatrix3(matrix);
2345
+ result.set([scratchVector[0], scratchVector[1]], i * components);
2346
+ }
2347
+ if (originalTexCoord === texCoord) {
2348
+ updateGltf(accessor, bufferView, gltfData.buffers, result);
2349
+ } else {
2350
+ createAttribute(texCoord, accessor, primitive, gltfData, result);
2351
+ }
2352
+ }
2353
+ }
2354
+ }
2355
+ }
2356
+ function updateGltf(accessor, bufferView, buffers, newTexCoordArray) {
2357
+ accessor.componentType = 5126;
2358
+ buffers.push({
2359
+ arrayBuffer: newTexCoordArray.buffer,
2360
+ byteOffset: 0,
2361
+ byteLength: newTexCoordArray.buffer.byteLength
2362
+ });
2363
+ bufferView.buffer = buffers.length - 1;
2364
+ bufferView.byteLength = newTexCoordArray.buffer.byteLength;
2365
+ bufferView.byteOffset = 0;
2366
+ delete bufferView.byteStride;
2367
+ }
2368
+ function createAttribute(newTexCoord, originalAccessor, primitive, gltfData, newTexCoordArray) {
2369
+ gltfData.buffers.push({
2370
+ arrayBuffer: newTexCoordArray.buffer,
2371
+ byteOffset: 0,
2372
+ byteLength: newTexCoordArray.buffer.byteLength
2373
+ });
2374
+ const bufferViews = gltfData.json.bufferViews;
2375
+ if (!bufferViews) {
2376
+ return;
2377
+ }
2378
+ bufferViews.push({
2379
+ buffer: gltfData.buffers.length - 1,
2380
+ byteLength: newTexCoordArray.buffer.byteLength,
2381
+ byteOffset: 0
2382
+ });
2383
+ const accessors = gltfData.json.accessors;
2384
+ if (!accessors) {
2385
+ return;
2386
+ }
2387
+ accessors.push({
2388
+ bufferView: (bufferViews == null ? void 0 : bufferViews.length) - 1,
2389
+ byteOffset: 0,
2390
+ componentType: 5126,
2391
+ count: originalAccessor.count,
2392
+ type: "VEC2"
2393
+ });
2394
+ primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;
2395
+ }
2396
+ function makeTransformationMatrix(extensionData) {
2397
+ const { offset = [0, 0], rotation = 0, scale = [1, 1] } = extensionData;
2398
+ const translationMatrix = new import_core.Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
2399
+ const rotationMatrix = scratchRotationMatrix.set(
2400
+ Math.cos(rotation),
2401
+ Math.sin(rotation),
2402
+ 0,
2403
+ -Math.sin(rotation),
2404
+ Math.cos(rotation),
2405
+ 0,
2406
+ 0,
2407
+ 0,
2408
+ 1
2409
+ );
2410
+ const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
2411
+ return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
2412
+ }
2413
+
2414
+ // src/lib/extensions/deprecated/KHR_lights_punctual.ts
2415
+ var KHR_lights_punctual_exports = {};
2416
+ __export(KHR_lights_punctual_exports, {
2417
+ decode: () => decode8,
2418
+ encode: () => encode2,
2419
+ name: () => name9
2420
+ });
2421
+ var KHR_LIGHTS_PUNCTUAL = "KHR_lights_punctual";
2422
+ var name9 = KHR_LIGHTS_PUNCTUAL;
2423
+ async function decode8(gltfData) {
2424
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
2425
+ const { json } = gltfScenegraph;
2426
+ const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
2427
+ if (extension) {
2428
+ gltfScenegraph.json.lights = extension.lights;
2429
+ gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
2430
+ }
2431
+ for (const node of json.nodes || []) {
2432
+ const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
2433
+ if (nodeExtension) {
2434
+ node.light = nodeExtension.light;
2435
+ }
2436
+ gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
2437
+ }
2438
+ }
2439
+ async function encode2(gltfData) {
2440
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
2441
+ const { json } = gltfScenegraph;
2442
+ if (json.lights) {
2443
+ const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
2444
+ assert(!extension.lights);
2445
+ extension.lights = json.lights;
2446
+ delete json.lights;
2447
+ }
2448
+ if (gltfScenegraph.json.lights) {
2449
+ for (const light of gltfScenegraph.json.lights) {
2450
+ const node = light.node;
2451
+ gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
2452
+ }
2453
+ delete gltfScenegraph.json.lights;
2454
+ }
2455
+ }
2456
+
2457
+ // src/lib/extensions/deprecated/KHR_materials_unlit.ts
2458
+ var KHR_materials_unlit_exports = {};
2459
+ __export(KHR_materials_unlit_exports, {
2460
+ decode: () => decode9,
2461
+ encode: () => encode3,
2462
+ name: () => name10
2463
+ });
2464
+ var KHR_MATERIALS_UNLIT = "KHR_materials_unlit";
2465
+ var name10 = KHR_MATERIALS_UNLIT;
2466
+ async function decode9(gltfData) {
2467
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
2468
+ const { json } = gltfScenegraph;
2469
+ for (const material of json.materials || []) {
2470
+ const extension = material.extensions && material.extensions.KHR_materials_unlit;
2471
+ if (extension) {
2472
+ material.unlit = true;
2473
+ }
2474
+ gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
2475
+ }
2476
+ gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
2477
+ }
2478
+ function encode3(gltfData) {
2479
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
2480
+ const { json } = gltfScenegraph;
2481
+ if (gltfScenegraph.materials) {
2482
+ for (const material of json.materials || []) {
2483
+ if (material.unlit) {
2484
+ delete material.unlit;
2485
+ gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
2486
+ gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
2487
+ }
2488
+ }
2489
+ }
2490
+ }
2491
+
2492
+ // src/lib/extensions/deprecated/KHR_techniques_webgl.ts
2493
+ var KHR_techniques_webgl_exports = {};
2494
+ __export(KHR_techniques_webgl_exports, {
2495
+ decode: () => decode10,
2496
+ encode: () => encode4,
2497
+ name: () => name11
2498
+ });
2499
+ var KHR_TECHNIQUES_WEBGL = "KHR_techniques_webgl";
2500
+ var name11 = KHR_TECHNIQUES_WEBGL;
2501
+ async function decode10(gltfData) {
2502
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
2503
+ const { json } = gltfScenegraph;
2504
+ const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
2505
+ if (extension) {
2506
+ const techniques = resolveTechniques(extension, gltfScenegraph);
2507
+ for (const material of json.materials || []) {
2508
+ const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
2509
+ if (materialExtension) {
2510
+ material.technique = Object.assign(
2511
+ {},
2512
+ materialExtension,
2513
+ // @ts-ignore
2514
+ techniques[materialExtension.technique]
2515
+ );
2516
+ material.technique.values = resolveValues(material.technique, gltfScenegraph);
2517
+ }
2518
+ gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
2519
+ }
2520
+ gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
2521
+ }
2522
+ }
2523
+ async function encode4(gltfData, options) {
2524
+ }
2525
+ function resolveTechniques(techniquesExtension, gltfScenegraph) {
2526
+ const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
2527
+ const textDecoder = new TextDecoder();
2528
+ shaders.forEach((shader) => {
2529
+ if (Number.isFinite(shader.bufferView)) {
2530
+ shader.code = textDecoder.decode(
2531
+ gltfScenegraph.getTypedArrayForBufferView(shader.bufferView)
2532
+ );
2533
+ } else {
2534
+ throw new Error("KHR_techniques_webgl: no shader code");
2535
+ }
2536
+ });
2537
+ programs.forEach((program) => {
2538
+ program.fragmentShader = shaders[program.fragmentShader];
2539
+ program.vertexShader = shaders[program.vertexShader];
2540
+ });
2541
+ techniques.forEach((technique) => {
2542
+ technique.program = programs[technique.program];
2543
+ });
2544
+ return techniques;
2545
+ }
2546
+ function resolveValues(technique, gltfScenegraph) {
2547
+ const values = Object.assign({}, technique.values);
2548
+ Object.keys(technique.uniforms || {}).forEach((uniform) => {
2549
+ if (technique.uniforms[uniform].value && !(uniform in values)) {
2550
+ values[uniform] = technique.uniforms[uniform].value;
2551
+ }
2552
+ });
2553
+ Object.keys(values).forEach((uniform) => {
2554
+ if (typeof values[uniform] === "object" && values[uniform].index !== void 0) {
2555
+ values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
2556
+ }
2557
+ });
2558
+ return values;
2559
+ }
2560
+
2561
+ // src/lib/api/gltf-extensions.ts
2562
+ var EXTENSIONS = [
2563
+ // 1.0
2564
+ // KHR_binary_gltf is handled separately - must be processed before other parsing starts
2565
+ // KHR_binary_gltf,
2566
+ // 2.0
2567
+ EXT_structural_metadata_exports,
2568
+ EXT_mesh_features_exports,
2569
+ EXT_meshopt_compression_exports,
2570
+ EXT_texture_webp_exports,
2571
+ // Basisu should come after webp, we want basisu to be preferred if both are provided
2572
+ KHR_texture_basisu_exports,
2573
+ KHR_draco_mesh_compression_exports,
2574
+ KHR_lights_punctual_exports,
2575
+ KHR_materials_unlit_exports,
2576
+ KHR_techniques_webgl_exports,
2577
+ KHR_texture_transform_exports,
2578
+ EXT_feature_metadata_exports
2579
+ ];
2580
+ function preprocessExtensions(gltf, options = {}, context) {
2581
+ var _a;
2582
+ const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));
2583
+ for (const extension of extensions) {
2584
+ (_a = extension.preprocess) == null ? void 0 : _a.call(extension, gltf, options, context);
2585
+ }
2586
+ }
2587
+ async function decodeExtensions(gltf, options = {}, context) {
2588
+ var _a;
2589
+ const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));
2590
+ for (const extension of extensions) {
2591
+ await ((_a = extension.decode) == null ? void 0 : _a.call(extension, gltf, options, context));
2592
+ }
2593
+ }
2594
+ function useExtension(extensionName, options) {
2595
+ var _a;
2596
+ const excludes = ((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.excludeExtensions) || {};
2597
+ const exclude = extensionName in excludes && !excludes[extensionName];
2598
+ return !exclude;
2599
+ }
2600
+
2601
+ // src/lib/extensions/KHR_binary_gltf.ts
2602
+ var KHR_BINARY_GLTF = "KHR_binary_glTF";
2603
+ function preprocess4(gltfData) {
2604
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
2605
+ const { json } = gltfScenegraph;
2606
+ for (const image of json.images || []) {
2607
+ const extension = gltfScenegraph.getObjectExtension(
2608
+ image,
2609
+ KHR_BINARY_GLTF
2610
+ );
2611
+ if (extension) {
2612
+ Object.assign(image, extension);
2613
+ }
2614
+ gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);
2615
+ }
2616
+ if (json.buffers && json.buffers[0]) {
2617
+ delete json.buffers[0].uri;
2618
+ }
2619
+ gltfScenegraph.removeExtension(KHR_BINARY_GLTF);
2620
+ }
2621
+
2622
+ // src/lib/api/normalize-gltf-v1.ts
2623
+ var GLTF_ARRAYS = {
2624
+ accessors: "accessor",
2625
+ animations: "animation",
2626
+ buffers: "buffer",
2627
+ bufferViews: "bufferView",
2628
+ images: "image",
2629
+ materials: "material",
2630
+ meshes: "mesh",
2631
+ nodes: "node",
2632
+ samplers: "sampler",
2633
+ scenes: "scene",
2634
+ skins: "skin",
2635
+ textures: "texture"
2636
+ };
2637
+ var GLTF_KEYS = {
2638
+ accessor: "accessors",
2639
+ animations: "animation",
2640
+ buffer: "buffers",
2641
+ bufferView: "bufferViews",
2642
+ image: "images",
2643
+ material: "materials",
2644
+ mesh: "meshes",
2645
+ node: "nodes",
2646
+ sampler: "samplers",
2647
+ scene: "scenes",
2648
+ skin: "skins",
2649
+ texture: "textures"
2650
+ };
2651
+ var GLTFV1Normalizer = class {
2652
+ constructor() {
2653
+ this.idToIndexMap = {
2654
+ animations: {},
2655
+ accessors: {},
2656
+ buffers: {},
2657
+ bufferViews: {},
2658
+ images: {},
2659
+ materials: {},
2660
+ meshes: {},
2661
+ nodes: {},
2662
+ samplers: {},
2663
+ scenes: {},
2664
+ skins: {},
2665
+ textures: {}
2666
+ };
2667
+ }
2668
+ // constructor() {}
2669
+ /**
2670
+ * Convert (normalize) glTF < 2.0 to glTF 2.0
2671
+ * @param gltf - object with json and binChunks
2672
+ * @param options
2673
+ * @param options normalize Whether to actually normalize
2674
+ */
2675
+ normalize(gltf, options) {
2676
+ this.json = gltf.json;
2677
+ const json = gltf.json;
2678
+ switch (json.asset && json.asset.version) {
2679
+ case "2.0":
2680
+ return;
2681
+ case void 0:
2682
+ case "1.0":
2683
+ break;
2684
+ default:
2685
+ console.warn(`glTF: Unknown version ${json.asset.version}`);
2686
+ return;
2687
+ }
2688
+ if (!options.normalize) {
2689
+ throw new Error("glTF v1 is not supported.");
2690
+ }
2691
+ console.warn("Converting glTF v1 to glTF v2 format. This is experimental and may fail.");
2692
+ this._addAsset(json);
2693
+ this._convertTopLevelObjectsToArrays(json);
2694
+ preprocess4(gltf);
2695
+ this._convertObjectIdsToArrayIndices(json);
2696
+ this._updateObjects(json);
2697
+ this._updateMaterial(json);
2698
+ }
2699
+ // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639
2700
+ _addAsset(json) {
2701
+ json.asset = json.asset || {};
2702
+ json.asset.version = "2.0";
2703
+ json.asset.generator = json.asset.generator || "Normalized to glTF 2.0 by loaders.gl";
2704
+ }
2705
+ _convertTopLevelObjectsToArrays(json) {
2706
+ for (const arrayName in GLTF_ARRAYS) {
2707
+ this._convertTopLevelObjectToArray(json, arrayName);
2708
+ }
2709
+ }
2710
+ /** Convert one top level object to array */
2711
+ _convertTopLevelObjectToArray(json, mapName) {
2712
+ const objectMap = json[mapName];
2713
+ if (!objectMap || Array.isArray(objectMap)) {
2714
+ return;
2715
+ }
2716
+ json[mapName] = [];
2717
+ for (const id in objectMap) {
2718
+ const object = objectMap[id];
2719
+ object.id = object.id || id;
2720
+ const index = json[mapName].length;
2721
+ json[mapName].push(object);
2722
+ this.idToIndexMap[mapName][id] = index;
2723
+ }
2724
+ }
2725
+ /** Go through all objects in all top-level arrays and replace ids with indices */
2726
+ _convertObjectIdsToArrayIndices(json) {
2727
+ for (const arrayName in GLTF_ARRAYS) {
2728
+ this._convertIdsToIndices(json, arrayName);
2729
+ }
2730
+ if ("scene" in json) {
2731
+ json.scene = this._convertIdToIndex(json.scene, "scene");
2732
+ }
2733
+ for (const texture of json.textures) {
2734
+ this._convertTextureIds(texture);
2735
+ }
2736
+ for (const mesh of json.meshes) {
2737
+ this._convertMeshIds(mesh);
2738
+ }
2739
+ for (const node of json.nodes) {
2740
+ this._convertNodeIds(node);
2741
+ }
2742
+ for (const node of json.scenes) {
2743
+ this._convertSceneIds(node);
2744
+ }
2745
+ }
2746
+ _convertTextureIds(texture) {
2747
+ if (texture.source) {
2748
+ texture.source = this._convertIdToIndex(texture.source, "image");
2749
+ }
2750
+ }
2751
+ _convertMeshIds(mesh) {
2752
+ for (const primitive of mesh.primitives) {
2753
+ const { attributes, indices, material } = primitive;
2754
+ for (const attributeName in attributes) {
2755
+ attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], "accessor");
2756
+ }
2757
+ if (indices) {
2758
+ primitive.indices = this._convertIdToIndex(indices, "accessor");
2759
+ }
2760
+ if (material) {
2761
+ primitive.material = this._convertIdToIndex(material, "material");
2762
+ }
2763
+ }
2764
+ }
2765
+ _convertNodeIds(node) {
2766
+ if (node.children) {
2767
+ node.children = node.children.map((child) => this._convertIdToIndex(child, "node"));
2768
+ }
2769
+ if (node.meshes) {
2770
+ node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, "mesh"));
2771
+ }
2772
+ }
2773
+ _convertSceneIds(scene) {
2774
+ if (scene.nodes) {
2775
+ scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, "node"));
2776
+ }
2777
+ }
2778
+ /** Go through all objects in a top-level array and replace ids with indices */
2779
+ _convertIdsToIndices(json, topLevelArrayName) {
2780
+ if (!json[topLevelArrayName]) {
2781
+ console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`);
2782
+ json[topLevelArrayName] = [];
2783
+ }
2784
+ for (const object of json[topLevelArrayName]) {
2785
+ for (const key in object) {
2786
+ const id = object[key];
2787
+ const index = this._convertIdToIndex(id, key);
2788
+ object[key] = index;
2789
+ }
2790
+ }
2791
+ }
2792
+ _convertIdToIndex(id, key) {
2793
+ const arrayName = GLTF_KEYS[key];
2794
+ if (arrayName in this.idToIndexMap) {
2795
+ const index = this.idToIndexMap[arrayName][id];
2796
+ if (!Number.isFinite(index)) {
2797
+ throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);
2798
+ }
2799
+ return index;
2800
+ }
2801
+ return id;
2802
+ }
2803
+ /**
2804
+ *
2805
+ * @param {*} json
2806
+ */
2807
+ _updateObjects(json) {
2808
+ for (const buffer of this.json.buffers) {
2809
+ delete buffer.type;
2810
+ }
2811
+ }
2812
+ /**
2813
+ * Update material (set pbrMetallicRoughness)
2814
+ * @param {*} json
2815
+ */
2816
+ _updateMaterial(json) {
2817
+ var _a, _b, _c;
2818
+ for (const material of json.materials) {
2819
+ material.pbrMetallicRoughness = {
2820
+ baseColorFactor: [1, 1, 1, 1],
2821
+ metallicFactor: 1,
2822
+ roughnessFactor: 1
2823
+ };
2824
+ const textureId = ((_a = material.values) == null ? void 0 : _a.tex) || ((_b = material.values) == null ? void 0 : _b.texture2d_0) || ((_c = material.values) == null ? void 0 : _c.diffuseTex);
2825
+ const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);
2826
+ if (textureIndex !== -1) {
2827
+ material.pbrMetallicRoughness.baseColorTexture = { index: textureIndex };
2828
+ }
2829
+ }
2830
+ }
2831
+ };
2832
+ function normalizeGLTFV1(gltf, options = {}) {
2833
+ return new GLTFV1Normalizer().normalize(gltf, options);
2834
+ }
2835
+
2836
+ // src/lib/parsers/parse-gltf.ts
2837
+ async function parseGLTF(gltf, arrayBufferOrString, byteOffset = 0, options, context) {
2838
+ var _a, _b, _c;
2839
+ parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);
2840
+ normalizeGLTFV1(gltf, { normalize: (_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.normalize });
2841
+ preprocessExtensions(gltf, options, context);
2842
+ if (((_b = options == null ? void 0 : options.gltf) == null ? void 0 : _b.loadBuffers) && gltf.json.buffers) {
2843
+ await loadBuffers(gltf, options, context);
2844
+ }
2845
+ if ((_c = options == null ? void 0 : options.gltf) == null ? void 0 : _c.loadImages) {
2846
+ await loadImages(gltf, options, context);
2847
+ }
2848
+ await decodeExtensions(gltf, options, context);
2849
+ return gltf;
2850
+ }
2851
+ function parseGLTFContainerSync(gltf, data, byteOffset, options) {
2852
+ if (options.uri) {
2853
+ gltf.baseUri = options.uri;
2854
+ }
2855
+ if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options)) {
2856
+ const textDecoder = new TextDecoder();
2857
+ data = textDecoder.decode(data);
2858
+ }
2859
+ if (typeof data === "string") {
2860
+ gltf.json = (0, import_loader_utils4.parseJSON)(data);
2861
+ } else if (data instanceof ArrayBuffer) {
2862
+ const glb = {};
2863
+ byteOffset = parseGLBSync(glb, data, byteOffset, options.glb);
2864
+ assert(glb.type === "glTF", `Invalid GLB magic string ${glb.type}`);
2865
+ gltf._glb = glb;
2866
+ gltf.json = glb.json;
2867
+ } else {
2868
+ assert(false, "GLTF: must be ArrayBuffer or string");
2869
+ }
2870
+ const buffers = gltf.json.buffers || [];
2871
+ gltf.buffers = new Array(buffers.length).fill(null);
2872
+ if (gltf._glb && gltf._glb.header.hasBinChunk) {
2873
+ const { binChunks } = gltf._glb;
2874
+ gltf.buffers[0] = {
2875
+ arrayBuffer: binChunks[0].arrayBuffer,
2876
+ byteOffset: binChunks[0].byteOffset,
2877
+ byteLength: binChunks[0].byteLength
2878
+ };
2879
+ }
2880
+ const images = gltf.json.images || [];
2881
+ gltf.images = new Array(images.length).fill({});
2882
+ }
2883
+ async function loadBuffers(gltf, options, context) {
2884
+ var _a, _b;
2885
+ const buffers = gltf.json.buffers || [];
2886
+ for (let i = 0; i < buffers.length; ++i) {
2887
+ const buffer = buffers[i];
2888
+ if (buffer.uri) {
2889
+ const { fetch } = context;
2890
+ assert(fetch);
2891
+ const uri = resolveUrl(buffer.uri, options);
2892
+ const response = await ((_a = context == null ? void 0 : context.fetch) == null ? void 0 : _a.call(context, uri));
2893
+ const arrayBuffer = await ((_b = response == null ? void 0 : response.arrayBuffer) == null ? void 0 : _b.call(response));
2894
+ gltf.buffers[i] = {
2895
+ arrayBuffer,
2896
+ byteOffset: 0,
2897
+ byteLength: arrayBuffer.byteLength
2898
+ };
2899
+ delete buffer.uri;
2900
+ } else if (gltf.buffers[i] === null) {
2901
+ gltf.buffers[i] = {
2902
+ arrayBuffer: new ArrayBuffer(buffer.byteLength),
2903
+ byteOffset: 0,
2904
+ byteLength: buffer.byteLength
2905
+ };
2906
+ }
2907
+ }
2908
+ }
2909
+ async function loadImages(gltf, options, context) {
2910
+ const imageIndices = getReferencesImageIndices(gltf);
2911
+ const images = gltf.json.images || [];
2912
+ const promises = [];
2913
+ for (const imageIndex of imageIndices) {
2914
+ promises.push(loadImage(gltf, images[imageIndex], imageIndex, options, context));
2915
+ }
2916
+ return await Promise.all(promises);
2917
+ }
2918
+ function getReferencesImageIndices(gltf) {
2919
+ const imageIndices = /* @__PURE__ */ new Set();
2920
+ const textures = gltf.json.textures || [];
2921
+ for (const texture of textures) {
2922
+ if (texture.source !== void 0) {
2923
+ imageIndices.add(texture.source);
2924
+ }
2925
+ }
2926
+ return Array.from(imageIndices).sort();
2927
+ }
2928
+ async function loadImage(gltf, image, index, options, context) {
2929
+ let arrayBuffer;
2930
+ if (image.uri && !image.hasOwnProperty("bufferView")) {
2931
+ const uri = resolveUrl(image.uri, options);
2932
+ const { fetch } = context;
2933
+ const response = await fetch(uri);
2934
+ arrayBuffer = await response.arrayBuffer();
2935
+ image.bufferView = {
2936
+ data: arrayBuffer
2937
+ };
2938
+ }
2939
+ if (Number.isFinite(image.bufferView)) {
2940
+ const array = getTypedArrayForBufferView(gltf.json, gltf.buffers, image.bufferView);
2941
+ arrayBuffer = (0, import_loader_utils4.sliceArrayBuffer)(array.buffer, array.byteOffset, array.byteLength);
2942
+ }
2943
+ assert(arrayBuffer, "glTF image has no data");
2944
+ let parsedImage = await (0, import_loader_utils4.parseFromContext)(
2945
+ arrayBuffer,
2946
+ [import_images4.ImageLoader, import_textures.BasisLoader],
2947
+ {
2948
+ ...options,
2949
+ mimeType: image.mimeType,
2950
+ basis: options.basis || { format: (0, import_textures.selectSupportedBasisFormat)() }
2951
+ },
2952
+ context
2953
+ );
2954
+ if (parsedImage && parsedImage[0]) {
2955
+ parsedImage = {
2956
+ compressed: true,
2957
+ // @ts-expect-error
2958
+ mipmaps: false,
2959
+ width: parsedImage[0].width,
2960
+ height: parsedImage[0].height,
2961
+ data: parsedImage[0]
2962
+ };
2963
+ }
2964
+ gltf.images = gltf.images || [];
2965
+ gltf.images[index] = parsedImage;
2966
+ }
2967
+
2968
+ // src/gltf-loader.ts
2969
+ var GLTFLoader = {
2970
+ name: "glTF",
2971
+ id: "gltf",
2972
+ module: "gltf",
2973
+ version: VERSION,
2974
+ extensions: ["gltf", "glb"],
2975
+ mimeTypes: ["model/gltf+json", "model/gltf-binary"],
2976
+ text: true,
2977
+ binary: true,
2978
+ tests: ["glTF"],
2979
+ parse,
2980
+ options: {
2981
+ gltf: {
2982
+ normalize: true,
2983
+ // Normalize glTF v1 to glTF v2 format (not yet stable)
2984
+ loadBuffers: true,
2985
+ // Fetch any linked .BIN buffers, decode base64
2986
+ loadImages: true,
2987
+ // Create image objects
2988
+ decompressMeshes: true
2989
+ // Decompress Draco encoded meshes
2990
+ },
2991
+ // common?
2992
+ log: console
2993
+ // eslint-disable-line
2994
+ },
2995
+ deprecatedOptions: {
2996
+ fetchImages: "gltf.loadImages",
2997
+ createImages: "gltf.loadImages",
2998
+ decompress: "gltf.decompressMeshes",
2999
+ postProcess: "gltf.postProcess",
3000
+ gltf: {
3001
+ decompress: "gltf.decompressMeshes",
3002
+ postProcess: "removed in v4"
3003
+ }
3004
+ }
3005
+ };
3006
+ async function parse(arrayBuffer, options = {}, context) {
3007
+ options = { ...GLTFLoader.options, ...options };
3008
+ options.gltf = { ...GLTFLoader.options.gltf, ...options.gltf };
3009
+ const { byteOffset = 0 } = options;
3010
+ const gltf = {};
3011
+ return await parseGLTF(gltf, arrayBuffer, byteOffset, options, context);
3012
+ }
3013
+
3014
+ // src/lib/encoders/encode-glb.ts
3015
+ var import_loader_utils5 = require("@loaders.gl/loader-utils");
3016
+ var MAGIC_glTF2 = 1179937895;
3017
+ var MAGIC_JSON = 1313821514;
3018
+ var MAGIC_BIN = 5130562;
3019
+ var LE = true;
3020
+ function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) {
3021
+ const { magic = MAGIC_glTF2, version = 2, json = {}, binary } = glb;
3022
+ const byteOffsetStart = byteOffset;
3023
+ if (dataView) {
3024
+ dataView.setUint32(byteOffset + 0, magic, LE);
3025
+ dataView.setUint32(byteOffset + 4, version, LE);
3026
+ dataView.setUint32(byteOffset + 8, 0, LE);
3027
+ }
3028
+ const byteOffsetFileLength = byteOffset + 8;
3029
+ byteOffset += 12;
3030
+ const byteOffsetJsonHeader = byteOffset;
3031
+ if (dataView) {
3032
+ dataView.setUint32(byteOffset + 0, 0, LE);
3033
+ dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE);
3034
+ }
3035
+ byteOffset += 8;
3036
+ const jsonString = JSON.stringify(json);
3037
+ byteOffset = (0, import_loader_utils5.copyPaddedStringToDataView)(dataView, byteOffset, jsonString, 4);
3038
+ if (dataView) {
3039
+ const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8;
3040
+ dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE);
3041
+ }
3042
+ if (binary) {
3043
+ const byteOffsetBinHeader = byteOffset;
3044
+ if (dataView) {
3045
+ dataView.setUint32(byteOffset + 0, 0, LE);
3046
+ dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE);
3047
+ }
3048
+ byteOffset += 8;
3049
+ byteOffset = (0, import_loader_utils5.copyPaddedArrayBufferToDataView)(dataView, byteOffset, binary, 4);
3050
+ if (dataView) {
3051
+ const binByteLength = byteOffset - byteOffsetBinHeader - 8;
3052
+ dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE);
3053
+ }
3054
+ }
3055
+ if (dataView) {
3056
+ const fileByteLength = byteOffset - byteOffsetStart;
3057
+ dataView.setUint32(byteOffsetFileLength, fileByteLength, LE);
3058
+ }
3059
+ return byteOffset;
3060
+ }
3061
+
3062
+ // src/lib/encoders/encode-gltf.ts
3063
+ function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
3064
+ convertBuffersToBase64(gltf);
3065
+ return encodeGLBSync(gltf, arrayBuffer, byteOffset, options);
3066
+ }
3067
+ function convertBuffersToBase64(gltf, { firstBuffer = 0 } = {}) {
3068
+ if (gltf.buffers && gltf.buffers.length > firstBuffer) {
3069
+ throw new Error("encodeGLTF: multiple buffers not yet implemented");
3070
+ }
3071
+ }
3072
+
3073
+ // src/gltf-writer.ts
3074
+ var GLTFWriter = {
3075
+ name: "glTF",
3076
+ id: "gltf",
3077
+ module: "gltf",
3078
+ version: VERSION,
3079
+ extensions: ["glb"],
3080
+ // We only support encoding to binary GLB, not to JSON GLTF
3081
+ mimeTypes: ["model/gltf-binary"],
3082
+ // 'model/gltf+json',
3083
+ binary: true,
3084
+ encodeSync,
3085
+ options: {
3086
+ gltf: {}
3087
+ }
3088
+ };
3089
+ function encodeSync(gltf, options = {}) {
3090
+ const { byteOffset = 0 } = options;
3091
+ const byteLength = encodeGLTFSync(gltf, null, byteOffset, options);
3092
+ const arrayBuffer = new ArrayBuffer(byteLength);
3093
+ const dataView = new DataView(arrayBuffer);
3094
+ encodeGLTFSync(gltf, dataView, byteOffset, options);
3095
+ return arrayBuffer;
3096
+ }
3097
+
3098
+ // src/glb-loader.ts
3099
+ var GLBLoader = {
3100
+ name: "GLB",
3101
+ id: "glb",
3102
+ module: "gltf",
3103
+ version: VERSION,
3104
+ extensions: ["glb"],
3105
+ mimeTypes: ["model/gltf-binary"],
3106
+ binary: true,
3107
+ parse: parse2,
3108
+ parseSync,
3109
+ options: {
3110
+ glb: {
3111
+ strict: false
3112
+ // Enables deprecated XVIZ support (illegal CHUNK formats)
3113
+ }
3114
+ }
3115
+ };
3116
+ async function parse2(arrayBuffer, options) {
3117
+ return parseSync(arrayBuffer, options);
3118
+ }
3119
+ function parseSync(arrayBuffer, options) {
3120
+ const { byteOffset = 0 } = options || {};
3121
+ const glb = {};
3122
+ parseGLBSync(glb, arrayBuffer, byteOffset, options == null ? void 0 : options.glb);
3123
+ return glb;
3124
+ }
3125
+
3126
+ // src/glb-writer.ts
3127
+ var GLBWriter = {
3128
+ name: "GLB",
3129
+ id: "glb",
3130
+ module: "gltf",
3131
+ version: VERSION,
3132
+ extensions: ["glb"],
3133
+ mimeTypes: ["model/gltf-binary"],
3134
+ binary: true,
3135
+ encodeSync: encodeSync2,
3136
+ options: {
3137
+ glb: {}
3138
+ }
3139
+ };
3140
+ function encodeSync2(glb, options) {
3141
+ const { byteOffset = 0 } = options;
3142
+ const byteLength = encodeGLBSync(glb, null, byteOffset, options);
3143
+ const arrayBuffer = new ArrayBuffer(byteLength);
3144
+ const dataView = new DataView(arrayBuffer);
3145
+ encodeGLBSync(glb, dataView, byteOffset, options);
3146
+ return arrayBuffer;
3147
+ }
3148
+
3149
+ // src/lib/api/post-process-gltf.ts
3150
+ var COMPONENTS2 = {
3151
+ SCALAR: 1,
3152
+ VEC2: 2,
3153
+ VEC3: 3,
3154
+ VEC4: 4,
3155
+ MAT2: 4,
3156
+ MAT3: 9,
3157
+ MAT4: 16
3158
+ };
3159
+ var BYTES2 = {
3160
+ 5120: 1,
3161
+ // BYTE
3162
+ 5121: 1,
3163
+ // UNSIGNED_BYTE
3164
+ 5122: 2,
3165
+ // SHORT
3166
+ 5123: 2,
3167
+ // UNSIGNED_SHORT
3168
+ 5125: 4,
3169
+ // UNSIGNED_INT
3170
+ 5126: 4
3171
+ // FLOAT
3172
+ };
3173
+ var GL_SAMPLER = {
3174
+ // Sampler parameters
3175
+ TEXTURE_MAG_FILTER: 10240,
3176
+ TEXTURE_MIN_FILTER: 10241,
3177
+ TEXTURE_WRAP_S: 10242,
3178
+ TEXTURE_WRAP_T: 10243,
3179
+ // Sampler default values
3180
+ REPEAT: 10497,
3181
+ LINEAR: 9729,
3182
+ NEAREST_MIPMAP_LINEAR: 9986
3183
+ };
3184
+ var SAMPLER_PARAMETER_GLTF_TO_GL = {
3185
+ magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
3186
+ minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
3187
+ wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
3188
+ wrapT: GL_SAMPLER.TEXTURE_WRAP_T
3189
+ };
3190
+ var DEFAULT_SAMPLER_PARAMETERS = {
3191
+ [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
3192
+ [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
3193
+ [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
3194
+ [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
3195
+ };
3196
+ function makeDefaultSampler() {
3197
+ return {
3198
+ id: "default-sampler",
3199
+ parameters: DEFAULT_SAMPLER_PARAMETERS
3200
+ };
3201
+ }
3202
+ function getBytesFromComponentType(componentType) {
3203
+ return BYTES2[componentType];
3204
+ }
3205
+ function getSizeFromAccessorType(type) {
3206
+ return COMPONENTS2[type];
3207
+ }
3208
+ var GLTFPostProcessor = class {
3209
+ constructor() {
3210
+ this.baseUri = "";
3211
+ this.buffers = [];
3212
+ this.images = [];
3213
+ }
3214
+ postProcess(gltf, options = {}) {
3215
+ const { json, buffers = [], images = [] } = gltf;
3216
+ const { baseUri = "" } = gltf;
3217
+ assert(json);
3218
+ this.baseUri = baseUri;
3219
+ this.buffers = buffers;
3220
+ this.images = images;
3221
+ this.jsonUnprocessed = json;
3222
+ this.json = this._resolveTree(gltf.json, options);
3223
+ return this.json;
3224
+ }
3225
+ // Convert indexed glTF structure into tree structure
3226
+ // cross-link index resolution, enum lookup, convenience calculations
3227
+ // eslint-disable-next-line complexity, max-statements
3228
+ _resolveTree(gltf, options = {}) {
3229
+ const json = { ...gltf };
3230
+ this.json = json;
3231
+ if (gltf.bufferViews) {
3232
+ json.bufferViews = gltf.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));
3233
+ }
3234
+ if (gltf.images) {
3235
+ json.images = gltf.images.map((image, i) => this._resolveImage(image, i));
3236
+ }
3237
+ if (gltf.samplers) {
3238
+ json.samplers = gltf.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
3239
+ }
3240
+ if (gltf.textures) {
3241
+ json.textures = gltf.textures.map((texture, i) => this._resolveTexture(texture, i));
3242
+ }
3243
+ if (gltf.accessors) {
3244
+ json.accessors = gltf.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
3245
+ }
3246
+ if (gltf.materials) {
3247
+ json.materials = gltf.materials.map((material, i) => this._resolveMaterial(material, i));
3248
+ }
3249
+ if (gltf.meshes) {
3250
+ json.meshes = gltf.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
3251
+ }
3252
+ if (gltf.nodes) {
3253
+ json.nodes = gltf.nodes.map((node, i) => this._resolveNode(node, i));
3254
+ json.nodes = json.nodes.map((node, i) => this._resolveNodeChildren(node));
3255
+ }
3256
+ if (gltf.skins) {
3257
+ json.skins = gltf.skins.map((skin, i) => this._resolveSkin(skin, i));
3258
+ }
3259
+ if (gltf.scenes) {
3260
+ json.scenes = gltf.scenes.map((scene, i) => this._resolveScene(scene, i));
3261
+ }
3262
+ if (typeof this.json.scene === "number" && json.scenes) {
3263
+ json.scene = json.scenes[this.json.scene];
3264
+ }
3265
+ return json;
3266
+ }
3267
+ getScene(index) {
3268
+ return this._get(this.json.scenes, index);
3269
+ }
3270
+ getNode(index) {
3271
+ return this._get(this.json.nodes, index);
3272
+ }
3273
+ getSkin(index) {
3274
+ return this._get(this.json.skins, index);
3275
+ }
3276
+ getMesh(index) {
3277
+ return this._get(this.json.meshes, index);
3278
+ }
3279
+ getMaterial(index) {
3280
+ return this._get(this.json.materials, index);
3281
+ }
3282
+ getAccessor(index) {
3283
+ return this._get(this.json.accessors, index);
3284
+ }
3285
+ getCamera(index) {
3286
+ return this._get(this.json.cameras, index);
3287
+ }
3288
+ getTexture(index) {
3289
+ return this._get(this.json.textures, index);
3290
+ }
3291
+ getSampler(index) {
3292
+ return this._get(this.json.samplers, index);
3293
+ }
3294
+ getImage(index) {
3295
+ return this._get(this.json.images, index);
3296
+ }
3297
+ getBufferView(index) {
3298
+ return this._get(this.json.bufferViews, index);
3299
+ }
3300
+ getBuffer(index) {
3301
+ return this._get(this.json.buffers, index);
3302
+ }
3303
+ _get(array, index) {
3304
+ if (typeof index === "object") {
3305
+ return index;
3306
+ }
3307
+ const object = array && array[index];
3308
+ if (!object) {
3309
+ console.warn(`glTF file error: Could not find ${array}[${index}]`);
3310
+ }
3311
+ return object;
3312
+ }
3313
+ // PARSING HELPERS
3314
+ _resolveScene(scene, index) {
3315
+ return {
3316
+ ...scene,
3317
+ // @ts-ignore
3318
+ id: scene.id || `scene-${index}`,
3319
+ nodes: (scene.nodes || []).map((node) => this.getNode(node))
3320
+ };
3321
+ }
3322
+ _resolveNode(gltfNode, index) {
3323
+ const node = {
3324
+ ...gltfNode,
3325
+ // @ts-expect-error id could already be present, glTF standard does not prevent it
3326
+ id: (gltfNode == null ? void 0 : gltfNode.id) || `node-${index}`
3327
+ };
3328
+ if (gltfNode.mesh !== void 0) {
3329
+ node.mesh = this.getMesh(gltfNode.mesh);
3330
+ }
3331
+ if (gltfNode.camera !== void 0) {
3332
+ node.camera = this.getCamera(gltfNode.camera);
3333
+ }
3334
+ if (gltfNode.skin !== void 0) {
3335
+ node.skin = this.getSkin(gltfNode.skin);
3336
+ }
3337
+ if (gltfNode.meshes !== void 0 && gltfNode.meshes.length) {
3338
+ node.mesh = gltfNode.meshes.reduce(
3339
+ (accum, meshIndex) => {
3340
+ const mesh = this.getMesh(meshIndex);
3341
+ accum.id = mesh.id;
3342
+ accum.primitives = accum.primitives.concat(mesh.primitives);
3343
+ return accum;
3344
+ },
3345
+ { primitives: [] }
3346
+ );
3347
+ }
3348
+ return node;
3349
+ }
3350
+ _resolveNodeChildren(node) {
3351
+ if (node.children) {
3352
+ node.children = node.children.map((child) => this.getNode(child));
3353
+ }
3354
+ return node;
3355
+ }
3356
+ _resolveSkin(gltfSkin, index) {
3357
+ const inverseBindMatrices = typeof gltfSkin.inverseBindMatrices === "number" ? this.getAccessor(gltfSkin.inverseBindMatrices) : void 0;
3358
+ return {
3359
+ ...gltfSkin,
3360
+ id: gltfSkin.id || `skin-${index}`,
3361
+ inverseBindMatrices
3362
+ };
3363
+ }
3364
+ _resolveMesh(gltfMesh, index) {
3365
+ const mesh = {
3366
+ ...gltfMesh,
3367
+ id: gltfMesh.id || `mesh-${index}`,
3368
+ primitives: []
3369
+ };
3370
+ if (gltfMesh.primitives) {
3371
+ mesh.primitives = gltfMesh.primitives.map((gltfPrimitive) => {
3372
+ const primitive = {
3373
+ ...gltfPrimitive,
3374
+ attributes: {},
3375
+ indices: void 0,
3376
+ material: void 0
3377
+ };
3378
+ const attributes = gltfPrimitive.attributes;
3379
+ for (const attribute in attributes) {
3380
+ primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
3381
+ }
3382
+ if (gltfPrimitive.indices !== void 0) {
3383
+ primitive.indices = this.getAccessor(gltfPrimitive.indices);
3384
+ }
3385
+ if (gltfPrimitive.material !== void 0) {
3386
+ primitive.material = this.getMaterial(gltfPrimitive.material);
3387
+ }
3388
+ return primitive;
3389
+ });
3390
+ }
3391
+ return mesh;
3392
+ }
3393
+ _resolveMaterial(gltfMaterial, index) {
3394
+ const material = {
3395
+ ...gltfMaterial,
3396
+ // @ts-expect-error
3397
+ id: gltfMaterial.id || `material-${index}`
3398
+ };
3399
+ if (material.normalTexture) {
3400
+ material.normalTexture = { ...material.normalTexture };
3401
+ material.normalTexture.texture = this.getTexture(material.normalTexture.index);
3402
+ }
3403
+ if (material.occlusionTexture) {
3404
+ material.occlusionTexture = { ...material.occlusionTexture };
3405
+ material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
3406
+ }
3407
+ if (material.emissiveTexture) {
3408
+ material.emissiveTexture = { ...material.emissiveTexture };
3409
+ material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
3410
+ }
3411
+ if (!material.emissiveFactor) {
3412
+ material.emissiveFactor = material.emissiveTexture ? [1, 1, 1] : [0, 0, 0];
3413
+ }
3414
+ if (material.pbrMetallicRoughness) {
3415
+ material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness };
3416
+ const mr = material.pbrMetallicRoughness;
3417
+ if (mr.baseColorTexture) {
3418
+ mr.baseColorTexture = { ...mr.baseColorTexture };
3419
+ mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
3420
+ }
3421
+ if (mr.metallicRoughnessTexture) {
3422
+ mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture };
3423
+ mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
3424
+ }
3425
+ }
3426
+ return material;
3427
+ }
3428
+ _resolveAccessor(gltfAccessor, index) {
3429
+ const bytesPerComponent = getBytesFromComponentType(gltfAccessor.componentType);
3430
+ const components = getSizeFromAccessorType(gltfAccessor.type);
3431
+ const bytesPerElement = bytesPerComponent * components;
3432
+ const accessor = {
3433
+ ...gltfAccessor,
3434
+ // @ts-expect-error
3435
+ id: gltfAccessor.id || `accessor-${index}`,
3436
+ bytesPerComponent,
3437
+ components,
3438
+ bytesPerElement,
3439
+ value: void 0,
3440
+ bufferView: void 0,
3441
+ sparse: void 0
3442
+ };
3443
+ if (gltfAccessor.bufferView !== void 0) {
3444
+ accessor.bufferView = this.getBufferView(gltfAccessor.bufferView);
3445
+ }
3446
+ if (accessor.bufferView) {
3447
+ const buffer = accessor.bufferView.buffer;
3448
+ const { ArrayType, byteLength } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
3449
+ const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
3450
+ let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
3451
+ if (accessor.bufferView.byteStride) {
3452
+ cutBuffer = this._getValueFromInterleavedBuffer(
3453
+ buffer,
3454
+ byteOffset,
3455
+ accessor.bufferView.byteStride,
3456
+ accessor.bytesPerElement,
3457
+ accessor.count
3458
+ );
3459
+ }
3460
+ accessor.value = new ArrayType(cutBuffer);
3461
+ }
3462
+ return accessor;
3463
+ }
3464
+ /**
3465
+ * Take values of particular accessor from interleaved buffer
3466
+ * various parts of the buffer
3467
+ * @param buffer
3468
+ * @param byteOffset
3469
+ * @param byteStride
3470
+ * @param bytesPerElement
3471
+ * @param count
3472
+ * @returns
3473
+ */
3474
+ _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
3475
+ const result = new Uint8Array(count * bytesPerElement);
3476
+ for (let i = 0; i < count; i++) {
3477
+ const elementOffset = byteOffset + i * byteStride;
3478
+ result.set(
3479
+ new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)),
3480
+ i * bytesPerElement
3481
+ );
3482
+ }
3483
+ return result.buffer;
3484
+ }
3485
+ _resolveTexture(gltfTexture, index) {
3486
+ return {
3487
+ ...gltfTexture,
3488
+ // @ts-expect-error id could already be present, glTF standard does not prevent it
3489
+ id: gltfTexture.id || `texture-${index}`,
3490
+ sampler: typeof gltfTexture.sampler === "number" ? this.getSampler(gltfTexture.sampler) : makeDefaultSampler(),
3491
+ source: typeof gltfTexture.source === "number" ? this.getImage(gltfTexture.source) : void 0
3492
+ };
3493
+ }
3494
+ _resolveSampler(gltfSampler, index) {
3495
+ const sampler = {
3496
+ // @ts-expect-error id could already be present, glTF standard does not prevent it
3497
+ id: gltfSampler.id || `sampler-${index}`,
3498
+ ...gltfSampler,
3499
+ parameters: {}
3500
+ };
3501
+ for (const key in sampler) {
3502
+ const glEnum = this._enumSamplerParameter(key);
3503
+ if (glEnum !== void 0) {
3504
+ sampler.parameters[glEnum] = sampler[key];
3505
+ }
3506
+ }
3507
+ return sampler;
3508
+ }
3509
+ _enumSamplerParameter(key) {
3510
+ return SAMPLER_PARAMETER_GLTF_TO_GL[key];
3511
+ }
3512
+ _resolveImage(gltfImage, index) {
3513
+ const image = {
3514
+ ...gltfImage,
3515
+ // @ts-expect-error id could already be present, glTF standard does not prevent it
3516
+ id: gltfImage.id || `image-${index}`,
3517
+ image: null,
3518
+ bufferView: gltfImage.bufferView !== void 0 ? this.getBufferView(gltfImage.bufferView) : void 0
3519
+ };
3520
+ const preloadedImage = this.images[index];
3521
+ if (preloadedImage) {
3522
+ image.image = preloadedImage;
3523
+ }
3524
+ return image;
3525
+ }
3526
+ _resolveBufferView(gltfBufferView, index) {
3527
+ const bufferIndex = gltfBufferView.buffer;
3528
+ const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
3529
+ let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
3530
+ if (gltfBufferView.byteOffset) {
3531
+ byteOffset += gltfBufferView.byteOffset;
3532
+ }
3533
+ const bufferView = {
3534
+ // // @ts-expect-error id could already be present, glTF standard does not prevent it
3535
+ id: `bufferView-${index}`,
3536
+ ...gltfBufferView,
3537
+ // ...this.buffers[bufferIndex],
3538
+ buffer: this.buffers[bufferIndex],
3539
+ data: new Uint8Array(arrayBuffer, byteOffset, gltfBufferView.byteLength)
3540
+ };
3541
+ return bufferView;
3542
+ }
3543
+ _resolveCamera(gltfCamera, index) {
3544
+ const camera = {
3545
+ ...gltfCamera,
3546
+ // @ts-expect-error id could already be present, glTF standard does not prevent it
3547
+ id: gltfCamera.id || `camera-${index}`
3548
+ };
3549
+ if (camera.perspective) {
3550
+ }
3551
+ if (camera.orthographic) {
3552
+ }
3553
+ return camera;
3554
+ }
3555
+ };
3556
+ function postProcessGLTF(gltf, options) {
3557
+ return new GLTFPostProcessor().postProcess(gltf, options);
3558
+ }