Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unreal atlas #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Gizmos/T_UI_Giz_Battery.TGA
Binary file not shown.
Binary file added Gizmos/T_UI_Giz_Charge.TGA
Binary file not shown.
Binary file added Gizmos/T_UI_Giz_Power.TGA
Binary file not shown.
Binary file added Gizmos/T_UI_Giz_SignalHigh.TGA
Binary file not shown.
Binary file added Gizmos/T_UI_Giz_SignalLow.TGA
Binary file not shown.
Binary file added Gizmos/T_UI_Giz_SignalMid.TGA
Binary file not shown.
23 changes: 22 additions & 1 deletion PyTexturePacker/PackerInterface/AtlasInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
AtlasInterface.py
----------------------------------------------------------------------------"""

from ..Utils import ATLAS_FORMAT_PLIST, ATLAS_FORMAT_JSON
from ..Utils import ATLAS_FORMAT_PLIST, ATLAS_FORMAT_JSON,ATLAS_FORMAT_UNREAL_PAPER2D

MAX_RANK = 2 ** 32
MAX_WIDTH = 1024 * 16
Expand Down Expand Up @@ -80,6 +80,17 @@ def dump_plist(self, texture_file_name="", input_base_path=None, atlas_format=AT
sourceSize=dict(w=image_rect.source_size[0], h=image_rect.source_size[1])
)

if atlas_format == ATLAS_FORMAT_UNREAL_PAPER2D:
frames[path] = dict(
frame=dict(x=image_rect.x, y=image_rect.y, w=width, h=height),
rotated=bool(image_rect.rotated),
trimed=bool(image_rect.trimmed),
spriteSourceSize=dict(
x=image_rect.source_box[0], y=image_rect.source_box[1],
w=image_rect.source_box[2], h=image_rect.source_box[3]),
sourceSize=dict(w=image_rect.source_size[0], h=image_rect.source_size[1])
)

plist_data["frames"] = frames
if atlas_format == ATLAS_FORMAT_PLIST:
plist_data["metadata"] = dict(
Expand All @@ -96,6 +107,16 @@ def dump_plist(self, texture_file_name="", input_base_path=None, atlas_format=AT
size=dict(w=self.size[0], h=self.size[1]),
scale=1,
)
if atlas_format == ATLAS_FORMAT_UNREAL_PAPER2D:
plist_data["meta"] = dict(
app="https://www.codeandweb.com/texturepacker",
target="paper2d",
image=texture_file_name,
format="RGBA8888",
size=dict(w=self.size[0], h=self.size[1]),
scale=1,
)


return plist_data

Expand Down
2 changes: 1 addition & 1 deletion PyTexturePacker/PackerInterface/PackerInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PackerInterface(object):

def __init__(self, bg_color=0x00000000, texture_format=".png", max_width=4096, max_height=4096, enable_rotated=True,
force_square=False, border_padding=2, shape_padding=2, inner_padding=0, trim_mode=0,
reduce_border_artifacts=False, extrude=0, atlas_format=Utils.ATLAS_FORMAT_PLIST):
reduce_border_artifacts=False, extrude=0, atlas_format=Utils.ATLAS_FORMAT_UNREAL_PAPER2D):
"""
init a packer
:param bg_color: background color of output image.
Expand Down
19 changes: 18 additions & 1 deletion PyTexturePacker/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
if sys.version_info.major > 2:
xrange = range

SUPPORTED_IMAGE_FORMAT = [".png", ".jpg", ".bmp"]
SUPPORTED_IMAGE_FORMAT = [".png", ".jpg", ".bmp", '.tga']
ATLAS_FORMAT_PLIST = "plist"
ATLAS_FORMAT_JSON = "json"
ATLAS_FORMAT_UNREAL_PAPER2D = "unreal_paper2d"


def load_images_from_paths(image_path_list):
Expand Down Expand Up @@ -62,6 +63,8 @@ def get_atlas_data_ext(atlas_format):
return '.plist'
if atlas_format == ATLAS_FORMAT_JSON:
return '.json'
if atlas_format == ATLAS_FORMAT_UNREAL_PAPER2D:
return ".paper2dsprites"


def save_atlas_data(data_dict, file_path, atlas_format):
Expand All @@ -76,6 +79,8 @@ def save_atlas_data(data_dict, file_path, atlas_format):
return save_plist(data_dict, file_path)
if atlas_format == ATLAS_FORMAT_JSON:
return save_json(data_dict, file_path)
if atlas_format == ATLAS_FORMAT_UNREAL_PAPER2D:
return save_unreal_paper2d(data_dict, file_path)


def save_json(data_dict, file_path):
Expand All @@ -90,6 +95,18 @@ def save_json(data_dict, file_path):
json.dump(data_dict, fp)


def save_unreal_paper2d(data_dict, file_path):
"""
save a dict as a unreal json file
:param data_dict: dict data
:param file_path: json file path to save
:return:
"""
import json
with open(file_path, 'w') as fp:
json.dump(data_dict, fp)


def save_plist(data_dict, file_path):
"""
save a dict as a plist file
Expand Down
15 changes: 13 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
Description:
main.py
----------------------------------------------------------------------------"""
import os

import click
from PyTexturePacker import Packer


Expand All @@ -17,10 +19,19 @@ def pack_test():
packer = Packer.create(max_width=2048, max_height=2048, bg_color=0xffffff00)
# pack texture images under the directory "test_case/" and name the output images as "test_case".
# "%d" in output file name "test_case%d" is a placeholder, which is a multipack index, starting with 0.
packer.pack("test_image/", "test_image%d", "")
packer.pack("Gizmos/", "Gizmos%d", "")


def main():
def pack(source):
source = os.path.normpath(source)
for root, ds, fs in os.walk(source):
if len(fs) > 0:
dir_name = root.split('\\')[-1]
packer = Packer.create(max_width=2048, max_height=2048, bg_color=0xffffff00)
packer.pack(root, dir_name, root)


def main(source):
pack_test()


Expand Down