@loaders.gl/gltf 3.1.0-alpha.4 → 3.1.0-beta.3

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 (202) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +4518 -0
  4. package/dist/es5/bundle.js +1 -1
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/glb-loader.js +10 -33
  7. package/dist/es5/glb-loader.js.map +1 -1
  8. package/dist/es5/glb-writer.js +9 -8
  9. package/dist/es5/glb-writer.js.map +1 -1
  10. package/dist/es5/gltf-loader.js +14 -52
  11. package/dist/es5/gltf-loader.js.map +1 -1
  12. package/dist/es5/gltf-writer.js +10 -10
  13. package/dist/es5/gltf-writer.js.map +1 -1
  14. package/dist/es5/index.js +6 -6
  15. package/dist/es5/lib/api/gltf-extensions.js +18 -106
  16. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  17. package/dist/es5/lib/api/gltf-scenegraph.js +447 -541
  18. package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
  19. package/dist/es5/lib/api/normalize-gltf-v1.js +154 -279
  20. package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
  21. package/dist/es5/lib/api/post-process-gltf.js +301 -349
  22. package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
  23. package/dist/es5/lib/encoders/encode-glb.js +19 -22
  24. package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
  25. package/dist/es5/lib/encoders/encode-gltf.js +3 -5
  26. package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
  27. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +39 -104
  28. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  29. package/dist/es5/lib/extensions/EXT_texture_webp.js +12 -26
  30. package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
  31. package/dist/es5/lib/extensions/KHR_binary_gltf.js +12 -26
  32. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
  33. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +76 -261
  34. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  35. package/dist/es5/lib/extensions/KHR_texture_basisu.js +12 -26
  36. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
  37. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +40 -104
  38. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
  39. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +24 -69
  40. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
  41. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +34 -90
  42. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
  43. package/dist/es5/lib/gltf-utils/get-typed-array.js +6 -6
  44. package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -1
  45. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +19 -21
  46. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
  47. package/dist/es5/lib/gltf-utils/gltf-constants.js +7 -7
  48. package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
  49. package/dist/es5/lib/gltf-utils/gltf-utils.js +16 -16
  50. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  51. package/dist/es5/lib/gltf-utils/resolve-url.js +2 -2
  52. package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
  53. package/dist/es5/lib/parsers/parse-glb.js +34 -38
  54. package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
  55. package/dist/es5/lib/parsers/parse-gltf.js +107 -249
  56. package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
  57. package/dist/es5/lib/utils/assert.js.map +1 -1
  58. package/dist/es5/lib/utils/version.js +1 -1
  59. package/dist/es5/lib/utils/version.js.map +1 -1
  60. package/dist/es5/meshopt/meshopt-decoder.js +46 -197
  61. package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
  62. package/dist/es5/webp/webp.js +16 -84
  63. package/dist/es5/webp/webp.js.map +1 -1
  64. package/dist/esm/lib/api/gltf-scenegraph.js +1 -1
  65. package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
  66. package/dist/esm/lib/api/normalize-gltf-v1.js +9 -6
  67. package/dist/esm/lib/api/normalize-gltf-v1.js.map +1 -1
  68. package/dist/esm/lib/api/post-process-gltf.js +42 -15
  69. package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
  70. package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
  71. package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
  72. package/dist/esm/lib/extensions/EXT_meshopt_compression.js +1 -1
  73. package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  74. package/dist/esm/lib/extensions/EXT_texture_webp.js +1 -1
  75. package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
  76. package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
  77. package/dist/esm/lib/gltf-utils/resolve-url.js +1 -1
  78. package/dist/esm/lib/gltf-utils/resolve-url.js.map +1 -1
  79. package/dist/esm/lib/parsers/parse-glb.js +2 -6
  80. package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
  81. package/dist/esm/lib/parsers/parse-gltf.js +19 -2
  82. package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
  83. package/dist/esm/lib/utils/assert.js.map +1 -1
  84. package/dist/esm/lib/utils/version.js +1 -1
  85. package/dist/esm/lib/utils/version.js.map +1 -1
  86. package/dist/esm/meshopt/meshopt-decoder.js +1 -1
  87. package/dist/esm/meshopt/meshopt-decoder.js.map +1 -1
  88. package/dist/esm/webp/webp.js +1 -1
  89. package/dist/esm/webp/webp.js.map +1 -1
  90. package/dist/glb-loader.d.ts +13 -0
  91. package/dist/glb-loader.d.ts.map +1 -0
  92. package/dist/glb-loader.js +39 -0
  93. package/dist/glb-writer.d.ts +22 -0
  94. package/dist/glb-writer.d.ts.map +1 -0
  95. package/dist/glb-writer.js +37 -0
  96. package/dist/gltf-loader.d.ts +18 -0
  97. package/dist/gltf-loader.d.ts.map +1 -0
  98. package/dist/gltf-loader.js +50 -0
  99. package/dist/gltf-writer.d.ts +25 -0
  100. package/dist/gltf-writer.d.ts.map +1 -0
  101. package/dist/gltf-writer.js +32 -0
  102. package/dist/index.d.ts +11 -0
  103. package/dist/index.d.ts.map +1 -0
  104. package/dist/index.js +21 -0
  105. package/dist/lib/api/gltf-extensions.d.ts +26 -0
  106. package/dist/lib/api/gltf-extensions.d.ts.map +1 -0
  107. package/dist/lib/api/gltf-extensions.js +75 -0
  108. package/dist/lib/api/gltf-scenegraph.d.ts +183 -0
  109. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -0
  110. package/dist/lib/api/gltf-scenegraph.js +553 -0
  111. package/dist/lib/api/normalize-gltf-v1.d.ts +2 -0
  112. package/dist/lib/api/normalize-gltf-v1.d.ts.map +1 -0
  113. package/dist/lib/api/normalize-gltf-v1.js +295 -0
  114. package/dist/lib/api/post-process-gltf.d.ts +2 -0
  115. package/dist/lib/api/post-process-gltf.d.ts.map +1 -0
  116. package/dist/lib/api/post-process-gltf.js +367 -0
  117. package/dist/lib/encoders/encode-glb.d.ts +2 -0
  118. package/dist/lib/encoders/encode-glb.d.ts.map +1 -0
  119. package/dist/lib/encoders/encode-glb.js +61 -0
  120. package/dist/lib/encoders/encode-gltf.d.ts +2 -0
  121. package/dist/lib/encoders/encode-gltf.d.ts.map +1 -0
  122. package/dist/lib/encoders/encode-gltf.js +27 -0
  123. package/dist/lib/extensions/EXT_meshopt_compression.d.ts +10 -0
  124. package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -0
  125. package/dist/lib/extensions/EXT_meshopt_compression.js +54 -0
  126. package/dist/lib/extensions/EXT_texture_webp.d.ts +12 -0
  127. package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -0
  128. package/dist/lib/extensions/EXT_texture_webp.js +38 -0
  129. package/dist/lib/extensions/KHR_binary_gltf.d.ts +7 -0
  130. package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -0
  131. package/dist/lib/extensions/KHR_binary_gltf.js +42 -0
  132. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +13 -0
  133. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -0
  134. package/dist/lib/extensions/KHR_draco_mesh_compression.js +141 -0
  135. package/dist/lib/extensions/KHR_texture_basisu.d.ts +12 -0
  136. package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -0
  137. package/dist/lib/extensions/KHR_texture_basisu.js +31 -0
  138. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +7 -0
  139. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -0
  140. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +62 -0
  141. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +7 -0
  142. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -0
  143. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +47 -0
  144. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +7 -0
  145. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -0
  146. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +81 -0
  147. package/dist/lib/gltf-utils/get-typed-array.d.ts +3 -0
  148. package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -0
  149. package/dist/lib/gltf-utils/get-typed-array.js +41 -0
  150. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +6 -0
  151. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -0
  152. package/dist/lib/gltf-utils/gltf-attribute-utils.js +73 -0
  153. package/dist/lib/gltf-utils/gltf-constants.d.ts +4 -0
  154. package/dist/lib/gltf-utils/gltf-constants.d.ts.map +1 -0
  155. package/dist/lib/gltf-utils/gltf-constants.js +43 -0
  156. package/dist/lib/gltf-utils/gltf-utils.d.ts +8 -0
  157. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -0
  158. package/dist/lib/gltf-utils/gltf-utils.js +63 -0
  159. package/dist/lib/gltf-utils/resolve-url.d.ts +2 -0
  160. package/dist/lib/gltf-utils/resolve-url.d.ts.map +1 -0
  161. package/dist/lib/gltf-utils/resolve-url.js +18 -0
  162. package/dist/lib/parsers/parse-glb.d.ts +8 -0
  163. package/dist/lib/parsers/parse-glb.d.ts.map +1 -0
  164. package/dist/lib/parsers/parse-glb.js +141 -0
  165. package/dist/lib/parsers/parse-gltf.d.ts +14 -0
  166. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -0
  167. package/dist/lib/parsers/parse-gltf.js +189 -0
  168. package/dist/lib/types/glb-types.d.ts +17 -0
  169. package/dist/lib/types/glb-types.d.ts.map +1 -0
  170. package/dist/lib/types/glb-types.js +2 -0
  171. package/dist/lib/types/gltf-json-schema.d.ts +720 -0
  172. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -0
  173. package/dist/lib/types/gltf-json-schema.js +4 -0
  174. package/dist/lib/types/gltf-postprocessed-schema.d.ts +685 -0
  175. package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -0
  176. package/dist/lib/types/gltf-postprocessed-schema.js +4 -0
  177. package/dist/lib/types/gltf-types.d.ts +10 -0
  178. package/dist/lib/types/gltf-types.d.ts.map +1 -0
  179. package/dist/lib/types/gltf-types.js +3 -0
  180. package/dist/lib/utils/assert.d.ts +2 -0
  181. package/dist/lib/utils/assert.d.ts.map +1 -0
  182. package/dist/lib/utils/assert.js +12 -0
  183. package/dist/lib/utils/version.d.ts +2 -0
  184. package/dist/lib/utils/version.d.ts.map +1 -0
  185. package/dist/lib/utils/version.js +7 -0
  186. package/dist/meshopt/meshopt-decoder.d.ts +6 -0
  187. package/dist/meshopt/meshopt-decoder.d.ts.map +1 -0
  188. package/dist/meshopt/meshopt-decoder.js +118 -0
  189. package/dist/webp/webp.d.ts +7 -0
  190. package/dist/webp/webp.d.ts.map +1 -0
  191. package/dist/webp/webp.js +38 -0
  192. package/package.json +11 -8
  193. package/src/lib/api/{normalize-gltf-v1.js → normalize-gltf-v1.ts} +18 -16
  194. package/src/lib/api/{post-process-gltf.js → post-process-gltf.ts} +41 -3
  195. package/src/lib/encoders/{encode-glb.js → encode-glb.ts} +0 -0
  196. package/src/lib/encoders/{encode-gltf.js → encode-gltf.ts} +0 -0
  197. package/src/lib/extensions/KHR_texture_basisu.ts +2 -2
  198. package/src/lib/parsers/parse-gltf.ts +17 -1
  199. package/src/lib/utils/{assert.js → assert.ts} +1 -1
  200. package/src/lib/utils/{version.js → version.ts} +0 -0
  201. package/dist/dist.min.js +0 -2
  202. package/dist/dist.min.js.map +0 -1
