@loaders.gl/gltf 3.4.14 → 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 (65) hide show
  1. package/dist/es5/bundle.js +1 -1
  2. package/dist/es5/bundle.js.map +1 -1
  3. package/dist/es5/glb-loader.js +10 -26
  4. package/dist/es5/glb-loader.js.map +1 -1
  5. package/dist/es5/glb-writer.js +9 -8
  6. package/dist/es5/glb-writer.js.map +1 -1
  7. package/dist/es5/gltf-loader.js +18 -40
  8. package/dist/es5/gltf-loader.js.map +1 -1
  9. package/dist/es5/gltf-writer.js +10 -9
  10. package/dist/es5/gltf-writer.js.map +1 -1
  11. package/dist/es5/index.js +7 -7
  12. package/dist/es5/lib/api/gltf-extensions.js +19 -82
  13. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  14. package/dist/es5/lib/api/gltf-scenegraph.js +395 -524
  15. package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
  16. package/dist/es5/lib/api/normalize-gltf-v1.js +141 -259
  17. package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
  18. package/dist/es5/lib/api/post-process-gltf.js +263 -337
  19. package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
  20. package/dist/es5/lib/encoders/encode-glb.js +20 -21
  21. package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
  22. package/dist/es5/lib/encoders/encode-gltf.js +3 -3
  23. package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
  24. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +34 -79
  25. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  26. package/dist/es5/lib/extensions/EXT_texture_webp.js +11 -21
  27. package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
  28. package/dist/es5/lib/extensions/KHR_binary_gltf.js +11 -21
  29. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
  30. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +76 -201
  31. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  32. package/dist/es5/lib/extensions/KHR_texture_basisu.js +11 -21
  33. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
  34. package/dist/es5/lib/extensions/KHR_texture_transform.js +75 -114
  35. package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
  36. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +31 -48
  37. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  38. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +37 -84
  39. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
  40. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +24 -57
  41. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
  42. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +33 -75
  43. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
  44. package/dist/es5/lib/gltf-utils/get-typed-array.js +6 -6
  45. package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -1
  46. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +19 -18
  47. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
  48. package/dist/es5/lib/gltf-utils/gltf-constants.js +7 -7
  49. package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
  50. package/dist/es5/lib/gltf-utils/gltf-utils.js +28 -31
  51. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  52. package/dist/es5/lib/gltf-utils/resolve-url.js +2 -2
  53. package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
  54. package/dist/es5/lib/parsers/parse-glb.js +35 -34
  55. package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
  56. package/dist/es5/lib/parsers/parse-gltf.js +108 -230
  57. package/dist/es5/lib/parsers/parse-gltf.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 +48 -162
  61. package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
  62. package/dist/es5/webp/webp.js +17 -69
  63. package/dist/es5/webp/webp.js.map +1 -1
  64. package/dist/esm/lib/utils/version.js +1 -1
  65. package/package.json +6 -6
@@ -5,34 +5,27 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
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 _images = require("@loaders.gl/images");
13
10
  var _loaderUtils = require("@loaders.gl/loader-utils");
14
11
  var _assert = require("../utils/assert");
15
12
  var _gltfUtils = require("../gltf-utils/gltf-utils");
