-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpmo_export_menu.py
More file actions
143 lines (116 loc) · 4.47 KB
/
pmo_export_menu.py
File metadata and controls
143 lines (116 loc) · 4.47 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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,
hard_tristripification: bool = False, split: bool = False, do_fix_vg: bool = False, use_mat_remaps: bool = False):
ver = P3RD_MODEL if version == "1.2" else FU_MODEL
pmo, _ = export_pmo.export(ver, target=target, prepare_pmo=prepare_pmo, cleanup_vg=cleanup_vg, apply_modifiers=apply_modifiers,
hard_tristripification=hard_tristripification, do_fix_vg=do_fix_vg, use_mat_remaps=use_mat_remaps)
if isinstance(pmo, int):
return {'CANCELLED'}
if split:
with open(filepath+"_header.pmo", 'wb') as f1, open(filepath+"_mesh.bin", 'wb') as f2:
pmo.save(f1, second=f2)
else:
with open(filepath, 'wb') as f:
pmo.save(f)
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"),
("simple", "Simple", "Just split seams and sharp edges"),
("*&", "*&'s", "Run *&'s script"),
("xenthos", "Xenthos'", "Run Xenthos' script"),
),
default="simple"
)
cleanup_vg: BoolProperty(
name="Clean Up VG",
description="Remove vertex group assignments wich are not required",
default=False
)
do_fix_vg: BoolProperty(
name="Merge Submeshes",
description="Attempts to reduce submeshes by merging them based on material and bones",
default=False
)
use_mat_remaps: BoolProperty(
name="Save Material Remap Data",
description="Save Material Remap Data (Always on for FU)",
default=False
)
apply_modifiers: BoolProperty(
name="Apply Modifiers",
description="Apply modifiers before exporting",
default=False
)
hard_tristripification: BoolProperty(
name="Hard Tristripification",
description="Create as few tristrips as possible",
default=False
)
split: BoolProperty(
name="Split Model",
description="Separate headers and mesh data.",
default=False
)
def execute(self, context):
return export(
context,
filepath=self.filepath,
version=self.type,
target=self.export_target,
prepare_pmo=self.prep_pmo,
cleanup_vg=self.cleanup_vg,
apply_modifiers=self.apply_modifiers,
hard_tristripification=self.hard_tristripification,
split=self.split,
do_fix_vg=self.do_fix_vg,
use_mat_remaps=self.use_mat_remaps
)
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()