sa2kit 1.1.0 → 1.2.0

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.
@@ -1,346 +1,255 @@
1
+ import { Vector3 } from 'three';
1
2
  import React__default from 'react';
2
3
 
3
- /**
4
- * MMD 资源配置
5
- */
4
+ /** MMD 资源配置 */
6
5
  interface MMDResources {
7
- /** 模型路径 */
6
+ /** 模型文件路径 (.pmx/.pmd) */
8
7
  modelPath: string;
9
- /** 动作路径 */
8
+ /** 动作文件路径 (.vmd) - 可选 */
10
9
  motionPath?: string;
11
- /** 相机路径 */
10
+ /** 相机动画路径 (.vmd) - 可选 */
12
11
  cameraPath?: string;
13
- /** 音频路径 */
12
+ /** 音频文件路径 - 可选 */
14
13
  audioPath?: string;
15
- /**
16
- * 场景模型路径 (.pmx/.pmd)
17
- * 通常是静态的 3D 场景模型,如教室、舞台等
18
- */
14
+ /** 舞台/场景模型路径 (.pmx/.x) - 可选 */
19
15
  stageModelPath?: string;
20
- /**
21
- * 背景图片路径
22
- * 支持 jpg/png 等图片格式,将作为 360度背景 (Equirectangular) 或固定背景
23
- */
24
- backgroundPath?: string;
16
+ /** 附加动作文件 - 可选 */
17
+ additionalMotions?: string[];
25
18
  }
26
- /**
27
- * MMD 资源配置项(用于动态切换)
28
- */
19
+ /** 资源列表项 - 用于预设切换 */
29
20
  interface MMDResourceItem {
30
- /** 配置项 ID */
31
21
  id: string;
32
- /** 配置项名称 */
33
22
  name: string;
34
- /** 资源配置 */
35
23
  resources: MMDResources;
36
- }
37
- /**
38
- * MMD 资源选项(用于下拉框选择)
39
- */
40
- interface MMDResourceOption {
41
- /** 选项 ID */
42
- id: string;
43
- /** 选项名称 */
44
- name: string;
45
- /** 资源路径 */
46
- path: string;
47
- }
48
- /**
49
- * MMD 播放列表节点
50
- * 代表一个完整的 MMD 播放配置(模型+动作+音乐+相机+场景+背景)
51
- */
52
- interface MMDPlaylistNode {
53
- /** 节点 ID */
54
- id: string;
55
- /** 节点名称 */
56
- name: string;
57
- /** 节点描述(可选) */
24
+ thumbnail?: string;
58
25
  description?: string;
59
- /** 资源配置 */
60
- resources: MMDResources;
61
- /** 是否循环播放当前节点(默认 false) */
62
- loop?: boolean;
63
26
  }
