@seayoo-web/pixi-live2d 0.0.6 → 0.0.8
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 +12 -15
- package/package.json +1 -1
- package/types/index.d.ts +5 -1
package/dist/index.js
CHANGED
|
@@ -21666,17 +21666,27 @@ 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.
|
|
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);
|
|
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 = this.options.interactive || !0, this.model.on("pointertap", () => {
|
|
21676
|
+
this.model && (this.model.interactive = this.options.interactive || !0, this.options.interactive === !1 && this.lockHeadAngle(), this.model.on("pointertap", () => {
|
|
21677
21677
|
this.options.enableTapBody !== !1 && this.model?.motion("TapBody");
|
|
21678
21678
|
}));
|
|
21679
21679
|
}
|
|
21680
|
+
/**
|
|
21681
|
+
* 锁定头部角度参数,防止 motion 驱动头部晃动
|
|
21682
|
+
* 在 ticker 里 motion 更新之后强制覆盖为 0
|
|
21683
|
+
*/
|
|
21684
|
+
lockHeadAngle() {
|
|
21685
|
+
if (!this.model) return;
|
|
21686
|
+
const e = this.model.internalModel;
|
|
21687
|
+
e.updateNaturalMovements = () => {
|
|
21688
|
+
};
|
|
21689
|
+
}
|
|
21680
21690
|
/** 窗口大小改变的处理函数 */
|
|
21681
21691
|
handleResize = () => {
|
|
21682
21692
|
this.resize();
|
|
@@ -21771,19 +21781,6 @@ class Th {
|
|
|
21771
21781
|
destroy() {
|
|
21772
21782
|
this.options.autoResize !== !1 && window.removeEventListener("resize", this.handleResize), this.app.destroy(!0);
|
|
21773
21783
|
}
|
|
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
|
-
}
|
|
21787
21784
|
}
|
|
21788
21785
|
Th.loadCubismCore();
|
|
21789
21786
|
function JT(t) {
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -58,6 +58,11 @@ export declare class Live2DViewer {
|
|
|
58
58
|
private init;
|
|
59
59
|
/** 设置点击交互 */
|
|
60
60
|
private setupInteraction;
|
|
61
|
+
/**
|
|
62
|
+
* 锁定头部角度参数,防止 motion 驱动头部晃动
|
|
63
|
+
* 在 ticker 里 motion 更新之后强制覆盖为 0
|
|
64
|
+
*/
|
|
65
|
+
lockHeadAngle(): void;
|
|
61
66
|
/** 窗口大小改变的处理函数 */
|
|
62
67
|
private handleResize;
|
|
63
68
|
/** 重新计算布局和缩放 */
|
|
@@ -98,5 +103,4 @@ export declare class Live2DViewer {
|
|
|
98
103
|
loop(startTime?: number): () => void;
|
|
99
104
|
/** 销毁实例,清理资源和监听器 */
|
|
100
105
|
destroy(): void;
|
|
101
|
-
private startManualEyeBlink;
|
|
102
106
|
}
|