16
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
17
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
19
- 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; }
20
- 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; }
21
- var DEFAULT_GLTF_JSON = {
13
+ const DEFAULT_GLTF_JSON = {
22
14
  asset: {
23
15
  version: '2.0',
24
16
  generator: 'loaders.gl'
25
17
  },
26
18
  buffers: []
27
19
  };
28
- var GLTFScenegraph = function () {
29
- function GLTFScenegraph(gltf) {
30
- (0, _classCallCheck2.default)(this, GLTFScenegraph);
20
+ class GLTFScenegraph {
21
+ constructor(gltf) {
31
22
  (0, _defineProperty2.default)(this, "gltf", void 0);
32
23
  (0, _defineProperty2.default)(this, "sourceBuffers", void 0);
33
24
  (0, _defineProperty2.default)(this, "byteLength", void 0);
34
25
  this.gltf = gltf || {
35
- json: _objectSpread({}, DEFAULT_GLTF_JSON),
26
+ json: {
27
+ ...DEFAULT_GLTF_JSON
28
+ },
36
29
  buffers: []
37
30
  };
38
31
  this.sourceBuffers = [];
@@ -42,537 +35,415 @@ var GLTFScenegraph = function () {
42
35
  this.sourceBuffers = [this.gltf.buffers[0]];
43
36
  }
44
37
  }
45
- (0, _createClass2.default)(GLTFScenegraph, [{
46
- key: "json",
47
- get: function get() {
48
- return this.gltf.json;
49
- }
50
- }, {
51
- key: "getApplicationData",
52
- value: function getApplicationData(key) {
53
- var data = this.json[key];
54
- return data;
55
- }
56
- }, {
57
- key: "getExtraData",
58
- value: function getExtraData(key) {
59
- var extras = this.json.extras || {};
60
- return extras[key];
61
- }
62
- }, {
63
- key: "getExtension",
64
- value: function getExtension(extensionName) {
65
- var isExtension = this.getUsedExtensions().find(function (name) {
66
- return name === extensionName;
67
- });
68
- var extensions = this.json.extensions || {};
69
- return isExtension ? extensions[extensionName] || true : null;
70
- }
71
- }, {
72
- key: "getRequiredExtension",
73
- value: function getRequiredExtension(extensionName) {
74
- var isRequired = this.getRequiredExtensions().find(function (name) {
75
- return name === extensionName;
76
- });
77
- return isRequired ? this.getExtension(extensionName) : null;
78
- }
79
- }, {
80
- key: "getRequiredExtensions",
81
- value: function getRequiredExtensions() {
82
- return this.json.extensionsRequired || [];
83
- }
84
- }, {
85
- key: "getUsedExtensions",
86
- value: function getUsedExtensions() {
87
- return this.json.extensionsUsed || [];
88
- }
89
- }, {
90
- key: "getRemovedExtensions",
91
- value: function getRemovedExtensions() {
92
- return this.json.extensionsRemoved || [];
93
- }
94
- }, {
95
- key: "getObjectExtension",
96
- value: function getObjectExtension(object, extensionName) {
97
- var extensions = object.extensions || {};
98
- return extensions[extensionName];
99
- }
100
- }, {
101
- key: "getScene",
102
- value: function getScene(index) {
103
- return this.getObject('scenes', index);
104
- }
105
- }, {
106
- key: "getNode",
107
- value: function getNode(index) {
108
- return this.getObject('nodes', index);
109
- }
110
- }, {
111
- key: "getSkin",
112
- value: function getSkin(index) {
113
- return this.getObject('skins', index);
114
- }
115
- }, {
116
- key: "getMesh",
117
- value: function getMesh(index) {
118
- return this.getObject('meshes', index);
119
- }
120
- }, {
121
- key: "getMaterial",
122
- value: function getMaterial(index) {
123
- return this.getObject('materials', index);
124
- }
125
- }, {
126
- key: "getAccessor",
127
- value: function getAccessor(index) {
128
- return this.getObject('accessors', index);
129
- }
130
- }, {
131
- key: "getTexture",
132
- value: function getTexture(index) {
133
- return this.getObject('textures', index);
134
- }
135
- }, {
136
- key: "getSampler",
137
- value: function getSampler(index) {
138
- return this.getObject('samplers', index);
139
- }
140
- }, {
141
- key: "getImage",
142
- value: function getImage(index) {
143
- return this.getObject('images', index);
144
- }
145
- }, {
146
- key: "getBufferView",
147
- value: function getBufferView(index) {
148
- return this.getObject('bufferViews', index);
149
- }
150
- }, {
151
- key: "getBuffer",
152
- value: function getBuffer(index) {
153
- return this.getObject('buffers', index);
154
- }
155
- }, {
156
- key: "getObject",
157
- value: function getObject(array, index) {
158
- if ((0, _typeof2.default)(index) === 'object') {
159
- return index;
160
- }
161
- var object = this.json[array] && this.json[array][index];
162
- if (!object) {
163
- throw new Error("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
164
- }
165
- return object;
166
- }
167
- }, {
168
- key: "getTypedArrayForBufferView",
169
- value: function getTypedArrayForBufferView(bufferView) {
170
- bufferView = this.getBufferView(bufferView);
171
- var bufferIndex = bufferView.buffer;
172
- var binChunk = this.gltf.buffers[bufferIndex];
173
- (0, _assert.assert)(binChunk);
174
- var byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
175
- return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
176
- }
177
- }, {
178
- key: "getTypedArrayForAccessor",
179
- value: function getTypedArrayForAccessor(accessor) {
180
- accessor = this.getAccessor(accessor);
181
- var bufferView = this.getBufferView(accessor.bufferView);
182
- var buffer = this.getBuffer(bufferView.buffer);
183
- var arrayBuffer = buffer.data;
184
- var _getAccessorArrayType = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, bufferView),
185
- ArrayType = _getAccessorArrayType.ArrayType,
186
- length = _getAccessorArrayType.length;
187
- var byteOffset = bufferView.byteOffset + accessor.byteOffset;
188
- return new ArrayType(arrayBuffer, byteOffset, length);
189
- }
190
- }, {
191
- key: "getTypedArrayForImageData",
192
- value: function getTypedArrayForImageData(image) {
193
- image = this.getAccessor(image);
194
- var bufferView = this.getBufferView(image.bufferView);
195
- var buffer = this.getBuffer(bufferView.buffer);
196
- var arrayBuffer = buffer.data;
197
- var byteOffset = bufferView.byteOffset || 0;
198
- return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
199
- }
200
- }, {
201
- key: "addApplicationData",
202
- value: function addApplicationData(key, data) {
203
- this.json[key] = data;
204
- return this;
205
- }
206
- }, {
207
- key: "addExtraData",
208
- value: function addExtraData(key, data) {
209
- this.json.extras = this.json.extras || {};
210
- this.json.extras[key] = data;
211
- return this;
212
- }
213
- }, {
214
- key: "addObjectExtension",
215
- value: function addObjectExtension(object, extensionName, data) {
216
- object.extensions = object.extensions || {};
217
- object.extensions[extensionName] = data;
218
- this.registerUsedExtension(extensionName);
219
- return this;
220
- }
221
- }, {
222
- key: "setObjectExtension",
223
- value: function setObjectExtension(object, extensionName, data) {
224
- var extensions = object.extensions || {};
225
- extensions[extensionName] = data;
226
- }
227
- }, {
228
- key: "removeObjectExtension",
229
- value: function removeObjectExtension(object, extensionName) {
230
- var extensions = object.extensions || {};
231
- var extension = extensions[extensionName];
232
- delete extensions[extensionName];
233
- return extension;
234
- }
235
- }, {
236
- key: "addExtension",
237
- value: function addExtension(extensionName) {
238
- var extensionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
239
- (0, _assert.assert)(extensionData);
240
- this.json.extensions = this.json.extensions || {};
241
- this.json.extensions[extensionName] = extensionData;
242
- this.registerUsedExtension(extensionName);
243
- return extensionData;
244
- }
245
- }, {
246
- key: "addRequiredExtension",
247
- value: function addRequiredExtension(extensionName) {
248
- var extensionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
249
- (0, _assert.assert)(extensionData);
250
- this.addExtension(extensionName, extensionData);
251
- this.registerRequiredExtension(extensionName);
252
- return extensionData;
253
- }
254
- }, {
255
- key: "registerUsedExtension",
256
- value: function registerUsedExtension(extensionName) {
257
- this.json.extensionsUsed = this.json.extensionsUsed || [];
258
- if (!this.json.extensionsUsed.find(function (ext) {
259
- return ext === extensionName;
260
- })) {
261
- this.json.extensionsUsed.push(extensionName);
262
- }
38
+ get json() {
39
+ return this.gltf.json;
40
+ }
41
+ getApplicationData(key) {
42
+ const data = this.json[key];
43
+ return data;
44
+ }
45
+ getExtraData(key) {
46
+ const extras = this.json.extras || {};
47
+ return extras[key];
48
+ }
49
+ getExtension(extensionName) {
50
+ const isExtension = this.getUsedExtensions().find(name => name === extensionName);
51
+ const extensions = this.json.extensions || {};
52
+ return isExtension ? extensions[extensionName] || true : null;
53
+ }
54
+ getRequiredExtension(extensionName) {
55
+ const isRequired = this.getRequiredExtensions().find(name => name === extensionName);
56
+ return isRequired ? this.getExtension(extensionName) : null;
57
+ }
58
+ getRequiredExtensions() {
59
+ return this.json.extensionsRequired || [];
60
+ }
61
+ getUsedExtensions() {
62
+ return this.json.extensionsUsed || [];
63
+ }
64
+ getRemovedExtensions() {
65
+ return this.json.extensionsRemoved || [];
66
+ }
67
+ getObjectExtension(object, extensionName) {
68
+ const extensions = object.extensions || {};
69
+ return extensions[extensionName];
70
+ }
71
+ getScene(index) {
72
+ return this.getObject('scenes', index);
73
+ }
74
+ getNode(index) {
75
+ return this.getObject('nodes', index);
76
+ }
77
+ getSkin(index) {
78
+ return this.getObject('skins', index);
79
+ }
80
+ getMesh(index) {
81
+ return this.getObject('meshes', index);
82
+ }
83
+ getMaterial(index) {
84
+ return this.getObject('materials', index);
85
+ }
86
+ getAccessor(index) {
87
+ return this.getObject('accessors', index);
88
+ }
89
+ getTexture(index) {
90
+ return this.getObject('textures', index);
91
+ }
92
+ getSampler(index) {
93
+ return this.getObject('samplers', index);
94
+ }
95
+ getImage(index) {
96
+ return this.getObject('images', index);
97
+ }
98
+ getBufferView(index) {
99
+ return this.getObject('bufferViews', index);
100
+ }
101
+ getBuffer(index) {
102
+ return this.getObject('buffers', index);
103
+ }
104
+ getObject(array, index) {
105
+ if (typeof index === 'object') {
106
+ return index;
263
107
  }
264
- }, {
265
- key: "registerRequiredExtension",
266
- value: function registerRequiredExtension(extensionName) {
267
- this.registerUsedExtension(extensionName);
268
- this.json.extensionsRequired = this.json.extensionsRequired || [];
269
- if (!this.json.extensionsRequired.find(function (ext) {
270
- return ext === extensionName;
271
- })) {
272
- this.json.extensionsRequired.push(extensionName);
273
- }
108
+ const object = this.json[array] && this.json[array][index];
109
+ if (!object) {
110
+ throw new Error("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
274
111
  }
275
- }, {
276
- key: "removeExtension",
277
- value: function removeExtension(extensionName) {
278
- if (!this.getExtension(extensionName)) {
279
- return;
280
- }
281
- if (this.json.extensionsRequired) {
282
- this._removeStringFromArray(this.json.extensionsRequired, extensionName);
283
- }
284
- if (this.json.extensionsUsed) {
285
- this._removeStringFromArray(this.json.extensionsUsed, extensionName);
286
- }
287
- if (this.json.extensions) {
288
- delete this.json.extensions[extensionName];
289
- }
290
- if (!Array.isArray(this.json.extensionsRemoved)) {
291
- this.json.extensionsRemoved = [];
292
- }
293
- var extensionsRemoved = this.json.extensionsRemoved;
294
- if (!extensionsRemoved.includes(extensionName)) {
295
- extensionsRemoved.push(extensionName);
296
- }
297
- }
298
- }, {
299
- key: "setDefaultScene",
300
- value: function setDefaultScene(sceneIndex) {
301
- this.json.scene = sceneIndex;
112
+ return object;
113
+ }
114
+ getTypedArrayForBufferView(bufferView) {
115
+ bufferView = this.getBufferView(bufferView);
116
+ const bufferIndex = bufferView.buffer;
117
+ const binChunk = this.gltf.buffers[bufferIndex];
118
+ (0, _assert.assert)(binChunk);
119
+ const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
120
+ return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
121
+ }
122
+ getTypedArrayForAccessor(accessor) {
123
+ accessor = this.getAccessor(accessor);
124
+ const bufferView = this.getBufferView(accessor.bufferView);
125
+ const buffer = this.getBuffer(bufferView.buffer);
126
+ const arrayBuffer = buffer.data;
127
+ const {
128
+ ArrayType,
129
+ length
130
+ } = (0, _gltfUtils.getAccessorArrayTypeAndLength)(accessor, bufferView);
131
+ const byteOffset = bufferView.byteOffset + accessor.byteOffset;
132
+ return new ArrayType(arrayBuffer, byteOffset, length);
133
+ }
134
+ getTypedArrayForImageData(image) {
135
+ image = this.getAccessor(image);
136
+ const bufferView = this.getBufferView(image.bufferView);
137
+ const buffer = this.getBuffer(bufferView.buffer);
138
+ const arrayBuffer = buffer.data;
139
+ const byteOffset = bufferView.byteOffset || 0;
140
+ return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
141
+ }
142
+ addApplicationData(key, data) {
143
+ this.json[key] = data;
144
+ return this;
145
+ }
146
+ addExtraData(key, data) {
147
+ this.json.extras = this.json.extras || {};
148
+ this.json.extras[key] = data;
149
+ return this;
150
+ }
151
+ addObjectExtension(object, extensionName, data) {
152
+ object.extensions = object.extensions || {};
153
+ object.extensions[extensionName] = data;
154
+ this.registerUsedExtension(extensionName);
155
+ return this;
156
+ }
157
+ setObjectExtension(object, extensionName, data) {
158
+ const extensions = object.extensions || {};
159
+ extensions[extensionName] = data;
160
+ }
161
+ removeObjectExtension(object, extensionName) {
162
+ const extensions = object.extensions || {};
163
+ const extension = extensions[extensionName];
164
+ delete extensions[extensionName];
165
+ return extension;
166
+ }
167
+ addExtension(extensionName) {
168
+ let extensionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
169
+ (0, _assert.assert)(extensionData);
170
+ this.json.extensions = this.json.extensions || {};
171
+ this.json.extensions[extensionName] = extensionData;
172
+ this.registerUsedExtension(extensionName);
173
+ return extensionData;
174
+ }
175
+ addRequiredExtension(extensionName) {
176
+ let extensionData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
177
+ (0, _assert.assert)(extensionData);
178
+ this.addExtension(extensionName, extensionData);
179
+ this.registerRequiredExtension(extensionName);
180
+ return extensionData;
181
+ }
182
+ registerUsedExtension(extensionName) {
183
+ this.json.extensionsUsed = this.json.extensionsUsed || [];
184
+ if (!this.json.extensionsUsed.find(ext => ext === extensionName)) {
185
+ this.json.extensionsUsed.push(extensionName);
302
186
  }
303
- }, {
304
- key: "addScene",
305
- value: function addScene(scene) {
306
- var nodeIndices = scene.nodeIndices;
307
- this.json.scenes = this.json.scenes || [];
308
- this.json.scenes.push({
309
- nodes: nodeIndices
310
- });
311
- return this.json.scenes.length - 1;
187
+ }
188
+ registerRequiredExtension(extensionName) {
189
+ this.registerUsedExtension(extensionName);
190
+ this.json.extensionsRequired = this.json.extensionsRequired || [];
191
+ if (!this.json.extensionsRequired.find(ext => ext === extensionName)) {
192
+ this.json.extensionsRequired.push(extensionName);
312
193
  }
313
- }, {
314
- key: "addNode",
315
- value: function addNode(node) {
316
- var meshIndex = node.meshIndex,
317
- matrix = node.matrix;
318
- this.json.nodes = this.json.nodes || [];
319
- var nodeData = {
320
- mesh: meshIndex
321
- };
322
- if (matrix) {
323
- nodeData.matrix = matrix;
324
- }
325
- this.json.nodes.push(nodeData);
326
- return this.json.nodes.length - 1;
194
+ }
195
+ removeExtension(extensionName) {
196
+ if (!this.getExtension(extensionName)) {
197
+ return;
327
198
  }
328
- }, {
329
- key: "addMesh",
330
- value: function addMesh(mesh) {
331
- var attributes = mesh.attributes,
332
- indices = mesh.indices,
333
- material = mesh.material,
334
- _mesh$mode = mesh.mode,
335
- mode = _mesh$mode === void 0 ? 4 : _mesh$mode;
336
- var accessors = this._addAttributes(attributes);
337
- var glTFMesh = {
338
- primitives: [{
339
- attributes: accessors,
340
- mode: mode
341
- }]
342
- };
343
- if (indices) {
344
- var indicesAccessor = this._addIndices(indices);
345
- glTFMesh.primitives[0].indices = indicesAccessor;
346
- }
347
- if (Number.isFinite(material)) {
348
- glTFMesh.primitives[0].material = material;
349
- }
350
- this.json.meshes = this.json.meshes || [];
351
- this.json.meshes.push(glTFMesh);
352
- return this.json.meshes.length - 1;
199
+ if (this.json.extensionsRequired) {
200
+ this._removeStringFromArray(this.json.extensionsRequired, extensionName);
353
201
  }
354
- }, {
355
- key: "addPointCloud",
356
- value: function addPointCloud(attributes) {
357
- var accessorIndices = this._addAttributes(attributes);
358
- var glTFMesh = {
359
- primitives: [{
360
- attributes: accessorIndices,
361
- mode: 0
362
- }]
363
- };
364
- this.json.meshes = this.json.meshes || [];
365
- this.json.meshes.push(glTFMesh);
366
- return this.json.meshes.length - 1;
202
+ if (this.json.extensionsUsed) {
203
+ this._removeStringFromArray(this.json.extensionsUsed, extensionName);
367
204
  }
368
- }, {
369
- key: "addImage",
370
- value: function addImage(imageData, mimeTypeOpt) {
371
- var metadata = (0, _images.getBinaryImageMetadata)(imageData);
372
- var mimeType = mimeTypeOpt || (metadata === null || metadata === void 0 ? void 0 : metadata.mimeType);
373
- var bufferViewIndex = this.addBufferView(imageData);
374
- var glTFImage = {
375
- bufferView: bufferViewIndex,
376
- mimeType: mimeType
377
- };
378
- this.json.images = this.json.images || [];
379
- this.json.images.push(glTFImage);
380
- return this.json.images.length - 1;
205
+ if (this.json.extensions) {
206
+ delete this.json.extensions[extensionName];
381
207
  }
382
- }, {
383
- key: "addBufferView",
384
- value: function addBufferView(buffer) {
385
- var byteLength = buffer.byteLength;
386
- (0, _assert.assert)(Number.isFinite(byteLength));
387
- this.sourceBuffers = this.sourceBuffers || [];
388
- this.sourceBuffers.push(buffer);
389
- var glTFBufferView = {
390
- buffer: 0,
391
- byteOffset: this.byteLength,
392
- byteLength: byteLength
393
- };
394
- this.byteLength += (0, _loaderUtils.padToNBytes)(byteLength, 4);
395
- this.json.bufferViews = this.json.bufferViews || [];
396
- this.json.bufferViews.push(glTFBufferView);
397
- return this.json.bufferViews.length - 1;
208
+ if (!Array.isArray(this.json.extensionsRemoved)) {
209
+ this.json.extensionsRemoved = [];
398
210
  }
399
- }, {
400
- key: "addAccessor",
401
- value: function addAccessor(bufferViewIndex, accessor) {
402
- var glTFAccessor = {
403
- bufferView: bufferViewIndex,
404
- type: (0, _gltfUtils.getAccessorTypeFromSize)(accessor.size),
405
- componentType: accessor.componentType,
406
- count: accessor.count,
407
- max: accessor.max,
408
- min: accessor.min
409
- };
410
- this.json.accessors = this.json.accessors || [];
411
- this.json.accessors.push(glTFAccessor);
412
- return this.json.accessors.length - 1;
211
+ const extensionsRemoved = this.json.extensionsRemoved;
212
+ if (!extensionsRemoved.includes(extensionName)) {
213
+ extensionsRemoved.push(extensionName);
413
214
  }
414
- }, {
415
- key: "addBinaryBuffer",
416
- value: function addBinaryBuffer(sourceBuffer) {
417
- var accessor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
418
- size: 3
419
- };
420
- var bufferViewIndex = this.addBufferView(sourceBuffer);
421
- var minMax = {
422
- min: accessor.min,
423
- max: accessor.max
424
- };
425
- if (!minMax.min || !minMax.max) {
426
- minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
427
- }
428
- var accessorDefaults = {
429
- size: accessor.size,
430
- componentType: (0, _gltfUtils.getComponentTypeFromArray)(sourceBuffer),
431
- count: Math.round(sourceBuffer.length / accessor.size),
432
- min: minMax.min,
433
- max: minMax.max
434
- };
435
- return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
215
+ }
216
+ setDefaultScene(sceneIndex) {
217
+ this.json.scene = sceneIndex;
218
+ }
219
+ addScene(scene) {
220
+ const {
221
+ nodeIndices
222
+ } = scene;
223
+ this.json.scenes = this.json.scenes || [];
224
+ this.json.scenes.push({
225
+ nodes: nodeIndices
226
+ });
227
+ return this.json.scenes.length - 1;
228
+ }
229
+ addNode(node) {
230
+ const {
231
+ meshIndex,
232
+ matrix
233
+ } = node;
234
+ this.json.nodes = this.json.nodes || [];
235
+ const nodeData = {
236
+ mesh: meshIndex
237
+ };
238
+ if (matrix) {
239
+ nodeData.matrix = matrix;
436
240
  }
437
- }, {
438
- key: "addTexture",
439
- value: function addTexture(texture) {
440
- var imageIndex = texture.imageIndex;
441
- var glTFTexture = {
442
- source: imageIndex
443
- };
444
- this.json.textures = this.json.textures || [];
445
- this.json.textures.push(glTFTexture);
446
- return this.json.textures.length - 1;
241
+ this.json.nodes.push(nodeData);
242
+ return this.json.nodes.length - 1;
243
+ }
244
+ addMesh(mesh) {
245
+ const {
246
+ attributes,
247
+ indices,
248
+ material,
249
+ mode = 4
250
+ } = mesh;
251
+ const accessors = this._addAttributes(attributes);
252
+ const glTFMesh = {
253
+ primitives: [{
254
+ attributes: accessors,
255
+ mode
256
+ }]
257
+ };
258
+ if (indices) {
259
+ const indicesAccessor = this._addIndices(indices);
260
+ glTFMesh.primitives[0].indices = indicesAccessor;
447
261
  }
448
- }, {
449
- key: "addMaterial",
450
- value: function addMaterial(pbrMaterialInfo) {
451
- this.json.materials = this.json.materials || [];
452
- this.json.materials.push(pbrMaterialInfo);
453
- return this.json.materials.length - 1;
262
+ if (Number.isFinite(material)) {
263
+ glTFMesh.primitives[0].material = material;
454
264
  }
455
- }, {
456
- key: "createBinaryChunk",
457
- value: function createBinaryChunk() {
458
- var _this$json, _this$json$buffers;
459
- this.gltf.buffers = [];
460
- var totalByteLength = this.byteLength;
461
- var arrayBuffer = new ArrayBuffer(totalByteLength);
462
- var targetArray = new Uint8Array(arrayBuffer);
463
- var dstByteOffset = 0;
464
- var _iterator = _createForOfIteratorHelper(this.sourceBuffers || []),
465
- _step;
466
- try {
467
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
468
- var sourceBuffer = _step.value;
469
- dstByteOffset = (0, _loaderUtils.copyToArray)(sourceBuffer, targetArray, dstByteOffset);
470
- }
471
- } catch (err) {
472
- _iterator.e(err);
473
- } finally {
474
- _iterator.f();
475
- }
476
- if ((_this$json = this.json) !== null && _this$json !== void 0 && (_this$json$buffers = _this$json.buffers) !== null && _this$json$buffers !== void 0 && _this$json$buffers[0]) {
477
- this.json.buffers[0].byteLength = totalByteLength;
265
+ this.json.meshes = this.json.meshes || [];
266
+ this.json.meshes.push(glTFMesh);
267
+ return this.json.meshes.length - 1;
268
+ }
269
+ addPointCloud(attributes) {
270
+ const accessorIndices = this._addAttributes(attributes);
271
+ const glTFMesh = {
272
+ primitives: [{
273
+ attributes: accessorIndices,
274
+ mode: 0
275
+ }]
276
+ };
277
+ this.json.meshes = this.json.meshes || [];
278
+ this.json.meshes.push(glTFMesh);
279
+ return this.json.meshes.length - 1;
280
+ }
281
+ addImage(imageData, mimeTypeOpt) {
282
+ const metadata = (0, _images.getBinaryImageMetadata)(imageData);
283
+ const mimeType = mimeTypeOpt || (metadata === null || metadata === void 0 ? void 0 : metadata.mimeType);
284
+ const bufferViewIndex = this.addBufferView(imageData);
285
+ const glTFImage = {
286
+ bufferView: bufferViewIndex,
287
+ mimeType
288
+ };
289
+ this.json.images = this.json.images || [];
290
+ this.json.images.push(glTFImage);
291
+ return this.json.images.length - 1;
292
+ }
293
+ addBufferView(buffer) {
294
+ const byteLength = buffer.byteLength;
295
+ (0, _assert.assert)(Number.isFinite(byteLength));
296
+ this.sourceBuffers = this.sourceBuffers || [];
297
+ this.sourceBuffers.push(buffer);
298
+ const glTFBufferView = {
299
+ buffer: 0,
300
+ byteOffset: this.byteLength,
301
+ byteLength
302
+ };
303
+ this.byteLength += (0, _loaderUtils.padToNBytes)(byteLength, 4);
304
+ this.json.bufferViews = this.json.bufferViews || [];
305
+ this.json.bufferViews.push(glTFBufferView);
306
+ return this.json.bufferViews.length - 1;
307
+ }
308
+ addAccessor(bufferViewIndex, accessor) {
309
+ const glTFAccessor = {
310
+ bufferView: bufferViewIndex,
311
+ type: (0, _gltfUtils.getAccessorTypeFromSize)(accessor.size),
312
+ componentType: accessor.componentType,
313
+ count: accessor.count,
314
+ max: accessor.max,
315
+ min: accessor.min
316
+ };
317
+ this.json.accessors = this.json.accessors || [];
318
+ this.json.accessors.push(glTFAccessor);
319
+ return this.json.accessors.length - 1;
320
+ }
321
+ addBinaryBuffer(sourceBuffer) {
322
+ let accessor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
323
+ size: 3
324
+ };
325
+ const bufferViewIndex = this.addBufferView(sourceBuffer);
326
+ let minMax = {
327
+ min: accessor.min,
328
+ max: accessor.max
329
+ };
330
+ if (!minMax.min || !minMax.max) {
331
+ minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
332
+ }
333
+ const accessorDefaults = {
334
+ size: accessor.size,
335
+ componentType: (0, _gltfUtils.getComponentTypeFromArray)(sourceBuffer),
336
+ count: Math.round(sourceBuffer.length / accessor.size),
337
+ min: minMax.min,
338
+ max: minMax.max
339
+ };
340
+ return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
341
+ }
342
+ addTexture(texture) {
343
+ const {
344
+ imageIndex
345
+ } = texture;
346
+ const glTFTexture = {
347
+ source: imageIndex
348
+ };
349
+ this.json.textures = this.json.textures || [];
350
+ this.json.textures.push(glTFTexture);
351
+ return this.json.textures.length - 1;
352
+ }
353
+ addMaterial(pbrMaterialInfo) {
354
+ this.json.materials = this.json.materials || [];
355
+ this.json.materials.push(pbrMaterialInfo);
356
+ return this.json.materials.length - 1;
357
+ }
358
+ createBinaryChunk() {
359
+ var _this$json, _this$json$buffers;
360
+ this.gltf.buffers = [];
361
+ const totalByteLength = this.byteLength;
362
+ const arrayBuffer = new ArrayBuffer(totalByteLength);
363
+ const targetArray = new Uint8Array(arrayBuffer);
364
+ let dstByteOffset = 0;
365
+ for (const sourceBuffer of this.sourceBuffers || []) {
366
+ dstByteOffset = (0, _loaderUtils.copyToArray)(sourceBuffer, targetArray, dstByteOffset);
367
+ }
368
+ if ((_this$json = this.json) !== null && _this$json !== void 0 && (_this$json$buffers = _this$json.buffers) !== null && _this$json$buffers !== void 0 && _this$json$buffers[0]) {
369
+ this.json.buffers[0].byteLength = totalByteLength;
370
+ } else {
371
+ this.json.buffers = [{
372
+ byteLength: totalByteLength
373
+ }];
374
+ }
375
+ this.gltf.binary = arrayBuffer;
376
+ this.sourceBuffers = [arrayBuffer];
377
+ }
378
+ _removeStringFromArray(array, string) {
379
+ let found = true;
380
+ while (found) {
381
+ const index = array.indexOf(string);
382
+ if (index > -1) {
383
+ array.splice(index, 1);
478
384
  } else {
479
- this.json.buffers = [{
480
- byteLength: totalByteLength
481
- }];
385
+ found = false;
482
386
  }
483
- this.gltf.binary = arrayBuffer;
484
- this.sourceBuffers = [arrayBuffer];
485
387
  }
486
- }, {
487
- key: "_removeStringFromArray",
488
- value: function _removeStringFromArray(array, string) {
489
- var found = true;
490
- while (found) {
491
- var index = array.indexOf(string);
492
- if (index > -1) {
493
- array.splice(index, 1);
494
- } else {
495
- found = false;
496
- }
497
- }
388
+ }
389
+ _addAttributes() {
390
+ let attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
391
+ const result = {};
392
+ for (const attributeKey in attributes) {
393
+ const attributeData = attributes[attributeKey];
394
+ const attrName = this._getGltfAttributeName(attributeKey);
395
+ const accessor = this.addBinaryBuffer(attributeData.value, attributeData);
396
+ result[attrName] = accessor;
397
+ }
398
+ return result;
399
+ }
400
+ _addIndices(indices) {
401
+ return this.addBinaryBuffer(indices, {
402
+ size: 1
403
+ });
404
+ }
405
+ _getGltfAttributeName(attributeName) {
406
+ switch (attributeName.toLowerCase()) {
407
+ case 'position':
408
+ case 'positions':
409
+ case 'vertices':
410
+ return 'POSITION';
411
+ case 'normal':
412
+ case 'normals':
413
+ return 'NORMAL';
414
+ case 'color':
415
+ case 'colors':
416
+ return 'COLOR_0';
417
+ case 'texcoord':
418
+ case 'texcoords':
419
+ return 'TEXCOORD_0';
420
+ default:
421
+ return attributeName;
498
422
  }
499
- }, {
500
- key: "_addAttributes",
501
- value: function _addAttributes() {
502
- var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
503
- var result = {};
504
- for (var attributeKey in attributes) {
505
- var attributeData = attributes[attributeKey];
506
- var attrName = this._getGltfAttributeName(attributeKey);
507
- var accessor = this.addBinaryBuffer(attributeData.value, attributeData);
508
- result[attrName] = accessor;
509
- }
423
+ }
424
+ _getAccessorMinMax(buffer, size) {
425
+ const result = {
426
+ min: null,
427
+ max: null
428
+ };
429
+ if (buffer.length < size) {
510
430
  return result;
511
431
  }
512
- }, {
513
- key: "_addIndices",
514
- value: function _addIndices(indices) {
515
- return this.addBinaryBuffer(indices, {
516
- size: 1
517
- });
518
- }
519
- }, {
520
- key: "_getGltfAttributeName",
521
- value: function _getGltfAttributeName(attributeName) {
522
- switch (attributeName.toLowerCase()) {
523
- case 'position':
524
- case 'positions':
525
- case 'vertices':
526
- return 'POSITION';
527
- case 'normal':
528
- case 'normals':
529
- return 'NORMAL';
530
- case 'color':
531
- case 'colors':
532
- return 'COLOR_0';
533
- case 'texcoord':
534
- case 'texcoords':
535
- return 'TEXCOORD_0';
536
- default:
537
- return attributeName;
432
+ result.min = [];
433
+ result.max = [];
434
+ const initValues = buffer.subarray(0, size);
435
+ for (const value of initValues) {
436
+ result.min.push(value);
437
+ result.max.push(value);
438
+ }
439
+ for (let index = size; index < buffer.length; index += size) {
440
+ for (let componentIndex = 0; componentIndex < size; componentIndex++) {
441
+ result.min[0 + componentIndex] = Math.min(result.min[0 + componentIndex], buffer[index + componentIndex]);
442
+ result.max[0 + componentIndex] = Math.max(result.max[0 + componentIndex], buffer[index + componentIndex]);
538
443
  }
539
444
  }
540
- }, {
541
- key: "_getAccessorMinMax",
542
- value: function _getAccessorMinMax(buffer, size) {
543
- var result = {
544
- min: null,
545
- max: null
546
- };
547
- if (buffer.length < size) {
548
- return result;
549
- }
550
- result.min = [];
551
- result.max = [];
552
- var initValues = buffer.subarray(0, size);
553
- var _iterator2 = _createForOfIteratorHelper(initValues),
554
- _step2;
555
- try {
556
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
557
- var value = _step2.value;
558
- result.min.push(value);
559
- result.max.push(value);
560
- }
561
- } catch (err) {
562
- _iterator2.e(err);
563
- } finally {
564
- _iterator2.f();
565
- }
566
- for (var index = size; index < buffer.length; index += size) {
567
- for (var componentIndex = 0; componentIndex < size; componentIndex++) {
568
- result.min[0 + componentIndex] = Math.min(result.min[0 + componentIndex], buffer[index + componentIndex]);
569
- result.max[0 + componentIndex] = Math.max(result.max[0 + componentIndex], buffer[index + componentIndex]);
570
- }
571
- }
572
- return result;
573
- }
574
- }]);
575
- return GLTFScenegraph;
576
- }();
445
+ return result;
446
+ }
447
+ }
577
448
  exports.default = GLTFScenegraph;
578
449
  //# sourceMappingURL=gltf-scenegraph.js.map