Datasets:
EntropyDrop commited on
Commit ·
5bbe62a
1
Parent(s): da271e5
v73
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitignore +2 -0
- alice_to_steve.py +18 -0
- build_target_img.py +300 -0
- build_target_imgs.py +40 -0
- control_imgs/.DS_Store +0 -0
- control_imgs/0042.png +3 -0
- control_imgs/12.png +3 -0
- control_imgs/17474.png +3 -0
- control_imgs/1ed2b9af-0722-4869-8685-294610976cb5.png +3 -0
- control_imgs/222855.png +3 -0
- control_imgs/408097.png +3 -0
- control_imgs/49ed3dbc-2d35-491c-b995-be54c59ab423.png +3 -0
- control_imgs/517485.png +3 -0
- control_imgs/519494.png +3 -0
- control_imgs/525273.png +3 -0
- control_imgs/538419.png +3 -0
- control_imgs/553045.png +3 -0
- control_imgs/560261.png +3 -0
- control_imgs/6306fffe-5944-4659-adea-055d00af89b0.png +3 -0
- control_imgs/64154.png +3 -0
- control_imgs/64154f.png +3 -0
- control_imgs/645888.png +3 -0
- control_imgs/661333b9-bf31-4c70-af83-293663497b98.png +3 -0
- control_imgs/667114.png +3 -0
- control_imgs/716523.png +3 -0
- control_imgs/7d3f1a9c-1945-4b5f-a686-2eb7aa6f8d89.png +3 -0
- control_imgs/8024eb55-ef05-4752-a1b8-4ad7351a8172.png +3 -0
- control_imgs/8880001.png +3 -0
- control_imgs/8880002.png +3 -0
- control_imgs/8880003.png +3 -0
- control_imgs/8880005.png +3 -0
- control_imgs/8880006.png +3 -0
- control_imgs/8880007.png +3 -0
- control_imgs/8880008.png +3 -0
- control_imgs/8880010.png +3 -0
- control_imgs/8880015.png +3 -0
- control_imgs/8880020.png +3 -0
- control_imgs/8880020f.png +3 -0
- control_imgs/8880021.png +3 -0
- control_imgs/8880021f.png +3 -0
- control_imgs/8880022.png +3 -0
- control_imgs/8880022f.png +3 -0
- control_imgs/8880023.png +3 -0
- control_imgs/8880023f.png +3 -0
- control_imgs/8880030.png +3 -0
- control_imgs/8880031.png +3 -0
- control_imgs/8880041.png +3 -0
- control_imgs/8880101.png +3 -0
- control_imgs/8880101f.png +3 -0
- control_imgs/8880106.png +3 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
preserved
|
| 2 |
+
__pycache__
|
alice_to_steve.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image
|
| 2 |
+
|
| 3 |
+
def alice_to_steve(alice):
|
| 4 |
+
for arm_loc, decor_offset in [((40, 16), (0,16)), ((32,48),(16,0))]:
|
| 5 |
+
for (size, loc, offset_x) in [
|
| 6 |
+
# Top and bottom
|
| 7 |
+
((5,4),(arm_loc[0]+4+1, arm_loc[1]), 1),# Duplicate the middle pixel once
|
| 8 |
+
((2,4),(arm_loc[0]+4+4+1, arm_loc[1]), 1),
|
| 9 |
+
|
| 10 |
+
# Front and back
|
| 11 |
+
((9,12),(arm_loc[0]+4+1, arm_loc[1]+4), 1),
|
| 12 |
+
((2,12),(arm_loc[0]+4+4+4+1, arm_loc[1]+4), 1),
|
| 13 |
+
]:
|
| 14 |
+
for x in range(loc[0]+size[0]-1, loc[0]-1, -1):
|
| 15 |
+
for y in range(loc[1], loc[1]+size[1]):
|
| 16 |
+
alice.putpixel((x+offset_x, y), alice.getpixel((x, y)))
|
| 17 |
+
alice.putpixel((x+offset_x+decor_offset[0], y+decor_offset[1]), alice.getpixel((x+decor_offset[0], y+decor_offset[1])))
|
| 18 |
+
return alice
|
build_target_img.py
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import uuid
|
| 3 |
+
import concurrent.futures
|
| 4 |
+
from alice_to_steve import alice_to_steve
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import os
|
| 7 |
+
import numpy as np
|
| 8 |
+
import asyncio
|
| 9 |
+
import mc_render
|
| 10 |
+
import random
|
| 11 |
+
from mc_voxel_texture_resolver import resolve_voxel_consistency
|
| 12 |
+
|
| 13 |
+
SCALING_RATIO = 12
|
| 14 |
+
|
| 15 |
+
IMAGE_WIDTH = 768
|
| 16 |
+
IMAGE_HEIGHT = 768
|
| 17 |
+
|
| 18 |
+
SCALING_RATIO = 12*IMAGE_HEIGHT/768
|
| 19 |
+
|
| 20 |
+
SKIN_MASK = "skin-mask.png"
|
| 21 |
+
SKIN_DECOR_MASK = "skin-decor-mask.png"
|
| 22 |
+
|
| 23 |
+
bg = (128,128,128)
|
| 24 |
+
|
| 25 |
+
def create_mask():
|
| 26 |
+
if os.path.exists(SKIN_MASK) and os.path.exists(SKIN_DECOR_MASK):
|
| 27 |
+
return
|
| 28 |
+
|
| 29 |
+
# 64*64
|
| 30 |
+
|
| 31 |
+
mask = Image.new('RGBA', (64, 64), (0, 0, 0, 0))
|
| 32 |
+
decor_mask = Image.new('RGBA', (64, 64), (0, 0, 0, 0))
|
| 33 |
+
for (size, offset, decor_offset) in [
|
| 34 |
+
# head
|
| 35 |
+
[(8,8),(0,8),(32,0)],
|
| 36 |
+
[(8,8),(8,8),(32,0)],
|
| 37 |
+
[(8,8),(8,0),(32,0)],
|
| 38 |
+
[(8,8),(16,8),(32,0)],
|
| 39 |
+
[(8,8),(16,0),(32,0)],
|
| 40 |
+
[(8,8),(24,8),(32,0)],
|
| 41 |
+
|
| 42 |
+
#left arm
|
| 43 |
+
[(4,12),(32,52),(16,0)],
|
| 44 |
+
[(4,12),(32+4,52),(16,0)],
|
| 45 |
+
[(4,12),(32+8,52),(16,0)],
|
| 46 |
+
[(4,12),(32+12,52),(16,0)],
|
| 47 |
+
[(4,4),(32+4,48),(16,0)],
|
| 48 |
+
[(4,4),(32+8,48),(16,0)],
|
| 49 |
+
|
| 50 |
+
#right arm
|
| 51 |
+
[(4,12),(40,20),(0,16)],
|
| 52 |
+
[(4,12),(40+4,20),(0,16)],
|
| 53 |
+
[(4,12),(40+8,20),(0,16)],
|
| 54 |
+
[(4,12),(40+12,20),(0,16)],
|
| 55 |
+
[(4,4),(40+4,16),(0,16)],
|
| 56 |
+
[(4,4),(40+8,16),(0,16)],
|
| 57 |
+
|
| 58 |
+
#body
|
| 59 |
+
[(8,4),(20,16),(0,16)],
|
| 60 |
+
[(8,4),(20+8,16),(0,16)],
|
| 61 |
+
[(8,12),(20,20),(0,16)],
|
| 62 |
+
[(8,12),(20+12,20),(0,16)],
|
| 63 |
+
[(4,12),(16,20),(0,16)],
|
| 64 |
+
[(4,12),(28,20),(0,16)],
|
| 65 |
+
|
| 66 |
+
#left leg
|
| 67 |
+
[(4,12),(16,52),(-16,0)],
|
| 68 |
+
[(4,12),(16+4,52),(-16,0)],
|
| 69 |
+
[(4,12),(16+8,52),(-16,0)],
|
| 70 |
+
[(4,12),(16+12,52),(-16,0)],
|
| 71 |
+
[(4,4),(16+4,48),(-16,0)],
|
| 72 |
+
[(4,4),(16+8,48),(-16,0)],
|
| 73 |
+
|
| 74 |
+
#right leg
|
| 75 |
+
[(4,12),(0,20),(0,16)],
|
| 76 |
+
[(4,12),(0+4,20),(0,16)],
|
| 77 |
+
[(4,12),(0+8,20),(0,16)],
|
| 78 |
+
[(4,12),(0+12,20),(0,16)],
|
| 79 |
+
[(4,4),(0+4,16),(0,16)],
|
| 80 |
+
[(4,4),(0+8,16),(0,16)],
|
| 81 |
+
]:
|
| 82 |
+
mask.paste(Image.new('RGBA', size, (bg[0], bg[1], bg[2], 255)), offset)
|
| 83 |
+
decor_mask.paste(Image.new('RGBA', size, (bg[0], bg[1], bg[2], 255)), (offset[0]+decor_offset[0],offset[1]+decor_offset[1]))
|
| 84 |
+
|
| 85 |
+
mask.save(SKIN_MASK)
|
| 86 |
+
decor_mask.save(SKIN_DECOR_MASK)
|
| 87 |
+
|
| 88 |
+
create_mask()
|
| 89 |
+
|
| 90 |
+
def apply_mask(skin_image, skin_mask):
|
| 91 |
+
skin_image = Image.composite(skin_image, skin_mask, skin_mask)
|
| 92 |
+
return skin_image
|
| 93 |
+
|
| 94 |
+
def create_training_image(skin_image):
|
| 95 |
+
|
| 96 |
+
# Mask out any areas not directly mapping to the head, arm, leg, or
|
| 97 |
+
# torso portion of the character.
|
| 98 |
+
skin_image_first_layer = apply_mask(skin_image,Image.open(SKIN_MASK))
|
| 99 |
+
skin_image_second_layer = apply_mask(skin_image,Image.open(SKIN_DECOR_MASK))
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
training_image = Image.new('RGBA', (IMAGE_WIDTH, IMAGE_HEIGHT), (*bg, 255))
|
| 103 |
+
scaled_skin_image = skin_image.resize((int(32 * SCALING_RATIO), int(32 * SCALING_RATIO)),
|
| 104 |
+
resample=Image.BOX)
|
| 105 |
+
#scaled_first_layer = skin_image_first_layer.resize((int(32 * SCALING_RATIO), int(32 * SCALING_RATIO)),
|
| 106 |
+
# resample=Image.BOX)
|
| 107 |
+
#scaled_second_layer = skin_image_second_layer.resize((int(32 * SCALING_RATIO), int(32 * SCALING_RATIO)),
|
| 108 |
+
# resample=Image.BOX)
|
| 109 |
+
|
| 110 |
+
training_image.paste(scaled_skin_image, (0,0))
|
| 111 |
+
#training_image.paste(scaled_first_layer, (0,0))
|
| 112 |
+
#training_image.paste(scaled_second_layer, (int(32 * SCALING_RATIO),0))
|
| 113 |
+
|
| 114 |
+
# Optimized: Use NumPy for transparency and dot drawing
|
| 115 |
+
tr_arr = np.array(training_image)
|
| 116 |
+
|
| 117 |
+
# Fill transparent background areas
|
| 118 |
+
tr_arr[tr_arr[..., 3] == 0] = [*bg, 255]
|
| 119 |
+
|
| 120 |
+
# Draw white dots for skin transparency
|
| 121 |
+
skin_arr = np.array(skin_image)
|
| 122 |
+
y_indices, x_indices = np.where(skin_arr[..., 3] == 0)
|
| 123 |
+
|
| 124 |
+
for x, y in zip(x_indices, y_indices):
|
| 125 |
+
cx = int(int(x * SCALING_RATIO / 2) + SCALING_RATIO // 4)
|
| 126 |
+
cy = int(int(y * SCALING_RATIO / 2) + SCALING_RATIO // 4)
|
| 127 |
+
# Apply 2x2 white dot
|
| 128 |
+
tr_arr[cy-1:cy+1, cx-1:cx+1] = [255, 255, 255, 255]
|
| 129 |
+
|
| 130 |
+
training_image = Image.fromarray(tr_arr)
|
| 131 |
+
|
| 132 |
+
# skin_image -> np.ndarray
|
| 133 |
+
|
| 134 |
+
r_scale1 = 0.22
|
| 135 |
+
r_scale2 = 0.28
|
| 136 |
+
r_scale3 = 0.09
|
| 137 |
+
r_scale4 = 0.25
|
| 138 |
+
full_part = ['head','body','left_arm','right_arm','left_leg','right_leg']
|
| 139 |
+
|
| 140 |
+
limbs_offset = 0.8
|
| 141 |
+
default_pos_args = {
|
| 142 |
+
'head': (0, 28, 0),
|
| 143 |
+
'body': (0, 18, 0),
|
| 144 |
+
'right_arm': (-6 - limbs_offset, 18, 0),
|
| 145 |
+
'left_arm': (6 + limbs_offset, 18, 0),
|
| 146 |
+
'right_leg': (-2 - limbs_offset, 6, 0),
|
| 147 |
+
'left_leg': (2 + limbs_offset, 6, 0),
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
pos_args2 = {
|
| 151 |
+
'head': (0, 28, 0),
|
| 152 |
+
'body': (0, 18, 0),
|
| 153 |
+
'right_arm': (-6, 18 , 0),
|
| 154 |
+
'left_arm': (6, 18 , 0),
|
| 155 |
+
'right_leg': (-2, 6, 0),
|
| 156 |
+
'left_leg': (2, 6, 0),
|
| 157 |
+
}
|
| 158 |
+
for (ortho, s, look_at_y, core_display, decor_display, cam_front, offset,render_size, zoom, pos_args, walk) in [
|
| 159 |
+
(False, skin_image,12, full_part, full_part, (0.3, 0.4, 0.5), (int(IMAGE_WIDTH/2), 0), (int(IMAGE_WIDTH/2),int(IMAGE_HEIGHT/2*1.2)), r_scale1, default_pos_args, True),
|
| 160 |
+
|
| 161 |
+
(False, skin_image,12,full_part,full_part, (0.0, 0, 0.5),(0, int(IMAGE_HEIGHT/2)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/3)), 0.35, pos_args2, False),
|
| 162 |
+
(False, skin_image,12,full_part,full_part, (-0.0, -0.0, -0.5),(0, int(IMAGE_HEIGHT*3/4)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/3)), 0.35, pos_args2, False),
|
| 163 |
+
|
| 164 |
+
(False,skin_image_first_layer,12, full_part, full_part, (0.3, 0.4, 0.5), (int(IMAGE_WIDTH/5), int(IMAGE_HEIGHT/2)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/3)), r_scale2,default_pos_args, False),
|
| 165 |
+
(False,skin_image_first_layer,12, full_part, full_part, (-0.5, -0.4, -0.5), (int(IMAGE_WIDTH/5), int(IMAGE_HEIGHT*3/4)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/3)), r_scale2,default_pos_args, False),
|
| 166 |
+
|
| 167 |
+
#left
|
| 168 |
+
(False,skin_image,12, full_part, full_part, (0.3, 0.4, 0.5), (int(IMAGE_WIDTH*2/5), int(IMAGE_HEIGHT/2)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/3)), r_scale2,default_pos_args, False),
|
| 169 |
+
(False,skin_image,12, full_part, full_part, (-0.5, -0.4, -0.5), (int(IMAGE_WIDTH*2/5), int(IMAGE_HEIGHT*3/4)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/3)), r_scale2,default_pos_args, False),
|
| 170 |
+
|
| 171 |
+
# right
|
| 172 |
+
(False,skin_image, 12,full_part, full_part, (0.3, -0.4, 0.5),(int(IMAGE_WIDTH*3/5), int(IMAGE_HEIGHT/2)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/3)), r_scale2,default_pos_args, False),
|
| 173 |
+
(False,skin_image, 12,full_part, full_part, (-0.5, 0.4, -0.5),(int(IMAGE_WIDTH*3/5), int(IMAGE_HEIGHT*3/4)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/3)), r_scale2,default_pos_args, False),
|
| 174 |
+
|
| 175 |
+
# head
|
| 176 |
+
(False,skin_image,28, ['head'], ['head'], (-0.3, -0.4, 0.5),(int(IMAGE_WIDTH*4/5), int(IMAGE_HEIGHT/2)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/8)), r_scale3,default_pos_args, False),
|
| 177 |
+
(False,skin_image,28, ['head'], ['head'], (0.3, -0.4, 0.5),(int(IMAGE_WIDTH*4/5), int(IMAGE_HEIGHT/2 + IMAGE_HEIGHT/8)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/8)), r_scale3,default_pos_args, False),
|
| 178 |
+
(False,skin_image,28, ['head'], ['head'], (-0.5, -0.4, -0.5),(int(IMAGE_WIDTH*4/5), int(IMAGE_HEIGHT/2+ IMAGE_HEIGHT*2/8)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/8)), r_scale3,default_pos_args, False),
|
| 179 |
+
(False,skin_image,28, ['head'], ['head'], (0.5, -0.4, -0.5),(int(IMAGE_WIDTH*4/5), int(IMAGE_HEIGHT/2+ IMAGE_HEIGHT*3/8)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/8)), r_scale3,default_pos_args, False),
|
| 180 |
+
|
| 181 |
+
(False,skin_image,12, ['body'], ['body'], (0.3, 0.4, 0.5), (int(IMAGE_WIDTH*3/4*1.05), int(IMAGE_HEIGHT*1/5)), (int(IMAGE_WIDTH/4),int(IMAGE_HEIGHT/2)), r_scale4,default_pos_args, False),
|
| 182 |
+
(False,skin_image,12, ['body'], ['body'], (-0.3, 0.4, 0.5), (int(IMAGE_WIDTH*3/4*1.05), int(-IMAGE_HEIGHT*1/8)), (int(IMAGE_WIDTH/4),int(IMAGE_HEIGHT/2)), r_scale4,default_pos_args, False),
|
| 183 |
+
|
| 184 |
+
(False,skin_image,22, [], ['head'], (0.3, 0.3, 0), (int(IMAGE_WIDTH*1/2*0.95), int(IMAGE_HEIGHT*1/60)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/4.5)), r_scale4,default_pos_args, False),
|
| 185 |
+
(False,skin_image,22, [], ['head'], (-0.3, 0.3, 0), (int(IMAGE_WIDTH*1/2*0.95), int(IMAGE_HEIGHT*20/60)), (int(IMAGE_WIDTH/5),int(IMAGE_HEIGHT/4.5)), r_scale4,default_pos_args, False),
|
| 186 |
+
|
| 187 |
+
]:
|
| 188 |
+
# Optimized: Get image directly from memory instead of UUID-named temp files
|
| 189 |
+
img_np = mc_render.render_skin(
|
| 190 |
+
skin=np.array(s),
|
| 191 |
+
output_size=render_size,
|
| 192 |
+
cam_front=cam_front,
|
| 193 |
+
look_at_y=look_at_y,
|
| 194 |
+
use_voxels=True,
|
| 195 |
+
ortho=ortho,
|
| 196 |
+
core_display=core_display,
|
| 197 |
+
decor_display=decor_display,
|
| 198 |
+
show_wireframe=False,
|
| 199 |
+
pos_args=pos_args,
|
| 200 |
+
rot_args={
|
| 201 |
+
'rot_head': (0,0,0),
|
| 202 |
+
'rot_arm_right': (-30,0,0),
|
| 203 |
+
'rot_arm_left': (30,0,0),
|
| 204 |
+
'rot_leg_right': (30,0,0),
|
| 205 |
+
'rot_leg_left': (-30,0,0),
|
| 206 |
+
} if walk else {
|
| 207 |
+
'rot_head': (0,0,0),
|
| 208 |
+
'rot_arm_right': (0,0,0),
|
| 209 |
+
'rot_arm_left': (0,0,0),
|
| 210 |
+
'rot_leg_right': (0,0,0),
|
| 211 |
+
'rot_leg_left': (0,0,0),
|
| 212 |
+
},save_path=None, transparent_background=True, zoom=zoom, light=True)
|
| 213 |
+
|
| 214 |
+
if img_np is not None:
|
| 215 |
+
x = Image.fromarray(img_np)
|
| 216 |
+
training_image.paste(x, offset, x)
|
| 217 |
+
|
| 218 |
+
return training_image
|
| 219 |
+
|
| 220 |
+
def check_skin(img):
|
| 221 |
+
is_alex = False
|
| 222 |
+
if img.size != (64, 64):
|
| 223 |
+
print('size invalid')
|
| 224 |
+
return False,is_alex
|
| 225 |
+
skin_image_first_layer = apply_mask(img,Image.open(SKIN_MASK))
|
| 226 |
+
# Calculate the total number of opaque pixels
|
| 227 |
+
count = 0
|
| 228 |
+
count2 = 0
|
| 229 |
+
for x in range(64):
|
| 230 |
+
for y in range(64):
|
| 231 |
+
if img.getpixel((x, y))[3] == 255:
|
| 232 |
+
count2 +=1
|
| 233 |
+
if skin_image_first_layer.getpixel((x, y))[3] == 255:
|
| 234 |
+
count += 1
|
| 235 |
+
|
| 236 |
+
if count == 1632 - 4*2*2-12*2*2:
|
| 237 |
+
is_alex = True
|
| 238 |
+
|
| 239 |
+
if count != 1632 and (not is_alex):
|
| 240 |
+
print('count invalid', count)
|
| 241 |
+
return False,is_alex
|
| 242 |
+
|
| 243 |
+
if count2 == 64*64 and (not is_alex):
|
| 244 |
+
print('count2 invalid')
|
| 245 |
+
return False,is_alex
|
| 246 |
+
|
| 247 |
+
return True,is_alex
|
| 248 |
+
|
| 249 |
+
def ensure_valid_skin(skin_image):
|
| 250 |
+
skin_image_first_layer = Image.open(SKIN_MASK)
|
| 251 |
+
skin_image_second_layer = Image.open(SKIN_DECOR_MASK)
|
| 252 |
+
|
| 253 |
+
# Convert all semi-transparent to opaque
|
| 254 |
+
for x in range(skin_image.width):
|
| 255 |
+
for y in range(skin_image.height):
|
| 256 |
+
if skin_image.getpixel((x, y))[3] != 0 and skin_image.getpixel((x, y))[3] != 255:
|
| 257 |
+
skin_image.putpixel((x, y), (skin_image.getpixel((x, y))[0], skin_image.getpixel((x, y))[1], skin_image.getpixel((x, y))[2], 255))
|
| 258 |
+
# Ignore other pixels in the 1st and 2nd layers of the skin
|
| 259 |
+
if skin_image_first_layer.getpixel((x, y))[3] != 255 and skin_image_second_layer.getpixel((x, y))[3] != 255:
|
| 260 |
+
skin_image.putpixel((x, y), (bg[0],bg[1],bg[2], 255))
|
| 261 |
+
return skin_image
|
| 262 |
+
|
| 263 |
+
def build_target_img(input_path, output_path):
|
| 264 |
+
# This might fail if dirs not created yet
|
| 265 |
+
# But main process creates them
|
| 266 |
+
try:
|
| 267 |
+
if not os.path.exists(input_path):
|
| 268 |
+
print('not exists', input_path)
|
| 269 |
+
return
|
| 270 |
+
|
| 271 |
+
# Ensure subdir exists in output
|
| 272 |
+
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
| 273 |
+
|
| 274 |
+
if os.path.exists(output_path):
|
| 275 |
+
print('exists target', output_path)
|
| 276 |
+
return
|
| 277 |
+
|
| 278 |
+
print(f"Processing {input_path}")
|
| 279 |
+
skin_image = Image.open(input_path)
|
| 280 |
+
skin_image = skin_image.convert('RGBA')
|
| 281 |
+
valid,is_alex = check_skin(skin_image)
|
| 282 |
+
if not valid:
|
| 283 |
+
print('invalid', input_path)
|
| 284 |
+
return
|
| 285 |
+
if is_alex:
|
| 286 |
+
skin_image = alice_to_steve(skin_image)
|
| 287 |
+
|
| 288 |
+
skin_image = ensure_valid_skin(skin_image)
|
| 289 |
+
skin_image = resolve_voxel_consistency(skin_image)
|
| 290 |
+
training_image = create_training_image(skin_image)
|
| 291 |
+
training_image.save(output_path)
|
| 292 |
+
except Exception as e:
|
| 293 |
+
print(f"Error processing {input_path}: {e}")
|
| 294 |
+
|
| 295 |
+
if __name__ == '__main__':
|
| 296 |
+
parser = argparse.ArgumentParser(description="Process a single Minecraft skin to a target image")
|
| 297 |
+
parser.add_argument("input_path", help="Path to input skin image")
|
| 298 |
+
parser.add_argument("output_path", help="Path to output target image")
|
| 299 |
+
args = parser.parse_args()
|
| 300 |
+
build_target_img(args.input_path, args.output_path)
|
build_target_imgs.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import subprocess
|
| 4 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 5 |
+
|
| 6 |
+
output_dir = 'target_imgs_v73'
|
| 7 |
+
|
| 8 |
+
def process_skin(skin_id):
|
| 9 |
+
input_path = f'skins/{skin_id}.png'
|
| 10 |
+
output_path = f'{output_dir}/{skin_id}.png'
|
| 11 |
+
if not os.path.exists(output_path):
|
| 12 |
+
print(f"Starting process for skin: {skin_id}...")
|
| 13 |
+
# Run build_target_img.py as a separate subprocess using sys.executable
|
| 14 |
+
result = subprocess.run(
|
| 15 |
+
[sys.executable, 'build_target_img.py', input_path, output_path],
|
| 16 |
+
capture_output=True,
|
| 17 |
+
text=True
|
| 18 |
+
)
|
| 19 |
+
if result.returncode == 0:
|
| 20 |
+
print(f"Successfully processed: {skin_id}")
|
| 21 |
+
else:
|
| 22 |
+
print(f"Error processing skin {skin_id}:")
|
| 23 |
+
print(result.stderr or result.stdout)
|
| 24 |
+
|
| 25 |
+
def main():
|
| 26 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 27 |
+
iset = set()
|
| 28 |
+
for i in os.listdir('skins'):
|
| 29 |
+
if i.endswith('.png') and not i.startswith('.'):
|
| 30 |
+
iset.add(i.split('.')[0])
|
| 31 |
+
|
| 32 |
+
# Process skins in parallel using a pool of subprocesses
|
| 33 |
+
# Using 4 workers for fast parallel rendering on Mac
|
| 34 |
+
max_workers = 4
|
| 35 |
+
print(f"Processing {len(iset)} skins using {max_workers} parallel workers...")
|
| 36 |
+
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
| 37 |
+
executor.map(process_skin, sorted(list(iset)))
|
| 38 |
+
|
| 39 |
+
if __name__ == '__main__':
|
| 40 |
+
main()
|
control_imgs/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
control_imgs/0042.png
ADDED
|
Git LFS Details
|
control_imgs/12.png
ADDED
|
Git LFS Details
|
control_imgs/17474.png
ADDED
|
Git LFS Details
|
control_imgs/1ed2b9af-0722-4869-8685-294610976cb5.png
ADDED
|
Git LFS Details
|
control_imgs/222855.png
ADDED
|
Git LFS Details
|
control_imgs/408097.png
ADDED
|
Git LFS Details
|
control_imgs/49ed3dbc-2d35-491c-b995-be54c59ab423.png
ADDED
|
Git LFS Details
|
control_imgs/517485.png
ADDED
|
Git LFS Details
|
control_imgs/519494.png
ADDED
|
Git LFS Details
|
control_imgs/525273.png
ADDED
|
Git LFS Details
|
control_imgs/538419.png
ADDED
|
Git LFS Details
|
control_imgs/553045.png
ADDED
|
Git LFS Details
|
control_imgs/560261.png
ADDED
|
Git LFS Details
|
control_imgs/6306fffe-5944-4659-adea-055d00af89b0.png
ADDED
|
Git LFS Details
|
control_imgs/64154.png
ADDED
|
Git LFS Details
|
control_imgs/64154f.png
ADDED
|
Git LFS Details
|
control_imgs/645888.png
ADDED
|
Git LFS Details
|
control_imgs/661333b9-bf31-4c70-af83-293663497b98.png
ADDED
|
Git LFS Details
|
control_imgs/667114.png
ADDED
|
Git LFS Details
|
control_imgs/716523.png
ADDED
|
Git LFS Details
|
control_imgs/7d3f1a9c-1945-4b5f-a686-2eb7aa6f8d89.png
ADDED
|
Git LFS Details
|
control_imgs/8024eb55-ef05-4752-a1b8-4ad7351a8172.png
ADDED
|
Git LFS Details
|
control_imgs/8880001.png
ADDED
|
Git LFS Details
|
control_imgs/8880002.png
ADDED
|
Git LFS Details
|
control_imgs/8880003.png
ADDED
|
Git LFS Details
|
control_imgs/8880005.png
ADDED
|
Git LFS Details
|
control_imgs/8880006.png
ADDED
|
Git LFS Details
|
control_imgs/8880007.png
ADDED
|
Git LFS Details
|
control_imgs/8880008.png
ADDED
|
Git LFS Details
|
control_imgs/8880010.png
ADDED
|
Git LFS Details
|
control_imgs/8880015.png
ADDED
|
Git LFS Details
|
control_imgs/8880020.png
ADDED
|
Git LFS Details
|
control_imgs/8880020f.png
ADDED
|
Git LFS Details
|
control_imgs/8880021.png
ADDED
|
Git LFS Details
|
control_imgs/8880021f.png
ADDED
|
Git LFS Details
|
control_imgs/8880022.png
ADDED
|
Git LFS Details
|
control_imgs/8880022f.png
ADDED
|
Git LFS Details
|
control_imgs/8880023.png
ADDED
|
Git LFS Details
|
control_imgs/8880023f.png
ADDED
|
Git LFS Details
|
control_imgs/8880030.png
ADDED
|
Git LFS Details
|
control_imgs/8880031.png
ADDED
|
Git LFS Details
|
control_imgs/8880041.png
ADDED
|
Git LFS Details
|
control_imgs/8880101.png
ADDED
|
Git LFS Details
|
control_imgs/8880101f.png
ADDED
|
Git LFS Details
|
control_imgs/8880106.png
ADDED
|
Git LFS Details
|