@loaders.gl/tiles-3d 5.0.0-beta.4 → 5.0.0-beta.6
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/README.md +1 -1
- package/dist/3d-tiles/3d-tiles-archive-loader.js +1 -1
- package/dist/3d-tiles/dist.dev.js +941 -621
- package/dist/3d-tiles/dist.min.js +37 -37
- package/dist/3d-tiles/index.cjs +876 -947
- package/dist/3d-tiles/index.cjs.map +3 -3
- package/dist/3d-tiles/lib/parsers/parse-3d-tile-instanced-model.js +5 -1
- package/dist/3d-tiles/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -1
- package/dist/3d-tiles/lib/utils/version.js +1 -1
- package/dist/3d-tiles-archive-writer.cjs +1 -1
- package/dist/cesium-ion-loader-with-parser.cjs +821 -942
- package/dist/cesium-ion-loader-with-parser.cjs.map +3 -3
- package/dist/copc/copc-source-loader.js +2 -2
- package/dist/copc/copc-source-loader.js.map +1 -1
- package/dist/copc/copc-writer.js +1 -1
- package/dist/copc/index.cjs +121 -181
- package/dist/copc/index.cjs.map +3 -3
- package/dist/dist.dev.js +323 -40
- package/dist/dist.min.js +10 -10
- package/dist/i3s/arcgis-webscene-loader.js +1 -1
- package/dist/i3s/dist.dev.js +3173 -712
- package/dist/i3s/dist.min.js +47 -47
- package/dist/i3s/i3s-attribute-loader.js +1 -1
- package/dist/i3s/i3s-building-scene-layer-loader.js +1 -1
- package/dist/i3s/i3s-content-loader.js +1 -1
- package/dist/i3s/i3s-lepcc-loader-types.js +1 -1
- package/dist/i3s/i3s-loader.js +1 -1
- package/dist/i3s/i3s-node-page-loader.js +1 -1
- package/dist/i3s/i3s-slpk-loader.js +1 -1
- package/dist/i3s/i3s-slpk-writer.js +1 -1
- package/dist/i3s/index.cjs +2097 -544
- package/dist/i3s/index.cjs.map +3 -3
- package/dist/i3s-content-worker-node.js +11 -11
- package/dist/i3s-content-worker-node.js.map +4 -4
- package/dist/i3s-content-worker.js +768 -346
- package/dist/i3s-lepcc-worker-node.js +245 -12
- package/dist/i3s-lepcc-worker-node.js.map +4 -4
- package/dist/i3s-lepcc-worker.js +240 -12
- package/dist/i3s-mesh-writer.cjs +1749 -290
- package/dist/i3s-mesh-writer.cjs.map +3 -3
- package/dist/i3s-slpk-writer.cjs +1 -1
- package/dist/index.cjs +98 -4
- package/dist/index.cjs.map +2 -2
- package/dist/point-cloud-tile-source-loader-types.js +1 -1
- package/dist/point-cloud-tile-source-loader.cjs +46 -2
- package/dist/point-cloud-tile-source-loader.cjs.map +2 -2
- package/dist/point-cloud-tile-source.cjs +45 -1
- package/dist/point-cloud-tile-source.cjs.map +1 -1
- package/dist/potree/dist.dev.js +325 -91
- package/dist/potree/dist.min.js +30 -30
- package/dist/potree/index.cjs +115 -176
- package/dist/potree/index.cjs.map +3 -3
- package/dist/potree/potree-bin-loader.js +1 -1
- package/dist/potree/potree-hierarchy-chunk-loader.js +1 -1
- package/dist/potree/potree-loader-types.js +1 -1
- package/dist/potree/potree-source-loader.js +1 -1
- package/dist/potree/potree-writer.js +1 -1
- package/dist/potree/potree2-source.d.ts.map +1 -1
- package/dist/potree/potree2-source.js +3 -13
- package/dist/potree/potree2-source.js.map +1 -1
- package/dist/potree-loader.cjs +1 -1
- package/package.json +13 -13
- package/src/3d-tiles/lib/parsers/parse-3d-tile-instanced-model.ts +4 -1
- package/src/copc/copc-source-loader.ts +1 -1
- package/src/potree/potree2-source.ts +3 -14
package/dist/i3s-mesh-writer.cjs
CHANGED
|
@@ -424,18 +424,6 @@ var init_globals2 = __esm({
|
|
|
424
424
|
}
|
|
425
425
|
});
|
|
426
426
|
|
|
427
|
-
// ../core/src/worker-utils/lib/worker-api/task-runtime.ts
|
|
428
|
-
function normalizeTaskProgress(progress) {
|
|
429
|
-
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
430
|
-
}
|
|
431
|
-
var import_tasks;
|
|
432
|
-
var init_task_runtime = __esm({
|
|
433
|
-
"../core/src/worker-utils/lib/worker-api/task-runtime.ts"() {
|
|
434
|
-
"use strict";
|
|
435
|
-
import_tasks = require("@math.gl/core/tasks");
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
|
|
439
427
|
// ../core/src/worker-utils/lib/worker-api/get-worker-url.ts
|
|
440
428
|
function getCustomWorkerURL(worker, options = {}) {
|
|
441
429
|
var _a, _b;
|
|
@@ -501,6 +489,18 @@ var init_get_worker_url = __esm({
|
|
|
501
489
|
}
|
|
502
490
|
});
|
|
503
491
|
|
|
492
|
+
// ../core/src/worker-utils/lib/worker-api/task-runtime.ts
|
|
493
|
+
function normalizeTaskProgress(progress) {
|
|
494
|
+
return { ...progress, phase: progress.phase ?? "process", unit: progress.unit ?? "items" };
|
|
495
|
+
}
|
|
496
|
+
var import_tasks;
|
|
497
|
+
var init_task_runtime = __esm({
|
|
498
|
+
"../core/src/worker-utils/lib/worker-api/task-runtime.ts"() {
|
|
499
|
+
"use strict";
|
|
500
|
+
import_tasks = require("@math.gl/tasks");
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
|
|
504
504
|
// ../core/src/worker-utils/lib/worker-utils/get-transfer-list.ts
|
|
505
505
|
function getTransferList(object, recursive = true, transfers) {
|
|
506
506
|
const transfersSet = transfers || /* @__PURE__ */ new Set();
|
|
@@ -757,7 +757,7 @@ var import_tasks2, runners, activeRunners, moduleWorkerUrls;
|
|
|
757
757
|
var init_process_on_worker = __esm({
|
|
758
758
|
"../core/src/worker-utils/lib/worker-api/process-on-worker.ts"() {
|
|
759
759
|
"use strict";
|
|
760
|
-
import_tasks2 = require("@math.gl/
|
|
760
|
+
import_tasks2 = require("@math.gl/tasks");
|
|
761
761
|
init_get_worker_url();
|
|
762
762
|
init_task_runtime();
|
|
763
763
|
init_get_transfer_list();
|
|
@@ -872,6 +872,7 @@ async function loadLibraryInWorker(libraryUrl, moduleLibraryUrl = libraryUrl) {
|
|
|
872
872
|
} catch {
|
|
873
873
|
const moduleUrl = new URL(moduleLibraryUrl, globalThis.location.href).href;
|
|
874
874
|
const library = await import(
|
|
875
|
+
/* webpackIgnore: true */
|
|
875
876
|
/* @vite-ignore */
|
|
876
877
|
moduleUrl
|
|
877
878
|
);
|
|
@@ -932,12 +933,10 @@ var init_library_utils = __esm({
|
|
|
932
933
|
});
|
|
933
934
|
|
|
934
935
|
// ../core/src/worker-utils/index.ts
|
|
935
|
-
var import_tasks3;
|
|
936
936
|
var init_worker_utils = __esm({
|
|
937
937
|
"../core/src/worker-utils/index.ts"() {
|
|
938
938
|
"use strict";
|
|
939
939
|
init_globals2();
|
|
940
|
-
import_tasks3 = require("@math.gl/core/tasks");
|
|
941
940
|
init_process_on_worker();
|
|
942
941
|
init_library_utils();
|
|
943
942
|
}
|
|
@@ -1113,9 +1112,9 @@ var init_encode_array_buffer_to_base64 = __esm({
|
|
|
1113
1112
|
|
|
1114
1113
|
// ../core/src/loader-utils/lib/iterators/text-iterators.ts
|
|
1115
1114
|
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
1116
|
-
const
|
|
1115
|
+
const textDecoder2 = new TextDecoder(void 0, options);
|
|
1117
1116
|
for await (const arrayBuffer of arrayBufferIterator) {
|
|
1118
|
-
yield typeof arrayBuffer === "string" ? arrayBuffer :
|
|
1117
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder2.decode(arrayBuffer, { stream: true });
|
|
1119
1118
|
}
|
|
1120
1119
|
}
|
|
1121
1120
|
async function* makeLineIterator(textIterator) {
|
|
@@ -1246,8 +1245,8 @@ function isSVG(url) {
|
|
|
1246
1245
|
}
|
|
1247
1246
|
function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
1248
1247
|
if (isSVG(url)) {
|
|
1249
|
-
const
|
|
1250
|
-
let xmlText =
|
|
1248
|
+
const textDecoder2 = new TextDecoder();
|
|
1249
|
+
let xmlText = textDecoder2.decode(arrayBuffer);
|
|
1251
1250
|
try {
|
|
1252
1251
|
if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
|
|
1253
1252
|
xmlText = unescape(encodeURIComponent(xmlText));
|
|
@@ -2668,17 +2667,11 @@ function serializeArrowSchema(arrowSchema) {
|
|
|
2668
2667
|
metadata: serializeArrowMetadata(arrowSchema.metadata)
|
|
2669
2668
|
};
|
|
2670
2669
|
}
|
|
2671
|
-
function deserializeArrowSchema(schema, options) {
|
|
2672
|
-
return new arrow.Schema(
|
|
2673
|
-
schema.fields.map((field) => deserializeArrowField(field, options)),
|
|
2674
|
-
deserializeArrowMetadata(schema.metadata)
|
|
2675
|
-
);
|
|
2676
|
-
}
|
|
2677
2670
|
function serializeArrowMetadata(arrowMetadata) {
|
|
2678
2671
|
return Object.fromEntries(arrowMetadata);
|
|
2679
2672
|
}
|
|
2680
|
-
function deserializeArrowMetadata(
|
|
2681
|
-
return
|
|
2673
|
+
function deserializeArrowMetadata(metadata3) {
|
|
2674
|
+
return metadata3 ? new Map(Object.entries(metadata3)) : /* @__PURE__ */ new Map();
|
|
2682
2675
|
}
|
|
2683
2676
|
function serializeArrowField(field) {
|
|
2684
2677
|
return {
|
|
@@ -3382,22 +3375,22 @@ function getAttributeArrowField(schema, attributeName, column, componentType) {
|
|
|
3382
3375
|
if (!(suppliedField == null ? void 0 : suppliedField.metadata)) {
|
|
3383
3376
|
return canonicalField;
|
|
3384
3377
|
}
|
|
3385
|
-
const
|
|
3378
|
+
const metadata3 = new Map(canonicalField.metadata);
|
|
3386
3379
|
for (const [key, value] of Object.entries(suppliedField.metadata)) {
|
|
3387
|
-
|
|
3380
|
+
metadata3.set(key, value);
|
|
3388
3381
|
}
|
|
3389
3382
|
return new arrow4.Field(
|
|
3390
3383
|
canonicalField.name,
|
|
3391
3384
|
canonicalField.type,
|
|
3392
3385
|
canonicalField.nullable,
|
|
3393
|
-
|
|
3386
|
+
metadata3
|
|
3394
3387
|
);
|
|
3395
3388
|
}
|
|
3396
3389
|
const field = schema == null ? void 0 : schema.fields.find((schemaField) => schemaField.name === attributeName);
|
|
3397
3390
|
if (componentType === "float16") {
|
|
3398
|
-
const
|
|
3399
|
-
|
|
3400
|
-
return new arrow4.Field(attributeName, column.type, false,
|
|
3391
|
+
const metadata3 = new Map(Object.entries((field == null ? void 0 : field.metadata) || {}));
|
|
3392
|
+
metadata3.set("componentType", "float16");
|
|
3393
|
+
return new arrow4.Field(attributeName, column.type, false, metadata3);
|
|
3401
3394
|
}
|
|
3402
3395
|
if (field && field.type.toString() !== column.type.toString()) {
|
|
3403
3396
|
const deserializedField = deserializeArrowField(field);
|
|
@@ -3446,17 +3439,17 @@ function getIndicesVector(indices, vertexCount, type) {
|
|
|
3446
3439
|
}
|
|
3447
3440
|
function getMeshArrowMetadata(options) {
|
|
3448
3441
|
var _a;
|
|
3449
|
-
const
|
|
3442
|
+
const metadata3 = { ...(_a = options.schema) == null ? void 0 : _a.metadata };
|
|
3450
3443
|
if (options.topology) {
|
|
3451
|
-
|
|
3444
|
+
metadata3.topology ||= options.topology;
|
|
3452
3445
|
}
|
|
3453
3446
|
if (Number.isFinite(options.mode)) {
|
|
3454
|
-
|
|
3447
|
+
metadata3.mode ||= String(options.mode);
|
|
3455
3448
|
}
|
|
3456
3449
|
if (options.boundingBox) {
|
|
3457
|
-
|
|
3450
|
+
metadata3.boundingBox ||= JSON.stringify(options.boundingBox);
|
|
3458
3451
|
}
|
|
3459
|
-
return deserializeArrowMetadata(
|
|
3452
|
+
return deserializeArrowMetadata(metadata3);
|
|
3460
3453
|
}
|
|
3461
3454
|
var arrow4, MESH_ARROW_ATTRIBUTE_ORDER;
|
|
3462
3455
|
var init_convert_mesh_to_table = __esm({
|
|
@@ -3497,15 +3490,15 @@ function convertArrowTableToMesh(table) {
|
|
|
3497
3490
|
const attributeData = arrowTable.getChild(name22);
|
|
3498
3491
|
const size = getFixedSizeListSize(attributeData);
|
|
3499
3492
|
const typedArray = getAttributeTypedArray(attributeData, size);
|
|
3500
|
-
const
|
|
3501
|
-
const value =
|
|
3493
|
+
const metadata3 = getMeshAttributeMetadata(field.metadata);
|
|
3494
|
+
const value = metadata3.componentType === "float16" ? restoreFloat16Array(typedArray) : typedArray;
|
|
3502
3495
|
const shared = columns.find(
|
|
3503
3496
|
(column) => column.data.length === attributeData.data.length && attributes[column.name].value.constructor === value.constructor && column.data.every((chunk, index) => shareArrowStorage(chunk, attributeData.data[index]))
|
|
3504
3497
|
);
|
|
3505
3498
|
attributes[name22] = {
|
|
3506
3499
|
value: shared ? attributes[shared.name].value : value,
|
|
3507
3500
|
size,
|
|
3508
|
-
...
|
|
3501
|
+
...metadata3
|
|
3509
3502
|
};
|
|
3510
3503
|
if (!shared) columns.push({ name: name22, data: attributeData.data });
|
|
3511
3504
|
}
|
|
@@ -3543,23 +3536,23 @@ function getMeshBoundingBoxFromSchema(schema) {
|
|
|
3543
3536
|
}
|
|
3544
3537
|
return null;
|
|
3545
3538
|
}
|
|
3546
|
-
function getMeshAttributeMetadata(
|
|
3539
|
+
function getMeshAttributeMetadata(metadata3 = {}) {
|
|
3547
3540
|
const result = {};
|
|
3548
|
-
if (
|
|
3549
|
-
result.byteOffset = Number(
|
|
3541
|
+
if (metadata3.byteOffset !== void 0) {
|
|
3542
|
+
result.byteOffset = Number(metadata3.byteOffset);
|
|
3550
3543
|
}
|
|
3551
|
-
if (
|
|
3552
|
-
result.byteStride = Number(
|
|
3544
|
+
if (metadata3.byteStride !== void 0) {
|
|
3545
|
+
result.byteStride = Number(metadata3.byteStride);
|
|
3553
3546
|
}
|
|
3554
|
-
if (
|
|
3555
|
-
result.normalized =
|
|
3547
|
+
if (metadata3.normalized !== void 0) {
|
|
3548
|
+
result.normalized = metadata3.normalized === "true";
|
|
3556
3549
|
}
|
|
3557
|
-
if (
|
|
3550
|
+
if (metadata3.componentType === "float16") {
|
|
3558
3551
|
result.componentType = "float16";
|
|
3559
3552
|
}
|
|
3560
|
-
if (
|
|
3553
|
+
if (metadata3["loaders.gl.transform"]) {
|
|
3561
3554
|
try {
|
|
3562
|
-
const transform = JSON.parse(
|
|
3555
|
+
const transform = JSON.parse(metadata3["loaders.gl.transform"]);
|
|
3563
3556
|
if (isMeshAttributeTransform(transform)) {
|
|
3564
3557
|
result.transform = transform;
|
|
3565
3558
|
}
|
|
@@ -3648,17 +3641,29 @@ var init_convert_table_to_mesh = __esm({
|
|
|
3648
3641
|
});
|
|
3649
3642
|
|
|
3650
3643
|
// ../core/src/schema-utils/lib/mesh/deduce-mesh-schema.ts
|
|
3644
|
+
function deduceMeshSchema(attributes, metadata3 = {}) {
|
|
3645
|
+
const fields = deduceMeshFields(attributes);
|
|
3646
|
+
return { fields, metadata: metadata3 };
|
|
3647
|
+
}
|
|
3651
3648
|
function deduceMeshField(name22, attribute, optionalMetadata) {
|
|
3652
3649
|
const type = attribute.componentType || getDataTypeFromTypedArray(attribute.value);
|
|
3653
|
-
const
|
|
3650
|
+
const metadata3 = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
|
|
3654
3651
|
const dataType = attribute.size === 1 ? type : { type: "fixed-size-list", listSize: attribute.size, children: [{ name: "value", type }] };
|
|
3655
3652
|
return {
|
|
3656
3653
|
name: name22,
|
|
3657
3654
|
type: dataType,
|
|
3658
3655
|
nullable: false,
|
|
3659
|
-
metadata:
|
|
3656
|
+
metadata: metadata3
|
|
3660
3657
|
};
|
|
3661
3658
|
}
|
|
3659
|
+
function deduceMeshFields(attributes) {
|
|
3660
|
+
const fields = [];
|
|
3661
|
+
for (const attributeName in attributes) {
|
|
3662
|
+
const attribute = attributes[attributeName];
|
|
3663
|
+
fields.push(deduceMeshField(attributeName, attribute));
|
|
3664
|
+
}
|
|
3665
|
+
return fields;
|
|
3666
|
+
}
|
|
3662
3667
|
function makeMeshAttributeMetadata(attribute) {
|
|
3663
3668
|
const result = {};
|
|
3664
3669
|
if ("byteOffset" in attribute) {
|
|
@@ -3698,6 +3703,1418 @@ var init_schema_utils = __esm({
|
|
|
3698
3703
|
}
|
|
3699
3704
|
});
|
|
3700
3705
|
|
|
3706
|
+
// ../scene/src/usd/libs/usdc-parser.js
|
|
3707
|
+
function checkedLength(length, bytesPerElement = 8) {
|
|
3708
|
+
const byteLength = length * bytesPerElement;
|
|
3709
|
+
if (!Number.isSafeInteger(length) || length < 0 || !Number.isSafeInteger(byteLength) || byteLength > 256 * 1024 * 1024 - allocationBytes)
|
|
3710
|
+
throw new Error("USDC: decoded allocation limit exceeded");
|
|
3711
|
+
allocationBytes += byteLength;
|
|
3712
|
+
return length;
|
|
3713
|
+
}
|
|
3714
|
+
function checkedCount(count) {
|
|
3715
|
+
if (!Number.isSafeInteger(count) || count < 0 || count > 4e6)
|
|
3716
|
+
throw new Error("USDC: decoded allocation limit exceeded");
|
|
3717
|
+
return checkedLength(count);
|
|
3718
|
+
}
|
|
3719
|
+
function lz4DecompressBlock(input, inputOffset, inputEnd, output, outputOffset, outputEnd) {
|
|
3720
|
+
while (inputOffset < inputEnd) {
|
|
3721
|
+
const token = input[inputOffset++];
|
|
3722
|
+
if (inputOffset > inputEnd) throw new Error("USDC: truncated LZ4 token");
|
|
3723
|
+
let literalLength = token >> 4;
|
|
3724
|
+
if (literalLength === 15) {
|
|
3725
|
+
let b;
|
|
3726
|
+
do {
|
|
3727
|
+
if (inputOffset >= inputEnd) throw new Error("USDC: truncated LZ4 length");
|
|
3728
|
+
b = input[inputOffset++];
|
|
3729
|
+
literalLength += b;
|
|
3730
|
+
} while (b === 255);
|
|
3731
|
+
}
|
|
3732
|
+
if (literalLength > 0) {
|
|
3733
|
+
if (inputOffset + literalLength > inputEnd) {
|
|
3734
|
+
throw new Error("USDC: truncated LZ4 literal");
|
|
3735
|
+
}
|
|
3736
|
+
for (let i = 0; i < literalLength; i++) {
|
|
3737
|
+
if (outputOffset >= outputEnd) throw new Error("USDC: LZ4 output overflow");
|
|
3738
|
+
output[outputOffset++] = input[inputOffset++];
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
if (inputOffset >= inputEnd) break;
|
|
3742
|
+
if (inputOffset + 2 > inputEnd) throw new Error("USDC: truncated LZ4 offset");
|
|
3743
|
+
const matchOffset = input[inputOffset++] | input[inputOffset++] << 8;
|
|
3744
|
+
if (matchOffset === 0) {
|
|
3745
|
+
throw new Error("USDC: invalid LZ4 match offset");
|
|
3746
|
+
}
|
|
3747
|
+
let matchLength = (token & 15) + 4;
|
|
3748
|
+
if (matchLength === 19) {
|
|
3749
|
+
let b;
|
|
3750
|
+
do {
|
|
3751
|
+
if (inputOffset >= inputEnd) throw new Error("USDC: truncated LZ4 length");
|
|
3752
|
+
b = input[inputOffset++];
|
|
3753
|
+
matchLength += b;
|
|
3754
|
+
} while (b === 255);
|
|
3755
|
+
}
|
|
3756
|
+
const matchPos = outputOffset - matchOffset;
|
|
3757
|
+
if (matchPos < 0) {
|
|
3758
|
+
throw new Error("USDC: invalid LZ4 match position");
|
|
3759
|
+
}
|
|
3760
|
+
for (let i = 0; i < matchLength; i++) {
|
|
3761
|
+
if (outputOffset >= outputEnd) throw new Error("USDC: LZ4 output overflow");
|
|
3762
|
+
output[outputOffset++] = output[matchPos + i];
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
return outputOffset;
|
|
3766
|
+
}
|
|
3767
|
+
function decompressLZ4(input, uncompressedSize, allowShortOutput = false) {
|
|
3768
|
+
const output = new Uint8Array(checkedLength(uncompressedSize, 1));
|
|
3769
|
+
if (!input.length) throw new Error("USDC: missing LZ4 chunk header");
|
|
3770
|
+
const numChunks = input[0];
|
|
3771
|
+
if (numChunks === 0) {
|
|
3772
|
+
const written = lz4DecompressBlock(input, 1, input.length, output, 0, uncompressedSize);
|
|
3773
|
+
if (!allowShortOutput && written !== uncompressedSize)
|
|
3774
|
+
throw new Error("USDC: incomplete LZ4 output");
|
|
3775
|
+
return output.subarray(0, written);
|
|
3776
|
+
} else {
|
|
3777
|
+
const CHUNK_SIZE = 65536;
|
|
3778
|
+
if (1 + numChunks * 4 > input.length) throw new Error("USDC: truncated LZ4 chunk sizes");
|
|
3779
|
+
let headerOffset = 1;
|
|
3780
|
+
const compressedSizes = [];
|
|
3781
|
+
for (let i = 0; i < numChunks; i++) {
|
|
3782
|
+
const size = (input[headerOffset] | input[headerOffset + 1] << 8 | input[headerOffset + 2] << 16 | input[headerOffset + 3] << 24) >>> 0;
|
|
3783
|
+
compressedSizes.push(size);
|
|
3784
|
+
headerOffset += 4;
|
|
3785
|
+
}
|
|
3786
|
+
let inputOffset = headerOffset;
|
|
3787
|
+
let outputOffset = 0;
|
|
3788
|
+
for (let i = 0; i < numChunks; i++) {
|
|
3789
|
+
const chunkCompressedSize = compressedSizes[i];
|
|
3790
|
+
const chunkOutputSize = Math.min(CHUNK_SIZE, uncompressedSize - outputOffset);
|
|
3791
|
+
if (chunkCompressedSize > input.length - inputOffset)
|
|
3792
|
+
throw new Error("USDC: truncated LZ4 chunk");
|
|
3793
|
+
const written = lz4DecompressBlock(
|
|
3794
|
+
input,
|
|
3795
|
+
inputOffset,
|
|
3796
|
+
inputOffset + chunkCompressedSize,
|
|
3797
|
+
output,
|
|
3798
|
+
outputOffset,
|
|
3799
|
+
outputOffset + chunkOutputSize
|
|
3800
|
+
);
|
|
3801
|
+
inputOffset += chunkCompressedSize;
|
|
3802
|
+
if (i < numChunks - 1 && written !== outputOffset + chunkOutputSize)
|
|
3803
|
+
throw new Error("USDC: incomplete LZ4 chunk");
|
|
3804
|
+
outputOffset = written;
|
|
3805
|
+
}
|
|
3806
|
+
if (inputOffset !== input.length || !allowShortOutput && outputOffset !== uncompressedSize)
|
|
3807
|
+
throw new Error("USDC: incomplete LZ4 output");
|
|
3808
|
+
return output.subarray(0, outputOffset);
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
function decompressIntegers32(compressedData, numInts) {
|
|
3812
|
+
const encodedSize = numInts * 4 + (numInts * 2 + 7 >> 3) + 4;
|
|
3813
|
+
const encoded = decompressLZ4(new Uint8Array(compressedData), encodedSize, true);
|
|
3814
|
+
return decodeIntegers32(encoded, numInts);
|
|
3815
|
+
}
|
|
3816
|
+
function decodeIntegers32(data, numInts) {
|
|
3817
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
3818
|
+
let offset = 0;
|
|
3819
|
+
const commonValue = view.getInt32(offset, true);
|
|
3820
|
+
offset += 4;
|
|
3821
|
+
const numCodesBytes = numInts * 2 + 7 >> 3;
|
|
3822
|
+
if (data.length < offset + numCodesBytes) throw new Error("USDC: truncated integer codes");
|
|
3823
|
+
const codesStart = offset;
|
|
3824
|
+
const vintsStart = offset + numCodesBytes;
|
|
3825
|
+
const result = new Int32Array(checkedLength(numInts));
|
|
3826
|
+
let prevVal = 0;
|
|
3827
|
+
let codesOffset = codesStart;
|
|
3828
|
+
let vintsOffset = vintsStart;
|
|
3829
|
+
for (let i = 0; i < numInts; ) {
|
|
3830
|
+
const codeByte = data[codesOffset++];
|
|
3831
|
+
for (let j = 0; j < 4 && i < numInts; j++, i++) {
|
|
3832
|
+
const code = codeByte >> j * 2 & 3;
|
|
3833
|
+
let delta = 0;
|
|
3834
|
+
switch (code) {
|
|
3835
|
+
case 0:
|
|
3836
|
+
delta = commonValue;
|
|
3837
|
+
break;
|
|
3838
|
+
case 1:
|
|
3839
|
+
delta = view.getInt8(vintsOffset);
|
|
3840
|
+
vintsOffset += 1;
|
|
3841
|
+
break;
|
|
3842
|
+
case 2:
|
|
3843
|
+
delta = view.getInt16(vintsOffset, true);
|
|
3844
|
+
vintsOffset += 2;
|
|
3845
|
+
break;
|
|
3846
|
+
case 3:
|
|
3847
|
+
delta = view.getInt32(vintsOffset, true);
|
|
3848
|
+
vintsOffset += 4;
|
|
3849
|
+
break;
|
|
3850
|
+
}
|
|
3851
|
+
prevVal += delta;
|
|
3852
|
+
result[i] = prevVal;
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
return result;
|
|
3856
|
+
}
|
|
3857
|
+
var allocationBytes, textDecoder, HALF_EXPONENT_TABLE, HALF_DENORM_SCALE, TypeEnum, DICTIONARY_ARRAY_TYPES, FIELD_SET_TERMINATOR, FLOAT_COMPRESSION_INT, FLOAT_COMPRESSION_LUT, BinaryReader, ValueRep, USDCParser;
|
|
3858
|
+
var init_usdc_parser = __esm({
|
|
3859
|
+
"../scene/src/usd/libs/usdc-parser.js"() {
|
|
3860
|
+
"use strict";
|
|
3861
|
+
allocationBytes = 0;
|
|
3862
|
+
textDecoder = new TextDecoder();
|
|
3863
|
+
HALF_EXPONENT_TABLE = new Float32Array(32);
|
|
3864
|
+
for (let i = 0; i < 32; i++) {
|
|
3865
|
+
HALF_EXPONENT_TABLE[i] = Math.pow(2, i - 15);
|
|
3866
|
+
}
|
|
3867
|
+
HALF_DENORM_SCALE = Math.pow(2, -14);
|
|
3868
|
+
TypeEnum = {
|
|
3869
|
+
Invalid: 0,
|
|
3870
|
+
Bool: 1,
|
|
3871
|
+
UChar: 2,
|
|
3872
|
+
Int: 3,
|
|
3873
|
+
UInt: 4,
|
|
3874
|
+
Int64: 5,
|
|
3875
|
+
UInt64: 6,
|
|
3876
|
+
Half: 7,
|
|
3877
|
+
Float: 8,
|
|
3878
|
+
Double: 9,
|
|
3879
|
+
String: 10,
|
|
3880
|
+
Token: 11,
|
|
3881
|
+
AssetPath: 12,
|
|
3882
|
+
Matrix2d: 13,
|
|
3883
|
+
Matrix3d: 14,
|
|
3884
|
+
Matrix4d: 15,
|
|
3885
|
+
Quatd: 16,
|
|
3886
|
+
Quatf: 17,
|
|
3887
|
+
Quath: 18,
|
|
3888
|
+
Vec2d: 19,
|
|
3889
|
+
Vec2f: 20,
|
|
3890
|
+
Vec2h: 21,
|
|
3891
|
+
Vec2i: 22,
|
|
3892
|
+
Vec3d: 23,
|
|
3893
|
+
Vec3f: 24,
|
|
3894
|
+
Vec3h: 25,
|
|
3895
|
+
Vec3i: 26,
|
|
3896
|
+
Vec4d: 27,
|
|
3897
|
+
Vec4f: 28,
|
|
3898
|
+
Vec4h: 29,
|
|
3899
|
+
Vec4i: 30,
|
|
3900
|
+
Dictionary: 31,
|
|
3901
|
+
TokenListOp: 32,
|
|
3902
|
+
StringListOp: 33,
|
|
3903
|
+
PathListOp: 34,
|
|
3904
|
+
ReferenceListOp: 35,
|
|
3905
|
+
IntListOp: 36,
|
|
3906
|
+
Int64ListOp: 37,
|
|
3907
|
+
UIntListOp: 38,
|
|
3908
|
+
UInt64ListOp: 39,
|
|
3909
|
+
PathVector: 40,
|
|
3910
|
+
TokenVector: 41,
|
|
3911
|
+
Specifier: 42,
|
|
3912
|
+
Permission: 43,
|
|
3913
|
+
Variability: 44,
|
|
3914
|
+
VariantSelectionMap: 45,
|
|
3915
|
+
TimeSamples: 46,
|
|
3916
|
+
Payload: 47,
|
|
3917
|
+
DoubleVector: 48,
|
|
3918
|
+
LayerOffsetVector: 49,
|
|
3919
|
+
StringVector: 50,
|
|
3920
|
+
ValueBlock: 51,
|
|
3921
|
+
Value: 52,
|
|
3922
|
+
UnregisteredValue: 53,
|
|
3923
|
+
UnregisteredValueListOp: 54,
|
|
3924
|
+
PayloadListOp: 55,
|
|
3925
|
+
TimeCode: 56,
|
|
3926
|
+
PathExpression: 57,
|
|
3927
|
+
Relocates: 58,
|
|
3928
|
+
Spline: 59,
|
|
3929
|
+
AnimationBlock: 60
|
|
3930
|
+
};
|
|
3931
|
+
DICTIONARY_ARRAY_TYPES = /* @__PURE__ */ new Set([
|
|
3932
|
+
TypeEnum.Int,
|
|
3933
|
+
TypeEnum.UInt,
|
|
3934
|
+
TypeEnum.Float,
|
|
3935
|
+
TypeEnum.Double,
|
|
3936
|
+
TypeEnum.Half,
|
|
3937
|
+
TypeEnum.String,
|
|
3938
|
+
TypeEnum.Token
|
|
3939
|
+
]);
|
|
3940
|
+
FIELD_SET_TERMINATOR = 4294967295;
|
|
3941
|
+
FLOAT_COMPRESSION_INT = 105;
|
|
3942
|
+
FLOAT_COMPRESSION_LUT = 116;
|
|
3943
|
+
BinaryReader = class {
|
|
3944
|
+
constructor(buffer) {
|
|
3945
|
+
this.buffer = buffer;
|
|
3946
|
+
this.view = new DataView(buffer);
|
|
3947
|
+
this.offset = 0;
|
|
3948
|
+
}
|
|
3949
|
+
seek(offset) {
|
|
3950
|
+
if (!Number.isSafeInteger(offset) || offset < 0 || offset > this.buffer.byteLength)
|
|
3951
|
+
throw new Error("USDC: invalid seek");
|
|
3952
|
+
this.offset = offset;
|
|
3953
|
+
}
|
|
3954
|
+
tell() {
|
|
3955
|
+
return this.offset;
|
|
3956
|
+
}
|
|
3957
|
+
readUint8() {
|
|
3958
|
+
const value = this.view.getUint8(this.offset);
|
|
3959
|
+
this.offset += 1;
|
|
3960
|
+
return value;
|
|
3961
|
+
}
|
|
3962
|
+
readInt8() {
|
|
3963
|
+
const value = this.view.getInt8(this.offset);
|
|
3964
|
+
this.offset += 1;
|
|
3965
|
+
return value;
|
|
3966
|
+
}
|
|
3967
|
+
readUint16() {
|
|
3968
|
+
const value = this.view.getUint16(this.offset, true);
|
|
3969
|
+
this.offset += 2;
|
|
3970
|
+
return value;
|
|
3971
|
+
}
|
|
3972
|
+
readInt16() {
|
|
3973
|
+
const value = this.view.getInt16(this.offset, true);
|
|
3974
|
+
this.offset += 2;
|
|
3975
|
+
return value;
|
|
3976
|
+
}
|
|
3977
|
+
readUint32() {
|
|
3978
|
+
const value = this.view.getUint32(this.offset, true);
|
|
3979
|
+
this.offset += 4;
|
|
3980
|
+
return value;
|
|
3981
|
+
}
|
|
3982
|
+
readInt32() {
|
|
3983
|
+
const value = this.view.getInt32(this.offset, true);
|
|
3984
|
+
this.offset += 4;
|
|
3985
|
+
return value;
|
|
3986
|
+
}
|
|
3987
|
+
readUint64() {
|
|
3988
|
+
const lo = this.view.getUint32(this.offset, true);
|
|
3989
|
+
const hi = this.view.getUint32(this.offset + 4, true);
|
|
3990
|
+
this.offset += 8;
|
|
3991
|
+
const result = hi * 4294967296 + lo;
|
|
3992
|
+
if (!Number.isSafeInteger(result)) throw new Error("USDC: integer exceeds safe precision");
|
|
3993
|
+
return result;
|
|
3994
|
+
}
|
|
3995
|
+
readInt64() {
|
|
3996
|
+
const lo = this.view.getUint32(this.offset, true);
|
|
3997
|
+
const hi = this.view.getInt32(this.offset + 4, true);
|
|
3998
|
+
this.offset += 8;
|
|
3999
|
+
const result = hi * 4294967296 + lo;
|
|
4000
|
+
if (!Number.isSafeInteger(result)) throw new Error("USDC: integer exceeds safe precision");
|
|
4001
|
+
return result;
|
|
4002
|
+
}
|
|
4003
|
+
readFloat32() {
|
|
4004
|
+
const value = this.view.getFloat32(this.offset, true);
|
|
4005
|
+
this.offset += 4;
|
|
4006
|
+
return value;
|
|
4007
|
+
}
|
|
4008
|
+
readFloat64() {
|
|
4009
|
+
const value = this.view.getFloat64(this.offset, true);
|
|
4010
|
+
this.offset += 8;
|
|
4011
|
+
return value;
|
|
4012
|
+
}
|
|
4013
|
+
readBytes(length) {
|
|
4014
|
+
const bytes = new Uint8Array(this.buffer, this.offset, length);
|
|
4015
|
+
this.offset += length;
|
|
4016
|
+
return bytes;
|
|
4017
|
+
}
|
|
4018
|
+
readString(length) {
|
|
4019
|
+
const bytes = this.readBytes(length);
|
|
4020
|
+
let end = 0;
|
|
4021
|
+
while (end < length && bytes[end] !== 0) end++;
|
|
4022
|
+
return textDecoder.decode(bytes.subarray(0, end));
|
|
4023
|
+
}
|
|
4024
|
+
};
|
|
4025
|
+
ValueRep = class {
|
|
4026
|
+
constructor(lo, hi) {
|
|
4027
|
+
this.lo = lo;
|
|
4028
|
+
this.hi = hi;
|
|
4029
|
+
}
|
|
4030
|
+
get isArray() {
|
|
4031
|
+
return (this.hi & 2147483648) !== 0;
|
|
4032
|
+
}
|
|
4033
|
+
get isInlined() {
|
|
4034
|
+
return (this.hi & 1073741824) !== 0;
|
|
4035
|
+
}
|
|
4036
|
+
get isCompressed() {
|
|
4037
|
+
return (this.hi & 536870912) !== 0;
|
|
4038
|
+
}
|
|
4039
|
+
get typeEnum() {
|
|
4040
|
+
return this.hi >> 16 & 255;
|
|
4041
|
+
}
|
|
4042
|
+
get payload() {
|
|
4043
|
+
return this.lo + (this.hi & 65535) * 4294967296;
|
|
4044
|
+
}
|
|
4045
|
+
getInlinedValue() {
|
|
4046
|
+
return this.lo;
|
|
4047
|
+
}
|
|
4048
|
+
};
|
|
4049
|
+
USDCParser = class {
|
|
4050
|
+
/**
|
|
4051
|
+
* Parse USDC file and return raw spec data without building Three.js scene.
|
|
4052
|
+
* Used by USDComposer for unified scene composition.
|
|
4053
|
+
*/
|
|
4054
|
+
parseData(buffer) {
|
|
4055
|
+
allocationBytes = 0;
|
|
4056
|
+
this._valueReadCount = 0;
|
|
4057
|
+
this._activeDictionaries = /* @__PURE__ */ new Set();
|
|
4058
|
+
this.buffer = buffer instanceof ArrayBuffer ? buffer : buffer.buffer;
|
|
4059
|
+
this.reader = new BinaryReader(this.buffer);
|
|
4060
|
+
this.version = { major: 0, minor: 0, patch: 0 };
|
|
4061
|
+
this._conversionBuffer = new ArrayBuffer(4);
|
|
4062
|
+
this._conversionView = new DataView(this._conversionBuffer);
|
|
4063
|
+
this._readBootstrap();
|
|
4064
|
+
this._readTOC();
|
|
4065
|
+
this._readTokens();
|
|
4066
|
+
this._readStrings();
|
|
4067
|
+
this._readFields();
|
|
4068
|
+
this._readFieldSets();
|
|
4069
|
+
this._readPaths();
|
|
4070
|
+
this._readSpecs();
|
|
4071
|
+
this.specsByPath = /* @__PURE__ */ Object.create(null);
|
|
4072
|
+
for (const spec of this.specs) {
|
|
4073
|
+
const path = this.paths[spec.pathIndex];
|
|
4074
|
+
if (!path) continue;
|
|
4075
|
+
const fields = this._getFieldsForSpec(spec);
|
|
4076
|
+
this.specsByPath[path] = { specType: spec.specType, fields };
|
|
4077
|
+
}
|
|
4078
|
+
return { specsByPath: this.specsByPath };
|
|
4079
|
+
}
|
|
4080
|
+
_readBootstrap() {
|
|
4081
|
+
const reader = this.reader;
|
|
4082
|
+
reader.seek(0);
|
|
4083
|
+
const magic = reader.readString(8);
|
|
4084
|
+
if (magic !== "PXR-USDC") {
|
|
4085
|
+
throw new Error("THREE.USDCParser: Not a valid USDC file.");
|
|
4086
|
+
}
|
|
4087
|
+
this.version.major = reader.readUint8();
|
|
4088
|
+
this.version.minor = reader.readUint8();
|
|
4089
|
+
this.version.patch = reader.readUint8();
|
|
4090
|
+
reader.readBytes(5);
|
|
4091
|
+
this.tocOffset = reader.readUint64();
|
|
4092
|
+
}
|
|
4093
|
+
_readTOC() {
|
|
4094
|
+
const reader = this.reader;
|
|
4095
|
+
reader.seek(this.tocOffset);
|
|
4096
|
+
const numSections = reader.readUint64();
|
|
4097
|
+
if (numSections > 16) throw new Error("USDC: invalid section count");
|
|
4098
|
+
this.sections = /* @__PURE__ */ Object.create(null);
|
|
4099
|
+
for (let i = 0; i < numSections; i++) {
|
|
4100
|
+
const name22 = reader.readString(16);
|
|
4101
|
+
const start = reader.readUint64();
|
|
4102
|
+
const size = reader.readUint64();
|
|
4103
|
+
this.sections[name22] = { start, size };
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
_readTokens() {
|
|
4107
|
+
const section = this.sections["TOKENS"];
|
|
4108
|
+
if (!section) return;
|
|
4109
|
+
const reader = this.reader;
|
|
4110
|
+
reader.seek(section.start);
|
|
4111
|
+
const numTokens = checkedCount(reader.readUint64());
|
|
4112
|
+
this.tokens = [];
|
|
4113
|
+
if (this.version.major === 0 && this.version.minor < 4) {
|
|
4114
|
+
const tokensNumBytes = reader.readUint64();
|
|
4115
|
+
const tokensData = reader.readBytes(tokensNumBytes);
|
|
4116
|
+
let strStart = 0;
|
|
4117
|
+
for (let i = 0; i < numTokens; i++) {
|
|
4118
|
+
let strEnd = strStart;
|
|
4119
|
+
while (strEnd < tokensData.length && tokensData[strEnd] !== 0) strEnd++;
|
|
4120
|
+
if (strEnd >= tokensData.length) throw new Error("USDC: unterminated token data");
|
|
4121
|
+
this.tokens.push(textDecoder.decode(tokensData.subarray(strStart, strEnd)));
|
|
4122
|
+
strStart = strEnd + 1;
|
|
4123
|
+
}
|
|
4124
|
+
} else {
|
|
4125
|
+
const uncompressedSize = reader.readUint64();
|
|
4126
|
+
const compressedSize = reader.readUint64();
|
|
4127
|
+
const compressedData = reader.readBytes(compressedSize);
|
|
4128
|
+
const tokensData = decompressLZ4(compressedData, uncompressedSize);
|
|
4129
|
+
checkedLength(tokensData.length, 2);
|
|
4130
|
+
let strStart = 0;
|
|
4131
|
+
for (let i = 0; i < numTokens; i++) {
|
|
4132
|
+
let strEnd = strStart;
|
|
4133
|
+
while (strEnd < tokensData.length && tokensData[strEnd] !== 0) strEnd++;
|
|
4134
|
+
if (strEnd >= tokensData.length) throw new Error("USDC: unterminated token data");
|
|
4135
|
+
this.tokens.push(textDecoder.decode(tokensData.subarray(strStart, strEnd)));
|
|
4136
|
+
strStart = strEnd + 1;
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
_readStrings() {
|
|
4141
|
+
const section = this.sections["STRINGS"];
|
|
4142
|
+
if (!section) {
|
|
4143
|
+
this.strings = [];
|
|
4144
|
+
return;
|
|
4145
|
+
}
|
|
4146
|
+
const reader = this.reader;
|
|
4147
|
+
reader.seek(section.start);
|
|
4148
|
+
const numStrings = checkedCount(reader.readUint64());
|
|
4149
|
+
this.strings = [];
|
|
4150
|
+
for (let i = 0; i < numStrings; i++) {
|
|
4151
|
+
this.strings.push(reader.readUint32());
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
_readFields() {
|
|
4155
|
+
const section = this.sections["FIELDS"];
|
|
4156
|
+
if (!section) return;
|
|
4157
|
+
const reader = this.reader;
|
|
4158
|
+
reader.seek(section.start);
|
|
4159
|
+
this.fields = [];
|
|
4160
|
+
if (this.version.major === 0 && this.version.minor < 4) {
|
|
4161
|
+
const numFields = Math.floor(section.size / 12);
|
|
4162
|
+
for (let i = 0; i < numFields; i++) {
|
|
4163
|
+
const tokenIndex = reader.readUint32();
|
|
4164
|
+
const repLo = reader.readUint32();
|
|
4165
|
+
const repHi = reader.readUint32();
|
|
4166
|
+
this.fields.push({
|
|
4167
|
+
tokenIndex,
|
|
4168
|
+
valueRep: new ValueRep(repLo, repHi)
|
|
4169
|
+
});
|
|
4170
|
+
}
|
|
4171
|
+
} else {
|
|
4172
|
+
const numFields = checkedCount(reader.readUint64());
|
|
4173
|
+
const tokenIndicesCompressedSize = reader.readUint64();
|
|
4174
|
+
const tokenIndicesCompressed = reader.readBytes(tokenIndicesCompressedSize);
|
|
4175
|
+
const tokenIndices = decompressIntegers32(
|
|
4176
|
+
tokenIndicesCompressed.buffer.slice(
|
|
4177
|
+
tokenIndicesCompressed.byteOffset,
|
|
4178
|
+
tokenIndicesCompressed.byteOffset + tokenIndicesCompressedSize
|
|
4179
|
+
),
|
|
4180
|
+
numFields
|
|
4181
|
+
);
|
|
4182
|
+
const repsCompressedSize = reader.readUint64();
|
|
4183
|
+
const repsCompressed = reader.readBytes(repsCompressedSize);
|
|
4184
|
+
const repsData = decompressLZ4(repsCompressed, numFields * 8);
|
|
4185
|
+
const repsView = new DataView(repsData.buffer, repsData.byteOffset, repsData.byteLength);
|
|
4186
|
+
for (let i = 0; i < numFields; i++) {
|
|
4187
|
+
const repLo = repsView.getUint32(i * 8, true);
|
|
4188
|
+
const repHi = repsView.getUint32(i * 8 + 4, true);
|
|
4189
|
+
this.fields.push({
|
|
4190
|
+
tokenIndex: tokenIndices[i],
|
|
4191
|
+
valueRep: new ValueRep(repLo, repHi)
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
_readFieldSets() {
|
|
4197
|
+
const section = this.sections["FIELDSETS"];
|
|
4198
|
+
if (!section) return;
|
|
4199
|
+
const reader = this.reader;
|
|
4200
|
+
reader.seek(section.start);
|
|
4201
|
+
this.fieldSets = [];
|
|
4202
|
+
if (this.version.major === 0 && this.version.minor < 4) {
|
|
4203
|
+
const numFieldSets = Math.floor(section.size / 4);
|
|
4204
|
+
for (let i = 0; i < numFieldSets; i++) {
|
|
4205
|
+
this.fieldSets.push(reader.readUint32());
|
|
4206
|
+
}
|
|
4207
|
+
} else {
|
|
4208
|
+
const numFieldSets = checkedCount(reader.readUint64());
|
|
4209
|
+
const compressedSize = reader.readUint64();
|
|
4210
|
+
const compressed = reader.readBytes(compressedSize);
|
|
4211
|
+
const indices = decompressIntegers32(
|
|
4212
|
+
compressed.buffer.slice(compressed.byteOffset, compressed.byteOffset + compressedSize),
|
|
4213
|
+
numFieldSets
|
|
4214
|
+
);
|
|
4215
|
+
for (let i = 0; i < numFieldSets; i++) {
|
|
4216
|
+
this.fieldSets.push(indices[i]);
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
}
|
|
4220
|
+
_readPaths() {
|
|
4221
|
+
const section = this.sections["PATHS"];
|
|
4222
|
+
if (!section) return;
|
|
4223
|
+
const reader = this.reader;
|
|
4224
|
+
reader.seek(section.start);
|
|
4225
|
+
const numPaths = checkedCount(reader.readUint64());
|
|
4226
|
+
this.paths = new Array(checkedLength(numPaths)).fill("");
|
|
4227
|
+
if (this.version.major === 0 && this.version.minor < 4) {
|
|
4228
|
+
this._readPathsRecursive("");
|
|
4229
|
+
} else {
|
|
4230
|
+
reader.readUint64();
|
|
4231
|
+
const compressedSize1 = reader.readUint64();
|
|
4232
|
+
const pathIndicesCompressed = reader.readBytes(compressedSize1);
|
|
4233
|
+
const pathIndices = decompressIntegers32(
|
|
4234
|
+
pathIndicesCompressed.buffer.slice(
|
|
4235
|
+
pathIndicesCompressed.byteOffset,
|
|
4236
|
+
pathIndicesCompressed.byteOffset + compressedSize1
|
|
4237
|
+
),
|
|
4238
|
+
numPaths
|
|
4239
|
+
);
|
|
4240
|
+
const compressedSize2 = reader.readUint64();
|
|
4241
|
+
const elementTokenIndicesCompressed = reader.readBytes(compressedSize2);
|
|
4242
|
+
const elementTokenIndices = decompressIntegers32(
|
|
4243
|
+
elementTokenIndicesCompressed.buffer.slice(
|
|
4244
|
+
elementTokenIndicesCompressed.byteOffset,
|
|
4245
|
+
elementTokenIndicesCompressed.byteOffset + compressedSize2
|
|
4246
|
+
),
|
|
4247
|
+
numPaths
|
|
4248
|
+
);
|
|
4249
|
+
const compressedSize3 = reader.readUint64();
|
|
4250
|
+
const jumpsCompressed = reader.readBytes(compressedSize3);
|
|
4251
|
+
const jumps = decompressIntegers32(
|
|
4252
|
+
jumpsCompressed.buffer.slice(
|
|
4253
|
+
jumpsCompressed.byteOffset,
|
|
4254
|
+
jumpsCompressed.byteOffset + compressedSize3
|
|
4255
|
+
),
|
|
4256
|
+
numPaths
|
|
4257
|
+
);
|
|
4258
|
+
this._buildPathsFromCompressed(pathIndices, elementTokenIndices, jumps);
|
|
4259
|
+
}
|
|
4260
|
+
}
|
|
4261
|
+
_readPathsRecursive(parentPath, depth = 0) {
|
|
4262
|
+
const reader = this.reader;
|
|
4263
|
+
if (depth > 1e3) return;
|
|
4264
|
+
const index = reader.readUint32();
|
|
4265
|
+
const elementTokenIndex = reader.readUint32();
|
|
4266
|
+
const bits = reader.readUint8();
|
|
4267
|
+
const hasChild = (bits & 1) !== 0;
|
|
4268
|
+
const hasSibling = (bits & 2) !== 0;
|
|
4269
|
+
const isPrimProperty = (bits & 4) !== 0;
|
|
4270
|
+
let path;
|
|
4271
|
+
if (parentPath === "") {
|
|
4272
|
+
path = "/";
|
|
4273
|
+
} else {
|
|
4274
|
+
const elemToken = this.tokens[elementTokenIndex] || "";
|
|
4275
|
+
if (isPrimProperty) {
|
|
4276
|
+
path = parentPath + "." + elemToken;
|
|
4277
|
+
} else {
|
|
4278
|
+
path = parentPath === "/" ? "/" + elemToken : parentPath + "/" + elemToken;
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
4281
|
+
checkedLength(path.length, 2);
|
|
4282
|
+
this.paths[index] = path;
|
|
4283
|
+
if (hasChild && hasSibling) {
|
|
4284
|
+
const siblingOffset = reader.readUint64();
|
|
4285
|
+
this._readPathsRecursive(path, depth + 1);
|
|
4286
|
+
reader.seek(siblingOffset);
|
|
4287
|
+
this._readPathsRecursive(parentPath, depth + 1);
|
|
4288
|
+
} else if (hasChild) {
|
|
4289
|
+
this._readPathsRecursive(path, depth + 1);
|
|
4290
|
+
} else if (hasSibling) {
|
|
4291
|
+
this._readPathsRecursive(parentPath, depth + 1);
|
|
4292
|
+
}
|
|
4293
|
+
}
|
|
4294
|
+
/** Rebuilds compressed paths with an explicit stack instead of sibling recursion. */
|
|
4295
|
+
_buildPathsFromCompressed(pathIndices, elementTokenIndices, jumps) {
|
|
4296
|
+
let traversalCount = 0;
|
|
4297
|
+
const pendingPaths = [{ startIndex: 0, parentPath: "" }];
|
|
4298
|
+
while (pendingPaths.length) {
|
|
4299
|
+
const pendingPath = pendingPaths.pop();
|
|
4300
|
+
let currentIndex = pendingPath.startIndex;
|
|
4301
|
+
let parentPath = pendingPath.parentPath;
|
|
4302
|
+
while (currentIndex < pathIndices.length) {
|
|
4303
|
+
if (++traversalCount > pathIndices.length * 2)
|
|
4304
|
+
throw new Error("USDC: path traversal limit exceeded");
|
|
4305
|
+
const nodeIndex = currentIndex++;
|
|
4306
|
+
const pathIndex = pathIndices[nodeIndex];
|
|
4307
|
+
const elementTokenIndex = elementTokenIndices[nodeIndex];
|
|
4308
|
+
const jump = jumps[nodeIndex];
|
|
4309
|
+
if (pathIndex < 0 || pathIndex >= this.paths.length || Math.abs(elementTokenIndex) >= this.tokens.length || jump < -2)
|
|
4310
|
+
throw new Error("USDC: invalid compressed path index");
|
|
4311
|
+
let path;
|
|
4312
|
+
if (parentPath === "") {
|
|
4313
|
+
path = "/";
|
|
4314
|
+
parentPath = path;
|
|
4315
|
+
} else {
|
|
4316
|
+
const elementToken = this.tokens[Math.abs(elementTokenIndex)];
|
|
4317
|
+
path = elementTokenIndex < 0 ? parentPath + "." + elementToken : parentPath === "/" ? "/" + elementToken : parentPath + "/" + elementToken;
|
|
4318
|
+
}
|
|
4319
|
+
checkedLength(path.length, 2);
|
|
4320
|
+
this.paths[pathIndex] = path;
|
|
4321
|
+
const hasChild = jump > 0 || jump === -1;
|
|
4322
|
+
const hasSibling = jump >= 0;
|
|
4323
|
+
if ((hasChild || hasSibling) && currentIndex >= pathIndices.length)
|
|
4324
|
+
throw new Error("USDC: missing compressed path entry");
|
|
4325
|
+
if (hasChild && hasSibling) {
|
|
4326
|
+
const siblingIndex = nodeIndex + jump;
|
|
4327
|
+
if (siblingIndex <= currentIndex || siblingIndex >= pathIndices.length)
|
|
4328
|
+
throw new Error("USDC: invalid compressed path jump");
|
|
4329
|
+
pendingPaths.push({ startIndex: siblingIndex, parentPath });
|
|
4330
|
+
}
|
|
4331
|
+
if (hasChild) parentPath = path;
|
|
4332
|
+
else if (!hasSibling) break;
|
|
4333
|
+
}
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
_readSpecs() {
|
|
4337
|
+
const section = this.sections["SPECS"];
|
|
4338
|
+
if (!section) return;
|
|
4339
|
+
const reader = this.reader;
|
|
4340
|
+
reader.seek(section.start);
|
|
4341
|
+
this.specs = [];
|
|
4342
|
+
if (this.version.major === 0 && this.version.minor < 4) {
|
|
4343
|
+
const specSize = this.version.minor === 0 && this.version.patch === 1 ? 16 : 12;
|
|
4344
|
+
const numSpecs = Math.floor(section.size / specSize);
|
|
4345
|
+
for (let i = 0; i < numSpecs; i++) {
|
|
4346
|
+
const pathIndex = reader.readUint32();
|
|
4347
|
+
const fieldSetIndex = reader.readUint32();
|
|
4348
|
+
const specType = reader.readUint32();
|
|
4349
|
+
if (specSize === 16) reader.readUint32();
|
|
4350
|
+
this.specs.push({ pathIndex, fieldSetIndex, specType });
|
|
4351
|
+
}
|
|
4352
|
+
} else {
|
|
4353
|
+
const numSpecs = checkedCount(reader.readUint64());
|
|
4354
|
+
const compressedSize1 = reader.readUint64();
|
|
4355
|
+
const pathIndicesCompressed = reader.readBytes(compressedSize1);
|
|
4356
|
+
const pathIndices = decompressIntegers32(
|
|
4357
|
+
pathIndicesCompressed.buffer.slice(
|
|
4358
|
+
pathIndicesCompressed.byteOffset,
|
|
4359
|
+
pathIndicesCompressed.byteOffset + compressedSize1
|
|
4360
|
+
),
|
|
4361
|
+
numSpecs
|
|
4362
|
+
);
|
|
4363
|
+
const compressedSize2 = reader.readUint64();
|
|
4364
|
+
const fieldSetIndicesCompressed = reader.readBytes(compressedSize2);
|
|
4365
|
+
const fieldSetIndices = decompressIntegers32(
|
|
4366
|
+
fieldSetIndicesCompressed.buffer.slice(
|
|
4367
|
+
fieldSetIndicesCompressed.byteOffset,
|
|
4368
|
+
fieldSetIndicesCompressed.byteOffset + compressedSize2
|
|
4369
|
+
),
|
|
4370
|
+
numSpecs
|
|
4371
|
+
);
|
|
4372
|
+
const compressedSize3 = reader.readUint64();
|
|
4373
|
+
const specTypesCompressed = reader.readBytes(compressedSize3);
|
|
4374
|
+
const specTypes = decompressIntegers32(
|
|
4375
|
+
specTypesCompressed.buffer.slice(
|
|
4376
|
+
specTypesCompressed.byteOffset,
|
|
4377
|
+
specTypesCompressed.byteOffset + compressedSize3
|
|
4378
|
+
),
|
|
4379
|
+
numSpecs
|
|
4380
|
+
);
|
|
4381
|
+
for (let i = 0; i < numSpecs; i++) {
|
|
4382
|
+
this.specs.push({
|
|
4383
|
+
pathIndex: pathIndices[i],
|
|
4384
|
+
fieldSetIndex: fieldSetIndices[i],
|
|
4385
|
+
specType: specTypes[i]
|
|
4386
|
+
});
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
// ========================================================================
|
|
4391
|
+
// Value Reading
|
|
4392
|
+
// ========================================================================
|
|
4393
|
+
_readValue(valueRep) {
|
|
4394
|
+
this._valueReadCount = (this._valueReadCount || 0) + 1;
|
|
4395
|
+
if (this._valueReadCount > 1e6) throw new Error("USDC: value traversal limit exceeded");
|
|
4396
|
+
const type = valueRep.typeEnum;
|
|
4397
|
+
const isArray = valueRep.isArray;
|
|
4398
|
+
const isInlined = valueRep.isInlined;
|
|
4399
|
+
if (type === TypeEnum.TimeSamples) {
|
|
4400
|
+
return this._readTimeSamples(valueRep);
|
|
4401
|
+
}
|
|
4402
|
+
if (isInlined) {
|
|
4403
|
+
return this._readInlinedValue(valueRep);
|
|
4404
|
+
}
|
|
4405
|
+
const offset = valueRep.payload;
|
|
4406
|
+
if (offset === 0 && isArray) {
|
|
4407
|
+
return [];
|
|
4408
|
+
}
|
|
4409
|
+
if (offset < 0 || offset >= this.buffer.byteLength) {
|
|
4410
|
+
throw new RangeError(
|
|
4411
|
+
"USDCParser: Invalid payload offset " + offset + " for type " + type + "."
|
|
4412
|
+
);
|
|
4413
|
+
}
|
|
4414
|
+
const savedOffset = this.reader.tell();
|
|
4415
|
+
this.reader.seek(offset);
|
|
4416
|
+
let value;
|
|
4417
|
+
if (isArray) {
|
|
4418
|
+
value = this._readArrayValue(valueRep);
|
|
4419
|
+
} else {
|
|
4420
|
+
value = this._readScalarValue(type);
|
|
4421
|
+
}
|
|
4422
|
+
this.reader.seek(savedOffset);
|
|
4423
|
+
return value;
|
|
4424
|
+
}
|
|
4425
|
+
_readInlinedValue(valueRep) {
|
|
4426
|
+
const type = valueRep.typeEnum;
|
|
4427
|
+
const payload = valueRep.getInlinedValue();
|
|
4428
|
+
const view = this._conversionView;
|
|
4429
|
+
switch (type) {
|
|
4430
|
+
case TypeEnum.Dictionary:
|
|
4431
|
+
if (payload !== 0) throw new Error("USDC: invalid inline dictionary");
|
|
4432
|
+
return /* @__PURE__ */ Object.create(null);
|
|
4433
|
+
case TypeEnum.Bool:
|
|
4434
|
+
return payload !== 0;
|
|
4435
|
+
case TypeEnum.UChar:
|
|
4436
|
+
return payload & 255;
|
|
4437
|
+
case TypeEnum.Int:
|
|
4438
|
+
case TypeEnum.Int64:
|
|
4439
|
+
return payload | 0;
|
|
4440
|
+
case TypeEnum.UInt:
|
|
4441
|
+
case TypeEnum.UInt64:
|
|
4442
|
+
return payload >>> 0;
|
|
4443
|
+
case TypeEnum.Half:
|
|
4444
|
+
return this._halfToFloat(payload & 65535);
|
|
4445
|
+
case TypeEnum.Float: {
|
|
4446
|
+
view.setUint32(0, payload, true);
|
|
4447
|
+
return view.getFloat32(0, true);
|
|
4448
|
+
}
|
|
4449
|
+
case TypeEnum.Double: {
|
|
4450
|
+
view.setUint32(0, payload, true);
|
|
4451
|
+
return view.getFloat32(0, true);
|
|
4452
|
+
}
|
|
4453
|
+
case TypeEnum.Token:
|
|
4454
|
+
return this.tokens[payload] || "";
|
|
4455
|
+
case TypeEnum.String:
|
|
4456
|
+
return this.tokens[this.strings[payload]] || "";
|
|
4457
|
+
case TypeEnum.AssetPath:
|
|
4458
|
+
return this.tokens[payload] || "";
|
|
4459
|
+
case TypeEnum.Specifier:
|
|
4460
|
+
return payload;
|
|
4461
|
+
// 0=def, 1=over, 2=class
|
|
4462
|
+
case TypeEnum.Permission:
|
|
4463
|
+
case TypeEnum.Variability:
|
|
4464
|
+
return payload;
|
|
4465
|
+
// Vec2h: Two half-floats fit in 4 bytes, stored directly
|
|
4466
|
+
case TypeEnum.Vec2h: {
|
|
4467
|
+
view.setUint32(0, payload, true);
|
|
4468
|
+
return [
|
|
4469
|
+
this._halfToFloat(view.getUint16(0, true)),
|
|
4470
|
+
this._halfToFloat(view.getUint16(2, true))
|
|
4471
|
+
];
|
|
4472
|
+
}
|
|
4473
|
+
// Inlined vectors that don't fit in 4 bytes are encoded as signed 8-bit integers
|
|
4474
|
+
// Vec2f = 8 bytes (2x float32), Vec3f = 12 bytes, Vec4f = 16 bytes, etc.
|
|
4475
|
+
case TypeEnum.Vec2f:
|
|
4476
|
+
case TypeEnum.Vec2i: {
|
|
4477
|
+
view.setUint32(0, payload, true);
|
|
4478
|
+
return [view.getInt8(0), view.getInt8(1)];
|
|
4479
|
+
}
|
|
4480
|
+
case TypeEnum.Vec3f:
|
|
4481
|
+
case TypeEnum.Vec3i: {
|
|
4482
|
+
view.setUint32(0, payload, true);
|
|
4483
|
+
return [view.getInt8(0), view.getInt8(1), view.getInt8(2)];
|
|
4484
|
+
}
|
|
4485
|
+
case TypeEnum.Vec4f:
|
|
4486
|
+
case TypeEnum.Vec4i: {
|
|
4487
|
+
view.setUint32(0, payload, true);
|
|
4488
|
+
return [view.getInt8(0), view.getInt8(1), view.getInt8(2), view.getInt8(3)];
|
|
4489
|
+
}
|
|
4490
|
+
case TypeEnum.Matrix2d: {
|
|
4491
|
+
view.setUint32(0, payload, true);
|
|
4492
|
+
const d0 = view.getInt8(0), d1 = view.getInt8(1);
|
|
4493
|
+
return [d0, 0, 0, d1];
|
|
4494
|
+
}
|
|
4495
|
+
case TypeEnum.Matrix3d: {
|
|
4496
|
+
view.setUint32(0, payload, true);
|
|
4497
|
+
const d0 = view.getInt8(0), d1 = view.getInt8(1), d2 = view.getInt8(2);
|
|
4498
|
+
return [d0, 0, 0, 0, d1, 0, 0, 0, d2];
|
|
4499
|
+
}
|
|
4500
|
+
case TypeEnum.Matrix4d: {
|
|
4501
|
+
view.setUint32(0, payload, true);
|
|
4502
|
+
const d0 = view.getInt8(0), d1 = view.getInt8(1), d2 = view.getInt8(2), d3 = view.getInt8(3);
|
|
4503
|
+
return [d0, 0, 0, 0, 0, d1, 0, 0, 0, 0, d2, 0, 0, 0, 0, d3];
|
|
4504
|
+
}
|
|
4505
|
+
default:
|
|
4506
|
+
throw new Error("USDC: unsupported inline value type " + type);
|
|
4507
|
+
}
|
|
4508
|
+
}
|
|
4509
|
+
_readTimeSamples(valueRep) {
|
|
4510
|
+
const reader = this.reader;
|
|
4511
|
+
const offset = valueRep.payload;
|
|
4512
|
+
const savedOffset = reader.tell();
|
|
4513
|
+
reader.seek(offset);
|
|
4514
|
+
const timesStart = reader.tell();
|
|
4515
|
+
const timesRelOffset = reader.readInt64();
|
|
4516
|
+
reader.seek(timesStart + timesRelOffset);
|
|
4517
|
+
const timesRepLo = reader.readUint32();
|
|
4518
|
+
const timesRepHi = reader.readUint32();
|
|
4519
|
+
const timesRep = new ValueRep(timesRepLo, timesRepHi);
|
|
4520
|
+
const times = this._readValue(timesRep);
|
|
4521
|
+
const afterTimesRep = timesStart + timesRelOffset + 8;
|
|
4522
|
+
reader.seek(afterTimesRep);
|
|
4523
|
+
const valuesStart = reader.tell();
|
|
4524
|
+
const valuesRelOffset = reader.readInt64();
|
|
4525
|
+
reader.seek(valuesStart + valuesRelOffset);
|
|
4526
|
+
const numValues = checkedCount(reader.readUint64());
|
|
4527
|
+
const valueReps = [];
|
|
4528
|
+
for (let i = 0; i < numValues; i++) {
|
|
4529
|
+
const repLo = reader.readUint32();
|
|
4530
|
+
const repHi = reader.readUint32();
|
|
4531
|
+
valueReps.push(new ValueRep(repLo, repHi));
|
|
4532
|
+
}
|
|
4533
|
+
const values = [];
|
|
4534
|
+
for (let i = 0; i < numValues; i++) {
|
|
4535
|
+
values.push(this._readValue(valueReps[i]));
|
|
4536
|
+
}
|
|
4537
|
+
reader.seek(savedOffset);
|
|
4538
|
+
const timesArray = times instanceof Float64Array ? Array.from(times) : Array.isArray(times) ? times : [times];
|
|
4539
|
+
return { times: timesArray, values };
|
|
4540
|
+
}
|
|
4541
|
+
_readScalarValue(type) {
|
|
4542
|
+
const reader = this.reader;
|
|
4543
|
+
switch (type) {
|
|
4544
|
+
case TypeEnum.Invalid:
|
|
4545
|
+
return null;
|
|
4546
|
+
case TypeEnum.Bool:
|
|
4547
|
+
return reader.readUint8() !== 0;
|
|
4548
|
+
case TypeEnum.UChar:
|
|
4549
|
+
return reader.readUint8();
|
|
4550
|
+
case TypeEnum.Int:
|
|
4551
|
+
return reader.readInt32();
|
|
4552
|
+
case TypeEnum.UInt:
|
|
4553
|
+
return reader.readUint32();
|
|
4554
|
+
case TypeEnum.Int64:
|
|
4555
|
+
return reader.readInt64();
|
|
4556
|
+
case TypeEnum.UInt64:
|
|
4557
|
+
return reader.readUint64();
|
|
4558
|
+
case TypeEnum.Half:
|
|
4559
|
+
return this._readHalf();
|
|
4560
|
+
case TypeEnum.Float:
|
|
4561
|
+
return reader.readFloat32();
|
|
4562
|
+
case TypeEnum.Double:
|
|
4563
|
+
return reader.readFloat64();
|
|
4564
|
+
case TypeEnum.String:
|
|
4565
|
+
case TypeEnum.Token: {
|
|
4566
|
+
const index = reader.readUint32();
|
|
4567
|
+
return this.tokens[index] || "";
|
|
4568
|
+
}
|
|
4569
|
+
case TypeEnum.AssetPath: {
|
|
4570
|
+
const index = reader.readUint32();
|
|
4571
|
+
return this.tokens[index] || "";
|
|
4572
|
+
}
|
|
4573
|
+
case TypeEnum.Vec2f:
|
|
4574
|
+
return [reader.readFloat32(), reader.readFloat32()];
|
|
4575
|
+
case TypeEnum.Vec2d:
|
|
4576
|
+
return [reader.readFloat64(), reader.readFloat64()];
|
|
4577
|
+
case TypeEnum.Vec2i:
|
|
4578
|
+
return [reader.readInt32(), reader.readInt32()];
|
|
4579
|
+
case TypeEnum.Vec3f:
|
|
4580
|
+
return [reader.readFloat32(), reader.readFloat32(), reader.readFloat32()];
|
|
4581
|
+
case TypeEnum.Vec3d:
|
|
4582
|
+
return [reader.readFloat64(), reader.readFloat64(), reader.readFloat64()];
|
|
4583
|
+
case TypeEnum.Vec3i:
|
|
4584
|
+
return [reader.readInt32(), reader.readInt32(), reader.readInt32()];
|
|
4585
|
+
case TypeEnum.Vec4f:
|
|
4586
|
+
return [
|
|
4587
|
+
reader.readFloat32(),
|
|
4588
|
+
reader.readFloat32(),
|
|
4589
|
+
reader.readFloat32(),
|
|
4590
|
+
reader.readFloat32()
|
|
4591
|
+
];
|
|
4592
|
+
case TypeEnum.Vec4d:
|
|
4593
|
+
return [
|
|
4594
|
+
reader.readFloat64(),
|
|
4595
|
+
reader.readFloat64(),
|
|
4596
|
+
reader.readFloat64(),
|
|
4597
|
+
reader.readFloat64()
|
|
4598
|
+
];
|
|
4599
|
+
case TypeEnum.Quatf:
|
|
4600
|
+
return [
|
|
4601
|
+
reader.readFloat32(),
|
|
4602
|
+
reader.readFloat32(),
|
|
4603
|
+
reader.readFloat32(),
|
|
4604
|
+
reader.readFloat32()
|
|
4605
|
+
];
|
|
4606
|
+
case TypeEnum.Quatd:
|
|
4607
|
+
return [
|
|
4608
|
+
reader.readFloat64(),
|
|
4609
|
+
reader.readFloat64(),
|
|
4610
|
+
reader.readFloat64(),
|
|
4611
|
+
reader.readFloat64()
|
|
4612
|
+
];
|
|
4613
|
+
case TypeEnum.Matrix4d: {
|
|
4614
|
+
const m = [];
|
|
4615
|
+
for (let i = 0; i < 16; i++) m.push(reader.readFloat64());
|
|
4616
|
+
return m;
|
|
4617
|
+
}
|
|
4618
|
+
case TypeEnum.TokenVector: {
|
|
4619
|
+
const count = checkedCount(reader.readUint64());
|
|
4620
|
+
const tokens = [];
|
|
4621
|
+
for (let i = 0; i < count; i++) {
|
|
4622
|
+
const index = reader.readUint32();
|
|
4623
|
+
tokens.push(this.tokens[index] || "");
|
|
4624
|
+
}
|
|
4625
|
+
return tokens;
|
|
4626
|
+
}
|
|
4627
|
+
case TypeEnum.PathVector: {
|
|
4628
|
+
const count = checkedCount(reader.readUint64());
|
|
4629
|
+
const paths = [];
|
|
4630
|
+
for (let i = 0; i < count; i++) {
|
|
4631
|
+
const index = reader.readUint32();
|
|
4632
|
+
paths.push(this.paths[index] || "");
|
|
4633
|
+
}
|
|
4634
|
+
return paths;
|
|
4635
|
+
}
|
|
4636
|
+
case TypeEnum.DoubleVector: {
|
|
4637
|
+
const count = checkedCount(reader.readUint64());
|
|
4638
|
+
const arr = new Float64Array(checkedLength(count));
|
|
4639
|
+
for (let i = 0; i < count; i++) arr[i] = reader.readFloat64();
|
|
4640
|
+
return arr;
|
|
4641
|
+
}
|
|
4642
|
+
case TypeEnum.Dictionary:
|
|
4643
|
+
return this._readDictionary();
|
|
4644
|
+
case TypeEnum.TokenListOp:
|
|
4645
|
+
case TypeEnum.StringListOp:
|
|
4646
|
+
case TypeEnum.IntListOp:
|
|
4647
|
+
case TypeEnum.Int64ListOp:
|
|
4648
|
+
case TypeEnum.UIntListOp:
|
|
4649
|
+
case TypeEnum.UInt64ListOp:
|
|
4650
|
+
throw new Error("USDC: value list operations are unsupported");
|
|
4651
|
+
case TypeEnum.PathListOp: {
|
|
4652
|
+
const flags = reader.readUint8();
|
|
4653
|
+
if (flags & 24 || (flags & 102).toString(2).replaceAll("0", "").length > 1)
|
|
4654
|
+
throw new Error("USDC: compound path list operations are unsupported");
|
|
4655
|
+
const hasExplicitItems = (flags & 2) !== 0;
|
|
4656
|
+
const hasAddItems = (flags & 4) !== 0;
|
|
4657
|
+
const hasDeleteItems = (flags & 8) !== 0;
|
|
4658
|
+
const hasReorderItems = (flags & 16) !== 0;
|
|
4659
|
+
const hasPrependItems = (flags & 32) !== 0;
|
|
4660
|
+
const hasAppendItems = (flags & 64) !== 0;
|
|
4661
|
+
const readPathList = () => {
|
|
4662
|
+
const itemCount = checkedCount(reader.readUint64());
|
|
4663
|
+
const paths = [];
|
|
4664
|
+
for (let i = 0; i < itemCount; i++) {
|
|
4665
|
+
const pathIdx = reader.readUint32();
|
|
4666
|
+
paths.push(this.paths[pathIdx]);
|
|
4667
|
+
}
|
|
4668
|
+
return paths;
|
|
4669
|
+
};
|
|
4670
|
+
let explicitPaths = null;
|
|
4671
|
+
let addPaths = null;
|
|
4672
|
+
let prependPaths = null;
|
|
4673
|
+
let appendPaths = null;
|
|
4674
|
+
if (hasExplicitItems) explicitPaths = readPathList();
|
|
4675
|
+
if (hasAddItems) addPaths = readPathList();
|
|
4676
|
+
if (hasPrependItems) prependPaths = readPathList();
|
|
4677
|
+
if (hasAppendItems) appendPaths = readPathList();
|
|
4678
|
+
if (hasDeleteItems) readPathList();
|
|
4679
|
+
if (hasReorderItems) readPathList();
|
|
4680
|
+
if (prependPaths && prependPaths.length > 0) return prependPaths;
|
|
4681
|
+
if (explicitPaths && explicitPaths.length > 0) return explicitPaths;
|
|
4682
|
+
if (appendPaths && appendPaths.length > 0) return appendPaths;
|
|
4683
|
+
if (addPaths && addPaths.length > 0) return addPaths;
|
|
4684
|
+
return null;
|
|
4685
|
+
}
|
|
4686
|
+
case TypeEnum.VariantSelectionMap: {
|
|
4687
|
+
const elementCount = checkedCount(reader.readUint64());
|
|
4688
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
4689
|
+
for (let i = 0; i < elementCount; i++) {
|
|
4690
|
+
const keyIdx = reader.readUint32();
|
|
4691
|
+
const valueIdx = reader.readUint32();
|
|
4692
|
+
const key = this.tokens[this.strings[keyIdx]];
|
|
4693
|
+
const value = this.tokens[this.strings[valueIdx]];
|
|
4694
|
+
if (key && value) map[key] = value;
|
|
4695
|
+
}
|
|
4696
|
+
return map;
|
|
4697
|
+
}
|
|
4698
|
+
default:
|
|
4699
|
+
throw new Error(
|
|
4700
|
+
"USDC: unsupported encoding: " + ["USDCParser: Unsupported scalar type", type].join(" ")
|
|
4701
|
+
);
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
/** Reads bounded string-keyed dictionary entries and their recursive value representations. */
|
|
4705
|
+
_readDictionary() {
|
|
4706
|
+
const reader = this.reader;
|
|
4707
|
+
const dictionaryOffset = reader.tell();
|
|
4708
|
+
this._activeDictionaries ||= /* @__PURE__ */ new Set();
|
|
4709
|
+
if (this._activeDictionaries.has(dictionaryOffset))
|
|
4710
|
+
throw new Error("USDC: cyclic dictionary value");
|
|
4711
|
+
if (this._activeDictionaries.size >= 64)
|
|
4712
|
+
throw new Error("USDC: dictionary depth limit exceeded");
|
|
4713
|
+
this._activeDictionaries.add(dictionaryOffset);
|
|
4714
|
+
try {
|
|
4715
|
+
const count = checkedCount(reader.readUint64());
|
|
4716
|
+
if (count > Math.floor((this.buffer.byteLength - reader.tell()) / 20))
|
|
4717
|
+
throw new Error("USDC: truncated dictionary entries");
|
|
4718
|
+
const dictionary = /* @__PURE__ */ Object.create(null);
|
|
4719
|
+
for (let index = 0; index < count; index++) {
|
|
4720
|
+
const stringIndex = reader.readUint32();
|
|
4721
|
+
const key = this.tokens[this.strings[stringIndex]];
|
|
4722
|
+
if (typeof key !== "string" || Object.hasOwn(dictionary, key))
|
|
4723
|
+
throw new Error("USDC: invalid dictionary key");
|
|
4724
|
+
const offsetLocation = reader.tell();
|
|
4725
|
+
const relativeOffset = reader.readInt64();
|
|
4726
|
+
if (relativeOffset < 8) throw new Error("USDC: invalid dictionary value offset");
|
|
4727
|
+
reader.seek(offsetLocation + relativeOffset);
|
|
4728
|
+
const representation = new ValueRep(reader.readUint32(), reader.readUint32());
|
|
4729
|
+
if (representation.typeEnum < TypeEnum.Bool || representation.typeEnum > TypeEnum.AssetPath && representation.typeEnum !== TypeEnum.Dictionary || representation.isArray && !DICTIONARY_ARRAY_TYPES.has(representation.typeEnum))
|
|
4730
|
+
throw new Error("USDC: unsupported dictionary value type");
|
|
4731
|
+
const nextEntry = reader.tell();
|
|
4732
|
+
const value = this._readValue(representation);
|
|
4733
|
+
dictionary[key] = representation.typeEnum === TypeEnum.AssetPath ? { assetPath: value } : value;
|
|
4734
|
+
reader.seek(nextEntry);
|
|
4735
|
+
}
|
|
4736
|
+
return dictionary;
|
|
4737
|
+
} finally {
|
|
4738
|
+
this._activeDictionaries.delete(dictionaryOffset);
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
_readArrayValue(valueRep) {
|
|
4742
|
+
const reader = this.reader;
|
|
4743
|
+
const type = valueRep.typeEnum;
|
|
4744
|
+
const isCompressed = valueRep.isCompressed;
|
|
4745
|
+
let size;
|
|
4746
|
+
if (this.version.major === 0 && this.version.minor < 7) {
|
|
4747
|
+
size = reader.readUint32();
|
|
4748
|
+
} else {
|
|
4749
|
+
size = reader.readUint64();
|
|
4750
|
+
}
|
|
4751
|
+
if (!Number.isSafeInteger(size) || size < 0) {
|
|
4752
|
+
throw new RangeError("USDCParser: Invalid array size " + size + " for type " + type + ".");
|
|
4753
|
+
}
|
|
4754
|
+
if (size > 2147483647) {
|
|
4755
|
+
throw new RangeError("USDCParser: Array size " + size + " exceeds implementation limits.");
|
|
4756
|
+
}
|
|
4757
|
+
size = checkedCount(size);
|
|
4758
|
+
if (size === 0) return [];
|
|
4759
|
+
if (isCompressed) {
|
|
4760
|
+
return this._readCompressedArray(type, size);
|
|
4761
|
+
}
|
|
4762
|
+
switch (type) {
|
|
4763
|
+
case TypeEnum.Int: {
|
|
4764
|
+
const arr = new Int32Array(checkedLength(size));
|
|
4765
|
+
for (let i = 0; i < size; i++) arr[i] = reader.readInt32();
|
|
4766
|
+
return arr;
|
|
4767
|
+
}
|
|
4768
|
+
case TypeEnum.UInt: {
|
|
4769
|
+
const arr = new Uint32Array(checkedLength(size));
|
|
4770
|
+
for (let i = 0; i < size; i++) arr[i] = reader.readUint32();
|
|
4771
|
+
return arr;
|
|
4772
|
+
}
|
|
4773
|
+
case TypeEnum.Float: {
|
|
4774
|
+
const arr = new Float32Array(checkedLength(size));
|
|
4775
|
+
for (let i = 0; i < size; i++) arr[i] = reader.readFloat32();
|
|
4776
|
+
return arr;
|
|
4777
|
+
}
|
|
4778
|
+
case TypeEnum.Double: {
|
|
4779
|
+
const arr = new Float64Array(checkedLength(size));
|
|
4780
|
+
for (let i = 0; i < size; i++) arr[i] = reader.readFloat64();
|
|
4781
|
+
return arr;
|
|
4782
|
+
}
|
|
4783
|
+
case TypeEnum.Vec2f: {
|
|
4784
|
+
const arr = new Float32Array(checkedLength(size * 2));
|
|
4785
|
+
for (let i = 0; i < size * 2; i++) arr[i] = reader.readFloat32();
|
|
4786
|
+
return arr;
|
|
4787
|
+
}
|
|
4788
|
+
case TypeEnum.Vec3f: {
|
|
4789
|
+
const arr = new Float32Array(checkedLength(size * 3));
|
|
4790
|
+
for (let i = 0; i < size * 3; i++) arr[i] = reader.readFloat32();
|
|
4791
|
+
return arr;
|
|
4792
|
+
}
|
|
4793
|
+
case TypeEnum.Vec4f: {
|
|
4794
|
+
const arr = new Float32Array(checkedLength(size * 4));
|
|
4795
|
+
for (let i = 0; i < size * 4; i++) arr[i] = reader.readFloat32();
|
|
4796
|
+
return arr;
|
|
4797
|
+
}
|
|
4798
|
+
case TypeEnum.Vec3h: {
|
|
4799
|
+
const arr = new Float32Array(checkedLength(size * 3));
|
|
4800
|
+
for (let i = 0; i < size * 3; i++) arr[i] = this._readHalf();
|
|
4801
|
+
return arr;
|
|
4802
|
+
}
|
|
4803
|
+
case TypeEnum.Quatf: {
|
|
4804
|
+
const arr = new Float32Array(checkedLength(size * 4));
|
|
4805
|
+
for (let i = 0; i < size * 4; i++) arr[i] = reader.readFloat32();
|
|
4806
|
+
return arr;
|
|
4807
|
+
}
|
|
4808
|
+
case TypeEnum.Quath: {
|
|
4809
|
+
const arr = new Float32Array(checkedLength(size * 4));
|
|
4810
|
+
for (let i = 0; i < size * 4; i++) arr[i] = this._readHalf();
|
|
4811
|
+
return arr;
|
|
4812
|
+
}
|
|
4813
|
+
case TypeEnum.Matrix4d: {
|
|
4814
|
+
const arr = new Float64Array(checkedLength(size * 16));
|
|
4815
|
+
for (let i = 0; i < size * 16; i++) arr[i] = reader.readFloat64();
|
|
4816
|
+
return arr;
|
|
4817
|
+
}
|
|
4818
|
+
case TypeEnum.String:
|
|
4819
|
+
case TypeEnum.Token: {
|
|
4820
|
+
const arr = [];
|
|
4821
|
+
for (let i = 0; i < size; i++) {
|
|
4822
|
+
const index = reader.readUint32();
|
|
4823
|
+
const tokenIndex = type === TypeEnum.String ? this.strings[index] : index;
|
|
4824
|
+
const value = this.tokens[tokenIndex];
|
|
4825
|
+
if (typeof value !== "string") throw new Error("USDC: invalid string array index");
|
|
4826
|
+
arr.push(value);
|
|
4827
|
+
}
|
|
4828
|
+
return arr;
|
|
4829
|
+
}
|
|
4830
|
+
case TypeEnum.Half: {
|
|
4831
|
+
const arr = new Float32Array(checkedLength(size));
|
|
4832
|
+
for (let i = 0; i < size; i++) arr[i] = this._readHalf();
|
|
4833
|
+
return arr;
|
|
4834
|
+
}
|
|
4835
|
+
default:
|
|
4836
|
+
throw new Error(
|
|
4837
|
+
"USDC: unsupported encoding: " + ["USDCParser: Unsupported array type", type].join(" ")
|
|
4838
|
+
);
|
|
4839
|
+
}
|
|
4840
|
+
}
|
|
4841
|
+
_readCompressedArray(type, size) {
|
|
4842
|
+
const reader = this.reader;
|
|
4843
|
+
switch (type) {
|
|
4844
|
+
case TypeEnum.Int:
|
|
4845
|
+
case TypeEnum.UInt: {
|
|
4846
|
+
const compressedSize = reader.readUint64();
|
|
4847
|
+
const compressed = reader.readBytes(compressedSize);
|
|
4848
|
+
const values = decompressIntegers32(
|
|
4849
|
+
compressed.buffer.slice(compressed.byteOffset, compressed.byteOffset + compressedSize),
|
|
4850
|
+
size
|
|
4851
|
+
);
|
|
4852
|
+
return type === TypeEnum.UInt ? new Uint32Array(values.buffer, values.byteOffset, values.length) : values;
|
|
4853
|
+
}
|
|
4854
|
+
case TypeEnum.Half:
|
|
4855
|
+
case TypeEnum.Double:
|
|
4856
|
+
case TypeEnum.Float: {
|
|
4857
|
+
const code = reader.readInt8();
|
|
4858
|
+
if (code === FLOAT_COMPRESSION_INT) {
|
|
4859
|
+
const compressedSize = reader.readUint64();
|
|
4860
|
+
const compressed = reader.readBytes(compressedSize);
|
|
4861
|
+
const ints = decompressIntegers32(
|
|
4862
|
+
compressed.buffer.slice(compressed.byteOffset, compressed.byteOffset + compressedSize),
|
|
4863
|
+
size
|
|
4864
|
+
);
|
|
4865
|
+
const floats = type === TypeEnum.Double ? new Float64Array(checkedLength(size)) : new Float32Array(checkedLength(size));
|
|
4866
|
+
for (let i = 0; i < size; i++)
|
|
4867
|
+
floats[i] = type === TypeEnum.Half ? this._convertHalfInteger(ints[i]) : ints[i];
|
|
4868
|
+
return floats;
|
|
4869
|
+
} else if (code === FLOAT_COMPRESSION_LUT) {
|
|
4870
|
+
const lutSize = checkedCount(reader.readUint32());
|
|
4871
|
+
if (lutSize === 0) throw new Error("USDC: invalid float lookup table");
|
|
4872
|
+
const lut = type === TypeEnum.Double ? new Float64Array(checkedLength(lutSize)) : new Float32Array(checkedLength(lutSize));
|
|
4873
|
+
for (let i = 0; i < lutSize; i++)
|
|
4874
|
+
lut[i] = type === TypeEnum.Half ? this._readHalf() : type === TypeEnum.Double ? reader.readFloat64() : reader.readFloat32();
|
|
4875
|
+
const compressedSize = reader.readUint64();
|
|
4876
|
+
const compressed = reader.readBytes(compressedSize);
|
|
4877
|
+
const indices = decompressIntegers32(
|
|
4878
|
+
compressed.buffer.slice(compressed.byteOffset, compressed.byteOffset + compressedSize),
|
|
4879
|
+
size
|
|
4880
|
+
);
|
|
4881
|
+
const floats = type === TypeEnum.Double ? new Float64Array(checkedLength(size)) : new Float32Array(checkedLength(size));
|
|
4882
|
+
for (let i = 0; i < size; i++) {
|
|
4883
|
+
if (indices[i] < 0 || indices[i] >= lutSize)
|
|
4884
|
+
throw new Error("USDC: invalid float lookup index");
|
|
4885
|
+
floats[i] = lut[indices[i]];
|
|
4886
|
+
}
|
|
4887
|
+
return floats;
|
|
4888
|
+
}
|
|
4889
|
+
throw new Error(
|
|
4890
|
+
"USDC: unsupported encoding: " + ["USDCParser: Unknown float compression code", code].join(" ")
|
|
4891
|
+
);
|
|
4892
|
+
}
|
|
4893
|
+
default:
|
|
4894
|
+
throw new Error(
|
|
4895
|
+
"USDC: unsupported encoding: " + ["USDCParser: Unsupported compressed array type", type].join(" ")
|
|
4896
|
+
);
|
|
4897
|
+
}
|
|
4898
|
+
}
|
|
4899
|
+
/** Rounds integer-compressed half samples using IEEE ties-to-even semantics. */
|
|
4900
|
+
_convertHalfInteger(value) {
|
|
4901
|
+
const absoluteValue = Math.abs(value);
|
|
4902
|
+
if (absoluteValue <= 2048) return value;
|
|
4903
|
+
if (absoluteValue >= 65520) return Math.sign(value) * Infinity;
|
|
4904
|
+
const spacing = 2 ** (Math.floor(Math.log2(absoluteValue)) - 10);
|
|
4905
|
+
const scaledValue = absoluteValue / spacing;
|
|
4906
|
+
const lowerValue = Math.floor(scaledValue);
|
|
4907
|
+
const fractionValue = scaledValue - lowerValue;
|
|
4908
|
+
const roundedValue = fractionValue > 0.5 || fractionValue === 0.5 && lowerValue % 2 !== 0 ? lowerValue + 1 : lowerValue;
|
|
4909
|
+
return Math.sign(value) * roundedValue * spacing;
|
|
4910
|
+
}
|
|
4911
|
+
_readHalf() {
|
|
4912
|
+
return this._halfToFloat(this.reader.readUint16());
|
|
4913
|
+
}
|
|
4914
|
+
_halfToFloat(h) {
|
|
4915
|
+
const sign = (h & 32768) >> 15;
|
|
4916
|
+
const exp = (h & 31744) >> 10;
|
|
4917
|
+
const frac = h & 1023;
|
|
4918
|
+
if (exp === 0) {
|
|
4919
|
+
if (frac === 0) {
|
|
4920
|
+
return sign ? -0 : 0;
|
|
4921
|
+
}
|
|
4922
|
+
return (sign ? -1 : 1) * HALF_DENORM_SCALE * (frac / 1024);
|
|
4923
|
+
} else if (exp === 31) {
|
|
4924
|
+
return frac ? NaN : sign ? -Infinity : Infinity;
|
|
4925
|
+
}
|
|
4926
|
+
return (sign ? -1 : 1) * HALF_EXPONENT_TABLE[exp] * (1 + frac / 1024);
|
|
4927
|
+
}
|
|
4928
|
+
_getFieldsForSpec(spec) {
|
|
4929
|
+
const fields = /* @__PURE__ */ Object.create(null);
|
|
4930
|
+
let fieldSetIndex = spec.fieldSetIndex;
|
|
4931
|
+
const maxIterations = 1e4;
|
|
4932
|
+
let iterations = 0;
|
|
4933
|
+
while (fieldSetIndex < this.fieldSets.length && iterations < maxIterations) {
|
|
4934
|
+
const fieldIndex = this.fieldSets[fieldSetIndex];
|
|
4935
|
+
if (fieldIndex === FIELD_SET_TERMINATOR || fieldIndex === -1) break;
|
|
4936
|
+
const field = this.fields[fieldIndex];
|
|
4937
|
+
if (!field) throw new Error("USDC: invalid field index");
|
|
4938
|
+
if (field) {
|
|
4939
|
+
const name22 = this.tokens[field.tokenIndex];
|
|
4940
|
+
const value = this._readValue(field.valueRep);
|
|
4941
|
+
fields[name22] = value;
|
|
4942
|
+
}
|
|
4943
|
+
fieldSetIndex++;
|
|
4944
|
+
iterations++;
|
|
4945
|
+
}
|
|
4946
|
+
if (iterations >= maxIterations) throw new Error("USDC: field traversal limit exceeded");
|
|
4947
|
+
return fields;
|
|
4948
|
+
}
|
|
4949
|
+
};
|
|
4950
|
+
}
|
|
4951
|
+
});
|
|
4952
|
+
|
|
4953
|
+
// ../scene/src/usd/lib/parse-usdc.ts
|
|
4954
|
+
function parseUSDC(data, url) {
|
|
4955
|
+
var _a, _b, _c;
|
|
4956
|
+
if (data.byteLength < 88 || data.byteLength > 64 * 1024 * 1024)
|
|
4957
|
+
throw new Error("USDC: invalid input size");
|
|
4958
|
+
const bytes = new Uint8Array(data);
|
|
4959
|
+
if (bytes[8] !== 0 || bytes[9] !== 8 || bytes[10] !== 0)
|
|
4960
|
+
throw new Error("USDC: initial decoder requires crate version 0.8.0");
|
|
4961
|
+
const reader = new DataView(data);
|
|
4962
|
+
const table = reader.getBigUint64(16, true);
|
|
4963
|
+
if (table > BigInt(data.byteLength - 8)) throw new Error("USDC: invalid section table");
|
|
4964
|
+
const offset = Number(table), count = reader.getBigUint64(offset, true);
|
|
4965
|
+
if (count > 16n || offset + 8 + Number(count) * 32 > data.byteLength)
|
|
4966
|
+
throw new Error("USDC: invalid section table length");
|
|
4967
|
+
const sectionNames = /* @__PURE__ */ new Set();
|
|
4968
|
+
for (let index = 0; index < Number(count); index++) {
|
|
4969
|
+
const entry = offset + 8 + index * 32;
|
|
4970
|
+
const nameBytes = bytes.subarray(entry, entry + 16);
|
|
4971
|
+
const terminator = nameBytes.indexOf(0);
|
|
4972
|
+
const name22 = new TextDecoder().decode(
|
|
4973
|
+
nameBytes.subarray(0, terminator < 0 ? nameBytes.length : terminator)
|
|
4974
|
+
);
|
|
4975
|
+
if (sectionNames.has(name22)) throw new Error("USDC: duplicate section");
|
|
4976
|
+
sectionNames.add(name22);
|
|
4977
|
+
const start = reader.getBigUint64(entry + 16, true), size = reader.getBigUint64(entry + 24, true);
|
|
4978
|
+
if (start < 88n || start + size > BigInt(data.byteLength))
|
|
4979
|
+
throw new Error("USDC: section out of bounds");
|
|
4980
|
+
}
|
|
4981
|
+
for (const name22 of ["TOKENS", "STRINGS", "FIELDS", "FIELDSETS", "PATHS", "SPECS"])
|
|
4982
|
+
if (!sectionNames.has(name22)) throw new Error("USDC: missing required section");
|
|
4983
|
+
const { specsByPath } = new USDCParser().parseData(data);
|
|
4984
|
+
const prims = /* @__PURE__ */ new Map();
|
|
4985
|
+
for (const [path, specification] of Object.entries(specsByPath)) {
|
|
4986
|
+
if (specification.specType === 7 && path === "/") continue;
|
|
4987
|
+
if (specification.specType === 1 || specification.specType === 8) continue;
|
|
4988
|
+
if (specification.specType !== 6 || !/^\/(?:[A-Za-z_][\w:]*\/)*[A-Za-z_][\w:]*$/.test(path))
|
|
4989
|
+
throw new Error("USDC: unsupported prim specification");
|
|
4990
|
+
const fields = specification.fields;
|
|
4991
|
+
const specifier = fields.specifier ?? 0;
|
|
4992
|
+
if (specifier !== 0 && specifier !== 1 && specifier !== 2)
|
|
4993
|
+
throw new Error("USDC: invalid prim specifier");
|
|
4994
|
+
const metadata3 = convertFields(
|
|
4995
|
+
fields,
|
|
4996
|
+
/* @__PURE__ */ new Set(["specifier", "typeName", "primChildren", "properties"])
|
|
4997
|
+
);
|
|
4998
|
+
prims.set(path, {
|
|
4999
|
+
name: path.slice(path.lastIndexOf("/") + 1),
|
|
5000
|
+
path,
|
|
5001
|
+
sourceUrl: url,
|
|
5002
|
+
type: String(fields.typeName || ""),
|
|
5003
|
+
specifier: ["def", "over", "class"][specifier],
|
|
5004
|
+
attributes: /* @__PURE__ */ Object.create(null),
|
|
5005
|
+
metadata: metadata3,
|
|
5006
|
+
variants: /* @__PURE__ */ Object.create(null),
|
|
5007
|
+
children: []
|
|
5008
|
+
});
|
|
5009
|
+
}
|
|
5010
|
+
const roots = [];
|
|
5011
|
+
for (const prim of prims.values()) {
|
|
5012
|
+
const parentPath = prim.path.slice(0, prim.path.lastIndexOf("/"));
|
|
5013
|
+
if (!parentPath) roots.push(prim);
|
|
5014
|
+
else {
|
|
5015
|
+
const parent = prims.get(parentPath);
|
|
5016
|
+
if (!parent) throw new Error("USDC: missing parent prim");
|
|
5017
|
+
parent.children.push(prim);
|
|
5018
|
+
}
|
|
5019
|
+
}
|
|
5020
|
+
orderPrims(roots, (_a = specsByPath["/"]) == null ? void 0 : _a.fields.primChildren);
|
|
5021
|
+
for (const prim of prims.values())
|
|
5022
|
+
orderPrims(prim.children, (_b = specsByPath[prim.path]) == null ? void 0 : _b.fields.primChildren);
|
|
5023
|
+
for (const [path, specification] of Object.entries(specsByPath)) {
|
|
5024
|
+
if (specification.specType !== 1 && specification.specType !== 8) continue;
|
|
5025
|
+
const separator = path.indexOf(".");
|
|
5026
|
+
const prim = prims.get(path.slice(0, separator));
|
|
5027
|
+
if (separator < 0 || !prim) throw new Error("USDC: property has no owning prim");
|
|
5028
|
+
const name22 = path.slice(separator + 1), fields = specification.fields;
|
|
5029
|
+
const type = specification.specType === 8 ? "rel" : String(fields.typeName || "");
|
|
5030
|
+
const value = convertAttributeValue(
|
|
5031
|
+
specification.specType === 8 ? fields.targetPaths : fields.default,
|
|
5032
|
+
type
|
|
5033
|
+
);
|
|
5034
|
+
const metadata3 = convertFields(
|
|
5035
|
+
fields,
|
|
5036
|
+
/* @__PURE__ */ new Set(["typeName", "default", "targetPaths", "timeSamples"])
|
|
5037
|
+
);
|
|
5038
|
+
if (fields.timeSamples !== void 0)
|
|
5039
|
+
metadata3.timeSamples = convertTimeSamples(fields.timeSamples, type);
|
|
5040
|
+
prim.attributes[name22] = {
|
|
5041
|
+
name: name22,
|
|
5042
|
+
type,
|
|
5043
|
+
value,
|
|
5044
|
+
metadata: metadata3
|
|
5045
|
+
};
|
|
5046
|
+
}
|
|
5047
|
+
return {
|
|
5048
|
+
format: "usdc",
|
|
5049
|
+
url,
|
|
5050
|
+
metadata: convertFields(((_c = specsByPath["/"]) == null ? void 0 : _c.fields) || {}, /* @__PURE__ */ new Set(["primChildren"])),
|
|
5051
|
+
rootPrims: roots,
|
|
5052
|
+
layers: []
|
|
5053
|
+
};
|
|
5054
|
+
}
|
|
5055
|
+
function convertFields(fields, excluded) {
|
|
5056
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
5057
|
+
for (const [name22, value] of Object.entries(fields))
|
|
5058
|
+
if (!excluded.has(name22)) result[name22] = convertValue(value);
|
|
5059
|
+
return result;
|
|
5060
|
+
}
|
|
5061
|
+
function convertValue(value) {
|
|
5062
|
+
if (value === void 0 || value === null) return null;
|
|
5063
|
+
if (typeof value === "number" || typeof value === "string" || typeof value === "boolean")
|
|
5064
|
+
return value;
|
|
5065
|
+
if (Array.isArray(value)) return value.map(convertValue);
|
|
5066
|
+
if (ArrayBuffer.isView(value) && !(value instanceof DataView))
|
|
5067
|
+
return Array.from(value);
|
|
5068
|
+
if (typeof value === "object") return convertFields(value, /* @__PURE__ */ new Set());
|
|
5069
|
+
throw new Error("USDC: unsupported decoded value");
|
|
5070
|
+
}
|
|
5071
|
+
function convertAttributeValue(raw, type) {
|
|
5072
|
+
const value = convertValue(raw);
|
|
5073
|
+
if (type === "asset" && typeof value === "string") return { assetPath: value };
|
|
5074
|
+
if (type === "rel" && Array.isArray(value))
|
|
5075
|
+
return value.map((path) => typeof path === "string" ? { path } : path);
|
|
5076
|
+
const tuple = /^(?:(?:point|normal|vector|color|texCoord)([234])[fdh]|(?:float|double|half|int)([234]))\[\]$/.exec(
|
|
5077
|
+
type
|
|
5078
|
+
);
|
|
5079
|
+
if (tuple && Array.isArray(value)) {
|
|
5080
|
+
const components = Number(tuple[1] || tuple[2]);
|
|
5081
|
+
if (value.length % components) throw new Error("USDC: incomplete vector tuple");
|
|
5082
|
+
const tuples = [];
|
|
5083
|
+
for (let offset = 0; offset < value.length; offset += components)
|
|
5084
|
+
tuples.push(value.slice(offset, offset + components));
|
|
5085
|
+
return tuples;
|
|
5086
|
+
}
|
|
5087
|
+
return value;
|
|
5088
|
+
}
|
|
5089
|
+
function orderPrims(prims, names) {
|
|
5090
|
+
if (names === void 0) return;
|
|
5091
|
+
if (!Array.isArray(names)) throw new Error("USDC: invalid primChildren order");
|
|
5092
|
+
const remaining = new Map(prims.map((prim) => [prim.name, prim]));
|
|
5093
|
+
const ordered = [];
|
|
5094
|
+
for (const name22 of names) {
|
|
5095
|
+
const prim = typeof name22 === "string" ? remaining.get(name22) : void 0;
|
|
5096
|
+
if (!prim) throw new Error("USDC: invalid primChildren reference");
|
|
5097
|
+
ordered.push(prim);
|
|
5098
|
+
remaining.delete(name22);
|
|
5099
|
+
}
|
|
5100
|
+
for (const prim of remaining.values()) ordered.push(prim);
|
|
5101
|
+
for (let index = 0; index < ordered.length; index++) prims[index] = ordered[index];
|
|
5102
|
+
}
|
|
5103
|
+
function convertTimeSamples(raw, type) {
|
|
5104
|
+
if (!raw || typeof raw !== "object") throw new Error("USDC: invalid time samples");
|
|
5105
|
+
const samples = raw;
|
|
5106
|
+
const times = convertValue(samples.times);
|
|
5107
|
+
if (!Array.isArray(times) || !Array.isArray(samples.values) || times.length !== samples.values.length)
|
|
5108
|
+
throw new Error("USDC: invalid time samples");
|
|
5109
|
+
return { times, values: samples.values.map((value) => convertAttributeValue(value, type)) };
|
|
5110
|
+
}
|
|
5111
|
+
var init_parse_usdc = __esm({
|
|
5112
|
+
"../scene/src/usd/lib/parse-usdc.ts"() {
|
|
5113
|
+
"use strict";
|
|
5114
|
+
init_usdc_parser();
|
|
5115
|
+
}
|
|
5116
|
+
});
|
|
5117
|
+
|
|
3701
5118
|
// ../scene/src/usd/lib/parse-usda.ts
|
|
3702
5119
|
function parseUSDA(source, url) {
|
|
3703
5120
|
if (!source.trimStart().startsWith("#usda")) {
|
|
@@ -3732,7 +5149,7 @@ var init_parse_usda = __esm({
|
|
|
3732
5149
|
}
|
|
3733
5150
|
/** Parses the complete USDA layer. */
|
|
3734
5151
|
parse() {
|
|
3735
|
-
const
|
|
5152
|
+
const metadata3 = this.tokenizer.match("(") ? this.parseMetadata(")") : {};
|
|
3736
5153
|
const rootPrims = [];
|
|
3737
5154
|
while (!this.tokenizer.isAtEnd()) {
|
|
3738
5155
|
if (this.isPrimDeclaration()) {
|
|
@@ -3744,7 +5161,7 @@ var init_parse_usda = __esm({
|
|
|
3744
5161
|
return {
|
|
3745
5162
|
format: "usda",
|
|
3746
5163
|
url: this.url,
|
|
3747
|
-
metadata:
|
|
5164
|
+
metadata: metadata3,
|
|
3748
5165
|
rootPrims,
|
|
3749
5166
|
layers: this.url ? [this.url] : []
|
|
3750
5167
|
};
|
|
@@ -3758,7 +5175,7 @@ var init_parse_usda = __esm({
|
|
|
3758
5175
|
const type = hasExplicitType ? firstToken.value : "";
|
|
3759
5176
|
const name22 = hasExplicitType ? this.tokenizer.read().value : firstToken.value;
|
|
3760
5177
|
const path = `${parentPath}/${name22}`;
|
|
3761
|
-
const
|
|
5178
|
+
const metadata3 = this.tokenizer.match("(") ? this.parseMetadata(")") : {};
|
|
3762
5179
|
this.tokenizer.expect("{");
|
|
3763
5180
|
const contents = this.parsePrimContents(path);
|
|
3764
5181
|
return {
|
|
@@ -3768,7 +5185,7 @@ var init_parse_usda = __esm({
|
|
|
3768
5185
|
type,
|
|
3769
5186
|
specifier,
|
|
3770
5187
|
attributes: contents.attributes,
|
|
3771
|
-
metadata: { ...
|
|
5188
|
+
metadata: { ...metadata3, ...contents.metadata },
|
|
3772
5189
|
variants: contents.variants,
|
|
3773
5190
|
children: contents.children
|
|
3774
5191
|
};
|
|
@@ -3776,7 +5193,7 @@ var init_parse_usda = __esm({
|
|
|
3776
5193
|
/** Parses the attributes, variants, and child prims inside a prim body. */
|
|
3777
5194
|
parsePrimContents(parentPath) {
|
|
3778
5195
|
const attributes = {};
|
|
3779
|
-
const
|
|
5196
|
+
const metadata3 = {};
|
|
3780
5197
|
const children = [];
|
|
3781
5198
|
const variants = {};
|
|
3782
5199
|
while (!this.tokenizer.isAtEnd() && !this.tokenizer.match("}")) {
|
|
@@ -3791,7 +5208,7 @@ var init_parse_usda = __esm({
|
|
|
3791
5208
|
}
|
|
3792
5209
|
}
|
|
3793
5210
|
}
|
|
3794
|
-
return { attributes, metadata:
|
|
5211
|
+
return { attributes, metadata: metadata3, children, variants };
|
|
3795
5212
|
}
|
|
3796
5213
|
/** Parses one named variant set. */
|
|
3797
5214
|
parseVariantSet(parentPath, variants) {
|
|
@@ -3841,12 +5258,12 @@ var init_parse_usda = __esm({
|
|
|
3841
5258
|
const name22 = significantTokens[significantTokens.length - 1].value;
|
|
3842
5259
|
const type = significantTokens.slice(0, -1).map((token) => token.value).join("");
|
|
3843
5260
|
const value = this.parseValue();
|
|
3844
|
-
const
|
|
3845
|
-
return { name: name22, type, value, metadata:
|
|
5261
|
+
const metadata3 = this.tokenizer.match("(") ? this.parseMetadata(")") : {};
|
|
5262
|
+
return { name: name22, type, value, metadata: metadata3 };
|
|
3846
5263
|
}
|
|
3847
5264
|
/** Parses a metadata dictionary through the requested terminator. */
|
|
3848
5265
|
parseMetadata(terminator) {
|
|
3849
|
-
const
|
|
5266
|
+
const metadata3 = {};
|
|
3850
5267
|
while (!this.tokenizer.isAtEnd() && !this.tokenizer.match(terminator)) {
|
|
3851
5268
|
this.tokenizer.match(",");
|
|
3852
5269
|
if (this.tokenizer.peek().value === terminator) {
|
|
@@ -3869,10 +5286,10 @@ var init_parse_usda = __esm({
|
|
|
3869
5286
|
continue;
|
|
3870
5287
|
}
|
|
3871
5288
|
const name22 = declarationTokens[declarationTokens.length - 1].value;
|
|
3872
|
-
|
|
5289
|
+
metadata3[name22] = this.parseValue();
|
|
3873
5290
|
this.tokenizer.match(",");
|
|
3874
5291
|
}
|
|
3875
|
-
return
|
|
5292
|
+
return metadata3;
|
|
3876
5293
|
}
|
|
3877
5294
|
/** Parses one scalar, list, tuple, dictionary, asset path, or scene path value. */
|
|
3878
5295
|
parseValue() {
|
|
@@ -4088,30 +5505,52 @@ function parseUSDZArchive(arrayBuffer) {
|
|
|
4088
5505
|
const directoryOffset = findCentralDirectory(view);
|
|
4089
5506
|
const entryCount = view.getUint16(directoryOffset + 10, true);
|
|
4090
5507
|
let entryOffset = view.getUint32(directoryOffset + 16, true);
|
|
5508
|
+
const dataLimit = entryOffset;
|
|
4091
5509
|
const files = /* @__PURE__ */ new Map();
|
|
4092
|
-
const
|
|
5510
|
+
const textDecoder2 = new TextDecoder();
|
|
5511
|
+
let extractedByteLength = 0;
|
|
4093
5512
|
for (let entryIndex = 0; entryIndex < entryCount; entryIndex++) {
|
|
5513
|
+
if (entryOffset + 46 > directoryOffset) {
|
|
5514
|
+
throw new Error("USDZ archive contains a truncated ZIP central-directory entry.");
|
|
5515
|
+
}
|
|
4094
5516
|
if (view.getUint32(entryOffset, true) !== CENTRAL_DIRECTORY_ENTRY) {
|
|
4095
5517
|
throw new Error("USDZ archive contains an invalid ZIP central-directory entry.");
|
|
4096
5518
|
}
|
|
4097
5519
|
const compression = view.getUint16(entryOffset + 10, true);
|
|
4098
5520
|
const compressedLength = view.getUint32(entryOffset + 20, true);
|
|
5521
|
+
const uncompressedLength = view.getUint32(entryOffset + 24, true);
|
|
4099
5522
|
const filenameLength = view.getUint16(entryOffset + 28, true);
|
|
4100
5523
|
const extraLength = view.getUint16(entryOffset + 30, true);
|
|
4101
5524
|
const commentLength = view.getUint16(entryOffset + 32, true);
|
|
4102
5525
|
const localOffset = view.getUint32(entryOffset + 42, true);
|
|
4103
|
-
|
|
5526
|
+
if (entryOffset + 46 + filenameLength + extraLength + commentLength > directoryOffset) {
|
|
5527
|
+
throw new Error("USDZ archive contains a truncated ZIP filename or extra field.");
|
|
5528
|
+
}
|
|
5529
|
+
const filename = textDecoder2.decode(
|
|
4104
5530
|
new Uint8Array(arrayBuffer, entryOffset + 46, filenameLength)
|
|
4105
5531
|
);
|
|
4106
5532
|
if (compression !== 0) {
|
|
4107
5533
|
throw new Error(`USDZ entry "${filename}" is compressed; USDZ requires stored ZIP entries.`);
|
|
4108
5534
|
}
|
|
5535
|
+
if (localOffset + 30 > dataLimit || compressedLength !== uncompressedLength) {
|
|
5536
|
+
throw new Error(`USDZ entry "${filename}" has invalid stored ZIP bounds.`);
|
|
5537
|
+
}
|
|
4109
5538
|
if (view.getUint32(localOffset, true) !== LOCAL_FILE_HEADER) {
|
|
4110
5539
|
throw new Error(`USDZ entry "${filename}" has an invalid local ZIP header.`);
|
|
4111
5540
|
}
|
|
4112
5541
|
const localNameLength = view.getUint16(localOffset + 26, true);
|
|
4113
5542
|
const localExtraLength = view.getUint16(localOffset + 28, true);
|
|
4114
5543
|
const contentOffset = localOffset + 30 + localNameLength + localExtraLength;
|
|
5544
|
+
if ((view.getUint16(entryOffset + 8, true) | view.getUint16(localOffset + 6, true)) & 1) {
|
|
5545
|
+
throw new Error(`USDZ entry "${filename}" is encrypted.`);
|
|
5546
|
+
}
|
|
5547
|
+
if (contentOffset + compressedLength > dataLimit || view.getUint16(localOffset + 8, true) !== 0 || textDecoder2.decode(new Uint8Array(arrayBuffer, localOffset + 30, localNameLength)) !== filename || files.has(filename)) {
|
|
5548
|
+
throw new Error(`USDZ entry "${filename}" has invalid or duplicate stored ZIP data.`);
|
|
5549
|
+
}
|
|
5550
|
+
extractedByteLength += compressedLength;
|
|
5551
|
+
if (extractedByteLength > arrayBuffer.byteLength) {
|
|
5552
|
+
throw new Error("USDZ archive exceeds its stored data budget.");
|
|
5553
|
+
}
|
|
4115
5554
|
files.set(filename, arrayBuffer.slice(contentOffset, contentOffset + compressedLength));
|
|
4116
5555
|
entryOffset += 46 + filenameLength + extraLength + commentLength;
|
|
4117
5556
|
}
|
|
@@ -4162,21 +5601,32 @@ async function parseUSD(data, options = {}, context) {
|
|
|
4162
5601
|
let stage;
|
|
4163
5602
|
if (isZIPArchive(data)) {
|
|
4164
5603
|
const archive = parseUSDZArchive(data);
|
|
4165
|
-
const rootFilename =
|
|
4166
|
-
if (!rootFilename) {
|
|
4167
|
-
throw new Error("USDZ
|
|
5604
|
+
const rootFilename = archive.keys().next().value;
|
|
5605
|
+
if (!rootFilename || !/\.(?:usd[ac]?)$/i.test(rootFilename)) {
|
|
5606
|
+
throw new Error("USDZ archive has no supported USD root layer.");
|
|
4168
5607
|
}
|
|
4169
5608
|
const archiveBase = "https://usd.archive/";
|
|
5609
|
+
const assets = /* @__PURE__ */ Object.create(null);
|
|
4170
5610
|
for (const [filename, content] of archive) {
|
|
4171
|
-
|
|
5611
|
+
const assetUrl = new URL(filename, archiveBase);
|
|
5612
|
+
if (filename.startsWith("/") || /^[a-z][a-z\d+.-]*:/i.test(filename) || filename.includes("\\") || /[\u0000-\u001f\u007f]/.test(filename) || filename.trim() !== filename || filename.split("/").some((segment) => {
|
|
5613
|
+
const normalizedSegment = segment.replace(/%2e/gi, ".");
|
|
5614
|
+
return normalizedSegment === "." || normalizedSegment === "..";
|
|
5615
|
+
}) || assetUrl.origin !== new URL(archiveBase).origin || assetUrl.search || assetUrl.hash || assets[assetUrl.href]) {
|
|
5616
|
+
throw new Error(`USDZ entry "${filename}" has an ambiguous package URL.`);
|
|
5617
|
+
}
|
|
5618
|
+
environment.archiveFiles.set(assetUrl.href, content);
|
|
5619
|
+
assets[assetUrl.href] = createEmbeddedAsset(filename, content);
|
|
4172
5620
|
}
|
|
4173
5621
|
const rootUrl = new URL(rootFilename, archiveBase).href;
|
|
4174
5622
|
stage = parseUSDLayer(archive.get(rootFilename), rootUrl);
|
|
4175
5623
|
stage.format = "usdz";
|
|
5624
|
+
stage.assets = assets;
|
|
4176
5625
|
} else {
|
|
4177
5626
|
stage = parseUSDLayer(data, url);
|
|
4178
5627
|
}
|
|
4179
5628
|
if (stage.url) {
|
|
5629
|
+
setAttributeSourceUrls(stage, stage.url);
|
|
4180
5630
|
environment.layers.add(stage.url);
|
|
4181
5631
|
}
|
|
4182
5632
|
if (((_b = environment.options.usd) == null ? void 0 : _b.compose) !== false) {
|
|
@@ -4188,6 +5638,11 @@ async function parseUSD(data, options = {}, context) {
|
|
|
4188
5638
|
}
|
|
4189
5639
|
return stage;
|
|
4190
5640
|
}
|
|
5641
|
+
function createEmbeddedAsset(path, data) {
|
|
5642
|
+
const extension = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
5643
|
+
const mimeType = extension === "png" ? "image/png" : /^(?:jpe?g)$/.test(extension) ? "image/jpeg" : void 0;
|
|
5644
|
+
return mimeType ? { path, data, mimeType } : { path, data };
|
|
5645
|
+
}
|
|
4191
5646
|
function getSourceLocation(configuredLocation, contextLocation) {
|
|
4192
5647
|
const configuredUrl = getAbsoluteUrl(configuredLocation);
|
|
4193
5648
|
if (configuredUrl) {
|
|
@@ -4214,10 +5669,29 @@ function resolveAssetPath(assetPath, sourceLocation) {
|
|
|
4214
5669
|
function parseUSDLayer(data, url) {
|
|
4215
5670
|
const signature = TEXT_DECODER.decode(data.slice(0, 8));
|
|
4216
5671
|
if (signature === CRATE_SIGNATURE) {
|
|
4217
|
-
|
|
5672
|
+
return parseUSDC(data, url);
|
|
4218
5673
|
}
|
|
4219
5674
|
return parseUSDA(TEXT_DECODER.decode(data), url);
|
|
4220
5675
|
}
|
|
5676
|
+
function setAttributeSourceUrls(stage, sourceUrl) {
|
|
5677
|
+
const pendingContents = [...stage.rootPrims];
|
|
5678
|
+
while (pendingContents.length) {
|
|
5679
|
+
const contents = pendingContents.pop();
|
|
5680
|
+
for (const attribute of Object.values(contents.attributes)) {
|
|
5681
|
+
attribute.sourceUrl = sourceUrl;
|
|
5682
|
+
}
|
|
5683
|
+
for (const child of contents.children) {
|
|
5684
|
+
pendingContents.push(child);
|
|
5685
|
+
}
|
|
5686
|
+
if ("variants" in contents) {
|
|
5687
|
+
for (const variants of Object.values(contents.variants)) {
|
|
5688
|
+
for (const variant of Object.values(variants)) {
|
|
5689
|
+
pendingContents.push(variant);
|
|
5690
|
+
}
|
|
5691
|
+
}
|
|
5692
|
+
}
|
|
5693
|
+
}
|
|
5694
|
+
}
|
|
4221
5695
|
async function composePrims(prims, sourceUrl, inheritedVariants, environment, depth) {
|
|
4222
5696
|
var _a, _b, _c;
|
|
4223
5697
|
if (depth > (((_a = environment.options.usd) == null ? void 0 : _a.maxReferenceDepth) ?? 12)) {
|
|
@@ -4297,6 +5771,7 @@ async function loadReferencedStage(url, environment) {
|
|
|
4297
5771
|
content = response.arrayBuffer();
|
|
4298
5772
|
}
|
|
4299
5773
|
const stage = parseUSDLayer(await content, url);
|
|
5774
|
+
setAttributeSourceUrls(stage, url);
|
|
4300
5775
|
environment.layers.add(url);
|
|
4301
5776
|
return stage;
|
|
4302
5777
|
})();
|
|
@@ -4396,6 +5871,7 @@ var TEXT_DECODER, CRATE_SIGNATURE, ZIP_SIGNATURE, USD_LOADER_DEFAULT_OPTIONS;
|
|
|
4396
5871
|
var init_parse_usd = __esm({
|
|
4397
5872
|
"../scene/src/usd/lib/parse-usd.ts"() {
|
|
4398
5873
|
"use strict";
|
|
5874
|
+
init_parse_usdc();
|
|
4399
5875
|
init_parse_usda();
|
|
4400
5876
|
init_parse_usdz();
|
|
4401
5877
|
TEXT_DECODER = new TextDecoder();
|
|
@@ -4450,11 +5926,11 @@ var init_usd_loader_types = __esm({
|
|
|
4450
5926
|
id: "usd",
|
|
4451
5927
|
module: "scene",
|
|
4452
5928
|
version: VERSION3,
|
|
4453
|
-
extensions: ["usd", "usda", "usdz"],
|
|
4454
|
-
mimeTypes: ["model/vnd.usd", "model/vnd.usda", "model/vnd.usdz+zip"],
|
|
5929
|
+
extensions: ["usd", "usda", "usdc", "usdz"],
|
|
5930
|
+
mimeTypes: ["model/vnd.usd", "model/vnd.usda", "model/vnd.usdc", "model/vnd.usdz+zip"],
|
|
4455
5931
|
text: true,
|
|
4456
5932
|
binary: true,
|
|
4457
|
-
tests: ["#usda", "PK"],
|
|
5933
|
+
tests: ["#usda", "PXR-USDC", "PK"],
|
|
4458
5934
|
options: {
|
|
4459
5935
|
usd: {
|
|
4460
5936
|
compose: true,
|
|
@@ -4493,124 +5969,22 @@ var init_obj_format = __esm({
|
|
|
4493
5969
|
}
|
|
4494
5970
|
});
|
|
4495
5971
|
|
|
4496
|
-
// ../core/src/
|
|
4497
|
-
function splitArrowBuffers(input, options = {}) {
|
|
4498
|
-
const context = { ...options, copies: /* @__PURE__ */ new WeakMap() };
|
|
4499
|
-
if (isArrowTable(input)) {
|
|
4500
|
-
return splitArrowTableBuffersInternal(input, context);
|
|
4501
|
-
}
|
|
4502
|
-
if (isArrowRecordBatch(input)) {
|
|
4503
|
-
return splitArrowRecordBatchBuffers(input, context);
|
|
4504
|
-
}
|
|
4505
|
-
if (isArrowVector(input)) {
|
|
4506
|
-
return splitArrowVectorBuffers(input, context);
|
|
4507
|
-
}
|
|
4508
|
-
return splitArrowDataBuffers(input, context);
|
|
4509
|
-
}
|
|
4510
|
-
function isArrowTable(input) {
|
|
4511
|
-
return "batches" in input;
|
|
4512
|
-
}
|
|
4513
|
-
function isArrowRecordBatch(input) {
|
|
4514
|
-
return "schema" in input && "data" in input && !Array.isArray(input.data);
|
|
4515
|
-
}
|
|
4516
|
-
function isArrowVector(input) {
|
|
4517
|
-
return "data" in input && Array.isArray(input.data);
|
|
4518
|
-
}
|
|
4519
|
-
function splitArrowTableBuffersInternal(table, options) {
|
|
4520
|
-
const recordBatches = table.batches.map(
|
|
4521
|
-
(recordBatch) => splitArrowRecordBatchBuffers(recordBatch, options)
|
|
4522
|
-
);
|
|
4523
|
-
return new arrow6.Table(table.schema, recordBatches);
|
|
4524
|
-
}
|
|
4525
|
-
function splitArrowRecordBatchBuffers(recordBatch, options) {
|
|
4526
|
-
return new arrow6.RecordBatch(
|
|
4527
|
-
recordBatch.schema,
|
|
4528
|
-
splitArrowDataBuffers(recordBatch.data, options)
|
|
4529
|
-
);
|
|
4530
|
-
}
|
|
4531
|
-
function splitArrowDataBuffers(data, options) {
|
|
4532
|
-
const children = data.children.map((childData) => splitArrowDataBuffers(childData, options));
|
|
4533
|
-
const dictionary = data.dictionary ? splitArrowVectorBuffers(data.dictionary, options) : void 0;
|
|
4534
|
-
const buffers = {
|
|
4535
|
-
[arrow6.BufferType.OFFSET]: splitArrowBuffer(data.buffers[arrow6.BufferType.OFFSET], options),
|
|
4536
|
-
[arrow6.BufferType.DATA]: splitArrowBuffer(data.buffers[arrow6.BufferType.DATA], options),
|
|
4537
|
-
[arrow6.BufferType.VALIDITY]: splitArrowBuffer(data.buffers[arrow6.BufferType.VALIDITY], options),
|
|
4538
|
-
[arrow6.BufferType.TYPE]: splitArrowBuffer(data.buffers[arrow6.BufferType.TYPE], options)
|
|
4539
|
-
};
|
|
4540
|
-
return new arrow6.Data(
|
|
4541
|
-
data.type,
|
|
4542
|
-
data.offset,
|
|
4543
|
-
data.length,
|
|
4544
|
-
// @ts-expect-error _nullCount is protected. Reuse it to preserve lazy null-count state.
|
|
4545
|
-
data._nullCount,
|
|
4546
|
-
buffers,
|
|
4547
|
-
children,
|
|
4548
|
-
dictionary
|
|
4549
|
-
);
|
|
4550
|
-
}
|
|
4551
|
-
function splitArrowVectorBuffers(vector, options) {
|
|
4552
|
-
return new arrow6.Vector(vector.data.map((data) => splitArrowDataBuffers(data, options)));
|
|
4553
|
-
}
|
|
4554
|
-
function splitArrowBuffer(array, options) {
|
|
4555
|
-
if (!isArrowTypedArray(array)) {
|
|
4556
|
-
return array;
|
|
4557
|
-
}
|
|
4558
|
-
if (options.copy === "none") {
|
|
4559
|
-
return array;
|
|
4560
|
-
}
|
|
4561
|
-
if (options.copy !== "all" && array.byteOffset === 0 && array.byteLength === array.buffer.byteLength) {
|
|
4562
|
-
return array;
|
|
4563
|
-
}
|
|
4564
|
-
let copy = options.copies.get(array);
|
|
4565
|
-
if (!copy) {
|
|
4566
|
-
copy = array.slice();
|
|
4567
|
-
options.copies.set(array, copy);
|
|
4568
|
-
}
|
|
4569
|
-
return copy;
|
|
4570
|
-
}
|
|
4571
|
-
function isArrowTypedArray(value) {
|
|
4572
|
-
return ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
4573
|
-
}
|
|
4574
|
-
var arrow6;
|
|
4575
|
-
var init_split_arrow_buffers = __esm({
|
|
4576
|
-
"../core/src/schema-utils/lib/arrow/split-arrow-buffers.ts"() {
|
|
4577
|
-
"use strict";
|
|
4578
|
-
arrow6 = __toESM(require("apache-arrow"), 1);
|
|
4579
|
-
}
|
|
4580
|
-
});
|
|
4581
|
-
|
|
4582
|
-
// ../core/src/schema-utils/lib/arrow/arrow-table-transport.ts
|
|
4583
|
-
function dehydrateArrowTable(table, options) {
|
|
4584
|
-
const splitTable = splitArrowBuffers(table, options);
|
|
4585
|
-
return {
|
|
4586
|
-
shape: "arrow-table",
|
|
4587
|
-
transport: "arrow-js",
|
|
4588
|
-
schema: serializeArrowSchema(splitTable.schema),
|
|
4589
|
-
batches: splitTable.batches.map((recordBatch) => dehydrateArrowRecordBatch(recordBatch))
|
|
4590
|
-
};
|
|
4591
|
-
}
|
|
4592
|
-
function hydrateArrowTable(table) {
|
|
4593
|
-
const schema = deserializeArrowSchema(table.schema);
|
|
4594
|
-
const recordBatches = table.batches.map(
|
|
4595
|
-
(recordBatch) => new arrow7.RecordBatch(schema, hydrateArrowData(recordBatch.data))
|
|
4596
|
-
);
|
|
4597
|
-
return new arrow7.Table(schema, recordBatches);
|
|
4598
|
-
}
|
|
5972
|
+
// ../core/src/arrow-worker-transport.ts
|
|
4599
5973
|
function serializeArrowWorkerTable(result) {
|
|
4600
5974
|
if (!isArrowTableWrapper(result)) {
|
|
4601
5975
|
throw new Error("Workers require Arrow table output");
|
|
4602
5976
|
}
|
|
4603
|
-
const { data, ...
|
|
5977
|
+
const { data, ...metadata3 } = result;
|
|
4604
5978
|
return {
|
|
4605
|
-
...structuredClone(
|
|
4606
|
-
data: dehydrateArrowTable(data, { copy: "all" })
|
|
5979
|
+
...structuredClone(metadata3),
|
|
5980
|
+
data: (0, import_arrow.dehydrateArrowTable)(data, { copy: "all" })
|
|
4607
5981
|
};
|
|
4608
5982
|
}
|
|
4609
5983
|
function deserializeArrowWorkerTable(result) {
|
|
4610
5984
|
if (!isDehydratedArrowTableWrapper(result)) {
|
|
4611
5985
|
throw new Error("Workers require Arrow column transport");
|
|
4612
5986
|
}
|
|
4613
|
-
return { ...result, data: hydrateArrowTable(result.data) };
|
|
5987
|
+
return { ...result, data: (0, import_arrow.hydrateArrowTable)(result.data) };
|
|
4614
5988
|
}
|
|
4615
5989
|
function serializeArrowWorkerResult(result, options) {
|
|
4616
5990
|
var _a;
|
|
@@ -4621,14 +5995,14 @@ function serializeArrowWorkerResult(result, options) {
|
|
|
4621
5995
|
const bufferCopyMode = ((_a = workerOptions == null ? void 0 : workerOptions.core) == null ? void 0 : _a.workerTransferBufferCopy) ?? (workerOptions == null ? void 0 : workerOptions.workerTransferBufferCopy);
|
|
4622
5996
|
return {
|
|
4623
5997
|
...result,
|
|
4624
|
-
data: dehydrateArrowTable(result.data, bufferCopyMode ? { copy: bufferCopyMode } : void 0)
|
|
5998
|
+
data: (0, import_arrow.dehydrateArrowTable)(result.data, bufferCopyMode ? { copy: bufferCopyMode } : void 0)
|
|
4625
5999
|
};
|
|
4626
6000
|
}
|
|
4627
6001
|
function deserializeArrowWorkerResult(result) {
|
|
4628
6002
|
if (!isDehydratedArrowTableWrapper(result)) {
|
|
4629
6003
|
return result;
|
|
4630
6004
|
}
|
|
4631
|
-
return { ...result, data: hydrateArrowTable(result.data) };
|
|
6005
|
+
return { ...result, data: (0, import_arrow.hydrateArrowTable)(result.data) };
|
|
4632
6006
|
}
|
|
4633
6007
|
function isArrowTableWrapper(value) {
|
|
4634
6008
|
const table = value;
|
|
@@ -4642,70 +6016,20 @@ function isDehydratedArrowTableWrapper(value) {
|
|
|
4642
6016
|
table && table.shape === "arrow-table" && table.data && table.data.transport === "arrow-js" && Array.isArray(table.data.batches)
|
|
4643
6017
|
);
|
|
4644
6018
|
}
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
function dehydrateArrowData(data) {
|
|
4649
|
-
return {
|
|
4650
|
-
type: serializeArrowType(data.type),
|
|
4651
|
-
offset: data.offset,
|
|
4652
|
-
length: data.length,
|
|
4653
|
-
// @ts-expect-error _nullCount is protected. Preserve the Arrow lazy null-count state.
|
|
4654
|
-
nullCount: data._nullCount,
|
|
4655
|
-
buffers: {
|
|
4656
|
-
[arrow7.BufferType.OFFSET]: data.buffers[arrow7.BufferType.OFFSET],
|
|
4657
|
-
[arrow7.BufferType.DATA]: data.buffers[arrow7.BufferType.DATA],
|
|
4658
|
-
[arrow7.BufferType.VALIDITY]: data.buffers[arrow7.BufferType.VALIDITY],
|
|
4659
|
-
[arrow7.BufferType.TYPE]: data.buffers[arrow7.BufferType.TYPE]
|
|
4660
|
-
},
|
|
4661
|
-
children: data.children.map((childData) => dehydrateArrowData(childData)),
|
|
4662
|
-
dictionary: data.dictionary ? dehydrateArrowVector(data.dictionary) : void 0
|
|
4663
|
-
};
|
|
4664
|
-
}
|
|
4665
|
-
function dehydrateArrowVector(vector) {
|
|
4666
|
-
return { data: vector.data.map((data) => dehydrateArrowData(data)) };
|
|
4667
|
-
}
|
|
4668
|
-
function hydrateArrowData(data) {
|
|
4669
|
-
const children = data.children.map((childData) => hydrateArrowData(childData));
|
|
4670
|
-
const dictionary = data.dictionary ? hydrateArrowVector(data.dictionary) : void 0;
|
|
4671
|
-
return new arrow7.Data(
|
|
4672
|
-
deserializeArrowType(data.type),
|
|
4673
|
-
data.offset,
|
|
4674
|
-
data.length,
|
|
4675
|
-
data.nullCount,
|
|
4676
|
-
data.buffers,
|
|
4677
|
-
children,
|
|
4678
|
-
dictionary
|
|
4679
|
-
);
|
|
4680
|
-
}
|
|
4681
|
-
function hydrateArrowVector(vector) {
|
|
4682
|
-
return new arrow7.Vector(vector.data.map((data) => hydrateArrowData(data)));
|
|
4683
|
-
}
|
|
4684
|
-
var arrow7;
|
|
4685
|
-
var init_arrow_table_transport = __esm({
|
|
4686
|
-
"../core/src/schema-utils/lib/arrow/arrow-table-transport.ts"() {
|
|
6019
|
+
var import_arrow;
|
|
6020
|
+
var init_arrow_worker_transport = __esm({
|
|
6021
|
+
"../core/src/arrow-worker-transport.ts"() {
|
|
4687
6022
|
"use strict";
|
|
4688
|
-
|
|
4689
|
-
init_convert_arrow_schema();
|
|
4690
|
-
init_split_arrow_buffers();
|
|
4691
|
-
}
|
|
4692
|
-
});
|
|
4693
|
-
|
|
4694
|
-
// ../core/src/schema-utils/arrow-transport.ts
|
|
4695
|
-
var init_arrow_transport = __esm({
|
|
4696
|
-
"../core/src/schema-utils/arrow-transport.ts"() {
|
|
4697
|
-
"use strict";
|
|
4698
|
-
init_arrow_table_transport();
|
|
4699
|
-
init_split_arrow_buffers();
|
|
6023
|
+
import_arrow = require("@math.gl/arrow");
|
|
4700
6024
|
}
|
|
4701
6025
|
});
|
|
4702
6026
|
|
|
4703
6027
|
// ../scene/src/obj/lib/get-obj-schema.ts
|
|
4704
|
-
function getOBJSchema(attributes,
|
|
6028
|
+
function getOBJSchema(attributes, metadata3 = {}) {
|
|
4705
6029
|
const stringMetadata = {};
|
|
4706
|
-
for (const key in
|
|
6030
|
+
for (const key in metadata3) {
|
|
4707
6031
|
if (key !== "value") {
|
|
4708
|
-
stringMetadata[key] = JSON.stringify(
|
|
6032
|
+
stringMetadata[key] = JSON.stringify(metadata3[key]);
|
|
4709
6033
|
}
|
|
4710
6034
|
}
|
|
4711
6035
|
const fields = [];
|
|
@@ -4717,10 +6041,10 @@ function getOBJSchema(attributes, metadata2 = {}) {
|
|
|
4717
6041
|
return { fields, metadata: stringMetadata };
|
|
4718
6042
|
}
|
|
4719
6043
|
function getFieldFromAttribute(name22, attribute) {
|
|
4720
|
-
const
|
|
6044
|
+
const metadata3 = {};
|
|
4721
6045
|
for (const key in attribute) {
|
|
4722
6046
|
if (key !== "value") {
|
|
4723
|
-
|
|
6047
|
+
metadata3[key] = JSON.stringify(attribute[key]);
|
|
4724
6048
|
}
|
|
4725
6049
|
}
|
|
4726
6050
|
let { type } = getDataTypeFromArray(attribute.value);
|
|
@@ -4728,7 +6052,7 @@ function getFieldFromAttribute(name22, attribute) {
|
|
|
4728
6052
|
if (!isSingleValue) {
|
|
4729
6053
|
type = { type: "fixed-size-list", listSize: attribute.size, children: [{ name: "values", type }] };
|
|
4730
6054
|
}
|
|
4731
|
-
return { name: name22, type, nullable: false, metadata:
|
|
6055
|
+
return { name: name22, type, nullable: false, metadata: metadata3 };
|
|
4732
6056
|
}
|
|
4733
6057
|
var init_get_obj_schema = __esm({
|
|
4734
6058
|
"../scene/src/obj/lib/get-obj-schema.ts"() {
|
|
@@ -5291,7 +6615,7 @@ var init_obj_loader = __esm({
|
|
|
5291
6615
|
"../scene/src/obj/obj-loader.ts"() {
|
|
5292
6616
|
"use strict";
|
|
5293
6617
|
init_loader_utils();
|
|
5294
|
-
|
|
6618
|
+
init_arrow_worker_transport();
|
|
5295
6619
|
init_schema_utils();
|
|
5296
6620
|
init_get_obj_schema();
|
|
5297
6621
|
init_parse_obj();
|
|
@@ -5339,7 +6663,7 @@ var init_obj_loader_types = __esm({
|
|
|
5339
6663
|
"../scene/src/obj/obj-loader-types.ts"() {
|
|
5340
6664
|
"use strict";
|
|
5341
6665
|
init_obj_format();
|
|
5342
|
-
|
|
6666
|
+
init_arrow_worker_transport();
|
|
5343
6667
|
VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
5344
6668
|
OBJLoader = {
|
|
5345
6669
|
...OBJFormat,
|
|
@@ -5818,8 +7142,8 @@ function parseGLBChunksSync(glb, dataView, byteOffset, chunkHeaderSize, options)
|
|
|
5818
7142
|
}
|
|
5819
7143
|
function parseJSONChunk(glb, dataView, byteOffset, chunkLength, chunkIndex) {
|
|
5820
7144
|
const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
|
|
5821
|
-
const
|
|
5822
|
-
const jsonText =
|
|
7145
|
+
const textDecoder2 = new TextDecoder("utf8");
|
|
7146
|
+
const jsonText = textDecoder2.decode(jsonChunk);
|
|
5823
7147
|
glb.json = JSON.parse(jsonText);
|
|
5824
7148
|
glb.jsonChunkIndex = chunkIndex;
|
|
5825
7149
|
return padToFourBytes(chunkLength);
|
|
@@ -6609,8 +7933,8 @@ var init_gltf_scenegraph = __esm({
|
|
|
6609
7933
|
* @param mimeType
|
|
6610
7934
|
*/
|
|
6611
7935
|
addImage(imageData, mimeTypeOpt) {
|
|
6612
|
-
const
|
|
6613
|
-
const mimeType = mimeTypeOpt || (
|
|
7936
|
+
const metadata3 = getBinaryImageMetadata(imageData);
|
|
7937
|
+
const mimeType = mimeTypeOpt || (metadata3 == null ? void 0 : metadata3.mimeType);
|
|
6614
7938
|
const bufferViewIndex = this.addBufferView(imageData);
|
|
6615
7939
|
const glTFImage = {
|
|
6616
7940
|
bufferView: bufferViewIndex,
|
|
@@ -7493,8 +8817,8 @@ var init_gltf_iterator = __esm({
|
|
|
7493
8817
|
}
|
|
7494
8818
|
/** Return the loaded buffer companion for a raw buffer definition. */
|
|
7495
8819
|
getLoadedBuffer(buffer) {
|
|
7496
|
-
const
|
|
7497
|
-
return this.gltf.buffers[
|
|
8820
|
+
const metadata3 = this.getMetadata(buffer);
|
|
8821
|
+
return this.gltf.buffers[metadata3.index];
|
|
7498
8822
|
}
|
|
7499
8823
|
/** Return the loaded byte range for a raw buffer-view definition. */
|
|
7500
8824
|
getLoadedBufferView(bufferView) {
|
|
@@ -8049,7 +9373,7 @@ function parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount,
|
|
|
8049
9373
|
return attributeValueArray;
|
|
8050
9374
|
}
|
|
8051
9375
|
function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets, fixedArrayCount) {
|
|
8052
|
-
const
|
|
9376
|
+
const textDecoder2 = new TextDecoder("utf8");
|
|
8053
9377
|
if (arrayOffsets) {
|
|
8054
9378
|
if (!stringOffsets) {
|
|
8055
9379
|
throw new Error("stringOffsets is required for variable-length string arrays");
|
|
@@ -8063,7 +9387,7 @@ function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets,
|
|
|
8063
9387
|
const startByte = stringOffsets[stringIndex];
|
|
8064
9388
|
const endByte = stringOffsets[stringIndex + 1];
|
|
8065
9389
|
const stringData = valuesDataBytes.subarray(startByte, endByte);
|
|
8066
|
-
strings.push(
|
|
9390
|
+
strings.push(textDecoder2.decode(stringData));
|
|
8067
9391
|
}
|
|
8068
9392
|
result.push(strings);
|
|
8069
9393
|
}
|
|
@@ -8076,7 +9400,7 @@ function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets,
|
|
|
8076
9400
|
const startByte = Number(stringOffsets[index]);
|
|
8077
9401
|
const endByte = Number(stringOffsets[index + 1]);
|
|
8078
9402
|
if (startByte >= 0 && endByte >= startByte && endByte <= valuesDataBytes.length) {
|
|
8079
|
-
stringsArray.push(
|
|
9403
|
+
stringsArray.push(textDecoder2.decode(valuesDataBytes.subarray(startByte, endByte)));
|
|
8080
9404
|
}
|
|
8081
9405
|
}
|
|
8082
9406
|
return fixedArrayCount ? Array.from(
|
|
@@ -8969,7 +10293,7 @@ __export(KHR_gaussian_splatting_exports, {
|
|
|
8969
10293
|
name: () => name4
|
|
8970
10294
|
});
|
|
8971
10295
|
async function decode3(gltfData, options, context) {
|
|
8972
|
-
var _a, _b, _c, _d, _e;
|
|
10296
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
8973
10297
|
const loader = (_a = context == null ? void 0 : context.loaders) == null ? void 0 : _a.find((candidate) => {
|
|
8974
10298
|
var _a2;
|
|
8975
10299
|
return (_a2 = candidate.extensions) == null ? void 0 : _a2.includes("spz");
|
|
@@ -8980,22 +10304,29 @@ async function decode3(gltfData, options, context) {
|
|
|
8980
10304
|
for (const [primitiveIndex, primitive] of mesh.primitives.entries()) {
|
|
8981
10305
|
const extension = (_b = primitive.extensions) == null ? void 0 : _b[name4];
|
|
8982
10306
|
if (!extension) continue;
|
|
10307
|
+
const descriptor = descriptors.find(
|
|
10308
|
+
(item) => item.meshIndex === meshIndex && item.primitiveIndex === primitiveIndex
|
|
10309
|
+
);
|
|
10310
|
+
const legacyColorSpace = (_c = options == null ? void 0 : options.gltf) == null ? void 0 : _c.legacyGaussianSplatColorSpace;
|
|
10311
|
+
const normalizedExtension = legacyColorSpace && ((_d = extension.extensions) == null ? void 0 : _d[SPZ_COMPRESSION_EXTENSION_NAME]) ? {
|
|
10312
|
+
...extension,
|
|
10313
|
+
kernel: extension.kernel ?? "ellipse",
|
|
10314
|
+
colorSpace: extension.colorSpace ?? legacyColorSpace
|
|
10315
|
+
} : extension;
|
|
10316
|
+
if (descriptor) descriptor.extension = normalizedExtension;
|
|
8983
10317
|
validateGaussianSplatPrimitive(
|
|
8984
10318
|
gltfData.json,
|
|
8985
10319
|
primitive,
|
|
8986
|
-
|
|
10320
|
+
normalizedExtension,
|
|
8987
10321
|
meshIndex,
|
|
8988
10322
|
primitiveIndex,
|
|
8989
10323
|
iterator
|
|
8990
10324
|
);
|
|
8991
|
-
const compression = (
|
|
10325
|
+
const compression = (_e = extension.extensions) == null ? void 0 : _e[SPZ_COMPRESSION_EXTENSION_NAME];
|
|
8992
10326
|
if (compression) {
|
|
8993
|
-
const descriptor = descriptors.find(
|
|
8994
|
-
(item) => item.meshIndex === meshIndex && item.primitiveIndex === primitiveIndex
|
|
8995
|
-
);
|
|
8996
10327
|
if (descriptor) {
|
|
8997
|
-
const decoder = (
|
|
8998
|
-
const bufferView = (
|
|
10328
|
+
const decoder = (_f = options == null ? void 0 : options.gltf) == null ? void 0 : _f.splatDecoder;
|
|
10329
|
+
const bufferView = (_g = gltfData.json.bufferViews) == null ? void 0 : _g[compression.bufferView];
|
|
8999
10330
|
if (bufferView && gltfData.buffers[bufferView.buffer]) {
|
|
9000
10331
|
descriptor.compressedBytes = getBufferViewBytes(gltfData, compression.bufferView);
|
|
9001
10332
|
} else if (decoder || loader) {
|
|
@@ -10572,7 +11903,7 @@ var init_draco_module_loader = __esm({
|
|
|
10572
11903
|
|
|
10573
11904
|
// ../scene/src/draco/lib/utils/get-draco-schema.ts
|
|
10574
11905
|
function getDracoSchema(attributes, loaderData, indices) {
|
|
10575
|
-
const
|
|
11906
|
+
const metadata3 = makeMetadata(loaderData.metadata);
|
|
10576
11907
|
const fields = [];
|
|
10577
11908
|
const namedLoaderDataAttributes = transformAttributesLoaderData(loaderData.attributes);
|
|
10578
11909
|
for (const attributeName in attributes) {
|
|
@@ -10588,7 +11919,7 @@ function getDracoSchema(attributes, loaderData, indices) {
|
|
|
10588
11919
|
const indicesField = getArrowFieldFromAttribute("indices", indices);
|
|
10589
11920
|
fields.push(indicesField);
|
|
10590
11921
|
}
|
|
10591
|
-
return { fields, metadata:
|
|
11922
|
+
return { fields, metadata: metadata3 };
|
|
10592
11923
|
}
|
|
10593
11924
|
function transformAttributesLoaderData(loaderData) {
|
|
10594
11925
|
const result = {};
|
|
@@ -10606,11 +11937,11 @@ function getArrowFieldFromAttribute(attributeName, attribute, loaderData) {
|
|
|
10606
11937
|
const field = deduceMeshField(attributeName, attribute, metadataMap);
|
|
10607
11938
|
return field;
|
|
10608
11939
|
}
|
|
10609
|
-
function makeMetadata(
|
|
10610
|
-
Object.entries(
|
|
11940
|
+
function makeMetadata(metadata3) {
|
|
11941
|
+
Object.entries(metadata3);
|
|
10611
11942
|
const serializedMetadata = {};
|
|
10612
|
-
for (const key in
|
|
10613
|
-
serializedMetadata[`${key}.string`] = JSON.stringify(
|
|
11943
|
+
for (const key in metadata3) {
|
|
11944
|
+
serializedMetadata[`${key}.string`] = JSON.stringify(metadata3[key]);
|
|
10614
11945
|
}
|
|
10615
11946
|
return serializedMetadata;
|
|
10616
11947
|
}
|
|
@@ -10829,14 +12160,14 @@ var init_draco_parser = __esm({
|
|
|
10829
12160
|
* @returns
|
|
10830
12161
|
*/
|
|
10831
12162
|
_getDracoLoaderData(dracoGeometry, geometry_type, options) {
|
|
10832
|
-
const
|
|
12163
|
+
const metadata3 = this._getTopLevelMetadata(dracoGeometry);
|
|
10833
12164
|
const attributes = this._getDracoAttributes(dracoGeometry, options);
|
|
10834
12165
|
return {
|
|
10835
12166
|
geometry_type,
|
|
10836
12167
|
num_attributes: dracoGeometry.num_attributes(),
|
|
10837
12168
|
num_points: dracoGeometry.num_points(),
|
|
10838
12169
|
num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
|
|
10839
|
-
metadata:
|
|
12170
|
+
metadata: metadata3,
|
|
10840
12171
|
attributes
|
|
10841
12172
|
};
|
|
10842
12173
|
}
|
|
@@ -10850,7 +12181,7 @@ var init_draco_parser = __esm({
|
|
|
10850
12181
|
const dracoAttributes = {};
|
|
10851
12182
|
for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
|
|
10852
12183
|
const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
|
|
10853
|
-
const
|
|
12184
|
+
const metadata3 = this._getAttributeMetadata(dracoGeometry, attributeId);
|
|
10854
12185
|
dracoAttributes[dracoAttribute.unique_id()] = {
|
|
10855
12186
|
unique_id: dracoAttribute.unique_id(),
|
|
10856
12187
|
attribute_type: dracoAttribute.attribute_type(),
|
|
@@ -10860,7 +12191,7 @@ var init_draco_parser = __esm({
|
|
|
10860
12191
|
byte_stride: dracoAttribute.byte_stride(),
|
|
10861
12192
|
normalized: dracoAttribute.normalized(),
|
|
10862
12193
|
attribute_index: attributeId,
|
|
10863
|
-
metadata:
|
|
12194
|
+
metadata: metadata3
|
|
10864
12195
|
};
|
|
10865
12196
|
const quantization = this._getQuantizationTransform(dracoAttribute, options);
|
|
10866
12197
|
if (quantization) {
|
|
@@ -11379,7 +12710,7 @@ var DracoLoader, DracoWorkerLoader;
|
|
|
11379
12710
|
var init_draco_loader_types = __esm({
|
|
11380
12711
|
"../scene/src/draco/draco-loader-types.ts"() {
|
|
11381
12712
|
"use strict";
|
|
11382
|
-
|
|
12713
|
+
init_arrow_worker_transport();
|
|
11383
12714
|
init_version4();
|
|
11384
12715
|
init_draco_format();
|
|
11385
12716
|
init_draco_loader_options();
|
|
@@ -11959,10 +13290,10 @@ async function encode5(gltfData, options) {
|
|
|
11959
13290
|
}
|
|
11960
13291
|
function resolveTechniques(techniquesExtension, iterator) {
|
|
11961
13292
|
const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
|
|
11962
|
-
const
|
|
13293
|
+
const textDecoder2 = new TextDecoder();
|
|
11963
13294
|
shaders.forEach((shader) => {
|
|
11964
13295
|
if (Number.isFinite(shader.bufferView)) {
|
|
11965
|
-
shader.code =
|
|
13296
|
+
shader.code = textDecoder2.decode(
|
|
11966
13297
|
getTypedArrayForBufferView(iterator.data, iterator.gltf.buffers, shader.bufferView)
|
|
11967
13298
|
);
|
|
11968
13299
|
} else {
|
|
@@ -14619,8 +15950,8 @@ function parseGLTFContainerSync(gltf, data, byteOffset, options) {
|
|
|
14619
15950
|
gltf.baseUri = (_b = options.core) == null ? void 0 : _b.baseUrl;
|
|
14620
15951
|
}
|
|
14621
15952
|
if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options.glb)) {
|
|
14622
|
-
const
|
|
14623
|
-
data =
|
|
15953
|
+
const textDecoder2 = new TextDecoder();
|
|
15954
|
+
data = textDecoder2.decode(data);
|
|
14624
15955
|
}
|
|
14625
15956
|
if (typeof data === "string") {
|
|
14626
15957
|
gltf.json = parseJSON(data);
|
|
@@ -15748,9 +17079,9 @@ var init_draco_builder = __esm({
|
|
|
15748
17079
|
* @param dracoGeometry - WASM Draco Object
|
|
15749
17080
|
* @param metadata
|
|
15750
17081
|
*/
|
|
15751
|
-
_addGeometryMetadata(dracoGeometry,
|
|
17082
|
+
_addGeometryMetadata(dracoGeometry, metadata3) {
|
|
15752
17083
|
const dracoMetadata = new this.draco.Metadata();
|
|
15753
|
-
this._populateDracoMetadata(dracoMetadata,
|
|
17084
|
+
this._populateDracoMetadata(dracoMetadata, metadata3);
|
|
15754
17085
|
this.dracoMeshBuilder.AddMetadata(dracoGeometry, dracoMetadata);
|
|
15755
17086
|
}
|
|
15756
17087
|
/**
|
|
@@ -15759,9 +17090,9 @@ var init_draco_builder = __esm({
|
|
|
15759
17090
|
* @param uniqueAttributeId
|
|
15760
17091
|
* @param metadata
|
|
15761
17092
|
*/
|
|
15762
|
-
_addAttributeMetadata(dracoGeometry, uniqueAttributeId,
|
|
17093
|
+
_addAttributeMetadata(dracoGeometry, uniqueAttributeId, metadata3) {
|
|
15763
17094
|
const dracoAttributeMetadata = new this.draco.Metadata();
|
|
15764
|
-
this._populateDracoMetadata(dracoAttributeMetadata,
|
|
17095
|
+
this._populateDracoMetadata(dracoAttributeMetadata, metadata3);
|
|
15765
17096
|
this.dracoMeshBuilder.SetMetadataForAttribute(
|
|
15766
17097
|
dracoGeometry,
|
|
15767
17098
|
uniqueAttributeId,
|
|
@@ -15773,8 +17104,8 @@ var init_draco_builder = __esm({
|
|
|
15773
17104
|
* @param dracoMetadata - WASM Draco Object
|
|
15774
17105
|
* @param metadata
|
|
15775
17106
|
*/
|
|
15776
|
-
_populateDracoMetadata(dracoMetadata,
|
|
15777
|
-
for (const [key, value] of getEntries(
|
|
17107
|
+
_populateDracoMetadata(dracoMetadata, metadata3) {
|
|
17108
|
+
for (const [key, value] of getEntries(metadata3)) {
|
|
15778
17109
|
switch (typeof value) {
|
|
15779
17110
|
case "number":
|
|
15780
17111
|
if (Math.trunc(value) === value) {
|
|
@@ -17988,6 +19319,132 @@ var init_materialx_loader_types = __esm({
|
|
|
17988
19319
|
}
|
|
17989
19320
|
});
|
|
17990
19321
|
|
|
19322
|
+
// ../scene/src/stl/parse-stl.ts
|
|
19323
|
+
function parseSTL(data) {
|
|
19324
|
+
const view = new DataView(data);
|
|
19325
|
+
const binary = data.byteLength >= 84 && 84 + view.getUint32(80, true) * 50 === data.byteLength;
|
|
19326
|
+
let positions;
|
|
19327
|
+
let normals;
|
|
19328
|
+
let header;
|
|
19329
|
+
if (binary) {
|
|
19330
|
+
const triangleCount = view.getUint32(80, true);
|
|
19331
|
+
positions = new Float32Array(triangleCount * 9);
|
|
19332
|
+
normals = new Float32Array(triangleCount * 9);
|
|
19333
|
+
header = new TextDecoder().decode(data.slice(0, 80));
|
|
19334
|
+
for (let triangle = 0; triangle < triangleCount; triangle++) {
|
|
19335
|
+
const offset = 84 + triangle * 50;
|
|
19336
|
+
for (let component = 0; component < 9; component++) {
|
|
19337
|
+
positions[triangle * 9 + component] = view.getFloat32(offset + 12 + component * 4, true);
|
|
19338
|
+
normals[triangle * 9 + component] = view.getFloat32(offset + component % 3 * 4, true);
|
|
19339
|
+
}
|
|
19340
|
+
}
|
|
19341
|
+
} else {
|
|
19342
|
+
const lines = new TextDecoder().decode(data).trim().split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
19343
|
+
const vertices = [];
|
|
19344
|
+
const normalValues = [];
|
|
19345
|
+
header = lines[0] || "";
|
|
19346
|
+
let lineIndex = 0;
|
|
19347
|
+
while (lineIndex < lines.length) {
|
|
19348
|
+
if (!/^solid(?:\s|$)/i.test(lines[lineIndex++]))
|
|
19349
|
+
throw new Error("STL: expected solid header or exact binary length");
|
|
19350
|
+
while (lineIndex < lines.length && !/^endsolid(?:\s|$)/i.test(lines[lineIndex])) {
|
|
19351
|
+
const normal = parseVector(lines[lineIndex++], "facet normal");
|
|
19352
|
+
if (!/^outer\s+loop$/i.test(lines[lineIndex++] || ""))
|
|
19353
|
+
throw new Error("STL: expected outer loop");
|
|
19354
|
+
for (let vertex = 0; vertex < 3; vertex++) {
|
|
19355
|
+
vertices.push(...parseVector(lines[lineIndex++], "vertex"));
|
|
19356
|
+
normalValues.push(...normal);
|
|
19357
|
+
}
|
|
19358
|
+
if (!/^endloop$/i.test(lines[lineIndex++] || "") || !/^endfacet$/i.test(lines[lineIndex++] || ""))
|
|
19359
|
+
throw new Error("STL: incomplete facet");
|
|
19360
|
+
}
|
|
19361
|
+
if (lineIndex >= lines.length) throw new Error("STL: missing endsolid");
|
|
19362
|
+
lineIndex++;
|
|
19363
|
+
}
|
|
19364
|
+
if (!lines.length) throw new Error("STL: empty input");
|
|
19365
|
+
positions = new Float32Array(vertices);
|
|
19366
|
+
normals = new Float32Array(normalValues);
|
|
19367
|
+
}
|
|
19368
|
+
if (!positions.every(Number.isFinite) || !normals.every(Number.isFinite))
|
|
19369
|
+
throw new Error("STL: non-finite coordinates");
|
|
19370
|
+
const attributes = { POSITION: { value: positions, size: 3 }, NORMAL: { value: normals, size: 3 } };
|
|
19371
|
+
return {
|
|
19372
|
+
topology: "triangle-list",
|
|
19373
|
+
mode: 4,
|
|
19374
|
+
attributes,
|
|
19375
|
+
schema: deduceMeshSchema(attributes),
|
|
19376
|
+
header: {
|
|
19377
|
+
vertexCount: positions.length / 3,
|
|
19378
|
+
boundingBox: getMeshBoundingBox(attributes) ?? void 0
|
|
19379
|
+
},
|
|
19380
|
+
loaderData: { header, format: binary ? "binary" : "ascii" }
|
|
19381
|
+
};
|
|
19382
|
+
}
|
|
19383
|
+
function parseVector(line, prefix) {
|
|
19384
|
+
const tokens = (line == null ? void 0 : line.split(/\s+/)) || [];
|
|
19385
|
+
const prefixTokens = prefix.split(" ");
|
|
19386
|
+
const components = tokens.slice(prefixTokens.length);
|
|
19387
|
+
if (prefixTokens.some((token, index) => {
|
|
19388
|
+
var _a;
|
|
19389
|
+
return ((_a = tokens[index]) == null ? void 0 : _a.toLowerCase()) !== token;
|
|
19390
|
+
}) || components.length !== 3 || components.some((value) => !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(value))) {
|
|
19391
|
+
throw new Error(`STL: invalid ${prefix} record`);
|
|
19392
|
+
}
|
|
19393
|
+
return components.map(Number);
|
|
19394
|
+
}
|
|
19395
|
+
var init_parse_stl = __esm({
|
|
19396
|
+
"../scene/src/stl/parse-stl.ts"() {
|
|
19397
|
+
"use strict";
|
|
19398
|
+
init_schema_utils();
|
|
19399
|
+
}
|
|
19400
|
+
});
|
|
19401
|
+
|
|
19402
|
+
// ../scene/src/stl-loader.ts
|
|
19403
|
+
var stl_loader_exports = {};
|
|
19404
|
+
__export(stl_loader_exports, {
|
|
19405
|
+
STLLoaderWithParser: () => STLLoaderWithParser
|
|
19406
|
+
});
|
|
19407
|
+
var _preload2, metadata2, STLLoaderWithParser;
|
|
19408
|
+
var init_stl_loader = __esm({
|
|
19409
|
+
"../scene/src/stl-loader.ts"() {
|
|
19410
|
+
"use strict";
|
|
19411
|
+
init_stl_loader_types();
|
|
19412
|
+
init_parse_stl();
|
|
19413
|
+
({ preload: _preload2, ...metadata2 } = STLLoader);
|
|
19414
|
+
STLLoaderWithParser = {
|
|
19415
|
+
...metadata2,
|
|
19416
|
+
parse: async (data) => parseSTL(data),
|
|
19417
|
+
parseSync: parseSTL
|
|
19418
|
+
};
|
|
19419
|
+
}
|
|
19420
|
+
});
|
|
19421
|
+
|
|
19422
|
+
// ../scene/src/stl-loader-types.ts
|
|
19423
|
+
async function preload10() {
|
|
19424
|
+
const { STLLoaderWithParser: STLLoaderWithParser2 } = await Promise.resolve().then(() => (init_stl_loader(), stl_loader_exports));
|
|
19425
|
+
return STLLoaderWithParser2;
|
|
19426
|
+
}
|
|
19427
|
+
var VERSION9, STLLoader;
|
|
19428
|
+
var init_stl_loader_types = __esm({
|
|
19429
|
+
"../scene/src/stl-loader-types.ts"() {
|
|
19430
|
+
"use strict";
|
|
19431
|
+
VERSION9 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
19432
|
+
STLLoader = {
|
|
19433
|
+
name: "STL",
|
|
19434
|
+
id: "stl",
|
|
19435
|
+
module: "scene",
|
|
19436
|
+
version: VERSION9,
|
|
19437
|
+
extensions: ["stl"],
|
|
19438
|
+
mimeTypes: ["model/stl"],
|
|
19439
|
+
binary: true,
|
|
19440
|
+
dataType: null,
|
|
19441
|
+
batchType: null,
|
|
19442
|
+
options: {},
|
|
19443
|
+
preload: preload10
|
|
19444
|
+
};
|
|
19445
|
+
}
|
|
19446
|
+
});
|
|
19447
|
+
|
|
17991
19448
|
// ../scene/src/index.ts
|
|
17992
19449
|
var src_exports = {};
|
|
17993
19450
|
__export(src_exports, {
|
|
@@ -18010,6 +19467,7 @@ __export(src_exports, {
|
|
|
18010
19467
|
OBJLoader: () => OBJLoader,
|
|
18011
19468
|
OBJWorkerLoader: () => OBJWorkerLoader,
|
|
18012
19469
|
OBJWriter: () => OBJWriter,
|
|
19470
|
+
STLLoader: () => STLLoader,
|
|
18013
19471
|
USDLoader: () => USDLoader
|
|
18014
19472
|
});
|
|
18015
19473
|
var init_src2 = __esm({
|
|
@@ -18030,6 +19488,7 @@ var init_src2 = __esm({
|
|
|
18030
19488
|
init_draco_format();
|
|
18031
19489
|
init_draco_libraries();
|
|
18032
19490
|
init_materialx_loader_types();
|
|
19491
|
+
init_stl_loader_types();
|
|
18033
19492
|
}
|
|
18034
19493
|
});
|
|
18035
19494
|
|
|
@@ -18048,12 +19507,12 @@ function prepareI3SMeshTexture(attribute, vertexCount, texture) {
|
|
|
18048
19507
|
if (texture) {
|
|
18049
19508
|
if (!(texture.data instanceof Uint8Array) || Object.keys(texture).some((name22) => !["data", "mimeType", "sampler", "transform"].includes(name22)))
|
|
18050
19509
|
throw new Error("Invalid I3S base-color texture");
|
|
18051
|
-
let
|
|
19510
|
+
let metadata3;
|
|
18052
19511
|
try {
|
|
18053
|
-
|
|
19512
|
+
metadata3 = getBinaryImageMetadata(new DataView(texture.data.buffer, texture.data.byteOffset, texture.data.byteLength));
|
|
18054
19513
|
} catch {
|
|
18055
19514
|
}
|
|
18056
|
-
if (!
|
|
19515
|
+
if (!metadata3 || metadata3.mimeType !== texture.mimeType || !["image/png", "image/jpeg"].includes(texture.mimeType) || metadata3.width <= 0 || metadata3.height <= 0)
|
|
18057
19516
|
throw new Error("I3S texture header must match a PNG/JPEG mimeType and positive dimensions");
|
|
18058
19517
|
const sampler = texture.sampler;
|
|
18059
19518
|
if (sampler && (Object.keys(sampler).some((name22) => !["wrapS", "wrapT", "magFilter", "minFilter"].includes(name22)) || sampler.magFilter !== void 0 || sampler.minFilter !== void 0 || [sampler.wrapS, sampler.wrapT].some((value) => value !== void 0 && ![33071, 33648, 10497].includes(value))))
|
|
@@ -18145,11 +19604,11 @@ var CompressUtilsCompressor = class extends Compressor {
|
|
|
18145
19604
|
/** Shared import and WASM initialization for concurrent callers. */
|
|
18146
19605
|
modulePromise = null;
|
|
18147
19606
|
/** Creates a format-specific compress-utils encoder. */
|
|
18148
|
-
constructor(
|
|
19607
|
+
constructor(metadata3, loadModule, options = {}) {
|
|
18149
19608
|
super(options);
|
|
18150
|
-
this.name =
|
|
18151
|
-
this.extensions =
|
|
18152
|
-
this.contentEncodings =
|
|
19609
|
+
this.name = metadata3.name;
|
|
19610
|
+
this.extensions = metadata3.extensions || [];
|
|
19611
|
+
this.contentEncodings = metadata3.contentEncodings || [];
|
|
18153
19612
|
this.loadModule = loadModule;
|
|
18154
19613
|
this.options = options;
|
|
18155
19614
|
}
|