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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/bundle.js +10 -7
  2. package/dist/es5/bundle.js +1 -1
  3. package/dist/es5/bundle.js.map +1 -1
  4. package/dist/es5/glb-loader.js +33 -10
  5. package/dist/es5/glb-loader.js.map +1 -1
  6. package/dist/es5/glb-writer.js +8 -9
  7. package/dist/es5/glb-writer.js.map +1 -1
  8. package/dist/es5/gltf-loader.js +52 -14
  9. package/dist/es5/gltf-loader.js.map +1 -1
  10. package/dist/es5/gltf-writer.js +10 -10
  11. package/dist/es5/gltf-writer.js.map +1 -1
  12. package/dist/es5/index.js +6 -6
  13. package/dist/es5/index.js.map +1 -1
  14. package/dist/es5/lib/api/gltf-extensions.js +106 -18
  15. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  16. package/dist/es5/lib/api/gltf-scenegraph.js +541 -447
  17. package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
  18. package/dist/es5/lib/api/normalize-gltf-v1.js +278 -150
  19. package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
  20. package/dist/es5/lib/api/post-process-gltf.js +367 -293
  21. package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
  22. package/dist/es5/lib/encoders/encode-glb.js +22 -19
  23. package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
  24. package/dist/es5/lib/encoders/encode-gltf.js +5 -3
  25. package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
  26. package/dist/es5/lib/extensions/EXT_meshopt_compression.js +104 -39
  27. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  28. package/dist/es5/lib/extensions/EXT_texture_webp.js +26 -12
  29. package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
  30. package/dist/es5/lib/extensions/KHR_binary_gltf.js +26 -12
  31. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
  32. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +261 -76
  33. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  34. package/dist/es5/lib/extensions/KHR_texture_basisu.js +26 -12
  35. package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
  36. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +104 -40
  37. package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
  38. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +69 -24
  39. package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
  40. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +90 -34
  41. package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
  42. package/dist/es5/lib/gltf-utils/get-typed-array.js +6 -6
  43. package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -1
  44. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +21 -19
  45. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
  46. package/dist/es5/lib/gltf-utils/gltf-constants.js +7 -7
  47. package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
  48. package/dist/es5/lib/gltf-utils/gltf-utils.js +16 -16
  49. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  50. package/dist/es5/lib/gltf-utils/resolve-url.js +2 -2
  51. package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
  52. package/dist/es5/lib/parsers/parse-glb.js +38 -34
  53. package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
  54. package/dist/es5/lib/parsers/parse-gltf.js +266 -106
  55. package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
  56. package/dist/es5/lib/utils/version.js +1 -1
  57. package/dist/es5/lib/utils/version.js.map +1 -1
  58. package/dist/es5/meshopt/meshopt-decoder.js +197 -46
  59. package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
  60. package/dist/es5/webp/webp.js +84 -16
  61. package/dist/es5/webp/webp.js.map +1 -1
  62. package/dist/esm/index.js.map +1 -1
  63. package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
  64. package/dist/esm/lib/api/post-process-gltf.js +7 -4
  65. package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
  66. package/dist/esm/lib/parsers/parse-gltf.js +1 -1
  67. package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
  68. package/dist/esm/lib/utils/version.js +1 -1
  69. package/dist/esm/lib/utils/version.js.map +1 -1
  70. package/dist/index.d.ts +1 -1
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/lib/api/gltf-scenegraph.d.ts +4 -4
  73. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
  74. package/dist/lib/api/post-process-gltf.d.ts +1 -1
  75. package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
  76. package/dist/lib/api/post-process-gltf.js +7 -4
  77. package/dist/lib/parsers/parse-gltf.js +1 -1
  78. package/dist/lib/types/gltf-postprocessed-schema.d.ts +3 -2
  79. package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
  80. package/dist/lib/types/gltf-types.d.ts +2 -1
  81. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  82. package/package.json +6 -6
  83. package/src/index.ts +1 -0
  84. package/src/lib/api/gltf-scenegraph.ts +2 -2
  85. package/src/lib/api/post-process-gltf.ts +11 -6
  86. package/src/lib/parsers/parse-gltf.ts +1 -1
  87. package/src/lib/types/gltf-postprocessed-schema.ts +3 -2
  88. package/src/lib/types/gltf-types.ts +4 -1
