-
Notifications
You must be signed in to change notification settings - Fork 3
/
halo1_model.py
162 lines (131 loc) · 4.01 KB
/
halo1_model.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import bpy
import os
from bpy.utils import register_class, unregister_class
from bpy.props import BoolProperty, FloatProperty, StringProperty, EnumProperty
from bpy_extras.io_utils import ImportHelper, ExportHelper, orientation_helper, path_reference_mode, axis_conversion
from ...halo1.model import (
read_halo1model,
import_halo1_nodes_from_jms,
import_halo1_markers_from_jms,
import_halo1_all_regions_from_jms,
)
from ...constants import SCALE_MULTIPLIERS
#@orientation_helper(axis_forward='-Z') Find the right value for this.
class MT_krieg_ImportHalo1Model(bpy.types.Operator, ImportHelper):
"""
The import operator for gbxmodel/jms models.
This stores the properties when inside of the import dialog, and
it specifies what to show on the side panel when importing.
"""
bl_idname = "import_scene.halo1_model"
bl_label = "Import Halo 1 Model"
bl_options = {'PRESET', 'UNDO'}
# Import-file-dialog settings:
filename_ext = ".gbxmodel"
filter_glob: StringProperty(
default="*.gbxmodel;*.model;*.jms",
options={'HIDDEN'},
)
# Node settings:
use_nodes: BoolProperty(
name="Import Nodes",
description="Import the nodes/frames.",
default=True,
)
node_size: FloatProperty(
name="Node Scene Size",
description="Set the size that nodes should have in the Blender scene if at 1.0 scale.",
default=0.1,
min=0.0,
)
use_armatures: BoolProperty(
name="Import Nodes as Armature",
description="Import the nodes as armature.",
default=False,
)
# Marker settings:
use_markers: BoolProperty(
name="Import Markers",
description="Import the markers.",
default=True,
)
marker_size: FloatProperty(
name="Marker Scene Size",
description="Set the size that markers should have in the Blender scene.",
default=0.05,
min=0.0,
)
# Scaling settings:
scale_enum: EnumProperty(
name="Scale",
items=(
('METRIC', "Blender", "Use Blender's metric scaling."),
('MAX', "3ds Max", "Use 3dsmax's 100xHalo scale."),
('HALO', "Internal", "Use Halo's internal 1.0 scale (small)."),
('CUSTOM', "Custom", "Set your own scaling multiplier."),
)
)
scale_float: FloatProperty(
name="Custom Scale",
description="Set your own scale.",
default=1.0,
min=0.0,
)
def execute(self, context):
# Set appropriate scaling
scale = 1.0
if self.scale_enum in SCALE_MULTIPLIERS:
scale = SCALE_MULTIPLIERS[self.scale_enum]
elif self.scale_enum == 'CUSTOM':
scale = self.scale_float
else:
raise ValueError('Invalid scale_enum state.')
# Test if jms import function doesn't crash.
jms = read_halo1model(self.filepath)
# Get name without path or file extension.
name = os.path.basename(os.path.splitext(self.filepath)[0])
# Import nodes into the scene.
armature, nodes = import_halo1_nodes_from_jms(jms, scale=scale, node_size=self.node_size)
# Import markers.
import_halo1_markers_from_jms(jms, scale=scale,
node_size=self.marker_size, armature=armature, scene_nodes=nodes)
import_halo1_all_regions_from_jms(jms, name=name, scale=scale, armature_obj=armature)
return {'FINISHED'}
def draw(self, context):
layout = self.layout
# Node settings elements:
box = layout.box()
row = box.row()
row.label(text="Nodes:")
row.prop(self, "use_nodes")
if self.use_nodes:
box.prop(self, "node_size")
box.prop(self, "use_armatures")
# Marker settings elements:
box = layout.box()
row = box.row()
row.label(text="Markers:")
row.prop(self, "use_markers")
if self.use_markers:
box.prop(self, "node_size")
# Scale settings elements:
box = layout.box()
box.label(text="Scale:")
row = box.row()
row.prop(self, "scale_enum", expand=True)
if self.scale_enum == 'CUSTOM':
row = box.row()
row.prop(self, "scale_float")
# Enumerate all classes for easy register/unregister.
classes = (
MT_krieg_ImportHalo1Model,
)
def register():
for cls in classes:
register_class(cls)
def unregister():
#Unregister classes in reverse order to avoid any dependency problems.
for cls in reversed(classes):
unregister_class(cls)
if __name__ == "__main__":
register()