From a8166afc177c3fec4bb33636ce5274d52097ffee Mon Sep 17 00:00:00 2001
From: ghostboats <106226990+ghostboats@users.noreply.github.com>
Date: Tue, 21 May 2024 11:01:48 -0500
Subject: [PATCH] remove pyton scriupts hope all is awell, worked right before
this, pushing to dev
---
.../scripts/python/add_icons_to_atlas.py | 257 ------------------
support_files/scripts/python/check_pil.py | 4 -
.../scripts/python/check_pythonnet.py | 4 -
support_files/scripts/python/check_wand.py | 14 -
4 files changed, 279 deletions(-)
delete mode 100644 support_files/scripts/python/add_icons_to_atlas.py
delete mode 100644 support_files/scripts/python/check_pil.py
delete mode 100644 support_files/scripts/python/check_pythonnet.py
delete mode 100644 support_files/scripts/python/check_wand.py
diff --git a/support_files/scripts/python/add_icons_to_atlas.py b/support_files/scripts/python/add_icons_to_atlas.py
deleted file mode 100644
index c56e474a..00000000
--- a/support_files/scripts/python/add_icons_to_atlas.py
+++ /dev/null
@@ -1,257 +0,0 @@
-import os
-import subprocess
-from dataclasses import dataclass
-from pathlib import Path
-import argparse
-import timeit
-
-# External
-from PIL import Image
-import numpy
-
-atlas_template = """
-
-
-
-
- {icons}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-"""
-
-@dataclass
-class UV():
- u1:float
- v1:float
- u2:float
- v2:float
-
-@dataclass
-class Icon():
- image_path:Path
- pos:tuple[float,float]
- uv:UV
- image:Image.Image = None
-
- @property
- def name(self):
- return self.image_path.stem
-
- def __post_init__(self):
- self.image = Image.open(self.image_path).convert("RGBA")
-
- def to_xml(self):
- return """
-
-
-
-
-
-
- """.format(
- name = self.name,
- u1 = self.uv.u1,
- v1 = self.uv.v1,
- u2 = self.uv.u2,
- v2 = self.uv.v2
- )
-
-def get_images(directory):
- dir_path = Path(directory)
- files = dir_path.glob("*.png")
- return list(files)
-
-def truncate(number, digits, round_num = True) -> float:
- stepper = 10.0 ** digits
- if round_num:
- return round(numpy.trunc(stepper * number) / stepper, digits - 1)
- else:
- return numpy.trunc(stepper * number) / stepper
-
-script_dir = Path(os.path.dirname(os.path.abspath(__file__)))
-os.chdir(script_dir)
-
-totalIcons = 0
-
-texture_resource_template = """
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-"""
-
-
-
-def get_icons(icons_dir:Path, icon_size:tuple[int,int], texture_size:tuple[int,int])->list[Icon]:
- icons = []
- padding = (float(0.5/texture_size[0]), float(0.5/texture_size[1]))
- col_max = texture_size[0] / icon_size[0]
- row_max = texture_size[1] / icon_size[1]
-
- x = 0
- y = 0
-
- icons_first = []
- images = get_images(icons_dir)
- for img in images:
- round_num = True
- truncate_u1 = 7
- truncate_v1 = 8
- truncate_u2 = 7
- truncate_v2 = 7
-
- if x <= 1 and y == 0:
- u1 = truncate(numpy.clip(float(((icon_size[0] * x) / texture_size[0]) + padding[0]), 0, 1.0), 9, round_num=True)
- v1 = truncate(numpy.clip(float(((icon_size[1] * y) / texture_size[0]) + padding[0]), 0, 1.0), 9, round_num=False)
- u2 = truncate(numpy.clip(float(((icon_size[0] * (x + 1)) / texture_size[1]) - padding[1]), 0, 1.0), 7, round_num=False)
- v2 = truncate(numpy.clip(float(((icon_size[1] * (y + 1)) / texture_size[1]) - padding[1]), 0, 1.0), 7, round_num=False)
- else:
- u1 = truncate(numpy.clip(float(((icon_size[0] * x) / texture_size[0]) + padding[0]), 0, 1.0), truncate_u1, round_num)
- v1 = truncate(numpy.clip(float(((icon_size[1] * y) / texture_size[0]) + padding[0]), 0, 1.0), truncate_v1, round_num)
- u2 = truncate(numpy.clip(float(((icon_size[0] * (x + 1)) / texture_size[1]) - padding[1]), 0, 1.0), truncate_u2, round_num)
- v2 = truncate(numpy.clip(float(((icon_size[1] * (y + 1)) / texture_size[1]) - padding[1]), 0, 1.0), truncate_v2, round_num)
-
- icon = Icon(img.resolve(), (x * icon_size[0], y * icon_size[1]), UV(u1, v1, u2, v2))
-
- if x <= 1 and y == 0:
- icons_first.append(icon)
- else:
- icons.append(icon)
-
- x += 1
- if(x >= col_max):
- y += 1
- x = 0
- if (y > row_max):
- break
-
- icons.extend(icons_first)
- return icons
-
-def generate_texture(icons:list[Icon], texture_output:Path, texture_size:tuple[int,int], dds_format:str = "DXT5", do_mipmaps:bool=False):
- temp_texture_png = texture_output.with_suffix(".png")
- texture_image = Image.new('RGBA', texture_size, (0, 0, 0, 0))
- for icon in icons:
- #texture_image.paste(icon.image, icon.pos, mask=0)
- texture_image.alpha_composite(icon.image, icon.pos)
-
-
- texture_image.save(temp_texture_png)
-
-
- # -m 1 disables mimaps
- command = f"texconv -m {12 if do_mipmaps else 1} -ft DDS -f {dds_format} -nologo -timing -y -o \"{texture_output.parent}\" \"{temp_texture_png.absolute()}\""
- p = subprocess.run(command,
- shell=True,
- universal_newlines=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
-
- if p.returncode == 0:
- os.remove(str(temp_texture_png.absolute()).replace("/", "\\"))
- return True
-
-def generate_atlas_lsx(icons:list[Icon], atlas_output:Path, texture_output:Path, atlas_uuid:str, icon_size:tuple[int,int], texture_size:tuple[int,int])->bool:
- if atlas_uuid is None or atlas_uuid == "":
- #atlas_uuid = common.NewUUID()
- atlas_uuid = '6b3e6d54-dd4d-4ff1-89e4-f131e68e9035'
-
- atlas_output = atlas_output.with_suffix(".lsx")
- texture_output = texture_output.with_suffix(".dds")
- root_data_dir = atlas_output.parent.parent.parent
-
- def create_atlas_output(icons_str, icon_w, icon_h,
- texture_path, uuid, texture_width, texture_height):
- return atlas_template.format(
- icons = icons_str,
- icon_w = icon_w,
- icon_h = icon_h,
- texture_path = texture_path,
- texture_uuid = uuid,
- texture_width = texture_width,
- texture_height = texture_height
- )
-
- icons_str = ""
- for icon in icons:
- icons_str += icon.to_xml()
-
- atlas_output.parent.mkdir(exist_ok=True, parents=True)
- texture_output.parent.mkdir(exist_ok=True, parents=True)
-
- xml_str = create_atlas_output(icons_str, icon_size[0], icon_size[1],
- texture_output.relative_to(root_data_dir), atlas_uuid, texture_size[0], texture_size[1])
-
- f = open(atlas_output, "w")
- f.write(xml_str)
-
-if __name__ == "__main__":
- parser = argparse.ArgumentParser(description='Create a texture atlas from a folder of icons.')
- parser.add_argument("-i", "--icons", type=Path, required=True, help='The directory of icons to process.')
- parser.add_argument("-a", "--atlas", type=Path, required=True, help='The path of the atlas file to create, such as Public/ModName_UUID/GUI/MyAtlas.lsx.')
- parser.add_argument("-t", "--texture", type=Path, required=True, help='The path of the texture to create.')
- parser.add_argument("-u", "--uuid", type=str, default="", help='The UUID to use for the atlas (defaults to a new UUID4).')
- parser.add_argument("-m", "--mipmaps", action='store_true', help='Generate mipmaps (default False).')
- parser.add_argument("-f", "--ddsformat", type=str, default="DXT5", help='The dds format to use (DXT1, DXT5 etc). Defaults to DXT5 (BC3_UNORM).')
- parser.add_argument("-r", "--resource", type=Path, help='The path to content texture resource lsf to generate (optional). This requires --divine to be set, or a LSLIB_PATH environment variable to be set.')
- parser.add_argument("--resourcelsx", type=Path, help='Optional path to output the content resource to, in lsx format.')
- parser.add_argument("--ddstool", type=Path, help='The path to the "DirectXTex texture processing library" (directory where texconv is).')
- parser.add_argument("--iconsize", type=int, default=(64,64), nargs="+", help='The icon width/height/.')
- parser.add_argument("--texturesize", type=int, default=(2048,2048), nargs="+", help='The texture width/height/.')
- parser.add_argument("--divine", type=Path, help="The path to divine.exe.")
- parser.usage = f"""
- Example usage:
- python create_atlas.py -i "G:/Modding/BG3/Mods/MyMod/Icons" -a "C:/BG3/Data/Public/MyModFolder/GUI/MyMod_Icons.lsx" -u 6bae909c-1736-48e7-ae19-314b3aa7b1f5 -t "C:/BG3/Data/Public/MyModFolder/Assets/Textures/Icons/MyMod_Icons.dds" --ddstool "C:/Portable/DirectXTex" --texturesize 1024 1024
- """
- def run_cmd():
- args = parser.parse_args()
- icons_dir:Path = args.icons
- atlas_output:Path = args.atlas
- texture_output:Path = args.texture
- atlas_uuid:str = args.uuid
- dds_format:str = args.ddsformat
- icon_size:tuple[int,int] = args.iconsize
- texture_size:tuple[int,int] = args.texturesize
- do_mipmaps:bool = args.mipmaps
- icons = get_icons(icons_dir, icon_size, texture_size)
- global totalIcons
- totalIcons = len(icons)
- if totalIcons > 0:
- generate_atlas_lsx(icons, atlas_output, texture_output, atlas_uuid, icon_size, texture_size)
- generate_texture(icons, texture_output, texture_size, dds_format, do_mipmaps)
-
- print("Created atlas in {} seconds for {} icons.".format(timeit.timeit(run_cmd, number=1), totalIcons))
\ No newline at end of file
diff --git a/support_files/scripts/python/check_pil.py b/support_files/scripts/python/check_pil.py
deleted file mode 100644
index f7199daa..00000000
--- a/support_files/scripts/python/check_pil.py
+++ /dev/null
@@ -1,4 +0,0 @@
-try:
- import PIL
-except ImportError:
- print("PIL (Pillow) is not installed.")
\ No newline at end of file
diff --git a/support_files/scripts/python/check_pythonnet.py b/support_files/scripts/python/check_pythonnet.py
deleted file mode 100644
index faa46195..00000000
--- a/support_files/scripts/python/check_pythonnet.py
+++ /dev/null
@@ -1,4 +0,0 @@
-try:
- import clr
-except ImportError:
- print("clr is not installed")
\ No newline at end of file
diff --git a/support_files/scripts/python/check_wand.py b/support_files/scripts/python/check_wand.py
deleted file mode 100644
index 9fd76da9..00000000
--- a/support_files/scripts/python/check_wand.py
+++ /dev/null
@@ -1,14 +0,0 @@
-try:
- # Check if Wand package is installed
- import wand
-except ImportError:
- print("Wand not installed")
- exit()
-
-# Separate check for ImageMagick
-try:
- # Check if Wand image module works (requires ImageMagick)
- import wand.image
- print("Wand and ImageMagick are installed")
-except ImportError:
- print("ImageMagick not installed")