Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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 (rendering), Assimp (FBX and other formats) and Dear 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
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
macOS without Homebrew (e.g. macOS 12 and older)
Homebrew no longer supports older macOS releases. Everything can be built in a user directory without admin rights:
xcode-select --install
mkdir -p ~/Dev/mr-deps && cd ~/Dev/mr-deps
curl -fLO https://github.com/Kitware/CMake/releases/download/v3.31.6/cmake-3.31.6-macos-universal.tar.gz
tar xzf cmake-3.31.6-macos-universal.tar.gz
curl -fLO https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-mac.zip
unzip ninja-mac.zip -d bin
export PATH=$PWD/cmake-3.31.6-macos-universal/CMake.app/Contents/bin:$PWD/bin:$PATH
curl -fL -o osg.tar.gz https://github.com/openscenegraph/OpenSceneGraph/archive/refs/tags/OpenSceneGraph-3.6.5.tar.gz
tar xzf osg.tar.gz
cmake -S OpenSceneGraph-OpenSceneGraph-3.6.5 -B osg-build -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$PWD/osg-install -DCMAKE_INSTALL_NAME_DIR=$PWD/osg-install/lib \
-DBUILD_OSG_APPLICATIONS=OFF -DBUILD_OSG_EXAMPLES=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5
cmake --build osg-build && cmake --install osg-build
cd path/to/3d-model-renderer
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$HOME/Dev/mr-deps/osg-install -DMR_FETCH_ASSIMP=ON
cmake --build build
CMAKE_INSTALL_NAME_DIR matters: without it the OSG libraries are installed with bare names and the renderer fails at
startup with Library not loaded: libosgDB.161.dylib.
Linux (Debian / Ubuntu)
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)
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.
./build/model_renderer miku.pmd --morph あ=1 --morph まばたき=1 --bone 左腕=0,0,-40 \
--orbit 20,10 --hide-ui --screenshot out.png
Tests
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 |