@loaders.gl/gltf 3.0.13 → 3.0.14

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 (59) hide show
  1. package/dist/dist.es5.min.js +1 -1
  2. package/dist/dist.es5.min.js.map +1 -1
  3. package/dist/dist.min.js +1 -1
  4. package/dist/dist.min.js.map +1 -1
  5. package/dist/es5/bundle.js +2 -2
  6. package/dist/es5/bundle.js.map +1 -1
  7. package/dist/es5/glb-loader.js +33 -10
  8. package/dist/es5/glb-loader.js.map +1 -1
  9. package/dist/es5/glb-writer.js +8 -9
  10. package/dist/es5/glb-writer.js.map +1 -1
  11. package/dist/es5/gltf-loader.js +52 -14
  12. package/dist/es5/gltf-loader.js.map +1 -1
  13. package/dist/es5/gltf-writer.js +10 -10
  14. package/dist/es5/gltf-writer.js.map +1 -1
  15. package/dist/es5/index.js +7 -7
  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 +280 -150
  19. package/dist/es5/lib/api/normalize-gltf-v1.js.map +1 -1
  20. package/dist/es5/lib/api/post-process-gltf.js +354 -279
  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 +99 -34
  27. package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
  28. package/dist/es5/lib/extensions/KHR_binary_gltf.js +22 -8
  29. package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
  30. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +244 -70
  31. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  32. package/dist/es5/lib/extensions/KHR_lights_punctual.js +102 -38
  33. package/dist/es5/lib/extensions/KHR_lights_punctual.js.map +1 -1
  34. package/dist/es5/lib/extensions/KHR_materials_unlit.js +67 -22
  35. package/dist/es5/lib/extensions/KHR_materials_unlit.js.map +1 -1
  36. package/dist/es5/lib/extensions/KHR_techniques_webgl.js +88 -32
  37. package/dist/es5/lib/extensions/KHR_techniques_webgl.js.map +1 -1
  38. package/dist/es5/lib/extensions/gltf-extensions.js +67 -17
  39. package/dist/es5/lib/extensions/gltf-extensions.js.map +1 -1
  40. package/dist/es5/lib/gltf-utils/get-typed-array.js +6 -6
  41. package/dist/es5/lib/gltf-utils/get-typed-array.js.map +1 -1
  42. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js +21 -19
  43. package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
  44. package/dist/es5/lib/gltf-utils/gltf-constants.js +13 -13
  45. package/dist/es5/lib/gltf-utils/gltf-constants.js.map +1 -1
  46. package/dist/es5/lib/gltf-utils/gltf-utils.js +16 -16
  47. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  48. package/dist/es5/lib/gltf-utils/resolve-url.js +2 -2
  49. package/dist/es5/lib/gltf-utils/resolve-url.js.map +1 -1
  50. package/dist/es5/lib/parsers/parse-glb.js +38 -34
  51. package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
  52. package/dist/es5/lib/parsers/parse-gltf.js +215 -80
  53. package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
  54. package/dist/es5/lib/utils/version.js +1 -1
  55. package/dist/es5/lib/utils/version.js.map +1 -1
  56. package/dist/es5/meshopt/meshopt-decoder.js +197 -46
  57. package/dist/es5/meshopt/meshopt-decoder.js.map +1 -1
  58. package/dist/esm/lib/utils/version.js +1 -1
  59. package/package.json +6 -6
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _regeneratorRuntime2 = require("@babel/runtime/regenerator");
4
+
3
5
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
6
 
5
7
  Object.defineProperty(exports, "__esModule", {
@@ -8,6 +10,14 @@ Object.defineProperty(exports, "__esModule", {
8
10
  exports.decode = decode;
9
11
  exports.encode = encode;
10
12
 
13
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
+
15
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
16
+
17
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
+
19
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
20
+
11
21
  var _draco = require("@loaders.gl/draco");
12
22
 
13
23
  var _loaderUtils = require("@loaders.gl/loader-utils");
@@ -18,101 +28,189 @@ var _gltfConstants = require("../gltf-utils/gltf-constants");
18
28
 
19
29
  var _gltfAttributeUtils = require("../gltf-utils/gltf-attribute-utils");
20
30
 
21
- async function decode(gltfData, options, context) {
22
- var _options$gltf;
31
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
23
32
 
24
- if (!(options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.decompressMeshes)) {
25
- return;
26
- }
33
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
27
34
 
28
- const scenegraph = new _gltfScenegraph.default(gltfData);
29
- const promises = [];
35
+ var _marked = _regeneratorRuntime2.mark(makeMeshPrimitiveIterator);
30
36
 
31
- for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
32
- if (scenegraph.getObjectExtension(primitive, _gltfConstants.KHR_DRACO_MESH_COMPRESSION)) {
33
- promises.push(decompressPrimitive(scenegraph, primitive, options, context));
34
- }
35
- }
37
+ 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; } } }; }
36
38
 
37
- await Promise.all(promises);
38
- scenegraph.removeExtension(_gltfConstants.KHR_DRACO_MESH_COMPRESSION);
39
- }
39
+ 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); }
40
40
 
41
- function encode(gltfData, options = {}) {
42
- const scenegraph = new _gltfScenegraph.default(gltfData);
41
+ 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; }
43
42
 
44
- for (const mesh of scenegraph.json.meshes || []) {
45
- compressMesh(mesh, options);
46
- scenegraph.addRequiredExtension(_gltfConstants.KHR_DRACO_MESH_COMPRESSION);
47
- }
43
+ function decode(_x, _x2, _x3) {
44
+ return _decode.apply(this, arguments);
48
45
  }
49
46
 
