Skip to main content

Wrapper for reading and modifying VMD and PMX files

Project description

PyPMXVMD

Python MikuMikuDance File Parser Library

Python Version License Version

PyPMXVMD is a Python library for parsing and modifying MikuMikuDance (MMD) files, supporting the following formats:

  • VMD (Vocaloid Motion Data) - Motion/animation data
  • PMX (Polygon Model eXtended) - 3D model data
  • VPD (Vocaloid Pose Data) - Pose data

Features

  • Full support for reading and writing VMD, PMX, and VPD files
  • Conversion between binary and text formats
  • Object-oriented API design, easy to use
  • Complete type annotation support
  • Optional Cython acceleration for core parsing and binary I/O (average 3.7x faster than the previous path)
  • No external dependencies (core functionality)
  • Supports Python 3.8+

Installation

# Install from source
git clone https://github.com/pypmxvmd/pypmxvmd.git
cd pypmxvmd
pip install -e .

# Install development dependencies
pip install -e ".[dev]"

Optional: Build Cython Accelerators

The core parsing path supports Cython-accelerated modules for VMD/PMX and binary I/O. In typical workloads, the Cython implementation is ~3.7x faster on average than the previous implementation. Prebuilt Cython binaries are only provided for Python 3.11; other Python versions need to compile locally. If the compiled modules are not available, the library automatically falls back to pure Python.

pip install cython
python scripts/build_cython.py

Quick Start

Basic Usage

import pypmxvmd

# Load VMD motion file
motion = pypmxvmd.load_vmd("motion.vmd")
print(f"Bone frames: {len(motion.bone_frames)}")
print(f"Morph frames: {len(motion.morph_frames)}")

# Modify and save
pypmxvmd.save_vmd(motion, "modified_motion.vmd")

# Load PMX model file
model = pypmxvmd.load_pmx("model.pmx")
print(f"Vertices: {len(model.vertices)}")
print(f"Materials: {len(model.materials)}")

# Load VPD pose file
pose = pypmxvmd.load_vpd("pose.vpd")
print(f"Bone poses: {len(pose.bone_poses)}")

Automatic Format Detection

import pypmxvmd

# Automatically detect file type and load
data = pypmxvmd.load("file.vmd")  # Returns VmdMotion
data = pypmxvmd.load("file.pmx")  # Returns PmxModel
data = pypmxvmd.load("file.vpd")  # Returns VpdPose

# Automatically detect data type and save
pypmxvmd.save(motion, "output.vmd")
pypmxvmd.save(model, "output.pmx")
pypmxvmd.save(pose, "output.vpd")

Text Format Conversion

PyPMXVMD supports converting binary files to readable text format for viewing and editing:

import pypmxvmd

# VMD -> Text
motion = pypmxvmd.load_vmd("motion.vmd")
pypmxvmd.save_vmd_text(motion, "motion.txt")

# Text -> VMD
motion = pypmxvmd.load_vmd_text("motion.txt")
pypmxvmd.save_vmd(motion, "motion.vmd")

# PMX -> Text
model = pypmxvmd.load_pmx("model.pmx")
pypmxvmd.save_pmx_text(model, "model.txt")

# VPD -> Text
pose = pypmxvmd.load_vpd("pose.vpd")
pypmxvmd.save_vpd_text(pose, "pose.txt")

Using Parser Classes

If you need more control, you can use the parser classes directly:

from pypmxvmd import VmdParser, PmxParser, VpdParser

# VMD Parser
vmd_parser = VmdParser()
motion = vmd_parser.parse_file("motion.vmd", more_info=True)
vmd_parser.write_file(motion, "output.vmd")

# PMX Parser
pmx_parser = PmxParser()
model = pmx_parser.parse_file("model.pmx", more_info=True)
pmx_parser.write_file(model, "output.pmx")

# VPD Parser
vpd_parser = VpdParser()
pose = vpd_parser.parse_file("pose.vpd", more_info=True)
vpd_parser.write_file(pose, "output.vpd")

Data Structures

VmdMotion (VMD Motion)

