32 lines
914 B
Python
32 lines
914 B
Python
import json
|
|
from os import PathLike
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
|
|
from image_assembler import ImageAssembler
|
|
|
|
json_dir = Path('C:\\extracts\\MonoBehaviour')
|
|
atlas_dir = Path('C:\\extracts\\Texture2D')
|
|
output_dir = Path('./output')
|
|
|
|
|
|
def assemble_json(json_file: PathLike):
|
|
with open(json_file) as f:
|
|
metadata = json.load(f)
|
|
|
|
for image in metadata['textureDataList']:
|
|
# TODO try-catch Image.open
|
|
atlas = Image.open(atlas_dir / (image['atlasName'] + '.png'))
|
|
assembler = ImageAssembler(image, atlas, metadata['cellSize'], metadata['padding'])
|
|
assembler.paint()
|
|
output = assembler.get_output()
|
|
|
|
output.save(output_dir / (image['name'] + '.png'), 'PNG')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
for item in json_dir.iterdir():
|
|
if item.is_file() and (str(item)).endswith('.json'):
|
|
print(item)
|
|
assemble_json(item)
|