@d5techs/3dgs-lib 1.4.75 → 1.4.76

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
@@ -17568,213 +17568,212 @@ class EyedropperSelection {
17568
17568
  }
17569
17569
  }
17570
17570
  class SphereSelection {
17571
- constructor(parent, onSelect) {
17571
+ constructor(parent, callbacks) {
17572
17572
  __publicField(this, "parent");
17573
- __publicField(this, "svg");
17574
- __publicField(this, "circle");
17575
- __publicField(this, "onSelect");
17576
- __publicField(this, "center", { x: 0, y: 0 });
17577
- __publicField(this, "radiusPx", 0);
17578
- __publicField(this, "dragId");
17573
+ __publicField(this, "toolbar");
17574
+ __publicField(this, "callbacks");
17575
+ __publicField(this, "_radius", 1);
17576
+ __publicField(this, "radiusInput");
17579
17577
  this.parent = parent;
17580
- this.onSelect = onSelect;
17581
- this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
17582
- this.svg.classList.add("tool-svg");
17583
- this.svg.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;display:none;z-index:10;";
17584
- parent.appendChild(this.svg);
17585
- this.circle = document.createElementNS(
17586
- this.svg.namespaceURI,
17587
- "circle"
17588
- );
17589
- this.circle.setAttribute("fill", "rgba(0,150,255,0.12)");
17590
- this.circle.setAttribute("stroke", "#09f");
17591
- this.circle.setAttribute("stroke-width", "1.5");
17592
- this.circle.setAttribute("stroke-dasharray", "6 3");
17593
- this.circle.style.display = "none";
17594
- this.svg.appendChild(this.circle);
17595
- this.pointerdown = this.pointerdown.bind(this);
17596
- this.pointermove = this.pointermove.bind(this);
17597
- this.pointerup = this.pointerup.bind(this);
17598
- }
17599
- activate() {
17600
- this.svg.style.display = "block";
17601
- this.parent.style.cursor = "crosshair";
17602
- this.parent.addEventListener("pointerdown", this.pointerdown);
17603
- this.parent.addEventListener("pointermove", this.pointermove);
17604
- this.parent.addEventListener("pointerup", this.pointerup);
17605
- }
17606
- deactivate() {
17607
- if (this.dragId !== void 0) this.dragEnd();
17608
- this.svg.style.display = "none";
17609
- this.parent.style.cursor = "";
17610
- this.parent.removeEventListener("pointerdown", this.pointerdown);
17611
- this.parent.removeEventListener("pointermove", this.pointermove);
17612
- this.parent.removeEventListener("pointerup", this.pointerup);
17613
- }
17614
- updateCircle() {
17615
- this.circle.setAttribute("cx", this.center.x.toString());
17616
- this.circle.setAttribute("cy", this.center.y.toString());
17617
- this.circle.setAttribute("r", Math.max(1, this.radiusPx).toString());
17578
+ this.callbacks = callbacks;
17579
+ this.toolbar = document.createElement("div");
17580
+ this.toolbar.className = "volume-select-toolbar";
17581
+ this.toolbar.style.cssText = `
17582
+ position:absolute; bottom:12px; left:50%; transform:translateX(-50%);
17583
+ display:none; z-index:20; background:rgba(30,30,30,0.92);
17584
+ border-radius:8px; padding:6px 10px; gap:6px;
17585
+ align-items:center; font-size:13px; color:#ddd;
17586
+ backdrop-filter:blur(6px); user-select:none; white-space:nowrap;
17587
+ box-shadow:0 2px 12px rgba(0,0,0,0.4);
17588
+ `;
17589
+ this.toolbar.addEventListener("pointerdown", (e) => e.stopPropagation());
17590
+ this.toolbar.addEventListener("wheel", (e) => e.stopPropagation());
17591
+ const mkBtn = (label2, op) => {
17592
+ const btn = document.createElement("button");
17593
+ btn.textContent = label2;
17594
+ btn.style.cssText = `
17595
+ padding:4px 12px; border:1px solid #555; border-radius:4px;
17596
+ background:#333; color:#ddd; cursor:pointer; font-size:13px;
17597
+ transition: background 0.15s;
17598
+ `;
17599
+ btn.addEventListener("mouseenter", () => {
17600
+ btn.style.background = "#555";
17601
+ });
17602
+ btn.addEventListener("mouseleave", () => {
17603
+ btn.style.background = "#333";
17604
+ });
17605
+ btn.addEventListener("pointerdown", (e) => {
17606
+ e.stopPropagation();
17607
+ this.callbacks.onApply(op);
17608
+ });
17609
+ return btn;
17610
+ };
17611
+ const setBtn = mkBtn("Set", "set");
17612
+ const addBtn = mkBtn("Add", "add");
17613
+ const removeBtn = mkBtn("Remove", "remove");
17614
+ const inputWrap = document.createElement("span");
17615
+ inputWrap.style.cssText = "display:inline-flex; align-items:center; gap:2px;";
17616
+ const input = document.createElement("input");
17617
+ input.type = "number";
17618
+ input.min = "0.01";
17619
+ input.step = "0.1";
17620
+ input.value = this._radius.toFixed(2);
17621
+ input.style.cssText = `
17622
+ width:50px; padding:3px 4px; border:1px solid #555; border-radius:4px;
17623
+ background:#222; color:#ddd; font-size:12px; text-align:center;
17624
+ `;
17625
+ const label = document.createElement("span");
17626
+ label.textContent = "Radius";
17627
+ label.style.cssText = "color:#888; font-size:11px;";
17628
+ input.addEventListener("change", () => {
17629
+ const v = Math.max(0.01, parseFloat(input.value) || 0.01);
17630
+ input.value = v.toFixed(2);
17631
+ this._radius = v;
17632
+ this.callbacks.onRadiusChanged(v);
17633
+ });
17634
+ inputWrap.appendChild(input);
17635
+ inputWrap.appendChild(label);
17636
+ this.radiusInput = input;
17637
+ this.toolbar.appendChild(setBtn);
17638
+ this.toolbar.appendChild(addBtn);
17639
+ this.toolbar.appendChild(removeBtn);
17640
+ this.toolbar.appendChild(inputWrap);
17641
+ parent.appendChild(this.toolbar);
17618
17642
  }
17619
- pointerdown(e) {
17620
- if (this.dragId !== void 0) return;
17621
- if (e.pointerType === "mouse" ? e.button !== 0 : !e.isPrimary) return;
17622
- e.preventDefault();
17623
- e.stopPropagation();
17624
- this.dragId = e.pointerId;
17625
- this.parent.setPointerCapture(this.dragId);
17626
- this.center.x = e.offsetX;
17627
- this.center.y = e.offsetY;
17628
- this.radiusPx = 0;
17629
- this.updateCircle();
17630
- this.circle.style.display = "block";
17643
+ get radius() {
17644
+ return this._radius;
17631
17645
  }
17632
- pointermove(e) {
17633
- if (e.pointerId !== this.dragId) return;
17634
- e.preventDefault();
17635
- e.stopPropagation();
17636
- const dx = e.offsetX - this.center.x;
17637
- const dy = e.offsetY - this.center.y;
17638
- this.radiusPx = Math.sqrt(dx * dx + dy * dy);
17639
- this.updateCircle();
17646
+ setRadius(radius) {
17647
+ this._radius = radius;
17648
+ this.radiusInput.value = radius.toFixed(2);
17640
17649
  }
17641
- dragEnd() {
17642
- if (this.dragId !== void 0) {
17643
- this.parent.releasePointerCapture(this.dragId);
17644
- this.dragId = void 0;
17645
- }
17646
- this.circle.style.display = "none";
17650
+ activate() {
17651
+ this.toolbar.style.display = "flex";
17647
17652
  }
17648
- pointerup(e) {
17649
- if (e.pointerId !== this.dragId) return;
17650
- e.preventDefault();
17651
- e.stopPropagation();
17652
- const selectOp = e.shiftKey ? "add" : e.ctrlKey ? "remove" : "set";
17653
- if (this.radiusPx < 3) this.radiusPx = 20;
17654
- this.onSelect(selectOp, { x: this.center.x, y: this.center.y }, this.radiusPx);
17655
- this.dragEnd();
17653
+ deactivate() {
17654
+ this.toolbar.style.display = "none";
17656
17655
  }
17657
17656
  }
17658
17657
  class BoxSelection {
17659
- constructor(parent, onSelect) {
17658
+ constructor(parent, callbacks) {
17660
17659
  __publicField(this, "parent");
17661
- __publicField(this, "svg");
17662
- __publicField(this, "rect");
17663
- __publicField(this, "crossV");
17664
- __publicField(this, "crossH");
17665
- __publicField(this, "onSelect");
17666
- __publicField(this, "center", { x: 0, y: 0 });
17667
- __publicField(this, "halfW", 0);
17668
- __publicField(this, "halfH", 0);
17669
- __publicField(this, "dragId");
17660
+ __publicField(this, "toolbar");
17661
+ __publicField(this, "callbacks");
17662
+ __publicField(this, "_lenX", 2);
17663
+ __publicField(this, "_lenY", 2);
17664
+ __publicField(this, "_lenZ", 2);
17665
+ __publicField(this, "inputX");
17666
+ __publicField(this, "inputY");
17667
+ __publicField(this, "inputZ");
17670
17668
  this.parent = parent;
17671
- this.onSelect = onSelect;
17672
- this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
17673
- this.svg.classList.add("tool-svg");
17674
- this.svg.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;display:none;z-index:10;";
17675
- parent.appendChild(this.svg);
17676
- this.rect = document.createElementNS(
17677
- this.svg.namespaceURI,
17678
- "rect"
17679
- );
17680
- this.rect.setAttribute("fill", "rgba(0,200,100,0.12)");
17681
- this.rect.setAttribute("stroke", "#0c6");
17682
- this.rect.setAttribute("stroke-width", "1.5");
17683
- this.rect.setAttribute("stroke-dasharray", "6 3");
17684
- this.rect.style.display = "none";
17685
- this.svg.appendChild(this.rect);
17686
- const mkLine = () => {
17687
- const l = document.createElementNS(this.svg.namespaceURI, "line");
17688
- l.setAttribute("stroke", "#0c6");
17689
- l.setAttribute("stroke-width", "1");
17690
- l.setAttribute("stroke-dasharray", "3 3");
17691
- l.style.display = "none";
17692
- this.svg.appendChild(l);
17693
- return l;
17669
+ this.callbacks = callbacks;
17670
+ this.toolbar = document.createElement("div");
17671
+ this.toolbar.className = "volume-select-toolbar";
17672
+ this.toolbar.style.cssText = `
17673
+ position:absolute; bottom:12px; left:50%; transform:translateX(-50%);
17674
+ display:none; z-index:20; background:rgba(30,30,30,0.92);
17675
+ border-radius:8px; padding:6px 10px; gap:6px;
17676
+ align-items:center; font-size:13px; color:#ddd;
17677
+ backdrop-filter:blur(6px); user-select:none; white-space:nowrap;
17678
+ box-shadow:0 2px 12px rgba(0,0,0,0.4);
17679
+ `;
17680
+ this.toolbar.addEventListener("pointerdown", (e) => e.stopPropagation());
17681
+ this.toolbar.addEventListener("wheel", (e) => e.stopPropagation());
17682
+ const mkBtn = (label, op) => {
17683
+ const btn = document.createElement("button");
17684
+ btn.textContent = label;
17685
+ btn.style.cssText = `
17686
+ padding:4px 12px; border:1px solid #555; border-radius:4px;
17687
+ background:#333; color:#ddd; cursor:pointer; font-size:13px;
17688
+ transition: background 0.15s;
17689
+ `;
17690
+ btn.addEventListener("mouseenter", () => {
17691
+ btn.style.background = "#555";
17692
+ });
17693
+ btn.addEventListener("mouseleave", () => {
17694
+ btn.style.background = "#333";
17695
+ });
17696
+ btn.addEventListener("pointerdown", (e) => {
17697
+ e.stopPropagation();
17698
+ this.callbacks.onApply(op);
17699
+ });
17700
+ return btn;
17694
17701
  };
17695
- this.crossV = mkLine();
17696
- this.crossH = mkLine();
17697
- this.pointerdown = this.pointerdown.bind(this);
17698
- this.pointermove = this.pointermove.bind(this);
17699
- this.pointerup = this.pointerup.bind(this);
17702
+ const mkInput = (placeholder, initial, onChange) => {
17703
+ const wrap = document.createElement("span");
17704
+ wrap.style.cssText = "display:inline-flex; align-items:center; gap:2px;";
17705
+ const input = document.createElement("input");
17706
+ input.type = "number";
17707
+ input.min = "0.01";
17708
+ input.step = "0.1";
17709
+ input.value = initial.toFixed(2);
17710
+ input.style.cssText = `
17711
+ width:50px; padding:3px 4px; border:1px solid #555; border-radius:4px;
17712
+ background:#222; color:#ddd; font-size:12px; text-align:center;
17713
+ `;
17714
+ const label = document.createElement("span");
17715
+ label.textContent = placeholder;
17716
+ label.style.cssText = "color:#888; font-size:11px;";
17717
+ input.addEventListener("change", () => {
17718
+ const v = Math.max(0.01, parseFloat(input.value) || 0.01);
17719
+ input.value = v.toFixed(2);
17720
+ onChange(v);
17721
+ });
17722
+ wrap.appendChild(input);
17723
+ wrap.appendChild(label);
17724
+ return { wrap, input };
17725
+ };
17726
+ const setBtn = mkBtn("Set", "set");
17727
+ const addBtn = mkBtn("Add", "add");
17728
+ const removeBtn = mkBtn("Remove", "remove");
17729
+ const xInput = mkInput("LenX", this._lenX, (v) => {
17730
+ this._lenX = v;
17731
+ this.emitDims();
17732
+ });
17733
+ const yInput = mkInput("LenY", this._lenY, (v) => {
17734
+ this._lenY = v;
17735
+ this.emitDims();
17736
+ });
17737
+ const zInput = mkInput("LenZ", this._lenZ, (v) => {
17738
+ this._lenZ = v;
17739
+ this.emitDims();
17740
+ });
17741
+ this.inputX = xInput.input;
17742
+ this.inputY = yInput.input;
17743
+ this.inputZ = zInput.input;
17744
+ this.toolbar.appendChild(setBtn);
17745
+ this.toolbar.appendChild(addBtn);
17746
+ this.toolbar.appendChild(removeBtn);
17747
+ this.toolbar.appendChild(xInput.wrap);
17748
+ this.toolbar.appendChild(yInput.wrap);
17749
+ this.toolbar.appendChild(zInput.wrap);
17750
+ parent.appendChild(this.toolbar);
17751
+ }
17752
+ get lenX() {
17753
+ return this._lenX;
17754
+ }
17755
+ get lenY() {
17756
+ return this._lenY;
17757
+ }
17758
+ get lenZ() {
17759
+ return this._lenZ;
17760
+ }
17761
+ setDimensions(lenX, lenY, lenZ) {
17762
+ this._lenX = lenX;
17763
+ this._lenY = lenY;
17764
+ this._lenZ = lenZ;
17765
+ this.inputX.value = lenX.toFixed(2);
17766
+ this.inputY.value = lenY.toFixed(2);
17767
+ this.inputZ.value = lenZ.toFixed(2);
17700
17768
  }
17701
17769
  activate() {
17702
- this.svg.style.display = "block";
17703
- this.parent.style.cursor = "crosshair";
17704
- this.parent.addEventListener("pointerdown", this.pointerdown);
17705
- this.parent.addEventListener("pointermove", this.pointermove);
17706
- this.parent.addEventListener("pointerup", this.pointerup);
17770
+ this.toolbar.style.display = "flex";
17707
17771
  }
17708
17772
  deactivate() {
17709
- if (this.dragId !== void 0) this.dragEnd();
17710
- this.svg.style.display = "none";
17711
- this.parent.style.cursor = "";
17712
- this.parent.removeEventListener("pointerdown", this.pointerdown);
17713
- this.parent.removeEventListener("pointermove", this.pointermove);
17714
- this.parent.removeEventListener("pointerup", this.pointerup);
17773
+ this.toolbar.style.display = "none";
17715
17774
  }
17716
- updateVisuals() {
17717
- const x = this.center.x - this.halfW;
17718
- const y = this.center.y - this.halfH;
17719
- const w = this.halfW * 2;
17720
- const h = this.halfH * 2;
17721
- this.rect.setAttribute("x", x.toString());
17722
- this.rect.setAttribute("y", y.toString());
17723
- this.rect.setAttribute("width", Math.max(1, w).toString());
17724
- this.rect.setAttribute("height", Math.max(1, h).toString());
17725
- this.crossV.setAttribute("x1", this.center.x.toString());
17726
- this.crossV.setAttribute("y1", y.toString());
17727
- this.crossV.setAttribute("x2", this.center.x.toString());
17728
- this.crossV.setAttribute("y2", (y + h).toString());
17729
- this.crossH.setAttribute("x1", x.toString());
17730
- this.crossH.setAttribute("y1", this.center.y.toString());
17731
- this.crossH.setAttribute("x2", (x + w).toString());
17732
- this.crossH.setAttribute("y2", this.center.y.toString());
17733
- }
17734
- pointerdown(e) {
17735
- if (this.dragId !== void 0) return;
17736
- if (e.pointerType === "mouse" ? e.button !== 0 : !e.isPrimary) return;
17737
- e.preventDefault();
17738
- e.stopPropagation();
17739
- this.dragId = e.pointerId;
17740
- this.parent.setPointerCapture(this.dragId);
17741
- this.center.x = e.offsetX;
17742
- this.center.y = e.offsetY;
17743
- this.halfW = 0;
17744
- this.halfH = 0;
17745
- this.updateVisuals();
17746
- this.rect.style.display = "block";
17747
- this.crossV.style.display = "block";
17748
- this.crossH.style.display = "block";
17749
- }
17750
- pointermove(e) {
17751
- if (e.pointerId !== this.dragId) return;
17752
- e.preventDefault();
17753
- e.stopPropagation();
17754
- this.halfW = Math.abs(e.offsetX - this.center.x);
17755
- this.halfH = Math.abs(e.offsetY - this.center.y);
17756
- this.updateVisuals();
17757
- }
17758
- dragEnd() {
17759
- if (this.dragId !== void 0) {
17760
- this.parent.releasePointerCapture(this.dragId);
17761
- this.dragId = void 0;
17762
- }
17763
- this.rect.style.display = "none";
17764
- this.crossV.style.display = "none";
17765
- this.crossH.style.display = "none";
17766
- }
17767
- pointerup(e) {
17768
- if (e.pointerId !== this.dragId) return;
17769
- e.preventDefault();
17770
- e.stopPropagation();
17771
- const selectOp = e.shiftKey ? "add" : e.ctrlKey ? "remove" : "set";
17772
- if (this.halfW < 3 && this.halfH < 3) {
17773
- this.halfW = 20;
17774
- this.halfH = 20;
17775
- }
17776
- this.onSelect(selectOp, { x: this.center.x, y: this.center.y }, this.halfW, this.halfH);
17777
- this.dragEnd();
17775
+ emitDims() {
17776
+ this.callbacks.onDimensionsChanged(this._lenX, this._lenY, this._lenZ);
17778
17777
  }
17779
17778
  }
17780
17779
  function exportEditedPLY(positions, scales, rotations, colors, opacities, shCoeffs, state) {
@@ -17878,9 +17877,205 @@ function exportEditedPLY(positions, scales, rotations, colors, opacities, shCoef
17878
17877
  }
17879
17878
  return buffer;
17880
17879
  }
17880
+ const SPHERE_SEGMENTS = 64;
17881
+ const SPHERE_RINGS = 3;
17882
+ class SelectionVolumeRenderer {
17883
+ constructor(renderer, camera) {
17884
+ __publicField(this, "renderer");
17885
+ __publicField(this, "camera");
17886
+ __publicField(this, "pipeline", null);
17887
+ __publicField(this, "uniformBuffer", null);
17888
+ __publicField(this, "bindGroup", null);
17889
+ __publicField(this, "vertexBuffer", null);
17890
+ __publicField(this, "_volume", { type: null, center: [0, 0, 0], dimensions: [2, 2, 2] });
17891
+ __publicField(this, "vertexCount", 0);
17892
+ __publicField(this, "maxVertices");
17893
+ __publicField(this, "lineColor", [0.2, 0.8, 1]);
17894
+ this.renderer = renderer;
17895
+ this.camera = camera;
17896
+ this.maxVertices = Math.max(
17897
+ 24,
17898
+ SPHERE_SEGMENTS * 2 * SPHERE_RINGS
17899
+ );
17900
+ this.createPipeline();
17901
+ this.createVertexBuffer();
17902
+ }
17903
+ get volume() {
17904
+ return this._volume;
17905
+ }
17906
+ setVolume(type, center, dimensions) {
17907
+ this._volume.type = type;
17908
+ if (center) this._volume.center = center;
17909
+ if (dimensions) this._volume.dimensions = dimensions;
17910
+ }
17911
+ setCenter(x, y, z) {
17912
+ this._volume.center = [x, y, z];
17913
+ }
17914
+ setDimensions(a, b, c) {
17915
+ this._volume.dimensions = [a, b, c];
17916
+ }
17917
+ createPipeline() {
17918
+ const device = this.renderer.device;
17919
+ const shaderCode = (
17920
+ /* wgsl */
17921
+ `
17922
+ struct Uniforms { viewProjection: mat4x4<f32> }
17923
+ @group(0) @binding(0) var<uniform> uniforms: Uniforms;
17924
+
17925
+ struct VI { @location(0) position: vec3<f32>, @location(1) color: vec3<f32> }
17926
+ struct VO { @builtin(position) position: vec4<f32>, @location(0) color: vec3<f32> }
17927
+
17928
+ @vertex fn vs(i: VI) -> VO {
17929
+ var o: VO;
17930
+ o.position = uniforms.viewProjection * vec4(i.position, 1.0);
17931
+ o.color = i.color;
17932
+ return o;
17933
+ }
17934
+ @fragment fn fs(i: VO) -> @location(0) vec4<f32> {
17935
+ return vec4(i.color, 0.8);
17936
+ }
17937
+ `
17938
+ );
17939
+ const sm = device.createShaderModule({ code: shaderCode });
17940
+ this.uniformBuffer = device.createBuffer({ size: 64, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST });
17941
+ const bgl = device.createBindGroupLayout({
17942
+ entries: [{ binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: "uniform" } }]
17943
+ });
17944
+ this.bindGroup = device.createBindGroup({ layout: bgl, entries: [{ binding: 0, resource: { buffer: this.uniformBuffer } }] });
17945
+ this.pipeline = device.createRenderPipeline({
17946
+ layout: device.createPipelineLayout({ bindGroupLayouts: [bgl] }),
17947
+ vertex: {
17948
+ module: sm,
17949
+ entryPoint: "vs",
17950
+ buffers: [{
17951
+ arrayStride: 24,
17952
+ attributes: [
17953
+ { shaderLocation: 0, offset: 0, format: "float32x3" },
17954
+ { shaderLocation: 1, offset: 12, format: "float32x3" }
17955
+ ]
17956
+ }]
17957
+ },
17958
+ fragment: {
17959
+ module: sm,
17960
+ entryPoint: "fs",
17961
+ targets: [{
17962
+ format: this.renderer.format,
17963
+ blend: {
17964
+ color: { srcFactor: "src-alpha", dstFactor: "one-minus-src-alpha", operation: "add" },
17965
+ alpha: { srcFactor: "one", dstFactor: "one-minus-src-alpha", operation: "add" }
17966
+ }
17967
+ }]
17968
+ },
17969
+ primitive: { topology: "line-list", cullMode: "none" },
17970
+ depthStencil: { format: this.renderer.depthFormat, depthWriteEnabled: false, depthCompare: "always" }
17971
+ });
17972
+ }
17973
+ createVertexBuffer() {
17974
+ const size = this.maxVertices * 24;
17975
+ this.vertexBuffer = this.renderer.device.createBuffer({
17976
+ size,
17977
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
17978
+ });
17979
+ }
17980
+ generateBoxVertices() {
17981
+ const [cx, cy, cz] = this._volume.center;
17982
+ const [lx, ly, lz] = this._volume.dimensions;
17983
+ const hx = lx / 2, hy = ly / 2, hz = lz / 2;
17984
+ const [r, g, b] = this.lineColor;
17985
+ const v = [];
17986
+ const addLine = (x12, y12, z12, x2, y2, z2) => {
17987
+ v.push(x12, y12, z12, r, g, b, x2, y2, z2, r, g, b);
17988
+ };
17989
+ const x0 = cx - hx, x1 = cx + hx;
17990
+ const y0 = cy - hy, y1 = cy + hy;
17991
+ const z0 = cz - hz, z1 = cz + hz;
17992
+ addLine(x0, y0, z0, x1, y0, z0);
17993
+ addLine(x1, y0, z0, x1, y0, z1);
17994
+ addLine(x1, y0, z1, x0, y0, z1);
17995
+ addLine(x0, y0, z1, x0, y0, z0);
17996
+ addLine(x0, y1, z0, x1, y1, z0);
17997
+ addLine(x1, y1, z0, x1, y1, z1);
17998
+ addLine(x1, y1, z1, x0, y1, z1);
17999
+ addLine(x0, y1, z1, x0, y1, z0);
18000
+ addLine(x0, y0, z0, x0, y1, z0);
18001
+ addLine(x1, y0, z0, x1, y1, z0);
18002
+ addLine(x1, y0, z1, x1, y1, z1);
18003
+ addLine(x0, y0, z1, x0, y1, z1);
18004
+ return new Float32Array(v);
18005
+ }
18006
+ generateSphereVertices() {
18007
+ const [cx, cy, cz] = this._volume.center;
18008
+ const radius = this._volume.dimensions[0];
18009
+ const [r, g, b] = this.lineColor;
18010
+ const v = [];
18011
+ const seg = SPHERE_SEGMENTS;
18012
+ const addCircle = (axis) => {
18013
+ for (let i = 0; i < seg; i++) {
18014
+ const a0 = i / seg * Math.PI * 2;
18015
+ const a1 = (i + 1) / seg * Math.PI * 2;
18016
+ let x0, y0, z0, x1, y1, z1;
18017
+ if (axis === "y") {
18018
+ x0 = cx + Math.cos(a0) * radius;
18019
+ y0 = cy;
18020
+ z0 = cz + Math.sin(a0) * radius;
18021
+ x1 = cx + Math.cos(a1) * radius;
18022
+ y1 = cy;
18023
+ z1 = cz + Math.sin(a1) * radius;
18024
+ } else if (axis === "x") {
18025
+ x0 = cx;
18026
+ y0 = cy + Math.cos(a0) * radius;
18027
+ z0 = cz + Math.sin(a0) * radius;
18028
+ x1 = cx;
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);
18040
+ }
18041
+ };
18042
+ addCircle("x");
18043
+ addCircle("y");
18044
+ addCircle("z");
18045
+ return new Float32Array(v);
18046
+ }
18047
+ render(pass) {
18048
+ if (!this._volume.type || !this.pipeline || !this.bindGroup || !this.vertexBuffer || !this.uniformBuffer) return;
18049
+ const device = this.renderer.device;
18050
+ const verts = this._volume.type === "box" ? this.generateBoxVertices() : this.generateSphereVertices();
18051
+ this.vertexCount = verts.length / 6;
18052
+ if (this.vertexCount === 0) return;
18053
+ const needed = this.vertexCount * 24;
18054
+ if (needed > this.vertexBuffer.size) {
18055
+ this.vertexBuffer.destroy();
18056
+ this.vertexBuffer = device.createBuffer({ size: needed, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST });
18057
+ }
18058
+ device.queue.writeBuffer(this.vertexBuffer, 0, verts.buffer);
18059
+ device.queue.writeBuffer(this.uniformBuffer, 0, new Float32Array(this.camera.viewProjectionMatrix));
18060
+ pass.setPipeline(this.pipeline);
18061
+ pass.setBindGroup(0, this.bindGroup);
18062
+ pass.setVertexBuffer(0, this.vertexBuffer);
18063
+ pass.draw(this.vertexCount);
18064
+ }
18065
+ destroy() {
18066
+ var _a2, _b2;
18067
+ (_a2 = this.vertexBuffer) == null ? void 0 : _a2.destroy();
18068
+ (_b2 = this.uniformBuffer) == null ? void 0 : _b2.destroy();
18069
+ this.vertexBuffer = null;
18070
+ this.uniformBuffer = null;
18071
+ this.pipeline = null;
18072
+ this.bindGroup = null;
18073
+ }
18074
+ }
17881
18075
  class SplatEditor {
17882
- constructor(camera, gsRenderer, container, callbacks = {}) {
18076
+ constructor(camera, gsRenderer, container, callbacks = {}, renderer) {
17883
18077
  __publicField(this, "camera");
18078
+ __publicField(this, "gpuRenderer");
17884
18079
  __publicField(this, "gsRenderer");
17885
18080
  __publicField(this, "container");
17886
18081
  __publicField(this, "splatState");
@@ -17895,6 +18090,10 @@ class SplatEditor {
17895
18090
  __publicField(this, "projDirty", true);
17896
18091
  __publicField(this, "_active", false);
17897
18092
  __publicField(this, "overlayCleanup", []);
18093
+ /** 体积选择线框渲染器 */
18094
+ __publicField(this, "volumeRenderer", null);
18095
+ __publicField(this, "boxTool", null);
18096
+ __publicField(this, "sphereTool", null);
17898
18097
  // ============================================
17899
18098
  // 键盘快捷键
17900
18099
  // ============================================
@@ -17903,6 +18102,7 @@ class SplatEditor {
17903
18102
  this.gsRenderer = gsRenderer;
17904
18103
  this.container = container;
17905
18104
  this.callbacks = callbacks;
18105
+ this.gpuRenderer = renderer;
17906
18106
  }
17907
18107
  get active() {
17908
18108
  return this._active;
@@ -17949,9 +18149,20 @@ class SplatEditor {
17949
18149
  this.container.style.position = "relative";
17950
18150
  }
17951
18151
  this.toolManager = new ToolManager((name) => {
17952
- var _a2, _b2;
17953
- this.toolOverlay.style.display = name ? "block" : "none";
17954
- (_b2 = (_a2 = this.callbacks).onToolChanged) == null ? void 0 : _b2.call(_a2, name);
18152
+ var _a2, _b2, _c, _d, _e, _f;
18153
+ const isVolumeTool = name === "box" || name === "sphere";
18154
+ this.toolOverlay.style.display = name && !isVolumeTool ? "block" : "none";
18155
+ if (isVolumeTool && this.volumeRenderer) {
18156
+ const volType = name;
18157
+ const center = this.getModelCenter();
18158
+ const dims = volType === "box" ? [this.boxTool.lenX, this.boxTool.lenY, this.boxTool.lenZ] : [this.sphereTool.radius, 0, 0];
18159
+ this.volumeRenderer.setVolume(volType, center, dims);
18160
+ (_b2 = (_a2 = this.callbacks).onVolumeToolActivated) == null ? void 0 : _b2.call(_a2, this.volumeRenderer.volume);
18161
+ } else {
18162
+ if (this.volumeRenderer) this.volumeRenderer.setVolume(null);
18163
+ (_d = (_c = this.callbacks).onVolumeToolDeactivated) == null ? void 0 : _d.call(_c);
18164
+ }
18165
+ (_f = (_e = this.callbacks).onToolChanged) == null ? void 0 : _f.call(_e, name);
17955
18166
  });
17956
18167
  this.toolManager.register("rect", new RectSelection(
17957
18168
  this.toolOverlay,
@@ -17987,24 +18198,42 @@ class SplatEditor {
17987
18198
  this.toolOverlay,
17988
18199
  (op, pt, threshold) => this.selectByColor(op, pt, threshold)
17989
18200
  ));
17990
- this.toolManager.register("sphere", new SphereSelection(
17991
- this.toolOverlay,
17992
- (op, centerPx, radiusPx) => this.selectBySphere(op, centerPx, radiusPx)
17993
- ));
17994
- this.toolManager.register("box", new BoxSelection(
17995
- this.toolOverlay,
17996
- (op, centerPx, halfW, halfH) => this.selectByBox(op, centerPx, halfW, halfH)
17997
- ));
18201
+ if (this.gpuRenderer) {
18202
+ this.volumeRenderer = new SelectionVolumeRenderer(this.gpuRenderer, this.camera);
18203
+ }
18204
+ this.sphereTool = new SphereSelection(this.container, {
18205
+ onApply: (op) => this.applyVolumeSelection(op),
18206
+ onRadiusChanged: (radius) => {
18207
+ var _a2;
18208
+ (_a2 = this.volumeRenderer) == null ? void 0 : _a2.setDimensions(radius, 0, 0);
18209
+ }
18210
+ });
18211
+ this.toolManager.register("sphere", this.sphereTool);
18212
+ this.boxTool = new BoxSelection(this.container, {
18213
+ onApply: (op) => this.applyVolumeSelection(op),
18214
+ onDimensionsChanged: (lx, ly, lz) => {
18215
+ var _a2;
18216
+ (_a2 = this.volumeRenderer) == null ? void 0 : _a2.setDimensions(lx, ly, lz);
18217
+ }
18218
+ });
18219
+ this.toolManager.register("box", this.boxTool);
17998
18220
  this.gsRenderer.setEditorState(this.splatState.data);
17999
18221
  this._keyHandler = this._onKeyDown.bind(this);
18000
18222
  window.addEventListener("keydown", this._keyHandler);
18001
18223
  this.projDirty = true;
18002
18224
  }
18225
+ /**
18226
+ * 渲染体积选择线框(在主渲染 pass 内调用)
18227
+ */
18228
+ renderVolume(pass) {
18229
+ var _a2;
18230
+ (_a2 = this.volumeRenderer) == null ? void 0 : _a2.render(pass);
18231
+ }
18003
18232
  /**
18004
18233
  * 退出编辑模式,将编辑结果永久写入渲染数据
18005
18234
  */
18006
18235
  exit() {
18007
- var _a2, _b2;
18236
+ var _a2, _b2, _c;
18008
18237
  if (!this._active) return;
18009
18238
  this._active = false;
18010
18239
  window.removeEventListener("keydown", this._keyHandler);
@@ -18013,6 +18242,8 @@ class SplatEditor {
18013
18242
  this.overlayCleanup = [];
18014
18243
  (_a2 = this.toolOverlay) == null ? void 0 : _a2.remove();
18015
18244
  (_b2 = this.maskCanvas) == null ? void 0 : _b2.remove();
18245
+ (_c = this.volumeRenderer) == null ? void 0 : _c.destroy();
18246
+ this.volumeRenderer = null;
18016
18247
  this.applyEditsToRenderer();
18017
18248
  this.editHistory.clear();
18018
18249
  this.gsRenderer.clearEditorState();
@@ -18248,52 +18479,119 @@ class SplatEditor {
18248
18479
  this.editHistory.add(editOp);
18249
18480
  }
18250
18481
  /**
18251
- * 球选择:在屏幕空间判断 splat 是否在圆形区域内
18482
+ * 世界空间球体选择
18252
18483
  */
18253
- selectBySphere(op, centerPx, radiusPx) {
18254
- this.ensureProjection();
18255
- const proj = this.projectedPositions;
18256
- if (!proj) return;
18257
- const w = this.container.clientWidth;
18258
- const h = this.container.clientHeight;
18259
- const cx = centerPx.x / w;
18260
- const cy = centerPx.y / h;
18261
- const rx = radiusPx / w;
18262
- const ry = radiusPx / h;
18263
- const rx2 = rx * rx;
18264
- const ry2 = ry * ry;
18484
+ selectByWorldSphere(op, center, radius) {
18485
+ const cpuPos = this.gsRenderer.getCPUPositions();
18486
+ if (!cpuPos) return;
18487
+ const modelMat = this.gsRenderer.getModelMatrix();
18488
+ const r2 = radius * radius;
18489
+ const [cx, cy, cz] = center;
18265
18490
  const editOp = new SelectOp(this.splatState, op, (i) => {
18266
- const b = i * 3;
18267
- const sx = proj[b], sy = proj[b + 1], sz = proj[b + 2];
18268
- if (sz <= 0 || sz >= 1) return false;
18269
- const dx = sx - cx, dy = sy - cy;
18270
- return dx * dx / rx2 + dy * dy / ry2 <= 1;
18491
+ if (this.splatState.data[i] & (State.hidden | State.deleted)) return false;
18492
+ const i3 = i * 3;
18493
+ const lx = cpuPos[i3], ly = cpuPos[i3 + 1], lz = cpuPos[i3 + 2];
18494
+ const wx = modelMat[0] * lx + modelMat[4] * ly + modelMat[8] * lz + modelMat[12];
18495
+ const wy = modelMat[1] * lx + modelMat[5] * ly + modelMat[9] * lz + modelMat[13];
18496
+ const wz = modelMat[2] * lx + modelMat[6] * ly + modelMat[10] * lz + modelMat[14];
18497
+ const dx = wx - cx, dy = wy - cy, dz = wz - cz;
18498
+ return dx * dx + dy * dy + dz * dz <= r2;
18271
18499
  });
18272
18500
  this.editHistory.add(editOp);
18273
18501
  }
18274
18502
  /**
18275
- * 盒选择:在屏幕空间判断 splat 是否在矩形区域内
18503
+ * 世界空间 AABB 选择
18276
18504
  */
18277
- selectByBox(op, centerPx, halfWPx, halfHPx) {
18278
- this.ensureProjection();
18279
- const proj = this.projectedPositions;
18280
- if (!proj) return;
18281
- const w = this.container.clientWidth;
18282
- const h = this.container.clientHeight;
18283
- const cx = centerPx.x / w;
18284
- const cy = centerPx.y / h;
18285
- const hw = halfWPx / w;
18286
- const hh = halfHPx / h;
18287
- const left = cx - hw, right = cx + hw;
18288
- const top = cy - hh, bottom = cy + hh;
18505
+ selectByWorldBox(op, center, lenX, lenY, lenZ) {
18506
+ const cpuPos = this.gsRenderer.getCPUPositions();
18507
+ if (!cpuPos) return;
18508
+ const modelMat = this.gsRenderer.getModelMatrix();
18509
+ const [cx, cy, cz] = center;
18510
+ const hx = lenX / 2, hy = lenY / 2, hz = lenZ / 2;
18289
18511
  const editOp = new SelectOp(this.splatState, op, (i) => {
18290
- const b = i * 3;
18291
- const sx = proj[b], sy = proj[b + 1], sz = proj[b + 2];
18292
- if (sz <= 0 || sz >= 1) return false;
18293
- return sx >= left && sx <= right && sy >= top && sy <= bottom;
18512
+ if (this.splatState.data[i] & (State.hidden | State.deleted)) return false;
18513
+ const i3 = i * 3;
18514
+ const lx = cpuPos[i3], ly = cpuPos[i3 + 1], lz = cpuPos[i3 + 2];
18515
+ const wx = modelMat[0] * lx + modelMat[4] * ly + modelMat[8] * lz + modelMat[12];
18516
+ const wy = modelMat[1] * lx + modelMat[5] * ly + modelMat[9] * lz + modelMat[13];
18517
+ const wz = modelMat[2] * lx + modelMat[6] * ly + modelMat[10] * lz + modelMat[14];
18518
+ const rx = wx - cx, ry = wy - cy, rz = wz - cz;
18519
+ return rx >= -hx && rx <= hx && ry >= -hy && ry <= hy && rz >= -hz && rz <= hz;
18294
18520
  });
18295
18521
  this.editHistory.add(editOp);
18296
18522
  }
18523
+ /**
18524
+ * 应用当前体积选择
18525
+ */
18526
+ applyVolumeSelection(op) {
18527
+ if (!this.volumeRenderer) return;
18528
+ const vol = this.volumeRenderer.volume;
18529
+ if (!vol.type) return;
18530
+ if (vol.type === "sphere") {
18531
+ this.selectByWorldSphere(op, vol.center, vol.dimensions[0]);
18532
+ } else {
18533
+ this.selectByWorldBox(op, vol.center, vol.dimensions[0], vol.dimensions[1], vol.dimensions[2]);
18534
+ }
18535
+ }
18536
+ /**
18537
+ * 设置体积选择的中心位置(供外部 gizmo 调用)
18538
+ */
18539
+ setVolumeCenter(x, y, z) {
18540
+ var _a2;
18541
+ (_a2 = this.volumeRenderer) == null ? void 0 : _a2.setCenter(x, y, z);
18542
+ }
18543
+ /**
18544
+ * 获取当前体积状态
18545
+ */
18546
+ getVolumeState() {
18547
+ var _a2;
18548
+ return ((_a2 = this.volumeRenderer) == null ? void 0 : _a2.volume) ?? null;
18549
+ }
18550
+ /**
18551
+ * 创建体积位置的 TransformableObject 代理,供 gizmo 控制
18552
+ */
18553
+ createVolumeTransformProxy() {
18554
+ if (!this.volumeRenderer) return null;
18555
+ const vol = this.volumeRenderer;
18556
+ return {
18557
+ get position() {
18558
+ return vol.volume.center;
18559
+ },
18560
+ get rotation() {
18561
+ return [0, 0, 0];
18562
+ },
18563
+ get scale() {
18564
+ return [1, 1, 1];
18565
+ },
18566
+ setPosition: (x, y, z) => {
18567
+ vol.setCenter(x, y, z);
18568
+ },
18569
+ setRotation: () => {
18570
+ },
18571
+ setScale: () => {
18572
+ }
18573
+ };
18574
+ }
18575
+ /**
18576
+ * 获取模型包围盒中心(世界空间)
18577
+ */
18578
+ getModelCenter() {
18579
+ const cpuPos = this.gsRenderer.getCPUPositions();
18580
+ if (!cpuPos || cpuPos.length === 0) return [0, 0, 0];
18581
+ const modelMat = this.gsRenderer.getModelMatrix();
18582
+ const count = this.splatState.count;
18583
+ let sx = 0, sy = 0, sz = 0, n = 0;
18584
+ const step = Math.max(1, Math.floor(count / 1e3));
18585
+ for (let i = 0; i < count; i += step) {
18586
+ const i3 = i * 3;
18587
+ const lx = cpuPos[i3], ly = cpuPos[i3 + 1], lz = cpuPos[i3 + 2];
18588
+ sx += modelMat[0] * lx + modelMat[4] * ly + modelMat[8] * lz + modelMat[12];
18589
+ sy += modelMat[1] * lx + modelMat[5] * ly + modelMat[9] * lz + modelMat[13];
18590
+ sz += modelMat[2] * lx + modelMat[6] * ly + modelMat[10] * lz + modelMat[14];
18591
+ n++;
18592
+ }
18593
+ return n > 0 ? [sx / n, sy / n, sz / n] : [0, 0, 0];
18594
+ }
18297
18595
  /**
18298
18596
  * 根据屏幕像素坐标,找到最近的可见 splat 并返回其世界坐标及深度换算系数
18299
18597
  */
@@ -18498,6 +18796,8 @@ class App {
18498
18796
  __publicField(this, "baseRenderScale", 1);
18499
18797
  // 绑定的事件处理函数
18500
18798
  __publicField(this, "boundOnResize");
18799
+ /** 额外渲染回调(在 gizmo 之前、场景辅助之后执行) */
18800
+ __publicField(this, "extraRenderCallbacks", []);
18501
18801
  this.canvas = canvas;
18502
18802
  this.boundOnResize = this.onResize.bind(this);
18503
18803
  }
@@ -18943,6 +19243,7 @@ class App {
18943
19243
  }
18944
19244
  this.meshRenderer.render(pass);
18945
19245
  this.sceneAids.render(pass);
19246
+ for (const cb of this.extraRenderCallbacks) cb(pass);
18946
19247
  this.gizmoManager.render(pass);
18947
19248
  this.renderer.endFrame();
18948
19249
  if (this.hotspotManager.isActive()) {
@@ -19185,6 +19486,16 @@ class App {
19185
19486
  getRenderer() {
19186
19487
  return this.renderer;
19187
19488
  }
19489
+ /**
19490
+ * 注册额外的渲染回调(在场景辅助之后、gizmo 之前执行)
19491
+ */
19492
+ addRenderCallback(cb) {
19493
+ this.extraRenderCallbacks.push(cb);
19494
+ }
19495
+ removeRenderCallback(cb) {
19496
+ const idx = this.extraRenderCallbacks.indexOf(cb);
19497
+ if (idx >= 0) this.extraRenderCallbacks.splice(idx, 1);
19498
+ }
19188
19499
  /**
19189
19500
  * CPU splat 拾取:在屏幕坐标 (clientX, clientY) 处找最近的 splat,返回世界坐标或 null
19190
19501
  */
@@ -19583,6 +19894,7 @@ exports.Renderer = Renderer;
19583
19894
  exports.SHMode = SHMode;
19584
19895
  exports.SceneAidsRenderer = SceneAidsRenderer;
19585
19896
  exports.SceneManager = SceneManager;
19897
+ exports.SelectionVolumeRenderer = SelectionVolumeRenderer;
19586
19898
  exports.SkyboxRenderer = SkyboxRenderer;
19587
19899
  exports.SplatBoundingBoxProvider = SplatBoundingBoxProvider;
19588
19900
  exports.SplatEditor = SplatEditor;