diff --git a/packages/webgal/package.json b/packages/webgal/package.json index 4790dffa4..b7d16f4fd 100644 --- a/packages/webgal/package.json +++ b/packages/webgal/package.json @@ -24,7 +24,7 @@ "mitt": "^3.0.0", "modern-css-reset": "^1.4.0", "pixi-filters": "^4.2.0", - "pixi-live2d-display-webgal": "^0.5.16", + "pixi-live2d-display-webgal": "^0.5.19", "pixi.js": "^6.3.0", "popmotion": "^11.0.5", "react": "^17.0.2", diff --git a/packages/webgal/src/Core/live2DCore.ts b/packages/webgal/src/Core/live2DCore.ts index 50280b9c7..110197658 100644 --- a/packages/webgal/src/Core/live2DCore.ts +++ b/packages/webgal/src/Core/live2DCore.ts @@ -38,6 +38,7 @@ export class Live2DCore { public Config: any; public createCubism2Texture?: (texture: Texture) => Texture; + public reserveCoreMemory?: (size: number) => void; // 临时记录未初始化前的数据 // 旧版表情混合模式 @@ -52,6 +53,18 @@ export class Live2DCore { } } + // CubismCore预留堆内存容量,单位MB;PLDW的对应API的单位是byte + private _cubismMemoryReservedSize = 32 + public get CubismMemoryReservedSize() { + return this._cubismMemoryReservedSize; + } + public set CubismMemoryReservedSize(size: number) { + this._cubismMemoryReservedSize = size; + if (this.isAvailable && this.reserveCoreMemory) { + this.reserveCoreMemory(this.CubismMemoryReservedSize * 1024 * 1024); + } + } + public constructor() { this.ready = this.initLive2D(); } @@ -65,17 +78,27 @@ export class Live2DCore { console.warn('live2d plugin load failed'); return; } - const { Live2DModel, SoundManager, config, Live2DLoader, ModelSettings, createCubism2Texture } = await import( - 'pixi-live2d-display-webgal' - ); + const { + Live2DModel, + SoundManager, + config, + Live2DLoader, + ModelSettings, + createCubism2Texture, + reserveCoreMemory, + } = await import('pixi-live2d-display-webgal'); installLive2dAssetCache({ Live2DLoader, ModelSettings }); this.Live2DModel = Live2DModel; this.SoundManager = SoundManager; this.Config = config; this.isAvailable = true; this.createCubism2Texture = createCubism2Texture; + this.reserveCoreMemory = reserveCoreMemory; console.log('Live2D plugin load success'); this.initConfig(); + if (this.reserveCoreMemory) { + this.reserveCoreMemory(this.CubismMemoryReservedSize * 1024 * 1024); + } }) .catch((error) => { this.isAvailable = false; diff --git a/packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts b/packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts index 299e34218..5e8510955 100644 --- a/packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts +++ b/packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts @@ -67,6 +67,11 @@ export const infoFetcher = (url: string): Promise => { const appId = String(res); WebGAL.steam.initialize(appId); } + if (command === 'Cubism_Memory_Reserved_Size_MB') { + if (typeof res === 'number') { + Live2D.CubismMemoryReservedSize = res; + } + } } } }); diff --git a/yarn.lock b/yarn.lock index fc2d5369d..6889b121e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4993,10 +4993,10 @@ pixi-filters@^4.2.0: "@pixi/filter-twist" "4.2.0" "@pixi/filter-zoom-blur" "4.2.0" -pixi-live2d-display-webgal@^0.5.16: - version "0.5.16" - resolved "https://registry.yarnpkg.com/pixi-live2d-display-webgal/-/pixi-live2d-display-webgal-0.5.16.tgz#eddc6a4a478f9fef51fce942d0a21faccc2a7074" - integrity sha512-dKKWLHRdC70FUGyo10R0oNtB0fH4q1sCmJxFr3DhHDlUI+rPtsCiGag5PJ8yF6KG9HX+rUpe6R2GrvuHk3N5PA== +pixi-live2d-display-webgal@^0.5.19: + version "0.5.19" + resolved "https://registry.yarnpkg.com/pixi-live2d-display-webgal/-/pixi-live2d-display-webgal-0.5.19.tgz#3bec5c75b55477ab6896d72bceaa2ae139ed1224" + integrity sha512-486kQpM4O0wpxKaQUTefSI46xmTGe1GbSNsCv7Fs4+2isvTSBB3frbTIEgVOSaU2uH8MyfN/WqE50Q3+9j5zwA== dependencies: gh-pages "^4.0.0"