1c837766cd
Add backend-driven assembly and simulation experiences, MAKE branding, mobile rendering budgets and desktop-only CAD/PCB routes. Improve logo loading progress, document image recovery and URDF request handling; include dev packaging and regression coverage.
215 lines
12 KiB
Python
215 lines
12 KiB
Python
"""Build current upload assets, preserving source data and validating every dependency."""
|
|
import copy, hashlib, json, shutil, struct, zipfile
|
|
from pathlib import Path
|
|
import xml.etree.ElementTree as ET
|
|
REPO = Path(__file__).resolve().parents[1]
|
|
SOURCE = Path('/Users/jerry/Downloads/vibemakersandbox 2')
|
|
PUBLIC = SOURCE / 'app/public'
|
|
OUT = Path('/Users/jerry/Downloads/三个机器人-后台上传-20261030')
|
|
LFS = {r['path']: r for r in json.loads(Path('/tmp/make-current-lfs.json').read_text())}
|
|
VERIFIED_FILES = {}
|
|
PROVENANCE = []
|
|
def sha(data):
|
|
return hashlib.sha256(data).hexdigest()
|
|
|
|
|
|
def write_json(path, value):
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(json.dumps(value, ensure_ascii=False, indent=2) + '\n')
|
|
|
|
|
|
def copy_file(source, dest):
|
|
data = source.read_bytes()
|
|
if data.startswith(b'version https://git-lfs.github.com/spec/v1'):
|
|
pointer = dict(line.split(' ', 1) for line in data.decode().strip().splitlines())
|
|
expected_sha = pointer['oid'].removeprefix('sha256:')
|
|
expected_size = int(pointer['size'])
|
|
key = source.relative_to(PUBLIC).as_posix()
|
|
local = Path(LFS[key]['local']) if key in LFS else VERIFIED_FILES.get(str(source))
|
|
if local is None or not local.is_file():
|
|
local = VERIFIED_FILES.get(str(source))
|
|
assert local and local.is_file(), f'Missing real Git LFS resource: {key}'
|
|
data = local.read_bytes()
|
|
assert len(data) == expected_size and sha(data) == expected_sha, key
|
|
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
dest.write_bytes(data)
|
|
assert sha(dest.read_bytes()) == sha(data)
|
|
PROVENANCE.append({'file': dest.relative_to(OUT).as_posix(), 'source': str(source),
|
|
'bytes': len(data), 'sha256': sha(data)})
|
|
|
|
|
|
def copy_tree(source, dest):
|
|
for p in sorted(source.rglob('*')):
|
|
if p.is_file() and not any(s.startswith('.') for s in p.relative_to(source).parts):
|
|
copy_file(p, dest / p.relative_to(source))
|
|
|
|
|
|
def inventory(folder):
|
|
return [{'path': p.relative_to(folder).as_posix(), 'bytes': p.stat().st_size,
|
|
'sha256': sha(p.read_bytes())} for p in sorted(folder.rglob('*')) if p.is_file()]
|
|
|
|
|
|
def validate_motion(folder, entries):
|
|
def require(name):
|
|
p = folder / name
|
|
assert p.resolve().is_relative_to(folder.resolve()), name
|
|
assert p.is_file(), name
|
|
return p
|
|
|
|
configs = []
|
|
for entry in entries:
|
|
config_path = require(entry)
|
|
d = json.loads(config_path.read_text())
|
|
base = config_path.parent
|
|
paths = [d['model']] + [a['path'] for a in d['assets']]
|
|
paths += [a['path'] for a in d['render'].get('body_visuals', [])]
|
|
paths += [s['controller']['policy'] for s in d['skills']
|
|
if s['controller']['type'] == 'onnx' and s.get('available', True)]
|
|
for s in d['skills']:
|
|
if not s.get('reference'):
|
|
continue
|
|
spec = json.loads((base / s['reference']).read_text())
|
|
blob = (base / spec['data']).read_bytes()
|
|
assert len(blob) == spec['frames'] * len(spec['joint_names']) * 2 * 4
|
|
assert spec['joint_names'] == d['joints']['groups'][s['owns']]
|
|
assert abs(spec['step_dt'] - d['sim']['timestep'] * d['sim']['decimation']) < 1e-9
|
|
paths += [s['reference'], spec['data']]
|
|
for name in paths:
|
|
require((base / name).relative_to(folder).as_posix())
|
|
xml_path = base / d['model']
|
|
xml = ET.parse(xml_path).getroot()
|
|
compiler = xml.find('compiler')
|
|
for elem in xml.iter():
|
|
file = elem.get('file')
|
|
if not file:
|
|
continue
|
|
prefix = ''
|
|
if compiler is not None:
|
|
prefix = compiler.get('meshdir' if elem.tag == 'mesh' else 'texturedir', '') if elem.tag in ('mesh', 'texture') else ''
|
|
# The original Microduck adapter mounts meshes/<name> as assets/<name>
|
|
# in MuJoCo VFS (runtime.js), without changing the source MJCF.
|
|
if d['adapter'] == 'microduck' and elem.tag == 'mesh' and prefix == 'assets':
|
|
prefix = 'meshes'
|
|
require((xml_path.parent / prefix / file).relative_to(folder).as_posix())
|
|
configs.append({'entry': entry, 'id': d['id'], 'skills': [s['id'] for s in d['skills']], 'resourceReferences': len(paths)})
|
|
for name in ('source-manifest.json', 'visual-source-manifest.json'):
|
|
p = folder / name
|
|
if p.exists():
|
|
d = json.loads(p.read_text())
|
|
for record in d['files'] + d.get('additionalNotices', []):
|
|
assert sha(require(record['file']).read_bytes()) == record['sha256'], record['file']
|
|
for record in inventory(folder):
|
|
p = folder / record['path']
|
|
b = p.read_bytes()
|
|
assert not b.startswith(b'version https://git-lfs.github.com/spec/v1'), p
|
|
if p.suffix.lower() == '.glb':
|
|
magic, version, size, chunk, typ = struct.unpack_from('<5I', b)
|
|
assert (magic, version, size, typ) == (0x46546c67, 2, len(b), 0x4e4f534a), p
|
|
doc = json.loads(b[20:20+chunk])
|
|
assert all(not a.get('uri') or a['uri'].startswith('data:') for a in doc.get('buffers', []) + doc.get('images', [])), p
|
|
return configs
|
|
|
|
OUT.mkdir(exist_ok=True)
|
|
duck = OUT/'01-小鸭子-Microduck'
|
|
ban = OUT/'02-人形机器人-Microban'
|
|
rp1 = OUT/'03-双足机器人-RP1'
|
|
for name,folder,parts,whole in [
|
|
('Microduck',duck,Path('/Users/jerry/Downloads/开发提交/鸭子最新glb'),Path('/Users/jerry/Downloads/鸭子_压缩.glb')),
|
|
('Microban',ban,Path('/Users/jerry/Downloads/开发提交/人形机器人-light-最终使用'),Path('/Users/jerry/Documents/人形.glb')),
|
|
('RP1',rp1,Path('/Users/jerry/Downloads/开发提交/RP1机器人glb'),Path('/Users/jerry/Documents/RP1.glb')),
|
|
]:
|
|
folder.mkdir(exist_ok=True)
|
|
copy_file(whole,folder/'01-整机模型'/f'{name}-整机.glb')
|
|
for p in parts.glob('*.glb'):copy_file(p,folder/'02-零件模型'/p.name)
|
|
|
|
# The new filenames are mapped by embedded node identity, not guessed by filename suffix.
|
|
manifest=json.loads((REPO/'deliverables/experience-packages/microduck-current/manifest.json').read_text())
|
|
newparts=[]
|
|
for p in sorted((duck/'02-零件模型').glob('*.glb')):
|
|
data=p.read_bytes();size=struct.unpack_from('<I',data,12)[0];doc=json.loads(data[20:20+size])
|
|
nodes=[n for n in doc['nodes'] if 'mesh' in n];assert len(nodes)==1,p.name
|
|
newparts.append({'file':p.name,'node':nodes[0]['name'],'bytes':len(data),'sha256':sha(data)})
|
|
# Local preview uses these exact supplied files, without re-encoding.
|
|
shutil.copytree(duck/'02-零件模型',REPO/'deliverables/current-robots/duck-parts',dirs_exist_ok=True)
|
|
by_node={p['node']:p for p in newparts};assert len(by_node)==243
|
|
for part in manifest['parts']:
|
|
node=part['file'].removesuffix('.glb');assert node in by_node,node
|
|
part['file']=by_node[node]['file']
|
|
for tool in manifest['tools']:
|
|
assert (duck/'02-零件模型'/tool['file']).is_file()
|
|
manifest['files']=[{'path':p['file'],'bytes':p['bytes'],'sha256':p['sha256']}for p in newparts]
|
|
assert len(manifest['steps'])==239 and len(manifest['parts'])==242
|
|
write_json(duck/'03-拼装步骤/小鸭子-239步装配.json',manifest)
|
|
copy_file(REPO/'deliverables/experience-packages/microduck-current/mapping.json',OUT/'开发核对/小鸭子-编号与模型差异.json')
|
|
write_json(OUT/'开发核对/小鸭子-原始零件文件校验.json',newparts)
|
|
(OUT/'开发核对/小鸭子-零件压缩与材质校验.json').unlink(missing_ok=True)
|
|
|
|
motion_roots={}
|
|
for name,folder in [('microduck',duck),('microban',ban),('rp1',rp1)]:
|
|
motion=REPO/'deliverables/current-robots'/name/'motion'
|
|
motion_roots[name]=motion
|
|
# copy_file records are relative to OUT: prepare inside upload folder first, then mirror for local preview.
|
|
stage=folder/'04-运动资源';stage.mkdir(exist_ok=True)
|
|
if name=='microduck':
|
|
for sub in ['robot','policies','assets','worlds','licenses']:copy_tree(PUBLIC/sub,stage/sub)
|
|
for srcname,target in [('microduck-legs','robot.json'),('microduck-rollers','variants/rollers.json')]:
|
|
d=json.loads((PUBLIC/'robots'/srcname/'robot.json').read_text());prefix=''if target=='robot.json'else'../'
|
|
d['model']=prefix+d['model'].removeprefix('../../')
|
|
for skill in d['skills']:
|
|
if skill['controller'].get('policy'):skill['controller']['policy']=prefix+skill['controller']['policy'].removeprefix('../../')
|
|
write_json(stage/target,d)
|
|
else:copy_tree(PUBLIC/'robots'/name,stage)
|
|
copy_file(SOURCE/'LICENSE',stage/'Sandbox-LICENSE')
|
|
for filename in ['NOTICE','UPSTREAM.md']:copy_file(REPO/'sandbox'/filename,stage/f'Sandbox-{filename}')
|
|
configs=validate_motion(stage,['robot.json','variants/rollers.json']if name=='microduck'else['robot.json'])
|
|
files=inventory(stage);size=sum(f['bytes']for f in files)
|
|
archive=folder/'04-仿真.zip'
|
|
(folder/'04-运动演示.zip').unlink(missing_ok=True)
|
|
with zipfile.ZipFile(archive,'w',zipfile.ZIP_DEFLATED,compresslevel=6)as z:
|
|
for f in files:z.write(stage/f['path'],f['path'])
|
|
with zipfile.ZipFile(archive)as z:assert z.testzip()is None
|
|
print(name,'motion',len(files),'files',round(size/1024/1024,1),'MiB', 'skills',configs[0]['skills'],flush=True)
|
|
shutil.copytree(stage,motion,dirs_exist_ok=True)
|
|
# ZIP is the only visible motion upload choice, so there is no duplicated directory to confuse uploaders.
|
|
shutil.rmtree(stage)
|
|
copy_file(SOURCE/f'docs/robots/{"microduck" if name=="microduck" else name}.md',OUT/f'开发核对/{name}-上游说明.md') if (SOURCE/f'docs/robots/{name}.md').exists()else None
|
|
instructions=f'''{name} 后台上传顺序
|
|
1. 整机模型:选择 01-整机模型 中的 GLB。
|
|
2. 零件模型:选择整个 02-零件模型 文件夹,保留文件名。
|
|
3. 拼装步骤:{'上传 03-拼装步骤/小鸭子-239步装配.json。' if name=='microduck' else '留空;此机器人没有安装步骤 JSON。若此前绑定过旧步骤,请清除旧步骤绑定。'}
|
|
4. 仿真:上传 04-仿真.zip。ZIP 解压根目录直接是 robot.json。
|
|
|
|
运动包包含模型、物理配置、控制配置、策略、动作数据及其依赖;不需要另传 JS、WASM 或网页。
|
|
随机几何体、碰撞/拖拽、光照、背景与网格调色由新版社区播放器提供;只上传 ZIP 不会更新旧前端。
|
|
先部署本次新版前端,再刷新项目详情验证。打开默认静止,方向键或动作按钮可直接开始;只有配置的动作才显示。
|
|
'''
|
|
if name=='microduck':instructions+='''
|
|
本次为最新完整 239 步:左腿 52、右腿 52、躯干 47、颈部 24、头部 64。
|
|
沿用已确认的双腿/已有躯干安装规则及扳手动画。242 个本次零件 + 1 个扳手,全部与新文件名匹配。
|
|
本次零件直接复制你提供的 GLB,字节、材质、颜色、贴图和文件名全部保持原样,不再额外压缩。
|
|
165 颗杯头螺丝的扳手朝向已修正为工作端对准螺丝头;原打入轴向及 239 步顺序保持不变。
|
|
整机用此前给出的最新“鸭子_压缩.glb”;零件用本次“鸭子最新glb”,最终安装坐标来自对应整机。
|
|
部分源模型配合接触/编号规格差异仍按上轮说明保留,未宣称全程无穿模。
|
|
'''
|
|
if name=='rp1':instructions+='''
|
|
本次 RP1 仿真使用上游新增的带原材质视觉件;63 个零件挂接到现有 25 个物理 body。
|
|
两个手部由上游工具按固定手型合并,原材质/贴图保留;未改变物理关节、训练策略。
|
|
动作包括行走、跳舞和挥手;没有踢球,不需要足球策略。
|
|
'''
|
|
(folder/'上传说明.txt').write_text(instructions)
|
|
|
|
(OUT/'先看这里.txt').write_text('''三个机器人 · 最新后台上传资料 · 2026-10-30
|
|
|
|
每个机器人分别进入自己的后台项目,按子目录里的“上传说明.txt”上传。
|
|
01-小鸭子-Microduck:整机 GLB、243 个零件/工具 GLB、239 步 JSON、运动 ZIP。
|
|
02-人形机器人-Microban:整机 GLB、20 个零件 GLB、运动 ZIP;拼装步骤留空。
|
|
03-双足机器人-RP1:整机 GLB、63 个零件 GLB、运动 ZIP;拼装步骤留空。
|
|
|
|
不要把这整个总文件夹压成一个包上传到仿真;分别用各机器人里的 04-仿真.zip。
|
|
零件需整批替换/绑定,避免旧零件混入。小鸭子 JSON 必须与本批 02 文件夹配套。
|
|
开发核对目录只供核对,不需要上传。
|
|
本次只准备文件和更新社区播放器,没有替你修改后台资源绑定。
|
|
''')
|
|
write_json(OUT/'开发核对/文件来源与SHA256.json',PROVENANCE)
|
|
print('READY',OUT)
|