Files
a7l20-hug-sim/scripts/fetch_controller_meshes.py

27 lines
902 B
Python

"""Download exactly the mesh files referenced by the controller URDF."""
import hashlib
import json
from pathlib import Path
import urllib.request
import xml.etree.ElementTree as ET
ROOT=Path(__file__).resolve().parents[1]
DEST=ROOT/'assets/controller_model'
def main():
root=ET.parse(DEST/'lingzuv2_description.urdf').getroot()
meshes=sorted({Path(e.get('filename')).name for e in root.findall('.//mesh')})
(DEST/'meshes').mkdir(exist_ok=True)
manifest={}
for name in meshes:
url='http://192.168.10.21:8000/meshes/'+name
data=urllib.request.urlopen(url,timeout=15).read()
(DEST/'meshes'/name).write_bytes(data)
manifest[name]={'url':url,'bytes':len(data),'sha256':hashlib.sha256(data).hexdigest()}
print(name,len(data),flush=True)
(DEST/'mesh_manifest.json').write_text(json.dumps(manifest,indent=2))
if __name__=='__main__':main()