viral-viewer-2 7.2.3 → 7.2.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.
@@ -2,11 +2,6 @@ import { Box3, BufferGeometry, type Color, type Material, Mesh, Vector3 } from "
2
2
  import { type LineMaterial } from "three/examples/jsm/Addons";
3
3
  import { type BufferElement } from "../..";
4
4
  import type { WorkerThreadPool } from "../worker/base/worker-pool";
5
- /**
6
- * Special alpha value to mark selected vertices for fast outline detection.
7
- * The AlphaSelectionOutlinePass detects this value with ZERO extra render passes.
8
- */
9
- export declare const SELECTION_ALPHA = 0.99;
10
5
  export declare class ViralBatchedMesh extends Mesh {
11
6
  globalMaterialIndex: number;
12
7
  private workerPool;
@@ -115,13 +110,6 @@ export declare class ViralBatchedMesh extends Mesh {
115
110
  elementId: string;
116
111
  }[];
117
112
  unselect(): void;
118
- /**
119
- * Set alpha value for elements (used for selection marking)
120
- * This is VERY fast - only updates alpha channel, no geometry copying
121
- *
122
- * When setting alpha to 1.0 (removing selection), respects hidden/isolated state
123
- */
124
- private _setSelectionAlpha;
125
113
  /**
126
114
  * Hide elements by setting their alpha to 0 (GPU-accelerated)
127
115
  * Hidden elements are discarded in fragment shader - no rendering cost
@@ -1,11 +1,6 @@
1
1
  import { Box3, BufferGeometry, Color, InstancedMesh, type Material, Matrix4, Object3D, Vector3 } from "three";
2
2
  import { type LineMaterial } from "three/examples/jsm/Addons";
3
3
  import { type BufferElement } from "../..";
4
- /**
5
- * Special alpha value to mark selected instances for fast outline detection.
6
- * Note: Instanced meshes use a separate instanceSelected attribute instead of alpha.
7
- */
8
- export declare const SELECTION_ALPHA = 0.99;
9
4
  export declare class ViralInstancedMeshV2 extends Object3D {
10
5
  protected material?: Material | undefined;
11
6
  globalMaterialIndex: number;
@@ -56,12 +51,6 @@ export declare class ViralInstancedMeshV2 extends Object3D {
56
51
  };
57
52
  }[]): void;
58
53
  unselect(): void;
59
- /**
60
- * Set instance selection state for fast outline detection
61
- * @param elements - Elements to set selection for
62
- * @param selected - 1.0 = selected, 0.0 = not selected
63
- */
64
- private _setInstanceSelection;
65
54
  /**
66
55
  * Changes the color of multiple elements.
67
56
  * @param elements - An array of elements, each containing `modelId` and `elementId`.
@@ -174,10 +163,7 @@ export declare class ViralInstancedMeshV2 extends Object3D {
174
163
  */
175
164
  isElementVisible(modelId: string, elementId: string): boolean;
176
165
  /**
177
- * Inject per-instance opacity and selection shader into material
178
- * Enables:
179
- * - Per-instance opacity (ghosting, hiding)
180
- * - Selection alpha marker (for fast outline detection via AlphaSelectionOutlinePass)
166
+ * Inject per-instance opacity shader into material
181
167
  * Must be called after material is set and before rendering
182
168
  */
183
169
  injectOpacityShader(): void;
