diff --git a/Chat/lib/lira-avatar/liraCore.ts b/Chat/lib/lira-avatar/liraCore.ts index 3ba5fbe4..6ff06529 100644 --- a/Chat/lib/lira-avatar/liraCore.ts +++ b/Chat/lib/lira-avatar/liraCore.ts @@ -71,7 +71,7 @@ export class LiraCore { // FIX: Disable Pixi auto-resize which might catch the container at 0x0 during animation // and corrupt the mask buffers. We handle resize manually via Observer. - this.app.resizeTo = null as any; + this.app.resizeTo = null; // FIX: Force immediate renderer resize to fix "Disappearing Head" (Masking) // Ensure we NEVER resize to 0x0. Use safe defaults if container is collapsing. @@ -117,13 +117,17 @@ export class LiraCore { console.log("[LiraCore] Model reused from cache."); this.model = globalModel; this.model.visible = true; + + // FIX: Ensure previous models are cleared even when reusing + this.app.stage.removeChildren(); + this.app.stage.addChild(this.model); + this.setupTicker(); return; } try { console.log(`[LiraCore] Loading Fresh Model: ${modelPath}`); - // @ts-ignore const Live2DModel = window.PIXI.live2d.Live2DModel; // MONKEY PATCH (Keep it, it's safe) @@ -143,7 +147,6 @@ export class LiraCore { this.model.autoUpdate = false; // FIX: Clear previous models to prevent duplication - // @ts-ignore this.app.stage.removeChildren(); this.app.stage.addChild(this.model); diff --git a/Chat/lib/lira-avatar/types.ts b/Chat/lib/lira-avatar/types.ts index 3eba5e89..75df9f7a 100644 --- a/Chat/lib/lira-avatar/types.ts +++ b/Chat/lib/lira-avatar/types.ts @@ -6,6 +6,7 @@ export interface Live2DModelType { y: number; width: number; height: number; + visible: boolean; scale: { x: number, y: number, set: (x: number, y?: number) => void }; anchor: { set: (x: number, y?: number) => void }; on: (event: string, callback: (hitAreas: string[]) => void) => void; @@ -36,6 +37,8 @@ export interface PixiApp { view: HTMLCanvasElement; stage: { addChild: (child: any) => void; + removeChild: (child: any) => void; + removeChildren: (beginIndex?: number, endIndex?: number) => void; }; screen: { width: number; @@ -44,10 +47,16 @@ export interface PixiApp { ticker: { add: (fn: (delta: number) => void) => void; remove: (fn: (delta: number) => void) => void; + stop: () => void; + start: () => void; elapsedMS: number; }; + start: () => void; + stop: () => void; + resizeTo: HTMLElement | null; destroy: (removeView?: boolean, stageOptions?: any) => void; renderer: { + resize: (width: number, height: number) => void; plugins: { interaction: { on: (event: string, fn: (e: any) => void) => void; @@ -61,8 +70,12 @@ declare global { interface Window { PIXI: { Application: new (options: any) => PixiApp; + BLEND_MODES: { + NORMAL: any; + }; live2d: { Live2DModel: { + prototype: any; from: (url: string, options?: any) => Promise; registerTicker: (ticker: any) => void; }; diff --git a/LiraCompanion/lib/lira-avatar/liraCore.ts b/LiraCompanion/lib/lira-avatar/liraCore.ts index 8e94453f..8be17747 100644 --- a/LiraCompanion/lib/lira-avatar/liraCore.ts +++ b/LiraCompanion/lib/lira-avatar/liraCore.ts @@ -78,7 +78,7 @@ export class LiraCore { // FIX: Disable Pixi auto-resize which might catch the container at 0x0 during animation // and corrupt the mask buffers. We handle resize manually via Observer. - this.app.resizeTo = null as any; + this.app.resizeTo = null; // FIX: Force immediate renderer resize to fix "Disappearing Head" (Masking) // Ensure we NEVER resize to 0x0. Use safe defaults if container is collapsing. @@ -124,13 +124,17 @@ export class LiraCore { console.log("[LiraCore] Model reused from cache."); this.model = globalModel; this.model.visible = true; + + // FIX: Ensure previous models are cleared even when reusing + this.app.stage.removeChildren(); + this.app.stage.addChild(this.model); + this.setupTicker(); return; } try { console.log(`[LiraCore] Loading Fresh Model: ${modelPath}`); - // @ts-ignore const Live2DModel = window.PIXI.live2d.Live2DModel; // MONKEY PATCH (Keep it, it's safe) @@ -150,7 +154,6 @@ export class LiraCore { this.model.autoUpdate = false; // FIX: Clear previous models to prevent duplication - // @ts-ignore this.app.stage.removeChildren(); this.app.stage.addChild(this.model); diff --git a/LiraCompanion/lib/lira-avatar/types.ts b/LiraCompanion/lib/lira-avatar/types.ts index 3eba5e89..75df9f7a 100644 --- a/LiraCompanion/lib/lira-avatar/types.ts +++ b/LiraCompanion/lib/lira-avatar/types.ts @@ -6,6 +6,7 @@ export interface Live2DModelType { y: number; width: number; height: number; + visible: boolean; scale: { x: number, y: number, set: (x: number, y?: number) => void }; anchor: { set: (x: number, y?: number) => void }; on: (event: string, callback: (hitAreas: string[]) => void) => void; @@ -36,6 +37,8 @@ export interface PixiApp { view: HTMLCanvasElement; stage: { addChild: (child: any) => void; + removeChild: (child: any) => void; + removeChildren: (beginIndex?: number, endIndex?: number) => void; }; screen: { width: number; @@ -44,10 +47,16 @@ export interface PixiApp { ticker: { add: (fn: (delta: number) => void) => void; remove: (fn: (delta: number) => void) => void; + stop: () => void; + start: () => void; elapsedMS: number; }; + start: () => void; + stop: () => void; + resizeTo: HTMLElement | null; destroy: (removeView?: boolean, stageOptions?: any) => void; renderer: { + resize: (width: number, height: number) => void; plugins: { interaction: { on: (event: string, fn: (e: any) => void) => void; @@ -61,8 +70,12 @@ declare global { interface Window { PIXI: { Application: new (options: any) => PixiApp; + BLEND_MODES: { + NORMAL: any; + }; live2d: { Live2DModel: { + prototype: any; from: (url: string, options?: any) => Promise; registerTicker: (ticker: any) => void; }; diff --git a/LiraCompanion/liraLive2D.js b/LiraCompanion/liraLive2D.js index d9eaeed8..71e465f7 100644 --- a/LiraCompanion/liraLive2D.js +++ b/LiraCompanion/liraLive2D.js @@ -48,6 +48,7 @@ class LiraLive2D { this.model.y = 50; // Add to stage + this.app.stage.removeChildren(); this.app.stage.addChild(this.model); console.log('[Live2D] Model loaded successfully!');