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

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 (211) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/dist.min.js +13 -13
  4. package/dist/glb-loader.js +28 -33
  5. package/dist/glb-loader.js.map +1 -0
  6. package/dist/glb-writer.js +26 -34
  7. package/dist/glb-writer.js.map +1 -0
  8. package/dist/gltf-loader.js +43 -46
  9. package/dist/gltf-loader.js.map +1 -0
  10. package/dist/gltf-writer.js +26 -29
  11. package/dist/gltf-writer.js.map +1 -0
  12. package/dist/index.js +7 -21
  13. package/dist/index.js.map +1 -0
  14. package/dist/lib/api/gltf-extensions.js +31 -71
  15. package/dist/lib/api/gltf-extensions.js.map +1 -0
  16. package/dist/lib/api/gltf-scenegraph.js +512 -550
  17. package/dist/lib/api/gltf-scenegraph.js.map +1 -0
  18. package/dist/lib/api/normalize-gltf-v1.js +229 -274
  19. package/dist/lib/api/normalize-gltf-v1.js.map +1 -0
  20. package/dist/lib/api/post-process-gltf.js +376 -324
  21. package/dist/lib/api/post-process-gltf.js.map +1 -0
  22. package/dist/lib/encoders/encode-glb.js +58 -56
  23. package/dist/lib/encoders/encode-glb.js.map +1 -0
  24. package/dist/lib/encoders/encode-gltf.js +12 -25
  25. package/dist/lib/encoders/encode-gltf.js.map +1 -0
  26. package/dist/lib/extensions/EXT_meshopt_compression.js +49 -47
  27. package/dist/lib/extensions/EXT_meshopt_compression.js.map +1 -0
  28. package/dist/lib/extensions/EXT_texture_webp.js +28 -34
  29. package/dist/lib/extensions/EXT_texture_webp.js.map +1 -0
  30. package/dist/lib/extensions/KHR_binary_gltf.js +23 -39
  31. package/dist/lib/extensions/KHR_binary_gltf.js.map +1 -0
  32. package/dist/lib/extensions/KHR_draco_mesh_compression.js +111 -126
  33. package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +1 -0
  34. package/dist/lib/extensions/KHR_texture_basisu.js +19 -28
  35. package/dist/lib/extensions/KHR_texture_basisu.js.map +1 -0
  36. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +44 -57
  37. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -0
  38. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +32 -42
  39. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -0
  40. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +62 -75
  41. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -0
  42. package/dist/lib/gltf-utils/get-typed-array.js +14 -39
  43. package/dist/lib/gltf-utils/get-typed-array.js.map +1 -0
  44. package/dist/lib/gltf-utils/gltf-attribute-utils.js +65 -65
  45. package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +1 -0
  46. package/dist/lib/gltf-utils/gltf-constants.js +30 -36
  47. package/dist/lib/gltf-utils/gltf-constants.js.map +1 -0
  48. package/dist/lib/gltf-utils/gltf-utils.js +45 -52
  49. package/dist/lib/gltf-utils/gltf-utils.js.map +1 -0
  50. package/dist/lib/gltf-utils/resolve-url.js +15 -17
  51. package/dist/lib/gltf-utils/resolve-url.js.map +1 -0
  52. package/dist/lib/parsers/parse-glb.js +107 -120
  53. package/dist/lib/parsers/parse-glb.js.map +1 -0
  54. package/dist/lib/parsers/parse-gltf.js +154 -173
  55. package/dist/lib/parsers/parse-gltf.js.map +1 -0
  56. package/dist/lib/types/glb-types.js +2 -2
  57. package/dist/{es5/lib → lib}/types/glb-types.js.map +0 -0
  58. package/dist/lib/types/gltf-json-schema.js +2 -4
  59. package/dist/{es5/lib → lib}/types/gltf-json-schema.js.map +0 -0
  60. package/dist/lib/types/gltf-postprocessed-schema.js +2 -4
  61. package/dist/{es5/lib → lib}/types/gltf-postprocessed-schema.js.map +0 -0
  62. package/dist/lib/types/gltf-types.js +2 -3
  63. package/dist/{es5/lib → lib}/types/gltf-types.js.map +0 -0
  64. package/dist/lib/utils/assert.js +5 -11
  65. package/dist/lib/utils/assert.js.map +1 -0
  66. package/dist/lib/utils/version.js +2 -7
  67. package/dist/lib/utils/version.js.map +1 -0
  68. package/dist/meshopt/meshopt-decoder.js +82 -97
  69. package/dist/meshopt/meshopt-decoder.js.map +1 -0
  70. package/dist/{es5/meshopt → meshopt}/meshopt-encoder.ts.disabled +0 -0
  71. package/dist/webp/webp.js +23 -32
  72. package/dist/webp/webp.js.map +1 -0
  73. package/package.json +8 -11
  74. package/src/lib/parsers/parse-gltf.ts +1 -1
  75. package/dist/es5/bundle.js +0 -7
  76. package/dist/es5/bundle.js.map +0 -1
  77. package/dist/es5/glb-loader.js +0 -70
  78. package/dist/es5/glb-loader.js.map +0 -1
  79. package/dist/es5/glb-writer.js +0 -41
  80. package/dist/es5/glb-writer.js.map +0 -1
  81. package/dist/es5/gltf-loader.js +0 -97
  82. package/dist/es5/gltf-loader.js.map +0 -1
  83. package/dist/es5/gltf-writer.js +0 -40
  84. package/dist/es5/gltf-writer.js.map +0 -1
  85. package/dist/es5/index.js +0 -56
  86. package/dist/es5/index.js.map +0 -1
  87. package/dist/es5/lib/api/gltf-extensions.js +0 -146
  88. package/dist/es5/lib/api/gltf-extensions.js.map +0 -1
  89. package/dist/es5/lib/api/gltf-scenegraph.js +0 -623
  90. package/dist/es5/lib/api/gltf-scenegraph.js.map +0 -1
  91. package/dist/es5/lib/api/normalize-gltf-v1.js +0 -392
  92. package/dist/es5/lib/api/normalize-gltf-v1.js.map +0 -1
  93. package/dist/es5/lib/api/post-process-gltf.js +0 -502
  94. package/dist/es5/lib/api/post-process-gltf.js.map +0 -1
  95. package/dist/es5/lib/encoders/encode-glb.js +0 -75
  96. package/dist/es5/lib/encoders/encode-glb.js.map +0 -1
  97. package/dist/es5/lib/encoders/encode-gltf.js +0 -26
  98. package/dist/es5/lib/encoders/encode-gltf.js.map +0 -1
  99. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +0 -137
  100. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +0 -1
  101. package/dist/es5/lib/extensions/EXT_texture_webp.js +0 -60
  102. package/dist/es5/lib/extensions/EXT_texture_webp.js.map +0 -1
  103. package/dist/es5/lib/extensions/KHR_binary_gltf.js +0 -53
  104. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +0 -1
  105. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +0 -331
  106. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
  107. package/dist/es5/lib/extensions/KHR_texture_basisu.js +0 -49
  108. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +0 -1
  109. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +0 -129
  110. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
  111. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +0 -97
  112. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
  113. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -139
  114. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
  115. package/dist/es5/lib/gltf-utils/get-typed-array.js +0 -26
  116. package/dist/es5/lib/gltf-utils/get-typed-array.js.map +0 -1
  117. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +0 -85
  118. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
  119. package/dist/es5/lib/gltf-utils/gltf-constants.js +0 -48
  120. package/dist/es5/lib/gltf-utils/gltf-constants.js.map +0 -1
  121. package/dist/es5/lib/gltf-utils/gltf-utils.js +0 -69
  122. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +0 -1
  123. package/dist/es5/lib/gltf-utils/resolve-url.js +0 -23
  124. package/dist/es5/lib/gltf-utils/resolve-url.js.map +0 -1
  125. package/dist/es5/lib/parsers/parse-glb.js +0 -142
  126. package/dist/es5/lib/parsers/parse-glb.js.map +0 -1
  127. package/dist/es5/lib/parsers/parse-gltf.js +0 -353
  128. package/dist/es5/lib/parsers/parse-gltf.js.map +0 -1
  129. package/dist/es5/lib/types/glb-types.js +0 -2
  130. package/dist/es5/lib/types/gltf-json-schema.js +0 -2
  131. package/dist/es5/lib/types/gltf-postprocessed-schema.js +0 -2
  132. package/dist/es5/lib/types/gltf-types.js +0 -2
  133. package/dist/es5/lib/utils/assert.js +0 -13
  134. package/dist/es5/lib/utils/assert.js.map +0 -1
  135. package/dist/es5/lib/utils/version.js +0 -9
  136. package/dist/es5/lib/utils/version.js.map +0 -1
  137. package/dist/es5/meshopt/meshopt-decoder.js +0 -270
  138. package/dist/es5/meshopt/meshopt-decoder.js.map +0 -1
  139. package/dist/es5/webp/webp.js +0 -104
  140. package/dist/es5/webp/webp.js.map +0 -1
  141. package/dist/esm/bundle.js +0 -5
  142. package/dist/esm/bundle.js.map +0 -1
  143. package/dist/esm/glb-loader.js +0 -34
  144. package/dist/esm/glb-loader.js.map +0 -1
  145. package/dist/esm/glb-writer.js +0 -29
  146. package/dist/esm/glb-writer.js.map +0 -1
  147. package/dist/esm/gltf-loader.js +0 -47
  148. package/dist/esm/gltf-loader.js.map +0 -1
  149. package/dist/esm/gltf-writer.js +0 -29
  150. package/dist/esm/gltf-writer.js.map +0 -1
  151. package/dist/esm/index.js +0 -7
  152. package/dist/esm/index.js.map +0 -1
  153. package/dist/esm/lib/api/gltf-extensions.js +0 -35
  154. package/dist/esm/lib/api/gltf-extensions.js.map +0 -1
  155. package/dist/esm/lib/api/gltf-scenegraph.js +0 -515
  156. package/dist/esm/lib/api/gltf-scenegraph.js.map +0 -1
  157. package/dist/esm/lib/api/normalize-gltf-v1.js +0 -250
  158. package/dist/esm/lib/api/normalize-gltf-v1.js.map +0 -1
  159. package/dist/esm/lib/api/post-process-gltf.js +0 -422
  160. package/dist/esm/lib/api/post-process-gltf.js.map +0 -1
  161. package/dist/esm/lib/encoders/encode-glb.js +0 -63
  162. package/dist/esm/lib/encoders/encode-glb.js.map +0 -1
  163. package/dist/esm/lib/encoders/encode-gltf.js +0 -14
  164. package/dist/esm/lib/encoders/encode-gltf.js.map +0 -1
  165. package/dist/esm/lib/extensions/EXT_meshopt_compression.js +0 -56
  166. package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +0 -1
  167. package/dist/esm/lib/extensions/EXT_texture_webp.js +0 -32
  168. package/dist/esm/lib/extensions/EXT_texture_webp.js.map +0 -1
  169. package/dist/esm/lib/extensions/KHR_binary_gltf.js +0 -26
  170. package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +0 -1
  171. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +0 -126
  172. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
  173. package/dist/esm/lib/extensions/KHR_texture_basisu.js +0 -22
  174. package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +0 -1
  175. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +0 -49
  176. package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
  177. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +0 -37
  178. package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
  179. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -68
  180. package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
  181. package/dist/esm/lib/gltf-utils/get-typed-array.js +0 -16
  182. package/dist/esm/lib/gltf-utils/get-typed-array.js.map +0 -1
  183. package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js +0 -73
  184. package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
  185. package/dist/esm/lib/gltf-utils/gltf-constants.js +0 -37
  186. package/dist/esm/lib/gltf-utils/gltf-constants.js.map +0 -1
  187. package/dist/esm/lib/gltf-utils/gltf-utils.js +0 -56
  188. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +0 -1
  189. package/dist/esm/lib/gltf-utils/resolve-url.js +0 -16
  190. package/dist/esm/lib/gltf-utils/resolve-url.js.map +0 -1
  191. package/dist/esm/lib/parsers/parse-glb.js +0 -128
  192. package/dist/esm/lib/parsers/parse-glb.js.map +0 -1
  193. package/dist/esm/lib/parsers/parse-gltf.js +0 -170
  194. package/dist/esm/lib/parsers/parse-gltf.js.map +0 -1
  195. package/dist/esm/lib/types/glb-types.js +0 -2
  196. package/dist/esm/lib/types/glb-types.js.map +0 -1
  197. package/dist/esm/lib/types/gltf-json-schema.js +0 -2
  198. package/dist/esm/lib/types/gltf-json-schema.js.map +0 -1
  199. package/dist/esm/lib/types/gltf-postprocessed-schema.js +0 -2
  200. package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +0 -1
  201. package/dist/esm/lib/types/gltf-types.js +0 -2
  202. package/dist/esm/lib/types/gltf-types.js.map +0 -1
  203. package/dist/esm/lib/utils/assert.js +0 -6
  204. package/dist/esm/lib/utils/assert.js.map +0 -1
  205. package/dist/esm/lib/utils/version.js +0 -2
  206. package/dist/esm/lib/utils/version.js.map +0 -1
  207. package/dist/esm/meshopt/meshopt-decoder.js +0 -103
  208. package/dist/esm/meshopt/meshopt-decoder.js.map +0 -1
  209. package/dist/esm/meshopt/meshopt-encoder.ts.disabled +0 -409
  210. package/dist/esm/webp/webp.js +0 -29
  211. package/dist/esm/webp/webp.js.map +0 -1
