| |
| """Generate ../metadata.csv (animations) and ../characters.csv from the JSON indexes. |
| Plain stdlib csv, so prompts containing commas/slashes are quoted correctly.""" |
| import csv, json, os, sys |
| HERE=os.path.dirname(os.path.abspath(__file__)); ROOT=os.path.dirname(HERE) |
| J=lambda n: json.load(open(os.path.join(ROOT,n))) |
|
|
| prompts, frames = J("animation_prompts.json"), J("animation_frames.json") |
| rows=[] |
| for f in sorted(prompts): |
| v=prompts[f] |
| rows.append({ |
| "file": "animation/"+f, |
| "prompt": v.get("prompt",""), |
| "description": v.get("description",""), |
| "text": v.get("description") or v.get("prompt",""), |
| "frames": frames.get(f,""), |
| "motion_id": v.get("motion_id",""), |
| }) |
| out=os.path.join(ROOT,"metadata.csv") |
| with open(out,"w",newline="",encoding="utf-8") as fh: |
| w=csv.DictWriter(fh,fieldnames=["file","prompt","description","text","frames","motion_id"]) |
| w.writeheader(); w.writerows(rows) |
| print("metadata.csv ->",len(rows),"rows") |
|
|
| chars, cbones = J("characters.json"), J("character_bones.json") |
| anim=set(J("animation_bones.json")["mixamo"]) |
| crows=[] |
| for f in sorted(chars): |
| b=set(cbones.get(f,[])) |
| crows.append({ |
| "file": "character_refined/"+f, |
| "file_original": "character/"+f, |
| "name": chars[f].get("name",""), |
| "uuid": chars[f].get("uuid",""), |
| "bone_count": len(b), |
| "covers_animation_rig": str(anim <= b).lower(), |
| }) |
| out=os.path.join(ROOT,"characters.csv") |
| with open(out,"w",newline="",encoding="utf-8") as fh: |
| w=csv.DictWriter(fh,fieldnames=["file","file_original","name","uuid","bone_count","covers_animation_rig"]) |
| w.writeheader(); w.writerows(crows) |
| n=sum(1 for r in crows if r["covers_animation_rig"]=="true") |
| print("characters.csv ->",len(crows),"rows |",n,"fully retargetable") |
|
|