@loaders.gl/tiles-3d 5.0.0-beta.4 → 5.0.0-beta.5

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