@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
@@ -1,21 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.normalizeGLTFV1 = normalizeGLTFV1;
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 KHR_binary_glTF = _interopRequireWildcard(require("../extensions/KHR_binary_gltf"));
13
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
- 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; } } }; }
16
- 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); }
17
- 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; }
18
- var GLTF_ARRAYS = {
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
+ const GLTF_ARRAYS = {
19
13
  accessors: 'accessor',
20
14
  animations: 'animation',
21
15
  buffers: 'buffer',
@@ -29,7 +23,7 @@ var GLTF_ARRAYS = {
29
23
  skins: 'skin',
30
24
  textures: 'texture'
31
25
  };
32
- var GLTF_KEYS = {
26
+ const GLTF_KEYS = {
33
27
  accessor: 'accessors',
34
28
  animations: 'animation',
35
29
  buffer: 'buffers',
@@ -43,9 +37,8 @@ var GLTF_KEYS = {
43
37
  skin: 'skins',
44
38
  texture: 'textures'
45
39
  };
46
- var GLTFV1Normalizer = function () {
47
- function GLTFV1Normalizer() {
48
- (0, _classCallCheck2.default)(this, GLTFV1Normalizer);
40
+ class GLTFV1Normalizer {
41
+ constructor() {
49
42
  (0, _defineProperty2.default)(this, "idToIndexMap", {
50
43
  animations: {},
51
44
  accessors: {},
@@ -62,270 +55,159 @@ var GLTFV1Normalizer = function () {
62
55
  });
63
56
  (0, _defineProperty2.default)(this, "json", void 0);
64
57
  }
65
- (0, _createClass2.default)(GLTFV1Normalizer, [{
66
- key: "normalize",
67
- value: function normalize(gltf, options) {
68
- this.json = gltf.json;
69
- var json = gltf.json;
70
- switch (json.asset && json.asset.version) {
71
- case '2.0':
72
- return;
73
- case undefined:
74
- case '1.0':
75
- break;
76
- default:
77
- console.warn("glTF: Unknown version ".concat(json.asset.version));
78
- return;
79
- }
80
- if (!options.normalize) {
81
- throw new Error('glTF v1 is not supported.');
82
- }
83
- console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');
84
- this._addAsset(json);
85
- this._convertTopLevelObjectsToArrays(json);
86
- KHR_binary_glTF.preprocess(gltf);
87
- this._convertObjectIdsToArrayIndices(json);
88
- this._updateObjects(json);
89
- this._updateMaterial(json);
58
+ normalize(gltf, options) {
59
+ this.json = gltf.json;
60
+ const json = gltf.json;
61
+ switch (json.asset && json.asset.version) {
62
+ case '2.0':
63
+ return;
64
+ case undefined:
65
+ case '1.0':
66
+ break;
67
+ default:
68
+ console.warn("glTF: Unknown version ".concat(json.asset.version));
69
+ return;
90
70
  }
91
- }, {
92
- key: "_addAsset",
93
- value: function _addAsset(json) {
94
- json.asset = json.asset || {};
95
- json.asset.version = '2.0';
96
- json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
71
+ if (!options.normalize) {
72
+ throw new Error('glTF v1 is not supported.');
97
73
  }
98
- }, {
99
- key: "_convertTopLevelObjectsToArrays",
100
- value: function _convertTopLevelObjectsToArrays(json) {
101
- for (var arrayName in GLTF_ARRAYS) {
102
- this._convertTopLevelObjectToArray(json, arrayName);
103
- }
74
+ console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');
75
+ this._addAsset(json);
76
+ this._convertTopLevelObjectsToArrays(json);
77
+ KHR_binary_glTF.preprocess(gltf);
78
+ this._convertObjectIdsToArrayIndices(json);
79
+ this._updateObjects(json);
80
+ this._updateMaterial(json);
81
+ }
82
+ _addAsset(json) {
83
+ json.asset = json.asset || {};
84
+ json.asset.version = '2.0';
85
+ json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
86
+ }
87
+ _convertTopLevelObjectsToArrays(json) {
88
+ for (const arrayName in GLTF_ARRAYS) {
89
+ this._convertTopLevelObjectToArray(json, arrayName);
104
90
  }
105
- }, {
106
- key: "_convertTopLevelObjectToArray",
107
- value: function _convertTopLevelObjectToArray(json, mapName) {
108
- var objectMap = json[mapName];
109
- if (!objectMap || Array.isArray(objectMap)) {
110
- return;
111
- }
112
- json[mapName] = [];
113
- for (var id in objectMap) {
114
- var object = objectMap[id];
115
- object.id = object.id || id;
116
- var index = json[mapName].length;
117
- json[mapName].push(object);
118
- this.idToIndexMap[mapName][id] = index;
119
- }
91
+ }
92
+ _convertTopLevelObjectToArray(json, mapName) {
93
+ const objectMap = json[mapName];
94
+ if (!objectMap || Array.isArray(objectMap)) {
95
+ return;
120
96
  }
121
- }, {
122
- key: "_convertObjectIdsToArrayIndices",
123
- value: function _convertObjectIdsToArrayIndices(json) {
124
- for (var arrayName in GLTF_ARRAYS) {
125
- this._convertIdsToIndices(json, arrayName);
126
- }
127
- if ('scene' in json) {
128
- json.scene = this._convertIdToIndex(json.scene, 'scene');
129
- }
130
- var _iterator = _createForOfIteratorHelper(json.textures),
131
- _step;
132
- try {
133
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
134
- var texture = _step.value;
135
- this._convertTextureIds(texture);
136
- }
137
- } catch (err) {
138
- _iterator.e(err);
139
- } finally {
140
- _iterator.f();
141
- }
142
- var _iterator2 = _createForOfIteratorHelper(json.meshes),
143
- _step2;
144
- try {
145
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
146
- var mesh = _step2.value;
147
- this._convertMeshIds(mesh);
148
- }
149
- } catch (err) {
150
- _iterator2.e(err);
151
- } finally {
152
- _iterator2.f();
153
- }
154
- var _iterator3 = _createForOfIteratorHelper(json.nodes),
155
- _step3;
156
- try {
157
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
158
- var node = _step3.value;
159
- this._convertNodeIds(node);
160
- }
161
- } catch (err) {
162
- _iterator3.e(err);
163
- } finally {
164
- _iterator3.f();
165
- }
166
- var _iterator4 = _createForOfIteratorHelper(json.scenes),
167
- _step4;
168
- try {
169
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
170
- var _node = _step4.value;
171
- this._convertSceneIds(_node);
172
- }
173
- } catch (err) {
174
- _iterator4.e(err);
175
- } finally {
176
- _iterator4.f();
177
- }
97
+ json[mapName] = [];
98
+ for (const id in objectMap) {
99
+ const object = objectMap[id];
100
+ object.id = object.id || id;
101
+ const index = json[mapName].length;
102
+ json[mapName].push(object);
103
+ this.idToIndexMap[mapName][id] = index;
178
104
  }
179
- }, {
180
- key: "_convertTextureIds",
181
- value: function _convertTextureIds(texture) {
182
- if (texture.source) {
183
- texture.source = this._convertIdToIndex(texture.source, 'image');
184
- }
105
+ }
106
+ _convertObjectIdsToArrayIndices(json) {
107
+ for (const arrayName in GLTF_ARRAYS) {
108
+ this._convertIdsToIndices(json, arrayName);
185
109
  }
186
- }, {
187
- key: "_convertMeshIds",
188
- value: function _convertMeshIds(mesh) {
189
- var _iterator5 = _createForOfIteratorHelper(mesh.primitives),
190
- _step5;
191
- try {
192
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
193
- var primitive = _step5.value;
194
- var attributes = primitive.attributes,
195
- indices = primitive.indices,
196
- material = primitive.material;
197
- for (var attributeName in attributes) {
198
- attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
199
- }
200
- if (indices) {
201
- primitive.indices = this._convertIdToIndex(indices, 'accessor');
202
- }
203
- if (material) {
204
- primitive.material = this._convertIdToIndex(material, 'material');
205
- }
206
- }
207
- } catch (err) {
208
- _iterator5.e(err);
209
- } finally {
210
- _iterator5.f();
211
- }
110
+ if ('scene' in json) {
111
+ json.scene = this._convertIdToIndex(json.scene, 'scene');
212
112
  }
213
- }, {
214
- key: "_convertNodeIds",
215
- value: function _convertNodeIds(node) {
216
- var _this = this;
217
- if (node.children) {
218
- node.children = node.children.map(function (child) {
219
- return _this._convertIdToIndex(child, 'node');
220
- });
221
- }
222
- if (node.meshes) {
223
- node.meshes = node.meshes.map(function (mesh) {
224
- return _this._convertIdToIndex(mesh, 'mesh');
225
- });
226
- }
113
+ for (const texture of json.textures) {
114
+ this._convertTextureIds(texture);
227
115
  }
228
- }, {
229
- key: "_convertSceneIds",
230
- value: function _convertSceneIds(scene) {
231
- var _this2 = this;
232
- if (scene.nodes) {
233
- scene.nodes = scene.nodes.map(function (node) {
234
- return _this2._convertIdToIndex(node, 'node');
235
- });
236
- }
116
+ for (const mesh of json.meshes) {
117
+ this._convertMeshIds(mesh);
237
118
  }
238
- }, {
239
- key: "_convertIdsToIndices",
240
- value: function _convertIdsToIndices(json, topLevelArrayName) {
241
- if (!json[topLevelArrayName]) {
242
- console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));
243
- json[topLevelArrayName] = [];
244
- }
245
- var _iterator6 = _createForOfIteratorHelper(json[topLevelArrayName]),
246
- _step6;
247
- try {
248
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
249
- var object = _step6.value;
250
- for (var key in object) {
251
- var id = object[key];
252
- var index = this._convertIdToIndex(id, key);
253
- object[key] = index;
254
- }
255
- }
256
- } catch (err) {
257
- _iterator6.e(err);
258
- } finally {
259
- _iterator6.f();
260
- }
119
+ for (const node of json.nodes) {
120
+ this._convertNodeIds(node);
121
+ }
122
+ for (const node of json.scenes) {
123
+ this._convertSceneIds(node);
124
+ }
125
+ }
126
+ _convertTextureIds(texture) {
127
+ if (texture.source) {
128
+ texture.source = this._convertIdToIndex(texture.source, 'image');
261
129
  }
262
- }, {
263
- key: "_convertIdToIndex",
264
- value: function _convertIdToIndex(id, key) {
265
- var arrayName = GLTF_KEYS[key];
266
- if (arrayName in this.idToIndexMap) {
267
- var index = this.idToIndexMap[arrayName][id];
268
- if (!Number.isFinite(index)) {
269
- throw new Error("gltf v1: failed to resolve ".concat(key, " with id ").concat(id));
270
- }
271
- return index;
130
+ }
131
+ _convertMeshIds(mesh) {
132
+ for (const primitive of mesh.primitives) {
133
+ const {
134
+ attributes,
135
+ indices,
136
+ material
137
+ } = primitive;
138
+ for (const attributeName in attributes) {
139
+ attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
140
+ }
141
+ if (indices) {
142
+ primitive.indices = this._convertIdToIndex(indices, 'accessor');
143
+ }
144
+ if (material) {
145
+ primitive.material = this._convertIdToIndex(material, 'material');
272
146
  }
273
- return id;
274
147
  }
275
- }, {
276
- key: "_updateObjects",
277
- value: function _updateObjects(json) {
278
- var _iterator7 = _createForOfIteratorHelper(this.json.buffers),
279
- _step7;
280
- try {
281
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
282
- var buffer = _step7.value;
283
- delete buffer.type;
284
- }
285
- } catch (err) {
286
- _iterator7.e(err);
287
- } finally {
288
- _iterator7.f();
148
+ }
149
+ _convertNodeIds(node) {
150
+ if (node.children) {
151
+ node.children = node.children.map(child => this._convertIdToIndex(child, 'node'));
152
+ }
153
+ if (node.meshes) {
154
+ node.meshes = node.meshes.map(mesh => this._convertIdToIndex(mesh, 'mesh'));
155
+ }
156
+ }
157
+ _convertSceneIds(scene) {
158
+ if (scene.nodes) {
159
+ scene.nodes = scene.nodes.map(node => this._convertIdToIndex(node, 'node'));
160
+ }
161
+ }
162
+ _convertIdsToIndices(json, topLevelArrayName) {
163
+ if (!json[topLevelArrayName]) {
164
+ console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));
165
+ json[topLevelArrayName] = [];
166
+ }
167
+ for (const object of json[topLevelArrayName]) {
168
+ for (const key in object) {
169
+ const id = object[key];
170
+ const index = this._convertIdToIndex(id, key);
171
+ object[key] = index;
289
172
  }
290
173
  }
291
- }, {
292
- key: "_updateMaterial",
293
- value: function _updateMaterial(json) {
294
- var _iterator8 = _createForOfIteratorHelper(json.materials),
295
- _step8;
296
- try {
297
- var _loop = function _loop() {
298
- var _material$values, _material$values2, _material$values3;
299
- var material = _step8.value;
300
- material.pbrMetallicRoughness = {
301
- baseColorFactor: [1, 1, 1, 1],
302
- metallicFactor: 1,
303
- roughnessFactor: 1
304
- };
305
- var textureId = ((_material$values = material.values) === null || _material$values === void 0 ? void 0 : _material$values.tex) || ((_material$values2 = material.values) === null || _material$values2 === void 0 ? void 0 : _material$values2.texture2d_0) || ((_material$values3 = material.values) === null || _material$values3 === void 0 ? void 0 : _material$values3.diffuseTex);
306
- var textureIndex = json.textures.findIndex(function (texture) {
307
- return texture.id === textureId;
308
- });
309
- if (textureIndex !== -1) {
310
- material.pbrMetallicRoughness.baseColorTexture = {
311
- index: textureIndex
312
- };
313
- }
174
+ }
175
+ _convertIdToIndex(id, key) {
176
+ const arrayName = GLTF_KEYS[key];
177
+ if (arrayName in this.idToIndexMap) {
178
+ const index = this.idToIndexMap[arrayName][id];
179
+ if (!Number.isFinite(index)) {
180
+ throw new Error("gltf v1: failed to resolve ".concat(key, " with id ").concat(id));
181
+ }
182
+ return index;
183
+ }
184
+ return id;
185
+ }
186
+ _updateObjects(json) {
187
+ for (const buffer of this.json.buffers) {
188
+ delete buffer.type;
189
+ }
190
+ }
191
+ _updateMaterial(json) {
192
+ for (const material of json.materials) {
193
+ var _material$values, _material$values2, _material$values3;
194
+ material.pbrMetallicRoughness = {
195
+ baseColorFactor: [1, 1, 1, 1],
196
+ metallicFactor: 1,
197
+ roughnessFactor: 1
198
+ };
199
+ const textureId = ((_material$values = material.values) === null || _material$values === void 0 ? void 0 : _material$values.tex) || ((_material$values2 = material.values) === null || _material$values2 === void 0 ? void 0 : _material$values2.texture2d_0) || ((_material$values3 = material.values) === null || _material$values3 === void 0 ? void 0 : _material$values3.diffuseTex);
200
+ const textureIndex = json.textures.findIndex(texture => texture.id === textureId);
201
+ if (textureIndex !== -1) {
202
+ material.pbrMetallicRoughness.baseColorTexture = {
203
+ index: textureIndex
314
204
  };
315
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
316
- _loop();
317
- }
318
- } catch (err) {
319
- _iterator8.e(err);
320
- } finally {
321
- _iterator8.f();
322
205
  }
323
206
  }
324
- }]);
325
- return GLTFV1Normalizer;
326
- }();
207
+ }
208
+ }
327
209
  function normalizeGLTFV1(gltf) {
328
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
210
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
329
211
  return new GLTFV1Normalizer().normalize(gltf, options);
330
212
  }
331
213
  //# sourceMappingURL=normalize-gltf-v1.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-gltf-v1.js","names":["KHR_binary_glTF","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","step","next","_e2","return","minLen","_arrayLikeToArray","toString","slice","constructor","name","from","test","arr","len","arr2","GLTF_ARRAYS","accessors","animations","buffers","bufferViews","images","materials","meshes","nodes","samplers","scenes","skins","textures","GLTF_KEYS","accessor","buffer","bufferView","image","material","mesh","node","sampler","scene","skin","texture","GLTFV1Normalizer","_classCallCheck2","_defineProperty2","_createClass2","normalize","gltf","options","json","asset","version","undefined","console","warn","concat","Error","_addAsset","_convertTopLevelObjectsToArrays","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","id","object","index","push","idToIndexMap","_convertIdsToIndices","_convertIdToIndex","_iterator","_step","_convertTextureIds","_iterator2","_step2","_convertMeshIds","_iterator3","_step3","_convertNodeIds","_iterator4","_step4","_convertSceneIds","source","_iterator5","primitives","_step5","primitive","attributes","indices","attributeName","_this","children","map","child","_this2","topLevelArrayName","_iterator6","_step6","Number","isFinite","_iterator7","_step7","type","_iterator8","_step8","_loop","_material$values","_material$values2","_material$values3","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","texture2d_0","diffuseTex","textureIndex","findIndex","baseColorTexture","normalizeGLTFV1","arguments"],"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';\n\n// Binary format changes (mainly implemented by GLBLoader)\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n\n// JSON format changes:\n// https://github.com/khronosgroup/gltf/issues/605\n\n// - [x] Top-level JSON objects are arrays now\n// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712\n// - [ ] material.parameter.value and technique.parameter.value must be an array, #690\n// - [ ] Node can have only one mesh #821\n// - [ ] Added reqs on JSON encoding\n// - [ ] Added reqs on binary data alignment #802 (comment)\n\n// Additions:\n// - [ ] Added accessor.normalized, #691, #706\n// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619\n// - [ ] Added extensionsRequired property, #720, #721\n// - [ ] Added \"STEP\" as valid animation.sampler.interpolation value, #712\n\n// Removals:\n// - [x] Removed buffer.type, #786, #629\n// - [ ] Removed revision number from profile.version, #709\n// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681\n// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.\n\n// Other edits:\n// - [x] asset is now required, #642\n// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.\n// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.\n// - [ ] Clarified animation.sampler and animation.channel restrictions, #712\n// - [ ] skin.inverseBindMatrices is now optional, #461.\n// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).\n// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).\n// - [ ] TEXCOORD and COLOR attribute semantics must be written in the form [semantic]_[set_index], e.g., just TEXCOORD should be TEXCOORD_0, and just COLOR should be COLOR_0, #649\n// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).\n// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).\n// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,\n\n// #563 (comment).\n// - [ ] technique.parameter.count can only be defined when the semantic is JOINTMATRIX or an application-specific semantic is used. It can never be defined for attribute parameters; only uniforms, d2f6945\n// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d\n// - [ ] Mesh-only models are allowed, e.g., without materials, #642\n// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647\n// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707\n\nconst GLTF_ARRAYS = {\n accessors: 'accessor',\n animations: 'animation',\n buffers: 'buffer',\n bufferViews: 'bufferView',\n images: 'image',\n materials: 'material',\n meshes: 'mesh',\n nodes: 'node',\n samplers: 'sampler',\n scenes: 'scene',\n skins: 'skin',\n textures: 'texture'\n};\n\nconst GLTF_KEYS = {\n accessor: 'accessors',\n animations: 'animation',\n buffer: 'buffers',\n bufferView: 'bufferViews',\n image: 'images',\n material: 'materials',\n mesh: 'meshes',\n node: 'nodes',\n sampler: 'samplers',\n scene: 'scenes',\n skin: 'skins',\n texture: 'textures'\n};\n\n/**\n * Converts (normalizes) glTF v1 to v2\n */\nclass GLTFV1Normalizer {\n idToIndexMap = {\n animations: {},\n accessors: {},\n buffers: {},\n bufferViews: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n samplers: {},\n scenes: {},\n skins: {},\n textures: {}\n };\n\n json;\n\n // constructor() {}\n\n /**\n * Convert (normalize) glTF < 2.0 to glTF 2.0\n * @param gltf - object with json and binChunks\n * @param options\n * @param options normalize Whether to actually normalize\n */\n normalize(gltf, options) {\n this.json = gltf.json;\n const json = gltf.json;\n\n // Check version\n switch (json.asset && json.asset.version) {\n // We are converting to v2 format. Return if there is nothing to do\n case '2.0':\n return;\n\n // This class is written to convert 1.0\n case undefined:\n case '1.0':\n break;\n\n default:\n // eslint-disable-next-line no-undef, no-console\n console.warn(`glTF: Unknown version ${json.asset.version}`);\n return;\n }\n\n if (!options.normalize) {\n // We are still missing a few conversion tricks, remove once addressed\n throw new Error('glTF v1 is not supported.');\n }\n\n // eslint-disable-next-line no-undef, no-console\n console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');\n\n this._addAsset(json);\n\n // In glTF2 top-level fields are Arrays not Object maps\n this._convertTopLevelObjectsToArrays(json);\n\n // Extract bufferView indices for images\n // (this extension needs to be invoked early in the normalization process)\n // TODO can this be handled by standard extension processing instead of called explicitly?\n KHR_binary_glTF.preprocess(gltf);\n\n // Convert object references from ids to indices\n this._convertObjectIdsToArrayIndices(json);\n\n this._updateObjects(json);\n\n this._updateMaterial(json);\n }\n\n // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639\n _addAsset(json) {\n json.asset = json.asset || {};\n // We are normalizing to glTF v2, so change version to \"2.0\"\n json.asset.version = '2.0';\n json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';\n }\n\n _convertTopLevelObjectsToArrays(json) {\n // TODO check that all arrays are covered\n for (const arrayName in GLTF_ARRAYS) {\n this._convertTopLevelObjectToArray(json, arrayName);\n }\n }\n\n /** Convert one top level object to array */\n _convertTopLevelObjectToArray(json, mapName) {\n const objectMap = json[mapName];\n if (!objectMap || Array.isArray(objectMap)) {\n return;\n }\n\n // Rewrite the top-level field as an array\n json[mapName] = [];\n // Copy the map key into object.id\n for (const id in objectMap) {\n const object = objectMap[id];\n object.id = object.id || id; // Mutates the loaded object\n const index = json[mapName].length;\n json[mapName].push(object);\n this.idToIndexMap[mapName][id] = index;\n }\n }\n\n /** Go through all objects in all top-level arrays and replace ids with indices */\n _convertObjectIdsToArrayIndices(json) {\n for (const arrayName in GLTF_ARRAYS) {\n this._convertIdsToIndices(json, arrayName);\n }\n if ('scene' in json) {\n json.scene = this._convertIdToIndex(json.scene, 'scene');\n }\n\n // Convert any index references that are not using array names\n\n // texture.source (image)\n for (const texture of json.textures) {\n this._convertTextureIds(texture);\n }\n for (const mesh of json.meshes) {\n this._convertMeshIds(mesh);\n }\n for (const node of json.nodes) {\n this._convertNodeIds(node);\n }\n for (const node of json.scenes) {\n this._convertSceneIds(node);\n }\n }\n\n _convertTextureIds(texture) {\n if (texture.source) {\n texture.source = this._convertIdToIndex(texture.source, 'image');\n }\n }\n\n _convertMeshIds(mesh) {\n for (const primitive of mesh.primitives) {\n const {attributes, indices, material} = primitive;\n for (const attributeName in attributes) {\n attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');\n }\n if (indices) {\n primitive.indices = this._convertIdToIndex(indices, 'accessor');\n }\n if (material) {\n primitive.material = this._convertIdToIndex(material, 'material');\n }\n }\n }\n\n _convertNodeIds(node) {\n if (node.children) {\n node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));\n }\n if (node.meshes) {\n node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));\n }\n }\n\n _convertSceneIds(scene) {\n if (scene.nodes) {\n scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));\n }\n }\n\n /** Go through all objects in a top-level array and replace ids with indices */\n _convertIdsToIndices(json, topLevelArrayName) {\n if (!json[topLevelArrayName]) {\n console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef\n json[topLevelArrayName] = [];\n }\n for (const object of json[topLevelArrayName]) {\n for (const key in object) {\n const id = object[key];\n const index = this._convertIdToIndex(id, key);\n object[key] = index;\n }\n }\n }\n\n _convertIdToIndex(id, key) {\n const arrayName = GLTF_KEYS[key];\n if (arrayName in this.idToIndexMap) {\n const index = this.idToIndexMap[arrayName][id];\n if (!Number.isFinite(index)) {\n throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);\n }\n return index;\n }\n return id;\n }\n\n /**\n *\n * @param {*} json\n */\n _updateObjects(json) {\n for (const buffer of this.json.buffers) {\n // - [x] Removed buffer.type, #786, #629\n delete buffer.type;\n }\n }\n\n /**\n * Update material (set pbrMetallicRoughness)\n * @param {*} json\n */\n _updateMaterial(json) {\n for (const material of json.materials) {\n material.pbrMetallicRoughness = {\n baseColorFactor: [1, 1, 1, 1],\n metallicFactor: 1,\n roughnessFactor: 1\n };\n\n const textureId =\n material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;\n const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);\n if (textureIndex !== -1) {\n material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};\n }\n }\n }\n}\n\nexport function normalizeGLTFV1(gltf, options = {}) {\n return new GLTFV1Normalizer().normalize(gltf, options);\n}\n"],"mappings":";;;;;;;;;;;AACA,IAAAA,eAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAiE,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,aAAAE,OAAA,CAAAF,GAAA,yBAAAA,GAAA,4BAAAG,OAAA,EAAAH,GAAA,UAAAI,KAAA,GAAAT,wBAAA,CAAAC,WAAA,OAAAQ,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAL,GAAA,YAAAI,KAAA,CAAAE,GAAA,CAAAN,GAAA,SAAAO,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAZ,GAAA,QAAAY,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAf,GAAA,EAAAY,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAX,GAAA,EAAAY,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eAAeA,CAAC/E,IAAI,EAAgB;EAAA,IAAdC,OAAO,GAAA+E,SAAA,CAAA3I,MAAA,QAAA2I,SAAA,QAAA3E,SAAA,GAAA2E,SAAA,MAAG,CAAC,CAAC;EAChD,OAAO,IAAIrF,gBAAgB,CAAC,CAAC,CAACI,SAAS,CAACC,IAAI,EAAEC,OAAO,CAAC;AACxD"}
1
+ {"version":3,"file":"normalize-gltf-v1.js","names":["KHR_binary_glTF","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","GLTF_ARRAYS","accessors","animations","buffers","bufferViews","images","materials","meshes","nodes","samplers","scenes","skins","textures","GLTF_KEYS","accessor","buffer","bufferView","image","material","mesh","node","sampler","scene","skin","texture","GLTFV1Normalizer","constructor","_defineProperty2","normalize","gltf","options","json","asset","version","undefined","console","warn","concat","Error","_addAsset","_convertTopLevelObjectsToArrays","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","Array","isArray","id","object","index","length","push","idToIndexMap","_convertIdsToIndices","_convertIdToIndex","_convertTextureIds","_convertMeshIds","_convertNodeIds","_convertSceneIds","source","primitive","primitives","attributes","indices","attributeName","children","map","child","topLevelArrayName","Number","isFinite","type","_material$values","_material$values2","_material$values3","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","texture2d_0","diffuseTex","textureIndex","findIndex","baseColorTexture","normalizeGLTFV1","arguments"],"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport * as KHR_binary_glTF from '../extensions/KHR_binary_gltf';\n\n// Binary format changes (mainly implemented by GLBLoader)\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n\n// JSON format changes:\n// https://github.com/khronosgroup/gltf/issues/605\n\n// - [x] Top-level JSON objects are arrays now\n// - [ ] Removed indirection from animation: sampler now refers directly to accessors, #712\n// - [ ] material.parameter.value and technique.parameter.value must be an array, #690\n// - [ ] Node can have only one mesh #821\n// - [ ] Added reqs on JSON encoding\n// - [ ] Added reqs on binary data alignment #802 (comment)\n\n// Additions:\n// - [ ] Added accessor.normalized, #691, #706\n// - [ ] Added glExtensionsUsed property and 5125 (UNSIGNED_INT) accessor.componentType value, #619\n// - [ ] Added extensionsRequired property, #720, #721\n// - [ ] Added \"STEP\" as valid animation.sampler.interpolation value, #712\n\n// Removals:\n// - [x] Removed buffer.type, #786, #629\n// - [ ] Removed revision number from profile.version, #709\n// - [ ] Removed technique.functions.scissor and removed 3089 (SCISSOR_TEST) as a valid value for technique.states.enable, #681\n// - [ ] Techniques, programs, and shaders were moved out to KHR_technique_webgl extension.\n\n// Other edits:\n// - [x] asset is now required, #642\n// - [ ] buffer.byteLength and bufferView.byteLength are now required, #560.\n// - [ ] accessor.min and accessor.max are now required, #593, and clarified that the JSON value and binary data must be the same, #628.\n// - [ ] Clarified animation.sampler and animation.channel restrictions, #712\n// - [ ] skin.inverseBindMatrices is now optional, #461.\n// - [ ] Attribute parameters can't have a value defined in the technique or parameter, #563 (comment).\n// - [ ] Only TEXCOORD and COLOR attribute semantics can be written in the form [semantic]_[set_index], #563 (comment).\n// - [ ] TEXCOORD and COLOR attribute semantics must be written in the form [semantic]_[set_index], e.g., just TEXCOORD should be TEXCOORD_0, and just COLOR should be COLOR_0, #649\n// - [ ] camera.perspective.aspectRatio and camera.perspective.yfov must now be > 0, not >= 0, #563 (comment).\n// - [ ] Application-specific parameter semantics must start with an underscore, e.g., _TEMPERATURE and _SIMULATION_TIME, #563 (comment).\n// - [ ] Properties in technique.parameters must be defined in technique.uniforms or technique.attributes,\n\n// #563 (comment).\n// - [ ] technique.parameter.count can only be defined when the semantic is JOINTMATRIX or an application-specific semantic is used. It can never be defined for attribute parameters; only uniforms, d2f6945\n// - [ ] technique.parameter.semantic is required when the parameter is an attribute, 28e113d\n// - [ ] Mesh-only models are allowed, e.g., without materials, #642\n// - [ ] Skeleton hierarchies (nodes containing jointName) must be separated from non-skeleton hierarchies., #647\n// - [ ] technique.states.functions.blendColor and technique.states.functions.depthRange parameters now must match WebGL function min/max, #707\n\nconst GLTF_ARRAYS = {\n accessors: 'accessor',\n animations: 'animation',\n buffers: 'buffer',\n bufferViews: 'bufferView',\n images: 'image',\n materials: 'material',\n meshes: 'mesh',\n nodes: 'node',\n samplers: 'sampler',\n scenes: 'scene',\n skins: 'skin',\n textures: 'texture'\n};\n\nconst GLTF_KEYS = {\n accessor: 'accessors',\n animations: 'animation',\n buffer: 'buffers',\n bufferView: 'bufferViews',\n image: 'images',\n material: 'materials',\n mesh: 'meshes',\n node: 'nodes',\n sampler: 'samplers',\n scene: 'scenes',\n skin: 'skins',\n texture: 'textures'\n};\n\n/**\n * Converts (normalizes) glTF v1 to v2\n */\nclass GLTFV1Normalizer {\n idToIndexMap = {\n animations: {},\n accessors: {},\n buffers: {},\n bufferViews: {},\n images: {},\n materials: {},\n meshes: {},\n nodes: {},\n samplers: {},\n scenes: {},\n skins: {},\n textures: {}\n };\n\n json;\n\n // constructor() {}\n\n /**\n * Convert (normalize) glTF < 2.0 to glTF 2.0\n * @param gltf - object with json and binChunks\n * @param options\n * @param options normalize Whether to actually normalize\n */\n normalize(gltf, options) {\n this.json = gltf.json;\n const json = gltf.json;\n\n // Check version\n switch (json.asset && json.asset.version) {\n // We are converting to v2 format. Return if there is nothing to do\n case '2.0':\n return;\n\n // This class is written to convert 1.0\n case undefined:\n case '1.0':\n break;\n\n default:\n // eslint-disable-next-line no-undef, no-console\n console.warn(`glTF: Unknown version ${json.asset.version}`);\n return;\n }\n\n if (!options.normalize) {\n // We are still missing a few conversion tricks, remove once addressed\n throw new Error('glTF v1 is not supported.');\n }\n\n // eslint-disable-next-line no-undef, no-console\n console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');\n\n this._addAsset(json);\n\n // In glTF2 top-level fields are Arrays not Object maps\n this._convertTopLevelObjectsToArrays(json);\n\n // Extract bufferView indices for images\n // (this extension needs to be invoked early in the normalization process)\n // TODO can this be handled by standard extension processing instead of called explicitly?\n KHR_binary_glTF.preprocess(gltf);\n\n // Convert object references from ids to indices\n this._convertObjectIdsToArrayIndices(json);\n\n this._updateObjects(json);\n\n this._updateMaterial(json);\n }\n\n // asset is now required, #642 https://github.com/KhronosGroup/glTF/issues/639\n _addAsset(json) {\n json.asset = json.asset || {};\n // We are normalizing to glTF v2, so change version to \"2.0\"\n json.asset.version = '2.0';\n json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';\n }\n\n _convertTopLevelObjectsToArrays(json) {\n // TODO check that all arrays are covered\n for (const arrayName in GLTF_ARRAYS) {\n this._convertTopLevelObjectToArray(json, arrayName);\n }\n }\n\n /** Convert one top level object to array */\n _convertTopLevelObjectToArray(json, mapName) {\n const objectMap = json[mapName];\n if (!objectMap || Array.isArray(objectMap)) {\n return;\n }\n\n // Rewrite the top-level field as an array\n json[mapName] = [];\n // Copy the map key into object.id\n for (const id in objectMap) {\n const object = objectMap[id];\n object.id = object.id || id; // Mutates the loaded object\n const index = json[mapName].length;\n json[mapName].push(object);\n this.idToIndexMap[mapName][id] = index;\n }\n }\n\n /** Go through all objects in all top-level arrays and replace ids with indices */\n _convertObjectIdsToArrayIndices(json) {\n for (const arrayName in GLTF_ARRAYS) {\n this._convertIdsToIndices(json, arrayName);\n }\n if ('scene' in json) {\n json.scene = this._convertIdToIndex(json.scene, 'scene');\n }\n\n // Convert any index references that are not using array names\n\n // texture.source (image)\n for (const texture of json.textures) {\n this._convertTextureIds(texture);\n }\n for (const mesh of json.meshes) {\n this._convertMeshIds(mesh);\n }\n for (const node of json.nodes) {\n this._convertNodeIds(node);\n }\n for (const node of json.scenes) {\n this._convertSceneIds(node);\n }\n }\n\n _convertTextureIds(texture) {\n if (texture.source) {\n texture.source = this._convertIdToIndex(texture.source, 'image');\n }\n }\n\n _convertMeshIds(mesh) {\n for (const primitive of mesh.primitives) {\n const {attributes, indices, material} = primitive;\n for (const attributeName in attributes) {\n attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');\n }\n if (indices) {\n primitive.indices = this._convertIdToIndex(indices, 'accessor');\n }\n if (material) {\n primitive.material = this._convertIdToIndex(material, 'material');\n }\n }\n }\n\n _convertNodeIds(node) {\n if (node.children) {\n node.children = node.children.map((child) => this._convertIdToIndex(child, 'node'));\n }\n if (node.meshes) {\n node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, 'mesh'));\n }\n }\n\n _convertSceneIds(scene) {\n if (scene.nodes) {\n scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, 'node'));\n }\n }\n\n /** Go through all objects in a top-level array and replace ids with indices */\n _convertIdsToIndices(json, topLevelArrayName) {\n if (!json[topLevelArrayName]) {\n console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`); // eslint-disable-line no-console, no-undef\n json[topLevelArrayName] = [];\n }\n for (const object of json[topLevelArrayName]) {\n for (const key in object) {\n const id = object[key];\n const index = this._convertIdToIndex(id, key);\n object[key] = index;\n }\n }\n }\n\n _convertIdToIndex(id, key) {\n const arrayName = GLTF_KEYS[key];\n if (arrayName in this.idToIndexMap) {\n const index = this.idToIndexMap[arrayName][id];\n if (!Number.isFinite(index)) {\n throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);\n }\n return index;\n }\n return id;\n }\n\n /**\n *\n * @param {*} json\n */\n _updateObjects(json) {\n for (const buffer of this.json.buffers) {\n // - [x] Removed buffer.type, #786, #629\n delete buffer.type;\n }\n }\n\n /**\n * Update material (set pbrMetallicRoughness)\n * @param {*} json\n */\n _updateMaterial(json) {\n for (const material of json.materials) {\n material.pbrMetallicRoughness = {\n baseColorFactor: [1, 1, 1, 1],\n metallicFactor: 1,\n roughnessFactor: 1\n };\n\n const textureId =\n material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;\n const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);\n if (textureIndex !== -1) {\n material.pbrMetallicRoughness.baseColorTexture = {index: textureIndex};\n }\n }\n }\n}\n\nexport function normalizeGLTFV1(gltf, options = {}) {\n return new GLTFV1Normalizer().normalize(gltf, options);\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,eAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAiE,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAA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