@loaders.gl/gltf 3.1.0-beta.3 → 3.1.1

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 +37 -14
  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 +7 -7
  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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/extensions/KHR_binary_gltf.ts"],"names":["KHR_BINARY_GLTF","name","preprocess","gltfData","gltfScenegraph","GLTFScenegraph","json","image","images","extension","getObjectExtension","Object","assign","removeObjectExtension","buffers","uri","removeExtension"],"mappings":";;;;;;;;;;AAMA;;AAEA,MAAMA,eAAe,GAAG,iBAAxB;AAGO,MAAMC,IAAI,GAAGD,eAAb;;;AAEA,SAASE,UAAT,CAAoBC,QAApB,EAAkD;AACvD,QAAMC,cAAc,GAAG,IAAIC,uBAAJ,CAAmBF,QAAnB,CAAvB;AACA,QAAM;AAACG,IAAAA;AAAD,MAASF,cAAf;;AAOA,OAAK,MAAMG,KAAX,IAAoBD,IAAI,CAACE,MAAL,IAAe,EAAnC,EAAuC;AACrC,UAAMC,SAAS,GAAGL,cAAc,CAACM,kBAAf,CAChBH,KADgB,EAEhBP,eAFgB,CAAlB;;AAKA,QAAIS,SAAJ,EAAe;AACbE,MAAAA,MAAM,CAACC,MAAP,CAAcL,KAAd,EAAqBE,SAArB;AACD;;AACDL,IAAAA,cAAc,CAACS,qBAAf,CAAqCN,KAArC,EAA4CP,eAA5C;AACD;;AAMD,MAAIM,IAAI,CAACQ,OAAL,IAAgBR,IAAI,CAACQ,OAAL,CAAa,CAAb,CAApB,EAAqC;AACnC,WAAOR,IAAI,CAACQ,OAAL,CAAa,CAAb,EAAgBC,GAAvB;AACD;;AAGDX,EAAAA,cAAc,CAACY,eAAf,CAA+BhB,eAA/B;AACD","sourcesContent":["// GLTF 1.0 EXTENSION: KHR_binary_glTF\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-types';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_BINARY_GLTF = 'KHR_binary_glTF';\n\n/** Extension name */\nexport const name = KHR_BINARY_GLTF;\n\nexport function preprocess(gltfData: {json: GLTF}): void {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Note: json.buffers.binary_glTF also needs to be replaced\n // This is currently done during gltf normalization\n\n // Image and shader nodes can have the extension\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json\n for (const image of json.images || []) {\n const extension = gltfScenegraph.getObjectExtension<GLTF_KHR_binary_glTF>(\n image,\n KHR_BINARY_GLTF\n );\n // The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in\n if (extension) {\n Object.assign(image, extension);\n }\n gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);\n }\n\n // TODO shaders - At least traverse and throw error if used?\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json\n\n // glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0\n if (json.buffers && json.buffers[0]) {\n delete json.buffers[0].uri;\n }\n\n // Remove the top-level extension as it has now been removed from all nodes\n gltfScenegraph.removeExtension(KHR_BINARY_GLTF);\n}\n\n// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0\n// export function encode() {\n// throw new Error(KHR_BINARY_GLTF);\n// }\n"],"file":"KHR_binary_gltf.js"}
