@loaders.gl/draco 3.4.0-alpha.1 → 3.4.0-alpha.3
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.
- package/dist/dist.min.js.map +2 -2
- package/dist/draco-loader.js +1 -1
- package/dist/draco-nodejs-worker.js +54 -54
- package/dist/draco-nodejs-worker.js.map +2 -2
- package/dist/draco-worker.js +1 -1
- package/dist/draco-worker.js.map +2 -2
- package/dist/draco-writer-nodejs-worker.js +55 -55
- package/dist/draco-writer-nodejs-worker.js.map +2 -2
- package/dist/draco-writer-worker.js +2 -2
- package/dist/draco-writer-worker.js.map +2 -2
- package/dist/es5/draco-loader.js +0 -2
- package/dist/es5/draco-loader.js.map +1 -1
- package/dist/es5/draco-writer-nodejs.js.map +1 -1
- package/dist/es5/draco-writer.js +18 -21
- package/dist/es5/draco-writer.js.map +1 -1
- package/dist/es5/draco3d/draco3d-types.js +16 -16
- package/dist/es5/draco3d/draco3d-types.js.map +1 -1
- package/dist/es5/index.js +17 -20
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/draco-builder.js +12 -41
- package/dist/es5/lib/draco-builder.js.map +1 -1
- package/dist/es5/lib/draco-module-loader.js +95 -104
- package/dist/es5/lib/draco-module-loader.js.map +1 -1
- package/dist/es5/lib/draco-parser.js +16 -61
- package/dist/es5/lib/draco-parser.js.map +1 -1
- package/dist/es5/lib/utils/get-draco-schema.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/es5/workers/draco-nodejs-worker.js.map +1 -1
- package/dist/es5/workers/draco-worker.js.map +1 -1
- package/dist/es5/workers/draco-writer-nodejs-worker.js +29 -31
- package/dist/es5/workers/draco-writer-nodejs-worker.js.map +1 -1
- package/dist/es5/workers/draco-writer-worker.js +29 -31
- package/dist/es5/workers/draco-writer-worker.js.map +1 -1
- package/dist/esm/bundle.js +0 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/draco-loader.js +0 -1
- package/dist/esm/draco-loader.js.map +1 -1
- package/dist/esm/draco-writer-nodejs.js +0 -1
- package/dist/esm/draco-writer-nodejs.js.map +1 -1
- package/dist/esm/draco-writer.js +0 -1
- package/dist/esm/draco-writer.js.map +1 -1
- package/dist/esm/draco3d/draco3d-types.js +12 -18
- package/dist/esm/draco3d/draco3d-types.js.map +1 -1
- package/dist/esm/index.js +0 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/draco-builder.js +0 -17
- package/dist/esm/lib/draco-builder.js.map +1 -1
- package/dist/esm/lib/draco-module-loader.js +0 -6
- package/dist/esm/lib/draco-module-loader.js.map +1 -1
- package/dist/esm/lib/draco-parser.js +0 -28
- package/dist/esm/lib/draco-parser.js.map +1 -1
- package/dist/esm/lib/utils/get-draco-schema.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -2
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/package.json +6 -6
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["DracoWriterWorker","id","isBrowser","name","module","version","VERSION","worker","options","draco","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_dracoLoader","require","_dracoParser","_interopRequireDefault","_dracoModuleLoader","_version","_workerUtils","_dracoWriter","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","DracoWriterWorker","id","isBrowser","name","module","version","VERSION","worker","options","draco","exports","DracoLoader","DracoWorkerLoader","parse","_x","_x2","_parse","_asyncToGenerator2","_regenerator","mark","_callee","arrayBuffer","_yield$loadDracoDecod","dracoParser","wrap","_callee$","_context","prev","next","loadDracoDecoderModule","sent","DracoParser","abrupt","parseSync","destroy","finish","stop","_TypecheckDracoLoader"],"sources":["../../src/index.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {DracoMesh, DracoLoaderData} from './lib/draco-types';\nimport type {DracoLoaderOptions} from './draco-loader';\nimport {DracoLoader as DracoWorkerLoader} from './draco-loader';\nimport DracoParser from './lib/draco-parser';\nimport {loadDracoDecoderModule} from './lib/draco-module-loader';\nimport {VERSION} from './lib/utils/version';\nimport {isBrowser} from '@loaders.gl/worker-utils';\n\n// Draco data types\n\nexport type {DracoMesh, DracoLoaderData};\n\n// Draco Writer\n\nexport type {DracoWriterOptions} from './draco-writer';\nexport {DracoWriter} from './draco-writer';\n\n/**\n * Browser worker doesn't work because of issue during \"draco_encoder.js\" loading.\n * Refused to execute script from 'https://raw.githubusercontent.com/google/draco/1.4.1/javascript/draco_encoder.js' because its MIME type ('') is not executable.\n */\nexport const DracoWriterWorker = {\n id: isBrowser ? 'draco-writer' : 'draco-writer-nodejs',\n name: 'Draco compressed geometry writer',\n module: 'draco',\n version: VERSION,\n worker: true,\n options: {\n draco: {},\n source: null\n }\n};\n\n// Draco Loader\n\nexport type {DracoLoaderOptions};\nexport {DracoWorkerLoader};\n\n/**\n * Loader for Draco3D compressed geometries\n */\nexport const DracoLoader = {\n ...DracoWorkerLoader,\n parse\n};\n\nasync function parse(arrayBuffer: ArrayBuffer, options?: DracoLoaderOptions): Promise<DracoMesh> {\n const {draco} = await loadDracoDecoderModule(options);\n const dracoParser = new DracoParser(draco);\n try {\n return dracoParser.parseSync(arrayBuffer, options?.draco);\n } finally {\n dracoParser.destroy();\n }\n}\n\n// TYPE TESTS - TODO find a better way than exporting junk\nexport const _TypecheckDracoLoader: LoaderWithParser = DracoLoader;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,O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AAhB,OAAA;EAAA,CAEzB;EAAA,OAAAJ,MAAA,CAAA9B,KAAA,OAAAI,SAAA;AAAA;AAGM,IAAM+C,qBAAuC,GAAG1B,WAAW;AAACD,OAAA,CAAA2B,qBAAA,GAAAA,qBAAA"}
|
|
@@ -13,10 +13,9 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
13
13
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
14
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
15
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
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
16
|
+
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; }
|
|
17
17
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
18
18
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
|
|
20
19
|
var GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
|
|
21
20
|
POSITION: 'POSITION',
|
|
22
21
|
NORMAL: 'NORMAL',
|
|
@@ -47,31 +46,24 @@ var DracoBuilder = function () {
|
|
|
47
46
|
this.dracoEncoder = null;
|
|
48
47
|
this.draco = null;
|
|
49
48
|
}
|
|
50
|
-
|
|
51
49
|
}, {
|
|
52
50
|
key: "destroyEncodedObject",
|
|
53
|
-
value:
|
|
54
|
-
function destroyEncodedObject(object) {
|
|
51
|
+
value: function destroyEncodedObject(object) {
|
|
55
52
|
if (object) {
|
|
56
53
|
this.draco.destroy(object);
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
|
|
60
56
|
}, {
|
|
61
57
|
key: "encodeSync",
|
|
62
|
-
value:
|
|
63
|
-
function encodeSync(mesh) {
|
|
58
|
+
value: function encodeSync(mesh) {
|
|
64
59
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
65
60
|
this.log = noop;
|
|
66
61
|
this._setOptions(options);
|
|
67
62
|
return options.pointcloud ? this._encodePointCloud(mesh, options) : this._encodeMesh(mesh, options);
|
|
68
63
|
}
|
|
69
|
-
|
|
70
64
|
}, {
|
|
71
65
|
key: "_getAttributesFromMesh",
|
|
72
|
-
value:
|
|
73
|
-
|
|
74
|
-
function _getAttributesFromMesh(mesh) {
|
|
66
|
+
value: function _getAttributesFromMesh(mesh) {
|
|
75
67
|
var attributes = _objectSpread(_objectSpread({}, mesh), mesh.attributes);
|
|
76
68
|
if (mesh.indices) {
|
|
77
69
|
attributes.indices = mesh.indices;
|
|
@@ -86,7 +78,6 @@ var DracoBuilder = function () {
|
|
|
86
78
|
this._addGeometryMetadata(dracoPointCloud, options.metadata);
|
|
87
79
|
}
|
|
88
80
|
var attributes = this._getAttributesFromMesh(pointcloud);
|
|
89
|
-
|
|
90
81
|
this._createDracoPointCloud(dracoPointCloud, attributes, options);
|
|
91
82
|
var dracoData = new this.draco.DracoInt8Array();
|
|
92
83
|
try {
|
|
@@ -109,7 +100,6 @@ var DracoBuilder = function () {
|
|
|
109
100
|
this._addGeometryMetadata(dracoMesh, options.metadata);
|
|
110
101
|
}
|
|
111
102
|
var attributes = this._getAttributesFromMesh(mesh);
|
|
112
|
-
|
|
113
103
|
this._createDracoMesh(dracoMesh, attributes, options);
|
|
114
104
|
var dracoData = new this.draco.DracoInt8Array();
|
|
115
105
|
try {
|
|
@@ -124,11 +114,9 @@ var DracoBuilder = function () {
|
|
|
124
114
|
this.destroyEncodedObject(dracoMesh);
|
|
125
115
|
}
|
|
126
116
|
}
|
|
127
|
-
|
|
128
117
|
}, {
|
|
129
118
|
key: "_setOptions",
|
|
130
|
-
value:
|
|
131
|
-
function _setOptions(options) {
|
|
119
|
+
value: function _setOptions(options) {
|
|
132
120
|
if ('speed' in options) {
|
|
133
121
|
var _this$dracoEncoder;
|
|
134
122
|
(_this$dracoEncoder = this.dracoEncoder).SetSpeedOptions.apply(_this$dracoEncoder, (0, _toConsumableArray2.default)(options.speed));
|
|
@@ -145,11 +133,9 @@ var DracoBuilder = function () {
|
|
|
145
133
|
}
|
|
146
134
|
}
|
|
147
135
|
}
|
|
148
|
-
|
|
149
136
|
}, {
|
|
150
137
|
key: "_createDracoMesh",
|
|
151
|
-
value:
|
|
152
|
-
function _createDracoMesh(dracoMesh, attributes, options) {
|
|
138
|
+
value: function _createDracoMesh(dracoMesh, attributes, options) {
|
|
153
139
|
var optionalMetadata = options.attributesMetadata || {};
|
|
154
140
|
try {
|
|
155
141
|
var positions = this._getPositionAttribute(attributes);
|
|
@@ -173,11 +159,9 @@ var DracoBuilder = function () {
|
|
|
173
159
|
}
|
|
174
160
|
return dracoMesh;
|
|
175
161
|
}
|
|
176
|
-
|
|
177
162
|
}, {
|
|
178
163
|
key: "_createDracoPointCloud",
|
|
179
|
-
value:
|
|
180
|
-
function _createDracoPointCloud(dracoPointCloud, attributes, options) {
|
|
164
|
+
value: function _createDracoPointCloud(dracoPointCloud, attributes, options) {
|
|
181
165
|
var optionalMetadata = options.attributesMetadata || {};
|
|
182
166
|
try {
|
|
183
167
|
var positions = this._getPositionAttribute(attributes);
|
|
@@ -201,11 +185,9 @@ var DracoBuilder = function () {
|
|
|
201
185
|
}
|
|
202
186
|
return dracoPointCloud;
|
|
203
187
|
}
|
|
204
|
-
|
|
205
188
|
}, {
|
|
206
189
|
key: "_addAttributeToMesh",
|
|
207
|
-
value:
|
|
208
|
-
function _addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
|
|
190
|
+
value: function _addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
|
|
209
191
|
if (!ArrayBuffer.isView(attribute)) {
|
|
210
192
|
return -1;
|
|
211
193
|
}
|
|
@@ -214,7 +196,6 @@ var DracoBuilder = function () {
|
|
|
214
196
|
if (type === 'indices') {
|
|
215
197
|
var numFaces = attribute.length / 3;
|
|
216
198
|
this.log("Adding attribute ".concat(attributeName, ", size ").concat(numFaces));
|
|
217
|
-
|
|
218
199
|
this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);
|
|
219
200
|
return -1;
|
|
220
201
|
}
|
|
@@ -240,11 +221,9 @@ var DracoBuilder = function () {
|
|
|
240
221
|
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
|
|
241
222
|
}
|
|
242
223
|
}
|
|
243
|
-
|
|
244
224
|
}, {
|
|
245
225
|
key: "_getDracoAttributeType",
|
|
246
|
-
value:
|
|
247
|
-
function _getDracoAttributeType(attributeName) {
|
|
226
|
+
value: function _getDracoAttributeType(attributeName) {
|
|
248
227
|
switch (attributeName.toLowerCase()) {
|
|
249
228
|
case 'indices':
|
|
250
229
|
return 'indices';
|
|
@@ -277,29 +256,23 @@ var DracoBuilder = function () {
|
|
|
277
256
|
}
|
|
278
257
|
return null;
|
|
279
258
|
}
|
|
280
|
-
|
|
281
259
|
}, {
|
|
282
260
|
key: "_addGeometryMetadata",
|
|
283
|
-
value:
|
|
284
|
-
function _addGeometryMetadata(dracoGeometry, metadata) {
|
|
261
|
+
value: function _addGeometryMetadata(dracoGeometry, metadata) {
|
|
285
262
|
var dracoMetadata = new this.draco.Metadata();
|
|
286
263
|
this._populateDracoMetadata(dracoMetadata, metadata);
|
|
287
264
|
this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
|
|
288
265
|
}
|
|
289
|
-
|
|
290
266
|
}, {
|
|
291
267
|
key: "_addAttributeMetadata",
|
|
292
|
-
value:
|
|
293
|
-
function _addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
|
|
268
|
+
value: function _addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
|
|
294
269
|
var dracoAttributeMetadata = new this.draco.Metadata();
|
|
295
270
|
this._populateDracoMetadata(dracoAttributeMetadata, metadata);
|
|
296
271
|
this.dracoMeshBuilder.SetMetadataForAttribute(dracoGeometry, uniqueAttributeId, dracoAttributeMetadata);
|
|
297
272
|
}
|
|
298
|
-
|
|
299
273
|
}, {
|
|
300
274
|
key: "_populateDracoMetadata",
|
|
301
|
-
value:
|
|
302
|
-
function _populateDracoMetadata(dracoMetadata, metadata) {
|
|
275
|
+
value: function _populateDracoMetadata(dracoMetadata, metadata) {
|
|
303
276
|
var _iterator = _createForOfIteratorHelper(getEntries(metadata)),
|
|
304
277
|
_step;
|
|
305
278
|
try {
|
|
@@ -335,7 +308,6 @@ var DracoBuilder = function () {
|
|
|
335
308
|
return DracoBuilder;
|
|
336
309
|
}();
|
|
337
310
|
exports.default = DracoBuilder;
|
|
338
|
-
|
|
339
311
|
function dracoInt8ArrayToArrayBuffer(dracoData) {
|
|
340
312
|
var byteLength = dracoData.size();
|
|
341
313
|
var outputBuffer = new ArrayBuffer(byteLength);
|
|
@@ -345,7 +317,6 @@ function dracoInt8ArrayToArrayBuffer(dracoData) {
|
|
|
345
317
|
}
|
|
346
318
|
return outputBuffer;
|
|
347
319
|
}
|
|
348
|
-
|
|
349
320
|
function getEntries(container) {
|
|
350
321
|
var hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');
|
|
351
322
|
return hasEntriesFunc ? container.entries() : Object.entries(container);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draco-builder.js","names":["GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","noop","DracoBuilder","draco","dracoEncoder","Encoder","dracoMeshBuilder","MeshBuilder","dracoMetadataBuilder","MetadataBuilder","destroyEncodedObject","object","destroy","mesh","options","log","_setOptions","pointcloud","_encodePointCloud","_encodeMesh","attributes","indices","dracoPointCloud","PointCloud","metadata","_addGeometryMetadata","_getAttributesFromMesh","_createDracoPointCloud","dracoData","DracoInt8Array","encodedLen","EncodePointCloudToDracoBuffer","Error","num_points","num_attributes","dracoInt8ArrayToArrayBuffer","dracoMesh","Mesh","_createDracoMesh","EncodeMeshToDracoBuffer","SetSpeedOptions","speed","dracoMethod","method","SetEncodingMethod","attribute","quantization","bits","dracoPosition","SetAttributeQuantization","optionalMetadata","attributesMetadata","positions","_getPositionAttribute","vertexCount","length","attributeName","uniqueId","_addAttributeToMesh","_addAttributeMetadata","name","error","ArrayBuffer","isView","type","_getDracoAttributeType","size","numFaces","AddFacesToMesh","builder","buffer","constructor","Int8Array","AddInt8Attribute","Int16Array","AddInt16Attribute","Int32Array","AddInt32Attribute","Uint8Array","Uint8ClampedArray","AddUInt8Attribute","Uint16Array","AddUInt16Attribute","Uint32Array","AddUInt32Attribute","Float32Array","AddFloatAttribute","toLowerCase","COLOR","TEX_COORD","GENERIC","dracoType","dracoGeometry","dracoMetadata","Metadata","_populateDracoMetadata","AddMetadata","uniqueAttributeId","dracoAttributeMetadata","SetMetadataForAttribute","getEntries","key","value","Math","trunc","AddIntEntry","AddDoubleEntry","AddIntEntryArray","AddStringEntry","byteLength","outputBuffer","outputData","i","GetValue","container","hasEntriesFunc","entries","hasOwnProperty","Object"],"sources":["../../../src/lib/draco-builder.ts"],"sourcesContent":["/* eslint-disable camelcase */\n// This code is inspired by example code in the DRACO repository\nimport type {\n Draco3D,\n DracoInt8Array,\n Encoder,\n Mesh,\n MeshBuilder,\n PointCloud,\n Metadata,\n MetadataBuilder,\n draco_GeometryAttribute_Type\n} from '../draco3d/draco3d-types';\n\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {DracoMesh} from './draco-types';\n\nexport type DracoBuildOptions = {\n pointcloud?: boolean;\n metadata?: {[key: string]: string};\n attributesMetadata?: {};\n log?: any;\n\n // draco encoding options\n speed?: [number, number];\n method?: string;\n quantization?: {[attributeName: string]: number};\n};\n\n// Native Draco attribute names to GLTF attribute names.\nconst GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {\n POSITION: 'POSITION',\n NORMAL: 'NORMAL',\n COLOR_0: 'COLOR',\n TEXCOORD_0: 'TEX_COORD'\n};\n\nconst noop = () => {};\n\nexport default class DracoBuilder {\n draco: Draco3D;\n dracoEncoder: Encoder;\n dracoMeshBuilder: MeshBuilder;\n dracoMetadataBuilder: MetadataBuilder;\n log: any;\n\n // draco - the draco decoder, either import `draco3d` or load dynamically\n constructor(draco: Draco3D) {\n this.draco = draco;\n this.dracoEncoder = new this.draco.Encoder();\n this.dracoMeshBuilder = new this.draco.MeshBuilder();\n this.dracoMetadataBuilder = new this.draco.MetadataBuilder();\n }\n\n destroy(): void {\n this.destroyEncodedObject(this.dracoMeshBuilder);\n this.destroyEncodedObject(this.dracoEncoder);\n this.destroyEncodedObject(this.dracoMetadataBuilder);\n // @ts-ignore\n this.dracoMeshBuilder = null;\n // @ts-ignore\n this.dracoEncoder = null;\n // @ts-ignore\n this.draco = null;\n }\n\n // TBD - when does this need to be called?\n destroyEncodedObject(object): void {\n if (object) {\n this.draco.destroy(object);\n }\n }\n\n /**\n * Encode mesh or point cloud\n * @param mesh =({})\n * @param options\n */\n encodeSync(mesh: DracoMesh, options: DracoBuildOptions = {}): ArrayBuffer {\n this.log = noop; // TODO\n this._setOptions(options);\n\n return options.pointcloud\n ? this._encodePointCloud(mesh, options)\n : this._encodeMesh(mesh, options);\n }\n\n // PRIVATE\n\n _getAttributesFromMesh(mesh: DracoMesh) {\n // TODO - Change the encodePointCloud interface instead?\n const attributes = {...mesh, ...mesh.attributes};\n // Fold indices into the attributes\n if (mesh.indices) {\n attributes.indices = mesh.indices;\n }\n return attributes;\n }\n\n _encodePointCloud(pointcloud: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoPointCloud = new this.draco.PointCloud();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoPointCloud, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(pointcloud);\n\n // Build a `DracoPointCloud` from the input data\n this._createDracoPointCloud(dracoPointCloud, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(\n dracoPointCloud,\n false,\n dracoData\n );\n\n if (!(encodedLen > 0)) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoPointCloud.num_points()} points\n with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoPointCloud);\n }\n }\n\n _encodeMesh(mesh: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoMesh = new this.draco.Mesh();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoMesh, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(mesh);\n\n // Build a `DracoMesh` from the input data\n this._createDracoMesh(dracoMesh, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);\n if (encodedLen <= 0) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoMesh.num_points()} points\n with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoMesh);\n }\n }\n\n /**\n * Set encoding options.\n * @param {{speed?: any; method?: any; quantization?: any;}} options\n */\n _setOptions(options: DracoBuildOptions): void {\n if ('speed' in options) {\n // @ts-ignore\n this.dracoEncoder.SetSpeedOptions(...options.speed);\n }\n if ('method' in options) {\n const dracoMethod = this.draco[options.method || 'MESH_SEQUENTIAL_ENCODING'];\n // assert(dracoMethod)\n this.dracoEncoder.SetEncodingMethod(dracoMethod);\n }\n if ('quantization' in options) {\n for (const attribute in options.quantization) {\n const bits = options.quantization[attribute];\n const dracoPosition = this.draco[attribute];\n this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);\n }\n }\n }\n\n /**\n * @param {Mesh} dracoMesh\n * @param {object} attributes\n * @returns {Mesh}\n */\n _createDracoMesh(dracoMesh: Mesh, attributes, options: DracoBuildOptions): Mesh {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);\n\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoMesh, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoMesh);\n throw error;\n }\n\n return dracoMesh;\n }\n\n /**\n * @param {} dracoPointCloud\n * @param {object} attributes\n */\n _createDracoPointCloud(\n dracoPointCloud: PointCloud,\n attributes: object,\n options: DracoBuildOptions\n ): PointCloud {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(\n dracoPointCloud,\n attributeName,\n attribute,\n vertexCount\n );\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoPointCloud, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoPointCloud);\n throw error;\n }\n\n return dracoPointCloud;\n }\n\n /**\n * @param mesh\n * @param attributeName\n * @param attribute\n * @param vertexCount\n */\n _addAttributeToMesh(\n mesh: PointCloud,\n attributeName: string,\n attribute: TypedArray,\n vertexCount: number\n ) {\n if (!ArrayBuffer.isView(attribute)) {\n return -1;\n }\n\n const type = this._getDracoAttributeType(attributeName);\n // @ts-ignore TODO/fix types\n const size = attribute.length / vertexCount;\n\n if (type === 'indices') {\n // @ts-ignore TODO/fix types\n const numFaces = attribute.length / 3;\n this.log(`Adding attribute ${attributeName}, size ${numFaces}`);\n\n // @ts-ignore assumes mesh is a Mesh, not a point cloud\n this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);\n return -1;\n }\n\n this.log(`Adding attribute ${attributeName}, size ${size}`);\n\n const builder = this.dracoMeshBuilder;\n const {buffer} = attribute;\n\n switch (attribute.constructor) {\n case Int8Array:\n return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));\n\n case Int16Array:\n return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));\n\n case Int32Array:\n return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));\n case Uint8Array:\n case Uint8ClampedArray:\n return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));\n\n case Uint16Array:\n return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));\n\n case Uint32Array:\n return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));\n\n case Float32Array:\n default:\n return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));\n }\n }\n\n /**\n * DRACO can compress attributes of know type better\n * TODO - expose an attribute type map?\n * @param attributeName\n */\n _getDracoAttributeType(attributeName: string): draco_GeometryAttribute_Type | 'indices' {\n switch (attributeName.toLowerCase()) {\n case 'indices':\n return 'indices';\n case 'position':\n case 'positions':\n case 'vertices':\n return this.draco.POSITION;\n case 'normal':\n case 'normals':\n return this.draco.NORMAL;\n case 'color':\n case 'colors':\n return this.draco.COLOR;\n case 'texcoord':\n case 'texcoords':\n return this.draco.TEX_COORD;\n default:\n return this.draco.GENERIC;\n }\n }\n\n _getPositionAttribute(attributes) {\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const dracoType = this._getDracoAttributeType(attributeName);\n if (dracoType === this.draco.POSITION) {\n return attribute;\n }\n }\n return null;\n }\n\n /**\n * Add metadata for the geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param metadata\n */\n _addGeometryMetadata(dracoGeometry: PointCloud, metadata: {[key: string]: string}) {\n const dracoMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoMetadata, metadata);\n this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);\n }\n\n /**\n * Add metadata for an attribute to geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param uniqueAttributeId\n * @param metadata\n */\n _addAttributeMetadata(\n dracoGeometry: PointCloud,\n uniqueAttributeId: number,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n // Note: Draco JS IDL doesn't seem to expose draco.AttributeMetadata, however it seems to\n // create such objects automatically from draco.Metadata object.\n const dracoAttributeMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoAttributeMetadata, metadata);\n // Draco3d doc note: Directly add attribute metadata to geometry.\n // You can do this without explicitly adding |GeometryMetadata| to mesh.\n this.dracoMeshBuilder.SetMetadataForAttribute(\n dracoGeometry,\n uniqueAttributeId,\n dracoAttributeMetadata\n );\n }\n\n /**\n * Add contents of object or map to a WASM Draco Metadata Object\n * @param dracoMetadata - WASM Draco Object\n * @param metadata\n */\n _populateDracoMetadata(\n dracoMetadata: Metadata,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n for (const [key, value] of getEntries(metadata)) {\n switch (typeof value) {\n case 'number':\n if (Math.trunc(value) === value) {\n this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);\n } else {\n this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);\n }\n break;\n case 'object':\n if (value instanceof Int32Array) {\n this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);\n }\n break;\n case 'string':\n default:\n this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);\n }\n }\n }\n}\n\n// HELPER FUNCTIONS\n\n/**\n * Copy encoded data to buffer\n * @param dracoData\n */\nfunction dracoInt8ArrayToArrayBuffer(dracoData: DracoInt8Array) {\n const byteLength = dracoData.size();\n const outputBuffer = new ArrayBuffer(byteLength);\n const outputData = new Int8Array(outputBuffer);\n for (let i = 0; i < byteLength; ++i) {\n outputData[i] = dracoData.GetValue(i);\n }\n return outputBuffer;\n}\n\n/** Enable iteration over either an object or a map */\nfunction getEntries(container) {\n const hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');\n return hasEntriesFunc ? container.entries() : Object.entries(container);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,IAAMA,gCAAgC,GAAG;EACvCC,QAAQ,EAAE,UAAU;EACpBC,MAAM,EAAE,QAAQ;EAChBC,OAAO,EAAE,OAAO;EAChBC,UAAU,EAAE;AACd,CAAC;AAED,IAAMC,IAAI,GAAG,SAAPA,IAAI,GAAS,CAAC,CAAC;AAAC,IAEDC,YAAY;EAQ/B,sBAAYC,KAAc,EAAE;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAC1B,IAAI,CAACA,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,YAAY,GAAG,IAAI,IAAI,CAACD,KAAK,CAACE,OAAO,EAAE;IAC5C,IAAI,CAACC,gBAAgB,GAAG,IAAI,IAAI,CAACH,KAAK,CAACI,WAAW,EAAE;IACpD,IAAI,CAACC,oBAAoB,GAAG,IAAI,IAAI,CAACL,KAAK,CAACM,eAAe,EAAE;EAC9D;EAAC;IAAA;IAAA,OAED,mBAAgB;MACd,IAAI,CAACC,oBAAoB,CAAC,IAAI,CAACJ,gBAAgB,CAAC;MAChD,IAAI,CAACI,oBAAoB,CAAC,IAAI,CAACN,YAAY,CAAC;MAC5C,IAAI,CAACM,oBAAoB,CAAC,IAAI,CAACF,oBAAoB,CAAC;MAEpD,IAAI,CAACF,gBAAgB,GAAG,IAAI;MAE5B,IAAI,CAACF,YAAY,GAAG,IAAI;MAExB,IAAI,CAACD,KAAK,GAAG,IAAI;IACnB;;EAAC;IAAA;IAAA;IAGD,8BAAqBQ,MAAM,EAAQ;MACjC,IAAIA,MAAM,EAAE;QACV,IAAI,CAACR,KAAK,CAACS,OAAO,CAACD,MAAM,CAAC;MAC5B;IACF;;EAAC;IAAA;IAAA;IAOD,oBAAWE,I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C;AACzE"}
|
|
1
|
+
{"version":3,"file":"draco-builder.js","names":["GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","noop","DracoBuilder","draco","_classCallCheck2","default","_defineProperty2","dracoEncoder","Encoder","dracoMeshBuilder","MeshBuilder","dracoMetadataBuilder","MetadataBuilder","_createClass2","key","value","destroy","destroyEncodedObject","object","encodeSync","mesh","options","arguments","length","undefined","log","_setOptions","pointcloud","_encodePointCloud","_encodeMesh","_getAttributesFromMesh","attributes","_objectSpread","indices","dracoPointCloud","PointCloud","metadata","_addGeometryMetadata","_createDracoPointCloud","dracoData","DracoInt8Array","encodedLen","EncodePointCloudToDracoBuffer","Error","concat","num_points","num_attributes","dracoInt8ArrayToArrayBuffer","dracoMesh","Mesh","_createDracoMesh","EncodeMeshToDracoBuffer","_this$dracoEncoder","SetSpeedOptions","apply","_toConsumableArray2","speed","dracoMethod","method","SetEncodingMethod","attribute","quantization","bits","dracoPosition","SetAttributeQuantization","optionalMetadata","attributesMetadata","positions","_getPositionAttribute","vertexCount","attributeName","uniqueId","_addAttributeToMesh","_addAttributeMetadata","name","error","ArrayBuffer","isView","type","_getDracoAttributeType","size","numFaces","AddFacesToMesh","builder","buffer","constructor","Int8Array","AddInt8Attribute","Int16Array","AddInt16Attribute","Int32Array","AddInt32Attribute","Uint8Array","Uint8ClampedArray","AddUInt8Attribute","Uint16Array","AddUInt16Attribute","Uint32Array","AddUInt32Attribute","Float32Array","AddFloatAttribute","toLowerCase","COLOR","TEX_COORD","GENERIC","dracoType","dracoGeometry","dracoMetadata","Metadata","_populateDracoMetadata","AddMetadata","uniqueAttributeId","dracoAttributeMetadata","SetMetadataForAttribute","_iterator","_createForOfIteratorHelper","getEntries","_step","s","n","done","_step$value","_slicedToArray2","_typeof2","Math","trunc","AddIntEntry","AddDoubleEntry","AddIntEntryArray","AddStringEntry","err","e","f","exports","byteLength","outputBuffer","outputData","i","GetValue","container","hasEntriesFunc","entries","hasOwnProperty","Object"],"sources":["../../../src/lib/draco-builder.ts"],"sourcesContent":["/* eslint-disable camelcase */\n// This code is inspired by example code in the DRACO repository\nimport type {\n Draco3D,\n DracoInt8Array,\n Encoder,\n Mesh,\n MeshBuilder,\n PointCloud,\n Metadata,\n MetadataBuilder,\n draco_GeometryAttribute_Type\n} from '../draco3d/draco3d-types';\n\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {DracoMesh} from './draco-types';\n\nexport type DracoBuildOptions = {\n pointcloud?: boolean;\n metadata?: {[key: string]: string};\n attributesMetadata?: {};\n log?: any;\n\n // draco encoding options\n speed?: [number, number];\n method?: string;\n quantization?: {[attributeName: string]: number};\n};\n\n// Native Draco attribute names to GLTF attribute names.\nconst GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {\n POSITION: 'POSITION',\n NORMAL: 'NORMAL',\n COLOR_0: 'COLOR',\n TEXCOORD_0: 'TEX_COORD'\n};\n\nconst noop = () => {};\n\nexport default class DracoBuilder {\n draco: Draco3D;\n dracoEncoder: Encoder;\n dracoMeshBuilder: MeshBuilder;\n dracoMetadataBuilder: MetadataBuilder;\n log: any;\n\n // draco - the draco decoder, either import `draco3d` or load dynamically\n constructor(draco: Draco3D) {\n this.draco = draco;\n this.dracoEncoder = new this.draco.Encoder();\n this.dracoMeshBuilder = new this.draco.MeshBuilder();\n this.dracoMetadataBuilder = new this.draco.MetadataBuilder();\n }\n\n destroy(): void {\n this.destroyEncodedObject(this.dracoMeshBuilder);\n this.destroyEncodedObject(this.dracoEncoder);\n this.destroyEncodedObject(this.dracoMetadataBuilder);\n // @ts-ignore\n this.dracoMeshBuilder = null;\n // @ts-ignore\n this.dracoEncoder = null;\n // @ts-ignore\n this.draco = null;\n }\n\n // TBD - when does this need to be called?\n destroyEncodedObject(object): void {\n if (object) {\n this.draco.destroy(object);\n }\n }\n\n /**\n * Encode mesh or point cloud\n * @param mesh =({})\n * @param options\n */\n encodeSync(mesh: DracoMesh, options: DracoBuildOptions = {}): ArrayBuffer {\n this.log = noop; // TODO\n this._setOptions(options);\n\n return options.pointcloud\n ? this._encodePointCloud(mesh, options)\n : this._encodeMesh(mesh, options);\n }\n\n // PRIVATE\n\n _getAttributesFromMesh(mesh: DracoMesh) {\n // TODO - Change the encodePointCloud interface instead?\n const attributes = {...mesh, ...mesh.attributes};\n // Fold indices into the attributes\n if (mesh.indices) {\n attributes.indices = mesh.indices;\n }\n return attributes;\n }\n\n _encodePointCloud(pointcloud: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoPointCloud = new this.draco.PointCloud();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoPointCloud, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(pointcloud);\n\n // Build a `DracoPointCloud` from the input data\n this._createDracoPointCloud(dracoPointCloud, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(\n dracoPointCloud,\n false,\n dracoData\n );\n\n if (!(encodedLen > 0)) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoPointCloud.num_points()} points\n with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoPointCloud);\n }\n }\n\n _encodeMesh(mesh: DracoMesh, options: DracoBuildOptions): ArrayBuffer {\n const dracoMesh = new this.draco.Mesh();\n\n if (options.metadata) {\n this._addGeometryMetadata(dracoMesh, options.metadata);\n }\n\n const attributes = this._getAttributesFromMesh(mesh);\n\n // Build a `DracoMesh` from the input data\n this._createDracoMesh(dracoMesh, attributes, options);\n\n const dracoData = new this.draco.DracoInt8Array();\n\n try {\n const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);\n if (encodedLen <= 0) {\n throw new Error('Draco encoding failed.');\n }\n\n this.log(`DRACO encoded ${dracoMesh.num_points()} points\n with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);\n\n return dracoInt8ArrayToArrayBuffer(dracoData);\n } finally {\n this.destroyEncodedObject(dracoData);\n this.destroyEncodedObject(dracoMesh);\n }\n }\n\n /**\n * Set encoding options.\n * @param {{speed?: any; method?: any; quantization?: any;}} options\n */\n _setOptions(options: DracoBuildOptions): void {\n if ('speed' in options) {\n // @ts-ignore\n this.dracoEncoder.SetSpeedOptions(...options.speed);\n }\n if ('method' in options) {\n const dracoMethod = this.draco[options.method || 'MESH_SEQUENTIAL_ENCODING'];\n // assert(dracoMethod)\n this.dracoEncoder.SetEncodingMethod(dracoMethod);\n }\n if ('quantization' in options) {\n for (const attribute in options.quantization) {\n const bits = options.quantization[attribute];\n const dracoPosition = this.draco[attribute];\n this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);\n }\n }\n }\n\n /**\n * @param {Mesh} dracoMesh\n * @param {object} attributes\n * @returns {Mesh}\n */\n _createDracoMesh(dracoMesh: Mesh, attributes, options: DracoBuildOptions): Mesh {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);\n\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoMesh, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoMesh);\n throw error;\n }\n\n return dracoMesh;\n }\n\n /**\n * @param {} dracoPointCloud\n * @param {object} attributes\n */\n _createDracoPointCloud(\n dracoPointCloud: PointCloud,\n attributes: object,\n options: DracoBuildOptions\n ): PointCloud {\n const optionalMetadata = options.attributesMetadata || {};\n\n try {\n const positions = this._getPositionAttribute(attributes);\n if (!positions) {\n throw new Error('positions');\n }\n const vertexCount = positions.length / 3;\n\n for (let attributeName in attributes) {\n const attribute = attributes[attributeName];\n attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;\n const uniqueId = this._addAttributeToMesh(\n dracoPointCloud,\n attributeName,\n attribute,\n vertexCount\n );\n if (uniqueId !== -1) {\n this._addAttributeMetadata(dracoPointCloud, uniqueId, {\n name: attributeName,\n ...(optionalMetadata[attributeName] || {})\n });\n }\n }\n } catch (error) {\n this.destroyEncodedObject(dracoPointCloud);\n throw error;\n }\n\n return dracoPointCloud;\n }\n\n /**\n * @param mesh\n * @param attributeName\n * @param attribute\n * @param vertexCount\n */\n _addAttributeToMesh(\n mesh: PointCloud,\n attributeName: string,\n attribute: TypedArray,\n vertexCount: number\n ) {\n if (!ArrayBuffer.isView(attribute)) {\n return -1;\n }\n\n const type = this._getDracoAttributeType(attributeName);\n // @ts-ignore TODO/fix types\n const size = attribute.length / vertexCount;\n\n if (type === 'indices') {\n // @ts-ignore TODO/fix types\n const numFaces = attribute.length / 3;\n this.log(`Adding attribute ${attributeName}, size ${numFaces}`);\n\n // @ts-ignore assumes mesh is a Mesh, not a point cloud\n this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);\n return -1;\n }\n\n this.log(`Adding attribute ${attributeName}, size ${size}`);\n\n const builder = this.dracoMeshBuilder;\n const {buffer} = attribute;\n\n switch (attribute.constructor) {\n case Int8Array:\n return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));\n\n case Int16Array:\n return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));\n\n case Int32Array:\n return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));\n case Uint8Array:\n case Uint8ClampedArray:\n return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));\n\n case Uint16Array:\n return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));\n\n case Uint32Array:\n return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));\n\n case Float32Array:\n default:\n return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));\n }\n }\n\n /**\n * DRACO can compress attributes of know type better\n * TODO - expose an attribute type map?\n * @param attributeName\n */\n _getDracoAttributeType(attributeName: string): draco_GeometryAttribute_Type | 'indices' {\n switch (attributeName.toLowerCase()) {\n case 'indices':\n return 'indices';\n case 'position':\n case 'positions':\n case 'vertices':\n return this.draco.POSITION;\n case 'normal':\n case 'normals':\n return this.draco.NORMAL;\n case 'color':\n case 'colors':\n return this.draco.COLOR;\n case 'texcoord':\n case 'texcoords':\n return this.draco.TEX_COORD;\n default:\n return this.draco.GENERIC;\n }\n }\n\n _getPositionAttribute(attributes) {\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const dracoType = this._getDracoAttributeType(attributeName);\n if (dracoType === this.draco.POSITION) {\n return attribute;\n }\n }\n return null;\n }\n\n /**\n * Add metadata for the geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param metadata\n */\n _addGeometryMetadata(dracoGeometry: PointCloud, metadata: {[key: string]: string}) {\n const dracoMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoMetadata, metadata);\n this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);\n }\n\n /**\n * Add metadata for an attribute to geometry.\n * @param dracoGeometry - WASM Draco Object\n * @param uniqueAttributeId\n * @param metadata\n */\n _addAttributeMetadata(\n dracoGeometry: PointCloud,\n uniqueAttributeId: number,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n // Note: Draco JS IDL doesn't seem to expose draco.AttributeMetadata, however it seems to\n // create such objects automatically from draco.Metadata object.\n const dracoAttributeMetadata = new this.draco.Metadata();\n this._populateDracoMetadata(dracoAttributeMetadata, metadata);\n // Draco3d doc note: Directly add attribute metadata to geometry.\n // You can do this without explicitly adding |GeometryMetadata| to mesh.\n this.dracoMeshBuilder.SetMetadataForAttribute(\n dracoGeometry,\n uniqueAttributeId,\n dracoAttributeMetadata\n );\n }\n\n /**\n * Add contents of object or map to a WASM Draco Metadata Object\n * @param dracoMetadata - WASM Draco Object\n * @param metadata\n */\n _populateDracoMetadata(\n dracoMetadata: Metadata,\n metadata: Map<string, string> | {[key: string]: string}\n ) {\n for (const [key, value] of getEntries(metadata)) {\n switch (typeof value) {\n case 'number':\n if (Math.trunc(value) === value) {\n this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);\n } else {\n this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);\n }\n break;\n case 'object':\n if (value instanceof Int32Array) {\n this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);\n }\n break;\n case 'string':\n default:\n this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);\n }\n }\n }\n}\n\n// HELPER FUNCTIONS\n\n/**\n * Copy encoded data to buffer\n * @param dracoData\n */\nfunction dracoInt8ArrayToArrayBuffer(dracoData: DracoInt8Array) {\n const byteLength = dracoData.size();\n const outputBuffer = new ArrayBuffer(byteLength);\n const outputData = new Int8Array(outputBuffer);\n for (let i = 0; i < byteLength; ++i) {\n outputData[i] = dracoData.GetValue(i);\n }\n return outputBuffer;\n}\n\n/** Enable iteration over either an object or a map */\nfunction getEntries(container) {\n const hasEntriesFunc = container.entries && !container.hasOwnProperty('entries');\n return hasEntriesFunc ? container.entries() : Object.entries(container);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA8BA,IAAMA,gCAAgC,GAAG;EACvCC,QAAQ,EAAE,UAAU;EACpBC,MAAM,EAAE,QAAQ;EAChBC,OAAO,EAAE,OAAO;EAChBC,UAAU,EAAE;AACd,CAAC;AAED,IAAMC,IAAI,GAAG,SAAPA,IAAIA,CAAA,EAAS,CAAC,CAAC;AAAC,IAEDC,YAAY;EAQ/B,SAAAA,aAAYC,KAAc,EAAE;IAAA,IAAAC,gBA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MAAC,SAAAmH,GAAA;QAAAhB,SAAA,CAAAiB,CAAA,CAAAD,GAAA;MAAA;QAAAhB,SAAA,CAAAkB,CAAA;MAAA;IACH;EAAC;EAAA,OAAAlI,YAAA;AAAA;AAAAmI,OAAA,CAAAhI,OAAA,GAAAH,YAAA;AASH,SAAS6C,2BAA2BA,CAACR,SAAyB,EAAE;EAC9D,IAAM+F,UAAU,GAAG/F,SAAS,CAACyC,IAAI,EAAE;EACnC,IAAMuD,YAAY,GAAG,IAAI3D,WAAW,CAAC0D,UAAU,CAAC;EAChD,IAAME,UAAU,GAAG,IAAIlD,SAAS,CAACiD,YAAY,CAAC;EAC9C,KAAK,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,UAAU,EAAE,EAAEG,CAAC,EAAE;IACnCD,UAAU,CAACC,CAAC,CAAC,GAAGlG,SAAS,CAACmG,QAAQ,CAACD,CAAC,CAAC;EACvC;EACA,OAAOF,YAAY;AACrB;AAGA,SAASnB,UAAUA,CAACuB,SAAS,EAAE;EAC7B,IAAMC,cAAc,GAAGD,SAAS,CAACE,OAAO,IAAI,CAACF,SAAS,CAACG,cAAc,CAAC,SAAS,CAAC;EAChF,OAAOF,cAAc,GAAGD,SAAS,CAACE,OAAO,EAAE,GAAGE,MAAM,CAACF,OAAO,CAACF,SAAS,CAAC;AACzE"}
|
|
@@ -29,27 +29,25 @@ function _loadDracoDecoderModule() {
|
|
|
29
29
|
_loadDracoDecoderModule = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(options) {
|
|
30
30
|
var modules;
|
|
31
31
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
32
|
-
while (1) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return _context.stop();
|
|
52
|
-
}
|
|
32
|
+
while (1) switch (_context.prev = _context.next) {
|
|
33
|
+
case 0:
|
|
34
|
+
modules = options.modules || {};
|
|
35
|
+
if (modules.draco3d) {
|
|
36
|
+
loadDecoderPromise = loadDecoderPromise || modules.draco3d.createDecoderModule({}).then(function (draco) {
|
|
37
|
+
return {
|
|
38
|
+
draco: draco
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);
|
|
43
|
+
}
|
|
44
|
+
_context.next = 4;
|
|
45
|
+
return loadDecoderPromise;
|
|
46
|
+
case 4:
|
|
47
|
+
return _context.abrupt("return", _context.sent);
|
|
48
|
+
case 5:
|
|
49
|
+
case "end":
|
|
50
|
+
return _context.stop();
|
|
53
51
|
}
|
|
54
52
|
}, _callee);
|
|
55
53
|
}));
|
|
@@ -62,27 +60,25 @@ function _loadDracoEncoderModule() {
|
|
|
62
60
|
_loadDracoEncoderModule = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(options) {
|
|
63
61
|
var modules;
|
|
64
62
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
65
|
-
while (1) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return _context2.stop();
|
|
85
|
-
}
|
|
63
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
modules = options.modules || {};
|
|
66
|
+
if (modules.draco3d) {
|
|
67
|
+
loadEncoderPromise = loadEncoderPromise || modules.draco3d.createEncoderModule({}).then(function (draco) {
|
|
68
|
+
return {
|
|
69
|
+
draco: draco
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
} else {
|
|
73
|
+
loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);
|
|
74
|
+
}
|
|
75
|
+
_context2.next = 4;
|
|
76
|
+
return loadEncoderPromise;
|
|
77
|
+
case 4:
|
|
78
|
+
return _context2.abrupt("return", _context2.sent);
|
|
79
|
+
case 5:
|
|
80
|
+
case "end":
|
|
81
|
+
return _context2.stop();
|
|
86
82
|
}
|
|
87
83
|
}, _callee2);
|
|
88
84
|
}));
|
|
@@ -95,46 +91,44 @@ function _loadDracoDecoder() {
|
|
|
95
91
|
_loadDracoDecoder = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(options) {
|
|
96
92
|
var DracoDecoderModule, wasmBinary, _yield$Promise$all, _yield$Promise$all2;
|
|
97
93
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
98
|
-
while (1) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return _context3.stop();
|
|
137
|
-
}
|
|
94
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
95
|
+
case 0:
|
|
96
|
+
_context3.t0 = options.draco && options.draco.decoderType;
|
|
97
|
+
_context3.next = _context3.t0 === 'js' ? 3 : _context3.t0 === 'wasm' ? 7 : 7;
|
|
98
|
+
break;
|
|
99
|
+
case 3:
|
|
100
|
+
_context3.next = 5;
|
|
101
|
+
return (0, _workerUtils.loadLibrary)(DRACO_JS_DECODER_URL, 'draco', options);
|
|
102
|
+
case 5:
|
|
103
|
+
DracoDecoderModule = _context3.sent;
|
|
104
|
+
return _context3.abrupt("break", 21);
|
|
105
|
+
case 7:
|
|
106
|
+
_context3.t1 = Promise;
|
|
107
|
+
_context3.next = 10;
|
|
108
|
+
return (0, _workerUtils.loadLibrary)(DRACO_WASM_WRAPPER_URL, 'draco', options);
|
|
109
|
+
case 10:
|
|
110
|
+
_context3.t2 = _context3.sent;
|
|
111
|
+
_context3.next = 13;
|
|
112
|
+
return (0, _workerUtils.loadLibrary)(DRACO_WASM_DECODER_URL, 'draco', options);
|
|
113
|
+
case 13:
|
|
114
|
+
_context3.t3 = _context3.sent;
|
|
115
|
+
_context3.t4 = [_context3.t2, _context3.t3];
|
|
116
|
+
_context3.next = 17;
|
|
117
|
+
return _context3.t1.all.call(_context3.t1, _context3.t4);
|
|
118
|
+
case 17:
|
|
119
|
+
_yield$Promise$all = _context3.sent;
|
|
120
|
+
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 2);
|
|
121
|
+
DracoDecoderModule = _yield$Promise$all2[0];
|
|
122
|
+
wasmBinary = _yield$Promise$all2[1];
|
|
123
|
+
case 21:
|
|
124
|
+
DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;
|
|
125
|
+
_context3.next = 24;
|
|
126
|
+
return initializeDracoDecoder(DracoDecoderModule, wasmBinary);
|
|
127
|
+
case 24:
|
|
128
|
+
return _context3.abrupt("return", _context3.sent);
|
|
129
|
+
case 25:
|
|
130
|
+
case "end":
|
|
131
|
+
return _context3.stop();
|
|
138
132
|
}
|
|
139
133
|
}, _callee3);
|
|
140
134
|
}));
|
|
@@ -155,7 +149,6 @@ function initializeDracoDecoder(DracoDecoderModule, wasmBinary) {
|
|
|
155
149
|
}));
|
|
156
150
|
});
|
|
157
151
|
}
|
|
158
|
-
|
|
159
152
|
function loadDracoEncoder(_x4) {
|
|
160
153
|
return _loadDracoEncoder.apply(this, arguments);
|
|
161
154
|
}
|
|
@@ -163,27 +156,25 @@ function _loadDracoEncoder() {
|
|
|
163
156
|
_loadDracoEncoder = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4(options) {
|
|
164
157
|
var DracoEncoderModule;
|
|
165
158
|
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
166
|
-
while (1) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return _context4.stop();
|
|
186
|
-
}
|
|
159
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
160
|
+
case 0:
|
|
161
|
+
_context4.next = 2;
|
|
162
|
+
return (0, _workerUtils.loadLibrary)(DRACO_ENCODER_URL, 'draco', options);
|
|
163
|
+
case 2:
|
|
164
|
+
DracoEncoderModule = _context4.sent;
|
|
165
|
+
DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;
|
|
166
|
+
return _context4.abrupt("return", new Promise(function (resolve) {
|
|
167
|
+
DracoEncoderModule({
|
|
168
|
+
onModuleLoaded: function onModuleLoaded(draco) {
|
|
169
|
+
return resolve({
|
|
170
|
+
draco: draco
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}));
|
|
175
|
+
case 5:
|
|
176
|
+
case "end":
|
|
177
|
+
return _context4.stop();
|
|
187
178
|
}
|
|
188
179
|
}, _callee4);
|
|
189
180
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draco-module-loader.js","names":["DRACO_DECODER_VERSION","DRACO_ENCODER_VERSION","STATIC_DECODER_URL","DRACO_JS_DECODER_URL","DRACO_WASM_WRAPPER_URL","DRACO_WASM_DECODER_URL","DRACO_ENCODER_URL","loadDecoderPromise","loadEncoderPromise","loadDracoDecoderModule","options","modules","draco3d","createDecoderModule","then","draco","loadDracoDecoder","loadDracoEncoderModule","createEncoderModule","loadDracoEncoder","decoderType","loadLibrary","DracoDecoderModule","Promise","all","wasmBinary","globalThis","initializeDracoDecoder","resolve","onModuleLoaded","DracoEncoderModule"],"sources":["../../../src/lib/draco-module-loader.ts"],"sourcesContent":["// Dynamic DRACO module loading inspired by THREE.DRACOLoader\n// https://github.com/mrdoob/three.js/blob/398c4f39ebdb8b23eefd4a7a5ec49ec0c96c7462/examples/jsm/loaders/DRACOLoader.js\n// by Don McCurdy / https://www.donmccurdy.com / MIT license\n\nimport {loadLibrary} from '@loaders.gl/worker-utils';\n\nconst DRACO_DECODER_VERSION = '1.5.5';\nconst DRACO_ENCODER_VERSION = '1.4.1';\n\nconst STATIC_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_DECODER_VERSION}`;\n\nconst DRACO_JS_DECODER_URL = `${STATIC_DECODER_URL}/draco_decoder.js`;\nconst DRACO_WASM_WRAPPER_URL = `${STATIC_DECODER_URL}/draco_wasm_wrapper.js`;\nconst DRACO_WASM_DECODER_URL = `${STATIC_DECODER_URL}/draco_decoder.wasm`;\n\nconst DRACO_ENCODER_URL = `https://raw.githubusercontent.com/google/draco/${DRACO_ENCODER_VERSION}/javascript/draco_encoder.js`;\n\nlet loadDecoderPromise;\nlet loadEncoderPromise;\n\nexport async function loadDracoDecoderModule(options) {\n const modules = options.modules || {};\n\n // Check if a bundled draco3d library has been supplied by application\n if (modules.draco3d) {\n loadDecoderPromise =\n loadDecoderPromise ||\n modules.draco3d.createDecoderModule({}).then((draco) => {\n return {draco};\n });\n } else {\n // If not, dynamically load the WASM script from our CDN\n loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);\n }\n return await loadDecoderPromise;\n}\n\nexport async function loadDracoEncoderModule(options) {\n const modules = options.modules || {};\n\n // Check if a bundled draco3d library has been supplied by application\n if (modules.draco3d) {\n loadEncoderPromise =\n loadEncoderPromise ||\n modules.draco3d.createEncoderModule({}).then((draco) => {\n return {draco};\n });\n } else {\n // If not, dynamically load the WASM script from our CDN\n loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);\n }\n return await loadEncoderPromise;\n}\n\n// DRACO DECODER LOADING\n\nasync function loadDracoDecoder(options) {\n let DracoDecoderModule;\n let wasmBinary;\n switch (options.draco && options.draco.decoderType) {\n case 'js':\n DracoDecoderModule = await loadLibrary(DRACO_JS_DECODER_URL, 'draco', options);\n break;\n\n case 'wasm':\n default:\n [DracoDecoderModule, wasmBinary] = await Promise.all([\n await loadLibrary(DRACO_WASM_WRAPPER_URL, 'draco', options),\n await loadLibrary(DRACO_WASM_DECODER_URL, 'draco', options)\n ]);\n }\n // Depends on how import happened...\n // @ts-ignore\n DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;\n return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);\n}\n\nfunction initializeDracoDecoder(DracoDecoderModule, wasmBinary) {\n const options: {wasmBinary?: any} = {};\n if (wasmBinary) {\n options.wasmBinary = wasmBinary;\n }\n\n return new Promise((resolve) => {\n DracoDecoderModule({\n ...options,\n onModuleLoaded: (draco) => resolve({draco}) // Module is Promise-like. Wrap in object to avoid loop.\n });\n });\n}\n\n// ENCODER\n\nasync function loadDracoEncoder(options) {\n let DracoEncoderModule = await loadLibrary(DRACO_ENCODER_URL, 'draco', options);\n // @ts-ignore\n DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;\n\n return new Promise((resolve) => {\n DracoEncoderModule({\n onModuleLoaded: (draco) => resolve({draco}) // Module is Promise-like. Wrap in object to avoid loop.\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;AAIA;AAAqD;AAAA;AAErD,IAAMA,qBAAqB,GAAG,OAAO;AACrC,IAAMC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UAACK,OAAO,EAAK;IAC9BN,kBAAkB,iCACbZ,OAAO;MACVmB,cAAc,EAAE,wBAACd,KAAK;QAAA,OAAKa,OAAO,CAAC;UAACb,KAAK,EAALA;QAAK,CAAC,CAAC;MAAA;IAAA,GAC3C;EACJ,CAAC,CAAC;AACJ;;AAAC,SAIcI,gBAAgB;EAAA;AAAA;AAAA;EAAA,8EAA/B,kBAAgCT,OAAO;IAAA;IAAA;MAAA;QAAA;UAAA;YAAA;YAAA,OACN,IAAAW,wBAAW,EAACf,iBAAiB,EAAE,OAAO,EAAEI,OAAO,CAAC;UAAA;YAA3EoB,kBAAkB;YAEtBA,kBAAkB,GAAGA,kBAAkB,IAAIJ,UAAU,CAACI,kBAAkB;YAAC,kCAElE,IAAIP,OAAO,CAAC,UAACK,OAAO,EAAK;cAC9BE,kBAAkB,CAAC;gBACjBD,cAAc,EAAE,wBAACd,KAAK;kBAAA,OAAKa,OAAO,CAAC;oBAACb,KAAK,EAALA;kBAAK,CAAC,CAAC;gBAAA;cAC7C,CAAC,CAAC;YACJ,CAAC,CAAC;UAAA;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CACH;EAAA;AAAA"}
|
|
1
|
+
{"version":3,"file":"draco-module-loader.js","names":["_workerUtils","require","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","DRACO_DECODER_VERSION","DRACO_ENCODER_VERSION","STATIC_DECODER_URL","concat","DRACO_JS_DECODER_URL","DRACO_WASM_WRAPPER_URL","DRACO_WASM_DECODER_URL","DRACO_ENCODER_URL","loadDecoderPromise","loadEncoderPromise","loadDracoDecoderModule","_x","_loadDracoDecoderModule","_asyncToGenerator2","_regenerator","mark","_callee","options","modules","wrap","_callee$","_context","prev","next","draco3d","createDecoderModule","then","draco","loadDracoDecoder","abrupt","sent","stop","loadDracoEncoderModule","_x2","_loadDracoEncoderModule","_callee2","_callee2$","_context2","createEncoderModule","loadDracoEncoder","_x3","_loadDracoDecoder","_callee3","DracoDecoderModule","wasmBinary","_yield$Promise$all","_yield$Promise$all2","_callee3$","_context3","t0","decoderType","loadLibrary","t1","Promise","t2","t3","t4","all","call","_slicedToArray2","globalThis","initializeDracoDecoder","resolve","onModuleLoaded","_x4","_loadDracoEncoder","_callee4","DracoEncoderModule","_callee4$","_context4"],"sources":["../../../src/lib/draco-module-loader.ts"],"sourcesContent":["// Dynamic DRACO module loading inspired by THREE.DRACOLoader\n// https://github.com/mrdoob/three.js/blob/398c4f39ebdb8b23eefd4a7a5ec49ec0c96c7462/examples/jsm/loaders/DRACOLoader.js\n// by Don McCurdy / https://www.donmccurdy.com / MIT license\n\nimport {loadLibrary} from '@loaders.gl/worker-utils';\n\nconst DRACO_DECODER_VERSION = '1.5.5';\nconst DRACO_ENCODER_VERSION = '1.4.1';\n\nconst STATIC_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_DECODER_VERSION}`;\n\nconst DRACO_JS_DECODER_URL = `${STATIC_DECODER_URL}/draco_decoder.js`;\nconst DRACO_WASM_WRAPPER_URL = `${STATIC_DECODER_URL}/draco_wasm_wrapper.js`;\nconst DRACO_WASM_DECODER_URL = `${STATIC_DECODER_URL}/draco_decoder.wasm`;\n\nconst DRACO_ENCODER_URL = `https://raw.githubusercontent.com/google/draco/${DRACO_ENCODER_VERSION}/javascript/draco_encoder.js`;\n\nlet loadDecoderPromise;\nlet loadEncoderPromise;\n\nexport async function loadDracoDecoderModule(options) {\n const modules = options.modules || {};\n\n // Check if a bundled draco3d library has been supplied by application\n if (modules.draco3d) {\n loadDecoderPromise =\n loadDecoderPromise ||\n modules.draco3d.createDecoderModule({}).then((draco) => {\n return {draco};\n });\n } else {\n // If not, dynamically load the WASM script from our CDN\n loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);\n }\n return await loadDecoderPromise;\n}\n\nexport async function loadDracoEncoderModule(options) {\n const modules = options.modules || {};\n\n // Check if a bundled draco3d library has been supplied by application\n if (modules.draco3d) {\n loadEncoderPromise =\n loadEncoderPromise ||\n modules.draco3d.createEncoderModule({}).then((draco) => {\n return {draco};\n });\n } else {\n // If not, dynamically load the WASM script from our CDN\n loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);\n }\n return await loadEncoderPromise;\n}\n\n// DRACO DECODER LOADING\n\nasync function loadDracoDecoder(options) {\n let DracoDecoderModule;\n let wasmBinary;\n switch (options.draco && options.draco.decoderType) {\n case 'js':\n DracoDecoderModule = await loadLibrary(DRACO_JS_DECODER_URL, 'draco', options);\n break;\n\n case 'wasm':\n default:\n [DracoDecoderModule, wasmBinary] = await Promise.all([\n await loadLibrary(DRACO_WASM_WRAPPER_URL, 'draco', options),\n await loadLibrary(DRACO_WASM_DECODER_URL, 'draco', options)\n ]);\n }\n // Depends on how import happened...\n // @ts-ignore\n DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;\n return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);\n}\n\nfunction initializeDracoDecoder(DracoDecoderModule, wasmBinary) {\n const options: {wasmBinary?: any} = {};\n if (wasmBinary) {\n options.wasmBinary = wasmBinary;\n }\n\n return new Promise((resolve) => {\n DracoDecoderModule({\n ...options,\n onModuleLoaded: (draco) => resolve({draco}) // Module is Promise-like. Wrap in object to avoid loop.\n });\n });\n}\n\n// ENCODER\n\nasync function loadDracoEncoder(options) {\n let DracoEncoderModule = await loadLibrary(DRACO_ENCODER_URL, 'draco', options);\n // @ts-ignore\n DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;\n\n return new Promise((resolve) => {\n DracoEncoderModule({\n onModuleLoaded: (draco) => resolve({draco}) // Module is Promise-like. Wrap in object to avoid loop.\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;AAIA,IAAAA,YAAA,GAAAC,OAAA;AAAqD,SAAAC,QAAAC,MAAA,EAAAC,cAAA,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