-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpack_import.py
116 lines (94 loc) · 4.94 KB
/
pack_import.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
import bpy, os
from .importers.levelData_import import importLevelData
from .classes.pack import *
from .importers.meshAsset_import import construct_meshes
from .importers.materialAssets_import import construct_materials, extract_textures
imported_texturePacks = []
failed_texturePacks = []
imported_materialPacks = []
def clear_importLists():
imported_materialPacks.clear()
imported_texturePacks.clear()
def main(packFilePath, do_extract_textures, do_construct_materials, batch_size, addon_name):
pack_directory = os.path.dirname(os.path.abspath(packFilePath))
# meshPack
print("Parsing Mesh PACK file...", packFilePath)
with open(packFilePath, "rb") as packFile:
meshPack = Pack(packFile)
print("\nConstructing Blender Objects...")
construct_meshes(meshPack)
importLevelData(meshPack.levelData, addon_name)
# Import materials + textures
failedTexturesAssets = []
if do_extract_textures or do_construct_materials:
noesis_path = bpy.context.preferences.addons[addon_name].preferences.noesis_path
if not os.path.isfile(noesis_path):
print("Noesis path is not set or invalid. Cancelling texture import!")
return
# materialPacks
materialPacks = []
for path in meshPack.paths:
materialPackFilename = path.path.split('/')[-1]
materialPackFullPath = pack_directory + "\\" + materialPackFilename
if not os.path.isfile(materialPackFullPath):
if os.path.isfile(materialPackFullPath + ".xap"):
materialPackFullPath += ".xap"
else:
print("[!] Failed to find material PACK file:", materialPackFilename)
continue
if (materialPackFullPath not in imported_materialPacks):
imported_materialPacks.append(materialPackFullPath)
print("Parsing Material PACK file...", path.path)
with open(materialPackFullPath, "rb") as packFile:
materialPacks.append(Pack(packFile))
#texturePacks
texturePacks = []
for materialPack in materialPacks:
for path in materialPack.paths:
texturePackFilename = path.path.split('/')[-1]
texturePackFullPath = pack_directory + "\\" + texturePackFilename
if not os.path.isfile(texturePackFullPath):
if os.path.isfile(texturePackFullPath + ".xap"):
texturePackFullPath += ".xap"
else:
if (texturePackFullPath not in failed_texturePacks):
failed_texturePacks.append(texturePackFullPath)
print("[!] Failed to find texture PACK file.", texturePackFilename)
continue
if (texturePackFullPath not in imported_texturePacks):
imported_texturePacks.append(texturePackFullPath)
print("Parsing Texture PACK file...", path.path)
with open(texturePackFullPath, "rb") as packFile:
texturePacks.append(Pack(packFile))
if do_extract_textures:
failedTexturesAssets = extract_textures(pack_directory, texturePacks, noesis_path, batch_size)
if do_construct_materials:
construct_materials(pack_directory, materialPacks)
if len(failedTexturesAssets) > 0:
print("[!] Some textures failed to extract!")
print("Report this issue @ https://github.com/WoefulWolf/Replicant2Blender/issues")
print("Please include the unknown formats logged below and the path of the file you were trying to import.")
for assetFile in failedTexturesAssets:
texHead = assetFile.content.texHead
print(assetFile.name, hex(texHead.header.XonSurfaceFormat))
else:
print('Importing finished. ;)')
def only_extract_textures(packFilePath, batch_size, addon_name):
pack_directory = os.path.dirname(os.path.abspath(packFilePath))
noesis_path = bpy.context.preferences.addons[addon_name].preferences.noesis_path
if not os.path.isfile(noesis_path):
print("Noesis path is not set or invalid. Cancelling texture import!")
return {"FAILED"}
packFile = open(packFilePath, "rb")
texturePack = Pack(packFile)
packFile.close()
failedTexturesAssets = extract_textures(pack_directory, [texturePack], noesis_path, batch_size)
if len(failedTexturesAssets) > 0:
print("[!] Some textures failed to extract!")
print("Report this issue @ https://github.com/WoefulWolf/Replicant2Blender/issues")
print("Please include the unknown formats logged below and the path of the file you were trying to import.")
for assetFile in failedTexturesAssets:
texHead = assetFile.content.texHead
print(assetFile.name, "0x"+(texHead.header.XonSurfaceFormat).hex())
else:
print('Extraction finished. ;)')