@chocozhang/three-model-render 1.0.1 β 1.0.3
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 +127 -505
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
A high-performance, TypeScript-first toolkit providing 14 optimized utilities for Three.js model visualization and interaction.
|
|
6
6
|
|
|
7
|
-
[
|
|
7
|
+
> π **[Live Demo: Experience the Power](https://happycolour.github.io/)**
|
|
8
|
+
|
|
9
|
+
[](https://github.com/HappyColour/three-model-render)
|
|
8
10
|
[](./LICENSE)
|
|
9
11
|
[](https://www.typescriptlang.org/)
|
|
10
12
|
|
|
@@ -21,19 +23,12 @@ A high-performance, TypeScript-first toolkit providing 14 optimized utilities fo
|
|
|
21
23
|
|
|
22
24
|
## π¦ Installation
|
|
23
25
|
|
|
24
|
-
### Using npm
|
|
25
|
-
```bash
|
|
26
|
-
npm install three-model-render
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Using yarn
|
|
30
|
-
```bash
|
|
31
|
-
yarn add three-model-render
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Using pnpm
|
|
35
26
|
```bash
|
|
36
|
-
|
|
27
|
+
npm install @chocozhang/three-model-render
|
|
28
|
+
# OR
|
|
29
|
+
yarn add @chocozhang/three-model-render
|
|
30
|
+
# OR
|
|
31
|
+
pnpm add @chocozhang/three-model-render
|
|
37
32
|
```
|
|
38
33
|
|
|
39
34
|
**Peer Dependencies:**
|
|
@@ -43,496 +38,182 @@ npm install three@^0.160.0
|
|
|
43
38
|
|
|
44
39
|
---
|
|
45
40
|
|
|
46
|
-
## π
|
|
41
|
+
## π Best Practice Workflow
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { followModels, addChildModelLabels, enableHoverBreath } from 'three-model-render'
|
|
43
|
+
Build a professional 3D viewer following our optimized integration pattern. This workflow ensures maximum performance and visual quality.
|
|
51
44
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
easing: 'easeInOut',
|
|
55
|
-
duration: 1000
|
|
56
|
-
})
|
|
57
|
-
```
|
|
45
|
+
### 1. Core Setup & Model Loading
|
|
46
|
+
Initialize your basic Three.js scene and load your model using our optimized loader.
|
|
58
47
|
|
|
59
|
-
### Importζι (Recommended)
|
|
60
48
|
```typescript
|
|
61
|
-
|
|
62
|
-
import { followModels } from 'three-model-render/camera'
|
|
63
|
-
import { addChildModelLabels } from 'three-model-render/core'
|
|
64
|
-
import { enableHoverBreath } from '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
|
|
49
|
+
import { loadModelByUrl } from '@chocozhang/three-model-render';
|
|
84
50
|
|
|
85
|
-
|
|
86
|
-
|
|
51
|
+
// 1. Basic Three.js Setup
|
|
52
|
+
const scene = new THREE.Scene();
|
|
53
|
+
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
|
|
54
|
+
const renderer = new THREE.WebGLRenderer();
|
|
55
|
+
const controls = new OrbitControls(camera, renderer.domElement);
|
|
87
56
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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.
|
|
120
|
-
|
|
121
|
-
**Features:**
|
|
122
|
-
- β
Bounding box caching (60% performance boost)
|
|
123
|
-
- β
Pause/resume API
|
|
124
|
-
- β
Configurable update intervals
|
|
125
|
-
|
|
126
|
-
**Usage:**
|
|
127
|
-
```typescript
|
|
128
|
-
import { addChildModelLabels } from 'three-model-render/core'
|
|
129
|
-
|
|
130
|
-
const labelManager = addChildModelLabels(camera, renderer, model, {
|
|
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
|
|
57
|
+
// 2. Load Model with Progress
|
|
58
|
+
const model = await loadModelByUrl('path/to/model.glb', {
|
|
59
|
+
manager: new THREE.LoadingManager(() => console.log('Loaded'))
|
|
60
|
+
});
|
|
61
|
+
scene.add(model);
|
|
145
62
|
```
|
|
146
63
|
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
}
|
|
158
|
-
```
|
|
64
|
+
### 2. Auto-Configuration (Critical Step)
|
|
65
|
+
Automatically position the camera and setup studio-quality lighting based on the model's bounding box.
|
|
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
67
|
```typescript
|
|
173
|
-
import {
|
|
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.
|
|
68
|
+
import { autoSetupCameraAndLight } from '@chocozhang/three-model-render/setup';
|
|
196
69
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
- β
Resolution scaling for performance
|
|
200
|
-
- β
Complete lifecycle management
|
|
201
|
-
|
|
202
|
-
**Usage:**
|
|
203
|
-
```typescript
|
|
204
|
-
import { initPostProcessing } from 'three-model-render/core'
|
|
205
|
-
|
|
206
|
-
const ppManager = initPostProcessing(renderer, scene, camera, {
|
|
207
|
-
resolutionScale: 0.8, // 80% resolution for better performance
|
|
208
|
-
edgeStrength: 4,
|
|
209
|
-
visibleEdgeColor: '#ffee00'
|
|
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()
|
|
70
|
+
// Automatically calculates optimal camera distance and lighting
|
|
71
|
+
autoSetupCameraAndLight(camera, scene, model);
|
|
221
72
|
```
|
|
222
73
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
### Camera: followModels
|
|
74
|
+
### 3. Cinematic Entrance
|
|
75
|
+
Create a smooth entry animation to focus on the model.
|
|
226
76
|
|
|
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
|
|
233
|
-
|
|
234
|
-
**Usage:**
|
|
235
77
|
```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 'three-model-render/camera'
|
|
78
|
+
import { followModels, FOLLOW_ANGLES } from '@chocozhang/three-model-render';
|
|
255
79
|
|
|
256
80
|
followModels(camera, model, {
|
|
257
|
-
|
|
258
|
-
|
|
81
|
+
...FOLLOW_ANGLES.FRONT,
|
|
82
|
+
duration: 1500,
|
|
83
|
+
padding: 0.6,
|
|
84
|
+
controls,
|
|
85
|
+
easing: 'easeInOut'
|
|
86
|
+
});
|
|
259
87
|
```
|
|
260
88
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
### Camera: setView
|
|
264
|
-
|
|
265
|
-
Quick view switching with smooth animations.
|
|
89
|
+
### 4. Post-Processing & Hover Effects
|
|
90
|
+
Enable high-performance post-processing and optimized hover effects (saves 80% CPU when idle).
|
|
266
91
|
|
|
267
|
-
**Usage:**
|
|
268
92
|
```typescript
|
|
269
|
-
import {
|
|
270
|
-
|
|
271
|
-
// Programmatic view
|
|
272
|
-
await setView(camera, controls, model, 'front', {
|
|
273
|
-
easing: 'easeInOut',
|
|
274
|
-
duration: 800
|
|
275
|
-
})
|
|
93
|
+
import { initPostProcessing, enableHoverBreath } from '@chocozhang/three-model-render';
|
|
276
94
|
|
|
277
|
-
//
|
|
278
|
-
|
|
279
|
-
|
|
95
|
+
// 1. Initialize Post-Processing Manager
|
|
96
|
+
const ppManager = initPostProcessing(renderer, scene, camera, {
|
|
97
|
+
resolutionScale: 0.8, // Optimize performance
|
|
98
|
+
edgeStrength: 4,
|
|
99
|
+
visibleEdgeColor: '#ffee00'
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// 2. Enable Smart Hover Effect
|
|
103
|
+
const hoverController = enableHoverBreath({
|
|
104
|
+
camera,
|
|
105
|
+
scene,
|
|
106
|
+
renderer,
|
|
107
|
+
outlinePass: ppManager.outlinePass,
|
|
108
|
+
throttleDelay: 16, // 60fps limit
|
|
109
|
+
minStrength: 2,
|
|
110
|
+
maxStrength: 8,
|
|
111
|
+
speed: 3
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// IMPORTANT: Add composer to your animation loop
|
|
115
|
+
function animate() {
|
|
116
|
+
// ...
|
|
117
|
+
ppManager.composer.render();
|
|
118
|
+
}
|
|
280
119
|
```
|
|
281
120
|
|
|
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.
|
|
121
|
+
### 5. Interaction Handling
|
|
122
|
+
Add intelligent click handling that zooms to parts and triggers actions.
|
|
296
123
|
|
|
297
|
-
**Features:**
|
|
298
|
-
- β
Auto-format detection
|
|
299
|
-
- β
DRACO/KTX2 support (GLTF)
|
|
300
|
-
- β
Geometry optimization
|
|
301
|
-
- β
Texture downscaling
|
|
302
|
-
|
|
303
|
-
**Usage:**
|
|
304
124
|
```typescript
|
|
305
|
-
import {
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
|
125
|
+
import { createModelClickHandler } from '@chocozhang/three-model-render';
|
|
126
|
+
|
|
127
|
+
const disposeClickHandler = createModelClickHandler(
|
|
128
|
+
camera,
|
|
129
|
+
scene,
|
|
130
|
+
renderer,
|
|
131
|
+
ppManager.outlinePass,
|
|
132
|
+
(object, info) => {
|
|
133
|
+
console.log('Clicked:', info);
|
|
134
|
+
|
|
135
|
+
// Zoom to clicked part
|
|
136
|
+
followModels(camera, object, {
|
|
137
|
+
...FOLLOW_ANGLES.ISOMETRIC,
|
|
138
|
+
duration: 1500
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 6. Advanced Effects (Explosion)
|
|
145
|
+
Add interactive mesh explosion/disassembly effects.
|
|
333
146
|
|
|
334
|
-
**Usage:**
|
|
335
147
|
```typescript
|
|
336
|
-
import {
|
|
148
|
+
import { GroupExploder } from '@chocozhang/three-model-render';
|
|
337
149
|
|
|
338
150
|
// Initialize
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
// Load with progress
|
|
342
|
-
await BlueSky.loadAsync('/sky.exr', {
|
|
343
|
-
background: true,
|
|
344
|
-
onProgress: (progress) => {
|
|
345
|
-
console.log(`Loading: ${Math.round(progress * 100)}%`)
|
|
346
|
-
},
|
|
347
|
-
onComplete: () => console.log('Loaded!'),
|
|
348
|
-
onError: (err) => console.error(err)
|
|
349
|
-
})
|
|
350
|
-
|
|
351
|
-
// Check status
|
|
352
|
-
BlueSky.isLoading() // boolean
|
|
353
|
-
BlueSky.getLoadingState() // 'idle' | 'loading' | 'loaded' | 'error'
|
|
354
|
-
|
|
355
|
-
// Cancel
|
|
356
|
-
BlueSky.cancelLoad()
|
|
357
|
-
|
|
358
|
-
// Cleanup
|
|
359
|
-
BlueSky.dispose()
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
---
|
|
363
|
-
|
|
364
|
-
### UI: createModelsLabel
|
|
365
|
-
|
|
366
|
-
Create labels with connection lines and animations.
|
|
367
|
-
|
|
368
|
-
**Features:**
|
|
369
|
-
- β
Pause/resume API
|
|
370
|
-
- β
Bounding box caching
|
|
371
|
-
- β
Fade-in animations
|
|
372
|
-
|
|
373
|
-
**Usage:**
|
|
374
|
-
```typescript
|
|
375
|
-
import { createModelsLabel } from 'three-model-render/ui'
|
|
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
|
-
```
|
|
151
|
+
const exploder = new GroupExploder(scene, camera, controls);
|
|
152
|
+
exploder.init();
|
|
392
153
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
### Effect: GroupExploder
|
|
396
|
-
|
|
397
|
-
Model explosion effects with multiple arrangement modes.
|
|
398
|
-
|
|
399
|
-
**Features:**
|
|
400
|
-
- β
4 explosion modes (ring, spiral, grid, radial)
|
|
401
|
-
- β
Smooth animations
|
|
402
|
-
- β
Dim other objects
|
|
403
|
-
|
|
404
|
-
**Usage:**
|
|
405
|
-
```typescript
|
|
406
|
-
import { GroupExploder } from '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)
|
|
154
|
+
// Set Targets
|
|
155
|
+
exploder.setMeshes(targetMeshes);
|
|
414
156
|
|
|
415
157
|
// Explode
|
|
416
|
-
exploder.explode({
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
dimOthers: {
|
|
422
|
-
enabled: true,
|
|
423
|
-
opacity: 0.25
|
|
424
|
-
}
|
|
425
|
-
})
|
|
158
|
+
exploder.explode({
|
|
159
|
+
mode: 'grid',
|
|
160
|
+
spacing: 2.8,
|
|
161
|
+
dimOthers: { enabled: true, opacity: 0.1 }
|
|
162
|
+
});
|
|
426
163
|
|
|
427
164
|
// Restore
|
|
428
|
-
exploder.restore(600)
|
|
429
|
-
|
|
430
|
-
// Cleanup
|
|
431
|
-
exploder.dispose()
|
|
165
|
+
exploder.restore(600);
|
|
432
166
|
```
|
|
433
167
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
### Setup: autoSetupCameraAndLight
|
|
437
|
-
|
|
438
|
-
Automatically setup camera and lighting for a model.
|
|
168
|
+
### 7. View Control
|
|
169
|
+
Easily switch between standard views.
|
|
439
170
|
|
|
440
|
-
**Features:**
|
|
441
|
-
- β
Auto-calculate optimal position
|
|
442
|
-
- β
Multi-directional lighting
|
|
443
|
-
- β
Shadow support
|
|
444
|
-
- β
Light intensity adjustment
|
|
445
|
-
|
|
446
|
-
**Usage:**
|
|
447
171
|
```typescript
|
|
448
|
-
import {
|
|
449
|
-
|
|
450
|
-
const handle = autoSetupCameraAndLight(camera, scene, model, {
|
|
451
|
-
enableShadows: true,
|
|
452
|
-
padding: 1.2,
|
|
453
|
-
shadowMapSize: 2048,
|
|
454
|
-
renderer
|
|
455
|
-
})
|
|
172
|
+
import { setView } from '@chocozhang/three-model-render';
|
|
456
173
|
|
|
457
|
-
//
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
handle.dispose()
|
|
174
|
+
// Switch to Top View
|
|
175
|
+
setView(camera, controls, model, 'top');
|
|
176
|
+
// Switch to Isometric
|
|
177
|
+
setView(camera, controls, model, 'iso');
|
|
462
178
|
```
|
|
463
179
|
|
|
464
180
|
---
|
|
465
181
|
|
|
466
|
-
##
|
|
182
|
+
## π Module Overview
|
|
467
183
|
|
|
468
|
-
###
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
import { followModels } from 'three-model-render/camera'
|
|
473
|
-
import { addChildModelLabels } from 'three-model-render/core'
|
|
184
|
+
### **Core (`/core`)**
|
|
185
|
+
- `initPostProcessing`: Performance-optimized post-processing manager.
|
|
186
|
+
- `enableHoverBreath`: Idle-aware hover effects.
|
|
187
|
+
- `addChildModelLabels`: 3D labeling system.
|
|
474
188
|
|
|
475
|
-
|
|
189
|
+
### **Camera (`/camera`)**
|
|
190
|
+
- `followModels`: Smooth camera transitions.
|
|
191
|
+
- `setView`: Preset view switching (Top, Front, Iso, etc.).
|
|
476
192
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
})
|
|
481
|
-
|
|
482
|
-
followModels(camera, model, {
|
|
483
|
-
easing: 'easeInOut'
|
|
484
|
-
})
|
|
485
|
-
})
|
|
193
|
+
### **Loader (`/loader`)**
|
|
194
|
+
- `loadModelByUrl`: Robust model loader (GLTF, FBX, OBJ).
|
|
195
|
+
- `BlueSky`: Environment map manager.
|
|
486
196
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
})
|
|
490
|
-
</script>
|
|
491
|
-
```
|
|
197
|
+
### **Interaction (`/interaction`)**
|
|
198
|
+
- `createModelClickHandler`: Raycasting click handler.
|
|
492
199
|
|
|
493
|
-
###
|
|
494
|
-
|
|
495
|
-
import { useEffect } from 'react'
|
|
496
|
-
import { followModels } from 'three-model-render/camera'
|
|
497
|
-
import { addChildModelLabels } from '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
|
-
```
|
|
200
|
+
### **Effect (`/effect`)**
|
|
201
|
+
- `GroupExploder`: Mesh disassembly animations.
|
|
513
202
|
|
|
514
|
-
|
|
203
|
+
### **Setup (`/setup`)**
|
|
204
|
+
- `autoSetupCameraAndLight`: Instant scene configuration.
|
|
515
205
|
|
|
516
|
-
|
|
206
|
+
---
|
|
517
207
|
|
|
518
|
-
|
|
208
|
+
## π¨ HTML/Vue 3 Example
|
|
519
209
|
|
|
520
|
-
|
|
521
|
-
import type {
|
|
522
|
-
LabelManager,
|
|
523
|
-
LabelOptions,
|
|
524
|
-
HoverController,
|
|
525
|
-
PostProcessingManager,
|
|
526
|
-
FollowOptions,
|
|
527
|
-
ExplodeOptions
|
|
528
|
-
} from 'three-model-render'
|
|
529
|
-
```
|
|
210
|
+
For a complete, deployable HTML/Vue 3 example demonstrating all these features, check `examples/html-best-practice/`.
|
|
530
211
|
|
|
531
212
|
---
|
|
532
213
|
|
|
533
|
-
##
|
|
214
|
+
## βοΈ TypeScript Support
|
|
534
215
|
|
|
535
|
-
|
|
216
|
+
Full TypeScript definitions included. Ensure your `tsconfig.json` matches:
|
|
536
217
|
```json
|
|
537
218
|
{
|
|
538
219
|
"compilerOptions": {
|
|
@@ -545,65 +226,6 @@ import type {
|
|
|
545
226
|
|
|
546
227
|
---
|
|
547
228
|
|
|
548
|
-
## π Performance
|
|
549
|
-
|
|
550
|
-
### Optimization Results
|
|
551
|
-
- **CPU Usage**: β¬οΈ 55% reduction
|
|
552
|
-
- **Memory Usage**: β¬οΈ 33% reduction
|
|
553
|
-
- **Idle Performance**: β¬οΈ 80% CPU when inactive
|
|
554
|
-
|
|
555
|
-
### Benchmarks
|
|
556
|
-
| Utility | Before | After | Improvement |
|
|
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% |
|
|
562
|
-
|
|
563
|
-
---
|
|
564
|
-
|
|
565
|
-
## π¦ Build and Publish
|
|
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
229
|
## π License
|
|
591
230
|
|
|
592
231
|
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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chocozhang/three-model-render",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Professional Three.js model visualization and interaction toolkit with 14 high-performance utilities",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -68,11 +68,11 @@
|
|
|
68
68
|
"typescript",
|
|
69
69
|
"performance"
|
|
70
70
|
],
|
|
71
|
-
"author": "
|
|
71
|
+
"author": "Danny Zhang <happyelement.danny@gmail.com>",
|
|
72
72
|
"license": "MIT",
|
|
73
73
|
"repository": {
|
|
74
74
|
"type": "git",
|
|
75
|
-
"url": "https://github.com/
|
|
75
|
+
"url": "https://github.com/HappyColour/three-model-render.git"
|
|
76
76
|
},
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|