@chocozhang/three-model-render 1.0.6 → 2.0.1
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/README.md +248 -126
- package/dist/core/index.d.ts +186 -45
- package/dist/core/index.js +326 -203
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +318 -203
- package/dist/core/index.mjs.map +1 -1
- package/dist/index.d.ts +356 -56
- package/dist/index.js +923 -284
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +913 -284
- package/dist/index.mjs.map +1 -1
- package/dist/ui/index.d.ts +171 -11
- package/dist/ui/index.js +745 -81
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/index.mjs +744 -82
- package/dist/ui/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/ui/index.d.ts
CHANGED
|
@@ -3,45 +3,205 @@ import * as THREE from 'three';
|
|
|
3
3
|
/**
|
|
4
4
|
* @file modelsLabel.ts
|
|
5
5
|
* @description
|
|
6
|
-
* Creates interactive 2D labels (DOM elements) attached to 3D objects
|
|
6
|
+
* Creates interactive 2D labels (DOM elements) attached to 3D objects.
|
|
7
|
+
* unified tool replacing the old labelManager.ts and modelsLabel.ts.
|
|
7
8
|
*
|
|
8
9
|
* @best-practice
|
|
9
10
|
* - Use `createModelsLabel` to annotate parts of a model.
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
11
|
+
* - set `style: 'line'` (default) for labels with connecting lines and pulsing dots.
|
|
12
|
+
* - set `style: 'simple'` for simple overhead labels (like the old labelManager).
|
|
12
13
|
*/
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Configuration options for the labeling system.
|
|
17
|
+
*/
|
|
14
18
|
interface LabelOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Label style:
|
|
21
|
+
* - 'simple': Traditional overhead text label.
|
|
22
|
+
* - 'line': Modern callout with a connecting line and pulsing status dot.
|
|
23
|
+
*/
|
|
24
|
+
style?: 'simple' | 'line';
|
|
25
|
+
/** Font size for the label text. Default is '12px'. */
|
|
15
26
|
fontSize?: string;
|
|
27
|
+
/** Text color. Default is '#ffffff'. */
|
|
16
28
|
color?: string;
|
|
29
|
+
/** Background color of the label. Supports CSS color strings. */
|
|
17
30
|
background?: string;
|
|
31
|
+
/** CSS padding for the label. Default is '6px 10px'. */
|
|
18
32
|
padding?: string;
|
|
33
|
+
/** CSS border radius for the label. Default is '6px'. */
|
|
19
34
|
borderRadius?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Vertical lift amount in pixels.
|
|
37
|
+
* For 'line' style, this determines the length of the callout line.
|
|
38
|
+
*/
|
|
20
39
|
lift?: number;
|
|
40
|
+
/** Diameter of the status dot in pixels (for 'line' style). */
|
|
21
41
|
dotSize?: number;
|
|
42
|
+
/** Spacing between the status dot and the label text. */
|
|
22
43
|
dotSpacing?: number;
|
|
44
|
+
/** Color of the connecting line. */
|
|
23
45
|
lineColor?: string;
|
|
46
|
+
/** Width of the connecting line in pixels. */
|
|
24
47
|
lineWidth?: number;
|
|
48
|
+
/** Throttling interval for position updates in milliseconds. 0 is per-frame. */
|
|
25
49
|
updateInterval?: number;
|
|
50
|
+
/** Duration of the fade-in animation in milliseconds. */
|
|
26
51
|
fadeInDuration?: number;
|
|
52
|
+
/** Number of frames to skip between occlusion checks. Increase to improve performance. */
|
|
53
|
+
occlusionCheckInterval?: number;
|
|
54
|
+
/** Whether to enable raycasting-based occlusion detection. Default is true. */
|
|
55
|
+
enableOcclusionDetection?: boolean;
|
|
56
|
+
/** Threshold for camera movement to trigger an update. Higher values reduce CPU usage. */
|
|
57
|
+
cameraMoveThreshold?: number;
|
|
58
|
+
/** Maximum distance from camera at which labels are visible. */
|
|
59
|
+
maxDistance?: number;
|
|
27
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Interface for controlling the label system instance.
|
|
63
|
+
*/
|
|
28
64
|
interface LabelManager {
|
|
65
|
+
/** Rebuilds labels for a different model. */
|
|
29
66
|
updateModel: (model: THREE.Object3D) => void;
|
|
67
|
+
/** Updates the mapping of mesh names to label text. */
|
|
30
68
|
updateLabelsMap: (map: Record<string, string>) => void;
|
|
69
|
+
/** Temporarily stops position updates and occlusion checks. */
|
|
31
70
|
pause: () => void;
|
|
71
|
+
/** Resumes position updates. */
|
|
32
72
|
resume: () => void;
|
|
73
|
+
/** Completely removes all labels and cleans up resources. */
|
|
33
74
|
dispose: () => void;
|
|
75
|
+
/** Returns the current running state. */
|
|
76
|
+
isRunning: () => boolean;
|
|
34
77
|
}
|
|
35
78
|
/**
|
|
36
|
-
*
|
|
79
|
+
* Initializes the unified labeling system for a specific model.
|
|
80
|
+
*
|
|
81
|
+
* Performance:
|
|
82
|
+
* - Uses Object Pooling for all Vector3/Box3 operations to minimize GC.
|
|
83
|
+
* - Throttles updates based on camera movement and configurable intervals.
|
|
84
|
+
* - Optimized occlusion detection with frame-skipping.
|
|
37
85
|
*
|
|
38
|
-
*
|
|
39
|
-
* -
|
|
40
|
-
* -
|
|
41
|
-
* -
|
|
42
|
-
* -
|
|
43
|
-
*
|
|
86
|
+
* @param {THREE.Camera} camera - The active camera used for projection.
|
|
87
|
+
* @param {THREE.WebGLRenderer} renderer - The renderer used for dimension calculations.
|
|
88
|
+
* @param {THREE.Object3D} parentModel - The model to search for meshes to label.
|
|
89
|
+
* @param {Record<string, string>} modelLabelsMap - Mapping of part name substrings to label text.
|
|
90
|
+
* @param {LabelOptions} [options] - Configuration for styles and performance.
|
|
91
|
+
* @returns {LabelManager} Controls to manage the lifecycle of the labels.
|
|
44
92
|
*/
|
|
45
93
|
declare function createModelsLabel(camera: THREE.Camera, renderer: THREE.WebGLRenderer, parentModel: THREE.Object3D, modelLabelsMap: Record<string, string>, options?: LabelOptions): LabelManager;
|
|
46
94
|
|
|
47
|
-
|
|
95
|
+
/**
|
|
96
|
+
* @file performanceStats.ts
|
|
97
|
+
* @description
|
|
98
|
+
* Real-time performance monitoring overlay for Three.js applications.
|
|
99
|
+
* Displays FPS, memory usage, draw calls, and performance warnings.
|
|
100
|
+
*
|
|
101
|
+
* @best-practice
|
|
102
|
+
* - Create once during initialization
|
|
103
|
+
* - Call update() in your animation loop
|
|
104
|
+
* - Use minimal styling for low performance impact
|
|
105
|
+
*
|
|
106
|
+
* @performance
|
|
107
|
+
* - Uses requestAnimationFrame for efficient updates
|
|
108
|
+
* - DOM updates are batched and throttled
|
|
109
|
+
* - Minimal memory footprint
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Options for configuring the performance monitoring overlay.
|
|
114
|
+
*/
|
|
115
|
+
interface PerformanceStatsOptions {
|
|
116
|
+
/** Position of the stats overlay on the screen. Default is 'top-left'. */
|
|
117
|
+
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
118
|
+
/** Refresh interval for DOM updates in milliseconds. Default is 500ms. */
|
|
119
|
+
updateInterval?: number;
|
|
120
|
+
/** Whether to track and display JS heap memory usage. Default is true. */
|
|
121
|
+
enableMemoryTracking?: boolean;
|
|
122
|
+
/** Whether to show visual warnings when performance drops. Default is true. */
|
|
123
|
+
enableWarnings?: boolean;
|
|
124
|
+
/** Optional WebGLRenderer to track draw calls and triangle counts. */
|
|
125
|
+
renderer?: THREE.WebGLRenderer | null;
|
|
126
|
+
/** FPS threshold below which a warning is triggered. Default is 30. */
|
|
127
|
+
fpsWarningThreshold?: number;
|
|
128
|
+
/** Memory usage threshold (in MB) above which a warning is triggered. Default is 200. */
|
|
129
|
+
memoryWarningThreshold?: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Performance Stats Monitor
|
|
133
|
+
* Lightweight FPS and memory monitoring overlay
|
|
134
|
+
*/
|
|
135
|
+
declare class PerformanceStats {
|
|
136
|
+
private container;
|
|
137
|
+
private fpsElement;
|
|
138
|
+
private memoryElement;
|
|
139
|
+
private drawCallsElement;
|
|
140
|
+
private trianglesElement;
|
|
141
|
+
private warningsContainer;
|
|
142
|
+
private frames;
|
|
143
|
+
private lastTime;
|
|
144
|
+
private fps;
|
|
145
|
+
private fpsHistory;
|
|
146
|
+
private maxHistoryLength;
|
|
147
|
+
private updateInterval;
|
|
148
|
+
private lastUpdateTime;
|
|
149
|
+
private warnings;
|
|
150
|
+
private maxWarnings;
|
|
151
|
+
private enabled;
|
|
152
|
+
private isVisible;
|
|
153
|
+
private options;
|
|
154
|
+
constructor(options?: PerformanceStatsOptions);
|
|
155
|
+
private setPosition;
|
|
156
|
+
private injectStyles;
|
|
157
|
+
/**
|
|
158
|
+
* Updates the performance statistics. This method must be called within the application's animation loop.
|
|
159
|
+
*/
|
|
160
|
+
update(): void;
|
|
161
|
+
private formatNumber;
|
|
162
|
+
private addWarning;
|
|
163
|
+
private updateWarningsDisplay;
|
|
164
|
+
/**
|
|
165
|
+
* Gets the current frames per second (FPS).
|
|
166
|
+
* @returns {number} The current FPS.
|
|
167
|
+
*/
|
|
168
|
+
getFPS(): number;
|
|
169
|
+
/**
|
|
170
|
+
* Gets the average FPS over the recent history period.
|
|
171
|
+
* @returns {number} The average FPS.
|
|
172
|
+
*/
|
|
173
|
+
getAverageFPS(): number;
|
|
174
|
+
/**
|
|
175
|
+
* Returns a snapshot of all tracked performance metrics.
|
|
176
|
+
* @returns {object} Current performance statistics.
|
|
177
|
+
*/
|
|
178
|
+
getStats(): any;
|
|
179
|
+
/**
|
|
180
|
+
* Toggles the visibility of the performance stats overlay.
|
|
181
|
+
*/
|
|
182
|
+
toggle(): void;
|
|
183
|
+
/**
|
|
184
|
+
* Shows the performance stats overlay.
|
|
185
|
+
*/
|
|
186
|
+
show(): void;
|
|
187
|
+
/**
|
|
188
|
+
* Hides the performance stats overlay.
|
|
189
|
+
*/
|
|
190
|
+
hide(): void;
|
|
191
|
+
/**
|
|
192
|
+
* Enables or disables performance statistics collection.
|
|
193
|
+
* @param {boolean} enabled - Whether collection should be enabled.
|
|
194
|
+
*/
|
|
195
|
+
setEnabled(enabled: boolean): void;
|
|
196
|
+
/**
|
|
197
|
+
* Disposes of the performance monitor and removes its DOM elements.
|
|
198
|
+
*/
|
|
199
|
+
dispose(): void;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Helper function to create performance monitor
|
|
203
|
+
*/
|
|
204
|
+
declare function createPerformanceMonitor(options?: PerformanceStatsOptions): PerformanceStats;
|
|
205
|
+
|
|
206
|
+
export { PerformanceStats, createModelsLabel, createPerformanceMonitor };
|
|
207
|
+
export type { PerformanceStatsOptions };
|