1
+ {"version":3,"sources":["../../../../src/lib/extensions/KHR_binary_gltf.ts"],"names":["KHR_BINARY_GLTF","name","preprocess","gltfData","gltfScenegraph","GLTFScenegraph","json","images","image","extension","getObjectExtension","Object","assign","removeObjectExtension","buffers","uri","removeExtension"],"mappings":";;;;;;;;;;AAMA;;;;;;;;AAEA,IAAMA,eAAe,GAAG,iBAAxB;AAGO,IAAMC,IAAI,GAAGD,eAAb;;;AAEA,SAASE,UAAT,CAAoBC,QAApB,EAAkD;AACvD,MAAMC,cAAc,GAAG,IAAIC,uBAAJ,CAAmBF,QAAnB,CAAvB;AACA,MAAOG,IAAP,GAAeF,cAAf,CAAOE,IAAP;;AAFuD,6CASnCA,IAAI,CAACC,MAAL,IAAe,EAToB;AAAA;;AAAA;AASvD,wDAAuC;AAAA,UAA5BC,KAA4B;AACrC,UAAMC,SAAS,GAAGL,cAAc,CAACM,kBAAf,CAChBF,KADgB,EAEhBR,eAFgB,CAAlB;;AAKA,UAAIS,SAAJ,EAAe;AACbE,QAAAA,MAAM,CAACC,MAAP,CAAcJ,KAAd,EAAqBC,SAArB;AACD;;AACDL,MAAAA,cAAc,CAACS,qBAAf,CAAqCL,KAArC,EAA4CR,eAA5C;AACD;AAnBsD;AAAA;AAAA;AAAA;AAAA;;AAyBvD,MAAIM,IAAI,CAACQ,OAAL,IAAgBR,IAAI,CAACQ,OAAL,CAAa,CAAb,CAApB,EAAqC;AACnC,WAAOR,IAAI,CAACQ,OAAL,CAAa,CAAb,EAAgBC,GAAvB;AACD;;AAGDX,EAAAA,cAAc,CAACY,eAAf,CAA+BhB,eAA/B;AACD","sourcesContent":["// GLTF 1.0 EXTENSION: KHR_binary_glTF\n// https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_binary_glTF} from '../types/gltf-types';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_BINARY_GLTF = 'KHR_binary_glTF';\n\n/** Extension name */\nexport const name = KHR_BINARY_GLTF;\n\nexport function preprocess(gltfData: {json: GLTF}): void {\n const gltfScenegraph = new GLTFScenegraph(gltfData);\n const {json} = gltfScenegraph;\n\n // Note: json.buffers.binary_glTF also needs to be replaced\n // This is currently done during gltf normalization\n\n // Image and shader nodes can have the extension\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json\n for (const image of json.images || []) {\n const extension = gltfScenegraph.getObjectExtension<GLTF_KHR_binary_glTF>(\n image,\n KHR_BINARY_GLTF\n );\n // The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in\n if (extension) {\n Object.assign(image, extension);\n }\n gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);\n }\n\n // TODO shaders - At least traverse and throw error if used?\n // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json\n\n // glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0\n if (json.buffers && json.buffers[0]) {\n delete json.buffers[0].uri;\n }\n\n // Remove the top-level extension as it has now been removed from all nodes\n gltfScenegraph.removeExtension(KHR_BINARY_GLTF);\n}\n\n// KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0\n// export function encode() {\n// throw new Error(KHR_BINARY_GLTF);\n// }\n"],"file":"KHR_binary_gltf.js"}
@@ -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", {
@@ -10,6 +12,14 @@ exports.decode = decode;
10
12
  exports.encode = encode;
11
13
  exports.name = void 0;
12
14
 
15
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
16
+
17
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
18
+
19
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
+
21
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
22
+
13
23
  var _draco = require("@loaders.gl/draco");
14
24
 
15
25
  var _loaderUtils = require("@loaders.gl/loader-utils");
@@ -18,113 +28,212 @@ var _gltfScenegraph = _interopRequireDefault(require("../api/gltf-scenegraph"));
18
28
 
19
29
  var _gltfAttributeUtils = require("../gltf-utils/gltf-attribute-utils");
20
30
 
21
- const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
22
- const name = KHR_DRACO_MESH_COMPRESSION;
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; }
32
+
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; }
34
+
35
+ var _marked = _regeneratorRuntime2.mark(makeMeshPrimitiveIterator);
36
+
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; } } }; }
38
+
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
+
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; }
42
+
43
+ var KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
44
+ var name = KHR_DRACO_MESH_COMPRESSION;
23
45
  exports.name = name;
24
46
 
25
47
  function preprocess(gltfData, options, context) {
26
- const scenegraph = new _gltfScenegraph.default(gltfData);
48
+ var scenegraph = new _gltfScenegraph.default(gltfData);
49
+
50
+ var _iterator = _createForOfIteratorHelper(makeMeshPrimitiveIterator(scenegraph)),
51
+ _step;
27
52
 
28
- for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
29
- if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {}
53
+ try {
54
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
55
+ var primitive = _step.value;
56
+
57
+ if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {}
58
+ }
59
+ } catch (err) {
60
+ _iterator.e(err);
61
+ } finally {
62
+ _iterator.f();
30
63
  }
31
64
  }
32
65
 
