18 lines
1.1 KiB
Python
18 lines
1.1 KiB
Python
import urllib.request,json,pathlib,hashlib,concurrent.futures
|
|||
|
|
root=pathlib.Path.cwd(); out=root/'assets/scan/quarry_realism'; out.mkdir(parents=True,exist_ok=True)
|
||
|
|
ids=['concrete_road_barrier','Barrel_02','old_tyre','portable_generator','wooden_crate_02','covered_car']
|
||
|
|
def get(url):
|
||
|
|
req=urllib.request.Request(url,headers={'User-Agent':'BLOCKLINE asset preparation'})
|
||
|
|
return urllib.request.urlopen(req,timeout=120).read()
|
||
|
|
def asset(a):
|
||
|
|
meta=json.loads(get('https://api.polyhaven.com/files/'+a)); pack=meta['gltf']['2k']['gltf']; folder=out/a; folder.mkdir(exist_ok=True)
|
||
|
|
files={a+'.gltf':pack,**pack['include']}
|
||
|
|
for rel,info in files.items():
|
||
|
|
path=folder/rel; path.parent.mkdir(parents=True,exist_ok=True)
|
||
|
|
if not path.exists() or hashlib.md5(path.read_bytes()).hexdigest()!=info['md5']:
|
||
|
|
data=get(info['url']); assert hashlib.md5(data).hexdigest()==info['md5']; path.write_bytes(data)
|
||
|
|
(folder/'source.json').write_text(json.dumps({'source':'https://polyhaven.com/a/'+a,'license':'CC0-1.0','files':files},indent=2))
|
||
|
|
print(a,'downloaded',flush=True)
|
||
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool: list(pool.map(asset,ids))
|
||
|
|
|