class VmdMotion:
    header: VmdHeader           # File header information
    bone_frames: List[VmdBoneFrame]      # Bone keyframes
    morph_frames: List[VmdMorphFrame]    # Morph keyframes
    camera_frames: List[VmdCameraFrame]  # Camera keyframes
    light_frames: List[VmdLightFrame]    # Light keyframes
    shadow_frames: List[VmdShadowFrame]  # Shadow keyframes
    ik_frames: List[VmdIkFrame]          # IK keyframes

PmxModel (PMX Model)

class PmxModel:
    header: PmxHeader           # File header information
    vertices: List[PmxVertex]   # Vertex list
    faces: List[int]            # Face indices
    textures: List[str]         # Texture paths
    materials: List[PmxMaterial]  # Material list
    bones: List[PmxBone]        # Bone list
    morphs: List[PmxMorph]      # Morph list
    frames: List[PmxFrame]      # Display frames
    rigidbodies: List[PmxRigidBody]  # Rigidbody list
    joints: List[PmxJoint]      # Joint list

VpdPose (VPD Pose)

class VpdPose:
    model_name: str             # Model name
    bone_poses: List[VpdBonePose]   # Bone pose list
    morph_poses: List[VpdMorphPose] # Morph pose list

API Reference

Core Functions

Function Description
load_vmd(path) Load VMD file
save_vmd(motion, path) Save VMD file
load_pmx(path) Load PMX file
save_pmx(model, path) Save PMX file
load_vpd(path) Load VPD file
save_vpd(pose, path) Save VPD file
load(path) Auto-detect and load
save(data, path) Auto-detect and save

Text Format Functions

Function Description
load_vmd_text(path) Load VMD from text
save_vmd_text(motion, path) Save VMD as text
load_pmx_text(path) Load PMX from text
save_pmx_text(model, path) Save PMX as text
load_vpd_text(path) Load VPD from text
save_vpd_text(pose, path) Save VPD as text
load_text(path) Auto-detect and load text
save_text(data, path) Auto-detect and save text

Project Structure

pypmxvmd/
├── pypmxvmd/                      # Main package
│   ├── __init__.py            # Public API
│   ├── common/                # Common components
│   │   ├── models/            # Data models
│   │   │   ├── vmd.py        # VMD data structures
│   │   │   ├── pmx.py        # PMX data structures
│   │   │   └── vpd.py        # VPD data structures
│   │   └── parsers/           # Parsers
│   │       ├── vmd_parser_nuthouse.py
│   │       ├── pmx_parser_nuthouse.py
│   │       └── vpd_parser.py
│   └── presentation/          # Presentation layer
│       ├── cli/               # Command-line interface
│       └── gui/               # Graphical interface
├── tests/                     # Tests
├── docs/                      # Documentation
└── mmd_scripting/             # Legacy code (reference)

Testing

# Run all tests
pytest tests/ -v

# Run specific test
pytest tests/test_vmd_parser.py -v

# Run coverage test
pytest tests/ --cov=pypmxvmd --cov-report=html

Development

# Install development dependencies
pip install -e ".[dev]"

# Code formatting
black pypmxvmd/
isort pypmxvmd/

# Type checking
mypy pypmxvmd/

# Code linting
flake8 pypmxvmd/

Version History

v2.5.1

  • Added optional Cython acceleration for core parsing and binary I/O
  • Cython path averages ~3.7x faster than the previous implementation

v2.0.0 (2024)

  • Complete refactor to object-oriented architecture
  • Added complete type annotations
  • Support for text format export/import
  • Improved error handling and validation
  • Added progress callback support

v1.x (Original)

  • Based on Nuthouse01's original implementation
  • Functional API

Acknowledgments

This project is refactored from the original MMD scripting tools by Nuthouse01.

License

MIT License - See LICENSE file for details

Contributing