33
- async function decode(gltfData, options, context) {
34
- var _options$gltf;
66
+ function decode(_x, _x2, _x3) {
67
+ return _decode.apply(this, arguments);
68
+ }
35
69
 
36
- if (!(options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.decompressMeshes)) {
37
- return;
38
- }
70
+ function _decode() {
71
+ _decode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(gltfData, options, context) {
72
+ var _options$gltf;
39
73
 
40
- const scenegraph = new _gltfScenegraph.default(gltfData);
41
- const promises = [];
74
+ var scenegraph, promises, _iterator5, _step5, primitive;
42
75
 
43
- for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
44
- if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
45
- promises.push(decompressPrimitive(scenegraph, primitive, options, context));
46
- }
47
- }
76
+ return _regenerator.default.wrap(function _callee$(_context2) {
77
+ while (1) {
78
+ switch (_context2.prev = _context2.next) {
79
+ case 0:
80
+ if (options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.decompressMeshes) {
81
+ _context2.next = 2;
82
+ break;
83
+ }
48
84
 
49
- await Promise.all(promises);
50
- scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
51
- }
85
+ return _context2.abrupt("return");
52
86
 
53
- function encode(gltfData, options = {}) {
54
- const scenegraph = new _gltfScenegraph.default(gltfData);
87
+ case 2:
88
+ scenegraph = new _gltfScenegraph.default(gltfData);
89
+ promises = [];
90
+ _iterator5 = _createForOfIteratorHelper(makeMeshPrimitiveIterator(scenegraph));
55
91
 
56
- for (const mesh of scenegraph.json.meshes || []) {
57
- compressMesh(mesh, options);
58
- scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);
59
- }
60
- }
92
+ try {
93
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
94
+ primitive = _step5.value;
61
95
 
62
- async function decompressPrimitive(scenegraph, primitive, options, context) {
63
- const dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
96
+ if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
97
+ promises.push(decompressPrimitive(scenegraph, primitive, options, context));
98
+ }
99
+ }
100
+ } catch (err) {
101
+ _iterator5.e(err);
102
+ } finally {
103
+ _iterator5.f();
104
+ }
64
105
 
65
- if (!dracoExtension) {
66
- return;
67
- }
106
+ _context2.next = 8;
107
+ return Promise.all(promises);
68
108
 
69
- const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);
70
- const bufferCopy = (0, _loaderUtils.sliceArrayBuffer)(buffer.buffer, buffer.byteOffset);
71
- const {
72
- parse
73
- } = context;
74
- const dracoOptions = { ...options
75
- };
76
- delete dracoOptions['3d-tiles'];
77
- const decodedData = await parse(bufferCopy, _draco.DracoLoader, dracoOptions, context);
78
- const decodedAttributes = (0, _gltfAttributeUtils.getGLTFAccessors)(decodedData.attributes);
79
-
80
- for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {
81
- if (attributeName in primitive.attributes) {
82
- const accessorIndex = primitive.attributes[attributeName];
83
- const accessor = scenegraph.getAccessor(accessorIndex);
84
-
85
- if (accessor !== null && accessor !== void 0 && accessor.min && accessor !== null && accessor !== void 0 && accessor.max) {
86
- decodedAttribute.min = accessor.min;
87
- decodedAttribute.max = accessor.max;
109
+ case 8:
110
+ scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
111
+
112
+ case 9:
113
+ case "end":
114
+ return _context2.stop();
115
+ }
88
116
  }
117
+ }, _callee);
118
+ }));
119
+ return _decode.apply(this, arguments);
120
+ }
121
+
122
+ function encode(gltfData) {
123
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
124
+ var scenegraph = new _gltfScenegraph.default(gltfData);
125
+
126
+ var _iterator2 = _createForOfIteratorHelper(scenegraph.json.meshes || []),
127
+ _step2;
128
+
129
+ try {
130
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
131
+ var mesh = _step2.value;
132
+ compressMesh(mesh, options);
133
+ scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);
89
134
  }
135
+ } catch (err) {
136
+ _iterator2.e(err);
137
+ } finally {
138
+ _iterator2.f();
90
139
  }
140
+ }
91
141
 
92
- primitive.attributes = decodedAttributes;
142
+ function decompressPrimitive(_x4, _x5, _x6, _x7) {
143
+ return _decompressPrimitive.apply(this, arguments);
144
+ }
93
145
 
94
- if (decodedData.indices) {
95
- primitive.indices = (0, _gltfAttributeUtils.getGLTFAccessor)(decodedData.indices);
96
- }
146
+ function _decompressPrimitive() {
147
+ _decompressPrimitive = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(scenegraph, primitive, options, context) {
148
+ var dracoExtension, buffer, bufferCopy, parse, dracoOptions, decodedData, decodedAttributes, _i, _Object$entries, _Object$entries$_i, attributeName, decodedAttribute, accessorIndex, accessor;
149
+
150
+ return _regenerator.default.wrap(function _callee2$(_context3) {
151
+ while (1) {
152
+ switch (_context3.prev = _context3.next) {
153
+ case 0:
154
+ dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
155
+
156
+ if (dracoExtension) {
157
+ _context3.next = 3;
158
+ break;
159
+ }
160
+
161
+ return _context3.abrupt("return");
162
+
163
+ case 3:
164
+ buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);
165
+ bufferCopy = (0, _loaderUtils.sliceArrayBuffer)(buffer.buffer, buffer.byteOffset);
166
+ parse = context.parse;
167
+ dracoOptions = _objectSpread({}, options);
168
+ delete dracoOptions['3d-tiles'];
169
+ _context3.next = 10;
170
+ return parse(bufferCopy, _draco.DracoLoader, dracoOptions, context);
97
171
 
98
- checkPrimitive(primitive);
172
+ case 10:
173
+ decodedData = _context3.sent;
174
+ decodedAttributes = (0, _gltfAttributeUtils.getGLTFAccessors)(decodedData.attributes);
175
+
176
+ for (_i = 0, _Object$entries = Object.entries(decodedAttributes); _i < _Object$entries.length; _i++) {
177
+ _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2), attributeName = _Object$entries$_i[0], decodedAttribute = _Object$entries$_i[1];
178
+
179
+ if (attributeName in primitive.attributes) {
180
+ accessorIndex = primitive.attributes[attributeName];
181
+ accessor = scenegraph.getAccessor(accessorIndex);
182
+
183
+ if (accessor !== null && accessor !== void 0 && accessor.min && accessor !== null && accessor !== void 0 && accessor.max) {
184
+ decodedAttribute.min = accessor.min;
185
+ decodedAttribute.max = accessor.max;
186
+ }
187
+ }
188
+ }
189
+
190
+ primitive.attributes = decodedAttributes;
191
+
192
+ if (decodedData.indices) {
193
+ primitive.indices = (0, _gltfAttributeUtils.getGLTFAccessor)(decodedData.indices);
194
+ }
195
+
196
+ checkPrimitive(primitive);
197
+
198
+ case 16:
199
+ case "end":
200
+ return _context3.stop();
201
+ }
202
+ }
203
+ }, _callee2);
204
+ }));
205
+ return _decompressPrimitive.apply(this, arguments);
99
206
  }
100
207
 
101
- function compressMesh(attributes, indices, mode = 4, options, context) {
208
+ function compressMesh(attributes, indices) {
102
209
  var _context$parseSync;
103
210
 
211
+ var mode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4;
212
+ var options = arguments.length > 3 ? arguments[3] : undefined;
213
+ var context = arguments.length > 4 ? arguments[4] : undefined;
214
+
104
215
  if (!options.DracoWriter) {
105
216
  throw new Error('options.gltf.DracoWriter not provided');
106
217
  }
107
218
 
108
- const compressedData = options.DracoWriter.encodeSync({
109
- attributes
219
+ var compressedData = options.DracoWriter.encodeSync({
220
+ attributes: attributes
110
221
  });
111
- const decodedData = context === null || context === void 0 ? void 0 : (_context$parseSync = context.parseSync) === null || _context$parseSync === void 0 ? void 0 : _context$parseSync.call(context, {
112
- attributes
222
+ var decodedData = context === null || context === void 0 ? void 0 : (_context$parseSync = context.parseSync) === null || _context$parseSync === void 0 ? void 0 : _context$parseSync.call(context, {
223
+ attributes: attributes
113
224
  });
114
225
 
115
- const fauxAccessors = options._addFauxAttributes(decodedData.attributes);
226
+ var fauxAccessors = options._addFauxAttributes(decodedData.attributes);
116
227
 
117
- const bufferViewIndex = options.addBufferView(compressedData);
118
- const glTFMesh = {
228
+ var bufferViewIndex = options.addBufferView(compressedData);
229
+ var glTFMesh = {
119
230
  primitives: [{
120
231
  attributes: fauxAccessors,
121
- mode,
122
- extensions: {
123
- [KHR_DRACO_MESH_COMPRESSION]: {
124
- bufferView: bufferViewIndex,
125
- attributes: fauxAccessors
126
- }
127
- }
232
+ mode: mode,
233
+ extensions: (0, _defineProperty2.default)({}, KHR_DRACO_MESH_COMPRESSION, {
234
+ bufferView: bufferViewIndex,
235
+ attributes: fauxAccessors
236
+ })
128
237
  }]
129
238
  };
130
239
  return glTFMesh;
@@ -136,11 +245,87 @@ function checkPrimitive(primitive) {
136
245
  }
137
246
  }
138
247
 
139
- function* makeMeshPrimitiveIterator(scenegraph) {
140
- for (const mesh of scenegraph.json.meshes || []) {
141
- for (const primitive of mesh.primitives) {
142
- yield primitive;
248
+ function makeMeshPrimitiveIterator(scenegraph) {
249
+ var _iterator3, _step3, mesh, _iterator4, _step4, primitive;
250
+
251
+ return _regenerator.default.wrap(function makeMeshPrimitiveIterator$(_context) {
252
+ while (1) {
253
+ switch (_context.prev = _context.next) {
254
+ case 0:
255
+ _iterator3 = _createForOfIteratorHelper(scenegraph.json.meshes || []);
256
+ _context.prev = 1;
257
+
258
+ _iterator3.s();
259
+
260
+ case 3:
261
+ if ((_step3 = _iterator3.n()).done) {
262
+ _context.next = 24;
263
+ break;
264
+ }
265
+
266
+ mesh = _step3.value;
267
+ _iterator4 = _createForOfIteratorHelper(mesh.primitives);
268
+ _context.prev = 6;
269
+
270
+ _iterator4.s();
271
+
272
+ case 8:
273
+ if ((_step4 = _iterator4.n()).done) {
274
+ _context.next = 14;
275
+ break;
276
+ }
277
+
278
+ primitive = _step4.value;
279
+ _context.next = 12;
280
+ return primitive;
281
+
282
+ case 12:
283
+ _context.next = 8;
284
+ break;
285
+
286
+ case 14:
287
+ _context.next = 19;
288
+ break;
289
+
290
+ case 16:
291
+ _context.prev = 16;
292
+ _context.t0 = _context["catch"](6);
293
+
294
+ _iterator4.e(_context.t0);
295
+
296
+ case 19:
297
+ _context.prev = 19;
298
+
299
+ _iterator4.f();
300
+
301
+ return _context.finish(19);
302
+
303
+ case 22:
304
+ _context.next = 3;
305
+ break;
306
+
307
+ case 24:
308
+ _context.next = 29;
309
+ break;
310
+
311
+ case 26:
312
+ _context.prev = 26;
313
+ _context.t1 = _context["catch"](1);
314
+
315
+ _iterator3.e(_context.t1);
316
+
317
+ case 29:
318
+ _context.prev = 29;
319
+
320
+ _iterator3.f();
321
+
322
+ return _context.finish(29);
323
+
324
+ case 32:
325
+ case "end":
326
+ return _context.stop();
327
+ }
143
328
  }
144
- }
329
+ }, _marked, null, [[1, 26, 29, 32], [6, 16, 19, 22]]);
145
330
  }
146
331
  //# sourceMappingURL=KHR_draco_mesh_compression.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/extensions/KHR_draco_mesh_compression.ts"],"names":["KHR_DRACO_MESH_COMPRESSION","name","preprocess","gltfData","options","context","scenegraph","Scenegraph","primitive","makeMeshPrimitiveIterator","getObjectExtension","decode","gltf","decompressMeshes","promises","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":";;;;;;;;;;;;AAcA;;AAEA;;AACA;;AACA;;AAEA,MAAMA,0BAA0B,GAAG,4BAAnC;AAGO,MAAMC,IAAI,GAAGD,0BAAb;;;AAEA,SAASE,UAAT,CACLC,QADK,EAELC,OAFK,EAGLC,OAHK,EAIC;AACN,QAAMC,UAAU,GAAG,IAAIC,uBAAJ,CAAeJ,QAAf,CAAnB;;AACA,OAAK,MAAMK,SAAX,IAAwBC,yBAAyB,CAACH,UAAD,CAAjD,EAA+D;AAC7D,QAAIA,UAAU,CAACI,kBAAX,CAA8BF,SAA9B,EAAyCR,0BAAzC,CAAJ,EAA0E,CAEzE;AACF;AACF;;AAEM,eAAeW,MAAf,CACLR,QADK,EAELC,OAFK,EAGLC,OAHK,EAIU;AAAA;;AACf,MAAI,EAACD,OAAD,aAACA,OAAD,gCAACA,OAAO,CAAEQ,IAAV,0CAAC,cAAeC,gBAAhB,CAAJ,EAAsC;AACpC;AACD;;AAED,QAAMP,UAAU,GAAG,IAAIC,uBAAJ,CAAeJ,QAAf,CAAnB;AACA,QAAMW,QAAyB,GAAG,EAAlC;;AACA,OAAK,MAAMN,SAAX,IAAwBC,yBAAyB,CAACH,UAAD,CAAjD,E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;AAAChB,IAAAA;AAAD,GAA/B,CAAvB;AAQA,QAAMH,WAAW,GAAG7B,OAAH,aAAGA,OAAH,6CAAGA,OAAO,CAAEiD,SAAZ,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,SAAC7D,0BAAD,GAA8B;AAC5B6B,UAAAA,UAAU,EAAE4B,eADgB;AAE5BpB,UAAAA,UAAU,EAAEkB;AAFgB;AADpB;AAHd,KADU;AADG,GAAjB;AAeA,SAAOI,QAAP;AACD;;AAID,SAASX,cAAT,CAAwBxC,SAAxB,EAAsD;AACpD,MAAI,CAACA,SAAS,CAAC6B,UAAX,IAAyBG,MAAM,CAACsB,IAAP,CAAYtD,SAAS,CAAC6B,UAAtB,EAAkC0B,MAAlC,GAA2C,CAAxE,EAA2E;AACzE,UAAM,IAAIZ,KAAJ,CAAU,8DAAV,CAAN;AACD;AACF;;AAED,UAAU1C,yBAAV,CAAoCH,UAApC,EAAgD;AAC9C,OAAK,MAAMe,IAAX,IAAmBf,UAAU,CAACgB,IAAX,CAAgBC,MAAhB,IAA0B,EAA7C,EAAiD;AAC/C,SAAK,MAAMf,SAAX,IAAwBa,IAAI,CAACuC,UAA7B,EAAyC;AACvC,YAAMpD,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/* eslint-disable camelcase */\n\n/* eslint-disable camelcase */\nimport type {\n GLTF,\n GLTFAccessor,\n GLTFMeshPrimitive,\n GLTF_KHR_draco_mesh_compression\n} 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, DracoMesh} from '@loaders.gl/draco';\nimport {sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {default as Scenegraph} from '../api/gltf-scenegraph';\nimport {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';\n\nconst KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';\n\n/** Extension name */\nexport const name = KHR_DRACO_MESH_COMPRESSION;\n\nexport function preprocess(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): void {\n const scenegraph = new Scenegraph(gltfData);\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n // TODO - Remove fallback accessors to make sure we don't load unnecessary buffers\n }\n }\n}\n\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<GLTF_KHR_draco_mesh_compression>(\n primitive,\n KHR_DRACO_MESH_COMPRESSION\n );\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(bufferCopy, DracoLoader, dracoOptions, context)) as DracoMesh;\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","KHR_DRACO_MESH_COMPRESSION","name","preprocess","gltfData","options","context","scenegraph","Scenegraph","primitive","getObjectExtension","decode","gltf","decompressMeshes","promises","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":";;;;;;;;;;;;;;;;;;;;;;AAcA;;AAEA;;AACA;;AACA;;;;;;wCAsKUA,yB;;;;;;;;AApKV,IAAMC,0BAA0B,GAAG,4BAAnC;AAGO,IAAMC,IAAI,GAAGD,0BAAb;;;AAEA,SAASE,UAAT,CACLC,QADK,EAELC,OAFK,EAGLC,OAHK,EAIC;AACN,MAAMC,UAAU,GAAG,IAAIC,uBAAJ,CAAeJ,QAAf,CAAnB;;AADM,6CAEkBJ,yBAAyB,CAACO,UAAD,CAF3C;AAAA;;AAAA;AAEN,wDAA+D;AAAA,UAApDE,SAAoD;;AAC7D,UAAIF,UAAU,CAACG,kBAAX,CAA8BD,SAA9B,EAAyCR,0BAAzC,CAAJ,EAA0E,CAEzE;AACF;AANK;AAAA;AAAA;AAAA;AAAA;AAOP;;SAEqBU,M;;;;;sEAAf,iBACLP,QADK,EAELC,OAFK,EAGLC,OAHK;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,gBAKAD,OALA,aAKAA,OALA,gCAKAA,OAAO,CAAEO,IALT,0CAKA,cAAeC,gBALf;AAAA;AAAA;AAAA;;AAAA;;AAAA;AASCN,YAAAA,UATD,GASc,IAAIC,uBAAJ,CAAeJ,QAAf,CATd;AAUCU,YAAAA,QAVD,GAU6B,EAV7B;AAAA,oDAWmBd,yBAAyB,CAACO,UAAD,CAX5C;;AAAA;AAWL,qEAA+D;AAApDE,gBAAAA,SAAoD;;AAC7D,oBAAIF,UAAU,CAACG,kBAAX,C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ACqBA,UAAU,CAACc,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;;AAEenD,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/* eslint-disable camelcase */\n\n/* eslint-disable camelcase */\nimport type {\n GLTF,\n GLTFAccessor,\n GLTFMeshPrimitive,\n GLTF_KHR_draco_mesh_compression\n} 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, DracoMesh} from '@loaders.gl/draco';\nimport {sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {default as Scenegraph} from '../api/gltf-scenegraph';\nimport {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';\n\nconst KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';\n\n/** Extension name */\nexport const name = KHR_DRACO_MESH_COMPRESSION;\n\nexport function preprocess(\n gltfData: {json: GLTF},\n options: GLTFLoaderOptions,\n context: LoaderContext\n): void {\n const scenegraph = new Scenegraph(gltfData);\n for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {\n if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {\n // TODO - Remove fallback accessors to make sure we don't load unnecessary buffers\n }\n }\n}\n\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<GLTF_KHR_draco_mesh_compression>(\n primitive,\n KHR_DRACO_MESH_COMPRESSION\n );\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(bufferCopy, DracoLoader, dracoOptions, context)) as DracoMesh;\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"}
@@ -10,24 +10,38 @@ exports.name = void 0;
10
10
 
11
11
  var _gltfScenegraph = _interopRequireDefault(require("../api/gltf-scenegraph"));
12
12
 
13
- const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
14
- const name = KHR_TEXTURE_BASISU;
13
+ 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; } } }; }
14
+
15
+ 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); }
16
+
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
+
19
+ var KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
20
+ var name = KHR_TEXTURE_BASISU;
15
21
  exports.name = name;
16
22
 
17
23
  function preprocess(gltfData, options) {
18
- const scene = new _gltfScenegraph.default(gltfData);
19
- const {
20
- json
21
- } = scene;
24
+ var scene = new _gltfScenegraph.default(gltfData);
25
+ var json = scene.json;
22
26
 
23
- for (const texture of json.textures || []) {
24
- const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
27
+ var _iterator = _createForOfIteratorHelper(json.textures || []),
28
+ _step;
25
29
 
26
- if (extension) {
27
- texture.source = extension.source;
28
- }
30
+ try {
31
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
32
+ var texture = _step.value;
33
+ var extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
34
+
35
+ if (extension) {
36
+ texture.source = extension.source;
37
+ }
29
38
 
30
- scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
39
+ scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
40
+ }
41
+ } catch (err) {
42
+ _iterator.e(err);
43
+ } finally {
44
+ _iterator.f();
31
45
  }
32
46
 
33
47
  scene.removeExtension(KHR_TEXTURE_BASISU);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/extensions/KHR_texture_basisu.ts"],"names":["KHR_TEXTURE_BASISU","name","preprocess","gltfData","options","scene","GLTFScenegraph","json","texture","textures","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"mappings":";;;;;;;;;;AAOA;;AAEA,MAAMA,kBAAkB,GAAG,oBAA3B;AAGO,MAAMC,IAAI,GAAGD,kBAAb;;;AAMA,SAASE,UAAT,CAAoBC,QAApB,EAA4CC,OAA5C,EAA8E;AACnF,QAAMC,KAAK,GAAG,IAAIC,uBAAJ,CAAmBH,QAAnB,CAAd;AACA,QAAM;AAACI,IAAAA;AAAD,MAASF,KAAf;;AAEA,OAAK,MAAMG,OAAX,IAAsBD,IAAI,CAACE,QAAL,IAAiB,EAAvC,EAA2C;AACzC,UAAMC,SAAS,GAAGL,KAAK,CAACM,kBAAN,CAChBH,OADgB,EAEhBR,kBAFgB,CAAlB;;AAIA,QAAIU,SAAJ,EAAe;AACbF,MAAAA,OAAO,CAACI,MAAR,GAAiBF,SAAS,CAACE,MAA3B;AACD;;AACDP,IAAAA,KAAK,CAACQ,qBAAN,CAA4BL,OAA5B,EAAqCR,kBAArC;AACD;;AAGDK,EAAAA,KAAK,CAACS,eAAN,CAAsBd,kBAAtB;AACD","sourcesContent":["// GLTF EXTENSION: KHR_texture_basisu\n// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_TEXTURE_BASISU = 'KHR_texture_basisu';\n\n/** Extension name */\nexport const name = KHR_TEXTURE_BASISU;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scene = new GLTFScenegraph(gltfData);\n const {json} = scene;\n\n for (const texture of json.textures || []) {\n const extension = scene.getObjectExtension<GLTF_KHR_texture_basisu>(\n texture,\n KHR_TEXTURE_BASISU\n );\n if (extension) {\n texture.source = extension.source;\n }\n scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);\n }\n\n // Remove the top-level extension\n scene.removeExtension(KHR_TEXTURE_BASISU);\n}\n"],"file":"KHR_texture_basisu.js"}
1
+ {"version":3,"sources":["../../../../src/lib/extensions/KHR_texture_basisu.ts"],"names":["KHR_TEXTURE_BASISU","name","preprocess","gltfData","options","scene","GLTFScenegraph","json","textures","texture","extension","getObjectExtension","source","removeObjectExtension","removeExtension"],"mappings":";;;;;;;;;;AAOA;;;;;;;;AAEA,IAAMA,kBAAkB,GAAG,oBAA3B;AAGO,IAAMC,IAAI,GAAGD,kBAAb;;;AAMA,SAASE,UAAT,CAAoBC,QAApB,EAA4CC,OAA5C,EAA8E;AACnF,MAAMC,KAAK,GAAG,IAAIC,uBAAJ,CAAmBH,QAAnB,CAAd;AACA,MAAOI,IAAP,GAAeF,KAAf,CAAOE,IAAP;;AAFmF,6CAI7DA,IAAI,CAACC,QAAL,IAAiB,EAJ4C;AAAA;;AAAA;AAInF,wDAA2C;AAAA,UAAhCC,OAAgC;AACzC,UAAMC,SAAS,GAAGL,KAAK,CAACM,kBAAN,CAChBF,OADgB,EAEhBT,kBAFgB,CAAlB;;AAIA,UAAIU,SAAJ,EAAe;AACbD,QAAAA,OAAO,CAACG,MAAR,GAAiBF,SAAS,CAACE,MAA3B;AACD;;AACDP,MAAAA,KAAK,CAACQ,qBAAN,CAA4BJ,OAA5B,EAAqCT,kBAArC;AACD;AAbkF;AAAA;AAAA;AAAA;AAAA;;AAgBnFK,EAAAA,KAAK,CAACS,eAAN,CAAsBd,kBAAtB;AACD","sourcesContent":["// GLTF EXTENSION: KHR_texture_basisu\n// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_basisu\n/* eslint-disable camelcase */\n\nimport type {GLTF, GLTF_KHR_texture_basisu} from '../types/gltf-types';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport GLTFScenegraph from '../api/gltf-scenegraph';\n\nconst KHR_TEXTURE_BASISU = 'KHR_texture_basisu';\n\n/** Extension name */\nexport const name = KHR_TEXTURE_BASISU;\n\n/**\n * Replaces a texture source reference with the extension texture\n * Done in preprocess() to prevent load of default image\n */\nexport function preprocess(gltfData: {json: GLTF}, options: GLTFLoaderOptions): void {\n const scene = new GLTFScenegraph(gltfData);\n const {json} = scene;\n\n for (const texture of json.textures || []) {\n const extension = scene.getObjectExtension<GLTF_KHR_texture_basisu>(\n texture,\n KHR_TEXTURE_BASISU\n );\n if (extension) {\n texture.source = extension.source;\n }\n scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);\n }\n\n // Remove the top-level extension\n scene.removeExtension(KHR_TEXTURE_BASISU);\n}\n"],"file":"KHR_texture_basisu.js"}