Download validate_rugc.py from DenSnoychik/RUGC-Dataset: direct link, hf CLI and curl.
- Browser
- Download file 5.63 kB
-
https://huggingface.co/datasets/DenSnoychik/RUGC-Dataset/resolve/main/validate_rugc.py
- Command line
-
hf download hf://datasets/DenSnoychik/RUGC-Dataset/validate_rugc.py
-
curl -L -o validate_rugc.py https://huggingface.co/datasets/DenSnoychik/RUGC-Dataset/resolve/main/validate_rugc.py
5.63 kB
| #!/usr/bin/env python3 | |
| """Read-only RUGC v1 package validator. Python standard library only.""" | |
| import argparse, json, pathlib, re, struct, sys, zipfile | |
| SUPPORTED={'range','toggle','select','color'} | |
| TARGETS={'visibility','color','roughness','metalness','opacity','normalStrength','materialPreset','meshChoice','position.x','position.y','position.z','rotation.x','rotation.y','rotation.z','scale.x','scale.y','scale.z','scale.all'} | |
| ASSET_EXT=('.obj','.png','.jpg','.jpeg','.webp') | |
| def inspect(path): | |
| errors=[]; warnings=[]; table=[] | |
| if pathlib.Path(path).stat().st_size>100*1024*1024: errors.append('Размер пакета >100 МБ') | |
| with zipfile.ZipFile(path) as z: | |
| names=set(z.namelist()); total=sum(f.file_size for f in z.infolist()); | |
| if total>180*1024*1024: errors.append('Распакованный размер >180 МБ') | |
| if len(names)>700: errors.append('Число файлов >700') | |
| for n in names: | |
| if n.startswith('/') or '\\' in n or '..' in n.split('/'): | |
| errors.append('Опасный путь: '+n) | |
| if z.getinfo(n).file_size>35*1024*1024: errors.append('Файл >35 МБ: '+n) | |
| if 'manifest.json' not in names: raise ValueError('Нет manifest.json') | |
| m=json.loads(z.read('manifest.json')) | |
| if m.get('format')!='RUGC' or m.get('formatVersion')!=1: errors.append('Требуется RUGC v1') | |
| if not m.get('name'): errors.append('Не указано name') | |
| qualities=m.get('qualities',[]); parts=m.get('parts',[]); ctrls=m.get('controls',[]) | |
| if not (1<=len(qualities)<=8): errors.append('qualities: 1–8') | |
| if not (1<=len(parts)<=80): errors.append('parts: 1–80') | |
| if len(ctrls)>120: errors.append('controls: максимум 120') | |
| pids={p['id'] for p in parts if 'id' in p} | |
| qids=[q.get('id') for q in qualities] | |
| if len(set(qids))!=len(qids):errors.append('Дубли qualities.id') | |
| if len(pids)!=len(parts):errors.append('Дубли/missing parts.id') | |
| for q in qids: | |
| tri=0 | |
| for p in parts: | |
| fn=p.get('meshes',{}).get(q) | |
| if fn not in names: errors.append(f'Нет OBJ {p.get("id")}/{q}: {fn}');continue | |
| vertices=[]; faces=0; bad=0 | |
| for ln in z.read(fn).decode('utf-8-sig').splitlines(): | |
| if ln.startswith('v '): | |
| try: vertices.append(tuple(map(float,ln.split()[1:4]))) | |
| except ValueError: bad+=1 | |
| elif ln.startswith('f '): | |
| pts=ln.split()[1:] | |
| if len(pts)!=3: bad+=1 | |
| else: | |
| try: | |
| ix=[int(p.split('/')[0]) for p in pts] | |
| if min(ix)<1 or max(ix)>len(vertices) or len(set(ix))<3:bad+=1 | |
| except Exception:bad+=1 | |
| faces+=max(0,len(pts)-2) | |
| if bad:errors.append(f'Некорректные грани/вершины {fn}: {bad}') | |
| tri+=faces | |
| table.append((q,tri)) | |
| lim=m.get('limits',{}).get('maxTriangles',4000) | |
| if tri>lim:errors.append(f'Качество {q}: {tri} > {lim} треугольников') | |
| for p in parts: | |
| for mat in [p.get('material',{}),*p.get('materialPresets',{}).values()]: | |
| for k in ('colorMap','normalMap','roughnessMap','metalnessMap'): | |
| asset=mat.get(k) | |
| if asset is not None and asset not in names:errors.append(f'Отсутствует {k}: {asset}') | |
| for variant in p.get('meshVariants',{}).values(): | |
| for q in qids: | |
| if variant.get(q) not in names:errors.append('Отсутствует meshVariant '+str(variant.get(q))) | |
| for c in ctrls: | |
| if c.get('type') not in SUPPORTED:errors.append('Тип настройки '+str(c.get('id'))) | |
| if c.get('target') not in TARGETS:errors.append('Target настройки '+str(c.get('id'))) | |
| for pid in c.get('parts',[]): | |
| if pid not in pids: errors.append(f'Настройка {c.get("id")} указывает на неизвестную часть {pid}') | |
| if m.get('defaultQuality') and m['defaultQuality'] not in qids: errors.append('Неверный defaultQuality') | |
| for n in names: | |
| if n.lower().endswith('.png'): | |
| dat=z.read(n)[:24] | |
| if len(dat)<24 or not dat.startswith(b'\x89PNG\r\n\x1a\n'): errors.append('Некорректный PNG: '+n) | |
| else: | |
| w,h=struct.unpack('>II',dat[16:24]); | |
| if w>2048 or h>2048:warnings.append(f'Текстура {n}: {w}x{h}, может превышать лимит Roblox') | |
| return m,table,errors,warnings | |
| if __name__=='__main__': | |
| ap=argparse.ArgumentParser();ap.add_argument('file');a=ap.parse_args() | |
| try: | |
| m,table,errors,warnings=inspect(a.file) | |
| print('Пакет:',m.get('name')) | |
| for q,tri in table:print(f' {q}: {tri} треугольников (без проверки посадки)') | |
| for w in warnings:print('ПРЕДУПРЕЖДЕНИЕ:',w) | |
| for e in errors:print('ОШИБКА:',e) | |
| print('РЕЗУЛЬТАТ:', 'ОК — структурные проверки' if not errors else 'НЕ ПРОШЁЛ') | |
| sys.exit(1 if errors else 0) | |
| except Exception as e:print('НЕ УДАЛОСЬ ПРОЧИТАТЬ:',e);sys.exit(2) | |