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)
| 133 | return False |
| 134 | |
| 135 | |
| 136 | def _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 | |
| 148 | def _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'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 | |
| 160 | def _rewrite_asset_path(elem, src_dir: Path, root_dir: Path, |
| 161 | meshdir: str, texturedir: str, assetdir: str): |