@@ -1,370 +1,422 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.postProcessGLTF = void 0;
4
- const assert_1 = require("../utils/assert");
5
- const gltf_utils_1 = require("../gltf-utils/gltf-utils");
6
- // This is a post processor for loaded glTF files
7
- // The goal is to make the loaded data easier to use in WebGL applications
8
- //
9
- // Functions:
10
- // * Resolve indexed arrays structure of glTF into a linked tree.
11
- // * Translate stringified enum keys and values into WebGL constants.
12
- // * Load images (optional)
13
- // ENUM LOOKUP
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import { assert } from '../utils/assert';
3
+ import { getAccessorArrayTypeAndLength } from '../gltf-utils/gltf-utils';
14
4
  const COMPONENTS = {
15
- SCALAR: 1,
16
- VEC2: 2,
17
- VEC3: 3,
18
- VEC4: 4,
19
- MAT2: 4,
20
- MAT3: 9,
21
- MAT4: 16
5
+ SCALAR: 1,
6
+ VEC2: 2,
7
+ VEC3: 3,
8
+ VEC4: 4,
9
+ MAT2: 4,
10
+ MAT3: 9,
11
+ MAT4: 16
22
12
  };
23
13
  const BYTES = {
24
- 5120: 1,
25
- 5121: 1,
26
- 5122: 2,
27
- 5123: 2,
28
- 5125: 4,
29
- 5126: 4 // FLOAT
14
+ 5120: 1,
15
+ 5121: 1,
16
+ 5122: 2,
17
+ 5123: 2,
18
+ 5125: 4,
19
+ 5126: 4
30
20
  };
