@d5techs/3dgs-lib 1.4.76 → 1.4.78
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 +134 -77
- package/dist/3dgs-lib.cjs.map +1 -1
- package/dist/3dgs-lib.js +134 -77
- package/dist/3dgs-lib.js.map +1 -1
- package/dist/editor/SelectionVolumeRenderer.d.ts +0 -2
- package/dist/editor/SplatEditor.d.ts +2 -1
- package/package.json +1 -1
package/dist/3dgs-lib.cjs
CHANGED
|
@@ -17579,7 +17579,7 @@ class SphereSelection {
|
|
|
17579
17579
|
this.toolbar = document.createElement("div");
|
|
17580
17580
|
this.toolbar.className = "volume-select-toolbar";
|
|
17581
17581
|
this.toolbar.style.cssText = `
|
|
17582
|
-
position:absolute; bottom:
|
|
17582
|
+
position:absolute; bottom:90px; left:50%; transform:translateX(-50%);
|
|
17583
17583
|
display:none; z-index:20; background:rgba(30,30,30,0.92);
|
|
17584
17584
|
border-radius:8px; padding:6px 10px; gap:6px;
|
|
17585
17585
|
align-items:center; font-size:13px; color:#ddd;
|
|
@@ -17670,7 +17670,7 @@ class BoxSelection {
|
|
|
17670
17670
|
this.toolbar = document.createElement("div");
|
|
17671
17671
|
this.toolbar.className = "volume-select-toolbar";
|
|
17672
17672
|
this.toolbar.style.cssText = `
|
|
17673
|
-
position:absolute; bottom:
|
|
17673
|
+
position:absolute; bottom:90px; left:50%; transform:translateX(-50%);
|
|
17674
17674
|
display:none; z-index:20; background:rgba(30,30,30,0.92);
|
|
17675
17675
|
border-radius:8px; padding:6px 10px; gap:6px;
|
|
17676
17676
|
align-items:center; font-size:13px; color:#ddd;
|
|
@@ -17877,8 +17877,10 @@ function exportEditedPLY(positions, scales, rotations, colors, opacities, shCoef
|
|
|
17877
17877
|
}
|
|
17878
17878
|
return buffer;
|
|
17879
17879
|
}
|
|
17880
|
-
const
|
|
17881
|
-
const
|
|
17880
|
+
const SEG = 64;
|
|
17881
|
+
const LAT_COUNT = 8;
|
|
17882
|
+
const LON_COUNT = 12;
|
|
17883
|
+
const BOX_GRID_SUBDIV = 4;
|
|
17882
17884
|
class SelectionVolumeRenderer {
|
|
17883
17885
|
constructor(renderer, camera) {
|
|
17884
17886
|
__publicField(this, "renderer");
|
|
@@ -17889,16 +17891,14 @@ class SelectionVolumeRenderer {
|
|
|
17889
17891
|
__publicField(this, "vertexBuffer", null);
|
|
17890
17892
|
__publicField(this, "_volume", { type: null, center: [0, 0, 0], dimensions: [2, 2, 2] });
|
|
17891
17893
|
__publicField(this, "vertexCount", 0);
|
|
17892
|
-
__publicField(this, "
|
|
17893
|
-
__publicField(this, "lineColor", [0.2, 0.8, 1]);
|
|
17894
|
+
__publicField(this, "lineColor", [0.4, 0.9, 1]);
|
|
17894
17895
|
this.renderer = renderer;
|
|
17895
17896
|
this.camera = camera;
|
|
17896
|
-
this.maxVertices = Math.max(
|
|
17897
|
-
24,
|
|
17898
|
-
SPHERE_SEGMENTS * 2 * SPHERE_RINGS
|
|
17899
|
-
);
|
|
17900
17897
|
this.createPipeline();
|
|
17901
|
-
this.
|
|
17898
|
+
this.vertexBuffer = this.renderer.device.createBuffer({
|
|
17899
|
+
size: 65536,
|
|
17900
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
17901
|
+
});
|
|
17902
17902
|
}
|
|
17903
17903
|
get volume() {
|
|
17904
17904
|
return this._volume;
|
|
@@ -17932,7 +17932,7 @@ class SelectionVolumeRenderer {
|
|
|
17932
17932
|
return o;
|
|
17933
17933
|
}
|
|
17934
17934
|
@fragment fn fs(i: VO) -> @location(0) vec4<f32> {
|
|
17935
|
-
return vec4(i.color, 0.
|
|
17935
|
+
return vec4(i.color, 0.6);
|
|
17936
17936
|
}
|
|
17937
17937
|
`
|
|
17938
17938
|
);
|
|
@@ -17970,78 +17970,115 @@ class SelectionVolumeRenderer {
|
|
|
17970
17970
|
depthStencil: { format: this.renderer.depthFormat, depthWriteEnabled: false, depthCompare: "always" }
|
|
17971
17971
|
});
|
|
17972
17972
|
}
|
|
17973
|
-
|
|
17974
|
-
const size = this.maxVertices * 24;
|
|
17975
|
-
this.vertexBuffer = this.renderer.device.createBuffer({
|
|
17976
|
-
size,
|
|
17977
|
-
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
17978
|
-
});
|
|
17979
|
-
}
|
|
17973
|
+
// ========== Box: 12 edges + grid lines on all 6 faces ==========
|
|
17980
17974
|
generateBoxVertices() {
|
|
17981
17975
|
const [cx, cy, cz] = this._volume.center;
|
|
17982
17976
|
const [lx, ly, lz] = this._volume.dimensions;
|
|
17983
17977
|
const hx = lx / 2, hy = ly / 2, hz = lz / 2;
|
|
17984
17978
|
const [r, g, b] = this.lineColor;
|
|
17985
17979
|
const v = [];
|
|
17986
|
-
const
|
|
17980
|
+
const line = (x12, y12, z12, x2, y2, z2) => {
|
|
17987
17981
|
v.push(x12, y12, z12, r, g, b, x2, y2, z2, r, g, b);
|
|
17988
17982
|
};
|
|
17989
17983
|
const x0 = cx - hx, x1 = cx + hx;
|
|
17990
17984
|
const y0 = cy - hy, y1 = cy + hy;
|
|
17991
17985
|
const z0 = cz - hz, z1 = cz + hz;
|
|
17992
|
-
|
|
17993
|
-
|
|
17994
|
-
|
|
17995
|
-
|
|
17996
|
-
|
|
17997
|
-
|
|
17998
|
-
|
|
17999
|
-
|
|
18000
|
-
|
|
18001
|
-
|
|
18002
|
-
|
|
18003
|
-
|
|
17986
|
+
line(x0, y0, z0, x1, y0, z0);
|
|
17987
|
+
line(x1, y0, z0, x1, y0, z1);
|
|
17988
|
+
line(x1, y0, z1, x0, y0, z1);
|
|
17989
|
+
line(x0, y0, z1, x0, y0, z0);
|
|
17990
|
+
line(x0, y1, z0, x1, y1, z0);
|
|
17991
|
+
line(x1, y1, z0, x1, y1, z1);
|
|
17992
|
+
line(x1, y1, z1, x0, y1, z1);
|
|
17993
|
+
line(x0, y1, z1, x0, y1, z0);
|
|
17994
|
+
line(x0, y0, z0, x0, y1, z0);
|
|
17995
|
+
line(x1, y0, z0, x1, y1, z0);
|
|
17996
|
+
line(x1, y0, z1, x1, y1, z1);
|
|
17997
|
+
line(x0, y0, z1, x0, y1, z1);
|
|
17998
|
+
const n = BOX_GRID_SUBDIV;
|
|
17999
|
+
for (let i = 1; i < n; i++) {
|
|
18000
|
+
const t = i / n;
|
|
18001
|
+
const px = x0 + (x1 - x0) * t;
|
|
18002
|
+
const pz = z0 + (z1 - z0) * t;
|
|
18003
|
+
line(px, y0, z0, px, y0, z1);
|
|
18004
|
+
line(px, y1, z0, px, y1, z1);
|
|
18005
|
+
line(x0, y0, pz, x1, y0, pz);
|
|
18006
|
+
line(x0, y1, pz, x1, y1, pz);
|
|
18007
|
+
}
|
|
18008
|
+
for (let i = 1; i < n; i++) {
|
|
18009
|
+
const t = i / n;
|
|
18010
|
+
const px = x0 + (x1 - x0) * t;
|
|
18011
|
+
const py = y0 + (y1 - y0) * t;
|
|
18012
|
+
line(px, y0, z0, px, y1, z0);
|
|
18013
|
+
line(px, y0, z1, px, y1, z1);
|
|
18014
|
+
line(x0, py, z0, x1, py, z0);
|
|
18015
|
+
line(x0, py, z1, x1, py, z1);
|
|
18016
|
+
}
|
|
18017
|
+
for (let i = 1; i < n; i++) {
|
|
18018
|
+
const t = i / n;
|
|
18019
|
+
const py = y0 + (y1 - y0) * t;
|
|
18020
|
+
const pz = z0 + (z1 - z0) * t;
|
|
18021
|
+
line(x0, py, z0, x0, py, z1);
|
|
18022
|
+
line(x1, py, z0, x1, py, z1);
|
|
18023
|
+
line(x0, y0, pz, x0, y1, pz);
|
|
18024
|
+
line(x1, y0, pz, x1, y1, pz);
|
|
18025
|
+
}
|
|
18004
18026
|
return new Float32Array(v);
|
|
18005
18027
|
}
|
|
18028
|
+
// ========== Sphere: latitude + longitude rings ==========
|
|
18006
18029
|
generateSphereVertices() {
|
|
18007
18030
|
const [cx, cy, cz] = this._volume.center;
|
|
18008
18031
|
const radius = this._volume.dimensions[0];
|
|
18009
18032
|
const [r, g, b] = this.lineColor;
|
|
18010
18033
|
const v = [];
|
|
18011
|
-
const
|
|
18012
|
-
|
|
18013
|
-
|
|
18014
|
-
const
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
|
|
18018
|
-
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
y1 = cy + Math.cos(a1) * radius;
|
|
18030
|
-
z1 = cz + Math.sin(a1) * radius;
|
|
18031
|
-
} else {
|
|
18032
|
-
x0 = cx + Math.cos(a0) * radius;
|
|
18033
|
-
y0 = cy + Math.sin(a0) * radius;
|
|
18034
|
-
z0 = cz;
|
|
18035
|
-
x1 = cx + Math.cos(a1) * radius;
|
|
18036
|
-
y1 = cy + Math.sin(a1) * radius;
|
|
18037
|
-
z1 = cz;
|
|
18038
|
-
}
|
|
18039
|
-
v.push(x0, y0, z0, r, g, b, x1, y1, z1, r, g, b);
|
|
18034
|
+
const addRing = (centerY, ringRadius) => {
|
|
18035
|
+
for (let i = 0; i < SEG; i++) {
|
|
18036
|
+
const a0 = i / SEG * Math.PI * 2;
|
|
18037
|
+
const a1 = (i + 1) / SEG * Math.PI * 2;
|
|
18038
|
+
v.push(
|
|
18039
|
+
cx + Math.cos(a0) * ringRadius,
|
|
18040
|
+
cy + centerY,
|
|
18041
|
+
cz + Math.sin(a0) * ringRadius,
|
|
18042
|
+
r,
|
|
18043
|
+
g,
|
|
18044
|
+
b,
|
|
18045
|
+
cx + Math.cos(a1) * ringRadius,
|
|
18046
|
+
cy + centerY,
|
|
18047
|
+
cz + Math.sin(a1) * ringRadius,
|
|
18048
|
+
r,
|
|
18049
|
+
g,
|
|
18050
|
+
b
|
|
18051
|
+
);
|
|
18040
18052
|
}
|
|
18041
18053
|
};
|
|
18042
|
-
|
|
18043
|
-
|
|
18044
|
-
|
|
18054
|
+
for (let i = 0; i <= LAT_COUNT; i++) {
|
|
18055
|
+
const phi = -Math.PI / 2 + i / LAT_COUNT * Math.PI;
|
|
18056
|
+
const y = Math.sin(phi) * radius;
|
|
18057
|
+
const ringR = Math.cos(phi) * radius;
|
|
18058
|
+
if (ringR < 1e-3) continue;
|
|
18059
|
+
addRing(y, ringR);
|
|
18060
|
+
}
|
|
18061
|
+
for (let j = 0; j < LON_COUNT; j++) {
|
|
18062
|
+
const theta = j / LON_COUNT * Math.PI;
|
|
18063
|
+
for (let i = 0; i < SEG; i++) {
|
|
18064
|
+
const phi0 = i / SEG * Math.PI * 2;
|
|
18065
|
+
const phi1 = (i + 1) / SEG * Math.PI * 2;
|
|
18066
|
+
v.push(
|
|
18067
|
+
cx + Math.cos(phi0) * Math.sin(theta) * radius,
|
|
18068
|
+
cy + Math.sin(phi0) * radius,
|
|
18069
|
+
cz + Math.cos(phi0) * Math.cos(theta) * radius,
|
|
18070
|
+
r,
|
|
18071
|
+
g,
|
|
18072
|
+
b,
|
|
18073
|
+
cx + Math.cos(phi1) * Math.sin(theta) * radius,
|
|
18074
|
+
cy + Math.sin(phi1) * radius,
|
|
18075
|
+
cz + Math.cos(phi1) * Math.cos(theta) * radius,
|
|
18076
|
+
r,
|
|
18077
|
+
g,
|
|
18078
|
+
b
|
|
18079
|
+
);
|
|
18080
|
+
}
|
|
18081
|
+
}
|
|
18045
18082
|
return new Float32Array(v);
|
|
18046
18083
|
}
|
|
18047
18084
|
render(pass) {
|
|
@@ -18154,9 +18191,17 @@ class SplatEditor {
|
|
|
18154
18191
|
this.toolOverlay.style.display = name && !isVolumeTool ? "block" : "none";
|
|
18155
18192
|
if (isVolumeTool && this.volumeRenderer) {
|
|
18156
18193
|
const volType = name;
|
|
18157
|
-
const
|
|
18158
|
-
const
|
|
18159
|
-
|
|
18194
|
+
const bounds = this.getModelBounds();
|
|
18195
|
+
const defaultSize = Math.max(bounds.size[0], bounds.size[1], bounds.size[2]) * 0.3;
|
|
18196
|
+
const safeSize = Math.max(defaultSize, 0.5);
|
|
18197
|
+
if (volType === "box") {
|
|
18198
|
+
this.boxTool.setDimensions(safeSize, safeSize, safeSize);
|
|
18199
|
+
this.volumeRenderer.setVolume("box", bounds.center, [safeSize, safeSize, safeSize]);
|
|
18200
|
+
} else {
|
|
18201
|
+
const r = safeSize / 2;
|
|
18202
|
+
this.sphereTool.setRadius(r);
|
|
18203
|
+
this.volumeRenderer.setVolume("sphere", bounds.center, [r, 0, 0]);
|
|
18204
|
+
}
|
|
18160
18205
|
(_b2 = (_a2 = this.callbacks).onVolumeToolActivated) == null ? void 0 : _b2.call(_a2, this.volumeRenderer.volume);
|
|
18161
18206
|
} else {
|
|
18162
18207
|
if (this.volumeRenderer) this.volumeRenderer.setVolume(null);
|
|
@@ -18573,24 +18618,36 @@ class SplatEditor {
|
|
|
18573
18618
|
};
|
|
18574
18619
|
}
|
|
18575
18620
|
/**
|
|
18576
|
-
*
|
|
18621
|
+
* 获取模型世界空间包围盒(中心 + 尺寸)
|
|
18577
18622
|
*/
|
|
18578
|
-
|
|
18623
|
+
getModelBounds() {
|
|
18579
18624
|
const cpuPos = this.gsRenderer.getCPUPositions();
|
|
18580
|
-
if (!cpuPos || cpuPos.length === 0) return [0, 0, 0];
|
|
18625
|
+
if (!cpuPos || cpuPos.length === 0) return { center: [0, 0, 0], size: [2, 2, 2] };
|
|
18581
18626
|
const modelMat = this.gsRenderer.getModelMatrix();
|
|
18582
18627
|
const count = this.splatState.count;
|
|
18583
|
-
let
|
|
18584
|
-
|
|
18628
|
+
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
|
18629
|
+
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
18630
|
+
const step = Math.max(1, Math.floor(count / 2e3));
|
|
18585
18631
|
for (let i = 0; i < count; i += step) {
|
|
18586
18632
|
const i3 = i * 3;
|
|
18587
18633
|
const lx = cpuPos[i3], ly = cpuPos[i3 + 1], lz = cpuPos[i3 + 2];
|
|
18588
|
-
|
|
18589
|
-
|
|
18590
|
-
|
|
18591
|
-
|
|
18634
|
+
const wx = modelMat[0] * lx + modelMat[4] * ly + modelMat[8] * lz + modelMat[12];
|
|
18635
|
+
const wy = modelMat[1] * lx + modelMat[5] * ly + modelMat[9] * lz + modelMat[13];
|
|
18636
|
+
const wz = modelMat[2] * lx + modelMat[6] * ly + modelMat[10] * lz + modelMat[14];
|
|
18637
|
+
if (wx < minX) minX = wx;
|
|
18638
|
+
if (wx > maxX) maxX = wx;
|
|
18639
|
+
if (wy < minY) minY = wy;
|
|
18640
|
+
if (wy > maxY) maxY = wy;
|
|
18641
|
+
if (wz < minZ) minZ = wz;
|
|
18642
|
+
if (wz > maxZ) maxZ = wz;
|
|
18592
18643
|
}
|
|
18593
|
-
return
|
|
18644
|
+
return {
|
|
18645
|
+
center: [(minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2],
|
|
18646
|
+
size: [maxX - minX, maxY - minY, maxZ - minZ]
|
|
18647
|
+
};
|
|
18648
|
+
}
|
|
18649
|
+
getModelCenter() {
|
|
18650
|
+
return this.getModelBounds().center;
|
|
18594
18651
|
}
|
|
18595
18652
|
/**
|
|
18596
18653
|
* 根据屏幕像素坐标,找到最近的可见 splat 并返回其世界坐标及深度换算系数
|