viral-viewer-2 7.2.2 → 7.2.3
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/components/custom-objects/viral-batched-mesh.d.ts +12 -0
- package/dist/components/custom-objects/viral-instanced-mesh-v2.d.ts +20 -1
- package/dist/components/post-processing/alpha-selection-outline-pass.d.ts +49 -0
- package/dist/components/post-processing/post-processing-renderer.d.ts +41 -0
- package/dist/components/post-processing/stencil-selection-outline-pass.d.ts +54 -0
- package/dist/components/visibility-manager/viral-visibility-manager.d.ts +34 -0
- package/dist/index.mjs +1055 -724
- package/package.json +1 -1
|
@@ -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);
|
|
@@ -158,4 +160,43 @@ export declare class PostProcessingRenderer {
|
|
|
158
160
|
* Set selection outline thickness in pixels
|
|
159
161
|
*/
|
|
160
162
|
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;
|
|
161
202
|
}
|
|
@@ -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
|
+
}
|
|
@@ -184,6 +184,40 @@ export declare class ViralVisibilityManager {
|
|
|
184
184
|
* Get whether selection outline mode is enabled
|
|
185
185
|
*/
|
|
186
186
|
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;
|
|
187
221
|
enableNight(): void;
|
|
188
222
|
disableNight(): void;
|
|
189
223
|
enableSectionBox(): void;
|