pypmxvmd 2.7.1__tar.gz → 2.8.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. pypmxvmd-2.8.1/LICENSE +21 -0
  2. pypmxvmd-2.8.1/MANIFEST.in +3 -0
  3. pypmxvmd-2.8.1/PKG-INFO +450 -0
  4. pypmxvmd-2.8.1/README.md +427 -0
  5. pypmxvmd-2.8.1/docs/API.md +1681 -0
  6. pypmxvmd-2.8.1/docs/API_CN.md +1846 -0
  7. pypmxvmd-2.8.1/docs/index.md +18 -0
  8. pypmxvmd-2.8.1/pypmxvmd/__init__.py +1147 -0
  9. pypmxvmd-2.8.1/pypmxvmd/common/__init__.py +11 -0
  10. pypmxvmd-2.8.1/pypmxvmd/common/expressions/__init__.py +1 -0
  11. pypmxvmd-2.8.1/pypmxvmd/common/expressions/expression_profile.py +370 -0
  12. pypmxvmd-2.8.1/pypmxvmd/common/expressions/expression_profile_io.py +190 -0
  13. pypmxvmd-2.8.1/pypmxvmd/common/expressions/expression_resolution.py +426 -0
  14. pypmxvmd-2.8.1/pypmxvmd/common/expressions/pmx_expression_profile.py +135 -0
  15. pypmxvmd-2.8.1/pypmxvmd/common/expressions/tda_expression_profile.py +138 -0
  16. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/io/__init__.py +16 -16
  17. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/io/_fast_binary.c +6666 -4555
  18. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/io/_fast_binary.pyi +32 -32
  19. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/io/_fast_binary.pyx +43 -6
  20. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/io/binary_io.py +465 -451
  21. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/io/file_utils.py +313 -293
  22. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/io/text_io.py +316 -299
  23. pypmxvmd-2.8.1/pypmxvmd/common/io/vmd_codec.py +132 -0
  24. pypmxvmd-2.8.1/pypmxvmd/common/io/vmd_layout.py +195 -0
  25. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/models/__init__.py +18 -18
  26. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/models/base.py +172 -168
  27. pypmxvmd-2.8.1/pypmxvmd/common/models/pmx.py +2019 -0
  28. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/models/vmd.py +387 -350
  29. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/models/vpd.py +114 -111
  30. pypmxvmd-2.8.1/pypmxvmd/common/morph/__init__.py +1 -0
  31. pypmxvmd-2.8.1/pypmxvmd/common/morph/expression_controller.py +55 -0
  32. pypmxvmd-2.8.1/pypmxvmd/common/morph/eye_controller.py +236 -0
  33. pypmxvmd-2.8.1/pypmxvmd/common/morph/morph_control_plan.py +143 -0
  34. pypmxvmd-2.8.1/pypmxvmd/common/morph/morph_control_planner.py +247 -0
  35. pypmxvmd-2.8.1/pypmxvmd/common/morph/morph_controller.py +253 -0
  36. pypmxvmd-2.8.1/pypmxvmd/common/morph/morph_rig_profile.py +233 -0
  37. pypmxvmd-2.8.1/pypmxvmd/common/morph/mouth_controller.py +55 -0
  38. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/__init__.py +16 -16
  39. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/_fast_pmx.c +6079 -4127
  40. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/_fast_pmx.pyi +5 -6
  41. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/_fast_pmx.pyx +35 -9
  42. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/_fast_vmd.c +6580 -4226
  43. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/_fast_vmd.pyi +5 -6
  44. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/_fast_vmd.pyx +24 -13
  45. pypmxvmd-2.8.1/pypmxvmd/common/parsers/pmx_parser.py +2716 -0
  46. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/pmx_parser_nuthouse.py +1607 -1320
  47. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/vmd_parser.py +1852 -1569
  48. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/vmd_parser_nuthouse.py +1426 -1092
  49. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd/common/parsers/vpd_parser.py +627 -589
  50. pypmxvmd-2.8.1/pypmxvmd/common/pmx/__init__.py +496 -0
  51. pypmxvmd-2.8.1/pypmxvmd/common/pmx/cursor.py +415 -0
  52. pypmxvmd-2.8.1/pypmxvmd/common/pmx/document.py +903 -0
  53. pypmxvmd-2.8.1/pypmxvmd/common/pmx/editing.py +2749 -0
  54. pypmxvmd-2.8.1/pypmxvmd/common/pmx/errors.py +165 -0
  55. pypmxvmd-2.8.1/pypmxvmd/common/pmx/legacy_patch.py +628 -0
  56. pypmxvmd-2.8.1/pypmxvmd/common/pmx/limits.py +33 -0
  57. pypmxvmd-2.8.1/pypmxvmd/common/pmx/material_compatibility.py +532 -0
  58. pypmxvmd-2.8.1/pypmxvmd/common/pmx/motion_diagnostics.py +1001 -0
  59. pypmxvmd-2.8.1/pypmxvmd/common/pmx/motion_repair.py +2189 -0
  60. pypmxvmd-2.8.1/pypmxvmd/common/pmx/outfit.py +8243 -0
  61. pypmxvmd-2.8.1/pypmxvmd/common/pmx/report.py +114 -0
  62. pypmxvmd-2.8.1/pypmxvmd/common/pmx/transaction.py +3479 -0
  63. pypmxvmd-2.8.1/pypmxvmd/common/pmx/types.py +127 -0
  64. pypmxvmd-2.8.1/pypmxvmd/common/pmx/validator.py +1143 -0
  65. pypmxvmd-2.8.1/pypmxvmd/common/pmx/writer.py +478 -0
  66. pypmxvmd-2.8.1/pypmxvmd/common/vmd/__init__.py +1 -0
  67. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_bone_editor.py +134 -0
  68. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_document.py +223 -0
  69. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_edit_plan.py +198 -0
  70. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_edit_transaction.py +519 -0
  71. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_frame_codec.py +286 -0
  72. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_record_index.py +77 -0
  73. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_rotation.py +94 -0
  74. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_sampler.py +341 -0
  75. pypmxvmd-2.8.1/pypmxvmd/common/vmd/vmd_track_operations.py +436 -0
  76. pypmxvmd-2.8.1/pypmxvmd/py.typed +0 -0
  77. pypmxvmd-2.8.1/pypmxvmd.egg-info/PKG-INFO +450 -0
  78. pypmxvmd-2.8.1/pypmxvmd.egg-info/SOURCES.txt +140 -0
  79. pypmxvmd-2.8.1/pypmxvmd.egg-info/not-zip-safe +1 -0
  80. pypmxvmd-2.8.1/pypmxvmd.egg-info/requires.txt +4 -0
  81. pypmxvmd-2.8.1/pyproject.toml +149 -0
  82. pypmxvmd-2.8.1/setup.py +54 -0
  83. pypmxvmd-2.8.1/tests/test_api_compatibility.py +178 -0
  84. pypmxvmd-2.8.1/tests/test_api_integration.py +94 -0
  85. pypmxvmd-2.8.1/tests/test_complete_coverage.py +1288 -0
  86. pypmxvmd-2.8.1/tests/test_corpus_parsers.py +73 -0
  87. pypmxvmd-2.8.1/tests/test_cython_parsers.py +203 -0
  88. pypmxvmd-2.8.1/tests/test_expression_profiles.py +212 -0
  89. pypmxvmd-2.8.1/tests/test_expression_resolution.py +230 -0
  90. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/tests/test_io_utils.py +10 -1
  91. pypmxvmd-2.8.1/tests/test_morph_controller.py +252 -0
  92. pypmxvmd-2.8.1/tests/test_parser_optimization.py +114 -0
  93. pypmxvmd-2.8.1/tests/test_pmx_0047_ik_contract.py +295 -0
  94. pypmxvmd-2.8.1/tests/test_pmx_21.py +357 -0
  95. pypmxvmd-2.8.1/tests/test_pmx_binary_layout.py +113 -0
  96. pypmxvmd-2.8.1/tests/test_pmx_bone_editing.py +342 -0
  97. pypmxvmd-2.8.1/tests/test_pmx_bone_morph_items.py +159 -0
  98. pypmxvmd-2.8.1/tests/test_pmx_bone_reader.py +298 -0
  99. pypmxvmd-2.8.1/tests/test_pmx_comprehensive.py +56 -0
  100. pypmxvmd-2.8.1/tests/test_pmx_cursor.py +163 -0
  101. pypmxvmd-2.8.1/tests/test_pmx_document.py +162 -0
  102. pypmxvmd-2.8.1/tests/test_pmx_high_level_editing.py +334 -0
  103. pypmxvmd-2.8.1/tests/test_pmx_integrity.py +219 -0
  104. pypmxvmd-2.8.1/tests/test_pmx_joint_editing.py +267 -0
  105. pypmxvmd-2.8.1/tests/test_pmx_legacy_patch.py +310 -0
  106. pypmxvmd-2.8.1/tests/test_pmx_malformed.py +73 -0
  107. pypmxvmd-2.8.1/tests/test_pmx_material_compatibility.py +332 -0
  108. pypmxvmd-2.8.1/tests/test_pmx_material_editing.py +445 -0
  109. pypmxvmd-2.8.1/tests/test_pmx_model_fields.py +191 -0
  110. pypmxvmd-2.8.1/tests/test_pmx_model_validation.py +131 -0
  111. pypmxvmd-2.8.1/tests/test_pmx_motion_diagnostics.py +374 -0
  112. pypmxvmd-2.8.1/tests/test_pmx_motion_repair.py +1103 -0
  113. pypmxvmd-2.8.1/tests/test_pmx_outfit_api.py +1996 -0
  114. pypmxvmd-2.8.1/tests/test_pmx_patch.py +152 -0
  115. pypmxvmd-2.8.1/tests/test_pmx_physics_components.py +371 -0
  116. pypmxvmd-2.8.1/tests/test_pmx_rigid_body_editing.py +271 -0
  117. pypmxvmd-2.8.1/tests/test_pmx_roundtrip.py +139 -0
  118. pypmxvmd-2.8.1/tests/test_pmx_sections_reader.py +358 -0
  119. pypmxvmd-2.8.1/tests/test_pmx_transactions.py +553 -0
  120. pypmxvmd-2.8.1/tests/test_pmx_validator.py +644 -0
  121. pypmxvmd-2.8.1/tests/test_pmx_vertex_reader.py +104 -0
  122. pypmxvmd-2.8.1/tests/test_pmx_writer.py +125 -0
  123. pypmxvmd-2.8.1/tests/test_pmx_writer_canonical.py +118 -0
  124. pypmxvmd-2.8.1/tests/test_quick_integration.py +31 -0
  125. pypmxvmd-2.8.1/tests/test_text_processing.py +79 -0
  126. pypmxvmd-2.8.1/tests/test_vmd_comparison.py +36 -0
  127. pypmxvmd-2.8.1/tests/test_vmd_comprehensive.py +71 -0
  128. pypmxvmd-2.8.1/tests/test_vmd_document.py +141 -0
  129. pypmxvmd-2.8.1/tests/test_vmd_editing.py +315 -0
  130. pypmxvmd-2.8.1/tests/test_vmd_format_baseline.py +197 -0
  131. pypmxvmd-2.8.1/tests/test_vmd_header.py +32 -0
  132. pypmxvmd-2.8.1/tests/test_vmd_parser.py +33 -0
  133. pypmxvmd-2.8.1/tests/test_vmd_sampler.py +91 -0
  134. pypmxvmd-2.8.1/tests/test_vmd_section_editing.py +154 -0
  135. pypmxvmd-2.8.1/tests/test_vmd_track_operations.py +120 -0
  136. pypmxvmd-2.8.1/tests/test_vpd_parser.py +37 -0
  137. pypmxvmd-2.7.1/PKG-INFO +0 -324
  138. pypmxvmd-2.7.1/README.md +0 -300
  139. pypmxvmd-2.7.1/pypmxvmd/__init__.py +0 -401
  140. pypmxvmd-2.7.1/pypmxvmd/common/__init__.py +0 -11
  141. pypmxvmd-2.7.1/pypmxvmd/common/io/_fast_binary.cp311-win_amd64.pyd +0 -0
  142. pypmxvmd-2.7.1/pypmxvmd/common/io/_fast_binary.cp38-win_amd64.pyd +0 -0
  143. pypmxvmd-2.7.1/pypmxvmd/common/models/pmx.py +0 -633
  144. pypmxvmd-2.7.1/pypmxvmd/common/parsers/_fast_pmx.cp311-win_amd64.pyd +0 -0
  145. pypmxvmd-2.7.1/pypmxvmd/common/parsers/_fast_pmx.cp38-win_amd64.pyd +0 -0
  146. pypmxvmd-2.7.1/pypmxvmd/common/parsers/_fast_vmd.cp311-win_amd64.pyd +0 -0
  147. pypmxvmd-2.7.1/pypmxvmd/common/parsers/_fast_vmd.cp38-win_amd64.pyd +0 -0
  148. pypmxvmd-2.7.1/pypmxvmd/common/parsers/pmx_parser.py +0 -1397
  149. pypmxvmd-2.7.1/pypmxvmd.egg-info/PKG-INFO +0 -324
  150. pypmxvmd-2.7.1/pypmxvmd.egg-info/SOURCES.txt +0 -57
  151. pypmxvmd-2.7.1/pypmxvmd.egg-info/entry_points.txt +0 -2
  152. pypmxvmd-2.7.1/pypmxvmd.egg-info/requires.txt +0 -3
  153. pypmxvmd-2.7.1/pyproject.toml +0 -110
  154. pypmxvmd-2.7.1/setup.py +0 -54
  155. pypmxvmd-2.7.1/tests/test_api_integration.py +0 -276
  156. pypmxvmd-2.7.1/tests/test_cython_parsers.py +0 -395
  157. pypmxvmd-2.7.1/tests/test_parser_optimization.py +0 -456
  158. pypmxvmd-2.7.1/tests/test_pmx_comprehensive.py +0 -247
  159. pypmxvmd-2.7.1/tests/test_pmx_writer.py +0 -114
  160. pypmxvmd-2.7.1/tests/test_quick_integration.py +0 -128
  161. pypmxvmd-2.7.1/tests/test_text_processing.py +0 -299
  162. pypmxvmd-2.7.1/tests/test_vmd_comparison.py +0 -162
  163. pypmxvmd-2.7.1/tests/test_vmd_comprehensive.py +0 -213
  164. pypmxvmd-2.7.1/tests/test_vmd_header.py +0 -76
  165. pypmxvmd-2.7.1/tests/test_vmd_parser.py +0 -63
  166. pypmxvmd-2.7.1/tests/test_vpd_parser.py +0 -151
  167. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd.egg-info/dependency_links.txt +0 -0
  168. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/pypmxvmd.egg-info/top_level.txt +0 -0
  169. {pypmxvmd-2.7.1 → pypmxvmd-2.8.1}/setup.cfg +0 -0