@@ -7,25 +7,13 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.postProcessGLTF = postProcessGLTF;
9
9
 
10
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
-
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
11
 
18
12
  var _assert = require("../utils/assert");
19
13
 
20
14
  var _gltfUtils = require("../gltf-utils/gltf-utils");
21
15
 
22
- var _DEFAULT_SAMPLER;
23
-
24
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
25
-
26
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
27
-
28
- var COMPONENTS = {
16
+ const COMPONENTS = {
29
17
  SCALAR: 1,
30
18
  VEC2: 2,
31
19
  VEC3: 3,
@@ -34,7 +22,7 @@ var COMPONENTS = {
34
22
  MAT3: 9,
35
23
  MAT4: 16
36
24
  };
37
- var BYTES = {
25
+ const BYTES = {
38
26
  5120: 1,
39
27
  5121: 1,
40
28
  5122: 2,
@@ -42,7 +30,7 @@ var BYTES = {
42
30
  5125: 4,
43
31
  5126: 4
44
32
  };
45
- var GL_SAMPLER = {
33
+ const GL_SAMPLER = {
46
34
  TEXTURE_MAG_FILTER: 0x2800,
47
35
  TEXTURE_MIN_FILTER: 0x2801,
48
36
  TEXTURE_WRAP_S: 0x2802,
@@ -51,13 +39,18 @@ var GL_SAMPLER = {
51
39
  LINEAR: 0x2601,
52
40
  NEAREST_MIPMAP_LINEAR: 0x2702
53
41
  };
54
- var SAMPLER_PARAMETER_GLTF_TO_GL = {
42
+ const SAMPLER_PARAMETER_GLTF_TO_GL = {
55
43
  magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
56
44
  minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
57
45
  wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
58
46
  wrapT: GL_SAMPLER.TEXTURE_WRAP_T
59
47
  };
60
- var DEFAULT_SAMPLER = (_DEFAULT_SAMPLER = {}, (0, _defineProperty2.default)(_DEFAULT_SAMPLER, GL_SAMPLER.TEXTURE_MAG_FILTER, GL_SAMPLER.LINEAR), (0, _defineProperty2.default)(_DEFAULT_SAMPLER, GL_SAMPLER.TEXTURE_MIN_FILTER, GL_SAMPLER.NEAREST_MIPMAP_LINEAR), (0, _defineProperty2.default)(_DEFAULT_SAMPLER, GL_SAMPLER.TEXTURE_WRAP_S, GL_SAMPLER.REPEAT), (0, _defineProperty2.default)(_DEFAULT_SAMPLER, GL_SAMPLER.TEXTURE_WRAP_, GL_SAMPLER.REPEAT), _DEFAULT_SAMPLER);
48
+ const DEFAULT_SAMPLER = {
49
+ [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
50
+ [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
51
+ [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
52
+ [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
53
+ };
61
54
 
62
55
  function getBytesFromComponentType(componentType) {
63
56
  return BYTES[componentType];
@@ -67,408 +60,367 @@ function getSizeFromAccessorType(type) {
67
60
  return COMPONENTS[type];
68
61
  }
69
62
 
70
- var GLTFPostProcessor = function () {
71
- function GLTFPostProcessor() {
72
- (0, _classCallCheck2.default)(this, GLTFPostProcessor);
63
+ class GLTFPostProcessor {
64
+ constructor() {
65
+ (0, _defineProperty2.default)(this, "baseUri", '');
66
+ (0, _defineProperty2.default)(this, "json", {});
67
+ (0, _defineProperty2.default)(this, "buffers", []);
68
+ (0, _defineProperty2.default)(this, "images", []);
69
+ }
70
+
71
+ postProcess(gltf, options = {}) {
72
+ const {
73
+ json,
74
+ buffers = [],
75
+ images = [],
76
+ baseUri = ''
77
+ } = gltf;
78
+ (0, _assert.assert)(json);
79
+ this.baseUri = baseUri;
80
+ this.json = json;
81
+ this.buffers = buffers;
82
+ this.images = images;
83
+
84
+ this._resolveTree(this.json, options);
85
+
86
+ return this.json;
73
87
  }
74
88
 
75
- (0, _createClass2.default)(GLTFPostProcessor, [{
76
- key: "postProcess",
77
- value: function postProcess(gltf) {
78
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
79
- var json = gltf.json,
80
- _gltf$buffers = gltf.buffers,
81
- buffers = _gltf$buffers === void 0 ? [] : _gltf$buffers,
82
- _gltf$images = gltf.images,
83
- images = _gltf$images === void 0 ? [] : _gltf$images,
84
- _gltf$baseUri = gltf.baseUri,
85
- baseUri = _gltf$baseUri === void 0 ? '' : _gltf$baseUri;
86
- (0, _assert.assert)(json);
87
- this.baseUri = baseUri;
88
- this.json = json;
89
- this.buffers = buffers;
90
- this.images = images;
91
-
92
- this._resolveTree(this.json, options);
93
-
94
- return this.json;
89
+ _resolveTree(json, options = {}) {
90
+ if (json.bufferViews) {
91
+ json.bufferViews = json.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));
95
92
  }
96
- }, {
97
- key: "_resolveTree",
98
- value: function _resolveTree(json) {
99
- var _this = this;
100
93
 
101
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
94
+ if (json.images) {
95
+ json.images = json.images.map((image, i) => this._resolveImage(image, i));
96
+ }
102
97
 
103
- if (json.bufferViews) {
104
- json.bufferViews = json.bufferViews.map(function (bufView, i) {
105
- return _this._resolveBufferView(bufView, i);
106
- });
107
- }
98
+ if (json.samplers) {
99
+ json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
100
+ }
108
101
 
109
- if (json.images) {
110
- json.images = json.images.map(function (image, i) {
111
- return _this._resolveImage(image, i);
112
- });
113
- }
102
+ if (json.textures) {
103
+ json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));
104
+ }
114
105
 
115
- if (json.samplers) {
116
- json.samplers = json.samplers.map(function (sampler, i) {
117
- return _this._resolveSampler(sampler, i);
118
- });
119
- }
106
+ if (json.accessors) {
107
+ json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
108
+ }
120
109
 
121
- if (json.textures) {
122
- json.textures = json.textures.map(function (texture, i) {
123
- return _this._resolveTexture(texture, i);
124
- });
125
- }
110
+ if (json.materials) {
111
+ json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));
112
+ }
126
113
 
127
- if (json.accessors) {
128
- json.accessors = json.accessors.map(function (accessor, i) {
129
- return _this._resolveAccessor(accessor, i);
130
- });
131
- }
114
+ if (json.meshes) {
115
+ json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
116
+ }
132
117
 
133
- if (json.materials) {
134
- json.materials = json.materials.map(function (material, i) {
135
- return _this._resolveMaterial(material, i);
136
- });
137
- }
118
+ if (json.nodes) {
119
+ json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));
120
+ }
138
121
 
139
- if (json.meshes) {
140
- json.meshes = json.meshes.map(function (mesh, i) {
141
- return _this._resolveMesh(mesh, i);
142
- });
143
- }
122
+ if (json.skins) {
123
+ json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));
124
+ }
144
125
 
145
- if (json.nodes) {
146
- json.nodes = json.nodes.map(function (node, i) {
147
- return _this._resolveNode(node, i);
148
- });
149
- }
126
+ if (json.scenes) {
127
+ json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));
128
+ }
150
129
 
151
- if (json.skins) {
152
- json.skins = json.skins.map(function (skin, i) {
153
- return _this._resolveSkin(skin, i);
154
- });
155
- }
130
+ if (json.scene !== undefined) {
131
+ json.scene = json.scenes[this.json.scene];
132
+ }
133
+ }
156
134
 
157
- if (json.scenes) {
158
- json.scenes = json.scenes.map(function (scene, i) {
159
- return _this._resolveScene(scene, i);
160
- });
161
- }
135
+ getScene(index) {
136
+ return this._get('scenes', index);
137
+ }
162
138
 
163
- if (json.scene !== undefined) {
164
- json.scene = json.scenes[this.json.scene];
165
- }
166
- }
167
- }, {
168
- key: "getScene",
169
- value: function getScene(index) {
170
- return this._get('scenes', index);
171
- }
172
- }, {
173
- key: "getNode",
174
- value: function getNode(index) {
175
- return this._get('nodes', index);
176
- }
177
- }, {
178
- key: "getSkin",
179
- value: function getSkin(index) {
180
- return this._get('skins', index);
181
- }
182
- }, {
183
- key: "getMesh",
184
- value: function getMesh(index) {
185
- return this._get('meshes', index);
186
- }
187
- }, {
188
- key: "getMaterial",
189
- value: function getMaterial(index) {
190
- return this._get('materials', index);
191
- }
192
- }, {
193
- key: "getAccessor",
194
- value: function getAccessor(index) {
195
- return this._get('accessors', index);
196
- }
197
- }, {
198
- key: "getCamera",
199
- value: function getCamera(index) {
200
- return null;
201
- }
202
- }, {
203
- key: "getTexture",
204
- value: function getTexture(index) {
205
- return this._get('textures', index);
206
- }
207
- }, {
208
- key: "getSampler",
209
- value: function getSampler(index) {
210
- return this._get('samplers', index);
211
- }
212
- }, {
213
- key: "getImage",
214
- value: function getImage(index) {
215
- return this._get('images', index);
216
- }
217
- }, {
218
- key: "getBufferView",
219
- value: function getBufferView(index) {
220
- return this._get('bufferViews', index);
221
- }
222
- }, {
223
- key: "getBuffer",
224
- value: function getBuffer(index) {
225
- return this._get('buffers', index);
226
- }
227
- }, {
228
- key: "_get",
229
- value: function _get(array, index) {
230
- if ((0, _typeof2.default)(index) === 'object') {
231
- return index;
232
- }
139
+ getNode(index) {
140
+ return this._get('nodes', index);
141
+ }
233
142
 
234
- var object = this.json[array] && this.json[array][index];
143
+ getSkin(index) {
144
+ return this._get('skins', index);
145
+ }
235
146
 
236
- if (!object) {
237
- console.warn("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
238
- }
147
+ getMesh(index) {
148
+ return this._get('meshes', index);
149
+ }
239
150
 
240
- return object;
241
- }
242
- }, {
243
- key: "_resolveScene",
244
- value: function _resolveScene(scene, index) {
245
- var _this2 = this;
246
-
247
- scene.id = scene.id || "scene-".concat(index);
248
- scene.nodes = (scene.nodes || []).map(function (node) {
249
- return _this2.getNode(node);
250
- });
251
- return scene;
252
- }
253
- }, {
254
- key: "_resolveNode",
255
- value: function _resolveNode(node, index) {
256
- var _this3 = this;
151
+ getMaterial(index) {
152
+ return this._get('materials', index);
153
+ }
257
154
 
258
- node.id = node.id || "node-".concat(index);
155
+ getAccessor(index) {
156
+ return this._get('accessors', index);
157
+ }
259
158
 
260
- if (node.children) {
261
- node.children = node.children.map(function (child) {
262
- return _this3.getNode(child);
263
- });
264
- }
159
+ getCamera(index) {
160
+ return null;
161
+ }
265
162
 
266
- if (node.mesh !== undefined) {
267
- node.mesh = this.getMesh(node.mesh);
268
- } else if (node.meshes !== undefined && node.meshes.length) {
269
- node.mesh = node.meshes.reduce(function (accum, meshIndex) {
270
- var mesh = _this3.getMesh(meshIndex);
271
-
272
- accum.id = mesh.id;
273
- accum.primitives = accum.primitives.concat(mesh.primitives);
274
- return accum;
275
- }, {
276
- primitives: []
277
- });
278
- }
163
+ getTexture(index) {
164
+ return this._get('textures', index);
165
+ }
279
166
 
280
- if (node.camera !== undefined) {
281
- node.camera = this.getCamera(node.camera);
282
- }
167
+ getSampler(index) {
168
+ return this._get('samplers', index);
169
+ }
283
170
 
284
- if (node.skin !== undefined) {
285
- node.skin = this.getSkin(node.skin);
286
- }
171
+ getImage(index) {
172
+ return this._get('images', index);
173
+ }
174
+
175
+ getBufferView(index) {
176
+ return this._get('bufferViews', index);
177
+ }
287
178
 
288
- return node;
179
+ getBuffer(index) {
180
+ return this._get('buffers', index);
181
+ }
182
+
183
+ _get(array, index) {
184
+ if (typeof index === 'object') {
185
+ return index;
289
186
  }
290
- }, {
291
- key: "_resolveSkin",
292
- value: function _resolveSkin(skin, index) {
293
- skin.id = skin.id || "skin-".concat(index);
294
- skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
295
- return skin;
187
+
188
+ const object = this.json[array] && this.json[array][index];
189
+
190
+ if (!object) {
191
+ console.warn("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
296
192
  }
297
- }, {
298
- key: "_resolveMesh",
299
- value: function _resolveMesh(mesh, index) {
300
- var _this4 = this;
301
193
 
302
- mesh.id = mesh.id || "mesh-".concat(index);
194
+ return object;
195
+ }
303
196
 
304
- if (mesh.primitives) {
305
- mesh.primitives = mesh.primitives.map(function (primitive) {
306
- primitive = _objectSpread({}, primitive);
307
- var attributes = primitive.attributes;
308
- primitive.attributes = {};
197
+ _resolveScene(scene, index) {
198
+ scene.id = scene.id || "scene-".concat(index);
199
+ scene.nodes = (scene.nodes || []).map(node => this.getNode(node));
200
+ return scene;
201
+ }
309
202
 
310
- for (var attribute in attributes) {
311
- primitive.attributes[attribute] = _this4.getAccessor(attributes[attribute]);
312
- }
203
+ _resolveNode(node, index) {
204
+ node.id = node.id || "node-".concat(index);
313
205
 
314
- if (primitive.indices !== undefined) {
315
- primitive.indices = _this4.getAccessor(primitive.indices);
316
- }
206
+ if (node.children) {
207
+ node.children = node.children.map(child => this.getNode(child));
208
+ }
317
209
 
318
- if (primitive.material !== undefined) {
319
- primitive.material = _this4.getMaterial(primitive.material);
320
- }
210
+ if (node.mesh !== undefined) {
211
+ node.mesh = this.getMesh(node.mesh);
212
+ } else if (node.meshes !== undefined && node.meshes.length) {
213
+ node.mesh = node.meshes.reduce((accum, meshIndex) => {
214
+ const mesh = this.getMesh(meshIndex);
215
+ accum.id = mesh.id;
216
+ accum.primitives = accum.primitives.concat(mesh.primitives);
217
+ return accum;
218
+ }, {
219
+ primitives: []
220
+ });
221
+ }
321
222
 
322
- return primitive;
323
- });
324
- }
223
+ if (node.camera !== undefined) {
224
+ node.camera = this.getCamera(node.camera);
225
+ }
325
226
 
326
- return mesh;
227
+ if (node.skin !== undefined) {
228
+ node.skin = this.getSkin(node.skin);
327
229
  }
328
- }, {
329
- key: "_resolveMaterial",
330
- value: function _resolveMaterial(material, index) {
331
- material.id = material.id || "material-".concat(index);
332
-
333
- if (material.normalTexture) {
334
- material.normalTexture = _objectSpread({}, material.normalTexture);
335
- material.normalTexture.texture = this.getTexture(material.normalTexture.index);
336
- }
337
230
 
338
- if (material.occlusionTexture) {
339
- material.occlustionTexture = _objectSpread({}, material.occlustionTexture);
340
- material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
341
- }
231
+ return node;
232
+ }
342
233
 
343
- if (material.emissiveTexture) {
344
- material.emmisiveTexture = _objectSpread({}, material.emmisiveTexture);
345
- material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
346
- }
234
+ _resolveSkin(skin, index) {
235
+ skin.id = skin.id || "skin-".concat(index);
236
+ skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
237
+ return skin;
238
+ }
347
239
 
348
- if (!material.emissiveFactor) {
349
- material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];
350
- }
240
+ _resolveMesh(mesh, index) {
241
+ mesh.id = mesh.id || "mesh-".concat(index);
351
242
 
352
- if (material.pbrMetallicRoughness) {
353
- material.pbrMetallicRoughness = _objectSpread({}, material.pbrMetallicRoughness);
354
- var mr = material.pbrMetallicRoughness;
243
+ if (mesh.primitives) {
244
+ mesh.primitives = mesh.primitives.map(primitive => {
245
+ primitive = { ...primitive
246
+ };
247
+ const attributes = primitive.attributes;
248
+ primitive.attributes = {};
355
249
 
356
- if (mr.baseColorTexture) {
357
- mr.baseColorTexture = _objectSpread({}, mr.baseColorTexture);
358
- mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
250
+ for (const attribute in attributes) {
251
+ primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
359
252
  }
360
253
 
361
- if (mr.metallicRoughnessTexture) {
362
- mr.metallicRoughnessTexture = _objectSpread({}, mr.metallicRoughnessTexture);
363
- mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
254
+ if (primitive.indices !== undefined) {
255
+ primitive.indices = this.getAccessor(primitive.indices);
364
256
  }
365
- }
366
257
 
367
- return material;
368
- }
369
- }, {
370
- key: "_resolveAccessor",
371
- value: function _resolveAccessor(accessor, index) {
372
- accessor.id = accessor.id || "accessor-".concat(index);
258
+ if (primitive.material !== undefined) {
259
+ primitive.material = this.getMaterial(primitive.material);
260
+ }
373
261
 
374
- if (accessor.bufferView !== undefined) {
375
- accessor.bufferView = this.getBufferView(accessor.bufferView);
376
- }
262
+ return primitive;
263
+ });
264
+ }
377
265
 
378
- accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);
379
- accessor.components = getSizeFromAccessorType(accessor.type);
380
- accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
266
+ return mesh;
267
+ }
381
268
 
382
- if (accessor.bufferView) {
383
- var buffer = accessor.bufferView.buffer;
269
+ _resolveMaterial(material, index) {
270
+ material.id = material.id || "material-".concat(index);
384
271
 
385
- var _getAccessorArrayType = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, accessor.bufferView),
386
- ArrayType = _getAccessorArrayType.ArrayType,
387
- byteLength = _getAccessorArrayType.byteLength;
272
+ if (material.normalTexture) {
273
+ material.normalTexture = { ...material.normalTexture
274
+ };
275
+ material.normalTexture.texture = this.getTexture(material.normalTexture.index);
276
+ }
388
277
 
389
- var byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
390
- var cutBufffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
391
- accessor.value = new ArrayType(cutBufffer);
392
- }
278
+ if (material.occlusionTexture) {
279
+ material.occlustionTexture = { ...material.occlustionTexture
280
+ };
281
+ material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
282
+ }
393
283
 
394
- return accessor;
284
+ if (material.emissiveTexture) {
285
+ material.emmisiveTexture = { ...material.emmisiveTexture
286
+ };
287
+ material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
395
288
  }
396
- }, {
397
- key: "_resolveTexture",
398
- value: function _resolveTexture(texture, index) {
399
- texture.id = texture.id || "texture-".concat(index);
400
- texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
401
- texture.source = this.getImage(texture.source);
402
- return texture;
289
+
290
+ if (!material.emissiveFactor) {
291
+ material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];
403
292
  }
404
- }, {
405
- key: "_resolveSampler",
406
- value: function _resolveSampler(sampler, index) {
407
- sampler.id = sampler.id || "sampler-".concat(index);
408
- sampler.parameters = {};
409
293
 
410
- for (var key in sampler) {
411
- var glEnum = this._enumSamplerParameter(key);
294
+ if (material.pbrMetallicRoughness) {
295
+ material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness
296
+ };
297
+ const mr = material.pbrMetallicRoughness;
412
298
 
413
- if (glEnum !== undefined) {
414
- sampler.parameters[glEnum] = sampler[key];
415
- }
299
+ if (mr.baseColorTexture) {
300
+ mr.baseColorTexture = { ...mr.baseColorTexture
301
+ };
302
+ mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
416
303
  }
417
304
 
418
- return sampler;
305
+ if (mr.metallicRoughnessTexture) {
306
+ mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture
307
+ };
308
+ mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
309
+ }
419
310
  }
420
- }, {
421
- key: "_enumSamplerParameter",
422
- value: function _enumSamplerParameter(key) {
423
- return SAMPLER_PARAMETER_GLTF_TO_GL[key];
311
+
312
+ return material;
313
+ }
314
+
315
+ _resolveAccessor(accessor, index) {
316
+ accessor.id = accessor.id || "accessor-".concat(index);
317
+
318
+ if (accessor.bufferView !== undefined) {
319
+ accessor.bufferView = this.getBufferView(accessor.bufferView);
424
320
  }
425
- }, {
426
- key: "_resolveImage",
427
- value: function _resolveImage(image, index) {
428
- image.id = image.id || "image-".concat(index);
429
321
 
430
- if (image.bufferView !== undefined) {
431
- image.bufferView = this.getBufferView(image.bufferView);
322
+ accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);
323
+ accessor.components = getSizeFromAccessorType(accessor.type);
324
+ accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
325
+
326
+ if (accessor.bufferView) {
327
+ const buffer = accessor.bufferView.buffer;
328
+ const {
329
+ ArrayType,
330
+ byteLength
331
+ } = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, accessor.bufferView);
332
+ const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
333
+ let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
334
+
335
+ if (accessor.bufferView.byteStride) {
336
+ cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
432
337
  }
433
338
 
434
- var preloadedImage = this.images[index];
339
+ accessor.value = new ArrayType(cutBuffer);
340
+ }
435
341
 
436
- if (preloadedImage) {
437
- image.image = preloadedImage;
438
- }
342
+ return accessor;
343
+ }
344
+
345
+ _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
346
+ const result = new Uint8Array(count * bytesPerElement);
439
347
 
440
- return image;
348
+ for (let i = 0; i < count; i++) {
349
+ const elementOffset = byteOffset + i * byteStride;
350
+ result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i * bytesPerElement);
441
351
  }
442
- }, {
443
- key: "_resolveBufferView",
444
- value: function _resolveBufferView(bufferView, index) {
445
- bufferView.id = bufferView.id || "bufferView-".concat(index);
446
- var bufferIndex = bufferView.buffer;
447
- bufferView.buffer = this.buffers[bufferIndex];
448
- var arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
449
- var byteOffset = this.buffers[bufferIndex].byteOffset || 0;
450
-
451
- if ('byteOffset' in bufferView) {
452
- byteOffset += bufferView.byteOffset;
352
+
353
+ return result.buffer;
354
+ }
355
+
356
+ _resolveTexture(texture, index) {
357
+ texture.id = texture.id || "texture-".concat(index);
358
+ texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
359
+ texture.source = this.getImage(texture.source);
360
+ return texture;
361
+ }
362
+
363
+ _resolveSampler(sampler, index) {
364
+ sampler.id = sampler.id || "sampler-".concat(index);
365
+ sampler.parameters = {};
366
+
367
+ for (const key in sampler) {
368
+ const glEnum = this._enumSamplerParameter(key);
369
+
370
+ if (glEnum !== undefined) {
371
+ sampler.parameters[glEnum] = sampler[key];
453
372
  }
373
+ }
374
+
375
+ return sampler;
376
+ }
454
377
 
455
- bufferView.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
456
- return bufferView;
378
+ _enumSamplerParameter(key) {
379
+ return SAMPLER_PARAMETER_GLTF_TO_GL[key];
380
+ }
381
+
382
+ _resolveImage(image, index) {
383
+ image.id = image.id || "image-".concat(index);
384
+
385
+ if (image.bufferView !== undefined) {
386
+ image.bufferView = this.getBufferView(image.bufferView);
387
+ }
388
+
389
+ const preloadedImage = this.images[index];
390
+
391
+ if (preloadedImage) {
392
+ image.image = preloadedImage;
457
393
  }
458
- }, {
459
- key: "_resolveCamera",
460
- value: function _resolveCamera(camera, index) {
461
- camera.id = camera.id || "camera-".concat(index);
462
394
 
463
- if (camera.perspective) {}
395
+ return image;
396
+ }
464
397
 
465
- if (camera.orthographic) {}
398
+ _resolveBufferView(bufferView, index) {
399
+ bufferView.id = bufferView.id || "bufferView-".concat(index);
400
+ const bufferIndex = bufferView.buffer;
401
+ bufferView.buffer = this.buffers[bufferIndex];
402
+ const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
403
+ let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
466
404
 
467
- return camera;
405
+ if ('byteOffset' in bufferView) {
406
+ byteOffset += bufferView.byteOffset;
468
407
  }
469
- }]);
470
- return GLTFPostProcessor;
471
- }();
408
+
409
+ bufferView.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
410
+ return bufferView;
411
+ }
412
+
413
+ _resolveCamera(camera, index) {
414
+ camera.id = camera.id || "camera-".concat(index);
415
+
416
+ if (camera.perspective) {}
417
+
418
+ if (camera.orthographic) {}
419
+
420
+ return camera;
421
+ }
422
+
423
+ }
472
424
 
473
425
  function postProcessGLTF(gltf, options) {
474
426
  return new GLTFPostProcessor().postProcess(gltf, options);