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 | |
| 134 | |
| 135 | def _rewrite_asset_path(elem, src_dir: Path, root_dir: Path, |
| 136 | meshdir: str, texturedir: str, assetdir: str): |
| 137 | """Rewrite an asset element's ``file=`` so it resolves from ``root_dir`` (the |
| 138 | output _ue.xml location) after the declaring file has been spliced in. |
| 139 | |
| 140 | Paths are resolved relative to the *declaring* file's directory plus its |
| 141 | meshdir/texturedir/assetdir, matching how the C++ importer resolves includes, |
| 142 | then re-expressed relative to root_dir. The companion <compiler> dir |
| 143 | attributes are cleared by the caller so nothing double-prefixes them. |
| 144 | """ |
| 145 | file_attr = elem.get("file") |
| 146 | if not file_attr: |
| 147 | return |
| 148 | if elem.tag == "texture": |
| 149 | subdir = texturedir or assetdir |
| 150 | else: # mesh, hfield, skin |
| 151 | subdir = meshdir or assetdir |
| 152 | base = src_dir / subdir if subdir else src_dir |
| 153 | abs_path = (base / file_attr).resolve() |
| 154 | try: |
| 155 | rel = os.path.relpath(abs_path, root_dir) |
| 156 | except ValueError: |
| 157 | rel = str(abs_path) # different drive on Windows — keep absolute |
| 158 | elem.set("file", rel.replace("\\", "/")) |
| 159 | |
| 160 | |
| 161 | def _append_expanded(out_parent, elem, src_dir: Path, root_dir: Path, |