| |
| """Download all Mixamo characters as rigged FBX WITH skin mesh (T-pose). |
| Reuses mixamo_download's token hot-reload, export, download helpers.""" |
| import argparse, json, os, sys, time, requests |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| import mixamo_download as M |
|
|
| TPOSE = "c9c818ab-b96c-11e4-a802-0aaa78deedf9" |
|
|
| def main(): |
| ap = argparse.ArgumentParser() |
| ap.add_argument("--token-file", required=True) |
| ap.add_argument("--out", default="mixamo_characters") |
| ap.add_argument("--delay", type=float, default=1.0) |
| ap.add_argument("--max", type=int, default=0) |
| a = ap.parse_args() |
| M._TOKEN_FILE = a.token_file |
| tok = M.load_token_file(a.token_file) |
| s = requests.Session(); s.headers.update(M.headers(tok)) |
| os.makedirs(a.out, exist_ok=True) |
| manifest = os.path.join(a.out, "manifest.jsonl") |
| done_ids = set() |
| if os.path.exists(manifest): |
| for ln in open(manifest): |
| try: done_ids.add(json.loads(ln)["uuid"]) |
| except: pass |
| mf = open(manifest, "a") |
|
|
| chars = M.get(s, "https://www.mixamo.com/api/v1/characters", |
| params={"page":1,"limit":300,"type":"Character"}) |
| if isinstance(chars, dict): chars = chars.get("results", list(chars.values())) |
| print("characters:", len(chars), flush=True) |
|
|
| seen, done, failed = {}, 0, [] |
| for c in chars: |
| uuid = c.get("uuid"); name = c.get("name") or uuid |
| if not uuid or uuid in done_ids: continue |
| base = M.slug(name); seen[base]=seen.get(base,0)+1 |
| if seen[base]>1: base="%s_%d"%(base,seen[base]) |
| fn = base+".fbx"; path=os.path.join(a.out, fn) |
| if os.path.exists(path): |
| mf.write(json.dumps({"file":fn,"name":name,"uuid":uuid})+"\n"); mf.flush() |
| done_ids.add(uuid); continue |
| try: |
| det = M.get(s, "https://www.mixamo.com/api/v1/products/%s"%TPOSE, |
| params={"character_id":uuid}) |
| gms = det["details"]["gms_hash"] |
| body = {"gms_hash":[M.flatten(g) for g in (gms if isinstance(gms,list) else [gms])], |
| "preferences":{"format":"fbx7_2019","skin":"true","fps":"30","reducekf":"0"}, |
| "character_id":uuid,"type":"Character","product_name":name} |
| for attempt in range(8): |
| r = s.post("https://www.mixamo.com/api/v1/animations/export", json=body, timeout=60) |
| if r.status_code==401: |
| M.wait_for_fresh_token(s, a.token_file, s.headers.get("Authorization","")[7:]); continue |
| if r.status_code==429: time.sleep(4*(attempt+1)); continue |
| r.raise_for_status(); break |
| url=None |
| for _ in range(40): |
| time.sleep(1.5) |
| mon=M.get(s,"https://www.mixamo.com/api/v1/characters/%s/monitor"%uuid) |
| if mon["status"]=="completed": url=mon["job_result"]; break |
| if mon["status"]=="failed": raise RuntimeError(mon.get("message","failed")) |
| if not url: raise RuntimeError("timeout") |
| size=M.download(url, path) |
| mf.write(json.dumps({"file":fn,"name":name,"uuid":uuid})+"\n"); mf.flush() |
| done_ids.add(uuid); done+=1 |
| print(" ok %-38s %8.1f KB"%(name[:38], size/1024), flush=True) |
| except Exception as e: |
| failed.append((name,str(e))); print(" ERR %s -> %s"%(name,str(e)[:70]), flush=True) |
| if a.max and done>=a.max: break |
| time.sleep(a.delay) |
| mf.close() |
| print("\n%d characters in %s; %d failed"%(done, os.path.abspath(a.out), len(failed))) |
|
|
| if __name__=="__main__": main() |
|
|