Adapt store assets to backend physics
This commit is contained in:
parent
6e9ac3db4c
commit
d6b5173b08
@ -39,6 +39,13 @@ DEFAULT_ASSET_ROOT = Path("/opt/Motphys/motrixsim-docs/examples/assets")
|
||||
DEFAULT_G1_SCENE = DEFAULT_ASSET_ROOT / "g1/g1_mjx_feetonly.xml"
|
||||
DEFAULT_STORE_SCENE = DEFAULT_ASSET_ROOT / "store/store.xml"
|
||||
DEFAULT_G1_COMPOSE_POSE = [1.85, -0.95, 0.0]
|
||||
DEFAULT_COMPOSE_SCENE_ID = "g1-store-blocks-physics"
|
||||
SUPPORTED_COMPOSE_SCENE_IDS = {
|
||||
DEFAULT_COMPOSE_SCENE_ID,
|
||||
"g1-store-floor-staging-physics",
|
||||
"g1-store-inbound-pallet-physics",
|
||||
"g1-store-sorting-physics",
|
||||
}
|
||||
|
||||
COMPOSE_PROP_SPECS: dict[str, dict[str, Any]] = {
|
||||
"red-cube": {
|
||||
@ -66,7 +73,58 @@ COMPOSE_PROP_SPECS: dict[str, dict[str, Any]] = {
|
||||
"pallet": {
|
||||
"material": "demo_pallet",
|
||||
"geom": {"type": "box", "size": "0.21 0.14 0.04", "density": "450"},
|
||||
"z": 0.09,
|
||||
"z": 0.04,
|
||||
},
|
||||
"store-bottle-350": {
|
||||
"visual": {"mesh": "V_Bottle_350", "material": "Bottle_A"},
|
||||
"collisions": [
|
||||
{"type": "box", "size": "0.0265 0.0265 0.0579022", "pos": "0 0 0.0579022", "density": "280"},
|
||||
{"type": "cylinder", "size": "0.0197049 0.0285978", "pos": "0 0 0.144402", "density": "280"},
|
||||
],
|
||||
"z": 0.0,
|
||||
},
|
||||
"store-bottle-360": {
|
||||
"visual": {"mesh": "V_Bottle_360", "material": "Bottle_B"},
|
||||
"collisions": [
|
||||
{"type": "cylinder", "size": "0.029 0.0673171", "pos": "0 0 0.0673171", "density": "280"},
|
||||
{"type": "cylinder", "size": "0.0145 0.0266829", "pos": "0 0 0.161317", "density": "280"},
|
||||
],
|
||||
"z": 0.0,
|
||||
},
|
||||
"store-can-250": {
|
||||
"visual": {"mesh": "V_Cans_N250", "material": "Cans_A"},
|
||||
"collisions": [
|
||||
{"type": "cylinder", "size": "0.0331 0.046", "pos": "0 0 0.046", "density": "320"},
|
||||
],
|
||||
"z": 0.0,
|
||||
},
|
||||
"store-can-330": {
|
||||
"visual": {"mesh": "V_Cans_N330", "material": "Cans_B"},
|
||||
"collisions": [
|
||||
{"type": "cylinder", "size": "0.0331 0.0576", "pos": "0 0 0.0576", "density": "320"},
|
||||
],
|
||||
"z": 0.0,
|
||||
},
|
||||
"store-tetra-250": {
|
||||
"visual": {"mesh": "V_Tetra_250_F", "material": "Tetra_A"},
|
||||
"collisions": [
|
||||
{"type": "box", "size": "0.0324065 0.020046 0.053404", "pos": "0 0 0.053404", "density": "260"},
|
||||
],
|
||||
"z": 0.0,
|
||||
},
|
||||
"store-tetra-500": {
|
||||
"visual": {"mesh": "V_Tetra_500", "material": "Tetra_D"},
|
||||
"collisions": [
|
||||
{"type": "box", "size": "0.0363751 0.03602 0.049006", "pos": "0 0 0.049006", "density": "260"},
|
||||
{
|
||||
"type": "box",
|
||||
"size": "0.03602 0.0254984 0.0254984",
|
||||
"pos": "0 0 0.096384",
|
||||
"quat": "0.9238795 -0.3826835 0 0",
|
||||
"density": "260",
|
||||
},
|
||||
],
|
||||
"z": 0.0,
|
||||
},
|
||||
}
|
||||
|
||||
@ -436,9 +494,9 @@ def parse_float_list(raw: str | None, default: list[float]) -> list[float]:
|
||||
|
||||
|
||||
def normalize_compose_request(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
scene_id = str(payload.get("scene") or payload.get("scenePreset") or "g1-store-blocks-physics")
|
||||
scene_id = str(payload.get("scene") or payload.get("scenePreset") or DEFAULT_COMPOSE_SCENE_ID)
|
||||
robot_id = str(payload.get("robot") or payload.get("robotPreset") or "none")
|
||||
if scene_id != "g1-store-blocks-physics":
|
||||
if scene_id not in SUPPORTED_COMPOSE_SCENE_IDS:
|
||||
raise ValueError(f"unsupported physical compose scene: {scene_id}")
|
||||
if robot_id not in {"none", "g1"}:
|
||||
raise ValueError("physical compose currently supports the built-in G1 robot only")
|
||||
@ -473,6 +531,44 @@ def normalize_compose_request(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def append_compose_prop_geoms(body: ET.Element, spec: dict[str, Any]) -> None:
|
||||
visual = spec.get("visual")
|
||||
if isinstance(visual, dict):
|
||||
visual_attrs = {
|
||||
"class": "store_visual",
|
||||
"mesh": str(visual["mesh"]),
|
||||
"material": str(visual["material"]),
|
||||
"contype": "0",
|
||||
"conaffinity": "0",
|
||||
"group": "2",
|
||||
}
|
||||
if visual.get("pos"):
|
||||
visual_attrs["pos"] = str(visual["pos"])
|
||||
if visual.get("quat"):
|
||||
visual_attrs["quat"] = str(visual["quat"])
|
||||
ET.SubElement(body, "geom", visual_attrs)
|
||||
for collision in spec.get("collisions", []):
|
||||
collision_attrs = {
|
||||
**collision,
|
||||
"group": "3",
|
||||
"contype": "1",
|
||||
"conaffinity": "1",
|
||||
"friction": "0.9",
|
||||
"condim": "3",
|
||||
"rgba": "1 1 1 0.05",
|
||||
}
|
||||
ET.SubElement(body, "geom", collision_attrs)
|
||||
return
|
||||
|
||||
geom_attrs = {
|
||||
**spec["geom"],
|
||||
"material": str(spec["material"]),
|
||||
"friction": "0.8",
|
||||
"condim": "3",
|
||||
}
|
||||
ET.SubElement(body, "geom", geom_attrs)
|
||||
|
||||
|
||||
def compose_request_key(request: dict[str, Any]) -> str:
|
||||
identity = {
|
||||
"scene": request["scene"],
|
||||
@ -639,13 +735,7 @@ def compose_physical_scene(payload: dict[str, Any], compose_dir: Path, request:
|
||||
body_attrs["euler"] = str(spec["euler"])
|
||||
body = ET.SubElement(worldbody, "body", body_attrs)
|
||||
ET.SubElement(body, "freejoint")
|
||||
geom_attrs = {
|
||||
**spec["geom"],
|
||||
"material": str(spec["material"]),
|
||||
"friction": "0.8",
|
||||
"condim": "3",
|
||||
}
|
||||
ET.SubElement(body, "geom", geom_attrs)
|
||||
append_compose_prop_geoms(body, spec)
|
||||
|
||||
tree = ET.ElementTree(mujoco)
|
||||
ET.indent(tree, space=" ")
|
||||
|
||||
27
src/i18n.ts
27
src/i18n.ts
@ -96,6 +96,9 @@ export type MessageKey =
|
||||
| "button.copyLink"
|
||||
| "button.exportConfig"
|
||||
| "button.templateStore"
|
||||
| "button.templateStaging"
|
||||
| "button.templatePallet"
|
||||
| "button.templateSorting"
|
||||
| "button.templateEmpty"
|
||||
| "button.templateArm"
|
||||
| "button.load"
|
||||
@ -144,6 +147,9 @@ export type MessageKey =
|
||||
| "title.copyLink"
|
||||
| "title.exportConfig"
|
||||
| "title.templateStore"
|
||||
| "title.templateStaging"
|
||||
| "title.templatePallet"
|
||||
| "title.templateSorting"
|
||||
| "title.templateEmpty"
|
||||
| "title.templateArm"
|
||||
| "title.load"
|
||||
@ -386,6 +392,9 @@ export type MessageKey =
|
||||
| "mode.visualComposition"
|
||||
| "preset.scene.empty"
|
||||
| "preset.scene.g1StoreBlocksPhysics"
|
||||
| "preset.scene.storeFloorStagingPhysics"
|
||||
| "preset.scene.storeInboundPalletPhysics"
|
||||
| "preset.scene.storeSortingPhysics"
|
||||
| "preset.scene.storeLite"
|
||||
| "preset.scene.storeFull"
|
||||
| "preset.scene.frankaCube"
|
||||
@ -506,6 +515,9 @@ const messages: Record<Locale, Messages> = {
|
||||
"button.copyLink": "复制分享链接",
|
||||
"button.exportConfig": "导出配置",
|
||||
"button.templateStore": "货架补货",
|
||||
"button.templateStaging": "地面分拣",
|
||||
"button.templatePallet": "托盘入库",
|
||||
"button.templateSorting": "G1 分拣",
|
||||
"button.templateEmpty": "空场景摆放",
|
||||
"button.templateArm": "单臂演示",
|
||||
"button.load": "加载",
|
||||
@ -554,6 +566,9 @@ const messages: Record<Locale, Messages> = {
|
||||
"title.copyLink": "复制可恢复当前编排的分享链接",
|
||||
"title.exportConfig": "导出当前编排 JSON",
|
||||
"title.templateStore": "加载完整货架商品场景",
|
||||
"title.templateStaging": "加载带多种商品的地面分拣物理场景",
|
||||
"title.templatePallet": "加载托盘与商品入库物理场景",
|
||||
"title.templateSorting": "加载带 G1 和可掉落商品的分拣物理场景",
|
||||
"title.templateEmpty": "加载轻量空场景摆放模板",
|
||||
"title.templateArm": "加载 Franka 单臂演示模板",
|
||||
"title.load": "加载 manifest",
|
||||
@ -796,6 +811,9 @@ const messages: Record<Locale, Messages> = {
|
||||
"mode.visualComposition": "前端视觉组合",
|
||||
"preset.scene.empty": "空网格",
|
||||
"preset.scene.g1StoreBlocksPhysics": "G1 + 货架商品后端物理场景",
|
||||
"preset.scene.storeFloorStagingPhysics": "货架商品地面分拣物理场景",
|
||||
"preset.scene.storeInboundPalletPhysics": "托盘入库商品物理场景",
|
||||
"preset.scene.storeSortingPhysics": "G1 商品分拣物理场景",
|
||||
"preset.scene.storeLite": "轻量货架场景",
|
||||
"preset.scene.storeFull": "完整货架场景",
|
||||
"preset.scene.frankaCube": "Franka 单臂物理场景",
|
||||
@ -910,6 +928,9 @@ const messages: Record<Locale, Messages> = {
|
||||
"button.copyLink": "Copy Share Link",
|
||||
"button.exportConfig": "Export Config",
|
||||
"button.templateStore": "Store Refill",
|
||||
"button.templateStaging": "Floor Staging",
|
||||
"button.templatePallet": "Inbound Pallet",
|
||||
"button.templateSorting": "G1 Sorting",
|
||||
"button.templateEmpty": "Empty Layout",
|
||||
"button.templateArm": "Arm Demo",
|
||||
"button.load": "Load",
|
||||
@ -958,6 +979,9 @@ const messages: Record<Locale, Messages> = {
|
||||
"title.copyLink": "Copy a share link that restores this composition",
|
||||
"title.exportConfig": "Export the current composition as JSON",
|
||||
"title.templateStore": "Load the stocked shelf scene",
|
||||
"title.templateStaging": "Load a backend physics scene with mixed goods staged on the floor",
|
||||
"title.templatePallet": "Load a backend physics inbound pallet scene",
|
||||
"title.templateSorting": "Load a backend physics G1 sorting scene with movable goods",
|
||||
"title.templateEmpty": "Load a lightweight empty layout template",
|
||||
"title.templateArm": "Load the Franka arm demo template",
|
||||
"title.load": "Load manifest",
|
||||
@ -1199,6 +1223,9 @@ const messages: Record<Locale, Messages> = {
|
||||
"mode.visualComposition": "visual composition",
|
||||
"preset.scene.empty": "Empty grid",
|
||||
"preset.scene.g1StoreBlocksPhysics": "G1 + stocked shelves backend physics",
|
||||
"preset.scene.storeFloorStagingPhysics": "Store goods floor staging physics",
|
||||
"preset.scene.storeInboundPalletPhysics": "Inbound pallet goods physics",
|
||||
"preset.scene.storeSortingPhysics": "G1 goods sorting physics",
|
||||
"preset.scene.storeLite": "Store shelves lite",
|
||||
"preset.scene.storeFull": "Store shelves full",
|
||||
"preset.scene.frankaCube": "Franka arm physics",
|
||||
|
||||
116
src/main.ts
116
src/main.ts
@ -17,8 +17,29 @@ import { initialLocale, isLocale, persistLocale, SUPPORTED_LOCALES, translate, t
|
||||
|
||||
const DEFAULT_MANIFEST = "http://127.0.0.1:18090/manifest";
|
||||
const BACKEND_STORE_SCENE_ID = "g1-store-blocks-physics";
|
||||
const BACKEND_STORE_STAGING_SCENE_ID = "g1-store-floor-staging-physics";
|
||||
const BACKEND_STORE_PALLET_SCENE_ID = "g1-store-inbound-pallet-physics";
|
||||
const BACKEND_STORE_SORTING_SCENE_ID = "g1-store-sorting-physics";
|
||||
const BACKEND_STORE_SCENE_IDS = new Set([
|
||||
BACKEND_STORE_SCENE_ID,
|
||||
BACKEND_STORE_STAGING_SCENE_ID,
|
||||
BACKEND_STORE_PALLET_SCENE_ID,
|
||||
BACKEND_STORE_SORTING_SCENE_ID,
|
||||
]);
|
||||
const DEFAULT_BUILDER_SCENE_ID = BACKEND_STORE_SCENE_ID;
|
||||
const BACKEND_COMPOSE_PROP_IDS = new Set(["red-cube", "blue-crate", "green-ball", "yellow-capsule"]);
|
||||
const BACKEND_COMPOSE_PROP_IDS = new Set([
|
||||
"store-bottle-350",
|
||||
"store-bottle-360",
|
||||
"store-can-250",
|
||||
"store-can-330",
|
||||
"store-tetra-250",
|
||||
"store-tetra-500",
|
||||
"pallet",
|
||||
"red-cube",
|
||||
"blue-crate",
|
||||
"green-ball",
|
||||
"yellow-capsule",
|
||||
]);
|
||||
const BUILDER_STORAGE_KEY = "motrixsim-web-builder-draft";
|
||||
const SAVED_PROJECTS_STORAGE_KEY = "motrixsim-web-saved-projects";
|
||||
const ACTIVITY_LIMIT = 20;
|
||||
@ -386,6 +407,33 @@ const SCENE_PRESETS: ScenePreset[] = [
|
||||
physical: true,
|
||||
defaultProps: [],
|
||||
},
|
||||
{
|
||||
id: BACKEND_STORE_STAGING_SCENE_ID,
|
||||
label: "Store floor staging backend physics",
|
||||
labelKey: "preset.scene.storeFloorStagingPhysics",
|
||||
manifestUrl: "http://127.0.0.1:18090/manifest",
|
||||
composeUrl: "http://127.0.0.1:18090/compose",
|
||||
physical: true,
|
||||
defaultProps: ["store-bottle-350", "store-bottle-360", "store-can-250", "store-can-330", "store-tetra-250", "store-tetra-500"],
|
||||
},
|
||||
{
|
||||
id: BACKEND_STORE_PALLET_SCENE_ID,
|
||||
label: "Inbound pallet backend physics",
|
||||
labelKey: "preset.scene.storeInboundPalletPhysics",
|
||||
manifestUrl: "http://127.0.0.1:18090/manifest",
|
||||
composeUrl: "http://127.0.0.1:18090/compose",
|
||||
physical: true,
|
||||
defaultProps: ["pallet", "store-tetra-500", "store-tetra-500", "store-can-330", "store-bottle-360"],
|
||||
},
|
||||
{
|
||||
id: BACKEND_STORE_SORTING_SCENE_ID,
|
||||
label: "Store sorting backend physics",
|
||||
labelKey: "preset.scene.storeSortingPhysics",
|
||||
manifestUrl: "http://127.0.0.1:18090/manifest",
|
||||
composeUrl: "http://127.0.0.1:18090/compose",
|
||||
physical: true,
|
||||
defaultProps: ["store-bottle-350", "store-can-250", "store-tetra-250", "store-bottle-360", "store-can-330", "store-tetra-500"],
|
||||
},
|
||||
];
|
||||
|
||||
const ROBOT_PRESETS: RobotPreset[] = [
|
||||
@ -522,6 +570,66 @@ const SCENE_TEMPLATES: SceneTemplate[] = [
|
||||
props: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "store-floor-staging",
|
||||
labelKey: "button.templateStaging",
|
||||
titleKey: "title.templateStaging",
|
||||
config: {
|
||||
version: 1,
|
||||
sceneId: BACKEND_STORE_STAGING_SCENE_ID,
|
||||
robotId: "none",
|
||||
robotPose: [...PHYSICAL_G1_SAFE_POSE],
|
||||
physicsEnabled: true,
|
||||
props: [
|
||||
{ presetId: "store-bottle-350", position: [0.66, -0.46, 0] },
|
||||
{ presetId: "store-bottle-360", position: [0.84, -0.46, 0] },
|
||||
{ presetId: "store-can-250", position: [1.02, -0.46, 0] },
|
||||
{ presetId: "store-can-330", position: [0.66, -0.66, 0] },
|
||||
{ presetId: "store-tetra-250", position: [0.84, -0.66, 0] },
|
||||
{ presetId: "store-tetra-500", position: [1.02, -0.66, 0] },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "store-pallet-inbound",
|
||||
labelKey: "button.templatePallet",
|
||||
titleKey: "title.templatePallet",
|
||||
config: {
|
||||
version: 1,
|
||||
sceneId: BACKEND_STORE_PALLET_SCENE_ID,
|
||||
robotId: "none",
|
||||
robotPose: [...PHYSICAL_G1_SAFE_POSE],
|
||||
physicsEnabled: true,
|
||||
props: [
|
||||
{ presetId: "pallet", position: [0.72, -0.62, 0.04] },
|
||||
{ presetId: "store-tetra-500", position: [0.58, -0.56, 0.1] },
|
||||
{ presetId: "store-tetra-500", position: [0.72, -0.56, 0.1] },
|
||||
{ presetId: "store-tetra-500", position: [0.86, -0.56, 0.1] },
|
||||
{ presetId: "store-can-330", position: [0.64, -0.74, 0.1] },
|
||||
{ presetId: "store-bottle-360", position: [0.82, -0.74, 0.1] },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "store-sorting",
|
||||
labelKey: "button.templateSorting",
|
||||
titleKey: "title.templateSorting",
|
||||
config: {
|
||||
version: 1,
|
||||
sceneId: BACKEND_STORE_SORTING_SCENE_ID,
|
||||
robotId: "g1",
|
||||
robotPose: [...PHYSICAL_G1_SAFE_POSE],
|
||||
physicsEnabled: true,
|
||||
props: [
|
||||
{ presetId: "store-bottle-350", position: [0.55, -0.52, 0] },
|
||||
{ presetId: "store-can-250", position: [0.72, -0.48, 0] },
|
||||
{ presetId: "store-tetra-250", position: [0.9, -0.5, 0] },
|
||||
{ presetId: "store-bottle-360", position: [0.62, -0.72, 0] },
|
||||
{ presetId: "store-can-330", position: [0.82, -0.74, 0] },
|
||||
{ presetId: "store-tetra-500", position: [1.02, -0.72, 0] },
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
|
||||
@ -2172,7 +2280,7 @@ function applyContextualRobotLabels(sceneId: string): void {
|
||||
if (!noneOption) {
|
||||
return;
|
||||
}
|
||||
noneOption.textContent = sceneId === BACKEND_STORE_SCENE_ID
|
||||
noneOption.textContent = BACKEND_STORE_SCENE_IDS.has(sceneId)
|
||||
? t("preset.robot.sceneBuiltInG1")
|
||||
: t("preset.robot.none");
|
||||
}
|
||||
@ -2246,7 +2354,7 @@ function canRobotUseBackendCompose(scenePreset: ScenePreset, robotPreset = selec
|
||||
if (!scenePreset.composeUrl) {
|
||||
return false;
|
||||
}
|
||||
return scenePreset.id === BACKEND_STORE_SCENE_ID && (robotPreset.id === "none" || robotPreset.id === "g1");
|
||||
return BACKEND_STORE_SCENE_IDS.has(scenePreset.id) && (robotPreset.id === "none" || robotPreset.id === "g1");
|
||||
}
|
||||
|
||||
function canUseBackendCompose(scenePreset: ScenePreset, robotPreset = selectedRobotPreset()): boolean {
|
||||
@ -3741,7 +3849,7 @@ function isVec3(value: unknown): value is Vec3 {
|
||||
}
|
||||
|
||||
function defaultRobotPoseForScene(sceneId: string): Vec3 {
|
||||
return sceneId === BACKEND_STORE_SCENE_ID ? [...PHYSICAL_G1_SAFE_POSE] : [0, 0, 0];
|
||||
return BACKEND_STORE_SCENE_IDS.has(sceneId) ? [...PHYSICAL_G1_SAFE_POSE] : [0, 0, 0];
|
||||
}
|
||||
|
||||
function parseBuilderConfig(raw: string | null): BuilderConfig | undefined {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user