@d5techs/3dgs-lib 1.4.23 → 1.4.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/3dgs-lib.cjs CHANGED
@@ -6626,12 +6626,14 @@ async function encodeWebP(width, height, pixelData) {
6626
6626
  }
6627
6627
  return new Uint8Array(await blob.arrayBuffer());
6628
6628
  }
6629
+ const yieldToUI = () => new Promise((r) => setTimeout(r, 0));
6629
6630
  async function serializeSOG(data, coordinateSystem = "blender", options = {}, onProgress) {
6630
6631
  const { maxSHBands = 3, iterations = 10, paletteSize = 1024 } = options;
6631
6632
  const { count, colors, opacities } = data;
6632
6633
  let { positions, scales, rotations } = data;
6633
6634
  let shCoeffs = data.shCoeffs ? new Float32Array(data.shCoeffs) : void 0;
6634
- onProgress == null ? void 0 : onProgress("坐标系变换", 0);
6635
+ onProgress == null ? void 0 : onProgress("coord_transform", 0);
6636
+ await yieldToUI();
6635
6637
  if (coordinateSystem === "blender") {
6636
6638
  positions = new Float32Array(positions);
6637
6639
  scales = new Float32Array(scales);
@@ -6654,7 +6656,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6654
6656
  }
6655
6657
  }
6656
6658
  }
6657
- onProgress == null ? void 0 : onProgress("Morton 排序", 0.05);
6659
+ onProgress == null ? void 0 : onProgress("morton_sort", 0.05);
6660
+ await yieldToUI();
6658
6661
  const sortOrder = mortonSort(positions, count);
6659
6662
  const sPos = new Float32Array(count * 3);
6660
6663
  const sSca = new Float32Array(count * 3);
@@ -6687,7 +6690,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6687
6690
  }
6688
6691
  const { width, height } = calcImageDimensions(count);
6689
6692
  const totalPixels = width * height;
6690
- onProgress == null ? void 0 : onProgress("编码位置", 0.1);
6693
+ onProgress == null ? void 0 : onProgress("encode_position", 0.1);
6694
+ await yieldToUI();
6691
6695
  const logPos = new Float32Array(count * 3);
6692
6696
  for (let i = 0; i < count * 3; i++) logPos[i] = symLog(sPos[i]);
6693
6697
  const mins = [Infinity, Infinity, Infinity];
@@ -6715,7 +6719,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6715
6719
  meansLData[off + 3] = 255;
6716
6720
  meansUData[off + 3] = 255;
6717
6721
  }
6718
- onProgress == null ? void 0 : onProgress("编码缩放", 0.2);
6722
+ onProgress == null ? void 0 : onProgress("encode_scale", 0.2);
6723
+ await yieldToUI();
6719
6724
  const logScales = new Float32Array(count * 3);
6720
6725
  for (let i = 0; i < count * 3; i++) logScales[i] = Math.log(Math.max(1e-8, sSca[i]));
6721
6726
  const scaleCodebook = buildCodebook(logScales, 256);
@@ -6728,7 +6733,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6728
6733
  scalesData[off + 2] = findNearest(scaleCodebook, logScales[i * 3 + 2]);
6729
6734
  scalesData[off + 3] = 255;
6730
6735
  }
6731
- onProgress == null ? void 0 : onProgress("编码四元数", 0.3);
6736
+ onProgress == null ? void 0 : onProgress("encode_quaternion", 0.3);
6737
+ await yieldToUI();
6732
6738
  const quatsData = new Uint8ClampedArray(totalPixels * 4);
6733
6739
  quatsData.fill(255);
6734
6740
  const SQRT2 = Math.SQRT2;
@@ -6781,7 +6787,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6781
6787
  quatsData[off + 2] = Math.round(Math.max(0, Math.min(255, (r2 / SQRT2 + 0.5) * 255)));
6782
6788
  quatsData[off + 3] = largest + 252;
6783
6789
  }
6784
- onProgress == null ? void 0 : onProgress("编码颜色", 0.4);
6790
+ onProgress == null ? void 0 : onProgress("encode_color", 0.4);
6791
+ await yieldToUI();
6785
6792
  const dcValues = new Float32Array(count * 3);
6786
6793
  for (let i = 0; i < count; i++) {
6787
6794
  dcValues[i * 3] = (sCol[i * 3] - 0.5) / SH_C0;
@@ -6810,7 +6817,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6810
6817
  encodeWebP(width, height, sh0Data)
6811
6818
  ];
6812
6819
  if (actualBands > 0 && sSH) {
6813
- onProgress == null ? void 0 : onProgress("压缩球谐系数 (GPU)", 0.5);
6820
+ onProgress == null ? void 0 : onProgress("sh_compress", 0.5);
6821
+ await yieldToUI();
6814
6822
  const pointsFlat = new Float32Array(count * shDim);
6815
6823
  for (let i = 0; i < count; i++) {
6816
6824
  const b = i * 45;
@@ -6825,10 +6833,11 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6825
6833
  iterations,
6826
6834
  (iter, total) => {
6827
6835
  const p = 0.5 + 0.35 * (iter / total);
6828
- onProgress == null ? void 0 : onProgress(`球谐聚类 ${iter}/${total}`, p);
6836
+ onProgress == null ? void 0 : onProgress("sh_cluster", p, { iter, total });
6829
6837
  }
6830
6838
  );
6831
- onProgress == null ? void 0 : onProgress("量化球谐 codebook", 0.88);
6839
+ onProgress == null ? void 0 : onProgress("sh_quantize", 0.88);
6840
+ await yieldToUI();
6832
6841
  const allCoeffValues = new Float32Array(effectivePaletteSize * shDim);
6833
6842
  for (let c = 0; c < effectivePaletteSize; c++) {
6834
6843
  for (let d = 0; d < shDim; d++) allCoeffValues[c * shDim + d] = centroids[c * shDim + d];
@@ -6870,7 +6879,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6870
6879
  files: ["sh_centroids.webp", "sh_labels.webp"]
6871
6880
  };
6872
6881
  }
6873
- onProgress == null ? void 0 : onProgress("编码 WebP 图像", 0.92);
6882
+ onProgress == null ? void 0 : onProgress("encode_webp", 0.92);
6883
+ await yieldToUI();
6874
6884
  const webps = await Promise.all(webpPromises);
6875
6885
  const [meansLWebP, meansUWebP, scalesWebP, quatsWebP, sh0WebP] = webps;
6876
6886
  const meta = {
@@ -6896,9 +6906,10 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
6896
6906
  zipEntries["sh_centroids.webp"] = webps[5];
6897
6907
  zipEntries["sh_labels.webp"] = webps[6];
6898
6908
  }
6899
- onProgress == null ? void 0 : onProgress("打包 ZIP", 0.98);
6909
+ onProgress == null ? void 0 : onProgress("pack_zip", 0.98);
6910
+ await yieldToUI();
6900
6911
  const zipData = zipSync(zipEntries, { level: 0 });
6901
- onProgress == null ? void 0 : onProgress("完成", 1);
6912
+ onProgress == null ? void 0 : onProgress("done", 1);
6902
6913
  return zipData.buffer;
6903
6914
  }
6904
6915
  const WORKGROUP_SIZE$1 = 256;