31
21
  const GL_SAMPLER = {
32
- // Sampler parameters
33
- TEXTURE_MAG_FILTER: 0x2800,
34
- TEXTURE_MIN_FILTER: 0x2801,
35
- TEXTURE_WRAP_S: 0x2802,
36
- TEXTURE_WRAP_T: 0x2803,
37
- // Sampler default values
38
- REPEAT: 0x2901,
39
- LINEAR: 0x2601,
40
- NEAREST_MIPMAP_LINEAR: 0x2702
22
+ TEXTURE_MAG_FILTER: 0x2800,
23
+ TEXTURE_MIN_FILTER: 0x2801,
24
+ TEXTURE_WRAP_S: 0x2802,
25
+ TEXTURE_WRAP_T: 0x2803,
26
+ REPEAT: 0x2901,
27
+ LINEAR: 0x2601,
28
+ NEAREST_MIPMAP_LINEAR: 0x2702
41
29
  };
42
30
  const SAMPLER_PARAMETER_GLTF_TO_GL = {
43
- magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
44
- minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
45
- wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
46
- wrapT: GL_SAMPLER.TEXTURE_WRAP_T
31
+ magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
32
+ minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
33
+ wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
34
+ wrapT: GL_SAMPLER.TEXTURE_WRAP_T
47
35
  };