pypmxvmd-2.8.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 PythonImporter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include docs/API.md
2
+ include docs/API_CN.md
3
+ include docs/index.md
@@ -0,0 +1,450 @@
1
+ Metadata-Version: 2.2
2
+ Name: pypmxvmd
3
+ Version: 2.8.1
4
+ Summary: Wrapper for reading and modifying VMD and PMX files
5
+ Author-email: PythonImporter <271374667@qq.com>
6
+ Project-URL: Homepage, https://github.com/271374667/pypmxvmd
7
+ Project-URL: Documentation, https://pypmxvmd.readthedocs.io/
8
+ Project-URL: Repository, https://github.com/271374667/pypmxvmd
9
+ Project-URL: Bug Tracker, https://github.com/271374667/pypmxvmd/issues
10
+ Keywords: mmd,mikumikudance,pmx,vmd,vpd,3d,animation
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ Provides-Extra: all
21
+ Requires-Dist: numpy>=2.4.6; extra == "all"
22
+ Requires-Dist: scipy>=1.17.1; extra == "all"
23
+
24
+ # PyPMXVMD
25
+
26
+ ![pypmxvmd](https://socialify.git.ci/271374667/pypmxvmd/image?description=1&font=Inter&language=1&name=1&owner=1&theme=Auto)
27
+
28
+ [English API](docs/API.md) | [中文 API](docs/API_CN.md)
29
+
30
+ Python MikuMikuDance File Parser Library
31
+
32
+ [![Python Version](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/)
33
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
34
+ [![Version](https://img.shields.io/badge/version-2.8.1-orange.svg)](https://github.com/271374667/pypmxvmd)
35
+
36
+ PyPMXVMD is a Python library for parsing and modifying MikuMikuDance (MMD) files, supporting the following formats:
37
+
38
+ - **VMD** (Vocaloid Motion Data) - Motion/animation data
39
+ - **PMX** (Polygon Model eXtended) - 3D model data
40
+ - **VPD** (Vocaloid Pose Data) - Pose data
41
+
42
+ ## Features
43
+
44
+ - Complete PMX 2.0 reading and canonical writing through Spring 6DOF Joint
45
+ - PMX 2.1 QDEF, Flip/Impulse Morph, all six Joint types, and full Soft Body records
46
+ - Validating, atomic PMX 2.0/2.1 output with semantic round-trip coverage
47
+ - Conversion between binary and text formats
48
+ - Object-oriented API design, easy to use
49
+ - Distributed type information via `py.typed`
50
+ - Optional Cython acceleration for core parsing and binary I/O; PMX currently uses the canonical Cursor model for complete public results
51
+ - PMX core parsing remains dependency-light; surface fitting is available with
52
+ the optional `all` extra (`numpy` and `scipy`)
53
+ - Uses Python 3.11 as the supported development and release baseline
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ # Core parser/writer only
59
+ pip install pypmxvmd
60
+
61
+ # Include surface fitting and other numeric features
62
+ pip install "pypmxvmd[all]"
63
+
64
+ # Add the released package to a uv project
65
+ uv add pypmxvmd
66
+
67
+ # Prepare a source checkout for development
68
+ git clone https://github.com/271374667/pypmxvmd.git
69
+ cd pypmxvmd
70
+ uv sync --group dev --python 3.11.12
71
+ ```
72
+
73
+ The core package has no mandatory third-party runtime dependencies. Install the
74
+ `all` extra when using `fit_part_to_surface()` or
75
+ `PmxVariantBuilder(surface_fit=...)`.
76
+
77
+ ### Optional: Build Cython Accelerators
78
+
79
+ The core parsing path supports Cython-accelerated modules for VMD/PMX and binary I/O.
80
+ `uv sync` builds the three native extensions through the project's setuptools backend.
81
+ The runtime automatically falls back to pure Python when compiled modules are unavailable.
82
+
83
+ ```bash
84
+ uv run --python 3.11.12 --no-sync python scripts/build_cython.py
85
+ uv run --python 3.11.12 --no-sync pytest tests/test_cython_parsers.py -m "cython and not benchmark" -ra
86
+ ```
87
+
88
+ Set `PYPMXVMD_BUILD_CYTHON=0` before `uv sync` when a pure-Python environment is
89
+ required explicitly.
90
+
91
+ ## Quick Start
92
+
93
+ ### Basic Usage
94
+
95
+ ```python
96
+ import pypmxvmd
97
+
98
+ # Load VMD motion file
99
+ motion = pypmxvmd.load_vmd("motion.vmd")
100
+ print(f"Bone frames: {len(motion.bone_frames)}")
101
+ print(f"Morph frames: {len(motion.morph_frames)}")
102
+
103
+ # Modify and save
104
+ pypmxvmd.save_vmd(motion, "modified_motion.vmd")
105
+
106
+ # Load PMX model file
107
+ model = pypmxvmd.load_pmx("model.pmx")
108
+ print(f"Vertices: {len(model.vertices)}")
109
+ print(f"Materials: {len(model.materials)}")
110
+ pypmxvmd.save_pmx(model, "canonical-model.pmx")
111
+
112
+ # Load VPD pose file
113
+ pose = pypmxvmd.load_vpd("pose.vpd")
114
+ print(f"Bone poses: {len(pose.bone_poses)}")
115
+ ```
116
+
117
+ ### Automatic Format Detection
118
+
119
+ ```python
120
+ import pypmxvmd
121
+
122
+ # Automatically detect file type and load
123
+ data = pypmxvmd.load("file.vmd") # Returns VmdMotion
124
+ data = pypmxvmd.load("file.pmx") # Returns PmxModel
125
+ data = pypmxvmd.load("file.vpd") # Returns VpdPose
126
+
127
+ # Automatically detect data type and save
128
+ pypmxvmd.save(motion, "output.vmd")
129
+ pypmxvmd.save(model, "output.pmx")
130
+ pypmxvmd.save(pose, "output.vpd")
131
+ ```
132
+
133
+ PMX 2.0/2.1 binary loading and canonical saving consume every version-required
134
+ section through Joint/Soft Body. Saving validates the full model before
135
+ atomically replacing the target;
136
+ canonical output chooses deterministic index widths and is semantically stable,
137
+ but is not promised to be byte-identical to the source. Semantic validation is
138
+ available through `PmxModel.validate()`. PMX 2.1 support covers QDEF,
139
+ Flip/Impulse Morphs, Spring 6DOF/6DOF/P2P/ConeTwist/Slider/Hinge Joint records,
140
+ and all Soft Body Config/Cluster/Iteration/Material/Anchor/Pin fields. This
141
+ evidence currently comes from independent synthetic fixed-byte fixtures; no
142
+ redistributable real PMX 2.1 corpus is claimed.
143
+
144
+ PMX binary modes are explicit and keyword-only, so existing positional calls
145
+ remain compatible:
146
+
147
+ ```python
148
+ # Complete model or IncompletePmxError
149
+ model = pypmxvmd.load_pmx("model.pmx", mode="strict")
150
+
151
+ # Diagnostic model plus section/EOF evidence
152
+ result = pypmxvmd.load_pmx("model.pmx", mode="partial")
153
+
154
+ # Canonical PMX 2.0/2.1 output
155
+ pypmxvmd.write_pmx(model, "output.pmx", mode="canonical")
156
+
157
+ # Source-backed fixed-width editing
158
+ document = pypmxvmd.load_pmx_document("model.pmx")
159
+ document.model.bones[0].deform_layer = 1
160
+ pypmxvmd.write_pmx(document, "patched.pmx", mode="lossless_patch")
161
+
162
+ # Transactional editing of an existing Bone record, including variable layouts
163
+ document = pypmxvmd.load_pmx_document("model.pmx")
164
+ editor = document.edit_bones()
165
+ editor.set_deform_layer(0, 2)
166
+ editor.set_tail_offset(0, [0.0, 1.0, 0.0])
167
+ editor.write_file("bone-edited.pmx")
168
+
169
+ # Transactional editing of an existing Rigid Body record
170
+ editor = document.edit_rigid_bodies()
171
+ editor.set_bone(0, -1) # legal no-Bone sentinel
172
+ editor.set_collision(0, collision_group=0, collision_mask=0xFFFE)
173
+ editor.set_physical_parameters(0, mass=1.0, friction=0.5)
174
+ editor.write_file("rigid-body-edited.pmx")
175
+
176
+ # Transactional editing of an existing PMX 2.0 Spring 6DOF Joint
177
+ editor = document.edit_joints()
178
+ editor.set_rigid_body_references(0, -1, 1)
179
+ editor.set_rotation_limits(0, [-0.5, -0.25, -0.1], [0.5, 0.25, 0.1])
180
+ editor.set_rotation_spring(0, [0.2, 0.3, 0.4])
181
+ editor.write_file("joint-edited.pmx")
182
+
183
+ # Transactional editing of an existing Material record
184
+ editor = document.edit_materials()
185
+ editor.set_diffuse_color(0, [0.8, 0.6, 0.5, 1.0])
186
+ editor.sync_ambient_from_diffuse(0) # explicit; never happens on ordinary save
187
+ editor.set_shared_toon(0, 0) # built-in toon01.bmp
188
+ editor.write_file("material-edited.pmx")
189
+ ```
190
+
191
+ `document`/field-span reads and fixed-width `lossless_patch` writes are available
192
+ for selected directly mapped Material, Bone, Rigid Body, and Joint fields. Every patch is
193
+ range/before-byte checked, strict-reparsed, and compared against the edited model.
194
+ The Bone, Rigid Body, Joint, and Material transactions below can rebuild their
195
+ existing variable-length records. Other variable-length fields, record
196
+ insertion/deletion, global index renumbering, and PMX 2.1-specific high-level
197
+ editing remain unsupported; `preserve_layout` also remains unsupported.
198
+ Lossless mode never silently falls back to canonical output.
199
+
200
+ Legacy fixed-width consumers can migrate one allowlisted operation at a time
201
+ without adding a runtime dependency in this package. Objects that provide the
202
+ existing `PatchRecord.to_dict()` shape are accepted directly. Use
203
+ `write_legacy_patches(..., mode="dual")` to require byte-for-byte agreement
204
+ between the old algorithm and the registered `PmxDocument` engine before an
205
+ atomic output, then change the explicit mode to `document` for single-write
206
+ cutover. `legacy` remains the rollback mode. All modes reject the source path
207
+ and existing targets unless overwrite is explicitly allowed. The current
208
+ allowlist remains PMX 2.0 `bones[*].parent_index`; other Rebuilder patch
209
+ families fail closed pending field-span and semantic approval.
210
+
211
+ `PmxBoneEditor` additionally supports all PMX 2.0 fields of existing Bone
212
+ records: variable-length names, position/parent/deform layer, basic flags, both
213
+ tail modes, inheritance, fixed/local axes, external parent, and IK links/limits.
214
+ It rebuilds only changed Bone records, validates the complete model, strict-
215
+ reparses the result, and writes atomically. Bone insertion, deletion, replacement,
216
+ reordering, and global index renumbering remain unsupported and fail closed.
217
+
218
+ `PmxRigidBodyEditor` supports all fields of existing PMX 2.0 Rigid Body
219
+ records: variable-length names, Bone reference including `-1`, three shapes and
220
+ physics modes, raw collision group/mask, size/position/rotation in source units,
221
+ and all five physical parameters. It rebuilds only changed records and preserves
222
+ existing Joint index semantics. Rigid Body insertion, deletion, replacement, and
223
+ reordering remain unsupported and fail closed.
224
+
225
+ `PmxJointEditor` supports every field of existing PMX 2.0 Spring 6DOF Joint
226
+ records: variable-length names, the A/B Rigid Body references including `-1`,
227
+ position/rotation, translation/rotation min/max limits, and both spring vectors.
228
+ Rotation values remain raw radians. Limit setters require component-wise
229
+ `minimum <= maximum`; unchanged legacy source axes are preserved. Joint insertion,
230
+ deletion, replacement, reordering, and PMX 2.1 Joint types remain unsupported.
231
+
232
+ `PmxMaterialEditor` supports every serialized field of existing PMX 2.0
233
+ Material records: variable-length names/comments, colors, all eight draw flags,
234
+ edge settings, Texture/Sphere/Toon modes and references, and face-index counts.
235
+ Texture display paths remain derived from the serialized indices. Face counts
236
+ are updated as one validated collection, and ambient/diffuse synchronization is
237
+ an explicit command only. Material or texture-table insertion, deletion,
238
+ replacement, and reordering remain unsupported.
239
+
240
+ ### Text Format Conversion
241
+
242
+ PyPMXVMD supports converting binary files to readable text format for viewing and editing:
243
+
244
+ ```python
245
+ import pypmxvmd
246
+
247
+ # VMD -> Text
248
+ motion = pypmxvmd.load_vmd("motion.vmd")
249
+ pypmxvmd.save_vmd_text(motion, "motion.txt")
250
+
251
+ # Text -> VMD
252
+ motion = pypmxvmd.load_vmd_text("motion.txt")
253
+ pypmxvmd.save_vmd(motion, "motion.vmd")
254
+
255
+ # PMX -> Text
256
+ model = pypmxvmd.load_pmx("model.pmx")
257
+ pypmxvmd.save_pmx_text(model, "model.txt")
258
+
259
+ # VPD -> Text
260
+ pose = pypmxvmd.load_vpd("pose.vpd")
261
+ pypmxvmd.save_vpd_text(pose, "pose.txt")
262
+ ```
263
+
264
+ ### Using Parser Classes
265
+
266
+ If you need more control, you can use the parser classes directly:
267
+
268
+ ```python
269
+ from pypmxvmd import VmdParser, PmxParser, VpdParser
270
+
271
+ # VMD Parser
272
+ vmd_parser = VmdParser()
273
+ motion = vmd_parser.parse_file("motion.vmd", more_info=True)
274
+ vmd_parser.write_file(motion, "output.vmd")
275
+
276
+ # PMX Parser
277
+ pmx_parser = PmxParser()
278
+ model = pmx_parser.parse_file("model.pmx", more_info=True)
279
+ pmx_parser.write_file(model, "canonical-model.pmx")
280
+
281
+ # VPD Parser
282
+ vpd_parser = VpdParser()
283
+ pose = vpd_parser.parse_file("pose.vpd", more_info=True)
284
+ vpd_parser.write_file(pose, "output.vpd")
285
+ ```
286
+
287
+ ## Data Structures
288
+
289
+ ### VmdMotion (VMD Motion)
290
+
291
+ ```python
292
+ class VmdMotion:
293
+ header: VmdHeader # File header information
294
+ bone_frames: List[VmdBoneFrame] # Bone keyframes
295
+ morph_frames: List[VmdMorphFrame] # Morph keyframes
296
+ camera_frames: List[VmdCameraFrame] # Camera keyframes
297
+ light_frames: List[VmdLightFrame] # Light keyframes
298
+ shadow_frames: List[VmdShadowFrame] # Shadow keyframes
299
+ ik_frames: List[VmdIkFrame] # IK keyframes
300
+ ```
301
+
302
+ ### PmxModel (PMX Model)
303
+
304
+ ```python
305
+ class PmxModel:
306
+ header: PmxHeader # File header information
307
+ vertices: List[PmxVertex] # Vertex list
308
+ faces: List[int] # Face indices
309
+ textures: List[str] # Texture paths
310
+ materials: List[PmxMaterial] # Material list
311
+ bones: List[PmxBone] # Bone list
312
+ morphs: List[PmxMorph] # Morph list
313
+ frames: List[PmxFrame] # Display frames
314
+ rigidbodies: List[PmxRigidBody] # Rigidbody list
315
+ joints: List[PmxJoint] # Joint list
316
+ ```
317
+
318
+ ### VpdPose (VPD Pose)
319
+
320
+ ```python
321
+ class VpdPose:
322
+ model_name: str # Model name
323
+ bone_poses: List[VpdBonePose] # Bone pose list
324
+ morph_poses: List[VpdMorphPose] # Morph pose list
325
+ ```
326
+
327
+ ## API Reference
328
+
329
+ ### Core Functions
330
+
331
+ | Function | Description |
332
+ |------|------|
333
+ | `load_vmd(path)` | Load VMD file |
334
+ | `save_vmd(motion, path)` | Save VMD file |
335
+ | `load_pmx(path)` | Load PMX file |
336
+ | `load_pmx(path, mode="partial")` | Load PMX with completeness evidence |
337
+ | `load_pmx_document(path)` | Load exact source bytes and fixed-field spans |
338
+ | `save_pmx(model, path)` | Save PMX file |
339
+ | `write_pmx(model, path, mode="canonical")` | Canonical PMX writer |
340
+ | `write_pmx(document, path, mode="lossless_patch")` | Audited fixed-field patch |
341
+ | `adapt_legacy_patches(document, records)` | Map approved legacy fixed-width records |
342
+ | `dual_write_legacy_patches(document, records)` | Compare legacy and lossless outputs |
343
+ | `verify_legacy_patch_engines(document, records)` | Compare legacy and document engines without a mirrored model edit |
344
+ | `write_legacy_patches(document, records, path, mode="dual")` | Atomically run the legacy/dual/document migration stage |
345
+ | `load_vpd(path)` | Load VPD file |
346
+ | `save_vpd(pose, path)` | Save VPD file |
347
+ | `load(path)` | Auto-detect and load |
348
+ | `save(data, path)` | Auto-detect and save |
349
+
350
+ ### Text Format Functions
351
+
352
+ | Function | Description |
353
+ |------|------|
354
+ | `load_vmd_text(path)` | Load VMD from text |
355
+ | `save_vmd_text(motion, path)` | Save VMD as text |
356
+ | `load_pmx_text(path)` | Load PMX from text |
357
+ | `save_pmx_text(model, path)` | Save PMX as text |
358
+ | `load_vpd_text(path)` | Load VPD from text |
359
+ | `save_vpd_text(pose, path)` | Save VPD as text |
360
+ | `load_text(path)` | Auto-detect and load text |
361
+ | `save_text(data, path)` | Auto-detect and save text |
362
+
363
+ ## Project Structure
364
+
365
+ ```
366
+ pypmxvmd/ # Main package
367
+ __init__.py # Public API (load/save helpers)
368
+ common/ # Core implementation
369
+ io/ # Binary/text IO (+ Cython accel)
370
+ models/ # Data models (VMD/PMX/VPD)
371
+ parsers/ # Parsers (+ fast modules)
372
+ docs/ # Documentation
373
+ API.md # English API
374
+ API_CN.md # 中文 API
375
+ scripts/ # Build helpers
376
+ build_cython.py
377
+ build_wheels.py
378
+ tests/ # Tests + fixtures
379
+ ```
380
+
381
+
382
+ ## Testing
383
+
384
+ ```bash
385
+ # Run correctness tests, including a local corpus when present
386
+ uv run --python 3.11.12 --no-sync pytest -m "not benchmark" -ra
387
+
388
+ # Run the local PMX/VMD corpus only
389
+ uv run --python 3.11.12 --no-sync pytest -m corpus -ra
390
+
391
+ # Run coverage test
392
+ uv run --python 3.11.12 --no-sync pytest --cov=pypmxvmd --cov-report=html
393
+ ```
394
+
395
+ ## Development
396
+
397
+ ```bash
398
+ # Resolve and install the locked development environment
399
+ uv sync --group dev --python 3.11.12
400
+
401
+ # Code formatting and linting (including import sorting)
402
+ uv run --python 3.11.12 --no-sync ruff format --check pypmxvmd tests scripts
403
+ uv run --python 3.11.12 --no-sync ruff check pypmxvmd tests scripts
404
+
405
+ # Type checking
406
+ uv run --python 3.11.12 --no-sync ty check pypmxvmd
407
+
408
+ # Build sdist and the platform wheel
409
+ uv build
410
+ ```
411
+
412
+ ## Changelog
413
+
414
+ ### v2.7.1
415
+ - Updated core parsers and binary I/O with Cython fast paths
416
+ - Restored the Windows CPython 3.11 native wheel build
417
+ - Improved text format auto-detection and test coverage
418
+
419
+ ### v2.5.1
420
+ - Added optional Cython acceleration for core parsing and binary I/O
421
+ - Cython path averages ~3.7x faster than the previous implementation
422
+
423
+ ### v2.0.0 (2024)
424
+ - Complete refactor to object-oriented architecture
425
+ - Added complete type annotations
426
+ - Support for text format export/import
427
+ - Improved error handling and validation
428
+ - Added progress callback support
429
+
430
+ ### v1.x (Original)
431
+ - Based on Nuthouse01's original implementation
432
+ - Functional API
433
+
434
+ ## Acknowledgments
435
+
436
+ This project is refactored from the original MMD scripting tools by [Nuthouse01](https://github.com/Nuthouse01/PMX-VMD-Scripting-Tools).
437
+
438
+ ## License
439
+
440
+ MIT License - See [LICENSE](LICENSE) file for details
441
+
442
+ ## Contributing
443
+
444
+ Issues and Pull Requests are welcome!
445
+
446
+ 1. Fork this repository
447
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
448
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
449
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
450
+ 5. Create a Pull Request