@loaders.gl/draco 4.0.0-beta.2 → 4.0.0-beta.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.dev.js +1245 -0
- package/dist/{esm/draco-loader.js → draco-loader.js} +1 -1
- package/dist/draco-loader.js.map +1 -0
- package/dist/draco-worker-node.js +286 -140
- package/dist/draco-worker-node.js.map +4 -4
- package/dist/draco-worker.js +1 -1
- package/dist/draco-worker.js.map +4 -4
- package/dist/draco-writer-worker-node.js +287 -141
- package/dist/draco-writer-worker-node.js.map +4 -4
- package/dist/draco-writer-worker.js +3 -3
- package/dist/draco-writer-worker.js.map +4 -4
- package/dist/{esm/draco-writer.js → draco-writer.js} +3 -3
- package/dist/draco-writer.js.map +1 -0
- package/dist/draco3d/draco3d-types.js.map +1 -0
- package/dist/index.cjs +1028 -0
- package/dist/{esm/index.js → index.js} +6 -6
- package/dist/index.js.map +1 -0
- package/dist/{esm/lib → lib}/draco-builder.js +11 -10
- package/dist/lib/draco-builder.js.map +1 -0
- package/dist/{esm/lib → lib}/draco-module-loader.js +5 -5
- package/dist/lib/draco-module-loader.js.map +1 -0
- package/dist/{esm/lib → lib}/draco-parser.js +6 -7
- package/dist/lib/draco-parser.js.map +1 -0
- package/dist/lib/draco-types.js.map +1 -0
- package/dist/{esm/lib → lib}/utils/get-draco-schema.js +1 -1
- package/dist/lib/utils/get-draco-schema.js.map +1 -0
- package/dist/lib/utils/version.js +2 -0
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/libs/draco_encoder.js +2 -52
- package/dist/libs/draco_encoder.js.map +1 -0
- package/dist/libs/draco_wasm_wrapper.js +1985 -117
- package/dist/libs/draco_wasm_wrapper.js.map +1 -0
- package/dist/{esm/workers → workers}/draco-worker-node.js +1 -1
- package/dist/workers/draco-worker-node.js.map +1 -0
- package/dist/{esm/workers → workers}/draco-worker.js +1 -1
- package/dist/workers/draco-worker.js.map +1 -0
- package/dist/{esm/workers → workers}/draco-writer-worker-node.js +1 -1
- package/dist/workers/draco-writer-worker-node.js.map +1 -0
- package/dist/{esm/workers → workers}/draco-writer-worker.js +1 -1
- package/dist/workers/draco-writer-worker.js.map +1 -0
- package/package.json +18 -10
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/dist.min.js +0 -4
- package/dist/dist.min.js.map +0 -7
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/draco-loader.js +0 -31
- package/dist/es5/draco-loader.js.map +0 -1
- package/dist/es5/draco-writer.js +0 -63
- package/dist/es5/draco-writer.js.map +0 -1
- package/dist/es5/draco3d/draco3d-types.js +0 -51
- package/dist/es5/draco3d/draco3d-types.js.map +0 -1
- package/dist/es5/index.js +0 -88
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/draco-builder.js +0 -324
- package/dist/es5/lib/draco-builder.js.map +0 -1
- package/dist/es5/lib/draco-module-loader.js +0 -190
- package/dist/es5/lib/draco-module-loader.js.map +0 -1
- package/dist/es5/lib/draco-parser.js +0 -435
- package/dist/es5/lib/draco-parser.js.map +0 -1
- package/dist/es5/lib/draco-types.js +0 -2
- package/dist/es5/lib/draco-types.js.map +0 -1
- package/dist/es5/lib/utils/get-draco-schema.js +0 -47
- package/dist/es5/lib/utils/get-draco-schema.js.map +0 -1
- package/dist/es5/lib/utils/version.js +0 -9
- package/dist/es5/lib/utils/version.js.map +0 -1
- package/dist/es5/workers/draco-worker-node.js +0 -7
- package/dist/es5/workers/draco-worker-node.js.map +0 -1
- package/dist/es5/workers/draco-worker.js +0 -6
- package/dist/es5/workers/draco-worker.js.map +0 -1
- package/dist/es5/workers/draco-writer-worker-node.js +0 -54
- package/dist/es5/workers/draco-writer-worker-node.js.map +0 -1
- package/dist/es5/workers/draco-writer-worker.js +0 -53
- package/dist/es5/workers/draco-writer-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/draco-loader.js.map +0 -1
- package/dist/esm/draco-writer.js.map +0 -1
- package/dist/esm/draco3d/draco3d-types.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/draco-builder.js.map +0 -1
- package/dist/esm/lib/draco-module-loader.js.map +0 -1
- package/dist/esm/lib/draco-parser.js.map +0 -1
- package/dist/esm/lib/draco-types.js.map +0 -1
- package/dist/esm/lib/utils/get-draco-schema.js.map +0 -1
- package/dist/esm/lib/utils/version.js +0 -2
- package/dist/esm/lib/utils/version.js.map +0 -1
- package/dist/esm/libs/draco_decoder.wasm +0 -0
- package/dist/esm/libs/draco_encoder.js +0 -52
- package/dist/esm/libs/draco_wasm_wrapper.js +0 -117
- package/dist/esm/workers/draco-worker-node.js.map +0 -1
- package/dist/esm/workers/draco-worker.js.map +0 -1
- package/dist/esm/workers/draco-writer-worker-node.js.map +0 -1
- package/dist/esm/workers/draco-writer-worker.js.map +0 -1
- package/src/bundle.ts +0 -4
- /package/dist/{esm/draco3d → draco3d}/draco3d-types.js +0 -0
- /package/dist/{esm/lib → lib}/draco-types.js +0 -0
- /package/dist/{es5 → libs}/libs/draco_decoder.wasm +0 -0
- /package/dist/{es5 → libs}/libs/draco_encoder.js +0 -0
- /package/dist/{es5 → libs}/libs/draco_wasm_wrapper.js +0 -0
package/dist/dist.dev.js
ADDED
|
@@ -0,0 +1,1245 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory();
|
|
4
|
+
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
+
else if (typeof exports === 'object') exports['loader'] = factory();
|
|
6
|
+
else root['loader'] = factory();})(globalThis, function () {
|
|
7
|
+
"use strict";
|
|
8
|
+
var __exports__ = (() => {
|
|
9
|
+
var __create = Object.create;
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
14
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
16
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
+
};
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
+
};
|
|
22
|
+
var __copyProps = (to, from, except, desc) => {
|
|
23
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
+
for (let key of __getOwnPropNames(from))
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
26
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
27
|
+
}
|
|
28
|
+
return to;
|
|
29
|
+
};
|
|
30
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
33
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
36
|
+
mod
|
|
37
|
+
));
|
|
38
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
|
|
40
|
+
// (disabled):../worker-utils/src/lib/node/require-utils.node
|
|
41
|
+
var require_require_utils = __commonJS({
|
|
42
|
+
"(disabled):../worker-utils/src/lib/node/require-utils.node"() {
|
|
43
|
+
"use strict";
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// src/index.ts
|
|
48
|
+
var src_exports = {};
|
|
49
|
+
__export(src_exports, {
|
|
50
|
+
DRACO_EXTERNAL_LIBRARIES: () => DRACO_EXTERNAL_LIBRARIES,
|
|
51
|
+
DRACO_EXTERNAL_LIBRARY_URLS: () => DRACO_EXTERNAL_LIBRARY_URLS,
|
|
52
|
+
DracoLoader: () => DracoLoader2,
|
|
53
|
+
DracoWorkerLoader: () => DracoLoader,
|
|
54
|
+
DracoWriter: () => DracoWriter,
|
|
55
|
+
DracoWriterWorker: () => DracoWriterWorker
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// src/lib/utils/version.ts
|
|
59
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
60
|
+
|
|
61
|
+
// src/draco-loader.ts
|
|
62
|
+
var DEFAULT_DRACO_OPTIONS = {
|
|
63
|
+
draco: {
|
|
64
|
+
decoderType: typeof WebAssembly === "object" ? "wasm" : "js",
|
|
65
|
+
// 'js' for IE11
|
|
66
|
+
libraryPath: "libs/",
|
|
67
|
+
extraAttributes: {},
|
|
68
|
+
attributeNameEntry: void 0
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var DracoLoader = {
|
|
72
|
+
name: "Draco",
|
|
73
|
+
id: "draco",
|
|
74
|
+
module: "draco",
|
|
75
|
+
// shapes: ['mesh'],
|
|
76
|
+
version: VERSION,
|
|
77
|
+
worker: true,
|
|
78
|
+
extensions: ["drc"],
|
|
79
|
+
mimeTypes: ["application/octet-stream"],
|
|
80
|
+
binary: true,
|
|
81
|
+
tests: ["DRACO"],
|
|
82
|
+
options: DEFAULT_DRACO_OPTIONS
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// ../schema/src/lib/table/simple-table/data-type.ts
|
|
86
|
+
function getDataTypeFromTypedArray(array) {
|
|
87
|
+
switch (array.constructor) {
|
|
88
|
+
case Int8Array:
|
|
89
|
+
return "int8";
|
|
90
|
+
case Uint8Array:
|
|
91
|
+
case Uint8ClampedArray:
|
|
92
|
+
return "uint8";
|
|
93
|
+
case Int16Array:
|
|
94
|
+
return "int16";
|
|
95
|
+
case Uint16Array:
|
|
96
|
+
return "uint16";
|
|
97
|
+
case Int32Array:
|
|
98
|
+
return "int32";
|
|
99
|
+
case Uint32Array:
|
|
100
|
+
return "uint32";
|
|
101
|
+
case Float32Array:
|
|
102
|
+
return "float32";
|
|
103
|
+
case Float64Array:
|
|
104
|
+
return "float64";
|
|
105
|
+
default:
|
|
106
|
+
return "null";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ../schema/src/lib/mesh/mesh-utils.ts
|
|
111
|
+
function getMeshBoundingBox(attributes) {
|
|
112
|
+
let minX = Infinity;
|
|
113
|
+
let minY = Infinity;
|
|
114
|
+
let minZ = Infinity;
|
|
115
|
+
let maxX = -Infinity;
|
|
116
|
+
let maxY = -Infinity;
|
|
117
|
+
let maxZ = -Infinity;
|
|
118
|
+
const positions = attributes.POSITION ? attributes.POSITION.value : [];
|
|
119
|
+
const len = positions && positions.length;
|
|
120
|
+
for (let i = 0; i < len; i += 3) {
|
|
121
|
+
const x = positions[i];
|
|
122
|
+
const y = positions[i + 1];
|
|
123
|
+
const z = positions[i + 2];
|
|
124
|
+
minX = x < minX ? x : minX;
|
|
125
|
+
minY = y < minY ? y : minY;
|
|
126
|
+
minZ = z < minZ ? z : minZ;
|
|
127
|
+
maxX = x > maxX ? x : maxX;
|
|
128
|
+
maxY = y > maxY ? y : maxY;
|
|
129
|
+
maxZ = z > maxZ ? z : maxZ;
|
|
130
|
+
}
|
|
131
|
+
return [[minX, minY, minZ], [maxX, maxY, maxZ]];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ../schema/src/lib/mesh/deduce-mesh-schema.ts
|
|
135
|
+
function deduceMeshField(name, attribute, optionalMetadata) {
|
|
136
|
+
const type = getDataTypeFromTypedArray(attribute.value);
|
|
137
|
+
const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
|
|
138
|
+
return {
|
|
139
|
+
name,
|
|
140
|
+
type: {
|
|
141
|
+
type: "fixed-size-list",
|
|
142
|
+
listSize: attribute.size,
|
|
143
|
+
children: [{
|
|
144
|
+
name: "value",
|
|
145
|
+
type
|
|
146
|
+
}]
|
|
147
|
+
},
|
|
148
|
+
nullable: false,
|
|
149
|
+
metadata
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function makeMeshAttributeMetadata(attribute) {
|
|
153
|
+
const result = {};
|
|
154
|
+
if ("byteOffset" in attribute) {
|
|
155
|
+
result.byteOffset = attribute.byteOffset.toString(10);
|
|
156
|
+
}
|
|
157
|
+
if ("byteStride" in attribute) {
|
|
158
|
+
result.byteStride = attribute.byteStride.toString(10);
|
|
159
|
+
}
|
|
160
|
+
if ("normalized" in attribute) {
|
|
161
|
+
result.normalized = attribute.normalized.toString();
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/lib/utils/get-draco-schema.ts
|
|
167
|
+
function getDracoSchema(attributes, loaderData, indices) {
|
|
168
|
+
const metadata = makeMetadata(loaderData.metadata);
|
|
169
|
+
const fields = [];
|
|
170
|
+
const namedLoaderDataAttributes = transformAttributesLoaderData(loaderData.attributes);
|
|
171
|
+
for (const attributeName in attributes) {
|
|
172
|
+
const attribute = attributes[attributeName];
|
|
173
|
+
const field = getArrowFieldFromAttribute(attributeName, attribute, namedLoaderDataAttributes[attributeName]);
|
|
174
|
+
fields.push(field);
|
|
175
|
+
}
|
|
176
|
+
if (indices) {
|
|
177
|
+
const indicesField = getArrowFieldFromAttribute("indices", indices);
|
|
178
|
+
fields.push(indicesField);
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
fields,
|
|
182
|
+
metadata
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function transformAttributesLoaderData(loaderData) {
|
|
186
|
+
const result = {};
|
|
187
|
+
for (const key in loaderData) {
|
|
188
|
+
const dracoAttribute = loaderData[key];
|
|
189
|
+
result[dracoAttribute.name || "undefined"] = dracoAttribute;
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
function getArrowFieldFromAttribute(attributeName, attribute, loaderData) {
|
|
194
|
+
const metadataMap = loaderData ? makeMetadata(loaderData.metadata) : void 0;
|
|
195
|
+
const field = deduceMeshField(attributeName, attribute, metadataMap);
|
|
196
|
+
return field;
|
|
197
|
+
}
|
|
198
|
+
function makeMetadata(metadata) {
|
|
199
|
+
Object.entries(metadata);
|
|
200
|
+
const serializedMetadata = {};
|
|
201
|
+
for (const key in metadata) {
|
|
202
|
+
serializedMetadata[`${key}.string`] = JSON.stringify(metadata[key]);
|
|
203
|
+
}
|
|
204
|
+
return serializedMetadata;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/lib/draco-parser.ts
|
|
208
|
+
var DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {
|
|
209
|
+
POSITION: "POSITION",
|
|
210
|
+
NORMAL: "NORMAL",
|
|
211
|
+
COLOR: "COLOR_0",
|
|
212
|
+
TEX_COORD: "TEXCOORD_0"
|
|
213
|
+
};
|
|
214
|
+
var DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
|
|
215
|
+
1: Int8Array,
|
|
216
|
+
2: Uint8Array,
|
|
217
|
+
3: Int16Array,
|
|
218
|
+
4: Uint16Array,
|
|
219
|
+
5: Int32Array,
|
|
220
|
+
6: Uint32Array,
|
|
221
|
+
9: Float32Array
|
|
222
|
+
};
|
|
223
|
+
var INDEX_ITEM_SIZE = 4;
|
|
224
|
+
var DracoParser = class {
|
|
225
|
+
// draco - the draco decoder, either import `draco3d` or load dynamically
|
|
226
|
+
constructor(draco) {
|
|
227
|
+
this.draco = draco;
|
|
228
|
+
this.decoder = new this.draco.Decoder();
|
|
229
|
+
this.metadataQuerier = new this.draco.MetadataQuerier();
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Destroy draco resources
|
|
233
|
+
*/
|
|
234
|
+
destroy() {
|
|
235
|
+
this.draco.destroy(this.decoder);
|
|
236
|
+
this.draco.destroy(this.metadataQuerier);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* NOTE: caller must call `destroyGeometry` on the return value after using it
|
|
240
|
+
* @param arrayBuffer
|
|
241
|
+
* @param options
|
|
242
|
+
*/
|
|
243
|
+
parseSync(arrayBuffer, options = {}) {
|
|
244
|
+
const buffer = new this.draco.DecoderBuffer();
|
|
245
|
+
buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
|
|
246
|
+
this._disableAttributeTransforms(options);
|
|
247
|
+
const geometry_type = this.decoder.GetEncodedGeometryType(buffer);
|
|
248
|
+
const dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
|
|
249
|
+
try {
|
|
250
|
+
let dracoStatus;
|
|
251
|
+
switch (geometry_type) {
|
|
252
|
+
case this.draco.TRIANGULAR_MESH:
|
|
253
|
+
dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
|
|
254
|
+
break;
|
|
255
|
+
case this.draco.POINT_CLOUD:
|
|
256
|
+
dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
|
|
257
|
+
break;
|
|
258
|
+
default:
|
|
259
|
+
throw new Error("DRACO: Unknown geometry type.");
|
|
260
|
+
}
|
|
261
|
+
if (!dracoStatus.ok() || !dracoGeometry.ptr) {
|
|
262
|
+
const message = `DRACO decompression failed: ${dracoStatus.error_msg()}`;
|
|
263
|
+
throw new Error(message);
|
|
264
|
+
}
|
|
265
|
+
const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);
|
|
266
|
+
const geometry = this._getMeshData(dracoGeometry, loaderData, options);
|
|
267
|
+
const boundingBox = getMeshBoundingBox(geometry.attributes);
|
|
268
|
+
const schema = getDracoSchema(geometry.attributes, loaderData, geometry.indices);
|
|
269
|
+
const data = {
|
|
270
|
+
loader: "draco",
|
|
271
|
+
loaderData,
|
|
272
|
+
header: {
|
|
273
|
+
vertexCount: dracoGeometry.num_points(),
|
|
274
|
+
boundingBox
|
|
275
|
+
},
|
|
276
|
+
...geometry,
|
|
277
|
+
schema
|
|
278
|
+
};
|
|
279
|
+
return data;
|
|
280
|
+
} finally {
|
|
281
|
+
this.draco.destroy(buffer);
|
|
282
|
+
if (dracoGeometry) {
|
|
283
|
+
this.draco.destroy(dracoGeometry);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// Draco specific "loader data"
|
|
288
|
+
/**
|
|
289
|
+
* Extract
|
|
290
|
+
* @param dracoGeometry
|
|
291
|
+
* @param geometry_type
|
|
292
|
+
* @param options
|
|
293
|
+
* @returns
|
|
294
|
+
*/
|
|
295
|
+
_getDracoLoaderData(dracoGeometry, geometry_type, options) {
|
|
296
|
+
const metadata = this._getTopLevelMetadata(dracoGeometry);
|
|
297
|
+
const attributes = this._getDracoAttributes(dracoGeometry, options);
|
|
298
|
+
return {
|
|
299
|
+
geometry_type,
|
|
300
|
+
num_attributes: dracoGeometry.num_attributes(),
|
|
301
|
+
num_points: dracoGeometry.num_points(),
|
|
302
|
+
num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
|
|
303
|
+
metadata,
|
|
304
|
+
attributes
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Extract all draco provided information and metadata for each attribute
|
|
309
|
+
* @param dracoGeometry
|
|
310
|
+
* @param options
|
|
311
|
+
* @returns
|
|
312
|
+
*/
|
|
313
|
+
_getDracoAttributes(dracoGeometry, options) {
|
|
314
|
+
const dracoAttributes = {};
|
|
315
|
+
for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
|
|
316
|
+
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
|
|
317
|
+
const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
|
|
318
|
+
dracoAttributes[dracoAttribute.unique_id()] = {
|
|
319
|
+
unique_id: dracoAttribute.unique_id(),
|
|
320
|
+
attribute_type: dracoAttribute.attribute_type(),
|
|
321
|
+
data_type: dracoAttribute.data_type(),
|
|
322
|
+
num_components: dracoAttribute.num_components(),
|
|
323
|
+
byte_offset: dracoAttribute.byte_offset(),
|
|
324
|
+
byte_stride: dracoAttribute.byte_stride(),
|
|
325
|
+
normalized: dracoAttribute.normalized(),
|
|
326
|
+
attribute_index: attributeId,
|
|
327
|
+
metadata
|
|
328
|
+
};
|
|
329
|
+
const quantization = this._getQuantizationTransform(dracoAttribute, options);
|
|
330
|
+
if (quantization) {
|
|
331
|
+
dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
|
|
332
|
+
}
|
|
333
|
+
const octahedron = this._getOctahedronTransform(dracoAttribute, options);
|
|
334
|
+
if (octahedron) {
|
|
335
|
+
dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return dracoAttributes;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Get standard loaders.gl mesh category data
|
|
342
|
+
* Extracts the geometry from draco
|
|
343
|
+
* @param dracoGeometry
|
|
344
|
+
* @param options
|
|
345
|
+
*/
|
|
346
|
+
_getMeshData(dracoGeometry, loaderData, options) {
|
|
347
|
+
const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
|
|
348
|
+
const positionAttribute = attributes.POSITION;
|
|
349
|
+
if (!positionAttribute) {
|
|
350
|
+
throw new Error("DRACO: No position attribute found.");
|
|
351
|
+
}
|
|
352
|
+
if (dracoGeometry instanceof this.draco.Mesh) {
|
|
353
|
+
switch (options.topology) {
|
|
354
|
+
case "triangle-strip":
|
|
355
|
+
return {
|
|
356
|
+
topology: "triangle-strip",
|
|
357
|
+
mode: 4,
|
|
358
|
+
// GL.TRIANGLES
|
|
359
|
+
attributes,
|
|
360
|
+
indices: {
|
|
361
|
+
value: this._getTriangleStripIndices(dracoGeometry),
|
|
362
|
+
size: 1
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
case "triangle-list":
|
|
366
|
+
default:
|
|
367
|
+
return {
|
|
368
|
+
topology: "triangle-list",
|
|
369
|
+
mode: 5,
|
|
370
|
+
// GL.TRIANGLE_STRIP
|
|
371
|
+
attributes,
|
|
372
|
+
indices: {
|
|
373
|
+
value: this._getTriangleListIndices(dracoGeometry),
|
|
374
|
+
size: 1
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
topology: "point-list",
|
|
381
|
+
mode: 0,
|
|
382
|
+
// GL.POINTS
|
|
383
|
+
attributes
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
_getMeshAttributes(loaderData, dracoGeometry, options) {
|
|
387
|
+
const attributes = {};
|
|
388
|
+
for (const loaderAttribute of Object.values(loaderData.attributes)) {
|
|
389
|
+
const attributeName = this._deduceAttributeName(loaderAttribute, options);
|
|
390
|
+
loaderAttribute.name = attributeName;
|
|
391
|
+
const {
|
|
392
|
+
value,
|
|
393
|
+
size
|
|
394
|
+
} = this._getAttributeValues(dracoGeometry, loaderAttribute);
|
|
395
|
+
attributes[attributeName] = {
|
|
396
|
+
value,
|
|
397
|
+
size,
|
|
398
|
+
byteOffset: loaderAttribute.byte_offset,
|
|
399
|
+
byteStride: loaderAttribute.byte_stride,
|
|
400
|
+
normalized: loaderAttribute.normalized
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
return attributes;
|
|
404
|
+
}
|
|
405
|
+
// MESH INDICES EXTRACTION
|
|
406
|
+
/**
|
|
407
|
+
* For meshes, we need indices to define the faces.
|
|
408
|
+
* @param dracoGeometry
|
|
409
|
+
*/
|
|
410
|
+
_getTriangleListIndices(dracoGeometry) {
|
|
411
|
+
const numFaces = dracoGeometry.num_faces();
|
|
412
|
+
const numIndices = numFaces * 3;
|
|
413
|
+
const byteLength = numIndices * INDEX_ITEM_SIZE;
|
|
414
|
+
const ptr = this.draco._malloc(byteLength);
|
|
415
|
+
try {
|
|
416
|
+
this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
|
|
417
|
+
return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
|
|
418
|
+
} finally {
|
|
419
|
+
this.draco._free(ptr);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* For meshes, we need indices to define the faces.
|
|
424
|
+
* @param dracoGeometry
|
|
425
|
+
*/
|
|
426
|
+
_getTriangleStripIndices(dracoGeometry) {
|
|
427
|
+
const dracoArray = new this.draco.DracoInt32Array();
|
|
428
|
+
try {
|
|
429
|
+
this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);
|
|
430
|
+
return getUint32Array(dracoArray);
|
|
431
|
+
} finally {
|
|
432
|
+
this.draco.destroy(dracoArray);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
*
|
|
437
|
+
* @param dracoGeometry
|
|
438
|
+
* @param dracoAttribute
|
|
439
|
+
* @param attributeName
|
|
440
|
+
*/
|
|
441
|
+
_getAttributeValues(dracoGeometry, attribute) {
|
|
442
|
+
const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
|
|
443
|
+
const numComponents = attribute.num_components;
|
|
444
|
+
const numPoints = dracoGeometry.num_points();
|
|
445
|
+
const numValues = numPoints * numComponents;
|
|
446
|
+
const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;
|
|
447
|
+
const dataType = getDracoDataType(this.draco, TypedArrayCtor);
|
|
448
|
+
let value;
|
|
449
|
+
const ptr = this.draco._malloc(byteLength);
|
|
450
|
+
try {
|
|
451
|
+
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
|
|
452
|
+
this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
|
|
453
|
+
value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
|
|
454
|
+
} finally {
|
|
455
|
+
this.draco._free(ptr);
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
value,
|
|
459
|
+
size: numComponents
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
// Attribute names
|
|
463
|
+
/**
|
|
464
|
+
* DRACO does not store attribute names - We need to deduce an attribute name
|
|
465
|
+
* for each attribute
|
|
466
|
+
_getAttributeNames(
|
|
467
|
+
dracoGeometry: Mesh | PointCloud,
|
|
468
|
+
options: DracoParseOptions
|
|
469
|
+
): {[unique_id: number]: string} {
|
|
470
|
+
const attributeNames: {[unique_id: number]: string} = {};
|
|
471
|
+
for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
|
|
472
|
+
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
|
|
473
|
+
const attributeName = this._deduceAttributeName(dracoAttribute, options);
|
|
474
|
+
attributeNames[attributeName] = attributeName;
|
|
475
|
+
}
|
|
476
|
+
return attributeNames;
|
|
477
|
+
}
|
|
478
|
+
*/
|
|
479
|
+
/**
|
|
480
|
+
* Deduce an attribute name.
|
|
481
|
+
* @note DRACO does not save attribute names, just general type (POSITION, COLOR)
|
|
482
|
+
* to help optimize compression. We generate GLTF compatible names for the Draco-recognized
|
|
483
|
+
* types
|
|
484
|
+
* @param attributeData
|
|
485
|
+
*/
|
|
486
|
+
_deduceAttributeName(attribute, options) {
|
|
487
|
+
const uniqueId = attribute.unique_id;
|
|
488
|
+
for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) {
|
|
489
|
+
if (attributeUniqueId === uniqueId) {
|
|
490
|
+
return attributeName;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
const thisAttributeType = attribute.attribute_type;
|
|
494
|
+
for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
|
|
495
|
+
const attributeType = this.draco[dracoAttributeConstant];
|
|
496
|
+
if (attributeType === thisAttributeType) {
|
|
497
|
+
return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const entryName = options.attributeNameEntry || "name";
|
|
501
|
+
if (attribute.metadata[entryName]) {
|
|
502
|
+
return attribute.metadata[entryName].string;
|
|
503
|
+
}
|
|
504
|
+
return `CUSTOM_ATTRIBUTE_${uniqueId}`;
|
|
505
|
+
}
|
|
506
|
+
// METADATA EXTRACTION
|
|
507
|
+
/** Get top level metadata */
|
|
508
|
+
_getTopLevelMetadata(dracoGeometry) {
|
|
509
|
+
const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
|
|
510
|
+
return this._getDracoMetadata(dracoMetadata);
|
|
511
|
+
}
|
|
512
|
+
/** Get per attribute metadata */
|
|
513
|
+
_getAttributeMetadata(dracoGeometry, attributeId) {
|
|
514
|
+
const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
|
|
515
|
+
return this._getDracoMetadata(dracoMetadata);
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Extract metadata field values
|
|
519
|
+
* @param dracoMetadata
|
|
520
|
+
* @returns
|
|
521
|
+
*/
|
|
522
|
+
_getDracoMetadata(dracoMetadata) {
|
|
523
|
+
if (!dracoMetadata || !dracoMetadata.ptr) {
|
|
524
|
+
return {};
|
|
525
|
+
}
|
|
526
|
+
const result = {};
|
|
527
|
+
const numEntries = this.metadataQuerier.NumEntries(dracoMetadata);
|
|
528
|
+
for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) {
|
|
529
|
+
const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
|
|
530
|
+
result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
|
|
531
|
+
}
|
|
532
|
+
return result;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Extracts possible values for one metadata entry by name
|
|
536
|
+
* @param dracoMetadata
|
|
537
|
+
* @param entryName
|
|
538
|
+
*/
|
|
539
|
+
_getDracoMetadataField(dracoMetadata, entryName) {
|
|
540
|
+
const dracoArray = new this.draco.DracoInt32Array();
|
|
541
|
+
try {
|
|
542
|
+
this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);
|
|
543
|
+
const intArray = getInt32Array(dracoArray);
|
|
544
|
+
return {
|
|
545
|
+
int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
|
|
546
|
+
string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
|
|
547
|
+
double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
|
|
548
|
+
intArray
|
|
549
|
+
};
|
|
550
|
+
} finally {
|
|
551
|
+
this.draco.destroy(dracoArray);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
// QUANTIZED ATTRIBUTE SUPPORT (NO DECOMPRESSION)
|
|
555
|
+
/** Skip transforms for specific attribute types */
|
|
556
|
+
_disableAttributeTransforms(options) {
|
|
557
|
+
const {
|
|
558
|
+
quantizedAttributes = [],
|
|
559
|
+
octahedronAttributes = []
|
|
560
|
+
} = options;
|
|
561
|
+
const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];
|
|
562
|
+
for (const dracoAttributeName of skipAttributes) {
|
|
563
|
+
this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Extract (and apply?) Position Transform
|
|
568
|
+
* @todo not used
|
|
569
|
+
*/
|
|
570
|
+
_getQuantizationTransform(dracoAttribute, options) {
|
|
571
|
+
const {
|
|
572
|
+
quantizedAttributes = []
|
|
573
|
+
} = options;
|
|
574
|
+
const attribute_type = dracoAttribute.attribute_type();
|
|
575
|
+
const skip = quantizedAttributes.map((type) => this.decoder[type]).includes(attribute_type);
|
|
576
|
+
if (skip) {
|
|
577
|
+
const transform = new this.draco.AttributeQuantizationTransform();
|
|
578
|
+
try {
|
|
579
|
+
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
580
|
+
return {
|
|
581
|
+
quantization_bits: transform.quantization_bits(),
|
|
582
|
+
range: transform.range(),
|
|
583
|
+
min_values: new Float32Array([1, 2, 3]).map((i) => transform.min_value(i))
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
} finally {
|
|
587
|
+
this.draco.destroy(transform);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
_getOctahedronTransform(dracoAttribute, options) {
|
|
593
|
+
const {
|
|
594
|
+
octahedronAttributes = []
|
|
595
|
+
} = options;
|
|
596
|
+
const attribute_type = dracoAttribute.attribute_type();
|
|
597
|
+
const octahedron = octahedronAttributes.map((type) => this.decoder[type]).includes(attribute_type);
|
|
598
|
+
if (octahedron) {
|
|
599
|
+
const transform = new this.draco.AttributeQuantizationTransform();
|
|
600
|
+
try {
|
|
601
|
+
if (transform.InitFromAttribute(dracoAttribute)) {
|
|
602
|
+
return {
|
|
603
|
+
quantization_bits: transform.quantization_bits()
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
} finally {
|
|
607
|
+
this.draco.destroy(transform);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
// HELPERS
|
|
613
|
+
};
|
|
614
|
+
function getDracoDataType(draco, attributeType) {
|
|
615
|
+
switch (attributeType) {
|
|
616
|
+
case Float32Array:
|
|
617
|
+
return draco.DT_FLOAT32;
|
|
618
|
+
case Int8Array:
|
|
619
|
+
return draco.DT_INT8;
|
|
620
|
+
case Int16Array:
|
|
621
|
+
return draco.DT_INT16;
|
|
622
|
+
case Int32Array:
|
|
623
|
+
return draco.DT_INT32;
|
|
624
|
+
case Uint8Array:
|
|
625
|
+
return draco.DT_UINT8;
|
|
626
|
+
case Uint16Array:
|
|
627
|
+
return draco.DT_UINT16;
|
|
628
|
+
case Uint32Array:
|
|
629
|
+
return draco.DT_UINT32;
|
|
630
|
+
default:
|
|
631
|
+
return draco.DT_INVALID;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function getInt32Array(dracoArray) {
|
|
635
|
+
const numValues = dracoArray.size();
|
|
636
|
+
const intArray = new Int32Array(numValues);
|
|
637
|
+
for (let i = 0; i < numValues; i++) {
|
|
638
|
+
intArray[i] = dracoArray.GetValue(i);
|
|
639
|
+
}
|
|
640
|
+
return intArray;
|
|
641
|
+
}
|
|
642
|
+
function getUint32Array(dracoArray) {
|
|
643
|
+
const numValues = dracoArray.size();
|
|
644
|
+
const intArray = new Int32Array(numValues);
|
|
645
|
+
for (let i = 0; i < numValues; i++) {
|
|
646
|
+
intArray[i] = dracoArray.GetValue(i);
|
|
647
|
+
}
|
|
648
|
+
return intArray;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// ../worker-utils/src/lib/env-utils/version.ts
|
|
652
|
+
var NPM_TAG = "beta";
|
|
653
|
+
function getVersion() {
|
|
654
|
+
if (!globalThis._loadersgl_?.version) {
|
|
655
|
+
globalThis._loadersgl_ = globalThis._loadersgl_ || {};
|
|
656
|
+
if (typeof __VERSION__ === "undefined") {
|
|
657
|
+
console.error("loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.");
|
|
658
|
+
globalThis._loadersgl_.version = NPM_TAG;
|
|
659
|
+
} else {
|
|
660
|
+
globalThis._loadersgl_.version = __VERSION__;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return globalThis._loadersgl_.version;
|
|
664
|
+
}
|
|
665
|
+
var VERSION2 = getVersion();
|
|
666
|
+
|
|
667
|
+
// ../worker-utils/src/lib/env-utils/assert.ts
|
|
668
|
+
function assert(condition, message) {
|
|
669
|
+
if (!condition) {
|
|
670
|
+
throw new Error(message || "loaders.gl assertion failed.");
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// ../worker-utils/src/lib/env-utils/globals.ts
|
|
675
|
+
var globals = {
|
|
676
|
+
self: typeof self !== "undefined" && self,
|
|
677
|
+
window: typeof window !== "undefined" && window,
|
|
678
|
+
global: typeof global !== "undefined" && global,
|
|
679
|
+
document: typeof document !== "undefined" && document
|
|
680
|
+
};
|
|
681
|
+
var self_ = globals.self || globals.window || globals.global || {};
|
|
682
|
+
var window_ = globals.window || globals.self || globals.global || {};
|
|
683
|
+
var global_ = globals.global || globals.self || globals.window || {};
|
|
684
|
+
var document_ = globals.document || {};
|
|
685
|
+
var isBrowser = (
|
|
686
|
+
// @ts-ignore process.browser
|
|
687
|
+
typeof process !== "object" || String(process) !== "[object process]" || process.browser
|
|
688
|
+
);
|
|
689
|
+
var isWorker = typeof importScripts === "function";
|
|
690
|
+
var isMobile = typeof window !== "undefined" && typeof window.orientation !== "undefined";
|
|
691
|
+
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
692
|
+
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
693
|
+
|
|
694
|
+
// ../worker-utils/src/lib/library-utils/library-utils.ts
|
|
695
|
+
var node = __toESM(require_require_utils(), 1);
|
|
696
|
+
var loadLibraryPromises = {};
|
|
697
|
+
async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
|
|
698
|
+
if (moduleName) {
|
|
699
|
+
libraryUrl = getLibraryUrl(libraryUrl, moduleName, options, libraryName);
|
|
700
|
+
}
|
|
701
|
+
loadLibraryPromises[libraryUrl] = // eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
702
|
+
loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
|
|
703
|
+
return await loadLibraryPromises[libraryUrl];
|
|
704
|
+
}
|
|
705
|
+
function getLibraryUrl(library, moduleName, options = {}, libraryName = null) {
|
|
706
|
+
if (!options.useLocalLibraries && library.startsWith("http")) {
|
|
707
|
+
return library;
|
|
708
|
+
}
|
|
709
|
+
libraryName = libraryName || library;
|
|
710
|
+
const modules = options.modules || {};
|
|
711
|
+
if (modules[libraryName]) {
|
|
712
|
+
return modules[libraryName];
|
|
713
|
+
}
|
|
714
|
+
if (!isBrowser) {
|
|
715
|
+
return `modules/${moduleName}/dist/libs/${libraryName}`;
|
|
716
|
+
}
|
|
717
|
+
if (options.CDN) {
|
|
718
|
+
assert(options.CDN.startsWith("http"));
|
|
719
|
+
return `${options.CDN}/${moduleName}@${VERSION2}/dist/libs/${libraryName}`;
|
|
720
|
+
}
|
|
721
|
+
if (isWorker) {
|
|
722
|
+
return `../src/libs/${libraryName}`;
|
|
723
|
+
}
|
|
724
|
+
return `modules/${moduleName}/src/libs/${libraryName}`;
|
|
725
|
+
}
|
|
726
|
+
async function loadLibraryFromFile(libraryUrl) {
|
|
727
|
+
if (libraryUrl.endsWith("wasm")) {
|
|
728
|
+
return await loadAsArrayBuffer(libraryUrl);
|
|
729
|
+
}
|
|
730
|
+
if (!isBrowser) {
|
|
731
|
+
try {
|
|
732
|
+
return node && void 0 && await (void 0)(libraryUrl);
|
|
733
|
+
} catch (error) {
|
|
734
|
+
console.error(error);
|
|
735
|
+
return null;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (isWorker) {
|
|
739
|
+
return importScripts(libraryUrl);
|
|
740
|
+
}
|
|
741
|
+
const scriptSource = await loadAsText(libraryUrl);
|
|
742
|
+
return loadLibraryFromString(scriptSource, libraryUrl);
|
|
743
|
+
}
|
|
744
|
+
function loadLibraryFromString(scriptSource, id) {
|
|
745
|
+
if (!isBrowser) {
|
|
746
|
+
return void 0 && (void 0)(scriptSource, id);
|
|
747
|
+
}
|
|
748
|
+
if (isWorker) {
|
|
749
|
+
eval.call(global_, scriptSource);
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
const script = document.createElement("script");
|
|
753
|
+
script.id = id;
|
|
754
|
+
try {
|
|
755
|
+
script.appendChild(document.createTextNode(scriptSource));
|
|
756
|
+
} catch (e) {
|
|
757
|
+
script.text = scriptSource;
|
|
758
|
+
}
|
|
759
|
+
document.body.appendChild(script);
|
|
760
|
+
return null;
|
|
761
|
+
}
|
|
762
|
+
async function loadAsArrayBuffer(url) {
|
|
763
|
+
if (!void 0 || url.startsWith("http")) {
|
|
764
|
+
const response = await fetch(url);
|
|
765
|
+
return await response.arrayBuffer();
|
|
766
|
+
}
|
|
767
|
+
return await (void 0)(url);
|
|
768
|
+
}
|
|
769
|
+
async function loadAsText(url) {
|
|
770
|
+
if (!void 0 || url.startsWith("http")) {
|
|
771
|
+
const response = await fetch(url);
|
|
772
|
+
return await response.text();
|
|
773
|
+
}
|
|
774
|
+
return await (void 0)(url);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// src/lib/draco-module-loader.ts
|
|
778
|
+
var DRACO_DECODER_VERSION = "1.5.6";
|
|
779
|
+
var DRACO_ENCODER_VERSION = "1.4.1";
|
|
780
|
+
var STATIC_DECODER_URL = `https://www.gstatic.com/draco/versioned/decoders/${DRACO_DECODER_VERSION}`;
|
|
781
|
+
var DRACO_EXTERNAL_LIBRARIES = {
|
|
782
|
+
/** The primary Draco3D encoder, javascript wrapper part */
|
|
783
|
+
DECODER: "draco_wasm_wrapper.js",
|
|
784
|
+
/** The primary draco decoder, compiled web assembly part */
|
|
785
|
+
DECODER_WASM: "draco_decoder.wasm",
|
|
786
|
+
/** Fallback decoder for non-webassebly environments. Very big bundle, lower performance */
|
|
787
|
+
FALLBACK_DECODER: "draco_decoder.js",
|
|
788
|
+
/** Draco encoder */
|
|
789
|
+
ENCODER: "draco_encoder.js"
|
|
790
|
+
};
|
|
791
|
+
var DRACO_EXTERNAL_LIBRARY_URLS = {
|
|
792
|
+
[DRACO_EXTERNAL_LIBRARIES.DECODER]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.DECODER}`,
|
|
793
|
+
[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.DECODER_WASM}`,
|
|
794
|
+
[DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER]: `${STATIC_DECODER_URL}/${DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER}`,
|
|
795
|
+
[DRACO_EXTERNAL_LIBRARIES.ENCODER]: `https://raw.githubusercontent.com/google/draco/${DRACO_ENCODER_VERSION}/javascript/${DRACO_EXTERNAL_LIBRARIES.ENCODER}`
|
|
796
|
+
};
|
|
797
|
+
var loadDecoderPromise;
|
|
798
|
+
var loadEncoderPromise;
|
|
799
|
+
async function loadDracoDecoderModule(options) {
|
|
800
|
+
const modules = options.modules || {};
|
|
801
|
+
if (modules.draco3d) {
|
|
802
|
+
loadDecoderPromise = loadDecoderPromise || modules.draco3d.createDecoderModule({}).then((draco) => {
|
|
803
|
+
return {
|
|
804
|
+
draco
|
|
805
|
+
};
|
|
806
|
+
});
|
|
807
|
+
} else {
|
|
808
|
+
loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);
|
|
809
|
+
}
|
|
810
|
+
return await loadDecoderPromise;
|
|
811
|
+
}
|
|
812
|
+
async function loadDracoEncoderModule(options) {
|
|
813
|
+
const modules = options.modules || {};
|
|
814
|
+
if (modules.draco3d) {
|
|
815
|
+
loadEncoderPromise = loadEncoderPromise || modules.draco3d.createEncoderModule({}).then((draco) => {
|
|
816
|
+
return {
|
|
817
|
+
draco
|
|
818
|
+
};
|
|
819
|
+
});
|
|
820
|
+
} else {
|
|
821
|
+
loadEncoderPromise = loadEncoderPromise || loadDracoEncoder(options);
|
|
822
|
+
}
|
|
823
|
+
return await loadEncoderPromise;
|
|
824
|
+
}
|
|
825
|
+
async function loadDracoDecoder(options) {
|
|
826
|
+
let DracoDecoderModule;
|
|
827
|
+
let wasmBinary;
|
|
828
|
+
switch (options.draco && options.draco.decoderType) {
|
|
829
|
+
case "js":
|
|
830
|
+
DracoDecoderModule = await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER], "draco", options, DRACO_EXTERNAL_LIBRARIES.FALLBACK_DECODER);
|
|
831
|
+
break;
|
|
832
|
+
case "wasm":
|
|
833
|
+
default:
|
|
834
|
+
[DracoDecoderModule, wasmBinary] = await Promise.all([await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER], "draco", options, DRACO_EXTERNAL_LIBRARIES.DECODER), await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.DECODER_WASM], "draco", options, DRACO_EXTERNAL_LIBRARIES.DECODER_WASM)]);
|
|
835
|
+
}
|
|
836
|
+
DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;
|
|
837
|
+
return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);
|
|
838
|
+
}
|
|
839
|
+
function initializeDracoDecoder(DracoDecoderModule, wasmBinary) {
|
|
840
|
+
const options = {};
|
|
841
|
+
if (wasmBinary) {
|
|
842
|
+
options.wasmBinary = wasmBinary;
|
|
843
|
+
}
|
|
844
|
+
return new Promise((resolve) => {
|
|
845
|
+
DracoDecoderModule({
|
|
846
|
+
...options,
|
|
847
|
+
onModuleLoaded: (draco) => resolve({
|
|
848
|
+
draco
|
|
849
|
+
})
|
|
850
|
+
// Module is Promise-like. Wrap in object to avoid loop.
|
|
851
|
+
});
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
async function loadDracoEncoder(options) {
|
|
855
|
+
let DracoEncoderModule = await loadLibrary(DRACO_EXTERNAL_LIBRARY_URLS[DRACO_EXTERNAL_LIBRARIES.ENCODER], "draco", options, DRACO_EXTERNAL_LIBRARIES.ENCODER);
|
|
856
|
+
DracoEncoderModule = DracoEncoderModule || globalThis.DracoEncoderModule;
|
|
857
|
+
return new Promise((resolve) => {
|
|
858
|
+
DracoEncoderModule({
|
|
859
|
+
onModuleLoaded: (draco) => resolve({
|
|
860
|
+
draco
|
|
861
|
+
})
|
|
862
|
+
// Module is Promise-like. Wrap in object to avoid loop.
|
|
863
|
+
});
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// src/lib/draco-builder.ts
|
|
868
|
+
var GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP = {
|
|
869
|
+
POSITION: "POSITION",
|
|
870
|
+
NORMAL: "NORMAL",
|
|
871
|
+
COLOR_0: "COLOR",
|
|
872
|
+
TEXCOORD_0: "TEX_COORD"
|
|
873
|
+
};
|
|
874
|
+
var noop = () => {
|
|
875
|
+
};
|
|
876
|
+
var DracoBuilder = class {
|
|
877
|
+
// draco - the draco decoder, either import `draco3d` or load dynamically
|
|
878
|
+
constructor(draco) {
|
|
879
|
+
this.draco = draco;
|
|
880
|
+
this.dracoEncoder = new this.draco.Encoder();
|
|
881
|
+
this.dracoMeshBuilder = new this.draco.MeshBuilder();
|
|
882
|
+
this.dracoMetadataBuilder = new this.draco.MetadataBuilder();
|
|
883
|
+
}
|
|
884
|
+
destroy() {
|
|
885
|
+
this.destroyEncodedObject(this.dracoMeshBuilder);
|
|
886
|
+
this.destroyEncodedObject(this.dracoEncoder);
|
|
887
|
+
this.destroyEncodedObject(this.dracoMetadataBuilder);
|
|
888
|
+
this.dracoMeshBuilder = null;
|
|
889
|
+
this.dracoEncoder = null;
|
|
890
|
+
this.draco = null;
|
|
891
|
+
}
|
|
892
|
+
// TBD - when does this need to be called?
|
|
893
|
+
destroyEncodedObject(object) {
|
|
894
|
+
if (object) {
|
|
895
|
+
this.draco.destroy(object);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Encode mesh or point cloud
|
|
900
|
+
* @param mesh =({})
|
|
901
|
+
* @param options
|
|
902
|
+
*/
|
|
903
|
+
encodeSync(mesh, options = {}) {
|
|
904
|
+
this.log = noop;
|
|
905
|
+
this._setOptions(options);
|
|
906
|
+
return options.pointcloud ? this._encodePointCloud(mesh, options) : this._encodeMesh(mesh, options);
|
|
907
|
+
}
|
|
908
|
+
// PRIVATE
|
|
909
|
+
_getAttributesFromMesh(mesh) {
|
|
910
|
+
const attributes = {
|
|
911
|
+
...mesh,
|
|
912
|
+
...mesh.attributes
|
|
913
|
+
};
|
|
914
|
+
if (mesh.indices) {
|
|
915
|
+
attributes.indices = mesh.indices;
|
|
916
|
+
}
|
|
917
|
+
return attributes;
|
|
918
|
+
}
|
|
919
|
+
_encodePointCloud(pointcloud, options) {
|
|
920
|
+
const dracoPointCloud = new this.draco.PointCloud();
|
|
921
|
+
if (options.metadata) {
|
|
922
|
+
this._addGeometryMetadata(dracoPointCloud, options.metadata);
|
|
923
|
+
}
|
|
924
|
+
const attributes = this._getAttributesFromMesh(pointcloud);
|
|
925
|
+
this._createDracoPointCloud(dracoPointCloud, attributes, options);
|
|
926
|
+
const dracoData = new this.draco.DracoInt8Array();
|
|
927
|
+
try {
|
|
928
|
+
const encodedLen = this.dracoEncoder.EncodePointCloudToDracoBuffer(dracoPointCloud, false, dracoData);
|
|
929
|
+
if (!(encodedLen > 0)) {
|
|
930
|
+
throw new Error("Draco encoding failed.");
|
|
931
|
+
}
|
|
932
|
+
this.log(`DRACO encoded ${dracoPointCloud.num_points()} points
|
|
933
|
+
with ${dracoPointCloud.num_attributes()} attributes into ${encodedLen} bytes`);
|
|
934
|
+
return dracoInt8ArrayToArrayBuffer(dracoData);
|
|
935
|
+
} finally {
|
|
936
|
+
this.destroyEncodedObject(dracoData);
|
|
937
|
+
this.destroyEncodedObject(dracoPointCloud);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
_encodeMesh(mesh, options) {
|
|
941
|
+
const dracoMesh = new this.draco.Mesh();
|
|
942
|
+
if (options.metadata) {
|
|
943
|
+
this._addGeometryMetadata(dracoMesh, options.metadata);
|
|
944
|
+
}
|
|
945
|
+
const attributes = this._getAttributesFromMesh(mesh);
|
|
946
|
+
this._createDracoMesh(dracoMesh, attributes, options);
|
|
947
|
+
const dracoData = new this.draco.DracoInt8Array();
|
|
948
|
+
try {
|
|
949
|
+
const encodedLen = this.dracoEncoder.EncodeMeshToDracoBuffer(dracoMesh, dracoData);
|
|
950
|
+
if (encodedLen <= 0) {
|
|
951
|
+
throw new Error("Draco encoding failed.");
|
|
952
|
+
}
|
|
953
|
+
this.log(`DRACO encoded ${dracoMesh.num_points()} points
|
|
954
|
+
with ${dracoMesh.num_attributes()} attributes into ${encodedLen} bytes`);
|
|
955
|
+
return dracoInt8ArrayToArrayBuffer(dracoData);
|
|
956
|
+
} finally {
|
|
957
|
+
this.destroyEncodedObject(dracoData);
|
|
958
|
+
this.destroyEncodedObject(dracoMesh);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Set encoding options.
|
|
963
|
+
* @param {{speed?: any; method?: any; quantization?: any;}} options
|
|
964
|
+
*/
|
|
965
|
+
_setOptions(options) {
|
|
966
|
+
if ("speed" in options) {
|
|
967
|
+
this.dracoEncoder.SetSpeedOptions(...options.speed);
|
|
968
|
+
}
|
|
969
|
+
if ("method" in options) {
|
|
970
|
+
const dracoMethod = this.draco[options.method || "MESH_SEQUENTIAL_ENCODING"];
|
|
971
|
+
this.dracoEncoder.SetEncodingMethod(dracoMethod);
|
|
972
|
+
}
|
|
973
|
+
if ("quantization" in options) {
|
|
974
|
+
for (const attribute in options.quantization) {
|
|
975
|
+
const bits = options.quantization[attribute];
|
|
976
|
+
const dracoPosition = this.draco[attribute];
|
|
977
|
+
this.dracoEncoder.SetAttributeQuantization(dracoPosition, bits);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* @param {Mesh} dracoMesh
|
|
983
|
+
* @param {object} attributes
|
|
984
|
+
* @returns {Mesh}
|
|
985
|
+
*/
|
|
986
|
+
_createDracoMesh(dracoMesh, attributes, options) {
|
|
987
|
+
const optionalMetadata = options.attributesMetadata || {};
|
|
988
|
+
try {
|
|
989
|
+
const positions = this._getPositionAttribute(attributes);
|
|
990
|
+
if (!positions) {
|
|
991
|
+
throw new Error("positions");
|
|
992
|
+
}
|
|
993
|
+
const vertexCount = positions.length / 3;
|
|
994
|
+
for (let attributeName in attributes) {
|
|
995
|
+
const attribute = attributes[attributeName];
|
|
996
|
+
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
|
|
997
|
+
const uniqueId = this._addAttributeToMesh(dracoMesh, attributeName, attribute, vertexCount);
|
|
998
|
+
if (uniqueId !== -1) {
|
|
999
|
+
this._addAttributeMetadata(dracoMesh, uniqueId, {
|
|
1000
|
+
name: attributeName,
|
|
1001
|
+
...optionalMetadata[attributeName] || {}
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
} catch (error) {
|
|
1006
|
+
this.destroyEncodedObject(dracoMesh);
|
|
1007
|
+
throw error;
|
|
1008
|
+
}
|
|
1009
|
+
return dracoMesh;
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* @param {} dracoPointCloud
|
|
1013
|
+
* @param {object} attributes
|
|
1014
|
+
*/
|
|
1015
|
+
_createDracoPointCloud(dracoPointCloud, attributes, options) {
|
|
1016
|
+
const optionalMetadata = options.attributesMetadata || {};
|
|
1017
|
+
try {
|
|
1018
|
+
const positions = this._getPositionAttribute(attributes);
|
|
1019
|
+
if (!positions) {
|
|
1020
|
+
throw new Error("positions");
|
|
1021
|
+
}
|
|
1022
|
+
const vertexCount = positions.length / 3;
|
|
1023
|
+
for (let attributeName in attributes) {
|
|
1024
|
+
const attribute = attributes[attributeName];
|
|
1025
|
+
attributeName = GLTF_TO_DRACO_ATTRIBUTE_NAME_MAP[attributeName] || attributeName;
|
|
1026
|
+
const uniqueId = this._addAttributeToMesh(dracoPointCloud, attributeName, attribute, vertexCount);
|
|
1027
|
+
if (uniqueId !== -1) {
|
|
1028
|
+
this._addAttributeMetadata(dracoPointCloud, uniqueId, {
|
|
1029
|
+
name: attributeName,
|
|
1030
|
+
...optionalMetadata[attributeName] || {}
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
} catch (error) {
|
|
1035
|
+
this.destroyEncodedObject(dracoPointCloud);
|
|
1036
|
+
throw error;
|
|
1037
|
+
}
|
|
1038
|
+
return dracoPointCloud;
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* @param mesh
|
|
1042
|
+
* @param attributeName
|
|
1043
|
+
* @param attribute
|
|
1044
|
+
* @param vertexCount
|
|
1045
|
+
*/
|
|
1046
|
+
_addAttributeToMesh(mesh, attributeName, attribute, vertexCount) {
|
|
1047
|
+
if (!ArrayBuffer.isView(attribute)) {
|
|
1048
|
+
return -1;
|
|
1049
|
+
}
|
|
1050
|
+
const type = this._getDracoAttributeType(attributeName);
|
|
1051
|
+
const size = attribute.length / vertexCount;
|
|
1052
|
+
if (type === "indices") {
|
|
1053
|
+
const numFaces = attribute.length / 3;
|
|
1054
|
+
this.log(`Adding attribute ${attributeName}, size ${numFaces}`);
|
|
1055
|
+
this.dracoMeshBuilder.AddFacesToMesh(mesh, numFaces, attribute);
|
|
1056
|
+
return -1;
|
|
1057
|
+
}
|
|
1058
|
+
this.log(`Adding attribute ${attributeName}, size ${size}`);
|
|
1059
|
+
const builder = this.dracoMeshBuilder;
|
|
1060
|
+
const {
|
|
1061
|
+
buffer
|
|
1062
|
+
} = attribute;
|
|
1063
|
+
switch (attribute.constructor) {
|
|
1064
|
+
case Int8Array:
|
|
1065
|
+
return builder.AddInt8Attribute(mesh, type, vertexCount, size, new Int8Array(buffer));
|
|
1066
|
+
case Int16Array:
|
|
1067
|
+
return builder.AddInt16Attribute(mesh, type, vertexCount, size, new Int16Array(buffer));
|
|
1068
|
+
case Int32Array:
|
|
1069
|
+
return builder.AddInt32Attribute(mesh, type, vertexCount, size, new Int32Array(buffer));
|
|
1070
|
+
case Uint8Array:
|
|
1071
|
+
case Uint8ClampedArray:
|
|
1072
|
+
return builder.AddUInt8Attribute(mesh, type, vertexCount, size, new Uint8Array(buffer));
|
|
1073
|
+
case Uint16Array:
|
|
1074
|
+
return builder.AddUInt16Attribute(mesh, type, vertexCount, size, new Uint16Array(buffer));
|
|
1075
|
+
case Uint32Array:
|
|
1076
|
+
return builder.AddUInt32Attribute(mesh, type, vertexCount, size, new Uint32Array(buffer));
|
|
1077
|
+
case Float32Array:
|
|
1078
|
+
default:
|
|
1079
|
+
return builder.AddFloatAttribute(mesh, type, vertexCount, size, new Float32Array(buffer));
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* DRACO can compress attributes of know type better
|
|
1084
|
+
* TODO - expose an attribute type map?
|
|
1085
|
+
* @param attributeName
|
|
1086
|
+
*/
|
|
1087
|
+
_getDracoAttributeType(attributeName) {
|
|
1088
|
+
switch (attributeName.toLowerCase()) {
|
|
1089
|
+
case "indices":
|
|
1090
|
+
return "indices";
|
|
1091
|
+
case "position":
|
|
1092
|
+
case "positions":
|
|
1093
|
+
case "vertices":
|
|
1094
|
+
return this.draco.POSITION;
|
|
1095
|
+
case "normal":
|
|
1096
|
+
case "normals":
|
|
1097
|
+
return this.draco.NORMAL;
|
|
1098
|
+
case "color":
|
|
1099
|
+
case "colors":
|
|
1100
|
+
return this.draco.COLOR;
|
|
1101
|
+
case "texcoord":
|
|
1102
|
+
case "texcoords":
|
|
1103
|
+
return this.draco.TEX_COORD;
|
|
1104
|
+
default:
|
|
1105
|
+
return this.draco.GENERIC;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
_getPositionAttribute(attributes) {
|
|
1109
|
+
for (const attributeName in attributes) {
|
|
1110
|
+
const attribute = attributes[attributeName];
|
|
1111
|
+
const dracoType = this._getDracoAttributeType(attributeName);
|
|
1112
|
+
if (dracoType === this.draco.POSITION) {
|
|
1113
|
+
return attribute;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return null;
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Add metadata for the geometry.
|
|
1120
|
+
* @param dracoGeometry - WASM Draco Object
|
|
1121
|
+
* @param metadata
|
|
1122
|
+
*/
|
|
1123
|
+
_addGeometryMetadata(dracoGeometry, metadata) {
|
|
1124
|
+
const dracoMetadata = new this.draco.Metadata();
|
|
1125
|
+
this._populateDracoMetadata(dracoMetadata, metadata);
|
|
1126
|
+
this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Add metadata for an attribute to geometry.
|
|
1130
|
+
* @param dracoGeometry - WASM Draco Object
|
|
1131
|
+
* @param uniqueAttributeId
|
|
1132
|
+
* @param metadata
|
|
1133
|
+
*/
|
|
1134
|
+
_addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata) {
|
|
1135
|
+
const dracoAttributeMetadata = new this.draco.Metadata();
|
|
1136
|
+
this._populateDracoMetadata(dracoAttributeMetadata, metadata);
|
|
1137
|
+
this.dracoMeshBuilder.SetMetadataForAttribute(dracoGeometry, uniqueAttributeId, dracoAttributeMetadata);
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Add contents of object or map to a WASM Draco Metadata Object
|
|
1141
|
+
* @param dracoMetadata - WASM Draco Object
|
|
1142
|
+
* @param metadata
|
|
1143
|
+
*/
|
|
1144
|
+
_populateDracoMetadata(dracoMetadata, metadata) {
|
|
1145
|
+
for (const [key, value] of getEntries(metadata)) {
|
|
1146
|
+
switch (typeof value) {
|
|
1147
|
+
case "number":
|
|
1148
|
+
if (Math.trunc(value) === value) {
|
|
1149
|
+
this.dracoMetadataBuilder.AddIntEntry(dracoMetadata, key, value);
|
|
1150
|
+
} else {
|
|
1151
|
+
this.dracoMetadataBuilder.AddDoubleEntry(dracoMetadata, key, value);
|
|
1152
|
+
}
|
|
1153
|
+
break;
|
|
1154
|
+
case "object":
|
|
1155
|
+
if (value instanceof Int32Array) {
|
|
1156
|
+
this.dracoMetadataBuilder.AddIntEntryArray(dracoMetadata, key, value, value.length);
|
|
1157
|
+
}
|
|
1158
|
+
break;
|
|
1159
|
+
case "string":
|
|
1160
|
+
default:
|
|
1161
|
+
this.dracoMetadataBuilder.AddStringEntry(dracoMetadata, key, value);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
};
|
|
1166
|
+
function dracoInt8ArrayToArrayBuffer(dracoData) {
|
|
1167
|
+
const byteLength = dracoData.size();
|
|
1168
|
+
const outputBuffer = new ArrayBuffer(byteLength);
|
|
1169
|
+
const outputData = new Int8Array(outputBuffer);
|
|
1170
|
+
for (let i = 0; i < byteLength; ++i) {
|
|
1171
|
+
outputData[i] = dracoData.GetValue(i);
|
|
1172
|
+
}
|
|
1173
|
+
return outputBuffer;
|
|
1174
|
+
}
|
|
1175
|
+
function getEntries(container) {
|
|
1176
|
+
const hasEntriesFunc = container.entries && !container.hasOwnProperty("entries");
|
|
1177
|
+
return hasEntriesFunc ? container.entries() : Object.entries(container);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// src/draco-writer.ts
|
|
1181
|
+
var DEFAULT_DRACO_WRITER_OPTIONS = {
|
|
1182
|
+
pointcloud: false,
|
|
1183
|
+
// Set to true if pointcloud (mode: 0, no indices)
|
|
1184
|
+
attributeNameEntry: "name"
|
|
1185
|
+
// Draco Compression Parameters
|
|
1186
|
+
// method: 'MESH_EDGEBREAKER_ENCODING', // Use draco defaults
|
|
1187
|
+
// speed: [5, 5], // Use draco defaults
|
|
1188
|
+
// quantization: { // Use draco defaults
|
|
1189
|
+
// POSITION: 10
|
|
1190
|
+
// }
|
|
1191
|
+
};
|
|
1192
|
+
var DracoWriter = {
|
|
1193
|
+
name: "DRACO",
|
|
1194
|
+
id: "draco",
|
|
1195
|
+
module: "draco",
|
|
1196
|
+
version: VERSION,
|
|
1197
|
+
extensions: ["drc"],
|
|
1198
|
+
encode,
|
|
1199
|
+
options: {
|
|
1200
|
+
draco: DEFAULT_DRACO_WRITER_OPTIONS
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
async function encode(data, options = {}) {
|
|
1204
|
+
const {
|
|
1205
|
+
draco
|
|
1206
|
+
} = await loadDracoEncoderModule(options);
|
|
1207
|
+
const dracoBuilder = new DracoBuilder(draco);
|
|
1208
|
+
try {
|
|
1209
|
+
return dracoBuilder.encodeSync(data, options.draco);
|
|
1210
|
+
} finally {
|
|
1211
|
+
dracoBuilder.destroy();
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// src/index.ts
|
|
1216
|
+
var DracoWriterWorker = {
|
|
1217
|
+
id: "draco-writer",
|
|
1218
|
+
name: "Draco compressed geometry writer",
|
|
1219
|
+
module: "draco",
|
|
1220
|
+
version: VERSION,
|
|
1221
|
+
worker: true,
|
|
1222
|
+
options: {
|
|
1223
|
+
draco: {},
|
|
1224
|
+
source: null
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
var DracoLoader2 = {
|
|
1228
|
+
...DracoLoader,
|
|
1229
|
+
parse
|
|
1230
|
+
};
|
|
1231
|
+
async function parse(arrayBuffer, options) {
|
|
1232
|
+
const {
|
|
1233
|
+
draco
|
|
1234
|
+
} = await loadDracoDecoderModule(options);
|
|
1235
|
+
const dracoParser = new DracoParser(draco);
|
|
1236
|
+
try {
|
|
1237
|
+
return dracoParser.parseSync(arrayBuffer, options?.draco);
|
|
1238
|
+
} finally {
|
|
1239
|
+
dracoParser.destroy();
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return __toCommonJS(src_exports);
|
|
1243
|
+
})();
|
|
1244
|
+
return __exports__;
|
|
1245
|
+
});
|