Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/webgal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 26 additions & 3 deletions packages/webgal/src/Core/live2DCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class Live2DCore {
public Config: any;

public createCubism2Texture?: (texture: Texture) => Texture;
public reserveCoreMemory?: (size: number) => void;

// 临时记录未初始化前的数据
// 旧版表情混合模式
Expand All @@ -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();
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export const infoFetcher = (url: string): Promise<IGameVar> => {
const appId = String(res);
WebGAL.steam.initialize(appId);
}
if (command === 'Cubism_Memory_Reserved_Size_MB') {
if (typeof res === 'number') {
Live2D.CubismMemoryReservedSize = res;
}
}
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Loading