MCPcopy Create free account
hub / github.com/URLab-Sim/UnrealRoboticsLab / _rewrite_asset_path

Function _rewrite_asset_path

Scripts/clean_meshes.py:135–158  ·  view source on GitHub ↗

Rewrite an asset element's ``file=`` so it resolves from ``root_dir`` (the output _ue.xml location) after the declaring file has been spliced in. Paths are resolved relative to the *declaring* file's directory plus its meshdir/texturedir/assetdir, matching how the C++ importer resolves

(elem, src_dir: Path, root_dir: Path,
                        meshdir: str, texturedir: str, assetdir: str)

Source from the content-addressed store, hash-verified

133 return False
134
135
136def _parse_floats(s: str) -> list:
137 """Whitespace-tolerant float list parser for inline mesh attributes."""
138 return [float(t) for t in s.replace(",", " ").split() if t]
139
140
141# Asset elements whose ``file=`` attribute is a path that must stay resolvable
142# after includes are flattened into a single file in a (possibly) different dir.
143_ASSET_FILE_TAGS = ("mesh", "texture", "hfield", "skin")
144# Tags that may legally be the root of an MJCF document or an include fragment.
145_MODEL_ROOT_TAGS = ("mujoco", "mujocoinclude")
146
147
148def _compiler_dirs(root) -> tuple:
149 """Return (meshdir, texturedir, assetdir) declared by any <compiler> directly
150 under ``root``. MuJoCo allows several compiler elements; later ones win for a
151 given attribute, matching the C++ importer&#x27;s last-writer behaviour."""
152 md = txd = ad = ""
153 for comp in root.findall("compiler"):
154 md = comp.get("meshdir", md)
155 txd = comp.get("texturedir", txd)
156 ad = comp.get("assetdir", ad)
157 return md, txd, ad
158
159
160def _rewrite_asset_path(elem, src_dir: Path, root_dir: Path,
161 meshdir: str, texturedir: str, assetdir: str):

Callers 1

_append_expandedFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected