UNPKG

@softrobot/loaders.gl-draco

Version:

Framework-independent loader and writer for Draco compressed meshes and point clouds

214 lines (181 loc) 7.86 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; 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; } 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) { _defineProperty(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; } import { loadLibrary, global } from '@loaders.gl/worker-utils'; var DRACO_VERSION = '1.4.1'; var DRACO_JS_DECODER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_decoder.js"); var DRACO_WASM_WRAPPER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_wasm_wrapper.js"); var DRACO_WASM_DECODER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_decoder.wasm"); var DRACO_ENCODER_URL = "https://raw.githubusercontent.com/google/draco/".concat(DRACO_VERSION, "/javascript/draco_encoder.js"); var loadDecoderPromise; var loadEncoderPromise; export function loadDracoDecoderModule(_x) { return _loadDracoDecoderModule.apply(this, arguments); } function _loadDracoDecoderModule() { _loadDracoDecoderModule = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(options) { var modules; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: modules = options.modules || {}; if (modules.draco3d) { loadDecoderPromise = loadDecoderPromise || modules.draco3d.createDecoderModule({}).then(function (draco) { return { draco: draco }; }); } else { loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options); } _context.next = 4; return loadDecoderPromise; case 4: return _context.abrupt("return", _context.sent); case 5: case "end": return _context.stop(); } } }, _callee); })); return _loadDracoDecoderModule.apply(this, arguments); } export function loadDracoEncoderModule(_x2) { return _loadDracoEncoderModule.apply(this, arguments); } function _loadDracoEncoderModule() { _loadDracoEncoderModule = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(options) { var modules; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: modules = options.modules || {}; if (modules.draco3d) { loadEncoderPromise = loadEncoderPromise || modules.draco3d.createEncoderModule({}).then(function (draco) { return { draco: draco }; }); } else { loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options); } _context2.next = 4; return loadEncoderPromise; case 4: return _context2.abrupt("return", _context2.sent); case 5: case "end": return _context2.stop(); } } }, _callee2); })); return _loadDracoEncoderModule.apply(this, arguments); } function loadDracoDecoder(_x3) { return _loadDracoDecoder.apply(this, arguments); } function _loadDracoDecoder() { _loadDracoDecoder = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(options) { var DracoDecoderModule, wasmBinary, _yield$Promise$all, _yield$Promise$all2; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.t0 = options.draco && options.draco.decoderType; _context3.next = _context3.t0 === 'js' ? 3 : _context3.t0 === 'wasm' ? 7 : 7; break; case 3: _context3.next = 5; return loadLibrary(DRACO_JS_DECODER_URL, 'draco', options); case 5: DracoDecoderModule = _context3.sent; return _context3.abrupt("break", 21); case 7: _context3.t1 = Promise; _context3.next = 10; return loadLibrary(DRACO_WASM_WRAPPER_URL, 'draco', options); case 10: _context3.t2 = _context3.sent; _context3.next = 13; return loadLibrary(DRACO_WASM_DECODER_URL, 'draco', options); case 13: _context3.t3 = _context3.sent; _context3.t4 = [_context3.t2, _context3.t3]; _context3.next = 17; return _context3.t1.all.call(_context3.t1, _context3.t4); case 17: _yield$Promise$all = _context3.sent; _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2); DracoDecoderModule = _yield$Promise$all2[0]; wasmBinary = _yield$Promise$all2[1]; case 21: DracoDecoderModule = DracoDecoderModule || global.DracoDecoderModule; _context3.next = 24; return initializeDracoDecoder(DracoDecoderModule, wasmBinary); case 24: return _context3.abrupt("return", _context3.sent); case 25: case "end": return _context3.stop(); } } }, _callee3); })); return _loadDracoDecoder.apply(this, arguments); } function initializeDracoDecoder(DracoDecoderModule, wasmBinary) { var options = {}; if (wasmBinary) { options.wasmBinary = wasmBinary; } return new Promise(function (resolve) { DracoDecoderModule(_objectSpread(_objectSpread({}, options), {}, { onModuleLoaded: function onModuleLoaded(draco) { return resolve({ draco: draco }); } })); }); } function loadDracoEncoder(_x4) { return _loadDracoEncoder.apply(this, arguments); } function _loadDracoEncoder() { _loadDracoEncoder = _asyncToGenerator(_regeneratorRuntime.mark(function _callee4(options) { var DracoEncoderModule; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return loadLibrary(DRACO_ENCODER_URL, 'draco', options); case 2: DracoEncoderModule = _context4.sent; DracoEncoderModule = DracoEncoderModule || global.DracoEncoderModule; return _context4.abrupt("return", new Promise(function (resolve) { DracoEncoderModule({ onModuleLoaded: function onModuleLoaded(draco) { return resolve({ draco: draco }); } }); })); case 5: case "end": return _context4.stop(); } } }, _callee4); })); return _loadDracoEncoder.apply(this, arguments); } //# sourceMappingURL=draco-module-loader.js.map