50
- async function decompressPrimitive(scenegraph, primitive, options, context) {
51
- const dracoExtension = scenegraph.getObjectExtension(primitive, _gltfConstants.KHR_DRACO_MESH_COMPRESSION);
47
+ function _decode() {
48
+ _decode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(gltfData, options, context) {
49
+ var _options$gltf;
52
50
 
53
- if (!dracoExtension) {
54
- return;
55
- }
51
+ var scenegraph, promises, _iterator4, _step4, primitive;
56
52
 
57
- const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);
58
- const bufferCopy = (0, _loaderUtils.sliceArrayBuffer)(buffer.buffer, buffer.byteOffset);
59
- const {
60
- parse
61
- } = context;
62
- const dracoOptions = { ...options
63
- };
64
- delete dracoOptions['3d-tiles'];
65
- const decodedData = await parse(bufferCopy, _draco.DracoLoader, dracoOptions, context);
66
- const decodedAttributes = (0, _gltfAttributeUtils.getGLTFAccessors)(decodedData.attributes);
67
-
68
- for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {
69
- if (attributeName in primitive.attributes) {
70
- const accessorIndex = primitive.attributes[attributeName];
71
- const accessor = scenegraph.getAccessor(accessorIndex);
72
-
73
- if (accessor !== null && accessor !== void 0 && accessor.min && accessor !== null && accessor !== void 0 && accessor.max) {
74
- decodedAttribute.min = accessor.min;
75
- decodedAttribute.max = accessor.max;
53
+ return _regenerator.default.wrap(function _callee$(_context2) {
54
+ while (1) {
55
+ switch (_context2.prev = _context2.next) {
56
+ case 0:
57
+ if (options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.decompressMeshes) {
58
+ _context2.next = 2;
59
+ break;
60
+ }
61
+
62
+ return _context2.abrupt("return");
63
+
64
+ case 2:
65
+ scenegraph = new _gltfScenegraph.default(gltfData);
66
+ promises = [];
67
+ _iterator4 = _createForOfIteratorHelper(makeMeshPrimitiveIterator(scenegraph));
68
+
69
+ try {
70
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
71
+ primitive = _step4.value;
72
+
73
+ if (scenegraph.getObjectExtension(primitive, _gltfConstants.KHR_DRACO_MESH_COMPRESSION)) {
74
+ promises.push(decompressPrimitive(scenegraph, primitive, options, context));
75
+ }
76
+ }
77
+ } catch (err) {
78
+ _iterator4.e(err);
79
+ } finally {
80
+ _iterator4.f();
81
+ }
82
+
83
+ _context2.next = 8;
84
+ return Promise.all(promises);
85
+
86
+ case 8:
87
+ scenegraph.removeExtension(_gltfConstants.KHR_DRACO_MESH_COMPRESSION);
88
+
89
+ case 9:
90
+ case "end":
91
+ return _context2.stop();
92
+ }
76
93
  }
94
+ }, _callee);
95
+ }));
96
+ return _decode.apply(this, arguments);
97
+ }
98
+
99
+ function encode(gltfData) {
100
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
101
+ var scenegraph = new _gltfScenegraph.default(gltfData);
102
+
103
+ var _iterator = _createForOfIteratorHelper(scenegraph.json.meshes || []),
104
+ _step;
105
+
106
+ try {
107
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
108
+ var mesh = _step.value;
109
+ compressMesh(mesh, options);
110
+ scenegraph.addRequiredExtension(_gltfConstants.KHR_DRACO_MESH_COMPRESSION);
77
111
  }
112
+ } catch (err) {
113
+ _iterator.e(err);
114
+ } finally {
115
+ _iterator.f();
78
116
  }
117
+ }
79
118
 
80
- primitive.attributes = decodedAttributes;
119
+ function decompressPrimitive(_x4, _x5, _x6, _x7) {
120
+ return _decompressPrimitive.apply(this, arguments);
121
+ }
81
122
 
82
- if (decodedData.indices) {
83
- primitive.indices = (0, _gltfAttributeUtils.getGLTFAccessor)(decodedData.indices);
84
- }
123
+ function _decompressPrimitive() {
124
+ _decompressPrimitive = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(scenegraph, primitive, options, context) {
125
+ var dracoExtension, buffer, bufferCopy, parse, dracoOptions, decodedData, decodedAttributes, _i, _Object$entries, _Object$entries$_i, attributeName, decodedAttribute, accessorIndex, accessor;
126
+
127
+ return _regenerator.default.wrap(function _callee2$(_context3) {
128
+ while (1) {
129
+ switch (_context3.prev = _context3.next) {
130
+ case 0:
131
+ dracoExtension = scenegraph.getObjectExtension(primitive, _gltfConstants.KHR_DRACO_MESH_COMPRESSION);
132
+
133
+ if (dracoExtension) {
134
+ _context3.next = 3;
135
+ break;
136
+ }
137
+
138
+ return _context3.abrupt("return");
139
+
140
+ case 3:
141
+ buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);
142
+ bufferCopy = (0, _loaderUtils.sliceArrayBuffer)(buffer.buffer, buffer.byteOffset);
143
+ parse = context.parse;
144
+ dracoOptions = _objectSpread({}, options);
145
+ delete dracoOptions['3d-tiles'];
146
+ _context3.next = 10;
147
+ return parse(bufferCopy, _draco.DracoLoader, dracoOptions, context);
148
+
149
+ case 10:
150
+ decodedData = _context3.sent;
151
+ decodedAttributes = (0, _gltfAttributeUtils.getGLTFAccessors)(decodedData.attributes);
152
+
153
+ for (_i = 0, _Object$entries = Object.entries(decodedAttributes); _i < _Object$entries.length; _i++) {
154
+ _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2), attributeName = _Object$entries$_i[0], decodedAttribute = _Object$entries$_i[1];
155
+
156
+ if (attributeName in primitive.attributes) {
157
+ accessorIndex = primitive.attributes[attributeName];
158
+ accessor = scenegraph.getAccessor(accessorIndex);
85
159
 
86
- checkPrimitive(primitive);
160
+ if (accessor !== null && accessor !== void 0 && accessor.min && accessor !== null && accessor !== void 0 && accessor.max) {
161
+ decodedAttribute.min = accessor.min;
162
+ decodedAttribute.max = accessor.max;
163
+ }
164
+ }
165
+ }
166
+
167
+ primitive.attributes = decodedAttributes;
168
+
169
+ if (decodedData.indices) {
170
+ primitive.indices = (0, _gltfAttributeUtils.getGLTFAccessor)(decodedData.indices);
171
+ }
172
+
173
+ checkPrimitive(primitive);
174
+
175
+ case 16:
176
+ case "end":
177
+ return _context3.stop();
178
+ }
179
+ }
180
+ }, _callee2);
181
+ }));
182
+ return _decompressPrimitive.apply(this, arguments);
87
183
  }
