@chocozhang/three-model-render 1.0.2 → 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 +149 -530
- 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 +1 -1
package/dist/camera/index.mjs
CHANGED
|
@@ -1,31 +1,41 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @file followModels.ts
|
|
5
|
+
* @description
|
|
6
|
+
* Camera utility to automatically follow and focus on 3D models.
|
|
7
|
+
* It smoothly moves the camera to an optimal viewing position relative to the target object(s).
|
|
8
|
+
*
|
|
9
|
+
* @best-practice
|
|
10
|
+
* - Use `followModels` to focus on a newly selected object.
|
|
11
|
+
* - Call `cancelFollow` before starting a new manual camera interaction if needed.
|
|
12
|
+
* - Adjust `padding` to control how tight the camera framing is.
|
|
13
|
+
*/
|
|
14
|
+
// Use WeakMap to track animations, allowing for cancellation
|
|
5
15
|
const _animationMap = new WeakMap();
|
|
6
16
|
/**
|
|
7
|
-
*
|
|
17
|
+
* Recommended camera angles for quick selection of common views
|
|
8
18
|
*/
|
|
9
19
|
const FOLLOW_ANGLES = {
|
|
10
|
-
/**
|
|
20
|
+
/** Isometric view (default) - suitable for architecture, mechanical equipment */
|
|
11
21
|
ISOMETRIC: { azimuth: Math.PI / 4, elevation: Math.PI / 4 },
|
|
12
|
-
/**
|
|
22
|
+
/** Front view - suitable for frontal display, UI alignment */
|
|
13
23
|
FRONT: { azimuth: 0, elevation: 0 },
|
|
14
|
-
/**
|
|
24
|
+
/** Right view - suitable for mechanical sections, side inspection */
|
|
15
25
|
RIGHT: { azimuth: Math.PI / 2, elevation: 0 },
|
|
16
|
-
/**
|
|
26
|
+
/** Left view */
|
|
17
27
|
LEFT: { azimuth: -Math.PI / 2, elevation: 0 },
|
|
18
|
-
/**
|
|
28
|
+
/** Back view */
|
|
19
29
|
BACK: { azimuth: Math.PI, elevation: 0 },
|
|
20
|
-
/**
|
|
30
|
+
/** Top view - suitable for maps, layout display */
|
|
21
31
|
TOP: { azimuth: 0, elevation: Math.PI / 2 },
|
|
22
|
-
/**
|
|
32
|
+
/** Low angle view - suitable for vehicles, characters near the ground */
|
|
23
33
|
LOW_ANGLE: { azimuth: Math.PI / 4, elevation: Math.PI / 6 },
|
|
24
|
-
/**
|
|
34
|
+
/** High angle view - suitable for bird's eye view, panoramic browsing */
|
|
25
35
|
HIGH_ANGLE: { azimuth: Math.PI / 4, elevation: Math.PI / 3 }
|
|
26
36
|
};
|
|
27
37
|
/**
|
|
28
|
-
*
|
|
38
|
+
* Collection of easing functions
|
|
29
39
|
*/
|
|
30
40
|
const EASING_FUNCTIONS = {
|
|
31
41
|
linear: (t) => t,
|
|
@@ -34,20 +44,21 @@ const EASING_FUNCTIONS = {
|
|
|
34
44
|
easeIn: (t) => t * t * t
|
|
35
45
|
};
|
|
36
46
|
/**
|
|
37
|
-
*
|
|
47
|
+
* Automatically moves the camera to a diagonal position relative to the target,
|
|
48
|
+
* ensuring the target is within the field of view (smooth transition).
|
|
38
49
|
*
|
|
39
|
-
*
|
|
40
|
-
* -
|
|
41
|
-
* -
|
|
42
|
-
* -
|
|
43
|
-
* - WeakMap
|
|
44
|
-
* -
|
|
50
|
+
* Features:
|
|
51
|
+
* - Supports multiple easing functions
|
|
52
|
+
* - Adds progress callback
|
|
53
|
+
* - Supports animation cancellation
|
|
54
|
+
* - Uses WeakMap to track and prevent memory leaks
|
|
55
|
+
* - Robust error handling
|
|
45
56
|
*/
|
|
46
57
|
function followModels(camera, targets, options = {}) {
|
|
47
58
|
var _a, _b, _c, _d, _e, _f;
|
|
48
|
-
//
|
|
59
|
+
// Cancel previous animation
|
|
49
60
|
cancelFollow(camera);
|
|
50
|
-
//
|
|
61
|
+
// Boundary check
|
|
51
62
|
const arr = [];
|
|
52
63
|
if (!targets)
|
|
53
64
|
return Promise.resolve();
|
|
@@ -56,15 +67,15 @@ function followModels(camera, targets, options = {}) {
|
|
|
56
67
|
else
|
|
57
68
|
arr.push(targets);
|
|
58
69
|
if (arr.length === 0) {
|
|
59
|
-
console.warn('followModels:
|
|
70
|
+
console.warn('followModels: Target object is empty');
|
|
60
71
|
return Promise.resolve();
|
|
61
72
|
}
|
|
62
73
|
try {
|
|
63
74
|
const box = new THREE.Box3();
|
|
64
75
|
arr.forEach((o) => box.expandByObject(o));
|
|
65
|
-
//
|
|
76
|
+
// Check bounding box validity
|
|
66
77
|
if (!isFinite(box.min.x) || !isFinite(box.max.x)) {
|
|
67
|
-
console.warn('followModels:
|
|
78
|
+
console.warn('followModels: Failed to calculate bounding box');
|
|
68
79
|
return Promise.resolve();
|
|
69
80
|
}
|
|
70
81
|
const sphere = new THREE.Sphere();
|
|
@@ -80,7 +91,7 @@ function followModels(camera, targets, options = {}) {
|
|
|
80
91
|
const elevation = (_e = options.elevation) !== null && _e !== void 0 ? _e : Math.PI / 4;
|
|
81
92
|
const easing = (_f = options.easing) !== null && _f !== void 0 ? _f : 'easeOut';
|
|
82
93
|
const onProgress = options.onProgress;
|
|
83
|
-
//
|
|
94
|
+
// Get easing function
|
|
84
95
|
const easingFn = EASING_FUNCTIONS[easing] || EASING_FUNCTIONS.easeOut;
|
|
85
96
|
let distance = 10;
|
|
86
97
|
if (camera.isPerspectiveCamera) {
|
|
@@ -100,7 +111,7 @@ function followModels(camera, targets, options = {}) {
|
|
|
100
111
|
else {
|
|
101
112
|
distance = camera.position.distanceTo(center);
|
|
102
113
|
}
|
|
103
|
-
//
|
|
114
|
+
// Calculate direction based on azimuth / elevation
|
|
104
115
|
const hx = Math.sin(azimuth);
|
|
105
116
|
const hz = Math.cos(azimuth);
|
|
106
117
|
const dir = new THREE.Vector3(hx * Math.cos(elevation), Math.sin(elevation), hz * Math.cos(elevation)).normalize();
|
|
@@ -113,7 +124,6 @@ function followModels(camera, targets, options = {}) {
|
|
|
113
124
|
const startTime = performance.now();
|
|
114
125
|
return new Promise((resolve) => {
|
|
115
126
|
const step = (now) => {
|
|
116
|
-
var _a;
|
|
117
127
|
const elapsed = now - startTime;
|
|
118
128
|
const t = Math.min(1, duration > 0 ? elapsed / duration : 1);
|
|
119
129
|
const k = easingFn(t);
|
|
@@ -127,14 +137,16 @@ function followModels(camera, targets, options = {}) {
|
|
|
127
137
|
else {
|
|
128
138
|
camera.lookAt(endTarget);
|
|
129
139
|
}
|
|
130
|
-
(
|
|
131
|
-
|
|
140
|
+
if (camera.updateProjectionMatrix) {
|
|
141
|
+
camera.updateProjectionMatrix();
|
|
142
|
+
}
|
|
143
|
+
// Call progress callback
|
|
132
144
|
if (onProgress) {
|
|
133
145
|
try {
|
|
134
146
|
onProgress(t);
|
|
135
147
|
}
|
|
136
148
|
catch (error) {
|
|
137
|
-
console.error('followModels:
|
|
149
|
+
console.error('followModels: Progress callback error', error);
|
|
138
150
|
}
|
|
139
151
|
}
|
|
140
152
|
if (t < 1) {
|
|
@@ -160,12 +172,12 @@ function followModels(camera, targets, options = {}) {
|
|
|
160
172
|
});
|
|
161
173
|
}
|
|
162
174
|
catch (error) {
|
|
163
|
-
console.error('followModels:
|
|
175
|
+
console.error('followModels: Execution failed', error);
|
|
164
176
|
return Promise.reject(error);
|
|
165
177
|
}
|
|
166
178
|
}
|
|
167
179
|
/**
|
|
168
|
-
*
|
|
180
|
+
* Cancel the camera follow animation
|
|
169
181
|
*/
|
|
170
182
|
function cancelFollow(camera) {
|
|
171
183
|
const rafId = _animationMap.get(camera);
|
|
@@ -175,42 +187,50 @@ function cancelFollow(camera) {
|
|
|
175
187
|
}
|
|
176
188
|
}
|
|
177
189
|
|
|
178
|
-
// src/utils/setView.ts - 优化版
|
|
179
190
|
/**
|
|
180
|
-
*
|
|
191
|
+
* @file setView.ts
|
|
192
|
+
* @description
|
|
193
|
+
* Utility to smoothly transition the camera to preset views (Front, Back, Top, Isometric, etc.).
|
|
194
|
+
*
|
|
195
|
+
* @best-practice
|
|
196
|
+
* - Use `setView` for UI buttons that switch camera angles.
|
|
197
|
+
* - Leverage `ViewPresets` for readable code when using standard views.
|
|
198
|
+
*/
|
|
199
|
+
/**
|
|
200
|
+
* Smoothly switches the camera to the optimal angle for the model.
|
|
181
201
|
*
|
|
182
|
-
*
|
|
183
|
-
* -
|
|
184
|
-
* -
|
|
185
|
-
* -
|
|
186
|
-
* -
|
|
187
|
-
* -
|
|
202
|
+
* Features:
|
|
203
|
+
* - Reuses followModels logic to avoid code duplication
|
|
204
|
+
* - Supports more angles
|
|
205
|
+
* - Enhanced configuration options
|
|
206
|
+
* - Returns Promise to support chaining
|
|
207
|
+
* - Supports animation cancellation
|
|
188
208
|
*
|
|
189
|
-
* @param camera THREE.PerspectiveCamera
|
|
190
|
-
* @param controls OrbitControls
|
|
191
|
-
* @param targetObj THREE.Object3D
|
|
192
|
-
* @param position
|
|
193
|
-
* @param options
|
|
209
|
+
* @param camera THREE.PerspectiveCamera instance
|
|
210
|
+
* @param controls OrbitControls instance
|
|
211
|
+
* @param targetObj THREE.Object3D model object
|
|
212
|
+
* @param position View position
|
|
213
|
+
* @param options Configuration options
|
|
194
214
|
* @returns Promise<void>
|
|
195
215
|
*/
|
|
196
216
|
function setView(camera, controls, targetObj, position = 'front', options = {}) {
|
|
197
217
|
const { distanceFactor = 0.8, duration = 1000, easing = 'easeInOut', onProgress } = options;
|
|
198
|
-
//
|
|
218
|
+
// Boundary check
|
|
199
219
|
if (!targetObj) {
|
|
200
|
-
console.warn('setView:
|
|
220
|
+
console.warn('setView: Target object is empty');
|
|
201
221
|
return Promise.reject(new Error('Target object is required'));
|
|
202
222
|
}
|
|
203
223
|
try {
|
|
204
|
-
//
|
|
224
|
+
// Calculate bounding box
|
|
205
225
|
const box = new THREE.Box3().setFromObject(targetObj);
|
|
206
226
|
if (!isFinite(box.min.x)) {
|
|
207
|
-
console.warn('setView:
|
|
227
|
+
console.warn('setView: Failed to calculate bounding box');
|
|
208
228
|
return Promise.reject(new Error('Invalid bounding box'));
|
|
209
229
|
}
|
|
210
230
|
const center = box.getCenter(new THREE.Vector3());
|
|
211
231
|
const size = box.getSize(new THREE.Vector3());
|
|
212
232
|
const maxSize = Math.max(size.x, size.y, size.z);
|
|
213
|
-
//
|
|
233
|
+
// Use mapping table for creating view angles
|
|
214
234
|
const viewAngles = {
|
|
215
235
|
'front': { azimuth: 0, elevation: 0 },
|
|
216
236
|
'back': { azimuth: Math.PI, elevation: 0 },
|
|
@@ -221,7 +241,7 @@ function setView(camera, controls, targetObj, position = 'front', options = {})
|
|
|
221
241
|
'iso': { azimuth: Math.PI / 4, elevation: Math.PI / 4 }
|
|
222
242
|
};
|
|
223
243
|
const angle = viewAngles[position] || viewAngles.front;
|
|
224
|
-
//
|
|
244
|
+
// Reuse followModels to avoid code duplication
|
|
225
245
|
return followModels(camera, targetObj, {
|
|
226
246
|
duration,
|
|
227
247
|
padding: distanceFactor,
|
|
@@ -233,30 +253,30 @@ function setView(camera, controls, targetObj, position = 'front', options = {})
|
|
|
233
253
|
});
|
|
234
254
|
}
|
|
235
255
|
catch (error) {
|
|
236
|
-
console.error('setView:
|
|
256
|
+
console.error('setView: Execution failed', error);
|
|
237
257
|
return Promise.reject(error);
|
|
238
258
|
}
|
|
239
259
|
}
|
|
240
260
|
/**
|
|
241
|
-
*
|
|
261
|
+
* Cancel view switch animation
|
|
242
262
|
*/
|
|
243
263
|
function cancelSetView(camera) {
|
|
244
264
|
cancelFollow(camera);
|
|
245
265
|
}
|
|
246
266
|
/**
|
|
247
|
-
*
|
|
267
|
+
* Preset view shortcut methods
|
|
248
268
|
*/
|
|
249
269
|
const ViewPresets = {
|
|
250
270
|
/**
|
|
251
|
-
*
|
|
271
|
+
* Front View
|
|
252
272
|
*/
|
|
253
273
|
front: (camera, controls, target, options) => setView(camera, controls, target, 'front', options),
|
|
254
274
|
/**
|
|
255
|
-
*
|
|
275
|
+
* Isometric View
|
|
256
276
|
*/
|
|
257
277
|
isometric: (camera, controls, target, options) => setView(camera, controls, target, 'iso', options),
|
|
258
278
|
/**
|
|
259
|
-
*
|
|
279
|
+
* Top View
|
|
260
280
|
*/
|
|
261
281
|
top: (camera, controls, target, options) => setView(camera, controls, target, 'top', options)
|
|
262
282
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/camera/followModels.ts","../../src/camera/setView.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;AAAA;
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/camera/followModels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EAAE,KAAK,CAAC,OAAO;YACtB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,MAAM;YACN;AACD,SAAA,CAAC;IACJ;IAAE,OAAO,KAAK,EAAE;AACd,QAAA,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC;AACjD,QAAA,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAC9B;AACF;AAEA;;AAEG;AACG,SAAU,aAAa,CAAC,MAA+B,EAAA;IAC3D,YAAY,CAAC,MAAM,CAAC;AACtB;AAEA;;AAEG;AACI,MAAM,WAAW,GAAG;AACzB;;AAEG;IACH,KAAK,EAAE,CAAC,MAA+B,EAAE,QAAuB,EAAE,MAAsB,EAAE,OAAwB,KAChH,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC;AAErD;;AAEG;IACH,SAAS,EAAE,CAAC,MAA+B,EAAE,QAAuB,EAAE,MAAsB,EAAE,OAAwB,KACpH,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC;AAEnD;;AAEG;IACH,GAAG,EAAE,CAAC,MAA+B,EAAE,QAAuB,EAAE,MAAsB,EAAE,OAAwB,KAC9G,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;;;;;"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -2,6 +2,17 @@ import * as THREE from 'three';
|
|
|
2
2
|
import { OutlinePass } from 'three/examples/jsm/postprocessing/OutlinePass';
|
|
3
3
|
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @file labelManager.ts
|
|
7
|
+
* @description
|
|
8
|
+
* Manages HTML labels attached to 3D objects. Efficiently updates label positions based on camera movement.
|
|
9
|
+
*
|
|
10
|
+
* @best-practice
|
|
11
|
+
* - Use `addChildModelLabels` to label parts of a loaded model.
|
|
12
|
+
* - Labels are HTML elements overlaid on the canvas.
|
|
13
|
+
* - Supports performance optimization via caching and visibility culling.
|
|
14
|
+
*/
|
|
15
|
+
|
|
5
16
|
interface LabelOptions {
|
|
6
17
|
fontSize?: string;
|
|
7
18
|
color?: string;
|
|
@@ -18,23 +29,34 @@ interface LabelManager {
|
|
|
18
29
|
isRunning: () => boolean;
|
|
19
30
|
}
|
|
20
31
|
/**
|
|
21
|
-
*
|
|
32
|
+
* Add overhead labels to child models (supports Mesh and Group)
|
|
22
33
|
*
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
25
|
-
* -
|
|
26
|
-
* -
|
|
27
|
-
* -
|
|
34
|
+
* Features:
|
|
35
|
+
* - Caches bounding boxes to avoid repetitive calculation every frame
|
|
36
|
+
* - Supports pause/resume
|
|
37
|
+
* - Configurable update interval to reduce CPU usage
|
|
38
|
+
* - Automatically pauses when hidden
|
|
28
39
|
*
|
|
29
|
-
* @param camera THREE.Camera -
|
|
30
|
-
* @param renderer THREE.WebGLRenderer -
|
|
31
|
-
* @param parentModel THREE.Object3D - FBX
|
|
32
|
-
* @param modelLabelsMap Record<string,string> -
|
|
33
|
-
* @param options LabelOptions -
|
|
34
|
-
* @returns LabelManager -
|
|
40
|
+
* @param camera THREE.Camera - Scene camera
|
|
41
|
+
* @param renderer THREE.WebGLRenderer - Renderer, used for screen size
|
|
42
|
+
* @param parentModel THREE.Object3D - FBX root node or Group
|
|
43
|
+
* @param modelLabelsMap Record<string,string> - Map of model name to label text
|
|
44
|
+
* @param options LabelOptions - Optional label style configuration
|
|
45
|
+
* @returns LabelManager - Management interface containing pause/resume/dispose
|
|
35
46
|
*/
|
|
36
47
|
declare function addChildModelLabels(camera: THREE.Camera, renderer: THREE.WebGLRenderer, parentModel: THREE.Object3D, modelLabelsMap: Record<string, string>, options?: LabelOptions): LabelManager;
|
|
37
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @file hoverEffect.ts
|
|
51
|
+
* @description
|
|
52
|
+
* Singleton highlight effect manager. Uses OutlinePass to create a breathing highlight effect on hovered objects.
|
|
53
|
+
*
|
|
54
|
+
* @best-practice
|
|
55
|
+
* - Initialize once in your setup/mounted hook.
|
|
56
|
+
* - Call `updateHighlightNames` to filter which objects are interactive.
|
|
57
|
+
* - Automatically handles mousemove throttling and cleanup on dispose.
|
|
58
|
+
*/
|
|
59
|
+
|
|
38
60
|
type HoverBreathOptions = {
|
|
39
61
|
camera: THREE.Camera;
|
|
40
62
|
scene: THREE.Scene;
|
|
@@ -47,13 +69,13 @@ type HoverBreathOptions = {
|
|
|
47
69
|
throttleDelay?: number;
|
|
48
70
|
};
|
|
49
71
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
72
|
+
* Create a singleton highlighter - Recommended to create once on mount
|
|
73
|
+
* Returns { updateHighlightNames, dispose, getHoveredName } interface
|
|
52
74
|
*
|
|
53
|
-
*
|
|
54
|
-
* -
|
|
55
|
-
* - mousemove
|
|
56
|
-
* -
|
|
75
|
+
* Features:
|
|
76
|
+
* - Automatically pauses animation when no object is hovered
|
|
77
|
+
* - Throttles mousemove events to avoid excessive calculation
|
|
78
|
+
* - Uses passive event listeners to improve scrolling performance
|
|
57
79
|
*/
|
|
58
80
|
declare function enableHoverBreath(opts: HoverBreathOptions): {
|
|
59
81
|
updateHighlightNames: (names: string[] | null) => void;
|
|
@@ -63,7 +85,18 @@ declare function enableHoverBreath(opts: HoverBreathOptions): {
|
|
|
63
85
|
};
|
|
64
86
|
|
|
65
87
|
/**
|
|
66
|
-
*
|
|
88
|
+
* @file postProcessing.ts
|
|
89
|
+
* @description
|
|
90
|
+
* Manages the post-processing chain, specifically for Outline effects and Gamma correction.
|
|
91
|
+
*
|
|
92
|
+
* @best-practice
|
|
93
|
+
* - call `initPostProcessing` after creating your renderer and scene.
|
|
94
|
+
* - Use the returned `composer` in your render loop instead of `renderer.render`.
|
|
95
|
+
* - Handles resizing automatically via the `resize` method.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Post-processing configuration options
|
|
67
100
|
*/
|
|
68
101
|
interface PostProcessingOptions {
|
|
69
102
|
edgeStrength?: number;
|
|
@@ -74,7 +107,7 @@ interface PostProcessingOptions {
|
|
|
74
107
|
resolutionScale?: number;
|
|
75
108
|
}
|
|
76
109
|
/**
|
|
77
|
-
*
|
|
110
|
+
* Post-processing management interface
|
|
78
111
|
*/
|
|
79
112
|
interface PostProcessingManager {
|
|
80
113
|
composer: EffectComposer;
|
|
@@ -83,18 +116,18 @@ interface PostProcessingManager {
|
|
|
83
116
|
dispose: () => void;
|
|
84
117
|
}
|
|
85
118
|
/**
|
|
86
|
-
*
|
|
119
|
+
* Initialize outline-related information (contains OutlinePass)
|
|
87
120
|
*
|
|
88
|
-
*
|
|
89
|
-
* -
|
|
90
|
-
* -
|
|
91
|
-
* -
|
|
121
|
+
* Capabilities:
|
|
122
|
+
* - Supports automatic update on window resize
|
|
123
|
+
* - Configurable resolution scale for performance improvement
|
|
124
|
+
* - Comprehensive resource disposal management
|
|
92
125
|
*
|
|
93
126
|
* @param renderer THREE.WebGLRenderer
|
|
94
127
|
* @param scene THREE.Scene
|
|
95
128
|
* @param camera THREE.Camera
|
|
96
|
-
* @param options PostProcessingOptions -
|
|
97
|
-
* @returns PostProcessingManager -
|
|
129
|
+
* @param options PostProcessingOptions - Optional configuration
|
|
130
|
+
* @returns PostProcessingManager - Management interface containing composer/outlinePass/resize/dispose
|
|
98
131
|
*/
|
|
99
132
|
declare function initPostProcessing(renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera, options?: PostProcessingOptions): PostProcessingManager;
|
|
100
133
|
|