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

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 (292) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +2037 -1013
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/glb-loader.js +56 -0
  6. package/dist/es5/glb-loader.js.map +1 -0
  7. package/dist/es5/glb-writer.js +35 -0
  8. package/dist/es5/glb-writer.js.map +1 -0
  9. package/dist/es5/gltf-loader.js +81 -0
  10. package/dist/es5/gltf-loader.js.map +1 -0
  11. package/dist/es5/gltf-writer.js +35 -0
  12. package/dist/es5/gltf-writer.js.map +1 -0
  13. package/dist/es5/index.js +49 -0
  14. package/dist/es5/index.js.map +1 -0
  15. package/dist/es5/lib/api/gltf-extensions.js +109 -0
  16. package/dist/es5/lib/api/gltf-extensions.js.map +1 -0
  17. package/dist/es5/lib/api/gltf-scenegraph.js +578 -0
  18. package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -0
  19. package/dist/es5/lib/api/normalize-gltf-v1.js +331 -0
  20. package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -0
  21. package/dist/es5/lib/api/post-process-gltf.js +422 -0
  22. package/dist/es5/lib/api/post-process-gltf.js.map +1 -0
  23. package/dist/es5/lib/encoders/encode-glb.js +61 -0
  24. package/dist/es5/lib/encoders/encode-glb.js.map +1 -0
  25. package/dist/es5/lib/encoders/encode-gltf.js +21 -0
  26. package/dist/es5/lib/encoders/encode-gltf.js.map +1 -0
  27. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +96 -0
  28. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -0
  29. package/dist/es5/lib/extensions/EXT_texture_webp.js +44 -0
  30. package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -0
  31. package/dist/es5/lib/extensions/KHR_binary_gltf.js +40 -0
  32. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -0
  33. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +246 -0
  34. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
  35. package/dist/es5/lib/extensions/KHR_texture_basisu.js +37 -0
  36. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -0
  37. package/dist/es5/lib/extensions/KHR_texture_transform.js +229 -0
  38. package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -0
  39. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +103 -0
  40. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
  41. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +99 -0
  42. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
  43. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +76 -0
  44. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
  45. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +113 -0
  46. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
  47. package/dist/es5/lib/gltf-utils/get-typed-array.js +23 -0
  48. package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -0
  49. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +68 -0
  50. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
  51. package/dist/es5/lib/gltf-utils/gltf-constants.js +48 -0
  52. package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -0
  53. package/dist/es5/lib/gltf-utils/gltf-utils.js +62 -0
  54. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -0
  55. package/dist/es5/lib/gltf-utils/resolve-url.js +18 -0
  56. package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -0
  57. package/dist/es5/lib/parsers/parse-glb.js +120 -0
  58. package/dist/es5/lib/parsers/parse-glb.js.map +1 -0
  59. package/dist/es5/lib/parsers/parse-gltf.js +287 -0
  60. package/dist/es5/lib/parsers/parse-gltf.js.map +1 -0
  61. package/dist/es5/lib/types/glb-types.js +2 -0
  62. package/dist/es5/lib/types/glb-types.js.map +1 -0
  63. package/dist/es5/lib/types/gltf-json-schema.js +2 -0
  64. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -0
  65. package/dist/es5/lib/types/gltf-postprocessed-schema.js +2 -0
  66. package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -0
  67. package/dist/es5/lib/types/gltf-types.js +2 -0
  68. package/dist/es5/lib/types/gltf-types.js.map +1 -0
  69. package/dist/es5/lib/utils/assert.js +12 -0
  70. package/dist/es5/lib/utils/assert.js.map +1 -0
  71. package/dist/es5/lib/utils/version.js +9 -0
  72. package/dist/es5/lib/utils/version.js.map +1 -0
  73. package/dist/es5/meshopt/meshopt-decoder.js +215 -0
  74. package/dist/es5/meshopt/meshopt-decoder.js.map +1 -0
  75. package/dist/es5/webp/webp.js +83 -0
  76. package/dist/es5/webp/webp.js.map +1 -0
  77. package/dist/esm/bundle.js +4 -0
  78. package/dist/esm/bundle.js.map +1 -0
  79. package/dist/esm/glb-loader.js +31 -0
  80. package/dist/esm/glb-loader.js.map +1 -0
  81. package/dist/esm/glb-writer.js +27 -0
  82. package/dist/esm/glb-writer.js.map +1 -0
  83. package/dist/esm/gltf-loader.js +51 -0
  84. package/dist/esm/gltf-loader.js.map +1 -0
  85. package/dist/esm/gltf-writer.js +28 -0
  86. package/dist/esm/gltf-writer.js.map +1 -0
  87. package/dist/esm/index.js +7 -0
  88. package/dist/esm/index.js.map +1 -0
  89. package/dist/esm/lib/api/gltf-extensions.js +35 -0
  90. package/dist/esm/lib/api/gltf-extensions.js.map +1 -0
  91. package/dist/esm/lib/api/gltf-scenegraph.js +441 -0
  92. package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -0
  93. package/dist/esm/lib/api/normalize-gltf-v1.js +204 -0
  94. package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -0
  95. package/dist/esm/lib/api/post-process-gltf.js +341 -0
  96. package/dist/esm/lib/api/post-process-gltf.js.map +1 -0
  97. package/dist/esm/lib/encoders/encode-glb.js +54 -0
  98. package/dist/esm/lib/encoders/encode-glb.js.map +1 -0
  99. package/dist/esm/lib/encoders/encode-gltf.js +14 -0
  100. package/dist/esm/lib/encoders/encode-gltf.js.map +1 -0
  101. package/dist/esm/lib/extensions/EXT_meshopt_compression.js +42 -0
  102. package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -0
  103. package/dist/esm/lib/extensions/EXT_texture_webp.js +25 -0
  104. package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -0
  105. package/dist/esm/lib/extensions/KHR_binary_gltf.js +21 -0
  106. package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -0
  107. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +110 -0
  108. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
  109. package/dist/esm/lib/extensions/KHR_texture_basisu.js +18 -0
  110. package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -0
  111. package/dist/esm/lib/extensions/KHR_texture_transform.js +181 -0
  112. package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -0
  113. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +77 -0
  114. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -0
  115. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +42 -0
  116. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
  117. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +33 -0
  118. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
  119. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +61 -0
  120. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
  121. package/dist/esm/lib/gltf-utils/get-typed-array.js +16 -0
  122. package/dist/esm/lib/gltf-utils/get-typed-array.js.map +1 -0
  123. package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js +62 -0
  124. package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
  125. package/dist/esm/lib/gltf-utils/gltf-constants.js +37 -0
  126. package/dist/esm/lib/gltf-utils/gltf-constants.js.map +1 -0
  127. package/dist/esm/lib/gltf-utils/gltf-utils.js +54 -0
  128. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -0
  129. package/dist/esm/lib/gltf-utils/resolve-url.js +12 -0
  130. package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -0
  131. package/dist/esm/lib/parsers/parse-glb.js +114 -0
  132. package/dist/esm/lib/parsers/parse-glb.js.map +1 -0
  133. package/dist/esm/lib/parsers/parse-gltf.js +156 -0
  134. package/dist/esm/lib/parsers/parse-gltf.js.map +1 -0
  135. package/dist/esm/lib/types/glb-types.js +2 -0
  136. package/dist/esm/lib/types/glb-types.js.map +1 -0
  137. package/dist/esm/lib/types/gltf-json-schema.js +2 -0
  138. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -0
  139. package/dist/esm/lib/types/gltf-postprocessed-schema.js +2 -0
  140. package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -0
  141. package/dist/esm/lib/types/gltf-types.js +2 -0
  142. package/dist/esm/lib/types/gltf-types.js.map +1 -0
  143. package/dist/esm/lib/utils/assert.js +6 -0
  144. package/dist/esm/lib/utils/assert.js.map +1 -0
  145. package/dist/esm/lib/utils/version.js +2 -0
  146. package/dist/esm/lib/utils/version.js.map +1 -0
  147. package/dist/esm/meshopt/meshopt-decoder.js +91 -0
  148. package/dist/esm/meshopt/meshopt-decoder.js.map +1 -0
  149. package/dist/esm/meshopt/meshopt-encoder.ts.disabled +409 -0
  150. package/dist/esm/webp/webp.js +25 -0
  151. package/dist/esm/webp/webp.js.map +1 -0
  152. package/dist/glb-loader.d.ts +3 -2
  153. package/dist/glb-loader.d.ts.map +1 -1
  154. package/dist/glb-loader.js +33 -28
  155. package/dist/glb-writer.d.ts +7 -16
  156. package/dist/glb-writer.d.ts.map +1 -1
  157. package/dist/glb-writer.js +34 -26
  158. package/dist/gltf-loader.d.ts +3 -2
  159. package/dist/gltf-loader.d.ts.map +1 -1
  160. package/dist/gltf-loader.js +46 -43
  161. package/dist/gltf-writer.d.ts +2 -2
  162. package/dist/gltf-writer.d.ts.map +1 -1
  163. package/dist/gltf-writer.js +29 -26
  164. package/dist/index.d.ts +2 -1
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +21 -7
  167. package/dist/lib/api/gltf-extensions.d.ts +6 -1
  168. package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
  169. package/dist/lib/api/gltf-extensions.js +79 -31
  170. package/dist/lib/api/gltf-scenegraph.d.ts +5 -11
  171. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
  172. package/dist/lib/api/gltf-scenegraph.js +563 -512
  173. package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -1
  174. package/dist/lib/api/normalize-gltf-v1.js +278 -229
  175. package/dist/lib/api/post-process-gltf.js +324 -376
  176. package/dist/lib/encoders/encode-glb.d.ts +2 -1
  177. package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
  178. package/dist/lib/encoders/encode-glb.js +56 -58
  179. package/dist/lib/encoders/encode-gltf.d.ts +18 -0
  180. package/dist/lib/encoders/encode-gltf.d.ts.map +1 -1
  181. package/dist/lib/encoders/encode-gltf.js +33 -12
  182. package/dist/lib/extensions/EXT_meshopt_compression.d.ts +0 -3
  183. package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
  184. package/dist/lib/extensions/EXT_meshopt_compression.js +39 -50
  185. package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
  186. package/dist/lib/extensions/EXT_texture_webp.js +35 -28
  187. package/dist/lib/extensions/KHR_binary_gltf.js +39 -23
  188. package/dist/lib/extensions/KHR_draco_mesh_compression.js +126 -111
  189. package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
  190. package/dist/lib/extensions/KHR_texture_basisu.js +29 -19
  191. package/dist/lib/extensions/KHR_texture_transform.d.ts +13 -0
  192. package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -0
  193. package/dist/lib/extensions/KHR_texture_transform.js +230 -0
  194. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +6 -0
  195. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -0
  196. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +118 -0
  197. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +57 -44
  198. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +42 -32
  199. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
  200. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +76 -62
  201. package/dist/lib/gltf-utils/get-typed-array.js +39 -14
  202. package/dist/lib/gltf-utils/gltf-attribute-utils.js +65 -65
  203. package/dist/lib/gltf-utils/gltf-constants.d.ts +17 -0
  204. package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -1
  205. package/dist/lib/gltf-utils/gltf-constants.js +38 -32
  206. package/dist/lib/gltf-utils/gltf-utils.js +52 -45
  207. package/dist/lib/gltf-utils/resolve-url.js +17 -15
  208. package/dist/lib/parsers/parse-glb.d.ts +1 -1
  209. package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
  210. package/dist/lib/parsers/parse-glb.js +120 -107
  211. package/dist/lib/parsers/parse-gltf.d.ts +2 -2
  212. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
  213. package/dist/lib/parsers/parse-gltf.js +187 -154
  214. package/dist/lib/types/glb-types.d.ts +3 -3
  215. package/dist/lib/types/glb-types.d.ts.map +1 -1
  216. package/dist/lib/types/glb-types.js +2 -2
  217. package/dist/lib/types/gltf-json-schema.d.ts +396 -11
  218. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  219. package/dist/lib/types/gltf-json-schema.js +4 -2
  220. package/dist/lib/types/gltf-postprocessed-schema.d.ts +10 -10
  221. package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
  222. package/dist/lib/types/gltf-postprocessed-schema.js +4 -2
  223. package/dist/lib/types/gltf-types.d.ts +8 -5
  224. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  225. package/dist/lib/types/gltf-types.js +3 -2
  226. package/dist/lib/utils/assert.js +11 -5
  227. package/dist/lib/utils/version.js +7 -2
  228. package/dist/meshopt/meshopt-decoder.js +97 -82
  229. package/dist/webp/webp.d.ts +1 -1
  230. package/dist/webp/webp.d.ts.map +1 -1
  231. package/dist/webp/webp.js +32 -23
  232. package/package.json +9 -8
  233. package/src/glb-loader.ts +1 -1
  234. package/src/glb-writer.ts +9 -3
  235. package/src/gltf-writer.ts +2 -2
  236. package/src/index.ts +10 -1
  237. package/src/lib/api/gltf-extensions.ts +13 -2
  238. package/src/lib/api/gltf-scenegraph.ts +21 -12
  239. package/src/lib/api/normalize-gltf-v1.ts +2 -1
  240. package/src/lib/encoders/encode-glb.ts +8 -1
  241. package/src/lib/encoders/encode-gltf.ts +18 -9
  242. package/src/lib/extensions/EXT_meshopt_compression.ts +12 -19
  243. package/src/lib/extensions/EXT_texture_webp.ts +3 -2
  244. package/src/lib/extensions/KHR_binary_gltf.ts +1 -1
  245. package/src/lib/extensions/KHR_draco_mesh_compression.ts +1 -1
  246. package/src/lib/extensions/KHR_texture_basisu.ts +1 -0
  247. package/src/lib/extensions/KHR_texture_transform.ts +305 -0
  248. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +163 -0
  249. package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +3 -3
  250. package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +1 -0
  251. package/src/lib/gltf-utils/gltf-constants.ts +2 -2
  252. package/src/lib/parsers/parse-gltf.ts +10 -1
  253. package/src/lib/types/glb-types.ts +1 -1
  254. package/src/lib/types/gltf-json-schema.ts +434 -5
  255. package/src/lib/types/gltf-postprocessed-schema.ts +9 -9
  256. package/src/lib/types/gltf-types.ts +24 -3
  257. package/dist/bundle.js.map +0 -1
  258. package/dist/glb-loader.js.map +0 -1
  259. package/dist/glb-writer.js.map +0 -1
  260. package/dist/gltf-loader.js.map +0 -1
  261. package/dist/gltf-writer.js.map +0 -1
  262. package/dist/index.js.map +0 -1
  263. package/dist/lib/api/gltf-extensions.js.map +0 -1
  264. package/dist/lib/api/gltf-scenegraph.js.map +0 -1
  265. package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
  266. package/dist/lib/api/post-process-gltf.js.map +0 -1
  267. package/dist/lib/encoders/encode-glb.js.map +0 -1
  268. package/dist/lib/encoders/encode-gltf.js.map +0 -1
  269. package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
  270. package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
  271. package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
  272. package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
  273. package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
  274. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
  275. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
  276. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
  277. package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
  278. package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
  279. package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
  280. package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
  281. package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
  282. package/dist/lib/parsers/parse-glb.js.map +0 -1
  283. package/dist/lib/parsers/parse-gltf.js.map +0 -1
  284. package/dist/lib/types/glb-types.js.map +0 -1
  285. package/dist/lib/types/gltf-json-schema.js.map +0 -1
  286. package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
  287. package/dist/lib/types/gltf-types.js.map +0 -1
  288. package/dist/lib/utils/assert.js.map +0 -1
  289. package/dist/lib/utils/version.js.map +0 -1
  290. package/dist/meshopt/meshopt-decoder.js.map +0 -1
  291. package/dist/webp/webp.js.map +0 -1
  292. /package/dist/{meshopt → es5/meshopt}/meshopt-encoder.ts.disabled +0 -0
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.decode = exports.name = void 0;
7
+ const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
8
+ /** Extension name */
9
+ const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
10
+ exports.name = EXT_FEATURE_METADATA;
11
+ async function decode(gltfData) {
12
+ const scenegraph = new gltf_scenegraph_1.default(gltfData);
13
+ decodeExtFeatureMetadata(scenegraph);
14
+ }
15
+ exports.decode = decode;
16
+ /**
17
+ * Decodes feature metadata from extension
18
+ * @param scenegraph
19
+ */
20
+ function decodeExtFeatureMetadata(scenegraph) {
21
+ const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
22
+ const schemaClasses = extension?.schema?.classes;
23
+ const featureTables = extension?.featureTables;
24
+ const featureTextures = extension?.featureTextures;
25
+ if (featureTextures) {
26
+ /*
27
+ * TODO add support for featureTextures
28
+ * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-textures
29
+ */
30
+ // eslint-disable-next-line no-console
31
+ console.warn('featureTextures is not yet supported in the "EXT_feature_metadata" extension.');
32
+ }
33
+ if (schemaClasses && featureTables) {
34
+ for (const schemaName in schemaClasses) {
35
+ const schemaClass = schemaClasses[schemaName];
36
+ const featureTable = findFeatureTableByName(featureTables, schemaName);
37
+ if (featureTable) {
38
+ handleFeatureTableProperties(scenegraph, featureTable, schemaClass);
39
+ }
40
+ }
41
+ }
42
+ }
43
+ /**
44
+ * Navigate throw all properies in feature table and gets properties data.
45
+ * @param scenegraph
46
+ * @param featureTable
47
+ * @param schemaClass
48
+ */
49
+ function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
50
+ for (const propertyName in schemaClass.properties) {
51
+ const schemaProperty = schemaClass.properties[propertyName];
52
+ const featureTableProperty = featureTable?.properties?.[propertyName];
53
+ const numberOfFeatures = featureTable.count;
54
+ if (featureTableProperty) {
55
+ const data = getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty);
56
+ featureTableProperty.data = data;
57
+ }
58
+ }
59
+ }
60
+ /**
61
+ * Decode properties from binary sourse based on property type.
62
+ * @param scenegraph
63
+ * @param schemaProperty
64
+ * @param numberOfFeatures
65
+ * @param featureTableProperty
66
+ */
67
+ function getPropertyDataFromBinarySource(scenegraph, schemaProperty, numberOfFeatures, featureTableProperty) {
68
+ const bufferView = featureTableProperty.bufferView;
69
+ // TODO think maybe we shouldn't get data only in Uint8Array format.
70
+ let data = scenegraph.getTypedArrayForBufferView(bufferView);
71
+ switch (schemaProperty.type) {
72
+ case 'STRING': {
73
+ // stringOffsetBufferView should be available for string type.
74
+ const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView;
75
+ const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
76
+ data = getStringAttributes(data, offsetsData, numberOfFeatures);
77
+ break;
78
+ }
79
+ default:
80
+ }
81
+ return data;
82
+ }
83
+ /**
84
+ * Find the feature table by class name.
85
+ * @param featureTables
86
+ * @param schemaClassName
87
+ */
88
+ function findFeatureTableByName(featureTables, schemaClassName) {
89
+ for (const featureTableName in featureTables) {
90
+ const featureTable = featureTables[featureTableName];
91
+ if (featureTable.class === schemaClassName) {
92
+ return featureTable;
93
+ }
94
+ }
95
+ return null;
96
+ }
97
+ /**
98
+ * Getting string attributes from binary data.
99
+ * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata#strings
100
+ * @param data
101
+ * @param offsetsData
102
+ * @param stringsCount
103
+ */
104
+ function getStringAttributes(data, offsetsData, stringsCount) {
105
+ const stringsArray = [];
106
+ const textDecoder = new TextDecoder('utf8');
107
+ let stringOffset = 0;
108
+ const bytesPerStringSize = 4;
109
+ for (let index = 0; index < stringsCount; index++) {
110
+ // TODO check if it is multiplication on bytesPerStringSize is valid operation?
111
+ const stringByteSize = offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
112
+ const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
113
+ const stringAttribute = textDecoder.decode(stringData);
114
+ stringsArray.push(stringAttribute);
115
+ stringOffset += stringByteSize;
116
+ }
117
+ return stringsArray;
118
+ }
@@ -1,49 +1,62 @@
1
- import { assert } from '../../utils/assert';
2
- import GLTFScenegraph from '../../api/gltf-scenegraph';
1
+ "use strict";
2
+ // GLTF EXTENSION: KHR_lights_punctual
3
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.encode = exports.decode = exports.name = void 0;
9
+ const assert_1 = require("../../utils/assert");
10
+ const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
3
11
  const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
