Skip to content

Commit

Permalink
PyMJCF nested include tags relative to base model
Browse files Browse the repository at this point in the history
  • Loading branch information
guyazran committed Aug 5, 2023
1 parent d6f9cb4 commit 02986a8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dm_control/mjcf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def from_file(file_handle, escape_separators=False,


def from_path(path, escape_separators=False, resolve_references=True,
assets=None):
assets=None, model_dir=None):
"""Parses an XML file into an MJCF object model.
Args:
Expand All @@ -94,11 +94,14 @@ def from_path(path, escape_separators=False, resolve_references=True,
assets: (optional) A dictionary of pre-loaded assets, of the form
`{filename: bytestring}`. If present, PyMJCF will search for assets in
this dictionary before attempting to load them from the filesystem.
model_dir: (optional) Path to the directory containing the model XML file.
This is used to prefix the paths of all asset files.
Returns:
An `mjcf.RootElement`.
"""
model_dir, _ = os.path.split(path)
if model_dir is None:
model_dir, _ = os.path.split(path)
contents = resources.GetResource(path)
xml_root = etree.fromstring(contents)
return _parse(xml_root, escape_separators,
Expand Down Expand Up @@ -153,7 +156,7 @@ def _parse(xml_root, escape_separators=False,
path_or_xml_string,
escape_separators=escape_separators,
resolve_references=resolve_references,
assets=assets)
assets=assets, model_dir=model_dir)
to_include.append(included_mjcf)
# We must remove <include/> tags before parsing the main XML file, since
# these are a schema violation.
Expand Down

0 comments on commit 02986a8

Please sign in to comment.