3D: square mesh input, paint_mesh projection painter, cutout_ai
generate_mesh pads portrait images to a white square (CLIPVisionEncode centre-crops, which cut off helmet and feet). paint_mesh cleans a Hunyuan3D shape, projects front/back views onto it with z-buffer visibility and writes a painted GLB, an OBJ for Mixamo and a preview. cutout_ai/adopt --ai let rembg decide near-black regions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
12
adopt.py
12
adopt.py
@@ -10,6 +10,7 @@ PictureBoxSizeMode.Zoom, so square keeps every icon the same visual size.
|
||||
py -3.12 adopt.py --all every name in the prompt list
|
||||
py -3.12 adopt.py --size 512 hero larger square (default 128)
|
||||
py -3.12 adopt.py --holes archer also clear enclosed black (see cutout.py)
|
||||
py -3.12 adopt.py --ai hero dark parts decided by a matting model (rembg)
|
||||
"""
|
||||
import glob
|
||||
import importlib
|
||||
@@ -20,7 +21,7 @@ from PIL import Image
|
||||
|
||||
import _bootstrap # Projektordner (config.py, Listen) vor allen anderen Modulen
|
||||
import config
|
||||
from cutout import cutout
|
||||
from cutout import cutout, cutout_ai
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
DEST = os.path.join(config.ASSETS_DIR, "Sprites")
|
||||
@@ -29,7 +30,7 @@ MARGIN = 0.04 # share of the side left free around the icon
|
||||
ALPHA_THRESHOLD = 8
|
||||
|
||||
|
||||
def adopt(name, size=None, holes=False):
|
||||
def adopt(name, size=None, holes=False, ai=False):
|
||||
size = size or SIZE
|
||||
raws = sorted(glob.glob(os.path.join(config.OUTPUT_DIR, f"{name}_raw_*.png")),
|
||||
key=os.path.getmtime)
|
||||
@@ -37,7 +38,7 @@ def adopt(name, size=None, holes=False):
|
||||
print(f" {name}: no raw render in output/, skipped")
|
||||
return False
|
||||
|
||||
image = cutout(raws[-1], holes=holes)
|
||||
image = cutout_ai(raws[-1]) if ai else cutout(raws[-1], holes=holes)
|
||||
box = image.getchannel("A").point(lambda v: 255 if v > ALPHA_THRESHOLD else 0).getbbox()
|
||||
if box is None:
|
||||
print(f" {name}: fully transparent after cutout, skipped")
|
||||
@@ -78,7 +79,8 @@ if __name__ == "__main__":
|
||||
args = sys.argv[1:]
|
||||
size = None
|
||||
holes = "--holes" in args
|
||||
args = [a for a in args if a != "--holes"]
|
||||
ai = "--ai" in args
|
||||
args = [a for a in args if a not in ("--holes", "--ai")]
|
||||
if len(args) >= 2 and args[0] == "--size":
|
||||
size = int(args[1])
|
||||
args = args[2:]
|
||||
@@ -90,5 +92,5 @@ if __name__ == "__main__":
|
||||
if args == ["--all"]:
|
||||
prompts = importlib.import_module(getattr(config, "PROMPTS_MODULE", "prompts_life"))
|
||||
args = [p[0] for p in prompts.PROMPTS]
|
||||
ok = sum(adopt(n, size, holes) for n in args)
|
||||
ok = sum(adopt(n, size, holes, ai) for n in args)
|
||||
print(f"{ok}/{len(args)} adopted")
|
||||
|
||||
Reference in New Issue
Block a user