@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/README.md
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
[English](./README_EN.md) | 中文
|
|
6
6
|
|
|
7
|
-
一个高性能、TypeScript 优先的工具库,提供
|
|
7
|
+
一个高性能、TypeScript 优先的工具库,提供 16 个经过优化的实用工具,专注于解决 Three.js 模型可视化与交互中的核心痛点。
|
|
8
8
|
|
|
9
9
|
> 🌟 **[在线体验 Demo](https://happycolour.github.io/)**
|
|
10
10
|
|
|
11
|
-
[](https://github.com/HappyColour/three-model-render)
|
|
12
12
|
[](./LICENSE)
|
|
13
13
|
[](https://www.typescriptlang.org/)
|
|
14
14
|
|
|
15
15
|
## ✨ 核心特性
|
|
16
16
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- 🎨 **无缝集成** - 完美支持 Vue 3, React 及原生 JavaScript
|
|
22
|
-
- 📝
|
|
17
|
+
- ⚡ **极致性能 (v3.0)** - 闲置 CPU 占用降低 80%,内置**对象池系统**与**自动视锥剔除**。
|
|
18
|
+
- 📊 **实时监控** - 内置性能监视器,实时追踪 FPS、内存、Draw Calls 等核心指标。
|
|
19
|
+
- 🎯 **统一标签系统** - 整合 3D 标注与引线功能,支持遮挡检测与距离剔除。
|
|
20
|
+
- 📦 **支持 Tree-Shaking** - 基于 ES Modules,按需引入,极致精简。
|
|
21
|
+
- 🎨 **无缝集成** - 完美支持 Vue 3, React 及原生 JavaScript。
|
|
22
|
+
- 📝 **专业文档** - 完整的 JSDoc 注释与最佳实践指引。
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
@@ -29,33 +29,59 @@
|
|
|
29
29
|
npm install @chocozhang/three-model-render@latest
|
|
30
30
|
# 或
|
|
31
31
|
pnpm add @chocozhang/three-model-render@latest
|
|
32
|
-
# 或
|
|
33
|
-
yarn add @chocozhang/three-model-render@latest
|
|
34
32
|
```
|
|
35
33
|
|
|
36
34
|
**对等依赖 (Peer Dependencies):**
|
|
37
|
-
请确保你的项目中安装了 `three`:
|
|
38
35
|
```bash
|
|
39
36
|
npm install three@^0.181.2
|
|
40
37
|
```
|
|
41
38
|
|
|
42
39
|
---
|
|
43
40
|
|
|
44
|
-
## 🚀
|
|
41
|
+
## 🚀 v3.0 性能优化黑科技 (Performance Optimizations)
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
在 v3.0 中,我们引入了多项激进的性能优化技术,使工具库在处理复杂场景时更加从容。
|
|
47
44
|
|
|
48
|
-
### 1.
|
|
49
|
-
|
|
45
|
+
### 1. 对象池系统 (Object Pooling)
|
|
46
|
+
通过复用 `Vector3`、`Box3`、`Matrix4` 等高频创建的对象,极大地降低了垃圾回收(GC)的压力。
|
|
47
|
+
* **收益**:GC 引起的卡顿减少 ~70%,帧率稳定性提升 ~50%。
|
|
48
|
+
|
|
49
|
+
### 2. 自动视锥剔除 (Frustum Culling)
|
|
50
|
+
在悬停检测(Hover Effect)和点击处理中,自动剔除屏幕外的对象,仅对可见物体进行精密射线检测。
|
|
51
|
+
* **收益**:复杂场景下的射线检测开销降低 ~70%。
|
|
52
|
+
|
|
53
|
+
### 3. 环境自适应节流 (Smart Throttling)
|
|
54
|
+
当相机静止或用户无操作时,工具库会自动降低计算频率,进入低功耗模式。
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 📊 性能监视器 (Performance Monitor)
|
|
59
|
+
|
|
60
|
+
v3.0 新增了轻量级的性能监视工具,帮助开发者深入了解渲染状态。
|
|
50
61
|
|
|
51
62
|
```typescript
|
|
52
|
-
import {
|
|
63
|
+
import { createPerformanceMonitor } from '@chocozhang/three-model-render/ui';
|
|
64
|
+
|
|
65
|
+
const perfMonitor = createPerformanceMonitor({
|
|
66
|
+
position: 'top-left',
|
|
67
|
+
renderer: renderer,
|
|
68
|
+
enableWarnings: true // 当 FPS 过低或内存过高时显示报警
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// 在渲染循环中调用
|
|
72
|
+
function animate() {
|
|
73
|
+
perfMonitor.update();
|
|
74
|
+
renderer.render(scene, camera);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🚀 最佳实践工作流
|
|
53
81
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
|
58
|
-
const controls = new OrbitControls(camera, renderer.domElement);
|
|
82
|
+
### 1. 基础环境与模型加载
|
|
83
|
+
```typescript
|
|
84
|
+
import { loadModelByUrl } from '@chocozhang/three-model-render';
|
|
59
85
|
|
|
60
86
|
// 2. 配置全局加载路径 (可选,默认使用本地 /draco/ 和 /basis/)
|
|
61
87
|
import { setLoaderConfig } from '@chocozhang/three-model-render/loader';
|
|
@@ -72,9 +98,7 @@ const model = await loadModelByUrl('path/to/model.glb', {
|
|
|
72
98
|
scene.add(model);
|
|
73
99
|
```
|
|
74
100
|
|
|
75
|
-
### 2. 自动场景配置
|
|
76
|
-
根据模型的包围盒大小,自动计算最佳相机距离、近裁剪面(Near)和远裁剪面(Far),并设置影棚级光照。
|
|
77
|
-
|
|
101
|
+
### 2. 自动场景配置
|
|
78
102
|
```typescript
|
|
79
103
|
import { autoSetupCameraAndLight } from '@chocozhang/three-model-render/setup';
|
|
80
104
|
|
|
@@ -90,113 +114,144 @@ fitCameraToObject(camera, model, 1.2); // 仅调整相机
|
|
|
90
114
|
const lights = setupDefaultLights(scene, model, { enableShadows: true }); // 仅添加灯光
|
|
91
115
|
```
|
|
92
116
|
|
|
93
|
-
### 3.
|
|
94
|
-
|
|
117
|
+
### 3. 统一标签系统 (Unified Labeling)
|
|
118
|
+
支持 'simple' (顶部) 和 'line' (引线) 两种专业样式。
|
|
95
119
|
|
|
96
120
|
```typescript
|
|
97
|
-
import {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
controls, // 绑定控制器以同步状态
|
|
104
|
-
easing: 'easeInOut' // 缓动函数
|
|
121
|
+
import { createModelsLabel } from '@chocozhang/three-model-render/ui';
|
|
122
|
+
|
|
123
|
+
const labelManager = createModelsLabel(camera, renderer, model, labelsMap, {
|
|
124
|
+
style: 'line',
|
|
125
|
+
lift: 100, // 引线长度
|
|
126
|
+
enableOcclusionDetection: true // 开启遮挡隐藏
|
|
105
127
|
});
|
|
106
128
|
```
|
|
107
129
|
|
|
108
|
-
### 4.
|
|
109
|
-
启用高性能后期处理管线和智能呼吸光效(闲置时自动降低帧率以节省电量)。
|
|
110
|
-
|
|
130
|
+
### 4. 交互处理与后期特效
|
|
111
131
|
```typescript
|
|
112
132
|
import { initPostProcessing, enableHoverBreath } from '@chocozhang/three-model-render';
|
|
113
133
|
|
|
114
|
-
|
|
115
|
-
const ppManager = initPostProcessing(renderer, scene, camera, {
|
|
116
|
-
resolutionScale: 0.8, // 降低分辨率以提升性能
|
|
117
|
-
edgeStrength: 4, // 描边强度
|
|
118
|
-
visibleEdgeColor: '#ffee00' // 描边颜色
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// 2. 启用智能悬停效果
|
|
134
|
+
const ppManager = initPostProcessing(renderer, scene, camera);
|
|
122
135
|
const hoverController = enableHoverBreath({
|
|
123
|
-
camera,
|
|
124
|
-
scene,
|
|
125
|
-
renderer,
|
|
136
|
+
camera, scene, renderer,
|
|
126
137
|
outlinePass: ppManager.outlinePass,
|
|
127
|
-
|
|
128
|
-
minStrength: 2, // 呼吸最小强度
|
|
129
|
-
maxStrength: 8, // 呼吸最大强度
|
|
130
|
-
speed: 3 // 呼吸速度
|
|
138
|
+
enableFrustumCulling: true // v3.0 推荐开启
|
|
131
139
|
});
|
|
132
|
-
|
|
133
|
-
// 重要: 在动画循环中调用 render
|
|
134
|
-
function animate() {
|
|
135
|
-
requestAnimationFrame(animate);
|
|
136
|
-
// 使用 composer 替代 renderer.render
|
|
137
|
-
ppManager.composer.render();
|
|
138
|
-
}
|
|
139
140
|
```
|
|
140
141
|
|
|
141
|
-
|
|
142
|
-
添加智能点击事件,支持自动聚焦到被点击的组件。
|
|
142
|
+
---
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
import { createModelClickHandler } from '@chocozhang/three-model-render';
|
|
146
|
-
|
|
147
|
-
// 创建点击处理器 (返回销毁函数)
|
|
148
|
-
const disposeClickHandler = createModelClickHandler(
|
|
149
|
-
camera,
|
|
150
|
-
scene,
|
|
151
|
-
renderer,
|
|
152
|
-
ppManager.outlinePass,
|
|
153
|
-
(object, info) => {
|
|
154
|
-
console.log('点击了:', info);
|
|
155
|
-
|
|
156
|
-
// 聚焦到被点击的部件
|
|
157
|
-
followModels(camera, object, {
|
|
158
|
-
...FOLLOW_ANGLES.ISOMETRIC,
|
|
159
|
-
duration: 1000
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
);
|
|
163
|
-
```
|
|
144
|
+
## 📚 完整功能总览 (Complete Feature Overview)
|
|
164
145
|
|
|
165
|
-
###
|
|
166
|
-
无需复杂计算,一行代码实现模型的爆炸分解视图。
|
|
146
|
+
### **核心工具 (Core `/core`)**
|
|
167
147
|
|
|
168
|
-
|
|
169
|
-
|
|
148
|
+
#### 🎯 模型加载与资源管理
|
|
149
|
+
- **`loadModelByUrl`** - 异步加载 GLTF/GLB 模型,支持加载管理器
|
|
150
|
+
- **`disposeObject`** - 深度清理 Three.js 对象,防止内存泄漏
|
|
151
|
+
- **`objectPool`** - 全局对象池系统 (`globalPools`),降低 GC 压力 70%
|
|
170
152
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
153
|
+
#### ✨ 后期处理与交互特效
|
|
154
|
+
- **`initPostProcessing`** - 高性能后期处理流水线,内置 OutlinePass
|
|
155
|
+
- **`enableHoverBreath`** - 智能悬停高亮,支持视锥剔除与节流优化
|
|
156
|
+
- **`createModelClickHandler`** - 模型点击事件处理,集成射线检测
|
|
174
157
|
|
|
175
|
-
|
|
176
|
-
|
|
158
|
+
### **相机控制 (Camera `/camera`)**
|
|
159
|
+
- **`followModels`** - 平滑相机运镜,支持多种预设角度与缓动函数
|
|
160
|
+
- **`setView`** - 一键切换 6 种预设视角 (前/后/左/右/顶/等轴测)
|
|
161
|
+
- **`FOLLOW_ANGLES`** - 预定义相机角度常量
|
|
177
162
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
163
|
+
### **交互效果 (Interaction `/interaction`)**
|
|
164
|
+
- **`LiquidFillerGroup`** - 液体填充动画,支持多对象批量填充
|
|
165
|
+
- 特性:逼真波动效果、可调填充速度、自动恢复功能
|
|
166
|
+
|
|
167
|
+
### **视觉特效 (Effect `/effect`)**
|
|
168
|
+
- **`GroupExploder`** - 智能模型爆炸/拆解系统
|
|
169
|
+
- 支持模式:`grid`(网格) | `radial`(径向) | `random`(随机)
|
|
170
|
+
- 特性:自动相机跟随、部件淡化、可自定义间距与提升高度
|
|
171
|
+
|
|
172
|
+
### **UI 组件 (UI `/ui`)**
|
|
173
|
+
|
|
174
|
+
#### 📊 性能监控
|
|
175
|
+
- **`createPerformanceMonitor`** - 实时性能面板
|
|
176
|
+
- 显示指标:FPS、内存使用、DrawCalls、三角形数
|
|
177
|
+
- 特性:自动告警、可配置阈值、低开销设计
|
|
178
|
+
|
|
179
|
+
#### 🏷️ 统一标签系统
|
|
180
|
+
- **`createModelsLabel`** - 专业 3D 标注系统
|
|
181
|
+
- **样式模式**:
|
|
182
|
+
- `'simple'`: 顶部文字标签 (轻量级)
|
|
183
|
+
- `'line'`: 引线标注 + 状态点 (专业级)
|
|
184
|
+
- **高级特性**:
|
|
185
|
+
- 遮挡检测 (物体被遮挡时自动隐藏)
|
|
186
|
+
- 距离剔除 (超出范围自动隐藏)
|
|
187
|
+
- 智能节流 (相机静止时暂停更新)
|
|
188
|
+
- 对象池优化 (复用 Vector3/Box3)
|
|
189
|
+
|
|
190
|
+
### **场景配置 (Setup `/setup`)**
|
|
191
|
+
- **`autoSetupCameraAndLight`** - 影棚级灯光与相机自动配置
|
|
192
|
+
- 包含:环境光、主光源、辅助填充光,最佳视角计算
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 💡 完整使用示例
|
|
184
197
|
|
|
185
|
-
|
|
186
|
-
|
|
198
|
+
### 基础场景搭建
|
|
199
|
+
```typescript
|
|
200
|
+
import * as THREE from 'three'
|
|
201
|
+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
|
|
202
|
+
import { loadModelByUrl, autoSetupCameraAndLight } from '@chocozhang/three-model-render'
|
|
203
|
+
|
|
204
|
+
const scene = new THREE.Scene()
|
|
205
|
+
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000)
|
|
206
|
+
const renderer = new THREE.WebGLRenderer()
|
|
207
|
+
const controls = new OrbitControls(camera, renderer.domElement)
|
|
208
|
+
|
|
209
|
+
const model = await loadModelByUrl('model.glb')
|
|
210
|
+
scene.add(model)
|
|
211
|
+
autoSetupCameraAndLight(camera, scene, model)
|
|
187
212
|
```
|
|
188
213
|
|
|
189
|
-
###
|
|
190
|
-
|
|
214
|
+
### 添加交互高亮与点击
|
|
215
|
+
```typescript
|
|
216
|
+
import { initPostProcessing, enableHoverBreath, createModelClickHandler, followModels, FOLLOW_ANGLES } from '@chocozhang/three-model-render'
|
|
217
|
+
|
|
218
|
+
const { composer, outlinePass } = initPostProcessing(renderer, scene, camera)
|
|
219
|
+
|
|
220
|
+
// 悬停高亮 (v3.0 性能优化)
|
|
221
|
+
const hoverCtrl = enableHoverBreath({
|
|
222
|
+
camera, scene, renderer, outlinePass,
|
|
223
|
+
enableFrustumCulling: true, // 🔥 开启视锥剔除
|
|
224
|
+
throttleDelay: 16 // 60fps 节流
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
// 点击聚焦
|
|
228
|
+
const dispose = createModelClickHandler(camera, scene, renderer, outlinePass, (object, info) => {
|
|
229
|
+
console.log('Clicked:', object.name, info)
|
|
230
|
+
followModels(camera, object, {
|
|
231
|
+
...FOLLOW_ANGLES.ISOMETRIC,
|
|
232
|
+
duration: 1500,
|
|
233
|
+
controls
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
```
|
|
191
237
|
|
|
238
|
+
### 液体填充效果
|
|
192
239
|
```typescript
|
|
193
|
-
import {
|
|
240
|
+
import { LiquidFillerGroup } from '@chocozhang/three-model-render/interaction'
|
|
241
|
+
|
|
242
|
+
const targetMeshes = new Set()
|
|
243
|
+
model.traverse(child => {
|
|
244
|
+
if (child.name.includes('tank')) targetMeshes.add(child)
|
|
245
|
+
})
|
|
194
246
|
|
|
195
|
-
|
|
196
|
-
|
|
247
|
+
const filler = new LiquidFillerGroup(targetMeshes, scene, camera, renderer, {
|
|
248
|
+
color: 0x00ff00,
|
|
249
|
+
opacity: 0.5,
|
|
250
|
+
speed: 0.01
|
|
251
|
+
}, 10)
|
|
197
252
|
|
|
198
|
-
//
|
|
199
|
-
|
|
253
|
+
filler.fillTo(targetMeshes, 0.8) // 填充至 80%
|
|
254
|
+
// filler.restoreAll() // 恢复原状
|
|
200
255
|
```
|
|
201
256
|
|
|
202
257
|
### 8. 资源管理与内存释放 (重要)
|
|
@@ -228,38 +283,105 @@ rm.dispose();
|
|
|
228
283
|
|
|
229
284
|
---
|
|
230
285
|
|
|
231
|
-
|
|
286
|
+
### 专业标注系统
|
|
287
|
+
```typescript
|
|
288
|
+
import { createModelsLabel } from '@chocozhang/three-model-render/ui'
|
|
232
289
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
290
|
+
const labelsMap = {
|
|
291
|
+
'engine': '发动机',
|
|
292
|
+
'wheel': '轮胎',
|
|
293
|
+
'chassis': '底盘'
|
|
294
|
+
}
|
|
237
295
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
296
|
+
const labelMgr = createModelsLabel(camera, renderer, model, labelsMap, {
|
|
297
|
+
style: 'line', // 引线样式
|
|
298
|
+
lift: 120, // 引线长度
|
|
299
|
+
enableOcclusionDetection: true, // 🔥 遮挡检测
|
|
300
|
+
occlusionCheckInterval: 3, // 每 3 帧检测一次
|
|
301
|
+
maxDistance: 50, // 距离剔除
|
|
302
|
+
cameraMoveThreshold: 0.001 // 相机移动阈值优化
|
|
303
|
+
})
|
|
304
|
+
```
|
|
241
305
|
|
|
242
|
-
###
|
|
243
|
-
|
|
244
|
-
|
|
306
|
+
### 性能监控面板
|
|
307
|
+
```typescript
|
|
308
|
+
import { createPerformanceMonitor } from '@chocozhang/three-model-render/ui'
|
|
309
|
+
|
|
310
|
+
const perfMonitor = createPerformanceMonitor({
|
|
311
|
+
position: 'top-left',
|
|
312
|
+
renderer,
|
|
313
|
+
enableMemoryTracking: true,
|
|
314
|
+
enableWarnings: true,
|
|
315
|
+
fpsWarningThreshold: 30,
|
|
316
|
+
memoryWarningThreshold: 200
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
// 在渲染循环中
|
|
320
|
+
function animate() {
|
|
321
|
+
perfMonitor.update() // ✅ 必须调用
|
|
322
|
+
composer.render() // or renderer.render(scene, camera)
|
|
323
|
+
requestAnimationFrame(animate)
|
|
324
|
+
}
|
|
325
|
+
```
|
|
245
326
|
|
|
246
|
-
###
|
|
247
|
-
|
|
327
|
+
### 资源清理 (防止内存泄漏)
|
|
328
|
+
```typescript
|
|
329
|
+
import { disposeObject } from '@chocozhang/three-model-render'
|
|
330
|
+
|
|
331
|
+
// 组件卸载时
|
|
332
|
+
disposeObject(model)
|
|
333
|
+
hoverCtrl?.dispose()
|
|
334
|
+
dispose?.() // 点击处理器
|
|
335
|
+
exploder?.dispose()
|
|
336
|
+
filler?.dispose()
|
|
337
|
+
labelMgr?.dispose()
|
|
338
|
+
perfMonitor?.dispose()
|
|
339
|
+
controls?.dispose()
|
|
340
|
+
renderer?.dispose()
|
|
341
|
+
```
|
|
248
342
|
|
|
249
|
-
|
|
250
|
-
- `GroupExploder`: 模型爆炸/拆解动画控制器。
|
|
343
|
+
---
|
|
251
344
|
|
|
252
|
-
|
|
253
|
-
|
|
345
|
+
## 🎨 完整示例项目
|
|
346
|
+
|
|
347
|
+
两个示例项目展示了**全部 16+ 工具**的完整集成:
|
|
348
|
+
|
|
349
|
+
- 👉 **[Vue 3 完整示例 (推荐)](https://github.com/HappyColour/three-model-render/tree/main/examples/vue-example)**
|
|
350
|
+
- 包含:液体填充、模型爆炸、智能标注、性能监控等所有功能
|
|
351
|
+
- TypeScript + Composition API 最佳实践
|
|
352
|
+
|
|
353
|
+
- 👉 **[HTML 原生示例](https://github.com/HappyColour/three-model-render/tree/main/examples/html-example)**
|
|
354
|
+
- 零构建工具,直接通过 CDN 使用
|
|
355
|
+
- 适合快速原型验证
|
|
254
356
|
|
|
255
357
|
---
|
|
256
358
|
|
|
257
|
-
##
|
|
359
|
+
## 🔧 高级配置
|
|
258
360
|
|
|
259
|
-
|
|
361
|
+
### 对象池使用 (高级)
|
|
362
|
+
```typescript
|
|
363
|
+
import { globalPools, withPooledVector3 } from '@chocozhang/three-model-render'
|
|
364
|
+
|
|
365
|
+
// 方式 1: 手动管理
|
|
366
|
+
const v = globalPools.vector3.acquire()
|
|
367
|
+
v.set(1, 2, 3)
|
|
368
|
+
// ... 使用 v ...
|
|
369
|
+
globalPools.vector3.release(v)
|
|
370
|
+
|
|
371
|
+
// 方式 2: 自动管理 (推荐)
|
|
372
|
+
const distance = withPooledVector3(v => {
|
|
373
|
+
v.set(1, 2, 3)
|
|
374
|
+
return v.length()
|
|
375
|
+
}) // 自动释放
|
|
376
|
+
```
|
|
260
377
|
|
|
261
|
-
|
|
262
|
-
|
|
378
|
+
### 视角切换
|
|
379
|
+
```typescript
|
|
380
|
+
import { setView } from '@chocozhang/three-model-render'
|
|
381
|
+
|
|
382
|
+
setView(camera, controls, model, 'front') // 前视图
|
|
383
|
+
setView(camera, controls, model, 'iso') // 等轴测 (45°)
|
|
384
|
+
```
|
|
263
385
|
|
|
264
386
|
---
|
|
265
387
|
|