88
184
 
89
- function compressMesh(attributes, indices, mode = 4, options, context) {
185
+ function compressMesh(attributes, indices) {
90
186
  var _context$parseSync;
91
187
 
188
+ var mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
189
+ var options = arguments.length > 3 ? arguments[3] : undefined;
190
+ var context = arguments.length > 4 ? arguments[4] : undefined;
191
+
92
192
  if (!options.DracoWriter) {
93
193
  throw new Error('options.gltf.DracoWriter not provided');
94
194
  }
95
195
 
96
- const compressedData = options.DracoWriter.encodeSync({
97
- attributes
196
+ var compressedData = options.DracoWriter.encodeSync({
197
+ attributes: attributes
98
198
  });
99
- const decodedData = context === null || context === void 0 ? void 0 : (_context$parseSync = context.parseSync) === null || _context$parseSync === void 0 ? void 0 : _context$parseSync.call(context, {
100
- attributes
199
+ var decodedData = context === null || context === void 0 ? void 0 : (_context$parseSync = context.parseSync) === null || _context$parseSync === void 0 ? void 0 : _context$parseSync.call(context, {
200
+ attributes: attributes
101
201
  });
102
202
 
103
- const fauxAccessors = options._addFauxAttributes(decodedData.attributes);
203
+ var fauxAccessors = options._addFauxAttributes(decodedData.attributes);
104
204
 
105
- const bufferViewIndex = options.addBufferView(compressedData);
106
- const glTFMesh = {
205
+ var bufferViewIndex = options.addBufferView(compressedData);
206
+ var glTFMesh = {
107
207
  primitives: [{
108
208
  attributes: fauxAccessors,
109
- mode,
110
- extensions: {
111
- [_gltfConstants.KHR_DRACO_MESH_COMPRESSION]: {
112
- bufferView: bufferViewIndex,
113
- attributes: fauxAccessors
114
- }
115
- }
209
+ mode: mode,
210
+ extensions: (0, _defineProperty2.default)({}, _gltfConstants.KHR_DRACO_MESH_COMPRESSION, {
211
+ bufferView: bufferViewIndex,
212
+ attributes: fauxAccessors
213
+ })
116
214
  }]
117
215
  };
118
216
  return glTFMesh;
@@ -124,11 +222,87 @@ function checkPrimitive(primitive) {
124
222
  }
125
223
  }
126
224
 
127
- function* makeMeshPrimitiveIterator(scenegraph) {
128
- for (const mesh of scenegraph.json.meshes || []) {
129
- for (const primitive of mesh.primitives) {
130
- yield primitive;
225
+ function makeMeshPrimitiveIterator(scenegraph) {
226
+ var _iterator2, _step2, mesh, _iterator3, _step3, primitive;
227
+
228
+ return _regenerator.default.wrap(function makeMeshPrimitiveIterator$(_context) {
229
+ while (1) {
230
+ switch (_context.prev = _context.next) {
231
+ case 0:
232
+ _iterator2 = _createForOfIteratorHelper(scenegraph.json.meshes || []);
233
+ _context.prev = 1;
234
+
235
+ _iterator2.s();
236
+
237
+ case 3:
238
+ if ((_step2 = _iterator2.n()).done) {
239
+ _context.next = 24;
240
+ break;
241
+ }
242
+
243
+ mesh = _step2.value;
244
+ _iterator3 = _createForOfIteratorHelper(mesh.primitives);
245
+ _context.prev = 6;
246
+
247
+ _iterator3.s();
248
+
249
+ case 8:
250
+ if ((_step3 = _iterator3.n()).done) {
251
+ _context.next = 14;
252
+ break;
253
+ }
254
+
255
+ primitive = _step3.value;
256
+ _context.next = 12;
257
+ return primitive;
258
+
259
+ case 12:
260
+ _context.next = 8;
261
+ break;
262
+
263
+ case 14:
264
+ _context.next = 19;
265
+ break;
266
+
267
+ case 16:
268
+ _context.prev = 16;
269
+ _context.t0 = _context["catch"](6);
270
+
271
+ _iterator3.e(_context.t0);
272
+
273
+ case 19:
274
+ _context.prev = 19;
275
+
276
+ _iterator3.f();
277
+
278
+ return _context.finish(19);
279
+
280
+ case 22:
281
+ _context.next = 3;
282
+ break;
283
+
284
+ case 24:
285
+ _context.next = 29;
286
+ break;
287
+
288
+ case 26:
289
+ _context.prev = 26;
290
+ _context.t1 = _context["catch"](1);
291
+
292
+ _iterator2.e(_context.t1);
293
+
294
+ case 29:
295
+ _context.prev = 29;
296
+
297
+ _iterator2.f();
298
+
299
+ return _context.finish(29);
300
+
301
+ case 32:
302
+ case "end":
303
+ return _context.stop();
304
+ }
131
305
  }
132
- }
306
+ }, _marked, null, [[1, 26, 29, 32], [6, 16, 19, 22]]);
133
307
  }
134
308
  //# sourceMappingURL=KHR_draco_mesh_compression.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"names":["decode","gltfData","options","context","gltf","decompressMeshes","scenegraph","Scenegraph","promises","primitive","makeMeshPrimitiveIterator","getObjectExtension","KHR_DRACO_MESH_COMPRESSION","push","decompressPrimitive","Promise","all","removeExtension","encode","mesh","json","meshes","compressMesh","addRequiredExtension","dracoExtension","buffer","getTypedArrayForBufferView","bufferView","bufferCopy","byteOffset","parse","dracoOptions","decodedData","DracoLoader","decodedAttributes","attributes","attributeName","decodedAttribute","Object","entries","accessorIndex","accessor","getAccessor","min","max","indices","checkPrimitive","mode","DracoWriter","Error","compressedData","encodeSync","parseSync","fauxAccessors","_addFauxAttributes","bufferViewIndex","addBufferView","glTFMesh","primitives","extensions","keys","length"],"mappings":";;;;;;;;;;AAQA;;AAEA;;AACA;;AACA;;AACA;;AAGO,eAAeA,MAAf,CACLC,QADK,EAELC,OAFK,EAGLC,OAHK,EAIU;AAAA;;AACf,MAAI,EAACD,OAAD,aAACA,OAAD,gCAACA,OAAO,CAAEE,IAAV,0CAAC,cAAeC,gBAAhB,CAAJ,EAAsC;AACpC;AACD;;AAED,QAAMC,UAAU,GAAG,IAAIC,uBAAJ,CAAeN,QAAf,CAAnB;AACA,QAAMO,QAAyB,GAAG,EAAlC;;AACA,OAAK,MAAMC,SAAX,IAAwBC,yBAAyB,CAACJ,UAAD,CAAjD,EAA+D;AAC7D,QAAIA,UAAU,CAACK,kBAAX,CAA8BF,SAA9B,EAAyCG,yCAAzC,CAAJ,EAA0E;AACxEJ,MAAAA,QAAQ,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,uDAAG,wBAAAjD,OAAO,EAAc;AAACgC,IAAAA;AAAD,GAAd,CAA3B;;AACA,QAAMkB,aAAa,GAAGnD,OAAO,CAACoD,kBAAR,CAA2BtB,WAAW,CAACG,UAAvC,CAAtB;;AAEA,QAAMoB,eAAe,GAAGrD,OAAO,CAACsD,aAAR,CAAsBN,cAAtB,CAAxB;AAEA,QAAMO,QAAQ,GAAG;AACfC,IAAAA,UAAU,EAAE,CACV;AACEvB,MAAAA,UAAU,EAAEkB,aADd;AAEEN,MAAAA,IAFF;AAGEY,MAAAA,UAAU,EAAE;AACV,SAAC/C,yCAAD,GAA8B;AAC5Be,UAAAA,UAAU,EAAE4B,eADgB;AAE5BpB,UAAAA,UAAU,EAAEkB;AAFgB;AADpB;AAHd,KADU;AADG,GAAjB;AAeA,SAAOI,QAAP;AACD;;AAID,SAASX,cAAT,CAAwBrC,SAAxB,EAAsD;AACpD,MAAI,CAACA,SAAS,CAAC0B,UAAX,IAAyBG,MAAM,CAACsB,IAAP,CAAYnD,SAAS,CAAC0B,UAAtB,EAAkC0B,MAAlC,GAA2C,CAAxE,EAA2E;AACzE,UAAM,IAAIZ,KAAJ,CAAU,8DAAV,CAAN;AACD;AACF;;AAED,UAAUvC,yBAAV,CAAoCJ,UAApC,EAAgD;AAC9C,OAAK,MAAMa,IAAX,IAAmBb,UAAU,CAACc,IAAX,CAAgBC,MAAhB,IAA0B,EAA7C,EAAiD;AAC/C,SAAK,MAAMZ,SAAX,IAAwBU,IAAI,CAACuC,UAA7B,EAAyC;AACvC,YAAMjD,SAAN;AACD;AACF;AACF","sourcesContent":["// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\n\n/* eslint-disable camelcase */\nimport type {GLTF, GLTFAccessor, GLTFMeshPrimitive} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport {DracoLoader} from '@loaders.gl/draco';\nimport {DracoLoaderOptions, DracoMeshData} from '@loaders.gl/draco';\nimport {sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {default as Scenegraph} from '../api/gltf-scenegraph';\nimport {KHR_DRACO_MESH_COMPRESSION} from '../gltf-utils/gltf-constants';\nimport {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';\n\n// Note: We have a \"soft dependency\" on DracoWriter to avoid bundling it when not needed\nexport async function decode(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const scenegraph = new Scenegraph(gltfData);\n const promises: Promise<void>[] = [];\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n promises.push(decompressPrimitive(scenegraph, primitive, options, context));\n }\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extensions\n scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);\n}\n\nexport function encode(gltfData, options: GLTFLoaderOptions = {}): void {\n const scenegraph = new Scenegraph(gltfData);\n\n for (const mesh of scenegraph.json.meshes || []) {\n // eslint-disable-next-line camelcase\n // @ts-ignore\n compressMesh(mesh, options);\n // NOTE: Only add the extension if something was actually compressed\n scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);\n }\n}\n\n// DECODE\n\n// Unpacks one mesh primitive and removes the extension from the primitive\n// DracoDecoder needs to be imported and registered by app\n// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete\n\n// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec\n\nasync function decompressPrimitive(\n scenegraph: Scenegraph,\n primitive: GLTFMeshPrimitive,\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n const dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);\n if (!dracoExtension) {\n return;\n }\n\n const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);\n // TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer\n // TODO - remove when `parse` is fixed to handle `byteOffset`s\n const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);\n\n const {parse} = context;\n const dracoOptions: DracoLoaderOptions = {...options};\n\n // TODO - remove hack: The entire tileset might be included, too expensive to serialize\n delete dracoOptions['3d-tiles'];\n const decodedData = (await parse(\n bufferCopy,\n DracoLoader,\n dracoOptions,\n context\n )) as DracoMeshData;\n\n const decodedAttributes: {[key: string]: GLTFAccessor} = getGLTFAccessors(decodedData.attributes);\n\n // Restore min/max values\n for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {\n if (attributeName in primitive.attributes) {\n const accessorIndex: number = primitive.attributes[attributeName];\n const accessor = scenegraph.getAccessor(accessorIndex);\n if (accessor?.min && accessor?.max) {\n decodedAttribute.min = accessor.min;\n decodedAttribute.max = accessor.max;\n }\n }\n }\n\n // @ts-ignore\n primitive.attributes = decodedAttributes;\n if (decodedData.indices) {\n // @ts-ignore\n primitive.indices = getGLTFAccessor(decodedData.indices);\n }\n\n // Extension has been processed, delete it\n // delete primitive.extensions[KHR_DRACO_MESH_COMPRESSION];\n\n checkPrimitive(primitive);\n}\n\n// ENCODE\n\n// eslint-disable-next-line max-len\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\nfunction compressMesh(attributes, indices, mode: number = 4, options, context: LoaderContext) {\n if (!options.DracoWriter) {\n throw new Error('options.gltf.DracoWriter not provided');\n }\n\n // TODO - use DracoWriter using encode w/ registered DracoWriter...\n const compressedData = options.DracoWriter.encodeSync({attributes});\n\n // Draco compression may change the order and number of vertices in a mesh.\n // To satisfy the requirement that accessors properties be correct for both\n // compressed and uncompressed data, generators should create uncompressed\n // attributes and indices using data that has been decompressed from the Draco buffer,\n // rather than the original source data.\n // @ts-ignore TODO this needs to be fixed\n const decodedData = context?.parseSync?.({attributes});\n const fauxAccessors = options._addFauxAttributes(decodedData.attributes);\n\n const bufferViewIndex = options.addBufferView(compressedData);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: fauxAccessors, // TODO - verify with spec\n mode, // GL.POINTS\n extensions: {\n [KHR_DRACO_MESH_COMPRESSION]: {\n bufferView: bufferViewIndex,\n attributes: fauxAccessors // TODO - verify with spec\n }\n }\n }\n ]\n };\n\n return glTFMesh;\n}\n\n// UTILS\n\nfunction checkPrimitive(primitive: GLTFMeshPrimitive) {\n if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {\n throw new Error('glTF: Empty primitive detected: Draco decompression failure?');\n }\n}\n\nfunction* makeMeshPrimitiveIterator(scenegraph) {\n for (const mesh of scenegraph.json.meshes || []) {\n for (const primitive of mesh.primitives) {\n yield primitive;\n }\n }\n}\n"],"file":"KHR_draco_mesh_compression.js"}
1
+ {"version":3,"sources":["../../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"names":["makeMeshPrimitiveIterator","decode","gltfData","options","context","gltf","decompressMeshes","scenegraph","Scenegraph","promises","primitive","getObjectExtension","KHR_DRACO_MESH_COMPRESSION","push","decompressPrimitive","Promise","all","removeExtension","encode","json","meshes","mesh","compressMesh","addRequiredExtension","dracoExtension","buffer","getTypedArrayForBufferView","bufferView","bufferCopy","byteOffset","parse","dracoOptions","DracoLoader","decodedData","decodedAttributes","attributes","Object","entries","attributeName","decodedAttribute","accessorIndex","accessor","getAccessor","min","max","indices","checkPrimitive","mode","DracoWriter","Error","compressedData","encodeSync","parseSync","fauxAccessors","_addFauxAttributes","bufferViewIndex","addBufferView","glTFMesh","primitives","extensions","keys","length"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQA;;AAEA;;AACA;;AACA;;AACA;;;;;;wCAuJUA,yB;;;;;;;;SApJYC,M;;;;;sEAAf,iBACLC,QADK,EAELC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,EAAEkB;AAFgB,OADtB;AAHZ,KADU;AADG,GAAjB;AAeA,SAAOI,QAAP;AACD;;AAID,SAASX,cAAT,CAAwBpC,SAAxB,EAAsD;AACpD,MAAI,CAACA,SAAS,CAACyB,UAAX,IAAyBC,MAAM,CAACwB,IAAP,CAAYlD,SAAS,CAACyB,UAAtB,EAAkC0B,MAAlC,GAA2C,CAAxE,EAA2E;AACzE,UAAM,IAAIZ,KAAJ,CAAU,8DAAV,CAAN;AACD;AACF;;AAED,SAAUjD,yBAAV,CAAoCO,UAApC;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,kDACqBA,UAAU,CAACY,IAAX,CAAgBC,MAAhB,IAA0B,EAD/C;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AACaC,UAAAA,IADb;AAAA,kDAE4BA,IAAI,CAACqC,UAFjC;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEehD,UAAAA,SAFf;AAAA;AAGM,iBAAMA,SAAN;;AAHN;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\n\n/* eslint-disable camelcase */\nimport type {GLTF, GLTFAccessor, GLTFMeshPrimitive} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport {DracoLoader} from '@loaders.gl/draco';\nimport {DracoLoaderOptions, DracoMeshData} from '@loaders.gl/draco';\nimport {sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {default as Scenegraph} from '../api/gltf-scenegraph';\nimport {KHR_DRACO_MESH_COMPRESSION} from '../gltf-utils/gltf-constants';\nimport {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';\n\n// Note: We have a \"soft dependency\" on DracoWriter to avoid bundling it when not needed\nexport async function decode(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n if (!options?.gltf?.decompressMeshes) {\n return;\n }\n\n const scenegraph = new Scenegraph(gltfData);\n const promises: Promise<void>[] = [];\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n promises.push(decompressPrimitive(scenegraph, primitive, options, context));\n }\n }\n\n // Decompress meshes in parallel\n await Promise.all(promises);\n\n // We have now decompressed all primitives, so remove the top-level extensions\n scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);\n}\n\nexport function encode(gltfData, options: GLTFLoaderOptions = {}): void {\n const scenegraph = new Scenegraph(gltfData);\n\n for (const mesh of scenegraph.json.meshes || []) {\n // eslint-disable-next-line camelcase\n // @ts-ignore\n compressMesh(mesh, options);\n // NOTE: Only add the extension if something was actually compressed\n scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);\n }\n}\n\n// DECODE\n\n// Unpacks one mesh primitive and removes the extension from the primitive\n// DracoDecoder needs to be imported and registered by app\n// Returns: Promise that resolves when all pending draco decoder jobs for this mesh complete\n\n// TODO - Implement fallback behavior per KHR_DRACO_MESH_COMPRESSION spec\n\nasync function decompressPrimitive(\n scenegraph: Scenegraph,\n primitive: GLTFMeshPrimitive,\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<void> {\n const dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);\n if (!dracoExtension) {\n return;\n }\n\n const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);\n // TODO - parse does not yet deal well with byte offsets embedded in typed arrays. Copy buffer\n // TODO - remove when `parse` is fixed to handle `byteOffset`s\n const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);\n\n const {parse} = context;\n const dracoOptions: DracoLoaderOptions = {...options};\n\n // TODO - remove hack: The entire tileset might be included, too expensive to serialize\n delete dracoOptions['3d-tiles'];\n const decodedData = (await parse(\n bufferCopy,\n DracoLoader,\n dracoOptions,\n context\n )) as DracoMeshData;\n\n const decodedAttributes: {[key: string]: GLTFAccessor} = getGLTFAccessors(decodedData.attributes);\n\n // Restore min/max values\n for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {\n if (attributeName in primitive.attributes) {\n const accessorIndex: number = primitive.attributes[attributeName];\n const accessor = scenegraph.getAccessor(accessorIndex);\n if (accessor?.min && accessor?.max) {\n decodedAttribute.min = accessor.min;\n decodedAttribute.max = accessor.max;\n }\n }\n }\n\n // @ts-ignore\n primitive.attributes = decodedAttributes;\n if (decodedData.indices) {\n // @ts-ignore\n primitive.indices = getGLTFAccessor(decodedData.indices);\n }\n\n // Extension has been processed, delete it\n // delete primitive.extensions[KHR_DRACO_MESH_COMPRESSION];\n\n checkPrimitive(primitive);\n}\n\n// ENCODE\n\n// eslint-disable-next-line max-len\n// Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported\nfunction compressMesh(attributes, indices, mode: number = 4, options, context: LoaderContext) {\n if (!options.DracoWriter) {\n throw new Error('options.gltf.DracoWriter not provided');\n }\n\n // TODO - use DracoWriter using encode w/ registered DracoWriter...\n const compressedData = options.DracoWriter.encodeSync({attributes});\n\n // Draco compression may change the order and number of vertices in a mesh.\n // To satisfy the requirement that accessors properties be correct for both\n // compressed and uncompressed data, generators should create uncompressed\n // attributes and indices using data that has been decompressed from the Draco buffer,\n // rather than the original source data.\n // @ts-ignore TODO this needs to be fixed\n const decodedData = context?.parseSync?.({attributes});\n const fauxAccessors = options._addFauxAttributes(decodedData.attributes);\n\n const bufferViewIndex = options.addBufferView(compressedData);\n\n const glTFMesh = {\n primitives: [\n {\n attributes: fauxAccessors, // TODO - verify with spec\n mode, // GL.POINTS\n extensions: {\n [KHR_DRACO_MESH_COMPRESSION]: {\n bufferView: bufferViewIndex,\n attributes: fauxAccessors // TODO - verify with spec\n }\n }\n }\n ]\n };\n\n return glTFMesh;\n}\n\n// UTILS\n\nfunction checkPrimitive(primitive: GLTFMeshPrimitive) {\n if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {\n throw new Error('glTF: Empty primitive detected: Draco decompression failure?');\n }\n}\n\nfunction* makeMeshPrimitiveIterator(scenegraph) {\n for (const mesh of scenegraph.json.meshes || []) {\n for (const primitive of mesh.primitives) {\n yield primitive;\n }\n }\n}\n"],"file":"KHR_draco_mesh_compression.js"}
@@ -8,55 +8,119 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.decode = decode;
9
9
  exports.encode = encode;
10
10
 
11
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
+
13
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
+
11
15
  var _assert = require("../utils/assert");
12
16
 
13
17
  var _gltfScenegraph = _interopRequireDefault(require("../api/gltf-scenegraph"));
14
18
 
15
19
  var _gltfConstants = require("../gltf-utils/gltf-constants");
16
20
 
17
- async function decode(gltfData) {
18
- const gltfScenegraph = new _gltfScenegraph.default(gltfData);
19
- const {
20
- json
21
- } = gltfScenegraph;
22
- const extension = gltfScenegraph.getExtension(_gltfConstants.KHR_LIGHTS_PUNCTUAL);
21
+ 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; } } }; }
22
+
23
+ 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); }
24
+
25
+ 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; }
26
+
27
+ function decode(_x) {
28
+ return _decode.apply(this, arguments);
29
+ }
30
+
31
+ function _decode() {
32
+ _decode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(gltfData) {
33
+ var gltfScenegraph, json, extension, _iterator, _step, node, nodeExtension;
34
+
35
+ return _regenerator.default.wrap(function _callee$(_context) {
36
+ while (1) {
37
+ switch (_context.prev = _context.next) {
38
+ case 0:
39
+ gltfScenegraph = new _gltfScenegraph.default(gltfData);
40
+ json = gltfScenegraph.json;
41
+ extension = gltfScenegraph.getExtension(_gltfConstants.KHR_LIGHTS_PUNCTUAL);
42
+
43
+ if (extension) {
44
+ gltfScenegraph.json.lights = extension.lights;
45
+ gltfScenegraph.removeExtension(_gltfConstants.KHR_LIGHTS_PUNCTUAL);
46
+ }
23
47
 
24
- if (extension) {
25
- gltfScenegraph.json.lights = extension.lights;
26
- gltfScenegraph.removeExtension(_gltfConstants.KHR_LIGHTS_PUNCTUAL);
27
- }
48
+ _iterator = _createForOfIteratorHelper(json.nodes || []);
28
49
 
29
- for (const node of json.nodes || []) {
30
- const nodeExtension = gltfScenegraph.getObjectExtension(node, _gltfConstants.KHR_LIGHTS_PUNCTUAL);
50
+ try {
51
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
52
+ node = _step.value;
53
+ nodeExtension = gltfScenegraph.getObjectExtension(node, _gltfConstants.KHR_LIGHTS_PUNCTUAL);
31
54
 
32
- if (nodeExtension) {
33
- node.light = nodeExtension.light;
34
- }
55
+ if (nodeExtension) {
56
+ node.light = nodeExtension.light;
57
+ }
35
58
 
36
- gltfScenegraph.removeObjectExtension(node, _gltfConstants.KHR_LIGHTS_PUNCTUAL);
37
- }
59
+ gltfScenegraph.removeObjectExtension(node, _gltfConstants.KHR_LIGHTS_PUNCTUAL);
60
+ }
61
+ } catch (err) {
62
+ _iterator.e(err);
63
+ } finally {
64
+ _iterator.f();
65
+ }
66
+
67
+ case 6:
68
+ case "end":
69
+ return _context.stop();
70
+ }
71
+ }
72
+ }, _callee);
73
+ }));
74
+ return _decode.apply(this, arguments);
75
+ }
76
+
77
+ function encode(_x2) {
78
+ return _encode.apply(this, arguments);
38
79
  }
