Add official-URDF fetch notes and stdlib morph apply script
Browse files- GET_OFFICIAL_URDF.md +68 -0
- README.md +12 -1
- morph_specs/README.md +5 -1
- scripts/apply_morph_to_urdf.py +249 -0
GET_OFFICIAL_URDF.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Official URDFs (not in this dataset)
|
| 2 |
+
|
| 3 |
+
This dataset ships **morph ratio tables**, not robot geometry. Collection applies those ratios to **RoboTwin 2.0 official embodiment URDFs**. The rewritten XML still points at the same vendor meshes; uploading 382×5 morphed URDFs would either break (no meshes) or re-host OEM CAD.
|
| 4 |
+
|
| 5 |
+
Apply morphs locally with `scripts/apply_morph_to_urdf.py` after you fetch the official tree.
|
| 6 |
+
|
| 7 |
+
## 1. RoboTwin 2.0 (what collection used)
|
| 8 |
+
|
| 9 |
+
Docs: https://robotwin-platform.github.io/doc/usage/robotwin-install.html
|
| 10 |
+
Code: https://github.com/RoboTwin-Platform/RoboTwin
|
| 11 |
+
|
| 12 |
+
```bash
|
| 13 |
+
git clone https://github.com/RoboTwin-Platform/RoboTwin.git
|
| 14 |
+
cd RoboTwin
|
| 15 |
+
bash scripts/_download_assets.sh
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
Embodiment folders land under `assets/embodiments/`. Name map used by this pack:
|
| 19 |
+
|
| 20 |
+
| Pack family | RoboTwin embodiment dir | Notes |
|
| 21 |
+
|---|---|---|
|
| 22 |
+
| `aloha-agilex` | `aloha-agilex` | Dual-arm; cannot split into compositions |
|
| 23 |
+
| `arx-x5` | `ARX-X5` | Single arm |
|
| 24 |
+
| `franka` | `franka-panda` | Single arm |
|
| 25 |
+
| `ur5` | `ur5-wsg` | Single arm |
|
| 26 |
+
| `piper` | `piper` | Single arm; held-out in UniRobo training |
|
| 27 |
+
|
| 28 |
+
Each dir has `config.yml` with `urdf_path` plus meshes. Follow RoboTwin's license for those files.
|
| 29 |
+
|
| 30 |
+
Then:
|
| 31 |
+
|
| 32 |
+
```bash
|
| 33 |
+
python scripts/apply_morph_to_urdf.py \
|
| 34 |
+
--embodiment-dir /path/to/RoboTwin/assets/embodiments/franka-panda \
|
| 35 |
+
--spec morph_specs/morphs.json \
|
| 36 |
+
--morph-id link_short_3pct
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
`--all` writes one URDF per morph id next to the official file (shared meshes, no mesh copy). Relative `filename=` paths stay valid if you keep the XML in that folder.
|
| 40 |
+
|
| 41 |
+
## 2. Public extras (optional, not bit-identical)
|
| 42 |
+
|
| 43 |
+
These are **not** the files collection compiled against. Do not mix them into a RoboTwin eval and call it the same robot.
|
| 44 |
+
|
| 45 |
+
| Source | URL | Format | Typical models |
|
| 46 |
+
|---|---|---|---|
|
| 47 |
+
| MuJoCo Menagerie | https://github.com/google-deepmind/mujoco_menagerie | MJCF | `franka_emika_panda`, `universal_robots_ur5e`, `agilex_piper` |
|
| 48 |
+
| dex-urdf | https://github.com/dexsuite/dex-urdf | URDF | extra grippers |
|
| 49 |
+
|
| 50 |
+
`apply_morph_to_urdf.py` only accepts **URDF**. Menagerie MJCF needs a separate conversion; per-model LICENSE files still apply.
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
git clone https://github.com/google-deepmind/mujoco_menagerie.git
|
| 54 |
+
git clone https://github.com/dexsuite/dex-urdf.git
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## 3. What the script changes
|
| 58 |
+
|
| 59 |
+
- Joint `<origin xyz>` on proximal/distal arm links (and finger joints via `finger_length`)
|
| 60 |
+
- Prismatic gripper `limit` lower/upper via `finger_width`, clamped to `[0.85, 1.12]`
|
| 61 |
+
- **Not** mesh `scale=""` (must stay unit or mplib/FCL fails)
|
| 62 |
+
- **Not** appearance (swatches/textures bind in the renderer, not in URDF)
|
| 63 |
+
|
| 64 |
+
Compositions in `morph_specs/compositions.json` are left/right **family pairs** for RoboTwin `embodiment: [left, right, interval]`. They are not merged URDFs.
|
| 65 |
+
|
| 66 |
+
## 4. Appearance
|
| 67 |
+
|
| 68 |
+
Paint and albedo maps do not belong in URDF. Load PNGs from `appearance_assets/textures/` and set base-color in the simulator (SAPIEN: `RenderMaterial.set_base_color_texture`).
|
README.md
CHANGED
|
@@ -76,6 +76,15 @@ snapshot_download("Suchenl/Robot-Customization-Assets", repo_type="dataset")
|
|
| 76 |
|
| 77 |
PNG maps: `appearance_assets/textures/`. Full JSON tables: `appearance_assets/catalog.json` and `morph_specs/`.
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
## Browse / load catalogs
|
| 80 |
|
| 81 |
The Dataset Viewer above reads the `index/*.jsonl` catalogs. The dropdown is **subset** (swatches / textures / morphs / compositions), not a train/test split.
|
|
@@ -99,6 +108,8 @@ compositions = load_dataset("Suchenl/Robot-Customization-Assets", "compositions"
|
|
| 99 |
| `appearance_assets/textures/cc0_polyhaven/` | Poly Haven Diffuse 1k (CC0) |
|
| 100 |
| `morph_specs/morphs.json` | Joint-origin morph ratios |
|
| 101 |
| `morph_specs/compositions.json` | Left/right arm pairs |
|
|
|
|
|
|
|
| 102 |
| `index/*.jsonl` | Hub-loadable catalogs (Viewer) |
|
| 103 |
|
| 104 |
## Appearance vs morph vs PBR
|
|
@@ -113,6 +124,6 @@ compositions = load_dataset("Suchenl/Robot-Customization-Assets", "compositions"
|
|
| 113 |
|
| 114 |
- **Apache-2.0**: catalogs, procedural maps, morph and composition tables.
|
| 115 |
- **CC0-1.0**: ambientCG and Poly Haven maps (copy, modify, redistribute, including commercially; attribution not required). See [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/).
|
| 116 |
-
- Vendor robot meshes are **not** redistributed
|
| 117 |
|
| 118 |
Related names: robot appearance library, robot skin dataset, colorway pack, albedo pack, morphology specification, embodiment composition, visual domain randomization.
|
|
|
|
| 76 |
|
| 77 |
PNG maps: `appearance_assets/textures/`. Full JSON tables: `appearance_assets/catalog.json` and `morph_specs/`.
|
| 78 |
|
| 79 |
+
Official robot URDFs are **not** in this repo (vendor meshes). How to clone RoboTwin 2.0 / Menagerie and apply `morphs.json` locally: [`GET_OFFICIAL_URDF.md`](GET_OFFICIAL_URDF.md).
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
python scripts/apply_morph_to_urdf.py \
|
| 83 |
+
--embodiment-dir /path/to/RoboTwin/assets/embodiments/franka-panda \
|
| 84 |
+
--spec morph_specs/morphs.json \
|
| 85 |
+
--morph-id link_short_3pct
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
## Browse / load catalogs
|
| 89 |
|
| 90 |
The Dataset Viewer above reads the `index/*.jsonl` catalogs. The dropdown is **subset** (swatches / textures / morphs / compositions), not a train/test split.
|
|
|
|
| 108 |
| `appearance_assets/textures/cc0_polyhaven/` | Poly Haven Diffuse 1k (CC0) |
|
| 109 |
| `morph_specs/morphs.json` | Joint-origin morph ratios |
|
| 110 |
| `morph_specs/compositions.json` | Left/right arm pairs |
|
| 111 |
+
| `GET_OFFICIAL_URDF.md` | Clone RoboTwin / Menagerie; do not expect URDFs here |
|
| 112 |
+
| `scripts/apply_morph_to_urdf.py` | Stdlib: write a morphed URDF from an official source |
|
| 113 |
| `index/*.jsonl` | Hub-loadable catalogs (Viewer) |
|
| 114 |
|
| 115 |
## Appearance vs morph vs PBR
|
|
|
|
| 124 |
|
| 125 |
- **Apache-2.0**: catalogs, procedural maps, morph and composition tables.
|
| 126 |
- **CC0-1.0**: ambientCG and Poly Haven maps (copy, modify, redistribute, including commercially; attribution not required). See [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/).
|
| 127 |
+
- Vendor robot meshes are **not** redistributed. Clone them yourself ([`GET_OFFICIAL_URDF.md`](GET_OFFICIAL_URDF.md)) and run `scripts/apply_morph_to_urdf.py`.
|
| 128 |
|
| 129 |
Related names: robot appearance library, robot skin dataset, colorway pack, albedo pack, morphology specification, embodiment composition, visual domain randomization.
|
morph_specs/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
| 1 |
Morphology specs (joint-origin morphs and cross-embodiment compositions), not appearance assets.
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
Morphology specs (joint-origin morphs and cross-embodiment compositions), not appearance assets.
|
| 2 |
+
Orthogonal to appearance_assets: the same skeleton can change paint and link origins independently.
|
| 3 |
|
| 4 |
+
This folder is JSON only. Official robot URDFs and meshes are **not** stored here.
|
| 5 |
+
|
| 6 |
+
1. Fetch RoboTwin 2.0 embodiments: see `../GET_OFFICIAL_URDF.md`.
|
| 7 |
+
2. Apply a spec: `python ../scripts/apply_morph_to_urdf.py --source <official.urdf> --spec morphs.json --morph-id link_short_3pct`.
|
scripts/apply_morph_to_urdf.py
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Apply Robot-Customization-Assets morph specs to an official URDF.
|
| 3 |
+
|
| 4 |
+
Stdlib only. Keep the scale rules in sync with
|
| 5 |
+
``unirobo.data_pipeline.config_catalog.write_joint_origin_urdf``.
|
| 6 |
+
|
| 7 |
+
Does **not** rewrite triangle-mesh scale (mplib/FCL rejects anisotropic mesh
|
| 8 |
+
scale). Only joint-origin ``xyz`` and prismatic gripper limits change.
|
| 9 |
+
"""
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import argparse
|
| 13 |
+
import hashlib
|
| 14 |
+
import json
|
| 15 |
+
import os
|
| 16 |
+
import re
|
| 17 |
+
import sys
|
| 18 |
+
import xml.etree.ElementTree as ET
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
from typing import Any
|
| 21 |
+
|
| 22 |
+
SKIP_LINK_TOKENS = (
|
| 23 |
+
"world", "finger", "gripper", "knuckle", "camera", "wsg", "pad",
|
| 24 |
+
"footprint", "inertial", "wheel", "castor", "caster",
|
| 25 |
+
)
|
| 26 |
+
SKIP_EXACT = frozenset({"base", "base_link", "ee_link", "tool0", "panda_link0"})
|
| 27 |
+
ARM_LINK_RE = re.compile(
|
| 28 |
+
r"^(?:(?:fl_|fr_)link[1-6]|link[1-6]|panda_link[1-7]|"
|
| 29 |
+
r"(?:shoulder|upper_arm|forearm|wrist_\d+)_link)$",
|
| 30 |
+
re.I,
|
| 31 |
+
)
|
| 32 |
+
FINGER_WIDTH_MIN = 0.85
|
| 33 |
+
FINGER_WIDTH_MAX = 1.12
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _vec(text: str | None) -> list[float]:
|
| 37 |
+
if not text:
|
| 38 |
+
return [0.0, 0.0, 0.0]
|
| 39 |
+
return [float(item) for item in text.replace(",", " ").split()]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _fmt(values: list[float]) -> str:
|
| 43 |
+
return " ".join(f"{float(item):.10g}" for item in values)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _is_gripper_name(*parts: str | None) -> bool:
|
| 47 |
+
blob = " ".join(part or "" for part in parts).lower()
|
| 48 |
+
return any(token in blob for token in ("finger", "gripper", "knuckle", "wsg"))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def arm_links(urdf: Path) -> list[str]:
|
| 52 |
+
names: list[str] = []
|
| 53 |
+
fallback: list[str] = []
|
| 54 |
+
for link in ET.parse(urdf).getroot().findall("link"):
|
| 55 |
+
name = link.get("name") or ""
|
| 56 |
+
lowered = name.lower()
|
| 57 |
+
if ARM_LINK_RE.match(name):
|
| 58 |
+
names.append(name)
|
| 59 |
+
continue
|
| 60 |
+
if lowered in SKIP_EXACT:
|
| 61 |
+
continue
|
| 62 |
+
if any(token in lowered for token in SKIP_LINK_TOKENS):
|
| 63 |
+
continue
|
| 64 |
+
fallback.append(name)
|
| 65 |
+
if names:
|
| 66 |
+
return names
|
| 67 |
+
if not fallback:
|
| 68 |
+
raise RuntimeError(f"no scalable arm links in {urdf}")
|
| 69 |
+
return fallback
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def link_scale_map(link_names: list[str], spec: dict[str, Any]) -> dict[str, float]:
|
| 73 |
+
groups: dict[str, list[str]] = {}
|
| 74 |
+
for name in link_names:
|
| 75 |
+
if name.startswith("fl_"):
|
| 76 |
+
groups.setdefault("fl", []).append(name)
|
| 77 |
+
elif name.startswith("fr_"):
|
| 78 |
+
groups.setdefault("fr", []).append(name)
|
| 79 |
+
else:
|
| 80 |
+
groups.setdefault("arm", []).append(name)
|
| 81 |
+
link_scale: dict[str, float] = {}
|
| 82 |
+
for members in groups.values():
|
| 83 |
+
split = max(1, len(members) // 2)
|
| 84 |
+
for index, name in enumerate(members):
|
| 85 |
+
link_scale[name] = spec["proximal"] if index < split else spec["distal"]
|
| 86 |
+
return link_scale
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def _retarget_meshes(root: ET.Element, source_urdf: Path, output_urdf: Path) -> None:
|
| 90 |
+
src_dir = source_urdf.parent.resolve()
|
| 91 |
+
out_dir = output_urdf.parent.resolve()
|
| 92 |
+
if src_dir == out_dir:
|
| 93 |
+
return
|
| 94 |
+
for mesh in root.findall(".//mesh"):
|
| 95 |
+
filename = mesh.get("filename")
|
| 96 |
+
if not filename or filename.startswith("package://"):
|
| 97 |
+
continue
|
| 98 |
+
path = Path(filename)
|
| 99 |
+
if not path.is_absolute():
|
| 100 |
+
path = (src_dir / path).resolve()
|
| 101 |
+
try:
|
| 102 |
+
mesh.set("filename", os.path.relpath(path, out_dir))
|
| 103 |
+
except ValueError:
|
| 104 |
+
mesh.set("filename", str(path))
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def write_joint_origin_urdf(
|
| 108 |
+
source_urdf: Path, output_urdf: Path, spec: dict[str, Any],
|
| 109 |
+
) -> dict[str, Any]:
|
| 110 |
+
tree = ET.parse(source_urdf)
|
| 111 |
+
root = tree.getroot()
|
| 112 |
+
links = arm_links(source_urdf)
|
| 113 |
+
scales = link_scale_map(links, spec)
|
| 114 |
+
finger_length = float(spec["finger_length"])
|
| 115 |
+
opening = min(FINGER_WIDTH_MAX, max(FINGER_WIDTH_MIN, float(spec["finger_width"])))
|
| 116 |
+
joint_updates = []
|
| 117 |
+
gripper_updates = []
|
| 118 |
+
for joint in root.findall("joint"):
|
| 119 |
+
parent = joint.find("parent")
|
| 120 |
+
origin = joint.find("origin")
|
| 121 |
+
parent_name = parent.get("link") if parent is not None else ""
|
| 122 |
+
child = joint.find("child")
|
| 123 |
+
child_name = child.get("link") if child is not None else ""
|
| 124 |
+
name = joint.get("name") or ""
|
| 125 |
+
gripper = _is_gripper_name(name, parent_name, child_name)
|
| 126 |
+
scale = finger_length if gripper else float(scales.get(parent_name, 1.0))
|
| 127 |
+
if origin is not None and origin.get("xyz") and scale != 1.0:
|
| 128 |
+
before = _vec(origin.get("xyz"))
|
| 129 |
+
after = [item * scale for item in before]
|
| 130 |
+
origin.set("xyz", _fmt(after))
|
| 131 |
+
joint_updates.append({
|
| 132 |
+
"joint": name, "parent": parent_name, "scale": scale,
|
| 133 |
+
"before_xyz": before, "after_xyz": after,
|
| 134 |
+
})
|
| 135 |
+
if gripper and joint.get("type") == "prismatic" and opening != 1.0:
|
| 136 |
+
limit = joint.find("limit")
|
| 137 |
+
if limit is not None:
|
| 138 |
+
row: dict[str, Any] = {"joint": name, "opening_scale": opening}
|
| 139 |
+
for bound in ("lower", "upper"):
|
| 140 |
+
if limit.get(bound) is not None:
|
| 141 |
+
before_v = float(limit.get(bound))
|
| 142 |
+
limit.set(bound, f"{before_v * opening:.10g}")
|
| 143 |
+
row[bound] = {"before": before_v, "after": before_v * opening}
|
| 144 |
+
gripper_updates.append(row)
|
| 145 |
+
for mesh in root.findall(".//mesh"):
|
| 146 |
+
scale = mesh.get("scale")
|
| 147 |
+
if scale and any(abs(float(item) - 1.0) > 1e-9 for item in _vec(scale)):
|
| 148 |
+
raise RuntimeError(
|
| 149 |
+
f"refusing non-unit mesh scale {scale} in {source_urdf}; "
|
| 150 |
+
"mplib/FCL requires unit scale")
|
| 151 |
+
_retarget_meshes(root, source_urdf, output_urdf)
|
| 152 |
+
output_urdf.parent.mkdir(parents=True, exist_ok=True)
|
| 153 |
+
tree.write(output_urdf, encoding="utf-8", xml_declaration=True)
|
| 154 |
+
digest = hashlib.sha256(output_urdf.read_bytes()).hexdigest()
|
| 155 |
+
return {
|
| 156 |
+
"link_scale": scales,
|
| 157 |
+
"finger_length_scale": finger_length,
|
| 158 |
+
"opening_scale": opening,
|
| 159 |
+
"n_joint_origin_updates": len(joint_updates),
|
| 160 |
+
"n_gripper_limit_updates": len(gripper_updates),
|
| 161 |
+
"mesh_scale_policy": "unchanged_unit",
|
| 162 |
+
"output": str(output_urdf),
|
| 163 |
+
"output_sha256": digest,
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def _load_specs(path: Path) -> dict[str, dict[str, Any]]:
|
| 168 |
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
| 169 |
+
if not isinstance(payload, dict):
|
| 170 |
+
raise ValueError(f"{path} must be an object of morph_id -> spec")
|
| 171 |
+
return payload
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def resolve_source_urdf(source: Path | None, embodiment_dir: Path | None) -> Path:
|
| 175 |
+
if source is not None:
|
| 176 |
+
if not source.is_file():
|
| 177 |
+
raise FileNotFoundError(source)
|
| 178 |
+
return source.resolve()
|
| 179 |
+
if embodiment_dir is None:
|
| 180 |
+
raise ValueError("pass --source or --embodiment-dir")
|
| 181 |
+
config = embodiment_dir / "config.yml"
|
| 182 |
+
if config.is_file():
|
| 183 |
+
match = re.search(r"urdf_path:\s*(\S+)", config.read_text(encoding="utf-8"))
|
| 184 |
+
if match:
|
| 185 |
+
raw = match.group(1).strip().strip("\"'")
|
| 186 |
+
raw = re.sub(r"^\$\{ASSETS_PATH\}/", "", raw)
|
| 187 |
+
candidate = Path(raw)
|
| 188 |
+
if candidate.is_file():
|
| 189 |
+
return candidate.resolve()
|
| 190 |
+
local = embodiment_dir / candidate.name
|
| 191 |
+
if local.is_file():
|
| 192 |
+
return local.resolve()
|
| 193 |
+
nested = embodiment_dir / candidate
|
| 194 |
+
if nested.is_file():
|
| 195 |
+
return nested.resolve()
|
| 196 |
+
found = sorted(embodiment_dir.glob("*.urdf"))
|
| 197 |
+
if len(found) == 1:
|
| 198 |
+
return found[0].resolve()
|
| 199 |
+
raise FileNotFoundError(
|
| 200 |
+
f"could not resolve a URDF under {embodiment_dir}; pass --source")
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def main() -> int:
|
| 204 |
+
here = Path(__file__).resolve()
|
| 205 |
+
default_spec = here.parents[1] / "morph_specs" / "morphs.json"
|
| 206 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 207 |
+
parser.add_argument("--source", type=Path, help="Official URDF path")
|
| 208 |
+
parser.add_argument(
|
| 209 |
+
"--embodiment-dir", type=Path,
|
| 210 |
+
help="RoboTwin assets/embodiments/<name> (reads config.yml urdf_path)")
|
| 211 |
+
parser.add_argument("--spec", type=Path, default=default_spec,
|
| 212 |
+
help="morphs.json from this dataset")
|
| 213 |
+
parser.add_argument("--morph-id", help="One key from morphs.json")
|
| 214 |
+
parser.add_argument("--all", action="store_true",
|
| 215 |
+
help="Write one URDF per morph id")
|
| 216 |
+
parser.add_argument("--output", type=Path, help="Output URDF (single morph)")
|
| 217 |
+
parser.add_argument("--output-dir", type=Path,
|
| 218 |
+
help="Directory for --all (default: next to the source URDF)")
|
| 219 |
+
parser.add_argument("--list", action="store_true", help="Print morph ids")
|
| 220 |
+
args = parser.parse_args()
|
| 221 |
+
specs = _load_specs(args.spec)
|
| 222 |
+
if args.list:
|
| 223 |
+
for name, spec in specs.items():
|
| 224 |
+
print(f"{name}\t{spec.get('description', '')}")
|
| 225 |
+
return 0
|
| 226 |
+
source = resolve_source_urdf(args.source, args.embodiment_dir)
|
| 227 |
+
wanted = list(specs) if args.all else [args.morph_id]
|
| 228 |
+
if not args.all and not args.morph_id:
|
| 229 |
+
parser.error("pass --morph-id, --all, or --list")
|
| 230 |
+
unknown = [name for name in wanted if name not in specs]
|
| 231 |
+
if unknown:
|
| 232 |
+
raise KeyError(f"unknown morph id: {unknown[:8]}")
|
| 233 |
+
reports = []
|
| 234 |
+
if args.all:
|
| 235 |
+
out_dir = args.output_dir or source.parent
|
| 236 |
+
for name in wanted:
|
| 237 |
+
output = out_dir / f"{source.stem}__{name}{source.suffix}"
|
| 238 |
+
reports.append(write_joint_origin_urdf(source, output, specs[name]))
|
| 239 |
+
else:
|
| 240 |
+
output = args.output
|
| 241 |
+
if output is None:
|
| 242 |
+
output = source.with_name(f"{source.stem}__{args.morph_id}{source.suffix}")
|
| 243 |
+
reports.append(write_joint_origin_urdf(source, output, specs[args.morph_id]))
|
| 244 |
+
print(json.dumps(reports if args.all else reports[0], indent=2))
|
| 245 |
+
return 0
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
if __name__ == "__main__":
|
| 249 |
+
raise SystemExit(main())
|