@loaders.gl/gltf 3.4.13 → 3.4.15

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