39
80
 
40
- async function encode(gltfData) {
41
- const gltfScenegraph = new _gltfScenegraph.default(gltfData);
42
- const {
43
- json
44
- } = gltfScenegraph;
45
-
46
- if (json.lights) {
47
- const extension = gltfScenegraph.addExtension(_gltfConstants.KHR_LIGHTS_PUNCTUAL);
48
- (0, _assert.assert)(!extension.lights);
49
- extension.lights = json.lights;
50
- delete json.lights;
51
- }
52
-
53
- if (gltfScenegraph.json.lights) {
54
- for (const light of gltfScenegraph.json.lights) {
55
- const node = light.node;
56
- gltfScenegraph.addObjectExtension(node, _gltfConstants.KHR_LIGHTS_PUNCTUAL, light);
57
- }
58
-
59
- delete gltfScenegraph.json.lights;
60
- }
81
+ function _encode() {
82
+ _encode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(gltfData) {
83
+ var gltfScenegraph, json, extension, _iterator2, _step2, light, node;
84
+
85
+ return _regenerator.default.wrap(function _callee2$(_context2) {
86
+ while (1) {
87
+ switch (_context2.prev = _context2.next) {
88
+ case 0:
89
+ gltfScenegraph = new _gltfScenegraph.default(gltfData);
90
+ json = gltfScenegraph.json;
91
+
92
+ if (json.lights) {
93
+ extension = gltfScenegraph.addExtension(_gltfConstants.KHR_LIGHTS_PUNCTUAL);
94
+ (0, _assert.assert)(!extension.lights);
95
+ extension.lights = json.lights;
96
+ delete json.lights;
97
+ }
98
+
99
+ if (gltfScenegraph.json.lights) {
100
+ _iterator2 = _createForOfIteratorHelper(gltfScenegraph.json.lights);
101
+
102
+ try {
103
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
104
+ light = _step2.value;
105
+ node = light.node;
106
+ gltfScenegraph.addObjectExtension(node, _gltfConstants.KHR_LIGHTS_PUNCTUAL, light);
107
+ }
108
+ } catch (err) {
109
+ _iterator2.e(err);
110
+ } finally {
111
+ _iterator2.f();
112
+ }
113
+
114
+ delete gltfScenegraph.json.lights;
115
+ }
116
+
117
+ case 4:
118
+ case "end":
119
+ return _context2.stop();
120
+ }
121
+ }
122
+ }, _callee2);
123
+ }));
124
+ return _encode.apply(this, arguments);
61
125
  }
