@loaders.gl/gltf 3.1.0-beta.7 → 3.1.0

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