Issues and Pull Requests are welcome!

  1. Fork this repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Create a Pull Request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypmxvmd-2.7.1.tar.gz (627.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pypmxvmd-2.7.1-cp313-cp313-win_amd64.whl (735.2 kB view details)

Uploaded CPython 3.13Windows x86-64

pypmxvmd-2.7.1-cp312-cp312-win_amd64.whl (737.5 kB view details)

Uploaded CPython 3.12Windows x86-64

pypmxvmd-2.7.1-cp311-cp311-win_amd64.whl (621.7 kB view details)

Uploaded CPython 3.11Windows x86-64

pypmxvmd-2.7.1-cp310-cp310-win_amd64.whl (737.1 kB view details)

Uploaded CPython 3.10Windows x86-64

pypmxvmd-2.7.1-cp39-cp39-win_amd64.whl (738.1 kB view details)

Uploaded CPython 3.9Windows x86-64

pypmxvmd-2.7.1-cp38-cp38-win_amd64.whl (621.5 kB view details)

Uploaded CPython 3.8Windows x86-64

File details

Details for the file pypmxvmd-2.7.1.tar.gz.

File metadata

  • Download URL: pypmxvmd-2.7.1.tar.gz
  • Upload date:
  • Size: 627.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for pypmxvmd-2.7.1.tar.gz
Algorithm Hash digest
SHA256 47ac9b3c42e4654e0b4755aa3d0d05d2eacee61eeac972ed4905b40a65dd5d79
MD5 4a95aa46922e9f7c577ead94510bda93
BLAKE2b-256 2d83b4171fc089a34bdb8db9467aa1fd836d48d7eb7bc29978d7c3708f78e73f

See more details on using hashes here.

File details

Details for the file pypmxvmd-2.7.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pypmxvmd-2.7.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a28718777ea8e1cdce935e2a5166a05036d7cdb875765ea30585603cb026cdab
MD5 dafc70504db39c1d676729f3e335c1ec
BLAKE2b-256 5f1c1b9c9ceef139729b8b8838d85416f75c95c29dc63505405a56d94ee7843c

See more details on using hashes here.

File details

Details for the file pypmxvmd-2.7.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pypmxvmd-2.7.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9f8cad7848f8541ca2b6f193d76d59b8dbfd9048bac2c4cb49fec8fe3678d547
MD5 e2f76f8f1aed7685a0bb0b54029c81c5
BLAKE2b-256 71e6d903ba1316b144331e2b0ad87588dfd28ac438b56fd050903f01086d89ad

See more details on using hashes here.

File details

Details for the file pypmxvmd-2.7.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pypmxvmd-2.7.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d30d9edebb9e6dd81e0784011820ca2523e6e97f34e4421ce54894561ae20540
MD5 2b159944a656dabfe445600e44f9df2f
BLAKE2b-256 2739f5112b61d5f8bce644493816cbfc704e9706990f355c92aea007d593d75f

See more details on using hashes here.

File details

Details for the file pypmxvmd-2.7.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pypmxvmd-2.7.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7fcbb0149955838c5aca9020c96542c86896f381e0e6d3dbff0257c0d7acadc1
MD5 5c337241d3f4d3ad8af4a47af25dc591
BLAKE2b-256 7301040d0b63dde5a8a4af31c7f870b688aa6763636040cc6708d70403a52479

See more details on using hashes here.

File details

Details for the file pypmxvmd-2.7.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pypmxvmd-2.7.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 738.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for pypmxvmd-2.7.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ea0dc613fb6ca0cb50f6f734c03b525f66131ff014a6bd48d393a5c2c5cfa08f
MD5 d6f781158c4bdb2b139ec762fa7060fb
BLAKE2b-256 815d2747b3383eb9ce62f74ddf6f7eabb91d56e14026c2052efcf8234a7fe1e0

See more details on using hashes here.

File details

Details for the file pypmxvmd-2.7.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pypmxvmd-2.7.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 621.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for pypmxvmd-2.7.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 571f0d3b5b54257f78383c442bca5dea08e3fff30753fc44d7e8c73d73d0f9cb
MD5 77e72a25702d52c73f58f79ddd8f72e9
BLAKE2b-256 f84b4bed9e7802be859d875b1ef9a16e2a2460d77bec41266bf53ff7b5b53aa8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page