in robogym/mujoco/mujoco_xml.py [0:0]
def load_includes(self, include_root=""):
"""
Some mujoco files contain includes that need to be process on our side of the system
Find all elements that have an 'include' child
"""
for element in self.root_element.findall(".//include/.."):
# Remove in a second pass to avoid modifying list while iterating it
elements_to_remove_insert = []
for idx, subelement in enumerate(element):
if subelement.tag == "include":
# Branch off initial filename
include_path = os.path.join(include_root, subelement.get("file"))
include_element = MujocoXML.parse(include_path)
elements_to_remove_insert.append(
(idx, subelement, include_element.root_element)
)
# Iterate in reversed order to make sure indices are not screwed up
for idx, to_remove, to_insert in reversed(elements_to_remove_insert):
element.remove(to_remove)
to_insert_list = list(to_insert)
# Insert multiple elements
for i in range(len(to_insert)):
element.insert(idx + i, to_insert_list[i])
return self