Compare commits

..

No commits in common. "main" and "feat/poc-cluster-productization" have entirely different histories.

188 changed files with 153047 additions and 10431 deletions

11
.dockerignore Normal file
View File

@ -0,0 +1,11 @@
.git
.venv
.pytest_cache
workspace
acceptance_runs
qa
docs
tests
**/__pycache__
**/*.pyc
*.tgz

View File

@ -1,3 +0,0 @@
DASHSCOPE_API_KEY=sk-your-beijing-region-api-key
DASHSCOPE_API_BASE=https://dashscope.aliyuncs.com/api/v1
PORT=8789

View File

@ -1,25 +0,0 @@
#!/bin/sh
set -eu
node --input-type=module - "$1" <<'NODE'
import { readFileSync } from 'node:fs';
const messagePath = process.argv[2];
const message = readFileSync(messagePath, 'utf8');
const subject = message
.split(/\r?\n/)
.find((line) => line.trim() && !line.trimStart().startsWith('#'))
?.trim();
if (!subject) {
console.error('commit-msg: commit subject is empty.');
process.exit(1);
}
const startsWithEmoji = /^(?:\p{Emoji_Presentation}|\p{Extended_Pictographic}\uFE0F?)/u.test(subject);
if (!startsWithEmoji) {
console.error('commit-msg: commit subject must start with an emoji, for example "✨ add asset cache".');
process.exit(1);
}
NODE

View File

@ -1,11 +0,0 @@
#!/bin/sh
set -eu
echo "pre-commit: running unit tests"
npm run test:run
echo "pre-commit: running lint"
npm run lint
echo "pre-commit: running production build"
npm run build

View File

@ -1,21 +0,0 @@
---
name: Bug report
about: A reproducible problem in the workbench or an exported scene
---
## What happened?
## Reproduction steps
## Environment
- OS / CPU / GPU:
- Node.js / browser:
- Python / Genesis version (if relevant):
- Demo or generation mode:
## Expected result
## Logs or screenshots
Remove credentials, private assets and signed download URLs before posting.

View File

@ -1,10 +0,0 @@
---
name: Feature request
about: Describe a concrete workflow that the workbench should support
---
## Workflow and user need
## Current workaround
## Proposed behavior and an example

View File

@ -1,34 +0,0 @@
name: CI
on: [push, pull_request]
permissions:
contents: read
jobs:
workbench:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run test:run
- run: npm run lint
- run: npm run build
- run: npm audit --omit=dev
- run: npx playwright install --with-deps chromium
- run: npm run test:e2e
- uses: actions/upload-artifact@v4
if: always()
with:
name: browser-evidence
path: artifacts/smoke/
metric-tests:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: python -m pip install numpy==2.4.6
- run: python scripts/test-physics-metrics.py

48
.gitignore vendored
View File

@ -1,35 +1,21 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
.DS_Store
.env
.env.*
!.env.example
.data
coverage
.venv
__pycache__
*.pyc
artifacts
playwright-report
test-results
.pytest_cache/
.ruff_cache/
.venv/
__pycache__/
*.py[cod]
*.log
config.toml
workspace/
acceptance_runs/
dist/
build/
*.egg-info/
certs/
secrets/
models/
checkpoints/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -1,21 +0,0 @@
# Contributing
Use Node.js 22.12+ and `npm ci`. Start with `npm run demo`; it uses an isolated local data directory and cannot call the paid generation API.
Before submitting a pull request:
```bash
npm run test:run
npm run lint
npm run build
npm run test:e2e
npm audit
```
The browser smoke test needs Chromium (`npx playwright install chromium`). It starts and stops its own isolated servers. For changes to physical parameter mapping or the Python export, also run the example through Genesis and include `metrics.json`, the environment, and reproduction commands.
Keep changes focused. Include a regression test for changed behavior and explain visible limitations. Do not commit `.env.local`, `.data`, virtual environments, credentials, private generated assets, or account sessions.
Useful first contributions include installation reports, a reproducible cloth example, unit-aware material presets, accessible keyboard controls and additional generation-provider adapters. Open an issue before adding a new simulator backend.
Existing optional Git hooks can be enabled with `git config core.hooksPath .githooks`. Their commit-message convention requires an emoji prefix. Contributions are licensed under MIT.

131
README.md
View File

@ -1,92 +1,89 @@
# Real2Sim Studio
# Real2Sim Platform
**A local-first workbench for 3D assets and Genesis simulation exports.**
管理视频/图片到 3D 场景重建、Scene Builder 场景、专家策略采集、数据集、训练和推理任务的单机平台。
[![CI](https://github.com/eust-w/real2sim-platform/actions/workflows/ci.yml/badge.svg)](https://github.com/eust-w/real2sim-platform/actions/workflows/ci.yml)
[中文](docs/README.zh-CN.md) · [Offline example](examples/README.md) · [Roadmap](docs/ROADMAP.md) · [Contributing](CONTRIBUTING.md) · [MIT license](LICENSE)
![Real2Sim Studio workbench](docs/images/workbench.png)
[Download v0.1.0 Alpha](https://github.com/eust-w/real2sim-platform/releases/tag/v0.1.0-alpha.1) · [90-second introduction](https://github.com/eust-w/real2sim-platform/releases/download/v0.1.0-alpha.1/real2sim-intro-en.mp4) · [中文视频](https://github.com/eust-w/real2sim-platform/releases/download/v0.1.0-alpha.1/real2sim-intro-zh.mp4) · [Gitea mirror](https://gitea.d-robotics.cc/longtao.wu/real2sim-platform)
[Watch on X](https://x.com/eustancewu/status/2115131684236800501) · [Watch on Douyin](https://www.douyin.com/video/7701399089530916159) · [Publication status](docs/releases/publication-status.md)
Inspect a GLB, configure a material preset and export a self-contained Genesis scene. Start with the included procedural example without an API key, or connect your own DashScope account for Tripo text/image-to-3D generation.
## Try it
Requires Node.js **22.12 or later**.
## 本机启动
```bash
git clone https://github.com/eust-w/real2sim-platform.git
cd real2sim-platform
npm ci
npm run demo
cd /Users/d-robotics/workSpace/real2sim2model/real2sim-platform
PYTHONPATH=src python -m real2sim_platform.server --host 127.0.0.1 --port 18126
```
Open the Vite URL printed in the terminal (normally `http://127.0.0.1:5173`). Select **Load example**, rotate the model, adjust the material controls, then **Export Genesis Package**. Demo mode cannot make paid generation calls and uses `.data/demo/`, separate from your usual tasks.
打开:
## What is included
```text
http://127.0.0.1:18126/
```
- Text, single-image and multi-image generation through DashScope / Tripo using your own account.
- Local task history and asset caching, GLB preview and downloads.
- A self-contained, MIT-licensed procedural sample.
- Material preset controls and Genesis export using the current settings, including gravity.
- FEM elastic export and an experimental PBD cloth export path.
- English / Chinese UI, unit tests, backend type checking and browser smoke tests.
## 任务类型
The package contains the mesh, `flex-profile.json`, `manifest.json`, `genesis_scene.py`, pinned runtime requirements and instructions. Physics runs in **Genesis**, not in the browser preview.
- `hf_import`: 从 Hugging Face dataset 下载指定 revision / allow patterns,落到 `workspace/datasets/{dataset_id}` 并生成 `dataset_manifest.json`。
- `media_prepare`: 把 HuggingFace parquet/video URL、本地 video、图片目录统一准备成 `prepared_media` dataset,默认按 `sample_fps=2`、`max_frames_per_video=80` 抽帧并生成 `prepared_manifest.json`。
- `reconstruction_preflight`: 对 prepared frames / 图片目录做重建前检查,默认要求 `min_frames=30`,输出 `capture_preflight_report.json`。
- `scene_reconstruction`: 视频/图片/RGBD 到 Real2Sim 场景包,默认走 `gs_playground/scripts/real2sim_video_motrix_scene.py`,支持 `mujoco` 和 `motrixsim` 产物。
- `simulator_validation`: 按 `smoke`、`runtime_if_available` 或 `runtime_required` 校验场景包中的 MuJoCo / MotrixSim 产物,输出 `validation_report.json`。
- `expert_collection`: 调用 `real2sim_expert.collect`,输出 `rollouts.jsonl`、`manifest.json` 和可视化帧。
- `training`: 调用 `real2sim_train.train`,输出 `policy_head.json`、`model_card.json`。
- `inference`: 调用 `real2sim_infer.run`,输出 `prediction_rollout.json` 和 `viewer.html`。
- `renderer_benchmark`: 记录 Aholo Viewer 与 Spark 的集成选择,默认 Spark,Aholo 用作大规模 LOD 备选。
## Run the exported scene
## 关键接口
See the [complete example guide](examples/README.md) for Python environment setup.
- `GET /api/version`
- `GET /api/datasets/{id}/manifest`
- `GET /api/scenes/{id}/manifest`
- `GET /api/models/{id}/card`
- `GET /api/tasks/{id}/reports`
- `GET /api/artifacts/{id}/content`
前端固定页面:总览、验收、数据、场景、3D 预览、采集、训练、推理、任务。
3D 预览页读取 scene manifest,优先用 vendored `@sparkjsdev/spark` 加载 PLY/SPZ/SPLAT/KSPLAT/SOG,失败或不可用时明确标为 Three.js fallback;Spark 和 Three.js runtime 都随静态文件部署,不依赖浏览器访问外部 CDN。Manifest 会给资产补充 `size_bytes`、`autoload`、`viewer_hint`,超过默认阈值的大 PLY/点云不会自动加载,页面会提示手动点击加载。
## 重建运行时
无影默认运行时配置:
```text
runtime_root = /opt/real2sim_paper_runtime
anysplat_root = /opt/real2sim_paper_runtime/AnySplat
anysplat_python = /opt/real2sim_paper_runtime/envs/anysplat/bin/python
cuda_home = /usr/local/cuda-12.1
```
`scene_reconstruction` 会向上游脚本显式传入 `--anysplat-root` 和
`--anysplat-python`,并导出 `REAL2SIM_ANYSPLAT_ROOT`、
`REAL2SIM_ANY_SPLAT_PYTHON`、`REAL2SIM_COLMAP_BIN` 等环境变量。
`reconstruction_preflight` 报告包含 `readiness_score` 和 `next_action`,用于 UI 向导区分“可以重建”“需要补帧/重采”“运行时配置缺失”等状态。
## 无影部署
默认通过 SSH 隧道访问,不把服务直接暴露公网。部署脚本会同步整个
`real2sim2model` 工作区到 `/opt/real2sim2model`,并保留远端
`real2sim-platform/workspace/` 中的历史任务、数据集和模型。
```bash
npm run example:export
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r examples/requirements.txt
python .data/genesis-packages/example-soft-puck/genesis_scene.py --steps 800 --record
bash scripts/deploy_wuying.sh --restart
ssh -i /Users/d-robotics/workSpace/document/80-private/orgs/drobotics/keys/wuying-39.106.101.95_ed25519 \
-L 18126:127.0.0.1:18126 root@39.106.101.95
```
The first run compiles solver kernels. Without `--record`, the scene runs numerical checks and saves metrics and a trajectory without requesting a camera. The recorded result uses the actual Genesis solver, not an animated preview.
**Alpha security limitation:** the optional Python runtime has known Pillow advisories constrained by an upstream MoviePy dependency. Use only the trusted example in an isolated environment; see [the audit note](SECURITY.md#known-optional-runtime-risk-2026-10-28). The Node audit and Python audit are separate.
## Optional AI generation
另开一个本地终端建立隧道:
```bash
cp .env.example .env.local
# Set your DashScope API key in .env.local.
npm run dev
ssh -i /Users/d-robotics/workSpace/document/80-private/orgs/drobotics/keys/wuying-39.106.101.95_ed25519 \
-L 18126:127.0.0.1:18126 root@39.106.101.95
```
Generation uses an external paid service. Provider models, generated assets and service terms are not covered by this repository's MIT license. A flexible variant is a new prompt-based generation; it is not deformation or reconstruction of the original GLB.
无影侧服务地址:
The local API defaults to `127.0.0.1:8789`. Set `PORT` in the shell or `.env.local` before starting to change it; the development proxy uses the same value. Shell values take precedence. Demo mode ignores dotenv files. This is a single-user local application, not a publicly hosted service. See [Security](SECURITY.md).
```text
http://127.0.0.1:18126/
```
## Limits
部署脚本会安装 `huggingface_hub`、`pyarrow`、`pillow`、`imageio`、`opencv-python-headless`、`mujoco` 等依赖,写入 systemd unit,并检查 `ffmpeg`、Spark bundle、Three.js bundle 和 AnySplat runtime。`images23dgs` 缺失只作为 `/api/doctor` warning。
- Material values are illustrative presets, not calibrated estimates from real objects.
- The included mesh is procedural. Arbitrary generated meshes can fail tetrahedralization and may need repair or unit correction.
- Cloth requires an appropriate surface mesh. Inflatable/soft-robot presets do not simulate pressure or actuators.
- No robot training, scene reconstruction, measured sim-to-real accuracy or universal model compatibility is claimed.
- The current exporter targets Genesis World 1.4.5. Newer releases may change APIs.
## Development
远端验收:
```bash
npm run test:run
npm run lint
npm run build
npx playwright install chromium
npm run test:e2e
npm audit
bash scripts/acceptance_wuying.sh
```
The browser test uses isolated data, exports a real GLB package, verifies current slider values, checks canvas pixels and rotation, and captures desktop/mobile screenshots. Physics execution is a separate Python check, not implied by passing the TypeScript tests.
## License and credits
MIT for this workbench and its procedural sample. See [third-party notices](THIRD_PARTY_NOTICES.md). Built with React, Three.js, Express and Genesis World; optional generation is provided by Tripo through DashScope. This project is independent of those upstream projects and providers.

View File

@ -1,17 +0,0 @@
# Security
Real2Sim Studio v0.1 is a single-user local workbench. The API binds to `127.0.0.1`, rejects non-local Host/Origin values, and does not enable permissive CORS. It is not a multi-user hosted service. Do not expose the API or Vite dev server through a public tunnel or reverse proxy.
Keep provider credentials in `.env.local` or the process environment. Never put them in a browser build, URL, issue, recording or commit. `npm run demo` disables provider access and separates demo tasks from normal user data.
Only run exported scripts and load model files from trusted sources. Material presets are not safety-certified or calibrated for real hardware.
## Known optional runtime risk (2026-10-28)
The separate Python simulation environment is **not vulnerability-clean**. `pip-audit` reported 72 advisory entries for Pillow 11.3.0 (some identifiers overlap). Genesis 1.4.5 depends on MoviePy >=2, whose current 2.2.1 release requires Pillow <12; the audited fixes extend through Pillow 13.0.0. Installing Pillow 13 alone makes that environment dependency-inconsistent. We do not hide or suppress those audit results.
This Alpha demonstrates only the bundled, trusted procedural mesh. Do not use this Python environment to process untrusted images, fonts or models, and do not expose it as an upload service. Use an isolated environment without credentials or private files. The recording validates the sample workflow, not immunity from dependency vulnerabilities. Track upstream MoviePy compatibility before using the optional runtime on external assets.
The Node dependency audit was clean at release preparation. These are point-in-time results, not a security guarantee.
Report vulnerabilities privately through [GitHub private vulnerability reporting](https://github.com/eust-w/real2sim-platform/security/advisories/new). Do not post credentials or sensitive reproductions in public issues.

View File

@ -1,11 +0,0 @@
# Third-party software and assets
The workbench and the procedural sample in `examples/soft-puck/` are distributed under the root MIT license. `scripts/generate-example.py` constructs that mesh from an icosphere; it contains no scanned, purchased, provider-generated, or company-internal asset.
- React, Express, Vite, Three.js, React Three Fiber, Drei and Zod retain their respective upstream licenses. See their installed package license files and the exact dependency versions in `package-lock.json`.
- Lucide icons use the ISC license.
- Genesis World is a separate Apache-2.0 project, installed by the user. Its transitive dependencies retain their own licenses. This repository does not redistribute Genesis, PyTorch or their model assets.
- Tripo through Alibaba Cloud DashScope is an optional external generation service. The root MIT license does not license that service, its models or generated outputs. Users supply their own credentials and must check their service terms and input/output rights.
- Video recordings supplied with a release show this project's procedural sample and workbench. They are not evidence of real-object material identification or physical calibration.
Upstream references: [Genesis World](https://github.com/Genesis-Embodied-AI/genesis-world), [Three.js](https://github.com/mrdoob/three.js), [Lucide](https://github.com/lucide-icons/lucide).

View File

@ -0,0 +1,346 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: real2sim-runtime-config
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
data:
config.toml: |
app_root = "/app"
workspace_dir = "/var/lib/real2sim-poc/workspace"
host = "0.0.0.0"
port = 18126
default_renderer = "spark"
real2sim2model_root = "/app"
expert_policy_root = "/app"
training_root = "/app"
inference_root = "/app"
discoverse_root = "/opt/DISCOVERSE"
gs_playground_root = "/opt/gs_playground"
images23dgs_root = "/opt/images23dgs"
colmap_binary = "/usr/bin/colmap"
gsplat_python = "/opt/real2sim_paper_runtime/envs/anysplat/bin/python"
runtime_root = "/opt/real2sim_paper_runtime"
anysplat_root = "/opt/real2sim_paper_runtime/AnySplat"
anysplat_python = "/opt/real2sim_paper_runtime/envs/anysplat/bin/python"
cuda_home = "/usr/local/cuda"
runtime_env_script = "/opt/gs_playground/scripts/real2sim_wuying_paper_env.sh"
motrixsim_docs_root = "/opt/motrixsim-docs"
allowed_path_roots = "/var/lib/real2sim-poc:/opt/DISCOVERSE:/opt/gs_playground:/opt/motrixsim-docs:/opt/real2sim_paper_runtime:/tmp"
production_mode = true
auth_enabled = true
secure_cookies = true
session_ttl_seconds = 43200
discoverse_commit = "d67f47c084aba0e0cf422a8725235f8b9238655a"
act_commit = "f8ab39c8d829d85571ab6d0250412ba4d0698fa0"
anysplat_commit = "5f5e208a7dd57d52e43ea0d553a95eab526e8775"
anysplat_model_revision = "d2e8c343672646041ad4ea518184968f94362f01"
vggt_model_revision = "860abec7937da0a4c03c41d3c269c366e82abdf9"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: real2sim-api
namespace: real2sim-poc
labels:
app.kubernetes.io/name: real2sim-api
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/version: "__BUILD_ID__"
spec:
replicas: 1
strategy: {type: Recreate}
selector:
matchLabels:
app.kubernetes.io/name: real2sim-api
template:
metadata:
labels:
app.kubernetes.io/name: real2sim-api
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/version: "__BUILD_ID__"
spec:
serviceAccountName: real2sim-poc
automountServiceAccountToken: false
nodeSelector:
kubernetes.io/hostname: "192.168.80.136"
securityContext:
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
fsGroup: 10001
seccompProfile: {type: RuntimeDefault}
imagePullSecrets:
- name: real2sim-registry
containers:
- name: api
image: __API_IMAGE__
imagePullPolicy: IfNotPresent
env:
- {name: REAL2SIM_PLATFORM_CONFIG, value: /etc/real2sim/config.toml}
- {name: REAL2SIM_WORKER_MODE, value: api}
- {name: REAL2SIM_WORKER_ID, value: real2sim-worker-a800}
- {name: REAL2SIM_PRODUCTION_MODE, value: "1"}
- {name: REAL2SIM_AUTH_ENABLED, value: "1"}
- {name: REAL2SIM_SECURE_COOKIES, value: "1"}
- {name: REAL2SIM_BOS_PREFIX, value: real2sim-poc}
- {name: BOS_BUCKET, value: testxyz}
- {name: BOS_ENDPOINT, value: https://bj.bcebos.com}
- name: BOS_ACCESS_KEY_ID
valueFrom: {secretKeyRef: {name: real2sim-bos, key: accessKeyId}}
- name: BOS_SECRET_ACCESS_KEY
valueFrom: {secretKeyRef: {name: real2sim-bos, key: secretAccessKey}}
- name: REAL2SIM_BOOTSTRAP_ADMIN_PASSWORD
valueFrom: {secretKeyRef: {name: real2sim-app-secrets, key: bootstrap-admin-password}}
ports:
- {name: http, containerPort: 18126}
resources:
requests: {cpu: 500m, memory: 1Gi}
limits: {cpu: "4", memory: 8Gi}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: {drop: [ALL]}
readinessProbe:
httpGet: {path: /api/health, port: http}
initialDelaySeconds: 3
periodSeconds: 5
livenessProbe:
httpGet: {path: /api/health, port: http}
initialDelaySeconds: 20
periodSeconds: 20
volumeMounts:
- {name: data, mountPath: /var/lib/real2sim-poc}
- {name: config, mountPath: /etc/real2sim/config.toml, subPath: config.toml, readOnly: true}
- {name: tmp, mountPath: /tmp}
volumes:
- name: data
persistentVolumeClaim: {claimName: real2sim-poc-data}
- name: config
configMap: {name: real2sim-runtime-config}
- name: tmp
emptyDir: {sizeLimit: 2Gi}
---
apiVersion: v1
kind: Service
metadata:
name: real2sim-api
namespace: real2sim-poc
labels:
app.kubernetes.io/name: real2sim-api
app.kubernetes.io/part-of: real2sim-poc
spec:
selector:
app.kubernetes.io/name: real2sim-api
ports:
- {name: http, port: 18126, targetPort: http}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: real2sim-worker
namespace: real2sim-poc
labels:
app.kubernetes.io/name: real2sim-worker
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/version: "__BUILD_ID__"
spec:
replicas: 1
strategy: {type: Recreate}
progressDeadlineSeconds: 3600
selector:
matchLabels:
app.kubernetes.io/name: real2sim-worker
template:
metadata:
labels:
app.kubernetes.io/name: real2sim-worker
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/version: "__BUILD_ID__"
spec:
serviceAccountName: real2sim-poc
automountServiceAccountToken: false
nodeSelector:
kubernetes.io/hostname: "192.168.80.136"
securityContext:
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
fsGroup: 10001
seccompProfile: {type: RuntimeDefault}
imagePullSecrets:
- name: real2sim-registry
initContainers:
- name: runtime-gate
image: __WORKER_IMAGE__
imagePullPolicy: IfNotPresent
command: [/bin/bash, -lc]
args: ["install -d -m 700 /tmp/xdg-runtime && exec real2sim-runtime-gate --mode bootstrap"]
env: &worker-env
- {name: REAL2SIM_PLATFORM_CONFIG, value: /etc/real2sim/config.toml}
- {name: REAL2SIM_WORKER_MODE, value: worker}
- {name: REAL2SIM_WORKER_ID, value: real2sim-worker-a800}
- {name: REAL2SIM_PRODUCTION_MODE, value: "1"}
- {name: REAL2SIM_BOS_PREFIX, value: real2sim-poc}
- {name: REAL2SIM_RUNTIME_GATE_DIR, value: /var/lib/real2sim-poc/cache/runtime-gate}
- {name: REAL2SIM_MOTRIXSIM_PYTHON, value: /opt/conda/bin/python}
- {name: REAL2SIM_FFMPEG_BIN, value: /usr/bin/ffmpeg}
- {name: MUJOCO_GL, value: egl}
- {name: PYOPENGL_PLATFORM, value: egl}
- {name: NVIDIA_DRIVER_CAPABILITIES, value: all}
- {name: WGPU_BACKEND, value: vulkan}
- {name: XDG_RUNTIME_DIR, value: /tmp/xdg-runtime}
- {name: HF_HOME, value: /var/lib/real2sim-poc/cache/huggingface}
- {name: HF_HUB_DISABLE_XET, value: "1"}
- {name: HOME, value: /var/lib/real2sim-poc/cache/home}
- {name: MPLCONFIGDIR, value: /var/lib/real2sim-poc/cache/matplotlib}
- {name: XDG_CACHE_HOME, value: /var/lib/real2sim-poc/cache/xdg}
- {name: GIT_CONFIG_COUNT, value: "4"}
- {name: GIT_CONFIG_KEY_0, value: safe.directory}
- {name: GIT_CONFIG_VALUE_0, value: /opt/real2sim_paper_runtime/AnySplat}
- {name: GIT_CONFIG_KEY_1, value: safe.directory}
- {name: GIT_CONFIG_VALUE_1, value: /opt/DISCOVERSE}
- {name: GIT_CONFIG_KEY_2, value: safe.directory}
- {name: GIT_CONFIG_VALUE_2, value: /opt/DISCOVERSE/policies/act}
- {name: GIT_CONFIG_KEY_3, value: safe.directory}
- {name: GIT_CONFIG_VALUE_3, value: /opt/motrixsim-docs}
- {name: BOS_BUCKET, value: testxyz}
- {name: BOS_ENDPOINT, value: https://bj.bcebos.com}
- name: BOS_ACCESS_KEY_ID
valueFrom: {secretKeyRef: {name: real2sim-bos, key: accessKeyId}}
- name: BOS_SECRET_ACCESS_KEY
valueFrom: {secretKeyRef: {name: real2sim-bos, key: secretAccessKey}}
resources:
requests: {cpu: "6", memory: 32Gi, nvidia.com/gpu: "1"}
limits: {cpu: "24", memory: 96Gi, nvidia.com/gpu: "1"}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: {drop: [ALL]}
volumeMounts: &worker-mounts
- {name: data, mountPath: /var/lib/real2sim-poc}
- {name: config, mountPath: /etc/real2sim/config.toml, subPath: config.toml, readOnly: true}
- {name: tmp, mountPath: /tmp}
- {name: shm, mountPath: /dev/shm}
containers:
- name: worker
image: __WORKER_IMAGE__
imagePullPolicy: IfNotPresent
env: *worker-env
resources:
requests: {cpu: "6", memory: 32Gi, nvidia.com/gpu: "1"}
limits: {cpu: "24", memory: 96Gi, nvidia.com/gpu: "1"}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: {drop: [ALL]}
readinessProbe:
exec: {command: [real2sim-runtime-gate, --mode, readiness]}
initialDelaySeconds: 5
periodSeconds: 15
timeoutSeconds: 10
failureThreshold: 4
livenessProbe:
exec: {command: [real2sim-runtime-gate, --mode, readiness]}
initialDelaySeconds: 45
periodSeconds: 60
timeoutSeconds: 15
failureThreshold: 3
volumeMounts: *worker-mounts
volumes:
- name: data
persistentVolumeClaim: {claimName: real2sim-poc-data}
- name: config
configMap: {name: real2sim-runtime-config}
- name: tmp
emptyDir: {sizeLimit: 12Gi}
- name: shm
emptyDir: {medium: Memory, sizeLimit: 12Gi}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: real2sim-frontend
namespace: real2sim-poc
labels:
app.kubernetes.io/name: real2sim-frontend
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/version: "__BUILD_ID__"
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: real2sim-frontend
template:
metadata:
labels:
app.kubernetes.io/name: real2sim-frontend
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/version: "__BUILD_ID__"
spec:
serviceAccountName: real2sim-poc
automountServiceAccountToken: false
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values: ["192.168.80.249", "192.168.81.47"]
securityContext:
runAsNonRoot: true
runAsUser: 101
runAsGroup: 101
seccompProfile: {type: RuntimeDefault}
imagePullSecrets:
- name: real2sim-registry
containers:
- name: frontend
image: __FRONTEND_IMAGE__
imagePullPolicy: IfNotPresent
ports:
- {name: http, containerPort: 8080}
- {name: https, containerPort: 8443}
resources:
requests: {cpu: 100m, memory: 128Mi}
limits: {cpu: "1", memory: 512Mi}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: {drop: [ALL]}
readinessProbe:
tcpSocket: {port: https}
initialDelaySeconds: 3
periodSeconds: 5
livenessProbe:
tcpSocket: {port: https}
initialDelaySeconds: 15
periodSeconds: 20
volumeMounts:
- {name: tls, mountPath: /etc/real2sim/tls, readOnly: true}
- {name: tmp, mountPath: /tmp}
- {name: nginx-cache, mountPath: /var/cache/nginx}
volumes:
- name: tls
secret: {secretName: real2sim-tls}
- name: tmp
emptyDir: {sizeLimit: 64Mi}
- name: nginx-cache
emptyDir: {sizeLimit: 128Mi}
---
apiVersion: v1
kind: Service
metadata:
name: real2sim-frontend
namespace: real2sim-poc
labels:
app.kubernetes.io/name: real2sim-frontend
app.kubernetes.io/part-of: real2sim-poc
spec:
type: LoadBalancer
selector:
app.kubernetes.io/name: real2sim-frontend
ports:
- {name: http, port: 80, targetPort: http}
- {name: https, port: 443, targetPort: https}

184
deploy/poc/bootstrap.yaml Normal file
View File

@ -0,0 +1,184 @@
apiVersion: v1
kind: Namespace
metadata:
name: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: real2sim-poc-local-pv
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
capacity:
storage: 150Gi
volumeMode: Filesystem
accessModes: [ReadWriteOnce]
persistentVolumeReclaimPolicy: Retain
storageClassName: real2sim-poc-local
local:
path: /var/lib/real2sim-poc
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values: ["192.168.80.136"]
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: real2sim-poc-data
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
accessModes: [ReadWriteOnce]
storageClassName: real2sim-poc-local
volumeName: real2sim-poc-local-pv
resources:
requests:
storage: 150Gi
---
apiVersion: v1
kind: ResourceQuota
metadata:
name: real2sim-poc-quota
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
hard:
pods: "12"
services: "6"
services.loadbalancers: "1"
requests.cpu: "40"
limits.cpu: "64"
requests.memory: 128Gi
limits.memory: 192Gi
requests.storage: 150Gi
requests.nvidia.com/gpu: "1"
limits.nvidia.com/gpu: "1"
---
apiVersion: v1
kind: LimitRange
metadata:
name: real2sim-poc-limits
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
limits:
- type: Container
defaultRequest:
cpu: 100m
memory: 128Mi
default:
cpu: "2"
memory: 4Gi
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: real2sim-poc
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
automountServiceAccountToken: false
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-dns
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
podSelector: {}
policyTypes: [Egress]
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- {protocol: UDP, port: 53}
- {protocol: TCP, port: 53}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: frontend-policy
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: real2sim-frontend
policyTypes: [Ingress, Egress]
ingress:
- ports:
- {protocol: TCP, port: 8080}
- {protocol: TCP, port: 8443}
egress:
- to:
- podSelector:
matchLabels:
app.kubernetes.io/name: real2sim-api
ports:
- {protocol: TCP, port: 18126}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: api-policy
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: real2sim-api
policyTypes: [Ingress, Egress]
ingress:
- from:
- podSelector:
matchLabels:
app.kubernetes.io/name: real2sim-frontend
ports:
- {protocol: TCP, port: 18126}
egress:
- ports:
- {protocol: TCP, port: 443}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: worker-policy
namespace: real2sim-poc
labels:
app.kubernetes.io/part-of: real2sim-poc
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: real2sim-worker
policyTypes: [Ingress, Egress]
egress:
- ports:
- {protocol: TCP, port: 443}
- {protocol: TCP, port: 80}

92
deploy/poc/nginx.conf Normal file
View File

@ -0,0 +1,92 @@
worker_processes auto;
pid /tmp/nginx.pid;
events { worker_connections 1024; }
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /dev/stdout;
error_log /dev/stderr warn;
sendfile on;
server_tokens off;
client_max_body_size 70m;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream real2sim_api { server real2sim-api.real2sim-poc.svc.cluster.local:18126; }
server {
listen 8080;
return 308 https://$host$request_uri;
}
server {
listen 8443 ssl;
ssl_certificate /etc/real2sim/tls/tls.crt;
ssl_certificate_key /etc/real2sim/tls/tls.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache shared:TLS:10m;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy same-origin always;
add_header X-Frame-Options SAMEORIGIN always;
root /usr/share/nginx/html;
index index.html;
location = /api/events/tasks {
proxy_pass http://real2sim_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 1h;
}
location /api/ {
proxy_pass http://real2sim_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_request_buffering off;
proxy_read_timeout 7200s;
}
location /datasets/ {
proxy_pass http://real2sim_api;
proxy_set_header Host $host;
}
location /runs/ {
proxy_pass http://real2sim_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_read_timeout 7200s;
}
location ~ ^/static/.*\.(html|js|css)$ {
try_files $uri =404;
expires -1;
add_header Cache-Control "no-store";
}
location /static/ {
try_files $uri =404;
expires 1h;
add_header Cache-Control "public, max-age=3600";
}
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-store";
}
}
}

View File

@ -0,0 +1,45 @@
numpy==1.25.0
wheel
tqdm
lightning
hydra-core
jaxtyping
beartype
einops
colorama
scikit-image
colorspacious
matplotlib
moviepy==1.0.3
imageio
timm
dacite
lpips
e3nn
plyfile
tabulate
svg.py
scikit-video
opencv-python-headless==4.8.1.78
Pillow
huggingface_hub
pydantic
open3d
safetensors
omegaconf
pyquaternion
pyyaml
packaging
h5py
dm_env
OneEuroFilter
pymeshlab
scipy
psutil
screeninfo
mediapy
termcolor
imagecodecs
av
wandb
trimesh

18
docker/api.Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM python:3.12-slim-bookworm
ARG BUILD_ID=dev
ARG SOURCE_COMMIT=unknown
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
REAL2SIM_PLATFORM_BUILD_ID=${BUILD_ID} \
REAL2SIM_SOURCE_COMMIT=${SOURCE_COMMIT}
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl ffmpeg libglib2.0-0 && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY pyproject.toml README.md ./
COPY src ./src
RUN python -m pip install --no-cache-dir --upgrade pip && python -m pip install --no-cache-dir .
RUN useradd --uid 10001 --create-home --shell /usr/sbin/nologin real2sim
USER 10001:10001
EXPOSE 18126
CMD ["real2sim-platform", "--host", "0.0.0.0", "--port", "18126"]

View File

@ -0,0 +1,10 @@
FROM nginxinc/nginx-unprivileged:1.27-alpine
ARG BUILD_ID=dev
LABEL org.opencontainers.image.title="Real2Sim POC frontend" \
org.opencontainers.image.version="${BUILD_ID}"
COPY deploy/poc/nginx.conf /etc/nginx/nginx.conf
COPY src/real2sim_platform/static/index.html /usr/share/nginx/html/index.html
COPY src/real2sim_platform/static /usr/share/nginx/html/static
USER 101:101
EXPOSE 8080 8443

View File

@ -0,0 +1,2 @@
numpy==1.25.0
opencv-python-headless==4.8.1.78

125
docker/worker.Dockerfile Normal file
View File

@ -0,0 +1,125 @@
FROM node:20.19.2-bookworm-slim@sha256:7cd3fbc830c75c92256fe1122002add9a1c025831af8770cd0bf8e45688ef661 AS node-runtime
FROM pytorch/pytorch:2.2.0-cuda12.1-cudnn8-runtime
ARG ANYSPLAT_COMMIT=5f5e208a7dd57d52e43ea0d553a95eab526e8775
ARG DISCOVERSE_COMMIT=d67f47c084aba0e0cf422a8725235f8b9238655a
ARG ACT_COMMIT=f8ab39c8d829d85571ab6d0250412ba4d0698fa0
ARG DISCOVERSE_ARCHIVE_SHA256=c8fbd6ca571ce3d44a61c6d3903de956075ee28d29afdfbcfe2b3fcc4cdab350
ARG ACT_ARCHIVE_SHA256=35c5dfc416ba0a5d7f10ad61252fa9f685ac4cf2b123cd6f1b3db1619a2b1b37
ARG TORCH_SCATTER_SHA256=caab7dd4a8783d49b2a983331e93ebf968c9c76ff4daaca158e2f6fb9c8028bf
ARG MOTRIXSIM_DOCS_COMMIT=2beecea67c81d25e29cefa30a80c0ddad7b44dde
ARG VGGT_MODEL_REVISION=860abec7937da0a4c03c41d3c269c366e82abdf9
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
REAL2SIM_VGGT_MODEL_REVISION=${VGGT_MODEL_REVISION} \
REAL2SIM_ANYSPLAT_ROOT=/opt/real2sim_paper_runtime/AnySplat \
REAL2SIM_ANY_SPLAT_PYTHON=/opt/real2sim_paper_runtime/envs/anysplat/bin/python \
REAL2SIM_POSE_INIT_TRAIN_PYTHON=/opt/real2sim_paper_runtime/envs/anysplat/bin/python \
CUDA_HOME=/usr/local/cuda \
PYTHONPATH=/opt/real2sim_paper_runtime/AnySplat:/opt/DISCOVERSE/policies/act:/opt/DISCOVERSE:/opt/gs_playground
RUN sed -i 's|http://archive.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g; s|http://security.ubuntu.com/ubuntu|http://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list && \
apt-get -o Acquire::Retries=5 update && apt-get -o Acquire::Retries=5 install -y --no-install-recommends \
ca-certificates curl ffmpeg git git-lfs build-essential cmake ninja-build pkg-config colmap \
libgl1 libglib2.0-0 libgomp1 libx11-6 libxext6 libsm6 && \
git lfs install --system && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY pyproject.toml README.md ./
COPY docker/anysplat-runtime-requirements.txt /tmp/anysplat-runtime-requirements.txt
COPY docker/worker-constraints.txt /tmp/worker-constraints.txt
COPY scripts/prepare_discoverse_act_runtime.py /tmp/prepare_discoverse_act_runtime.py
COPY src/real2sim_platform/__init__.py /tmp/real2sim_platform/__init__.py
COPY src/real2sim_platform/source_revision.py /tmp/real2sim_platform/source_revision.py
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel && \
python -m pip install --no-cache-dir tomli==2.2.1 && \
python -c 'import tomli; config=tomli.load(open("pyproject.toml", "rb")); open("/tmp/platform-requirements.txt", "w").write("\n".join(config["project"]["dependencies"]) + "\n")' && \
python -m pip install --no-cache-dir -c /tmp/worker-constraints.txt -r /tmp/platform-requirements.txt && \
python -m pip install --no-cache-dir torchvision==0.17.0 torchaudio==2.2.0 --index-url https://download.pytorch.org/whl/cu121 && \
python -m pip install --no-cache-dir -c /tmp/worker-constraints.txt -r /tmp/anysplat-runtime-requirements.txt && \
python -m pip install --no-cache-dir xformers==0.0.24 --no-deps && \
python -m pip install --no-cache-dir 'https://github.com/nerfstudio-project/gsplat/releases/download/v1.4.0/gsplat-1.4.0%2Bpt22cu121-cp310-cp310-linux_x86_64.whl' && \
python -m pip install --no-cache-dir -c /tmp/worker-constraints.txt motrixsim-core==0.8.0
RUN curl -fL --retry 8 --retry-all-errors --retry-delay 2 --connect-timeout 20 --max-time 300 --speed-limit 1024 --speed-time 30 \
-o '/tmp/torch_scatter-2.1.2+pt22cu121-cp310-cp310-linux_x86_64.whl' 'https://data.pyg.org/whl/torch-2.2.0%2Bcu121/torch_scatter-2.1.2%2Bpt22cu121-cp310-cp310-linux_x86_64.whl' && \
echo "${TORCH_SCATTER_SHA256} /tmp/torch_scatter-2.1.2+pt22cu121-cp310-cp310-linux_x86_64.whl" | sha256sum -c - && \
python -m pip install --no-cache-dir --no-deps '/tmp/torch_scatter-2.1.2+pt22cu121-cp310-cp310-linux_x86_64.whl' && \
rm -f '/tmp/torch_scatter-2.1.2+pt22cu121-cp310-cp310-linux_x86_64.whl'
RUN git clone --filter=blob:none --no-checkout https://github.com/InternRobotics/AnySplat.git /opt/real2sim_paper_runtime/AnySplat && \
git -C /opt/real2sim_paper_runtime/AnySplat checkout "${ANYSPLAT_COMMIT}" && \
test "$(git -C /opt/real2sim_paper_runtime/AnySplat rev-parse HEAD)" = "${ANYSPLAT_COMMIT}" && \
sed -i 's/VGGT.from_pretrained("facebook\/VGGT-1B")/VGGT.from_pretrained("facebook\/VGGT-1B", revision=os.environ.get("REAL2SIM_VGGT_MODEL_REVISION"))/g' /opt/real2sim_paper_runtime/AnySplat/src/model/encoder/anysplat.py
RUN mkdir -p /opt/DISCOVERSE /opt/DISCOVERSE/policies/act && \
curl -fL --retry 5 --retry-all-errors --connect-timeout 20 --max-time 900 \
-o /tmp/discoverse.tar.gz "https://codeload.github.com/eust-w/DISCOVERSE/tar.gz/${DISCOVERSE_COMMIT}" && \
echo "${DISCOVERSE_ARCHIVE_SHA256} /tmp/discoverse.tar.gz" | sha256sum -c - && \
tar -xzf /tmp/discoverse.tar.gz --strip-components=1 -C /opt/DISCOVERSE && \
rm -rf /opt/DISCOVERSE/policies/act && mkdir -p /opt/DISCOVERSE/policies/act && \
curl -fL --retry 5 --retry-all-errors --connect-timeout 20 --max-time 300 \
-o /tmp/act.tar.gz "https://codeload.github.com/OpenGHz/Imitate-All/tar.gz/${ACT_COMMIT}" && \
echo "${ACT_ARCHIVE_SHA256} /tmp/act.tar.gz" | sha256sum -c - && \
tar -xzf /tmp/act.tar.gz --strip-components=1 -C /opt/DISCOVERSE/policies/act && \
printf '{"schema":"real2sim.source.v1","source":"https://codeload.github.com/eust-w/DISCOVERSE/tar.gz/%s","commit":"%s","archive_sha256":"%s"}\n' \
"${DISCOVERSE_COMMIT}" "${DISCOVERSE_COMMIT}" "${DISCOVERSE_ARCHIVE_SHA256}" > /opt/DISCOVERSE/.real2sim-source.json && \
printf '{"schema":"real2sim.source.v1","source":"https://codeload.github.com/OpenGHz/Imitate-All/tar.gz/%s","commit":"%s","archive_sha256":"%s"}\n' \
"${ACT_COMMIT}" "${ACT_COMMIT}" "${ACT_ARCHIVE_SHA256}" > /opt/DISCOVERSE/policies/act/.real2sim-source.json && \
rm -f /tmp/discoverse.tar.gz /tmp/act.tar.gz && \
grep -Ev '^[[:space:]]*(torchvision|torch|opencv-python)([[:space:]]|$)' /opt/DISCOVERSE/policies/act/requirements/train_eval.txt > /tmp/discoverse-act-train-requirements.txt && \
python -m pip install --no-cache-dir -c /tmp/worker-constraints.txt -r /tmp/discoverse-act-train-requirements.txt && \
PYTHONPATH=/tmp python /tmp/prepare_discoverse_act_runtime.py --act-root /opt/DISCOVERSE/policies/act --expected-commit "${ACT_COMMIT}" && \
python -m pip install --no-cache-dir --no-deps -e /opt/DISCOVERSE
RUN git clone --filter=blob:none --no-checkout https://github.com/Motphys/motrixsim-docs.git /opt/motrixsim-docs && \
git -C /opt/motrixsim-docs checkout "${MOTRIXSIM_DOCS_COMMIT}" && \
git -C /opt/motrixsim-docs lfs pull --include='examples/assets/**' && \
test "$(git -C /opt/motrixsim-docs rev-parse HEAD)" = "${MOTRIXSIM_DOCS_COMMIT}" && \
test "$(stat -c%s /opt/motrixsim-docs/examples/assets/rm65_open_cabinet/assets/rm65/meshes/base_link.STL)" -gt 10000 && \
! grep -q 'git-lfs.github.com/spec' /opt/motrixsim-docs/examples/assets/rm65_open_cabinet/assets/rm65/meshes/base_link.STL && \
git config --system --add safe.directory /opt/motrixsim-docs && \
mkdir -p /opt/real2sim_paper_runtime/envs/anysplat/bin && \
ln -s /opt/conda/bin/python /opt/real2sim_paper_runtime/envs/anysplat/bin/python && \
ln -s /opt/conda/bin/pip /opt/real2sim_paper_runtime/envs/anysplat/bin/pip
# Keep the stable CUDA/ML dependency layers reusable when only the MotrixSim
# graphics runtime changes.
RUN apt-get -o Acquire::Retries=5 update && \
apt-get -o Acquire::Retries=5 install -y --no-install-recommends libvulkan1 && \
rm -rf /var/lib/apt/lists/*
COPY --from=node-runtime /usr/local/bin/node /usr/local/bin/node
RUN test "$(node --version)" = "v20.19.2"
COPY src ./src
COPY scripts ./scripts
COPY vendor/gs_playground /opt/gs_playground
RUN python -m pip install --no-cache-dir --no-deps .
RUN python -c 'import mujoco, motrixsim, torch, trimesh; from pxr import Usd, UsdGeom; from huggingface_hub import snapshot_download; assert torch.__version__.startswith("2.2"); assert Usd is not None and UsdGeom is not None and trimesh is not None' && \
test "$(node --version)" = "v20.19.2" && \
PYTHONPATH=/opt/DISCOVERSE/policies/act:/opt/DISCOVERSE python -c 'from policies.act.act import ACTPolicy; assert ACTPolicy is not None' && \
PYTHONPATH=/opt/real2sim_paper_runtime/AnySplat python -c 'from src.model.model.anysplat import AnySplat; assert AnySplat is not None' && \
test -f /opt/gs_playground/scripts/real2sim_video_motrix_scene.py
ARG BUILD_ID=dev
ARG SOURCE_COMMIT=unknown
ENV REAL2SIM_PLATFORM_BUILD_ID=${BUILD_ID} \
REAL2SIM_SOURCE_COMMIT=${SOURCE_COMMIT} \
REAL2SIM_MOTRIXSIM_DOCS_COMMIT=${MOTRIXSIM_DOCS_COMMIT} \
REAL2SIM_MOTRIXSIM_PYTHON=/opt/conda/bin/python \
REAL2SIM_FFMPEG_BIN=/usr/bin/ffmpeg \
MUJOCO_GL=egl \
PYOPENGL_PLATFORM=egl \
NVIDIA_DRIVER_CAPABILITIES=all
RUN useradd --uid 10001 --create-home --shell /usr/sbin/nologin real2sim && \
chown -R 10001:10001 /app
USER 10001:10001
CMD ["real2sim-worker"]

View File

@ -0,0 +1,46 @@
# Real2Sim Platform 实现细案
## 目标闭环
1. 场景:上传或导入视频、图片、RGBD 数据,创建 `scene_reconstruction` 任务,产出 3DGS/点云/mesh/collider、`scene.json`、MuJoCo/MotrixSim 可用文件和预览。
2. 数据:创建 `hf_import` 任务,从 Hugging Face dataset 下载小批量验收数据,生成 `dataset_manifest.json`。
3. 准备:创建 `media_prepare` 任务,把 HF parquet/video URL、本地 video、图片目录统一抽帧成 `prepared_media` 数据集,输出 `prepared_manifest.json` 和每个视频的帧贡献。
4. 预检:创建 `reconstruction_preflight` 任务,检查帧数、分辨率、帧间变化和 AnySplat/COLMAP/ffmpeg runtime,输出 `capture_preflight_report.json`。
5. 校验:创建 `simulator_validation` 任务,按 `smoke` / `runtime_if_available` / `runtime_required` 生成 MuJoCo/MotrixSim `validation_report.json`。
6. 采集:选择场景、机器人配置、任务配置和 episode/step 参数,创建 `expert_collection` 任务,产出专家数据集。
7. 训练:选择采集数据集,创建 `training` 任务,产出 `policy_head.json`、`model_card.json`。
8. 推理:选择场景和模型,创建 `inference` 任务,产出 `prediction_rollout.json` 和 `viewer.html`。
## 渲染器选择
- 默认:Spark。理由是它直接集成 Three.js,适合把 3DGS、Mesh、MuJoCo/MotrixSim proxy、轨迹和 UI overlay 放进同一个前端视图。平台随包部署 `@sparkjsdev/spark` 静态 ESM bundle。
- 回退:Three.js fallback。用于 Spark bundle 不存在、Spark runtime 加载失败或只是普通点云预览时,界面会明确显示 `Three.js fallback`,不再冒充 Spark;Three.js ESM、controls 和 loaders 随静态文件部署。
- 大资产策略:scene manifest 会在读取时补齐 `size_bytes`、`autoload` 和 `viewer_hint`。超过默认阈值的大 PLY/点云只显示手动加载入口,避免页面长时间停在 loading。
- 备选:Aholo Viewer。理由是它强调高性能 3DGS 和 chunked streaming LOD,更适合大场景或移动端流式加载,但需要把资产转成 Aholo 最适合的 packed/LOD 格式。
- 平台 API 保留 `renderer` 参数:`spark | aholo | auto`。首版 `auto` 在没有 Aholo LOD package 时等价于 `spark`,当 scene package 内存在 Aholo LOD 资产时切到 `aholo`。
## 仿真器支持
- `mujoco`:保留 `scene_mujoco.xml`、V-HACD/convex collision、MJCF smoke/validation artifact。
- `motrixsim`:保留 `motrix_scene.json`、`motrix_import.json`、预览 mesh/pointcloud/3DGS manifest。
- UI 中每个场景记录 `simulators: ["mujoco", "motrixsim"]`,任务不声称两者物理完全一致,分别展示各自产物和验证结果。
## API
- `POST /api/datasets/import-path`:导入服务器已有路径。
- `POST /api/datasets/upload`:上传 zip/video/RGBD。
- `POST /api/scenes/import`:导入已有 `scene.json`、`motrix_import.json` 或 `project_manifest.json`。
- `POST /api/tasks`:统一创建任务,`type` 为 `hf_import`、`media_prepare`、`reconstruction_preflight`、`scene_reconstruction`、`simulator_validation`、`expert_collection`、`training`、`inference`、`renderer_benchmark`。
- `GET /api/tasks/{id}/logs`、`GET /api/tasks/{id}/artifacts`、`GET /api/artifacts/{id}/content`:统一验收与下载。
- `GET /api/tasks/{id}/reports`:读取结构化报告索引和可读失败原因。
- `reconstruction_preflight` report 包含 `readiness_score` 和 `next_action`,任务详情页会直接展示失败门槛、关键指标和重采建议。
- `GET /api/datasets/{id}/manifest`、`GET /api/scenes/{id}/manifest`、`GET /api/models/{id}/card`:数据、场景、模型治理信息。
- `GET /api/version`:返回平台版本、构建时间、部署路径、功能开关和当前 renderer backend。
## 无影策略
- 无影作为重建、训练和部署主环境:`39.106.101.95`,root 登录,GPU、COLMAP、Real2Sim 和 gsplat Python 已验证。
- 服务默认绑定 `127.0.0.1:18126`,通过 SSH 隧道访问,避免公网暴露上传和模型产物。
- 缺失 Node 不影响后端运行;Spark bundle 在本地通过 `scripts/vendor_spark.sh` 生成,Three.js bundle 通过 `scripts/vendor_three.sh` 生成,二者都随静态文件部署。
- 无影 `.venv` 显式安装 `huggingface_hub`、`pyarrow`、`pillow`、`imageio`、`opencv-python-headless`、`mujoco`,`/api/doctor` 检查 `ffmpeg`、Spark bundle、Three.js bundle、媒体依赖、MuJoCo Python、AnySplat root/python、CUDA 和核心路径。
- `deploy_wuying.sh --restart` 写入 systemd unit 并重启服务;`acceptance_wuying.sh` 通过远端 API 跑 preflight、非 dry-run 重建和仿真校验。

45
docs/POC_PRODUCT_SPEC.md Normal file
View File

@ -0,0 +1,45 @@
# Real2Sim POC 产品与交互规格
## 用户与边界
| 角色 | 主要目标 | 写权限 |
| --- | --- | --- |
| 管理员 | 初始化平台、管理用户、存储和删除策略 | 全部;删除磁盘或 BOS 对象必须二次确认 |
| 算法工程师 | 导入数据、重建、采集、训练和推理 | 业务资源和任务,不可管理用户 |
| 只读用户 | 查看场景、报告、模型和 rollout | 无 |
平台面向内部 POC/Beta,不开放注册、计费或多组织租户。真实 MuJoCo 和 MotrixSim 是允许的领域运行时;禁止 mock、dry-run 验收、硬编码成功率、假进度和通过直接改物体位姿伪造抓取。
## 完整用户旅程
1. 管理员使用一次性初始密码登录,强制更新密码,再创建工程师或只读账号。
2. 工程师从 HuggingFace、浏览器分片上传或授权 BOS 前缀导入数据。系统计算 SHA-256、创建版本和清单。
3. 视频或图片包进入“准备输入”,统一生成 prepared frames;质量预检给出帧数、分辨率、清晰度、视差和可执行建议。
4. 场景重建向导选择 prepared dataset、质量档位、坐标系、渲染器和仿真器。任务立即进入本页,SSE 显示真实阶段和进度。
5. 重建成功后在场景管理中打开 Spark/Three Viewer,添加机器人或物体会生成新 revision,不覆盖来源场景。
6. 数据采集页只展示场景 manifest 声明兼容的真实控制器。RM65 采集要求双指接触、至少抬升 10 cm、放置误差不超过 5 cm。
7. 模型训练页只允许新建 DISCOVERSE ACT;配置由 HDF5 和场景 manifest 推导,输出 checkpoint、损失历史、模型卡和血缘。
8. 在线推理在真实引擎运行随机化 episode,输出视频、轨迹、动作统计和成功率。没有真实结果时显示空状态。
## 七页交互合同
- **总览**:当前闭环阶段、推荐下一步、真实任务、最近场景和模型结果。无运维状态条或调试 JSON。
- **数据管理**:来源卡打开导入弹窗;表格支持全选、多选、批量准备、预检和删除索引。
- **场景重建**:资源卡选择、质量评分、参数折叠、任务列表和完成后预览构成单页闭环。
- **场景管理**:场景库、3D Viewer、资产和仿真信息三栏;移动端按 Viewer、场景库、资产编辑顺序堆叠。
- **数据采集**:场景、控制器和采集规模在同页;任务完成后直接出现 HDF5 数据集。
- **模型训练**:采集数据、ACT 配方、真实指标、训练任务和模型卡同页呈现。
- **在线推理**:模型和场景卡选择、rollout 播放、轨迹产物与任务管理同页呈现。
任务详情使用右侧抽屉展示阶段、报告、建议、产物预览和下载;高级 JSON 仅在折叠区。删除默认只删平台索引,不删 PV 或 BOS 对象。
## 可行性证据与交付门槛
- 本地已用真实 MuJoCo 和 MotrixSim 加载同一 RM65 MJCF 并执行 step。
- 本地真实物理控制器已完成双指接触抓放:抬升 15.57 cm,放置误差 1.29 cm,输出 RGB/qpos/action/contact HDF5 与 MP4。
- 集群 worker 必须在 A800 上通过 CUDA 矩阵运算、AnySplat 固定 revision 模型加载、ACT import、MuJoCo step 和 MotrixSim step,之后才 Ready。
- 最终 `acceptance_report.json.pass=true` 还要求两次非 dry-run 重建、50 个成功采集 episode、真实 ACT checkpoint,以及 10 次推理成功率至少 50%。未达门槛时可保留 Beta 部署,但不得声明全链路通过。
## 视觉合同
视觉原型保存于 `docs/prototypes/real2sim-poc-product-board-v1.png`。实现采用深色中性底、青绿色命令色、紧凑表格、6px 面板圆角和纯文字导航;禁止大编号、运行时状态条、装饰图标、裸资源 ID/路径主输入及无数据时的虚构图表。

View File

@ -1,72 +0,0 @@
# Real2Sim Studio
一个本地优先的 3D 资产与 Genesis 仿真导出工作台。
[English](../README.md) | [示例复现](../examples/README.md) | [路线图](ROADMAP.md)
![工作台](images/workbench.png)
[下载 Alpha 发布包](https://github.com/eust-w/real2sim-platform/releases/tag/v0.1.0-alpha.1) | [90 秒介绍视频](https://github.com/eust-w/real2sim-platform/releases/download/v0.1.0-alpha.1/real2sim-intro-zh.mp4) | [45 秒竖版](https://github.com/eust-w/real2sim-platform/releases/download/v0.1.0-alpha.1/real2sim-short-zh.mp4) | [Gitea 镜像](https://gitea.d-robotics.cc/longtao.wu/real2sim-platform)
[抖音观看](https://www.douyin.com/video/7701399089530916159) | [X 观看](https://x.com/eustancewu/status/2115131684236800501) | [各平台实际状态](releases/publication-status.md)
预览 GLB、配置材料预设,并导出包含网格、参数和 Python 脚本的 Genesis 场景包。内置自制样例不需要 API Key;可选接入自己的 DashScope 账号,通过 Tripo 生成 3D 资产。
## 无需密钥体验
需要 Node.js 22.12 或更新版本。
```bash
git clone https://github.com/eust-w/real2sim-platform.git
cd real2sim-platform
npm ci
npm run demo
```
打开终端打印的本地网址,点击“加载示例”,调整材料参数,再导出 Genesis 包。演示模式不读取 `.env.local` 中的服务密钥,禁止付费生成调用,并使用独立的 `.data/demo/` 数据目录。
## 运行真实仿真
```bash
npm run example:export
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r examples/requirements.txt
python .data/genesis-packages/example-soft-puck/genesis_scene.py --steps 800 --record
```
首次启动需要编译求解器。无 `--record` 时不请求相机,输出数值指标与轨迹;添加 `--record` 输出实际 Genesis 求解画面。详细环境与注意事项见[示例文档](../examples/README.md)。
**Alpha 安全限制:**可选 Python 依赖链中的 Pillow 存在已知漏洞,上游 MoviePy 的版本约束尚未兼容修复版本。仅在隔离环境中运行可信样例,不要处理外来模型或图片,详见[审计说明](../SECURITY.md)。Node 审计通过不代表 Python 环境无漏洞。
## 已有功能
- 文本、单图、多图生成接口,可选使用用户自己的 DashScope / Tripo 服务。
- 本地任务历史、资产缓存、GLB 预览和模型下载。
- 自制且可按 MIT 许可再分发的离线样例。
- 根据当前滑杆导出材料预设、重力、网格和 Genesis 运行脚本。
- FEM 弹性体导出,以及实验性的 PBD 布料导出路径。
- 中英文界面、单元测试、后端类型检查与桌面/移动端浏览器测试。
## 边界与费用
浏览器是几何预览,不执行物理求解。材料参数是示意预设,不是从真实物体测得的参数。样例是程序化网格,不是扫描重建结果。布料路径没有被这个实体样例验证;充气体和软体机器人预设也不包含压力或执行器模型。
本项目不承诺任意网格都能仿真,不宣称已实现机器人训练、场景重建或经过测量的 sim-to-real 精度。生成式柔性变体是新的提示词生成,并非对原 GLB 的物理变形。
工作台代码和自制样例采用 MIT 许可。外部模型、服务及生成资产另受提供方条款约束,开源工作台不代表底层生成模型开源或生成免费。详见[第三方声明](../THIRD_PARTY_NOTICES.md)。
连接生成服务时,复制 `.env.example` 为 `.env.local` 并设置自己的 Key,然后运行 `npm run dev`。API 默认只监听 `127.0.0.1:8789`;普通模式可以通过 shell 或 `.env.local` 的 `PORT` 修改端口,前端代理同步使用该值,shell 优先。演示模式不读取 dotenv 文件。本项目不是可直接公开部署的多用户服务。不要把密钥或 `.data/` 提交到 Git。
## 开发与反馈
```bash
npm run test:run
npm run lint
npm run build
npx playwright install chromium
npm run test:e2e
npm audit
```
欢迎提交可复现的问题、安装日志和独立复现结果。请阅读[贡献指南](../CONTRIBUTING.md)与[安全说明](../SECURITY.md),不要在 Issue 中包含密钥或私人模型。

View File

@ -1,24 +0,0 @@
# Roadmap
## v0.1 scope
- Local generation through DashScope / Tripo, asset caching and GLB inspection.
- A procedural sample usable without an API key.
- Material presets and Genesis scene export using the current configuration.
- A reproducible FEM example with numerical checks and a recording.
- English / Chinese UI, setup guides, CI and an explicit license.
## Next
- A tested cloth mesh, PBD example and material-specific controls.
- Mesh diagnostics: watertightness, units, orientation and tetrahedralization failures.
- Import user-owned local GLB assets and retain provenance.
- Named, unit-aware material presets and tracked parameter comparisons.
- A provider interface, followed by an additional generation backend.
## Later, after validation
- Additional simulation export formats.
- Batch asset evaluation and task environments.
We do not currently claim calibrated real-to-sim reconstruction, browser physics, pressure-driven inflatable simulation, robot-policy training, or universal compatibility with arbitrary generated meshes.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 KiB

View File

@ -1,16 +0,0 @@
# Launch media sources
The release videos use only this repository's original procedural sample, actual offline UI recordings, the native Genesis camera recording and original explanatory text. No private task history, provider-generated mesh, cloned voice or third-party music is included.
`storyboard.json` is the bilingual narration and shot list. `scripts/capture-media.mjs` requires a running isolated `npm run demo` server. `scripts/render-launch.py` uses FFmpeg and macOS's built-in Tingting synthetic voice. It is a local production helper, not part of the cross-platform application runtime. Voice synthesis is explicitly disclosed in the video.
```bash
node scripts/capture-media.mjs
# Put the verified simulation.mp4 and metrics.json under artifacts/media/.
uv run --with pillow==13.0.0 python scripts/render-launch.py
uv run --with pillow==13.0.0 python scripts/render-launch.py --language zh --vertical
```
The media tool runs with a separate, current Pillow environment. Do not confuse that environment with the separately audited Genesis dependency chain.
Outputs in `artifacts/release/` are intentionally excluded from Git. Publish only inspected final files as Release assets. Keep platform IDs, public URLs and publication states in a separate ledger; an upload or draft is not public playback.

View File

@ -1,38 +0,0 @@
# Platform copy
All versions describe an Alpha and use actual UI / Genesis footage with synthetic narration. Do not replace these limits with claims of calibrated real-world accuracy or free generation.
## Bilibili
Title: 3D 模型怎样进入真实仿真?Real2Sim Studio 开源 Alpha
Real2Sim Studio 是一个本地优先的 3D 资产工作台:预览 GLB、配置材料预设、导出 Genesis 场景包。这次从自制的 MIT 样例出发,展示实际界面与 Genesis CPU 有限元求解。慢放镜头已标注,旁白为合成语音。
源码与复现文档:https://github.com/eust-w/real2sim-platform
材料参数只是示意预设,不是实物标定;浏览器不执行物理求解。布料路径实验性,外部 DashScope / Tripo 服务可能收费。可选 Python 依赖存在已知 Pillow 风险,请仅在隔离环境运行可信样例,先读 SECURITY.md。欢迎提交复现反馈与可重现问题。
Tags: 开源项目、Genesis、机器人仿真、三维建模、程序员
## YouTube
Title: Real2Sim Studio Alpha: From a 3D Mesh to a Genesis Simulation
A local-first workbench for GLB inspection, material presets and Genesis scene export. This video uses the included original procedural sample, actual UI captures and a native CPU FEM solver recording. Slowed replay is labeled. Chinese synthetic narration with English captions; no cloned voice.
Code, MIT sample and reproduction guide: https://github.com/eust-w/real2sim-platform
Important: material presets are not measured real-world properties. The browser is geometry preview only. Cloth is experimental, and external generation services may incur fees. The optional Python stack has known Pillow advisories constrained by an upstream dependency. Use only the trusted sample in an isolated environment; read SECURITY.md first.
## Short-video platforms
Title: 3D模型进仿真:Real2Sim开源Alpha
本地预览 GLB、配置材料预设、导出 Genesis 场景包。内置自制样例无需 API Key;本片展示真实界面与 Genesis CPU 有限元求解,慢放已标注。GitHub:eust-w/real2sim-platform(MIT)。材料不是实物标定,布料路径实验性;可选 Python 依赖有已知风险,仅在隔离环境运行可信样例,详见 SECURITY.md。外部生成服务可能收费。合成配音,AI 辅助制作。
Tags: #开源项目 #机器人仿真 #Genesis #三维建模 #程序员
## X
Real2Sim Studio Alpha: GLB preview, material presets and Genesis export. Real CPU FEM footage; MIT sample, no API key. Not calibrated physics. Known Python dependency risks: see SECURITY.md. Synthetic voice.
https://github.com/eust-w/real2sim-platform

View File

@ -1,12 +0,0 @@
[
{"duration":7,"title":"从模型到真实求解","enTitle":"From a mesh to a solver","source":"physics","zh":"一个三维模型,怎样真正进入仿真?先看这段真实的柔体求解。","en":"How does a 3D mesh enter a simulation? Start with a real deformable-body solver run."},
{"duration":8,"title":"Real2Sim Studio","enTitle":"Real2Sim Studio","source":"ui","zh":"这是 Real2Sim Studio。把资产预览、材料配置和场景导出,放进一个本地工作台。","en":"Real2Sim Studio brings asset inspection, material presets and scene export into a local workbench."},
{"duration":9,"title":"先跑通一个可信样例","enTitle":"Start with a trusted sample","source":"ui","zh":"加载内置的自制样例。不需要接口密钥,也不会调用付费生成服务。","en":"Load the included procedural sample. No API key, and no paid generation calls."},
{"duration":8,"title":"几何预览,不冒充物理","enTitle":"Geometry preview, not physics","source":"ui","zh":"在浏览器中旋转和检查模型。这里是几何预览,不是物理仿真。","en":"Rotate and inspect the mesh in your browser. This is geometry preview, not physics."},
{"duration":9,"title":"当前参数,进入导出包","enTitle":"Export the settings you chose","source":"settings","zh":"调整材料预设和重力。导出的配置,使用你当前选择的参数。","en":"Adjust material presets and gravity. The exported package uses your current settings."},
{"duration":10,"title":"模型、配置、脚本,一起交付","enTitle":"Mesh, configuration and script","source":"package","zh":"下载完整场景包。模型、配置、运行脚本和依赖说明,都放在一起。","en":"Download a complete scene package: mesh, manifest, material profile, Python script and requirements."},
{"duration":10,"title":"Genesis FEM · CPU","enTitle":"Genesis FEM on CPU","source":"physics","zh":"运行导出的脚本。这里的下落、接触和形变,来自 Genesis 求解器,不是预设动画。","en":"Run the exported script. Falling, contact and deformation here come from Genesis, not a canned animation."},
{"duration":9,"title":"可复现,也有明确边界","enTitle":"Reproducible, with clear limits","source":"metrics","zh":"这是有限元弹性体样例。材料数值是示意预设,不是实物标定,也没有承诺仿真到现实的精度。","en":"This is an FEM elastic sample. Presets are illustrative, not measured material properties or sim-to-real validation."},
{"duration":10,"title":"可选生成服务 · Alpha 限制","enTitle":"Optional generation · Alpha limits","source":"limits","zh":"外部生成服务可能收费。可选 Python 依赖仍有已知风险,请先在隔离环境运行可信样例。","en":"External generation may incur fees. The optional Python dependencies have known advisories. Use the trusted sample in isolation."},
{"duration":10,"title":"下载、复现、反馈","enTitle":"Download. Reproduce. Contribute.","source":"end","zh":"代码和自制样例按 MIT 许可开放。下载并运行示例,欢迎把复现结果和问题反馈给我们。","en":"Code and the procedural sample are MIT-licensed. Run the example and share reproducible results and issues."}
]

View File

@ -1,123 +0,0 @@
# Real2Sim 开源首发与视频方案
核查日期:2026-10-26。代码基线:`3e4c2f4`。
本文保留 2026-10-26 的发布前基线,表内“当前”均指该次核查,不是最新状态。后续实现、验证与限制见 [v0.1.0 Alpha 发布说明](releases/v0.1.0-alpha.1.md);平台实际发布证据单独记录,不以本方案作为已发布证明。
## 判断与定位
项目具备开源工具的基础,但当前应定位为早期工作台。成为有影响力的开源项目,需要真实可复现的使用价值、清楚的技术边界和持续维护,不能由一次宣传或 Star 数承诺保证。
建议展示名:**Real2Sim Studio**,暂保留仓库名 `real2sim-platform`。
当前可用介绍:
> 一个开源准备中的 3D 资产工作台,连接 Tripo 生成、本地资产预览、材料参数配置和 Genesis 场景包导出。
首发目标定位:
> 面向具身智能开发者的可视化资产到仿真工作台,让第一个可运行案例更容易复现。
首要用户是需要把单个物体带入仿真的开发者和研究者。首版围绕一个完整案例展开,不同时承诺场景重建、机器人训练和多个仿真器。
当前生成依赖 DashScope / Tripo 服务;开源工作台不等于开源底层生成模型,也不等于免费生成。项目没有验证几何重建精度、实物材料参数辨识或 sim-to-real 效果。
## 已核查的状态
| 项目 | 本轮结果 | 能证明的范围 |
| --- | --- | --- |
| GitHub | `eust-w/real2sim-platform` 当前 PRIVATE,无许可证 | 还未成为公开授权的开源仓库 |
| 工作区 | 核查前干净 | 本轮方案以当前提交为基线 |
| 功能代码 | 文本 / 单图 / 多图生成、任务管理、缓存、GLB 预览、配置和 Genesis 导出 | 代码具备这些路径,未重新调用付费生成接口 |
| 单元测试 | 3 个文件、7 个测试通过 | 资产缓存、配置和导出包逻辑;不含真实 Genesis 执行 |
| lint / build | 均通过 | 编译与静态检查通过;构建仍提示较大的 JS bundle |
| 本地任务 | 5 条历史任务,其中 2 条记录有本地模型 URL | 可作为后续检查素材的候选,不证明素材权利或仿真成功 |
| 生产依赖审计 | 5 个受影响依赖:1 critical、2 high、2 moderate | npm advisory 分级,不等同于已验证可利用 |
| 敏感文件路径历史 | 本地可达 Git 历史的指定路径检查只出现 `.env.example` | 尚未进行完整内容级历史密钥扫描 |
审计涉及 `proxy-addr`、`body-parser`、`zod`、`qs`、`fflate`;应结合实际调用路径更新和复验。
## 首发前优先处理
1. **修复本地资产到柔性任务的接口契约。** `src/App.tsx` 将本地 `/assets/...` 路径作为 `sourceModelUrl` 提交,而 `server/schemas.ts` 使用绝对 URL 校验。本轮直接调用 schema 已复现 `Invalid URL`。需要覆盖真实本地资产选择流程。
2. **让导出参数与 UI 一致。** `server/genesisPackage.ts` 的脚本生成固定使用 `-9.8`,忽略用户重力。还要核对 UI、flex profile 和 Genesis manifest 对 solver、单位和参数含义的约定。
3. **验证真正的 Genesis 执行。** 当前测试用几个字节代替 GLB,并检查生成的 Python 文本,不能证明四面体化、材质创建和求解运行成功。固定已验证的 Genesis 版本、运行环境和样例,保存运行命令、日志、视频及失败限制。
4. **明确预览与求解的区别。** `Viewport3D.tsx` 的 `SoftBody` 使用 `MeshDistortMaterial` 和周期缩放;它是视觉占位效果。已有 GLB 的 `AssetModel` 路径展示几何,并未执行浏览器物理求解。宣传中的柔体结果必须来自实际仿真录屏。
5. **补齐可复现的首次体验。** 提供可再分发的样例和无需 API Key 的样例模式;生成模式使用用户自己的 Key,并写清服务依赖和费用边界。记录全新环境的安装和运行结果。
6. **完成发布基础。** 明确代码和素材授权主体,选定 LICENSE,补第三方素材说明、英文首页与中文文档、CI、CONTRIBUTING、问题模板、路线图和版本说明。完成依赖修复及完整历史密钥检查。
开放源码与公开托管服务是不同交付。当前后端没有用户鉴权、配额或请求限流,且监听地址没有限制为 loopback;公开演示若连接维护者的付费 Key,需先解决访问和成本控制。首发优先采用本地运行与只读样例展示。
README 现在写着 GitHub 应为 private、Gitea 应为 public。确定开源发布策略后,需要同步更新这段约定;本轮未调整远端可见性。
## 差异化方向
EmbodiedGen 官方项目已经描述了多种生成后端、物理属性、跨仿真器导出及 Genesis 柔体示例。仅以“AI 生成 3D + 导出仿真”做介绍,差异不明显。
建议把工作集中在可验证的体验优势:
- 用户能从干净环境快速复现一个已验证案例,而不是自行调通许多组件。
- 同一资产的来源、尺寸、材料配置、导出版本和运行结果可以追溯。
- 失败时能明确指出问题发生在生成、网格、导出还是求解阶段。
- 后续将生成后端做成可替换适配器;首发先交付一个可靠路径。
这些是产品方向,尚不是当前已经实现的能力。
## 分阶段交付
| 阶段 | 具体交付 | 进入下一阶段的条件 |
| --- | --- | --- |
| 可运行案例 | 修复主流程、锁定仿真版本、一个有授权的样例、运行日志和实录 | 他人在干净环境按说明复现 |
| 开源发布包 | LICENSE、英文 README、中文指南、CI、样例、v0.1.0 说明 | 功能声明与证据一致,授权和密钥检查完成 |
| 视频成片 | 90 秒横版母片、竖版短片、中英文字幕、封面、发布文案 | 所有镜头来自本项目可验证的行为 |
| 对外首发 | GitHub Release 与选定账号发布;记录实际链接 | 仓库和下载入口可访问,各平台发布结果可核对 |
| 用户迭代 | 收集安装失败、仿真失败和复现反馈,完善贡献入口 | 用真实使用与贡献衡量价值 |
首轮观察目标可设为 10 位独立用户成功复现、3 条具体使用反馈,再争取外部贡献。它们是内部验证目标,不是效果保证。
## 90 秒主视频分镜
主题:**从 3D 资产到 Genesis:把生成、配置和导出串起来。**
以下分镜用于主流程修复和真实仿真验证之后。尚未录制的结果不能用生成式视频或浏览器占位动画替代。
| 时长 | 画面 | 旁白方向 |
| --- | --- | --- |
| 0–6 秒 | 同一个样例的输入、GLB 和 Genesis 运行结果并列 | “生成一个 3D 模型之后,怎样把它带进仿真?” |
| 6–16 秒 | 工作台全景与样例选择 | “Real2Sim Studio 把资产预览、材料配置和场景导出放在一起。” |
| 16–32 秒 | 实际生成记录、缓存结果和模型旋转 | “使用 Tripo 生成资产,再把模型保存在本地。” |
| 32–48 秒 | 参数配置、单位、导出的配置文件 | “选择材料并调整参数,导出模型、配置和 Genesis 脚本。” |
| 48–68 秒 | 执行包内命令,展示真实求解画面 | “这是这个样例在已验证环境中的运行结果。” |
| 68–80 秒 | 完整下载包、示例和复现命令 | “同一份样例和配置可以下载复现。” |
| 80–90 秒 | GitHub 地址、版本号、示例入口 | “代码与示例已开放,欢迎复现并反馈。” |
制作要求:
- 录屏时保留同一资产的身份和过程连续性;等待过程可剪辑,但标注加速或省略,耗时只报实测值。
- 参数对比必须重新运行真实仿真;未验证前不使用“物理准确”“一键任意物体”“世界首个”等描述。
- 把 `API generation`、`3D preview`、`Genesis simulation` 的画面阶段标清。
- 画面不包含 API Key、服务令牌、私人任务内容或内部页面。
- 片尾“已开源”只在仓库可见性和许可证发布完成后使用。
- 留存无字幕母片、中文 SRT、英文 SRT、配音音轨和素材来源记录,便于后续适配。
## 平台版本建议
以下是编辑方案,不是平台上传限制或流量保证;实际上传时再核对各账号当时支持的规格。
| 渠道 | 建议版本 | 内容侧重 |
| --- | --- | --- |
| GitHub README / Release | 10–20 秒循环演示,加 90 秒完整视频入口 | 能做什么、如何复现、当前限制 |
| B 站 / YouTube | 90 秒介绍,加独立 3–5 分钟复现教程 | 实际操作、环境和失败排查 |
| 抖音 / 视频号 / 小红书 | 30–45 秒竖版,重新排版而非直接裁切横屏 | 先展示结果,再讲一个使用场景 |
| X / LinkedIn | 30–60 秒英文字幕版本,加项目链接 | 开发者价值、贡献方向 |
| 公众号 / 知乎 | 视频配技术文章与运行步骤 | 技术边界、设计取舍和可复现证据 |
发布次序建议:先让 GitHub 代码和示例可用,再发布完整演示与教程,随后分发短版。每次发布保留平台、账号、文案版本、成片版本、实际 URL 和状态。
具体账号和首发平台尚未指定。本轮未连接社交账号、未上传视频。
## 参考依据
- [GitHub:仓库许可说明](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository):公开仓库需要明确开源许可,不能将可见性视为完整授权。
- [EmbodiedGen 官方仓库](https://github.com/HorizonRobotics/EmbodiedGen):用于核对相邻项目的能力与本项目差异化方向,不代表已完成运行对比。
- 本地证据:`README.md`、`src/App.tsx`、`src/components/Viewport3D.tsx`、`server/schemas.ts`、`server/flex.ts`、`server/genesisPackage.ts`、`server/genesisPackage.test.ts`。

View File

@ -0,0 +1,8 @@
# Real2Sim product prototypes
The prototype board in this directory is the visual contract for the POC
productization branch. It covers login, the seven product pages, the task
drawer, and the key mobile layouts.
Implementation screenshots are stored under acceptance output and are not
committed to Git.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

@ -1,36 +0,0 @@
# Alpha Publication Status
Verified on 2026-10-28 (Asia/Shanghai). Uploads, drafts and review queues are not counted as publication.
| Channel | State | Evidence |
| --- | --- | --- |
| GitHub | Public MIT repository and prerelease | [Repository](https://github.com/eust-w/real2sim-platform), [v0.1.0-alpha.1](https://github.com/eust-w/real2sim-platform/releases/tag/v0.1.0-alpha.1) |
| Gitea | Public mirror and prerelease | [Repository](https://gitea.d-robotics.cc/longtao.wu/real2sim-platform), [v0.1.0-alpha.1](https://gitea.d-robotics.cc/longtao.wu/real2sim-platform/releases/tag/v0.1.0-alpha.1) |
| X | Published; 90-second video playback verified | [Public post](https://x.com/eustancewu/status/2115131684236800501) |
| Douyin | Published; 45-second video playback verified | [Public video](https://www.douyin.com/video/7701399089530916159) |
| Bilibili | Not published; awaiting uploader agreement confirmation | Chinese introduction and upload copy prepared |
| YouTube | Not published; awaiting account verification and agreement confirmation | English-captioned introduction and upload copy prepared |
| Xiaohongshu | Not published; draft saved, account action required | Vertical video and upload copy prepared |
| WeChat Channels | Not published; publishing interface unavailable to the current tool session | Vertical video and upload copy prepared |
Both releases contain 15 assets. GitHub asset SHA-256 metadata matches the local files; all 15 Gitea assets were downloaded without authentication and their SHA-256 hashes matched. Neither private task history nor local credentials are release assets.
## Media
- [90-second Chinese introduction](https://github.com/eust-w/real2sim-platform/releases/download/v0.1.0-alpha.1/real2sim-intro-zh.mp4)
- [90-second English-captioned introduction](https://github.com/eust-w/real2sim-platform/releases/download/v0.1.0-alpha.1/real2sim-intro-en.mp4), with Chinese synthetic narration
- [45-second Chinese vertical version](https://github.com/eust-w/real2sim-platform/releases/download/v0.1.0-alpha.1/real2sim-short-zh.mp4)
- [Native Genesis solver recording](https://github.com/eust-w/real2sim-platform/releases/download/v0.1.0-alpha.1/genesis-native-simulation.mp4)
- Subtitles, covers, the runnable example, metrics, license and security notes are attached to both releases.
The introduction uses actual UI captures and the original procedural sample. Slowed simulation replay is labeled. Synthetic narration and AI assistance are disclosed. The English-captioned version does not have an English voice track.
## Verification Boundary
The original release tag is `56f124f`; it has not been moved. Follow-up main-branch fixes pin the supported CI runner, add numerical-metric CI tests, and ensure the API and Vite receive the same `.env.local` port. [CI at 518917d passed](https://github.com/eust-w/real2sim-platform/actions/runs/40551404979), including browser smoke tests and numerical-metric tests. Current launcher regression checks also pass locally.
The recorded Genesis example completed 800 CPU steps with finite output and measured shape change. It is not a physical-accuracy benchmark, GPU validation or proof of arbitrary mesh compatibility. See [release notes](v0.1.0-alpha.1.md) and [numerical results](../verification/genesis-cpu.json).
The optional Python stack still has unresolved Pillow advisories due to an upstream MoviePy version constraint. Use only trusted sample assets in an isolated environment. A clean Node audit does not make the Python runtime safe for untrusted input; see [SECURITY.md](../../SECURITY.md).
Platform-specific copy is kept in [the media guide](../media/platform-copy.md). Publication records do not promise reach, stars or virality.

View File

@ -1,45 +0,0 @@
# Real2Sim Studio v0.1.0 Alpha
A local-first asset-to-simulation workbench with a reproducible, original example.
## Included
- Offline mode with a self-authored MIT procedural GLB, isolated task storage and disabled paid generation calls.
- Geometry preview, rotation, English/Chinese UI and material presets.
- Genesis archive export using the current sliders, including gravity. Downloads work from the default hidden `.data` directory.
- A Genesis 1.4.5 FEM runtime, implicit CPU solver, camera recording, trajectory and numerical metrics.
- Optional DashScope / Tripo text, image and multi-image integration. Paid generation was not called during this release verification.
- MIT license, third-party notices, contribution guide, security notes, CI and bilingual documentation.
## Verification on 2026-10-28
Reference environment: macOS 15.7.7 ARM64, Python 3.11.15, Genesis World 1.4.5, PyTorch 2.14.1, Node 24.14.0.
- 16 TypeScript tests and 2 numerical-metric unit tests passed.
- Lint and production build passed. The Three.js-containing JS bundle remains large (about 1.2 MB before gzip).
- Browser smoke tests verified a real GLB archive, gravity 3.7, hidden-directory download, nonblank canvas pixels, rotation, and mobile layout without horizontal overflow.
- The original sample ran for 800 steps of 0.002 s on CPU. All sampled positions were finite; the body fell onto the ground and changed shape. See [metrics](../verification/genesis-cpu.json).
- Shape deformation is measured after removing translation and rigid rotation with Kabsch alignment. It is not an accuracy benchmark against a real object.
- The native recording contains 1.6 seconds of simulated time. The introduction clearly labels slowed replay. Kernel compilation time is not presented as real-time performance.
- Node `npm audit`: 0 reported vulnerabilities at verification time. The optional Python audit is not clean; see below.
## Important limitations
This is an **Alpha**, not a calibrated digital-twin or robot-training system. Material values are illustrative presets; arbitrary meshes may fail tetrahedralization. Cloth export is experimental and is not validated by the solid example. Inflatable/soft-robot presets do not model pressure or actuators. A prompt-generated flexible variant is a new generation, not physical modification of its source mesh.
The optional Python stack has known Pillow advisories constrained by MoviePy's Pillow <12 requirement. Do not process untrusted assets. Use the bundled example in an isolated environment without credentials or private data. See [SECURITY.md](../../SECURITY.md) for the unresolved dependency issue; no advisory was silently ignored.
The browser is only a geometry preview. It does not run Genesis physics. The workbench is a local single-user application; do not expose its development servers publicly.
## Reproduce
```bash
npm ci
npm run demo
# In a separate terminal, after configuring the Python environment:
npm run example:export
python .data/genesis-packages/example-soft-puck/genesis_scene.py --steps 800 --record
python scripts/verify-physics.py
```
See the [example guide](../../examples/README.md). The media uses the original procedural sample, actual UI captures and native Genesis recording, with synthetic narration and no cloned voice or third-party music.

View File

@ -1,19 +0,0 @@
{
"checks": [
"offline import",
"cross-origin rejection",
"real GLB archive",
"current gravity",
"solver mapping",
"desktop canvas pixels",
"interactive rotation",
"browser export current sliders",
"mobile no overflow"
],
"browserErrors": [],
"canvas": {
"colors": 282,
"width": 840,
"height": 578
}
}

View File

@ -1,15 +0,0 @@
{
"genesis_version": "1.4.5",
"backend": "cpu",
"solver": "fem_elastic",
"steps": 800,
"dt": 0.002,
"gravity": 9.8,
"vertex_count": 226,
"initial_center_z": 0.3496624529361725,
"final_center_z": 0.04337442293763161,
"min_vertex_z": 0.0009183835936710238,
"all_finite": true,
"recorded": true,
"max_shape_deformation_m": 0.041962653398513794
}

View File

@ -1,25 +0,0 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([
globalIgnores(['dist', '.venv', '.data', 'artifacts']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
globals: globals.browser,
},
rules: {
'react-hooks/set-state-in-effect': 'off',
},
},
])

View File

@ -1,50 +0,0 @@
# Reproduce the procedural example
This sample is an original, watertight mesh generated from an icosphere. The model and generator are MIT-licensed with the repository. It is not a scanned object or a paid generation result. GLB uses metres and Y-up coordinates.
## Inspect and export
```bash
npm ci
npm run demo
```
Open the local Vite URL, select **Load example**, then **Export Genesis Package**. The archive includes the current sliders, mesh, Python entry point, requirements and manifest. Unpack it before running. To export the default example without the UI:
```bash
npm run example:export
```
The default export goes to `.data/genesis-packages/example-soft-puck/`. Re-exporting replaces this generated folder, including previous run results. Keep any results you need elsewhere first.
## Run Genesis
The reference environment is Python 3.11, Genesis World 1.4.5 and PyTorch 2.14.1. Use a virtual environment; the Python dependencies are separate from the Node application.
```bash
python3.11 -m venv .venv
source .venv/bin/activate
python -m pip install -r examples/requirements.txt
python .data/genesis-packages/example-soft-puck/genesis_scene.py --steps 800
```
The default CPU run writes `metrics.json` and `trajectory.npz` next to the script. The first run may take several minutes to compile kernels. `--backend gpu` requests the Genesis GPU backend but is not covered by the reference CPU verification.
For a native Genesis camera recording:
```bash
python .data/genesis-packages/example-soft-puck/genesis_scene.py --steps 800 --record
```
This writes `simulation.mp4`. Rendering needs a supported graphics environment; a headless numerical success does not imply camera support. `--viewer` additionally opens the interactive Genesis viewer.
## Interpret the result
- FEM elastic material presets use an implicit solver with a 0.002 s step and four substeps. The sample is dropped onto a plane.
- The browser displays geometry only. Deformation footage comes from the exported Genesis scene.
- Gravity comes from the exported manifest, not a fixed value in the Python script.
- Presets are illustrative, not measured silicone properties. No physical calibration or sim-to-real accuracy is claimed.
- Cloth uses a separate experimental PBD path and requires a suitable surface mesh. This solid sample validates the FEM path only.
- Arbitrary generated models may have wrong units, disconnected surfaces or invalid topology. Inspect and repair them before simulation.
To regenerate the source geometry after installing the Python requirements, run `python scripts/generate-example.py`. This overwrites only `examples/soft-puck/model.glb`.

View File

@ -1,3 +0,0 @@
genesis-world==1.4.5
torch==2.14.1
imageio-ffmpeg==0.6.0

Binary file not shown.

View File

@ -1,13 +0,0 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>real2sim 平台</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

5396
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,54 +0,0 @@
{
"name": "real2sim-platform",
"private": true,
"version": "0.1.0",
"description": "A local-first 3D asset and Genesis simulation workbench",
"license": "MIT",
"repository": "github:eust-w/real2sim-platform",
"engines": { "node": ">=22.12" },
"type": "module",
"scripts": {
"dev": "node scripts/dev.mjs",
"demo": "node scripts/dev.mjs --demo",
"client": "vite",
"server": "tsx watch server/index.ts",
"start": "tsx server/index.ts",
"build": "tsc -b && tsc -p tsconfig.server.json && vite build",
"lint": "eslint .",
"preview": "vite preview",
"test": "vitest",
"test:run": "vitest run",
"test:e2e": "node scripts/smoke.mjs",
"example:export": "tsx scripts/export-example.ts"
},
"dependencies": {
"@react-three/drei": "^10.7.7",
"@react-three/fiber": "^9.6.1",
"dotenv": "^17.4.2",
"express": "^5.2.1",
"lucide-react": "^1.17.0",
"react": "^19.2.6",
"react-dom": "^19.2.6",
"three": "^0.184.0",
"zod": "^4.4.3"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@types/express": "^5.0.6",
"@types/node": "^24.12.3",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^6.0.1",
"concurrently": "^10.0.3",
"eslint": "^10.3.0",
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.2",
"globals": "^17.6.0",
"playwright": "^1.60.0",
"tsx": "^4.22.4",
"typescript": "~6.0.2",
"typescript-eslint": "^8.59.2",
"vite": "^8.0.12",
"vitest": "^4.1.8"
}
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 9.3 KiB

49
pyproject.toml Normal file
View File

@ -0,0 +1,49 @@
[build-system]
requires = ["setuptools>=68", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "real2sim-platform"
version = "0.1.0"
description = "Real2Sim scene, collection, training, and inference management platform"
requires-python = ">=3.10"
dependencies = [
"argon2-cffi>=23.1",
"bce-python-sdk>=0.9.29",
"fastapi>=0.110",
"huggingface_hub>=0.24",
"imageio>=2.34",
"opencv-python-headless>=4.8",
"pillow>=10",
"pyarrow>=15",
"mujoco>=3.2",
"numpy>=1.25,<2",
"pydantic>=2",
"python-multipart>=0.0.9",
"trimesh>=4.12,<5",
"usd-core==25.11",
"uvicorn[standard]>=0.27",
]
[project.scripts]
real2sim-platform = "real2sim_platform.server:main"
real2sim-worker = "real2sim_platform.worker_main:main"
real2sim-runtime-gate = "real2sim_platform.runtime_gate:main"
[tool.setuptools.packages.find]
where = ["src"]
[tool.setuptools.package-data]
"real2sim_platform" = [
"static/*",
"static/vendor/*",
"static/vendor/three/*",
"static/vendor/three/addons/controls/*",
"static/vendor/three/addons/loaders/*",
"static/vendor/three/addons/postprocessing/*",
"static/vendor/three/addons/utils/*",
"static/assets/robots/*",
]
[tool.pytest.ini_options]
markers = ["integration: exercises installed real runtimes and physical scene assets"]

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

842
scripts/acceptance_poc_cluster.py Executable file
View File

@ -0,0 +1,842 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import hashlib
import http.cookiejar
import json
import os
import secrets
import shutil
import socket
import ssl
import subprocess
import sys
import tempfile
import time
import urllib.error
import urllib.request
import zipfile
from pathlib import Path
from typing import Any, Callable
ROOT = Path(__file__).resolve().parents[1]
DEFAULT_KUBECONFIG = Path("/Users/d-robotics/Downloads/poc.config")
DEFAULT_PLAYROOM = Path("/Users/d-robotics/Downloads/images")
NAMESPACE = "real2sim-poc"
TERMINAL = {"succeeded", "failed", "failed_recovered", "canceled"}
class AcceptanceError(RuntimeError):
pass
class ApiError(AcceptanceError):
def __init__(self, status: int, path: str, payload: Any) -> None:
super().__init__(f"HTTP {status} {path}: {payload}")
self.status = status
self.path = path
self.payload = payload
class ApiClient:
def __init__(self, base_url: str) -> None:
self.base_url = base_url.rstrip("/")
self.cookies = http.cookiejar.CookieJar()
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
self.opener = urllib.request.build_opener(
urllib.request.ProxyHandler({}),
urllib.request.HTTPSHandler(context=context),
urllib.request.HTTPCookieProcessor(self.cookies),
)
def request(
self,
method: str,
path: str,
payload: Any | None = None,
*,
body: bytes | None = None,
content_type: str = "application/json",
timeout: int = 180,
) -> Any:
data = body
if payload is not None:
data = json.dumps(payload, ensure_ascii=False).encode("utf-8")
headers = {"Accept": "application/json"}
if data is not None:
headers["Content-Type"] = content_type
request = urllib.request.Request(self.base_url + path, data=data, headers=headers, method=method)
try:
with self.opener.open(request, timeout=timeout) as response:
raw = response.read()
response_type = response.headers.get("content-type", "")
if "application/json" in response_type:
return json.loads(raw.decode("utf-8"))
return raw.decode("utf-8", errors="replace")
except urllib.error.HTTPError as exc:
raw = exc.read()
try:
payload = json.loads(raw.decode("utf-8"))
except Exception:
payload = raw.decode("utf-8", errors="replace")
raise ApiError(exc.code, path, payload) from exc
def get(self, path: str) -> Any:
return self.request("GET", path)
def post(self, path: str, payload: Any | None = None) -> Any:
return self.request("POST", path, payload)
def utc_now() -> str:
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
def kubectl(kubeconfig: Path, *args: str, timeout: int = 3600, check: bool = True) -> subprocess.CompletedProcess[str]:
return subprocess.run(
["kubectl", "--kubeconfig", str(kubeconfig), *args],
text=True,
capture_output=True,
timeout=timeout,
check=check,
)
def free_port() -> int:
with socket.socket() as sock:
sock.bind(("127.0.0.1", 0))
return int(sock.getsockname()[1])
def start_port_forward(kubeconfig: Path, port: int, out_dir: Path) -> subprocess.Popen[str]:
log = (out_dir / "port-forward.log").open("w", encoding="utf-8")
process = subprocess.Popen(
[
"kubectl",
"--kubeconfig",
str(kubeconfig),
"-n",
NAMESPACE,
"port-forward",
"svc/real2sim-frontend",
f"{port}:443",
"--address",
"127.0.0.1",
],
text=True,
stdout=log,
stderr=subprocess.STDOUT,
)
deadline = time.time() + 90
while time.time() < deadline:
if process.poll() is not None:
log.close()
raise AcceptanceError((out_dir / "port-forward.log").read_text(encoding="utf-8", errors="replace"))
try:
with socket.create_connection(("127.0.0.1", port), timeout=1):
return process
except OSError:
time.sleep(1)
process.terminate()
log.close()
raise AcceptanceError("timed out waiting for the HTTPS port-forward")
class AcceptanceRun:
def __init__(self, *, client: ApiClient, out_dir: Path, kubeconfig: Path, build_id: str, timeout_seconds: int) -> None:
self.client = client
self.out_dir = out_dir
self.kubeconfig = kubeconfig
self.build_id = build_id
self.timeout_seconds = timeout_seconds
self.report: dict[str, Any] = {
"schema": "real2sim.poc_acceptance_report.v1",
"started_at": utc_now(),
"finished_at": "",
"build_id": build_id,
"namespace": NAMESPACE,
"version": {},
"doctor": {},
"capabilities": {},
"recipes": {},
"identities": {},
"tasks": [],
"datasets": [],
"scenes": [],
"models": [],
"storage": {},
"browser": {"status": "pending", "note": "Run browser acceptance after the API gate."},
"artifacts": [],
"checks": [],
"failures": [],
"warnings": [],
"pass": False,
}
def save(self) -> None:
self.out_dir.mkdir(parents=True, exist_ok=True)
(self.out_dir / "acceptance_report.json").write_text(
json.dumps(self.report, ensure_ascii=False, indent=2) + "\n",
encoding="utf-8",
)
lines = [
f"# Real2Sim POC Acceptance {self.build_id}",
"",
f"- Started: {self.report['started_at']}",
f"- Finished: {self.report['finished_at'] or 'running'}",
f"- Pass: **{self.report['pass']}**",
f"- Tasks: {len(self.report['tasks'])}",
f"- Failures: {len(self.report['failures'])}",
"",
"## Checks",
*[f"- {'PASS' if item['ok'] else 'FAIL'}: {item['name']}" for item in self.report["checks"]],
"",
"## Failures",
*([f"- {item['stage']}: {item['error']}" for item in self.report["failures"]] or ["- None"]),
"",
"## Warnings",
*([f"- {item}" for item in self.report["warnings"]] or ["- None"]),
]
(self.out_dir / "summary.md").write_text("\n".join(lines) + "\n", encoding="utf-8")
def check(self, name: str, ok: bool, detail: Any = None) -> None:
self.report["checks"].append({"name": name, "ok": bool(ok), "detail": detail})
self.save()
if not ok:
raise AcceptanceError(f"{name}: {detail}")
def stage(self, name: str, action: Callable[[], Any]) -> Any | None:
print(f"\n== {name} ==", flush=True)
started = time.time()
try:
result = action()
self.report["checks"].append({"name": name, "ok": True, "elapsed_seconds": round(time.time() - started, 2)})
self.save()
return result
except Exception as exc:
failure = {
"stage": name,
"error": f"{type(exc).__name__}: {exc}",
"elapsed_seconds": round(time.time() - started, 2),
"next_action": "Inspect the task reports and logs recorded in this acceptance directory, fix the real runtime blocker, then rerun the gate.",
}
self.report["checks"].append({"name": name, "ok": False, "elapsed_seconds": failure["elapsed_seconds"]})
self.report["failures"].append(failure)
self.save()
print(f"FAILED: {failure['error']}", file=sys.stderr, flush=True)
return None
def create_task(self, task_type: str, params: dict[str, Any], *, required_artifacts: tuple[str, ...] = ()) -> dict[str, Any]:
created = self.client.post("/api/tasks", {"type": task_type, "params": params})
print(f"{task_type}: {created['id']}", flush=True)
return self.wait_task(created["id"], required_artifacts=required_artifacts)
def wait_task(
self,
task_id: str,
*,
required_artifacts: tuple[str, ...] = (),
expected_status: str = "succeeded",
timeout_seconds: int | None = None,
) -> dict[str, Any]:
deadline = time.time() + int(timeout_seconds or self.timeout_seconds)
previous = None
task: dict[str, Any] = {}
while time.time() < deadline:
task = self.client.get(f"/api/tasks/{task_id}")
marker = (task.get("status"), task.get("progress"), task.get("stage"), task.get("message"))
if marker != previous:
print(f" {task.get('status')} {task.get('progress')}% {task.get('stage')} {task.get('message')}", flush=True)
previous = marker
if task.get("status") in TERMINAL:
break
time.sleep(5)
else:
raise AcceptanceError(f"task {task_id} timed out after {timeout_seconds or self.timeout_seconds}s")
artifacts = self.client.get(f"/api/tasks/{task_id}/artifacts")
reports = self.client.get(f"/api/tasks/{task_id}/reports")
task_record = {
"id": task_id,
"type": task.get("type"),
"status": task.get("status"),
"progress": task.get("progress"),
"stage": task.get("stage"),
"message": task.get("message"),
"error": task.get("error"),
"result": task.get("result"),
"artifact_count": len(artifacts),
"artifact_names": sorted({str(item.get("name") or "") for item in artifacts}),
"reports": reports,
}
self.report["tasks"].append(task_record)
self.save()
if task.get("status") != expected_status:
log = self.client.get(f"/api/tasks/{task_id}/logs")
failure_dir = self.out_dir / "task_failures" / task_id
failure_dir.mkdir(parents=True, exist_ok=True)
(failure_dir / "task.json").write_text(json.dumps(task, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
(failure_dir / "reports.json").write_text(json.dumps(reports, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
(failure_dir / "artifacts.json").write_text(json.dumps(artifacts, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
(failure_dir / "task.log").write_text(str(log), encoding="utf-8")
raise AcceptanceError(f"task {task_id} ended as {task.get('status')}: {reports.get('readable_error') or task.get('error')}")
if expected_status == "succeeded" and not artifacts:
raise AcceptanceError(f"succeeded task {task_id} has no indexed artifacts")
names = {str(item.get("name") or "") for item in artifacts}
missing = sorted(set(required_artifacts) - names)
if missing:
raise AcceptanceError(f"task {task_id} is missing required artifacts: {missing}")
result = task.get("result") or {}
if expected_status == "succeeded" and not str(result.get("run_storage_uri") or "").startswith("bos://testxyz/real2sim-poc/runs/"):
raise AcceptanceError(f"task {task_id} has no owned BOS run URI")
return task
def credential_candidates(root: Path, out_dir: Path) -> list[str]:
candidates: list[str] = []
explicit = os.environ.get("REAL2SIM_POC_ADMIN_PASSWORD", "").strip()
if explicit:
candidates.append(explicit)
for path in [out_dir / "acceptance-admin-password.txt", out_dir / "bootstrap-admin-password.txt"]:
if path.is_file():
candidates.append(path.read_text(encoding="utf-8").strip())
prior = sorted((root / "acceptance_runs" / "poc").glob("*/acceptance-admin-password.txt"), key=lambda path: path.stat().st_mtime, reverse=True)
prior += sorted((root / "acceptance_runs" / "poc").glob("*/bootstrap-admin-password.txt"), key=lambda path: path.stat().st_mtime, reverse=True)
for path in prior:
candidates.append(path.read_text(encoding="utf-8").strip())
return list(dict.fromkeys(value for value in candidates if value))
def authenticate_admin(run: AcceptanceRun) -> str:
login = None
current_password = ""
errors: list[str] = []
for candidate in credential_candidates(ROOT, run.out_dir):
try:
login = run.client.post("/api/auth/login", {"username": "admin", "password": candidate})
current_password = candidate
break
except ApiError as exc:
errors.append(str(exc.status))
if login is None:
raise AcceptanceError(f"admin login failed for all credential candidates: {errors}")
if login["user"].get("must_change_password"):
next_password = "Real2Sim!" + secrets.token_urlsafe(18) + "Aa1"
run.client.post(
"/api/auth/change-password",
{"current_password": current_password, "new_password": next_password},
)
run.client.post("/api/auth/login", {"username": "admin", "password": next_password})
current_password = next_password
password_path = run.out_dir / "acceptance-admin-password.txt"
password_path.write_text(current_password + "\n", encoding="utf-8")
password_path.chmod(0o600)
me = run.client.get("/api/auth/me")["user"]
run.check("管理员登录且已完成首次改密", me.get("role") == "admin" and not me.get("must_change_password"), me)
return current_password
def verify_rbac(run: AcceptanceRun) -> None:
suffix = secrets.token_hex(4)
records: dict[str, Any] = {}
for role in ("engineer", "viewer"):
username = f"acceptance.{role}.{suffix}"
password = f"{role.title()}!Password123"
user = run.client.post("/api/users", {"username": username, "password": password, "role": role})
records[role] = {"id": user["id"], "username": username}
role_client = ApiClient(run.client.base_url)
login = role_client.post("/api/auth/login", {"username": username, "password": password})
if login["user"].get("must_change_password"):
changed = f"{role.title()}!Changed456"
role_client.post("/api/auth/change-password", {"current_password": password, "new_password": changed})
role_client.post("/api/auth/login", {"username": username, "password": changed})
role_client.get("/api/datasets")
try:
payload = {"type": "motrixsim_asset_import" if role == "engineer" else "renderer_benchmark", "params": {}}
role_client.post("/api/tasks", payload)
except ApiError as exc:
if exc.status != 403:
raise
else:
raise AcceptanceError(f"{role} unexpectedly created a forbidden task")
run.report["identities"] = records
for record in records.values():
run.client.request("DELETE", f"/api/users/{record['id']}")
def build_playroom_archive(source: Path, build_id: str) -> tuple[Path, int, str]:
images = sorted(path for path in source.rglob("*") if path.is_file() and path.suffix.lower() in {".jpg", ".jpeg", ".png", ".webp"})
if len(images) < 225:
raise AcceptanceError(f"Playroom source has {len(images)} images; at least 225 are required")
target = Path(tempfile.gettempdir()) / f"real2sim-playroom-{build_id}.zip"
with zipfile.ZipFile(target, "w", compression=zipfile.ZIP_STORED, allowZip64=True) as archive:
for image in images:
archive.write(image, Path("playroom") / image.relative_to(source))
digest = hashlib.sha256()
with target.open("rb") as handle:
while chunk := handle.read(8 * 1024 * 1024):
digest.update(chunk)
return target, len(images), digest.hexdigest()
def upload_with_resume(run: AcceptanceRun, archive: Path, checksum: str) -> dict[str, Any]:
chunk_size = 8 * 1024 * 1024
created = run.client.post(
"/api/uploads",
{
"filename": archive.name,
"content_type": "application/zip",
"total_size": archive.stat().st_size,
"chunk_size": chunk_size,
"checksum": checksum,
},
)
upload_id = created["id"]
total_parts = int(created["total_parts"])
pause_after = max(1, total_parts // 2)
run.report["storage"] = {
**run.report.get("storage", {}),
"upload_id": upload_id,
"checksum": checksum,
"size_bytes": archive.stat().st_size,
"total_parts": total_parts,
"resume_checkpoint_part": pause_after,
"status": "uploading",
}
run.save()
with archive.open("rb") as handle:
for part in range(1, total_parts + 1):
body = handle.read(chunk_size)
run.client.request(
"PUT",
f"/api/uploads/{upload_id}/parts/{part}",
body=body,
content_type="application/octet-stream",
timeout=600,
)
print(f" uploaded part {part}/{total_parts}", flush=True)
if part == pause_after:
resumed = run.client.get(f"/api/uploads/{upload_id}")
expected = list(range(1, pause_after + 1))
run.check("BOS 上传分片状态可恢复", resumed.get("received_parts") == expected, resumed.get("received_parts"))
completed = run.client.post(f"/api/uploads/{upload_id}/complete")
dataset = completed["dataset"]
run.check("上传数据写入受控 BOS 前缀", str(dataset.get("storage_uri") or "").startswith("bos://testxyz/real2sim-poc/uploads/"), dataset.get("storage_uri"))
run.report["storage"] = {
**run.report.get("storage", {}),
"upload_id": upload_id,
"storage_uri": dataset.get("storage_uri"),
"checksum": checksum,
"size_bytes": archive.stat().st_size,
"total_parts": total_parts,
"resume_checkpoint_part": pause_after,
"status": "completed",
}
run.report["datasets"].append({"id": dataset["id"], "role": "playroom_upload", "storage_uri": dataset.get("storage_uri")})
return dataset
def validate_infrastructure(run: AcceptanceRun) -> None:
run.report["version"] = run.client.get("/api/version")
run.report["doctor"] = run.client.get("/api/doctor")
run.report["capabilities"] = run.client.get("/api/capabilities")
run.report["recipes"] = run.client.get("/api/recipes")
run.check("部署 build_id 与验收目标一致", run.report["version"].get("build_id") == run.build_id, run.report["version"].get("build_id"))
run.check("生产 API doctor 通过", bool(run.report["doctor"].get("ok")), run.report["doctor"])
run.check("A800 worker 心跳就绪", bool((run.report["doctor"].get("worker") or {}).get("ready")), run.report["doctor"].get("worker"))
runtimes = run.report["capabilities"].get("runtimes") or {}
for name in ("anysplat", "mujoco", "motrixsim", "discoverse_act", "rm65_controller"):
run.check(f"真实运行时就绪: {name}", bool((runtimes.get(name) or {}).get("ready")), runtimes.get(name))
bos = (run.report["capabilities"].get("storage") or {}).get("bos") or {}
run.check("BOS 前缀隔离", bos.get("prefix") == "real2sim-poc", bos)
def exercise_task_operations(run: AcceptanceRun, scene_id: str | None) -> None:
benchmark = run.create_task("renderer_benchmark", {})
retry = run.client.post(f"/api/tasks/{benchmark['id']}/retry")
retried = run.wait_task(retry["id"])
bulk = run.client.post("/api/tasks/bulk", {"action": "retry", "ids": [benchmark["id"], retried["id"]], "params": {}})
run.check("任务批量重试逐项返回", len(bulk.get("results") or []) == 2 and all(item.get("ok") for item in bulk["results"]), bulk)
for item in bulk["results"]:
run.wait_task(item["result"]["id"], timeout_seconds=300)
if not scene_id:
run.report["warnings"].append("RM65 scene unavailable; cancellation and restart-recovery probes were skipped")
return
cancel_probe = run.client.post(
"/api/tasks",
{
"type": "expert_collection",
"params": {
"scene_id": scene_id,
"policy_preset": "rm65_pick_place_6d_ik",
"episodes": 50,
"max_attempts": 150,
"steps": 240,
"name": "acceptance-cancel-probe",
},
},
)
wait_until_status(run.client, cancel_probe["id"], "running", 300)
run.client.post(f"/api/tasks/{cancel_probe['id']}/cancel")
run.wait_task(cancel_probe["id"], expected_status="canceled", timeout_seconds=300)
recovery_probe = run.client.post(
"/api/tasks",
{
"type": "expert_collection",
"params": {
"scene_id": scene_id,
"policy_preset": "rm65_pick_place_6d_ik",
"episodes": 50,
"max_attempts": 150,
"steps": 240,
"name": "acceptance-recovery-probe",
},
},
)
wait_until_status(run.client, recovery_probe["id"], "running", 300)
kubectl(run.kubeconfig, "-n", NAMESPACE, "rollout", "restart", "deployment/real2sim-worker")
kubectl(run.kubeconfig, "-n", NAMESPACE, "rollout", "status", "deployment/real2sim-worker", "--timeout=3600s", timeout=3700)
run.wait_task(recovery_probe["id"], expected_status="failed_recovered", timeout_seconds=600)
run.check("worker 重启后历史任务仍可查询", run.client.get(f"/api/tasks/{benchmark['id']}").get("id") == benchmark["id"])
def wait_until_status(client: ApiClient, task_id: str, status: str, timeout_seconds: int) -> dict[str, Any]:
deadline = time.time() + timeout_seconds
while time.time() < deadline:
task = client.get(f"/api/tasks/{task_id}")
if task.get("status") == status:
return task
if task.get("status") in TERMINAL:
raise AcceptanceError(f"task {task_id} reached {task.get('status')} before {status}")
time.sleep(2)
raise AcceptanceError(f"task {task_id} did not reach {status} within {timeout_seconds}s")
def resume_reconstruction_evidence(run: AcceptanceRun, report_path: Path) -> tuple[str, list[str]]:
if not report_path.is_file():
raise AcceptanceError(f"resume report not found: {report_path}")
previous = json.loads(report_path.read_text(encoding="utf-8"))
if previous.get("schema") != "real2sim.poc_acceptance_report.v1":
raise AcceptanceError(f"unsupported resume report schema: {previous.get('schema')}")
source_build_id = str(previous.get("build_id") or "")
if not source_build_id:
raise AcceptanceError("resume report does not identify its source build")
prepared = next((item for item in previous.get("datasets", []) if item.get("role") == "playroom_prepared"), None)
scenes = [item for item in previous.get("scenes", []) if str(item.get("role") or "").startswith("playroom_reconstruction_")]
tasks = list(previous.get("tasks", []))
by_type: dict[str, list[dict[str, Any]]] = {}
for task in tasks:
by_type.setdefault(str(task.get("type") or ""), []).append(task)
if not prepared or len(scenes) != 2:
raise AcceptanceError("resume report does not contain one prepared Playroom dataset and two reconstruction scenes")
required_counts = {"media_prepare": 1, "reconstruction_preflight": 1, "scene_reconstruction": 2, "simulator_validation": 2}
for task_type, count in required_counts.items():
if len(by_type.get(task_type, [])) < count:
raise AcceptanceError(f"resume report has only {len(by_type.get(task_type, []))} {task_type} task(s); expected {count}")
artifact_requirements = {
"media_prepare": ("prepared_manifest.json",),
"reconstruction_preflight": ("capture_preflight_report.json",),
"scene_reconstruction": (
"environment.json",
"reconstruction_command.json",
"capture_preflight_report.json",
"reconstruction_report.json",
"scene_manifest.json",
),
"simulator_validation": ("validation_report.json",),
}
for task_type, count in required_counts.items():
for task in by_type[task_type][:count]:
run.wait_task(str(task["id"]), required_artifacts=artifact_requirements[task_type])
prepared_id = str(prepared["id"])
prepared_manifest = run.client.get(f"/api/datasets/{prepared_id}/manifest")
run.check("恢复数据集仍有至少 80 帧", int(prepared_manifest.get("frame_count") or 0) >= 80, prepared_manifest.get("frame_count"))
scene_ids = [str(item["id"]) for item in scenes]
for scene_id in scene_ids:
manifest = run.client.get(f"/api/scenes/{scene_id}/manifest")
names = {str(asset.get("name") or "") for asset in manifest.get("assets", []) if isinstance(asset, dict)}
run.check(f"恢复场景 {scene_id[:8]} 仍有 3D 与仿真资产", bool({"scene.ply", "pose_init_trained_scene.ply"} & names) and "scene.xml" in names, sorted(names)[:20])
run.check("恢复的两次重建场景相互独立", len(set(scene_ids)) == 2, scene_ids)
run.report["datasets"] = [item for item in previous.get("datasets", []) if item.get("role") in {"playroom_upload", "playroom_prepared"}]
run.report["scenes"] = scenes
run.report["storage"] = dict(previous.get("storage") or {})
run.report["resumed_evidence"] = {
"report": str(report_path.resolve()),
"source_build_id": source_build_id,
"target_build_id": run.build_id,
"cross_build": source_build_id != run.build_id,
"reaudited_task_ids": [
str(task["id"])
for task_type, count in required_counts.items()
for task in by_type[task_type][:count]
],
"prepared_dataset_id": prepared_id,
"scene_ids": scene_ids,
}
run.save()
return prepared_id, scene_ids
def run_acceptance(args: argparse.Namespace) -> int:
build_id = args.build_id or kubectl(
args.kubeconfig,
"-n",
NAMESPACE,
"get",
"deployment/real2sim-api",
"-o",
"jsonpath={.metadata.labels.app\\.kubernetes\\.io/version}",
).stdout.strip()
if not build_id:
raise AcceptanceError("unable to determine deployed build id")
out_dir = args.out or ROOT / "acceptance_runs" / "poc" / build_id
out_dir.mkdir(parents=True, exist_ok=True)
port = args.port or free_port()
forward = start_port_forward(args.kubeconfig, port, out_dir)
archive: Path | None = None
run = AcceptanceRun(
client=ApiClient(f"https://127.0.0.1:{port}"),
out_dir=out_dir,
kubeconfig=args.kubeconfig,
build_id=build_id,
timeout_seconds=args.timeout_seconds,
)
try:
if run.stage("管理员认证", lambda: authenticate_admin(run)) is None:
return finalize(run)
run.stage("运行时、存储与版本预检", lambda: validate_infrastructure(run))
run.stage("用户 CRUD 与角色隔离", lambda: verify_rbac(run))
reconstruction_scenes: list[str] = []
prepared_dataset_id: str | None = None
if args.resume_report:
resumed = run.stage("恢复并复核已通过的 Playroom 重建证据", lambda: resume_reconstruction_evidence(run, args.resume_report))
if resumed:
prepared_dataset_id, reconstruction_scenes = resumed
else:
uploaded_dataset: dict[str, Any] | None = None
playroom = run.stage("打包真实 Playroom 225 帧", lambda: build_playroom_archive(args.playroom, build_id))
if playroom:
archive, image_count, checksum = playroom
run.report["storage"]["source_image_count"] = image_count
uploaded_dataset = run.stage("BOS 分片上传与断点续传", lambda: upload_with_resume(run, archive, checksum))
if uploaded_dataset:
prepared = run.stage(
"媒体准备 225 帧",
lambda: run.create_task(
"media_prepare",
{
"dataset_id": uploaded_dataset["id"],
"camera_label": "playroom.rgb",
"target_frame_count": 225,
"min_total_frames": 80,
"max_frames_per_video": 225,
"max_videos": 1,
"sample_fps": 2,
"output_name": f"playroom-prepared-{build_id}",
},
required_artifacts=("prepared_manifest.json",),
),
)
if prepared:
prepared_dataset_id = str(prepared["result"]["dataset_id"])
run.report["datasets"].append({"id": prepared_dataset_id, "role": "playroom_prepared", "frame_count": prepared["result"].get("frame_count")})
run.stage(
"Playroom 重建质量预检",
lambda: run.create_task(
"reconstruction_preflight",
{"dataset_id": prepared_dataset_id, "min_frames": 80, "target_frame_count": 225, "allow_low_quality": False, "quality_preset": "capture-high"},
required_artifacts=("capture_preflight_report.json",),
),
)
if prepared_dataset_id:
for index in range(1, 3):
reconstructed = run.stage(
f"Playroom AnySplat 真实重建 #{index}",
lambda index=index: run.create_task(
"scene_reconstruction",
{
"dataset_id": prepared_dataset_id,
"scene_name": f"Playroom A800 Reconstruction {index}",
"renderer": "spark",
"simulators": ["mujoco", "motrixsim"],
"dry_run": False,
"preflight_required": True,
"min_frames": 80,
"allow_low_quality": False,
"quality_preset": "capture-high",
"pose_init_train": True,
"sfm_matcher": "exhaustive",
"sfm_guided_matching": True,
"sfm_frames": "selected",
"anysplat_keyframe_strategy": "sfm-registered",
"auto_cover": True,
},
required_artifacts=(
"environment.json",
"reconstruction_command.json",
"capture_preflight_report.json",
"reconstruction_report.json",
"scene_manifest.json",
),
),
)
if reconstructed:
scene_id = str(reconstructed["result"]["scene_id"])
reconstruction_scenes.append(scene_id)
run.report["scenes"].append({"id": scene_id, "role": f"playroom_reconstruction_{index}"})
run.stage(
f"Playroom 重建仿真双运行时校验 #{index}",
lambda scene_id=scene_id: run.create_task(
"simulator_validation",
{"scene_id": scene_id, "simulators": ["mujoco", "motrixsim"], "level": "runtime_required"},
required_artifacts=("validation_report.json",),
),
)
if len(reconstruction_scenes) == 2:
run.stage(
"两次重建产生独立场景包",
lambda: run.check("重建 scene_id 独立", len(set(reconstruction_scenes)) == 2, reconstruction_scenes),
)
motrix_task = run.stage(
"MotrixSim 官方客厅与 RM65 资产导入",
lambda: run.create_task(
"motrixsim_asset_import",
{"source": "/opt/motrixsim-docs", "validation_steps": 120, "max_parlour_meshes": 240},
required_artifacts=("motrixsim_asset_import_report.json", "rm65_table_pick_place_validation.json", "motrixsim_parlour_rm65_preview.glb"),
),
)
rm65_scene_id = str(motrix_task["result"]["scene_id"]) if motrix_task else None
if rm65_scene_id:
run.report["scenes"].append({"id": rm65_scene_id, "role": "rm65_pick_place"})
run.stage(
"RM65 场景 runtime_required 校验",
lambda: run.create_task(
"simulator_validation",
{"scene_id": rm65_scene_id, "simulators": ["mujoco", "motrixsim"], "level": "runtime_required"},
required_artifacts=("validation_report.json",),
),
)
collection = None
if rm65_scene_id:
collection = run.stage(
"RM65 真实物理专家采集 50 条成功 episode",
lambda: run.create_task(
"expert_collection",
{
"scene_id": rm65_scene_id,
"policy_preset": "rm65_pick_place_6d_ik",
"episodes": 50,
"max_attempts": 150,
"steps": 240,
"workers": 1,
"seed": 7,
"image_width": 320,
"image_height": 240,
"name": f"RM65 Physical ACT Dataset {build_id}",
},
required_artifacts=("manifest.json", "episode_0.hdf5", "episode_0.mp4"),
),
)
collection_dataset_id = str(collection["result"]["dataset_id"]) if collection else None
if collection_dataset_id:
run.report["datasets"].append({"id": collection_dataset_id, "role": "rm65_physical_collection", "samples": collection["result"].get("samples")})
run.stage("采集成功数门槛", lambda: run.check("成功 episode 至少 50", int(collection["result"].get("samples") or 0) >= 50, collection["result"]))
trained = None
if collection_dataset_id:
trained = run.stage(
"DISCOVERSE ACT 真实训练",
lambda: run.create_task(
"training",
{
"dataset_id": collection_dataset_id,
"recipe": "discoverse_act",
"epochs": args.act_epochs,
"batch_size": 8,
"chunk_size": 32,
"seed": 1,
"name": f"RM65 ACT {build_id}",
},
required_artifacts=("policy_best.ckpt", "dataset_stats.pkl", "model_card.json", "task_config.py"),
),
)
model_id = str(trained["result"]["model_id"]) if trained else None
if model_id:
run.report["models"].append({"id": model_id, "role": "discoverse_act", "metrics": trained["result"].get("metrics")})
if model_id and rm65_scene_id:
inference = run.stage(
"DISCOVERSE ACT 在线推理 10 回合",
lambda: run.create_task(
"inference",
{
"model_id": model_id,
"scene_id": rm65_scene_id,
"recipe": "discoverse_act",
"episodes": 10,
"steps": 240,
"workers": 1,
"seed": 11,
"minimum_success_rate": 0.5,
},
required_artifacts=("inference_report.json", "episode_000.mp4", "episode_000_trajectory.json"),
),
)
if inference:
run.stage("ACT 推理成功率门槛", lambda: run.check("推理成功率至少 50%", float(inference["result"].get("success_rate") or 0) >= 0.5, inference["result"]))
run.stage("任务取消、重试、批量操作与重启恢复", lambda: exercise_task_operations(run, rm65_scene_id))
return finalize(run)
finally:
if archive and archive.exists():
archive.unlink()
forward.terminate()
try:
forward.wait(timeout=10)
except subprocess.TimeoutExpired:
forward.kill()
def finalize(run: AcceptanceRun) -> int:
run.report["finished_at"] = utc_now()
run.report["pass"] = not run.report["failures"] and all(item.get("ok") for item in run.report["checks"])
run.save()
print(f"\nacceptance_report={run.out_dir / 'acceptance_report.json'}", flush=True)
print(f"pass={run.report['pass']}", flush=True)
return 0 if run.report["pass"] else 1
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Run the real Real2Sim production acceptance against the isolated POC namespace.")
parser.add_argument("--kubeconfig", type=Path, default=Path(os.environ.get("REAL2SIM_POC_KUBECONFIG", DEFAULT_KUBECONFIG)))
parser.add_argument("--playroom", type=Path, default=Path(os.environ.get("REAL2SIM_POC_PLAYROOM", DEFAULT_PLAYROOM)))
parser.add_argument("--build-id", default=os.environ.get("REAL2SIM_POC_BUILD_ID", ""))
parser.add_argument("--out", type=Path, default=Path(os.environ["REAL2SIM_POC_ACCEPTANCE_OUT"]) if os.environ.get("REAL2SIM_POC_ACCEPTANCE_OUT") else None)
parser.add_argument("--resume-report", type=Path, default=Path(os.environ["REAL2SIM_POC_RESUME_REPORT"]) if os.environ.get("REAL2SIM_POC_RESUME_REPORT") else None)
parser.add_argument("--port", type=int, default=0)
parser.add_argument("--timeout-seconds", type=int, default=int(os.environ.get("REAL2SIM_POC_ACCEPTANCE_TIMEOUT_SECONDS", "28800")))
parser.add_argument("--act-epochs", type=int, default=int(os.environ.get("REAL2SIM_POC_ACT_EPOCHS", "500")))
return parser.parse_args()
if __name__ == "__main__":
try:
raise SystemExit(run_acceptance(parse_args()))
except KeyboardInterrupt:
raise SystemExit(130)
except Exception as exc:
print(f"acceptance bootstrap failed: {type(exc).__name__}: {exc}", file=sys.stderr)
raise SystemExit(2)

View File

@ -0,0 +1,277 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import hashlib
import os
import time
from pathlib import Path
from typing import Any
from acceptance_poc_cluster import (
DEFAULT_KUBECONFIG,
NAMESPACE,
AcceptanceError,
AcceptanceRun,
ApiClient,
authenticate_admin,
finalize,
free_port,
kubectl,
start_port_forward,
upload_with_resume,
)
ROOT = Path(__file__).resolve().parents[1]
DEFAULT_BUNDLE = Path("/Users/d-robotics/Downloads/demo_2.zip")
def sha256_file(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
while chunk := handle.read(8 * 1024 * 1024):
digest.update(chunk)
return digest.hexdigest()
def dataset_for_checksum(run: AcceptanceRun, checksum: str) -> dict[str, Any] | None:
for dataset in run.client.get("/api/datasets"):
if str(dataset.get("checksum") or "").lower() == checksum.lower():
return dataset
return None
def verify_spatial_dataset(run: AcceptanceRun, dataset: dict[str, Any], expected_checksum: str) -> None:
scan = dataset.get("scan") or {}
run.check("空间包 SHA-256 与原文件一致", dataset.get("checksum") == expected_checksum, dataset.get("checksum"))
run.check("识别为 MotrixSim 空间包", scan.get("input_kind") == "motrixsim_spatial_bundle", scan)
run.check("USDZ 碰撞、视觉和 3DGS 三层完整", bool(scan.get("spatial_bundle_ready")), scan)
run.check("原始空间包已持久化到受控 BOS 前缀", str(dataset.get("storage_uri") or "").startswith("bos://testxyz/real2sim-poc/uploads/"), dataset.get("storage_uri"))
def import_scene(run: AcceptanceRun, dataset_id: str) -> dict[str, Any]:
created = run.client.post(f"/api/datasets/{dataset_id}/import-motrixsim")
task = run.wait_task(
created["id"],
required_artifacts=(
"scene_manifest.json",
"motrixsim_scene_import_report.json",
"runtime_validation.json",
"scene.xml",
"environment_visual.glb",
"full_res.spz",
),
timeout_seconds=7200,
)
result = task.get("result") or {}
runtime = result.get("runtime_validation") or {}
run.check("MuJoCo 真实加载并步进导入场景", bool((runtime.get("mujoco") or {}).get("ok")), runtime)
run.check("MotrixSim 真实加载并步进导入场景", bool((runtime.get("motrixsim") or {}).get("ok")), runtime)
scene_id = str(result.get("scene_id") or "")
run.check("空间包已登记为平台场景", bool(scene_id), result)
manifest = run.client.get(f"/api/scenes/{scene_id}/manifest")
formats = {str(item.get("format") or "").lower() for item in manifest.get("assets", [])}
names = {str(item.get("name") or "") for item in manifest.get("assets", [])}
run.check("场景保留 SPZ 高保真外观层", "spz" in formats or "full_res.spz" in names, sorted(names))
run.check("场景生成可交互 GLB 回退预览", "glb" in formats or "environment_visual.glb" in names, sorted(names))
run.report["scenes"].append({"id": scene_id, "role": "spatial_bundle_import", "manifest": manifest})
return {"scene_id": scene_id, "manifest": manifest, "task": task}
def add_asset_revision(
run: AcceptanceRun,
*,
scene_id: str,
primitive: str,
name: str,
translation: list[float],
dimensions: list[float],
dynamic: bool,
) -> dict[str, Any]:
created = run.client.post(
f"/api/scenes/{scene_id}/assets",
{
"source": {"type": "primitive"},
"primitive": primitive,
"name": name,
"transform": {
"translation": translation,
"rotation_euler_degrees": [0.0, 0.0, 0.0],
"scale": [1.0, 1.0, 1.0],
},
"physics": {
"dynamic": dynamic,
"mass": 0.35 if dynamic else 1.0,
"collision_mode": "visual_and_collision",
"dimensions": dimensions,
"friction": [0.8, 0.01, 0.001],
"rgba": [0.12, 0.78, 0.68, 1.0],
},
"validation_steps": 120,
"revision_name": f"空间场景 · {name}",
},
)
task_id = str((created.get("task") or {}).get("id") or "")
run.check(f"{name} 合成任务已创建", bool(task_id), created)
task = run.wait_task(
task_id,
required_artifacts=("scene_manifest.json", "scene.xml"),
timeout_seconds=7200,
)
result = task.get("result") or {}
runtime = result.get("runtime_validation") or {}
run.check(f"{name} 修订通过 MuJoCo", bool((runtime.get("mujoco") or {}).get("ok")), runtime)
run.check(f"{name} 修订通过 MotrixSim", bool((runtime.get("motrixsim") or {}).get("ok")), runtime)
if dynamic:
run.check(f"{name} 在 MotrixSim 中具有真实自由关节", int((runtime.get("motrixsim") or {}).get("nq") or 0) >= 7, runtime)
revision_id = str(result.get("scene_id") or "")
run.check(f"{name} 生成独立场景版本", bool(revision_id) and revision_id != scene_id, result)
run.check(
f"{name} 使用修订包内独立运行时文件",
"/scene_asset_compose/" in str(result.get("scene_path") or ""),
result.get("scene_path"),
)
manifest = run.client.get(f"/api/scenes/{revision_id}/manifest")
added = [item for item in manifest.get("assets", []) if item.get("role") == "added_asset"]
run.check(f"{name} 已写入场景清单", any(item.get("name") == name for item in added), added)
run.report["scenes"].append(
{
"id": revision_id,
"role": f"asset_revision_{primitive}",
"parent_scene_id": scene_id,
"added_assets": [item.get("name") for item in added],
"runtime_validation": runtime,
}
)
return {"scene_id": revision_id, "manifest": manifest, "task": task}
def run_acceptance(args: argparse.Namespace) -> int:
bundle = args.bundle.expanduser().resolve()
if not bundle.is_file():
raise AcceptanceError(f"spatial bundle does not exist: {bundle}")
checksum = sha256_file(bundle)
build_id = args.build_id or kubectl(
args.kubeconfig,
"-n",
NAMESPACE,
"get",
"deployment/real2sim-api",
"-o",
"jsonpath={.metadata.labels.app\\.kubernetes\\.io/version}",
).stdout.strip()
if not build_id:
raise AcceptanceError("unable to determine deployed build id")
timestamp = time.strftime("%Y%m%d-%H%M%S")
out_dir = args.out or ROOT / "acceptance_runs" / "poc" / f"{build_id}-spatial-{timestamp}"
out_dir.mkdir(parents=True, exist_ok=True)
port = args.port or free_port()
forward = start_port_forward(args.kubeconfig, port, out_dir)
run = AcceptanceRun(
client=ApiClient(f"https://127.0.0.1:{port}"),
out_dir=out_dir,
kubeconfig=args.kubeconfig,
build_id=build_id,
timeout_seconds=args.timeout_seconds,
)
run.report["schema"] = "real2sim.spatial_bundle_acceptance.v1"
run.report["source"] = {
"path": str(bundle),
"filename": bundle.name,
"size_bytes": bundle.stat().st_size,
"sha256": checksum,
}
try:
if run.stage("管理员认证", lambda: authenticate_admin(run)) is None:
return finalize(run)
version = run.client.get("/api/version")
doctor = run.client.get("/api/doctor")
run.report["version"] = version
run.report["doctor"] = doctor
run.check("部署版本与验收目标一致", version.get("build_id") == build_id, version)
run.check("生产运行时 doctor 通过", bool(doctor.get("ok")), doctor)
dataset = dataset_for_checksum(run, checksum) if args.reuse else None
if dataset is None:
dataset = run.stage("真实空间包分片上传", lambda: upload_with_resume(run, bundle, checksum))
else:
run.report["warnings"].append(f"Reused dataset {dataset['id']} with identical SHA-256.")
if dataset is None:
return finalize(run)
verify_spatial_dataset(run, dataset, checksum)
imported = run.stage("USDZ/SPZ 转 MotrixSim 场景", lambda: import_scene(run, dataset["id"]))
if not imported:
return finalize(run)
cube = run.stage(
"添加动态抓取方块并生成修订",
lambda: add_asset_revision(
run,
scene_id=imported["scene_id"],
primitive="box",
name="动态抓取方块",
translation=[0.0, 0.0, 1.0],
dimensions=[0.6, 0.6, 0.6],
dynamic=True,
),
)
if not cube:
return finalize(run)
marker = run.stage(
"添加静态目标圆柱并保留上一资产",
lambda: add_asset_revision(
run,
scene_id=cube["scene_id"],
primitive="cylinder",
name="静态放置目标",
translation=[1.2, 0.0, 0.6],
dimensions=[0.8, 0.8, 1.2],
dynamic=False,
),
)
if marker:
added_names = {
str(item.get("name") or "")
for item in marker["manifest"].get("assets", [])
if item.get("role") == "added_asset"
}
run.check("连续场景修订保留全部数字资产", {"动态抓取方块", "静态放置目标"}.issubset(added_names), sorted(added_names))
parent_after = run.client.get(f"/api/scenes/{imported['scene_id']}/manifest")
parent_added = [item.get("name") for item in parent_after.get("assets", []) if item.get("role") == "added_asset"]
first_after = run.client.get(f"/api/scenes/{cube['scene_id']}/manifest")
first_added = [item.get("name") for item in first_after.get("assets", []) if item.get("role") == "added_asset"]
run.check("父场景未被资产修订污染", not parent_added, parent_added)
run.check("第一版修订只包含首个新增资产", first_added == ["动态抓取方块"], first_added)
run.report["browser"]["target_scene_id"] = marker["scene_id"]
run.report["browser"]["viewer_url"] = f"/static/scene-viewer.html?scene_id={marker['scene_id']}"
return finalize(run)
finally:
forward.terminate()
try:
forward.wait(timeout=10)
except Exception:
forward.kill()
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Import a real USDZ/SPZ spatial bundle, validate MotrixSim, and compose digital assets in the isolated POC namespace.")
parser.add_argument("--bundle", type=Path, default=Path(os.environ.get("REAL2SIM_SPATIAL_BUNDLE", DEFAULT_BUNDLE)))
parser.add_argument("--kubeconfig", type=Path, default=Path(os.environ.get("REAL2SIM_POC_KUBECONFIG", DEFAULT_KUBECONFIG)))
parser.add_argument("--build-id", default=os.environ.get("REAL2SIM_POC_BUILD_ID", ""))
parser.add_argument("--out", type=Path)
parser.add_argument("--port", type=int, default=0)
parser.add_argument("--timeout-seconds", type=int, default=7200)
parser.add_argument("--no-reuse", dest="reuse", action="store_false")
parser.set_defaults(reuse=True)
return parser.parse_args()
if __name__ == "__main__":
try:
raise SystemExit(run_acceptance(parse_args()))
except KeyboardInterrupt:
raise SystemExit(130)
except Exception as exc:
print(f"spatial bundle acceptance failed: {type(exc).__name__}: {exc}", flush=True)
raise SystemExit(2)

74
scripts/acceptance_wuying.sh Executable file
View File

@ -0,0 +1,74 @@
#!/usr/bin/env bash
set -euo pipefail
KEY="${REAL2SIM_WUYING_KEY:-/Users/d-robotics/workSpace/document/80-private/orgs/drobotics/keys/wuying-39.106.101.95_ed25519}"
HOST="${REAL2SIM_WUYING_HOST:-root@39.106.101.95}"
FIXTURE="${REAL2SIM_ACCEPTANCE_FIXTURE:-/opt/real2sim_paper_runtime/sam-3d-objects/notebook/images/shutterstock_modern_colorful_Interior_2620125197}"
MIN_FRAMES="${REAL2SIM_ACCEPTANCE_MIN_FRAMES:-30}"
TIMEOUT_SECONDS="${REAL2SIM_ACCEPTANCE_TIMEOUT_SECONDS:-3600}"
ssh -i "$KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new "$HOST" \
"REAL2SIM_ACCEPTANCE_FIXTURE='$FIXTURE' REAL2SIM_ACCEPTANCE_MIN_FRAMES='$MIN_FRAMES' REAL2SIM_ACCEPTANCE_TIMEOUT_SECONDS='$TIMEOUT_SECONDS' python3 - <<'PY'
import json
import os
import time
import urllib.error
import urllib.request
BASE = 'http://127.0.0.1:18126'
FIXTURE = os.environ['REAL2SIM_ACCEPTANCE_FIXTURE']
MIN_FRAMES = int(os.environ['REAL2SIM_ACCEPTANCE_MIN_FRAMES'])
TIMEOUT = int(os.environ['REAL2SIM_ACCEPTANCE_TIMEOUT_SECONDS'])
def api(path, payload=None):
data = None
headers = {}
if payload is not None:
data = json.dumps(payload).encode('utf-8')
headers['Content-Type'] = 'application/json'
req = urllib.request.Request(BASE + path, data=data, headers=headers)
with urllib.request.urlopen(req, timeout=30) as response:
return json.loads(response.read().decode('utf-8'))
def create_task(task_type, params):
task = api('/api/tasks', {'type': task_type, 'params': params})
print(f'{task_type}: {task[\"id\"]}', flush=True)
return wait_task(task['id'])
def wait_task(task_id):
deadline = time.time() + TIMEOUT
while time.time() < deadline:
task = api(f'/api/tasks/{task_id}')
if task['status'] in {'succeeded', 'failed', 'canceled', 'failed_recovered'}:
print(json.dumps({'task_id': task_id, 'type': task['type'], 'status': task['status'], 'result': task.get('result'), 'error': task.get('error')}, ensure_ascii=False), flush=True)
return task
time.sleep(5)
raise SystemExit(f'timeout waiting for {task_id}')
doctor = api('/api/doctor')
version = api('/api/version')
print(json.dumps({'doctor_ok': doctor['ok'], 'warnings': doctor.get('warnings'), 'version': version.get('version'), 'build_id': version.get('build_id')}, ensure_ascii=False), flush=True)
preflight = create_task('reconstruction_preflight', {'input_path': FIXTURE, 'min_frames': MIN_FRAMES})
if not preflight.get('result', {}).get('ok'):
raise SystemExit('preflight failed; inspect reports for task ' + preflight['id'])
reconstruction = create_task('scene_reconstruction', {
'input_path': FIXTURE,
'dry_run': False,
'renderer': 'spark',
'simulators': ['mujoco', 'motrixsim'],
'min_frames': MIN_FRAMES,
'quality_preset': 'capture-high',
})
if reconstruction['status'] != 'succeeded':
raise SystemExit('scene_reconstruction failed; inspect reports for task ' + reconstruction['id'])
scene_id = reconstruction['result']['scene_id']
validation = create_task('simulator_validation', {'scene_id': scene_id, 'simulators': ['mujoco', 'motrixsim'], 'level': 'runtime_if_available'})
print(json.dumps({'scene_id': scene_id, 'validation_task': validation['id'], 'validation_ok': validation.get('result', {}).get('ok')}, ensure_ascii=False), flush=True)
PY"

View File

@ -1,56 +0,0 @@
import { chromium } from 'playwright'
import { mkdir, copyFile, writeFile } from 'node:fs/promises'
import path from 'node:path'
const base = process.env.DEMO_URL || 'http://127.0.0.1:5173'
const health = await (await fetch(`${base}/api/health`)).json()
if (!health.demo || health.apiConfigured) throw new Error('Media capture requires isolated offline demo mode.')
const root = path.resolve('artifacts/media')
await mkdir(root, { recursive: true })
await mkdir('docs/images', { recursive: true })
const browser = await chromium.launch({ args: ['--enable-webgl', '--use-angle=swiftshader', '--enable-unsafe-swiftshader'] })
try {
const context = await browser.newContext({ viewport: { width: 1600, height: 900 }, recordVideo: { dir: root, size: { width: 1600, height: 900 } } })
const page = await context.newPage()
await page.addInitScript(() => localStorage.setItem('real2sim.locale', 'en'))
await page.goto(base)
await page.getByRole('button', { name: 'Load example', exact: true }).click()
await page.getByRole('heading', { name: 'Material & Simulation Export' }).waitFor()
await page.waitForTimeout(3000)
await page.screenshot({ path: 'docs/images/workbench.png' })
await page.getByRole('button', { name: 'Rotate model' }).click()
await page.waitForTimeout(8000)
await page.getByRole('button', { name: 'Rotate model' }).click()
const gravity = page.getByLabel('Gravity', { exact: true })
await gravity.focus()
await gravity.press('Home')
for (let i = 0; i < 37; i++) await gravity.press('ArrowRight')
await page.waitForTimeout(2000)
const downloadPromise = page.waitForEvent('download')
await page.getByRole('button', { name: 'Export Genesis Package', exact: true }).click()
await (await downloadPromise).saveAs(path.join(root, 'gravity-3.7-export.tar.gz'))
await page.screenshot({ path: path.join(root, 'settings.png') })
await page.waitForTimeout(3000)
const video = page.video()
await context.close()
await video.saveAs(path.join(root, 'workbench.webm'))
const mobile = await browser.newContext({ viewport: { width: 540, height: 960 }, recordVideo: { dir: root, size: { width: 540, height: 960 } } })
const phone = await mobile.newPage()
await phone.addInitScript(() => localStorage.setItem('real2sim.locale', 'zh'))
await phone.goto(base)
await phone.getByRole('button', { name: '加载样例', exact: true }).click()
await phone.waitForTimeout(3000)
await phone.getByRole('button', { name: 'Rotate model' }).click()
await phone.waitForTimeout(6000)
await phone.getByRole('button', { name: 'Rotate model' }).click()
await phone.getByLabel('重力', { exact: true }).scrollIntoViewIfNeeded()
await phone.waitForTimeout(5000)
const mobileVideo = phone.video()
await mobile.close()
await mobileVideo.saveAs(path.join(root, 'mobile.webm'))
await copyFile('docs/images/workbench.png', path.join(root, 'workbench.png'))
await writeFile(path.join(root, 'capture.json'), JSON.stringify({ capturedAt: new Date().toISOString(), source: 'isolated local offline example', model: 'examples/soft-puck/model.glb', noPaidGeneration: true }, null, 2))
} finally {
await browser.close()
}

View File

@ -0,0 +1,202 @@
import fs from "node:fs/promises";
import { createReadStream } from "node:fs";
import path from "node:path";
import { createInterface } from "node:readline";
import { pathToFileURL } from "node:url";
const SH_C0 = 0.28209479177387814;
function parseArgs(argv) {
const args = {};
for (let index = 2; index < argv.length; index += 1) {
const item = argv[index];
if (!item.startsWith("--")) continue;
const key = item.slice(2);
const next = argv[index + 1];
if (!next || next.startsWith("--")) args[key] = true;
else {
args[key] = next;
index += 1;
}
}
return args;
}
async function ensureSparkImport(vendorRoot) {
const tmpRoot = path.join("/tmp", `real2sim-spark-node-${process.pid}`);
const threeRoot = path.join(tmpRoot, "node_modules", "three");
await fs.mkdir(path.join(threeRoot, "addons", "postprocessing"), { recursive: true });
await fs.writeFile(
path.join(threeRoot, "package.json"),
JSON.stringify({ name: "three", type: "module", main: "./three.module.js", exports: { ".": "./three.module.js", "./addons/*": "./addons/*" } }),
);
await fs.copyFile(path.join(vendorRoot, "three", "three.module.js"), path.join(threeRoot, "three.module.js"));
await fs.copyFile(path.join(vendorRoot, "three", "three.core.js"), path.join(threeRoot, "three.core.js"));
await fs.copyFile(path.join(vendorRoot, "three", "addons", "postprocessing", "Pass.js"), path.join(threeRoot, "addons", "postprocessing", "Pass.js"));
await fs.copyFile(path.join(vendorRoot, "spark.module.min.js"), path.join(tmpRoot, "spark.module.min.js"));
return import(pathToFileURL(path.join(tmpRoot, "spark.module.min.js")).href);
}
async function readPlyHeader(input) {
const handle = await fs.open(input, "r");
try {
const buffer = Buffer.alloc(4 * 1024 * 1024);
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
const text = buffer.subarray(0, bytesRead).toString("utf8");
const end = text.indexOf("end_header");
if (end < 0) throw new Error("PLY header exceeds 4 MiB or is missing end_header");
const lines = text.slice(0, end + "end_header".length).split(/\r?\n/);
let format = "";
let activeElement = "";
let numSplats = 0;
const properties = [];
for (const rawLine of lines) {
const parts = rawLine.trim().split(/\s+/);
if (parts[0] === "format") format = parts[1] || "";
if (parts[0] === "element") {
activeElement = parts[1] || "";
if (activeElement === "vertex") numSplats = Number(parts[2] || 0);
}
if (parts[0] === "property" && activeElement === "vertex") {
if (parts[1] === "list") throw new Error("list properties are not supported for Gaussian vertices");
properties.push(parts.at(-1));
}
}
if (!format || !numSplats || !properties.length) throw new Error("invalid Gaussian PLY header");
return { format, numSplats, properties };
} finally {
await handle.close();
}
}
function clamp01(value) {
return Math.max(0, Math.min(1, Number(value)));
}
function sigmoid(value) {
const number = Number(value);
if (number >= 0) return 1 / (1 + Math.exp(-number));
const exponential = Math.exp(number);
return exponential / (1 + exponential);
}
function normalizeQuaternion(w, x, y, z) {
const length = Math.hypot(w, x, y, z) || 1;
return [x / length, y / length, z / length, w / length];
}
async function convertAsciiPly(input, header, spark) {
const propertyIndex = new Map(header.properties.map((name, index) => [name, index]));
const required = ["x", "y", "z", "scale_0", "scale_1", "scale_2", "rot_0", "rot_1", "rot_2", "rot_3"];
const missing = required.filter((name) => !propertyIndex.has(name));
if (missing.length) throw new Error(`ASCII Gaussian PLY is missing properties: ${missing.join(", ")}`);
const hasShColor = ["f_dc_0", "f_dc_1", "f_dc_2"].every((name) => propertyIndex.has(name));
const hasRgbColor = ["red", "green", "blue"].every((name) => propertyIndex.has(name));
if (!hasShColor && !hasRgbColor) throw new Error("ASCII Gaussian PLY has neither f_dc_* nor RGB color properties");
const writer = new spark.SpzWriter({ numSplats: header.numSplats, shDegree: 0 });
const reader = createInterface({ input: createReadStream(input, { encoding: "utf8" }), crlfDelay: Infinity });
let headerComplete = false;
let written = 0;
for await (const rawLine of reader) {
const line = rawLine.trim();
if (!headerComplete) {
headerComplete = line === "end_header";
continue;
}
if (!line || written >= header.numSplats) continue;
const fields = line.split(/\s+/);
if (fields.length < header.properties.length) throw new Error(`vertex ${written} has ${fields.length} values; expected ${header.properties.length}`);
const value = (name) => Number(fields[propertyIndex.get(name)]);
const numbers = required.map(value);
if (numbers.some((number) => !Number.isFinite(number))) throw new Error(`vertex ${written} contains a non-finite required value`);
const [quatX, quatY, quatZ, quatW] = normalizeQuaternion(value("rot_0"), value("rot_1"), value("rot_2"), value("rot_3"));
writer.setCenter(written, value("x"), value("y"), value("z"));
writer.setScale(
written,
Math.max(Math.exp(Math.max(-20, Math.min(20, value("scale_0")))), 1e-6),
Math.max(Math.exp(Math.max(-20, Math.min(20, value("scale_1")))), 1e-6),
Math.max(Math.exp(Math.max(-20, Math.min(20, value("scale_2")))), 1e-6),
);
writer.setQuat(written, quatX, quatY, quatZ, quatW);
writer.setAlpha(written, propertyIndex.has("opacity") ? sigmoid(value("opacity")) : 1);
if (hasShColor) {
writer.setRgb(
written,
clamp01(0.5 + SH_C0 * value("f_dc_0")),
clamp01(0.5 + SH_C0 * value("f_dc_1")),
clamp01(0.5 + SH_C0 * value("f_dc_2")),
);
} else {
const divisor = Math.max(value("red"), value("green"), value("blue")) > 1 ? 255 : 1;
writer.setRgb(written, clamp01(value("red") / divisor), clamp01(value("green") / divisor), clamp01(value("blue") / divisor));
}
written += 1;
}
if (written !== header.numSplats) throw new Error(`ASCII Gaussian PLY declared ${header.numSplats} vertices but yielded ${written}`);
return { writer, numSplats: header.numSplats, written };
}
async function main() {
const args = parseArgs(process.argv);
const input = args.input;
const output = args.output;
const vendorRoot = args["vendor-root"];
const reportPath = args.report;
if (!input || !output || !vendorRoot || !reportPath) {
throw new Error("usage: node convert_3dgs_ply_to_spz.mjs --input scene.ply --output scene.spz --vendor-root static/vendor --report report.json");
}
const started = Date.now();
const spark = await ensureSparkImport(vendorRoot);
const header = await readPlyHeader(input);
let writer;
let numSplats;
let written;
if (header.format === "ascii") {
({ writer, numSplats, written } = await convertAsciiPly(input, header, spark));
} else {
if (header.format !== "binary_little_endian") throw new Error(`unsupported PLY format: ${header.format}`);
const fileBytes = new Uint8Array(await fs.readFile(input));
const reader = new spark.PlyReader({ fileBytes });
await reader.parseHeader();
await reader.parseData(() => {});
numSplats = Number(reader.numSplats || 0);
if (!numSplats) throw new Error("Spark PlyReader returned zero splats");
writer = new spark.SpzWriter({ numSplats, shDegree: 0 });
written = 0;
reader.parseSplats((index, x, y, z, scaleX, scaleY, scaleZ, quatX, quatY, quatZ, quatW, opacity, red, green, blue) => {
writer.setCenter(index, x, y, z);
writer.setScale(index, Math.max(scaleX, 1e-6), Math.max(scaleY, 1e-6), Math.max(scaleZ, 1e-6));
writer.setQuat(index, quatX, quatY, quatZ, quatW);
writer.setAlpha(index, clamp01(opacity ?? 1));
writer.setRgb(index, clamp01(red), clamp01(green), clamp01(blue));
written += 1;
});
}
const encoded = await writer.finalize();
await fs.mkdir(path.dirname(output), { recursive: true });
await fs.writeFile(output, encoded);
const inputStat = await fs.stat(input);
const outputStat = await fs.stat(output);
const report = {
schema: "real2sim.spz_export_report.v1",
input,
output,
splats: numSplats,
written_splats: written,
input_format: header.format,
input_size_bytes: inputStat.size,
output_size_bytes: outputStat.size,
compression_ratio: Number((outputStat.size / Math.max(inputStat.size, 1)).toFixed(4)),
elapsed_ms: Date.now() - started,
clipped_count: writer.clippedCount || 0,
};
await fs.writeFile(reportPath, `${JSON.stringify(report, null, 2)}\n`);
console.log(JSON.stringify(report));
}
main().catch((error) => {
console.error(error?.stack || error?.message || String(error));
process.exit(1);
});

281
scripts/deploy_poc_cluster.sh Executable file
View File

@ -0,0 +1,281 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
KUBECONFIG_PATH="${REAL2SIM_POC_KUBECONFIG:-/Users/d-robotics/Downloads/poc.config}"
NAMESPACE="real2sim-poc"
GPU_NODE="${REAL2SIM_POC_GPU_NODE:-192.168.80.136}"
REGISTRY="${REAL2SIM_POC_REGISTRY:-ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc}"
SOURCE_COMMIT="$(git -C "$ROOT" rev-parse --short=12 HEAD)"
BUILD_ID="${REAL2SIM_POC_BUILD_ID:-${SOURCE_COMMIT}-$(date -u +%Y%m%d%H%M%S)}"
OUT="${REAL2SIM_POC_ACCEPTANCE_OUT:-$ROOT/acceptance_runs/poc/$BUILD_ID}"
BUILD_IMAGES=1
DEPLOY_APP=1
ONLY_COMPONENT="all"
tls_dir=""
context_archive=""
rendered_manifest=""
trap 'rm -rf "${tls_dir:-}" "${context_archive:-}" "${rendered_manifest:-}"' EXIT
for arg in "$@"; do
case "$arg" in
--skip-build) BUILD_IMAGES=0 ;;
--build-only) DEPLOY_APP=0 ;;
--frontend-only) ONLY_COMPONENT="frontend" ;;
--api-only) ONLY_COMPONENT="api" ;;
--worker-only) ONLY_COMPONENT="worker" ;;
--help)
echo "usage: $0 [--skip-build] [--build-only] [--frontend-only|--api-only|--worker-only]"
exit 0
;;
*) echo "unknown argument: $arg" >&2; exit 2 ;;
esac
done
K=(kubectl --kubeconfig "$KUBECONFIG_PATH")
mkdir -p "$OUT"
require() { command -v "$1" >/dev/null || { echo "missing required command: $1" >&2; exit 1; }; }
for command in kubectl jq openssl tar git sed; do require "$command"; done
test -f "$KUBECONFIG_PATH" || { echo "kubeconfig not found: $KUBECONFIG_PATH" >&2; exit 1; }
test "$(git -C "$ROOT" branch --show-current)" = "feat/poc-cluster-productization" || {
echo "deployment is only allowed from feat/poc-cluster-productization" >&2
exit 1
}
gpu_capacity="$("${K[@]}" get node "$GPU_NODE" -o jsonpath='{.status.allocatable.nvidia\.com/gpu}')"
gpu_in_use="$("${K[@]}" get pods -A --field-selector "spec.nodeName=$GPU_NODE" -o json | jq '[.items[] | select(.status.phase=="Running" or .status.phase=="Pending") | ([.spec.containers[]?.resources.requests["nvidia.com/gpu"] // "0" | tonumber] | add // 0)] | add // 0')"
if (( gpu_capacity - gpu_in_use < 1 )); then
echo "A800 node has no free GPU: capacity=$gpu_capacity in_use=$gpu_in_use" >&2
exit 1
fi
printf 'gpu_capacity=%s\ngpu_in_use=%s\nbuild_id=%s\n' "$gpu_capacity" "$gpu_in_use" "$BUILD_ID" > "$OUT/deploy_preflight.txt"
"${K[@]}" apply -f "$ROOT/deploy/poc/bootstrap.yaml"
ensure_host_directory() {
local pod="real2sim-hostpath-bootstrap"
"${K[@]}" -n "$NAMESPACE" delete pod "$pod" --ignore-not-found --wait=true >/dev/null
cat <<YAML | "${K[@]}" apply -f - >/dev/null
apiVersion: v1
kind: Pod
metadata:
name: $pod
namespace: $NAMESPACE
labels:
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/component: storage-bootstrap
spec:
restartPolicy: Never
nodeSelector:
kubernetes.io/hostname: "$GPU_NODE"
containers:
- name: bootstrap
image: busybox:1.36
command: [sh, -eu, -c]
args:
- mkdir -p /host-var-lib/real2sim-poc && chmod 0770 /host-var-lib/real2sim-poc && chown 10001:10001 /host-var-lib/real2sim-poc
resources:
requests: {cpu: 20m, memory: 32Mi}
limits: {cpu: 100m, memory: 64Mi}
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
capabilities: {drop: [ALL], add: [CHOWN, FOWNER]}
volumeMounts:
- {name: host-var-lib, mountPath: /host-var-lib}
volumes:
- name: host-var-lib
hostPath: {path: /var/lib, type: Directory}
YAML
if ! "${K[@]}" -n "$NAMESPACE" wait --for=jsonpath='{.status.phase}'=Succeeded "pod/$pod" --timeout=180s; then
"${K[@]}" -n "$NAMESPACE" describe "pod/$pod" >&2 || true
exit 1
fi
"${K[@]}" -n "$NAMESPACE" delete pod "$pod" --wait=true >/dev/null
}
ensure_host_directory
clone_secret() {
local source_namespace="$1" source_name="$2" target_name="$3"
"${K[@]}" -n "$source_namespace" get secret "$source_name" -o json |
jq --arg ns "$NAMESPACE" --arg name "$target_name" '
del(.metadata.uid,.metadata.resourceVersion,.metadata.creationTimestamp,.metadata.managedFields,.metadata.ownerReferences) |
.metadata.namespace=$ns | .metadata.name=$name |
.metadata.labels={"app.kubernetes.io/part-of":"real2sim-poc"}' |
"${K[@]}" apply -f - >/dev/null
}
clone_secret droboticflow droboticflow-registry real2sim-registry
clone_secret droboticflow droboticflow-bos-workspace real2sim-bos
if ! "${K[@]}" -n "$NAMESPACE" get secret real2sim-app-secrets >/dev/null 2>&1; then
admin_password="$(openssl rand -base64 30 | tr -d '/+=' | cut -c1-28)Aa1!"
session_secret="$(openssl rand -hex 32)"
"${K[@]}" -n "$NAMESPACE" create secret generic real2sim-app-secrets \
--from-literal=bootstrap-admin-password="$admin_password" \
--from-literal=session-secret="$session_secret" \
--dry-run=client -o yaml |
"${K[@]}" label --local -f - app.kubernetes.io/part-of=real2sim-poc -o yaml |
"${K[@]}" apply -f - >/dev/null
fi
if ! "${K[@]}" -n "$NAMESPACE" get secret real2sim-tls >/dev/null 2>&1; then
tls_dir="$(mktemp -d)"
openssl req -x509 -newkey rsa:3072 -sha256 -nodes -days 365 \
-subj "/CN=real2sim-poc.local" \
-addext "subjectAltName=DNS:real2sim-poc.local,DNS:localhost,IP:127.0.0.1" \
-keyout "$tls_dir/tls.key" -out "$tls_dir/tls.crt" >/dev/null 2>&1
"${K[@]}" -n "$NAMESPACE" create secret tls real2sim-tls \
--key "$tls_dir/tls.key" --cert "$tls_dir/tls.crt" --dry-run=client -o yaml |
"${K[@]}" label --local -f - app.kubernetes.io/part-of=real2sim-poc -o yaml |
"${K[@]}" apply -f - >/dev/null
fi
"${K[@]}" -n "$NAMESPACE" get secret real2sim-app-secrets -o jsonpath='{.data.bootstrap-admin-password}' |
base64 --decode > "$OUT/bootstrap-admin-password.txt"
chmod 600 "$OUT/bootstrap-admin-password.txt"
printf 'admin\n' > "$OUT/bootstrap-admin-username.txt"
chmod 600 "$OUT/bootstrap-admin-username.txt"
prepare_context() {
context_archive="$(mktemp -t real2sim-poc-context.XXXXXX.tgz)"
tar -C "$ROOT" -czf "$context_archive" \
--exclude='.git' --exclude='.venv' --exclude='.pytest_cache' --exclude='workspace' \
--exclude='acceptance_runs' --exclude='qa' --exclude='docs' --exclude='tests' .
local loader="real2sim-context-${BUILD_ID//[^a-zA-Z0-9-]/-}"
loader="${loader:0:60}"
"${K[@]}" -n "$NAMESPACE" delete pod "$loader" --ignore-not-found --wait=true >/dev/null
"${K[@]}" -n "$NAMESPACE" run "$loader" \
--image=busybox:1.36 --restart=Never \
--labels="app.kubernetes.io/part-of=real2sim-poc,app.kubernetes.io/component=build-context" \
--overrides="$(jq -cn --arg node "$GPU_NODE" '{spec:{nodeSelector:{"kubernetes.io/hostname":$node},containers:[{name:"context-loader",image:"busybox:1.36",command:["sh","-c","sleep 3600"],resources:{requests:{cpu:"100m",memory:"64Mi"},limits:{cpu:"500m",memory:"256Mi"}},volumeMounts:[{name:"data",mountPath:"/data"}]}],volumes:[{name:"data",persistentVolumeClaim:{claimName:"real2sim-poc-data"}}]}}')" >/dev/null
"${K[@]}" -n "$NAMESPACE" wait --for=condition=Ready "pod/$loader" --timeout=180s
"${K[@]}" -n "$NAMESPACE" cp "$context_archive" "$loader:/tmp/context.tgz"
"${K[@]}" -n "$NAMESPACE" exec "$loader" -- sh -eu -c \
"mkdir -p '/data/build-context/$BUILD_ID' /data/workspace /data/cache /data/scratch; rm -rf '/data/build-context/$BUILD_ID/'*; tar -xzf /tmp/context.tgz -C '/data/build-context/$BUILD_ID'; chown -R 10001:10001 /data/workspace /data/cache /data/scratch; chmod 0770 /data/workspace /data/cache /data/scratch"
"${K[@]}" -n "$NAMESPACE" delete pod "$loader" --wait=true >/dev/null
}
build_image() {
local component="$1" dockerfile="$2" destination="$3"
local job="real2sim-build-${component}-${BUILD_ID//[^a-zA-Z0-9-]/-}"
job="${job:0:60}"
"${K[@]}" -n "$NAMESPACE" delete job "$job" --ignore-not-found --wait=true >/dev/null
cat <<YAML | "${K[@]}" apply -f - >/dev/null
apiVersion: batch/v1
kind: Job
metadata:
name: $job
namespace: $NAMESPACE
labels:
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/component: image-build
spec:
backoffLimit: 0
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app.kubernetes.io/part-of: real2sim-poc
app.kubernetes.io/component: image-build
spec:
restartPolicy: Never
nodeSelector:
kubernetes.io/hostname: "$GPU_NODE"
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:v1.23.2-debug
args:
- --context=dir:///data/build-context/$BUILD_ID
- --dockerfile=/data/build-context/$BUILD_ID/$dockerfile
- --destination=$destination
- --build-arg=BUILD_ID=$BUILD_ID
- --build-arg=SOURCE_COMMIT=$SOURCE_COMMIT
- --snapshot-mode=redo
- --use-new-run
- --cache=true
- --cache-repo=$REGISTRY/real2sim-build-cache
- --verbosity=info
resources:
requests: {cpu: "2", memory: 4Gi}
limits: {cpu: "16", memory: 32Gi}
volumeMounts:
- {name: data, mountPath: /data}
- {name: docker-config, mountPath: /kaniko/.docker, readOnly: true}
volumes:
- name: data
persistentVolumeClaim: {claimName: real2sim-poc-data}
- name: docker-config
secret:
secretName: real2sim-registry
items:
- {key: .dockerconfigjson, path: config.json}
YAML
local deadline=$((SECONDS + 7200))
local build_state="running"
while (( SECONDS < deadline )); do
local succeeded failed
succeeded="$("${K[@]}" -n "$NAMESPACE" get "job/$job" -o jsonpath='{.status.succeeded}' 2>/dev/null || true)"
failed="$("${K[@]}" -n "$NAMESPACE" get "job/$job" -o jsonpath='{.status.failed}' 2>/dev/null || true)"
if [[ "$succeeded" == "1" ]]; then
build_state="succeeded"
break
fi
if [[ -n "$failed" && "$failed" != "0" ]]; then
build_state="failed"
break
fi
sleep 5
done
if [[ "$build_state" != "succeeded" ]]; then
"${K[@]}" -n "$NAMESPACE" logs "job/$job" --all-containers=true > "$OUT/build-${component}.log" 2>&1 || true
"${K[@]}" -n "$NAMESPACE" describe "job/$job" > "$OUT/build-${component}-describe.txt" 2>&1 || true
echo "image build $component ended as $build_state; see $OUT/build-${component}.log" >&2
return 1
fi
"${K[@]}" -n "$NAMESPACE" logs "job/$job" --all-containers=true > "$OUT/build-${component}.log"
"${K[@]}" -n "$NAMESPACE" delete job "$job" --wait=true >/dev/null
}
FRONTEND_IMAGE="$REGISTRY/real2sim-frontend:$BUILD_ID"
API_IMAGE="$REGISTRY/real2sim-api:$BUILD_ID"
WORKER_IMAGE="$REGISTRY/real2sim-worker:$BUILD_ID"
printf '%s\n' "$FRONTEND_IMAGE" "$API_IMAGE" "$WORKER_IMAGE" > "$OUT/images.txt"
if [[ "$BUILD_IMAGES" == "1" ]]; then
prepare_context
[[ "$ONLY_COMPONENT" == "all" || "$ONLY_COMPONENT" == "frontend" ]] && build_image frontend docker/frontend.Dockerfile "$FRONTEND_IMAGE"
[[ "$ONLY_COMPONENT" == "all" || "$ONLY_COMPONENT" == "api" ]] && build_image api docker/api.Dockerfile "$API_IMAGE"
[[ "$ONLY_COMPONENT" == "all" || "$ONLY_COMPONENT" == "worker" ]] && build_image worker docker/worker.Dockerfile "$WORKER_IMAGE"
fi
if [[ "$DEPLOY_APP" == "1" ]]; then
if [[ "$ONLY_COMPONENT" == "all" ]]; then
rendered_manifest="$(mktemp -t real2sim-poc-manifest.XXXXXX.yaml)"
sed \
-e "s|__BUILD_ID__|$BUILD_ID|g" \
-e "s|__FRONTEND_IMAGE__|$FRONTEND_IMAGE|g" \
-e "s|__API_IMAGE__|$API_IMAGE|g" \
-e "s|__WORKER_IMAGE__|$WORKER_IMAGE|g" \
"$ROOT/deploy/poc/app-template.yaml" > "$rendered_manifest"
"${K[@]}" apply -f "$rendered_manifest"
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-api --timeout=600s
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-frontend --timeout=600s
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-worker --timeout=3600s
elif [[ "$ONLY_COMPONENT" == "frontend" ]]; then
"${K[@]}" -n "$NAMESPACE" set image deployment/real2sim-frontend "frontend=$FRONTEND_IMAGE"
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-frontend --timeout=600s
elif [[ "$ONLY_COMPONENT" == "api" ]]; then
"${K[@]}" -n "$NAMESPACE" set image deployment/real2sim-api "api=$API_IMAGE"
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-api --timeout=600s
elif [[ "$ONLY_COMPONENT" == "worker" ]]; then
"${K[@]}" -n "$NAMESPACE" set image deployment/real2sim-worker "worker=$WORKER_IMAGE" "runtime-gate=$WORKER_IMAGE"
"${K[@]}" -n "$NAMESPACE" rollout status deployment/real2sim-worker --timeout=3600s
fi
"${K[@]}" -n "$NAMESPACE" get pods,svc,pvc -l app.kubernetes.io/part-of=real2sim-poc -o wide > "$OUT/resources.txt"
"${K[@]}" -n "$NAMESPACE" get svc real2sim-frontend -o json > "$OUT/frontend-service.json"
fi
printf 'build_id=%s\nnamespace=%s\ncredentials=%s\n' "$BUILD_ID" "$NAMESPACE" "$OUT/bootstrap-admin-password.txt"

127
scripts/deploy_wuying.sh Executable file
View File

@ -0,0 +1,127 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PROJECT_ROOT="$(cd "$ROOT/.." && pwd)"
KEY="${REAL2SIM_WUYING_KEY:-/Users/d-robotics/workSpace/document/80-private/orgs/drobotics/keys/wuying-39.106.101.95_ed25519}"
HOST="${REAL2SIM_WUYING_HOST:-root@39.106.101.95}"
SSH_CONNECT_TIMEOUT="${REAL2SIM_SSH_CONNECT_TIMEOUT:-20}"
REMOTE_BASE="${REAL2SIM_REMOTE_BASE:-/opt/real2sim2model}"
REMOTE="$REMOTE_BASE/real2sim-platform"
SERVICE="real2sim-platform.service"
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
BUILD_ID="${REAL2SIM_PLATFORM_BUILD_ID:-$BUILD_TIME}"
RUNTIME_ROOT="${REAL2SIM_RUNTIME_ROOT:-/opt/real2sim_paper_runtime}"
ANYSPLAT_ROOT="${REAL2SIM_ANYSPLAT_ROOT:-$RUNTIME_ROOT/AnySplat}"
ANYSPLAT_PYTHON="${REAL2SIM_ANY_SPLAT_PYTHON:-$RUNTIME_ROOT/envs/anysplat/bin/python}"
CUDA_HOME_REMOTE="${CUDA_HOME_REMOTE:-/usr/local/cuda-12.1}"
RESTART=0
STATUS_ONLY=0
SETUP_DESKTOP=0
for arg in "$@"; do
case "$arg" in
--restart) RESTART=1 ;;
--status) STATUS_ONLY=1 ;;
--desktop-launcher) SETUP_DESKTOP=1 ;;
*) echo "unknown argument: $arg" >&2; exit 2 ;;
esac
done
ssh_opts=(-i "$KEY" -o BatchMode=yes -o ConnectTimeout="$SSH_CONNECT_TIMEOUT" -o ServerAliveInterval=10 -o ServerAliveCountMax=2 -o StrictHostKeyChecking=accept-new)
ssh_cmd=(ssh "${ssh_opts[@]}" "$HOST")
if [[ "$STATUS_ONLY" == "1" ]]; then
"${ssh_cmd[@]}" "systemctl status '$SERVICE' --no-pager || true; curl -fsS http://127.0.0.1:18126/api/health || true; echo; curl -fsS http://127.0.0.1:18126/api/doctor || true"
exit 0
fi
if [[ ! -f "$ROOT/src/real2sim_platform/static/vendor/spark.module.min.js" ]]; then
bash "$ROOT/scripts/vendor_spark.sh"
fi
if [[ ! -f "$ROOT/src/real2sim_platform/static/vendor/three/three.module.js" ]]; then
bash "$ROOT/scripts/vendor_three.sh"
fi
"${ssh_cmd[@]}" "mkdir -p '$REMOTE_BASE'"
rsync -az --delete \
--exclude '.git/' \
--exclude 'real2sim-platform/workspace/' \
--exclude 'real2sim-platform/.venv/' \
--exclude '.pytest_cache/' \
--exclude '__pycache__/' \
-e "ssh -i $KEY -o BatchMode=yes -o ConnectTimeout=$SSH_CONNECT_TIMEOUT -o ServerAliveInterval=10 -o ServerAliveCountMax=2 -o StrictHostKeyChecking=accept-new" \
"$PROJECT_ROOT/" "$HOST:$REMOTE_BASE/"
"${ssh_cmd[@]}" "cd '$REMOTE' && python3 -m venv .venv && .venv/bin/python -m pip install -q --upgrade pip && .venv/bin/python -m pip install -q -e ."
"${ssh_cmd[@]}" "cd '$REMOTE' && .venv/bin/python - <<'PY'
import importlib.util
required = ['huggingface_hub', 'pyarrow', 'PIL', 'imageio', 'cv2', 'mujoco']
missing = [name for name in required if importlib.util.find_spec(name) is None]
if missing:
raise SystemExit('missing runtime deps: ' + ', '.join(missing))
PY
command -v ffmpeg >/dev/null
test -f '$REMOTE/src/real2sim_platform/static/vendor/spark.module.min.js'
test -f '$REMOTE/src/real2sim_platform/static/vendor/three/three.module.js'
test -d '$ANYSPLAT_ROOT'
test -x '$ANYSPLAT_PYTHON'"
"${ssh_cmd[@]}" "cat > '$REMOTE/config.toml' <<'EOF'
app_root = \"$REMOTE\"
workspace_dir = \"$REMOTE/workspace\"
host = \"127.0.0.1\"
port = 18126
default_renderer = \"spark\"
real2sim2model_root = \"$REMOTE_BASE\"
expert_policy_root = \"$REMOTE_BASE/real2sim-expert-policy\"
training_root = \"$REMOTE_BASE/real2sim-policy-training\"
inference_root = \"$REMOTE_BASE/real2sim-policy-inference\"
discoverse_root = \"/opt/gs_playground_real2sim_48q/DISCOVERSE\"
gs_playground_root = \"/opt/gs_playground_real2sim_48q\"
images23dgs_root = \"/opt/images23dgs_app/src\"
colmap_binary = \"/usr/local/bin/colmap\"
gsplat_python = \"$ANYSPLAT_PYTHON\"
runtime_root = \"$RUNTIME_ROOT\"
anysplat_root = \"$ANYSPLAT_ROOT\"
anysplat_python = \"$ANYSPLAT_PYTHON\"
cuda_home = \"$CUDA_HOME_REMOTE\"
runtime_env_script = \"/opt/gs_playground_real2sim_48q/scripts/real2sim_wuying_paper_env.sh\"
allowed_path_roots = \"$REMOTE_BASE:$REMOTE/workspace:/opt/gs_playground_real2sim_48q:$RUNTIME_ROOT:$ANYSPLAT_ROOT:/tmp\"
EOF"
"${ssh_cmd[@]}" "cat > /etc/systemd/system/$SERVICE <<'EOF'
[Unit]
Description=Real2Sim Platform
After=network.target
[Service]
Type=simple
WorkingDirectory=$REMOTE
Environment=REAL2SIM_PLATFORM_CONFIG=$REMOTE/config.toml
Environment=REAL2SIM_PLATFORM_BUILD_TIME=$BUILD_TIME
Environment=REAL2SIM_PLATFORM_BUILD_ID=$BUILD_ID
Environment=MUJOCO_GL=egl
ExecStart=$REMOTE/.venv/bin/real2sim-platform
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable '$SERVICE' >/dev/null"
if [[ "$RESTART" == "1" ]]; then
"${ssh_cmd[@]}" "systemctl stop '$SERVICE' || true; port_pid=\$(ss -ltnp 2>/dev/null | sed -n 's/.*127\\.0\\.0\\.1:18126.*pid=\\([0-9][0-9]*\\).*/\\1/p' | head -1); if [ -n \"\$port_pid\" ]; then kill \"\$port_pid\" || true; fi; sleep 2; systemctl restart '$SERVICE'; sleep 2; systemctl status '$SERVICE' --no-pager --lines=20"
fi
if [[ "$SETUP_DESKTOP" == "1" ]]; then
"${ssh_cmd[@]}" "bash '$REMOTE/scripts/setup_wuying_desktop_launcher.sh' --local --project-root '$REMOTE' --service '$SERVICE' --port 18126"
fi
echo "deployed to $HOST:$REMOTE"
echo "service: $SERVICE"
echo "health: ssh -i $KEY -L 18126:127.0.0.1:18126 $HOST"
echo "restart: bash scripts/deploy_wuying.sh --restart"
echo "desktop launcher: bash scripts/deploy_wuying.sh --restart --desktop-launcher"

View File

@ -1,18 +0,0 @@
import { join } from 'node:path'
import dotenv from 'dotenv'
export function loadDevEnvironment(root, demo, inherited = process.env) {
const env = { ...inherited }
if (demo) {
env.REAL2SIM_DEMO = '1'
env.REAL2SIM_DATA_ROOT = join(root, '.data/demo')
delete env.DASHSCOPE_API_KEY
delete env.REAL2SIM_ASSET_ROOT
delete env.REAL2SIM_GENESIS_PACKAGE_ROOT
} else {
// Load once before spawning so Vite and the API share the same overrides.
dotenv.config({ path: join(root, '.env.local'), processEnv: env, quiet: true })
dotenv.config({ path: join(root, '.env'), processEnv: env, quiet: true })
}
return env
}

View File

@ -1,48 +0,0 @@
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, expect, test } from 'vitest'
import { loadDevEnvironment } from './dev-env.mjs'
const roots = []
afterEach(async () => {
for (const root of roots.splice(0)) await rm(root, { recursive: true, force: true })
})
async function fixture() {
const root = await mkdtemp(join(tmpdir(), 'real2sim-dev-env-'))
roots.push(root)
await writeFile(join(root, '.env'), 'PORT=9981\nREAL2SIM_DATA_ROOT=/example/default\n')
await writeFile(join(root, '.env.local'), 'PORT=9982\nDASHSCOPE_API_KEY=fixture-only\n')
return root
}
test('loads the same dotenv port for the API and Vite children', async () => {
const root = await fixture()
const env = loadDevEnvironment(root, false, {})
expect(env.PORT).toBe('9982')
expect(env.REAL2SIM_DATA_ROOT).toBe('/example/default')
})
test('preserves explicit shell overrides without mutating them', async () => {
const root = await fixture()
const inherited = { PORT: '9983' }
expect(loadDevEnvironment(root, false, inherited).PORT).toBe('9983')
expect(inherited).toEqual({ PORT: '9983' })
})
test('keeps demo data and credentials separate from dotenv and inherited settings', async () => {
const root = await fixture()
const env = loadDevEnvironment(root, true, {
DASHSCOPE_API_KEY: 'fixture-only',
REAL2SIM_DATA_ROOT: '/example/private',
REAL2SIM_ASSET_ROOT: '/example/private/assets',
REAL2SIM_GENESIS_PACKAGE_ROOT: '/example/private/packages',
})
expect(env.REAL2SIM_DEMO).toBe('1')
expect(env.REAL2SIM_DATA_ROOT).toBe(join(root, '.data/demo'))
expect(env.DASHSCOPE_API_KEY).toBeUndefined()
expect(env.REAL2SIM_ASSET_ROOT).toBeUndefined()
expect(env.REAL2SIM_GENESIS_PACKAGE_ROOT).toBeUndefined()
expect(env.PORT).toBeUndefined()
})

View File

@ -1,24 +0,0 @@
import { spawn } from 'node:child_process'
import { fileURLToPath } from 'node:url'
import { loadDevEnvironment } from './dev-env.mjs'
const root = fileURLToPath(new URL('../', import.meta.url))
const demo = process.argv.includes('--demo')
const env = loadDevEnvironment(root, demo)
const children = [
spawn(process.execPath, ['--import', 'tsx', 'server/index.ts'], { cwd: root, env, stdio: 'inherit' }),
spawn(process.execPath, ['node_modules/vite/bin/vite.js', '--host', '127.0.0.1'], { cwd: root, env, stdio: 'inherit' }),
]
let closing = false
function stop(code = 0) {
if (closing) return
closing = true
for (const child of children) child.kill('SIGTERM')
process.exitCode = code
}
for (const child of children) {
child.on('error', (error) => { console.error(error.message); stop(1) })
child.on('exit', (code) => stop(code || 0))
}
process.on('SIGINT', () => stop())
process.on('SIGTERM', () => stop())

View File

@ -1,6 +0,0 @@
import { createGenesisPackage } from '../server/genesisPackage.js'
import { importExample } from '../server/examples.js'
const task = await importExample()
const exported = await createGenesisPackage(task)
console.log(exported.packageDir)

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
from pathlib import Path
from real2sim_platform.motrix_scene import export_mujoco_body_glb
def main() -> int:
parser = argparse.ArgumentParser(description="Export the registered RM65 MJCF visual geometry as a browser GLB")
parser.add_argument("--source", type=Path, required=True)
parser.add_argument("--output", type=Path, required=True)
args = parser.parse_args()
result = export_mujoco_body_glb(args.source.resolve(), args.output.resolve(), root_body="base_link", relative_to_root=True)
print(json.dumps(result, ensure_ascii=False, indent=2))
return 0
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -0,0 +1,303 @@
#!/usr/bin/env node
import { spawn } from "node:child_process";
import { createRequire } from "node:module";
import fs from "node:fs";
import path from "node:path";
const key = process.env.REAL2SIM_WUYING_KEY || "/Users/d-robotics/workSpace/document/80-private/orgs/drobotics/keys/wuying-39.106.101.95_ed25519";
const host = process.env.REAL2SIM_WUYING_HOST || "root@39.106.101.95";
const remotePort = Number(process.env.REAL2SIM_REMOTE_PORT || "18126");
const requestedBase = process.env.REAL2SIM_FRONTEND_BASE_URL || "";
const outRoot = process.env.REAL2SIM_ACCEPTANCE_OUT || path.resolve("real2sim-platform", "workspace", "acceptance_runs", "frontend-local");
const timestamp = new Date().toISOString().replace(/[-:]/g, "").replace(/\..*/, "Z");
const outDir = path.join(outRoot, timestamp);
const reportPath = path.join(outDir, "frontend_acceptance_report.json");
const screenshots = [];
const failures = [];
const warnings = [];
const consoleMessages = [];
const pageChecks = [];
let tunnel = null;
fs.mkdirSync(outDir, { recursive: true });
function fail(message, context = {}) {
failures.push({ message, ...context });
console.error("FAIL:", message, context);
}
function saveReport(extra = {}) {
const report = {
schema: "real2sim.frontend_acceptance_report.v1",
started_at: timestamp,
finished_at: new Date().toISOString(),
base_url: extra.baseUrl || requestedBase,
screenshots,
console_messages: consoleMessages,
warnings,
page_checks: pageChecks,
failures,
pass: failures.length === 0,
...extra,
};
fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`);
return report;
}
async function main() {
const { chromium } = await importPlaywright();
const baseUrl = requestedBase || await startTunnel();
const browser = await chromium.launch({ headless: true });
try {
const page = await browser.newPage({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 });
page.on("console", (message) => {
const entry = { type: message.type(), text: message.text() };
consoleMessages.push(entry);
if (message.type() === "error") fail("browser console error", entry);
});
page.on("pageerror", (error) => fail("browser page error", { error: error.message }));
await page.goto(baseUrl, { waitUntil: "domcontentloaded", timeout: 60000 });
await page.waitForSelector(".app-shell", { timeout: 30000 });
await neutralizeEmbeddedViewers(page);
await expectText(page, "Real2Sim", "brand");
await expectAbsentText(page, "验收", "old acceptance nav");
await expectAbsentText(page, "3D预览", "old viewer nav");
await expectAbsentText(page, "workspace", "old workspace footer");
await expectAbsentText(page, "打开云桌面", "old cloud desktop button");
const pages = [
{ tab: "overview", title: "总览", shot: "desktop-overview.png", selectors: ["#journeySteps", "#recentTaskList"] },
{ tab: "data", title: "数据管理", shot: "desktop-data.png", selectors: ["#datasetList", "#dataTaskList"] },
{ tab: "reconstruct", title: "场景重建", shot: "desktop-reconstruct.png", selectors: ["#reconstructInput", "#sceneTaskList"] },
{ tab: "scenes", title: "场景管理", shot: "", selectors: ["#sceneList", "#scenePreview"] },
{ tab: "collect", title: "数据采集", shot: "desktop-collect.png", selectors: ["#collectScene", "#collectTaskList"] },
{ tab: "train", title: "模型训练", shot: "desktop-train.png", selectors: ["#trainDataset", "#trainTaskList", "#modelList"] },
{ tab: "infer", title: "在线推理", shot: "desktop-infer.png", selectors: ["#inferModel", "#inferScene", "#inferTaskList"] },
];
for (const item of pages) {
await openTab(page, item.tab);
await expectText(page, item.title, `${item.tab} title`);
for (const selector of item.selectors) await expectSelector(page, selector, `${item.tab} ${selector}`);
await assertNoOverflow(page, `desktop ${item.tab}`);
if (item.shot) await screenshot(page, item.shot, item.shotOptions || {});
else warnings.push(`${item.tab} screenshot skipped; page contains embedded WebGL iframe that can hang headless screenshot capture`);
pageChecks.push({ tab: item.tab, viewport: "desktop", ok: true });
}
await openTab(page, "reconstruct");
const taskCount = await page.locator("#sceneTaskList [data-task]").count();
if (taskCount === 0) {
warnings.push("no scene tasks visible for drawer/report validation");
} else {
await page.locator("#sceneTaskList [data-task]").first().click({ timeout: 10000 });
await page.waitForTimeout(1500);
await expectSelector(page, "#taskDrawer[aria-hidden=\"false\"]", "task drawer opened");
await expectSelector(page, "#drawerBody", "task drawer body");
await screenshot(page, "desktop-task-drawer.png");
}
await validateSceneViewerManifestGate(baseUrl);
warnings.push("live scene viewer probe is excluded from the main frontend gate; SPZ manifest/autoload is validated here and live WebGL should be checked with the dedicated viewer probe.");
await page.setViewportSize({ width: 390, height: 900 });
await neutralizeEmbeddedViewers(page);
for (const item of [pages[0], pages[1], pages[2], pages[3]]) {
await openTab(page, item.tab);
await expectText(page, item.title, `mobile ${item.tab} title`);
await assertNoOverflow(page, `mobile ${item.tab}`);
if (item.shot) await screenshot(page, item.shot.replace("desktop", "mobile"), item.shotOptions || {});
else warnings.push(`mobile ${item.tab} screenshot skipped; page contains embedded WebGL iframe that can hang headless screenshot capture`);
pageChecks.push({ tab: item.tab, viewport: "mobile", ok: true });
}
const report = saveReport({ baseUrl });
console.log(JSON.stringify({ pass: report.pass, report: reportPath, screenshots }, null, 2));
process.exitCode = report.pass ? 0 : 1;
} finally {
await browser.close();
if (tunnel) tunnel.kill("SIGTERM");
}
}
async function importPlaywright() {
const moduleDir = process.env.REAL2SIM_PLAYWRIGHT_NODE_MODULES || "";
if (moduleDir) {
const require = createRequire(path.join(moduleDir, "real2sim-playwright-loader.cjs"));
return require("playwright");
}
try {
return await import("playwright");
} catch (error) {
throw new Error(`playwright is required. Install it locally with: npm install playwright, or set REAL2SIM_PLAYWRIGHT_NODE_MODULES=/path/to/node_modules. Original error: ${error.message}`);
}
}
async function startTunnel() {
const port = Number(process.env.REAL2SIM_LOCAL_TUNNEL_PORT || await findPort(18130));
tunnel = spawn("ssh", [
"-i", key,
"-o", "BatchMode=yes",
"-o", "StrictHostKeyChecking=accept-new",
"-N",
"-L", `${port}:127.0.0.1:${remotePort}`,
host,
], { stdio: ["ignore", "pipe", "pipe"] });
tunnel.stderr.on("data", (chunk) => process.stderr.write(chunk));
tunnel.stdout.on("data", (chunk) => process.stdout.write(chunk));
const baseUrl = `http://127.0.0.1:${port}`;
const deadline = Date.now() + 30000;
while (Date.now() < deadline) {
try {
await fetchJson(baseUrl, "/api/health");
return baseUrl;
} catch {
await sleep(500);
}
}
throw new Error(`SSH tunnel did not become ready at ${baseUrl}`);
}
async function findPort(start) {
const net = await import("node:net");
for (let port = start; port < start + 100; port += 1) {
const ok = await new Promise((resolve) => {
const server = net.createServer();
server.once("error", () => resolve(false));
server.once("listening", () => server.close(() => resolve(true)));
server.listen(port, "127.0.0.1");
});
if (ok) return port;
}
throw new Error("no local tunnel port available");
}
async function fetchJson(baseUrl, apiPath) {
const response = await fetch(`${baseUrl}${apiPath}`);
if (!response.ok) throw new Error(`${apiPath} failed with ${response.status}: ${await response.text()}`);
return response.json();
}
async function openTab(page, tab) {
await page.evaluate((targetTab) => {
const button = document.querySelector(`[data-tab="${targetTab}"]`);
if (!button) throw new Error(`tab not found: ${targetTab}`);
button.click();
}, tab);
await page.waitForFunction((targetTab) => document.getElementById(targetTab)?.classList.contains("active"), tab, { timeout: 10000 });
}
async function neutralizeEmbeddedViewers(page) {
await page.evaluate(() => {
document.querySelectorAll("iframe").forEach((iframe) => {
iframe.dataset.acceptanceSrc = iframe.getAttribute("src") || "";
iframe.setAttribute("src", "about:blank");
});
}).catch(() => {});
}
async function assertNoOverflow(page, label) {
const metrics = await page.evaluate(() => ({
scrollWidth: document.documentElement.scrollWidth,
clientWidth: document.documentElement.clientWidth,
bodyScrollWidth: document.body.scrollWidth,
bodyClientWidth: document.body.clientWidth,
}));
if (metrics.scrollWidth > metrics.clientWidth + 2 || metrics.bodyScrollWidth > metrics.bodyClientWidth + 2) {
fail("horizontal overflow", { label, metrics });
}
}
async function expectText(page, text, label) {
const visible = await page.getByText(text, { exact: false }).first().isVisible().catch(() => false);
if (!visible) fail("expected text not visible", { label, text });
}
async function expectAbsentText(page, text, label) {
const visible = await page.getByText(text, { exact: false }).first().isVisible().catch(() => false);
if (visible) fail("legacy/debug text should not be visible", { label, text });
}
async function expectSelector(page, selector, label) {
const count = await page.locator(selector).count().catch(() => 0);
if (count <= 0) fail("expected selector not found", { label, selector });
}
async function pickPreviewableScene(baseUrl) {
const scenes = await fetchJson(baseUrl, "/api/scenes");
if (!Array.isArray(scenes) || scenes.length === 0) return null;
const scored = [];
for (const scene of scenes) {
try {
const manifest = await fetchJson(baseUrl, `/api/scenes/${encodeURIComponent(scene.id)}/manifest`);
const assets = Array.isArray(manifest.assets) ? manifest.assets : [];
let score = 0;
if (assets.some((asset) => /\.(spz|splat|ksplat|sog)$/i.test(String(asset.name || asset.path || "")))) score += 100;
if (assets.some((asset) => /pose_init_trained_scene\.ply$/i.test(String(asset.name || asset.path || "")))) score += 50;
if (assets.some((asset) => /\.(ply|glb|gltf|obj)$/i.test(String(asset.name || asset.path || "")))) score += 20;
scored.push({ scene, score });
} catch (error) {
warnings.push(`scene manifest unavailable for ${scene.id}: ${error.message}`);
}
}
scored.sort((left, right) => right.score - left.score);
return scored[0]?.scene || scenes[0];
}
async function validateSceneViewerManifestGate(baseUrl) {
const scene = await pickPreviewableScene(baseUrl);
if (!scene) {
fail("no scenes available for 3D viewer manifest validation");
return;
}
const manifest = await fetchJson(baseUrl, `/api/scenes/${encodeURIComponent(scene.id)}/manifest`);
const assets = Array.isArray(manifest.assets) ? manifest.assets : [];
const optimized = assets.find((asset) => /\.(spz|splat|ksplat|sog)$/i.test(String(asset.name || asset.path || "")));
if (!optimized) {
fail("scene manifest has no optimized splat asset for browser preview", { scene_id: scene.id });
return;
}
if (!optimized.url) fail("optimized splat asset has no URL", { scene_id: scene.id, asset: optimized });
if (optimized.autoload === false) fail("optimized splat asset is not marked autoload", { scene_id: scene.id, asset: optimized });
pageChecks.push({ tab: "scene-viewer", viewport: "desktop", ok: true, asset: optimized.name || optimized.path, size: optimized.size_label || optimized.size_bytes || "" });
}
async function screenshot(page, name, options = {}) {
const target = path.join(outDir, name);
const timeoutMs = Number(options.timeoutMs || 20000);
let styleHandle = null;
try {
if (options.hideIframes) {
styleHandle = await page.evaluateHandle(() => {
const style = document.createElement("style");
style.dataset.acceptanceScreenshot = "true";
style.textContent = "iframe, canvas { visibility: hidden !important; }";
document.head.appendChild(style);
return style;
});
await page.waitForTimeout(150);
}
await page.screenshot({ path: target, fullPage: options.fullPage ?? true, timeout: timeoutMs });
screenshots.push(target);
} catch (error) {
const message = `screenshot skipped for ${name}: ${error.message}`;
warnings.push(message);
} finally {
if (styleHandle) {
await page.evaluate(() => document.querySelector("[data-acceptance-screenshot='true']")?.remove()).catch(() => {});
await styleHandle.dispose().catch(() => {});
}
}
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
main().catch((error) => {
fail("frontend acceptance runner crashed", { error: error.message, stack: error.stack });
const report = saveReport();
console.error(JSON.stringify({ pass: false, report: reportPath, error: error.message }, null, 2));
if (tunnel) tunnel.kill("SIGTERM");
process.exit(1);
});

View File

@ -1,17 +0,0 @@
"""Regenerate the MIT-licensed sample from primitives, without external assets."""
from pathlib import Path
import trimesh
root = Path(__file__).resolve().parents[1] / "examples" / "soft-puck"
root.mkdir(parents=True, exist_ok=True)
mesh = trimesh.creation.icosphere(subdivisions=2, radius=0.08)
mesh.apply_scale([1, 0.65, 1])
mesh.visual = trimesh.visual.TextureVisuals(
material=trimesh.visual.material.PBRMaterial(
baseColorFactor=[31, 184, 158, 255], metallicFactor=0.0, roughnessFactor=0.38
)
)
assert mesh.is_watertight and mesh.volume > 0
mesh.export(root / "model.glb")
print(f"Generated watertight sample: {len(mesh.vertices)} vertices, {len(mesh.faces)} faces")

View File

@ -0,0 +1,254 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
import math
import sys
import time
import xml.etree.ElementTree as ET
from pathlib import Path
from typing import Any
import numpy as np
import trimesh
SCRIPT_DIR = Path(__file__).resolve().parent
APP_ROOT = SCRIPT_DIR.parent
SRC_ROOT = APP_ROOT / "src"
if str(SRC_ROOT) not in sys.path:
sys.path.insert(0, str(SRC_ROOT))
from real2sim_platform.config import ensure_workspace, load_config # noqa: E402
from real2sim_platform.store import PlatformStore # noqa: E402
SCENE_ID = "1f2618bdfcac4e45456569980716405a"
PACKAGE_SLUG = "parlour_rm65_pick_place"
def main() -> int:
parser = argparse.ArgumentParser(description="Generate a browser GLB preview from the MotrixSim parlour + RM65 scaffold package.")
parser.add_argument("--scene-id", default=SCENE_ID)
parser.add_argument("--max-parlour-meshes", type=int, default=240, help="Limit parlour meshes to keep the browser preview responsive.")
parser.add_argument("--skip-rm65", action="store_true")
args = parser.parse_args()
config = load_config()
ensure_workspace(config)
store = PlatformStore(config.db_path)
scene = store.get_scene(args.scene_id)
package_dir = Path(str((scene.get("metadata") or {}).get("package") or config.workspace_dir / "motrixsim_assets" / PACKAGE_SLUG))
manifest_path = Path(str(scene.get("manifest_path") or package_dir / "motrixsim_scene_manifest.json"))
if not manifest_path.is_file():
raise SystemExit(f"manifest not found: {manifest_path}")
output_dir = package_dir / "viewer_assets"
output_dir.mkdir(parents=True, exist_ok=True)
output_path = output_dir / "motrixsim_parlour_rm65_preview.glb"
report_path = output_dir / "motrixsim_preview_report.json"
scene_glb = trimesh.Scene()
report: dict[str, Any] = {
"schema": "real2sim.motrixsim_preview_report.v1",
"created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"inputs": [],
"warnings": [],
}
parlour_xml = package_dir / "assets/parlour/parlour.xml"
parlour_stats = add_mjcf_visuals(scene_glb, parlour_xml, max_meshes=args.max_parlour_meshes, name_prefix="parlour")
report["inputs"].append({"role": "parlour", "xml": str(parlour_xml), **parlour_stats})
if not args.skip_rm65:
rm65_xml = package_dir / "assets/rm65_open_cabinet/mjx_rm65.xml"
rm65_base = translation_matrix(np.array([0.8, 0.0, 0.55]))
rm65_stats = add_mjcf_visuals(scene_glb, rm65_xml, root_transform=rm65_base, max_meshes=80, name_prefix="rm65")
report["inputs"].append({"role": "rm65", "xml": str(rm65_xml), **rm65_stats})
if not scene_glb.geometry:
raise SystemExit("no mesh geometry was loaded from MotrixSim package")
data = scene_glb.export(file_type="glb")
output_path.write_bytes(data)
report["output"] = {"path": str(output_path), "size_bytes": output_path.stat().st_size, "geometry_count": len(scene_glb.geometry)}
report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
artifact = store.add_artifact(task_id=None, name=output_path.name, path=output_path, kind="mesh")
report_artifact = store.add_artifact(task_id=None, name=report_path.name, path=report_path, kind="json")
update_manifest(manifest_path, output_path, artifact["id"], report_path, report_artifact["id"], report)
print(json.dumps({"ok": True, "scene_id": args.scene_id, "glb": str(output_path), "report": str(report_path), "geometry_count": len(scene_glb.geometry), "size_bytes": output_path.stat().st_size}, ensure_ascii=False, indent=2))
return 0
def add_mjcf_visuals(
scene: trimesh.Scene,
xml_path: Path,
*,
root_transform: np.ndarray | None = None,
max_meshes: int,
name_prefix: str,
) -> dict[str, Any]:
root = ET.parse(xml_path).getroot()
asset_dir = xml_path.parent / (root.find("compiler").attrib.get("assetdir", "") if root.find("compiler") is not None else "")
mesh_defs = {
item.attrib["name"]: asset_dir / item.attrib["file"]
for item in root.findall("./asset/mesh")
if item.attrib.get("name") and item.attrib.get("file")
}
stats = {"mesh_defs": len(mesh_defs), "loaded": 0, "missing": 0, "skipped": 0}
world = root.find("worldbody")
if world is None:
return stats
root_matrix = root_transform if root_transform is not None else np.eye(4)
for node in list(world):
traverse_mjcf_node(scene, node, mesh_defs, root_matrix, stats, max_meshes=max_meshes, name_prefix=name_prefix)
return stats
def traverse_mjcf_node(
scene: trimesh.Scene,
node: ET.Element,
mesh_defs: dict[str, Path],
parent_transform: np.ndarray,
stats: dict[str, int],
*,
max_meshes: int,
name_prefix: str,
) -> None:
current = parent_transform
if node.tag == "body":
current = parent_transform @ node_transform(node.attrib)
elif node.tag == "geom":
mesh_name = node.attrib.get("mesh")
geom_class = node.attrib.get("class", "")
if mesh_name and mesh_name in mesh_defs and (geom_class != "collision" or node.attrib.get("group") == "2"):
if stats["loaded"] >= max_meshes:
stats["skipped"] += 1
else:
mesh_path = mesh_defs[mesh_name]
if mesh_path.is_file():
try:
mesh = load_mesh(mesh_path)
mesh.apply_transform(parent_transform @ node_transform(node.attrib))
scene.add_geometry(mesh, geom_name=f"{name_prefix}_{mesh_name}_{stats['loaded']}")
stats["loaded"] += 1
except Exception:
stats["skipped"] += 1
else:
stats["missing"] += 1
for child in list(node):
traverse_mjcf_node(scene, child, mesh_defs, current, stats, max_meshes=max_meshes, name_prefix=name_prefix)
def load_mesh(path: Path) -> trimesh.Trimesh:
loaded = trimesh.load(path, force="mesh", process=False)
if isinstance(loaded, trimesh.Scene):
return trimesh.util.concatenate(tuple(loaded.geometry.values()))
return loaded
def node_transform(attrs: dict[str, str]) -> np.ndarray:
transform = np.eye(4)
if "pos" in attrs:
transform = transform @ translation_matrix(parse_vec(attrs["pos"], 3))
if "quat" in attrs:
transform = transform @ quat_matrix(parse_vec(attrs["quat"], 4))
elif "euler" in attrs:
transform = transform @ euler_matrix(parse_vec(attrs["euler"], 3))
if "scale" in attrs:
scale = parse_vec(attrs["scale"], 3)
transform = transform @ np.diag([scale[0], scale[1], scale[2], 1.0])
return transform
def parse_vec(value: str, count: int) -> np.ndarray:
parts = [float(item) for item in value.split()]
if len(parts) == 1 and count == 3:
parts = parts * 3
while len(parts) < count:
parts.append(0.0)
return np.array(parts[:count], dtype=float)
def translation_matrix(vec: np.ndarray) -> np.ndarray:
matrix = np.eye(4)
matrix[:3, 3] = vec[:3]
return matrix
def quat_matrix(q: np.ndarray) -> np.ndarray:
w, x, y, z = q
norm = math.sqrt(w * w + x * x + y * y + z * z)
if norm <= 0:
return np.eye(4)
w, x, y, z = w / norm, x / norm, y / norm, z / norm
matrix = np.eye(4)
matrix[:3, :3] = np.array(
[
[1 - 2 * y * y - 2 * z * z, 2 * x * y - 2 * z * w, 2 * x * z + 2 * y * w],
[2 * x * y + 2 * z * w, 1 - 2 * x * x - 2 * z * z, 2 * y * z - 2 * x * w],
[2 * x * z - 2 * y * w, 2 * y * z + 2 * x * w, 1 - 2 * x * x - 2 * y * y],
]
)
return matrix
def euler_matrix(euler: np.ndarray) -> np.ndarray:
x, y, z = euler
cx, cy, cz = math.cos(x), math.cos(y), math.cos(z)
sx, sy, sz = math.sin(x), math.sin(y), math.sin(z)
rx = np.array([[1, 0, 0, 0], [0, cx, -sx, 0], [0, sx, cx, 0], [0, 0, 0, 1]])
ry = np.array([[cy, 0, sy, 0], [0, 1, 0, 0], [-sy, 0, cy, 0], [0, 0, 0, 1]])
rz = np.array([[cz, -sz, 0, 0], [sz, cz, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
return rz @ ry @ rx
def update_manifest(manifest_path: Path, glb_path: Path, artifact_id: str, report_path: Path, report_artifact_id: str, report: dict[str, Any]) -> None:
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
assets = [item for item in manifest.get("assets", []) if not (isinstance(item, dict) and item.get("name") == glb_path.name)]
glb_asset = {
"name": glb_path.name,
"role": "viewer_preview",
"kind": "mesh",
"path": str(glb_path),
"relative_path": str(glb_path.relative_to(manifest_path.parent)),
"url": f"/api/artifacts/{artifact_id}/content",
"exists": True,
"size_bytes": glb_path.stat().st_size,
"size_label": format_bytes(glb_path.stat().st_size),
"autoload": True,
"generated": True,
}
report_asset = {
"name": report_path.name,
"role": "preview_report",
"kind": "metadata",
"path": str(report_path),
"relative_path": str(report_path.relative_to(manifest_path.parent)),
"url": f"/api/artifacts/{report_artifact_id}/content",
"exists": True,
"size_bytes": report_path.stat().st_size,
"size_label": format_bytes(report_path.stat().st_size),
"generated": True,
}
manifest["assets"] = [glb_asset, report_asset, *assets]
manifest["viewer_assets"] = {"primary": glb_asset, "report": report_asset, "generator": "generate_motrixsim_preview.py"}
manifest["preview_generation"] = report
manifest["updated_at"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
manifest_path.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
def format_bytes(value: int) -> str:
units = ["B", "KB", "MB", "GB"]
size = float(value)
for unit in units:
if size < 1024 or unit == units[-1]:
return f"{size:.1f} {unit}" if unit != "B" else f"{int(size)} B"
size /= 1024
return f"{value} B"
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -0,0 +1,297 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import importlib.util
import json
import os
import subprocess
import sys
import time
from pathlib import Path
from typing import Any
SCRIPT_DIR = Path(__file__).resolve().parent
APP_ROOT = SCRIPT_DIR.parent
SRC_ROOT = APP_ROOT / "src"
if str(SRC_ROOT) not in sys.path:
sys.path.insert(0, str(SRC_ROOT))
from real2sim_platform.config import ensure_workspace, load_config # noqa: E402
from real2sim_platform.store import PlatformStore # noqa: E402
SCENE_ID = "1f2618bdfcac4e45456569980716405a"
PACKAGE_SLUG = "parlour_rm65_pick_place"
def main() -> int:
parser = argparse.ArgumentParser(description="Generate a runnable RM65 + coffee-table pick-place smoke MJCF for the MotrixSim asset package.")
parser.add_argument("--scene-id", default=SCENE_ID)
parser.add_argument("--steps", type=int, default=120)
parser.add_argument("--motrixsim-python", default="")
args = parser.parse_args()
config = load_config()
ensure_workspace(config)
store = PlatformStore(config.db_path)
scene = store.get_scene(args.scene_id)
package_dir = Path(str((scene.get("metadata") or {}).get("package") or config.workspace_dir / "motrixsim_assets" / PACKAGE_SLUG))
manifest_path = Path(str(scene.get("manifest_path") or package_dir / "motrixsim_scene_manifest.json"))
sim_dir = package_dir / "simulator_assets"
sim_dir.mkdir(parents=True, exist_ok=True)
runtime_rm65 = sim_dir / "rmjx_rm65_runtime.xml"
source_rm65 = package_dir / "assets/rm65_open_cabinet/mjx_rm65.xml"
runtime_xml = source_rm65.read_text(encoding="utf-8").replace(
'assetdir="assets"',
'assetdir="../assets/rm65_open_cabinet/assets"',
)
# The upstream pad capsules are visual-only diagnostics. Enable collision on
# the runtime copy so pick-place validation measures real bilateral contact.
runtime_xml = runtime_xml.replace(
'contype="0" conaffinity="0" density="0" group="2"/>',
'contype="1" conaffinity="1" density="0" friction="2.0 0.02 0.002" group="3"/>',
)
runtime_xml = runtime_xml.replace(
'name="left_finger_pad_z_axis" type="capsule" fromto="-0.021275 0.04375 -0.06 -0.021275 0.04375 0.06"\n size="0.003"',
'name="left_finger_pad_z_axis" type="capsule" fromto="-0.021275 0.04375 -0.06 -0.021275 0.04375 0.06"\n size="0.010"',
).replace(
'name="right_finger_pad_z_axis" type="capsule" fromto="-0.021275 0.04375 -0.06 -0.021275 0.04375 0.06"\n size="0.003"',
'name="right_finger_pad_z_axis" type="capsule" fromto="-0.021275 0.04375 -0.06 -0.021275 0.04375 0.06"\n size="0.010"',
)
runtime_rm65.write_text(runtime_xml, encoding="utf-8")
combined = sim_dir / "rm65_table_pick_place.xml"
combined.write_text(runtime_scene_xml(), encoding="utf-8")
mujoco_report = validate_mujoco(combined, steps=args.steps)
motrixsim_python = find_motrixsim_python(args.motrixsim_python)
motrixsim_report = validate_motrixsim(combined, steps=args.steps, python=motrixsim_python)
report = {
"schema": "real2sim.motrixsim_runtime_scene_validation.v2",
"created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"combined_mjcf": str(combined),
"steps_requested": args.steps,
"ok": bool(mujoco_report.get("ok") and motrixsim_report.get("ok")),
"runtimes": {"mujoco": mujoco_report, "motrixsim": motrixsim_report},
}
report_path = sim_dir / "rm65_table_pick_place_validation.json"
report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
scene_artifact = store.add_artifact(task_id=None, name=combined.name, path=combined, kind="simulator")
rm65_artifact = store.add_artifact(task_id=None, name=runtime_rm65.name, path=runtime_rm65, kind="simulator")
report_artifact = store.add_artifact(task_id=None, name=report_path.name, path=report_path, kind="json")
update_manifest(manifest_path, combined, scene_artifact["id"], runtime_rm65, rm65_artifact["id"], report_path, report_artifact["id"], report)
runtime_ready = bool(report["ok"])
metadata = dict(scene.get("metadata") or {})
metadata.update(
{
"status": "runtime_validated" if runtime_ready else "runtime_validation_failed",
"adapter_pending": not runtime_ready,
"runtime_validation": {"mujoco": bool(mujoco_report.get("ok")), "motrixsim": bool(motrixsim_report.get("ok"))},
}
)
tags = [tag for tag in scene.get("tags", []) if tag not in {"adapter-pending", "runtime-validated", "motrixsim-ready"}]
if runtime_ready:
tags.extend(["runtime-validated", "motrixsim-ready"])
else:
tags.append("adapter-pending")
store.update_scene(args.scene_id, metadata=metadata, tags=tags)
print(json.dumps({"ok": report["ok"], "scene_id": args.scene_id, "combined_mjcf": str(combined), "report": str(report_path), "validation": report}, ensure_ascii=False, indent=2))
return 0 if report["ok"] else 1
def runtime_scene_xml() -> str:
return """<mujoco model="rm65 table pick place smoke">
<include file="rmjx_rm65_runtime.xml"/>
<visual>
<global offwidth="960" offheight="540"/>
</visual>
<worldbody>
<body name="coffee_table" pos="0.65 0 0.25">
<geom name="coffee_table_top" type="box" size="0.45 0.32 0.03" rgba="0.45 0.30 0.18 1" friction="0.8 0.01 0.001"/>
<geom name="coffee_table_leg_1" type="box" pos="0.36 0.25 -0.14" size="0.025 0.025 0.14" rgba="0.20 0.13 0.08 1"/>
<geom name="coffee_table_leg_2" type="box" pos="-0.36 0.25 -0.14" size="0.025 0.025 0.14" rgba="0.20 0.13 0.08 1"/>
<geom name="coffee_table_leg_3" type="box" pos="0.36 -0.25 -0.14" size="0.025 0.025 0.14" rgba="0.20 0.13 0.08 1"/>
<geom name="coffee_table_leg_4" type="box" pos="-0.36 -0.25 -0.14" size="0.025 0.025 0.14" rgba="0.20 0.13 0.08 1"/>
</body>
<body name="pick_cube" pos="0.65 0 0.33">
<freejoint name="pick_cube_free"/>
<geom name="pick_cube_geom" type="box" size="0.03 0.03 0.03" rgba="0.9 0.2 0.12 1" mass="0.05" friction="0.9 0.01 0.001"/>
</body>
<body name="place_target" pos="0.43 0.18 0.335">
<geom name="place_target_marker" type="cylinder" size="0.055 0.004" rgba="0.1 0.8 0.6 0.35" contype="0" conaffinity="0"/>
</body>
<camera name="overview" pos="1.7 -1.6 1.25" xyaxes="0.68 0.73 0 -0.37 0.34 0.86"/>
</worldbody>
<keyframe>
<key name="home" qpos="0 0 0 -1.57079 0 1.57079 -0.7853 0 0 0 0 0 0.65 0 0.33 1 0 0 0" ctrl="0 0 0 -1.57079 0 1.57079 -0.7853"/>
</keyframe>
</mujoco>
"""
def validate_mujoco(path: Path, *, steps: int) -> dict[str, Any]:
started = time.time()
report: dict[str, Any] = {
"schema": "real2sim.motrixsim_runtime_scene_validation.v1",
"created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"combined_mjcf": str(path),
"steps_requested": steps,
"ok": False,
}
try:
import mujoco
model = mujoco.MjModel.from_xml_path(str(path))
data = mujoco.MjData(model)
for _ in range(max(0, steps)):
mujoco.mj_step(model, data)
report.update(
{
"ok": True,
"runtime": "mujoco",
"nq": int(model.nq),
"nv": int(model.nv),
"nbody": int(model.nbody),
"ngeom": int(model.ngeom),
"nkey": int(model.nkey),
"sim_time": float(data.time),
"elapsed_ms": round((time.time() - started) * 1000),
}
)
except Exception as exc:
report.update({"ok": False, "error": f"{type(exc).__name__}: {exc}", "elapsed_ms": round((time.time() - started) * 1000)})
return report
def find_motrixsim_python(explicit: str) -> Path | None:
current_python = sys.executable if importlib.util.find_spec("motrixsim") is not None else ""
candidates = [
explicit,
os.environ.get("REAL2SIM_MOTRIXSIM_PYTHON", ""),
current_python,
"/Users/d-robotics/workSpace/motrixsim-docs/.venv/bin/python",
"/opt/Motphys/motrixsim-docs/.venv/bin/python",
]
for candidate in candidates:
if candidate and Path(candidate).is_file():
return Path(candidate)
return None
def validate_motrixsim(path: Path, *, steps: int, python: Path | None) -> dict[str, Any]:
started = time.time()
report: dict[str, Any] = {"ok": False, "runtime": "motrixsim", "python": str(python or "")}
if python is None:
report.update({"status": "runtime_unavailable", "error": "motrixsim python environment was not found"})
return report
probe = """
import json, sys
from motrixsim import SceneData, load_model, step
model = load_model(sys.argv[1])
data = SceneData(model)
for _ in range(int(sys.argv[2])):
step(model, data)
print("REAL2SIM_RESULT=" + json.dumps({
"timestep": float(model.options.timestep),
"nq": len(data.low.dof_positions),
"nv": len(data.low.dof_velocities),
}))
"""
try:
completed = subprocess.run(
[str(python), "-c", probe, str(path), str(steps)],
check=True,
capture_output=True,
text=True,
timeout=120,
)
result_line = next(line for line in completed.stdout.splitlines() if line.startswith("REAL2SIM_RESULT="))
result = json.loads(result_line.split("=", 1)[1])
report.update(
{
"ok": True,
"status": "loaded_and_stepped",
"steps": steps,
**result,
"elapsed_ms": round((time.time() - started) * 1000),
}
)
except Exception as exc:
stderr = getattr(exc, "stderr", "") or ""
report.update(
{
"ok": False,
"status": "runtime_failed",
"error": f"{type(exc).__name__}: {exc}",
"stderr": stderr[-2000:],
"elapsed_ms": round((time.time() - started) * 1000),
}
)
return report
def update_manifest(
manifest_path: Path,
combined: Path,
combined_artifact_id: str,
runtime_rm65: Path,
runtime_rm65_artifact_id: str,
report_path: Path,
report_artifact_id: str,
report: dict[str, Any],
) -> None:
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
generated_names = {combined.name, runtime_rm65.name, report_path.name}
assets = [item for item in manifest.get("assets", []) if not (isinstance(item, dict) and item.get("name") in generated_names)]
generated = [
asset_entry(combined, combined_artifact_id, "runtime_scene", "simulator", "可运行 RM65 茶几 pick-place smoke MJCF", manifest_path),
asset_entry(runtime_rm65, runtime_rm65_artifact_id, "runtime_robot", "simulator", "RM65 runtime assetdir 修正版", manifest_path),
asset_entry(report_path, report_artifact_id, "runtime_validation_report", "metadata", "运行时加载校验报告", manifest_path),
]
manifest["assets"] = [*generated, *assets]
manifest["runtime_scene"] = {
"combined_mjcf": generated[0],
"runtime_rm65": generated[1],
"validation_report": generated[2],
"validation": report,
"status": "mujoco_and_motrixsim_smoke_passed" if report.get("ok") else "failed",
"scope": "combined_rm65_table_scene_runtime_load_and_step",
}
manifest["updated_at"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
manifest_path.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
def asset_entry(path: Path, artifact_id: str, role: str, kind: str, name: str, manifest_path: Path) -> dict[str, Any]:
size = path.stat().st_size
return {
"name": path.name,
"display_name": name,
"role": role,
"kind": kind,
"path": str(path),
"relative_path": str(path.relative_to(manifest_path.parent)),
"url": f"/api/artifacts/{artifact_id}/content",
"exists": True,
"size_bytes": size,
"size_label": format_bytes(size),
"generated": True,
}
def format_bytes(value: int) -> str:
units = ["B", "KB", "MB", "GB"]
size = float(value)
for unit in units:
if size < 1024 or unit == units[-1]:
return f"{size:.1f} {unit}" if unit != "B" else f"{int(size)} B"
size /= 1024
return f"{value} B"
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -0,0 +1,351 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import hashlib
import json
import shutil
import subprocess
import sys
import time
from pathlib import Path
from typing import Any
SCRIPT_DIR = Path(__file__).resolve().parent
APP_ROOT = SCRIPT_DIR.parent
SRC_ROOT = APP_ROOT / "src"
if str(SRC_ROOT) not in sys.path:
sys.path.insert(0, str(SRC_ROOT))
from real2sim_platform.config import ensure_workspace, load_config # noqa: E402
from real2sim_platform.store import PlatformStore # noqa: E402
DEFAULT_SOURCE = Path("/Users/d-robotics/workSpace/motrixsim-docs")
PACKAGE_SLUG = "parlour_rm65_pick_place"
SCENE_ID = hashlib.sha1(f"motrixsim:{PACKAGE_SLUG}".encode("utf-8")).hexdigest()[:32]
REQUIRED_FILES = {
"parlour_scene": Path("examples/assets/parlour/parlour.xml"),
"rm65_robot": Path("examples/assets/rm65_open_cabinet/mjx_rm65.xml"),
"rm65_reference_scene": Path("examples/assets/rm65_open_cabinet/scene.xml"),
"rm65_reference_controller": Path("examples/control/rm65_open_cabinet.py"),
"pick_place_template": Path("examples/assets/franka_emika_panda/scene_pick_cube.xml"),
"parlour_locomotion_example": Path("examples/control/robot_locomotion.py"),
}
DIRECTORIES_TO_COPY = {
"parlour": Path("examples/assets/parlour"),
"rm65_open_cabinet": Path("examples/assets/rm65_open_cabinet"),
"franka_emika_panda": Path("examples/assets/franka_emika_panda"),
}
def main() -> int:
parser = argparse.ArgumentParser(description="Import MotrixSim parlour + RM65 pick-place scaffold into Real2Sim Platform.")
parser.add_argument("--source", type=Path, default=DEFAULT_SOURCE, help="Local MotrixSim docs repository path.")
parser.add_argument("--name", default="MotrixSim 客厅 RM65 Pick-Place", help="Scene name shown in Real2Sim.")
parser.add_argument("--replace-index", action="store_true", help="Replace the existing deterministic scene index row.")
parser.add_argument("--skip-copy", action="store_true", help="Only refresh manifest/index using existing package files.")
parser.add_argument("--allow-missing-source", action="store_true", help="Allow registering an already-copied package when the MotrixSim repo is not present.")
args = parser.parse_args()
source = args.source.expanduser().resolve()
config = load_config()
ensure_workspace(config)
store = PlatformStore(config.db_path)
package_dir = config.workspace_dir / "motrixsim_assets" / PACKAGE_SLUG
if source.is_dir():
_assert_source(source)
source_commit = _git_commit(source)
elif args.skip_copy and args.allow_missing_source:
source_commit = _existing_source_commit(package_dir) or ""
else:
raise SystemExit(f"MotrixSim docs repo not found: {source}")
if not args.skip_copy:
_copy_package(source, package_dir)
_assert_package(package_dir)
scene_descriptor = package_dir / f"{PACKAGE_SLUG}.scene.json"
manifest_path = package_dir / "motrixsim_scene_manifest.json"
scene_descriptor.write_text(
json.dumps(
{
"schema": "real2sim.scene_descriptor.v1",
"name": args.name,
"package": str(package_dir),
"manifest_path": str(manifest_path),
"simulator": "motrixsim",
"status": "asset_imported_adapter_pending",
},
ensure_ascii=False,
indent=2,
)
+ "\n",
encoding="utf-8",
)
artifacts = _register_file_artifacts(store, package_dir)
manifest = _build_manifest(
name=args.name,
source=source,
source_commit=source_commit,
package_dir=package_dir,
scene_descriptor=scene_descriptor,
artifact_urls=artifacts,
)
manifest_path.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
scene = _upsert_scene(
store=store,
name=args.name,
package_dir=package_dir,
scene_descriptor=scene_descriptor,
manifest_path=manifest_path,
manifest=manifest,
replace_index=args.replace_index,
)
print(json.dumps({"ok": True, "scene_id": scene["id"], "scene_name": scene["name"], "package_dir": str(package_dir), "manifest_path": str(manifest_path)}, ensure_ascii=False, indent=2))
return 0
def _assert_source(source: Path) -> None:
if not source.is_dir():
raise SystemExit(f"MotrixSim docs repo not found: {source}")
missing = [str(source / rel) for rel in REQUIRED_FILES.values() if not (source / rel).is_file()]
missing.extend(str(source / rel) for rel in DIRECTORIES_TO_COPY.values() if not (source / rel).is_dir())
if missing:
raise SystemExit("Missing required MotrixSim assets:\n" + "\n".join(missing))
_assert_materialized_lfs_assets((source / rel for rel in DIRECTORIES_TO_COPY.values()), context=str(source))
def _copy_package(source: Path, package_dir: Path) -> None:
if package_dir.exists():
shutil.rmtree(package_dir)
(package_dir / "assets").mkdir(parents=True, exist_ok=True)
(package_dir / "examples" / "control").mkdir(parents=True, exist_ok=True)
for name, rel in DIRECTORIES_TO_COPY.items():
shutil.copytree(source / rel, package_dir / "assets" / name)
for rel in [Path("examples/control/rm65_open_cabinet.py"), Path("examples/control/robot_locomotion.py")]:
shutil.copy2(source / rel, package_dir / "examples" / "control" / rel.name)
def _assert_package(package_dir: Path) -> None:
required = [
package_dir / "assets/parlour/parlour.xml",
package_dir / "assets/rm65_open_cabinet/mjx_rm65.xml",
package_dir / "assets/rm65_open_cabinet/scene.xml",
package_dir / "assets/franka_emika_panda/scene_pick_cube.xml",
package_dir / "examples/control/rm65_open_cabinet.py",
package_dir / "examples/control/robot_locomotion.py",
]
missing = [str(path) for path in required if not path.is_file()]
if missing:
raise SystemExit("Package is incomplete:\n" + "\n".join(missing))
_assert_materialized_lfs_assets((package_dir / "assets" / name for name in DIRECTORIES_TO_COPY), context=str(package_dir))
def _assert_materialized_lfs_assets(roots: Any, *, context: str) -> None:
pointers: list[str] = []
for root in roots:
for path in Path(root).rglob("*"):
if not path.is_file() or path.stat().st_size > 1024:
continue
try:
header = path.read_bytes()[:160]
except OSError:
continue
if header.startswith(b"version https://git-lfs.github.com/spec/"):
pointers.append(str(path))
if pointers:
preview = "\n".join(pointers[:20])
suffix = f"\n... and {len(pointers) - 20} more" if len(pointers) > 20 else ""
raise SystemExit(
"MotrixSim Git LFS assets are not materialized. Run `git lfs pull` before import. "
f"Source: {context}\n{preview}{suffix}"
)
def _register_file_artifacts(store: PlatformStore, package_dir: Path) -> dict[str, str]:
files = {
"scene_descriptor": package_dir / f"{PACKAGE_SLUG}.scene.json",
"parlour_scene": package_dir / "assets/parlour/parlour.xml",
"rm65_robot": package_dir / "assets/rm65_open_cabinet/mjx_rm65.xml",
"rm65_reference_scene": package_dir / "assets/rm65_open_cabinet/scene.xml",
"rm65_controller": package_dir / "examples/control/rm65_open_cabinet.py",
"pick_place_template": package_dir / "assets/franka_emika_panda/scene_pick_cube.xml",
"franka_preview": package_dir / "assets/franka_emika_panda/panda.png",
}
urls: dict[str, str] = {}
for role, path in files.items():
if not path.is_file():
continue
artifact = store.add_artifact(task_id=None, name=path.name, path=path, kind=_artifact_kind(path))
urls[role] = f"/api/artifacts/{artifact['id']}/content"
return urls
def _build_manifest(
*,
name: str,
source: Path,
source_commit: str,
package_dir: Path,
scene_descriptor: Path,
artifact_urls: dict[str, str],
) -> dict[str, Any]:
ready_assets = [
_asset(package_dir, "assets/parlour/parlour.xml", "parlour_scene", "simulator", "MotrixSim parlour 客厅场景", artifact_urls.get("parlour_scene")),
_asset(package_dir, "assets/rm65_open_cabinet/mjx_rm65.xml", "rm65_robot", "robot", "RM65 机械臂 MJCF", artifact_urls.get("rm65_robot")),
_asset(package_dir, "assets/rm65_open_cabinet/scene.xml", "rm65_reference_scene", "simulator", "RM65 开柜门参考场景", artifact_urls.get("rm65_reference_scene")),
_asset(package_dir, "examples/control/rm65_open_cabinet.py", "rm65_controller", "controller", "RM65 参考控制脚本", artifact_urls.get("rm65_controller")),
_asset(package_dir, "assets/franka_emika_panda/scene_pick_cube.xml", "pick_place_template", "simulator", "Franka pick-cube 任务模板", artifact_urls.get("pick_place_template")),
]
preview = _asset(package_dir, "assets/franka_emika_panda/panda.png", "reference_preview", "image", "机械臂参考预览图", artifact_urls.get("franka_preview"))
assets = [preview, *ready_assets] if preview["exists"] else ready_assets
total_size = _directory_size(package_dir)
return {
"schema": "real2sim.motrixsim_asset_package.v1",
"name": name,
"status": "asset_imported_adapter_pending",
"created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"package_dir": str(package_dir),
"scene_descriptor": str(scene_descriptor),
"source": {
"repo": "https://github.com/Motphys/motrixsim-docs",
"docs": "https://motrixsim.readthedocs.io/zh-cn/latest/user_guide/overview/examples.html",
"local_path": str(source),
"commit": source_commit,
},
"ready_assets": ready_assets,
"assets": assets,
"adapter_plan": {
"goal": "将 parlour 客厅场景中的人形机器人示例替换为 RM65 机械臂,并在茶几区域完成 pick-place。",
"base_scene": "assets/parlour/parlour.xml",
"robot_asset": "assets/rm65_open_cabinet/mjx_rm65.xml",
"reference_controller": "examples/control/rm65_open_cabinet.py",
"pick_place_template": "assets/franka_emika_panda/scene_pick_cube.xml",
"recommended_steps": [
"在 parlour 中定位茶几 mesh/collision,并确定表面高度与可达工作区。",
"把 RM65 base 固定到茶几旁或茶几边缘,完成 z-up 坐标、尺度和碰撞组检查。",
"把 Franka pick-cube 的目标物、home/grasp/lift 阶段迁移到 RM65 关节空间。",
"将 RM65 开柜门示例中的 7 维动作和 gripper 控制改成 cube pick-place controller。",
"生成 combined MJCF 后再进入 simulator_validation runtime_required。",
],
},
"runbook": {
"source_parlour_demo": "uv run examples/control/robot_locomotion.py --robot g1 --scene parlour",
"source_rm65_demo": "uv run examples/control/rm65_open_cabinet.py",
"source_pick_template": "uv run examples/bench/grasp/shake_test_mx.py --object cube",
},
"known_gaps": [
"当前包是资产接入 scaffold,不是可直接运行的 combined MJCF。",
"尚未完成 parlour 茶几 mesh 的语义定位和 RM65 base 位姿标定。",
"尚未把 Franka pick-cube keyframe/controller 迁移到 RM65。",
],
"metrics": {
"asset_count": sum(1 for path in package_dir.rglob("*") if path.is_file()),
"total_size_bytes": total_size,
"copied_directories": sorted(DIRECTORIES_TO_COPY),
},
}
def _asset(package_dir: Path, rel: str, role: str, kind: str, name: str, url: str | None = None) -> dict[str, Any]:
path = package_dir / rel
return {
"name": name,
"role": role,
"kind": kind,
"path": str(path),
"relative_path": rel,
"url": url or "",
"exists": path.is_file(),
"size_bytes": path.stat().st_size if path.is_file() else 0,
}
def _upsert_scene(
*,
store: PlatformStore,
name: str,
package_dir: Path,
scene_descriptor: Path,
manifest_path: Path,
manifest: dict[str, Any],
replace_index: bool,
) -> dict[str, Any]:
try:
existing = store.get_scene(SCENE_ID)
except KeyError:
existing = None
if existing and not replace_index:
store.update_scene(SCENE_ID, name=name, tags=_tags(), version=str(manifest["source"]["commit"]))
return store.get_scene(SCENE_ID)
if existing and replace_index:
store.delete_scene(SCENE_ID)
return store.create_scene(
item_id=SCENE_ID,
name=name,
path=scene_descriptor,
metadata={
"package": str(package_dir),
"manifest_path": str(manifest_path),
"simulator": "motrixsim",
"status": "asset_imported_adapter_pending",
"adapter_pending": True,
},
source_type="motrixsim_docs",
source_uri="https://github.com/Motphys/motrixsim-docs",
version=str(manifest["source"]["commit"]),
manifest_path=manifest_path,
metrics=manifest["metrics"],
tags=_tags(),
)
def _tags() -> list[str]:
return ["motrixsim", "parlour", "rm65", "pick-place", "adapter-pending"]
def _git_commit(source: Path) -> str:
try:
return subprocess.check_output(["git", "-C", str(source), "rev-parse", "HEAD"], text=True).strip()
except (OSError, subprocess.CalledProcessError):
return ""
def _existing_source_commit(package_dir: Path) -> str:
manifest_path = package_dir / "motrixsim_scene_manifest.json"
if not manifest_path.is_file():
return ""
try:
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
except json.JSONDecodeError:
return ""
return str((manifest.get("source") or {}).get("commit") or "")
def _directory_size(path: Path) -> int:
return sum(item.stat().st_size for item in path.rglob("*") if item.is_file())
def _artifact_kind(path: Path) -> str:
suffix = path.suffix.lower()
if suffix in {".png", ".jpg", ".jpeg", ".webp"}:
return "image"
if suffix == ".xml":
return "simulator"
if suffix == ".py":
return "controller"
if suffix == ".json":
return "metadata"
return suffix.lstrip(".") or "file"
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -0,0 +1,52 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
from pathlib import Path
from real2sim_platform.source_revision import read_source_revision
OPTIONAL_IMPORT = "from airbot_data_collection.tools.av_coder import AvCoder"
OPTIONAL_REPLACEMENT = '''try:
from airbot_data_collection.tools.av_coder import AvCoder
except ModuleNotFoundError as exc:
_AIRBOT_DATA_COLLECTION_ERROR = str(exc)
class AvCoder:
def __init__(self, *args, **kwargs):
raise RuntimeError(
"airbot_data_collection is required only for MCAP decoding or AIRBOT hardware evaluation; "
"it is not required for Real2Sim HDF5 ACT training"
) from RuntimeError(_AIRBOT_DATA_COLLECTION_ERROR)
'''
def main() -> int:
parser = argparse.ArgumentParser(description="Prepare pinned DISCOVERSE ACT for server-side HDF5 training.")
parser.add_argument("--act-root", type=Path, required=True)
parser.add_argument("--expected-commit", required=True)
args = parser.parse_args()
root = args.act_root.resolve()
commit = read_source_revision(root)
if commit != args.expected_commit:
raise SystemExit(f"ACT revision mismatch: expected {args.expected_commit}, got {commit}")
target = root / "utils" / "utils.py"
changed = patch_optional_airbot_dependency(target)
print(json.dumps({"ok": True, "act_root": str(root), "commit": commit, "patched": changed}, indent=2))
return 0
def patch_optional_airbot_dependency(path: Path) -> bool:
source = path.read_text(encoding="utf-8")
if OPTIONAL_REPLACEMENT in source:
return False
if OPTIONAL_IMPORT not in source:
raise RuntimeError(f"expected AIRBOT dependency import was not found in {path}")
path.write_text(source.replace(OPTIONAL_IMPORT, OPTIONAL_REPLACEMENT, 1), encoding="utf-8")
return True
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -0,0 +1,441 @@
#!/usr/bin/env bash
set -euo pipefail
KEY="${REAL2SIM_WUYING_KEY:-/Users/d-robotics/workSpace/document/80-private/orgs/drobotics/keys/wuying-39.106.101.95_ed25519}"
HOST="${REAL2SIM_WUYING_HOST:-root@39.106.101.95}"
BASE_URL="${REAL2SIM_ACCEPTANCE_BASE_URL:-http://127.0.0.1:18126}"
MODE="${REAL2SIM_ACCEPTANCE_MODE:-production}"
SCALE="${REAL2SIM_ACCEPTANCE_SCALE:-pressure}"
OUT="${REAL2SIM_ACCEPTANCE_OUT:-/opt/real2sim2model/real2sim-platform/workspace/acceptance_runs}"
HF_REPO="${REAL2SIM_ACCEPTANCE_HF_REPO:-shashuo0104/xarm7_pusht}"
HF_PATTERNS="${REAL2SIM_ACCEPTANCE_HF_PATTERNS:-videos/chunk-000/observation.images.front/*.mp4,data/chunk-000/*.parquet,meta/**,README.md}"
RECON_FIXTURE="${REAL2SIM_ACCEPTANCE_RECON_FIXTURE:-/opt/real2sim_paper_runtime/sam-3d-objects/notebook/images/shutterstock_modern_colorful_Interior_2620125197}"
RECON_FALLBACKS="${REAL2SIM_ACCEPTANCE_RECON_FALLBACKS:-/opt/real2sim_paper_runtime/sam2/notebooks/videos/bedroom}"
MIN_RECON_FRAMES="${REAL2SIM_ACCEPTANCE_MIN_RECON_FRAMES:-80}"
TARGET_HF_FRAMES="${REAL2SIM_ACCEPTANCE_TARGET_HF_FRAMES:-240}"
MIN_HF_FRAMES="${REAL2SIM_ACCEPTANCE_MIN_HF_FRAMES:-120}"
TIMEOUT_SECONDS="${REAL2SIM_ACCEPTANCE_TIMEOUT_SECONDS:-7200}"
REQUIRE_MOTRIXSIM="${REAL2SIM_REQUIRE_MOTRIXSIM:-0}"
REPEAT_RECONSTRUCTIONS="${REAL2SIM_ACCEPTANCE_REPEAT_RECONSTRUCTIONS:-2}"
PRESSURE_TASKS="${REAL2SIM_ACCEPTANCE_PRESSURE_TASKS:-12}"
CONTINUE_AFTER_RECON_QUALITY_FAIL="${REAL2SIM_ACCEPTANCE_CONTINUE_AFTER_RECON_QUALITY_FAIL:-1}"
ssh -i "$KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new "$HOST" \
env \
REAL2SIM_ACCEPTANCE_BASE_URL="$BASE_URL" \
REAL2SIM_ACCEPTANCE_MODE="$MODE" \
REAL2SIM_ACCEPTANCE_SCALE="$SCALE" \
REAL2SIM_ACCEPTANCE_OUT="$OUT" \
REAL2SIM_ACCEPTANCE_HF_REPO="$HF_REPO" \
REAL2SIM_ACCEPTANCE_HF_PATTERNS="$HF_PATTERNS" \
REAL2SIM_ACCEPTANCE_RECON_FIXTURE="$RECON_FIXTURE" \
REAL2SIM_ACCEPTANCE_RECON_FALLBACKS="$RECON_FALLBACKS" \
REAL2SIM_ACCEPTANCE_MIN_RECON_FRAMES="$MIN_RECON_FRAMES" \
REAL2SIM_ACCEPTANCE_TARGET_HF_FRAMES="$TARGET_HF_FRAMES" \
REAL2SIM_ACCEPTANCE_MIN_HF_FRAMES="$MIN_HF_FRAMES" \
REAL2SIM_ACCEPTANCE_TIMEOUT_SECONDS="$TIMEOUT_SECONDS" \
REAL2SIM_REQUIRE_MOTRIXSIM="$REQUIRE_MOTRIXSIM" \
REAL2SIM_ACCEPTANCE_REPEAT_RECONSTRUCTIONS="$REPEAT_RECONSTRUCTIONS" \
REAL2SIM_ACCEPTANCE_PRESSURE_TASKS="$PRESSURE_TASKS" \
REAL2SIM_ACCEPTANCE_CONTINUE_AFTER_RECON_QUALITY_FAIL="$CONTINUE_AFTER_RECON_QUALITY_FAIL" \
python3 -s <<'PY'
from __future__ import annotations
import json
import os
import sys
import time
import traceback
import urllib.error
import urllib.request
from pathlib import Path
from typing import Any
BASE = os.environ["REAL2SIM_ACCEPTANCE_BASE_URL"].rstrip("/")
MODE = os.environ["REAL2SIM_ACCEPTANCE_MODE"]
SCALE = os.environ["REAL2SIM_ACCEPTANCE_SCALE"]
OUT_ROOT = Path(os.environ["REAL2SIM_ACCEPTANCE_OUT"])
HF_REPO = os.environ["REAL2SIM_ACCEPTANCE_HF_REPO"]
HF_PATTERNS = [item.strip() for item in os.environ["REAL2SIM_ACCEPTANCE_HF_PATTERNS"].split(",") if item.strip()]
RECON_FIXTURE = os.environ["REAL2SIM_ACCEPTANCE_RECON_FIXTURE"]
RECON_FALLBACKS = [item.strip() for item in os.environ["REAL2SIM_ACCEPTANCE_RECON_FALLBACKS"].split(":") if item.strip()]
MIN_RECON_FRAMES = int(os.environ["REAL2SIM_ACCEPTANCE_MIN_RECON_FRAMES"])
TARGET_HF_FRAMES = int(os.environ["REAL2SIM_ACCEPTANCE_TARGET_HF_FRAMES"])
MIN_HF_FRAMES = int(os.environ["REAL2SIM_ACCEPTANCE_MIN_HF_FRAMES"])
TIMEOUT = int(os.environ["REAL2SIM_ACCEPTANCE_TIMEOUT_SECONDS"])
REQUIRE_MOTRIXSIM = os.environ["REAL2SIM_REQUIRE_MOTRIXSIM"] == "1"
REPEAT_RECONSTRUCTIONS = int(os.environ["REAL2SIM_ACCEPTANCE_REPEAT_RECONSTRUCTIONS"])
PRESSURE_TASKS = int(os.environ["REAL2SIM_ACCEPTANCE_PRESSURE_TASKS"])
CONTINUE_AFTER_RECON_QUALITY_FAIL = os.environ["REAL2SIM_ACCEPTANCE_CONTINUE_AFTER_RECON_QUALITY_FAIL"] == "1"
TERMINAL_STATUSES = {"succeeded", "failed", "canceled", "failed_recovered"}
started_at = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
run_dir = OUT_ROOT / time.strftime("%Y%m%dT%H%M%SZ", time.gmtime())
run_dir.mkdir(parents=True, exist_ok=True)
report: dict[str, Any] = {
"schema": "real2sim.acceptance_report.v1",
"mode": MODE,
"scale": SCALE,
"started_at": started_at,
"finished_at": "",
"base_url": BASE,
"inputs": {
"hf_repo": HF_REPO,
"hf_patterns": HF_PATTERNS,
"reconstruction_fixture": RECON_FIXTURE,
"reconstruction_fallbacks": RECON_FALLBACKS,
"min_reconstruction_frames": MIN_RECON_FRAMES,
"target_hf_frames": TARGET_HF_FRAMES,
"min_hf_frames": MIN_HF_FRAMES,
"repeat_reconstructions": REPEAT_RECONSTRUCTIONS,
"pressure_tasks": PRESSURE_TASKS,
"require_motrixsim": REQUIRE_MOTRIXSIM,
"continue_after_reconstruction_quality_fail": CONTINUE_AFTER_RECON_QUALITY_FAIL,
},
"version": {},
"doctor": {},
"tasks": [],
"datasets": [],
"scenes": [],
"models": [],
"browser": {},
"viewer_probe": {
"status": "not_run",
"reason": "Run scripts/scene_viewer_probe_local.mjs separately; production API acceptance does not launch local Playwright.",
},
"screenshots": [],
"artifacts": [],
"warnings": [],
"failures": [],
"pass": False,
}
def api(path: str, payload: Any | None = None, timeout: int = 60) -> Any:
data = None
headers = {}
if payload is not None:
data = json.dumps(payload).encode("utf-8")
headers["Content-Type"] = "application/json"
req = urllib.request.Request(BASE + path, data=data, headers=headers)
try:
with urllib.request.urlopen(req, timeout=timeout) as response:
body = response.read().decode("utf-8")
if not body:
return None
ctype = response.headers.get("content-type", "")
return json.loads(body) if "application/json" in ctype else body
except urllib.error.HTTPError as exc:
detail = exc.read().decode("utf-8", errors="replace")
raise RuntimeError(f"{path} failed with HTTP {exc.code}: {detail}") from exc
def record_failure(message: str, **context: Any) -> None:
failure = {"message": message, **context}
print("FAIL:", json.dumps(failure, ensure_ascii=False), flush=True)
report["failures"].append(failure)
def save_report() -> None:
report["finished_at"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
(run_dir / "acceptance_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
lines = [
"# Real2Sim Production Acceptance",
"",
f"- pass: {str(report['pass']).lower()}",
f"- started_at: {report['started_at']}",
f"- finished_at: {report['finished_at']}",
f"- build_id: {report.get('version', {}).get('build_id', '')}",
f"- tasks: {len(report['tasks'])}",
f"- failures: {len(report['failures'])}",
f"- warnings: {len(report['warnings'])}",
f"- viewer_probe: {report.get('viewer_probe', {}).get('status', 'not_run')}",
"",
"## Task IDs",
]
for task in report["tasks"]:
lines.append(f"- {task.get('type')} {task.get('id')} {task.get('status')}")
if report["failures"]:
lines.extend(["", "## Failures"])
for failure in report["failures"]:
lines.append(f"- {failure.get('message')} {json.dumps(failure, ensure_ascii=False)[:600]}")
if report["warnings"]:
lines.extend(["", "## Warnings"])
for warning in report["warnings"]:
lines.append(f"- {warning}")
(run_dir / "summary.md").write_text("\n".join(lines) + "\n", encoding="utf-8")
def task_snapshot(task_id: str) -> dict[str, Any]:
task = api(f"/api/tasks/{task_id}")
try:
reports = api(f"/api/tasks/{task_id}/reports")
except Exception as exc:
reports = {"error": str(exc), "reports": []}
try:
artifacts = api(f"/api/tasks/{task_id}/artifacts")
except Exception as exc:
artifacts = [{"error": str(exc)}]
try:
logs = api(f"/api/tasks/{task_id}/logs")
except Exception as exc:
logs = f"log unavailable: {exc}"
snapshot = {
"id": task["id"],
"type": task["type"],
"status": task["status"],
"params": task.get("params"),
"result": task.get("result"),
"error": task.get("error"),
"run_dir": task.get("run_dir"),
"reports": reports,
"artifacts": artifacts,
"log_tail": str(logs)[-5000:],
}
(run_dir / f"task_{task_id}.json").write_text(json.dumps(snapshot, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
return snapshot
def wait_task(task_id: str, *, required: bool = True) -> dict[str, Any]:
deadline = time.time() + TIMEOUT
while time.time() < deadline:
task = api(f"/api/tasks/{task_id}")
if task["status"] in TERMINAL_STATUSES:
snapshot = task_snapshot(task_id)
report["tasks"].append(snapshot)
if required and task["status"] != "succeeded":
record_failure(f"required task {task['type']} did not succeed", task_id=task_id, status=task["status"], error=task.get("error"))
print(json.dumps({"task_id": task_id, "type": task["type"], "status": task["status"]}, ensure_ascii=False), flush=True)
return snapshot
time.sleep(5)
snapshot = task_snapshot(task_id)
report["tasks"].append(snapshot)
record_failure("task timed out", task_id=task_id)
if required:
raise TimeoutError(task_id)
return snapshot
def create_task(task_type: str, params: dict[str, Any], *, required: bool = True) -> dict[str, Any]:
task = api("/api/tasks", {"type": task_type, "params": params})
print(f"{task_type}: {task['id']}", flush=True)
return wait_task(task["id"], required=required)
def assert_artifacts(task: dict[str, Any], required_names: list[str] | None = None) -> None:
artifacts = task.get("artifacts") or []
names = {item.get("name") for item in artifacts}
if not artifacts:
record_failure("succeeded task has no artifacts", task_id=task.get("id"), task_type=task.get("type"))
for name in required_names or []:
if name not in names:
record_failure("required artifact missing", task_id=task.get("id"), task_type=task.get("type"), artifact=name, available=sorted(n for n in names if n))
for item in artifacts:
if item.get("name"):
report["artifacts"].append({"task_id": task.get("id"), "name": item.get("name"), "path": item.get("path"), "kind": item.get("kind")})
def refresh_entities() -> None:
report["datasets"] = api("/api/datasets")
report["scenes"] = api("/api/scenes")
report["models"] = api("/api/models")
def check_doctor() -> None:
report["version"] = api("/api/version")
doctor = api("/api/doctor")
report["doctor"] = doctor
checks = doctor.get("checks", {})
required = ["anysplat_root", "anysplat_python", "spark_bundle", "mujoco_python", "media_prepare_deps", "service_process"]
for name in required:
if not checks.get(name):
record_failure("doctor required check failed", check=name, value=checks.get(name))
for warning in doctor.get("warnings", []) or []:
report["warnings"].append(f"doctor: {warning}")
if not doctor.get("ok"):
record_failure("doctor returned ok=false", doctor=doctor)
def latest_scene_id(task: dict[str, Any]) -> str:
scene_id = (((task.get("result") or {}).get("scene_id")) or "")
if not scene_id:
record_failure("scene task did not return scene_id", task_id=task.get("id"))
return scene_id
def run_pressure_tasks(scene_id: str, expert_dataset_id: str, model_id: str, reconstruction_input: str) -> None:
queued = []
templates = [
("simulator_validation", {"scene_id": scene_id, "simulators": ["mujoco", "motrixsim"], "level": "runtime_if_available"}),
("expert_collection", {"scene_id": scene_id, "episodes": 3, "steps": 24}),
("training", {"dataset_id": expert_dataset_id, "epochs": 1}),
("inference", {"scene_id": scene_id, "model_id": model_id, "steps": 40}),
("reconstruction_preflight", {"input_path": reconstruction_input, "min_frames": MIN_RECON_FRAMES}),
]
for index in range(max(PRESSURE_TASKS, 12)):
task_type, params = templates[index % len(templates)]
task = api("/api/tasks", {"type": task_type, "params": params})
queued.append(task)
print(f"pressure {index + 1}: {task_type} {task['id']}", flush=True)
for task in queued:
wait_task(task["id"], required=True)
active = [task for task in api("/api/tasks") if task.get("status") in {"queued", "running", "canceling"}]
if active:
record_failure("active tasks remain after pressure batch", active=active[:20])
def select_reconstruction_input() -> tuple[str, dict[str, Any]]:
candidates = [RECON_FIXTURE, *RECON_FALLBACKS]
snapshots = []
for index, candidate in enumerate(candidates):
preflight = create_task("reconstruction_preflight", {
"input_path": candidate,
"min_frames": MIN_RECON_FRAMES,
})
assert_artifacts(preflight, ["capture_preflight_report.json"])
snapshots.append(preflight)
result = preflight.get("result") or {}
if result.get("ok"):
if index > 0:
report["warnings"].append(f"primary reconstruction fixture failed preflight; using fallback: {candidate}")
return candidate, preflight
report["warnings"].append(f"reconstruction fixture candidate failed preflight: {candidate}")
record_failure("no reconstruction fixture passed preflight", candidates=candidates)
return candidates[0], snapshots[-1] if snapshots else {}
def reconstruction_failed_on_quality_gate(task: dict[str, Any]) -> bool:
reports = task.get("reports") or {}
readable = str(reports.get("readable_error") or task.get("error") or "")
for report_item in reports.get("reports", []) or []:
payload = report_item.get("payload") or {}
readable += " " + str(payload.get("readable_error") or payload.get("decision") or "")
readable += " " + " ".join(str(item) for item in payload.get("blockers", []) or [])
return any(marker in readable for marker in ["allow-low-quality", "capture acceptance failed", "recapture_required", "registered_ratio", "sparse_points"])
def run_reconstruction_with_optional_continuation(reconstruction_input: str, repeat_index: int) -> dict[str, Any]:
params = {
"input_path": reconstruction_input,
"dry_run": False,
"renderer": "spark",
"simulators": ["mujoco", "motrixsim"],
"min_frames": MIN_RECON_FRAMES,
"quality_preset": "capture-high",
}
strict = create_task("scene_reconstruction", params)
if strict.get("status") == "succeeded":
assert_artifacts(strict, ["environment.json", "reconstruction_command.json", "capture_preflight_report.json", "reconstruction_report.json", "scene_manifest.json"])
return strict
assert_artifacts(strict, ["capture_preflight_report.json", "reconstruction_report.json"])
if not (CONTINUE_AFTER_RECON_QUALITY_FAIL and reconstruction_failed_on_quality_gate(strict)):
raise RuntimeError(f"scene_reconstruction failed: {strict.get('id')}")
report["warnings"].append(f"strict reconstruction {strict.get('id')} failed quality gate; continuing with allow_low_quality for downstream coverage")
continuation_params = {**params, "allow_low_quality": True, "name": f"acceptance-continuation-{repeat_index}"}
continuation = create_task("scene_reconstruction", continuation_params)
if continuation.get("status") != "succeeded":
assert_artifacts(continuation, ["capture_preflight_report.json", "reconstruction_report.json"])
raise RuntimeError(f"allow_low_quality scene_reconstruction failed: {continuation.get('id')}")
assert_artifacts(continuation, ["environment.json", "reconstruction_command.json", "capture_preflight_report.json", "reconstruction_report.json", "scene_manifest.json"])
return continuation
def main() -> int:
try:
check_doctor()
hf_import = create_task("hf_import", {
"repo_id": HF_REPO,
"repo_type": "dataset",
"allow_patterns": HF_PATTERNS,
"local_name": "acceptance-xarm7-pusht",
})
assert_artifacts(hf_import)
hf_dataset_id = (hf_import.get("result") or {}).get("dataset_id")
if not hf_dataset_id:
record_failure("hf_import did not return dataset_id", task_id=hf_import.get("id"))
media = create_task("media_prepare", {
"dataset_id": hf_dataset_id,
"camera_label": "observation.images.front",
"sample_fps": 2,
"max_frames_per_video": 80,
"max_videos": 16,
"target_frame_count": TARGET_HF_FRAMES,
"min_total_frames": MIN_HF_FRAMES,
"output_name": "acceptance-xarm7-pusht-prepared",
})
assert_artifacts(media)
prepared_id = (media.get("result") or {}).get("dataset_id")
frame_count = int((media.get("result") or {}).get("frame_count") or 0)
if frame_count < MIN_HF_FRAMES:
record_failure("media_prepare produced too few frames", frame_count=frame_count, minimum=MIN_HF_FRAMES)
hf_preflight = create_task("reconstruction_preflight", {
"dataset_id": prepared_id,
"min_frames": MIN_RECON_FRAMES,
"allow_low_quality": True,
})
assert_artifacts(hf_preflight, ["capture_preflight_report.json"])
reconstruction_input, fixture_preflight = select_reconstruction_input()
if not ((fixture_preflight.get("result") or {}).get("ok")):
raise RuntimeError("no reconstruction input passed preflight")
reconstruction_tasks = []
for index in range(max(REPEAT_RECONSTRUCTIONS, 2)):
reconstruction_tasks.append(run_reconstruction_with_optional_continuation(reconstruction_input, index + 1))
scene_id = latest_scene_id(reconstruction_tasks[-1])
if not scene_id:
raise RuntimeError("scene_reconstruction did not produce scene_id")
validation = create_task("simulator_validation", {
"scene_id": scene_id,
"simulators": ["mujoco", "motrixsim"],
"level": "runtime_required" if REQUIRE_MOTRIXSIM else "runtime_if_available",
})
assert_artifacts(validation, ["validation_report.json"])
validation_report = (validation.get("result") or {}).get("report") or {}
motrix = (validation_report.get("simulators") or {}).get("motrixsim") or {}
if REQUIRE_MOTRIXSIM and not motrix.get("ok"):
record_failure("MotrixSim runtime is required but validation failed", motrix=motrix)
elif not motrix.get("ok"):
report["warnings"].append(f"motrixsim validation not fully ok: {motrix.get('reason') or motrix.get('status')}")
expert = create_task("expert_collection", {"scene_id": scene_id, "episodes": 12, "steps": 48, "name": "acceptance-expert-rollouts"})
assert_artifacts(expert, ["manifest.json", "rollouts.jsonl"])
expert_dataset_id = (expert.get("result") or {}).get("dataset_id")
if not expert_dataset_id:
record_failure("expert_collection did not return dataset_id", task_id=expert.get("id"))
training = create_task("training", {"dataset_id": expert_dataset_id, "epochs": 3, "name": "acceptance-policy"})
assert_artifacts(training, ["model_card.json", "policy_head.json"])
model_id = (training.get("result") or {}).get("model_id")
if not model_id:
record_failure("training did not return model_id", task_id=training.get("id"))
inference = create_task("inference", {"scene_id": scene_id, "model_id": model_id, "steps": 80})
assert_artifacts(inference, ["prediction_rollout.json", "viewer.html"])
if int((inference.get("result") or {}).get("rollout_steps") or 0) <= 0:
record_failure("inference produced empty rollout", task_id=inference.get("id"), result=inference.get("result"))
run_pressure_tasks(scene_id, expert_dataset_id, model_id, reconstruction_input)
refresh_entities()
report["pass"] = len(report["failures"]) == 0
save_report()
print(json.dumps({"pass": report["pass"], "run_dir": str(run_dir), "report": str(run_dir / "acceptance_report.json")}, ensure_ascii=False), flush=True)
return 0 if report["pass"] else 1
except Exception as exc:
record_failure("acceptance runner crashed", error=str(exc), traceback=traceback.format_exc())
try:
refresh_entities()
except Exception:
pass
report["pass"] = False
save_report()
print(json.dumps({"pass": False, "run_dir": str(run_dir), "report": str(run_dir / "acceptance_report.json"), "error": str(exc)}, ensure_ascii=False), flush=True)
return 1
sys.exit(main())
PY

View File

@ -1,157 +0,0 @@
"""Build launch videos from captured UI and actual Genesis footage. macOS + FFmpeg."""
import argparse
import json
from pathlib import Path
import shutil
import subprocess
from PIL import Image, ImageDraw, ImageFont
ROOT = Path(__file__).resolve().parents[1]
MEDIA = ROOT / "artifacts/media"
OUT = ROOT / "artifacts/release"
OUT.mkdir(parents=True, exist_ok=True)
FONT = "/System/Library/Fonts/Hiragino Sans GB.ttc"
MONO = "/System/Library/Fonts/Menlo.ttc"
SCENES = json.loads((ROOT / "docs/media/storyboard.json").read_text())
INK, MUTED, GREEN = "#172624", "#566b66", "#087f70"
SIZE = (1920, 1080)
def run(*args):
subprocess.run([str(a) for a in args], check=True)
def probe(file):
return json.loads(subprocess.check_output(["ffprobe", "-v", "error", "-show_format", "-show_streams", "-of", "json", str(file)]))
def text(draw, value, x, y, size=42, fill=INK, width=1740, center=False, mono=False):
font = ImageFont.truetype(MONO if mono else FONT, size)
lines, line = [], ""
for char in value:
if char == "\n" or (line and draw.textlength(line + char, font=font) > width):
lines.append(line)
line = "" if char == "\n" else char
else:
line += char
if line:
lines.append(line)
for line in lines:
px = x + (width - draw.textlength(line, font=font)) / 2 if center else x
draw.text((px, y), line, font=font, fill=fill)
y += int(size * 1.4)
return y
def slide(kind):
image = Image.new("RGB", SIZE, "#edf3f2")
draw = ImageDraw.Draw(image)
if kind == "package":
text(draw, "A REPRODUCIBLE SCENE PACKAGE", 110, 180, 38, GREEN)
rows = [("assets/model.glb", "MIT procedural mesh"), ("manifest.json", "Gravity + solver parameters"), ("flex-profile.json", "Current material preset"), ("genesis_scene.py", "Runnable Genesis entry point"), ("requirements.txt", "Pinned direct dependencies")]
for i, (name, detail) in enumerate(rows):
y = 290 + i * 100
draw.line((110, y + 78, 1800, y + 78), fill="#cad8d4", width=2)
text(draw, name, 110, y, 40, mono=True, width=800)
text(draw, detail, 980, y, 34, MUTED, width=810)
elif kind == "metrics":
metrics = json.loads((MEDIA / "metrics.json").read_text())
rows = [f"Genesis {metrics['genesis_version']} / CPU", f"{metrics['steps']} steps x {metrics['dt']:.3f} s", f"{metrics['vertex_count']} simulated vertices", f"{metrics['max_shape_deformation_m'] * 100:.1f} cm max shape deformation", "Finite trajectory / ground contact"]
text(draw, "MEASURED IN THIS SAMPLE RUN", 110, 180, 38, GREEN)
for i, value in enumerate(rows):
text(draw, value, 110, 290 + i * 100, 47)
text(draw, "Not a material calibration or real-world accuracy benchmark.", 110, 830, 30, MUTED)
elif kind == "limits":
text(draw, "v0.1.0 ALPHA", 110, 180, 40, GREEN)
rows = ["Local single-user workbench", "Optional DashScope / Tripo service fees", "Known Python dependency advisories", "Trusted sample only, in an isolated environment", "Cloth export is experimental"]
for i, value in enumerate(rows):
text(draw, value, 110, 290 + i * 100, 43)
else:
text(draw, "Real2Sim Studio", 110, 190, 100)
text(draw, "MIT-LICENSED WORKBENCH + PROCEDURAL SAMPLE", 115, 355, 31, GREEN)
text(draw, "npm ci\nnpm run demo", 115, 455, 53, mono=True)
text(draw, "github.com/eust-w/real2sim-platform", 115, 690, 48, GREEN)
text(draw, "v0.1.0 Alpha | See README and SECURITY.md before running.", 115, 810, 29, MUTED)
file = MEDIA / f"slide-{kind}.png"
image.save(file)
return file
def overlay(index, scene, lang, vertical=False):
width, height = (1080, 1920) if vertical else SIZE
image = Image.new("RGBA", (width, height), (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
header, footer = (260, 390) if vertical else (132, 184)
draw.rectangle((0, 0, width, header), fill="#f6f9f8")
draw.rectangle((0, height - footer, width, height), fill="#172624")
title = scene["title"] if lang == "zh" else scene["enTitle"]
text(draw, "Real2Sim Studio / v0.1.0 Alpha", 48, 24, 25, GREEN, width=width-96)
text(draw, title, 48, 77, 48 if vertical else 46, width=width - 96)
caption = scene[lang]
text(draw, caption, 60, height - footer + 30, 42 if vertical else 36, "#ffffff", width=width-120, center=True)
label = "Genesis FEM / CPU / 0.2x replay" if scene["source"] == "physics" else "Actual workbench capture" if scene["source"] in ("ui", "settings") else "Reproducible Alpha / see repository"
text(draw, label, 48, height - footer - 43, 23, INK, width=width-96)
text(draw, "Synthetic narration / no cloned voice" if lang == "en" else "合成配音 · 非真人仿声", 48, height-55, 23, "#b5ccc5", width=width-96)
draw.rectangle((0, height - 7, int(width * (index + 1) / (5 if vertical else 10)), height), fill="#24bfa8")
file = MEDIA / f"overlay-{lang}-{'v' if vertical else 'h'}-{index}.png"
image.save(file)
return file
def audio(index, scene):
file = MEDIA / f"voice-{index}.aiff"
if not file.exists():
run("say", "-v", "Tingting", "-r", "190", "-o", file, scene["zh"])
return file
def render(lang="zh", vertical=False):
selection = [0, 2, 4, 6, 9] if vertical else list(range(10))
segments, subtitles, cursor = [], [], 0
for out_index, index in enumerate(selection):
scene = SCENES[index]
duration = scene["duration"]
voice = audio(index, scene)
voice_duration = float(probe(voice)["format"]["duration"])
tempo = max(1, voice_duration / (duration - 0.7))
source = scene["source"]
inputs = []
if source == "physics":
inputs = ["-stream_loop", "-1", "-i", MEDIA / "simulation.mp4"]
transform = "setpts=5*PTS,crop=520:640:380:40,scale=1080:1330,pad=1080:1920:0:270:color=0xedf3f2" if vertical else "setpts=5*PTS,crop=1000:500:140:140,scale=1720:860,pad=1920:1080:100:132:color=0xedf3f2"
elif source in ("ui", "settings"):
file = MEDIA / ("mobile.webm" if vertical else "workbench.webm")
inputs = ["-stream_loop", "-1", "-ss", "10" if source == "settings" else "4", "-i", file]
transform = "scale=900:1600,pad=1080:1920:90:200:color=0xedf3f2" if vertical else "scale=1568:882,pad=1920:1080:176:132:color=0xedf3f2"
else:
file = slide(source)
inputs = ["-loop", "1", "-framerate", "30", "-i", file]
transform = "scale=1080:608,pad=1080:1920:0:520:color=0xedf3f2" if vertical else "null"
cover = overlay(out_index, scene, lang, vertical)
output = MEDIA / f"segment-{lang}-{'v' if vertical else 'h'}-{out_index}.mp4"
run("ffmpeg", "-y", "-loglevel", "error", *inputs, "-loop", "1", "-i", cover, "-i", voice,
"-filter_complex", f"[0:v]{transform},setsar=1,fps=30[base];[base][1:v]overlay=0:0,format=yuv420p[v];[2:a]atempo={tempo:.5f},apad,atrim=duration={duration},loudnorm=I=-16:TP=-1.5:LRA=11[a]",
"-map", "[v]", "-map", "[a]", "-t", duration, "-c:v", "libx264", "-preset", "fast", "-crf", "20", "-threads", "4", "-c:a", "aac", "-b:a", "160k", "-ar", "48000", "-movflags", "+faststart", output)
segments.append(output)
subtitles.append((cursor, cursor + duration, scene[lang]))
cursor += duration
print(f"Rendered {lang} {'vertical' if vertical else 'landscape'} {out_index+1}/{len(selection)}", flush=True)
name = f"real2sim-{'short' if vertical else 'intro'}-{lang}"
listing = MEDIA / f"{name}-concat.txt"
listing.write_text("".join(f"file '{p}'\n" for p in segments))
run("ffmpeg", "-y", "-loglevel", "error", "-f", "concat", "-safe", "0", "-i", listing, "-c", "copy", "-movflags", "+faststart", OUT / f"{name}.mp4")
def timestamp(seconds):
return f"00:{seconds // 60:02}:{seconds % 60:02},000"
(OUT / f"{name}.srt").write_text("\n\n".join(f"{i+1}\n{timestamp(a)} --> {timestamp(b)}\n{caption}" for i, (a, b, caption) in enumerate(subtitles)) + "\n")
run("ffmpeg", "-y", "-loglevel", "error", "-ss", "2", "-i", OUT / f"{name}.mp4", "-frames:v", "1", OUT / f"{name}-cover.jpg")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--language", choices=["zh", "en", "all"], default="all")
parser.add_argument("--vertical", action="store_true")
args = parser.parse_args()
for language in (["zh", "en"] if args.language == "all" else [args.language]):
render(language, args.vertical)
shutil.copyfile(ROOT / "docs/media/storyboard.json", OUT / "storyboard.json")

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
KUBECONFIG_PATH="${REAL2SIM_POC_KUBECONFIG:-/Users/d-robotics/Downloads/poc.config}"
K=(kubectl --kubeconfig "$KUBECONFIG_PATH" -n real2sim-poc)
for deployment in real2sim-frontend real2sim-api real2sim-worker; do
"${K[@]}" rollout undo "deployment/$deployment"
"${K[@]}" rollout status "deployment/$deployment" --timeout=3600s
done
echo "rollback completed; PV and BOS objects were preserved"

View File

@ -0,0 +1,330 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
import math
import sys
import time
from pathlib import Path
from typing import Any
import imageio.v2 as imageio
import numpy as np
SCRIPT_DIR = Path(__file__).resolve().parent
APP_ROOT = SCRIPT_DIR.parent
SRC_ROOT = APP_ROOT / "src"
if str(SRC_ROOT) not in sys.path:
sys.path.insert(0, str(SRC_ROOT))
from real2sim_platform.config import ensure_workspace, load_config # noqa: E402
from real2sim_platform.store import PlatformStore # noqa: E402
SCENE_ID = "1f2618bdfcac4e45456569980716405a"
PACKAGE_SLUG = "parlour_rm65_pick_place"
def main() -> int:
parser = argparse.ArgumentParser(description="Run a scripted RM65 pick-place rollout on the generated smoke MJCF.")
parser.add_argument("--scene-id", default=SCENE_ID)
parser.add_argument("--fps", type=int, default=20)
parser.add_argument("--width", type=int, default=960)
parser.add_argument("--height", type=int, default=540)
parser.add_argument("--no-render", action="store_true")
args = parser.parse_args()
config = load_config()
ensure_workspace(config)
store = PlatformStore(config.db_path)
scene = store.get_scene(args.scene_id)
package_dir = Path(str((scene.get("metadata") or {}).get("package") or config.workspace_dir / "motrixsim_assets" / PACKAGE_SLUG))
manifest_path = Path(str(scene.get("manifest_path") or package_dir / "motrixsim_scene_manifest.json"))
sim_path = package_dir / "simulator_assets/rm65_table_pick_place.xml"
if not sim_path.is_file():
raise SystemExit(f"runtime scene not found: {sim_path}")
rollout_dir = package_dir / "rollouts" / time.strftime("%Y%m%d_%H%M%S")
rollout_dir.mkdir(parents=True, exist_ok=True)
result = run_rollout(
sim_path,
rollout_dir,
fps=args.fps,
width=args.width,
height=args.height,
render=not args.no_render,
)
artifacts = {}
for key, path in result["artifact_paths"].items():
if Path(path).is_file():
artifacts[key] = store.add_artifact(task_id=None, name=Path(path).name, path=Path(path), kind=artifact_kind(Path(path)))
update_manifest(manifest_path, rollout_dir, result, artifacts)
print(json.dumps({"ok": result["ok"], "scene_id": args.scene_id, "rollout_dir": str(rollout_dir), "summary": result["summary"], "artifacts": result["artifact_paths"]}, ensure_ascii=False, indent=2))
return 0 if result["ok"] else 1
def run_rollout(
sim_path: Path,
out_dir: Path,
*,
fps: int,
width: int,
height: int,
render: bool,
) -> dict[str, Any]:
import mujoco
model = mujoco.MjModel.from_xml_path(str(sim_path))
data = mujoco.MjData(model)
mujoco.mj_resetDataKeyframe(model, data, 0)
mujoco.mj_forward(model, data)
site_id = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_SITE, "gripper")
cube_joint = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_JOINT, "pick_cube_free")
cube_qadr = int(model.jnt_qposadr[cube_joint])
cube_geom = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_GEOM, "pick_cube_geom")
finger_geoms = {
mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_GEOM, "left_finger_pad_z_axis"),
mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_GEOM, "right_finger_pad_z_axis"),
}
ctrl_ranges = model.actuator_ctrlrange.copy()
gripper_joint = mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_JOINT, "gripper_Left_1_Joint")
gripper_qadr = int(model.jnt_qposadr[gripper_joint])
joint_ids = [mujoco.mj_name2id(model, mujoco.mjtObj.mjOBJ_JOINT, f"joint_{i}") for i in range(1, 7)]
qpos_adrs = [int(model.jnt_qposadr[jid]) for jid in joint_ids]
dof_adrs = [int(model.jnt_dofadr[jid]) for jid in joint_ids]
duration_scale = 8
phases = [
("home", np.array([0.42, 0.00, 0.72]), 0.0, 35 * duration_scale, False),
("approach", np.array([0.71, 0.015, 0.42]), 0.0, 55 * duration_scale, False),
("descend", np.array([0.71, 0.015, 0.24]), 0.0, 40 * duration_scale, False),
("grasp", np.array([0.71, 0.015, 0.24]), -0.91, 45 * duration_scale, True),
("lift", np.array([0.71, 0.015, 0.60]), -0.91, 200 * duration_scale, True),
("place", np.array([0.43, 0.18, 0.40]), -0.91, 65 * duration_scale, True),
("release", np.array([0.43, 0.18, 0.40]), 0.0, 35 * duration_scale, False),
("retreat", np.array([0.42, 0.00, 0.72]), 0.0, 45 * duration_scale, False),
]
trajectory = []
frames = []
renderer = None
if render:
renderer = mujoco.Renderer(model, height=height, width=width)
contact_steps = 0
bilateral_contact_steps = 0
phase_contacts = {phase: {"contact_steps": 0, "bilateral_contact_steps": 0} for phase, *_ in phases}
contact_force_metrics = {"max_normal": 0.0, "max_tangent": 0.0, "max_normal_z": 0.0, "samples": 0}
gripper_qpos_range = [float(data.qpos[gripper_qadr]), float(data.qpos[gripper_qadr])]
max_cube_z = float(data.qpos[cube_qadr + 2])
initial_cube = data.qpos[cube_qadr : cube_qadr + 3].copy()
settled_cube_z = float(initial_cube[2])
started = time.time()
frame_stride = max(1, round((1.0 / model.opt.timestep) / fps))
step_index = 0
for phase, target, gripper_ctrl, count, _contact_expected in phases:
if phase == "grasp":
settled_cube_z = float(data.qpos[cube_qadr + 2])
max_cube_z = settled_cube_z
q_target = solve_ik(model, data, site_id, target, qpos_adrs, dof_adrs, ctrl_ranges)
for local in range(count):
alpha = (local + 1) / count
current = data.ctrl[:6].copy()
data.ctrl[:6] = current * (1 - alpha) + q_target * alpha
data.ctrl[6] = gripper_ctrl
mujoco.mj_step(model, data)
touching_fingers = cube_finger_contacts(data, cube_geom, finger_geoms)
accumulate_contact_metrics(model, data, cube_geom, finger_geoms, contact_force_metrics)
if touching_fingers:
contact_steps += 1
phase_contacts[phase]["contact_steps"] += 1
if len(touching_fingers) == 2:
bilateral_contact_steps += 1
phase_contacts[phase]["bilateral_contact_steps"] += 1
gripper_qpos_range[0] = min(gripper_qpos_range[0], float(data.qpos[gripper_qadr]))
gripper_qpos_range[1] = max(gripper_qpos_range[1], float(data.qpos[gripper_qadr]))
max_cube_z = max(max_cube_z, float(data.qpos[cube_qadr + 2]))
if step_index % frame_stride == 0:
trajectory.append(sample_state(model, data, phase, step_index, site_id, cube_qadr))
if renderer is not None:
renderer.update_scene(data, camera="overview")
frames.append(renderer.render().copy())
step_index += 1
if renderer is not None:
renderer.close()
trajectory_path = out_dir / "rm65_pick_place_trajectory.json"
report_path = out_dir / "rm65_pick_place_rollout_report.json"
gif_path = out_dir / "rm65_pick_place_rollout.gif"
keyframe_path = out_dir / "rm65_pick_place_final.png"
trajectory_path.write_text(json.dumps({"schema": "real2sim.rm65_pick_place_trajectory.v1", "samples": trajectory}, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
artifact_paths = {"trajectory": str(trajectory_path)}
if frames:
imageio.mimsave(gif_path, frames, fps=fps)
imageio.imwrite(keyframe_path, frames[-1])
artifact_paths["gif"] = str(gif_path)
artifact_paths["final_frame"] = str(keyframe_path)
final = trajectory[-1] if trajectory else {}
final_cube = np.asarray(final.get("cube_pos") or initial_cube, dtype=float)
target_cube = np.array([0.43, 0.18, 0.31])
lift_height = max_cube_z - settled_cube_z
place_error = float(np.linalg.norm(final_cube - target_cube))
physical_success = bilateral_contact_steps > 0 and lift_height >= 0.10 and place_error <= 0.12
summary = {
"mode": "scripted_ik_physical_contact",
"steps": step_index,
"samples": len(trajectory),
"sim_time": float(data.time),
"final_gripper": final.get("gripper_pos"),
"final_cube": final.get("cube_pos"),
"initial_cube": [float(x) for x in initial_cube],
"settled_cube_z": settled_cube_z,
"max_cube_z": max_cube_z,
"lift_height": lift_height,
"place_target": [float(x) for x in target_cube],
"place_error": place_error,
"contact_steps": contact_steps,
"bilateral_contact_steps": bilateral_contact_steps,
"phase_contacts": phase_contacts,
"gripper_qpos_range": gripper_qpos_range,
"contact_force_metrics": contact_force_metrics,
"physical_success": physical_success,
"elapsed_ms": round((time.time() - started) * 1000),
}
report = {
"schema": "real2sim.rm65_pick_place_rollout_report.v1",
"created_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"ok": physical_success,
"runtime": "mujoco",
"scene": str(sim_path),
"summary": summary,
"phases": [phase for phase, *_ in phases],
"note": "Scripted IK with contact-physics grasp; the cube pose is never overwritten. This is not a learned policy.",
}
report_path.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
artifact_paths["report"] = str(report_path)
return {"ok": bool(report["ok"]), "summary": summary, "artifact_paths": artifact_paths}
def cube_finger_contacts(data: Any, cube_geom: int, finger_geoms: set[int]) -> set[int]:
touching: set[int] = set()
for index in range(data.ncon):
contact = data.contact[index]
pair = {int(contact.geom1), int(contact.geom2)}
if cube_geom not in pair:
continue
touching.update(pair & finger_geoms)
return touching
def accumulate_contact_metrics(model: Any, data: Any, cube_geom: int, finger_geoms: set[int], metrics: dict[str, Any]) -> None:
import mujoco
for index in range(data.ncon):
contact = data.contact[index]
pair = {int(contact.geom1), int(contact.geom2)}
if cube_geom not in pair or not (pair & finger_geoms):
continue
force = np.zeros(6)
mujoco.mj_contactForce(model, data, index, force)
metrics["max_normal"] = max(float(metrics["max_normal"]), abs(float(force[0])))
metrics["max_tangent"] = max(float(metrics["max_tangent"]), float(np.linalg.norm(force[1:3])))
metrics["max_normal_z"] = max(float(metrics["max_normal_z"]), abs(float(contact.frame[2])))
metrics["samples"] = int(metrics["samples"]) + 1
def solve_ik(model: Any, data: Any, site_id: int, target: np.ndarray, qpos_adrs: list[int], dof_adrs: list[int], ctrl_ranges: np.ndarray) -> np.ndarray:
import mujoco
q_backup = data.qpos.copy()
q = data.qpos[qpos_adrs].copy()
damping = 1e-3
for _ in range(80):
data.qpos[qpos_adrs] = q
mujoco.mj_forward(model, data)
err = target - data.site_xpos[site_id]
if np.linalg.norm(err) < 0.012:
break
jacp = np.zeros((3, model.nv))
jacr = np.zeros((3, model.nv))
mujoco.mj_jacSite(model, data, jacp, jacr, site_id)
j = jacp[:, dof_adrs]
dq = j.T @ np.linalg.solve(j @ j.T + damping * np.eye(3), err)
q = q + np.clip(dq, -0.08, 0.08)
for i in range(6):
q[i] = float(np.clip(q[i], ctrl_ranges[i, 0], ctrl_ranges[i, 1]))
data.qpos[:] = q_backup
mujoco.mj_forward(model, data)
return q
def sample_state(model: Any, data: Any, phase: str, step: int, site_id: int, cube_qadr: int) -> dict[str, Any]:
return {
"step": step,
"time": float(data.time),
"phase": phase,
"qpos_arm": [float(x) for x in data.qpos[:6]],
"gripper_ctrl": float(data.ctrl[6]),
"gripper_pos": [float(x) for x in data.site_xpos[site_id]],
"cube_pos": [float(x) for x in data.qpos[cube_qadr : cube_qadr + 3]],
}
def update_manifest(manifest_path: Path, rollout_dir: Path, result: dict[str, Any], artifacts: dict[str, dict[str, Any]]) -> None:
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
new_assets = []
for key, artifact in artifacts.items():
path = Path(artifact["path"])
new_assets.append(
{
"name": path.name,
"role": f"rollout_{key}",
"kind": artifact_kind(path),
"path": str(path),
"relative_path": str(path.relative_to(manifest_path.parent)),
"url": f"/api/artifacts/{artifact['id']}/content",
"exists": True,
"size_bytes": path.stat().st_size,
"size_label": format_bytes(path.stat().st_size),
"generated": True,
}
)
old_assets = [item for item in manifest.get("assets", []) if not (isinstance(item, dict) and str(item.get("role", "")).startswith("rollout_"))]
manifest["assets"] = [*new_assets, *old_assets]
manifest["latest_rollout"] = {
"dir": str(rollout_dir),
"summary": result["summary"],
"artifacts": new_assets,
"status": "scripted_rollout_succeeded",
}
manifest["updated_at"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
manifest_path.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
def artifact_kind(path: Path) -> str:
suffix = path.suffix.lower()
if suffix in {".png", ".jpg", ".jpeg", ".webp", ".gif"}:
return "image"
if suffix == ".json":
return "metadata"
return suffix.lstrip(".") or "file"
def format_bytes(value: int) -> str:
units = ["B", "KB", "MB", "GB"]
size = float(value)
for unit in units:
if size < 1024 or unit == units[-1]:
return f"{size:.1f} {unit}" if unit != "B" else f"{int(size)} B"
size /= 1024
return f"{value} B"
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -0,0 +1,244 @@
#!/usr/bin/env node
import { spawn } from "node:child_process";
import { createRequire } from "node:module";
import fs from "node:fs";
import path from "node:path";
const key = process.env.REAL2SIM_WUYING_KEY || "/Users/d-robotics/workSpace/document/80-private/orgs/drobotics/keys/wuying-39.106.101.95_ed25519";
const host = process.env.REAL2SIM_WUYING_HOST || "root@39.106.101.95";
const remotePort = Number(process.env.REAL2SIM_REMOTE_PORT || "18126");
const requestedBase = process.env.REAL2SIM_FRONTEND_BASE_URL || "";
const outRoot = process.env.REAL2SIM_ACCEPTANCE_OUT || path.resolve("real2sim-platform", "workspace", "acceptance_runs", "viewer-probe");
const liveRequired = process.env.REAL2SIM_VIEWER_LIVE_REQUIRED === "1";
const liveTimeoutMs = Number(process.env.REAL2SIM_VIEWER_LIVE_TIMEOUT_MS || "150000");
const sceneIdOverride = process.env.REAL2SIM_VIEWER_SCENE_ID || "";
const timestamp = new Date().toISOString().replace(/[-:]/g, "").replace(/\..*/, "Z");
const outDir = path.join(outRoot, timestamp);
const reportPath = path.join(outDir, "scene_viewer_probe_report.json");
const failures = [];
const warnings = [];
let tunnel = null;
fs.mkdirSync(outDir, { recursive: true });
function fail(message, context = {}) {
failures.push({ message, ...context });
console.error("FAIL:", message, context);
}
function warn(message, context = {}) {
warnings.push({ message, ...context });
console.warn("WARN:", message, context);
}
function writeReport(report) {
fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`);
return report;
}
async function main() {
const startedAt = new Date().toISOString();
const baseUrl = requestedBase || await startTunnel();
const scene = sceneIdOverride ? { id: sceneIdOverride } : await pickPreviewableScene(baseUrl);
let manifestGate = null;
let liveProbe = null;
if (!scene) {
fail("no scene available for viewer probe");
} else {
manifestGate = await validateManifestGate(baseUrl, scene.id);
liveProbe = await runLiveProbe(baseUrl, scene.id).catch((error) => {
const payload = { ok: false, error: error.message, stack: error.stack };
if (liveRequired) fail("live viewer probe failed", payload);
else warn("live viewer probe failed in non-required mode", payload);
return payload;
});
}
const report = writeReport({
schema: "real2sim.scene_viewer_probe_report.v1",
started_at: startedAt,
finished_at: new Date().toISOString(),
base_url: baseUrl,
scene_id: scene?.id || "",
live_required: liveRequired,
manifest_gate: manifestGate,
live_probe: liveProbe,
failures,
warnings,
pass: failures.length === 0,
});
console.log(JSON.stringify({ pass: report.pass, report: reportPath, scene_id: report.scene_id, live_probe: report.live_probe }, null, 2));
if (tunnel) tunnel.kill("SIGTERM");
process.exitCode = report.pass ? 0 : 1;
}
async function runLiveProbe(baseUrl, sceneId) {
const { chromium } = await importPlaywright();
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 });
const consoleErrors = [];
page.on("console", (message) => {
if (message.type() === "error") consoleErrors.push(message.text());
});
try {
const viewerUrl = `${baseUrl}/static/scene-viewer.html?scene_id=${encodeURIComponent(sceneId)}`;
await withTimeout((async () => {
await page.goto(viewerUrl, { waitUntil: "domcontentloaded", timeout: 30000 });
await page.waitForSelector("canvas", { timeout: 20000 });
await page.waitForFunction(() => {
const debug = window.real2simViewerDebug;
return debug && debug.canvas && debug.canvas.width > 0 && debug.canvas.height > 0 && (debug.loaded || debug.backend === "placeholder" || debug.errors?.length);
}, null, { timeout: Math.max(30000, liveTimeoutMs - 30000) });
await page.mouse.move(720, 450);
await page.mouse.down();
await page.mouse.move(900, 530, { steps: 8 });
await page.mouse.up();
})(), liveTimeoutMs, `live viewer probe timed out after ${liveTimeoutMs}ms`);
const debug = await page.evaluate(() => window.real2simViewerDebug.snapshot?.() || window.real2simViewerDebug);
const ok = !!debug && !debug.errors?.length && (debug.loaded || debug.backend === "placeholder");
if (liveRequired && !ok) fail("live viewer debug is not acceptable", { debug, console_errors: consoleErrors });
return { ok, url: viewerUrl, debug, console_errors: consoleErrors };
} finally {
await page.close().catch(() => {});
await browser.close().catch(() => {});
}
}
async function validateManifestGate(baseUrl, sceneId) {
const manifest = await fetchJson(baseUrl, `/api/scenes/${encodeURIComponent(sceneId)}/manifest`);
const assets = Array.isArray(manifest.assets) ? manifest.assets : [];
const optimized = assets.find((asset) => /\.(spz|splat|ksplat|sog)$/i.test(String(asset.name || asset.path || "")));
if (!optimized) {
fail("scene manifest has no optimized splat asset", { scene_id: sceneId });
return { ok: false, scene_id: sceneId };
}
if (!optimized.url) fail("optimized splat asset has no URL", { scene_id: sceneId, asset: optimized });
if (optimized.autoload === false) fail("optimized splat asset is not autoload", { scene_id: sceneId, asset: optimized });
return {
ok: failures.length === 0,
scene_id: sceneId,
asset: {
name: optimized.name || "",
url: optimized.url || "",
size_label: optimized.size_label || "",
size_bytes: optimized.size_bytes || 0,
autoload: optimized.autoload !== false,
},
};
}
async function pickPreviewableScene(baseUrl) {
const scenes = await fetchJson(baseUrl, "/api/scenes");
if (!Array.isArray(scenes) || scenes.length === 0) return null;
const scored = [];
for (const scene of scenes) {
try {
const manifest = await fetchJson(baseUrl, `/api/scenes/${encodeURIComponent(scene.id)}/manifest`);
const assets = Array.isArray(manifest.assets) ? manifest.assets : [];
let score = 0;
if (assets.some((asset) => /\.(spz|splat|ksplat|sog)$/i.test(String(asset.name || asset.path || "")))) score += 100;
if (assets.some((asset) => /pose_init_trained_scene\.ply$/i.test(String(asset.name || asset.path || "")))) score += 50;
if (assets.some((asset) => /\.(ply|glb|gltf|obj)$/i.test(String(asset.name || asset.path || "")))) score += 20;
scored.push({ scene, score });
} catch (error) {
warn("scene manifest unavailable", { scene_id: scene.id, error: error.message });
}
}
scored.sort((left, right) => right.score - left.score);
return scored[0]?.scene || scenes[0];
}
async function importPlaywright() {
const moduleDir = process.env.REAL2SIM_PLAYWRIGHT_NODE_MODULES || "";
if (moduleDir) {
const require = createRequire(path.join(moduleDir, "real2sim-playwright-loader.cjs"));
return require("playwright");
}
try {
return await import("playwright");
} catch (error) {
throw new Error(`playwright is required. Set REAL2SIM_PLAYWRIGHT_NODE_MODULES=/path/to/node_modules. Original error: ${error.message}`);
}
}
async function startTunnel() {
const port = Number(process.env.REAL2SIM_LOCAL_TUNNEL_PORT || await findPort(18140));
tunnel = spawn("ssh", [
"-i", key,
"-o", "BatchMode=yes",
"-o", "StrictHostKeyChecking=accept-new",
"-N",
"-L", `${port}:127.0.0.1:${remotePort}`,
host,
], { stdio: ["ignore", "pipe", "pipe"] });
tunnel.stderr.on("data", (chunk) => process.stderr.write(chunk));
tunnel.stdout.on("data", (chunk) => process.stdout.write(chunk));
const baseUrl = `http://127.0.0.1:${port}`;
const deadline = Date.now() + 30000;
while (Date.now() < deadline) {
try {
await fetchJson(baseUrl, "/api/health");
return baseUrl;
} catch {
await sleep(500);
}
}
throw new Error(`SSH tunnel did not become ready at ${baseUrl}`);
}
async function findPort(start) {
const net = await import("node:net");
for (let port = start; port < start + 100; port += 1) {
const ok = await new Promise((resolve) => {
const server = net.createServer();
server.once("error", () => resolve(false));
server.once("listening", () => server.close(() => resolve(true)));
server.listen(port, "127.0.0.1");
});
if (ok) return port;
}
throw new Error("no local tunnel port available");
}
async function fetchJson(baseUrl, apiPath) {
const response = await fetch(`${baseUrl}${apiPath}`);
if (!response.ok) throw new Error(`${apiPath} failed with ${response.status}: ${await response.text()}`);
return response.json();
}
async function withTimeout(promise, timeoutMs, message) {
let timer;
try {
return await Promise.race([
promise,
new Promise((_, reject) => {
timer = setTimeout(() => reject(new Error(message)), timeoutMs);
}),
]);
} finally {
clearTimeout(timer);
}
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
main().catch((error) => {
fail("scene viewer probe runner crashed", { error: error.message, stack: error.stack });
const report = writeReport({
schema: "real2sim.scene_viewer_probe_report.v1",
started_at: timestamp,
finished_at: new Date().toISOString(),
base_url: requestedBase,
scene_id: sceneIdOverride,
live_required: liveRequired,
failures,
warnings,
pass: false,
});
console.error(JSON.stringify({ pass: false, report: reportPath, error: error.message }, null, 2));
if (tunnel) tunnel.kill("SIGTERM");
process.exit(report.pass ? 0 : 1);
});

View File

@ -0,0 +1,331 @@
#!/usr/bin/env bash
set -euo pipefail
KEY="${REAL2SIM_WUYING_KEY:-/Users/d-robotics/workSpace/document/80-private/orgs/drobotics/keys/wuying-39.106.101.95_ed25519}"
HOST="${REAL2SIM_WUYING_HOST:-root@39.106.101.95}"
PROJECT_ROOT="${REAL2SIM_REMOTE_PLATFORM_ROOT:-/opt/real2sim2model/real2sim-platform}"
SERVICE="${REAL2SIM_PLATFORM_SERVICE:-real2sim-platform.service}"
PORT="${REAL2SIM_PLATFORM_PORT:-18126}"
DESKTOP_NAME="${REAL2SIM_DESKTOP_NAME:-Real2Sim 平台}"
DESKTOP_FILE_NAME="${REAL2SIM_DESKTOP_FILE_NAME:-Real2Sim Platform.desktop}"
MODE="local"
CLEAN_DESKTOP=1
CREATE_LAUNCHER=1
usage() {
cat <<'EOF'
Usage:
scripts/setup_wuying_desktop_launcher.sh --remote
scripts/setup_wuying_desktop_launcher.sh --local
Options:
--remote Run the setup on the Wuying host over SSH.
--local Run on the current Linux desktop host.
--no-clean Do not move existing desktop icons into backup.
--no-launcher Do not create/update the Real2Sim launcher.
--project-root PATH Remote Real2Sim platform root. Default: /opt/real2sim2model/real2sim-platform
--service NAME systemd service name. Default: real2sim-platform.service
--port PORT Local service port. Default: 18126
The cleanup is reversible: existing desktop entries are moved into a hidden
.real2sim_desktop_backup_<timestamp> directory on the Desktop, not deleted.
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--remote) MODE="remote"; shift ;;
--local) MODE="local"; shift ;;
--no-clean) CLEAN_DESKTOP=0; shift ;;
--no-launcher) CREATE_LAUNCHER=0; shift ;;
--project-root) PROJECT_ROOT="$2"; shift 2 ;;
--service) SERVICE="$2"; shift 2 ;;
--port) PORT="$2"; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) echo "unknown argument: $1" >&2; usage >&2; exit 2 ;;
esac
done
if [[ "$MODE" == "remote" ]]; then
ssh -i "$KEY" \
-o BatchMode=yes \
-o ConnectTimeout=20 \
-o StrictHostKeyChecking=accept-new \
"$HOST" \
"REAL2SIM_REMOTE_PLATFORM_ROOT='$PROJECT_ROOT' REAL2SIM_PLATFORM_SERVICE='$SERVICE' REAL2SIM_PLATFORM_PORT='$PORT' REAL2SIM_DESKTOP_NAME='$DESKTOP_NAME' REAL2SIM_DESKTOP_FILE_NAME='$DESKTOP_FILE_NAME' bash -s -- --local $([[ "$CLEAN_DESKTOP" == "0" ]] && printf '%s' '--no-clean') $([[ "$CREATE_LAUNCHER" == "0" ]] && printf '%s' '--no-launcher')" < "$0"
exit 0
fi
if [[ "$(uname -s)" != "Linux" ]]; then
echo "This setup must run on the Wuying Linux desktop host." >&2
exit 1
fi
timestamp="$(date +%Y%m%d-%H%M%S)"
add_desktop_dir() {
local dir="$1"
[[ -n "$dir" ]] || return 0
if [[ ! -d "$dir" ]]; then
mkdir -p "$dir"
fi
printf '%s\n' "$dir"
}
discover_desktop_dirs() {
local dirs=()
if [[ -n "${XDG_DESKTOP_DIR:-}" ]]; then
dirs+=("$XDG_DESKTOP_DIR")
fi
dirs+=("$HOME/Desktop" "$HOME/桌面")
if [[ "$(id -u)" == "0" ]]; then
dirs+=("/root/Desktop" "/root/桌面")
local home_dir
for home_dir in /home/*; do
[[ -d "$home_dir" ]] || continue
dirs+=("$home_dir/Desktop" "$home_dir/桌面")
done
fi
local seen="" dir
for dir in "${dirs[@]}"; do
[[ -n "$dir" ]] || continue
case ":$seen:" in
*":$dir:"*) continue ;;
esac
seen="$seen:$dir"
add_desktop_dir "$dir"
done
}
owner_for_path() {
local path="$1"
stat -c '%U:%G' "$path" 2>/dev/null || printf 'root:root\n'
}
write_launcher_script() {
local home_dir="$1"
local owner_group="$2"
local bin_dir="$home_dir/.local/bin"
local state_dir="$home_dir/.local/state"
local launcher="$bin_dir/real2sim-platform-launch"
mkdir -p "$bin_dir" "$state_dir"
cat > "$launcher" <<EOF
#!/usr/bin/env bash
set -u
PROJECT_ROOT="$PROJECT_ROOT"
SERVICE="$SERVICE"
PORT="$PORT"
URL="http://127.0.0.1:$PORT/"
LOG="\${XDG_STATE_HOME:-\$HOME/.local/state}/real2sim-launcher.log"
mkdir -p "\$(dirname "\$LOG")"
{
echo "==== \$(date '+%Y-%m-%d %H:%M:%S') Real2Sim launcher ===="
run_with_timeout() {
if command -v timeout >/dev/null 2>&1; then
timeout 25 "\$@"
else
"\$@"
fi
}
health_ok() {
if command -v curl >/dev/null 2>&1; then
curl -fsS "http://127.0.0.1:$PORT/api/health" >/dev/null 2>&1
else
python3 - <<'PY' >/dev/null 2>&1
import urllib.request
urllib.request.urlopen('http://127.0.0.1:$PORT/api/health', timeout=2).read()
PY
fi
}
wait_for_health() {
local i
for i in \$(seq 1 40); do
health_ok && return 0
sleep 1
done
return 1
}
if command -v systemctl >/dev/null 2>&1 && systemctl list-unit-files "$SERVICE" >/dev/null 2>&1; then
if systemctl is-failed --quiet "$SERVICE"; then
run_with_timeout systemctl restart "$SERVICE" || true
else
run_with_timeout systemctl start "$SERVICE" || true
fi
fi
if ! wait_for_health; then
if [[ -x "\$PROJECT_ROOT/.venv/bin/real2sim-platform" ]]; then
if ! pgrep -f "\$PROJECT_ROOT/.venv/bin/real2sim-platform" >/dev/null 2>&1; then
cd "\$PROJECT_ROOT" || exit 1
REAL2SIM_PLATFORM_CONFIG="\$PROJECT_ROOT/config.toml" nohup "\$PROJECT_ROOT/.venv/bin/real2sim-platform" >> "\$LOG" 2>&1 &
fi
wait_for_health || true
fi
fi
launch_chrome_app() {
local browser="\$1"
mkdir -p "\$HOME/.config/real2sim-platform-chrome"
nohup "\$browser" \\
--app="\$URL" \\
--new-window \\
--user-data-dir="\$HOME/.config/real2sim-platform-chrome" \\
--no-first-run \\
--disable-sync \\
--disable-translate \\
--disable-background-networking \\
--disable-component-update \\
--disable-domain-reliability \\
--disable-client-side-phishing-detection \\
--no-default-browser-check \\
--no-service-autorun \\
--disable-features=Translate,TranslateUI,AutofillServerCommunication \\
--window-size=1440,900 \\
--force-device-scale-factor=1 \\
>/dev/null 2>&1 &
}
if command -v google-chrome >/dev/null 2>&1; then
launch_chrome_app google-chrome
elif command -v chromium-browser >/dev/null 2>&1; then
launch_chrome_app chromium-browser
elif command -v xdg-open >/dev/null 2>&1; then
nohup xdg-open "\$URL" >/dev/null 2>&1 &
elif command -v firefox >/dev/null 2>&1; then
nohup firefox "\$URL" >/dev/null 2>&1 &
else
echo "No browser opener found. Open \$URL manually."
fi
if ! health_ok; then
echo "Real2Sim did not become healthy. Check: \$LOG"
if command -v x-terminal-emulator >/dev/null 2>&1; then
x-terminal-emulator -e "bash -lc 'tail -n 120 \"\$LOG\"; echo; read -p \"Press Enter to close\"'" &
elif command -v gnome-terminal >/dev/null 2>&1; then
gnome-terminal -- bash -lc "tail -n 120 \"\$LOG\"; echo; read -p 'Press Enter to close'" &
fi
fi
} >> "\$LOG" 2>&1
EOF
chmod 0755 "$launcher"
chown "$owner_group" "$launcher" "$bin_dir" "$state_dir" 2>/dev/null || true
printf '%s\n' "$launcher"
}
write_icon() {
local home_dir="$1"
local owner_group="$2"
local icon_dir="$home_dir/.local/share/icons"
local icon_file="$icon_dir/real2sim-platform.svg"
mkdir -p "$icon_dir"
cat > "$icon_file" <<'EOF'
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
<defs>
<linearGradient id="g" x1="16" y1="16" x2="112" y2="112" gradientUnits="userSpaceOnUse">
<stop stop-color="#66ead4"/>
<stop offset="0.55" stop-color="#23bca4"/>
<stop offset="1" stop-color="#6aa8ff"/>
</linearGradient>
</defs>
<rect width="128" height="128" rx="28" fill="#071119"/>
<path d="M64 16 104 39v50L64 112 24 89V39L64 16Z" fill="none" stroke="url(#g)" stroke-width="8" stroke-linejoin="round"/>
<path d="M64 36 84 47.5v25L64 84 44 72.5v-25L64 36Z" fill="none" stroke="#9ff7ea" stroke-width="6" stroke-linejoin="round"/>
<path d="M64 36v48M44 48l40 24M84 48 44 72" stroke="#2fdbc4" stroke-width="4" stroke-linecap="round"/>
</svg>
EOF
chmod 0644 "$icon_file"
chown "$owner_group" "$icon_file" "$icon_dir" 2>/dev/null || true
printf '%s\n' "$icon_file"
}
clean_desktop_dir() {
local desktop_dir="$1"
local keep_file="$desktop_dir/$DESKTOP_FILE_NAME"
local backup_dir="$desktop_dir/.real2sim_desktop_backup_$timestamp"
local moved=0
shopt -s nullglob dotglob
local item base
for item in "$desktop_dir"/* "$desktop_dir"/.[!.]* "$desktop_dir"/..?*; do
[[ -e "$item" ]] || continue
base="$(basename "$item")"
case "$base" in
"$DESKTOP_FILE_NAME"|".directory"|".real2sim_desktop_backup_"*) continue ;;
esac
if [[ "$item" == "$keep_file" ]]; then
continue
fi
mkdir -p "$backup_dir"
mv "$item" "$backup_dir/"
moved=$((moved + 1))
done
shopt -u nullglob dotglob
if [[ "$moved" == "0" && -d "$backup_dir" ]]; then
rmdir "$backup_dir" 2>/dev/null || true
fi
printf '%s\n' "$moved"
}
write_desktop_file() {
local desktop_dir="$1"
local owner_group="$2"
local launcher="$3"
local icon_file="$4"
local desktop_file="$desktop_dir/$DESKTOP_FILE_NAME"
cat > "$desktop_file" <<EOF
[Desktop Entry]
Type=Application
Name=$DESKTOP_NAME
Comment=启动 Real2Sim 服务并打开平台
Exec=$launcher
Icon=$icon_file
Terminal=false
Categories=Development;Science;
StartupNotify=true
EOF
chmod 0755 "$desktop_file"
chown "$owner_group" "$desktop_file" 2>/dev/null || true
if command -v gio >/dev/null 2>&1; then
gio set "$desktop_file" metadata::trusted true >/dev/null 2>&1 || true
fi
printf '%s\n' "$desktop_file"
}
main() {
if [[ ! -d "$PROJECT_ROOT" ]]; then
echo "warning: project root does not exist yet: $PROJECT_ROOT" >&2
fi
local desktop_dir owner_group home_dir launcher icon_file moved desktop_file
local count=0
while IFS= read -r desktop_dir; do
[[ -d "$desktop_dir" ]] || continue
owner_group="$(owner_for_path "$desktop_dir")"
home_dir="$(dirname "$desktop_dir")"
if [[ "$CREATE_LAUNCHER" == "1" ]]; then
launcher="$(write_launcher_script "$home_dir" "$owner_group")"
icon_file="$(write_icon "$home_dir" "$owner_group")"
desktop_file="$(write_desktop_file "$desktop_dir" "$owner_group" "$launcher" "$icon_file")"
else
desktop_file="$desktop_dir/$DESKTOP_FILE_NAME"
fi
if [[ "$CLEAN_DESKTOP" == "1" ]]; then
moved="$(clean_desktop_dir "$desktop_dir")"
else
moved=0
fi
echo "desktop=$desktop_dir launcher=$desktop_file moved_to_backup=$moved"
count=$((count + 1))
done < <(discover_desktop_dirs)
echo "Real2Sim desktop launcher setup complete. desktop_dirs=$count"
}
main

View File

@ -1,107 +0,0 @@
import assert from 'node:assert/strict'
import { spawn, execFileSync } from 'node:child_process'
import { createServer as createNetServer } from 'node:net'
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { createServer } from 'vite'
import { chromium } from 'playwright'
const scratch = await mkdtemp(path.join(os.tmpdir(), 'real2sim-smoke-'))
const data = path.join(scratch, '.data')
await mkdir(data)
const evidence = path.resolve('artifacts/smoke')
await mkdir(evidence, { recursive: true })
const portProbe = createNetServer()
await new Promise(resolve => portProbe.listen(0, '127.0.0.1', resolve))
const port = portProbe.address().port
await new Promise(resolve => portProbe.close(resolve))
const base = `http://127.0.0.1:${port}`
const backend = spawn(process.execPath, ['--import', 'tsx', 'server/index.ts'], {
env: { ...process.env, PORT: String(port), REAL2SIM_DEMO: '1', REAL2SIM_DATA_ROOT: data, REAL2SIM_ASSET_ROOT: `${data}/assets`, REAL2SIM_GENESIS_PACKAGE_ROOT: `${data}/genesis-packages`, DASHSCOPE_API_KEY: '' },
stdio: ['ignore', 'pipe', 'pipe'],
})
let logs = ''
backend.stdout.on('data', chunk => { logs += chunk })
backend.stderr.on('data', chunk => { logs += chunk })
let vite, browser
const report = { checks: [], browserErrors: [] }
try {
for (let i = 0; i < 100; i++) {
if (backend.exitCode !== null) throw new Error(`Backend exited: ${logs}`)
try { if ((await fetch(`${base}/api/health`)).ok) break } catch { /* Startup race. */ }
await new Promise(resolve => setTimeout(resolve, 100))
}
assert.equal((await (await fetch(`${base}/api/health`)).json()).apiConfigured, false)
assert.equal((await fetch(`${base}/api/examples/soft-puck`, { method: 'POST', headers: { origin: 'https://untrusted.example' } })).status, 403)
const imported = await (await fetch(`${base}/api/examples/soft-puck`, { method: 'POST' })).json()
assert.ok(imported.task, JSON.stringify(imported))
assert.equal(imported.task.kind, 'sample')
const sim = { ...imported.task.request.simulation, gravity: 3.7 }
const exported = await (await fetch(`${base}/api/genesis/packages`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sourceTaskId: imported.task.taskId, simulation: sim }) })).json()
assert.equal(exported.manifest.genesis.gravity, 3.7)
const archive = path.join(data, 'sample.tar.gz')
await writeFile(archive, Buffer.from(await (await fetch(base + exported.archiveUrl)).arrayBuffer()))
execFileSync('tar', ['-xzf', archive, '-C', data])
const manifest = JSON.parse(await readFile(path.join(data, 'manifest.json'), 'utf8'))
assert.equal(manifest.genesis.gravity, 3.7)
const model = await readFile(path.join(data, manifest.assets.model))
assert.equal(model.toString('ascii', 0, 4), 'glTF')
assert.equal(JSON.parse(await readFile(path.join(data, 'flex-profile.json'), 'utf8')).solver.type, 'fem_elastic')
report.checks.push('offline import', 'cross-origin rejection', 'real GLB archive', 'current gravity', 'solver mapping')
vite = await createServer({ server: { host: '127.0.0.1', port: 0, proxy: { '/api': base, '/assets': base } } })
await vite.listen()
browser = await chromium.launch({ args: ['--enable-webgl', '--use-angle=swiftshader', '--enable-unsafe-swiftshader'] })
const page = await browser.newPage({ viewport: { width: 1600, height: 1000 } })
await page.addInitScript(() => localStorage.setItem('real2sim.locale', 'en'))
page.on('pageerror', error => report.browserErrors.push(error.message))
await page.goto(vite.resolvedUrls.local[0])
await page.getByRole('button', { name: 'Load example', exact: true }).click()
await page.getByRole('heading', { name: 'Material & Simulation Export' }).waitFor()
await page.locator('canvas').waitFor()
await page.waitForTimeout(1500)
const pixels = await page.locator('canvas').evaluate(canvas => {
const gl = canvas.getContext('webgl2') || canvas.getContext('webgl')
if (!gl) return { colors: 0 }
const pixels = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4)
gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels)
const colors = new Set()
for (let i = 0; i < pixels.length; i += 400) colors.add(`${pixels[i]},${pixels[i + 1]},${pixels[i + 2]}`)
return { colors: colors.size, width: gl.drawingBufferWidth, height: gl.drawingBufferHeight }
})
assert.ok(pixels.colors > 15, `Blank canvas: ${JSON.stringify(pixels)}`)
await page.screenshot({ path: path.join(evidence, 'desktop.png'), fullPage: true })
const before = await page.locator('canvas').screenshot()
await page.getByRole('button', { name: 'Rotate model' }).click()
await page.waitForTimeout(3000)
assert.notDeepEqual(await page.locator('canvas').screenshot(), before)
await page.getByRole('button', { name: 'Rotate model' }).click()
const gravity = page.getByLabel('Gravity', { exact: true })
await gravity.focus()
await gravity.press('Home')
for (let i = 0; i < 37; i++) await gravity.press('ArrowRight')
const downloadPromise = page.waitForEvent('download')
await page.getByRole('button', { name: 'Export Genesis Package', exact: true }).click()
const download = await downloadPromise
await download.saveAs(path.join(evidence, 'browser-export.tar.gz'))
const extractDir = path.join(data, 'browser-export')
await mkdir(extractDir)
execFileSync('tar', ['-xzf', path.join(evidence, 'browser-export.tar.gz'), '-C', extractDir])
assert.equal(JSON.parse(await readFile(path.join(extractDir, 'manifest.json'), 'utf8')).genesis.gravity, 3.7)
await page.setViewportSize({ width: 390, height: 844 })
await page.waitForTimeout(500)
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth))
await page.screenshot({ path: path.join(evidence, 'mobile.png'), fullPage: true })
report.checks.push('desktop canvas pixels', 'interactive rotation', 'browser export current sliders', 'mobile no overflow')
report.canvas = pixels
assert.deepEqual(report.browserErrors, [])
await writeFile(path.join(evidence, 'report.json'), JSON.stringify(report, null, 2))
console.log(JSON.stringify(report, null, 2))
} finally {
await browser?.close()
await vite?.close()
backend.kill('SIGTERM')
if (backend.exitCode === null) await new Promise(resolve => backend.once('exit', resolve))
await rm(scratch, { recursive: true, force: true })
}

4
scripts/start_local.sh Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
PYTHONPATH=src python -m real2sim_platform.server --host 127.0.0.1 --port 18126

View File

@ -1,23 +0,0 @@
import sys
from pathlib import Path
import unittest
import numpy as np
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "server"))
from physics_metrics import shape_deformation
class MetricsTests(unittest.TestCase):
def setUp(self):
self.vertices = np.array([[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])
def test_rigid_motion_is_not_deformation(self):
rotation = np.array([[0., -1., 0.], [1., 0., 0.], [0., 0., 1.]])
self.assertLess(shape_deformation(self.vertices, self.vertices @ rotation + 5), 1e-12)
def test_compression_is_deformation(self):
self.assertGreater(shape_deformation(self.vertices, self.vertices * [1., 1., 0.5]), 0.1)
if __name__ == "__main__":
unittest.main()

16
scripts/vendor_spark.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
VERSION="${SPARK_VERSION:-2.1.0}"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
cd "$TMP"
npm pack "@sparkjsdev/spark@$VERSION" >/dev/null
tar -xzf "sparkjsdev-spark-$VERSION.tgz"
mkdir -p "$ROOT/src/real2sim_platform/static/vendor"
cp package/dist/spark.module.min.js "$ROOT/src/real2sim_platform/static/vendor/spark.module.min.js"
cp package/LICENSE "$ROOT/src/real2sim_platform/static/vendor/spark.LICENSE"
printf '%s\n' "$VERSION" > "$ROOT/src/real2sim_platform/static/vendor/spark.VERSION"
echo "vendored @sparkjsdev/spark@$VERSION"

20
scripts/vendor_three.sh Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VERSION="${THREE_VERSION:-0.185.1}"
VENDOR="$ROOT/src/real2sim_platform/static/vendor/three"
BASE="https://unpkg.com/three@$VERSION"
mkdir -p "$VENDOR/addons/controls" "$VENDOR/addons/loaders" "$VENDOR/addons/postprocessing" "$VENDOR/addons/utils"
curl -fsSL "$BASE/build/three.module.js" -o "$VENDOR/three.module.js"
curl -fsSL "$BASE/build/three.core.js" -o "$VENDOR/three.core.js"
curl -fsSL "$BASE/examples/jsm/controls/OrbitControls.js" -o "$VENDOR/addons/controls/OrbitControls.js"
curl -fsSL "$BASE/examples/jsm/loaders/OBJLoader.js" -o "$VENDOR/addons/loaders/OBJLoader.js"
curl -fsSL "$BASE/examples/jsm/loaders/PLYLoader.js" -o "$VENDOR/addons/loaders/PLYLoader.js"
curl -fsSL "$BASE/examples/jsm/loaders/GLTFLoader.js" -o "$VENDOR/addons/loaders/GLTFLoader.js"
curl -fsSL "$BASE/examples/jsm/postprocessing/Pass.js" -o "$VENDOR/addons/postprocessing/Pass.js"
curl -fsSL "$BASE/examples/jsm/utils/BufferGeometryUtils.js" -o "$VENDOR/addons/utils/BufferGeometryUtils.js"
curl -fsSL "$BASE/examples/jsm/utils/SkeletonUtils.js" -o "$VENDOR/addons/utils/SkeletonUtils.js"
printf '%s\n' "$VERSION" > "$ROOT/src/real2sim_platform/static/vendor/three.VERSION"
echo "vendored three@$VERSION"

View File

@ -1,20 +0,0 @@
"""Check the bundled drop-test evidence, not arbitrary materials or meshes."""
import json
from pathlib import Path
import sys
import numpy as np
root = Path(sys.argv[1] if len(sys.argv) > 1 else ".data/genesis-packages/example-soft-puck")
metrics = json.loads((root / "metrics.json").read_text())
trajectory = np.load(root / "trajectory.npz")["positions"]
assert metrics["solver"] == "fem_elastic"
assert metrics["gravity"] == 9.8
assert metrics["steps"] >= 500
assert np.isfinite(trajectory).all()
assert np.abs(trajectory).max() < 1
assert 0.30 < metrics["initial_center_z"] < 0.40
assert 0.0 < metrics["final_center_z"] < 0.15
assert metrics["min_vertex_z"] > -0.01
assert 0.001 < metrics["max_shape_deformation_m"] < 0.2
print("PASS: finite trajectory, falling body, ground contact, nonzero deformation")

View File

@ -1,118 +0,0 @@
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { StoredTask } from './taskStore.js'
const originalAssetRoot = process.env.REAL2SIM_ASSET_ROOT
let temporaryAssetRoot = ''
function createStoredTask(): StoredTask {
return {
taskId: 'task/one?',
kind: 'generation',
title: 'local cache test',
status: 'SUCCEEDED',
request: {
mode: 'text',
model: 'Tripo/Tripo-H3.1',
prompt: 'a soft robotic gripper',
parameters: {
texture_quality: 'detailed',
geometry_quality: 'standard',
pbr: true,
texture: true,
},
},
output: {
task_id: 'task/one?',
task_status: 'SUCCEEDED',
results: [
{
rendered_image_url: 'https://example.test/render.png',
pbr_model_url: 'https://example.test/model.glb',
},
],
},
createdAt: '2026-06-03T00:00:00.000Z',
updatedAt: '2026-06-03T00:00:00.000Z',
}
}
beforeEach(async () => {
temporaryAssetRoot = await mkdtemp(path.join(os.tmpdir(), 'real2sim-assets-'))
process.env.REAL2SIM_ASSET_ROOT = temporaryAssetRoot
vi.resetModules()
})
afterEach(async () => {
await rm(temporaryAssetRoot, { recursive: true, force: true })
vi.unstubAllGlobals()
vi.resetModules()
if (originalAssetRoot === undefined) {
delete process.env.REAL2SIM_ASSET_ROOT
} else {
process.env.REAL2SIM_ASSET_ROOT = originalAssetRoot
}
})
describe('asset store', () => {
it('caches task result assets under local /assets URLs', async () => {
const fetchMock = vi.fn(async () => new Response(new Uint8Array([1, 2, 3]), { status: 200 }))
vi.stubGlobal('fetch', fetchMock)
const { cacheTaskAssets } = await import('./assetStore.js')
const cachedTask = await cacheTaskAssets(createStoredTask())
const result = cachedTask.output?.results?.[0]
expect(result?.local_rendered_image_url).toBe('/assets/task_one_/render.png')
expect(result?.local_pbr_model_url).toBe('/assets/task_one_/pbr.glb')
expect(await readFile(path.join(temporaryAssetRoot, 'task_one_', 'render.png'))).toEqual(Buffer.from([1, 2, 3]))
expect(await readFile(path.join(temporaryAssetRoot, 'task_one_', 'pbr.glb'))).toEqual(Buffer.from([1, 2, 3]))
expect(fetchMock).toHaveBeenCalledTimes(2)
await cacheTaskAssets(cachedTask)
expect(fetchMock).toHaveBeenCalledTimes(2)
})
it('caches generic model_url results returned by non-PBR Tripo tasks', async () => {
const fetchMock = vi.fn(async () => new Response(new Uint8Array([4, 5, 6]), { status: 200 }))
vi.stubGlobal('fetch', fetchMock)
const task = createStoredTask()
task.output!.results = [
{
rendered_image_url: 'https://example.test/render.webp',
model_url: 'https://example.test/model.glb',
},
]
const { cacheTaskAssets } = await import('./assetStore.js')
const cachedTask = await cacheTaskAssets(task)
const result = cachedTask.output?.results?.[0]
expect(result?.local_rendered_image_url).toBe('/assets/task_one_/render.webp')
expect(result?.local_model_url).toBe('/assets/task_one_/model.glb')
expect(await readFile(path.join(temporaryAssetRoot, 'task_one_', 'model.glb'))).toEqual(Buffer.from([4, 5, 6]))
})
it('restores local URLs from existing files when signed remote URLs are no longer fetchable', async () => {
await mkdir(path.join(temporaryAssetRoot, 'task_one_'), { recursive: true })
await writeFile(path.join(temporaryAssetRoot, 'task_one_', 'render.webp'), new Uint8Array([7, 8, 9]))
const fetchMock = vi.fn(async () => new Response('expired', { status: 403 }))
vi.stubGlobal('fetch', fetchMock)
const task = createStoredTask()
task.output!.results = [
{
rendered_image_url: 'https://example.test/render.webp?auth_key=expired',
},
]
const { cacheTaskAssets } = await import('./assetStore.js')
const cachedTask = await cacheTaskAssets(task)
expect(cachedTask.output?.results?.[0]?.local_rendered_image_url).toBe('/assets/task_one_/render.webp')
expect(fetchMock).not.toHaveBeenCalled()
})
})

View File

@ -1,162 +0,0 @@
import { access, mkdir, writeFile } from 'node:fs/promises'
import path from 'node:path'
import type { StoredTask } from './taskStore.js'
type AssetSpec = {
remoteKey: 'rendered_image_url' | 'pbr_model_url' | 'base_model_url' | 'model_url'
localKey: 'local_rendered_image_url' | 'local_pbr_model_url' | 'local_base_model_url' | 'local_model_url'
baseName: string
fallbackExtension: string
}
const assetSpecs = [
{
remoteKey: 'rendered_image_url',
localKey: 'local_rendered_image_url',
baseName: 'render',
fallbackExtension: '.png',
},
{
remoteKey: 'pbr_model_url',
localKey: 'local_pbr_model_url',
baseName: 'pbr',
fallbackExtension: '.glb',
},
{
remoteKey: 'base_model_url',
localKey: 'local_base_model_url',
baseName: 'base',
fallbackExtension: '.glb',
},
{
remoteKey: 'model_url',
localKey: 'local_model_url',
baseName: 'model',
fallbackExtension: '.glb',
},
] as const satisfies readonly AssetSpec[]
export const assetRoot = process.env.REAL2SIM_ASSET_ROOT
? path.resolve(process.env.REAL2SIM_ASSET_ROOT)
: path.resolve(process.env.REAL2SIM_DATA_ROOT || '.data', 'assets')
function safePathSegment(value: string) {
return value.replace(/[^a-zA-Z0-9._-]/g, '_')
}
function extensionFromUrl(url: string) {
try {
const extension = path.extname(new URL(url).pathname).toLowerCase()
return extension || undefined
} catch {
return undefined
}
}
function extensionFromContentType(contentType: string | null) {
if (!contentType) return undefined
if (contentType.includes('model/gltf-binary')) return '.glb'
if (contentType.includes('image/png')) return '.png'
if (contentType.includes('image/jpeg')) return '.jpg'
if (contentType.includes('image/webp')) return '.webp'
return undefined
}
async function fileExists(filePath: string) {
try {
await access(filePath)
return true
} catch {
return false
}
}
function localAssetUrl(taskId: string, fileName: string) {
return `/assets/${encodeURIComponent(safePathSegment(taskId))}/${encodeURIComponent(fileName)}`
}
async function cacheRemoteAsset(taskId: string, remoteUrl: string, baseName: string, fallbackExtension: string) {
const parsed = new URL(remoteUrl)
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
return undefined
}
const extension = extensionFromUrl(remoteUrl) || fallbackExtension
const fileName = `${baseName}${extension}`
const assetDir = path.join(assetRoot, safePathSegment(taskId))
const filePath = path.join(assetDir, fileName)
if (await fileExists(filePath)) {
return localAssetUrl(taskId, fileName)
}
const response = await fetch(remoteUrl)
if (!response.ok) {
throw new Error(`Asset download failed with HTTP ${response.status}`)
}
const contentTypeExtension = extensionFromContentType(response.headers.get('content-type'))
const resolvedFileName = contentTypeExtension && extension === fallbackExtension ? `${baseName}${contentTypeExtension}` : fileName
const resolvedFilePath = path.join(assetDir, resolvedFileName)
await mkdir(assetDir, { recursive: true })
const buffer = Buffer.from(await response.arrayBuffer())
await writeFile(resolvedFilePath, buffer)
return localAssetUrl(taskId, resolvedFileName)
}
export async function cacheTaskAssets(task: StoredTask): Promise<StoredTask> {
const output = task.output
if (!output?.results?.length) return task
let changed = false
const results: NonNullable<NonNullable<StoredTask['output']>['results']> = []
for (const result of output.results) {
const nextResult = { ...result }
for (const spec of assetSpecs) {
const remoteUrl = result[spec.remoteKey]
if (!remoteUrl) continue
if (result[spec.localKey]?.startsWith('/assets/')) continue
try {
const localUrl = await cacheRemoteAsset(task.taskId, remoteUrl, spec.baseName, spec.fallbackExtension)
if (localUrl && nextResult[spec.localKey] !== localUrl) {
nextResult[spec.localKey] = localUrl
changed = true
}
} catch (error) {
const message = error instanceof Error ? error.message : 'Unknown asset download error'
console.warn(`Could not cache ${spec.remoteKey} for task ${task.taskId}: ${message}`)
}
}
results.push(nextResult)
}
if (!changed) return task
return {
...task,
output: {
...output,
results,
},
updatedAt: new Date().toISOString(),
}
}
export async function cacheTasksAssets(tasks: StoredTask[]) {
const nextTasks: StoredTask[] = []
let changed = false
for (const task of tasks) {
const nextTask = await cacheTaskAssets(task)
nextTasks.push(nextTask)
if (nextTask !== task) changed = true
}
return { tasks: nextTasks, changed }
}

View File

@ -1,7 +0,0 @@
import dotenv from 'dotenv'
// A demo must never inherit the user's paid provider key or private task history.
if (process.env.REAL2SIM_DEMO !== '1') {
dotenv.config({ path: '.env.local', quiet: true })
dotenv.config({ quiet: true })
}

View File

@ -1,33 +0,0 @@
import { copyFile, mkdir } from 'node:fs/promises'
import path from 'node:path'
import { assetRoot } from './assetStore.js'
import { upsertTask, type StoredTask } from './taskStore.js'
export async function importExample() {
const taskId = 'example-soft-puck'
const dir = path.join(assetRoot, taskId)
await mkdir(dir, { recursive: true })
await copyFile(new URL('../examples/soft-puck/model.glb', import.meta.url), path.join(dir, 'model.glb'))
const now = new Date().toISOString()
const task: StoredTask = {
taskId,
kind: 'sample',
title: 'Sample / Silicone puck',
status: 'SUCCEEDED',
request: {
sourceName: 'Procedural silicone puck (MIT example)',
sourceModelUrl: '/assets/example-soft-puck/model.glb',
model: 'Tripo/Tripo-H3.1',
parameters: { texture_quality: 'standard', geometry_quality: 'standard', pbr: true, texture: true },
simulation: { material: 'silicone', elasticity: 0, damping: 10, thickness: 20, deformation: 70, gravity: 9.8 },
},
output: {
task_id: taskId,
task_status: 'SUCCEEDED',
results: [{ local_model_url: '/assets/example-soft-puck/model.glb' }],
},
createdAt: now,
updatedAt: now,
}
return upsertTask(task)
}

View File

@ -1,59 +0,0 @@
import { describe, expect, it } from 'vitest'
import { buildFlexiblePrompt, createSimulationExport } from './flex.js'
describe('flex profile helpers', () => {
it('builds a material-aware prompt for Tripo generation', () => {
const prompt = buildFlexiblePrompt({
sourceName: '工业夹爪',
sourcePrompt: '一个双指机器人夹爪',
behaviorPrompt: '转化为柔性末端执行器',
model: 'Tripo/Tripo-H3.1',
parameters: {
texture_quality: 'detailed',
geometry_quality: 'standard',
pbr: true,
texture: true,
},
simulation: {
material: 'softRobot',
elasticity: 82,
damping: 48,
thickness: 4,
deformation: 70,
gravity: 9.8,
},
})
expect(prompt).toContain('一个双指机器人夹爪')
expect(prompt).toContain('软体机器人结构')
expect(prompt).toContain('弹性强度 82/100')
})
it('exports normalized simulation parameters', () => {
const profile = createSimulationExport({
sourceTaskId: 'task-1',
sourceName: '软袋',
sourceModelUrl: 'https://example.com/model.glb',
model: 'Tripo/Tripo-H3.1',
parameters: {
texture_quality: 'detailed',
geometry_quality: 'ultra',
pbr: true,
texture: true,
},
simulation: {
material: 'cloth',
elasticity: 50,
damping: 25,
thickness: 1.5,
deformation: 88,
gravity: 9.8,
},
})
expect(profile.schema).toBe('real2sim.flexProfile.v1')
expect(profile.physics.elasticity).toBe(0.5)
expect(profile.solver.type).toBe('pbd_cloth')
expect(profile.solver.parametersArePresets).toBe(true)
})
})

View File

@ -1,53 +0,0 @@
import type { CreateFlexTaskInput, SimulationProfile } from './schemas.js'
const materialCopy: Record<SimulationProfile['material'], string> = {
silicone: '半透明软硅胶材质,边缘圆润,受力后可压缩回弹',
cloth: '轻薄织物材质,表面有细密纤维纹理和自然褶皱',
inflatable: '充气膜结构,内部有气压支撑,表面柔和鼓起',
softRobot: '软体机器人结构,带有分段腔体、柔性关节和可驱动褶皱',
}
export function buildFlexiblePrompt(input: CreateFlexTaskInput): string {
const source =
input.sourcePrompt ||
input.sourceName ||
'一个适合仿真验证的真实物体'
const behavior = input.behaviorPrompt || '保持原始轮廓特征,同时变成可弯曲、可压缩的柔性物体'
const material = materialCopy[input.simulation.material]
const elasticity = Math.round(input.simulation.elasticity)
const deformation = Math.round(input.simulation.deformation)
return [
source,
behavior,
material,
`弹性强度 ${elasticity}/100,形变幅度 ${deformation}/100。`,
'生成高精度、可用于 real-to-sim 工作流的 3D 资产,保留清晰几何结构和物理仿真可读的材质细节。',
].join(' ')
}
export function createSimulationExport(input: CreateFlexTaskInput) {
return {
schema: 'real2sim.flexProfile.v1',
source: {
taskId: input.sourceTaskId,
modelUrl: input.sourceModelUrl || undefined,
prompt: input.sourcePrompt || undefined,
name: input.sourceName || undefined,
},
material: input.simulation.material,
physics: {
elasticity: input.simulation.elasticity / 100,
damping: input.simulation.damping / 100,
thicknessMm: input.simulation.thickness,
maxDeformation: input.simulation.deformation / 100,
gravity: input.simulation.gravity,
},
solver: {
type: input.simulation.material === 'cloth' ? 'pbd_cloth' : 'fem_elastic',
substeps: 4,
parametersArePresets: true,
},
generatedAt: new Date().toISOString(),
}
}

View File

@ -1,118 +0,0 @@
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { StoredTask } from './taskStore.js'
const originalAssetRoot = process.env.REAL2SIM_ASSET_ROOT
const originalPackageRoot = process.env.REAL2SIM_GENESIS_PACKAGE_ROOT
let temporaryAssetRoot = ''
let temporaryPackageRoot = ''
function createFlexTask(material: 'silicone' | 'cloth' = 'silicone'): StoredTask {
return {
taskId: `task-${material}`,
kind: 'flex',
title: `${material} flex object`,
status: 'SUCCEEDED',
request: {
sourceTaskId: 'source-task',
sourceName: 'source object',
sourceModelUrl: '/assets/source-task/pbr.glb',
behaviorPrompt: 'make it deformable',
model: 'Tripo/Tripo-H3.1',
parameters: {
texture_quality: 'detailed',
geometry_quality: 'standard',
pbr: true,
texture: true,
},
simulation: {
material,
elasticity: 72,
damping: 42,
thickness: 3.2,
deformation: 64,
gravity: 3.7,
},
},
output: {
task_id: `task-${material}`,
task_status: 'SUCCEEDED',
results: [
{
local_pbr_model_url: `/assets/task-${material}/pbr.glb`,
local_rendered_image_url: `/assets/task-${material}/render.webp`,
},
],
},
createdAt: '2026-06-03T00:00:00.000Z',
updatedAt: '2026-06-03T00:00:00.000Z',
}
}
beforeEach(async () => {
temporaryAssetRoot = await mkdtemp(path.join(os.tmpdir(), 'real2sim-assets-'))
temporaryPackageRoot = await mkdtemp(path.join(os.tmpdir(), 'real2sim-genesis-'))
process.env.REAL2SIM_ASSET_ROOT = temporaryAssetRoot
process.env.REAL2SIM_GENESIS_PACKAGE_ROOT = temporaryPackageRoot
vi.resetModules()
})
afterEach(async () => {
await rm(temporaryAssetRoot, { recursive: true, force: true })
await rm(temporaryPackageRoot, { recursive: true, force: true })
vi.resetModules()
if (originalAssetRoot === undefined) {
delete process.env.REAL2SIM_ASSET_ROOT
} else {
process.env.REAL2SIM_ASSET_ROOT = originalAssetRoot
}
if (originalPackageRoot === undefined) {
delete process.env.REAL2SIM_GENESIS_PACKAGE_ROOT
} else {
process.env.REAL2SIM_GENESIS_PACKAGE_ROOT = originalPackageRoot
}
})
describe('Genesis package export', () => {
it('creates a runnable FEM package for volumetric flexible materials', async () => {
await mkdir(path.join(temporaryAssetRoot, 'task-silicone'), { recursive: true })
await writeFile(path.join(temporaryAssetRoot, 'task-silicone', 'pbr.glb'), new Uint8Array([1, 2, 3]))
await writeFile(path.join(temporaryAssetRoot, 'task-silicone', 'render.webp'), new Uint8Array([4, 5, 6]))
const { createGenesisPackage } = await import('./genesisPackage.js')
const exported = await createGenesisPackage(createFlexTask('silicone'))
expect(exported.manifest.genesis.solver).toBe('fem_elastic')
expect(exported.manifest.assets.model).toBe('assets/model.glb')
expect(exported.manifest.assets.preview).toBe('assets/preview.webp')
expect((await stat(exported.archivePath)).size).toBeGreaterThan(0)
expect(await readFile(path.join(exported.packageDir, 'assets', 'model.glb'))).toEqual(Buffer.from([1, 2, 3]))
const script = await readFile(path.join(exported.packageDir, 'genesis_scene.py'), 'utf8')
expect(script).toContain('gs.materials.FEM.Elastic')
expect(script).toContain('force_retet=True')
expect(exported.manifest.genesis.parameters.E).toBe(70400)
expect(exported.manifest.genesis.gravity).toBe(3.7)
expect(script).toContain('gravity = -float(config["gravity"])')
const profile = JSON.parse(await readFile(path.join(exported.packageDir, 'flex-profile.json'), 'utf8'))
expect(profile.schema).toBe('real2sim.flexProfile.v1')
expect(profile.material).toBe('silicone')
})
it('creates a PBD cloth package for cloth materials', async () => {
await mkdir(path.join(temporaryAssetRoot, 'task-cloth'), { recursive: true })
await writeFile(path.join(temporaryAssetRoot, 'task-cloth', 'pbr.glb'), new Uint8Array([7, 8, 9]))
const { createGenesisPackage } = await import('./genesisPackage.js')
const exported = await createGenesisPackage(createFlexTask('cloth'))
expect(exported.manifest.genesis.solver).toBe('pbd_cloth')
const script = await readFile(path.join(exported.packageDir, 'genesis_scene.py'), 'utf8')
expect(script).toContain('gs.materials.PBD.Cloth')
expect(exported.manifest.genesis.parameters.stretchCompliance).toBeCloseTo(1e-6 / 73, 12)
})
})

View File

@ -1,289 +0,0 @@
import { access, copyFile, mkdir, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { gzipSync } from 'node:zlib'
import { assetRoot } from './assetStore.js'
import { createSimulationExport } from './flex.js'
import type { CreateFlexTaskInput, SimulationProfile } from './schemas.js'
import type { StoredTask } from './taskStore.js'
type GenesisSolver = 'fem_elastic' | 'pbd_cloth'
type GenesisParameters = {
E?: number
nu?: number
rho?: number
damping: number
stretchCompliance?: number
bendCompliance?: number
maxVolume?: number
}
export type GenesisPackageManifest = {
schema: 'real2sim.genesisPackage.v1'
taskId: string
title: string
assets: {
model: string
preview?: string
}
genesis: {
script: string
solver: GenesisSolver
material: SimulationProfile['material']
gravity: number
parameters: GenesisParameters
}
notes: string[]
generatedAt: string
}
export type GenesisPackageResult = {
packageDir: string
archivePath: string
manifest: GenesisPackageManifest
}
export const genesisPackageRoot = process.env.REAL2SIM_GENESIS_PACKAGE_ROOT
? path.resolve(process.env.REAL2SIM_GENESIS_PACKAGE_ROOT)
: path.resolve(process.env.REAL2SIM_DATA_ROOT || '.data', 'genesis-packages')
function safePathSegment(value: string) {
if (!/^[a-zA-Z0-9_-][a-zA-Z0-9._-]{0,199}$/.test(value)) throw new Error('Invalid task ID.')
return value
}
function isFlexTask(task: StoredTask): task is StoredTask & { request: CreateFlexTaskInput } {
return (task.kind === 'flex' || task.kind === 'sample') && typeof (task.request as Partial<CreateFlexTaskInput>).simulation === 'object'
}
function round(value: number, digits = 3) {
return Number(value.toFixed(digits))
}
function clamp(value: number, min: number, max: number) {
return Math.min(max, Math.max(min, value))
}
function localAssetPath(localUrl?: string) {
if (!localUrl?.startsWith('/assets/')) return undefined
const relativeParts = localUrl
.slice('/assets/'.length)
.split('/')
.filter(Boolean)
.map((part) => decodeURIComponent(part))
const resolved = path.resolve(assetRoot, ...relativeParts)
const root = path.resolve(assetRoot)
if (resolved !== root && !resolved.startsWith(`${root}${path.sep}`)) {
throw new Error('Asset path escapes the local asset root.')
}
return resolved
}
function chooseModelAsset(task: StoredTask) {
const result = task.output?.results?.[0]
return localAssetPath(result?.local_pbr_model_url) || localAssetPath(result?.local_base_model_url) || localAssetPath(result?.local_model_url)
}
function choosePreviewAsset(task: StoredTask) {
return localAssetPath(task.output?.results?.[0]?.local_rendered_image_url)
}
async function fileExists(filePath: string) {
try {
await access(filePath)
return true
} catch {
return false
}
}
function materialParameters(simulation: SimulationProfile): { solver: GenesisSolver; parameters: GenesisParameters } {
if (simulation.material === 'cloth') {
return {
solver: 'pbd_cloth',
parameters: {
damping: round(0.001 + simulation.damping * 0.0001, 5),
stretchCompliance: Number((1e-6 / (1 + simulation.elasticity)).toPrecision(6)),
bendCompliance: Number((1e-4 / (1 + simulation.thickness)).toPrecision(6)),
},
}
}
const materialDefaults = {
silicone: { baseE: 20000, nu: 0.47, rho: 1100 },
inflatable: { baseE: 12000, nu: 0.42, rho: 260 },
softRobot: { baseE: 36000, nu: 0.4, rho: 1050 },
}[simulation.material]
return {
solver: 'fem_elastic',
parameters: {
E: Math.round(clamp(materialDefaults.baseE + simulation.elasticity * 800 - simulation.deformation * 112.5, 12000, 180000)),
nu: materialDefaults.nu,
rho: materialDefaults.rho,
damping: round(0.02 + (simulation.damping / 100) * 0.48),
maxVolume: round(clamp((simulation.thickness / 1000) ** 3, 1e-7, 5e-5), 7),
},
}
}
function packageReadme(manifest: GenesisPackageManifest) {
return `# Genesis flexible object package
Task: ${manifest.title}
## Run
\`\`\`bash
pip install -r requirements.txt
python genesis_scene.py --steps 600
# Optional: --record saves simulation.mp4; --viewer opens an interactive viewer.
\`\`\`
## Contents
- \`assets/model${path.extname(manifest.assets.model)}\`: local generated 3D asset.
- \`flex-profile.json\`: real2sim physical profile exported from the UI sliders.
- \`manifest.json\`: package metadata and Genesis parameter mapping.
- \`genesis_scene.py\`: runnable Genesis scene using \`${manifest.genesis.solver}\`.
## Important
The GLB stores geometry and visual material only. It becomes deformable in Genesis because \`genesis_scene.py\` loads it with Genesis deformable material settings. If Genesis cannot tetrahedralize the GLB for FEM, convert the model to a clean watertight OBJ and update \`assets.model\` in \`manifest.json\`. Material values are illustrative presets, not calibrated measurements. External asset rights remain with their respective owners.
`
}
async function collectFiles(dir: string, prefix = ''): Promise<Array<{ absolutePath: string; archivePath: string }>> {
const entries = await readdir(dir, { withFileTypes: true })
const files = []
for (const entry of entries) {
const absolutePath = path.join(dir, entry.name)
const archivePath = prefix ? `${prefix}/${entry.name}` : entry.name
if (entry.isDirectory()) {
files.push(...(await collectFiles(absolutePath, archivePath)))
} else if (entry.isFile()) {
files.push({ absolutePath, archivePath })
}
}
return files
}
function writeTarString(buffer: Buffer, offset: number, length: number, value: string) {
buffer.write(value.slice(0, length), offset, length, 'utf8')
}
function octal(value: number, length: number) {
return value.toString(8).padStart(length - 1, '0').slice(-(length - 1)) + '\0'
}
function tarHeader(name: string, size: number, mode = 0o644) {
const header = Buffer.alloc(512, 0)
writeTarString(header, 0, 100, name)
writeTarString(header, 100, 8, octal(mode, 8))
writeTarString(header, 108, 8, octal(0, 8))
writeTarString(header, 116, 8, octal(0, 8))
writeTarString(header, 124, 12, octal(size, 12))
writeTarString(header, 136, 12, octal(Math.floor(Date.now() / 1000), 12))
header.fill(' ', 148, 156)
header.write('0', 156)
writeTarString(header, 257, 6, 'ustar')
writeTarString(header, 263, 2, '00')
let checksum = 0
for (const byte of header) checksum += byte
writeTarString(header, 148, 8, checksum.toString(8).padStart(6, '0') + '\0 ')
return header
}
async function createTarGz(sourceDir: string, archivePath: string) {
const files = await collectFiles(sourceDir)
const chunks: Buffer[] = []
for (const file of files) {
const content = await readFile(file.absolutePath)
chunks.push(tarHeader(file.archivePath, content.length), content)
const remainder = content.length % 512
if (remainder) {
chunks.push(Buffer.alloc(512 - remainder, 0))
}
}
chunks.push(Buffer.alloc(1024, 0))
await writeFile(archivePath, gzipSync(Buffer.concat(chunks)))
}
export async function createGenesisPackage(task: StoredTask): Promise<GenesisPackageResult> {
if (!isFlexTask(task)) {
throw new Error('Genesis export requires a flex task.')
}
const modelAssetPath = chooseModelAsset(task)
if (!modelAssetPath) {
throw new Error('Genesis export requires a cached local model asset.')
}
const simulation = task.request.simulation
const genesis = materialParameters(simulation)
const taskDirName = safePathSegment(task.taskId)
const packageDir = path.join(genesisPackageRoot, taskDirName)
const assetsDir = path.join(packageDir, 'assets')
const modelExtension = path.extname(modelAssetPath) || '.glb'
const modelRelativePath = `assets/model${modelExtension}`
const archivePath = path.join(genesisPackageRoot, `${taskDirName}.tar.gz`)
const previewAssetPath = choosePreviewAsset(task)
let previewRelativePath = previewAssetPath ? `assets/preview${path.extname(previewAssetPath) || '.webp'}` : undefined
await rm(packageDir, { recursive: true, force: true })
await mkdir(assetsDir, { recursive: true })
await copyFile(modelAssetPath, path.join(packageDir, modelRelativePath))
if (previewAssetPath && previewRelativePath && (await fileExists(previewAssetPath))) {
await copyFile(previewAssetPath, path.join(packageDir, previewRelativePath))
} else {
previewRelativePath = undefined
}
const manifest: GenesisPackageManifest = {
schema: 'real2sim.genesisPackage.v1',
taskId: task.taskId,
title: task.title,
assets: {
model: modelRelativePath,
...(previewRelativePath ? { preview: previewRelativePath } : {}),
},
genesis: {
script: 'genesis_scene.py',
solver: genesis.solver,
material: simulation.material,
gravity: simulation.gravity,
parameters: genesis.parameters,
},
notes: [
'The generated GLB is a visual mesh; Genesis deformability comes from the solver and material assigned in genesis_scene.py.',
'For FEM, Genesis may need a clean watertight mesh for tetrahedralization. Convert to OBJ if the GLB cannot be retetrahedralized.',
],
generatedAt: new Date().toISOString(),
}
await writeFile(path.join(packageDir, 'manifest.json'), JSON.stringify(manifest, null, 2))
await writeFile(path.join(packageDir, 'flex-profile.json'), JSON.stringify(createSimulationExport(task.request), null, 2))
await copyFile(new URL('./genesis_scene.py', import.meta.url), path.join(packageDir, 'genesis_scene.py'))
await copyFile(new URL('./physics_metrics.py', import.meta.url), path.join(packageDir, 'physics_metrics.py'))
await copyFile(new URL('../examples/requirements.txt', import.meta.url), path.join(packageDir, 'requirements.txt'))
await writeFile(path.join(packageDir, 'README.md'), packageReadme(manifest))
await mkdir(genesisPackageRoot, { recursive: true })
await createTarGz(packageDir, archivePath)
await stat(archivePath)
return {
packageDir,
archivePath,
manifest,
}
}

View File

@ -1,97 +0,0 @@
"""Run an exported Real2Sim scene. All geometry and parameters come from the package."""
import argparse
import json
from pathlib import Path
import genesis as gs
import numpy as np
from physics_metrics import shape_deformation
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--steps", type=int, default=600)
parser.add_argument("--backend", choices=["cpu", "gpu"], default="cpu")
parser.add_argument("--record", action="store_true")
parser.add_argument("--viewer", action="store_true")
parser.add_argument("--capture-every", type=int, default=5)
args = parser.parse_args()
if args.steps < 1 or args.capture_every < 1:
parser.error("steps and capture-every must be positive")
root = Path(__file__).resolve().parent
manifest = json.loads((root / "manifest.json").read_text())
config = manifest["genesis"]
params = config["parameters"]
gravity = -float(config["gravity"])
is_cloth = config["solver"] == "pbd_cloth"
dt = 0.005 if is_cloth else 0.002
gs.init(backend=gs.cpu if args.backend == "cpu" else gs.gpu, seed=0, logging_level="warning")
options = dict(
sim_options=gs.options.SimOptions(dt=dt, substeps=4, gravity=(0, 0, gravity)),
show_viewer=args.viewer,
)
if is_cloth:
options["pbd_options"] = gs.options.PBDOptions(max_stretch_solver_iterations=10)
else:
options["fem_options"] = gs.options.FEMOptions(
use_implicit_solver=True, n_newton_iterations=4, n_pcg_iterations=100,
damping=params["damping"], damping_alpha=params["damping"],
)
scene = gs.Scene(**options)
scene.add_entity(gs.morphs.Plane(), surface=gs.surfaces.Default(color=(0.84, 0.87, 0.88)))
mesh_options = dict(file=str(root / manifest["assets"]["model"]), pos=(0, 0, 0.35), scale=1.0)
if not is_cloth:
mesh_options.update(force_retet=True, maxvolume=params["maxVolume"])
material = (
gs.materials.PBD.Cloth(
stretch_compliance=params["stretchCompliance"], bending_compliance=params["bendCompliance"],
air_resistance=params["damping"],
)
if is_cloth else gs.materials.FEM.Elastic(E=params["E"], nu=params["nu"], rho=params["rho"])
)
body = scene.add_entity(
gs.morphs.Mesh(**mesh_options), material=material,
surface=gs.surfaces.Default(color=(0.12, 0.72, 0.62)),
)
camera = None
if args.record:
camera = scene.add_camera(res=(1280, 720), pos=(0.65, -0.85, 0.55), lookat=(0, 0, 0.16), fov=40, GUI=False)
print("Building Genesis scene...", flush=True)
scene.build()
print("Running solver...", flush=True)
def positions():
return body.get_state().pos.detach().cpu().numpy().reshape(-1, 3).copy()
initial = positions()
frames = [initial]
max_deformation = 0.0
min_z = float(initial[:, 2].min())
if camera:
camera.start_recording(save_to_filename=str(root / "simulation.mp4"), fps=50)
for step in range(args.steps):
scene.step()
if (step + 1) % args.capture_every == 0 or step == args.steps - 1:
pos = positions()
if not np.isfinite(pos).all() or np.abs(pos).max() > 100:
raise RuntimeError(f"Unstable solver state at step {step + 1}")
max_deformation = max(max_deformation, shape_deformation(initial, pos))
min_z = min(min_z, float(pos[:, 2].min()))
frames.append(pos)
if camera:
camera.stop_recording()
final = positions()
np.savez_compressed(root / "trajectory.npz", positions=np.asarray(frames), dt=dt * args.capture_every)
metrics = {
"genesis_version": gs.__version__, "backend": args.backend, "solver": config["solver"],
"steps": args.steps, "dt": dt, "gravity": config["gravity"], "vertex_count": len(initial),
"initial_center_z": float(initial[:, 2].mean()), "final_center_z": float(final[:, 2].mean()),
"min_vertex_z": min_z, "max_shape_deformation_m": max_deformation,
"all_finite": bool(np.isfinite(final).all()), "recorded": bool(camera),
}
(root / "metrics.json").write_text(json.dumps(metrics, indent=2) + "\n")
print(json.dumps(metrics, indent=2))
if __name__ == "__main__":
main()

View File

@ -1,289 +0,0 @@
import './config.js'
import express from 'express'
import { createReadStream } from 'node:fs'
import { stat } from 'node:fs/promises'
import path from 'node:path'
import { randomUUID } from 'node:crypto'
import { ZodError } from 'zod'
import { assetRoot, cacheTaskAssets, cacheTasksAssets } from './assetStore.js'
import { buildFlexiblePrompt, createSimulationExport } from './flex.js'
import { createGenesisPackage, genesisPackageRoot } from './genesisPackage.js'
import { createFlexTaskSchema, createTripoTaskSchema, exportGenesisSchema } from './schemas.js'
import { importExample } from './examples.js'
import { getTask, mergeTaskOutput, readTasks, upsertTask, writeTasks, type StoredTask } from './taskStore.js'
import { createTripoTask, queryTripoTask } from './tripoClient.js'
const app = express()
const port = Number(process.env.PORT || 8789)
const demo = process.env.REAL2SIM_DEMO === '1'
app.disable('x-powered-by')
app.use((req, res, next) => {
const localNames = new Set(['localhost', '127.0.0.1', '[::1]'])
const origin = req.get('origin')
try {
if (!localNames.has(req.hostname) || (origin && !localNames.has(new URL(origin).hostname))) {
res.status(403).json({ error: 'This workbench accepts local requests only.' })
return
}
} catch {
res.status(403).json({ error: 'Invalid request origin.' })
return
}
next()
})
app.use(express.json({ limit: '1mb' }))
app.use('/assets', express.static(assetRoot))
async function readTasksWithLocalAssets() {
const tasks = await readTasks()
const cached = await cacheTasksAssets(tasks)
if (cached.changed) {
await writeTasks(cached.tasks)
}
return cached.tasks
}
async function upsertTaskWithLocalAssets(task: StoredTask) {
const cachedTask = await cacheTaskAssets(task)
await upsertTask(cachedTask)
return cachedTask
}
app.get('/api/health', (_req, res) => {
res.json({
ok: true,
service: 'real2sim-platform',
apiConfigured: !demo && Boolean(process.env.DASHSCOPE_API_KEY),
demo,
defaultModel: 'Tripo/Tripo-H3.1',
})
})
app.post('/api/examples/soft-puck', async (_req, res, next) => {
try {
res.status(201).json({ task: await importExample() })
} catch (error) { next(error) }
})
app.post('/api/genesis/packages', async (req, res, next) => {
try {
const input = exportGenesisSchema.parse(req.body)
const source = await getTask(input.sourceTaskId)
if (!source) {
res.status(404).json({ error: 'Source asset not found.' })
return
}
const task: StoredTask = {
...source,
taskId: `export-${randomUUID()}`,
kind: 'flex',
request: {
sourceTaskId: source.taskId,
sourceName: source.title,
model: 'Tripo/Tripo-H3.1',
parameters: { texture_quality: 'standard', geometry_quality: 'standard', pbr: true, texture: true },
simulation: input.simulation,
},
}
const exported = await createGenesisPackage(task)
res.status(201).json({ manifest: exported.manifest, archiveUrl: `/api/genesis/exports/${task.taskId}/download` })
} catch (error) { next(error) }
})
app.get('/api/genesis/exports/:exportId/download', async (req, res, next) => {
if (!/^export-[0-9a-f-]{36}$/.test(req.params.exportId)) {
res.status(400).json({ error: 'Invalid export ID.' })
return
}
try {
const archive = path.join(genesisPackageRoot, `${req.params.exportId}.tar.gz`)
await stat(archive)
res.download(archive, `${req.params.exportId}.tar.gz`, { dotfiles: 'allow' })
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') res.status(404).json({ error: 'Export not found.' })
else next(error)
}
})
app.get('/api/tripo/tasks', async (_req, res, next) => {
try {
res.json({ tasks: await readTasksWithLocalAssets() })
} catch (error) {
next(error)
}
})
app.post('/api/tripo/tasks', async (req, res, next) => {
try {
const input = createTripoTaskSchema.parse(req.body)
const response = await createTripoTask(input)
const taskId = response.output?.task_id
if (!taskId || !response.output) {
throw new Error('DashScope did not return a task_id.')
}
const title = input.mode === 'text' ? input.prompt || taskId : input.mode === 'image' ? '单图生成' : '多图生成'
const now = new Date().toISOString()
const task: StoredTask = {
taskId,
kind: 'generation',
title,
status: response.output.task_status,
requestId: response.request_id,
request: input,
output: response.output,
usage: response.usage,
createdAt: now,
updatedAt: now,
}
const savedTask = await upsertTaskWithLocalAssets(task)
res.status(201).json({ task: savedTask })
} catch (error) {
next(error)
}
})
app.get('/api/tripo/tasks/:taskId', async (req, res, next) => {
try {
const stored = await getTask(req.params.taskId)
if (stored?.kind === 'sample') {
res.json({ task: stored })
return
}
const response = await queryTripoTask(req.params.taskId)
if (!response.output) {
throw new Error('DashScope did not return task output.')
}
const existing = await getTask(req.params.taskId)
const updated = existing
? mergeTaskOutput(existing, response.output, response.usage)
: ({
taskId: response.output.task_id,
kind: 'generation',
title: response.output.task_id,
status: response.output.task_status,
requestId: response.request_id,
request: {
mode: 'text',
model: 'Tripo/Tripo-H3.1',
prompt: '',
parameters: {
texture_quality: 'standard',
geometry_quality: 'standard',
pbr: true,
texture: true,
},
},
output: response.output,
usage: response.usage,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
} satisfies StoredTask)
const savedTask = await upsertTaskWithLocalAssets(updated)
res.json({ task: savedTask })
} catch (error) {
next(error)
}
})
app.post('/api/flex/tasks', async (req, res, next) => {
try {
const input = createFlexTaskSchema.parse(req.body)
const prompt = buildFlexiblePrompt(input)
const response = await createTripoTask({
mode: 'text',
model: input.model,
prompt,
parameters: input.parameters,
})
const taskId = response.output?.task_id
if (!taskId || !response.output) {
throw new Error('DashScope did not return a task_id.')
}
const now = new Date().toISOString()
const task: StoredTask = {
taskId,
kind: 'flex',
title: input.sourceName ? `${input.sourceName} · 柔性版本` : '柔性物体生成',
status: response.output.task_status,
requestId: response.request_id,
request: input,
output: response.output,
usage: response.usage,
createdAt: now,
updatedAt: now,
}
const savedTask = await upsertTaskWithLocalAssets(task)
res.status(201).json({
task: savedTask,
prompt,
simulationExport: createSimulationExport(input),
})
} catch (error) {
next(error)
}
})
app.get('/api/genesis/packages/:taskId', async (req, res, next) => {
try {
const task = await getTask(req.params.taskId)
if (!task) {
res.status(404).json({ error: 'Task not found.' })
return
}
const savedTask = await upsertTaskWithLocalAssets(task)
const exported = await createGenesisPackage(savedTask)
res.json({
manifest: exported.manifest,
archiveUrl: `/api/genesis/packages/${encodeURIComponent(savedTask.taskId)}/download`,
})
} catch (error) {
next(error)
}
})
app.get('/api/genesis/packages/:taskId/download', async (req, res, next) => {
try {
const task = await getTask(req.params.taskId)
if (!task) {
res.status(404).json({ error: 'Task not found.' })
return
}
const savedTask = await upsertTaskWithLocalAssets(task)
const exported = await createGenesisPackage(savedTask)
const archiveStat = await stat(exported.archivePath)
const filename = `${savedTask.taskId}-genesis-flex.tar.gz`
res.setHeader('Content-Type', 'application/gzip')
res.setHeader('Content-Length', archiveStat.size.toString())
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`)
createReadStream(exported.archivePath).on('error', next).pipe(res)
} catch (error) {
next(error)
}
})
app.use((error: unknown, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
void _next
if (error instanceof ZodError) {
res.status(400).json({ error: 'Validation failed', issues: error.issues })
return
}
const message = error instanceof Error ? error.message : 'Unknown server error.'
res.status(500).json({ error: message })
})
app.listen(port, '127.0.0.1', () => {
console.log(`real2sim assets served from ${path.relative(process.cwd(), assetRoot) || assetRoot}`)
console.log(`real2sim API listening on http://localhost:${port}`)
})

View File

@ -1,13 +0,0 @@
"""Separate shape change from translation and rigid rotation in a vertex trajectory."""
import numpy as np
def shape_deformation(initial, current):
reference = initial - initial.mean(axis=0)
observed = current - current.mean(axis=0)
# Kabsch alignment removes rigid motion without fitting scale or shear.
u, _, vh = np.linalg.svd(reference.T @ observed)
if np.linalg.det(u @ vh) < 0:
u[:, -1] *= -1
aligned = reference @ (u @ vh)
return float(np.linalg.norm(observed - aligned, axis=1).max())

View File

@ -1,14 +0,0 @@
import { describe, expect, it } from 'vitest'
import { createFlexTaskSchema } from './schemas.js'
const simulation = { material: 'silicone', elasticity: 72, damping: 42, thickness: 3.2, deformation: 64, gravity: 3.7 }
describe('flex source asset validation', () => {
it.each(['/assets/sample/model.glb', 'https://example.com/model.glb'])('accepts an asset URL: %s', (sourceModelUrl) => {
expect(createFlexTaskSchema.safeParse({ sourceModelUrl, simulation }).success).toBe(true)
})
it.each(['/assets/../secret', '/assets/%2e%2e/secret', '/assets/a%2fb/model.glb', '//example.com/a.glb', 'file:///etc/passwd', 'javascript:alert(1)', '/other/model.glb'])('rejects unsafe source: %s', (sourceModelUrl) => {
expect(createFlexTaskSchema.safeParse({ sourceModelUrl, simulation }).success).toBe(false)
})
})

View File

@ -1,101 +0,0 @@
import { z } from 'zod'
function isAssetUrl(value: string) {
if (value.startsWith('/assets/')) {
return /^\/assets\/[a-zA-Z0-9_-][a-zA-Z0-9._-]*\/[a-zA-Z0-9_-][a-zA-Z0-9._-]*$/.test(value)
}
try {
const url = new URL(value)
return (url.protocol === 'https:' || url.protocol === 'http:') && !url.username && !url.password
} catch {
return false
}
}
export const tripoModelSchema = z.enum(['Tripo/Tripo-H3.1', 'Tripo/Tripo-P1.0'])
export const generationModeSchema = z.enum(['text', 'image', 'multiImage'])
export const tripoParametersSchema = z.object({
texture_quality: z.enum(['standard', 'detailed']).default('standard'),
geometry_quality: z.enum(['standard', 'ultra']).default('standard'),
pbr: z.boolean().default(true),
texture: z.boolean().default(true),
})
export const multiImageSlotSchema = z.object({
type: z.enum(['jpeg', 'png']).default('png'),
file_token: z.string().url().or(z.literal('')).default(''),
})
export const createTripoTaskSchema = z
.object({
mode: generationModeSchema,
model: tripoModelSchema.default('Tripo/Tripo-H3.1'),
prompt: z.string().trim().max(1024).optional(),
image: z.string().trim().url().optional().or(z.literal('')),
images: z.array(multiImageSlotSchema).length(4).optional(),
parameters: tripoParametersSchema.default({ texture_quality: 'standard', geometry_quality: 'standard', pbr: true, texture: true }),
})
.superRefine((data, ctx) => {
if (data.mode === 'text' && !data.prompt) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['prompt'],
message: 'Prompt is required for text-to-3D.',
})
}
if (data.mode === 'image' && !data.image) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['image'],
message: 'Image URL is required for image-to-3D.',
})
}
if (data.mode === 'multiImage') {
const validImages = data.images?.filter((item) => item.file_token).length ?? 0
if (validImages < 2) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['images'],
message: 'At least two image URLs are required for multi-image generation.',
})
}
}
})
export const simulationProfileSchema = z.object({
material: z.enum(['silicone', 'cloth', 'inflatable', 'softRobot']),
elasticity: z.number().min(0).max(100),
damping: z.number().min(0).max(100),
thickness: z.number().min(0.1).max(20),
deformation: z.number().min(0).max(100),
gravity: z.number().min(0).max(30),
})
export const createFlexTaskSchema = z.object({
sourceTaskId: z.string().trim().optional(),
sourceName: z.string().trim().max(160).optional(),
sourcePrompt: z.string().trim().max(1024).optional(),
sourceModelUrl: z.string().trim().refine(isAssetUrl, 'Expected a local asset path or HTTP(S) URL.').optional().or(z.literal('')),
behaviorPrompt: z.string().trim().max(1024).optional(),
model: tripoModelSchema.default('Tripo/Tripo-H3.1'),
parameters: tripoParametersSchema.default({
texture_quality: 'detailed',
geometry_quality: 'standard',
pbr: true,
texture: true,
}),
simulation: simulationProfileSchema,
})
export type CreateTripoTaskInput = z.infer<typeof createTripoTaskSchema>
export type CreateFlexTaskInput = z.infer<typeof createFlexTaskSchema>
export type SimulationProfile = z.infer<typeof simulationProfileSchema>
export const exportGenesisSchema = z.object({
sourceTaskId: z.string().regex(/^[a-zA-Z0-9_-][a-zA-Z0-9._-]{0,159}$/),
simulation: simulationProfileSchema,
})

View File

@ -1,68 +0,0 @@
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import path from 'node:path'
import type { CreateFlexTaskInput, CreateTripoTaskInput } from './schemas.js'
import type { DashScopeTaskOutput, TaskStatus } from './tripoClient.js'
const dataDir = path.resolve(process.env.REAL2SIM_DATA_ROOT || path.join(process.cwd(), '.data'))
const storePath = path.join(dataDir, 'tasks.json')
export type StoredTask = {
taskId: string
kind: 'generation' | 'flex' | 'sample'
title: string
status: TaskStatus
requestId?: string
request: CreateTripoTaskInput | CreateFlexTaskInput
output?: DashScopeTaskOutput
usage?: Record<string, unknown>
createdAt: string
updatedAt: string
}
async function ensureStore() {
await mkdir(dataDir, { recursive: true })
}
export async function readTasks(): Promise<StoredTask[]> {
try {
const body = await readFile(storePath, 'utf8')
return JSON.parse(body) as StoredTask[]
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
return []
}
throw error
}
}
export async function writeTasks(tasks: StoredTask[]) {
await ensureStore()
await writeFile(storePath, JSON.stringify(tasks, null, 2))
}
export async function upsertTask(task: StoredTask) {
const tasks = await readTasks()
const index = tasks.findIndex((item) => item.taskId === task.taskId)
if (index >= 0) {
tasks[index] = task
} else {
tasks.unshift(task)
}
await writeTasks(tasks.slice(0, 80))
return task
}
export async function getTask(taskId: string) {
const tasks = await readTasks()
return tasks.find((task) => task.taskId === taskId)
}
export function mergeTaskOutput(task: StoredTask, output: DashScopeTaskOutput, usage?: Record<string, unknown>) {
return {
...task,
status: output.task_status,
output,
usage,
updatedAt: new Date().toISOString(),
} satisfies StoredTask
}

View File

@ -1,113 +0,0 @@
import type { CreateTripoTaskInput } from './schemas.js'
export type TaskStatus = 'PENDING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'CANCELED' | 'UNKNOWN'
export type TripoTaskResult = {
model_url?: string
pbr_model_url?: string
base_model_url?: string
rendered_image_url?: string
local_model_url?: string
local_pbr_model_url?: string
local_base_model_url?: string
local_rendered_image_url?: string
orig_prompt?: string
}
export type DashScopeTaskOutput = {
task_id: string
task_status: TaskStatus
submit_time?: string
scheduled_time?: string
end_time?: string
results?: TripoTaskResult[]
}
export type DashScopeTaskResponse = {
request_id?: string
output?: DashScopeTaskOutput
usage?: Record<string, unknown>
code?: string
message?: string
}
export type TripoPayload = {
model: CreateTripoTaskInput['model']
input: {
prompt?: string
image?: string
images?: Array<Record<string, string>>
}
parameters: CreateTripoTaskInput['parameters']
}
const apiBase = process.env.DASHSCOPE_API_BASE || 'https://dashscope.aliyuncs.com/api/v1'
function apiKey() {
if (process.env.REAL2SIM_DEMO === '1') throw new Error('Generation is disabled in offline demo mode.')
const key = process.env.DASHSCOPE_API_KEY
if (!key) {
throw new Error('DASHSCOPE_API_KEY is not configured.')
}
return key
}
async function readDashScopeResponse(response: Response): Promise<DashScopeTaskResponse> {
const text = await response.text()
const json = text ? (JSON.parse(text) as DashScopeTaskResponse) : {}
if (!response.ok || json.code) {
const message = json.message || `DashScope request failed with HTTP ${response.status}.`
throw new Error(message)
}
return json
}
export function toTripoPayload(input: CreateTripoTaskInput): TripoPayload {
const payload: TripoPayload = {
model: input.model,
input: {},
parameters: input.parameters,
}
if (input.mode === 'text') {
payload.input.prompt = input.prompt
}
if (input.mode === 'image') {
payload.input.image = input.image || undefined
}
if (input.mode === 'multiImage') {
payload.input.images = input.images?.map((item): Record<string, string> =>
item.file_token ? { type: item.type, file_token: item.file_token } : {},
)
}
return payload
}
export async function createTripoTask(input: CreateTripoTaskInput) {
const response = await fetch(`${apiBase}/services/aigc/video-generation/3d-generation`, {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey()}`,
'Content-Type': 'application/json',
'X-DashScope-Async': 'enable',
},
body: JSON.stringify(toTripoPayload(input)),
})
return readDashScopeResponse(response)
}
export async function queryTripoTask(taskId: string) {
const response = await fetch(`${apiBase}/tasks/${encodeURIComponent(taskId)}`, {
headers: {
Authorization: `Bearer ${apiKey()}`,
},
})
return readDashScopeResponse(response)
}

View File

@ -1,756 +0,0 @@
.app-shell {
min-height: 100vh;
color: #18211f;
background: #f7f9fa;
}
.topbar {
position: sticky;
top: 0;
z-index: 10;
display: grid;
grid-template-columns: minmax(210px, 1fr) auto auto;
gap: 22px;
align-items: center;
padding: 18px 28px;
border-bottom: 1px solid rgba(31, 41, 38, 0.12);
background: #f8fbf9;
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
isolation: isolate;
}
.brand {
display: flex;
align-items: center;
min-width: 0;
gap: 12px;
}
.brand-mark {
display: grid;
flex: 0 0 auto;
width: 38px;
height: 38px;
place-items: center;
color: #052e2b;
border: 1px solid rgba(4, 120, 87, 0.24);
border-radius: 8px;
background: linear-gradient(145deg, #b7f6e9, #f5fffb);
box-shadow: 0 14px 30px rgba(20, 83, 45, 0.1);
}
.brand h1 {
margin: 0;
font-size: 20px;
line-height: 1.1;
font-weight: 720;
}
.brand p {
margin: 3px 0 0;
color: #5a6864;
font-size: 13px;
}
.tabs {
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
padding: 4px;
border: 1px solid rgba(31, 41, 38, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.66);
}
.tabs button,
.language-button,
.secondary-button,
.submit-button,
.asset-actions button,
.toggle,
.segmented button,
.timeline-item {
font: inherit;
letter-spacing: 0;
}
.tabs button {
display: inline-flex;
min-height: 34px;
align-items: center;
justify-content: center;
gap: 7px;
padding: 0 12px;
color: #52625d;
border: 0;
border-radius: 6px;
background: transparent;
cursor: pointer;
}
.tabs button.active {
color: #10201c;
background: #ffffff;
box-shadow: 0 5px 16px rgba(15, 23, 42, 0.08);
}
.top-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 10px;
}
.api-status,
.language-button {
display: inline-flex;
min-height: 34px;
align-items: center;
justify-content: center;
gap: 7px;
padding: 0 11px;
border-radius: 7px;
border: 1px solid rgba(31, 41, 38, 0.13);
background: rgba(255, 255, 255, 0.72);
color: #42514d;
font-size: 13px;
white-space: nowrap;
}
.api-status.ready {
color: #047857;
}
.api-status.missing {
color: #b45309;
}
.language-button {
cursor: pointer;
}
.error-banner {
margin: 16px 28px 0;
padding: 11px 14px;
color: #7f1d1d;
border: 1px solid rgba(248, 113, 113, 0.35);
border-radius: 8px;
background: #fff7f7;
font-size: 14px;
}
.workbench {
display: grid;
grid-template-columns: minmax(284px, 330px) minmax(420px, 1fr) minmax(284px, 336px);
gap: 18px;
padding: 18px 28px;
}
.control-panel,
.result-panel,
.viewport-panel,
.timeline {
border: 1px solid rgba(31, 41, 38, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.78);
box-shadow: none;
}
.panel-form,
.result-panel {
display: flex;
flex-direction: column;
gap: 15px;
padding: 16px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.panel-heading h2 {
margin: 2px 0 0;
color: #15211e;
font-size: 19px;
line-height: 1.22;
}
.panel-label {
display: block;
color: #60706b;
font-size: 12px;
font-weight: 700;
}
.field {
display: flex;
flex-direction: column;
gap: 7px;
min-width: 0;
color: #52625d;
font-size: 13px;
font-weight: 650;
}
.field-inline {
display: grid;
grid-template-columns: 92px minmax(0, 1fr) 44px;
align-items: center;
gap: 10px;
}
.field-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
input,
textarea,
select {
width: 100%;
box-sizing: border-box;
color: #16231f;
border: 1px solid rgba(31, 41, 38, 0.14);
border-radius: 7px;
background: rgba(255, 255, 255, 0.9);
outline: none;
font: 14px/1.35 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
letter-spacing: 0;
}
input,
select {
height: 38px;
padding: 0 10px;
}
textarea {
min-height: 88px;
resize: vertical;
padding: 10px;
}
input:focus,
textarea:focus,
select:focus {
border-color: rgba(20, 184, 166, 0.72);
box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.14);
}
.segmented {
display: flex;
flex-wrap: wrap;
gap: 5px;
padding: 4px;
border: 1px solid rgba(31, 41, 38, 0.12);
border-radius: 8px;
background: #eef4f1;
}
.segmented button {
display: inline-flex;
flex: 1 1 auto;
min-height: 30px;
align-items: center;
justify-content: center;
gap: 6px;
padding: 0 8px;
color: #566662;
border: 0;
border-radius: 6px;
background: transparent;
cursor: pointer;
font-size: 13px;
}
.segmented button.selected {
color: #0f211d;
background: #ffffff;
box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}
.toggle-row,
.button-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.toggle {
display: inline-flex;
min-height: 38px;
align-items: center;
justify-content: center;
gap: 8px;
color: #4d5d58;
border: 1px solid rgba(31, 41, 38, 0.13);
border-radius: 7px;
background: #ffffff;
cursor: pointer;
}
.toggle:disabled {
cursor: not-allowed;
opacity: 0.7;
}
.switch {
position: relative;
display: inline-block;
width: 28px;
height: 16px;
border-radius: 999px;
background: #cfd9d4;
}
.switch::after {
position: absolute;
top: 3px;
left: 3px;
width: 10px;
height: 10px;
content: '';
border-radius: 50%;
background: #ffffff;
transition: transform 0.2s ease;
}
.toggle.checked .switch {
background: #14b8a6;
}
.toggle.checked .switch::after {
transform: translateX(12px);
}
.submit-button,
.primary-link,
.secondary-button,
.secondary-link {
display: inline-flex;
min-height: 40px;
align-items: center;
justify-content: center;
gap: 8px;
padding: 0 12px;
border-radius: 7px;
text-decoration: none;
cursor: pointer;
box-sizing: border-box;
}
.submit-button,
.primary-link {
color: #06201c;
border: 1px solid rgba(20, 184, 166, 0.42);
background: linear-gradient(135deg, #67f2dc, #d9f99d);
box-shadow: 0 12px 22px rgba(20, 184, 166, 0.18);
}
.submit-button:disabled {
cursor: wait;
opacity: 0.72;
}
.secondary-button,
.secondary-link {
color: #25312e;
border: 1px solid rgba(31, 41, 38, 0.14);
background: #ffffff;
}
.image-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.slider-stack {
display: flex;
flex-direction: column;
gap: 10px;
}
input[type='range'] {
height: 22px;
padding: 0;
accent-color: #14b8a6;
box-shadow: none;
}
output {
color: #1c2925;
font-size: 13px;
font-weight: 700;
text-align: right;
}
.viewport-panel {
display: flex;
min-height: 640px;
flex-direction: column;
overflow: hidden;
}
.viewport-toolbar {
display: flex;
min-height: 58px;
align-items: center;
justify-content: space-between;
gap: 14px;
padding: 12px 15px;
border-bottom: 1px solid rgba(31, 41, 38, 0.1);
}
.viewport-toolbar strong {
display: block;
margin-top: 2px;
font-size: 16px;
}
.mini-link {
display: inline-flex;
min-width: 44px;
min-height: 30px;
align-items: center;
justify-content: center;
color: #06322c;
border: 1px solid rgba(20, 184, 166, 0.34);
border-radius: 6px;
background: #ecfffb;
font-size: 12px;
font-weight: 800;
text-decoration: none;
}
.canvas-wrap {
position: relative;
min-height: 0;
flex: 1;
background: #f1f5f4;
}
.icon-button {
display: grid;
place-items: center;
width: 34px;
height: 34px;
padding: 0;
color: #176c60;
background: #fff;
border: 1px solid #cbd9d5;
border-radius: 6px;
cursor: pointer;
}
.icon-button[aria-pressed='true'] { background: #d4f8ee; }
.viewport-toolbar > div { margin-right: auto; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.button-grid > * { min-width: 0; padding: 8px; font-size: 13px; }
.canvas-fallback {
display: grid;
width: 100%;
height: 100%;
min-height: 420px;
place-items: center;
color: #60706b;
font-size: 14px;
}
.viewport-image-preview {
display: grid;
width: 100%;
height: 100%;
min-height: 420px;
place-items: center;
padding: 20px;
box-sizing: border-box;
}
.viewport-image-preview img {
width: min(100%, 980px);
max-height: 100%;
object-fit: contain;
border-radius: 8px;
box-shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
}
.result-panel {
min-height: 640px;
}
.render-preview,
.render-empty,
.empty-panel {
display: grid;
min-height: 174px;
place-items: center;
overflow: hidden;
color: #60706b;
border: 1px solid rgba(31, 41, 38, 0.1);
border-radius: 8px;
background: #f5faf7;
}
.render-preview img {
width: 100%;
height: 214px;
object-fit: cover;
}
.task-meta {
display: flex;
flex-direction: column;
gap: 10px;
margin: 0;
}
.task-meta div {
display: grid;
grid-template-columns: 86px minmax(0, 1fr);
gap: 8px;
align-items: start;
}
.task-meta dt {
color: #60706b;
font-size: 12px;
font-weight: 700;
}
.task-meta dd {
min-width: 0;
margin: 0;
overflow-wrap: anywhere;
color: #16231f;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
font-size: 12px;
}
.button-stack {
display: flex;
flex-direction: column;
gap: 9px;
margin-top: auto;
}
.status-pill {
display: inline-flex;
min-height: 24px;
align-items: center;
justify-content: center;
padding: 0 8px;
border-radius: 999px;
font-size: 12px;
font-weight: 750;
white-space: nowrap;
}
.status-pending,
.status-running {
color: #075985;
background: #e0f2fe;
}
.status-succeeded {
color: #047857;
background: #dffbed;
}
.status-failed,
.status-canceled,
.status-unknown {
color: #9f1239;
background: #ffe4e6;
}
.asset-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.asset-row {
display: grid;
grid-template-columns: 54px minmax(0, 1fr) auto;
gap: 11px;
align-items: center;
padding: 10px;
border: 1px solid rgba(31, 41, 38, 0.1);
border-radius: 8px;
background: #ffffff;
}
.asset-row img,
.asset-thumb {
width: 54px;
height: 54px;
border-radius: 7px;
object-fit: cover;
background: #eef4f1;
}
.asset-thumb {
display: grid;
place-items: center;
color: #60706b;
}
.asset-row strong,
.asset-row span {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.asset-row strong {
color: #16231f;
font-size: 14px;
}
.asset-row span {
margin: 2px 0 6px;
color: #60706b;
font-size: 12px;
}
.asset-actions {
display: flex;
gap: 6px;
}
.asset-actions button {
display: grid;
width: 32px;
height: 32px;
place-items: center;
color: #243430;
border: 1px solid rgba(31, 41, 38, 0.12);
border-radius: 7px;
background: #f8fbf9;
cursor: pointer;
}
.timeline {
margin: 0 28px 24px;
padding: 12px;
}
.timeline-title {
display: flex;
align-items: center;
gap: 7px;
color: #52625d;
font-size: 13px;
font-weight: 760;
}
.timeline-strip {
display: flex;
gap: 10px;
overflow-x: auto;
padding: 10px 0 2px;
}
.timeline-strip p {
margin: 0;
color: #60706b;
font-size: 13px;
}
.timeline-item {
display: grid;
flex: 0 0 210px;
grid-template-columns: minmax(0, 1fr) auto;
gap: 4px 8px;
align-items: center;
padding: 10px;
text-align: left;
border: 1px solid rgba(31, 41, 38, 0.11);
border-radius: 8px;
background: #ffffff;
cursor: pointer;
}
.timeline-item.selected {
border-color: rgba(20, 184, 166, 0.48);
box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.18);
}
.timeline-item span:first-child {
color: #60706b;
font-size: 12px;
}
.timeline-item strong {
grid-column: 1 / -1;
overflow: hidden;
color: #17231f;
font-size: 13px;
text-overflow: ellipsis;
white-space: nowrap;
}
@media (max-width: 1180px) {
.topbar {
grid-template-columns: 1fr;
align-items: stretch;
}
.tabs {
justify-content: flex-start;
overflow-x: auto;
}
.top-actions {
justify-content: flex-start;
flex-wrap: wrap;
}
.workbench {
grid-template-columns: 1fr;
}
.viewport-panel,
.result-panel {
min-height: 500px;
}
.viewport-panel { grid-row: 1; height: 500px; }
.topbar { position: static; gap: 12px; }
}
@media (max-width: 680px) {
.topbar,
.workbench {
padding-right: 14px;
padding-left: 14px;
}
.tabs button {
min-width: max-content;
}
.field-row,
.toggle-row,
.button-grid,
.image-grid {
grid-template-columns: 1fr;
}
.field-inline {
grid-template-columns: 1fr;
}
.timeline {
margin-right: 14px;
margin-left: 14px;
}
}

View File

@ -1,809 +0,0 @@
import {
AlertTriangle,
Box,
BrainCircuit,
CheckCircle2,
Database,
Download,
ExternalLink,
Image,
Languages,
Layers,
Package,
RefreshCw,
SlidersHorizontal,
Sparkles,
Waves,
} from 'lucide-react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { Viewport3D } from './components/Viewport3D'
import {
createFlexTask,
createGenerationTask,
getModelUrl,
getBaseModelUrl,
getPreviewImageUrl,
getPbrModelUrl,
getSourcePrompt,
health,
isLiveStatus,
listTasks,
importExample,
exportGenesis,
refreshTask,
type FlexRequest,
type GenerationRequest,
type SimulationProfile,
type StoredTask,
type TaskStatus,
} from './lib/api'
import { downloadJson } from './lib/download'
import { getInitialLocale, messages, type Locale, type Messages } from './lib/i18n'
import './App.css'
type TabId = 'generation' | 'flex' | 'library'
type GenerationMode = GenerationRequest['mode']
type TripoModel = GenerationRequest['model']
const defaultParameters: GenerationRequest['parameters'] = {
texture_quality: 'detailed',
geometry_quality: 'standard',
pbr: true,
texture: true,
}
const defaultSimulation: SimulationProfile = {
material: 'silicone',
elasticity: 72,
damping: 42,
thickness: 3.2,
deformation: 64,
gravity: 9.8,
}
const imageLabels = ['front', 'left', 'back', 'right'] as const
function statusText(status: TaskStatus | undefined, t: Messages) {
const key = (status || 'UNKNOWN').toLowerCase() as 'pending' | 'running' | 'succeeded' | 'failed' | 'canceled' | 'unknown'
return t.task[key]
}
function formatTime(value?: string) {
if (!value) return '-'
return new Intl.DateTimeFormat('zh-CN', {
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
}).format(new Date(value))
}
function Field({
label,
children,
inline = false,
}: {
label: string
children: React.ReactNode
inline?: boolean
}) {
return (
<label className={inline ? 'field field-inline' : 'field'}>
<span>{label}</span>
{children}
</label>
)
}
function Segmented<T extends string>({
value,
options,
onChange,
}: {
value: T
options: Array<{ value: T; label: string; icon?: React.ReactNode }>
onChange: (value: T) => void
}) {
return (
<div className="segmented">
{options.map((option) => (
<button
type="button"
key={option.value}
className={value === option.value ? 'selected' : ''}
onClick={() => onChange(option.value)}
>
{option.icon}
<span>{option.label}</span>
</button>
))}
</div>
)
}
function Toggle({
checked,
label,
disabled,
onChange,
}: {
checked: boolean
label: string
disabled?: boolean
onChange: (value: boolean) => void
}) {
return (
<button
type="button"
className={`toggle ${checked ? 'checked' : ''}`}
disabled={disabled}
onClick={() => onChange(!checked)}
aria-pressed={checked}
>
<span className="switch" />
{label}
</button>
)
}
function StatusPill({ status, t }: { status?: TaskStatus; t: Messages }) {
const normalized = (status || 'UNKNOWN').toLowerCase()
return <span className={`status-pill status-${normalized}`}>{statusText(status, t)}</span>
}
function TaskPanel({
task,
busy,
onRefresh,
onUseForFlex,
t,
}: {
task?: StoredTask | null
busy: boolean
onRefresh: (taskId: string) => void
onUseForFlex: (task: StoredTask) => void
t: Messages
}) {
const modelUrl = getModelUrl(task)
const previewImageUrl = getPreviewImageUrl(task)
const pbrModelUrl = getPbrModelUrl(task)
const baseModelUrl = getBaseModelUrl(task)
return (
<aside className="result-panel">
<div className="panel-heading">
<div>
<span className="panel-label">{t.task.title}</span>
<h2>{task ? t.task.current : t.task.noTask}</h2>
</div>
{task ? <StatusPill status={task.status} t={t} /> : null}
</div>
{task ? (
<>
{previewImageUrl ? (
<a href={previewImageUrl} target="_blank" rel="noreferrer" className="render-preview">
<img src={previewImageUrl} alt={t.task.rendered} />
</a>
) : (
<div className="render-empty">
<Box size={28} />
</div>
)}
<dl className="task-meta">
<div>
<dt>{t.task.taskId}</dt>
<dd>{task.taskId}</dd>
</div>
<div>
<dt>{t.task.status}</dt>
<dd>{statusText(task.status, t)}</dd>
</div>
{task.requestId ? (
<div>
<dt>{t.task.requestId}</dt>
<dd>{task.requestId}</dd>
</div>
) : null}
</dl>
<div className="button-stack">
<button type="button" className="secondary-button" onClick={() => onRefresh(task.taskId)} disabled={busy}>
<RefreshCw size={16} />
{t.task.poll}
</button>
{pbrModelUrl ? (
<a href={pbrModelUrl} className="primary-link" target="_blank" rel="noreferrer">
<Download size={16} />
{t.task.downloadPbr}
</a>
) : null}
{baseModelUrl ? (
<a href={baseModelUrl} className="secondary-link" target="_blank" rel="noreferrer">
<Download size={16} />
{t.task.downloadBase}
</a>
) : null}
{task.kind === 'flex' && modelUrl ? (
<a href={`/api/genesis/packages/${encodeURIComponent(task.taskId)}/download`} className="secondary-link">
<Package size={16} />
{t.task.exportGenesis}
</a>
) : null}
{modelUrl ? (
<button type="button" className="secondary-button" onClick={() => onUseForFlex(task)}>
<Waves size={16} />
{t.library.useForFlex}
</button>
) : null}
</div>
</>
) : (
<div className="empty-panel">
<Sparkles size={28} />
</div>
)}
</aside>
)
}
function Timeline({
tasks,
currentTaskId,
onSelect,
t,
}: {
tasks: StoredTask[]
currentTaskId?: string
onSelect: (task: StoredTask) => void
t: Messages
}) {
return (
<section className="timeline">
<div className="timeline-title">
<Database size={16} />
<span>{t.timeline.title}</span>
</div>
<div className="timeline-strip">
{tasks.length ? (
tasks.slice(0, 10).map((task) => (
<button
type="button"
key={task.taskId}
className={task.taskId === currentTaskId ? 'timeline-item selected' : 'timeline-item'}
onClick={() => onSelect(task)}
>
<span>{task.kind === 'sample' ? t.app.demoMode : task.kind === 'flex' ? t.tabs.flex : t.tabs.generation}</span>
<strong>{task.title}</strong>
<StatusPill status={task.status} t={t} />
</button>
))
) : (
<p>{t.timeline.empty}</p>
)}
</div>
</section>
)
}
function App() {
const [locale, setLocale] = useState<Locale>(getInitialLocale)
const t = messages[locale]
const [activeTab, setActiveTab] = useState<TabId>('generation')
const [apiConfigured, setApiConfigured] = useState(false)
const [demoMode, setDemoMode] = useState(false)
const [tasks, setTasks] = useState<StoredTask[]>([])
const [currentTask, setCurrentTask] = useState<StoredTask | null>(null)
const [error, setError] = useState('')
const [busy, setBusy] = useState(false)
const [mode, setMode] = useState<GenerationMode>('text')
const [model, setModel] = useState<TripoModel>('Tripo/Tripo-H3.1')
const [prompt, setPrompt] = useState('一只由柔性硅胶制成的机器人夹爪,带有清晰的传感器细节')
const [imageUrl, setImageUrl] = useState('')
const [imageSlots, setImageSlots] = useState([
{ type: 'png' as const, file_token: '' },
{ type: 'png' as const, file_token: '' },
{ type: 'png' as const, file_token: '' },
{ type: 'png' as const, file_token: '' },
])
const [parameters, setParameters] = useState<GenerationRequest['parameters']>(defaultParameters)
const [sourceTaskId, setSourceTaskId] = useState('')
const [sourceName, setSourceName] = useState('')
const [sourcePrompt, setSourcePrompt] = useState('')
const [sourceModelUrl, setSourceModelUrl] = useState('')
const [behaviorPrompt, setBehaviorPrompt] = useState('保持原始结构比例,转化为适合抓取、挤压和碰撞仿真的柔性版本')
const [simulation, setSimulation] = useState<SimulationProfile>(defaultSimulation)
const successfulTasks = useMemo(() => tasks.filter((task) => getModelUrl(task)), [tasks])
const loadTasks = useCallback(async () => {
const response = await listTasks()
setTasks(response.tasks)
setCurrentTask((current) => {
if (!current) return response.tasks[0] ?? null
return response.tasks.find((task) => task.taskId === current.taskId) ?? current
})
}, [])
useEffect(() => {
health()
.then((response) => { setApiConfigured(response.apiConfigured); setDemoMode(response.demo) })
.catch(() => setApiConfigured(false))
loadTasks().catch((loadError) => setError(loadError instanceof Error ? loadError.message : t.errors.generic))
}, [loadTasks, t.errors.generic])
useEffect(() => {
window.localStorage.setItem('real2sim.locale', locale)
}, [locale])
useEffect(() => {
if (!currentTask || !isLiveStatus(currentTask.status)) return
const timer = window.setInterval(() => {
refreshTask(currentTask.taskId)
.then((response) => {
setCurrentTask(response.task)
setTasks((items) => [response.task, ...items.filter((item) => item.taskId !== response.task.taskId)])
})
.catch((pollError) => setError(pollError instanceof Error ? pollError.message : t.errors.generic))
}, 15000)
return () => window.clearInterval(timer)
}, [currentTask, t.errors.generic])
function updateParameters(next: Partial<GenerationRequest['parameters']>) {
setParameters((current) => ({ ...current, ...next }))
}
function selectTask(task: StoredTask) {
setCurrentTask(task)
}
function selectTaskForFlex(task: StoredTask) {
setCurrentTask(task)
setSourceTaskId(task.taskId)
setSourceName(task.title)
setSourcePrompt(getSourcePrompt(task))
setSourceModelUrl(getModelUrl(task))
if (task.request.simulation && typeof task.request.simulation === 'object') {
setSimulation(task.request.simulation as SimulationProfile)
}
setActiveTab('flex')
}
async function loadExample() {
setBusy(true)
setError('')
try {
const { task } = await importExample()
selectTaskForFlex(task)
await loadTasks()
} catch (e) { setError(e instanceof Error ? e.message : t.errors.generic) }
finally { setBusy(false) }
}
async function downloadGenesis() {
setBusy(true)
setError('')
try {
const id = sourceTaskId || currentTask?.taskId
if (!id) return
const result = await exportGenesis(id, simulation)
const link = document.createElement('a')
link.href = result.archiveUrl
link.download = ''
link.click()
} catch (e) { setError(e instanceof Error ? e.message : t.errors.generic) }
finally { setBusy(false) }
}
async function handleGenerationSubmit(event: React.FormEvent) {
event.preventDefault()
setBusy(true)
setError('')
const payload: GenerationRequest = {
mode,
model,
prompt: mode === 'text' ? prompt.trim() : undefined,
image: mode === 'image' ? imageUrl.trim() : undefined,
images: mode === 'multiImage' ? imageSlots : undefined,
parameters,
}
try {
const response = await createGenerationTask(payload)
setCurrentTask(response.task)
await loadTasks()
} catch (submitError) {
setError(submitError instanceof Error ? submitError.message : t.errors.generic)
} finally {
setBusy(false)
}
}
async function handleFlexSubmit(event: React.FormEvent) {
event.preventDefault()
setBusy(true)
setError('')
const payload: FlexRequest = {
sourceTaskId: sourceTaskId || undefined,
sourceName: sourceName || undefined,
sourcePrompt: sourcePrompt || undefined,
sourceModelUrl: sourceModelUrl || undefined,
behaviorPrompt,
model: 'Tripo/Tripo-H3.1',
parameters: {
texture_quality: 'detailed',
geometry_quality: 'standard',
pbr: true,
texture: true,
},
simulation,
}
try {
const response = await createFlexTask(payload)
setCurrentTask(response.task)
await loadTasks()
} catch (submitError) {
setError(submitError instanceof Error ? submitError.message : t.errors.generic)
} finally {
setBusy(false)
}
}
async function handleRefreshTask(taskId: string) {
setBusy(true)
setError('')
try {
const response = await refreshTask(taskId)
setCurrentTask(response.task)
await loadTasks()
} catch (refreshError) {
setError(refreshError instanceof Error ? refreshError.message : t.errors.generic)
} finally {
setBusy(false)
}
}
function exportSimulation() {
const profile = {
schema: 'real2sim.flexProfile.v1',
source: {
taskId: sourceTaskId || undefined,
modelUrl: sourceModelUrl || undefined,
prompt: sourcePrompt || undefined,
name: sourceName || undefined,
},
material: simulation.material,
physics: {
elasticity: simulation.elasticity / 100,
damping: simulation.damping / 100,
thicknessMm: simulation.thickness,
maxDeformation: simulation.deformation / 100,
gravity: simulation.gravity,
},
solver: {
type: simulation.material === 'cloth' ? 'pbd_cloth' : 'fem_elastic',
substeps: 4,
parametersArePresets: true,
},
generatedAt: new Date().toISOString(),
} satisfies Record<string, unknown>
downloadJson('real2sim-flex-profile.json', profile)
}
return (
<div className="app-shell">
<header className="topbar">
<div className="brand">
<div className="brand-mark">
<Box size={20} />
</div>
<div>
<h1>{t.app.name}</h1>
<p>{t.app.subtitle}</p>
</div>
</div>
<nav className="tabs" aria-label="primary">
<button type="button" className={activeTab === 'generation' ? 'active' : ''} onClick={() => setActiveTab('generation')}>
<Sparkles size={17} />
{t.tabs.generation}
</button>
<button type="button" className={activeTab === 'flex' ? 'active' : ''} onClick={() => setActiveTab('flex')}>
<Waves size={17} />
{t.tabs.flex}
</button>
<button type="button" className={activeTab === 'library' ? 'active' : ''} onClick={() => setActiveTab('library')}>
<Database size={17} />
{t.tabs.library}
</button>
</nav>
<div className="top-actions">
<button type="button" className="secondary-button" onClick={loadExample} disabled={busy}>
<Box size={16} />{t.app.loadExample}
</button>
<span className={apiConfigured ? 'api-status ready' : 'api-status missing'}>
{apiConfigured ? <CheckCircle2 size={15} /> : <AlertTriangle size={15} />}
{demoMode ? t.app.demoMode : apiConfigured ? t.app.apiReady : t.app.apiMissing}
</span>
<button type="button" className="language-button" onClick={() => setLocale(locale === 'zh' ? 'en' : 'zh')}>
<Languages size={16} />
{locale === 'zh' ? '中文' : 'EN'}
</button>
</div>
</header>
{error ? <div className="error-banner">{error}</div> : null}
<main className="workbench">
<section className="control-panel">
{activeTab === 'generation' ? (
<form onSubmit={handleGenerationSubmit} className="panel-form">
<div className="panel-heading">
<div>
<span className="panel-label">{t.tabs.generation}</span>
<h2>{t.generation.title}</h2>
</div>
<Sparkles size={22} />
</div>
<Field label={t.generation.mode}>
<Segmented<GenerationMode>
value={mode}
onChange={setMode}
options={[
{ value: 'text', label: t.generation.text, icon: <BrainCircuit size={15} /> },
{ value: 'image', label: t.generation.image, icon: <Image size={15} /> },
{ value: 'multiImage', label: t.generation.multiImage, icon: <Layers size={15} /> },
]}
/>
</Field>
{mode === 'text' ? (
<Field label={t.generation.prompt}>
<textarea value={prompt} onChange={(event) => setPrompt(event.target.value)} placeholder={t.generation.promptPlaceholder} />
</Field>
) : null}
{mode === 'image' ? (
<Field label={t.generation.imageUrl}>
<input value={imageUrl} onChange={(event) => setImageUrl(event.target.value)} placeholder={t.generation.imagePlaceholder} />
</Field>
) : null}
{mode === 'multiImage' ? (
<div className="image-grid">
{imageSlots.map((slot, index) => (
<Field label={t.generation[imageLabels[index]]} key={imageLabels[index]}>
<input
value={slot.file_token}
onChange={(event) =>
setImageSlots((items) =>
items.map((item, itemIndex) =>
itemIndex === index ? { ...item, file_token: event.target.value } : item,
),
)
}
placeholder={t.generation.imagePlaceholder}
/>
</Field>
))}
</div>
) : null}
<div className="field-row">
<Field label={t.generation.model}>
<select value={model} onChange={(event) => setModel(event.target.value as TripoModel)}>
<option value="Tripo/Tripo-H3.1">Tripo-H3.1</option>
<option value="Tripo/Tripo-P1.0">Tripo-P1.0</option>
</select>
</Field>
<Field label={t.generation.geometryQuality}>
<select
value={parameters.geometry_quality}
disabled={model !== 'Tripo/Tripo-H3.1'}
onChange={(event) =>
updateParameters({ geometry_quality: event.target.value as GenerationRequest['parameters']['geometry_quality'] })
}
>
<option value="standard">{t.generation.standard}</option>
<option value="ultra">{t.generation.ultra}</option>
</select>
</Field>
</div>
<Field label={t.generation.textureQuality}>
<Segmented<GenerationRequest['parameters']['texture_quality']>
value={parameters.texture_quality}
onChange={(value) => updateParameters({ texture_quality: value })}
options={[
{ value: 'standard', label: t.generation.standard },
{ value: 'detailed', label: t.generation.detailed },
]}
/>
</Field>
<div className="toggle-row">
<Toggle
checked={parameters.pbr}
label={t.generation.pbr}
onChange={(value) => updateParameters({ pbr: value, texture: value ? true : parameters.texture })}
/>
<Toggle
checked={parameters.texture}
label={t.generation.texture}
disabled={parameters.pbr}
onChange={(value) => updateParameters({ texture: value, pbr: value ? parameters.pbr : false })}
/>
</div>
<button type="submit" className="submit-button" disabled={busy || !apiConfigured}>
<Sparkles size={17} />
{busy ? t.generation.generating : t.generation.generate}
</button>
</form>
) : null}
{activeTab === 'flex' ? (
<form onSubmit={handleFlexSubmit} className="panel-form">
<div className="panel-heading">
<div>
<span className="panel-label">{t.tabs.flex}</span>
<h2>{t.flex.title}</h2>
</div>
<Waves size={22} />
</div>
<Field label={t.flex.source}>
<select
value={sourceTaskId}
onChange={(event) => {
const selected = tasks.find((task) => task.taskId === event.target.value)
if (selected) selectTaskForFlex(selected)
}}
>
<option value="">{t.flex.chooseSource}</option>
{successfulTasks.map((task) => (
<option value={task.taskId} key={task.taskId}>
{task.title}
</option>
))}
</select>
</Field>
{apiConfigured ? <Field label={t.flex.sourcePrompt}>
<textarea value={sourcePrompt} onChange={(event) => setSourcePrompt(event.target.value)} />
</Field> : null}
<Field label={t.flex.sourceModelUrl}>
<input value={sourceModelUrl} onChange={(event) => setSourceModelUrl(event.target.value)} />
</Field>
{apiConfigured ? <Field label={t.flex.behavior}>
<textarea value={behaviorPrompt} onChange={(event) => setBehaviorPrompt(event.target.value)} placeholder={t.flex.behaviorPlaceholder} />
</Field> : null}
<Field label={t.flex.material}>
<Segmented<SimulationProfile['material']>
value={simulation.material}
onChange={(material) => setSimulation((current) => ({ ...current, material }))}
options={[
{ value: 'silicone', label: t.flex.silicone },
{ value: 'cloth', label: t.flex.cloth },
{ value: 'inflatable', label: t.flex.inflatable },
{ value: 'softRobot', label: t.flex.softRobot },
]}
/>
</Field>
<div className="slider-stack">
{[
['elasticity', t.flex.elasticity, 0, 100, 1],
['damping', t.flex.damping, 0, 100, 1],
['thickness', t.flex.thickness, 0.1, 20, 0.1],
['deformation', t.flex.deformation, 0, 100, 1],
['gravity', t.flex.gravity, 0, 30, 0.1],
].map(([key, label, min, max, step]) => (
<Field label={label as string} inline key={key as string}>
<input
type="range"
aria-label={label as string}
min={min as number}
max={max as number}
step={step as number}
value={simulation[key as keyof SimulationProfile] as number}
onChange={(event) =>
setSimulation((current) => ({
...current,
[key as keyof SimulationProfile]: Number(event.target.value),
}))
}
/>
<output>{simulation[key as keyof SimulationProfile]}</output>
</Field>
))}
</div>
<div className="button-grid">
<button type="button" className="submit-button" onClick={downloadGenesis} disabled={busy || !sourceTaskId}>
<Package size={17} />{t.task.exportGenesis}
</button>
{apiConfigured ? <button type="submit" className="secondary-button" disabled={busy}>
<Waves size={17} />
{busy ? t.generation.generating : t.flex.generate}
</button> : null}
<button type="button" className="secondary-button" onClick={exportSimulation}>
<SlidersHorizontal size={17} />
{t.flex.export}
</button>
</div>
</form>
) : null}
{activeTab === 'library' ? (
<section className="panel-form">
<div className="panel-heading">
<div>
<span className="panel-label">{t.tabs.library}</span>
<h2>{t.library.title}</h2>
</div>
<Database size={22} />
</div>
<div className="asset-list">
{tasks.length ? (
tasks.map((task) => {
const modelUrl = getModelUrl(task)
const previewImageUrl = getPreviewImageUrl(task)
return (
<article className="asset-row" key={task.taskId}>
{previewImageUrl ? (
<img src={previewImageUrl} alt="" />
) : (
<div className="asset-thumb">
<Box size={18} />
</div>
)}
<div>
<strong>{task.title}</strong>
<span>{formatTime(task.createdAt)}</span>
<StatusPill status={task.status} t={t} />
</div>
<div className="asset-actions">
<button type="button" onClick={() => selectTask(task)}>
<ExternalLink size={15} />
</button>
{modelUrl ? (
<button type="button" onClick={() => selectTaskForFlex(task)}>
<Waves size={15} />
</button>
) : null}
</div>
</article>
)
})
) : (
<div className="empty-panel">
<Database size={28} />
<span>{t.library.empty}</span>
</div>
)}
</div>
</section>
) : null}
</section>
<Viewport3D task={currentTask} simulation={simulation} labels={t.viewport} />
<TaskPanel task={currentTask} busy={busy} onRefresh={handleRefreshTask} onUseForFlex={selectTaskForFlex} t={t} />
</main>
<Timeline tasks={tasks} currentTaskId={currentTask?.taskId} onSelect={selectTask} t={t} />
</div>
)
}
export default App

View File

@ -1,134 +0,0 @@
import { Bounds, Center, ContactShadows, OrbitControls, useGLTF } from '@react-three/drei'
import { Canvas } from '@react-three/fiber'
import { Component, Suspense, useMemo, useState, type ErrorInfo, type ReactNode } from 'react'
import { Box3, Vector3, type Mesh, type Object3D } from 'three'
import { RotateCw } from 'lucide-react'
import type { SimulationProfile, StoredTask } from '../lib/api'
import { getModelUrl, getPreviewImageUrl } from '../lib/api'
import type { Messages } from '../lib/i18n'
type Viewport3DProps = {
task?: StoredTask | null
simulation: SimulationProfile
labels: Messages['viewport']
}
class CanvasErrorBoundary extends Component<{ children: ReactNode }, { failed: boolean }> {
state = { failed: false }
static getDerivedStateFromError() {
return { failed: true }
}
componentDidCatch(error: Error, info: ErrorInfo) {
console.error('3D viewport failed', error, info.componentStack)
}
render() {
if (this.state.failed) {
return (
<div className="canvas-fallback" role="status">
3D preview unavailable
</div>
)
}
return this.props.children
}
}
function Placeholder() {
return (
<mesh>
<boxGeometry args={[1.5, 1.5, 1.5]} />
<meshStandardMaterial color="#9aaba7" wireframe />
</mesh>
)
}
function StageGrid() {
return (
<group>
<mesh rotation={[-Math.PI / 2, 0, 0]} position={[0, -1.12, 0]} receiveShadow>
<planeGeometry args={[7.2, 7.2, 18, 18]} />
<meshStandardMaterial color="#eef2ef" roughness={0.9} />
</mesh>
<gridHelper args={[7.2, 18, '#a7b0aa', '#dde4df']} position={[0, -1.1, 0]} />
</group>
)
}
function enableShadows(object: Object3D) {
object.traverse((child) => {
const mesh = child as Mesh
if (mesh.isMesh) {
mesh.castShadow = true
mesh.receiveShadow = true
}
})
}
function AssetModel({ url }: { url: string }) {
const { scene } = useGLTF(url)
const previewScene = useMemo(() => {
const clonedScene = scene.clone(true)
const size = new Box3().setFromObject(clonedScene).getSize(new Vector3())
clonedScene.scale.multiplyScalar(2.2 / Math.max(size.x, size.y, size.z, 0.0001))
enableShadows(clonedScene)
return clonedScene
}, [scene])
return (
<Bounds fit clip observe margin={1.25}>
<Center>
<primitive object={previewScene} />
</Center>
</Bounds>
)
}
export function Viewport3D({ task, labels }: Viewport3DProps) {
const [rotating, setRotating] = useState(false)
const modelUrl = getModelUrl(task)
const previewImageUrl = getPreviewImageUrl(task)
const status = modelUrl ? labels.modelReady : previewImageUrl ? labels.imageReady : task ? labels.preview : labels.idle
return (
<section className="viewport-panel" aria-label={labels.label}>
<div className="viewport-toolbar">
<div>
<span className="panel-label">{labels.label}</span>
<strong>{status}</strong>
</div>
{modelUrl ? <button type="button" className="icon-button" aria-label="Rotate model" title="Rotate model" aria-pressed={rotating} onClick={() => setRotating(!rotating)}><RotateCw size={18} /></button> : null}
{modelUrl ? (
<a href={modelUrl} target="_blank" rel="noreferrer" className="mini-link">
GLB
</a>
) : null}
</div>
<div className="canvas-wrap">
{modelUrl || !previewImageUrl ? (
<CanvasErrorBoundary key={modelUrl}>
<Canvas camera={{ position: [3.7, 2.5, 4.2], fov: 42 }} gl={{ preserveDrawingBuffer: true, antialias: true }} shadows>
<ambientLight intensity={1} />
<hemisphereLight args={['#ffffff', '#9ca3af', 1.25]} />
<directionalLight position={[4, 5, 3]} intensity={2.4} castShadow />
<pointLight position={[-3, 2.2, -2]} intensity={0.65} color="#5eead4" />
<Suspense fallback={<Placeholder />}>
{modelUrl ? <AssetModel url={modelUrl} /> : <Placeholder />}
</Suspense>
<StageGrid />
<ContactShadows position={[0, -1.08, 0]} opacity={0.28} scale={5} blur={2.4} far={3} />
<OrbitControls enablePan={false} minDistance={3.4} maxDistance={8} autoRotate={rotating} autoRotateSpeed={1.5} />
</Canvas>
</CanvasErrorBoundary>
) : (
<a href={previewImageUrl} target="_blank" rel="noreferrer" className="viewport-image-preview">
<img src={previewImageUrl} alt={labels.imageReady} />
</a>
)}
</div>
</section>
)
}

View File

@ -1,42 +0,0 @@
:root {
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
color: #18211f;
background: #f5f8f6;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
* {
box-sizing: border-box;
}
html {
min-width: 320px;
background: #f5f8f6;
}
body {
min-width: 320px;
margin: 0;
}
button,
a,
input,
textarea,
select {
-webkit-tap-highlight-color: transparent;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
outline: 2px solid rgba(20, 184, 166, 0.75);
outline-offset: 2px;
}

View File

@ -1,154 +0,0 @@
export type TaskStatus = 'PENDING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'CANCELED' | 'UNKNOWN'
export type TripoTaskResult = {
model_url?: string
pbr_model_url?: string
base_model_url?: string
rendered_image_url?: string
local_model_url?: string
local_pbr_model_url?: string
local_base_model_url?: string
local_rendered_image_url?: string
orig_prompt?: string
}
export type TripoTaskOutput = {
task_id: string
task_status: TaskStatus
submit_time?: string
scheduled_time?: string
end_time?: string
results?: TripoTaskResult[]
}
export type StoredTask = {
taskId: string
kind: 'generation' | 'flex' | 'sample'
title: string
status: TaskStatus
requestId?: string
request: Record<string, unknown>
output?: TripoTaskOutput
usage?: Record<string, unknown>
createdAt: string
updatedAt: string
}
export type SimulationProfile = {
material: 'silicone' | 'cloth' | 'inflatable' | 'softRobot'
elasticity: number
damping: number
thickness: number
deformation: number
gravity: number
}
export type GenerationRequest = {
mode: 'text' | 'image' | 'multiImage'
model: 'Tripo/Tripo-H3.1' | 'Tripo/Tripo-P1.0'
prompt?: string
image?: string
images?: Array<{ type: 'jpeg' | 'png'; file_token: string }>
parameters: {
texture_quality: 'standard' | 'detailed'
geometry_quality: 'standard' | 'ultra'
pbr: boolean
texture: boolean
}
}
export type FlexRequest = {
sourceTaskId?: string
sourceName?: string
sourcePrompt?: string
sourceModelUrl?: string
behaviorPrompt?: string
model: GenerationRequest['model']
parameters: GenerationRequest['parameters']
simulation: SimulationProfile
}
async function requestJson<T>(url: string, options?: RequestInit): Promise<T> {
const response = await fetch(url, {
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
})
const body = await response.json().catch(() => ({}))
if (!response.ok) {
const message = body?.error || body?.message || `HTTP ${response.status}`
throw new Error(message)
}
return body as T
}
export function health() {
return requestJson<{ ok: boolean; apiConfigured: boolean; demo: boolean; defaultModel: string }>('/api/health')
}
export function importExample() {
return requestJson<{ task: StoredTask }>('/api/examples/soft-puck', { method: 'POST' })
}
export function exportGenesis(sourceTaskId: string, simulation: SimulationProfile) {
return requestJson<{ archiveUrl: string }>('/api/genesis/packages', {
method: 'POST', body: JSON.stringify({ sourceTaskId, simulation }),
})
}
export function listTasks() {
return requestJson<{ tasks: StoredTask[] }>('/api/tripo/tasks')
}
export function createGenerationTask(payload: GenerationRequest) {
return requestJson<{ task: StoredTask }>('/api/tripo/tasks', {
method: 'POST',
body: JSON.stringify(payload),
})
}
export function refreshTask(taskId: string) {
return requestJson<{ task: StoredTask }>(`/api/tripo/tasks/${encodeURIComponent(taskId)}`)
}
export function createFlexTask(payload: FlexRequest) {
return requestJson<{ task: StoredTask; prompt: string; simulationExport: Record<string, unknown> }>('/api/flex/tasks', {
method: 'POST',
body: JSON.stringify(payload),
})
}
export function getPrimaryResult(task?: StoredTask | null) {
return task?.output?.results?.[0]
}
export function getPreviewImageUrl(task?: StoredTask | null) {
const result = getPrimaryResult(task)
return result?.local_rendered_image_url || ''
}
export function getPbrModelUrl(task?: StoredTask | null) {
const result = getPrimaryResult(task)
return result?.local_pbr_model_url || ''
}
export function getBaseModelUrl(task?: StoredTask | null) {
const result = getPrimaryResult(task)
return result?.local_base_model_url || result?.local_model_url || ''
}
export function getModelUrl(task?: StoredTask | null) {
return getPbrModelUrl(task) || getBaseModelUrl(task)
}
export function getSourcePrompt(task?: StoredTask | null) {
const resultPrompt = getPrimaryResult(task)?.orig_prompt
const requestPrompt = typeof task?.request?.prompt === 'string' ? task.request.prompt : ''
return resultPrompt || requestPrompt || task?.title || ''
}
export function isLiveStatus(status?: TaskStatus) {
return status === 'PENDING' || status === 'RUNNING'
}

View File

@ -1,9 +0,0 @@
export function downloadJson(filename: string, data: unknown) {
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' })
const url = URL.createObjectURL(blob)
const anchor = document.createElement('a')
anchor.href = url
anchor.download = filename
anchor.click()
URL.revokeObjectURL(url)
}

View File

@ -1,232 +0,0 @@
export type Locale = 'zh' | 'en'
const dictionaries = {
zh: {
app: {
name: 'Real2Sim Studio',
subtitle: '资产 · 材料 · Genesis',
loadExample: '加载样例',
demoMode: '离线样例',
apiReady: 'API 已配置',
apiMissing: 'API 未配置',
language: '语言',
refresh: '刷新',
},
tabs: {
generation: '模型生成',
flex: '柔性物体',
library: '资产库',
},
generation: {
title: 'Tripo 3D 生成',
mode: '输入方式',
text: '文本',
image: '单图',
multiImage: '多图',
prompt: '提示词',
promptPlaceholder: '例如:一只带有工业传感器的柔性机器人夹爪',
imageUrl: '公网图片 URL',
imagePlaceholder: 'https://example.com/object.png',
front: '前视图',
left: '左视图',
back: '后视图',
right: '右视图',
model: '模型',
textureQuality: '贴图质量',
geometryQuality: '几何精度',
standard: '标准',
detailed: '高清',
ultra: '超清',
pbr: 'PBR 材质',
texture: '生成贴图',
generate: '创建任务',
generating: '提交中',
noTexture: '无贴图',
},
flex: {
title: '材料与仿真导出',
source: '源资产',
sourceModelUrl: '源 GLB',
sourcePrompt: '源描述',
behavior: '柔性目标',
behaviorPlaceholder: '保持原始轮廓,变成可压缩、可弯曲、适合仿真的柔性版本',
material: '材料类型',
silicone: '软硅胶',
cloth: '织物',
inflatable: '充气膜',
softRobot: '软体机器人',
elasticity: '刚度预设',
damping: '阻尼',
thickness: '厚度 mm',
deformation: '柔软度预设',
gravity: '重力',
generate: '生成柔性版本',
export: '导出仿真配置',
chooseSource: '从资产库选择',
},
library: {
title: '资产库',
empty: '暂无任务',
useForFlex: '作为柔性源',
openModel: '打开 GLB',
openImage: '打开预览',
createdAt: '创建时间',
},
task: {
title: '任务结果',
current: '当前任务',
taskId: '任务 ID',
requestId: '请求 ID',
status: '状态',
noTask: '尚未创建任务',
poll: '查询状态',
downloadPbr: '下载 PBR GLB',
downloadBase: '下载基础 GLB',
exportGenesis: '导出 Genesis 包',
rendered: '渲染预览',
pending: '排队中',
running: '处理中',
succeeded: '成功',
failed: '失败',
canceled: '已取消',
unknown: '未知',
},
viewport: {
label: '3D 预览',
modelReady: '几何预览',
imageReady: '渲染图已生成',
preview: '等待资产',
idle: '等待生成',
},
timeline: {
title: '任务时间线',
empty: '暂无历史任务',
},
errors: {
generic: '请求失败',
validation: '请检查输入',
},
},
en: {
app: {
name: 'Real2Sim Studio',
subtitle: 'Assets · Materials · Genesis',
loadExample: 'Load example',
demoMode: 'Offline example',
apiReady: 'API configured',
apiMissing: 'API missing',
language: 'Language',
refresh: 'Refresh',
},
tabs: {
generation: 'Model Generation',
flex: 'Flexible Object',
library: 'Asset Library',
},
generation: {
title: 'Tripo 3D Generation',
mode: 'Input Mode',
text: 'Text',
image: 'Single Image',
multiImage: 'Multi Image',
prompt: 'Prompt',
promptPlaceholder: 'Example: a flexible robot gripper with industrial sensors',
imageUrl: 'Public Image URL',
imagePlaceholder: 'https://example.com/object.png',
front: 'Front',
left: 'Left',
back: 'Back',
right: 'Right',
model: 'Model',
textureQuality: 'Texture Quality',
geometryQuality: 'Geometry Quality',
standard: 'Standard',
detailed: 'Detailed',
ultra: 'Ultra',
pbr: 'PBR material',
texture: 'Texture',
generate: 'Create Task',
generating: 'Submitting',
noTexture: 'Untextured',
},
flex: {
title: 'Material & Simulation Export',
source: 'Source Asset',
sourceModelUrl: 'Source GLB',
sourcePrompt: 'Source Description',
behavior: 'Soft Target',
behaviorPlaceholder: 'Preserve the original silhouette as a compressible, bendable simulation-ready variant',
material: 'Material',
silicone: 'Silicone',
cloth: 'Cloth',
inflatable: 'Inflatable',
softRobot: 'Soft Robot',
elasticity: 'Stiffness preset',
damping: 'Damping',
thickness: 'Thickness mm',
deformation: 'Softness preset',
gravity: 'Gravity',
generate: 'Generate Soft Variant',
export: 'Export Simulation Profile',
chooseSource: 'Choose from Library',
},
library: {
title: 'Asset Library',
empty: 'No tasks yet',
useForFlex: 'Use as Flex Source',
openModel: 'Open GLB',
openImage: 'Open Preview',
createdAt: 'Created',
},
task: {
title: 'Task Result',
current: 'Current Task',
taskId: 'Task ID',
requestId: 'Request ID',
status: 'Status',
noTask: 'No task yet',
poll: 'Query Status',
downloadPbr: 'Download PBR GLB',
downloadBase: 'Download Base GLB',
exportGenesis: 'Export Genesis Package',
rendered: 'Rendered Preview',
pending: 'Pending',
running: 'Running',
succeeded: 'Succeeded',
failed: 'Failed',
canceled: 'Canceled',
unknown: 'Unknown',
},
viewport: {
label: '3D Preview',
modelReady: 'Geometry preview',
imageReady: 'Rendered image generated',
preview: 'Waiting for asset',
idle: 'Waiting',
},
timeline: {
title: 'Task Timeline',
empty: 'No history yet',
},
errors: {
generic: 'Request failed',
validation: 'Check the input',
},
},
} as const
type WidenMessages<T> = {
readonly [K in keyof T]: T[K] extends string ? string : WidenMessages<T[K]>
}
export type Messages = WidenMessages<typeof dictionaries.zh>
export const messages: Record<Locale, Messages> = dictionaries
export function getInitialLocale(): Locale {
if (typeof window === 'undefined') {
return 'zh'
}
const saved = window.localStorage.getItem('real2sim.locale')
return saved === 'en' ? 'en' : 'zh'
}

View File

@ -1,10 +0,0 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)

Some files were not shown because too many files have changed in this diff Show More