@@ -80,7 +80,7 @@ def from_file(file_handle, escape_separators=False,
80
80
81
81
82
82
def from_path (path , escape_separators = False , resolve_references = True ,
83
- assets = None ):
83
+ assets = None , model_dir = None ):
84
84
"""Parses an XML file into an MJCF object model.
85
85
86
86
Args:
@@ -94,11 +94,14 @@ def from_path(path, escape_separators=False, resolve_references=True,
94
94
assets: (optional) A dictionary of pre-loaded assets, of the form
95
95
`{filename: bytestring}`. If present, PyMJCF will search for assets in
96
96
this dictionary before attempting to load them from the filesystem.
97
+ model_dir: (optional) Path to the directory containing the model XML file.
98
+ This is used to prefix the paths of all asset files.
97
99
98
100
Returns:
99
101
An `mjcf.RootElement`.
100
102
"""
101
- model_dir , _ = os .path .split (path )
103
+ if model_dir is None :
104
+ model_dir , _ = os .path .split (path )
102
105
contents = resources .GetResource (path )
103
106
xml_root = etree .fromstring (contents )
104
107
return _parse (xml_root , escape_separators ,
@@ -153,7 +156,7 @@ def _parse(xml_root, escape_separators=False,
153
156
path_or_xml_string ,
154
157
escape_separators = escape_separators ,
155
158
resolve_references = resolve_references ,
156
- assets = assets )
159
+ assets = assets , model_dir = model_dir )
157
160
to_include .append (included_mjcf )
158
161
# We must remove <include/> tags before parsing the main XML file, since
159
162
# these are a schema violation.
0 commit comments