From 4be85f33c6af0b9bff77d4f6eb97457e618a12e6 Mon Sep 17 00:00:00 2001 From: mengql Date: Wed, 8 Jan 2025 19:36:03 +0800 Subject: [PATCH] Inside mujoco composite element, the geom element does not have "name" attribute. Fix this bug by add judgement in objects.py and mjcf_utils.py. Add "extension" and "compiler" to MujocoXML class to support mujoco plugin and change default compiler attribute --- robosuite/models/base.py | 2 ++ robosuite/models/objects/objects.py | 21 +++++++++++---------- robosuite/utils/mjcf_utils.py | 2 ++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/robosuite/models/base.py b/robosuite/models/base.py index 52e6f98d47..f2e4ce8769 100644 --- a/robosuite/models/base.py +++ b/robosuite/models/base.py @@ -40,6 +40,8 @@ def __init__(self, fname): self.tendon = self.create_default_element("tendon") self.equality = self.create_default_element("equality") self.contact = self.create_default_element("contact") + self.extension = self.create_default_element("extension") + self.compiler = self.create_default_element("compiler") # Parse any default classes and replace them inline default = self.create_default_element("default") diff --git a/robosuite/models/objects/objects.py b/robosuite/models/objects/objects.py index e7681f8f39..52c9232ada 100644 --- a/robosuite/models/objects/objects.py +++ b/robosuite/models/objects/objects.py @@ -385,16 +385,17 @@ def _should_keep(el): if not _should_keep(element): parent.remove(element) else: - g_name = element.get("name") - g_name = g_name if g_name is not None else f"g{i}" - element.set("name", g_name) - # Also optionally duplicate collision geoms if requested (and this is a collision geom) - if self.duplicate_collision_geoms and element.get("group") in {None, "0"}: - parent.append(self._duplicate_visual_from_collision(element)) - # Also manually set the visual appearances to the original collision model - element.set("rgba", array_to_string(OBJECT_COLLISION_COLOR)) - if element.get("material") is not None: - del element.attrib["material"] + if parent.tag!="composite": + g_name = element.get("name") + g_name = g_name if g_name is not None else f"g{i}" + element.set("name", g_name) + # Also optionally duplicate collision geoms if requested (and this is a collision geom) + if self.duplicate_collision_geoms and element.get("group") in {None, "0"}: + parent.append(self._duplicate_visual_from_collision(element)) + # Also manually set the visual appearances to the original collision model + element.set("rgba", array_to_string(OBJECT_COLLISION_COLOR)) + if element.get("material") is not None: + del element.attrib["material"] # add joint(s) for joint_spec in self.joint_specs: obj.append(new_joint(**joint_spec)) diff --git a/robosuite/utils/mjcf_utils.py b/robosuite/utils/mjcf_utils.py index 6f7207a81f..fc0d454e57 100644 --- a/robosuite/utils/mjcf_utils.py +++ b/robosuite/utils/mjcf_utils.py @@ -670,6 +670,8 @@ def _element_filter(element, parent): # Check for actuator first since this is dependent on the parent element if parent is not None and parent.tag == "actuator": return "actuators" + elif parent is not None and parent.tag == "composite": + return "composite_geoms" elif element.tag == "joint": # Make sure this is not a tendon (this should not have a "joint", "joint1", or "joint2" attribute specified) if element.get("joint") is None and element.get("joint1") is None: