Files
vibemake/scripts/package-latest-robot-uploads.py
T
Jerry 1c837766cd feat: integrate robot assembly and simulation with resilient loading
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.
2026-10-30 18:38:39 +08:00

223 lines
19 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Prepare three upload folders from the supplied Sandbox snapshot and verified LFS blobs."""
import copy
import argparse
import hashlib
import json
from pathlib import Path
import shutil
import struct
import xml.etree.ElementTree as ET
import zipfile
REPO = Path(__file__).resolve().parents[1]
SOURCE = Path('/Users/jerry/Downloads/vibemakersandbox')
PUBLIC = SOURCE / 'app/public'
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--out', type=Path, default=Path('/Users/jerry/Downloads/三个机器人-当前上传'))
parser.add_argument('--resume', action='store_true')
args = parser.parse_args()
OUT = args.out
PREVIOUS = Path('/Users/jerry/Downloads/机器人后台上传测试-20261029')
LATEST_DUCK = Path('/Users/jerry/Downloads/小鸭子-双腿及躯干-当前上传/小鸭子-双腿及躯干-149步装配.json')
LFS_INDEX = Path('/tmp/make-latest-lfs.json')
LFS = {r['path']: r for r in json.loads(LFS_INDEX.read_text())} if LFS_INDEX.exists() else {}
VERIFIED = Path('/Users/jerry/Downloads/三个机器人-最新上传资料-20261029')
VERIFIED_INDEX = VERIFIED / '文件来源与SHA256.json'
VERIFIED_FILES = {r['source']: VERIFIED / r['file'] for r in json.loads(VERIFIED_INDEX.read_text())} if VERIFIED_INDEX.exists() else {}
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
resume = args.resume
assert not resume or not (OUT / '整理结果.json').exists(), 'Completed delivery must not be overwritten'
OUT.mkdir(exist_ok=resume) # Resume only an unfinished delivery created by this script.
duck = OUT / '01-小鸭子-Microduck'
ban = OUT / '02-双足机器人-Microban'
rp1 = OUT / '03-双足机器人-RP1'
for folder in (duck, ban, rp1):
folder.mkdir(exist_ok=resume)
# Preserve previously supplied display/assembly assets independently of simulation assets.
copy_tree(PREVIOUS / '01-Microduck小鸭子/01-整机模型', duck / '01-整机模型')
duck_assembly = Path('/Users/jerry/Downloads/小鸭子-扳手装配')
copy_tree(duck_assembly / '零件模型', duck / '02-零件模型')
copy_file(LATEST_DUCK, duck / '03-拼装步骤' / LATEST_DUCK.name)
latest_duck = json.loads(LATEST_DUCK.read_text())
assert len(latest_duck['steps']) == 149 and len(latest_duck['parts']) == 201
assert not {'trunk-3-36', 'trunk-3-37'} & {s['id'] for s in latest_duck['steps']}
copy_file(REPO / 'deliverables/experience-packages/microduck-numbered-body/validation.json', duck / '99-来源与核对/149步装配校验.json')
copy_file(REPO / 'deliverables/experience-packages/microduck-numbered-body/axis-review.json', duck / '99-来源与核对/149步轴向记录.json')
assert json.loads((duck / '99-来源与核对/149步装配校验.json').read_text())['sha256'] == sha(LATEST_DUCK.read_bytes())
for name in ('01-整机模型', '02-零件模型', '03-拼装步骤'):
copy_tree(PREVIOUS / '02-Microban双足机器人' / name, ban / name)
duck_motion = duck / '04-机器人运动演示'
for name in ('robot', 'policies', 'assets', 'worlds', 'licenses'):
copy_tree(PUBLIC / name, duck_motion / name)
# One root robot.json for admin discovery. Only path strings are rebased.
# Keep roller configuration under a distinct name; runtime adapter support is documented.
for source_name, target in [('microduck-legs', 'robot.json'), ('microduck-rollers', 'variants/rollers.json')]:
src = PUBLIC / 'robots' / source_name / 'robot.json'
d = json.loads(src.read_text())
original = copy.deepcopy(d)
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(duck_motion / target, d)
copy_file(src, duck / f'99-来源与核对/原配置/{source_name}.json')
check = copy.deepcopy(d)
check['model'] = original['model']
for s, old in zip(check['skills'], original['skills']):
if old['controller'].get('policy'):
s['controller']['policy'] = old['controller']['policy']
assert check == original, 'Only resource path rebasing is allowed'
for name, folder in [('microban', ban), ('rp1', rp1)]:
motion = folder / '04-机器人运动演示'
copy_tree(PUBLIC / 'robots' / name, motion)
copy_tree(PUBLIC / 'worlds', motion / 'worlds')
copy_file(SOURCE / f'docs/robots/{name}.md', folder / f'99-来源与核对/{name}-原项目说明.md')
for folder in (duck, ban, rp1):
copy_file(SOURCE / 'README.md', folder / '99-来源与核对/Sandbox-README.md')
copy_file(SOURCE / 'LICENSE', folder / '99-来源与核对/Sandbox-代码LICENSE')
copy_file(REPO / 'sandbox/UPSTREAM.md', duck / '99-来源与核对/小鸭子-已有来源说明.md')
copy_file(REPO / 'sandbox/NOTICE', duck / '99-来源与核对/小鸭子-已有NOTICE')
common = '''\n运动上传:选择整个“04-机器人运动演示”目录;如果后台是 ZIP 入口,选择同级“04-机器人运动演示.zip”。二选一,不要两份同时上传。\n资源清单根目录应直接出现 robot.json,不能额外套一层机器人文件夹。保留目录和文件名。\n99-来源与核对只供开发者核对,不上传为装配步骤/运动资源。\n\n本批仅整理文件,未修改前台或后台。最新 Sandbox 与社区当前播放器的支持范围不同;文件完整不等于已完成前台运行验证。先上传测试项目,播放器适配完成后再验证动作。\n'''
(duck / '00-上传说明.txt').write_text('''Microduck 小鸭子\n\n1. 整机模型(可选):01-整机模型/Microduck-整机.glb。\n 这是上轮由运动网格、运动学姿态及原 classic 配色生成的展示版,原样保留;不是本次重新生成的 GLB,也不是下方用户零件的合并导出。\n2. 零件模型:选择整个 02-零件模型(292 个原零件 + 1 个内六角扳手)。\n3. 拼装步骤:只选 03-拼装步骤/小鸭子-双腿及躯干-149步装配.json。\n 这是本次最新修订版:左腿 52 步 → 右腿 52 步 → 躯干 45 步,共 149 步、201 个零件实例;按确认跳过 3-36、3-37,后续编号不变。\n 本次编号范围不含头部/颈部,装配整体视图只展示双腿与躯干;整机模型与运动包仍是完整小鸭子。\n 已匹配现有 GLB,保留扳手动画,并执行轴向与进入距离优化。仍有部分干涉,不能视为全程无穿模认证。\n 02 目录保留完整 292 个原零件及扳手,149 步引用其中 187 个零件 GLB 加 1 个工具;同规格螺丝可复用文件形成独立实例。\n4. 机器人运动演示:选择 04 目录或同级 ZIP。\n\n新版运动包:9 个 ONNX,含行走、坐起/站起、翻滚、左右踢球、俯身拾取、恢复站立、轮滑、轮滑蹲伏;同时保留两套物理配置、运动映射、道具与声音素材。\n主配置 robot.json 对应腿式,轮滑配置 variants/rollers.json。为适配上传入口,仅修改两份配置中的资源相对路径;物理参数、策略和模型字节未改。\n\n兼容状态:当前社区仍是旧 microduck-alpha-v1 运行器。新版 microduck adapter、双模式和轮滑不能只换 ZIP 就运行;需同步新版适配器,并将其固定的模型/策略/素材请求改成使用后台返回的文件 URL。variants/rollers.json 是本包的轮滑入口;此路径安排已在开发说明记录。\n缺足球模型文件不代表漏传:原工程的足球由运行器创建,踢球策略已包含。\n''' + common)
(ban / '00-上传说明.txt').write_text('''Microban 双足机器人\n\n1. 整机模型:01-整机模型/机器人.glb(用户原文件)。\n2. 零件模型:选择整个 02-零件模型,保留里面的 parts/,275 个 GLB。不要只选内层 parts,因为步骤引用带 parts/ 前缀。\n3. 拼装步骤:03-拼装步骤/Microban-拼装步骤.json(此前的全机装配流程)。\n4. 机器人运动演示:选择 04 目录或同级 ZIP。\n\n新版运动:1 个行走 ONNX + 配置里的头部摆动;25 个物理网格、20 个 body_visuals GLB 外观。无踢球、无轮滑,不要求上传足球。\n运动外观来自最新 Sandbox 的 visuals/;它与 01/02 的用户整机/装配 GLB 是两套资料,均按来源原样保存。\n\n兼容状态:当前社区需要同步新版 SchemaValidator、BodyVisuals 加载/资源 URL 解析及新字段支持。否则旧播放器可能报配置不支持或不能显示新外观。\n''' + common)
(rp1 / '00-上传说明.txt').write_text('''RP1 双足机器人\n\n本次可上传:04-机器人运动演示 目录或同级 ZIP。\n最新源代码没有可用于社区整机上传的完整 GLB、独立装配 GLB 或安装步骤 JSON,所以没有伪造 01/02/03;后台这些项留空。STL 是运动物理模型依赖,不要上传到“零件 GLB”字段。\n\n新版运动:model.xml + 25 个 STL + 3 个 ONNX(walk/dance/wave)。\n舞蹈和挥手还分别依赖 motions/*.json 与对应的 *.f32 参考动作数据,不能漏传。\n舞蹈配置 duration=10 秒;虽然参考数据更长,本包沿用原工程已启用的 10 秒片段,不自行扩大播放范围。挥手为 4.36 秒。\n没有足球或踢球,不要求也不附加踢球策略。\n\n兼容状态:当前社区需要新版历史观测、episodic 动作、JointMotionReference、动作切换和按关节 PD/力矩限制支持。旧播放器不能只靠上传 ZIP 播放这些功能。模型/策略/动作数据均未重训练、修改或重新导出。\n''' + common)
summary = []
for folder, entries in [(duck, ['robot.json', 'variants/rollers.json']), (ban, ['robot.json']), (rp1, ['robot.json'])]:
motion = folder / '04-机器人运动演示'
configs = validate_motion(motion, entries)
files = inventory(motion)
archive = folder / '04-机器人运动演示.zip'
with zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as z:
for f in files:
z.write(motion / f['path'], f['path'])
with zipfile.ZipFile(archive) as z:
assert z.testzip() is None
assert sorted(z.namelist()) == sorted(f['path'] for f in files)
for f in files:
assert sha(z.read(f['path'])) == f['sha256']
record = {'folder': folder.name, 'configs': configs, 'files': len(files),
'uncompressedBytes': sum(f['bytes'] for f in files), 'zipBytes': archive.stat().st_size}
write_json(folder / '99-来源与核对/运动文件校验.json', {
'sourceDirectory': str(SOURCE), 'checked': ['resource paths', 'MJCF mesh dependencies', 'source hashes',
'motion reference dimensions and joint order', 'embedded GLB', 'no Git LFS pointers', 'ZIP CRC and SHA256'],
'browserPlaybackTested': False, 'configs': configs, 'files': files})
summary.append(record)
print(json.dumps(record, ensure_ascii=False), flush=True)
write_json(OUT / '文件来源与SHA256.json', PROVENANCE)
write_json(OUT / '整理结果.json', summary)
(OUT / '00-先看这里.txt').write_text('''三个机器人 · 当前上传资料 · 2026-10-29\n\n01-小鸭子-Microduck:整机展示版、292 个用户零件和扳手、最新双腿及躯干 149 步装配(跳过 3-36、3-37)、新版双模式运动包。\n02-双足机器人-Microban:原整机、275 个零件、全机装配 JSON、新版带 GLB 外观的行走包。\n03-双足机器人-RP1:新版行走/舞蹈/挥手运动包;源工程没有整机 GLB 和装配步骤,这两项留空。\n\n本目录为这次重新整理的当前上传资料。小鸭子 03 目录只放最新 149 步 JSON,不包含旧 91 步或 52 步文件,避免选错。\n每个机器人分别上传到对应项目,不要混传。具体选哪个文件/目录,阅读每个目录的 00-上传说明.txt。\n运动文件夹与 ZIP 内容相同,后台选一种入口即可。所有 Git LFS 占位文件已补齐成真实资源并核对哈希。\n\n本次整理了最新完整资源,但没有更新社区播放器,也未完成三套新版包的浏览器运行联调。小鸭子双模式、Microban 的 body_visuals、RP1 的动作参考和历史观测需要前台同步适配;不要把“资源校验通过”理解为“上传后即可正常播放”。\n原 GLB/ONNX/MJCF/STL/F32 字节按来源保留,未统一染色、重写材质或重新训练。小鸭子 robot.json 仅作上传根目录路径整理,原配置另存以便核对。\n文件来源与SHA256.json、整理结果.json 供核对,不上传到资源字段。\n''')
(OUT / '前台适配交接.txt').write_text('''最新运动包与当前社区播放器的对接点\n\n源代码:/Users/jerry/Downloads/vibemakersandbox/app/src\n社区项目:/Users/jerry/vibemake-site\n1. 保持按接口资源清单读取,不按项目名或本地 demo 路径代替。每个运动目录仅有一个 basename=robot.json,作为主入口。\n2. Microduck:主入口 robot.json,轮滑入口 variants/rollers.json。源工程 app/public/robots/microduck-legs/robot.json 和 microduck-rollers/robot.json 的 model、controller.policy 相对路径已重新定位,其余字段不变。适配器目前固定请求这两个旧路径,需要改为上述入口和后台资源映射;仅更换文件名不能兼容旧运行器。\n3. Microduck 还需将 ./robot/mjlab、./policies、./assets 的固定请求映射到本包根目录;腿式和轮滑分别使用各自 MJCF/kinematics,勿让多个 primary 同时控制同一关节。\n4. Microban:递归收集 render.body_visuals[].path;调用新版 BodyVisuals,保留 position/quaternion 和原 GLB 材质。\n5. RP1:完整支持 observations.history/term-major、逐关节 actuation、episodic skills、参考动作和 blend/reset;收集 skills[].controller.policy、skills[].reference,以及 motions JSON 的 data 路径。data 相对于 robot.json 包根目录,不能再拼一层 motions/。\n6. 使用最新 robot/world schema、动作编排和依赖解析,动作按钮按 skills/availability 生成;无踢球不创建足球。头部摆动来自 oscillator 配置,无需 ONNX。\n7. worlds/arena/world.json 与 worlds/flat/world.json 已随每个包提供,保持原工程按机器人尺寸缩放边界的规则。\n8. 保留手机/低性能设备的按需渲染、后台暂停、像素比预算、资源释放,切换动作后检查暂停/重置和默认不自动行走。\n\n已做资源/路径/哈希检查;未把未完成的运行联调标为通过。来源说明保留在每个包的 SOURCE.md/LICENSES/ 和 99-来源与核对。\n''')
print('COMPLETE:', OUT)