|
| 1 | +from asyncio.windows_events import NULL |
1 | 2 | import string
|
2 | 3 | import tkinter as tk
|
| 4 | +from turtle import st |
3 | 5 | import srctools
|
4 | 6 | import os
|
5 | 7 | import subprocess
|
@@ -393,6 +395,7 @@ def button_init():
|
393 | 395 | sdk.texture_menu.add_command(label="Build All Textures", command=build_all_texture)
|
394 | 396 | sdk.texture_menu.add_command(label="See Texture", command=open_vtf)
|
395 | 397 | 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) |
396 | 399 |
|
397 | 400 | sdk.model_menu.add_command(label="Build Model", command=build_model)
|
398 | 401 | sdk.model_menu.add_command(label="Build All Models", command=build_all_model)
|
@@ -712,6 +715,75 @@ def texture_to_tga():
|
712 | 715 | result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
713 | 716 | print(result)
|
714 | 717 |
|
| 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}") |
715 | 787 |
|
716 | 788 | # Replace these with your GitHub repository owner and name
|
717 | 789 | repo_owner = "ChocoScaff"
|
|
0 commit comments