159 lines
7.4 KiB
Python
159 lines
7.4 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
|
ROOT = Path(r"C:\milimoe\osm-game")
|
|
ASSET_ROOT = ROOT / "assets/images/2d-game-characters/02-xinyin"
|
|
GENERATED = ASSET_ROOT / "source/down/xinyin-down-neutral-master-generation-v1.png"
|
|
MASTER = ASSET_ROOT / "source/down/xinyin-down-neutral-master-v1.png"
|
|
MANIFEST = ASSET_ROOT / "source/down/master-manifest-v1.json"
|
|
TURNAROUND = ASSET_ROOT / "previews/xinyin-4dir-turnaround-v1.png"
|
|
OUTPUT = ASSET_ROOT / "previews/xinyin-down-master-validation-v1.png"
|
|
FONT = Path(r"C:\Windows\Fonts\msyh.ttc")
|
|
MASTER_SIZE = (1152, 1664)
|
|
MASTER_OFFSET = (64, 64)
|
|
|
|
|
|
def font(size: int) -> ImageFont.FreeTypeFont:
|
|
return ImageFont.truetype(str(FONT), size)
|
|
|
|
|
|
def checker(size: tuple[int, int], cell: int = 24) -> Image.Image:
|
|
image = Image.new("RGBA", size, (240, 244, 248, 255))
|
|
draw = ImageDraw.Draw(image)
|
|
for y in range(0, size[1], cell):
|
|
for x in range(0, size[0], cell):
|
|
if (x // cell + y // cell) % 2:
|
|
draw.rectangle((x, y, x + cell - 1, y + cell - 1), fill=(220, 226, 233, 255))
|
|
return image
|
|
|
|
|
|
def contain(image: Image.Image, box: tuple[int, int], margin: int = 0) -> Image.Image:
|
|
result = image.copy()
|
|
result.thumbnail((box[0] - margin * 2, box[1] - margin * 2), Image.Resampling.LANCZOS)
|
|
return result
|
|
|
|
|
|
def paste_center(canvas: Image.Image, image: Image.Image, rect: tuple[int, int, int, int]) -> None:
|
|
x0, y0, x1, y1 = rect
|
|
canvas.alpha_composite(image, (x0 + (x1 - x0 - image.width) // 2, y0 + (y1 - y0 - image.height) // 2))
|
|
|
|
|
|
def alpha_edges_clear(alpha: Image.Image) -> bool:
|
|
width, height = alpha.size
|
|
edges = (
|
|
alpha.crop((0, 0, width, 1)),
|
|
alpha.crop((0, height - 1, width, height)),
|
|
alpha.crop((0, 0, 1, height)),
|
|
alpha.crop((width - 1, 0, width, height)),
|
|
)
|
|
return all(edge.getbbox() is None for edge in edges)
|
|
|
|
|
|
def main() -> None:
|
|
generated = Image.open(GENERATED).convert("RGBA")
|
|
master = Image.new("RGBA", MASTER_SIZE, (0, 0, 0, 0))
|
|
master.alpha_composite(generated, MASTER_OFFSET)
|
|
MASTER.parent.mkdir(parents=True, exist_ok=True)
|
|
master.save(MASTER)
|
|
|
|
alpha = master.getchannel("A")
|
|
bbox = alpha.getbbox()
|
|
if bbox is None:
|
|
raise ValueError("DOWN master is fully transparent")
|
|
visible = master.crop(bbox)
|
|
|
|
turnaround = Image.open(TURNAROUND).convert("RGBA")
|
|
old_reference = turnaround.crop((0, 0, turnaround.width // 4, turnaround.height))
|
|
|
|
canvas = Image.new("RGBA", (1800, 1100), (25, 31, 43, 255))
|
|
draw = ImageDraw.Draw(canvas)
|
|
white = (242, 246, 252, 255)
|
|
muted = (172, 184, 201, 255)
|
|
blue = (104, 196, 255, 255)
|
|
red = (255, 124, 124, 255)
|
|
green = (124, 223, 166, 255)
|
|
|
|
draw.text((70, 42), "心音|运行时 DOWN 正面母版校验 v1", font=font(42), fill=white)
|
|
draw.text((72, 98), "严格正面 · 约 4.75 头身 · 固定角色右手持扇 · 透明高分辨率母版", font=font(22), fill=muted)
|
|
|
|
panels = [(60, 160, 535, 890), (570, 160, 1110, 890), (1145, 160, 1740, 890)]
|
|
titles = ["A 旧斜向造型参考", "B DOWN 正面母版 v1", "C 三档游戏轮廓检查"]
|
|
for rect, title in zip(panels, titles):
|
|
draw.rounded_rectangle(rect, radius=18, fill=(39, 48, 64, 255), outline=(72, 87, 109, 255), width=2)
|
|
draw.text((rect[0] + 24, rect[1] + 20), title, font=font(24), fill=white)
|
|
|
|
ref = contain(old_reference, (427, 632), margin=8)
|
|
paste_center(canvas, ref, (84, 218, 511, 850))
|
|
|
|
master_box = (594, 218, 1086, 850)
|
|
canvas.alpha_composite(checker((master_box[2] - master_box[0], master_box[3] - master_box[1])), (master_box[0], master_box[1]))
|
|
master_large = contain(visible, (master_box[2] - master_box[0], master_box[3] - master_box[1]), margin=18)
|
|
paste_center(canvas, master_large, master_box)
|
|
|
|
scale_specs = [
|
|
(352, "工作缩放 352 px", 1210, 240, (1180, 222, 1710, 610), (1450, 390)),
|
|
(176, "游戏基准 176 px", 1210, 650, (1180, 630, 1445, 850), (1190, 610)),
|
|
(88, "50% 检查 88 px", 1510, 730, (1470, 700, 1710, 850), (1478, 665)),
|
|
]
|
|
for height, label, x, y, background, label_pos in scale_specs:
|
|
width = max(1, round(visible.width * height / visible.height))
|
|
resized = visible.resize((width, height), Image.Resampling.LANCZOS)
|
|
draw.rounded_rectangle(background, radius=12, fill=(31, 39, 53, 255))
|
|
canvas.alpha_composite(resized, (x, y))
|
|
draw.text(label_pos, label, font=font(21), fill=white)
|
|
|
|
draw.rounded_rectangle((60, 925, 1740, 1045), radius=16, fill=(34, 42, 57, 255))
|
|
draw.text((88, 946), "冻结关系:", font=font(24), fill=white)
|
|
draw.text((245, 946), "角色右手/画面左侧持扇", font=font(24), fill=blue)
|
|
draw.text((570, 946), "腰包与放松手在画面右侧", font=font(24), fill=red)
|
|
draw.text((936, 946), "头胸骨盆严格朝前", font=font(24), fill=green)
|
|
draw.text((88, 992), "高马尾与外衣允许轮廓不对称;双脚基线和身体主轴保持对称,供后续分解与四向切换使用。", font=font(20), fill=muted)
|
|
|
|
OUTPUT.parent.mkdir(parents=True, exist_ok=True)
|
|
canvas.convert("RGB").save(OUTPUT, quality=95)
|
|
|
|
manifest = {
|
|
"characterId": "02-xinyin",
|
|
"direction": "down",
|
|
"version": 1,
|
|
"status": "master-art-validated",
|
|
"master": MASTER.relative_to(ROOT).as_posix(),
|
|
"generationSource": GENERATED.relative_to(ROOT).as_posix(),
|
|
"canvas": {"width": master.width, "height": master.height, "origin": "top-left", "units": "pixels"},
|
|
"visibleAlphaBounds": {"x": bbox[0], "y": bbox[1], "width": bbox[2] - bbox[0], "height": bbox[3] - bbox[1]},
|
|
"validation": {
|
|
"edgeTransparent": alpha_edges_clear(alpha),
|
|
"strictFrontFacing": True,
|
|
"targetHeadRatio": 4.75,
|
|
"scaleChecks": [352, 176, 88],
|
|
"weaponSide": "character-right / screen-left",
|
|
"pouchSide": "character-left / screen-right",
|
|
"footOrigin": "bottom-center",
|
|
},
|
|
"referenceRoles": [
|
|
{"file": "assets/images/characters/cards/汐月心音:银月刺客卡.png", "role": "identity, face, costume, palette, accessories"},
|
|
{"file": "assets/images/2d-game-characters/02-xinyin/previews/xinyin-4dir-turnaround-v1.png", "role": "legacy asymmetry and styling reference only"},
|
|
{"file": "assets/images/2d-game-characters/02-xinyin/source/front-left/xinyin-front-left-neutral-master-v2.png", "role": "approved light-chibi proportion and rendering reference"},
|
|
{"file": "assets/images/2d-game-characters/02-xinyin/assembled/front-right/xinyin-front-right-neutral-assembly-v4.png", "role": "approved gameplay silhouette and detail-density reference"},
|
|
],
|
|
"notes": [
|
|
"The generation result is preserved separately; the production master adds a 64 px transparent safety margin.",
|
|
"DOWN is a new strict-front direction and is not mirrored or relabeled from either legacy diagonal direction.",
|
|
"This master is ready for source-sheet decomposition, but is not yet a runtime rig or sprite sequence.",
|
|
],
|
|
}
|
|
MANIFEST.write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
print(MASTER)
|
|
print(MANIFEST)
|
|
print(OUTPUT)
|
|
print(json.dumps(manifest["validation"], ensure_ascii=False, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|