127 lines
6.2 KiB
Python
127 lines
6.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""전장 그림 바깥 구름 띠의 구름 조각 만들기 — PD 2026-11-21 「이번에 적용한 안개는 우리 게임의 화풍에도 맞지 않고 퀄리티도 저급해. 다시 할 것」.
|
||
게임 안개 기믹 그림(Resources/Gimmicks/Art/gim_fog*)을 참고(styleref)로 같은 그림체의 구름 조각을 초록 바탕에 그려 → 바탕을 걷어 투명 → 한 장(가로 4 칸)으로 묶는다.
|
||
|
||
python Tools/edge_cloud_make.py prep 참고(초록 바탕) · jobs_cloud.json
|
||
python -I <조직 레포>/scripts/pixel/comfy_krea2.py --jobs <작업 폴더>/jobs_cloud.json
|
||
python Tools/edge_cloud_make.py key 초록 바탕 → 투명(cloud/key/*.png) + 모음 cloud/sheet.jpg
|
||
python Tools/edge_cloud_make.py pack a b c d 고른 4 조각 → Assets/Resources/Board/edge_cloud.png(2048×512) + 몸통 색 출력
|
||
"""
|
||
import glob
|
||
import json
|
||
import os
|
||
import sys
|
||
|
||
import numpy as np
|
||
from PIL import Image
|
||
|
||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
WORK = os.path.join(os.environ.get("TKS_BGEXT", "E:/Nerdnavis/_tks_bgext"), "cloud")
|
||
ART = os.path.join(ROOT, "Assets", "Resources", "Gimmicks", "Art")
|
||
GREEN = (40, 200, 70)
|
||
CELL = 512
|
||
SHAPES = {
|
||
"round": "a round cluster of six bulging rounded lobes",
|
||
"wide": "a wide low cloud about twice as wide as it is tall, with a bumpy scalloped edge of seven rounded lobes",
|
||
"lumpy": "an irregular lumpy cloud made of rounded lobes of different sizes, slightly wider than tall",
|
||
"small": "a compact round puff made of four rounded lobes",
|
||
}
|
||
PROMPT = ("One single puffy cartoon mist cloud seen from directly above, a 2D mobile game map asset, drawn in exactly the same style as the reference pictures: "
|
||
"soft cream-white body with pale lavender-grey shading on the lower lobes, thick dark brown outline, flat cel colours, casual cute cartoon look. "
|
||
"The cloud is {shape}. No swirl, no spiral, no face, no eyes, no rain, no lightning. "
|
||
"The cloud is centered with empty space around it on a plain flat solid bright green background, no shadow on the background, nothing else in the picture.")
|
||
|
||
|
||
def d(*p):
|
||
path = os.path.join(WORK, *p)
|
||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||
return path
|
||
|
||
|
||
def prep(_):
|
||
refs = []
|
||
for n in ("gim_fog_1", "gim_fog5_1"):
|
||
im = Image.open(os.path.join(ART, n + ".png")).convert("RGBA")
|
||
k = 760.0 / max(im.size)
|
||
im = im.resize((int(im.width * k), int(im.height * k)), Image.LANCZOS)
|
||
bg = Image.new("RGBA", (1024, 1024), GREEN + (255,))
|
||
bg.alpha_composite(im, ((1024 - im.width) // 2, (1024 - im.height) // 2))
|
||
bg.convert("RGB").save(d("ref", n + "_green.png"))
|
||
refs.append(d("ref", n + "_green.png"))
|
||
jobs = []
|
||
for name, shape in SHAPES.items():
|
||
for s in (911, 912):
|
||
jobs.append({"mode": "styleref", "prompt": PROMPT.replace("{shape}", shape), "seed": s, "out": d("gen", "%s_s%d.png" % (name, s)),
|
||
"refs": refs, "w": 1024, "h": 1024, "steps": 8, "style": 1.0})
|
||
json.dump(jobs, open(d("jobs_cloud.json"), "w", encoding="utf-8"), ensure_ascii=False, indent=1)
|
||
print("jobs", len(jobs), d("jobs_cloud.json"))
|
||
|
||
|
||
def key_one(path):
|
||
a = np.asarray(Image.open(path).convert("RGB")).astype(np.float32)
|
||
r, g, b = a[..., 0], a[..., 1], a[..., 2]
|
||
green = g - np.maximum(r, b) # 초록 바탕일수록 큼
|
||
alpha = 1.0 - np.clip((green - 18.0) / 60.0, 0.0, 1.0)
|
||
solid = alpha >= 0.999
|
||
ys, xs = np.where(alpha > 0.5)
|
||
if len(xs) == 0:
|
||
return None
|
||
# 가장자리(반투명) 화소의 색 = 외곽선 색(초록 물 빼기): 불투명 화소 가운데 어두운 쪽 평균
|
||
lum = a.mean(axis=2)
|
||
line = a[solid & (lum < np.percentile(lum[solid], 12))].mean(axis=0)
|
||
out = a.copy()
|
||
part = ~solid
|
||
out[part] = line
|
||
rgba = np.dstack([out, alpha * 255.0]).clip(0, 255).astype(np.uint8)
|
||
im = Image.fromarray(rgba, "RGBA").crop((xs.min(), ys.min(), xs.max() + 1, ys.max() + 1))
|
||
return im
|
||
|
||
|
||
def key(_):
|
||
cells = []
|
||
for p in sorted(glob.glob(os.path.join(WORK, "gen", "*.png"))):
|
||
im = key_one(p)
|
||
if im is None:
|
||
print("빈 그림", p)
|
||
continue
|
||
n = os.path.splitext(os.path.basename(p))[0]
|
||
im.save(d("key", n + ".png"))
|
||
k = 280.0 / max(im.size)
|
||
sm = im.resize((int(im.width * k), int(im.height * k)), Image.LANCZOS)
|
||
bg = Image.new("RGBA", (300, 300), (196, 150, 84, 255))
|
||
bg.alpha_composite(sm, ((300 - sm.width) // 2, (300 - sm.height) // 2))
|
||
cells.append((n, bg.convert("RGB")))
|
||
print(n, im.size)
|
||
sh = Image.new("RGB", (4 * 304, ((len(cells) + 3) // 4) * 304), (20, 20, 20))
|
||
for i, (_, c) in enumerate(cells):
|
||
sh.paste(c, ((i % 4) * 304, (i // 4) * 304))
|
||
sh.save(d("sheet.jpg"), quality=88)
|
||
print(d("sheet.jpg"), [n for n, _ in cells])
|
||
|
||
|
||
def pack(args):
|
||
sheet = Image.new("RGBA", (CELL * len(args), CELL), (0, 0, 0, 0))
|
||
body = []
|
||
for i, n in enumerate(args):
|
||
im = Image.open(os.path.join(WORK, "key", n + ".png")).convert("RGBA")
|
||
k = (CELL - 16.0) / max(im.size)
|
||
im = im.resize((int(im.width * k), int(im.height * k)), Image.LANCZOS)
|
||
sheet.alpha_composite(im, (i * CELL + (CELL - im.width) // 2, (CELL - im.height) // 2))
|
||
a = np.asarray(im).astype(np.float32)
|
||
op = a[a[..., 3] > 250][:, :3]
|
||
lum = op.mean(axis=1)
|
||
body.append(op[lum > np.percentile(lum, 60)].mean(axis=0))
|
||
# 투명 화소의 색을 외곽선 색으로 채움(확대·축소 때 가장자리에 검은 테가 끼지 않게)
|
||
s = np.asarray(sheet).copy()
|
||
op = s[s[..., 3] > 250][:, :3].astype(np.float32)
|
||
line = op[op.mean(axis=1) < np.percentile(op.mean(axis=1), 10)].mean(axis=0)
|
||
s[s[..., 3] == 0, :3] = line.astype(np.uint8)
|
||
out = os.path.join(ROOT, "Assets", "Resources", "Board", "edge_cloud.png")
|
||
Image.fromarray(s, "RGBA").save(out)
|
||
c = np.mean(body, axis=0)
|
||
print(out, sheet.size, "몸통 색 #%02X%02X%02X" % tuple(int(round(x)) for x in c))
|
||
|
||
|
||
if __name__ == "__main__":
|
||
{"prep": prep, "key": key, "pack": pack}[sys.argv[1]](sys.argv[2:])
|