@@ -185,11 +171,6 @@ export declare class ViralInstancedMeshV2 extends Object3D {
185
171
  * Ensure all instanced meshes have opacity attribute
186
172
  */
187
173
  private _ensureOpacityAttributes;
188
- /**
189
- * Ensure all instanced meshes have selection attribute
190
- * Used for fast outline detection via AlphaSelectionOutlinePass
191
- */
192
- private _ensureSelectionAttributes;
193
174
  /**
194
175
  * Update opacity for specific instances
195
176
  */
@@ -6,7 +6,6 @@ import { ShaderPass } from "three/examples/jsm/postprocessing/ShaderPass";
6
6
  import { SMAAPass } from "three/examples/jsm/postprocessing/SMAAPass";
7
7
  import { type ViralViewerApi } from "../..";
8
8
  import { DevicePerformanceChecker } from "../../utils/device";
9
- import { AlphaSelectionOutlinePass } from "./alpha-selection-outline-pass";
10
9
  import { type ScreenSpaceEdgesOptions, ScreenSpaceEdgesPass } from "./screen-space-edges-pass";
11
10
  import { type SelectionOutlineOptions, SelectionOutlinePass } from "./selection-outline-pass";
12
11
  export declare class PostProcessingRenderer {
@@ -27,7 +26,6 @@ export declare class PostProcessingRenderer {
27
26
  outlinePass: OutlinePass | null;
28
27
  screenSpaceEdgesPass: ScreenSpaceEdgesPass | null;
29
28
  selectionOutlinePass: SelectionOutlinePass | null;
30
- alphaSelectionOutlinePass: AlphaSelectionOutlinePass | null;
31
29
  n8aoPass: any;
32
30
  perfChecker: DevicePerformanceChecker;
33
31
  constructor(renderer: WebGLRenderer, viralViewerApi: ViralViewerApi);
@@ -129,6 +127,11 @@ export declare class PostProcessingRenderer {
129
127
  * @param positions - Merged Float32Array of selected element positions, or null to clear
130
128
  */
131
129
  updateSelectionOutline(positions: Float32Array | null): void;
130
+ /**
131
+ * Notify the outline pass whether elements are currently selected.
132
+ * The GPU reads selection state directly from vertex colors — no data transfer needed.
133
+ */
134
+ setSelectionOutlineActive(hasSelection: boolean): void;
132
135
  /**
133
136
  * Enable selection outline rendering
134
137
  */
@@ -160,43 +163,4 @@ export declare class PostProcessingRenderer {
160
163
  * Set selection outline thickness in pixels
161
164
  */
162
165
  setSelectionOutlineThickness(thickness: number): void;
163
- /**
164
- * Initialize alpha-based selection outline pass
165
- * ZERO extra render passes - detects selection via alpha channel in main render
166
- * Cost: 1 fullscreen pass only (no geometry re-render)
167
- *
168
- * This is MUCH faster than SelectionOutlinePass for large selections
169
- * Works with both batched meshes (per-vertex alpha) and instanced meshes (per-instance alpha)
170
- */
171
- initAlphaSelectionOutlinePass(): void;
172
- /**
173
- * Enable alpha selection outline rendering
174
- */
175
- enableAlphaSelectionOutline(): void;
176
- /**
177
- * Disable alpha selection outline rendering
178
- */
179
- disableAlphaSelectionOutline(): void;
180
- /**
181
- * Bypass alpha selection outline (instant, zero cost)
182
- */
183
- bypassAlphaSelectionOutline(): void;
184
- /**
185
- * Resume alpha selection outline after bypassing
186
- */
187
- resumeAlphaSelectionOutline(): void;
188
- /**
189
- * Set alpha selection outline color
190
- */
191
- setAlphaSelectionOutlineColor(color: Color | number | string): void;
192
- /**
193
- * Set alpha selection outline thickness in pixels
194
- */
195
- setAlphaSelectionOutlineThickness(thickness: number): void;
196
- /**
197
- * Update alpha selection outline state
198
- * Call this when selection changes
199
- * @param hasSelection - Whether there's any selection active
200
- */
201
- updateAlphaSelectionOutline(hasSelection: boolean): void;
202
166
  }
@@ -1,14 +1,17 @@
1
- import type { Camera, WebGLRenderer } from "three";
2
- import { Color, Scene, type Vector2, WebGLRenderTarget } from "three";
1
+ import type { Camera, Vector2, WebGLRenderer } from "three";
2
+ import { Color, type Scene, WebGLRenderTarget } from "three";
3
3
  import { Pass } from "three/examples/jsm/postprocessing/Pass";
4
4
  /**
5
5
  * Selection Outline Pass
6
6
  *
7
- * Lightweight outline effect for selected elements in merged geometry.
8
- * Cost: 1 extra draw call (for mask) + 1 fullscreen Sobel pass
7
+ * GPU-based outline effect for selected elements.
8
+ * Renders the scene with a filter shader that outputs white only for
9
+ * fragments matching the selection color — zero CPU vertex work.
10
+ *
11
+ * Cost: 1-2 extra draw calls (mask render with overrideMaterial) + 1 fullscreen Sobel pass
9
12
  *
10
13
  * Process:
11
- * 1. Render selected geometry to mask texture (white on black)
14
+ * 1. Render entire scene with overrideMaterial that filters by SELECT_COLOR
12
15
  * 2. Sobel edge detection on mask
13
16
  * 3. Composite colored edges over scene
14
17
  */
@@ -25,30 +28,33 @@ export interface SelectionOutlineOptions {
25
28
  occludedOpacity: number;
26
29
  }
27
30
  export declare class SelectionOutlinePass extends Pass {
31
+ private scene;
28
32
  private camera;
29
33
  private resolution;
30
34
  private options;
31
35
  private maskRenderTarget;
32
36
  private maskDepthRenderTarget;
33
- private maskMaterial;
37
+ private selectionFilterMaterial;
38
+ private selectionFilterMaterialDepth;
34
39
  private outlineMaterial;
35
40
  private copyMaterial;
36
- private maskScene;
37
- private selectionMesh;
38
- private selectionGeometry;
39
41
  private fsQuad;
40
42
  private hasSelection;
41
43
  /**
42
- * 🔧 FAST TOGGLE:
44
+ * FAST TOGGLE:
43
45
  * - `bypass = false`: Full outline rendering (normal mode)
44
46
  * - `bypass = true`: Pass runs but just copies input to output (very fast, no mask render)
45
47
  */
46
48
  bypass: boolean;
47
- constructor(_scene: Scene, camera: Camera, resolution: Vector2, options?: Partial<SelectionOutlineOptions>);
49
+ constructor(scene: Scene, camera: Camera, resolution: Vector2, options?: Partial<SelectionOutlineOptions>);
50
+ /**
51
+ * Notify the pass whether there is an active selection.
52
+ * No data transfer needed — the GPU reads selection state from vertex colors.
53
+ */
54
+ setHasSelection(hasSelection: boolean): void;
48
55
  /**
49
- * Update selection geometry from buffer elements
50
- * Call this when selection changes
51
- * @param positions - Merged Float32Array of all selected element positions
56
+ * Legacy method kept for backward compatibility.
57
+ * With the GPU-based approach, this just toggles hasSelection.
52
58
  */
53
59
  updateSelectionGeometry(positions: Float32Array | null): void;
54
60
  /**
@@ -60,6 +66,7 @@ export declare class SelectionOutlinePass extends Pass {
60
66
  */
61
67
  setOptions(options: Partial<SelectionOutlineOptions>): void;
62
68
  render(renderer: WebGLRenderer, writeBuffer: WebGLRenderTarget, readBuffer: WebGLRenderTarget, _deltaTime?: number, _maskActive?: boolean): void;
69
+ private _renderCopyPass;
63
70
  setSize(width: number, height: number): void;
64
71
  dispose(): void;
65
72
  }
@@ -11,7 +11,7 @@ export declare class ViralVisibilityManager {
11
11
  */
12
12
  showAll2(): void;
13
13
  /**
14
- * hide all elements and reset back to normal visualization
14
+ * Hide all elements (sets all meshes invisible)
15
15
  */
16
16
  hideAllElements(): void;
17
17
  /**
@@ -167,6 +167,11 @@ export declare class ViralVisibilityManager {
167
167
  * Uses merged geometry for efficient rendering
168
168
  */
169
169
  updateSelectionOutline(): void;
170
+ /**
171
+ * Notify the outline pass whether there is an active selection.
172
+ * The GPU reads selection state directly from vertex colors — no CPU work needed.
173
+ */
174
+ private notifySelectionOutline;
170
175
  /**
171
176
  * Enable selection outline effect
172
177
  */
@@ -184,40 +189,6 @@ export declare class ViralVisibilityManager {
184
189
  * Get whether selection outline mode is enabled
185
190
  */
186
191
  get selectionOutlineEnabled(): boolean;
187
- /** Whether alpha selection outline is enabled (default: false, as it requires opt-in) */
188
- private _alphaSelectionOutlineEnabled;
189
- /**
190
- * Update alpha selection outline state
191
- * This is MUCH faster than updateSelectionOutline() - no geometry copying needed
192
- */
193
- updateAlphaSelectionOutline(): void;
194
- /**
195
- * Enable alpha selection outline effect
196
- * This is the FAST outline mode - constant cost regardless of selection size
197
- */
198
- enableAlphaSelectionOutline(): void;
199
- /**
200
- * Disable alpha selection outline effect
201
- */
202
- disableAlphaSelectionOutline(): void;
203
- /**
204
- * Set whether alpha selection outline mode is enabled
205
- * This is the recommended mode for large selections (1000+ elements)
206
- * @param enabled - true to enable, false to disable
207
- */
208
- setAlphaSelectionOutlineMode(enabled: boolean): void;
209
- /**
210
- * Get whether alpha selection outline mode is enabled
211
- */
212
- get alphaSelectionOutlineEnabled(): boolean;
213
- /**
214
- * Bypass alpha selection outline (fast, for camera movement)
215
- */
216
- bypassAlphaSelectionOutline(): void;
217
- /**
218
- * Resume alpha selection outline after bypass
219
- */
220
- resumeAlphaSelectionOutline(): void;
221
192
  enableNight(): void;
222
193
  disableNight(): void;
223
194
  enableSectionBox(): void;