pypmxvmd 2.6.1__cp313-cp313-win_amd64.whl

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 (41) hide show
  1. pypmxvmd/__init__.py +401 -0
  2. pypmxvmd/common/__init__.py +11 -0
  3. pypmxvmd/common/io/__init__.py +16 -0
  4. pypmxvmd/common/io/_fast_binary.c +19193 -0
  5. pypmxvmd/common/io/_fast_binary.cp311-win_amd64.pyd +0 -0
  6. pypmxvmd/common/io/_fast_binary.cp313-win_amd64.pyd +0 -0
  7. pypmxvmd/common/io/_fast_binary.cp38-win_amd64.pyd +0 -0
  8. pypmxvmd/common/io/_fast_binary.pyi +32 -0
  9. pypmxvmd/common/io/_fast_binary.pyx +264 -0
  10. pypmxvmd/common/io/binary_io.py +451 -0
  11. pypmxvmd/common/io/file_utils.py +293 -0
  12. pypmxvmd/common/io/text_io.py +299 -0
  13. pypmxvmd/common/models/__init__.py +18 -0
  14. pypmxvmd/common/models/base.py +168 -0
  15. pypmxvmd/common/models/pmx.py +633 -0
  16. pypmxvmd/common/models/vmd.py +350 -0
  17. pypmxvmd/common/models/vpd.py +111 -0
  18. pypmxvmd/common/parsers/__init__.py +16 -0
  19. pypmxvmd/common/parsers/_fast_pmx.c +16644 -0
  20. pypmxvmd/common/parsers/_fast_pmx.cp311-win_amd64.pyd +0 -0
  21. pypmxvmd/common/parsers/_fast_pmx.cp313-win_amd64.pyd +0 -0
  22. pypmxvmd/common/parsers/_fast_pmx.cp38-win_amd64.pyd +0 -0
  23. pypmxvmd/common/parsers/_fast_pmx.pyi +6 -0
  24. pypmxvmd/common/parsers/_fast_pmx.pyx +570 -0
  25. pypmxvmd/common/parsers/_fast_vmd.c +15477 -0
  26. pypmxvmd/common/parsers/_fast_vmd.cp311-win_amd64.pyd +0 -0
  27. pypmxvmd/common/parsers/_fast_vmd.cp313-win_amd64.pyd +0 -0
  28. pypmxvmd/common/parsers/_fast_vmd.cp38-win_amd64.pyd +0 -0
  29. pypmxvmd/common/parsers/_fast_vmd.pyi +6 -0
  30. pypmxvmd/common/parsers/_fast_vmd.pyx +463 -0
  31. pypmxvmd/common/parsers/pmx_parser.py +1398 -0
  32. pypmxvmd/common/parsers/pmx_parser_nuthouse.py +1320 -0
  33. pypmxvmd/common/parsers/vmd_parser.py +1569 -0
  34. pypmxvmd/common/parsers/vmd_parser_nuthouse.py +1092 -0
  35. pypmxvmd/common/parsers/vpd_parser.py +589 -0
  36. pypmxvmd/common/validators/__init__.py +7 -0
  37. pypmxvmd-2.6.1.dist-info/METADATA +315 -0
  38. pypmxvmd-2.6.1.dist-info/RECORD +41 -0
  39. pypmxvmd-2.6.1.dist-info/WHEEL +5 -0
  40. pypmxvmd-2.6.1.dist-info/entry_points.txt +2 -0
  41. pypmxvmd-2.6.1.dist-info/top_level.txt +1 -0
