diff --git a/packages/webgal/package.json b/packages/webgal/package.json index cf884027a..6e8d459a4 100644 --- a/packages/webgal/package.json +++ b/packages/webgal/package.json @@ -21,7 +21,7 @@ "mitt": "^3.0.0", "modern-css-reset": "^1.4.0", "pixi-filters": "^4.2.0", - "pixi-live2d-display-webgal": "^0.5.2", + "pixi-live2d-display-webgal": "^0.5.8", "pixi-spine": "^3.1.2", "pixi.js": "^6.3.0", "popmotion": "^11.0.5", diff --git a/packages/webgal/src/Core/controller/stage/pixi/PixiController.ts b/packages/webgal/src/Core/controller/stage/pixi/PixiController.ts index 33b310834..4a191af6c 100644 --- a/packages/webgal/src/Core/controller/stage/pixi/PixiController.ts +++ b/packages/webgal/src/Core/controller/stage/pixi/PixiController.ts @@ -12,7 +12,7 @@ import 'pixi-spine'; // Do this once at the very start of your code. This regist import { Spine } from 'pixi-spine'; import { SCREEN_CONSTANTS } from '@/Core/util/constants'; // import { figureCash } from '@/Core/gameScripts/vocal/conentsCash'; // 如果要使用 Live2D,取消这里的注释 -// import { Live2DModel, SoundManager } from 'pixi-live2d-display'; // 如果要使用 Live2D,取消这里的注释 +// import { Live2DModel, SoundManager } from 'pixi-live2d-display-webgal'; // 如果要使用 Live2D,取消这里的注释 export interface IAnimationObject { setStartState: Function; @@ -689,7 +689,23 @@ export default class PixiStage { // const setup = () => { // if (thisFigureContainer) { // (async function () { - // const models = await Promise.all([Live2DModel.from(jsonPath, { autoInteract: false })]); + // let overrideBounds: [number, number, number, number] = [0, 0, 0, 0]; + // const mot = webgalStore.getState().stage.live2dMotion.find((e) => e.target === key); + // if (mot?.overrideBounds) { + // overrideBounds = mot.overrideBounds; + // } + // console.log(overrideBounds); + // const models = await Promise.all([ + // Live2DModel.from(jsonPath, { + // autoInteract: false, + // overWriteBounds: { + // x0: overrideBounds[0], + // y0: overrideBounds[1], + // x1: overrideBounds[2], + // y1: overrideBounds[3], + // }, + // }), + // ]); // // models.forEach((model) => { // const scaleX = stageWidth / model.width; diff --git a/packages/webgal/src/Core/gameScripts/changeFigure.ts b/packages/webgal/src/Core/gameScripts/changeFigure.ts index a662159cd..92deb9e5b 100644 --- a/packages/webgal/src/Core/gameScripts/changeFigure.ts +++ b/packages/webgal/src/Core/gameScripts/changeFigure.ts @@ -33,6 +33,7 @@ export function changeFigure(sentence: ISentence): IPerform { let animationFlag: any = ''; let mouthAnimationKey: any = 'mouthAnimation'; let eyesAnimationKey: any = 'blinkAnimation'; + let overrideBounds = ''; const dispatch = webgalStore.dispatch; for (const e of sentence.args) { @@ -63,6 +64,9 @@ export function changeFigure(sentence: ISentence): IPerform { case 'motion': motion = e.value.toString(); break; + case 'bounds': + overrideBounds = String(e.value); + break; case 'expression': expression = e.value.toString(); break; @@ -215,8 +219,10 @@ export function changeFigure(sentence: ISentence): IPerform { */ const freeFigureItem: IFreeFigure = { key, name: content, basePosition: pos }; setAnimationNames(key, sentence); - if (motion) { - dispatch(stageActions.setLive2dMotion({ target: key, motion })); + if (motion || overrideBounds) { + dispatch( + stageActions.setLive2dMotion({ target: key, motion, overrideBounds: getOverrideBoundsArr(overrideBounds) }), + ); } if (expression) { dispatch(stageActions.setLive2dExpression({ target: key, expression })); @@ -236,8 +242,10 @@ export function changeFigure(sentence: ISentence): IPerform { key = positionMap[pos]; setAnimationNames(key, sentence); - if (motion) { - dispatch(stageActions.setLive2dMotion({ target: key, motion })); + if (motion || overrideBounds) { + dispatch( + stageActions.setLive2dMotion({ target: key, motion, overrideBounds: getOverrideBoundsArr(overrideBounds) }), + ); } if (expression) { dispatch(stageActions.setLive2dExpression({ target: key, expression })); @@ -255,3 +263,16 @@ export function changeFigure(sentence: ISentence): IPerform { stopTimeout: undefined, // 暂时不用,后面会交给自动清除 }; } + +function getOverrideBoundsArr(raw: string): undefined | [number, number, number, number] { + const parseOverrideBoundsResult = raw.split(',').map((e) => Number(e)); + let isPass = true; + parseOverrideBoundsResult.forEach((e) => { + if (isNaN(e)) { + isPass = false; + } + }); + isPass = isPass && parseOverrideBoundsResult.length === 4; + if (isPass) return parseOverrideBoundsResult as [number, number, number, number]; + else return undefined; +} diff --git a/packages/webgal/src/store/stageInterface.ts b/packages/webgal/src/store/stageInterface.ts index 51273975c..ea611ce70 100644 --- a/packages/webgal/src/store/stageInterface.ts +++ b/packages/webgal/src/store/stageInterface.ts @@ -108,6 +108,7 @@ export interface IRunPerform { export interface ILive2DMotion { target: string; motion: string; + overrideBounds?: [number, number, number, number]; } export interface ILive2DExpression { diff --git a/packages/webgal/src/store/stageReducer.ts b/packages/webgal/src/store/stageReducer.ts index 37c9abb1a..e53b604f3 100644 --- a/packages/webgal/src/store/stageReducer.ts +++ b/packages/webgal/src/store/stageReducer.ts @@ -154,16 +154,17 @@ const stageSlice = createSlice({ } }, setLive2dMotion: (state, action: PayloadAction) => { - const { target, motion } = action.payload; + const { target, motion, overrideBounds } = action.payload; const index = state.live2dMotion.findIndex((e) => e.target === target); if (index < 0) { // Add a new motion - state.live2dMotion.push({ target, motion }); + state.live2dMotion.push({ target, motion, overrideBounds }); } else { // Update the existing motion state.live2dMotion[index].motion = motion; + state.live2dMotion[index].overrideBounds = overrideBounds; } }, setLive2dExpression: (state, action: PayloadAction) => { diff --git a/yarn.lock b/yarn.lock index 89362fd36..74f5bb3bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4255,10 +4255,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.2: - version "0.5.2" - resolved "https://registry.yarnpkg.com/pixi-live2d-display-webgal/-/pixi-live2d-display-webgal-0.5.2.tgz#a9153e39540a92293b91ccff8b106908415cfc52" - integrity sha512-XWI9Ev4OOB0cmve5RPdKP22LjjB7RdF2GkgRv55A3hEJgMvueuU4IZ5wBDuLYqHwiVxeWA/gTMycj7vyDCyn1g== +pixi-live2d-display-webgal@^0.5.8: + version "0.5.8" + resolved "https://registry.yarnpkg.com/pixi-live2d-display-webgal/-/pixi-live2d-display-webgal-0.5.8.tgz#1ff7b5016559ff56a5cfaa96abeac84c878a2bbf" + integrity sha512-yekmPckXykqziyFcmmgYlZU4ad42rRGGmUFvrm96YJrdRIi+V9uv/xKOrRBMxD/tr3Sckqp6hOr9Wi3UX6NNLw== dependencies: gh-pages "^4.0.0"