62
126
  //# sourceMappingURL=KHR_lights_punctual.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/extensions/KHR_lights_punctual.ts"],"names":["decode","gltfData","gltfScenegraph","GLTFScenegraph","json","extension","getExtension","KHR_LIGHTS_PUNCTUAL","lights","removeExtension","node","nodes","nodeExtension","getObjectExtension","light","removeObjectExtension","encode","addExtension","addObjectExtension"],"mappings":";;;;;;;;;;AAKA;;AACA;;AACA;;AAEO,eAAeA,MAAf,CAAsBC,QAAtB,EAA6D;AAClE,QAAMC,cAAc,GAAG,IAAIC,uBAAJ,CAAmBF,QAAnB,CAAvB;AACA,QAAM;AAACG,IAAAA;AAAD,MAASF,cAAf;AAGA,QAAMG,SAAS,GAAGH,cA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;AACF","sourcesContent":["// GLTF EXTENSION: KHR_lights_punctual\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual\n\nimport type {GLTF} from '../types/gltf-types';\n\nimport {assert} from '../utils/assert';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\nimport {KHR_LIGHTS_PUNCTUAL} from '../gltf-utils/gltf-constants';\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Move the light array out of the extension and remove the extension\n const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);\n if (extension) {\n // @ts-ignore\n gltfScenegraph.json.lights = extension.lights;\n gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);\n }\n\n // Any nodes that have the extension, add lights field pointing to light object\n // and remove the extension\n for (const node of json.nodes || []) {\n const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);\n if (nodeExtension) {\n // @ts-ignore\n node.light = nodeExtension.light;\n }\n gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);\n }\n}\n\n// Move the light ar ray out of the extension and remove the extension\nexport async function encode(gltfData): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // @ts-ignore\n if (json.lights) {\n const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);\n // @ts-ignore\n assert(!extension.lights);\n // @ts-ignore\n extension.lights = json.lights;\n // @ts-ignore\n delete json.lights;\n }\n\n // Any nodes that have lights field pointing to light object\n // add the extension\n // @ts-ignore\n if (gltfScenegraph.json.lights) {\n // @ts-ignore\n for (const light of gltfScenegraph.json.lights) {\n const node = light.node;\n gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);\n }\n // @ts-ignore\n delete gltfScenegraph.json.lights;\n }\n}\n"],"file":"KHR_lights_punctual.js"}
