Skip to content

Commit 60fa06e

Browse files
Merge pull request #673 from A-kirami/fix/live2d-pivot-origin
fix: correct pivot point and positioning for Live2D figure
2 parents 611b53c + 18caafd commit 60fa06e

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

packages/webgal/src/Core/controller/stage/pixi/PixiController.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -662,22 +662,29 @@ export default class PixiStage {
662662
models.forEach((model) => {
663663
const scaleX = stageWidth / model.width;
664664
const scaleY = stageHeight / model.height;
665-
const targetScale = Math.min(scaleX, scaleY) * 1.5;
665+
const targetScale = Math.min(scaleX, scaleY);
666666
const targetWidth = model.width * targetScale;
667-
// const targetHeight = model.height * targetScale;
668-
669-
model.scale.set(targetScale);
667+
const targetHeight = model.height * targetScale;
668+
model.scale.x = targetScale;
669+
model.scale.y = targetScale;
670670
model.anchor.set(0.5);
671-
model.position.x = stageWidth / 2;
672-
model.position.y = stageHeight / 1.2;
671+
model.position.x = 0;
672+
model.position.y = stageHeight / 2;
673673

674-
if (pos === 'left') {
675-
model.position.x = targetWidth / 2;
674+
let baseY = stageHeight / 2;
675+
if (targetHeight < stageHeight) {
676+
baseY = stageHeight / 2 + stageHeight - targetHeight / 2;
676677
}
677-
if (pos === 'right') {
678-
model.position.x = stageWidth - targetWidth / 2;
678+
thisFigureContainer.setBaseY(baseY);
679+
if (pos === 'center') {
680+
thisFigureContainer.setBaseX(stageWidth / 2);
681+
} else if (pos === 'left') {
682+
thisFigureContainer.setBaseX(targetWidth / 2);
683+
} else if (pos === 'right') {
684+
thisFigureContainer.setBaseX(stageWidth - targetWidth / 2);
679685
}
680686

687+
thisFigureContainer.pivot.set(0, stageHeight / 2);
681688
let motionToSet = motion;
682689
let animation_index = 0;
683690
let priority_number = 3;

0 commit comments

Comments
 (0)