#!/usr/bin/env python3 """gvr-map-extract 결과(<코드>.glb + <코드>.json)를 사이트용으로 압축한다. pack.py <추출 폴더> <출력 폴더> <버전(예: VALORANT_13.08)> (agents.json 이 있으면 요원 agent_*.glb · 무기 weapon_*.glb 도 같은 폴더에, index.json agents · weapons) 출력: <출력>//<코드>.glb.gz (gltfpack -cc 로 meshopt 압축 · 위치 양자화 → gzip) + <출력>/index.json -ke: 재질 extras(두 층 섞기 B 층) 유지, -vt 14: 반복 UV 가 뭉개지지 않게 사이트 서버 data/maps3d 에 그대로 올리면 된다 (site/server/src/maps3d.ts).""" import datetime, gzip, json, os, re, shutil, subprocess, sys src, out, version = sys.argv[1], sys.argv[2], sys.argv[3] stamp = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%d%H%M') d = re.sub(r'[^\w.-]', '_', f'{version}-{stamp}') os.makedirs(os.path.join(out, d), exist_ok=True) maps = {} for name in sorted(os.listdir(src)): if not name.endswith('.json') or name == 'agents.json': continue info = json.load(open(os.path.join(src, name))) code = info['code'] glb = os.path.join(src, code + '.glb') if not os.path.exists(glb) or info.get('triangles', 0) == 0: continue packed = os.path.join(out, d, code + '.glb') subprocess.run(['npx', '-y', 'gltfpack@1.3.0', '-i', glb, '-o', packed, '-cc', '-ke', '-vt', '14'], check=True, stdout=subprocess.DEVNULL) with open(packed, 'rb') as f, gzip.open(packed + '.gz', 'wb', 9) as g: shutil.copyfileobj(f, g) os.remove(packed) size = os.path.getsize(packed + '.gz') maps[info['mapUrl']] = {'code': code, 'file': code + '.glb', 'bytes': size, 'triangles': info['triangles']} print(f"{code}: {info['triangles']} 삼각형 → {size / 1e6:.1f}MB") # 요원 · 무기 (agents 명령 결과 agents.json 이 있으면): 뼈대 · 애니메이션 · 노드 이름을 지킨다 (-kn) agents, weapons = {}, {} aj = os.path.join(src, 'agents.json') if os.path.exists(aj): a = json.load(open(aj)) def pack_one(file): glb = os.path.join(src, file) if not os.path.exists(glb): return None packed = os.path.join(out, d, file) subprocess.run(['npx', '-y', 'gltfpack@1.3.0', '-i', glb, '-o', packed, '-cc', '-kn', '-ke'], check=True, stdout=subprocess.DEVNULL) with open(packed, 'rb') as f, gzip.open(packed + '.gz', 'wb', 9) as g: shutil.copyfileobj(f, g) os.remove(packed) return os.path.getsize(packed + '.gz') for cls, v in a.get('agents', {}).items(): size = pack_one(v['file']) if size: agents[cls] = {'code': v['code'], 'file': v['file'], 'bytes': size} for name, v in a.get('weapons', {}).items(): size = pack_one(v['file']) if size: weapons[name] = {'file': v['file'], 'bytes': size, 'points': v.get('points') or {}} print(f'요원 {len(agents)} · 무기 {len(weapons)}') idx = {'version': version, 'dir': d, 'updatedAt': datetime.datetime.now(datetime.timezone.utc).isoformat(), 'maps': maps, 'agents': agents, 'weapons': weapons} tmp = os.path.join(out, 'index.json.tmp') json.dump(idx, open(tmp, 'w'), ensure_ascii=False, indent=1) os.replace(tmp, os.path.join(out, 'index.json')) print(f'index.json: 맵 {len(maps)}개 · 폴더 {d}')