48
- // When undefined, a sampler with repeat wrapping and auto filtering should be used.
49
- // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#texture
50
36
  const DEFAULT_SAMPLER = {
51
- [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
52
- [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
53
- [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
54
- [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
37
+ [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
38
+ [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
39
+ [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
40
+ [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
55
41
  };
42
+
56
43
  function getBytesFromComponentType(componentType) {
57
- return BYTES[componentType];
44
+ return BYTES[componentType];
58
45
  }
46
+
59
47
  function getSizeFromAccessorType(type) {
60
- return COMPONENTS[type];
48
+ return COMPONENTS[type];
61
49
  }
50
+
62
51
  class GLTFPostProcessor {
63
- constructor() {
64
- this.baseUri = '';
65
- this.json = {};
66
- this.buffers = [];
67
- this.images = [];
52
+ constructor() {
53
+ _defineProperty(this, "baseUri", '');
54
+
55
+ _defineProperty(this, "json", {});
56
+
57
+ _defineProperty(this, "buffers", []);
58
+
59
+ _defineProperty(this, "images", []);
60
+ }
61
+
62
+ postProcess(gltf, options = {}) {
63
+ const {
64
+ json,
65
+ buffers = [],
66
+ images = [],
67
+ baseUri = ''
68
+ } = gltf;
69
+ assert(json);
70
+ this.baseUri = baseUri;
71
+ this.json = json;
72
+ this.buffers = buffers;
73
+ this.images = images;
74
+
75
+ this._resolveTree(this.json, options);
76
+
77
+ return this.json;
78
+ }
79
+
80
+ _resolveTree(json, options = {}) {
81
+ if (json.bufferViews) {
82
+ json.bufferViews = json.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));
68
83
  }
69
- postProcess(gltf, options = {}) {
70
- const { json, buffers = [], images = [], baseUri = '' } = gltf;
71
- (0, assert_1.assert)(json);
72
- this.baseUri = baseUri;
73
- this.json = json;
74
- this.buffers = buffers;
75
- this.images = images;
76
- this._resolveTree(this.json, options);
77
- return this.json;
84
+
85
+ if (json.images) {
86
+ json.images = json.images.map((image, i) => this._resolveImage(image, i));
78
87
  }
79
- // Convert indexed glTF structure into tree structure
80
- // cross-link index resolution, enum lookup, convenience calculations
81
- // eslint-disable-next-line complexity
82
- _resolveTree(json, options = {}) {
83
- if (json.bufferViews) {
84
- json.bufferViews = json.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));
85
- }
86
- if (json.images) {
87
- json.images = json.images.map((image, i) => this._resolveImage(image, i));
88
- }
89
- if (json.samplers) {
90
- json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
91
- }
92
- if (json.textures) {
93
- json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));
94
- }
95
- if (json.accessors) {
96
- json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
97
- }
98
- if (json.materials) {
99
- json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));
100
- }
101
- if (json.meshes) {
102
- json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
103
- }
104
- if (json.nodes) {
105
- json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));
106
- }
107
- if (json.skins) {
108
- json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));
109
- }
110
- if (json.scenes) {
111
- json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));
112
- }
113
- if (json.scene !== undefined) {
114
- json.scene = json.scenes[this.json.scene];
115
- }
88
+
89
+ if (json.samplers) {
90
+ json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
116
91
  }
