Skip to content

Commit 48f69d7

Browse files
committed
Add texture to tga
1 parent 8549357 commit 48f69d7

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

file.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ def show_context_menu(self, event):
268268
elif file_extension == ".mdl":
269269
decompiler = Decompiler(self.sdk)
270270
self.context_menu.add_command(label="Decompile Model", command=lambda: decompiler.decompiler_file(file=file_path))
271-
271+
elif file_extension == ".vtf":
272+
texture = Texture(self.sdk)
273+
self.context_menu.add_command(label="Compile to tga", command=lambda: texture.texture_to_tga(file_path))
274+
272275
self.context_menu.add_command(label="Delete", command=lambda: self.delete_file(file_path, selected_item))
273276

274277
self.context_menu.post(event.x_root, event.y_root)

fileListApp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ def show_context_menu(self, event, file_path):
220220
elif file_extension == ".mdl":
221221
decompiler = Decompiler(self.sdk)
222222
self.context_menu.add_command(label="Decompile Model", command=lambda: decompiler.decompiler_file(file=file_path))
223+
elif file_extension == ".vtf":
224+
texture = Texture(self.sdk)
225+
self.context_menu.add_command(label="Compile to tga", command=lambda: texture.texture_to_tga(file_path))
223226

224227
self.context_menu.add_command(label="Delete", command=lambda: self.delete_file(file_path))
225228

texture.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,28 @@ def open_VTF(self,file=""):
8181
command = '"' + os.getcwd() + "/VTFEdit/x64/VTFEdit.exe" + '" ' + '"' + file + '"'
8282
subprocess.Popen(command)
8383

84-
def texture_to_tga(self):
84+
def texture_to_tga(self, file=None, output=None):
8585
"""
86+
Converts a .vtf file to a .tga file using vtf2tga.exe.
87+
88+
Parameters:
89+
file (str): Path to the input .vtf file. If not provided, a file dialog will prompt the user to select a file.
90+
output (str): Directory where the output .tga file will be saved. If not provided, a directory dialog will prompt the user to select a directory.
91+
92+
Returns:
93+
None
8694
"""
95+
if file == None:
96+
filenameVTF = filedialog.askopenfile(title="Select .vtf file", filetypes=[("VTF file", "*.vtf")], initialdir=self.sdk.selected_folder + "/materials")
97+
file = filenameVTF.name
98+
99+
if output == None:
100+
outputDir = filedialog.askdirectory(title="Select a Directory",initialdir=self.sdk.selected_folder + "/materialsrc")
101+
102+
base_name = os.path.splitext(os.path.basename(file))[0]
103+
output_file = os.path.join(outputDir, base_name + ".tga")
87104

88-
filenameVTF = filedialog.askopenfile(title="Select .vtf file", filetypes=[("VTF file", "*.vtf")], initialdir=self.sdk.selected_folder + "/materials")
89-
command = '"' + self.sdk.bin_folder + "/vtf2tga.exe" + '"'+ " -i " + '"' + filenameVTF.name + '"'
105+
command = f'"{self.sdk.bin_folder}/vtf2tga.exe" -i "{file}" -o "{output_file}"'
90106
result = subprocess.run(command, shell=True, capture_output=True, text=True)
91107
print(result)
92108

0 commit comments

Comments
 (0)