Skip to content

πŸ’ƒ Free CC0 mannequin pose reference library for AI image tools (Nano Banana, ChatGPT, ComfyUI, Midjourney) β€” 250+ poses Γ— 5 angles in line art, names in ja/zh/en/ko

10.0 KB
Raw Blame
#!/usr/bin/env python3
"""Check data/catalog.json, data/qc.json and images/ against each other.

- every non-null catalog view has a `pass` in qc.json and exists in both tiers;
- every null view has a non-pass qc status and a matching `gaps` entry (missing, line or structure);
- every pose has a desc_en (the prompt-ready description the gallery shows);
- every rating override in data/rating_overrides.json is applied;
- every redrawn pose (catalog `source`) was merged as such: qc.json `sources` names the same source;
- every single-view fill (catalog `fills`) was merged as such (qc.json `fills`) and sits in an original set (D-09);
- every photo has a `pass` in qc.json photos and exists in both tiers; nothing under images/ is unreferenced;
- every map view (catalog `maps`) belongs to a passed line view of the same file, has a `pass` in qc.json maps and
  exists as clay, depth and normal in every tier;
- every README download link names a zip of the data/packs.json version.
"""
import json, pathlib, re, sys

ROOT = pathlib.Path(__file__).resolve().parent.parent
VIEWS = ("front", "diag", "side", "above", "below")
TIERS = ("w300", "w600", "w900")
README_FILES = ("README.md", "docs/readme/README.zh-CN.md", "docs/readme/README.ja.md", "docs/readme/README.ko.md")


def main() -> int:
    cat = json.loads((ROOT / "data/catalog.json").read_text())
    qcd = json.loads((ROOT / "data/qc.json").read_text())
    qc, qc_photos, qc_maps = qcd["views"], qcd.get("photos", {}), qcd.get("maps", {})
    errs, want = [], set()
    ov_path = ROOT / "data/rating_overrides.json"
    for pid, o in (json.loads(ov_path.read_text()) if ov_path.exists() else {}).items():
        if next((p["rating"] for p in cat if p["id"] == pid), None) != o["rating"]:
            errs.append(f"{pid}: rating should be {o['rating']} (data/rating_overrides.json)")
    sources = {p["id"]: p["source"] for p in cat if p.get("source")}
    if sources != qcd.get("sources", {}):
        errs.append("catalog sources differ from qc.json sources (run qc_merge.py after import_redraws.py)")
    fills = {p["id"]: p["fills"] for p in cat if p.get("fills")}
    if fills != qcd.get("fills", {}):
        errs.append("catalog fills differ from qc.json fills (run qc_merge.py after import_fills.py)")
    errs += [f"{p['id']}: fills in a redrawn set ({p['source']})" for p in cat if p.get("fills") and p.get("source")]
    ids = [p["id"] for p in cat]
    if len(ids) != len(set(ids)):
        errs.append("duplicate ids in catalog")
    errs += [f"{p['id']}: empty desc_en (tools/import_descs.py)" for p in cat if not p.get("desc_en")]
    for p in cat:
        q = qc.get(p["id"])
        if q is None:
            errs.append(f"{p['id']}: no qc entry")
            continue
        for v in VIEWS:
            f, st = p["views"].get(v), q[v]["status"]
            if f:
                if st != "pass":
                    errs.append(f"{p['id']} {v}: in catalog but qc says {st}")
                for t in TIERS:
                    want.add(("line", t, f))
                    if not (ROOT / "images/line" / t / f).exists():
                        errs.append(f"{p['id']} {v}: images/line/{t}/{f} missing")
            else:
                if st == "pass":
                    errs.append(f"{p['id']} {v}: qc pass but catalog view is null")
                if p.get("gaps", {}).get(v) != st:
                    errs.append(f"{p['id']} {v}: gaps entry should be {st}")
        for v, f in (p.get("photos") or {}).items():
            if qc_photos.get(p["id"], {}).get(v, {}).get("status") != "pass":
                errs.append(f"{p['id']} photo {v}: in catalog without a qc pass")
            for t in TIERS:
                want.add(("photo", t, f))
                if not (ROOT / "images/photo" / t / f).exists():
                    errs.append(f"{p['id']} photo {v}: images/photo/{t}/{f} missing")
        for v, f in (p.get("maps") or {}).items():
            if p["views"].get(v) != f:
                errs.append(f"{p['id']} maps {v}: not the line view's file")
            if qc_maps.get(p["id"], {}).get(v, {}) != {"file": f, "status": "pass"}:
                errs.append(f"{p['id']} maps {v}: in catalog without a qc pass")
            for k in ("clay", "depth", "normal"):
                for t in TIERS:
                    want.add((k, t, f))
                    if not (ROOT / "images" / k / t / f).exists():
                        errs.append(f"{p['id']} maps {v}: images/{k}/{t}/{f} missing")
    for f in (ROOT / "images").glob("*/*/*.webp"):
        if (f.parent.parent.name, f.parent.name, f.name) not in want:
            errs.append(f"orphan {f.relative_to(ROOT)}")
    # README download links are versioned file names; pack_release.py rewrites them, this catches a hand edit.
    packs_path = ROOT / "data/packs.json"
    if packs_path.exists():
        packs = json.loads(packs_path.read_text())
        files = {k["file"] for k in packs["packs"].values()}
        for md in README_FILES:
            for m in re.finditer(r"releases/download/v([\d.]+)/(shisei-[\w]+-v[\d.]+\.zip)", (ROOT / md).read_text()):
                if m.group(1) != packs["version"] or m.group(2) not in files:
                    errs.append(f"{md}: download link {m.group(2)} is not in data/packs.json v{packs['version']}")
    errs += check_costumes()
    errs += check_series()
    for s in sorted({p["series"] for p in cat}):
        ps = [p for p in cat if p["series"] == s]
        shown = [p for p in ps if any(p["views"].values())]
        n = sum(1 for p in ps for v in VIEWS if p["views"].get(v))
        print(f"{s}: {len(shown)}/{len(ps)} poses shown, {n}/{len(ps) * 5} views pass")
    for e in errs:
        print("ERR", e)
    return 1 if errs else 0


