From 8f1b3855ef8775162e463a5187fd08142d2835de Mon Sep 17 00:00:00 2001 From: zanncdwbl Date: Mon, 3 Nov 2025 23:44:34 +0000 Subject: [PATCH 1/2] Fix bleedover when packing textures (thread linked) https://discord.com/channels/667753182608359424/1435035464070463621/1435035464070463621 --- DEV.md | 2 +- deppth2/deppth2.py | 2 +- deppth2/texpacking.py | 130 +++++++++++++++++++++--------------------- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/DEV.md b/DEV.md index 6b6a09c..8d1d7e5 100644 --- a/DEV.md +++ b/DEV.md @@ -1,4 +1,4 @@ python -m build --wheel python setup.py bdist_wheel -pip install .\dist\deppth2-0.1.5.0-py3-none-any.whl \ No newline at end of file +pip install .\dist\deppth2-0.1.6.0-py3-none-any.whl diff --git a/deppth2/deppth2.py b/deppth2/deppth2.py index 23fcc7e..dbed175 100644 --- a/deppth2/deppth2.py +++ b/deppth2/deppth2.py @@ -1,6 +1,6 @@ """Top-level API exposure of package actions""" -__version__ = "0.1.5.0" +__version__ = "0.1.6.0" import os import sys diff --git a/deppth2/texpacking.py b/deppth2/texpacking.py index d425f16..e95541b 100644 --- a/deppth2/texpacking.py +++ b/deppth2/texpacking.py @@ -35,14 +35,14 @@ def build_atlases(source_dir, target_dir, basename, size, include_hulls=False): return (hulls, namemap) -def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls=False, logger=lambda s: None, codec='RGBA'): - """ +def build_atlases_hades(source_dir, target_dir, deppth_pack=True, include_hulls=False, logger=lambda s: None, codec='RGBA'): + """ Build texture atlases from images within a source directory. Args: source_dir (str): The root directory to recursively search for images. target_dir (str): The target directory where the atlases will be saved. The atlases filenames will be named after the target directory name. The .pkg file too. (If created) - deppth2_pack (bool, optional): If True, automatically call pack for putting the built atlases into a SGG .pkg file. Defaults to True. + deppth_pack (bool, optional): If True, automatically call pack for putting the built atlases into a SGG .pkg file. Defaults to True. include_hulls (bool, optional): If True, computes convex hull points of images and includes them in the atlas data. Defaults to False. logger (callable, optional): A logging function that accepts a single string argument. @@ -50,77 +50,77 @@ def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls Returns: None - """ - - print(target_dir) - basename = os.path.splitext(os.path.basename(target_dir))[0] - print(basename) - - # Regex check to make sure user inserts a mod guid type basename - regexpattern = r"^[a-z0-9]+(\w+[a-z0-9])?-\w+$" - - if re.match(regexpattern, basename, flags=re.I|re.A): - pass - else: - print("Please provide a target with your mod guid, example ThunderstoreTeamName-Modname") - return - - if os.path.isdir(target_dir) == True: - print(f"Target directory {target_dir} already exists, deleting it.") - shutil.rmtree(target_dir) + """ + + print(target_dir) + basename = os.path.splitext(os.path.basename(target_dir))[0] + print(basename) + + # Regex check to make sure user inserts a mod guid type basename + regexpattern = r"^[a-z0-9]+(\w+[a-z0-9])?-\w+$" - os.mkdir(target_dir, 0o666) - os.mkdir(os.path.join(target_dir, "manifest"), 0o666) - os.mkdir(os.path.join(target_dir, "textures"), 0o666) - os.mkdir(os.path.join(target_dir, "textures", "atlases"), 0o666) - - files = find_files(source_dir) - hulls = {} - namemap = {} - for filename in files: - # Build hulls for each image so we can store them later - if include_hulls: - hulls[filename.name] = get_hull_points(filename) + if re.match(regexpattern, basename, flags=re.I|re.A): + pass else: - hulls[filename.name] = [] - namemap[filename.name] = str(filename) - - # Perfom the packing. This will create the spritesheets and primitive atlases, which we'll need to turn to usable ones - packer = PyTexturePacker.Packer.create(max_width=4096, max_height=4096, bg_color=0x00000000, atlas_format='json', - enable_rotated=False, trim_mode=1, border_padding=0, shape_padding=0) - packer.pack(files, f'{basename}%d') - - # Now, loop through the atlases made and transform them to be the right format - index = 0 - atlases = [] - manifest_paths = [] # Manifest Path Start - while os.path.exists(f'{basename}{index}.json'): - atlases.append(transform_atlas(target_dir, basename, f'{basename}{index}.json', namemap, hulls, source_dir, manifest_paths)) - os.remove(f'{basename}{index}.json') - index += 1 - - # Now, loop through the atlas images made and move them to the package folder - index = 0 - while os.path.exists(f'{basename}{index}.png') or os.path.exists(f'{basename}{index}.dds'): - try: - os.rename(f'{basename}{index}.png', os.path.join(target_dir, "textures", "atlases", f'{basename}{index}.png')) - except: - pass - try: - os.rename(f'{basename}{index}.dds', os.path.join(target_dir, "textures", "atlases", f'{basename}{index}.dds')) - except: - pass - index += 1 + print("Please provide a target with your mod guid, example ThunderstoreTeamName-Modname") + return + + if os.path.isdir(target_dir) == True: + print(f"Target directory {target_dir} already exists, deleting it.") + shutil.rmtree(target_dir) + + os.mkdir(target_dir, 0o666) + os.mkdir(os.path.join(target_dir, "manifest"), 0o666) + os.mkdir(os.path.join(target_dir, "textures"), 0o666) + os.mkdir(os.path.join(target_dir, "textures", "atlases"), 0o666) + + files = find_files(source_dir) + hulls = {} + namemap = {} + for filename in files: + # Build hulls for each image so we can store them later + if include_hulls: + hulls[filename.name] = get_hull_points(filename) + else: + hulls[filename.name] = [] + namemap[filename.name] = str(filename) + + # Perfom the packing. This will create the spritesheets and primitive atlases, which we'll need to turn to usable ones + packer = PyTexturePacker.Packer.create(max_width=2880, max_height=2880, bg_color=0x00000000, atlas_format='json', + enable_rotated=False, trim_mode=1, border_padding=0, shape_padding=1) + packer.pack(files, f'{basename}%d') + + # Now, loop through the atlases made and transform them to be the right format + index = 0 + atlases = [] + manifest_paths = [] # Manifest Path Start + while os.path.exists(f'{basename}{index}.json'): + atlases.append(transform_atlas(target_dir, basename, f'{basename}{index}.json', namemap, hulls, source_dir, manifest_paths)) + os.remove(f'{basename}{index}.json') + index += 1 + + # Now, loop through the atlas images made and move them to the package folder + index = 0 + while os.path.exists(f'{basename}{index}.png') or os.path.exists(f'{basename}{index}.dds'): + try: + os.rename(f'{basename}{index}.png', os.path.join(target_dir, "textures", "atlases", f'{basename}{index}.png')) + except: + pass + try: + os.rename(f'{basename}{index}.dds', os.path.join(target_dir, "textures", "atlases", f'{basename}{index}.dds')) + except: + pass + index += 1 # Create the packages - if deppth2_pack: + if deppth_pack: from .deppth2 import pack pack(target_dir, f'{target_dir}.pkg', *[], logger=lambda s: print(s), codec=codec) # print the manifest paths, so its easy to see the game path - print("\nManifest Paths - Use in Codebase:") + print("\nManifest Paths, _PLUGIN.guid followed by directory paths - Use in Codebase:\n") for path in manifest_paths: - print(path, "\n") + print(path) @requires('scipy.spatial') def get_hull_points(path): From 5c8b7a32fbb52678c93e95d6d0a59e75ce8579c4 Mon Sep 17 00:00:00 2001 From: zanncdwbl Date: Tue, 4 Nov 2025 00:52:09 +0000 Subject: [PATCH 2/2] set max_height back to 4k --- deppth2/texpacking.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deppth2/texpacking.py b/deppth2/texpacking.py index e95541b..4aa1f28 100644 --- a/deppth2/texpacking.py +++ b/deppth2/texpacking.py @@ -35,14 +35,14 @@ def build_atlases(source_dir, target_dir, basename, size, include_hulls=False): return (hulls, namemap) -def build_atlases_hades(source_dir, target_dir, deppth_pack=True, include_hulls=False, logger=lambda s: None, codec='RGBA'): +def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls=False, logger=lambda s: None, codec='RGBA'): """ Build texture atlases from images within a source directory. Args: source_dir (str): The root directory to recursively search for images. target_dir (str): The target directory where the atlases will be saved. The atlases filenames will be named after the target directory name. The .pkg file too. (If created) - deppth_pack (bool, optional): If True, automatically call pack for putting the built atlases into a SGG .pkg file. Defaults to True. + deppth2_pack (bool, optional): If True, automatically call pack for putting the built atlases into a SGG .pkg file. Defaults to True. include_hulls (bool, optional): If True, computes convex hull points of images and includes them in the atlas data. Defaults to False. logger (callable, optional): A logging function that accepts a single string argument. @@ -86,7 +86,7 @@ def build_atlases_hades(source_dir, target_dir, deppth_pack=True, include_hulls= namemap[filename.name] = str(filename) # Perfom the packing. This will create the spritesheets and primitive atlases, which we'll need to turn to usable ones - packer = PyTexturePacker.Packer.create(max_width=2880, max_height=2880, bg_color=0x00000000, atlas_format='json', + packer = PyTexturePacker.Packer.create(max_width=4096, max_height=4096, bg_color=0x00000000, atlas_format='json', enable_rotated=False, trim_mode=1, border_padding=0, shape_padding=1) packer.pack(files, f'{basename}%d') @@ -113,7 +113,7 @@ def build_atlases_hades(source_dir, target_dir, deppth_pack=True, include_hulls= index += 1 # Create the packages - if deppth_pack: + if deppth2_pack: from .deppth2 import pack pack(target_dir, f'{target_dir}.pkg', *[], logger=lambda s: print(s), codec=codec)