Skip to content

Commit

Permalink
fix(live2d): hit test after scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
ylxmf2005 committed Jan 24, 2025
1 parent 104598a commit 4bcfa20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ app.whenReady().then(() => {
return false;
});

if (process.env.NODE_ENV === "development") {
globalShortcut.register("F12", () => {
const window = windowManager.getWindow();
if (!window) return;

if (window.webContents.isDevToolsOpened()) {
window.webContents.closeDevTools();
} else {
window.webContents.openDevTools();
}
});
}
// if (process.env.NODE_ENV === "development") {
// globalShortcut.register("F12", () => {
// const window = windowManager.getWindow();
// if (!window) return;

// if (window.webContents.isDevToolsOpened()) {
// window.webContents.closeDevTools();
// } else {
// window.webContents.openDevTools();
// }
// });
// }

setupIPC();

Expand Down
10 changes: 4 additions & 6 deletions src/renderer/src/hooks/canvas/use-live2d-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,10 @@ export const useLive2DModel = ({
(model: Live2DModel, x: number, y: number) => {
if (!modelInfo?.tapMotions) return;

const hitAreas = model.hitTest(x, y);
// Convert global coordinates to model's local coordinates
const localPos = model.toLocal(new PIXI.Point(x, y));
const hitAreas = model.hitTest(localPos.x, localPos.y);

// Try to play motion for specific hit area
const foundMotion = hitAreas.find((area) => {
const motionGroup = modelInfo?.tapMotions?.[area];
if (motionGroup) {
Expand All @@ -285,11 +286,8 @@ export const useLive2DModel = ({
return false;
});

// If no specific hit area found, use merged motions
if (!foundMotion && Object.keys(modelInfo.tapMotions).length > 0) {
console.log("No specific hit area found, using merged motion groups");
const mergedMotions = getMergedMotionGroup(modelInfo.tapMotions);
console.log("Merged motion groups:", mergedMotions);
playRandomMotion(model, mergedMotions);
}
},
Expand Down Expand Up @@ -346,7 +344,7 @@ const playRandomMotion = (model: Live2DModel, motionGroup: MotionWeightMap) => {
if (random <= 0) {
const priority = audioTaskQueue.hasTask()
? MotionPriority.NORMAL
: MotionPriority.FORCE;
: MotionPriority.NORMAL;

console.log(
`Playing weighted motion: ${motion} (weight: ${weight}/${totalWeight}, priority: ${priority})`,
Expand Down

0 comments on commit 4bcfa20

Please sign in to comment.