Implementation:ARISE Initiative Robosuite MujocoObject Base
| Knowledge Sources | |
|---|---|
| Domains | Robotics, Simulation, MJCF_Modeling |
| Last Updated | 2026-02-15 07:00 GMT |
Overview
The objects module defines the core object model hierarchy -- MujocoObject, MujocoXMLObject, and MujocoGeneratedObject -- providing the foundational abstractions for all simulation objects in robosuite.
Description
MujocoObject is the base class for all objects in robosuite. It extends MujocoModel and manages an internal XML element tree (self._obj) representing the object's body subtree. The class categorizes geoms into collision (group 0), visual (group 1), or both ("all") groups via the obj_type parameter. When duplicate_collision_geoms is enabled, each collision geom gets a corresponding visual copy. The class provides a standardized API including get_obj() for retrieving the XML element, a naming prefix system based on the object's name, and template methods for joints (get_joint_attrib_template()) and sites (get_site_attrib_template()). The _get_object_properties() method parses the element tree to extract bodies, joints, actuators, sites, sensors, and geom groups, then applies naming prefixes. It also supports optional scaling of geoms, meshes, sites, and bodies via the set_scale() method.
MujocoXMLObject inherits from both MujocoObject and MujocoXML, loading objects from MJCF XML files. It finds the object body in the worldbody, renames it to "main", filters geoms based on obj_type, optionally duplicates collision geoms with visual copies, appends joints and a default site, and then applies naming prefixes to all elements including the broader XML root. It provides convenience methods for setting position (set_pos) and Euler angles (set_euler), and derives bottom_offset, top_offset, and horizontal_radius from specially named sites in the XML file. The _get_elements_by_name() helper method supports looking up specific geoms, bodies, and joints by name.
MujocoGeneratedObject is the base class for procedurally generated objects (those created from code rather than XML files). It adds shared material management to prevent duplicate material/texture prefixing, a sanity_check() hook called during initialization, and the append_material() method for adding CustomMaterial textures and materials to the object's asset tree. The exclude_from_prefixing() method exempts shared materials from having the naming prefix applied.
Usage
Use MujocoXMLObject as the base class when creating objects loaded from XML files (e.g., cans, bottles, nuts). Use MujocoGeneratedObject as the base class for procedurally generated objects (e.g., via CompositeObject or PrimitiveObject). Use MujocoObject directly only if you need the abstract interface for type checking or generic object handling.
Code Reference
Source Location
- Repository: ARISE_Initiative_Robosuite
- File: robosuite/models/objects/objects.py
Signature
class MujocoObject(MujocoModel):
def __init__(self, obj_type="all", duplicate_collision_geoms=True, scale=None)
class MujocoXMLObject(MujocoObject, MujocoXML):
def __init__(self, fname, name, joints="default", obj_type="all",
duplicate_collision_geoms=True, scale=None)
class MujocoGeneratedObject(MujocoObject):
def __init__(self, obj_type="all", duplicate_collision_geoms=True)
Import
from robosuite.models.objects.objects import MujocoObject, MujocoXMLObject, MujocoGeneratedObject
# Or more commonly via the package:
from robosuite.models.objects import MujocoObject, MujocoXMLObject, MujocoGeneratedObject
I/O Contract
Inputs (MujocoObject)
| Name | Type | Required | Description |
|---|---|---|---|
| obj_type | str | No | Geom type filter: "collision" (group 0), "visual" (group 1), or "all". Default: "all" |
| duplicate_collision_geoms | bool | No | If True, each collision geom gets a visual copy. Default: True |
| scale | float or list of float or None | No | Scale factor for geoms, meshes, sites, and bodies. Default: None |
Inputs (MujocoXMLObject)
| Name | Type | Required | Description |
|---|---|---|---|
| fname | str | Yes | Path to the MJCF XML file |
| name | str | Yes | Name of this object |
| joints | None, "default", or list of dict | No | Joint specifications. "default" adds a free joint. Default: "default" |
| obj_type | str | No | Geom type filter. Default: "all" |
| duplicate_collision_geoms | bool | No | Duplicate collision geoms as visual geoms. Default: True |
| scale | float or list of float or None | No | Scale factor. Default: None |
Outputs
| Name | Type | Description |
|---|---|---|
| name | str | Object name |
| naming_prefix | str | "{name}_" prefix for all elements |
| root_body | str | Prefix-corrected root body name |
| bodies | list of str | All body names |
| joints | list of str | All joint names |
| actuators | list of str | All actuator names |
| sites | list of str | All site names |
| contact_geoms | list of str | Group 0 geom names for collision |
| visual_geoms | list of str | Group 1 geom names for rendering |
| important_sites | dict | Default: {"obj": "{prefix}default_site"} |
| bottom_offset | np.array | Vector from root body to model bottom |
| top_offset | np.array | Vector from root body to model top |
| horizontal_radius | float | Maximum radial distance from root body |
Usage Examples
from robosuite.models.objects.objects import MujocoXMLObject, MujocoGeneratedObject
from robosuite.utils.mjcf_utils import xml_path_completion
# Load an object from XML
class MyXMLObj(MujocoXMLObject):
def __init__(self, name):
super().__init__(
xml_path_completion("objects/can.xml"),
name=name,
joints=[dict(type="free", damping="0.0005")],
obj_type="all",
duplicate_collision_geoms=True,
)
obj = MyXMLObj("soda_can")
# Access object properties
print(obj.root_body) # e.g., "soda_can_main"
print(obj.contact_geoms) # list of collision geom names
print(obj.bottom_offset) # np.array offset to bottom
# Get the XML element tree for merging into a world
xml_element = obj.get_obj()
# Set position and orientation
obj.set_pos([0.5, 0.0, 0.85])
obj.set_euler([0, 0, 1.57])