| import argparse |
| from PIL import Image |
|
|
| def get_head_uvs(): |
| """ |
| Returns the (x, y, w, h) of each 2D texture block of the head. |
| """ |
| head_uvs = [] |
| |
| |
| part = [ |
| [ |
| [(8,8,8),(8,8)], |
| [(8,8,8),(24,8)], |
| [(8,8,8),(16,8)], |
| [(8,8,8),(0,8)], |
| [(8,8,8),(8,0)], |
| [(8,8,8),(16,0)], |
| ], (32,0) |
| ] |
| |
| decor_offset = part[1] |
| |
| for size_info, offset in part[0]: |
| |
| w, h = size_info[0], size_info[1] |
| |
| |
| head_uvs.append((offset[0], offset[1], w, h)) |
| |
| |
| decor_x = offset[0] + decor_offset[0] |
| decor_y = offset[1] + decor_offset[1] |
| head_uvs.append((decor_x, decor_y, w, h)) |
| |
| return head_uvs |
|
|
| def merge_skins(skin_a_path, skin_b_path, output_path): |
| |
| img_a = Image.open(skin_a_path).convert("RGBA") |
| img_b = Image.open(skin_b_path).convert("RGBA") |
| |
| |
| if img_a.size != img_b.size: |
| print(f"Warning: Skin A ({img_a.size}) and Skin B ({img_b.size}) sizes do not match.") |
| |
| |
| img_c = img_b.copy() |
| |
| |
| head_uvs = get_head_uvs() |
| |
| for x, y, w, h in head_uvs: |
| box = (x, y, x + w, y + h) |
| |
| |
| region_a = img_a.crop(box) |
| |
| |
| img_c.paste(region_a, box) |
|
|
| img_c.save(output_path) |
| print(f"Successfully merged: A's head ({skin_a_path}) + B's body/limbs ({skin_b_path}) -> {output_path}") |
|
|
| if __name__ == "__main__": |
| parser = argparse.ArgumentParser(description="Combine skins: Take the head of Skin A and the body and limbs of Skin B.") |
| parser.add_argument("skin_a", help="Path to Skin A (provides the head)") |
| parser.add_argument("skin_b", help="Path to Skin B (provides the body and limbs)") |
| parser.add_argument("-o", "--output", default="skin_c.png", help="Output path for Skin C") |
| args = parser.parse_args() |
| |
| merge_skins(args.skin_a, args.skin_b, args.output) |
|
|