1
+ {"version":3,"sources":["../../../../src/lib/extensions/KHR_lights_punctual.ts"],"names":["decode","gltfData","gltfScenegraph","GLTFScenegraph","json","extension","getExtension","KHR_LIGHTS_PUNCTUAL","lights","removeExtension","nodes","node","nodeExtension","getObjectExtension","light","removeObjectExtension","encode","addExtension","addObjectExtension"],"mappings":";;;;;;;;;;;;;;AAKA;;AACA;;AACA;;;;;;;;SAEsBA,M;;;;;sEAAf,iBAAsBC,QAAtB;AAAA;;AAAA;AAAA;AAAA;AAAA;AACCC,YAAAA,cADD,GACkB,IAAIC,uBAAJ,CAAmBF,QAAnB,CADlB;AAEEG,YAAAA,IAFF,GAEUF,cAFV,CAEEE,IAFF;AAKCC,YAAAA,SALD,GAKaH,cAAc,CAACI,YAAf,CAA4BC,kCAA5B,CALb;;AAML,gBAAIF,SAAJ,EAAe;AAEbH,cAAAA,cAAc,CAACE,IAAf,CAAoBI,MAApB,GAA6BH,SAAS,CAACG,MAAvC;AACAN,cAAAA,cAAc,CAACO,eAAf,CAA+BF,kCAA/B;AACD;;AAVI,mDAccH,IAAI,CAACM,KAAL,IAAc,EAd5B;;AAAA;AAcL,kEAAqC;AAA1BC,gBAAAA,IAA0B;AAC7BC,gBAAAA,aAD6B,GACbV,cAAc,CAACW,kBAAf,CAAkCF,IAAlC,EAAwCJ,kCAAxC,CADa;;AAEnC,oBAAIK,aAAJ,EAAmB;AAEjBD,kBAAAA,IAAI,CAACG,KAAL,GAAaF,aAAa,CAACE,KAA3B;AACD;;AACDZ,gBAAAA,cAAc,CAACa,qBAAf,CAAqCJ,IAArC,EAA2CJ,kCAA3C;AACD;AArBI;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;SAyBeS,M;;;;;sEAAf,kBAAsBf,QAAtB;AAAA;;AAAA;AAAA;AAAA;AAAA;AACCC,YAAAA,cADD,GACkB,IAAIC,uBAAJ,CAAmBF,QAAnB,CADlB;AAEEG,YAAAA,IAFF,GAEUF,cAFV,CAEEE,IAFF;;AAKL,gBAAIA,IAAI,CAACI,MAAT,EAAiB;AACTH,cAAAA,SADS,GACGH,cAAc,CAACe,YAAf,CAA4BV,kCAA5B,CADH;AAGf,kCAAO,CAACF,SAAS,CAACG,MAAlB;AAEAH,cAAAA,SAAS,CAACG,MAAV,GAAmBJ,IAAI,CAACI,MAAxB;AAEA,qBAAOJ,IAAI,CAACI,MAAZ;AACD;;AAKD,gBAAIN,cAAc,CAACE,IAAf,CAAoBI,MAAxB,EAAgC;AAAA,sDAEVN,cAAc,CAACE,IAAf,CAAoBI,MAFV;;AAAA;AAE9B,uEAAgD;AAArCM,kBAAAA,KAAqC;AACxCH,kBAAAA,IADwC,GACjCG,KAAK,CAACH,IAD2B;AAE9CT,kBAAAA,cAAc,CAACgB,kBAAf,CAAkCP,IAAlC,EAAwCJ,kCAAxC,EAA6DO,KAA7D;AACD;AAL6B;AAAA;AAAA;AAAA;AAAA;;AAO9B,qBAAOZ,cAAc,CAACE,IAAf,CAAoBI,MAA3B;AACD;;AA1BI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["// GLTF EXTENSION: KHR_lights_punctual\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual\n\nimport type {GLTF} from '../types/gltf-types';\n\nimport {assert} from '../utils/assert';\nimport GLTFScenegraph from '../api/gltf-scenegraph';\nimport {KHR_LIGHTS_PUNCTUAL} from '../gltf-utils/gltf-constants';\n\nexport async function decode(gltfData: {json: GLTF}): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Move the light array out of the extension and remove the extension\n const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);\n if (extension) {\n // @ts-ignore\n gltfScenegraph.json.lights = extension.lights;\n gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);\n }\n\n // Any nodes that have the extension, add lights field pointing to light object\n // and remove the extension\n for (const node of json.nodes || []) {\n const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);\n if (nodeExtension) {\n // @ts-ignore\n node.light = nodeExtension.light;\n }\n gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);\n }\n}\n\n// Move the light ar ray out of the extension and remove the extension\nexport async function encode(gltfData): Promise<void> {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // @ts-ignore\n if (json.lights) {\n const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);\n // @ts-ignore\n assert(!extension.lights);\n // @ts-ignore\n extension.lights = json.lights;\n // @ts-ignore\n delete json.lights;\n }\n\n // Any nodes that have lights field pointing to light object\n // add the extension\n // @ts-ignore\n if (gltfScenegraph.json.lights) {\n // @ts-ignore\n for (const light of gltfScenegraph.json.lights) {\n const node = light.node;\n gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);\n }\n // @ts-ignore\n delete gltfScenegraph.json.lights;\n }\n}\n"],"file":"KHR_lights_punctual.js"}