64
- /**
65
- * MMD 播放列表配置
66
- */
67
- interface MMDPlaylistConfig {
68
- /** 播放列表 ID */
27
+ /** 资源选项 - 用于自由组合 */
28
+ interface ResourceOption {
69
29
  id: string;
70
- /** 播放列表名称 */
71
30
  name: string;
72
- /** 播放列表描述(可选) */
73
- description?: string;
74
- /** 播放节点列表 */
75
- nodes: MMDPlaylistNode[];
76
- /** 是否循环播放整个列表(默认 false) */
77
- loop?: boolean;
78
- /** 是否自动播放(默认 true) */
79
- autoPlay?: boolean;
31
+ path: string;
32
+ thumbnail?: string;
80
33
  }
81
- /**
82
- * MMD 资源选项列表(用于独立选择模型、动作、音乐、相机等)
83
- */
84
34
  interface MMDResourceOptions {
85
- /** 模型选项列表 */
86
- models?: MMDResourceOption[];
87
- /** 动作选项列表 */
88
- motions?: MMDResourceOption[];
89
- /** 音频选项列表 */
90
- audios?: MMDResourceOption[];
91
- /** 相机选项列表 */
92
- cameras?: MMDResourceOption[];
93
- /** 场景模型选项列表 */
94
- stageModels?: MMDResourceOption[];
95
- /** 背景图片选项列表 */
96
- backgrounds?: MMDResourceOption[];
35
+ models: ResourceOption[];
36
+ motions: ResourceOption[];
37
+ cameras?: ResourceOption[];
38
+ audios?: ResourceOption[];
39
+ stages?: ResourceOption[];
97
40
  }
98
- /**
99
- * MMD 舞台配置
100
- */
41
+ /** 舞台/场景配置 */
101
42
  interface MMDStage {
102
- /** 背景色 */
43
+ /** 背景颜色 */
103
44
  backgroundColor?: string;
104
- /**
105
- * 背景类型
106
- * 'color': 纯色背景 (默认)
107
- * 'image': 固定背景图片 (backgroundPath)
108
- * 'skybox': 360度全景图 (backgroundPath)
109
- * @default 'color'
110
- */
111
- backgroundType?: 'color' | 'image' | 'skybox';
45
+ /** 背景图片 URL */
46
+ backgroundImage?: string;
47
+ /** 是否启用物理模拟 (默认 true) */
48
+ enablePhysics?: boolean;
49
+ /** 物理引擎路径 (ammo.wasm.js 的路径) */
50
+ physicsPath?: string;
51
+ /** 是否启用阴影 (默认 true) */
52
+ enableShadow?: boolean;
53
+ /** 环境光强度 (默认 0.5) */
54
+ ambientLightIntensity?: number;
55
+ /** 方向光强度 (默认 0.8) */
56
+ directionalLightIntensity?: number;
112
57
  /** 相机初始位置 */
113
58
  cameraPosition?: {
114
59
  x: number;
115
60
  y: number;
116
61
  z: number;
117
- };
118
- /** 相机目标位置 */
62
+ } | Vector3;
63
+ /** 相机目标点 */
119
64
  cameraTarget?: {
120
65
  x: number;
121
66
  y: number;
122
67
  z: number;
123
- };
124
- /** 启用物理引擎 */
125
- enablePhysics?: boolean;
126
- /** 启用网格 */
127
- showGrid?: boolean;
128
- /** Ammo.js 脚本路径 */
129
- ammoPath?: string;
130
- /** Ammo WASM 文件的基础路径 */
131
- ammoWasmPath?: string;
68
+ } | Vector3;
132
69
  }