4
- export const name = KHR_LIGHTS_PUNCTUAL;
5
- export async function decode(gltfData) {
6
- const gltfScenegraph = new GLTFScenegraph(gltfData);
7
- const {
8
- json
9
- } = gltfScenegraph;
10
- const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
11
-
12
- if (extension) {
13
- gltfScenegraph.json.lights = extension.lights;
14
- gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
15
- }
16
-
17
- for (const node of json.nodes || []) {
18
- const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
19
-
20
- if (nodeExtension) {
21
- node.light = nodeExtension.light;
12
+ exports.name = KHR_LIGHTS_PUNCTUAL;
13
+ async function decode(gltfData) {
14
+ const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
15
+ const { json } = gltfScenegraph;
16
+ // Move the light array out of the extension and remove the extension
17
+ const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
18
+ if (extension) {
19
+ // @ts-ignore
20
+ gltfScenegraph.json.lights = extension.lights;
21
+ gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
22
+ }
23
+ // Any nodes that have the extension, add lights field pointing to light object
24
+ // and remove the extension
25
+ for (const node of json.nodes || []) {
26
+ const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
27
+ if (nodeExtension) {
28
+ // @ts-ignore
29
+ node.light = nodeExtension.light;
30
+ }
31
+ gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
22
32
  }
23
-
24
- gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
25
- }
26
33
  }
27
- export async function encode(gltfData) {
28
- const gltfScenegraph = new GLTFScenegraph(gltfData);
29
- const {
30
- json
31
- } = gltfScenegraph;
32
-
33
- if (json.lights) {
34
- const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
35
- assert(!extension.lights);
36
- extension.lights = json.lights;
37
- delete json.lights;
38
- }
39
-
40
- if (gltfScenegraph.json.lights) {
41
- for (const light of gltfScenegraph.json.lights) {
42
- const node = light.node;
43
- gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
34
+ exports.decode = decode;
35
+ // Move the light ar ray out of the extension and remove the extension
36
+ async function encode(gltfData) {
37
+ const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
38
+ const { json } = gltfScenegraph;
39
+ // @ts-ignore
40
+ if (json.lights) {
41
+ const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
42
+ // @ts-ignore
43
+ (0, assert_1.assert)(!extension.lights);
44
+ // @ts-ignore
45
+ extension.lights = json.lights;
46
+ // @ts-ignore
47
+ delete json.lights;
48
+ }
49
+ // Any nodes that have lights field pointing to light object
50
+ // add the extension
51
+ // @ts-ignore
52
+ if (gltfScenegraph.json.lights) {
53
+ // @ts-ignore
54
+ for (const light of gltfScenegraph.json.lights) {
55
+ const node = light.node;
56
+ gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
57
+ }
58
+ // @ts-ignore
59
+ delete gltfScenegraph.json.lights;
44
60
  }
45
-
46
- delete gltfScenegraph.json.lights;
47
- }
48
61
  }
49
- //# sourceMappingURL=KHR_lights_punctual.js.map
62
+ exports.encode = encode;
@@ -1,37 +1,47 @@
1
- import GLTFScenegraph from '../../api/gltf-scenegraph';
1
+ "use strict";
2
+ // GLTF EXTENSION: KHR_materials_unlit
3
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.encode = exports.decode = exports.name = void 0;
9
+ const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
2
10
  const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
3
- export const name = KHR_MATERIALS_UNLIT;
4
- export async function decode(gltfData) {
5
- const gltfScenegraph = new GLTFScenegraph(gltfData);
6
- const {
7
- json
8
- } = gltfScenegraph;
9
- gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
10
-
11
- for (const material of json.materials || []) {
12
- const extension = material.extensions && material.extensions.KHR_materials_unlit;
13
-
14
- if (extension) {
15
- material.unlit = true;
11
+ exports.name = KHR_MATERIALS_UNLIT;
12
+ async function decode(gltfData) {
13
+ const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
14
+ const { json } = gltfScenegraph;
15
+ // Any nodes that have the extension, add lights field pointing to light object
16
+ // and remove the extension
17
+ for (const material of json.materials || []) {
18
+ const extension = material.extensions && material.extensions.KHR_materials_unlit;
19
+ if (extension) {
20
+ // @ts-ignore TODO
21
+ material.unlit = true;
22
+ }
23
+ gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
16
24
  }
17
-
18
- gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
19
- }
25
+ // Remove the top-level extension
26
+ gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
20
27
  }
21
- export function encode(gltfData) {
22
- const gltfScenegraph = new GLTFScenegraph(gltfData);
23
- const {
24
- json
25
- } = gltfScenegraph;
26
-
27
- if (gltfScenegraph.materials) {
28
- for (const material of json.materials || []) {
29
- if (material.unlit) {
30
- delete material.unlit;
31
- gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
32
- gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
33
- }
28
+ exports.decode = decode;
29
+ function encode(gltfData) {
30
+ const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
31
+ const { json } = gltfScenegraph;
32
+ // Any nodes that have lights field pointing to light object
33
+ // add the extension
34
+ // @ts-ignore
35
+ if (gltfScenegraph.materials) {
36
+ for (const material of json.materials || []) {
37
+ // @ts-ignore
38
+ if (material.unlit) {
39
+ // @ts-ignore
40
+ delete material.unlit;
41
+ gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
42
+ gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
43
+ }
44
+ }
34
45
  }
35
- }
36
46
  }
37
- //# sourceMappingURL=KHR_materials_unlit.js.map
47
+ exports.encode = encode;
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_techniques_webgl.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAMjD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BlE;AAED,wBAAsB,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D"}
1
+ {"version":3,"file":"KHR_techniques_webgl.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,wBAAwB,CAAC;AAMjD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BlE;AAED,wBAAsB,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D"}
@@ -1,68 +1,82 @@
1
- import GLTFScenegraph from '../../api/gltf-scenegraph';
1
+ "use strict";
2
+ // GLTF EXTENSION: KHR_techniques_webgl
3
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.encode = exports.decode = exports.name = void 0;
9
+ const gltf_scenegraph_1 = __importDefault(require("../../api/gltf-scenegraph"));
2
10
  const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
3
- export const name = KHR_TECHNIQUES_WEBGL;
4
- export async function decode(gltfData) {
5
- const gltfScenegraph = new GLTFScenegraph(gltfData);
6
- const {
7
- json
8
- } = gltfScenegraph;
9
- const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
10
-
11
- if (extension) {
12
- const techniques = resolveTechniques(extension, gltfScenegraph);
13
-
14
- for (const material of json.materials || []) {
15
- const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
16
-
17
- if (materialExtension) {
18
- material.technique = Object.assign({}, materialExtension, techniques[materialExtension.technique]);
19
- material.technique.values = resolveValues(material.technique, gltfScenegraph);
20
- }
21
-
22
- gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
11
+ exports.name = KHR_TECHNIQUES_WEBGL;
12
+ async function decode(gltfData) {
13
+ const gltfScenegraph = new gltf_scenegraph_1.default(gltfData);
14
+ const { json } = gltfScenegraph;
15
+ const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
16
+ if (extension) {
17
+ const techniques = resolveTechniques(extension, gltfScenegraph);
18
+ for (const material of json.materials || []) {
19
+ const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
20
+ if (materialExtension) {
21
+ // @ts-ignore TODO
22
+ material.technique = Object.assign({}, materialExtension,
23
+ // @ts-ignore
24
+ techniques[materialExtension.technique]);
25
+ // @ts-ignore TODO
26
+ material.technique.values = resolveValues(material.technique, gltfScenegraph);
27
+ }
28
+ gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
29
+ }
30
+ // Remove the top-level extension
31
+ gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
23
32
  }
24
-
25
- gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
26
- }
27
33
  }
28
- export async function encode(gltfData, options) {}
29
-
30
- function resolveTechniques(techniquesExtension, gltfScenegraph) {
31
- const {
32
- programs = [],
33
- shaders = [],
34
- techniques = []
35
- } = techniquesExtension;
36
- const textDecoder = new TextDecoder();
37
- shaders.forEach(shader => {
38
- if (Number.isFinite(shader.bufferView)) {
39
- shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));
40
- } else {
41
- throw new Error('KHR_techniques_webgl: no shader code');
42
- }
43
- });
44
- programs.forEach(program => {
45
- program.fragmentShader = shaders[program.fragmentShader];
46
- program.vertexShader = shaders[program.vertexShader];
47
- });
48
- techniques.forEach(technique => {
49
- technique.program = programs[technique.program];
50
- });
51
- return techniques;
34
+ exports.decode = decode;
35
+ // eslint-disable-next-line
36
+ async function encode(gltfData, options) {
37
+ // TODO
38
+ }
39
+ exports.encode = encode;
40
+ function resolveTechniques(techniquesExtension,
41
+ // programs: {[key: string]: any}[],
42
+ // shaders: {[key: string]: any}[],
43
+ // techniques: {[key: string]: any}[]
44
+ gltfScenegraph) {
45
+ const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
46
+ const textDecoder = new TextDecoder();
47
+ shaders.forEach((shader) => {
48
+ if (Number.isFinite(shader.bufferView)) {
49
+ shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));
50
+ }
51
+ else {
52
+ // TODO: handle URI shader
53
+ throw new Error('KHR_techniques_webgl: no shader code');
54
+ }
55
+ });
56
+ programs.forEach((program) => {
57
+ program.fragmentShader = shaders[program.fragmentShader];
58
+ program.vertexShader = shaders[program.vertexShader];
59
+ });
60
+ techniques.forEach((technique) => {
61
+ technique.program = programs[technique.program];
62
+ });
63
+ return techniques;
52
64
  }
53
-
54
65
  function resolveValues(technique, gltfScenegraph) {
55
- const values = Object.assign({}, technique.values);
56
- Object.keys(technique.uniforms || {}).forEach(uniform => {
57
- if (technique.uniforms[uniform].value && !(uniform in values)) {
58
- values[uniform] = technique.uniforms[uniform].value;
59
- }
60
- });
61
- Object.keys(values).forEach(uniform => {
62
- if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
63
- values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
64
- }
65
- });
66
- return values;
66
+ const values = Object.assign({}, technique.values);
67
+ // merge values from uniforms
68
+ Object.keys(technique.uniforms || {}).forEach((uniform) => {
69
+ if (technique.uniforms[uniform].value && !(uniform in values)) {
70
+ values[uniform] = technique.uniforms[uniform].value;
71
+ }
72
+ });
73
+ // resolve textures
74
+ Object.keys(values).forEach((uniform) => {
75
+ if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
76
+ // Assume this is a texture
77
+ // TODO: find if there are any other types that can be referenced
78
+ values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
79
+ }
80
+ });
81
+ return values;
67
82
  }
68
- //# sourceMappingURL=KHR_techniques_webgl.js.map
@@ -1,16 +1,41 @@
1
- import { assert } from '../utils/assert';
2
- export function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {
3
- const bufferView = json.bufferViews[bufferViewIndex];
4
- assert(bufferView);
5
- const bufferIndex = bufferView.buffer;
6
- const binChunk = buffers[bufferIndex];
7
- assert(binChunk);
8
- const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
9
- return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTypedArrayForImageData = exports.getTypedArrayForBufferView = void 0;
4
+ // TODO - GLTFScenegraph should use these
5
+ const assert_1 = require("../utils/assert");
6
+ // accepts buffer view index or buffer view object
7
+ // returns a `Uint8Array`
8
+ function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {
9
+ const bufferView = json.bufferViews[bufferViewIndex];
10
+ (0, assert_1.assert)(bufferView);
11
+ // Get hold of the arrayBuffer
12
+ const bufferIndex = bufferView.buffer;
13
+ const binChunk = buffers[bufferIndex];
14
+ (0, assert_1.assert)(binChunk);
15
+ const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
16
+ return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
10
17
  }
11
- export function getTypedArrayForImageData(json, buffers, imageIndex) {
12
- const image = json.images[imageIndex];
13
- const bufferViewIndex = json.bufferViews[image.bufferView];
14
- return getTypedArrayForBufferView(json, buffers, bufferViewIndex);
18
+ exports.getTypedArrayForBufferView = getTypedArrayForBufferView;
19
+ // accepts accessor index or accessor object
20
+ // returns a `Uint8Array`
21
+ function getTypedArrayForImageData(json, buffers, imageIndex) {
22
+ const image = json.images[imageIndex];
23
+ const bufferViewIndex = json.bufferViews[image.bufferView];
24
+ return getTypedArrayForBufferView(json, buffers, bufferViewIndex);
15
25
  }
16
- //# sourceMappingURL=get-typed-array.js.map
26
+ exports.getTypedArrayForImageData = getTypedArrayForImageData;
27
+ /*
28
+ // accepts accessor index or accessor object
29
+ // returns a typed array with type that matches the types
30
+ export function getTypedArrayForAccessor(accessor) {
31
+ accessor = this.getAccessor(accessor);
32
+ const bufferView = this.getBufferView(accessor.bufferView);
33
+ const buffer = this.getBuffer(bufferView.buffer);
34
+ const arrayBuffer = buffer.data;
35
+
36
+ // Create a new typed array as a view into the combined buffer
37
+ const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);
38
+ const byteOffset = bufferView.byteOffset + accessor.byteOffset;
39
+ return new ArrayType(arrayBuffer, byteOffset, length);
40
+ }
41
+ */
@@ -1,73 +1,73 @@
1
- import { getAccessorTypeFromSize, getComponentTypeFromArray } from './gltf-utils';
2
- export function getGLTFAccessors(attributes) {
3
- const accessors = {};
4
-
5
- for (const name in attributes) {
6
- const attribute = attributes[name];
7
-
8
- if (name !== 'indices') {
9
- const glTFAccessor = getGLTFAccessor(attribute);
10
- accessors[name] = glTFAccessor;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGLTFAccessor = exports.getGLTFAccessors = void 0;
4
+ // TODO - remove
5
+ const gltf_utils_1 = require("./gltf-utils");
6
+ // Returns a fresh attributes object with glTF-standardized attributes names
7
+ // Attributes that cannot be identified will not be included
8
+ // Removes `indices` if present, as it should be stored separately from the attributes
9
+ function getGLTFAccessors(attributes) {
10
+ const accessors = {};
11
+ for (const name in attributes) {
12
+ const attribute = attributes[name];
13
+ if (name !== 'indices') {
14
+ const glTFAccessor = getGLTFAccessor(attribute);
15
+ accessors[name] = glTFAccessor;
16
+ }
11
17
  }
12
- }
13
-
14
- return accessors;
18
+ return accessors;
15
19
  }
16
- export function getGLTFAccessor(attribute) {
17
- const {
18
- buffer,
19
- size,
20
- count
21
- } = getAccessorData(attribute);
22
- const glTFAccessor = {
23
- value: buffer,
24
- size,
25
- byteOffset: 0,
26
- count,
27
- type: getAccessorTypeFromSize(size),
28
- componentType: getComponentTypeFromArray(buffer)
29
- };
30
- return glTFAccessor;
20
+ exports.getGLTFAccessors = getGLTFAccessors;
21
+ // Fix up a single accessor.
22
+ // Input: typed array or a partial accessor object
23
+ // Return: accessor object
24
+ function getGLTFAccessor(attribute) {
25
+ const { buffer, size, count } = getAccessorData(attribute);
26
+ const glTFAccessor = {
27
+ // glTF Accessor values
28
+ // TODO: Instead of a bufferView index we could have an actual buffer (typed array)
29
+ // bufferView: null,
30
+ // TODO: Deprecate `value` in favor of bufferView?
31
+ // @ts-ignore
32
+ value: buffer,
33
+ size,
34
+ byteOffset: 0,
35
+ count,
36
+ type: (0, gltf_utils_1.getAccessorTypeFromSize)(size),
37
+ componentType: (0, gltf_utils_1.getComponentTypeFromArray)(buffer)
38
+ };
39
+ return glTFAccessor;
31
40
  }
32
-
41
+ exports.getGLTFAccessor = getGLTFAccessor;
42
+ // export function getGLTFAttribute(data, gltfAttributeName): GLTFAccessor {
43
+ // return data.attributes[data.glTFAttributeMap[gltfAttributeName]];
44
+ // }
33
45
  function getAccessorData(attribute) {
34
- let buffer = attribute;
35
- let size = 1;
36
- let count = 0;
37
-
38
- if (attribute && attribute.value) {
39
- buffer = attribute.value;
40
- size = attribute.size || 1;
41
- }
42
-
43
- if (buffer) {
44
- if (!ArrayBuffer.isView(buffer)) {
45
- buffer = toTypedArray(buffer, Float32Array);
46
+ let buffer = attribute;
47
+ let size = 1;
48
+ let count = 0;
49
+ if (attribute && attribute.value) {
50
+ buffer = attribute.value;
51
+ size = attribute.size || 1;
46
52
  }
47
-
48
- count = buffer.length / size;
49
- }
50
-
51
- return {
52
- buffer,
53
- size,
54
- count
55
- };
53
+ if (buffer) {
54
+ if (!ArrayBuffer.isView(buffer)) {
55
+ buffer = toTypedArray(buffer, Float32Array);
56
+ }
57
+ count = buffer.length / size;
58
+ }
59
+ return { buffer, size, count };
56
60
  }
57
-
61
+ // Convert non-typed arrays to arrays of specified format
58
62
  function toTypedArray(array, ArrayType, convertTypedArrays = false) {
59
- if (!array) {
60
- return null;
61
- }
62
-
63
- if (Array.isArray(array)) {
64
- return new ArrayType(array);
65
- }
66
-
67
- if (convertTypedArrays && !(array instanceof ArrayType)) {
68
- return new ArrayType(array);
69
- }
70
-
71
- return array;
63
+ if (!array) {
64
+ return null;
65
+ }
66
+ if (Array.isArray(array)) {
67
+ return new ArrayType(array);
68
+ }
69
+ if (convertTypedArrays && !(array instanceof ArrayType)) {
70
+ return new ArrayType(array);
71
+ }
72
+ return array;
72
73
  }
73
- //# sourceMappingURL=gltf-attribute-utils.js.map