File size: 1,721 Bytes
11c70d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""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)