| """Path helpers for the public PhysInOne camera and rendering tools.""" |
|
|
| from __future__ import annotations |
|
|
| from dataclasses import dataclass |
| from pathlib import Path |
| import re |
|
|
|
|
| SCENE_PATTERN = re.compile( |
| r"^/Game/PhysInOne/Scenes/(?P<split>Train|Val|Test)/" |
| r"(?P<physics>SinglePhysics|DoublePhysics|TriplePhysics)/" |
| r"(?P<scene>[^./]+)(?:\.(?P=scene))?$" |
| ) |
|
|
|
|
| @dataclass(frozen=True) |
| class ScenePaths: |
| split: str |
| physics: str |
| scene: str |
| level_asset: str |
| sequence_asset: str |
|
|
| def render_directory(self, project_root: str | Path) -> Path: |
| return ( |
| Path(project_root) |
| / "Rendered" |
| / "Videos" |
| / self.split |
| / self.physics |
| / f"{self.scene}_trajectory" |
| ) |
|
|
|
|
| def parse_scene_path(level_path: str) -> ScenePaths: |
| """Parse a canonical PhysInOne UE level path. |
| |
| Accepted form: |
| /Game/PhysInOne/Scenes/<Split>/<Physics>/<Scene>[.<Scene>] |
| """ |
| normalized = level_path.strip().replace("\\", "/") |
| match = SCENE_PATTERN.fullmatch(normalized) |
| if not match: |
| raise ValueError( |
| "Expected /Game/PhysInOne/Scenes/<Train|Val|Test>/" |
| "<SinglePhysics|DoublePhysics|TriplePhysics>/<Scene>[.<Scene>], " |
| f"got: {level_path!r}" |
| ) |
|
|
| split = match.group("split") |
| physics = match.group("physics") |
| scene = match.group("scene") |
| base = f"/Game/PhysInOne" |
| level_asset = f"{base}/Scenes/{split}/{physics}/{scene}.{scene}" |
| sequence = f"{scene}_trajectory" |
| sequence_asset = ( |
| f"{base}/Trajectories/{split}/{physics}/{sequence}.{sequence}" |
| ) |
| return ScenePaths(split, physics, scene, level_asset, sequence_asset) |
|
|
|
|