Skip to content

Commit 5b88d13

Browse files
committed
add generate vmt
1 parent b24ac39 commit 5b88d13

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

sourceSDK++.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from asyncio.windows_events import NULL
12
import string
23
import tkinter as tk
4+
from turtle import st
35
import srctools
46
import os
57
import subprocess
@@ -393,6 +395,7 @@ def button_init():
393395
sdk.texture_menu.add_command(label="Build All Textures", command=build_all_texture)
394396
sdk.texture_menu.add_command(label="See Texture", command=open_vtf)
395397
sdk.texture_menu.add_command(label="Texture To TGA", command=texture_to_tga)
398+
sdk.texture_menu.add_command(label="Generate vmt", command=generate_vmt)
396399

397400
sdk.model_menu.add_command(label="Build Model", command=build_model)
398401
sdk.model_menu.add_command(label="Build All Models", command=build_all_model)
@@ -712,6 +715,75 @@ def texture_to_tga():
712715
result = subprocess.run(command, shell=True, capture_output=True, text=True)
713716
print(result)
714717

718+
def generate_vmt():
719+
720+
filenameVMTs = filedialog.askopenfilenames(title="Select .vtf file", filetypes=[("texture file", "*.vtf")], initialdir=sdk.selected_folder + "/materials")
721+
722+
diffuse_texture = NULL
723+
normal_texture = NULL
724+
if len(filenameVMTs) == 1:
725+
print(filenameVMTs)
726+
vtfName = str(filenameVMTs)
727+
print(vtfName)
728+
diffuse_texture = vtfName[:-3]
729+
else:
730+
for vmt in filenameVMTs:
731+
print(vmt)
732+
if "diffuse" in vmt.lower():
733+
diffuse_texture = vmt
734+
elif "normal" in vmt.lower():
735+
normal_texture = vmt
736+
737+
popup = tk.Toplevel(root)
738+
popup.title("shader Selector")
739+
740+
shaders = ["LightmappedGeneric", "VertexLitGeneric", "WorldVertexTransition", "UnlitGeneric", "Sky"]
741+
742+
selected_shaderTK = tk.StringVar()
743+
744+
def select_shader(shader):
745+
selected_shaderTK.set(shader)
746+
popup.destroy()
747+
748+
for shader in shaders:
749+
button = tk.Button(popup, text=shader, command=lambda m=shader: select_shader(m))
750+
button.pack()
751+
752+
popup.wait_window()
753+
754+
selected_shader = selected_shaderTK.get()
755+
756+
vmt="""
757+
"shader"
758+
{
759+
"$basetexture" "texture_diffuse"
760+
"$normalmap" "texture_normal"
761+
}
762+
"""
763+
vmt = vmt.replace("shader",selected_shader)
764+
765+
diffuse_texture = diffuse_texture[diffuse_texture.find("/materials/") + 11:]
766+
vmt = vmt.replace("texture_diffuse",diffuse_texture)
767+
if normal_texture != NULL:
768+
normal_texture = normal_texture[normal_texture.find("/materials/") + 11:]
769+
vmt = vmt.replace("texture_normal",normal_texture)
770+
else:
771+
vmt = vmt.replace('"$normalmap" "texture_normal"',"")
772+
773+
print(vmt)
774+
775+
fileVMT = sdk.selected_folder + "/materials/" + diffuse_texture[:-4] + ".vmt"
776+
fileVMT = str(fileVMT)
777+
fileVMT = fileVMT.replace("_diffuse", "")
778+
779+
print(fileVMT)
780+
781+
try:
782+
with open(fileVMT, 'w') as file:
783+
file.write(vmt)
784+
print(f"String saved to '{fileVMT}' successfully.")
785+
except Exception as e:
786+
print(f"Error: {e}")
715787

716788
# Replace these with your GitHub repository owner and name
717789
repo_owner = "ChocoScaff"

0 commit comments

Comments
 (0)