pypmxvmd/__init__.py ADDED
@@ -0,0 +1,401 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ PyPMXVMD - Python MikuMikuDance File Parser
4
+
5
+ A Python library for parsing and modifying MikuMikuDance (MMD) files:
6
+ - VMD (Vocaloid Motion Data) - Motion and animation data
7
+ - PMX (PolygonMoviemaker eXtended) - 3D model data
8
+ - VPD (Vocaloid Pose Data) - Pose/frame data
9
+
10
+ Usage:
11
+ import pypmxvmd
12
+
13
+ # Parse VMD motion file
14
+ motion = pypmxvmd.load_vmd("motion.vmd")
15
+ pypmxvmd.save_vmd(motion, "modified_motion.vmd")
16
+
17
+ # Parse PMX model file
18
+ model = pypmxvmd.load_pmx("model.pmx")
19
+ pypmxvmd.save_pmx(model, "modified_model.pmx")
20
+
21
+ # Parse VPD pose file
22
+ pose = pypmxvmd.load_vpd("pose.vpd")
23
+ pypmxvmd.save_vpd(pose, "modified_pose.vpd")
24
+ """
25
+
26
+ from pathlib import Path
27
+ from typing import Union
28
+
29
+ # Import parsers
30
+ from .common.parsers.vmd_parser import VmdParser
31
+ from .common.parsers.pmx_parser import PmxParser
32
+ from .common.parsers.vpd_parser import VpdParser
33
+
34
+ # Import models for type hints
35
+ from .common.models.vmd import VmdMotion
36
+ from .common.models.pmx import PmxModel
37
+ from .common.models.vpd import VpdPose
38
+
39
+ __version__ = "2.6.1"
40
+ __author__ = "PythonImporter"
41
+ __description__ = "Python MikuMikuDance File Parser"
42
+
43
+ # Core parser instances (reused for efficiency)
44
+ _vmd_parser = VmdParser()
45
+ _pmx_parser = PmxParser()
46
+ _vpd_parser = VpdParser()
47
+
48
+
49
+ def load_vmd(file_path: Union[str, Path], more_info: bool = False) -> VmdMotion:
50
+ """
51
+ Load VMD motion file.
52
+
53
+ Args:
54
+ file_path: Path to VMD file
55
+ more_info: Whether to include additional parsing information
56
+
57
+ Returns:
58
+ VmdMotion object
59
+
60
+ Raises:
61
+ FileNotFoundError: If file doesn't exist
62
+ ValueError: If file format is invalid
63
+ """
64
+ return _vmd_parser.parse_file(file_path, more_info=more_info)
65
+
66
+
67
+ def save_vmd(motion: VmdMotion, file_path: Union[str, Path]) -> None:
68
+ """
69
+ Save VMD motion to file.
70
+
71
+ Args:
72
+ motion: VmdMotion object to save
73
+ file_path: Output file path
74
+
75
+ Raises:
76
+ ValueError: If motion data is invalid
77
+ IOError: If file cannot be written
78
+ """
79
+ _vmd_parser.write_file(motion, file_path)
80
+
81
+
82
+ def load_pmx(file_path: Union[str, Path], more_info: bool = False) -> PmxModel:
83
+ """
84
+ Load PMX model file.
85
+
86
+ Args:
87
+ file_path: Path to PMX file
88
+ more_info: Whether to include additional parsing information
89
+
90
+ Returns:
91
+ PmxModel object
92
+
93
+ Raises:
94
+ FileNotFoundError: If file doesn't exist
95
+ ValueError: If file format is invalid
96
+ """
97
+ return _pmx_parser.parse_file(file_path, more_info=more_info)
98
+
99
+
100
+ def save_pmx(model: PmxModel, file_path: Union[str, Path]) -> None:
101
+ """
102
+ Save PMX model to file.
103
+
104
+ Args:
105
+ model: PmxModel object to save
106
+ file_path: Output file path
107
+
108
+ Raises:
109
+ ValueError: If model data is invalid
110
+ IOError: If file cannot be written
111
+ """
112
+ _pmx_parser.write_file(model, file_path)
113
+
114
+
115
+ def load_vpd(file_path: Union[str, Path], more_info: bool = False) -> VpdPose:
116
+ """
117
+ Load VPD pose file.
118
+
119
+ Args:
120
+ file_path: Path to VPD file
121
+ more_info: Whether to include additional parsing information
122
+
123
+ Returns:
124
+ VpdPose object
125
+
126
+ Raises:
127
+ FileNotFoundError: If file doesn't exist
128
+ ValueError: If file format is invalid
129
+ """
130
+ return _vpd_parser.parse_file(file_path, more_info=more_info)
131
+
132
+
133
+ def save_vpd(pose: VpdPose, file_path: Union[str, Path]) -> None:
134
+ """
135
+ Save VPD pose to file.
136
+
137
+ Args:
138
+ pose: VpdPose object to save
139
+ file_path: Output file path
140
+
141
+ Raises:
142
+ ValueError: If pose data is invalid
143
+ IOError: If file cannot be written
144
+ """
145
+ _vpd_parser.write_file(pose, file_path)
146
+
147
+
148
+ # Convenience functions for auto-detection
149
+ def load(file_path: Union[str, Path], more_info: bool = False):
150
+ """
151
+ Automatically detect file type and load appropriate format.
152
+
153
+ Args:
154
+ file_path: Path to file
155
+ more_info: Whether to include additional parsing information
156
+
157
+ Returns:
158
+ VmdMotion, PmxModel, or VpdPose object
159
+
160
+ Raises:
161
+ ValueError: If file type cannot be determined or is unsupported
162
+ """
163
+ path = Path(file_path)
164
+ suffix = path.suffix.lower()
165
+
166
+ if suffix == '.vmd':
167
+ return load_vmd(file_path, more_info)
168
+ elif suffix == '.pmx':
169
+ return load_pmx(file_path, more_info)
170
+ elif suffix == '.vpd':
171
+ return load_vpd(file_path, more_info)
172
+ else:
173
+ raise ValueError(f"Unsupported file type: {suffix}")
174
+
175
+
176
+ def save(data, file_path: Union[str, Path]) -> None:
177
+ """
178
+ Automatically detect data type and save in appropriate format.
179
+
180
+ Args:
181
+ data: VmdMotion, PmxModel, or VpdPose object
182
+ file_path: Output file path
183
+
184
+ Raises:
185
+ ValueError: If data type is unsupported
186
+ """
187
+ if isinstance(data, VmdMotion):
188
+ save_vmd(data, file_path)
189
+ elif isinstance(data, PmxModel):
190
+ save_pmx(data, file_path)
191
+ elif isinstance(data, VpdPose):
192
+ save_vpd(data, file_path)
193
+ else:
194
+ raise ValueError(f"Unsupported data type: {type(data)}")
195
+
196
+
197
+ # ===== 文本解析和导出功能 =====
198
+
199
+ def load_vmd_text(file_path: Union[str, Path], more_info: bool = False) -> VmdMotion:
200
+ """
201
+ Load VMD motion file from text format.
202
+
203
+ Args:
204
+ file_path: Path to VMD text file
205
+ more_info: Whether to include additional parsing information
206
+
207
+ Returns:
208
+ VmdMotion object
209
+
210
+ Raises:
211
+ FileNotFoundError: If file doesn't exist
212
+ ValueError: If file format is invalid
213
+ """
214
+ return _vmd_parser.parse_text_file(file_path, more_info=more_info)
215
+
216
+
217
+ def save_vmd_text(motion: VmdMotion, file_path: Union[str, Path]) -> None:
218
+ """
219
+ Save VMD motion to text file.
220
+
221
+ Args:
222
+ motion: VmdMotion object to save
223
+ file_path: Output text file path
224
+
225
+ Raises:
226
+ ValueError: If motion data is invalid
227
+ IOError: If file cannot be written
228
+ """
229
+ _vmd_parser.write_text_file(motion, file_path)
230
+
231
+
232
+ def load_pmx_text(file_path: Union[str, Path], more_info: bool = False) -> PmxModel:
233
+ """
234
+ Load PMX model file from text format.
235
+
236
+ Args:
237
+ file_path: Path to PMX text file
238
+ more_info: Whether to include additional parsing information
239
+
240
+ Returns:
241
+ PmxModel object
242
+
243
+ Raises:
244
+ FileNotFoundError: If file doesn't exist
245
+ ValueError: If file format is invalid
246
+ """
247
+ return _pmx_parser.parse_text_file(file_path, more_info=more_info)
248
+
249
+
250
+ def save_pmx_text(model: PmxModel, file_path: Union[str, Path]) -> None:
251
+ """
252
+ Save PMX model to text file.
253
+
254
+ Args:
255
+ model: PmxModel object to save
256
+ file_path: Output text file path
257
+
258
+ Raises:
259
+ ValueError: If model data is invalid
260
+ IOError: If file cannot be written
261
+ """
262
+ _pmx_parser.write_text_file(model, file_path)
263
+
264
+
265
+ def load_vpd_text(file_path: Union[str, Path], more_info: bool = False) -> VpdPose:
266
+ """
267
+ Load VPD pose file from structured text format.
268
+
269
+ Args:
270
+ file_path: Path to VPD text file (can be original VPD or structured text)
271
+ more_info: Whether to include additional parsing information
272
+
273
+ Returns:
274
+ VpdPose object
275
+
276
+ Raises:
277
+ FileNotFoundError: If file doesn't exist
278
+ ValueError: If file format is invalid
279
+ """
280
+ return _vpd_parser.parse_text_file(file_path, more_info=more_info)
281
+
282
+
283
+ def save_vpd_text(pose: VpdPose, file_path: Union[str, Path]) -> None:
284
+ """
285
+ Save VPD pose to structured text file.
286
+
287
+ Args:
288
+ pose: VpdPose object to save
289
+ file_path: Output text file path
290
+
291
+ Raises:
292
+ ValueError: If pose data is invalid
293
+ IOError: If file cannot be written
294
+ """
295
+ _vpd_parser.write_text_file(pose, file_path)
296
+
297
+
298
+ def load_text(file_path: Union[str, Path], more_info: bool = False):
299
+ """
300
+ Automatically detect text file type and load appropriate format.
301
+
302
+ Args:
303
+ file_path: Path to text file
304
+ more_info: Whether to include additional parsing information
305
+
306
+ Returns:
307
+ VmdMotion, PmxModel, or VpdPose object
308
+
309
+ Raises:
310
+ ValueError: If file type cannot be determined or is unsupported
311
+ """
312
+ path = Path(file_path)
313
+
314
+ # Try to detect format by reading first few lines
315
+ try:
316
+ with open(path, 'r', encoding='utf-8') as f:
317
+ first_lines = [f.readline().strip() for _ in range(3)]
318
+ except UnicodeDecodeError:
319
+ # Try shift_jis encoding for VPD files
320
+ with open(path, 'r', encoding='shift_jis') as f:
321
+ first_lines = [f.readline().strip() for _ in range(3)]
322
+
323
+ # Check for file format indicators
324
+ if any('version:' in line for line in first_lines):
325
+ if any('boneframe_ct:' in line or 'morphframe_ct:' in line for line in first_lines):
326
+ return load_vmd_text(file_path, more_info)
327
+ elif any('vertex_count:' in line for line in first_lines):
328
+ return load_pmx_text(file_path, more_info)
329
+ elif first_lines[0] == "Vocaloid Pose Data file" or any('model_name:' in line for line in first_lines):
330
+ return load_vpd_text(file_path, more_info)
331
+
332
+ # Fallback to file extension
333
+ suffix = path.suffix.lower()
334
+ if suffix == '.txt':
335
+ # Try VMD text format first (most common)
336
+ try:
337
+ return load_vmd_text(file_path, more_info)
338
+ except ValueError:
339
+ try:
340
+ return load_pmx_text(file_path, more_info)
341
+ except ValueError:
342
+ return load_vpd_text(file_path, more_info)
343
+ else:
344
+ raise ValueError(f"Cannot determine text file format for: {file_path}")
345
+
346
+
347
+ def save_text(data, file_path: Union[str, Path]) -> None:
348
+ """
349
+ Automatically detect data type and save in appropriate text format.
350
+
351
+ Args:
352
+ data: VmdMotion, PmxModel, or VpdPose object
353
+ file_path: Output text file path
354
+
355
+ Raises:
356
+ ValueError: If data type is unsupported
357
+ """
358
+ if isinstance(data, VmdMotion):
359
+ save_vmd_text(data, file_path)
360
+ elif isinstance(data, PmxModel):
361
+ save_pmx_text(data, file_path)
362
+ elif isinstance(data, VpdPose):
363
+ save_vpd_text(data, file_path)
364
+ else:
365
+ raise ValueError(f"Unsupported data type: {type(data)}")
366
+
367
+
368
+ # Export public API
369
+ __all__ = [
370
+ # Version info
371
+ '__version__',
372
+ '__author__',
373
+ '__description__',
374
+
375
+ # Binary file functions
376
+ 'load_vmd',
377
+ 'save_vmd',
378
+ 'load_pmx',
379
+ 'save_pmx',
380
+ 'load_vpd',
381
+ 'save_vpd',
382
+
383
+ # Text file functions
384
+ 'load_vmd_text',
385
+ 'save_vmd_text',
386
+ 'load_pmx_text',
387
+ 'save_pmx_text',
388
+ 'load_vpd_text',
389
+ 'save_vpd_text',
390
+
391
+ # Auto-detection functions
392
+ 'load',
393
+ 'save',
394
+ 'load_text',
395
+ 'save_text',
396
+
397
+ # Model classes (for type hints)
398
+ 'VmdMotion',
399
+ 'PmxModel',
400
+ 'VpdPose',
401
+ ]
@@ -0,0 +1,11 @@
1
+ """
2
+ PyPMXVMD 数据访问层
3
+
4
+ 负责文件I/O、数据持久化、格式转换等底层操作。
5
+ 包含数据模型、解析器、I/O工具和验证器。
6
+ """
7
+
8
+ from pypmxvmd.common.models import *
9
+ from pypmxvmd.common.parsers import *
10
+ from pypmxvmd.common.io import *
11
+ from pypmxvmd.common.validators import *
@@ -0,0 +1,16 @@
1
+ """
2
+ PyPMXVMD I/O操作模块
3
+
4
+ 提供文件读写、二进制数据处理等底层I/O功能。
5
+ 包含二进制文件操作、文本文件操作和通用文件工具。
6
+ """
7
+
8
+ from pypmxvmd.common.io.binary_io import BinaryIOHandler
9
+ from pypmxvmd.common.io.text_io import TextIOHandler
10
+ from pypmxvmd.common.io.file_utils import FileUtils
11
+
12
+ __all__ = [
13
+ "BinaryIOHandler",
14
+ "TextIOHandler",
15
+ "FileUtils",
16
+ ]