-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtn-dff-bon-to-blend-separate-per-mtn.py
106 lines (78 loc) · 3.11 KB
/
mtn-dff-bon-to-blend-separate-per-mtn.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
import bpy
import os
from DragonFF.ops import dff_importer
from io_scene_sth_mtn import import_sth_bon, import_sth_mtn
def cleanup():
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
for collection in bpy.data.collections:
bpy.context.scene.collection.children.unlink(collection)
bpy.data.collections.remove(collection)
bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)
def find_bon_root_armature(collection):
for obj in collection.objects:
## TODO: Find a way to find what to match to, its not necessarily going to match the filename
## The target name is always at 0x10 in the .bon file read!
if obj.name == "DevilDoom.bon":
return obj
return None
target_dff_name = "DEVILDOOM.DFF"
dff_parent = "C:\\Users\\user\\Desktop\\_TARGET\\"
dff_path = "C:\\Users\\user\\Desktop\\_TARGET\\" + target_dff_name
bon_path = "C:\\Users\\user\\Desktop\\_TARGET\\DEVILDOOM.BON"
mtn_directory = "C:\\Users\\user\\Desktop\\_TARGET\\MTN"
mtn_output = mtn_directory + "\\out"
os.makedirs(mtn_output, exist_ok=True)
mtns = [f for f in os.listdir(mtn_directory) if f.endswith('.MTN')]
options = {
'file_name' : dff_path,
'image_ext' : 'PNG',
'connect_bones' : False,
'use_mat_split' : False,
'remove_doubles' : False,
'group_materials': False,
'import_normals' : True
}
apply_bone_names = True
bake_action = True
create_nla_track = True
cleanup()
### Export once without any mtns
base_model_export = os.path.join(dff_parent, os.path.splitext(target_dff_name)[0] + '.blend')
### DFF Import ###
dff_importer.import_dff(options)
### BON Import ###
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
if obj.type == 'ARMATURE':
obj.select_set(True)
bpy.ops.import_scene.sth_bon(filepath=bon_path, apply_bone_names=apply_bone_names)
### Export mtnless model
bpy.ops.wm.save_as_mainfile(filepath=base_model_export)
### Export all mtns separately
for mtn in mtns:
input_path = os.path.join(mtn_directory, mtn)
output_path = os.path.join(mtn_output, os.path.splitext(mtn)[0] + '.blend')
cleanup()
### DFF Import ###
dff_importer.import_dff(options)
### BON Import ###
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.data.objects:
if obj.type == 'ARMATURE':
obj.select_set(True)
bpy.ops.import_scene.sth_bon(filepath=bon_path, apply_bone_names=apply_bone_names)
### MTN Import ###
bpy.ops.object.select_all(action='DESELECT')
# Start the search from the root level collections
for collection in bpy.data.collections:
bon_root_armature = find_bon_root_armature(collection)
if bon_root_armature:
# Set the armature as the active object
bpy.context.view_layer.objects.active = bon_root_armature
# Select the armature
bon_root_armature.select_set(True)
break
import_sth_mtn.load(bpy.context, input_path, bake_action, create_nla_track)
bpy.ops.wm.save_as_mainfile(filepath=output_path)
cleanup()