Wrapper for reading and modifying VMD and PMX files
Project description
PyPMXVMD
Python MikuMikuDance File Parser Library
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
- 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]"
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.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!
- Fork this repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypmxvmd-2.0.0.tar.gz.
File metadata
- Download URL: pypmxvmd-2.0.0.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fd340fb976ec4c8dfaad63e79af0248a5dae726cb57566f7f9c132d69315c12
|
|
| MD5 |
2dab5510c85ab2f70e8b7c72ad83e5af
|
|
| BLAKE2b-256 |
7d2b7adbccd9b733f344ded340f70cf4bf3e7126ec4de1030d6c6772ff07e65b
|
File details
Details for the file pypmxvmd-2.0.0-py3-none-any.whl.
File metadata
- Download URL: pypmxvmd-2.0.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a67f4ecd7f005c9075afc2b1059ce3be7ab66b887805cf9a3a38ada704f44c57
|
|
| MD5 |
bb7d303e279528eaa8f8ac633e9700eb
|
|
| BLAKE2b-256 |
4748585df336d4081e0d21435ec0f3c74323f78a7d16549738739d489269928f
|