RoboParty Release
Unify robohome source, assets and scenes delivery
3f15e9f
Raw History Blame Contribute Delete
1.86 kB
import curation_paths as paths
import sqlite3,json,bisect,collections as C,os
A=paths.A
db=sqlite3.connect("file:"+paths.L+"/full_matrix_reviewed_compatibility_v3.sqlite3?mode=ro",uri=True)
obj=[];urdf=[]
for aid,cat,rj in db.execute("select asset_id,normalized_category,record_json from assets where asset_id like 'hssd:%'"):
j=json.loads(rj); d=j.get("dimensions_m")
if not d or len(d)<3: continue
(urdf if aid.startswith("hssd:urdf") else obj).append(dict(id=aid,cat=cat,dims=sorted(d[:3]),path=j.get("canonical_path")))
objs=sorted(obj,key=lambda x:x["dims"][0]); keys=[o["dims"][0] for o in objs]
def close(a,b,t): return all(abs(x-y)<=t*max(x,y) for x,y in zip(a,b))
pairs=[];need=set();nc=C.Counter()
parts={}
import xml.etree.ElementTree as ET
for u in urdf:
d=u["dims"]; lo=bisect.bisect_left(keys,d[0]*0.99); hi=bisect.bisect_right(keys,d[0]*1.01)
c=[o for o in objs[lo:hi] if close(d,o["dims"],0.01) and (o["cat"]==u["cat"] or u["cat"]=="unknown" or o["cat"]=="unknown")]
nc[min(len(c),6)]+=1
if not c: continue
root=ET.parse(u["path"]).getroot(); base=os.path.dirname(u["path"])
parts[u["id"]]=[os.path.join(base,m.get("filename")) for m in root.iter("mesh") if m.get("filename")]
for o in c[:8]: pairs.append((u["id"],o["id"],o["path"])); need.add(o["id"])
print("urdf with >=1 candidate",sum(v for k,v in nc.items() if k>0),"cand-count histogram",dict(nc),"pairs",len(pairs),"distinct statics",len(need))
spec=[]
for uid,ps in parts.items(): spec.append(dict(key="U:"+uid,paths=sorted(set(ps))))
sp={o["id"]:o["path"] for o in obj}
for sid in sorted(need): spec.append(dict(key="S:"+sid,paths=[sp[sid]]))
json.dump(spec,open(A+"/pc_spec.json","w")); json.dump(pairs,open(A+"/pc_pairs.json","w"))
for i in range(16): json.dump(spec[i::16],open(A+"/pc_shard_%02d.json"%i,"w"))
print("blender jobs",len(spec))