@chocozhang/three-model-render 1.0.3 → 1.0.4
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 +93 -96
- package/dist/camera/index.d.ts +59 -36
- package/dist/camera/index.js +77 -57
- package/dist/camera/index.js.map +1 -1
- package/dist/camera/index.mjs +77 -57
- package/dist/camera/index.mjs.map +1 -1
- package/dist/core/index.d.ts +60 -27
- package/dist/core/index.js +124 -95
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +124 -95
- package/dist/core/index.mjs.map +1 -1
- package/dist/effect/index.d.ts +47 -134
- package/dist/effect/index.js +109 -65
- package/dist/effect/index.js.map +1 -1
- package/dist/effect/index.mjs +109 -65
- package/dist/effect/index.mjs.map +1 -1
- package/dist/index.d.ts +397 -341
- package/dist/index.js +651 -472
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +651 -472
- package/dist/index.mjs.map +1 -1
- package/dist/interaction/index.d.ts +85 -52
- package/dist/interaction/index.js +161 -133
- package/dist/interaction/index.js.map +1 -1
- package/dist/interaction/index.mjs +161 -133
- package/dist/interaction/index.mjs.map +1 -1
- package/dist/loader/index.d.ts +89 -56
- package/dist/loader/index.js +115 -76
- package/dist/loader/index.js.map +1 -1
- package/dist/loader/index.mjs +115 -76
- package/dist/loader/index.mjs.map +1 -1
- package/dist/setup/index.d.ts +28 -18
- package/dist/setup/index.js +33 -24
- package/dist/setup/index.js.map +1 -1
- package/dist/setup/index.mjs +33 -24
- package/dist/setup/index.mjs.map +1 -1
- package/dist/ui/index.d.ts +18 -7
- package/dist/ui/index.js +32 -22
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/index.mjs +32 -22
- package/dist/ui/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,17 @@ import { OutlinePass } from 'three/examples/jsm/postprocessing/OutlinePass';
|
|
|
3
3
|
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer';
|
|
4
4
|
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @file labelManager.ts
|
|
8
|
+
* @description
|
|
9
|
+
* Manages HTML labels attached to 3D objects. Efficiently updates label positions based on camera movement.
|
|
10
|
+
*
|
|
11
|
+
* @best-practice
|
|
12
|
+
* - Use `addChildModelLabels` to label parts of a loaded model.
|
|
13
|
+
* - Labels are HTML elements overlaid on the canvas.
|
|
14
|
+
* - Supports performance optimization via caching and visibility culling.
|
|
15
|
+
*/
|
|
16
|
+
|
|
6
17
|
interface LabelOptions$1 {
|
|
7
18
|
fontSize?: string;
|
|
8
19
|
color?: string;
|
|
@@ -19,23 +30,34 @@ interface LabelManager$1 {
|
|
|
19
30
|
isRunning: () => boolean;
|
|
20
31
|
}
|
|
21
32
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* -
|
|
26
|
-
* -
|
|
27
|
-
* -
|
|
28
|
-
* -
|
|
29
|
-
*
|
|
30
|
-
* @param camera THREE.Camera -
|
|
31
|
-
* @param renderer THREE.WebGLRenderer -
|
|
32
|
-
* @param parentModel THREE.Object3D - FBX
|
|
33
|
-
* @param modelLabelsMap Record<string,string> -
|
|
34
|
-
* @param options LabelOptions -
|
|
35
|
-
* @returns LabelManager -
|
|
33
|
+
* Add overhead labels to child models (supports Mesh and Group)
|
|
34
|
+
*
|
|
35
|
+
* Features:
|
|
36
|
+
* - Caches bounding boxes to avoid repetitive calculation every frame
|
|
37
|
+
* - Supports pause/resume
|
|
38
|
+
* - Configurable update interval to reduce CPU usage
|
|
39
|
+
* - Automatically pauses when hidden
|
|
40
|
+
*
|
|
41
|
+
* @param camera THREE.Camera - Scene camera
|
|
42
|
+
* @param renderer THREE.WebGLRenderer - Renderer, used for screen size
|
|
43
|
+
* @param parentModel THREE.Object3D - FBX root node or Group
|
|
44
|
+
* @param modelLabelsMap Record<string,string> - Map of model name to label text
|
|
45
|
+
* @param options LabelOptions - Optional label style configuration
|
|
46
|
+
* @returns LabelManager - Management interface containing pause/resume/dispose
|
|
36
47
|
*/
|
|
37
48
|
declare function addChildModelLabels(camera: THREE.Camera, renderer: THREE.WebGLRenderer, parentModel: THREE.Object3D, modelLabelsMap: Record<string, string>, options?: LabelOptions$1): LabelManager$1;
|
|
38
49
|
|
|
50
|
+
/**
|
|
51
|
+
* @file hoverEffect.ts
|
|
52
|
+
* @description
|
|
53
|
+
* Singleton highlight effect manager. Uses OutlinePass to create a breathing highlight effect on hovered objects.
|
|
54
|
+
*
|
|
55
|
+
* @best-practice
|
|
56
|
+
* - Initialize once in your setup/mounted hook.
|
|
57
|
+
* - Call `updateHighlightNames` to filter which objects are interactive.
|
|
58
|
+
* - Automatically handles mousemove throttling and cleanup on dispose.
|
|
59
|
+
*/
|
|
60
|
+
|
|
39
61
|
type HoverBreathOptions = {
|
|
40
62
|
camera: THREE.Camera;
|
|
41
63
|
scene: THREE.Scene;
|
|
@@ -48,13 +70,13 @@ type HoverBreathOptions = {
|
|
|
48
70
|
throttleDelay?: number;
|
|
49
71
|
};
|
|
50
72
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
73
|
+
* Create a singleton highlighter - Recommended to create once on mount
|
|
74
|
+
* Returns { updateHighlightNames, dispose, getHoveredName } interface
|
|
53
75
|
*
|
|
54
|
-
*
|
|
55
|
-
* -
|
|
56
|
-
* - mousemove
|
|
57
|
-
* -
|
|
76
|
+
* Features:
|
|
77
|
+
* - Automatically pauses animation when no object is hovered
|
|
78
|
+
* - Throttles mousemove events to avoid excessive calculation
|
|
79
|
+
* - Uses passive event listeners to improve scrolling performance
|
|
58
80
|
*/
|
|
59
81
|
declare function enableHoverBreath(opts: HoverBreathOptions): {
|
|
60
82
|
updateHighlightNames: (names: string[] | null) => void;
|
|
@@ -64,7 +86,18 @@ declare function enableHoverBreath(opts: HoverBreathOptions): {
|
|
|
64
86
|
};
|
|
65
87
|
|
|
66
88
|
/**
|
|
67
|
-
*
|
|
89
|
+
* @file postProcessing.ts
|
|
90
|
+
* @description
|
|
91
|
+
* Manages the post-processing chain, specifically for Outline effects and Gamma correction.
|
|
92
|
+
*
|
|
93
|
+
* @best-practice
|
|
94
|
+
* - call `initPostProcessing` after creating your renderer and scene.
|
|
95
|
+
* - Use the returned `composer` in your render loop instead of `renderer.render`.
|
|
96
|
+
* - Handles resizing automatically via the `resize` method.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Post-processing configuration options
|
|
68
101
|
*/
|
|
69
102
|
interface PostProcessingOptions {
|
|
70
103
|
edgeStrength?: number;
|
|
@@ -75,7 +108,7 @@ interface PostProcessingOptions {
|
|
|
75
108
|
resolutionScale?: number;
|
|
76
109
|
}
|
|
77
110
|
/**
|
|
78
|
-
*
|
|
111
|
+
* Post-processing management interface
|
|
79
112
|
*/
|
|
80
113
|
interface PostProcessingManager {
|
|
81
114
|
composer: EffectComposer;
|
|
@@ -84,23 +117,34 @@ interface PostProcessingManager {
|
|
|
84
117
|
dispose: () => void;
|
|
85
118
|
}
|
|
86
119
|
/**
|
|
87
|
-
*
|
|
120
|
+
* Initialize outline-related information (contains OutlinePass)
|
|
88
121
|
*
|
|
89
|
-
*
|
|
90
|
-
* -
|
|
91
|
-
* -
|
|
92
|
-
* -
|
|
122
|
+
* Capabilities:
|
|
123
|
+
* - Supports automatic update on window resize
|
|
124
|
+
* - Configurable resolution scale for performance improvement
|
|
125
|
+
* - Comprehensive resource disposal management
|
|
93
126
|
*
|
|
94
127
|
* @param renderer THREE.WebGLRenderer
|
|
95
128
|
* @param scene THREE.Scene
|
|
96
129
|
* @param camera THREE.Camera
|
|
97
|
-
* @param options PostProcessingOptions -
|
|
98
|
-
* @returns PostProcessingManager -
|
|
130
|
+
* @param options PostProcessingOptions - Optional configuration
|
|
131
|
+
* @returns PostProcessingManager - Management interface containing composer/outlinePass/resize/dispose
|
|
99
132
|
*/
|
|
100
133
|
declare function initPostProcessing(renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera, options?: PostProcessingOptions): PostProcessingManager;
|
|
101
134
|
|
|
102
135
|
/**
|
|
103
|
-
*
|
|
136
|
+
* @file clickHandler.ts
|
|
137
|
+
* @description
|
|
138
|
+
* Tool for handling model clicks and highlighting (OutlinePass version).
|
|
139
|
+
*
|
|
140
|
+
* @best-practice
|
|
141
|
+
* - Use `createModelClickHandler` to setup interaction.
|
|
142
|
+
* - Handles debouncing and click threshold automatically.
|
|
143
|
+
* - Cleanup using the returned dispose function.
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Click Handler Options
|
|
104
148
|
*/
|
|
105
149
|
interface ClickHandlerOptions {
|
|
106
150
|
clickThreshold?: number;
|
|
@@ -115,21 +159,21 @@ interface ClickHandlerOptions {
|
|
|
115
159
|
maxThickness?: number;
|
|
116
160
|
}
|
|
117
161
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* -
|
|
122
|
-
* -
|
|
123
|
-
* -
|
|
124
|
-
* -
|
|
125
|
-
*
|
|
126
|
-
* @param camera
|
|
127
|
-
* @param scene
|
|
128
|
-
* @param renderer
|
|
129
|
-
* @param outlinePass
|
|
130
|
-
* @param onClick
|
|
131
|
-
* @param options
|
|
132
|
-
* @returns
|
|
162
|
+
* Create Model Click Highlight Tool (OutlinePass Version) - Optimized
|
|
163
|
+
*
|
|
164
|
+
* Features:
|
|
165
|
+
* - Uses AbortController to unify event lifecycle management
|
|
166
|
+
* - Supports debounce to avoid frequent triggering
|
|
167
|
+
* - Customizable Raycaster parameters
|
|
168
|
+
* - Dynamically adjusts outline thickness based on camera distance
|
|
169
|
+
*
|
|
170
|
+
* @param camera Camera
|
|
171
|
+
* @param scene Scene
|
|
172
|
+
* @param renderer Renderer
|
|
173
|
+
* @param outlinePass Initialized OutlinePass
|
|
174
|
+
* @param onClick Click callback
|
|
175
|
+
* @param options Optional configuration
|
|
176
|
+
* @returns Dispose function, used to clean up events and resources
|
|
133
177
|
*/
|
|
134
178
|
declare function createModelClickHandler(camera: THREE.Camera, scene: THREE.Scene, renderer: THREE.WebGLRenderer, outlinePass: OutlinePass, onClick: (object: THREE.Object3D | null, info?: {
|
|
135
179
|
name?: string;
|
|
@@ -137,17 +181,28 @@ declare function createModelClickHandler(camera: THREE.Camera, scene: THREE.Scen
|
|
|
137
181
|
uuid?: string;
|
|
138
182
|
}) => void, options?: ClickHandlerOptions): () => void;
|
|
139
183
|
|
|
184
|
+
/**
|
|
185
|
+
* @file arrowGuide.ts
|
|
186
|
+
* @description
|
|
187
|
+
* Arrow guide effect tool, supports highlighting models and fading other objects.
|
|
188
|
+
*
|
|
189
|
+
* @best-practice
|
|
190
|
+
* - Use `highlight` to focus on specific models.
|
|
191
|
+
* - Automatically manages materials and memory using WeakMap.
|
|
192
|
+
* - Call `dispose` when component unmounts.
|
|
193
|
+
*/
|
|
194
|
+
|
|
140
195
|
type FilterFn = (obj: THREE.Object3D) => boolean;
|
|
141
196
|
/**
|
|
142
|
-
* ArrowGuide -
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* -
|
|
147
|
-
* -
|
|
148
|
-
* -
|
|
149
|
-
* -
|
|
150
|
-
* -
|
|
197
|
+
* ArrowGuide - Optimized Version
|
|
198
|
+
* Arrow guide effect tool, supports highlighting models and fading other objects.
|
|
199
|
+
*
|
|
200
|
+
* Features:
|
|
201
|
+
* - Uses WeakMap for automatic material recycling, preventing memory leaks
|
|
202
|
+
* - Uses AbortController to manage event lifecycle
|
|
203
|
+
* - Adds material reuse mechanism to reuse materials
|
|
204
|
+
* - Improved dispose logic ensuring complete resource release
|
|
205
|
+
* - Adds error handling and boundary checks
|
|
151
206
|
*/
|
|
152
207
|
declare class ArrowGuide {
|
|
153
208
|
private renderer;
|
|
@@ -176,44 +231,55 @@ declare class ArrowGuide {
|
|
|
176
231
|
private makeFadedClone;
|
|
177
232
|
private createFadedMaterialFrom;
|
|
178
233
|
/**
|
|
179
|
-
*
|
|
234
|
+
* Set Arrow Mesh
|
|
180
235
|
*/
|
|
181
236
|
setArrowMesh(mesh: THREE.Mesh): void;
|
|
182
237
|
/**
|
|
183
|
-
*
|
|
238
|
+
* Highlight specified models
|
|
184
239
|
*/
|
|
185
240
|
highlight(models: THREE.Object3D[]): void;
|
|
186
241
|
private applyHighlight;
|
|
187
242
|
restore(): void;
|
|
188
243
|
/**
|
|
189
|
-
*
|
|
244
|
+
* Animation update (called every frame)
|
|
190
245
|
*/
|
|
191
246
|
animate(): void;
|
|
192
247
|
/**
|
|
193
|
-
*
|
|
248
|
+
* Initialize event listeners
|
|
194
249
|
*/
|
|
195
250
|
private initEvents;
|
|
196
251
|
/**
|
|
197
|
-
*
|
|
252
|
+
* Dispose all resources
|
|
198
253
|
*/
|
|
199
254
|
dispose(): void;
|
|
200
255
|
}
|
|
201
256
|
|
|
257
|
+
/**
|
|
258
|
+
* @file liquidFiller.ts
|
|
259
|
+
* @description
|
|
260
|
+
* Liquid filling effect for single or multiple models using local clipping planes.
|
|
261
|
+
*
|
|
262
|
+
* @best-practice
|
|
263
|
+
* - Use `fillTo` to animate liquid level.
|
|
264
|
+
* - Supports multiple independent liquid levels.
|
|
265
|
+
* - Call `dispose` to clean up resources and event listeners.
|
|
266
|
+
*/
|
|
267
|
+
|
|
202
268
|
interface LiquidFillerOptions {
|
|
203
269
|
color?: number;
|
|
204
270
|
opacity?: number;
|
|
205
271
|
speed?: number;
|
|
206
272
|
}
|
|
207
273
|
/**
|
|
208
|
-
* LiquidFillerGroup -
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* -
|
|
213
|
-
* -
|
|
214
|
-
* -
|
|
215
|
-
* -
|
|
216
|
-
* -
|
|
274
|
+
* LiquidFillerGroup - Optimized
|
|
275
|
+
* Supports single or multi-model liquid level animation with independent color control.
|
|
276
|
+
*
|
|
277
|
+
* Features:
|
|
278
|
+
* - Uses renderer.domElement instead of window events
|
|
279
|
+
* - Uses AbortController to manage event lifecycle
|
|
280
|
+
* - Adds error handling and boundary checks
|
|
281
|
+
* - Optimized animation management to prevent memory leaks
|
|
282
|
+
* - Comprehensive resource disposal logic
|
|
217
283
|
*/
|
|
218
284
|
declare class LiquidFillerGroup {
|
|
219
285
|
private items;
|
|
@@ -225,35 +291,47 @@ declare class LiquidFillerGroup {
|
|
|
225
291
|
private clickThreshold;
|
|
226
292
|
private abortController;
|
|
227
293
|
/**
|
|
228
|
-
*
|
|
229
|
-
* @param models
|
|
230
|
-
* @param scene
|
|
231
|
-
* @param camera
|
|
232
|
-
* @param renderer
|
|
233
|
-
* @param defaultOptions
|
|
234
|
-
* @param clickThreshold
|
|
294
|
+
* Constructor
|
|
295
|
+
* @param models Single or multiple THREE.Object3D
|
|
296
|
+
* @param scene Scene
|
|
297
|
+
* @param camera Camera
|
|
298
|
+
* @param renderer Renderer
|
|
299
|
+
* @param defaultOptions Default liquid options
|
|
300
|
+
* @param clickThreshold Click threshold in pixels
|
|
235
301
|
*/
|
|
236
302
|
constructor(models: THREE.Object3D | THREE.Object3D[], scene: THREE.Scene, camera: THREE.Camera, renderer: THREE.WebGLRenderer, defaultOptions?: LiquidFillerOptions, clickThreshold?: number);
|
|
237
|
-
/** pointerdown
|
|
303
|
+
/** pointerdown record position */
|
|
238
304
|
private handlePointerDown;
|
|
239
|
-
/** pointerup
|
|
305
|
+
/** pointerup check click blank, restore original material */
|
|
240
306
|
private handlePointerUp;
|
|
241
307
|
/**
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
308
|
+
* Set liquid level
|
|
309
|
+
* @param models Single model or array of models
|
|
310
|
+
* @param percent Liquid level percentage 0~1
|
|
311
|
+
*/
|
|
246
312
|
fillTo(models: THREE.Object3D | THREE.Object3D[], percent: number): void;
|
|
247
|
-
/**
|
|
313
|
+
/** Set multiple model levels, percentList corresponds to items order */
|
|
248
314
|
fillToAll(percentList: number[]): void;
|
|
249
|
-
/**
|
|
315
|
+
/** Restore single model original material and remove liquid */
|
|
250
316
|
restore(model: THREE.Object3D): void;
|
|
251
|
-
/**
|
|
317
|
+
/** Restore all models */
|
|
252
318
|
restoreAll(): void;
|
|
253
|
-
/**
|
|
319
|
+
/** Dispose method, release events and resources */
|
|
254
320
|
dispose(): void;
|
|
255
321
|
}
|
|
256
322
|
|
|
323
|
+
/**
|
|
324
|
+
* @file followModels.ts
|
|
325
|
+
* @description
|
|
326
|
+
* Camera utility to automatically follow and focus on 3D models.
|
|
327
|
+
* It smoothly moves the camera to an optimal viewing position relative to the target object(s).
|
|
328
|
+
*
|
|
329
|
+
* @best-practice
|
|
330
|
+
* - Use `followModels` to focus on a newly selected object.
|
|
331
|
+
* - Call `cancelFollow` before starting a new manual camera interaction if needed.
|
|
332
|
+
* - Adjust `padding` to control how tight the camera framing is.
|
|
333
|
+
*/
|
|
334
|
+
|
|
257
335
|
interface FollowOptions {
|
|
258
336
|
duration?: number;
|
|
259
337
|
padding?: number;
|
|
@@ -269,72 +347,83 @@ interface FollowOptions {
|
|
|
269
347
|
onProgress?: (progress: number) => void;
|
|
270
348
|
}
|
|
271
349
|
/**
|
|
272
|
-
*
|
|
350
|
+
* Recommended camera angles for quick selection of common views
|
|
273
351
|
*/
|
|
274
352
|
declare const FOLLOW_ANGLES: {
|
|
275
|
-
/**
|
|
353
|
+
/** Isometric view (default) - suitable for architecture, mechanical equipment */
|
|
276
354
|
readonly ISOMETRIC: {
|
|
277
355
|
readonly azimuth: number;
|
|
278
356
|
readonly elevation: number;
|
|
279
357
|
};
|
|
280
|
-
/**
|
|
358
|
+
/** Front view - suitable for frontal display, UI alignment */
|
|
281
359
|
readonly FRONT: {
|
|
282
360
|
readonly azimuth: 0;
|
|
283
361
|
readonly elevation: 0;
|
|
284
362
|
};
|
|
285
|
-
/**
|
|
363
|
+
/** Right view - suitable for mechanical sections, side inspection */
|
|
286
364
|
readonly RIGHT: {
|
|
287
365
|
readonly azimuth: number;
|
|
288
366
|
readonly elevation: 0;
|
|
289
367
|
};
|
|
290
|
-
/**
|
|
368
|
+
/** Left view */
|
|
291
369
|
readonly LEFT: {
|
|
292
370
|
readonly azimuth: number;
|
|
293
371
|
readonly elevation: 0;
|
|
294
372
|
};
|
|
295
|
-
/**
|
|
373
|
+
/** Back view */
|
|
296
374
|
readonly BACK: {
|
|
297
375
|
readonly azimuth: number;
|
|
298
376
|
readonly elevation: 0;
|
|
299
377
|
};
|
|
300
|
-
/**
|
|
378
|
+
/** Top view - suitable for maps, layout display */
|
|
301
379
|
readonly TOP: {
|
|
302
380
|
readonly azimuth: 0;
|
|
303
381
|
readonly elevation: number;
|
|
304
382
|
};
|
|
305
|
-
/**
|
|
383
|
+
/** Low angle view - suitable for vehicles, characters near the ground */
|
|
306
384
|
readonly LOW_ANGLE: {
|
|
307
385
|
readonly azimuth: number;
|
|
308
386
|
readonly elevation: number;
|
|
309
387
|
};
|
|
310
|
-
/**
|
|
388
|
+
/** High angle view - suitable for bird's eye view, panoramic browsing */
|
|
311
389
|
readonly HIGH_ANGLE: {
|
|
312
390
|
readonly azimuth: number;
|
|
313
391
|
readonly elevation: number;
|
|
314
392
|
};
|
|
315
393
|
};
|
|
316
394
|
/**
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* -
|
|
322
|
-
* -
|
|
323
|
-
* -
|
|
324
|
-
* -
|
|
395
|
+
* Automatically moves the camera to a diagonal position relative to the target,
|
|
396
|
+
* ensuring the target is within the field of view (smooth transition).
|
|
397
|
+
*
|
|
398
|
+
* Features:
|
|
399
|
+
* - Supports multiple easing functions
|
|
400
|
+
* - Adds progress callback
|
|
401
|
+
* - Supports animation cancellation
|
|
402
|
+
* - Uses WeakMap to track and prevent memory leaks
|
|
403
|
+
* - Robust error handling
|
|
325
404
|
*/
|
|
326
405
|
declare function followModels(camera: THREE.Camera, targets: THREE.Object3D | THREE.Object3D[] | null | undefined, options?: FollowOptions): Promise<void>;
|
|
327
406
|
/**
|
|
328
|
-
*
|
|
407
|
+
* Cancel the camera follow animation
|
|
329
408
|
*/
|
|
330
409
|
declare function cancelFollow(camera: THREE.Camera): void;
|
|
331
410
|
|
|
332
411
|
/**
|
|
333
|
-
*
|
|
412
|
+
* @file setView.ts
|
|
413
|
+
* @description
|
|
414
|
+
* Utility to smoothly transition the camera to preset views (Front, Back, Top, Isometric, etc.).
|
|
415
|
+
*
|
|
416
|
+
* @best-practice
|
|
417
|
+
* - Use `setView` for UI buttons that switch camera angles.
|
|
418
|
+
* - Leverage `ViewPresets` for readable code when using standard views.
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* View types
|
|
334
423
|
*/
|
|
335
424
|
type ViewPosition = 'front' | 'back' | 'left' | 'right' | 'top' | 'bottom' | 'iso';
|
|
336
425
|
/**
|
|
337
|
-
*
|
|
426
|
+
* View configuration options
|
|
338
427
|
*/
|
|
339
428
|
interface SetViewOptions {
|
|
340
429
|
distanceFactor?: number;
|
|
@@ -343,46 +432,57 @@ interface SetViewOptions {
|
|
|
343
432
|
onProgress?: (progress: number) => void;
|
|
344
433
|
}
|
|
345
434
|
/**
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* -
|
|
350
|
-
* -
|
|
351
|
-
* -
|
|
352
|
-
* -
|
|
353
|
-
* -
|
|
354
|
-
*
|
|
355
|
-
* @param camera THREE.PerspectiveCamera
|
|
356
|
-
* @param controls OrbitControls
|
|
357
|
-
* @param targetObj THREE.Object3D
|
|
358
|
-
* @param position
|
|
359
|
-
* @param options
|
|
435
|
+
* Smoothly switches the camera to the optimal angle for the model.
|
|
436
|
+
*
|
|
437
|
+
* Features:
|
|
438
|
+
* - Reuses followModels logic to avoid code duplication
|
|
439
|
+
* - Supports more angles
|
|
440
|
+
* - Enhanced configuration options
|
|
441
|
+
* - Returns Promise to support chaining
|
|
442
|
+
* - Supports animation cancellation
|
|
443
|
+
*
|
|
444
|
+
* @param camera THREE.PerspectiveCamera instance
|
|
445
|
+
* @param controls OrbitControls instance
|
|
446
|
+
* @param targetObj THREE.Object3D model object
|
|
447
|
+
* @param position View position
|
|
448
|
+
* @param options Configuration options
|
|
360
449
|
* @returns Promise<void>
|
|
361
450
|
*/
|
|
362
451
|
declare function setView(camera: THREE.PerspectiveCamera, controls: OrbitControls, targetObj: THREE.Object3D, position?: ViewPosition, options?: SetViewOptions): Promise<void>;
|
|
363
452
|
/**
|
|
364
|
-
*
|
|
453
|
+
* Cancel view switch animation
|
|
365
454
|
*/
|
|
366
455
|
declare function cancelSetView(camera: THREE.PerspectiveCamera): void;
|
|
367
456
|
/**
|
|
368
|
-
*
|
|
457
|
+
* Preset view shortcut methods
|
|
369
458
|
*/
|
|
370
459
|
declare const ViewPresets: {
|
|
371
460
|
/**
|
|
372
|
-
*
|
|
461
|
+
* Front View
|
|
373
462
|
*/
|
|
374
463
|
front: (camera: THREE.PerspectiveCamera, controls: OrbitControls, target: THREE.Object3D, options?: SetViewOptions) => Promise<void>;
|
|
375
464
|
/**
|
|
376
|
-
*
|
|
465
|
+
* Isometric View
|
|
377
466
|
*/
|
|
378
467
|
isometric: (camera: THREE.PerspectiveCamera, controls: OrbitControls, target: THREE.Object3D, options?: SetViewOptions) => Promise<void>;
|
|
379
468
|
/**
|
|
380
|
-
*
|
|
469
|
+
* Top View
|
|
381
470
|
*/
|
|
382
471
|
top: (camera: THREE.PerspectiveCamera, controls: OrbitControls, target: THREE.Object3D, options?: SetViewOptions) => Promise<void>;
|
|
383
472
|
};
|
|
384
473
|
|
|
385
|
-
/**
|
|
474
|
+
/**
|
|
475
|
+
* @file modelLoader.ts
|
|
476
|
+
* @description
|
|
477
|
+
* Utility to load 3D models (GLTF, FBX, OBJ, PLY, STL) from URLs.
|
|
478
|
+
*
|
|
479
|
+
* @best-practice
|
|
480
|
+
* - Use `loadModelByUrl` for a unified loading interface.
|
|
481
|
+
* - Supports Draco compression and KTX2 textures for GLTF.
|
|
482
|
+
* - Includes optimization options like geometry merging and texture downscaling.
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
/** Loading Options: Now has default values */
|
|
386
486
|
interface LoadOptions {
|
|
387
487
|
manager?: THREE.LoadingManager;
|
|
388
488
|
dracoDecoderPath?: string | null;
|
|
@@ -394,21 +494,32 @@ interface LoadOptions {
|
|
|
394
494
|
skipSkinned?: boolean;
|
|
395
495
|
}
|
|
396
496
|
declare function loadModelByUrl(url: string, options?: LoadOptions): Promise<THREE.Object3D>;
|
|
397
|
-
/**
|
|
497
|
+
/** Completely dispose object: geometry, material and its textures (Danger: shared resources will be disposed) */
|
|
398
498
|
declare function disposeObject(obj: THREE.Object3D | null): void;
|
|
399
|
-
/**
|
|
499
|
+
/** Dispose material and its textures */
|
|
400
500
|
declare function disposeMaterial(mat: any): void;
|
|
401
501
|
|
|
402
502
|
/**
|
|
403
|
-
*
|
|
503
|
+
* @file skyboxLoader.ts
|
|
504
|
+
* @description
|
|
505
|
+
* Utility for loading skyboxes (CubeTexture or Equirectangular/HDR).
|
|
506
|
+
*
|
|
507
|
+
* @best-practice
|
|
508
|
+
* - Use `loadSkybox` for a unified interface.
|
|
509
|
+
* - Supports internal caching to avoid reloading the same skybox.
|
|
510
|
+
* - Can set background and environment map independently.
|
|
511
|
+
*/
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Skybox Loader Utility
|
|
404
515
|
*
|
|
405
|
-
*
|
|
406
|
-
* -
|
|
407
|
-
* -
|
|
516
|
+
* Supports:
|
|
517
|
+
* - Cube Texture: paths: [px, nx, py, ny, pz, nz]
|
|
518
|
+
* - Equirectangular / HDR Panorama: url: 'path/to/scene.hdr' or jpg
|
|
408
519
|
*
|
|
409
|
-
*
|
|
520
|
+
* Returns a SkyboxHandle containing modification records for the scene and a dispose() method.
|
|
410
521
|
*/
|
|
411
|
-
/**
|
|
522
|
+
/** Unified Return Handle */
|
|
412
523
|
type SkyboxHandle = {
|
|
413
524
|
key: string;
|
|
414
525
|
backgroundTexture: THREE.Texture | null;
|
|
@@ -416,10 +527,10 @@ type SkyboxHandle = {
|
|
|
416
527
|
pmremGenerator: THREE.PMREMGenerator | null;
|
|
417
528
|
setAsBackground: boolean;
|
|
418
529
|
setAsEnvironment: boolean;
|
|
419
|
-
/**
|
|
530
|
+
/** Unload and release resources (if cached/shared, refCount logic is needed) */
|
|
420
531
|
dispose: () => void;
|
|
421
532
|
};
|
|
422
|
-
/**
|
|
533
|
+
/** Loading Options & Defaults */
|
|
423
534
|
interface SkyboxOptions {
|
|
424
535
|
setAsBackground?: boolean;
|
|
425
536
|
setAsEnvironment?: boolean;
|
|
@@ -428,15 +539,15 @@ interface SkyboxOptions {
|
|
|
428
539
|
cache?: boolean;
|
|
429
540
|
}
|
|
430
541
|
/**
|
|
431
|
-
*
|
|
432
|
-
* @param renderer THREE.WebGLRenderer -
|
|
542
|
+
* Load Cube Texture (6 images)
|
|
543
|
+
* @param renderer THREE.WebGLRenderer - Used for PMREM generating environment map
|
|
433
544
|
* @param scene THREE.Scene
|
|
434
|
-
* @param paths string[] 6
|
|
545
|
+
* @param paths string[] 6 image paths, order: [px, nx, py, ny, pz, nz]
|
|
435
546
|
* @param opts SkyboxOptions
|
|
436
547
|
*/
|
|
437
548
|
declare function loadCubeSkybox(renderer: THREE.WebGLRenderer, scene: THREE.Scene, paths: string[], opts?: SkyboxOptions): Promise<SkyboxHandle>;
|
|
438
549
|
/**
|
|
439
|
-
*
|
|
550
|
+
* Load Equirectangular/Single Image (Supports HDR via RGBELoader)
|
|
440
551
|
* @param renderer THREE.WebGLRenderer
|
|
441
552
|
* @param scene THREE.Scene
|
|
442
553
|
* @param url string - *.hdr, *.exr, *.jpg, *.png
|
|
@@ -451,15 +562,26 @@ type LoadSkyboxParams = {
|
|
|
451
562
|
url: string;
|
|
452
563
|
};
|
|
453
564
|
declare function loadSkybox(renderer: THREE.WebGLRenderer, scene: THREE.Scene, params: LoadSkyboxParams, opts?: SkyboxOptions): Promise<SkyboxHandle>;
|
|
454
|
-
/**
|
|
565
|
+
/** Release a cached skybox (decrements refCount, only truly disposes when refCount=0) */
|
|
455
566
|
declare function releaseSkybox(handle: SkyboxHandle): void;
|
|
456
567
|
|
|
457
568
|
/**
|
|
458
|
-
*
|
|
569
|
+
* @file blueSkyManager.ts
|
|
570
|
+
* @description
|
|
571
|
+
* Global singleton manager for loading and managing HDR/EXR blue sky environment maps.
|
|
572
|
+
*
|
|
573
|
+
* @best-practice
|
|
574
|
+
* - Call `init` once before use.
|
|
575
|
+
* - Use `loadAsync` to load skyboxes with progress tracking.
|
|
576
|
+
* - Automatically handles PMREM generation for realistic lighting.
|
|
577
|
+
*/
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Load progress callback type
|
|
459
581
|
*/
|
|
460
582
|
type LoadProgressCallback = (progress: number) => void;
|
|
461
583
|
/**
|
|
462
|
-
*
|
|
584
|
+
* Load options
|
|
463
585
|
*/
|
|
464
586
|
interface LoadSkyOptions {
|
|
465
587
|
background?: boolean;
|
|
@@ -468,91 +590,102 @@ interface LoadSkyOptions {
|
|
|
468
590
|
onError?: (error: any) => void;
|
|
469
591
|
}
|
|
470
592
|
/**
|
|
471
|
-
* BlueSkyManager -
|
|
593
|
+
* BlueSkyManager - Optimized
|
|
472
594
|
* ---------------------------------------------------------
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
* -
|
|
477
|
-
* -
|
|
478
|
-
* -
|
|
479
|
-
* -
|
|
480
|
-
* -
|
|
595
|
+
* A global singleton manager for loading and managing HDR/EXR based blue sky environment maps.
|
|
596
|
+
*
|
|
597
|
+
* Features:
|
|
598
|
+
* - Adds load progress callback
|
|
599
|
+
* - Supports load cancellation
|
|
600
|
+
* - Improved error handling
|
|
601
|
+
* - Returns Promise for async operation
|
|
602
|
+
* - Adds loading state management
|
|
481
603
|
*/
|
|
482
604
|
declare class BlueSkyManager {
|
|
483
|
-
/** three.js
|
|
605
|
+
/** three.js renderer instance */
|
|
484
606
|
private renderer;
|
|
485
|
-
/** three.js
|
|
607
|
+
/** three.js scene instance */
|
|
486
608
|
private scene;
|
|
487
|
-
/** PMREM
|
|
609
|
+
/** PMREM generator, used to convert HDR/EXR to efficient reflection maps */
|
|
488
610
|
private pmremGen;
|
|
489
|
-
/**
|
|
611
|
+
/** RenderTarget for current environment map, used for subsequent disposal */
|
|
490
612
|
private skyRT;
|
|
491
|
-
/**
|
|
613
|
+
/** Whether already initialized */
|
|
492
614
|
private isInitialized;
|
|
493
|
-
/**
|
|
615
|
+
/** Current loader, used for cancelling load */
|
|
494
616
|
private currentLoader;
|
|
495
|
-
/**
|
|
617
|
+
/** Loading state */
|
|
496
618
|
private loadingState;
|
|
497
619
|
/**
|
|
498
|
-
*
|
|
620
|
+
* Initialize
|
|
499
621
|
* ---------------------------------------------------------
|
|
500
|
-
*
|
|
501
|
-
* @param renderer WebGLRenderer
|
|
502
|
-
* @param scene Three.js
|
|
503
|
-
* @param exposure
|
|
622
|
+
* Must be called once before using BlueSkyManager.
|
|
623
|
+
* @param renderer WebGLRenderer instance
|
|
624
|
+
* @param scene Three.js Scene
|
|
625
|
+
* @param exposure Exposure (default 1.0)
|
|
504
626
|
*/
|
|
505
627
|
init(renderer: THREE.WebGLRenderer, scene: THREE.Scene, exposure?: number): void;
|
|
506
628
|
/**
|
|
507
|
-
*
|
|
629
|
+
* Load blue sky HDR/EXR map and apply to scene (Promise version)
|
|
508
630
|
* ---------------------------------------------------------
|
|
509
|
-
* @param exrPath HDR/EXR
|
|
510
|
-
* @param options
|
|
631
|
+
* @param exrPath HDR/EXR file path
|
|
632
|
+
* @param options Load options
|
|
511
633
|
* @returns Promise<void>
|
|
512
634
|
*/
|
|
513
635
|
loadAsync(exrPath: string, options?: LoadSkyOptions): Promise<void>;
|
|
514
636
|
/**
|
|
515
|
-
*
|
|
637
|
+
* Load blue sky HDR/EXR map and apply to scene (Sync API, for backward compatibility)
|
|
516
638
|
* ---------------------------------------------------------
|
|
517
|
-
* @param exrPath HDR/EXR
|
|
518
|
-
* @param background
|
|
639
|
+
* @param exrPath HDR/EXR file path
|
|
640
|
+
* @param background Whether to apply as scene background (default true)
|
|
519
641
|
*/
|
|
520
642
|
load(exrPath: string, background?: boolean): void;
|
|
521
643
|
/**
|
|
522
|
-
*
|
|
644
|
+
* Cancel current load
|
|
523
645
|
*/
|
|
524
646
|
cancelLoad(): void;
|
|
525
647
|
/**
|
|
526
|
-
*
|
|
648
|
+
* Get loading state
|
|
527
649
|
*/
|
|
528
650
|
getLoadingState(): 'idle' | 'loading' | 'loaded' | 'error';
|
|
529
651
|
/**
|
|
530
|
-
*
|
|
652
|
+
* Is loading
|
|
531
653
|
*/
|
|
532
654
|
isLoading(): boolean;
|
|
533
655
|
/**
|
|
534
|
-
*
|
|
656
|
+
* Release current sky texture resources
|
|
535
657
|
* ---------------------------------------------------------
|
|
536
|
-
*
|
|
537
|
-
*
|
|
658
|
+
* Only cleans up skyRT, does not destroy PMREM
|
|
659
|
+
* Suitable for calling when switching HDR/EXR files
|
|
538
660
|
*/
|
|
539
661
|
dispose(): void;
|
|
540
662
|
/**
|
|
541
|
-
*
|
|
663
|
+
* Completely destroy BlueSkyManager
|
|
542
664
|
* ---------------------------------------------------------
|
|
543
|
-
*
|
|
544
|
-
*
|
|
665
|
+
* Includes destruction of PMREMGenerator
|
|
666
|
+
* Usually called when the scene is completely destroyed or the application exits
|
|
545
667
|
*/
|
|
546
668
|
destroy(): void;
|
|
547
669
|
}
|
|
548
670
|
/**
|
|
549
|
-
*
|
|
671
|
+
* Global Singleton
|
|
550
672
|
* ---------------------------------------------------------
|
|
551
|
-
*
|
|
552
|
-
*
|
|
673
|
+
* Directly export a globally unique BlueSkyManager instance,
|
|
674
|
+
* Ensuring only one PMREMGenerator is used throughout the application for best performance.
|
|
553
675
|
*/
|
|
554
676
|
declare const BlueSky: BlueSkyManager;
|
|
555
677
|
|
|
678
|
+
/**
|
|
679
|
+
* @file modelsLabel.ts
|
|
680
|
+
* @description
|
|
681
|
+
* Creates interactive 2D labels (DOM elements) attached to 3D objects with connecting lines.
|
|
682
|
+
*
|
|
683
|
+
* @best-practice
|
|
684
|
+
* - Use `createModelsLabel` to annotate parts of a model.
|
|
685
|
+
* - Supports fading endpoints, pulsing dots, and custom styling.
|
|
686
|
+
* - Performance optimized with caching and RAF throttling.
|
|
687
|
+
*/
|
|
688
|
+
|
|
556
689
|
interface LabelOptions {
|
|
557
690
|
fontSize?: string;
|
|
558
691
|
color?: string;
|
|
@@ -575,153 +708,48 @@ interface LabelManager {
|
|
|
575
708
|
dispose: () => void;
|
|
576
709
|
}
|
|
577
710
|
/**
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* -
|
|
582
|
-
* -
|
|
583
|
-
* -
|
|
584
|
-
* -
|
|
585
|
-
* - RAF
|
|
711
|
+
* Create Model Labels (with connecting lines and pulsing dots) - Optimized
|
|
712
|
+
*
|
|
713
|
+
* Features:
|
|
714
|
+
* - Supports pause/resume
|
|
715
|
+
* - Configurable update interval
|
|
716
|
+
* - Fade in/out effects
|
|
717
|
+
* - Cached bounding box calculation
|
|
718
|
+
* - RAF management optimization
|
|
586
719
|
*/
|
|
587
720
|
declare function createModelsLabel(camera: THREE.Camera, renderer: THREE.WebGLRenderer, parentModel: THREE.Object3D, modelLabelsMap: Record<string, string>, options?: LabelOptions): LabelManager;
|
|
588
721
|
|
|
589
722
|
/**
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
* - 仅初始化一次(onMounted)
|
|
594
|
-
* - 支持动态切换模型并自动还原上一个模型的爆炸状态
|
|
595
|
-
* - 支持多种排列模式(ring / spiral / grid / radial)
|
|
596
|
-
* - 支持非爆炸对象自动透明化(dimOthers)
|
|
597
|
-
* - 支持摄像机自动前置定位到最佳观察点
|
|
598
|
-
* - 所有动画均采用原生 requestAnimationFrame 实现
|
|
599
|
-
*
|
|
600
|
-
* ----------------------------------------------------------------------
|
|
601
|
-
* 🔧 构造参数
|
|
602
|
-
* ----------------------------------------------------------------------
|
|
603
|
-
* @param scene Three.js 场景实例
|
|
604
|
-
* @param camera Three.js 相机(一般为 PerspectiveCamera)
|
|
605
|
-
* @param controls OrbitControls 控件实例(必须绑定 camera)
|
|
606
|
-
*
|
|
723
|
+
* @file exploder.ts
|
|
724
|
+
* @description
|
|
725
|
+
* GroupExploder - Three.js based model explosion effect tool (Vue3 + TS Support)
|
|
607
726
|
* ----------------------------------------------------------------------
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
* @param spacing?: number
|
|
622
|
-
* 相邻爆炸对象之间的间距(默认:2.5)
|
|
623
|
-
*
|
|
624
|
-
* @param duration?: number
|
|
625
|
-
* 爆炸动画时长(ms),原生 rAF 完成(默认:1000)
|
|
626
|
-
*
|
|
627
|
-
* @param lift?: number
|
|
628
|
-
* 爆炸对象整体抬升的高度因子,用于让爆炸看起来更立体(默认:0.6)
|
|
629
|
-
*
|
|
630
|
-
* @param cameraPadding?: number
|
|
631
|
-
* 摄像机贴合爆炸后包围球时的额外安全距离(默认:1.2)
|
|
632
|
-
*
|
|
633
|
-
* @param autoRestorePrev?: boolean
|
|
634
|
-
* 当切换模型时,是否自动 restore 上一个模型的爆炸元素(默认:true)
|
|
635
|
-
*
|
|
636
|
-
* @param dimOthers?: { enabled: boolean; opacity?: number }
|
|
637
|
-
* 非爆炸对象透明化配置:
|
|
638
|
-
* - enabled: true 开启
|
|
639
|
-
* - opacity: number 指定非爆炸对象透明度(默认:0.15)
|
|
640
|
-
*
|
|
641
|
-
* @param debug?: boolean
|
|
642
|
-
* 是否开启调试日志,输出所有内部状态(默认 false)
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
* ----------------------------------------------------------------------
|
|
646
|
-
* 📌 方法说明
|
|
647
|
-
* ----------------------------------------------------------------------
|
|
648
|
-
*
|
|
649
|
-
* ◆ setMeshes(meshSet: Set<Mesh>, contextId?: string)
|
|
650
|
-
* 设置当前模型的爆炸 Mesh 集合:
|
|
651
|
-
* - 会记录 Mesh 的初始 transform
|
|
652
|
-
* - 根据 autoRestorePrev 自动还原上次爆炸
|
|
653
|
-
* - 第二个参数 contextId 可选,用于区分业务场景
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
* ◆ explode(options?: ExplodeOptions)
|
|
657
|
-
* 对当前 meshSet 执行爆炸动画:
|
|
658
|
-
* - 根据 mode 生成爆炸布局
|
|
659
|
-
* - 相机先自动飞向最佳观察点
|
|
660
|
-
* - 执行 mesh 位移动画
|
|
661
|
-
* - 按需将非爆炸模型透明化
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
* ◆ restore(duration?: number)
|
|
665
|
-
* 还原所有爆炸 Mesh 到爆炸前的 transform:
|
|
666
|
-
* - 支持平滑动画
|
|
667
|
-
* - 自动取消透明化
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
* ◆ dispose()
|
|
671
|
-
* 移除事件监听、取消动画、清理引用(在组件销毁时调用)
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
* ----------------------------------------------------------------------
|
|
675
|
-
* 🎨 排列模式说明
|
|
676
|
-
* ----------------------------------------------------------------------
|
|
677
|
-
*
|
|
678
|
-
* 1. Ring(环形)
|
|
679
|
-
* - 按圆均匀分布
|
|
680
|
-
* - spacing 控制半径
|
|
681
|
-
* - lift 控制整体抬起高度
|
|
682
|
-
*
|
|
683
|
-
* 2. Spiral(螺旋)
|
|
684
|
-
* - 在环形基础上添加高度递增(y++)
|
|
685
|
-
* - 数量大时视觉效果最强
|
|
686
|
-
*
|
|
687
|
-
* 3. Grid(网格)
|
|
688
|
-
* - 类似棋盘布局
|
|
689
|
-
* - spacing 控制网格大小
|
|
690
|
-
* - z 不变或小幅度变化
|
|
691
|
-
*
|
|
692
|
-
* 4. Radial(径向扩散)
|
|
693
|
-
* - 从中心向外 “爆炸式” 发散
|
|
694
|
-
* - 对于大型组件分解展示非常适合
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
* ----------------------------------------------------------------------
|
|
698
|
-
* 📌 使用示例(业务层 Vue)
|
|
699
|
-
* ----------------------------------------------------------------------
|
|
700
|
-
*
|
|
701
|
-
* const exploder = new GroupExploder(scene, camera, controls);
|
|
702
|
-
*
|
|
703
|
-
* onMounted(() => {
|
|
704
|
-
* exploder.setMeshes(new Set([meshA, meshB, meshC]));
|
|
705
|
-
* });
|
|
706
|
-
*
|
|
707
|
-
* const triggerExplode = () => {
|
|
708
|
-
* exploder.explode({
|
|
709
|
-
* mode: 'ring',
|
|
710
|
-
* spacing: 3,
|
|
711
|
-
* duration: 1200,
|
|
712
|
-
* lift: 0.8,
|
|
713
|
-
* cameraPadding: 1.3,
|
|
714
|
-
* dimOthers: { enabled: true, opacity: 0.2 },
|
|
715
|
-
* });
|
|
716
|
-
* };
|
|
717
|
-
*
|
|
718
|
-
* const triggerRestore = () => {
|
|
719
|
-
* exploder.restore(600);
|
|
720
|
-
* };
|
|
721
|
-
*
|
|
727
|
+
* This tool is used to perform "explode / restore" animations on a set of specified Meshes:
|
|
728
|
+
* - Initialize only once (onMounted)
|
|
729
|
+
* - Supports dynamic switching of models and automatically restores the explosion state of the previous model
|
|
730
|
+
* - Supports multiple arrangement modes (ring / spiral / grid / radial)
|
|
731
|
+
* - Supports automatic transparency for non-exploded objects (dimOthers)
|
|
732
|
+
* - Supports automatic camera positioning to the best observation point
|
|
733
|
+
* - All animations use native requestAnimationFrame
|
|
734
|
+
*
|
|
735
|
+
* @best-practice
|
|
736
|
+
* - Initialize in `onMounted`.
|
|
737
|
+
* - Use `setMeshes` to update the active set of meshes to explode.
|
|
738
|
+
* - Call `explode()` to trigger the effect and `restore()` to reset.
|
|
722
739
|
*/
|
|
723
740
|
|
|
724
741
|
type ArrangeMode = 'ring' | 'spiral' | 'grid' | 'radial';
|
|
742
|
+
/**
|
|
743
|
+
* Explosion Parameters
|
|
744
|
+
* @param mode Explosion arrangement mode: 'ring' | 'spiral' | 'grid' | 'radial'
|
|
745
|
+
* @param spacing Spacing between adjacent exploded objects (default: 2.5)
|
|
746
|
+
* @param duration Animation duration in ms (default: 1000)
|
|
747
|
+
* @param lift Lift factor for exploded objects (default: 0.6)
|
|
748
|
+
* @param cameraPadding Extra safety distance for camera framing (default: 1.2)
|
|
749
|
+
* @param autoRestorePrev Whether to automatically restore the previous model's explosion when switching models (default: true)
|
|
750
|
+
* @param dimOthers Configuration for dimming non-exploded objects
|
|
751
|
+
* @param debug Enable debug logs (default: false)
|
|
752
|
+
*/
|
|
725
753
|
type ExplodeOptions = {
|
|
726
754
|
mode?: ArrangeMode;
|
|
727
755
|
spacing?: number;
|
|
@@ -751,6 +779,12 @@ declare class GroupExploder {
|
|
|
751
779
|
private isExploded;
|
|
752
780
|
private isInitialized;
|
|
753
781
|
onLog?: (s: string) => void;
|
|
782
|
+
/**
|
|
783
|
+
* Constructor
|
|
784
|
+
* @param scene Three.js Scene instance
|
|
785
|
+
* @param camera Three.js Camera (usually PerspectiveCamera)
|
|
786
|
+
* @param controls OrbitControls instance (must be bound to camera)
|
|
787
|
+
*/
|
|
754
788
|
constructor(scene: THREE.Scene, camera: THREE.PerspectiveCamera | THREE.Camera, controls?: {
|
|
755
789
|
target?: THREE.Vector3;
|
|
756
790
|
update?: () => void;
|
|
@@ -758,10 +792,12 @@ declare class GroupExploder {
|
|
|
758
792
|
private log;
|
|
759
793
|
init(): void;
|
|
760
794
|
/**
|
|
761
|
-
*
|
|
795
|
+
* Set the current set of meshes for explosion.
|
|
762
796
|
* - Detects content-level changes even if same Set reference is used.
|
|
763
797
|
* - Preserves prevSet/stateMap to allow async restore when needed.
|
|
764
798
|
* - Ensures stateMap contains snapshots for *all meshes in the new set*.
|
|
799
|
+
* @param newSet The new set of meshes
|
|
800
|
+
* @param contextId Optional context ID to distinguish business scenarios
|
|
765
801
|
*/
|
|
766
802
|
setMeshes(newSet: Set<THREE.Mesh> | null, options?: {
|
|
767
803
|
autoRestorePrev?: boolean;
|
|
@@ -777,6 +813,11 @@ declare class GroupExploder {
|
|
|
777
813
|
* animate camera to that targetBound, then animate meshes to targets.
|
|
778
814
|
*/
|
|
779
815
|
explode(opts?: ExplodeOptions): Promise<void>;
|
|
816
|
+
/**
|
|
817
|
+
* Restore all exploded meshes to their original transform:
|
|
818
|
+
* - Supports smooth animation
|
|
819
|
+
* - Automatically cancels transparency
|
|
820
|
+
*/
|
|
780
821
|
restore(duration?: number): Promise<void>;
|
|
781
822
|
/**
|
|
782
823
|
* restoreSet: reparent and restore transforms using provided stateMap.
|
|
@@ -791,29 +832,44 @@ declare class GroupExploder {
|
|
|
791
832
|
private computeBoundingSphereForPositionsAndMeshes;
|
|
792
833
|
private computeTargetsByMode;
|
|
793
834
|
private animateCameraToFit;
|
|
794
|
-
|
|
835
|
+
/**
|
|
836
|
+
* Cancel all running animations
|
|
837
|
+
*/
|
|
795
838
|
private cancelAnimations;
|
|
796
|
-
|
|
839
|
+
/**
|
|
840
|
+
* Dispose: remove listener, cancel animation, clear references
|
|
841
|
+
*/
|
|
842
|
+
dispose(): void;
|
|
797
843
|
}
|
|
798
844
|
|
|
845
|
+
/**
|
|
846
|
+
* @file autoSetup.ts
|
|
847
|
+
* @description
|
|
848
|
+
* Automatically sets up the camera and basic lighting scene based on the model's bounding box.
|
|
849
|
+
*
|
|
850
|
+
* @best-practice
|
|
851
|
+
* - Call `autoSetupCameraAndLight` after loading a model to get a quick "good looking" scene.
|
|
852
|
+
* - Returns a handle to dispose lights or update intensity later.
|
|
853
|
+
*/
|
|
854
|
+
|
|
799
855
|
interface AutoSetupOptions {
|
|
800
|
-
/**
|
|
856
|
+
/** Extra padding multiplier based on bounding sphere (>1 expands view range) */
|
|
801
857
|
padding?: number;
|
|
802
|
-
/**
|
|
858
|
+
/** Camera elevation offset (radians), default slight top-down (0.2 rad ≈ 11°) */
|
|
803
859
|
elevation?: number;
|
|
804
|
-
/**
|
|
860
|
+
/** Whether to enable shadows - high performance cost, default false */
|
|
805
861
|
enableShadows?: boolean;
|
|
806
|
-
/**
|
|
862
|
+
/** Shadow map size, higher is clearer but more expensive, default 1024 */
|
|
807
863
|
shadowMapSize?: number;
|
|
808
|
-
/** DirectionalLights
|
|
864
|
+
/** Number of DirectionalLights (evenly distributed around) */
|
|
809
865
|
directionalCount?: number;
|
|
810
|
-
/**
|
|
866
|
+
/** Whether to automatically set mesh.castShadow / mesh.receiveShadow to true (default true) */
|
|
811
867
|
setMeshShadowProps?: boolean;
|
|
812
|
-
/**
|
|
868
|
+
/** If renderer is passed, the tool will automatically enable renderer.shadowMap (if enableShadows is true) */
|
|
813
869
|
renderer?: THREE.WebGLRenderer | null;
|
|
814
870
|
}
|
|
815
871
|
/**
|
|
816
|
-
*
|
|
872
|
+
* Return handle, containing created lights group, computed center/radius, and dispose method
|
|
817
873
|
*/
|
|
818
874
|
type AutoSetupHandle = {
|
|
819
875
|
lightsGroup: THREE.Group;
|
|
@@ -823,19 +879,19 @@ type AutoSetupHandle = {
|
|
|
823
879
|
updateLightIntensity: (factor: number) => void;
|
|
824
880
|
};
|
|
825
881
|
/**
|
|
826
|
-
*
|
|
882
|
+
* Automatically setup camera and basic lighting - Optimized
|
|
827
883
|
*
|
|
828
|
-
*
|
|
829
|
-
* -
|
|
830
|
-
* -
|
|
831
|
-
* -
|
|
884
|
+
* Features:
|
|
885
|
+
* - Adds light intensity adjustment method
|
|
886
|
+
* - Improved error handling
|
|
887
|
+
* - Optimized dispose logic
|
|
832
888
|
*
|
|
833
|
-
* - camera: THREE.PerspectiveCamera
|
|
834
|
-
* - scene: THREE.Scene
|
|
835
|
-
* - model: THREE.Object3D
|
|
836
|
-
* - options:
|
|
889
|
+
* - camera: THREE.PerspectiveCamera (will be moved and pointed at model center)
|
|
890
|
+
* - scene: THREE.Scene (newly created light group will be added to the scene)
|
|
891
|
+
* - model: THREE.Object3D loaded model (arbitrary transform/coordinates)
|
|
892
|
+
* - options: Optional configuration (see AutoSetupOptions)
|
|
837
893
|
*
|
|
838
|
-
*
|
|
894
|
+
* Returns AutoSetupHandle, caller should call handle.dispose() when component unmounts/switches
|
|
839
895
|
*/
|
|
840
896
|
declare function autoSetupCameraAndLight(camera: THREE.PerspectiveCamera, scene: THREE.Scene, model: THREE.Object3D, options?: AutoSetupOptions): AutoSetupHandle;
|
|
841
897
|
|