@chocozhang/three-model-render 1.0.3 → 1.0.5
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/CHANGELOG.md +39 -0
- package/README.md +134 -97
- package/dist/camera/index.d.ts +59 -36
- package/dist/camera/index.js +83 -67
- package/dist/camera/index.js.map +1 -1
- package/dist/camera/index.mjs +83 -67
- package/dist/camera/index.mjs.map +1 -1
- package/dist/core/index.d.ts +81 -28
- package/dist/core/index.js +194 -104
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +194 -105
- package/dist/core/index.mjs.map +1 -1
- package/dist/effect/index.d.ts +47 -134
- package/dist/effect/index.js +287 -288
- package/dist/effect/index.js.map +1 -1
- package/dist/effect/index.mjs +287 -288
- package/dist/effect/index.mjs.map +1 -1
- package/dist/index.d.ts +432 -349
- package/dist/index.js +1399 -1228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1395 -1229
- package/dist/index.mjs.map +1 -1
- package/dist/interaction/index.d.ts +85 -52
- package/dist/interaction/index.js +168 -142
- package/dist/interaction/index.js.map +1 -1
- package/dist/interaction/index.mjs +168 -142
- package/dist/interaction/index.mjs.map +1 -1
- package/dist/loader/index.d.ts +106 -58
- package/dist/loader/index.js +492 -454
- package/dist/loader/index.js.map +1 -1
- package/dist/loader/index.mjs +491 -455
- package/dist/loader/index.mjs.map +1 -1
- package/dist/setup/index.d.ts +26 -24
- package/dist/setup/index.js +125 -163
- package/dist/setup/index.js.map +1 -1
- package/dist/setup/index.mjs +124 -164
- package/dist/setup/index.mjs.map +1 -1
- package/dist/ui/index.d.ts +18 -7
- package/dist/ui/index.js +45 -37
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/index.mjs +45 -37
- package/dist/ui/index.mjs.map +1 -1
- package/package.json +50 -22
package/dist/effect/index.d.ts
CHANGED
|
@@ -1,141 +1,36 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* @file exploder.ts
|
|
5
|
+
* @description
|
|
6
|
+
* GroupExploder - Three.js based model explosion effect tool (Vue3 + TS Support)
|
|
5
7
|
* ----------------------------------------------------------------------
|
|
6
|
-
*
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @param camera Three.js 相机(一般为 PerspectiveCamera)
|
|
19
|
-
* @param controls OrbitControls 控件实例(必须绑定 camera)
|
|
20
|
-
*
|
|
21
|
-
* ----------------------------------------------------------------------
|
|
22
|
-
* 🔥 爆炸参数 ExplodeOptions
|
|
23
|
-
* ----------------------------------------------------------------------
|
|
24
|
-
* 所有参数均可在 explode() 调用时指定,也可设置默认值。
|
|
25
|
-
*
|
|
26
|
-
* type ArrangeMode = 'ring' | 'spiral' | 'grid' | 'radial'
|
|
27
|
-
*
|
|
28
|
-
* @param mode?: ArrangeMode
|
|
29
|
-
* 爆炸排列方式:
|
|
30
|
-
* - 'ring' 环形排列(默认)
|
|
31
|
-
* - 'spiral' 螺旋上升排列
|
|
32
|
-
* - 'grid' 平面网格排列(规则整齐)
|
|
33
|
-
* - 'radial' 从中心点向外扩散
|
|
34
|
-
*
|
|
35
|
-
* @param spacing?: number
|
|
36
|
-
* 相邻爆炸对象之间的间距(默认:2.5)
|
|
37
|
-
*
|
|
38
|
-
* @param duration?: number
|
|
39
|
-
* 爆炸动画时长(ms),原生 rAF 完成(默认:1000)
|
|
40
|
-
*
|
|
41
|
-
* @param lift?: number
|
|
42
|
-
* 爆炸对象整体抬升的高度因子,用于让爆炸看起来更立体(默认:0.6)
|
|
43
|
-
*
|
|
44
|
-
* @param cameraPadding?: number
|
|
45
|
-
* 摄像机贴合爆炸后包围球时的额外安全距离(默认:1.2)
|
|
46
|
-
*
|
|
47
|
-
* @param autoRestorePrev?: boolean
|
|
48
|
-
* 当切换模型时,是否自动 restore 上一个模型的爆炸元素(默认:true)
|
|
49
|
-
*
|
|
50
|
-
* @param dimOthers?: { enabled: boolean; opacity?: number }
|
|
51
|
-
* 非爆炸对象透明化配置:
|
|
52
|
-
* - enabled: true 开启
|
|
53
|
-
* - opacity: number 指定非爆炸对象透明度(默认:0.15)
|
|
54
|
-
*
|
|
55
|
-
* @param debug?: boolean
|
|
56
|
-
* 是否开启调试日志,输出所有内部状态(默认 false)
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* ----------------------------------------------------------------------
|
|
60
|
-
* 📌 方法说明
|
|
61
|
-
* ----------------------------------------------------------------------
|
|
62
|
-
*
|
|
63
|
-
* ◆ setMeshes(meshSet: Set<Mesh>, contextId?: string)
|
|
64
|
-
* 设置当前模型的爆炸 Mesh 集合:
|
|
65
|
-
* - 会记录 Mesh 的初始 transform
|
|
66
|
-
* - 根据 autoRestorePrev 自动还原上次爆炸
|
|
67
|
-
* - 第二个参数 contextId 可选,用于区分业务场景
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* ◆ explode(options?: ExplodeOptions)
|
|
71
|
-
* 对当前 meshSet 执行爆炸动画:
|
|
72
|
-
* - 根据 mode 生成爆炸布局
|
|
73
|
-
* - 相机先自动飞向最佳观察点
|
|
74
|
-
* - 执行 mesh 位移动画
|
|
75
|
-
* - 按需将非爆炸模型透明化
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* ◆ restore(duration?: number)
|
|
79
|
-
* 还原所有爆炸 Mesh 到爆炸前的 transform:
|
|
80
|
-
* - 支持平滑动画
|
|
81
|
-
* - 自动取消透明化
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* ◆ dispose()
|
|
85
|
-
* 移除事件监听、取消动画、清理引用(在组件销毁时调用)
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* ----------------------------------------------------------------------
|
|
89
|
-
* 🎨 排列模式说明
|
|
90
|
-
* ----------------------------------------------------------------------
|
|
91
|
-
*
|
|
92
|
-
* 1. Ring(环形)
|
|
93
|
-
* - 按圆均匀分布
|
|
94
|
-
* - spacing 控制半径
|
|
95
|
-
* - lift 控制整体抬起高度
|
|
96
|
-
*
|
|
97
|
-
* 2. Spiral(螺旋)
|
|
98
|
-
* - 在环形基础上添加高度递增(y++)
|
|
99
|
-
* - 数量大时视觉效果最强
|
|
100
|
-
*
|
|
101
|
-
* 3. Grid(网格)
|
|
102
|
-
* - 类似棋盘布局
|
|
103
|
-
* - spacing 控制网格大小
|
|
104
|
-
* - z 不变或小幅度变化
|
|
105
|
-
*
|
|
106
|
-
* 4. Radial(径向扩散)
|
|
107
|
-
* - 从中心向外 “爆炸式” 发散
|
|
108
|
-
* - 对于大型组件分解展示非常适合
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* ----------------------------------------------------------------------
|
|
112
|
-
* 📌 使用示例(业务层 Vue)
|
|
113
|
-
* ----------------------------------------------------------------------
|
|
114
|
-
*
|
|
115
|
-
* const exploder = new GroupExploder(scene, camera, controls);
|
|
116
|
-
*
|
|
117
|
-
* onMounted(() => {
|
|
118
|
-
* exploder.setMeshes(new Set([meshA, meshB, meshC]));
|
|
119
|
-
* });
|
|
120
|
-
*
|
|
121
|
-
* const triggerExplode = () => {
|
|
122
|
-
* exploder.explode({
|
|
123
|
-
* mode: 'ring',
|
|
124
|
-
* spacing: 3,
|
|
125
|
-
* duration: 1200,
|
|
126
|
-
* lift: 0.8,
|
|
127
|
-
* cameraPadding: 1.3,
|
|
128
|
-
* dimOthers: { enabled: true, opacity: 0.2 },
|
|
129
|
-
* });
|
|
130
|
-
* };
|
|
131
|
-
*
|
|
132
|
-
* const triggerRestore = () => {
|
|
133
|
-
* exploder.restore(600);
|
|
134
|
-
* };
|
|
135
|
-
*
|
|
8
|
+
* This tool is used to perform "explode / restore" animations on a set of specified Meshes:
|
|
9
|
+
* - Initialize only once (onMounted)
|
|
10
|
+
* - Supports dynamic switching of models and automatically restores the explosion state of the previous model
|
|
11
|
+
* - Supports multiple arrangement modes (ring / spiral / grid / radial)
|
|
12
|
+
* - Supports automatic transparency for non-exploded objects (dimOthers)
|
|
13
|
+
* - Supports automatic camera positioning to the best observation point
|
|
14
|
+
* - All animations use native requestAnimationFrame
|
|
15
|
+
*
|
|
16
|
+
* @best-practice
|
|
17
|
+
* - Initialize in `onMounted`.
|
|
18
|
+
* - Use `setMeshes` to update the active set of meshes to explode.
|
|
19
|
+
* - Call `explode()` to trigger the effect and `restore()` to reset.
|
|
136
20
|
*/
|
|
137
21
|
|
|
138
22
|
type ArrangeMode = 'ring' | 'spiral' | 'grid' | 'radial';
|
|
23
|
+
/**
|
|
24
|
+
* Explosion Parameters
|
|
25
|
+
* @param mode Explosion arrangement mode: 'ring' | 'spiral' | 'grid' | 'radial'
|
|
26
|
+
* @param spacing Spacing between adjacent exploded objects (default: 2.5)
|
|
27
|
+
* @param duration Animation duration in ms (default: 1000)
|
|
28
|
+
* @param lift Lift factor for exploded objects (default: 0.6)
|
|
29
|
+
* @param cameraPadding Extra safety distance for camera framing (default: 1.2)
|
|
30
|
+
* @param autoRestorePrev Whether to automatically restore the previous model's explosion when switching models (default: true)
|
|
31
|
+
* @param dimOthers Configuration for dimming non-exploded objects
|
|
32
|
+
* @param debug Enable debug logs (default: false)
|
|
33
|
+
*/
|
|
139
34
|
type ExplodeOptions = {
|
|
140
35
|
mode?: ArrangeMode;
|
|
141
36
|
spacing?: number;
|
|
@@ -165,6 +60,12 @@ declare class GroupExploder {
|
|
|
165
60
|
private isExploded;
|
|
166
61
|
private isInitialized;
|
|
167
62
|
onLog?: (s: string) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Constructor
|
|
65
|
+
* @param scene Three.js Scene instance
|
|
66
|
+
* @param camera Three.js Camera (usually PerspectiveCamera)
|
|
67
|
+
* @param controls OrbitControls instance (must be bound to camera)
|
|
68
|
+
*/
|
|
168
69
|
constructor(scene: THREE.Scene, camera: THREE.PerspectiveCamera | THREE.Camera, controls?: {
|
|
169
70
|
target?: THREE.Vector3;
|
|
170
71
|
update?: () => void;
|
|
@@ -172,10 +73,12 @@ declare class GroupExploder {
|
|
|
172
73
|
private log;
|
|
173
74
|
init(): void;
|
|
174
75
|
/**
|
|
175
|
-
*
|
|
76
|
+
* Set the current set of meshes for explosion.
|
|
176
77
|
* - Detects content-level changes even if same Set reference is used.
|
|
177
78
|
* - Preserves prevSet/stateMap to allow async restore when needed.
|
|
178
79
|
* - Ensures stateMap contains snapshots for *all meshes in the new set*.
|
|
80
|
+
* @param newSet The new set of meshes
|
|
81
|
+
* @param contextId Optional context ID to distinguish business scenarios
|
|
179
82
|
*/
|
|
180
83
|
setMeshes(newSet: Set<THREE.Mesh> | null, options?: {
|
|
181
84
|
autoRestorePrev?: boolean;
|
|
@@ -191,6 +94,11 @@ declare class GroupExploder {
|
|
|
191
94
|
* animate camera to that targetBound, then animate meshes to targets.
|
|
192
95
|
*/
|
|
193
96
|
explode(opts?: ExplodeOptions): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Restore all exploded meshes to their original transform:
|
|
99
|
+
* - Supports smooth animation
|
|
100
|
+
* - Automatically cancels transparency
|
|
101
|
+
*/
|
|
194
102
|
restore(duration?: number): Promise<void>;
|
|
195
103
|
/**
|
|
196
104
|
* restoreSet: reparent and restore transforms using provided stateMap.
|
|
@@ -205,9 +113,14 @@ declare class GroupExploder {
|
|
|
205
113
|
private computeBoundingSphereForPositionsAndMeshes;
|
|
206
114
|
private computeTargetsByMode;
|
|
207
115
|
private animateCameraToFit;
|
|
208
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Cancel all running animations
|
|
118
|
+
*/
|
|
209
119
|
private cancelAnimations;
|
|
210
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Dispose: remove listener, cancel animation, clear references
|
|
122
|
+
*/
|
|
123
|
+
dispose(): void;
|
|
211
124
|
}
|
|
212
125
|
|
|
213
126
|
export { GroupExploder };
|