def check_costumes() -> list:
    """Costume library (D-10): data/costumes.json ↔ data/costume-qc.json ↔ images/costume/grey/<tier>/."""
    path = ROOT / "data/costumes.json"
    if not path.exists():
        return []
    data, errs, want = json.loads(path.read_text()), [], set()
    qc_path = ROOT / "data/costume-qc.json"
    qc = json.loads(qc_path.read_text())["items"] if qc_path.exists() else {}
    ids = [i["id"] for i in data["items"]]
    if len(ids) != len(set(ids)) or set(ids) & set(data.get("retired", {}).values()):
        errs.append("costumes.json: duplicate or reused ids")
    for it in data["items"]:
        for k in ("form", "desc_en", "name_zh", "name_ja", "name_en", "name_ko"):
            if not it.get(k):
                errs.append(f"{it['id']}: empty {k}")
        for v in data["views"]:
            f, st = it["views"].get(v), qc.get(it["id"], {}).get(v, {}).get("status")
            if f:
                if st != "pass":
                    errs.append(f"{it['id']} {v}: in costumes.json but costume-qc says {st}")
                for t in TIERS:
                    want.add(ROOT / "images/costume/grey" / t / f)
                    if not (ROOT / "images/costume/grey" / t / f).exists():
                        errs.append(f"{it['id']} {v}: images/costume/grey/{t}/{f} missing")
            else:
                if st == "pass":
                    errs.append(f"{it['id']} {v}: costume-qc pass but view is null (run costume_build.py)")
                if st and it.get("gaps", {}).get(v) != st:
                    errs.append(f"{it['id']} {v}: gaps entry should be {st}")
    errs += [f"orphan {f.relative_to(ROOT)}" for f in (ROOT / "images/costume").glob("*/*/*.webp") if f not in want]
    shown = [i for i in data["items"] if any(i["views"].values())]
    n = sum(1 for i in data["items"] for v in data["views"] if i["views"].get(v))
    print(f"costume: {len(shown)}/{len(data['items'])} items shown, {n}/{len(data['items']) * len(data['views'])} views pass")
    return errs


def check_series() -> list:
    """Scene / prop / furniture / light / animal libraries: data/<lib>.json ↔ data/<lib>-qc.json ↔ images/<lib>/."""
    sys.path.insert(0, str(ROOT / "tools"))
    import series_kit as K
    errs = []
    for lib, cfg in K.LIBS.items():
        path = ROOT / cfg["out"]
        if not path.exists():
            continue
        data, want = json.loads(path.read_text()), set()
        qc_path = ROOT / K.qc_paths(lib)[1]
        qc = json.loads(qc_path.read_text())["items"] if qc_path.exists() else {}
        looks = K.LOOKS[cfg["matte"]]
        ids = [i["id"] for i in data["items"]]
        if len(ids) != len(set(ids)) or set(ids) & set(data.get("retired", {}).values()):
            errs.append(f"{path.name}: duplicate or reused ids")
        for it in data["items"]:
            for k in ("form", "desc_en", "name_zh", "name_ja", "name_en", "name_ko"):
                if not it.get(k):
                    errs.append(f"{it['id']}: empty {k}")
            for v in data["views"]:
                f, st = it["views"].get(v), qc.get(it["id"], {}).get(v, {}).get("status")
                if f:
                    if st != "pass":
                        errs.append(f"{it['id']} {v}: in {path.name} but {qc_path.name} says {st}")
                    for look, tiers in looks.items():
                        for t in tiers:
                            want.add(ROOT / "images" / lib / look / t / f)
                            if not (ROOT / "images" / lib / look / t / f).exists():
                                errs.append(f"{it['id']} {v}: images/{lib}/{look}/{t}/{f} missing")
                else:
                    if st == "pass":
                        errs.append(f"{it['id']} {v}: {qc_path.name} pass but view is null (run series_build.py)")
                    if st and it.get("gaps", {}).get(v) != st:
                        errs.append(f"{it['id']} {v}: gaps entry should be {st}")
        errs += [f"orphan {f.relative_to(ROOT)}" for f in (ROOT / "images" / lib).glob("*/*/*.webp") if f not in want]
        shown = [i for i in data["items"] if any(i["views"].values())]
        n = sum(1 for i in data["items"] for v in data["views"] if i["views"].get(v))
        print(f"{lib}: {len(shown)}/{len(data['items'])} items shown, {n}/{len(data['items']) * len(data['views'])} views pass")
    return errs


if __name__ == "__main__":
    sys.exit(main())