Skip to content

Commit 8eed43c

Browse files
committed
rewrite solver and migrate to nextjs
1 parent 48af8e7 commit 8eed43c

File tree

289 files changed

+9725
-11002
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

289 files changed

+9725
-11002
lines changed

.gitignore

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
1-
# Logs
2-
logs
3-
*.log
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
428
npm-debug.log*
529
yarn-debug.log*
630
yarn-error.log*
7-
pnpm-debug.log*
8-
lerna-debug.log*
9-
10-
node_modules
11-
dist
12-
dist-ssr
13-
dev-dist
14-
*.local
15-
16-
# Editor directories and files
17-
.vscode/*
18-
!.vscode/extensions.json
19-
.idea
20-
.DS_Store
21-
*.suo
22-
*.ntvs*
23-
*.njsproj
24-
*.sln
25-
*.sw?
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
2635

36+
# vercel
2737
.vercel
2838

29-
pose_solver/target
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts

LICENSE

Lines changed: 674 additions & 674 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,84 @@
1-
# MiKaPo: AI Pose Picker for MikuMikuDance
1+
# MiKaPo: Real-time MMD Motion Capture
22

3-
> **🎉 NEW PROJECT ALERT!** Check out [**PoPo**](https://popo.love) - Transform text into MMD poses with AI! No more manual bone adjustments - just type "shy smile while waving" and watch the magic happen ✨
3+
A web-based tool that enables real-time motion capture for MikuMikuDance (MMD) models.
44

5-
<img width="300px" alt="demo_pose" src="./logo.jpg" />
5+
## Overview
66

7-
[MiKaPo](https://mikapo.amyang.dev) is a **Web-based tool** that poses MMD models from video input in real-time. Welcome feature requests and PRs!
7+
[MiKaPo](https://mikapo.amyang.dev) transforms video input into real-time MMD model poses by detecting 3D landmarks and converting them to bone rotations. The core technical challenge lies in accurately mapping world-space 3D landmarks from MediaPipe to MMD bone quaternion rotations, accounting for MMD's specific bone coordinate system and directional conventions.
88

9-
<img width="400px" alt="demo_pose" src="./demo1.gif" />
10-
<img width="400px" alt="demo_face" src="./demo2.gif" />
11-
<img width="400px" alt="demo_img" src="./demo3.png" />
9+
**MiKaPo 2.0** introduces a completely rewritten solver with hierarchical bone transformations, migrating from Vite to Next.js for improved performance and maintainability.
1210

13-
## Tech Stack
11+
![](./screenshots/1.png)
12+
![](./screenshots/2.png)
1413

15-
- 3D key points detection: [Mediapipe](https://ai.google.dev/edge/mediapipe/solutions/vision/pose_landmarker/web_js)
16-
- 3D scene: [Babylon.js](https://www.babylonjs.com/)
17-
- MMD model viewer: [babylon-mmd](https://github.com/noname0310/babylon-mmd)
18-
- Web framework: [Vite+React](https://vitejs.dev/)
19-
- Models are from [aplaybox](https://aplaybox.com/en/mmd-models/).
14+
## Related Project
2015

21-
## Features
16+
Check out [**PoPo**](https://popo.love) - AI-powered text-to-MMD pose generation. Transform natural language descriptions into MMD poses instantly.
2217

23-
- [x] Pose detection
24-
- [x] Face detection
25-
- [x] Hand detection (experimental)
26-
- [x] Rust-WASM based pose-to-quaternion solver
27-
- [x] 360-degree background selection
28-
- [x] Video, image upload
29-
- [x] Webcam input
30-
- [x] Model selection
31-
- [x] Ollama support ([electron version](https://github.com/AmyangXYZ/MiKaPo-Electron))
32-
- [x] VMD import/export (to export a valid VMD file, you must record at least one motion)
33-
- [x] MMD editor: bone, material, mesh edit
18+
## Key Features
3419

35-
## Hint
20+
- **Real-time pose detection** using MediaPipe Pose
21+
- **Face and hand tracking** for comprehensive motion capture
22+
- **Multiple input sources**: webcam, video files, and image uploads
23+
- **Live MMD model rendering** with synchronized bone animations
3624

37-
- Let your browser use dedicated GPU for better performance.
25+
_Legacy features from v1.0 (VMD export, bone manipulation, 360° scene environment) will be added in future updates._
3826

39-
## Project Setup
27+
## Technical Stack
4028

41-
```sh
42-
npm install
43-
```
29+
- **3D Pose Detection**: [MediaPipe Pose Landmarker](https://ai.google.dev/edge/mediapipe/solutions/vision/pose_landmarker/web_js)
30+
- **3D Graphics Engine**: [Babylon.js](https://www.babylonjs.com/)
31+
- **MMD Integration**: [babylon-mmd](https://github.com/noname0310/babylon-mmd)
32+
- **Web Framework**: [Next.js](https://nextjs.org/)
4433

45-
### Compile and Hot-Reload for Development
34+
## Core Challenge
4635

47-
```sh
48-
npm run dev
49-
```
36+
The primary technical challenge involves solving the complex transformation from world-space 3D landmarks to MMD bone quaternion rotations. This requires:
5037

51-
### Type-Check, Compile and Minify for Production
38+
- Converting MediaPipe's coordinate system to MMD's bone space
39+
- Handling MMD's unique bone direction conventions
40+
- Computing accurate quaternion rotations for smooth animations
41+
- Maintaining temporal consistency across frames
5242

53-
```sh
54-
npm run build
55-
```
43+
## Technical Solution
44+
45+
The solver implements a hierarchical transformation approach that maps MediaPipe's world-space landmarks to MMD bone rotations:
46+
47+
```typescript
48+
// Key Algorithm Pseudocode
49+
function solveBoneRotation(landmarkName: string, parentChain: string[]): Quaternion {
50+
// 1. Get world-space landmarks from MediaPipe
51+
const worldLandmark = getMediaPipeLandmark(landmarkName)
52+
const worldTarget = getMediaPipeLandmark(targetLandmarkName)
53+
54+
// 2. Build full parent bone hierarchy chain (not just immediate parent)
55+
const fullParentQuat = parentChain.reduce(
56+
(acc, parent) => acc.multiply(boneStates[parent].rotation),
57+
Quaternion.Identity()
58+
)
5659

57-
### Lint with [ESLint](https://eslint.org/)
60+
// 3. Transform world landmarks to parent's local space
61+
const parentMatrix = Matrix.FromQuaternion(fullParentQuat).invert()
62+
const localLandmark = Vector3.TransformCoordinates(worldLandmark, parentMatrix)
63+
const localTarget = Vector3.TransformCoordinates(worldTarget, parentMatrix)
5864

59-
```sh
60-
npm run lint
65+
// 4. Calculate bone direction in local space
66+
const boneDirection = localTarget.subtract(localLandmark).normalize()
67+
68+
// 5. Set MMD bone's default A-pose reference direction
69+
const mmdReferenceDirection = getMMDDefaultDirection(boneName)
70+
71+
// 6. Compute quaternion rotation from reference to current direction
72+
return Quaternion.FromUnitVectors(referenceDirection, boneDirection)
73+
}
74+
75+
// Example: Left wrist transformation chain
76+
// Parent hierarchy: upper_body → left_arm → left_elbow → left_wrist
77+
// Each bone's rotation is computed in its parent's local space
6178
```
79+
80+
This approach ensures accurate bone rotations by:
81+
82+
- **Hierarchical Transformation**: Each bone is solved in its full parent chain's local space
83+
- **MMD A-Pose Alignment**: Reference directions match MMD's default bone orientations
84+
- **Coordinate System Conversion**: Properly handles MediaPipe's coordinate system to MMD's bone space

components.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "new-york",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "",
8+
"css": "src/app/globals.css",
9+
"baseColor": "zinc",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/lib/utils",
16+
"ui": "@/components/ui",
17+
"lib": "@/lib",
18+
"hooks": "@/hooks"
19+
},
20+
"iconLibrary": "lucide"
21+
}

demo1.gif

-5.99 MB
Binary file not shown.

demo2.gif

-7.43 MB
Binary file not shown.

demo3.png

-5.25 MB
Binary file not shown.

eslint.config.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { dirname } from "path";
2+
import { fileURLToPath } from "url";
3+
import { FlatCompat } from "@eslint/eslintrc";
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
7+
8+
const compat = new FlatCompat({
9+
baseDirectory: __dirname,
10+
});
11+
12+
const eslintConfig = [
13+
...compat.extends("next/core-web-vitals", "next/typescript"),
14+
];
15+
16+
export default eslintConfig;

icon.png

-116 KB
Binary file not shown.

0 commit comments

Comments
 (0)