@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
@@ -10,7 +10,8 @@ import type {
10
10
  GLTFTexture,
11
11
  GLTFImage,
12
12
  GLTFBuffer,
13
- GLTFBufferView
13
+ GLTFBufferView,
14
+ GLTFWithBuffers
14
15
  } from '../types/gltf-types';
15
16
 
16
17
  import {getBinaryImageMetadata} from '@loaders.gl/images';
@@ -22,12 +23,6 @@ import {
22
23
  getComponentTypeFromArray
23
24
  } from '../gltf-utils/gltf-utils';
24
25
 
25
- type GLTFWithBuffers = {
26
- json: GLTF;
27
- buffers: any[];
28
- binary?: ArrayBuffer;
29
- };
30
-
31
26
  const DEFAULT_GLTF_JSON: GLTF = {
32
27
  asset: {
33
28
  version: '2.0',
@@ -68,13 +63,13 @@ export default class GLTFScenegraph {
68
63
  return this.gltf.json;
69
64
  }
70
65
 
71
- getApplicationData(key: string): {[key: string]: any} {
66
+ getApplicationData(key: string): unknown {
72
67
  // TODO - Data is already unpacked by GLBParser
73
68
  const data = this.json[key];
74
69
  return data;
75
70
  }
76
71
 
77
- getExtraData(key: string): {[key: string]: any} {
72
+ getExtraData(key: string): {[key: string]: unknown} {
78
73
  // TODO - Data is already unpacked by GLBParser
79
74
  const extras = this.json.extras || {};
80
75
  return extras[key];
@@ -99,6 +94,10 @@ export default class GLTFScenegraph {
99
94
  return this.json.extensionsUsed || [];
100
95
  }
101
96
 
97
+ getRemovedExtensions(): string[] {
98
+ return (this.json.extensionsRemoved || []) as string[];
99
+ }
100
+
102
101
  getObjectExtension<T = Extension>(object: {[key: string]: any}, extensionName: string): T | null {
103
102
  const extensions = object.extensions || {};
104
103
  return extensions[extensionName];
@@ -157,7 +156,7 @@ export default class GLTFScenegraph {
157
156
  if (typeof index === 'object') {
158
157
  return index;
159
158
  }
160
- const object = this.json[array] && this.json[array][index];
159
+ const object = this.json[array] && (this.json[array] as {}[])[index];
161
160
  if (!object) {
162
161
  throw new Error(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line
163
162
  }
@@ -234,7 +233,7 @@ export default class GLTFScenegraph {
234
233
  */
235
234
  addExtraData(key: string, data: object): GLTFScenegraph {
236
235
  this.json.extras = this.json.extras || {};
237
- this.json.extras[key] = data;
236
+ (this.json.extras as Record<string, unknown>)[key] = data;
238
237
  return this;
239
238
  }
240
239
 
@@ -269,7 +268,7 @@ export default class GLTFScenegraph {
269
268
  addExtension(extensionName: string, extensionData: object = {}): object {
270
269
  assert(extensionData);
271
270
  this.json.extensions = this.json.extensions || {};
272
- this.json.extensions[extensionName] = extensionData;
271
+ (this.json.extensions as Record<string, unknown>)[extensionName] = extensionData;
273
272
  this.registerUsedExtension(extensionName);
274
273
  return extensionData;
275
274
  }
@@ -309,6 +308,9 @@ export default class GLTFScenegraph {
309
308
  * Removes an extension from the top-level list
310
309
  */
311
310
  removeExtension(extensionName: string): void {
311
+ if (!this.getExtension(extensionName)) {
312
+ return;
313
+ }
312
314
  if (this.json.extensionsRequired) {
313
315
  this._removeStringFromArray(this.json.extensionsRequired, extensionName);
314
316
  }
@@ -318,6 +320,13 @@ export default class GLTFScenegraph {
318
320
  if (this.json.extensions) {
319
321
  delete this.json.extensions[extensionName];
320
322
  }
323
+ if (!Array.isArray(this.json.extensionsRemoved)) {
324
+ this.json.extensionsRemoved = [];
325
+ }
326
+ const extensionsRemoved = this.json.extensionsRemoved as string[];
327
+ if (!extensionsRemoved.includes(extensionName)) {
328
+ extensionsRemoved.push(extensionName);
329
+ }
321
330
  }
322
331
 
323
332
  /**
@@ -298,7 +298,8 @@ class GLTFV1Normalizer {
298
298
  roughnessFactor: 1
299
299
  };
300
300
 
301
- const textureId = material.values && material.values.tex;
301
+ const textureId =
302
+ material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;
302
303
  const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);
303
304
  if (textureIndex !== -1) {
304
305
  material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};
@@ -10,10 +10,17 @@ const MAGIC_BIN = 0x004e4942; // BIN\0 in ASCII
10
10
 
11
11
  const LE = true; // Binary GLTF is little endian.
12
12
 
13
+ export type GLBEncodeOptions = {};
14
+
13
15
  // Encode the full GLB buffer with header etc
14
16
  // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#
15
17
  // glb-file-format-specification
16
- export default function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) {
18
+ export default function encodeGLBSync(
19
+ glb,
20
+ dataView,
21
+ byteOffset = 0,
22
+ options: GLBEncodeOptions = {}
23
+ ) {
17
24
  const {magic = MAGIC_glTF, version = 2, json = {}, binary} = glb;
18
25
 
19
26
  const byteOffsetStart = byteOffset;
@@ -1,15 +1,24 @@
1
1
  import encodeGLBSync from './encode-glb';
2
2
 
3
- // Encode the full glTF file as a binary GLB file
4
- // Returns an ArrayBuffer that represents the complete GLB image that can be saved to file
5
- //
6
- // TODO - Does not support encoding to non-GLB versions of glTF format
7
- // - Encode as a textual JSON file with binary data in base64 data URLs.
8
- // - Encode as a JSON with all images (and buffers?) in separate binary files
9
- //
10
- // glb-file-format-specification
11
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#
3
+ export type GLTFEncodeOptions = Record<string, any>;
12
4
 
5
+ /**
6
+ * Encode the full glTF file as a binary GLB file
7
+ * Returns an ArrayBuffer that represents the complete GLB image that can be saved to file
8
+ *
9
+ * @todo - Does not support encoding to non-GLB versions of glTF format. Other formats
10
+ * - Encode as a textual JSON file with binary data in base64 data URLs.
11
+ * - Encode as a JSON with all images (and buffers?) in separate binary files
12
+ *
13
+ * glb-file-format-specification
14
+ * @see https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#
15
+ *
16
+ * @param gltf
17
+ * @param arrayBuffer
18
+ * @param byteOffset
19
+ * @param options
20
+ * @returns
21
+ */
13
22
  export function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
14
23
  convertBuffersToBase64(gltf);
15
24
 
@@ -2,7 +2,7 @@
2
2
  import type {GLTF, GLTFBufferView, GLTF_EXT_meshopt_compression} from '../types/gltf-types';
3
3
  import type {GLTFLoaderOptions} from '../../gltf-loader';
4
4
  import GLTFScenegraph from '../api/gltf-scenegraph';
5
- import {isMeshoptSupported, meshoptDecodeGltfBuffer} from '../../meshopt/meshopt-decoder';
5
+ import {meshoptDecodeGltfBuffer} from '../../meshopt/meshopt-decoder';
6
6
 
7
7
  // @ts-ignore
8
8
  // eslint-disable-next-line
@@ -16,16 +16,6 @@ const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
16
16
 
17
17
  export const name = EXT_MESHOPT_COMPRESSION;
18
18
 
19
- export function preprocess(gltfData: {json: GLTF}) {
20
- const scenegraph = new GLTFScenegraph(gltfData);
21
- if (
22
- scenegraph.getRequiredExtensions().includes(EXT_MESHOPT_COMPRESSION) &&
23
- !isMeshoptSupported()
24
- ) {
25
- throw new Error(`gltf: Required extension ${EXT_MESHOPT_COMPRESSION} not supported by browser`);
26
- }
27
- }
28
-
29
19
  export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions) {
30
20
  const scenegraph = new GLTFScenegraph(gltfData);
31
21
 
@@ -41,7 +31,7 @@ export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions)
41
31
  // Decompress meshes in parallel
42
32
  await Promise.all(promises);
43
33
 
44
- // We have now decompressed all primitives, so remove the top-level extensions
34
+ // We have now decompressed all primitives, so remove the top-level extension
45
35
  scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
46
36
  }
47
37
 
@@ -55,21 +45,24 @@ async function decodeMeshoptBufferView(
55
45
  EXT_MESHOPT_COMPRESSION
56
46
  );
57
47
  if (meshoptExtension) {
58
- const buffer = bufferView.buffer;
59
-
60
48
  const {
61
49
  byteOffset = 0,
62
50
  byteLength = 0,
63
51
  byteStride,
64
52
  count,
65
53
  mode,
66
- filter = 'NONE'
54
+ filter = 'NONE',
55
+ buffer: bufferIndex
67
56
  } = meshoptExtension;
57
+ const buffer = scenegraph.gltf.buffers[bufferIndex];
68
58
 
69
- // @ts-expect-error TODO - fix buffer handling
70
- const source = new Uint8Array(buffer, byteOffset, byteLength);
71
- const result = new ArrayBuffer(count * byteStride);
72
- await meshoptDecodeGltfBuffer(new Uint8Array(result), count, byteStride, source, mode, filter);
59
+ const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
60
+ const result = new Uint8Array(
61
+ scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer,
62
+ bufferView.byteOffset,
63
+ bufferView.byteLength
64
+ );
65
+ await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);
73
66
  return result;
74
67
  }
75
68
 
@@ -5,7 +5,7 @@
5
5
  import type {GLTF, GLTF_EXT_texture_webp} from '../types/gltf-types';
6
6
  import type {GLTFLoaderOptions} from '../../gltf-loader';
7
7
 
8
- import {_isImageFormatSupported} from '@loaders.gl/images';
8
+ import {isImageFormatSupported} from '@loaders.gl/images';
9
9
  import GLTFScenegraph from '../api/gltf-scenegraph';
10
10
 
11
11
  const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
@@ -20,7 +20,7 @@ export const name = EXT_TEXTURE_WEBP;
20
20
  export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {
21
21
  const scenegraph = new GLTFScenegraph(gltfData);
22
22
 
23
- if (!_isImageFormatSupported('image/webp')) {
23
+ if (!isImageFormatSupported('image/webp')) {
24
24
  if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
25
25
  throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
26
26
  }
@@ -35,6 +35,7 @@ export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions):
35
35
  EXT_TEXTURE_WEBP
36
36
  );
37
37
  if (extension) {
38
+ // TODO - if multiple texture extensions are present which one wins?
38
39
  texture.source = extension.source;
39
40
  }
40
41
  scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
@@ -40,7 +40,7 @@ export function preprocess(gltfData: {json: GLTF}): void {
40
40
  delete json.buffers[0].uri;
41
41
  }
42
42
 
43
- // Remove the top-level extension as it has now been removed from all nodes
43
+ // Remove the top-level extension as it has now been processed
44
44
  gltfScenegraph.removeExtension(KHR_BINARY_GLTF);
45
45
  }
46
46
 
@@ -56,7 +56,7 @@ export async function decode(
56
56
  // Decompress meshes in parallel
57
57
  await Promise.all(promises);
58
58
 
59
- // We have now decompressed all primitives, so remove the top-level extensions
59
+ // We have now decompressed all primitives, so remove the top-level extension
60
60
  scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
61
61
  }
62
62
 
@@ -26,6 +26,7 @@ export function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions):
26
26
  KHR_TEXTURE_BASISU
27
27
  );
28
28
  if (extension) {
29
+ // TODO - if multiple texture extensions are present which one wins?
29
30
  texture.source = extension.source;
30
31
  }
31
32
  scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
@@ -0,0 +1,305 @@
1
+ /**
2
+ * https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_texture_transform/README.md
3
+ */
4
+
5
+ import {Vector3, Matrix3} from '@math.gl/core';
6
+ import type {GLTFMeshPrimitive, GLTFWithBuffers} from '../types/gltf-types';
7
+ import type {GLTFLoaderOptions} from '../../gltf-loader';
8
+ import {getAccessorArrayTypeAndLength} from '../gltf-utils/gltf-utils';
9
+ import {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';
10
+ import {
11
+ Accessor,
12
+ BufferView,
13
+ MaterialNormalTextureInfo,
14
+ MaterialOcclusionTextureInfo,
15
+ TextureInfo as GLTFTextureInfo
16
+ } from '../types/gltf-json-schema';
17
+ import GLTFScenegraph from '../api/gltf-scenegraph';
18
+
19
+ /** Extension name */
20
+ const EXT_MESHOPT_TRANSFORM = 'KHR_texture_transform';
21
+
22
+ export const name = EXT_MESHOPT_TRANSFORM;
23
+
24
+ const scratchVector = new Vector3();
25
+ const scratchRotationMatrix = new Matrix3();
26
+ const scratchScaleMatrix = new Matrix3();
27
+
28
+ /** Extension textureInfo https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */
29
+ type TextureInfo = {
30
+ /** The offset of the UV coordinate origin as a factor of the texture dimensions. */
31
+ offset?: [number, number];
32
+ /** Rotate the UVs by this many radians counter-clockwise around the origin. This is equivalent to a similar rotation of the image clockwise. */
33
+ rotation?: number;
34
+ /** The scale factor applied to the components of the UV coordinates. */
35
+ scale?: [number, number];
36
+ /** Overrides the textureInfo texCoord value if supplied, and if this extension is supported. */
37
+ texCoord?: number;
38
+ };
39
+ /** Intersection of all GLTF textures */
40
+ type CompoundGLTFTextureInfo = GLTFTextureInfo &
41
+ MaterialNormalTextureInfo &
42
+ MaterialOcclusionTextureInfo;
43
+ /** Parameters for TEXCOORD transformation */
44
+ type TransformParameters = {
45
+ /** Original texCoord value https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#_textureinfo_texcoord */
46
+ originalTexCoord: number;
47
+ /** New texCoord value from extension https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#gltf-schema-updates */
48
+ texCoord: number;
49
+ /** Transformation matrix */
50
+ matrix: Matrix3;
51
+ };
52
+
53
+ /**
54
+ * The extension entry to process the transformation
55
+ * @param gltfData gltf buffers and json
56
+ * @param options GLTFLoader options
57
+ */
58
+ export async function decode(gltfData: GLTFWithBuffers, options: GLTFLoaderOptions) {
59
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
60
+ const extension = gltfScenegraph.getExtension(EXT_MESHOPT_TRANSFORM);
61
+ if (!extension) {
62
+ return;
63
+ }
64
+ const materials = gltfData.json.materials || [];
65
+ for (let i = 0; i < materials.length; i++) {
66
+ transformTexCoords(i, gltfData);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Transform TEXCOORD by material
72
+ * @param materialIndex processing material index
73
+ * @param gltfData gltf buffers and json
74
+ */
75
+ function transformTexCoords(materialIndex: number, gltfData: GLTFWithBuffers): void {
76
+ // Save processed texCoords in order no to process the same twice
77
+ const processedTexCoords: [number, number][] = [];
78
+ const material = gltfData.json.materials?.[materialIndex];
79
+ const baseColorTexture = material?.pbrMetallicRoughness?.baseColorTexture;
80
+ if (baseColorTexture) {
81
+ transformPrimitives(gltfData, materialIndex, baseColorTexture, processedTexCoords);
82
+ }
83
+ const emisiveTexture = material?.emissiveTexture;
84
+ if (emisiveTexture) {
85
+ transformPrimitives(gltfData, materialIndex, emisiveTexture, processedTexCoords);
86
+ }
87
+ const normalTexture = material?.normalTexture;
88
+ if (normalTexture) {
89
+ transformPrimitives(gltfData, materialIndex, normalTexture, processedTexCoords);
90
+ }
91
+ const occlusionTexture = material?.occlusionTexture;
92
+ if (occlusionTexture) {
93
+ transformPrimitives(gltfData, materialIndex, occlusionTexture, processedTexCoords);
94
+ }
95
+ const metallicRoughnessTexture = material?.pbrMetallicRoughness?.metallicRoughnessTexture;
96
+ if (metallicRoughnessTexture) {
97
+ transformPrimitives(gltfData, materialIndex, metallicRoughnessTexture, processedTexCoords);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Transform primitives of the particular material
103
+ * @param gltfData gltf data
104
+ * @param materialIndex primitives with this material will be transformed
105
+ * @param texture texture object
106
+ * @param processedTexCoords storage to save already processed texCoords
107
+ */
108
+ function transformPrimitives(
109
+ gltfData: GLTFWithBuffers,
110
+ materialIndex: number,
111
+ texture: CompoundGLTFTextureInfo,
112
+ processedTexCoords: [number, number][]
113
+ ) {
114
+ const transformParameters = getTransformParameters(texture, processedTexCoords);
115
+ if (!transformParameters) {
116
+ return;
117
+ }
118
+ const meshes = gltfData.json.meshes || [];
119
+ for (const mesh of meshes) {
120
+ for (const primitive of mesh.primitives) {
121
+ const material = primitive.material;
122
+ if (Number.isFinite(material) && materialIndex === material) {
123
+ transformPrimitive(gltfData, primitive, transformParameters);
124
+ }
125
+ }
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Get parameters for TEXCOORD transformation
131
+ * @param texture texture object
132
+ * @param processedTexCoords storage to save already processed texCoords
133
+ * @returns texCoord couple and transformation matrix
134
+ */
135
+ function getTransformParameters(
136
+ texture: CompoundGLTFTextureInfo,
137
+ processedTexCoords: [number, number][]
138
+ ): TransformParameters | null {
139
+ const textureInfo = texture.extensions?.[EXT_MESHOPT_TRANSFORM];
140
+ const {texCoord: originalTexCoord = 0} = texture;
141
+ // If texCoord is not set in the extension, original attribute data will be replaced
142
+ const {texCoord = originalTexCoord} = textureInfo;
143
+ // Make sure that couple [originalTexCoord, extensionTexCoord] is not processed twice
144
+ const isProcessed =
145
+ processedTexCoords.findIndex(
146
+ ([original, newTexCoord]) => original === originalTexCoord && newTexCoord === texCoord
147
+ ) !== -1;
148
+ if (!isProcessed) {
149
+ const matrix = makeTransformationMatrix(textureInfo);
150
+ if (originalTexCoord !== texCoord) {
151
+ texture.texCoord = texCoord;
152
+ }
153
+ processedTexCoords.push([originalTexCoord, texCoord]);
154
+ return {originalTexCoord, texCoord, matrix};
155
+ }
156
+ return null;
157
+ }
158
+
159
+ /**
160
+ * Transform `TEXCOORD_0` attribute in the primitive
161
+ * @param gltfData gltf data
162
+ * @param primitive primitive object
163
+ * @param transformParameters texCoord couple and transformation matrix
164
+ */
165
+ function transformPrimitive(
166
+ gltfData: GLTFWithBuffers,
167
+ primitive: GLTFMeshPrimitive,
168
+ transformParameters: TransformParameters
169
+ ) {
170
+ const {originalTexCoord, texCoord, matrix} = transformParameters;
171
+ const texCoordAccessor = primitive.attributes[`TEXCOORD_${originalTexCoord}`];
172
+ if (Number.isFinite(texCoordAccessor)) {
173
+ // Get accessor of the `TEXCOORD_0` attribute
174
+ const accessor = gltfData.json.accessors?.[texCoordAccessor];
175
+ if (accessor && accessor.bufferView) {
176
+ // Get `bufferView` of the `accessor`
177
+ const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];
178
+ if (bufferView) {
179
+ // Get `arrayBuffer` the `bufferView` look at
180
+ const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];
181
+ // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets
182
+ const byteOffset =
183
+ (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
184
+ // Deduce TypedArray type and its length from `accessor` and `bufferView` data
185
+ const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);
186
+ // Number of bytes each component occupies
187
+ const bytes = BYTES[accessor.componentType];
188
+ // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2
189
+ const components = COMPONENTS[accessor.type];
190
+ // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer
191
+ const elementAddressScale = bufferView.byteStride || bytes * components;
192
+ // Data transform to Float32Array
193
+ const result = new Float32Array(length);
194
+ for (let i = 0; i < accessor.count; i++) {
195
+ // Take [u, v] couple from the arrayBuffer
196
+ const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
197
+ // Set and transform Vector3 per https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform#overview
198
+ scratchVector.set(uv[0], uv[1], 1);
199
+ scratchVector.transformByMatrix3(matrix);
200
+ // Save result in Float32Array
201
+ result.set([scratchVector[0], scratchVector[1]], i * components);
202
+ }
203
+ // If texCoord the same, replace gltf structural data
204
+ if (originalTexCoord === texCoord) {
205
+ updateGltf(accessor, bufferView, gltfData.buffers, result);
206
+ } else {
207
+ // If texCoord change, create new attribute
208
+ createAttribute(texCoord, accessor, primitive, gltfData, result);
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Update GLTF structural objects with new data as we create new `Float32Array` for `TEXCOORD_0`.
217
+ * @param accessor accessor to change
218
+ * @param bufferView bufferView to change
219
+ * @param buffers binary buffers
220
+ * @param newTexcoordArray typed array with data after transformation
221
+ */
222
+ function updateGltf(
223
+ accessor: Accessor,
224
+ bufferView: BufferView,
225
+ buffers: {arrayBuffer: ArrayBuffer; byteOffset: number; byteLength: number}[],
226
+ newTexCoordArray: Float32Array
227
+ ): void {
228
+ accessor.componentType = 5126;
229
+ buffers.push({
230
+ arrayBuffer: newTexCoordArray.buffer,
231
+ byteOffset: 0,
232
+ byteLength: newTexCoordArray.buffer.byteLength
233
+ });
234
+ bufferView.buffer = buffers.length - 1;
235
+ bufferView.byteLength = newTexCoordArray.buffer.byteLength;
236
+ bufferView.byteOffset = 0;
237
+ delete bufferView.byteStride;
238
+ }
239
+
240
+ /**
241
+ *
242
+ * @param newTexCoord new `texCoord` value
243
+ * @param originalAccessor original accessor object, that store data before transformation
244
+ * @param primitive primitive object
245
+ * @param gltfData gltf data
246
+ * @param newTexCoordArray typed array with data after transformation
247
+ * @returns
248
+ */
249
+ function createAttribute(
250
+ newTexCoord: number,
251
+ originalAccessor: Accessor,
252
+ primitive: GLTFMeshPrimitive,
253
+ gltfData: GLTFWithBuffers,
254
+ newTexCoordArray: Float32Array
255
+ ) {
256
+ gltfData.buffers.push({
257
+ arrayBuffer: newTexCoordArray.buffer,
258
+ byteOffset: 0,
259
+ byteLength: newTexCoordArray.buffer.byteLength
260
+ });
261
+ const bufferViews = gltfData.json.bufferViews;
262
+ if (!bufferViews) {
263
+ return;
264
+ }
265
+ bufferViews.push({
266
+ buffer: gltfData.buffers.length - 1,
267
+ byteLength: newTexCoordArray.buffer.byteLength,
268
+ byteOffset: 0
269
+ });
270
+ const accessors = gltfData.json.accessors;
271
+ if (!accessors) {
272
+ return;
273
+ }
274
+ accessors.push({
275
+ bufferView: bufferViews?.length - 1,
276
+ byteOffset: 0,
277
+ componentType: 5126,
278
+ count: originalAccessor.count,
279
+ type: 'VEC2'
280
+ });
281
+ primitive.attributes[`TEXCOORD_${newTexCoord}`] = accessors.length - 1;
282
+ }
283
+
284
+ /**
285
+ * Construct transformation matrix from the extension data (transition, rotation, scale)
286
+ * @param extensionData extension data
287
+ * @returns transformation matrix
288
+ */
289
+ function makeTransformationMatrix(extensionData: TextureInfo): Matrix3 {
290
+ const {offset = [0, 0], rotation = 0, scale = [1, 1]} = extensionData;
291
+ const translationMatirx = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
292
+ const rotationMatirx = scratchRotationMatrix.set(
293
+ Math.cos(rotation),
294
+ Math.sin(rotation),
295
+ 0,
296
+ -Math.sin(rotation),
297
+ Math.cos(rotation),
298
+ 0,
299
+ 0,
300
+ 0,
301
+ 1
302
+ );
303
+ const scaleMatrix = scratchScaleMatrix.set(scale[0], 0, 0, 0, scale[1], 0, 0, 0, 1);
304
+ return translationMatirx.multiplyRight(rotationMatirx).multiplyRight(scaleMatrix);
305
+ }