viral-viewer-2 7.2.5 → 7.2.6

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,6 +2,11 @@ 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;
5
10
  export declare class ViralBatchedMesh extends Mesh {
6
11
  globalMaterialIndex: number;
7
12
  private workerPool;
@@ -110,6 +115,13 @@ export declare class ViralBatchedMesh extends Mesh {
110
115
  elementId: string;
111
116
  }[];
112
117
  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;
113
125
  /**
114
126
  * Hide elements by setting their alpha to 0 (GPU-accelerated)
115
127
  * Hidden elements are discarded in fragment shader - no rendering cost
@@ -1,6 +1,11 @@
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;
4
9
  export declare class ViralInstancedMeshV2 extends Object3D {
5
10
  protected material?: Material | undefined;
6
11
  globalMaterialIndex: number;
@@ -51,6 +56,12 @@ export declare class ViralInstancedMeshV2 extends Object3D {
51
56
  };
52
57
  }[]): void;
53
58
  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;
54
65
  /**
55
66
  * Changes the color of multiple elements.
56
67
  * @param elements - An array of elements, each containing `modelId` and `elementId`.
@@ -163,7 +174,10 @@ export declare class ViralInstancedMeshV2 extends Object3D {
163
174
  */
164
175
  isElementVisible(modelId: string, elementId: string): boolean;
165
176
  /**
166
- * Inject per-instance opacity shader into material
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)
167
181
  * Must be called after material is set and before rendering
168
182
  */
169
183
  injectOpacityShader(): void;
@@ -171,6 +185,11 @@ export declare class ViralInstancedMeshV2 extends Object3D {
171
185
  * Ensure all instanced meshes have opacity attribute
172
186
  */
173
187
  private _ensureOpacityAttributes;
188
+ /**
189
+ * Ensure all instanced meshes have selection attribute
190
+ * Used for fast outline detection via AlphaSelectionOutlinePass
191
+ */
192
+ private _ensureSelectionAttributes;
174
193
  /**
175
194
  * Update opacity for specific instances
176
195
  */
@@ -0,0 +1,49 @@
1
+ import type { WebGLRenderer } from "three";
2
+ import { Color, type Vector2, type WebGLRenderTarget } from "three";
3
+ import { Pass } from "three/examples/jsm/postprocessing/Pass";
4
+ /**
5
+ * Alpha-Based Selection Outline Pass (FASTEST)
6
+ *
7
+ * This is the FASTEST possible selection outline implementation because:
8
+ * - ZERO extra render passes for selection mask
9
+ * - ZERO geometry copying
10
+ * - O(pixels) cost - same for 1 or 10,000 selected elements
11
+ *
12
+ * How it works:
13
+ * 1. Selected elements have their alpha set to a special value (SELECTION_ALPHA = 0.99)
14
+ * 2. This pass detects edges where alpha equals SELECTION_ALPHA
15
+ * 3. Applies outline effect at those edges
16
+ *
17
+ * Requirements:
18
+ * - ViralBatchedMesh/ViralInstancedMesh must set alpha = 0.99 for selected vertices
19
+ * - Must run after main render pass but before tone mapping
20
+ */
21
+ export interface AlphaSelectionOutlineOptions {
22
+ /** Outline color (default: accent color) */
23
+ outlineColor: Color;
24
+ /** Outline opacity 0-1 (default: 1.0) */
25
+ outlineOpacity: number;
26
+ /** Outline thickness in pixels (default: 2.0) */
27
+ outlineThickness: number;
28
+ /** Alpha value that indicates selection (default: 0.99) */
29
+ selectionAlpha: number;
30
+ /** Tolerance for alpha detection (default: 0.005) */
31
+ alphaTolerance: number;
32
+ }
33
+ export declare const SELECTION_ALPHA = 0.99;
34
+ export declare class AlphaSelectionOutlinePass extends Pass {
35
+ private resolution;
36
+ private options;
37
+ private outlineMaterial;
38
+ private copyMaterial;
39
+ private fsQuad;
40
+ /** Fast bypass during camera movement */
41
+ bypass: boolean;
42
+ /** Whether there's any selection active */
43
+ hasSelection: boolean;
44
+ constructor(resolution: Vector2, options?: Partial<AlphaSelectionOutlineOptions>);
45
+ setOptions(options: Partial<AlphaSelectionOutlineOptions>): void;
46
+ render(renderer: WebGLRenderer, writeBuffer: WebGLRenderTarget, readBuffer: WebGLRenderTarget, _deltaTime?: number, _maskActive?: boolean): void;
47
+ setSize(width: number, height: number): void;
48
+ dispose(): void;
49
+ }
@@ -6,6 +6,7 @@ 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";
9
10
  import { type ScreenSpaceEdgesOptions, ScreenSpaceEdgesPass } from "./screen-space-edges-pass";
10
11
  import { type SelectionOutlineOptions, SelectionOutlinePass } from "./selection-outline-pass";
11
12
  export declare class PostProcessingRenderer {
@@ -26,6 +27,7 @@ export declare class PostProcessingRenderer {
26
27
  outlinePass: OutlinePass | null;
27
28
  screenSpaceEdgesPass: ScreenSpaceEdgesPass | null;
28
29
  selectionOutlinePass: SelectionOutlinePass | null;
30
+ alphaSelectionOutlinePass: AlphaSelectionOutlinePass | null;
29
31
  n8aoPass: any;
30
32
  perfChecker: DevicePerformanceChecker;
31
33
  constructor(renderer: WebGLRenderer, viralViewerApi: ViralViewerApi);
@@ -163,4 +165,43 @@ export declare class PostProcessingRenderer {
163
165
  * Set selection outline thickness in pixels
164
166
  */
165
167
  setSelectionOutlineThickness(thickness: number): void;
168
+ /**
169
+ * Initialize alpha-based selection outline pass
170
+ * ZERO extra render passes - detects selection via alpha channel in main render
171
+ * Cost: 1 fullscreen pass only (no geometry re-render)
172
+ *
173
+ * This is MUCH faster than SelectionOutlinePass for large selections
174
+ * Works with both batched meshes (per-vertex alpha) and instanced meshes (per-instance alpha)
175
+ */
176
+ initAlphaSelectionOutlinePass(): void;
177
+ /**
178
+ * Enable alpha selection outline rendering
179
+ */
180
+ enableAlphaSelectionOutline(): void;
181
+ /**
182
+ * Disable alpha selection outline rendering
183
+ */
184
+ disableAlphaSelectionOutline(): void;
185
+ /**
186
+ * Bypass alpha selection outline (instant, zero cost)
187
+ */
188
+ bypassAlphaSelectionOutline(): void;
189
+ /**
190
+ * Resume alpha selection outline after bypassing
191
+ */
192
+ resumeAlphaSelectionOutline(): void;
193
+ /**
194
+ * Set alpha selection outline color
195
+ */
196
+ setAlphaSelectionOutlineColor(color: Color | number | string): void;
197
+ /**
198
+ * Set alpha selection outline thickness in pixels
199
+ */
200
+ setAlphaSelectionOutlineThickness(thickness: number): void;
201
+ /**
202
+ * Update alpha selection outline state
203
+ * Call this when selection changes
204
+ * @param hasSelection - Whether there's any selection active
205
+ */
206
+ updateAlphaSelectionOutline(hasSelection: boolean): void;
166
207
  }
@@ -0,0 +1,54 @@
1
+ import type { WebGLRenderer } from "three";
2
+ import { Color, type Vector2, type WebGLRenderTarget } from "three";
3
+ import { Pass } from "three/examples/jsm/postprocessing/Pass";
4
+ /**
5
+ * Stencil-Based Selection Outline Pass (FAST)
6
+ *
7
+ * This is a MUCH faster alternative to geometry-based selection outline.
8
+ * Instead of copying vertex data, it reads from a selection mask texture
9
+ * that's been written to during the main render pass.
10
+ *
11
+ * Performance: O(pixels) instead of O(selected_vertices)
12
+ * - 1000 selected elements = same cost as 1 selected element
13
+ * - No geometry copying
14
+ * - No extra mesh rendering
15
+ *
16
+ * Requirements:
17
+ * - Selection mask must be written by ViralBatchedMesh/ViralInstancedMesh during render
18
+ * - Main renderer must call updateSelectionMask() before this pass runs
19
+ */
20
+ export interface StencilSelectionOutlineOptions {
21
+ /** Outline color (default: accent color) */
22
+ outlineColor: Color;
23
+ /** Outline opacity 0-1 (default: 1.0) */
24
+ outlineOpacity: number;
25
+ /** Outline thickness in pixels (default: 2.0) */
26
+ outlineThickness: number;
27
+ }
28
+ export declare class StencilSelectionOutlinePass extends Pass {
29
+ private resolution;
30
+ private options;
31
+ private selectionMaskTarget;
32
+ private outlineMaterial;
33
+ private copyMaterial;
34
+ private fsQuad;
35
+ bypass: boolean;
36
+ private hasSelection;
37
+ constructor(resolution: Vector2, options?: Partial<StencilSelectionOutlineOptions>);
38
+ /**
39
+ * Set the selection mask render target
40
+ * This should be called by the renderer after writing selection mask
41
+ */
42
+ setSelectionMaskTarget(target: WebGLRenderTarget | null): void;
43
+ /**
44
+ * Set whether there's an active selection
45
+ */
46
+ setHasSelection(value: boolean): void;
47
+ /**
48
+ * Update outline options
49
+ */
50
+ setOptions(options: Partial<StencilSelectionOutlineOptions>): void;
51
+ render(renderer: WebGLRenderer, writeBuffer: WebGLRenderTarget, readBuffer: WebGLRenderTarget, _deltaTime?: number, _maskActive?: boolean): void;
52
+ setSize(width: number, height: number): void;
53
+ dispose(): void;
54
+ }
@@ -189,6 +189,40 @@ export declare class ViralVisibilityManager {
189
189
  * Get whether selection outline mode is enabled
190
190
  */
191
191
  get selectionOutlineEnabled(): boolean;
192
+ /** Whether alpha selection outline is enabled (default: false, as it requires opt-in) */
193
+ private _alphaSelectionOutlineEnabled;
194
+ /**
195
+ * Update alpha selection outline state
196
+ * This is MUCH faster than updateSelectionOutline() - no geometry copying needed
197
+ */
198
+ updateAlphaSelectionOutline(): void;
199
+ /**
200
+ * Enable alpha selection outline effect
201
+ * This is the FAST outline mode - constant cost regardless of selection size
202
+ */
203
+ enableAlphaSelectionOutline(): void;
204
+ /**
205
+ * Disable alpha selection outline effect
206
+ */
207
+ disableAlphaSelectionOutline(): void;
208
+ /**
209
+ * Set whether alpha selection outline mode is enabled
210
+ * This is the recommended mode for large selections (1000+ elements)
211
+ * @param enabled - true to enable, false to disable
212
+ */
213
+ setAlphaSelectionOutlineMode(enabled: boolean): void;
214
+ /**
215
+ * Get whether alpha selection outline mode is enabled
216
+ */
217
+ get alphaSelectionOutlineEnabled(): boolean;
218
+ /**
219
+ * Bypass alpha selection outline (fast, for camera movement)
220
+ */
221
+ bypassAlphaSelectionOutline(): void;
222
+ /**
223
+ * Resume alpha selection outline after bypass
224
+ */
225
+ resumeAlphaSelectionOutline(): void;
192
226
  enableNight(): void;
193
227
  disableNight(): void;
194
228
  enableSectionBox(): void;