Skip to content

Commit

Permalink
fix: handle spine with .json, fix spine pivot problem
Browse files Browse the repository at this point in the history
  • Loading branch information
MakinoharaShoko committed Dec 22, 2024
1 parent 3534bdd commit 4e10a86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/webgal/src/Core/controller/stage/pixi/PixiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,17 +610,19 @@ export default class PixiStage {
setTimeout(() => {
if (spineResource && this.getStageObjByUuid(figureUuid)) {
const figureSpine = new Spine(spineResource.spineData);
const transY = spineResource?.spineData?.y ?? 0;
const spineBounds = figureSpine.getLocalBounds();
const spineCenterX = spineBounds.x + spineBounds.width / 2;
const spineCenterY = spineBounds.y + spineBounds.height / 2;
figureSpine.pivot.set(spineCenterX, spineCenterY);
// TODO: set animation 还没做
// figureSpine.state.setAnimation()
/**
* 重设大小
*/
const originalWidth = figureSpine.width;
const originalHeight = figureSpine.height;
const scaleX = this.stageWidth / originalWidth;
const scaleY = this.stageHeight / originalHeight;
// 我也不知道为什么啊啊啊啊
figureSpine.y = -(scaleY * transY) / 2;
figureSpine.state.setAnimation(0, '07', true);
const targetScale = Math.min(scaleX, scaleY);
const figureSprite = new PIXI.Sprite();
figureSprite.addChild(figureSpine);
Expand Down
5 changes: 4 additions & 1 deletion packages/webgal/src/Stage/MainStage/useSetFigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ function removeFig(figObj: IStageObject, enterTikerKey: string, effects: IEffect

function addFigure(type?: 'image' | 'live2D' | 'spine', ...args: any[]) {
const url = args[1];
const baseUrl = window.location.origin;
const urlObject = new URL(url, baseUrl);
const _type = urlObject.searchParams.get('type') as 'image' | 'live2D' | 'spine' | null;
if (url.endsWith('.json')) {
return addLive2dFigure(...args);
} else if (url.endsWith('.skel')) {
} else if (url.endsWith('.skel') || _type === 'spine') {
// @ts-ignore
return WebGAL.gameplay.pixiStage?.addSpineFigure(...args);
} else {
Expand Down

0 comments on commit 4e10a86

Please sign in to comment.