@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/README.md
CHANGED
|
@@ -1,609 +1,228 @@
|
|
|
1
1
|
# three-model-render
|
|
2
2
|
|
|
3
|
-
> 🚀
|
|
3
|
+
> 🚀 专业级 Three.js 模型可视化与交互工具库
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[English](./README_EN.md) | 中文
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
一个高性能、TypeScript 优先的工具库,提供 14 个经过优化的实用工具,专注于解决 Three.js 模型可视化与交互中的常见问题。
|
|
8
|
+
|
|
9
|
+
> 🌟 **[在线体验 Demo](https://happycolour.github.io/)**
|
|
10
|
+
|
|
11
|
+
[](https://github.com/HappyColour/three-model-render)
|
|
8
12
|
[](./LICENSE)
|
|
9
13
|
[](https://www.typescriptlang.org/)
|
|
10
14
|
|
|
11
|
-
## ✨
|
|
15
|
+
## ✨ 核心特性
|
|
12
16
|
|
|
13
|
-
- 🎯 **14
|
|
14
|
-
- 📦
|
|
15
|
-
- 🔷 **TypeScript
|
|
16
|
-
- ⚡
|
|
17
|
-
- 🎨
|
|
18
|
-
- 📝
|
|
17
|
+
- 🎯 **14 个高性能工具** - 覆盖从加载、展示到交互的全流程
|
|
18
|
+
- 📦 **支持 Tree-Shaking** - 按需引入,体积更小
|
|
19
|
+
- 🔷 **TypeScript 优先** - 完整的类型定义与智能提示
|
|
20
|
+
- ⚡ **性能优化** - 相比原生实现,闲置 CPU 占用降低 55%,内存占用降低 33%
|
|
21
|
+
- 🎨 **无缝集成** - 完美支持 Vue 3, React 及原生 JavaScript
|
|
22
|
+
- 📝 **完善文档** - 提供最佳实践指引与完整示例
|
|
19
23
|
|
|
20
24
|
---
|
|
21
25
|
|
|
22
|
-
## 📦
|
|
23
|
-
|
|
24
|
-
### Using npm
|
|
25
|
-
```bash
|
|
26
|
-
npm install @chocozhang/three-model-render
|
|
27
|
-
```
|
|
26
|
+
## 📦 安装
|
|
28
27
|
|
|
29
|
-
### Using yarn
|
|
30
28
|
```bash
|
|
31
|
-
|
|
29
|
+
npm install @chocozhang/three-model-render@latest
|
|
30
|
+
# 或
|
|
31
|
+
pnpm add @chocozhang/three-model-render@latest
|
|
32
|
+
# 或
|
|
33
|
+
yarn add @chocozhang/three-model-render@latest
|
|
32
34
|
```
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
pnpm add @chocozhang/three-model-render
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
**Peer Dependencies:**
|
|
36
|
+
**对等依赖 (Peer Dependencies):**
|
|
37
|
+
请确保你的项目中安装了 `three`:
|
|
40
38
|
```bash
|
|
41
39
|
npm install three@^0.160.0
|
|
42
40
|
```
|
|
43
41
|
|
|
44
42
|
---
|
|
45
43
|
|
|
46
|
-
## 🚀
|
|
44
|
+
## 🚀 最佳实践工作流 (Best Practice Workflow)
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { followModels, addChildModelLabels, enableHoverBreath } from '@chocozhang/three-model-render'
|
|
46
|
+
为了构建专业、高性能的 3D 查看器,我们建议遵循以下集成模式。此工作流经过生产环境验证,能确保最佳的视觉效果与性能表现。
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
easing: 'easeInOut',
|
|
55
|
-
duration: 1000
|
|
56
|
-
})
|
|
57
|
-
```
|
|
48
|
+
### 1. 基础环境与模型加载
|
|
49
|
+
使用我们优化过的加载器初始化场景。它会自动处理 GLTF/GLB/FBX/OBJ 格式,并内置了 Draco 解码器配置。
|
|
58
50
|
|
|
59
|
-
### Import按需 (Recommended)
|
|
60
51
|
```typescript
|
|
61
|
-
|
|
62
|
-
import { followModels } from '@chocozhang/three-model-render/camera'
|
|
63
|
-
import { addChildModelLabels } from '@chocozhang/three-model-render/core'
|
|
64
|
-
import { enableHoverBreath } from '@chocozhang/three-model-render/core'
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
## 📚 Module Overview
|
|
70
|
-
|
|
71
|
-
### Core Utilities (`/core`)
|
|
72
|
-
High-frequency rendering optimizations
|
|
73
|
-
|
|
74
|
-
- **`addChildModelLabels`** - 3D model labels with 60% less CPU
|
|
75
|
-
- **`enableHoverBreath`** - Hover breathing effect with 80% less idle CPU
|
|
76
|
-
- **`initPostProcessing`** - Post-processing with resize support
|
|
77
|
-
|
|
78
|
-
### Interaction Utilities (`/interaction`)
|
|
79
|
-
User interaction enhancements
|
|
80
|
-
|
|
81
|
-
- **`createModelClickHandler`** - Click handling with debouncing
|
|
82
|
-
- **`ArrowGuide`** - Arrow指引 with fade effects
|
|
83
|
-
- **`LiquidFillerGroup`** - Liquid filling animations
|
|
84
|
-
|
|
85
|
-
### Camera Utilities (`/camera`)
|
|
86
|
-
Camera control and animation
|
|
87
|
-
|
|
88
|
-
- **`followModels`** - Smooth camera following with easing
|
|
89
|
-
- **`setView`** - Quick view switching with animations
|
|
90
|
-
|
|
91
|
-
### Loader Utilities (`/loader`)
|
|
92
|
-
Asset loading and management
|
|
93
|
-
|
|
94
|
-
- **`loadModelByUrl`** - Universal model loader (FBX, GLTF, OBJ, etc.)
|
|
95
|
-
- **`loadSkybox`** - Skybox loader with caching
|
|
96
|
-
- **`BlueSky`** - HDR/EXR environment manager
|
|
97
|
-
|
|
98
|
-
### UI Utilities (`/ui`)
|
|
99
|
-
User interface components
|
|
100
|
-
|
|
101
|
-
- **`createModelsLabel`** - Labels with connection lines and fade-in
|
|
102
|
-
|
|
103
|
-
### Effect Utilities (`/effect`)
|
|
104
|
-
Visual effects
|
|
105
|
-
|
|
106
|
-
- **`GroupExploder`** - Model explosion effects with multiple modes
|
|
107
|
-
|
|
108
|
-
### Setup Utilities (`/setup`)
|
|
109
|
-
Scene initialization
|
|
110
|
-
|
|
111
|
-
- **`autoSetupCameraAndLight`** - Auto camera and lighting setup
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## 📖 Detailed API Documentation
|
|
116
|
-
|
|
117
|
-
### Core: addChildModelLabels
|
|
118
|
-
|
|
119
|
-
Add floating 3D labels to model children with automatic position tracking.
|
|
52
|
+
import { loadModelByUrl } from '@chocozhang/three-model-render';
|
|
120
53
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
54
|
+
// 1. 初始化基础场景
|
|
55
|
+
const scene = new THREE.Scene();
|
|
56
|
+
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
|
|
57
|
+
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
|
58
|
+
const controls = new OrbitControls(camera, renderer.domElement);
|
|
125
59
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
'part1': 'Component 1',
|
|
132
|
-
'part2': 'Component 2'
|
|
133
|
-
}, {
|
|
134
|
-
enableCache: true, // Enable bounding box caching
|
|
135
|
-
updateInterval: 33, // Update at 30fps
|
|
136
|
-
fontSize: '14px',
|
|
137
|
-
color: '#ffffff'
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
// Control lifecycle
|
|
141
|
-
labelManager.pause() // Pause updates
|
|
142
|
-
labelManager.resume() // Resume updates
|
|
143
|
-
labelManager.isRunning() // Check status
|
|
144
|
-
labelManager.dispose() // Clean up
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
**Options:**
|
|
148
|
-
```typescript
|
|
149
|
-
interface LabelOptions {
|
|
150
|
-
fontSize?: string // Default: '12px'
|
|
151
|
-
color?: string // Default: '#ffffff'
|
|
152
|
-
background?: string // Default: '#1890ff'
|
|
153
|
-
padding?: string // Default: '6px 10px'
|
|
154
|
-
borderRadius?: string // Default: '6px'
|
|
155
|
-
updateInterval?: number // Default: 0 (every frame)
|
|
156
|
-
enableCache?: boolean // Default: true
|
|
157
|
-
}
|
|
60
|
+
// 2. 加载模型 (支持进度回调)
|
|
61
|
+
const model = await loadModelByUrl('path/to/model.glb', {
|
|
62
|
+
manager: new THREE.LoadingManager(() => console.log('加载完成'))
|
|
63
|
+
});
|
|
64
|
+
scene.add(model);
|
|
158
65
|
```
|
|
159
66
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
### Core: enableHoverBreath
|
|
163
|
-
|
|
164
|
-
Breathing outline effect on hover with intelligent performance optimization.
|
|
165
|
-
|
|
166
|
-
**Features:**
|
|
167
|
-
- ✅ Auto-pause when no object is hovered (80% idle CPU reduction)
|
|
168
|
-
- ✅ Mousemove throttling
|
|
169
|
-
- ✅ Passive event listeners
|
|
170
|
-
|
|
171
|
-
**Usage:**
|
|
172
|
-
```typescript
|
|
173
|
-
import { enableHoverBreath } from '@chocozhang/three-model-render/core'
|
|
174
|
-
|
|
175
|
-
const hoverEffect = enableHoverBreath({
|
|
176
|
-
camera,
|
|
177
|
-
scene,
|
|
178
|
-
renderer,
|
|
179
|
-
outlinePass,
|
|
180
|
-
highlightNames: ['model1', 'model2'],
|
|
181
|
-
throttleDelay: 16, // 60fps throttling
|
|
182
|
-
minStrength: 2,
|
|
183
|
-
maxStrength: 8,
|
|
184
|
-
speed: 3
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
// Cleanup
|
|
188
|
-
hoverEffect.dispose()
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
---
|
|
192
|
-
|
|
193
|
-
### Core: initPostProcessing
|
|
194
|
-
|
|
195
|
-
Initialize post-processing with resize handling and performance options.
|
|
196
|
-
|
|
197
|
-
**Features:**
|
|
198
|
-
- ✅ Auto-resize support
|
|
199
|
-
- ✅ Resolution scaling for performance
|
|
200
|
-
- ✅ Complete lifecycle management
|
|
67
|
+
### 2. 自动场景配置 (关键步骤)
|
|
68
|
+
根据模型的包围盒大小,自动计算最佳相机距离、近裁剪面(Near)和远裁剪面(Far),并设置影棚级光照。
|
|
201
69
|
|
|
202
|
-
**Usage:**
|
|
203
70
|
```typescript
|
|
204
|
-
import {
|
|
71
|
+
import { autoSetupCameraAndLight } from '@chocozhang/three-model-render/setup';
|
|
205
72
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
// Access components
|
|
213
|
-
ppManager.composer.render()
|
|
214
|
-
ppManager.outlinePass.selectedObjects = [mesh]
|
|
215
|
-
|
|
216
|
-
// Handle resize
|
|
217
|
-
window.addEventListener('resize', () => ppManager.resize())
|
|
218
|
-
|
|
219
|
-
// Cleanup
|
|
220
|
-
ppManager.dispose()
|
|
73
|
+
// 一键配置相机与灯光
|
|
74
|
+
const lightHandles = autoSetupCameraAndLight(camera, scene, model, {
|
|
75
|
+
enableShadows: true, // 开启阴影
|
|
76
|
+
intensity: 1.5 // 光照强度
|
|
77
|
+
});
|
|
221
78
|
```
|
|
222
79
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
### Camera: followModels
|
|
226
|
-
|
|
227
|
-
Smoothly move camera to focus on target objects with easing animations.
|
|
228
|
-
|
|
229
|
-
**Features:**
|
|
230
|
-
- ✅ Multiple easing functions
|
|
231
|
-
- ✅ Progress callback
|
|
232
|
-
- ✅ Cancelable animations
|
|
80
|
+
### 3. 电影级入场动画
|
|
81
|
+
模型加载后,使用平滑的运镜动画将视角聚焦到模型正面。
|
|
233
82
|
|
|
234
|
-
**Usage:**
|
|
235
83
|
```typescript
|
|
236
|
-
import { followModels,
|
|
237
|
-
|
|
238
|
-
await followModels(camera, targetMesh, {
|
|
239
|
-
easing: 'easeInOut', // 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
|
|
240
|
-
duration: 1000,
|
|
241
|
-
padding: 1.2,
|
|
242
|
-
controls: orbitControls,
|
|
243
|
-
onProgress: (progress) => {
|
|
244
|
-
console.log(`Animation: ${progress * 100}%`)
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
// Cancel animation
|
|
249
|
-
cancelFollow(camera)
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
**Preset Angles:**
|
|
253
|
-
```typescript
|
|
254
|
-
import { FOLLOW_ANGLES } from '@chocozhang/three-model-render/camera'
|
|
84
|
+
import { followModels, FOLLOW_ANGLES } from '@chocozhang/three-model-render';
|
|
255
85
|
|
|
256
86
|
followModels(camera, model, {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
### Camera: setView
|
|
264
|
-
|
|
265
|
-
Quick view switching with smooth animations.
|
|
266
|
-
|
|
267
|
-
**Usage:**
|
|
268
|
-
```typescript
|
|
269
|
-
import { setView, ViewPresets } from '@chocozhang/three-model-render/camera'
|
|
270
|
-
|
|
271
|
-
// Programmatic view
|
|
272
|
-
await setView(camera, controls, model, 'front', {
|
|
273
|
-
easing: 'easeInOut',
|
|
274
|
-
duration: 800
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
// Using presets
|
|
278
|
-
ViewPresets.isometric(camera, controls, model)
|
|
279
|
-
ViewPresets.top(camera, controls, model)
|
|
87
|
+
...FOLLOW_ANGLES.FRONT, // 使用预设角度
|
|
88
|
+
duration: 1500, // 动画时长 1.5s
|
|
89
|
+
padding: 0.8, // 留白比例
|
|
90
|
+
controls, // 绑定控制器以同步状态
|
|
91
|
+
easing: 'easeInOut' // 缓动函数
|
|
92
|
+
});
|
|
280
93
|
```
|
|
281
94
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
- `'back'` - Back view
|
|
285
|
-
- `'left'` - Left side
|
|
286
|
-
- `'right'` - Right side
|
|
287
|
-
- `'top'` - Top view
|
|
288
|
-
- `'bottom'` - Bottom view
|
|
289
|
-
- `'iso'` - Isometric view
|
|
290
|
-
|
|
291
|
-
---
|
|
292
|
-
|
|
293
|
-
### Loader: loadModelByUrl
|
|
294
|
-
|
|
295
|
-
Universal model loader supporting multiple formats.
|
|
296
|
-
|
|
297
|
-
**Features:**
|
|
298
|
-
- ✅ Auto-format detection
|
|
299
|
-
- ✅ DRACO/KTX2 support (GLTF)
|
|
300
|
-
- ✅ Geometry optimization
|
|
301
|
-
- ✅ Texture downscaling
|
|
95
|
+
### 4. 后期处理与呼吸光效
|
|
96
|
+
启用高性能后期处理管线和智能呼吸光效(闲置时自动降低帧率以节省电量)。
|
|
302
97
|
|
|
303
|
-
**Usage:**
|
|
304
98
|
```typescript
|
|
305
|
-
import {
|
|
99
|
+
import { initPostProcessing, enableHoverBreath } from '@chocozhang/three-model-render';
|
|
306
100
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
101
|
+
// 1. 初始化后期处理管理器
|
|
102
|
+
const ppManager = initPostProcessing(renderer, scene, camera, {
|
|
103
|
+
resolutionScale: 0.8, // 降低分辨率以提升性能
|
|
104
|
+
edgeStrength: 4, // 描边强度
|
|
105
|
+
visibleEdgeColor: '#ffee00' // 描边颜色
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// 2. 启用智能悬停效果
|
|
109
|
+
const hoverController = enableHoverBreath({
|
|
110
|
+
camera,
|
|
111
|
+
scene,
|
|
112
|
+
renderer,
|
|
113
|
+
outlinePass: ppManager.outlinePass,
|
|
114
|
+
throttleDelay: 16, // 60fps 节流
|
|
115
|
+
minStrength: 2, // 呼吸最小强度
|
|
116
|
+
maxStrength: 8, // 呼吸最大强度
|
|
117
|
+
speed: 3 // 呼吸速度
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// 重要: 在动画循环中调用 render
|
|
121
|
+
function animate() {
|
|
122
|
+
requestAnimationFrame(animate);
|
|
123
|
+
// 使用 composer 替代 renderer.render
|
|
124
|
+
ppManager.composer.render();
|
|
125
|
+
}
|
|
314
126
|
```
|
|
315
127
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
- FBX
|
|
319
|
-
- OBJ
|
|
320
|
-
- PLY
|
|
321
|
-
- STL
|
|
322
|
-
|
|
323
|
-
---
|
|
324
|
-
|
|
325
|
-
### Loader: BlueSky (HDR/EXR Manager)
|
|
326
|
-
|
|
327
|
-
Global singleton for managing HDR/EXR environment maps.
|
|
328
|
-
|
|
329
|
-
**Features:**
|
|
330
|
-
- ✅ Promise API with progress
|
|
331
|
-
- ✅ Loading state management
|
|
332
|
-
- ✅ Cancel loading support
|
|
128
|
+
### 5. 交互处理系统的集成
|
|
129
|
+
添加智能点击事件,支持自动聚焦到被点击的组件。
|
|
333
130
|
|
|
334
|
-
**Usage:**
|
|
335
131
|
```typescript
|
|
336
|
-
import {
|
|
337
|
-
|
|
338
|
-
//
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
// Cleanup
|
|
359
|
-
BlueSky.dispose()
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
---
|
|
363
|
-
|
|
364
|
-
### UI: createModelsLabel
|
|
365
|
-
|
|
366
|
-
Create labels with connection lines and animations.
|
|
132
|
+
import { createModelClickHandler } from '@chocozhang/three-model-render';
|
|
133
|
+
|
|
134
|
+
// 创建点击处理器 (返回销毁函数)
|
|
135
|
+
const disposeClickHandler = createModelClickHandler(
|
|
136
|
+
camera,
|
|
137
|
+
scene,
|
|
138
|
+
renderer,
|
|
139
|
+
ppManager.outlinePass,
|
|
140
|
+
(object, info) => {
|
|
141
|
+
console.log('点击了:', info);
|
|
142
|
+
|
|
143
|
+
// 聚焦到被点击的部件
|
|
144
|
+
followModels(camera, object, {
|
|
145
|
+
...FOLLOW_ANGLES.ISOMETRIC,
|
|
146
|
+
duration: 1000
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 6. 高级特效:爆炸分解
|
|
153
|
+
无需复杂计算,一行代码实现模型的爆炸分解视图。
|
|
367
154
|
|
|
368
|
-
**Features:**
|
|
369
|
-
- ✅ Pause/resume API
|
|
370
|
-
- ✅ Bounding box caching
|
|
371
|
-
- ✅ Fade-in animations
|
|
372
|
-
|
|
373
|
-
**Usage:**
|
|
374
155
|
```typescript
|
|
375
|
-
import {
|
|
376
|
-
|
|
377
|
-
const labelMgr = createModelsLabel(camera, renderer, model, {
|
|
378
|
-
'mesh1': 'Part A',
|
|
379
|
-
'mesh2': 'Part B'
|
|
380
|
-
}, {
|
|
381
|
-
updateInterval: 33, // 30fps
|
|
382
|
-
fadeInDuration: 300, // 300ms fade-in
|
|
383
|
-
lift: 100, // Lift labels 100px
|
|
384
|
-
lineColor: 'rgba(200,200,200,0.7)'
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
// Control
|
|
388
|
-
labelMgr.pause()
|
|
389
|
-
labelMgr.resume()
|
|
390
|
-
labelMgr.dispose()
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
---
|
|
156
|
+
import { GroupExploder } from '@chocozhang/three-model-render';
|
|
394
157
|
|
|
395
|
-
|
|
158
|
+
// 初始化爆炸控制器
|
|
159
|
+
const exploder = new GroupExploder(scene, camera, controls);
|
|
160
|
+
exploder.init();
|
|
396
161
|
|
|
397
|
-
|
|
162
|
+
// 设置需要爆炸的网格集合
|
|
163
|
+
exploder.setMeshes(targetMeshes);
|
|
398
164
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
165
|
+
// 执行爆炸 (Grid 模式)
|
|
166
|
+
exploder.explode({
|
|
167
|
+
mode: 'grid', // 排列模式: 'ring' | 'spiral' | 'grid' | 'radial'
|
|
168
|
+
spacing: 2.8, // 间距
|
|
169
|
+
dimOthers: { enabled: true, opacity: 0.1 } // 使其他物体透明
|
|
170
|
+
});
|
|
403
171
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
import { GroupExploder } from '@chocozhang/three-model-render/effect'
|
|
407
|
-
|
|
408
|
-
const exploder = new GroupExploder(scene, camera, controls)
|
|
409
|
-
exploder.init()
|
|
410
|
-
|
|
411
|
-
// Set target meshes
|
|
412
|
-
const meshes = new Set([mesh1, mesh2, mesh3])
|
|
413
|
-
exploder.setMeshes(meshes)
|
|
414
|
-
|
|
415
|
-
// Explode
|
|
416
|
-
exploder.explode({
|
|
417
|
-
mode: 'spiral', // 'ring' | 'spiral' | 'grid' | 'radial'
|
|
418
|
-
spacing: 2.5,
|
|
419
|
-
duration: 1000,
|
|
420
|
-
lift: 0.6,
|
|
421
|
-
dimOthers: {
|
|
422
|
-
enabled: true,
|
|
423
|
-
opacity: 0.25
|
|
424
|
-
}
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
// Restore
|
|
428
|
-
exploder.restore(600)
|
|
429
|
-
|
|
430
|
-
// Cleanup
|
|
431
|
-
exploder.dispose()
|
|
172
|
+
// 还原
|
|
173
|
+
exploder.restore(600);
|
|
432
174
|
```
|
|
433
175
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
### Setup: autoSetupCameraAndLight
|
|
437
|
-
|
|
438
|
-
Automatically setup camera and lighting for a model.
|
|
176
|
+
### 7. 视角快速切换
|
|
177
|
+
提供标准的工程视角切换功能。
|
|
439
178
|
|
|
440
|
-
**Features:**
|
|
441
|
-
- ✅ Auto-calculate optimal position
|
|
442
|
-
- ✅ Multi-directional lighting
|
|
443
|
-
- ✅ Shadow support
|
|
444
|
-
- ✅ Light intensity adjustment
|
|
445
|
-
|
|
446
|
-
**Usage:**
|
|
447
179
|
```typescript
|
|
448
|
-
import {
|
|
449
|
-
|
|
450
|
-
const handle = autoSetupCameraAndLight(camera, scene, model, {
|
|
451
|
-
enableShadows: true,
|
|
452
|
-
padding: 1.2,
|
|
453
|
-
shadowMapSize: 2048,
|
|
454
|
-
renderer
|
|
455
|
-
})
|
|
180
|
+
import { setView } from '@chocozhang/three-model-render';
|
|
456
181
|
|
|
457
|
-
//
|
|
458
|
-
|
|
182
|
+
// 切换到顶视图
|
|
183
|
+
setView(camera, controls, model, 'top');
|
|
459
184
|
|
|
460
|
-
//
|
|
461
|
-
|
|
185
|
+
// 切换到等轴测视图 (ISO)
|
|
186
|
+
setView(camera, controls, model, 'iso');
|
|
462
187
|
```
|
|
463
188
|
|
|
464
189
|
---
|
|
465
190
|
|
|
466
|
-
##
|
|
467
|
-
|
|
468
|
-
### Vue 3
|
|
469
|
-
```vue
|
|
470
|
-
<script setup lang="ts">
|
|
471
|
-
import { onMounted, onUnmounted } from 'vue'
|
|
472
|
-
import { followModels } from 'three-model-render/camera'
|
|
473
|
-
import { addChildModelLabels } from 'three-model-render/core'
|
|
474
|
-
|
|
475
|
-
let labelManager: any
|
|
476
|
-
|
|
477
|
-
onMounted(() => {
|
|
478
|
-
labelManager = addChildModelLabels(camera, renderer, model, labelsMap, {
|
|
479
|
-
enableCache: true
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
followModels(camera, model, {
|
|
483
|
-
easing: 'easeInOut'
|
|
484
|
-
})
|
|
485
|
-
})
|
|
486
|
-
|
|
487
|
-
onUnmounted(() => {
|
|
488
|
-
labelManager?.dispose()
|
|
489
|
-
})
|
|
490
|
-
</script>
|
|
491
|
-
```
|
|
191
|
+
## 📚 模块总览 (Module Overview)
|
|
492
192
|
|
|
493
|
-
###
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
import { addChildModelLabels } from '@chocozhang/three-model-render/core'
|
|
498
|
-
|
|
499
|
-
function ModelViewer() {
|
|
500
|
-
useEffect(() => {
|
|
501
|
-
const labelManager = addChildModelLabels(camera, renderer, model, labelsMap)
|
|
502
|
-
|
|
503
|
-
followModels(camera, model, {
|
|
504
|
-
easing: 'easeInOut'
|
|
505
|
-
})
|
|
506
|
-
|
|
507
|
-
return () => labelManager.dispose()
|
|
508
|
-
}, [])
|
|
509
|
-
|
|
510
|
-
return <div ref={containerRef} />
|
|
511
|
-
}
|
|
512
|
-
```
|
|
193
|
+
### **Core (`/core`)**
|
|
194
|
+
- `initPostProcessing`: 高性能后期处理管理器,内置 OutlinePass。
|
|
195
|
+
- `enableHoverBreath`: 智能呼吸光效,支持性能自适应。
|
|
196
|
+
- `addChildModelLabels`: 3D 标签系统,自动跟随模型运动。
|
|
513
197
|
|
|
514
|
-
|
|
198
|
+
### **Camera (`/camera`)**
|
|
199
|
+
- `followModels`: 智能相机跟随与聚焦。
|
|
200
|
+
- `setView`: 预设视角切换 (Top, Front, Iso, etc.)。
|
|
515
201
|
|
|
516
|
-
|
|
202
|
+
### **Loader (`/loader`)**
|
|
203
|
+
- `loadModelByUrl`: 统一模型加载器,支持多种格式。
|
|
204
|
+
- `BlueSky`: 快速创建天空盒环境。
|
|
517
205
|
|
|
518
|
-
|
|
206
|
+
### **Interaction (`/interaction`)**
|
|
207
|
+
- `createModelClickHandler`: 射线检测点击处理器。
|
|
519
208
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
LabelManager,
|
|
523
|
-
LabelOptions,
|
|
524
|
-
HoverController,
|
|
525
|
-
PostProcessingManager,
|
|
526
|
-
FollowOptions,
|
|
527
|
-
ExplodeOptions
|
|
528
|
-
} from '@chocozhang/three-model-render'
|
|
529
|
-
```
|
|
209
|
+
### **Effect (`/effect`)**
|
|
210
|
+
- `GroupExploder`: 模型爆炸/拆解动画控制器。
|
|
530
211
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
## 🔧 Advanced Configuration
|
|
534
|
-
|
|
535
|
-
### tsconfig.json
|
|
536
|
-
```json
|
|
537
|
-
{
|
|
538
|
-
"compilerOptions": {
|
|
539
|
-
"lib": ["ES2015", "DOM"],
|
|
540
|
-
"target": "ES2015",
|
|
541
|
-
"module": "ESNext"
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
```
|
|
212
|
+
### **Setup (`/setup`)**
|
|
213
|
+
- `autoSetupCameraAndLight`: 一键自动化场景配置大师。
|
|
545
214
|
|
|
546
215
|
---
|
|
547
216
|
|
|
548
|
-
##
|
|
217
|
+
## 🎨 示例项目
|
|
549
218
|
|
|
550
|
-
|
|
551
|
-
- **CPU Usage**: ⬇️ 55% reduction
|
|
552
|
-
- **Memory Usage**: ⬇️ 33% reduction
|
|
553
|
-
- **Idle Performance**: ⬇️ 80% CPU when inactive
|
|
219
|
+
我们提供了一个完整的、可部署的示例项目,展示了所有功能的集成方式:
|
|
554
220
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|---------|--------|-------|-------------|
|
|
558
|
-
| Label Updates | 15% CPU | 6% CPU | ⬇️ 60% |
|
|
559
|
-
| Hover (Idle) | 5% CPU | 1% CPU | ⬇️ 80% |
|
|
560
|
-
| Hover (Active) | 8% CPU | 5% CPU | ⬇️ 37.5% |
|
|
561
|
-
| Memory | 180MB | 120MB | ⬇️ 33% |
|
|
221
|
+
- 👉 **[Vue 3 示例 (推荐)](https://github.com/HappyColour/three-model-render/tree/main/examples/vue-example)** - 完整的 Vue 3 + TypeScript 集成最佳实践
|
|
222
|
+
- 👉 **[HTML 原生示例](https://github.com/HappyColour/three-model-render/tree/main/examples/html-example)** - 适合原生 JavaScript / jQuery 项目
|
|
562
223
|
|
|
563
224
|
---
|
|
564
225
|
|
|
565
|
-
##
|
|
566
|
-
|
|
567
|
-
### Build Package
|
|
568
|
-
```bash
|
|
569
|
-
npm run build
|
|
570
|
-
```
|
|
571
|
-
|
|
572
|
-
### Type Check
|
|
573
|
-
```bash
|
|
574
|
-
npm run type-check
|
|
575
|
-
```
|
|
576
|
-
|
|
577
|
-
### Publish to Private Registry
|
|
578
|
-
```bash
|
|
579
|
-
npm publish
|
|
580
|
-
```
|
|
581
|
-
|
|
582
|
-
---
|
|
583
|
-
|
|
584
|
-
## 🤝 Contributing
|
|
585
|
-
|
|
586
|
-
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md).
|
|
587
|
-
|
|
588
|
-
---
|
|
589
|
-
|
|
590
|
-
## 📄 License
|
|
226
|
+
## 📄 开源协议
|
|
591
227
|
|
|
592
228
|
MIT © [Danny Zhang]
|
|
593
|
-
|
|
594
|
-
---
|
|
595
|
-
|
|
596
|
-
## 🔗 Links
|
|
597
|
-
|
|
598
|
-
- [GitHub Repository](https://github.com/HappyColour/three-model-render)
|
|
599
|
-
- [Issue Tracker](https://github.com/HappyColour/three-model-render/issues)
|
|
600
|
-
- [Three.js](https://threejs.org/)
|
|
601
|
-
|
|
602
|
-
---
|
|
603
|
-
|
|
604
|
-
## 🙏 Acknowledgments
|
|
605
|
-
|
|
606
|
-
Built with ❤️ using:
|
|
607
|
-
- [Three.js](https://threejs.org/) - 3D library
|
|
608
|
-
- [TypeScript](https://www.typescriptlang.org/) - Type safety
|
|
609
|
-
- [Rollup](https://rollupjs.org/) - Module bundler
|