133
- /**
134
- * 基础 MMD 播放器属性(原始API)
135
- */
136
- interface MMDPlayerBaseProps {
137
- /**
138
- * URL to the PMX model file
139
- */
140
- modelUrl: string;
141
- /**
142
- * URL to the VMD motion file for the model
143
- */
144
- vmdUrl?: string;
145
- /**
146
- * URL to the VMD motion file for the camera
147
- */
148
- cameraUrl?: string;
149
- /**
150
- * URL to the audio file (wav, mp3)
151
- */
152
- audioUrl?: string;
153
- /**
154
- * Whether to enable physics simulation (requires Ammo.js)
155
- * @default true
156
- */
157
- physics?: boolean;
158
- /**
159
- * Width of the player
160
- * @default '100%'
161
- */
162
- width?: string | number;
163
- /**
164
- * Height of the player
165
- * @default '100%'
166
- */
167
- height?: string | number;
168
- /**
169
- * Callback when resources are loaded
170
- */
171
- onLoad?: () => void;
172
- /**
173
- * Callback for loading progress
174
- */
175
- onProgress?: (xhr: ProgressEvent) => void;
176
- /**
177
- * Callback for loading error
178
- */
179
- onError?: (error: unknown) => void;
70
+ /** 移动端优化配置 */
71
+ interface MobileOptimization {
72
+ /** 是否启用优化 (默认 true) */
73
+ enabled: boolean;
74
+ /** 像素比 (默认 1.0, 桌面端通常为 window.devicePixelRatio) */
75
+ pixelRatio?: number;
76
+ /** 是否强制关闭物理引擎 (默认 false) */
77
+ disablePhysics?: boolean;
78
+ /** 是否降低阴影质量 (默认 true) */
79
+ reduceShadowQuality?: boolean;
180
80
  }
181
- /**
182
- * MMD 播放列表组件属性
183
- */
184
- interface MMDPlaylistProps {
185
- /** 播放列表配置 */
186
- playlist: MMDPlaylistConfig;
81
+ /** MMDPlayerBase Ref 接口 */
82
+ interface MMDPlayerBaseRef {
83
+ /** 开始播放 */
84
+ play: () => void;
85
+ /** 暂停播放 */
86
+ pause: () => void;
87
+ /** 停止播放 (重置到开头) */
88
+ stop: () => void;
89
+ /** 跳转到指定时间 (秒) */
90
+ seek: (time: number) => void;
91
+ /** 获取当前播放时间 */
92
+ getCurrentTime: () => number;
93
+ /** 获取总时长 */
94
+ getDuration: () => number;
95
+ /** 获取播放状态 */
96
+ isPlaying: () => boolean;
97
+ /** 截图并返回 Base64 字符串 */
98
+ snapshot: () => string;
99
+ }
100
+ /** 基础播放器属性 */
101
+ interface MMDPlayerBaseProps {
102
+ /** 资源配置 */
103
+ resources: MMDResources;
187
104
  /** 舞台配置 */
188
105
  stage?: MMDStage;
189
- /** 默认播放的节点索引(默认 0) */
190
- defaultNodeIndex?: number;
191
- /** 自定义样式类名 */
106
+ /** 移动端优化配置 */
107
+ mobileOptimization?: MobileOptimization;
108
+ /** 播放控制 */
109
+ autoPlay?: boolean;
110
+ loop?: boolean;
111
+ volume?: number;
112
+ muted?: boolean;
113
+ /** 调试与辅助 */
114
+ showAxes?: boolean;
115
+ /** 事件回调 */
116
+ onLoad?: () => void;
117
+ onLoadProgress?: (progress: number, item: string) => void;
118
+ onError?: (error: Error) => void;
119
+ onPlay?: () => void;
120
+ onPause?: () => void;
121
+ onEnded?: () => void;
122
+ onTimeUpdate?: (time: number) => void;
123
+ /** 样式 */
192
124
  className?: string;
193
- /** 自定义样式 */
194
125
  style?: React.CSSProperties;
195
- /** 资源加载完成回调 */
196
- onLoad?: () => void;
197
- /** 资源加载错误回调 */
198
- onError?: (error: any) => void;
199
- /** 节点切换回调 */
200
- onNodeChange?: (nodeIndex: number, node: MMDPlaylistNode) => void;
201
- /** 播放列表完成回调 */
202
- onPlaylistComplete?: () => void;
203
126
  }
204
- /**
205
- * 增强版 MMD 播放器属性(支持resources和stage配置)
206
- */
207
- interface MMDPlayerEnhancedProps {
208
- /** MMD资源配置(单个) */
127
+ /** 增强播放器属性 */
128
+ interface MMDPlayerEnhancedProps extends Omit<MMDPlayerBaseProps, 'resources'> {
129
+ /** 单一资源模式 */
209
130
  resources?: MMDResources;
210
- /** MMD资源配置列表(用于动态切换),如果提供则显示设置按钮 */
131
+ /** 列表模式资源 */
211
132
  resourcesList?: MMDResourceItem[];
212
- /** 默认选中的资源ID(当使用 resourcesList 时) */
213
- defaultResourceId?: string;
214
- /** MMD资源选项列表(用于下拉框独立选择),如果提供则显示设置按钮 */
133
+ /** 自由组合模式选项 */
215
134
  resourceOptions?: MMDResourceOptions;
216
- /** 默认选中的资源(当使用 resourceOptions 时) */
135
+ /** 列表模式下的默认 ID */
136
+ defaultResourceId?: string;
137
+ /** 自由组合模式下的默认选择 */
217
138
  defaultSelection?: {
218
139
  modelId?: string;
219
140
  motionId?: string;
220
- audioId?: string;
221
141
  cameraId?: string;
222
- stageModelId?: string;
223
- backgroundId?: string;
142
+ audioId?: string;
143
+ stageId?: string;
224
144
  };
145
+ /** 是否显示调试信息面板 */
146
+ showDebugInfo?: boolean;
147
+ }
148
+ /** 播放列表节点 */
149
+ interface MMDPlaylistNode {
150
+ id: string;
151
+ name: string;
152
+ resources: MMDResources;
153
+ /** 该节点是否循环播放 */
154
+ loop?: boolean;
155
+ /** 预计时长(秒)- 用于进度计算 */
156
+ duration?: number;
157
+ /** 缩略图 */
158
+ thumbnail?: string;
159
+ }
160
+ /** 播放列表配置 */
161
+ interface MMDPlaylistConfig {
162
+ id: string;
163
+ name: string;
164
+ nodes: MMDPlaylistNode[];
165
+ /** 整个播放列表是否循环 */
166
+ loop?: boolean;
167
+ /** 预加载策略
168
+ * - 'none': 不预加载 (默认)
169
+ * - 'next': 预加载下一个节点
170
+ * - 'all': 预加载所有节点
171
+ */
172
+ preload?: 'none' | 'next' | 'all';
173
+ /** 是否自动播放 */
174
+ autoPlay?: boolean;
175
+ }
176
+ /** 播放列表组件属性 */
177
+ interface MMDPlaylistProps {
178
+ /** 播放列表配置 */
179
+ playlist: MMDPlaylistConfig;
225
180
  /** 舞台配置 */
226
181
  stage?: MMDStage;
227
- /** 自动播放 */
228
- autoPlay?: boolean;
229
- /** 循环播放 */
230
- loop?: boolean;
231
- /** 自定义类名 */
182
+ /** 移动端优化配置 */
183
+ mobileOptimization?: MobileOptimization;
184
+ /** 事件回调 */
185
+ onNodeChange?: (node: MMDPlaylistNode, index: number) => void;
186
+ onPlaylistComplete?: () => void;
187
+ onError?: (error: Error) => void;
188
+ /** 是否显示调试信息面板 */
189
+ showDebugInfo?: boolean;
190
+ /** 样式 */
232
191
  className?: string;
233
- /** 自定义样式 */
234
192
  style?: React.CSSProperties;
235
- /** 加载完成回调 */
236
- onLoad?: () => void;
237
- /** 错误回调 */
238
- onError?: (error: Error) => void;
239
- /** 资源切换回调(resourcesList 模式) */
240
- onResourceChange?: (resourceId: string) => void;
241
- /** 资源选择回调(resourceOptions 模式) */
242
- onSelectionChange?: (selection: {
243
- modelId?: string;
244
- motionId?: string;
245
- audioId?: string;
246
- cameraId?: string;
247
- stageModelId?: string;
248
- backgroundId?: string;
249
- }) => void;
250
- /** 音频播放结束回调 */
251
- onAudioEnded?: () => void;
252
- /** 动画播放结束回调(当没有音频或音频先结束时) */
253
- onAnimationEnded?: () => void;
254
193
  }
255
- /**
256
- * MMD 播放器属性(联合类型)
257
- */
258
- type MMDPlayerProps = MMDPlayerBaseProps | MMDPlayerEnhancedProps;
259
194
 
260
- declare const MMDPlayerBase: React__default.FC<MMDPlayerBaseProps>;
195
+ declare const MMDPlayerBase: React__default.ForwardRefExoticComponent<MMDPlayerBaseProps & React__default.RefAttributes<MMDPlayerBaseRef>>;
261
196
 
262
- /**
263
- * 增强版 MMD 播放器组件
264
- * 支持通过 resources 和 stage 配置快速使用
265
- * 所有资源均从 public 目录加载,无需额外配置
266
- */
267
- declare const MMDPlayerEnhanced: React__default.ForwardRefExoticComponent<MMDPlayerEnhancedProps & React__default.RefAttributes<any>>;
197
+ declare const MMDPlayerEnhanced: React__default.FC<MMDPlayerEnhancedProps>;
268
198
 
269
199
  /**
270
- * MMD 播放列表组件(预加载版本)
271
- *
272
- * 在初始化时预加载所有节点的资源,切换时无需加载页面,实现无缝切换
200
+ * MMDPlaylist - 播放列表管理器
273
201
  *
274
- * @example
275
- * ```tsx
276
- * const playlist = {
277
- * id: 'my-playlist',
278
- * name: '我的播放列表',
279
- * nodes: [
280
- * {
281
- * id: 'node1',
282
- * name: '第一个节点',
283
- * resources: { modelPath: '...', motionPath: '...', audioPath: '...' }
284
- * },
285
- * {
286
- * id: 'node2',
287
- * name: '第二个节点',
288
- * resources: { modelPath: '...', motionPath: '...', audioPath: '...' }
289
- * }
290
- * ],
291
- * loop: true,
292
- * autoPlay: true
293
- * };
294
- *
295
- * <MMDPlaylist playlist={playlist} />
296
- * ```
202
+ * 核心功能:
203
+ * - 管理多个播放节点
204
+ * - 实现无缝切换(通过 key 变化触发组件重新挂载)
205
+ * - 预加载策略 (none / next / all)
206
+ * - 智能内存回收
207
+ * - 播放列表 UI
297
208
  */
298
209
  declare const MMDPlaylist: React__default.FC<MMDPlaylistProps>;
299
210
 
300
- interface AmmoConfig {
301
- /** Ammo.js 脚本路径(例如:'/mikutalking/libs/ammo.wasm.js') */
302
- scriptPath: string;
303
- /** Ammo WASM 文件的基础路径(例如:'/mikutalking/libs/') */
304
- wasmBasePath: string;
211
+ interface MMDPlayerEnhancedDebugInfoProps {
212
+ isPlaying: boolean;
213
+ isLooping: boolean;
214
+ isFullscreen: boolean;
215
+ showAxes: boolean;
216
+ isLoading: boolean;
217
+ currentResourceId?: string;
218
+ currentResourceName?: string;
219
+ mode: 'single' | 'list' | 'options';
220
+ totalResources: number;
305
221
  }
306
- /**
307
- * 加载 Ammo.js 物理引擎
308
- * @param config Ammo.js 配置,包含脚本路径和 WASM 基础路径
309
- */
310
- declare const loadAmmo: (config: AmmoConfig) => Promise<void>;
222
+ declare const MMDPlayerEnhancedDebugInfo: React__default.FC<MMDPlayerEnhancedDebugInfoProps>;
311
223
 
312
- /**
313
- * MMD 预设配置
314
- */
315
- interface MMDPreset {
316
- /** 预设ID */
317
- id: string;
318
- /** 预设名称 */
319
- name: string;
320
- /** 预设简介 */
321
- summary: string;
322
- /** 预设标签 */
323
- badges?: string[];
324
- /** 资源配置 */
325
- resources: MMDResources;
326
- /** 舞台配置 */
327
- stage?: MMDStage;
224
+ interface MMDPlaylistDebugInfoProps {
225
+ playlistName: string;
226
+ currentIndex: number;
227
+ currentNode: MMDPlaylistNode;
228
+ totalNodes: number;
229
+ isPlaying: boolean;
230
+ isListLooping: boolean;
231
+ isNodeLooping: boolean;
232
+ preloadStrategy: 'none' | 'next' | 'all';
233
+ isLoading: boolean;
234
+ isFullscreen: boolean;
235
+ showAxes: boolean;
236
+ preloadedNodes: number[];
328
237
  }
238
+ declare const MMDPlaylistDebugInfo: React__default.FC<MMDPlaylistDebugInfoProps>;
239
+
329
240
  /**
330
- * 默认预设 - 仅模型
331
- */
332
- declare const defaultMMDPreset: MMDPreset;
333
- /**
334
- * 完整动画预设 - 模型+动作+相机+音频
335
- */
336
- declare const catchTheWavePreset: MMDPreset;
337
- /**
338
- * 简单模型预设
241
+ * Ammo.js 加载器
242
+ * 用于异步加载 Ammo.js 物理引擎 (WASM 版本)
339
243
  */
340
- declare const simpleModelPreset: MMDPreset;
244
+ declare global {
245
+ interface Window {
246
+ Ammo: any;
247
+ }
248
+ }
341
249
  /**
342
- * 所有可用的预设
250
+ * 加载 Ammo.js
251
+ * @param path Ammo.js (WASM wrapper) 的路径,默认为 '/libs/ammo.wasm.js'
343
252
  */
344
- declare const availableMMDPresets: MMDPreset[];
253
+ declare const loadAmmo: (path?: string) => Promise<any>;
345
254
 
346
- export { type AmmoConfig, MMDPlayerBase, type MMDPlayerBaseProps, MMDPlayerEnhanced, type MMDPlayerEnhancedProps, type MMDPlayerProps, MMDPlaylist, type MMDPlaylistConfig, type MMDPlaylistNode, type MMDPlaylistProps, type MMDPreset, type MMDResourceItem, type MMDResourceOption, type MMDResourceOptions, type MMDResources, type MMDStage, availableMMDPresets, catchTheWavePreset, defaultMMDPreset, loadAmmo, simpleModelPreset };
255
+ export { MMDPlayerBase, type MMDPlayerBaseProps, type MMDPlayerBaseRef, MMDPlayerEnhanced, MMDPlayerEnhancedDebugInfo, type MMDPlayerEnhancedProps, MMDPlaylist, type MMDPlaylistConfig, MMDPlaylistDebugInfo, type MMDPlaylistNode, type MMDPlaylistProps, type MMDResourceItem, type MMDResourceOptions, type MMDResources, type MMDStage, type MobileOptimization, type ResourceOption, loadAmmo };