117
- getScene(index) {
118
- return this._get('scenes', index);
92
+
93
+ if (json.textures) {
94
+ json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));
119
95
  }
120
- getNode(index) {
121
- return this._get('nodes', index);
96
+
97
+ if (json.accessors) {
98
+ json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
122
99
  }
123
- getSkin(index) {
124
- return this._get('skins', index);
100
+
101
+ if (json.materials) {
102
+ json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));
125
103
  }
126
- getMesh(index) {
127
- return this._get('meshes', index);
104
+
105
+ if (json.meshes) {
106
+ json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
128
107
  }
129
- getMaterial(index) {
130
- return this._get('materials', index);
108
+
109
+ if (json.nodes) {
110
+ json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));
131
111
  }
132
- getAccessor(index) {
133
- return this._get('accessors', index);
112
+
113
+ if (json.skins) {
114
+ json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));
134
115
  }
135
- getCamera(index) {
136
- return null; // TODO: fix this
116
+
117
+ if (json.scenes) {
118
+ json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));
137
119
  }
138
- getTexture(index) {
139
- return this._get('textures', index);
120
+
121
+ if (json.scene !== undefined) {
122
+ json.scene = json.scenes[this.json.scene];
140
123
  }
141
- getSampler(index) {
142
- return this._get('samplers', index);
124
+ }
125
+
126
+ getScene(index) {
127
+ return this._get('scenes', index);
128
+ }
129
+
130
+ getNode(index) {
131
+ return this._get('nodes', index);
132
+ }
133
+
134
+ getSkin(index) {
135
+ return this._get('skins', index);
136
+ }
137
+
138
+ getMesh(index) {
139
+ return this._get('meshes', index);
140
+ }
141
+
142
+ getMaterial(index) {
143
+ return this._get('materials', index);
144
+ }
145
+
146
+ getAccessor(index) {
147
+ return this._get('accessors', index);
148
+ }
149
+
150
+ getCamera(index) {
151
+ return null;
152
+ }
153
+
154
+ getTexture(index) {
155
+ return this._get('textures', index);
156
+ }
157
+
158
+ getSampler(index) {
159
+ return this._get('samplers', index);
160
+ }
161
+
162
+ getImage(index) {
163
+ return this._get('images', index);
164
+ }
165
+
166
+ getBufferView(index) {
167
+ return this._get('bufferViews', index);
168
+ }
169
+
170
+ getBuffer(index) {
171
+ return this._get('buffers', index);
172
+ }
173
+
174
+ _get(array, index) {
175
+ if (typeof index === 'object') {
176
+ return index;
143
177
  }
144
- getImage(index) {
145
- return this._get('images', index);
178
+
179
+ const object = this.json[array] && this.json[array][index];
180
+
181
+ if (!object) {
182
+ console.warn("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
146
183
  }
147
- getBufferView(index) {
148
- return this._get('bufferViews', index);
184
+
185
+ return object;
186
+ }
187
+
188
+ _resolveScene(scene, index) {
189
+ scene.id = scene.id || "scene-".concat(index);
190
+ scene.nodes = (scene.nodes || []).map(node => this.getNode(node));
191
+ return scene;
192
+ }
193
+
194
+ _resolveNode(node, index) {
195
+ node.id = node.id || "node-".concat(index);
196
+
197
+ if (node.children) {
198
+ node.children = node.children.map(child => this.getNode(child));
149
199
  }
150
- getBuffer(index) {
151
- return this._get('buffers', index);
200
+
201
+ if (node.mesh !== undefined) {
202
+ node.mesh = this.getMesh(node.mesh);
203
+ } else if (node.meshes !== undefined && node.meshes.length) {
204
+ node.mesh = node.meshes.reduce((accum, meshIndex) => {
205
+ const mesh = this.getMesh(meshIndex);
206
+ accum.id = mesh.id;
207
+ accum.primitives = accum.primitives.concat(mesh.primitives);
208
+ return accum;
209
+ }, {
210
+ primitives: []
211
+ });
152
212
  }
153
- _get(array, index) {
154
- // check if already resolved
155
- if (typeof index === 'object') {
156
- return index;
157
- }
158
- const object = this.json[array] && this.json[array][index];
159
- if (!object) {
160
- console.warn(`glTF file error: Could not find ${array}[${index}]`); // eslint-disable-line
161
- }
162
- return object;
213
+
214
+ if (node.camera !== undefined) {
215
+ node.camera = this.getCamera(node.camera);
163
216
  }
164
- // PARSING HELPERS
165
- _resolveScene(scene, index) {
166
- // scene = {...scene};
167
- scene.id = scene.id || `scene-${index}`;
168
- scene.nodes = (scene.nodes || []).map((node) => this.getNode(node));
169
- return scene;
217
+
218
+ if (node.skin !== undefined) {
219
+ node.skin = this.getSkin(node.skin);
170
220
  }
171
- _resolveNode(node, index) {
172
- // node = {...node};
173
- node.id = node.id || `node-${index}`;
174
- if (node.children) {
175
- node.children = node.children.map((child) => this.getNode(child));
176
- }
177
- if (node.mesh !== undefined) {
178
- node.mesh = this.getMesh(node.mesh);
179
- }
180
- else if (node.meshes !== undefined && node.meshes.length) {
181
- node.mesh = node.meshes.reduce((accum, meshIndex) => {
182
- const mesh = this.getMesh(meshIndex);
183
- accum.id = mesh.id;
184
- accum.primitives = accum.primitives.concat(mesh.primitives);
185
- return accum;
186
- }, { primitives: [] });
187
- }
188
- if (node.camera !== undefined) {
189
- node.camera = this.getCamera(node.camera);
190
- }
191
- if (node.skin !== undefined) {
192
- node.skin = this.getSkin(node.skin);
193
- }
194
- return node;
221
+
222
+ return node;
223
+ }
224
+
225
+ _resolveSkin(skin, index) {
226
+ skin.id = skin.id || "skin-".concat(index);
227
+ skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
228
+ return skin;
229
+ }
230
+
231
+ _resolveMesh(mesh, index) {
232
+ mesh.id = mesh.id || "mesh-".concat(index);
233
+
234
+ if (mesh.primitives) {
235
+ mesh.primitives = mesh.primitives.map(primitive => {
236
+ primitive = { ...primitive
237
+ };
238
+ const attributes = primitive.attributes;
239
+ primitive.attributes = {};
240
+
241
+ for (const attribute in attributes) {
242
+ primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
243
+ }
244
+
245
+ if (primitive.indices !== undefined) {
246
+ primitive.indices = this.getAccessor(primitive.indices);
247
+ }
248
+
249
+ if (primitive.material !== undefined) {
250
+ primitive.material = this.getMaterial(primitive.material);
251
+ }
252
+
253
+ return primitive;
254
+ });
195
255
  }
196
- _resolveSkin(skin, index) {
197
- // skin = {...skin};
198
- skin.id = skin.id || `skin-${index}`;
199
- skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
200
- return skin;
256
+
257
+ return mesh;
258
+ }
259
+
260
+ _resolveMaterial(material, index) {
261
+ material.id = material.id || "material-".concat(index);
262
+
263
+ if (material.normalTexture) {
264
+ material.normalTexture = { ...material.normalTexture
265
+ };
266
+ material.normalTexture.texture = this.getTexture(material.normalTexture.index);
201
267
  }
202
- _resolveMesh(mesh, index) {
203
- // mesh = {...mesh};
204
- mesh.id = mesh.id || `mesh-${index}`;
205
- if (mesh.primitives) {
206
- mesh.primitives = mesh.primitives.map((primitive) => {
207
- primitive = { ...primitive };
208
- const attributes = primitive.attributes;
209
- primitive.attributes = {};
210
- for (const attribute in attributes) {
211
- primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
212
- }
213
- if (primitive.indices !== undefined) {
214
- primitive.indices = this.getAccessor(primitive.indices);
215
- }
216
- if (primitive.material !== undefined) {
217
- primitive.material = this.getMaterial(primitive.material);
218
- }
219
- return primitive;
220
- });
221
- }
222
- return mesh;
268
+
269
+ if (material.occlusionTexture) {
270
+ material.occlustionTexture = { ...material.occlustionTexture
271
+ };
272
+ material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
223
273
  }
224
- _resolveMaterial(material, index) {
225
- // material = {...material};
226
- material.id = material.id || `material-${index}`;
227
- if (material.normalTexture) {
228
- material.normalTexture = { ...material.normalTexture };
229
- material.normalTexture.texture = this.getTexture(material.normalTexture.index);
230
- }
231
- if (material.occlusionTexture) {
232
- material.occlustionTexture = { ...material.occlustionTexture };
233
- material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
234
- }
235
- if (material.emissiveTexture) {
236
- material.emmisiveTexture = { ...material.emmisiveTexture };
237
- material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
238
- }
239
- if (!material.emissiveFactor) {
240
- material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];
241
- }
242
- if (material.pbrMetallicRoughness) {
243
- material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness };
244
- const mr = material.pbrMetallicRoughness;
245
- if (mr.baseColorTexture) {
246
- mr.baseColorTexture = { ...mr.baseColorTexture };
247
- mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
248
- }
249
- if (mr.metallicRoughnessTexture) {
250
- mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture };
251
- mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
252
- }
253
- }
254
- return material;
274
+
275
+ if (material.emissiveTexture) {
276
+ material.emmisiveTexture = { ...material.emmisiveTexture
277
+ };
278
+ material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
255
279
  }
256
- _resolveAccessor(accessor, index) {
257
- // accessor = {...accessor};
258
- accessor.id = accessor.id || `accessor-${index}`;
259
- if (accessor.bufferView !== undefined) {
260
- // Draco encoded meshes don't have bufferView
261
- accessor.bufferView = this.getBufferView(accessor.bufferView);
262
- }
263
- // Look up enums
264
- accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);
265
- accessor.components = getSizeFromAccessorType(accessor.type);
266
- accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
267
- // Create TypedArray for the accessor
268
- // Note: The canonical way to instantiate is to ignore this array and create
269
- // WebGLBuffer's using the bufferViews.
270
- if (accessor.bufferView) {
271
- const buffer = accessor.bufferView.buffer;
272
- const { ArrayType, byteLength } = (0, gltf_utils_1.getAccessorArrayTypeAndLength)(accessor, accessor.bufferView);
273
- const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
274
- let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
275
- if (accessor.bufferView.byteStride) {
276
- cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
277
- }
278
- accessor.value = new ArrayType(cutBuffer);
279
- }
280
- return accessor;
280
+
281
+ if (!material.emissiveFactor) {
282
+ material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];
281
283
  }
282
- /**
283
- * Take values of particular accessor from interleaved buffer
284
- * various parts of the buffer
285
- * @param buffer
286
- * @param byteOffset
287
- * @param byteStride
288
- * @param bytesPerElement
289
- * @param count
290
- * @returns
291
- */
292
- _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
293
- const result = new Uint8Array(count * bytesPerElement);
294
- for (let i = 0; i < count; i++) {
295
- const elementOffset = byteOffset + i * byteStride;
296
- result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i * bytesPerElement);
297
- }
298
- return result.buffer;
284
+
285
+ if (material.pbrMetallicRoughness) {
286
+ material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness
287
+ };
288
+ const mr = material.pbrMetallicRoughness;
289
+
290
+ if (mr.baseColorTexture) {
291
+ mr.baseColorTexture = { ...mr.baseColorTexture
292
+ };
293
+ mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
294
+ }
295
+
296
+ if (mr.metallicRoughnessTexture) {
297
+ mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture
298
+ };
299
+ mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
300
+ }
299
301
  }
300
- _resolveTexture(texture, index) {
301
- // texture = {...texture};
302
- texture.id = texture.id || `texture-${index}`;
303
- texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
304
- texture.source = this.getImage(texture.source);
305
- return texture;
302
+
303
+ return material;
304
+ }
305
+
306
+ _resolveAccessor(accessor, index) {
307
+ accessor.id = accessor.id || "accessor-".concat(index);
308
+
309
+ if (accessor.bufferView !== undefined) {
310
+ accessor.bufferView = this.getBufferView(accessor.bufferView);
306
311
  }
307
- _resolveSampler(sampler, index) {
308
- // sampler = {...sampler};
309
- sampler.id = sampler.id || `sampler-${index}`;
310
- // Map textual parameters to GL parameter values
311
- sampler.parameters = {};
312
- for (const key in sampler) {
313
- const glEnum = this._enumSamplerParameter(key);
314
- if (glEnum !== undefined) {
315
- sampler.parameters[glEnum] = sampler[key];
316
- }
317
- }
318
- return sampler;
312
+
313
+ accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);
314
+ accessor.components = getSizeFromAccessorType(accessor.type);
315
+ accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
316
+
317
+ if (accessor.bufferView) {
318
+ const buffer = accessor.bufferView.buffer;
319
+ const {
320
+ ArrayType,
321
+ byteLength
322
+ } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
323
+ const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
324
+ let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
325
+
326
+ if (accessor.bufferView.byteStride) {
327
+ cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
328
+ }
329
+
330
+ accessor.value = new ArrayType(cutBuffer);
319
331
  }
320
- _enumSamplerParameter(key) {
321
- return SAMPLER_PARAMETER_GLTF_TO_GL[key];
332
+
333
+ return accessor;
334
+ }
335
+
336
+ _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
337
+ const result = new Uint8Array(count * bytesPerElement);
338
+
339
+ for (let i = 0; i < count; i++) {
340
+ const elementOffset = byteOffset + i * byteStride;
341
+ result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i * bytesPerElement);
322
342
  }
323
- _resolveImage(image, index) {
324
- // image = {...image};
325
- image.id = image.id || `image-${index}`;
326
- if (image.bufferView !== undefined) {
327
- image.bufferView = this.getBufferView(image.bufferView);
328
- }
329
- // Check if image has been preloaded by the GLTFLoader
330
- // If so, link it into the JSON and drop the URI
331
- const preloadedImage = this.images[index];
332
- if (preloadedImage) {
333
- image.image = preloadedImage;
334
- }
335
- return image;
343
+
344
+ return result.buffer;
345
+ }
346
+
347
+ _resolveTexture(texture, index) {
348
+ texture.id = texture.id || "texture-".concat(index);
349
+ texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
350
+ texture.source = this.getImage(texture.source);
351
+ return texture;
352
+ }
353
+
354
+ _resolveSampler(sampler, index) {
355
+ sampler.id = sampler.id || "sampler-".concat(index);
356
+ sampler.parameters = {};
357
+
358
+ for (const key in sampler) {
359
+ const glEnum = this._enumSamplerParameter(key);
360
+
361
+ if (glEnum !== undefined) {
362
+ sampler.parameters[glEnum] = sampler[key];
363
+ }
336
364
  }
337
- _resolveBufferView(bufferView, index) {
338
- // bufferView = {...bufferView};
339
- const bufferIndex = bufferView.buffer;
340
- const result = {
341
- id: `bufferView-${index}`,
342
- ...bufferView,
343
- buffer: this.buffers[bufferIndex]
344
- };
345
- // @ts-expect-error
346
- const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
347
- // @ts-expect-error
348
- let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
349
- if ('byteOffset' in bufferView) {
350
- byteOffset += bufferView.byteOffset;
351
- }
352
- result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
353
- return result;
365
+
366
+ return sampler;
367
+ }
368
+
369
+ _enumSamplerParameter(key) {
370
+ return SAMPLER_PARAMETER_GLTF_TO_GL[key];
371
+ }
372
+
373
+ _resolveImage(image, index) {
374
+ image.id = image.id || "image-".concat(index);
375
+
376
+ if (image.bufferView !== undefined) {
377
+ image.bufferView = this.getBufferView(image.bufferView);
354
378
  }
355
- _resolveCamera(camera, index) {
356
- camera.id = camera.id || `camera-${index}`;
357
- // TODO - create 4x4 matrices
358
- if (camera.perspective) {
359
- // camera.matrix = createPerspectiveMatrix(camera.perspective);
360
- }
361
- if (camera.orthographic) {
362
- // camera.matrix = createOrthographicMatrix(camera.orthographic);
363
- }
364
- return camera;
379
+
380
+ const preloadedImage = this.images[index];
381
+
382
+ if (preloadedImage) {
383
+ image.image = preloadedImage;
384
+ }
385
+
386
+ return image;
387
+ }
388
+
389
+ _resolveBufferView(bufferView, index) {
390
+ const bufferIndex = bufferView.buffer;
391
+ const result = {
392
+ id: "bufferView-".concat(index),
393
+ ...bufferView,
394
+ buffer: this.buffers[bufferIndex]
395
+ };
396
+ const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
397
+ let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
398
+
399
+ if ('byteOffset' in bufferView) {
400
+ byteOffset += bufferView.byteOffset;
365
401
  }
402
+
403
+ result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
404
+ return result;
405
+ }
406
+
407
+ _resolveCamera(camera, index) {
408
+ camera.id = camera.id || "camera-".concat(index);
409
+
410
+ if (camera.perspective) {}
411
+
412
+ if (camera.orthographic) {}
413
+
414
+ return camera;
415
+ }
416
+
366
417
  }
367
- function postProcessGLTF(gltf, options) {
368
- return new GLTFPostProcessor().postProcess(gltf, options);
418
+
419
+ export function postProcessGLTF(gltf, options) {
420
+ return new GLTFPostProcessor().postProcess(gltf, options);
369
421
  }
370
- exports.postProcessGLTF = postProcessGLTF;
422
+ //# sourceMappingURL=post-process-gltf.js.map