@@ -2,20 +2,32 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
8
10
  exports.normalizeGLTFV1 = normalizeGLTFV1;
9
11
 
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
10
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
17
 
12
18
  var KHR_binary_glTF = _interopRequireWildcard(require("../extensions/KHR_binary_gltf"));
13
19
 
14
- 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); }
20
+ 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); }
21
+
22
+ 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; }
23
+
24
+ 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; } } }; }
15
25
 
16
- 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; }
26
+ 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
27
 
18
- const GLTF_ARRAYS = {
28
+ 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; }
29
+
30
+ var GLTF_ARRAYS = {
19
31
  accessors: 'accessor',
20
32
  animations: 'animation',
21
33
  buffers: 'buffer',
@@ -29,7 +41,7 @@ const GLTF_ARRAYS = {
29
41
  skins: 'skin',
30
42
  textures: 'texture'
31
43
  };
32
- const GLTF_KEYS = {
44
+ var GLTF_KEYS = {
33
45
  accessor: 'accessors',
34
46
  animations: 'animation',
35
47
  buffer: 'buffers',
@@ -44,8 +56,9 @@ const GLTF_KEYS = {
44
56
  texture: 'textures'
45
57
  };
46
58
 
47
- class GLTFV1Normalizer {
48
- constructor() {
59
+ var GLTFV1Normalizer = function () {
60
+ function GLTFV1Normalizer() {
61
+ (0, _classCallCheck2.default)(this, GLTFV1Normalizer);
49
62
  (0, _defineProperty2.default)(this, "idToIndexMap", {
50
63
  animations: {},
51
64
  accessors: {},
@@ -63,202 +76,317 @@ class GLTFV1Normalizer {
63
76
  (0, _defineProperty2.default)(this, "json", void 0);
64
77
  }
65
78
 
66
- normalize(gltf, options) {
67
- this.json = gltf.json;
68
- const json = gltf.json;
79
+ (0, _createClass2.default)(GLTFV1Normalizer, [{
80
+ key: "normalize",
81
+ value: function normalize(gltf, options) {
82
+ this.json = gltf.json;
83
+ var json = gltf.json;
69
84
 
70
- switch (json.asset && json.asset.version) {
71
- case '2.0':
72
- return;
85
+ switch (json.asset && json.asset.version) {
86
+ case '2.0':
87
+ return;
73
88
 
74
- case undefined:
75
- case '1.0':
76
- break;
89
+ case undefined:
90
+ case '1.0':
91
+ break;
77
92
 
78
- default:
79
- console.warn("glTF: Unknown version ".concat(json.asset.version));
80
- return;
81
- }
93
+ default:
94
+ console.warn("glTF: Unknown version ".concat(json.asset.version));
95
+ return;
96
+ }
82
97
 
83
- if (!options.normalize) {
84
- throw new Error('glTF v1 is not supported.');
85
- }
98
+ if (!options.normalize) {
99
+ throw new Error('glTF v1 is not supported.');
100
+ }
86
101
 
87
- console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');
102
+ console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');
88
103
 
89
- this._addAsset(json);
104
+ this._addAsset(json);
90
105
 
91
- this._convertTopLevelObjectsToArrays(json);
106
+ this._convertTopLevelObjectsToArrays(json);
92
107
 
93
- KHR_binary_glTF.preprocess(gltf);
108
+ KHR_binary_glTF.preprocess(gltf);
94
109
 
95
- this._convertObjectIdsToArrayIndices(json);
110
+ this._convertObjectIdsToArrayIndices(json);
96
111
 
97
- this._updateObjects(json);
112
+ this._updateObjects(json);
98
113
 
99
- this._updateMaterial(json);
100
- }
114
+ this._updateMaterial(json);
115
+ }
116
+ }, {
117
+ key: "_addAsset",
118
+ value: function _addAsset(json) {
119
+ json.asset = json.asset || {};
120
+ json.asset.version = '2.0';
121
+ json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
122
+ }
123
+ }, {
124
+ key: "_convertTopLevelObjectsToArrays",
125
+ value: function _convertTopLevelObjectsToArrays(json) {
126
+ for (var arrayName in GLTF_ARRAYS) {
127
+ this._convertTopLevelObjectToArray(json, arrayName);
128
+ }
129
+ }
130
+ }, {
131
+ key: "_convertTopLevelObjectToArray",
132
+ value: function _convertTopLevelObjectToArray(json, mapName) {
133
+ var objectMap = json[mapName];
101
134
 
102
- _addAsset(json) {
103
- json.asset = json.asset || {};
104
- json.asset.version = '2.0';
105
- json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
106
- }
135
+ if (!objectMap || Array.isArray(objectMap)) {
136
+ return;
137
+ }
138
+
139
+ json[mapName] = [];
107
140
 
108
- _convertTopLevelObjectsToArrays(json) {
109
- for (const arrayName in GLTF_ARRAYS) {
110
- this._convertTopLevelObjectToArray(json, arrayName);
141
+ for (var id in objectMap) {
142
+ var object = objectMap[id];
143
+ object.id = object.id || id;
144
+ var index = json[mapName].length;
145
+ json[mapName].push(object);
146
+ this.idToIndexMap[mapName][id] = index;
147
+ }
111
148
  }
112
- }
149
+ }, {
150
+ key: "_convertObjectIdsToArrayIndices",
151
+ value: function _convertObjectIdsToArrayIndices(json) {
152
+ for (var arrayName in GLTF_ARRAYS) {
153
+ this._convertIdsToIndices(json, arrayName);
154
+ }
113
155
 
114
- _convertTopLevelObjectToArray(json, mapName) {
115
- const objectMap = json[mapName];
156
+ if ('scene' in json) {
157
+ json.scene = this._convertIdToIndex(json.scene, 'scene');
158
+ }
116
159
 
117
- if (!objectMap || Array.isArray(objectMap)) {
118
- return;
119
- }
160
+ var _iterator = _createForOfIteratorHelper(json.textures),
161
+ _step;
120
162
 
121
- json[mapName] = [];
163
+ try {
164
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
165
+ var texture = _step.value;
122
166
 
123
- for (const id in objectMap) {
124
- const object = objectMap[id];
125
- object.id = object.id || id;
126
- const index = json[mapName].length;
127
- json[mapName].push(object);
128
- this.idToIndexMap[mapName][id] = index;
129
- }
130
- }
167
+ this._convertTextureIds(texture);
168
+ }
169
+ } catch (err) {
170
+ _iterator.e(err);
171
+ } finally {
172
+ _iterator.f();
173
+ }
131
174
 
132
- _convertObjectIdsToArrayIndices(json) {
133
- for (const arrayName in GLTF_ARRAYS) {
134
- this._convertIdsToIndices(json, arrayName);
135
- }
175
+ var _iterator2 = _createForOfIteratorHelper(json.meshes),
176
+ _step2;
136
177
 
137
- if ('scene' in json) {
138
- json.scene = this._convertIdToIndex(json.scene, 'scene');
139
- }
178
+ try {
179
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
180
+ var mesh = _step2.value;
140
181
 
141
- for (const texture of json.textures) {
142
- this._convertTextureIds(texture);
143
- }
182
+ this._convertMeshIds(mesh);
183
+ }
184
+ } catch (err) {
185
+ _iterator2.e(err);
186
+ } finally {
187
+ _iterator2.f();
188
+ }
144
189
 
145
- for (const mesh of json.meshes) {
146
- this._convertMeshIds(mesh);
147
- }
190
+ var _iterator3 = _createForOfIteratorHelper(json.nodes),
191
+ _step3;
148
192
 
149
- for (const node of json.nodes) {
150
- this._convertNodeIds(node);
151
- }
193
+ try {
194
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
195
+ var node = _step3.value;
152
196
 
153
- for (const node of json.scenes) {
154
- this._convertSceneIds(node);
155
- }
156
- }
197
+ this._convertNodeIds(node);
198
+ }
199
+ } catch (err) {
200
+ _iterator3.e(err);
201
+ } finally {
202
+ _iterator3.f();
203
+ }
157
204
 
158
- _convertTextureIds(texture) {
159
- if (texture.source) {
160
- texture.source = this._convertIdToIndex(texture.source, 'image');
161
- }
162
- }
205
+ var _iterator4 = _createForOfIteratorHelper(json.scenes),
206
+ _step4;
163
207
 
164
- _convertMeshIds(mesh) {
165
- for (const primitive of mesh.primitives) {
166
- const {
167
- attributes,
168
- indices,
169
- material
170
- } = primitive;
208
+ try {
209
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
210
+ var _node = _step4.value;
171
211
 
172
- for (const attributeName in attributes) {
173
- attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
212
+ this._convertSceneIds(_node);
213
+ }
214
+ } catch (err) {
215
+ _iterator4.e(err);
216
+ } finally {
217
+ _iterator4.f();
174
218
  }
175
-
176
- if (indices) {
177
- primitive.indices = this._convertIdToIndex(indices, 'accessor');
219
+ }
220
+ }, {
221
+ key: "_convertTextureIds",
222
+ value: function _convertTextureIds(texture) {
223
+ if (texture.source) {
224
+ texture.source = this._convertIdToIndex(texture.source, 'image');
178
225
  }
179
-
180
- if (material) {
181
- primitive.material = this._convertIdToIndex(material, 'material');
226
+ }
227
+ }, {
228
+ key: "_convertMeshIds",
229
+ value: function _convertMeshIds(mesh) {
230
+ var _iterator5 = _createForOfIteratorHelper(mesh.primitives),
231
+ _step5;
232
+
233
+ try {
234
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
235
+ var primitive = _step5.value;
236
+ var attributes = primitive.attributes,
237
+ indices = primitive.indices,
238
+ material = primitive.material;
239
+
240
+ for (var attributeName in attributes) {
241
+ attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
242
+ }
243
+
244
+ if (indices) {
245
+ primitive.indices = this._convertIdToIndex(indices, 'accessor');
246
+ }
247
+
248
+ if (material) {
249
+ primitive.material = this._convertIdToIndex(material, 'material');
250
+ }
251
+ }
252
+ } catch (err) {
253
+ _iterator5.e(err);
254
+ } finally {
255
+ _iterator5.f();
182
256
  }
183
257
  }
184
- }
258
+ }, {
259
+ key: "_convertNodeIds",
260
+ value: function _convertNodeIds(node) {
261
+ var _this = this;
262
+
263
+ if (node.children) {
264
+ node.children = node.children.map(function (child) {
265
+ return _this._convertIdToIndex(child, 'node');
266
+ });
267
+ }
185
268
 
186
- _convertNodeIds(node) {
187
- if (node.children) {
188
- node.children = node.children.map(child => this._convertIdToIndex(child, 'node'));
269
+ if (node.meshes) {
270
+ node.meshes = node.meshes.map(function (mesh) {
271
+ return _this._convertIdToIndex(mesh, 'mesh');
272
+ });
273
+ }
189
274
  }
190
-
191
- if (node.meshes) {
192
- node.meshes = node.meshes.map(mesh => this._convertIdToIndex(mesh, 'mesh'));
275
+ }, {
276
+ key: "_convertSceneIds",
277
+ value: function _convertSceneIds(scene) {
278
+ var _this2 = this;
279
+
280
+ if (scene.nodes) {
281
+ scene.nodes = scene.nodes.map(function (node) {
282
+ return _this2._convertIdToIndex(node, 'node');
283
+ });
284
+ }
193
285
  }
194
- }
286
+ }, {
287
+ key: "_convertIdsToIndices",
288
+ value: function _convertIdsToIndices(json, topLevelArrayName) {
289
+ if (!json[topLevelArrayName]) {
290
+ console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));
291
+ json[topLevelArrayName] = [];
292
+ }
195
293
 
196
- _convertSceneIds(scene) {
197
- if (scene.nodes) {
198
- scene.nodes = scene.nodes.map(node => this._convertIdToIndex(node, 'node'));
199
- }
200
- }
294
+ var _iterator6 = _createForOfIteratorHelper(json[topLevelArrayName]),
295
+ _step6;
201
296
 
202
- _convertIdsToIndices(json, topLevelArrayName) {
203
- if (!json[topLevelArrayName]) {
204
- console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));
205
- json[topLevelArrayName] = [];
206
- }
297
+ try {
298
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
299
+ var object = _step6.value;
207
300
 
208
- for (const object of json[topLevelArrayName]) {
209
- for (const key in object) {
210
- const id = object[key];
301
+ for (var key in object) {
302
+ var id = object[key];
211
303
 
212
- const index = this._convertIdToIndex(id, key);
304
+ var index = this._convertIdToIndex(id, key);
213
305
 
214
- object[key] = index;
306
+ object[key] = index;
307
+ }
308
+ }
309
+ } catch (err) {
310
+ _iterator6.e(err);
311
+ } finally {
312
+ _iterator6.f();
215
313
  }
216
314
  }
217
- }
315
+ }, {
316
+ key: "_convertIdToIndex",
317
+ value: function _convertIdToIndex(id, key) {
318
+ var arrayName = GLTF_KEYS[key];
218
319
 
219
- _convertIdToIndex(id, key) {
220
- const arrayName = GLTF_KEYS[key];
320
+ if (arrayName in this.idToIndexMap) {
321
+ var index = this.idToIndexMap[arrayName][id];
221
322
 
222
- if (arrayName in this.idToIndexMap) {
223
- const index = this.idToIndexMap[arrayName][id];
323
+ if (!Number.isFinite(index)) {
324
+ throw new Error("gltf v1: failed to resolve ".concat(key, " with id ").concat(id));
325
+ }
224
326
 
225
- if (!Number.isFinite(index)) {
226
- throw new Error("gltf v1: failed to resolve ".concat(key, " with id ").concat(id));
327
+ return index;
227
328
  }
228
329
 
229
- return index;
330
+ return id;
230
331
  }
231
-
232
- return id;
233
- }
234
-
235
- _updateObjects(json) {
236
- for (const buffer of this.json.buffers) {
237
- delete buffer.type;
332
+ }, {
333
+ key: "_updateObjects",
334
+ value: function _updateObjects(json) {
335
+ var _iterator7 = _createForOfIteratorHelper(this.json.buffers),
336
+ _step7;
337
+
338
+ try {
339
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
340
+ var buffer = _step7.value;
341
+ delete buffer.type;
342
+ }
343
+ } catch (err) {
344
+ _iterator7.e(err);
345
+ } finally {
346
+ _iterator7.f();
347
+ }
238
348
  }
239
- }
240
-
241
- _updateMaterial(json) {
242
- for (const material of json.materials) {
243
- material.pbrMetallicRoughness = {
244
- baseColorFactor: [1, 1, 1, 1],
245
- metallicFactor: 1,
246
- roughnessFactor: 1
247
- };
248
- const textureId = material.values && material.values.tex;
249
- const textureIndex = json.textures.findIndex(texture => texture.id === textureId);
250
-
251
- if (textureIndex !== -1) {
252
- material.pbrMetallicRoughness.baseColorTexture = {
253
- index: textureIndex
349
+ }, {
350
+ key: "_updateMaterial",
351
+ value: function _updateMaterial(json) {
352
+ var _iterator8 = _createForOfIteratorHelper(json.materials),
353
+ _step8;
354
+
355
+ try {
356
+ var _loop = function _loop() {
357
+ var material = _step8.value;
358
+ material.pbrMetallicRoughness = {
359
+ baseColorFactor: [1, 1, 1, 1],
360
+ metallicFactor: 1,
361
+ roughnessFactor: 1
362
+ };
363
+ var textureId = material.values && material.values.tex;
364
+ var textureIndex = json.textures.findIndex(function (texture) {
365
+ return texture.id === textureId;
366
+ });
367
+
368
+ if (textureIndex !== -1) {
369
+ material.pbrMetallicRoughness.baseColorTexture = {
370
+ index: textureIndex
371
+ };
372
+ }
254
373
  };
374
+
375
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
376
+ _loop();
377
+ }
378
+ } catch (err) {
379
+ _iterator8.e(err);
380
+ } finally {
381
+ _iterator8.f();
255
382
  }
256
383
  }
257
- }
258
-
259
- }
384
+ }]);
385
+ return GLTFV1Normalizer;
386
+ }();
260
387
 
261
- function normalizeGLTFV1(gltf, options = {}) {
388
+ function normalizeGLTFV1(gltf) {
389
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
262
390
  return new GLTFV1Normalizer().normalize(gltf, options);
263
391
  }
264
392
  //# sourceMappingURL=normalize-gltf-v1.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"names":["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","normalize","gltf","options","json","asset","version","undefined","console","warn","Error","_addAsset","_convertTopLevelObjectsToArrays","KHR_binary_glTF","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","key","Number","isFinite","type","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","textureIndex","findIndex","baseColorTexture","normalizeGLTFV1"],"mappings":";;;;;;;;;;;AACA;;;;;;AA+CA,MAAMA,WAAW,GAAG;AAClBC,EAAAA,SAAS,EAAE,UADO;AAElBC,EAAAA,UAAU,EAAE,WAFM;AAGlBC,EAAAA,OAAO,EAAE,QAHS;AAIlBC,EAAAA,WAAW,EAAE,YAJK;AAKlBC,EAAAA,MAAM,EAAE,OALU;AAMlBC,EAAAA,SAAS,EAAE,UANO;AAOlBC,EAAAA,MAAM,EAAE,MAPU;AAQlBC,EAAAA,KAAK,EAAE,MARW;AASlBC,EAAAA,QAAQ,EAAE,SATQ;AAUlBC,EAAAA,MAAM,EAAE,OAVU;AAWlBC,EAAAA,KAAK,EAAE,MAXW;AAYlBC,EAAAA,QAAQ,EAAE;AAZQ,CAApB;AAeA,MAAMC,SAAS,GAAG;AAChBC,EAAAA,QAAQ,EAAE,WADM;AAEhBZ,EAAAA,UAAU,EAAE,WAFI;AAGhBa,EAAAA,MAAM,EAAE,SAHQ;AAIhBC,EAAAA,UAAU,EAAE,aAJI;AAKhBC,EAAAA,KAAK,EAAE,QALS;AAMhBC,EAAAA,QAAQ,EAAE,WANM;AAOhBC,EAAAA,IAAI,EAAE,QAPU;AAQhBC,EAAAA,IAAI,EAAE,OARU;AAShBC,EAAAA,OAAO,EAAE,UATO;AAUhBC,EAAAA,KAAK,EAAE,QAVS;AAWhB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jB,QAAL,CAAcwE,SAAd,CAAyB5D,OAAD,IAAaA,OAAO,CAAC0B,EAAR,KAAe8B,SAApD,CAArB;;AACA,UAAIG,YAAY,KAAK,CAAC,CAAtB,EAAyB;AACvBjE,QAAAA,QAAQ,CAAC0D,oBAAT,CAA8BS,gBAA9B,GAAiD;AAACjC,UAAAA,KAAK,EAAE+B;AAAR,SAAjD;AACD;AACF;AACF;;AAjOoB;;AAoOhB,SAASG,eAAT,CAAyB3D,IAAzB,EAA+BC,OAAO,GAAG,EAAzC,EAA6C;AAClD,SAAO,IAAIH,gBAAJ,GAAuBC,SAAvB,CAAiCC,IAAjC,EAAuCC,OAAvC,CAAP;AACD","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 = material.values && material.values.tex;\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"],"file":"normalize-gltf-v1.js"}
1
+ {"version":3,"sources":["../../../../src/lib/api/normalize-gltf-v1.ts"],"names":["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","gltf","options","json","asset","version","undefined","console","warn","normalize","Error","_addAsset","_convertTopLevelObjectsToArrays","KHR_binary_glTF","preprocess","_convertObjectIdsToArrayIndices","_updateObjects","_updateMaterial","generator","arrayName","_convertTopLevelObjectToArray","mapName","objectMap","Array","isArray","id","object","index","length","push","idToIndexMap","_convertIdsToIndices","_convertIdToIndex","_convertTextureIds","_convertMeshIds","_convertNodeIds","_convertSceneIds","source","primitives","primitive","attributes","indices","attributeName","children","map","child","topLevelArrayName","key","Number","isFinite","type","pbrMetallicRoughness","baseColorFactor","metallicFactor","roughnessFactor","textureId","values","tex","textureIndex","findIndex","baseColorTexture","normalizeGLTFV1"],"mappings":";;;;;;;;;;;;;;;;;AACA;;;;;;;;;;;;AA+CA,IAAMA,WAAW,GAAG;AAClBC,EAAAA,SAAS,EAAE,UADO;AAElBC,EAAAA,UAAU,EAAE,WAFM;AAGlBC,EAAAA,OAAO,EAAE,QAHS;AAIlBC,EAAAA,WAAW,EAAE,YAJK;AAKlBC,EAAAA,MAAM,EAAE,OALU;AAMlBC,EAAAA,SAAS,EAAE,UANO;AAOlBC,EAAAA,MAAM,EAAE,MAPU;AAQlBC,EAAAA,KAAK,EAAE,MARW;AASlBC,EAAAA,QAAQ,EAAE,SATQ;AAUlBC,EAAAA,MAAM,EAAE,OAVU;AAWlBC,EAAAA,KAAK,EAAE,MAXW;AAYlBC,EAAAA,QAAQ,EAAE;AAZQ,CAApB;AAeA,IAAMC,SAAS,GAAG;AAChBC,EAAAA,QAAQ,EAAE,WADM;AAEhBZ,EAAAA,UAAU,EAAE,WAFI;AAGhBa,EAAAA,MAAM,EAAE,SAHQ;AAIhBC,EAAAA,UAAU,EAAE,aAJI;AAKhBC,EAAAA,KAAK,EAAE,QALS;AAMhBC,EAAAA,QAAQ,EAAE,WANM;AAOhBC,EAAAA,IAAI,EAAE,QAPU;AAQhBC,EAAAA,IAAI,EAAE,OARU;AAShBC,EAAAA,OAAO,EAAE,UATO;AAUhBC,EAAAA,KAAK,EAAE,QAVS;AAWhBC,EAAAA,IAAI,EAAE,OAXU;AAYhBC,EAAAA,OAAO,EAAE;AAZO,CAAlB;;IAkBMC,gB;;;wDACW;AACbvB,MAAAA,UAAU,EAAE,EADC;AAEbD,MAAAA,SAAS,EAAE,EAFE;AAGbE,MAAAA,OAAO,EAAE,EAHI;AAIbC,MAAAA,WAAW,EAAE,EAJA;A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E9BC,YAAAA,cAAc,EAAE,CAFc;AAG9BC,YAAAA,eAAe,EAAE;AAHa,WAAhC;AAMA,cAAMC,SAAS,GAAG9D,QAAQ,CAAC+D,MAAT,IAAmB/D,QAAQ,CAAC+D,MAAT,CAAgBC,GAArD;AACA,cAAMC,YAAY,GAAGvD,IAAI,CAAChB,QAAL,CAAcwE,SAAd,CAAwB,UAAC5D,OAAD;AAAA,mBAAaA,OAAO,CAAC0B,EAAR,KAAe8B,SAA5B;AAAA,WAAxB,CAArB;;AACA,cAAIG,YAAY,KAAK,CAAC,CAAtB,EAAyB;AACvBjE,YAAAA,QAAQ,CAAC0D,oBAAT,CAA8BS,gBAA9B,GAAiD;AAACjC,cAAAA,KAAK,EAAE+B;AAAR,aAAjD;AACD;AAZiB;;AACpB,+DAAuC;AAAA;AAYtC;AAbmB;AAAA;AAAA;AAAA;AAAA;AAcrB;;;;;AAGI,SAASG,eAAT,CAAyB5D,IAAzB,EAA6C;AAAA,MAAdC,OAAc,uEAAJ,EAAI;AAClD,SAAO,IAAIF,gBAAJ,GAAuBS,SAAvB,CAAiCR,IAAjC,EAAuCC,OAAvC,CAAP;AACD","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 = material.values && material.values.tex;\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"],"file":"normalize-gltf-v1.js"}