@seayoo-web/pixi-live2d 0.0.3 → 0.0.6
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/dist/index.js +17 -3
- package/package.json +1 -1
- package/types/index.d.ts +7 -1
package/dist/index.js
CHANGED
|
@@ -21666,15 +21666,15 @@ class Th {
|
|
|
21666
21666
|
/** 初始化模型 */
|
|
21667
21667
|
async init() {
|
|
21668
21668
|
try {
|
|
21669
|
-
await Th.loadCubismCore(this.options.cubismCoreUrl), this.model = await hp.from(this.options.modelPath), this.app.stage.addChild(this.model), this.resize(), this.setupInteraction(), this.options.onModelLoaded?.(this.model);
|
|
21669
|
+
await Th.loadCubismCore(this.options.cubismCoreUrl), this.model = await hp.from(this.options.modelPath), this.app.stage.addChild(this.model), this.resize(), this.setupInteraction(), this.startManualEyeBlink(), this.options.onModelLoaded?.(this.model);
|
|
21670
21670
|
} catch (e) {
|
|
21671
21671
|
console.error("Failed to initialize Live2D:", e), this.options.onModelError?.(JT(e));
|
|
21672
21672
|
}
|
|
21673
21673
|
}
|
|
21674
21674
|
/** 设置点击交互 */
|
|
21675
21675
|
setupInteraction() {
|
|
21676
|
-
this.model && (this.model.interactive = !0, this.model.on("pointertap", () => {
|
|
21677
|
-
this.model?.motion("TapBody");
|
|
21676
|
+
this.model && (this.model.interactive = this.options.interactive || !0, this.model.on("pointertap", () => {
|
|
21677
|
+
this.options.enableTapBody !== !1 && this.model?.motion("TapBody");
|
|
21678
21678
|
}));
|
|
21679
21679
|
}
|
|
21680
21680
|
/** 窗口大小改变的处理函数 */
|
|
@@ -21771,12 +21771,26 @@ class Th {
|
|
|
21771
21771
|
destroy() {
|
|
21772
21772
|
this.options.autoResize !== !1 && window.removeEventListener("resize", this.handleResize), this.app.destroy(!0);
|
|
21773
21773
|
}
|
|
21774
|
+
startManualEyeBlink() {
|
|
21775
|
+
if (!this.model) return;
|
|
21776
|
+
let e = 0, r = 3, i = "open", n = 0;
|
|
21777
|
+
this.app.ticker.add((s) => {
|
|
21778
|
+
if (!this.model) return;
|
|
21779
|
+
const a = s / 60;
|
|
21780
|
+
e += a;
|
|
21781
|
+
let o = 1;
|
|
21782
|
+
i === "open" ? e >= r && (i = "closing", n = 0) : i === "closing" ? (n += a / 0.1, o = 1 - n, n >= 1 && (i = "closed", n = 0)) : i === "closed" ? (n += a / 0.05, o = 0, n >= 1 && (i = "opening", n = 0)) : i === "opening" && (n += a / 0.1, o = n, n >= 1 && (i = "open", e = 0, r = 2.5 + Math.random() * 2.5)), o = Math.max(0, Math.min(1, o));
|
|
21783
|
+
const h = this.model.internalModel.coreModel;
|
|
21784
|
+
h?.setParameterValueById?.("ParamEyeLOpen", o), h?.setParameterValueById?.("ParamEyeROpen", o);
|
|
21785
|
+
});
|
|
21786
|
+
}
|
|
21774
21787
|
}
|
|
21775
21788
|
Th.loadCubismCore();
|
|
21776
21789
|
function JT(t) {
|
|
21777
21790
|
return t instanceof Error ? t : new Error(String(t));
|
|
21778
21791
|
}
|
|
21779
21792
|
export {
|
|
21793
|
+
hp as Live2DModel,
|
|
21780
21794
|
Th as Live2DViewer,
|
|
21781
21795
|
Oa as MotionPriority
|
|
21782
21796
|
};
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -23,12 +23,17 @@ export interface Live2DViewerOptions {
|
|
|
23
23
|
designHeight?: number;
|
|
24
24
|
/** Cubism Core 库的加载 URL */
|
|
25
25
|
cubismCoreUrl?: string;
|
|
26
|
+
/** 是否响应鼠标/触摸移动进行跟随动画,默认为 true */
|
|
27
|
+
interactive?: boolean;
|
|
28
|
+
/** 是否响应点击事件触发 TapBody 动作,默认为 true */
|
|
29
|
+
enableTapBody?: boolean;
|
|
26
30
|
/** 模型加载完成后的回调函数 */
|
|
27
31
|
onModelLoaded?: (model: Live2DModel<InternalModel>) => void;
|
|
28
32
|
/** 模型加载失败的回调函数 */
|
|
29
33
|
onModelError?: (error: Error) => void;
|
|
30
34
|
}
|
|
31
|
-
export { MotionPriority };
|
|
35
|
+
export { MotionPriority } from "pixi-live2d-display/cubism4";
|
|
36
|
+
export { Live2DModel } from "pixi-live2d-display/cubism4";
|
|
32
37
|
export declare class Live2DViewer {
|
|
33
38
|
/** 引擎加载状态 Promise,用于确保全局只加载一次 Core 库 */
|
|
34
39
|
private static coreLoadingPromise;
|
|
@@ -93,4 +98,5 @@ export declare class Live2DViewer {
|
|
|
93
98
|
loop(startTime?: number): () => void;
|
|
94
99
|
/** 销毁实例,清理资源和监听器 */
|
|
95
100
|
destroy(): void;
|
|
101
|
+
private startManualEyeBlink;
|
|
96
102
|
}
|