-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmo_export_menu.py
100 lines (77 loc) · 2.95 KB
/
pmo_export_menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import bpy
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator
from . import export_pmo
FU_MODEL = b'1.0\x00'
P3RD_MODEL = b'102\x00'
def export(context, filepath: str, version: str, target: str = 'scene', prepare_pmo: str = "none", cleanup_vg: bool = False, apply_modifiers: bool = False):
ver = P3RD_MODEL if version == "1.2" else FU_MODEL
pmo = export_pmo.export(ver, target, prepare_pmo, cleanup_vg, apply_modifiers)
if not isinstance(pmo, int):
f = open(filepath, 'wb')
pmo.save(f)
f.close()
return {'FINISHED'}
class ExportPmo(Operator, ExportHelper):
"""Export Monster Hunter PMO models."""
bl_idname = "export_mh.pmo"
bl_label = "Export PMO"
filename_ext = ".pmo"
filter_glob: StringProperty(
default="*.pmo",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
type: EnumProperty(
name="Format Version",
description="Choose pmo format version",
items=(
('1.0', "MHFU", "Export MHFU models"),
('1.2', "MHP3rd", "Export MHP3rd models"),
),
default='1.2',
)
export_target: EnumProperty(
name="Export target",
description="Select target for exporting",
items=(
("scene", "Scene", "Export all mesh objects in the scene"),
("visible", "Visible", "Export all visible mesh objects"),
("selection", "Selection", "Export all selected mesh objects"),
("active", "Active", "Export active mesh object")
),
default="visible",
)
prep_pmo: EnumProperty(
name="Prepare PMO",
description="Triangulate mesh and split vertex for normals/uvs. (Same as pressing 'Prepare PMO' but won't have a permanent effect on the model)",
items=(
("none", "None", "Do not run any prep script"),
("*&", "*&'s", "Run *&'s script"),
("xenthos", "Xenthos'", "Run Xenthos' script"),
),
default="none"
)
cleanup_vg: BoolProperty(
name="Clean Up VG",
description="Remove vertex group assignments wich are not required",
default=False
)
apply_modifiers: BoolProperty(
name="Apply Modifiers",
description="Apply modifiers before exporting",
default=False
)
def execute(self, context):
return export(context, self.filepath, self.type, self.export_target, self.prep_pmo, self.cleanup_vg, self.apply_modifiers)
def menu_func_export(self, context):
self.layout.operator(ExportPmo.bl_idname, text="PSP MH PMO")
def register():
bpy.utils.register_class(ExportPmo)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(ExportPmo)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()