xlerobot-sim / tools /make_tabletop.py
VectorW's picture
Household tasks in the style of the BEHAVIOR Challenge; walls cut away in the view; fixes
d72771b verified
Raw History Blame Contribute Delete
2.88 kB
"""Write the tabletop environment's objects, assets/environments/tabletop/objects.xml.
usage: python tools/make_tabletop.py
MuJoCo-GS-Web's tabletop scene is a kitchen: a 3D Gaussian splat over three counters (collision boxes in
scene.xml, tops at 0.82 m). Its own objects are five coloured blocks and balls dropped in a row. These are
the kitchen environment's objects instead (tools/objects.py), set out where things stand in a kitchen and
where the splat shows free worktop (tools/make_decor.py has what stands where):
- back counter, right of the mini fridge: a bowl with fruit around it, a banana;
- back counter, in front of the mini fridge: a plate; in front of the tray of bottles: a mug and a glass;
- right counter, either side of the microwave: a can and a juice carton, a yogurt;
- left counter, in front of the jars: a bottle of oil and a block.
Each stands about 6 cm in from its counter's edge, where an arm grasps it comfortably from the floor in
front; the bowl and the plate a little further in, by their size.
"""
from pathlib import Path
import objects as o # tools/objects.py
OUT = Path(__file__).resolve().parents[1] / "assets" / "environments" / "tabletop" / "objects.xml"
TOP = 0.82 # counter tops
BACK = -0.30 # the back counter's edge (y); it runs along x from -1 to 1
RIGHT = 1.0 # the right counter's edge (x), facing -x
LEFT = -1.0 # the left counter's edge (x), facing +x
def main() -> None:
parts = [
# Back counter. The robot faces -y here: its left arm is on the +x side.
o.apple(0.20, BACK - 0.06, TOP),
o.bowl(0.42, BACK - 0.09, TOP),
o.orange(0.64, BACK - 0.06, TOP),
o.banana(0.84, BACK - 0.065, TOP, yaw=0.35),
o.plate(-0.06, BACK - 0.115, TOP), # either arm reaches it, away from the corner
o.mug(-0.42, BACK - 0.065, TOP, yaw=1.57), # handle toward the room
o.cup(-0.58, BACK - 0.06, TOP),
# Right counter.
o.can(RIGHT + 0.06, -0.16, TOP),
o.juice_box(RIGHT + 0.06, 0.0, TOP, yaw=0.2),
o.yogurt(RIGHT + 0.06, 0.74, TOP),
# Left counter.
o.bottle(LEFT - 0.07, 0.20, TOP),
o.cube(LEFT - 0.06, -0.10, TOP, yaw=0.4),
]
used = {line.split('material="')[1].split('"')[0] for part in parts for line in part if 'material="' in line}
mats = "\n".join(f' <material name="{k}" rgba="{v}"/>' for k, v in o.MATERIALS.items() if k in used)
body = "\n".join(line for part in parts for line in part)
xml = f"""<mujoco model="tabletop objects">
<!-- Written by tools/make_tabletop.py: the kitchen environment's objects on MuJoCo-GS-Web's tabletop counters. -->
<asset>
{mats}
</asset>
<worldbody>
{body}
</worldbody>
</mujoco>
"""
OUT.write_text(xml, encoding="utf-8")
print(f"wrote {OUT} ({len(parts)} objects, {len(xml) / 1000:.1f} kB)")
if __name__ == "__main__":
main()