forked from JonnylikesJazz/Wadblender-Anim-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
277 lines (215 loc) · 7.87 KB
/
__init__.py
File metadata and controls
277 lines (215 loc) · 7.87 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
'''
Copyright (C) CURRENT_YEAR YOUR NAME
YOUR@MAIL.com
Created by YOUR NAME
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from dataclasses import dataclass
from bpy.types import Operator
from bpy.props import StringProperty, BoolProperty, EnumProperty, IntProperty
from bpy_extras.io_utils import ImportHelper
from . import model
from . import data
from . import read
from . import lara
from . import common
from . import objects
from . import movables
from . import statics
from . import developer_utils
from . import shinepanel
from . import export_anim
from . import import_anim
from .common import createMaterials
import importlib
import os
import bpy
bl_info = {
"name": "WAD Blender",
"description": "Import/Export Tomb Raider 4 WAD objects and animations (TRLE)",
"author": "veeti512",
"version": (0, 0, 10),
"blender": (2, 90, 1),
"location": "import.wad",
"warning": "This addon is still in development.",
"wiki_url": "",
"category": "Import-Export"}
# load and reload submodules
##################################
importlib.reload(developer_utils)
importlib.reload(movables)
importlib.reload(statics)
importlib.reload(common)
importlib.reload(lara)
importlib.reload(read)
importlib.reload(data)
importlib.reload(model)
modules = developer_utils.setup_addon_modules(
__path__, __name__, "bpy" in locals())
class Options:
filepath: str
wadname: str
path: str
scale: int
import_anims: bool
discard_junk: bool
export_fbx: bool
export_json: bool
create_nla: bool
export_obj: bool
rotate: bool
shinepanel.register()
# filepath, type, scale_setting, import_anims, discard_junk, export_fbx, export_json, create_nla):
def import_wad(context, type, options):
from importlib import reload
with open(options.filepath, "rb") as f:
wad = read.readWAD(f)
uvmap = bpy.data.images.new(
'textures', wad.mapwidth, wad.mapheight, alpha=True)
uvmap.pixels = wad.textureMap
texture_path = options.path + options.wadname + ".png"
bpy.data.images["textures"].save_render(texture_path)
materials = createMaterials(options.wadname, texture_path)
if type == 'OPT_A' or type == 'OPT_D':
# material_ids, path, wadname, wad, scale, import_anims, create_nla, export_fbx, export_json)
lara.main(materials, wad, options)
if type == 'OPT_B' or type == 'OPT_D':
# material_ids, path, wadname, wad, scale, import_anims, export_fbx, export_json, discard_junk, create_nla)
movables.main(materials, wad, options)
if type == 'OPT_C' or type == 'OPT_D':
# material_ids, path, wadname, wad, scale, export_fbx)
statics.main(materials, wad, options)
return set()
# ImportHelper is a helper class, defines filename and
# invoke() function which calls the file selector.
class ImportWAD(Operator, ImportHelper):
"""Load a Tomb Raider 4 WAD file"""
bl_idname = "import_test.some_data" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Import WAD"
# ImportHelper mixin class uses this
filename_ext = ".wad"
filter_glob: StringProperty(
default="*.wad;*.WAD",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
type: EnumProperty(
name="Import",
description="Choose between two items",
items=(
('OPT_A', "Lara", "Import all Lara objects"),
('OPT_B', "Movables", "Import all Movable objects"),
('OPT_C', "Statics", "Import all Static objects"),
('OPT_D', "Everything", "Import everything"),
),
default='OPT_D',
)
scale_setting: IntProperty(
name="Scale",
description="Dividing by 512, one TRLE click becomes 0.5 meters",
default=512,
min=1,
max=2048
)
import_anims: BoolProperty(
name="Import Animations",
description="Import Lara and Movables Animations",
default=True,
)
create_nla: BoolProperty(
name="Generate NLA tracks",
description="Generate NLA tracks to manipulate actions",
default=False,
)
discard_junk: BoolProperty(
name="Discard Placeholders",
description="Do not load triggers, particle emitters, AI, etc",
default=True,
)
rotate: BoolProperty(
name="Rotate objects upright",
description="Axis rotation for Unity",
default=True,
)
export_fbx: BoolProperty(
name="Export Objects and Animations (FBX)",
description="Export objects and animations in FBX format",
default=False,
)
export_obj: BoolProperty(
name="Export Objects (OBJ)",
description="Export objects and animations in OBJ format",
default=False,
)
export_json: BoolProperty(
name="Export Additional Data (JSON)",
description="Export additional wad data in json format",
default=False,
)
def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text='WAD Blender')
row = layout.row()
row.prop(self, "type")
row = layout.row()
row.prop(self, "scale_setting")
row = layout.row(align=True)
row.prop(self, "import_anims")
row = layout.row(align=True)
row.prop(self, "create_nla")
row = layout.row(align=True)
row.prop(self, "discard_junk")
row = layout.row(align=True)
row.prop(self, "rotate")
row = layout.row(align=True)
row.prop(self, "export_fbx")
row = layout.row(align=True)
row.prop(self, "export_obj")
row = layout.row(align=True)
row.prop(self, "export_json")
def execute(self, context):
options = Options()
options.filepath = self.filepath
options.wadname = os.path.basename(self.filepath)[:-4]
options.scale = int(self.scale_setting)
options.import_anims = self.import_anims
options.discard_junk = self.discard_junk
options.export_json = self.export_json
options.export_fbx = self.export_fbx
options.export_obj = self.export_obj
options.create_nla = self.create_nla
options.rotate = self.rotate
options.path, _ = os.path.split(options.filepath)
options.path += '\\'
# self.filepath, self.type, self.scale_setting, self.import_anims, self.discard_junk, self.export_fbx, self.export_json, self.create_nla)
return import_wad(context, self.type, options)
# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
self.layout.operator(ImportWAD.bl_idname,
text="Tomb Raider 4 WAD file (.wad)")
def register():
bpy.utils.register_class(ImportWAD)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
export_anim.register()
import_anim.register()
def unregister():
bpy.utils.unregister_class(ImportWAD)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
export_anim.unregister()
import_anim.unregister()
if __name__ == "__main__":
register()
# test call
bpy.ops.import_wad.objects('INVOKE_DEFAULT')