This repository has been archived by the owner on Aug 27, 2023. It is now read-only.
forked from C4nf3ng/Nier2Blender
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path__init__.py
122 lines (101 loc) · 5.41 KB
/
__init__.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
bl_info = {
"name": "NieR2Blender (NieR:Automata Model Importer)",
"author": "Woeful_Wolf (Original by C4nf3ng)",
"version": (2, 2),
"blender": (2, 80, 0),
"api": 38019,
"location": "File > Import",
"description": "Import Nier:Automata Model Data",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Import-Export"}
import bpy
import os
from bpy_extras.io_utils import ExportHelper,ImportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
class ImportNier2blender(bpy.types.Operator, ImportHelper):
'''Load a Nier:Automata WMB File.'''
bl_idname = "import_scene.wmb_data"
bl_label = "Import WMB Data"
bl_options = {'PRESET'}
filename_ext = ".wmb"
filter_glob: StringProperty(default="*.wmb", options={'HIDDEN'})
reset_blend: bpy.props.BoolProperty(name="Reset Blender Scene on Import", default=True)
def execute(self, context):
from . import wmb_importer
if self.reset_blend:
wmb_importer.reset_blend()
return wmb_importer.main(False, self.filepath)
class ImportDATNier2blender(bpy.types.Operator, ImportHelper):
'''Load a Nier:Automata DTT (and DAT) File.'''
bl_idname = "import_scene.dtt_data"
bl_label = "Import DTT (and DAT) Data"
bl_options = {'PRESET'}
filename_ext = ".dtt"
filter_glob: StringProperty(default="*.dtt", options={'HIDDEN'})
reset_blend: bpy.props.BoolProperty(name="Reset Blender Scene on Import", default=True)
bulk_import: bpy.props.BoolProperty(name="Bulk Import All DTT/DATs In Folder (Experimental)", default=False)
only_extract: bpy.props.BoolProperty(name="Only Extract DTT/DAT Contents. (Experimental)", default=False)
def execute(self, context):
from . import wmb_importer
if self.reset_blend and not self.only_extract:
wmb_importer.reset_blend()
if self.bulk_import:
folder = os.path.split(self.filepath)[0]
for filename in os.listdir(folder):
if filename[-4:] == '.dtt':
try:
filepath = folder + '\\' + filename
head = os.path.split(filepath)[0]
tail = os.path.split(filepath)[1]
tailless_tail = tail[:-4]
dat_filepath = head + '\\' + tailless_tail + '.dat'
extract_dir = head + '\\nier2blender_extracted'
from . import dat_unpacker
if os.path.isfile(dat_filepath):
dat_unpacker.main(dat_filepath, extract_dir + '\\' + tailless_tail + '.dat', dat_filepath) # dat
else:
print('DAT not found. Only extracting DTT. (No materials will automatically be imported)')
wtp_filename = dat_unpacker.main(filepath, extract_dir + '\\' + tailless_tail + '.dtt', filepath) # dtt
wmb_filepath = extract_dir + '\\' + tailless_tail + '.dtt\\' + wtp_filename[:-4] + '.wmb'
if not os.path.exists(wmb_filepath):
wmb_filepath = extract_dir + '\\' + tailless_tail + '.dat\\' + wtp_filename[:-4] + '.wmb' # if not in dtt, then must be in dat
wmb_importer.main(self.only_extract, wmb_filepath)
except:
print('ERROR: FAILED TO IMPORT', filename)
return {'FINISHED'}
else:
head = os.path.split(self.filepath)[0]
tail = os.path.split(self.filepath)[1]
tailless_tail = tail[:-4]
dat_filepath = head + '\\' + tailless_tail + '.dat'
extract_dir = head + '\\nier2blender_extracted'
from . import dat_unpacker
if os.path.isfile(dat_filepath):
dat_unpacker.main(dat_filepath, extract_dir + '\\' + tailless_tail + '.dat', dat_filepath) # dat
else:
print('DAT not found. Only extracting DTT. (No materials will automatically be imported)')
wtp_filename = dat_unpacker.main(self.filepath, extract_dir + '\\' + tailless_tail + '.dtt', self.filepath) # dtt
wmb_filepath = extract_dir + '\\' + tailless_tail + '.dtt\\' + wtp_filename[:-4] + '.wmb'
if not os.path.exists(wmb_filepath):
wmb_filepath = extract_dir + '\\' + tailless_tail + '.dat\\' + wtp_filename[:-4] + '.wmb' # if not in dtt, then must be in dat
from . import wmb_importer
return wmb_importer.main(self.only_extract, wmb_filepath)
# Registration
def menu_func_import(self, context):
self.layout.operator(ImportNier2blender.bl_idname, text="WMB File for Nier:Automata (.wmb)")
def menu_func_import_dat(self, context):
self.layout.operator(ImportDATNier2blender.bl_idname, text="DTT File for Nier:Automata (.dtt)")
def register():
bpy.utils.register_class(ImportNier2blender)
bpy.utils.register_class(ImportDATNier2blender)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import_dat)
def unregister():
bpy.utils.unregister_class(ImportNier2blender)
bpy.utils.unregister_class(ImportDATNier2blender)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import_dat)
if __name__ == '__main__':
register()