@@ -38,6 +38,7 @@ export class Live2DCore {
3838 public Config : any ;
3939
4040 public createCubism2Texture ?: ( texture : Texture ) => Texture ;
41+ public reserveCoreMemory ?: ( size : number ) => void ;
4142
4243 // 临时记录未初始化前的数据
4344 // 旧版表情混合模式
@@ -52,6 +53,18 @@ export class Live2DCore {
5253 }
5354 }
5455
56+ // CubismCore预留堆内存容量,单位MB;PLDW的对应API的单位是byte
57+ private _cubismMemoryReservedSize = 32
58+ public get CubismMemoryReservedSize ( ) {
59+ return this . _cubismMemoryReservedSize ;
60+ }
61+ public set CubismMemoryReservedSize ( size : number ) {
62+ this . _cubismMemoryReservedSize = size ;
63+ if ( this . isAvailable && this . reserveCoreMemory ) {
64+ this . reserveCoreMemory ( this . CubismMemoryReservedSize * 1024 * 1024 ) ;
65+ }
66+ }
67+
5568 public constructor ( ) {
5669 this . ready = this . initLive2D ( ) ;
5770 }
@@ -65,17 +78,27 @@ export class Live2DCore {
6578 console . warn ( 'live2d plugin load failed' ) ;
6679 return ;
6780 }
68- const { Live2DModel, SoundManager, config, Live2DLoader, ModelSettings, createCubism2Texture } = await import (
69- 'pixi-live2d-display-webgal'
70- ) ;
81+ const {
82+ Live2DModel,
83+ SoundManager,
84+ config,
85+ Live2DLoader,
86+ ModelSettings,
87+ createCubism2Texture,
88+ reserveCoreMemory,
89+ } = await import ( 'pixi-live2d-display-webgal' ) ;
7190 installLive2dAssetCache ( { Live2DLoader, ModelSettings } ) ;
7291 this . Live2DModel = Live2DModel ;
7392 this . SoundManager = SoundManager ;
7493 this . Config = config ;
7594 this . isAvailable = true ;
7695 this . createCubism2Texture = createCubism2Texture ;
96+ this . reserveCoreMemory = reserveCoreMemory ;
7797 console . log ( 'Live2D plugin load success' ) ;
7898 this . initConfig ( ) ;
99+ if ( this . reserveCoreMemory ) {
100+ this . reserveCoreMemory ( this . CubismMemoryReservedSize * 1024 * 1024 ) ;
101+ }
79102 } )
80103 . catch ( ( error ) => {
81104 this . isAvailable = false ;
0 commit comments