@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 +23 -12
- package/dist/3dgs-lib.cjs.map +1 -1
- package/dist/3dgs-lib.js +23 -12
- package/dist/3dgs-lib.js.map +1 -1
- package/dist/gs/SOGEncoder.d.ts +13 -1
- package/package.json +1 -1
package/dist/3dgs-lib.js
CHANGED
|
@@ -6624,12 +6624,14 @@ async function encodeWebP(width, height, pixelData) {
|
|
|
6624
6624
|
}
|
|
6625
6625
|
return new Uint8Array(await blob.arrayBuffer());
|
|
6626
6626
|
}
|
|
6627
|
+
const yieldToUI = () => new Promise((r) => setTimeout(r, 0));
|
|
6627
6628
|
async function serializeSOG(data, coordinateSystem = "blender", options = {}, onProgress) {
|
|
6628
6629
|
const { maxSHBands = 3, iterations = 10, paletteSize = 1024 } = options;
|
|
6629
6630
|
const { count, colors, opacities } = data;
|
|
6630
6631
|
let { positions, scales, rotations } = data;
|
|
6631
6632
|
let shCoeffs = data.shCoeffs ? new Float32Array(data.shCoeffs) : void 0;
|
|
6632
|
-
onProgress == null ? void 0 : onProgress("
|
|
6633
|
+
onProgress == null ? void 0 : onProgress("coord_transform", 0);
|
|
6634
|
+
await yieldToUI();
|
|
6633
6635
|
if (coordinateSystem === "blender") {
|
|
6634
6636
|
positions = new Float32Array(positions);
|
|
6635
6637
|
scales = new Float32Array(scales);
|
|
@@ -6652,7 +6654,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6652
6654
|
}
|
|
6653
6655
|
}
|
|
6654
6656
|
}
|
|
6655
|
-
onProgress == null ? void 0 : onProgress("
|
|
6657
|
+
onProgress == null ? void 0 : onProgress("morton_sort", 0.05);
|
|
6658
|
+
await yieldToUI();
|
|
6656
6659
|
const sortOrder = mortonSort(positions, count);
|
|
6657
6660
|
const sPos = new Float32Array(count * 3);
|
|
6658
6661
|
const sSca = new Float32Array(count * 3);
|
|
@@ -6685,7 +6688,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6685
6688
|
}
|
|
6686
6689
|
const { width, height } = calcImageDimensions(count);
|
|
6687
6690
|
const totalPixels = width * height;
|
|
6688
|
-
onProgress == null ? void 0 : onProgress("
|
|
6691
|
+
onProgress == null ? void 0 : onProgress("encode_position", 0.1);
|
|
6692
|
+
await yieldToUI();
|
|
6689
6693
|
const logPos = new Float32Array(count * 3);
|
|
6690
6694
|
for (let i = 0; i < count * 3; i++) logPos[i] = symLog(sPos[i]);
|
|
6691
6695
|
const mins = [Infinity, Infinity, Infinity];
|
|
@@ -6713,7 +6717,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6713
6717
|
meansLData[off + 3] = 255;
|
|
6714
6718
|
meansUData[off + 3] = 255;
|
|
6715
6719
|
}
|
|
6716
|
-
onProgress == null ? void 0 : onProgress("
|
|
6720
|
+
onProgress == null ? void 0 : onProgress("encode_scale", 0.2);
|
|
6721
|
+
await yieldToUI();
|
|
6717
6722
|
const logScales = new Float32Array(count * 3);
|
|
6718
6723
|
for (let i = 0; i < count * 3; i++) logScales[i] = Math.log(Math.max(1e-8, sSca[i]));
|
|
6719
6724
|
const scaleCodebook = buildCodebook(logScales, 256);
|
|
@@ -6726,7 +6731,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6726
6731
|
scalesData[off + 2] = findNearest(scaleCodebook, logScales[i * 3 + 2]);
|
|
6727
6732
|
scalesData[off + 3] = 255;
|
|
6728
6733
|
}
|
|
6729
|
-
onProgress == null ? void 0 : onProgress("
|
|
6734
|
+
onProgress == null ? void 0 : onProgress("encode_quaternion", 0.3);
|
|
6735
|
+
await yieldToUI();
|
|
6730
6736
|
const quatsData = new Uint8ClampedArray(totalPixels * 4);
|
|
6731
6737
|
quatsData.fill(255);
|
|
6732
6738
|
const SQRT2 = Math.SQRT2;
|
|
@@ -6779,7 +6785,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6779
6785
|
quatsData[off + 2] = Math.round(Math.max(0, Math.min(255, (r2 / SQRT2 + 0.5) * 255)));
|
|
6780
6786
|
quatsData[off + 3] = largest + 252;
|
|
6781
6787
|
}
|
|
6782
|
-
onProgress == null ? void 0 : onProgress("
|
|
6788
|
+
onProgress == null ? void 0 : onProgress("encode_color", 0.4);
|
|
6789
|
+
await yieldToUI();
|
|
6783
6790
|
const dcValues = new Float32Array(count * 3);
|
|
6784
6791
|
for (let i = 0; i < count; i++) {
|
|
6785
6792
|
dcValues[i * 3] = (sCol[i * 3] - 0.5) / SH_C0;
|
|
@@ -6808,7 +6815,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6808
6815
|
encodeWebP(width, height, sh0Data)
|
|
6809
6816
|
];
|
|
6810
6817
|
if (actualBands > 0 && sSH) {
|
|
6811
|
-
onProgress == null ? void 0 : onProgress("
|
|
6818
|
+
onProgress == null ? void 0 : onProgress("sh_compress", 0.5);
|
|
6819
|
+
await yieldToUI();
|
|
6812
6820
|
const pointsFlat = new Float32Array(count * shDim);
|
|
6813
6821
|
for (let i = 0; i < count; i++) {
|
|
6814
6822
|
const b = i * 45;
|
|
@@ -6823,10 +6831,11 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6823
6831
|
iterations,
|
|
6824
6832
|
(iter, total) => {
|
|
6825
6833
|
const p = 0.5 + 0.35 * (iter / total);
|
|
6826
|
-
onProgress == null ? void 0 : onProgress(
|
|
6834
|
+
onProgress == null ? void 0 : onProgress("sh_cluster", p, { iter, total });
|
|
6827
6835
|
}
|
|
6828
6836
|
);
|
|
6829
|
-
onProgress == null ? void 0 : onProgress("
|
|
6837
|
+
onProgress == null ? void 0 : onProgress("sh_quantize", 0.88);
|
|
6838
|
+
await yieldToUI();
|
|
6830
6839
|
const allCoeffValues = new Float32Array(effectivePaletteSize * shDim);
|
|
6831
6840
|
for (let c = 0; c < effectivePaletteSize; c++) {
|
|
6832
6841
|
for (let d = 0; d < shDim; d++) allCoeffValues[c * shDim + d] = centroids[c * shDim + d];
|
|
@@ -6868,7 +6877,8 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6868
6877
|
files: ["sh_centroids.webp", "sh_labels.webp"]
|
|
6869
6878
|
};
|
|
6870
6879
|
}
|
|
6871
|
-
onProgress == null ? void 0 : onProgress("
|
|
6880
|
+
onProgress == null ? void 0 : onProgress("encode_webp", 0.92);
|
|
6881
|
+
await yieldToUI();
|
|
6872
6882
|
const webps = await Promise.all(webpPromises);
|
|
6873
6883
|
const [meansLWebP, meansUWebP, scalesWebP, quatsWebP, sh0WebP] = webps;
|
|
6874
6884
|
const meta = {
|
|
@@ -6894,9 +6904,10 @@ async function serializeSOG(data, coordinateSystem = "blender", options = {}, on
|
|
|
6894
6904
|
zipEntries["sh_centroids.webp"] = webps[5];
|
|
6895
6905
|
zipEntries["sh_labels.webp"] = webps[6];
|
|
6896
6906
|
}
|
|
6897
|
-
onProgress == null ? void 0 : onProgress("
|
|
6907
|
+
onProgress == null ? void 0 : onProgress("pack_zip", 0.98);
|
|
6908
|
+
await yieldToUI();
|
|
6898
6909
|
const zipData = zipSync(zipEntries, { level: 0 });
|
|
6899
|
-
onProgress == null ? void 0 : onProgress("
|
|
6910
|
+
onProgress == null ? void 0 : onProgress("done", 1);
|
|
6900
6911
|
return zipData.buffer;
|
|
6901
6912
|
}
|
|
6902
6913
|
const WORKGROUP_SIZE$1 = 256;
|