Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
103 lines
4.1 KiB
Markdown
103 lines
4.1 KiB
Markdown
# 3d-model-renderer
|
|
|
|
A cross-platform (Linux, macOS, Windows) viewer for **PMX / PMD** (MikuMikuDance) and **FBX** models
|
|
that lets you pose bones and drive vertex morphs (eyes, mouth, eyebrows) from an on-screen UI.
|
|
|
|
Built with C++17, [OpenSceneGraph](https://github.com/openscenegraph/OpenSceneGraph) (rendering),
|
|
[Assimp](https://github.com/assimp/assimp) (FBX and other formats) and [Dear ImGui](https://github.com/ocornut/imgui) (UI).
|
|
|
|
## How it works
|
|
|
|
```
|
|
.pmx ──► PmxLoader ─┐
|
|
.pmd ──► PmdLoader ─┼─► mr::Model ──► mr::Poser ──► ModelNode (OSG geometry + GLSL) ──► osgViewer
|
|
.fbx ──► Assimp ──┘ (one format) (morphs + skinning, ImGui overlay (bones, morphs, view)
|
|
on the CPU)
|
|
```
|
|
|
|
* PMX and PMD use their own loaders because Assimp cannot read PMD and drops PMX morphs.
|
|
* Every format is converted into one internal model (right-handed, +Y up, facing +Z), so rendering,
|
|
posing and morphing share a single code path.
|
|
* Bone rotations in the UI are in model-space axes at the bone pivot, so they behave the same for
|
|
MMD and FBX rigs.
|
|
* Shaders are GLSL 1.20 so they run on macOS's legacy OpenGL context as well as Linux and Windows.
|
|
|
|
Supported: textures (incl. MMD sphere `.sph`/`.spa` and toon maps), vertex/group/bone/flip morphs,
|
|
BDEF1/2/4 weights (SDEF/QDEF approximated as linear blend). Not yet: IK solving, physics, UV and
|
|
material morphs, edge outlines, animation playback (VMD).
|
|
|
|
## Building
|
|
|
|
You need CMake ≥ 3.16, a C++17 compiler, OpenSceneGraph 3.6 and (optionally) Assimp. If Assimp is not
|
|
installed CMake downloads and builds it (`-DMR_FETCH_ASSIMP=ON` forces that). Dear ImGui is always downloaded.
|
|
|
|
### macOS
|
|
|
|
```sh
|
|
xcode-select --install
|
|
brew install cmake ninja open-scene-graph assimp
|
|
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
|
cmake --build build
|
|
./build/model_renderer path/to/model.pmx
|
|
```
|
|
|
|
### Linux (Debian / Ubuntu)
|
|
|
|
```sh
|
|
sudo apt install build-essential cmake ninja-build libopenscenegraph-dev libassimp-dev \
|
|
libgl1-mesa-dev fonts-noto-cjk xclip
|
|
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
|
cmake --build build
|
|
./build/model_renderer path/to/model.pmx
|
|
```
|
|
|
|
Copy/paste in text fields uses `xclip` or `xsel` on X11 and `wl-clipboard` on Wayland.
|
|
|
|
Fedora: `sudo dnf install cmake ninja-build gcc-c++ OpenSceneGraph-devel assimp-devel google-noto-sans-cjk-fonts`.
|
|
|
|
### Windows (Visual Studio 2022 + vcpkg)
|
|
|
|
```bat
|
|
git clone https://github.com/microsoft/vcpkg C:\vcpkg && C:\vcpkg\bootstrap-vcpkg.bat
|
|
C:\vcpkg\vcpkg install osg assimp --triplet x64-windows
|
|
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
|
|
cmake --build build --config Release
|
|
build\Release\model_renderer.exe path\to\model.pmx
|
|
```
|
|
|
|
A Japanese font is picked up automatically (Hiragino on macOS, Meiryo/Yu Gothic on Windows, Noto CJK on
|
|
Linux) so MMD bone and morph names display correctly.
|
|
|
|
## Using it
|
|
|
|
* **File > Open** picks a model; you can also pass the path on the command line.
|
|
* **Bones**: select a bone, then use the rotation sliders / move fields. `*` marks posed bones.
|
|
* **Morphs**: sliders grouped as Eye / Mouth / Eyebrow / Other, as in MMD.
|
|
* **View**: skeleton overlay, wireframe, culling, MMD toon vs Lambert shading, UI scale (use 2 on Retina).
|
|
* Camera: left drag orbits, middle drag pans, right drag or wheel zooms, Space resets.
|
|
|
|
Command-line options (`--help`) allow scripted renders, e.g.
|
|
|
|
```sh
|
|
./build/model_renderer miku.pmd --morph あ=1 --morph まばたき=1 --bone 左腕=0,0,-40 \
|
|
--orbit 20,10 --hide-ui --screenshot out.png
|
|
```
|
|
|
|
## Tests
|
|
|
|
```sh
|
|
cmake -S . -B build -DMR_BUILD_TESTS=ON && cmake --build build && ctest --test-dir build
|
|
```
|
|
|
|
The test models in `tests/data` are generated by `tools/make_test_models.py` (PMX/PMD) and
|
|
`tools/make_test_fbx.py` (FBX, run with `blender -b -P`).
|
|
|
|
## Layout
|
|
|
|
| Path | Contents |
|
|
| --- | --- |
|
|
| `src/model` | Internal model, PMX/PMD/Assimp loaders, `Poser` (morphs + skinning) |
|
|
| `src/render` | OSG scene node, shaders, texture loading |
|
|
| `src/ui` | ImGui ↔ OpenSceneGraph integration |
|
|
| `src/app` | Application, UI panels, file browser, command line |
|