This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
forked from WoefulWolf/NieR2Blender_2_8
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
147 lines (122 loc) · 6.49 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
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
bl_info = {
"name": "AstralChain2Blender (Astral Chain Model Importer)",
"author": "Cabalex and Woeful_Wolf (Original by C4nf3ng)",
"version": (2, 2),
"blender": (2, 80, 0),
"api": 38019,
"location": "File > Import",
"description": "Import Astral Chain 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 ImportAstralChain(bpy.types.Operator, ImportHelper):
'''Load an Astral Chain WMB File.'''
bl_idname = "import_scene.wmb_data_ac"
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 ImportCOLAstralChain(bpy.types.Operator, ImportHelper):
'''Load an Astral Chain COL File.'''
bl_idname = "import_scene.col_data_ac"
bl_label = "Import COL Data"
bl_options = {'PRESET'}
filename_ext = ".col"
filter_glob: StringProperty(default="*.col", options={'HIDDEN'})
reset_blend: bpy.props.BoolProperty(name="Reset Blender Scene on Import", default=True)
def execute(self, context):
from . import col_importer
from .wmb_importer import reset_blend
if self.reset_blend:
reset_blend()
return col_importer.main(False, self.filepath)
class ImportDATAstralChain(bpy.types.Operator, ImportHelper):
'''Load an Astral Chain DTT (and DAT) File.'''
bl_idname = "import_scene.dtt_data_ac"
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:
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 + '\\astralchain2blender_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 + '\\astralchain2blender_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
# WARNING: If there are other WTP files here, then it will detect the wrong one.
wmb_filepath = extract_dir + '\\' + tailless_tail + '.dtt\\' + tailless_tail + '.wmb'
if not os.path.exists(wmb_filepath):
wmb_filepath = extract_dir + '\\' + tailless_tail + '.dat\\' + tailless_tail + '.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 ac_menu_func_import(self, context):
self.layout.operator(ImportAstralChain.bl_idname, text="WMB File for Astral Chain (.wmb)")
def ac_menu_func_import_dat(self, context):
self.layout.operator(ImportDATAstralChain.bl_idname, text="DTT File for Astral Chain (.dtt)")
def ac_menu_func_import_col(self, context):
self.layout.operator(ImportCOLAstralChain.bl_idname, text="COL File for Astral Chain (.col)")
def register():
bpy.utils.register_class(ImportAstralChain)
bpy.utils.register_class(ImportDATAstralChain)
bpy.utils.register_class(ImportCOLAstralChain)
bpy.types.TOPBAR_MT_file_import.append(ac_menu_func_import)
bpy.types.TOPBAR_MT_file_import.append(ac_menu_func_import_dat)
bpy.types.TOPBAR_MT_file_import.append(ac_menu_func_import_col)
def unregister():
bpy.utils.unregister_class(ImportAstralChain)
bpy.utils.unregister_class(ImportDATAstralChain)
bpy.utils.unregister_class(ImportCOLAstralChain)
bpy.types.TOPBAR_MT_file_import.remove(ac_menu_func_import)
bpy.types.TOPBAR_MT_file_import.remove(ac_menu_func_import_dat)
bpy.types.TOPBAR_MT_file_import.remove(ac_menu_func_import_col)
if __name__ == '__main__':
register()