feat: add simple track generator
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
"name": "Simple Track",
|
||||
"start": {
|
||||
"pos": [
|
||||
0,
|
||||
-3
|
||||
30,
|
||||
0
|
||||
],
|
||||
"direction": [
|
||||
1,
|
||||
0
|
||||
0,
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -3,59 +3,255 @@
|
||||
"type": "road",
|
||||
"pts": [
|
||||
[
|
||||
0,
|
||||
-3,
|
||||
0,
|
||||
-1,
|
||||
30.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1
|
||||
],
|
||||
[
|
||||
2,
|
||||
-2,
|
||||
1,
|
||||
-1,
|
||||
29.544,
|
||||
5.209,
|
||||
0.985,
|
||||
0.174,
|
||||
1
|
||||
],
|
||||
[
|
||||
3,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
28.191,
|
||||
10.261,
|
||||
0.94,
|
||||
0.342,
|
||||
1
|
||||
],
|
||||
[
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
1,
|
||||
25.981,
|
||||
15.0,
|
||||
0.866,
|
||||
0.5,
|
||||
1
|
||||
],
|
||||
[
|
||||
0,
|
||||
3,
|
||||
0,
|
||||
1,
|
||||
22.981,
|
||||
19.284,
|
||||
0.766,
|
||||
0.643,
|
||||
1
|
||||
],
|
||||
[
|
||||
-2,
|
||||
2,
|
||||
-1,
|
||||
1,
|
||||
19.284,
|
||||
22.981,
|
||||
0.643,
|
||||
0.766,
|
||||
1
|
||||
],
|
||||
[
|
||||
-3,
|
||||
0,
|
||||
-1,
|
||||
0,
|
||||
15.0,
|
||||
25.981,
|
||||
0.5,
|
||||
0.866,
|
||||
1
|
||||
],
|
||||
[
|
||||
-2,
|
||||
-2,
|
||||
-1,
|
||||
-1,
|
||||
10.261,
|
||||
28.191,
|
||||
0.342,
|
||||
0.94,
|
||||
1
|
||||
],
|
||||
[
|
||||
5.209,
|
||||
29.544,
|
||||
0.174,
|
||||
0.985,
|
||||
1
|
||||
],
|
||||
[
|
||||
0.0,
|
||||
30.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1
|
||||
],
|
||||
[
|
||||
-5.209,
|
||||
29.544,
|
||||
-0.174,
|
||||
0.985,
|
||||
1
|
||||
],
|
||||
[
|
||||
-10.261,
|
||||
28.191,
|
||||
-0.342,
|
||||
0.94,
|
||||
1
|
||||
],
|
||||
[
|
||||
-15.0,
|
||||
25.981,
|
||||
-0.5,
|
||||
0.866,
|
||||
1
|
||||
],
|
||||
[
|
||||
-19.284,
|
||||
22.981,
|
||||
-0.643,
|
||||
0.766,
|
||||
1
|
||||
],
|
||||
[
|
||||
-22.981,
|
||||
19.284,
|
||||
-0.766,
|
||||
0.643,
|
||||
1
|
||||
],
|
||||
[
|
||||
-25.981,
|
||||
15.0,
|
||||
-0.866,
|
||||
0.5,
|
||||
1
|
||||
],
|
||||
[
|
||||
-28.191,
|
||||
10.261,
|
||||
-0.94,
|
||||
0.342,
|
||||
1
|
||||
],
|
||||
[
|
||||
-29.544,
|
||||
5.209,
|
||||
-0.985,
|
||||
0.174,
|
||||
1
|
||||
],
|
||||
[
|
||||
-30.0,
|
||||
0.0,
|
||||
-1.0,
|
||||
0.0,
|
||||
1
|
||||
],
|
||||
[
|
||||
-29.544,
|
||||
-5.209,
|
||||
-0.985,
|
||||
-0.174,
|
||||
1
|
||||
],
|
||||
[
|
||||
-28.191,
|
||||
-10.261,
|
||||
-0.94,
|
||||
-0.342,
|
||||
1
|
||||
],
|
||||
[
|
||||
-25.981,
|
||||
-15.0,
|
||||
-0.866,
|
||||
-0.5,
|
||||
1
|
||||
],
|
||||
[
|
||||
-22.981,
|
||||
-19.284,
|
||||
-0.766,
|
||||
-0.643,
|
||||
1
|
||||
],
|
||||
[
|
||||
-19.284,
|
||||
-22.981,
|
||||
-0.643,
|
||||
-0.766,
|
||||
1
|
||||
],
|
||||
[
|
||||
-15.0,
|
||||
-25.981,
|
||||
-0.5,
|
||||
-0.866,
|
||||
1
|
||||
],
|
||||
[
|
||||
-10.261,
|
||||
-28.191,
|
||||
-0.342,
|
||||
-0.94,
|
||||
1
|
||||
],
|
||||
[
|
||||
-5.209,
|
||||
-29.544,
|
||||
-0.174,
|
||||
-0.985,
|
||||
1
|
||||
],
|
||||
[
|
||||
-0.0,
|
||||
-30.0,
|
||||
-0.0,
|
||||
-1.0,
|
||||
1
|
||||
],
|
||||
[
|
||||
5.209,
|
||||
-29.544,
|
||||
0.174,
|
||||
-0.985,
|
||||
1
|
||||
],
|
||||
[
|
||||
10.261,
|
||||
-28.191,
|
||||
0.342,
|
||||
-0.94,
|
||||
1
|
||||
],
|
||||
[
|
||||
15.0,
|
||||
-25.981,
|
||||
0.5,
|
||||
-0.866,
|
||||
1
|
||||
],
|
||||
[
|
||||
19.284,
|
||||
-22.981,
|
||||
0.643,
|
||||
-0.766,
|
||||
1
|
||||
],
|
||||
[
|
||||
22.981,
|
||||
-19.284,
|
||||
0.766,
|
||||
-0.643,
|
||||
1
|
||||
],
|
||||
[
|
||||
25.981,
|
||||
-15.0,
|
||||
0.866,
|
||||
-0.5,
|
||||
1
|
||||
],
|
||||
[
|
||||
28.191,
|
||||
-10.261,
|
||||
0.94,
|
||||
-0.342,
|
||||
1
|
||||
],
|
||||
[
|
||||
29.544,
|
||||
-5.209,
|
||||
0.985,
|
||||
-0.174,
|
||||
1
|
||||
]
|
||||
]
|
||||
|
||||
40
scripts/track_gen.py
Normal file
40
scripts/track_gen.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import json
|
||||
from math import radians
|
||||
from pathlib import Path
|
||||
from src.utils import ROOT
|
||||
from src.vec import Vec
|
||||
|
||||
|
||||
def gen_circle(
|
||||
folder: Path, center: Vec, radius: float, n_sides: int, width: float = 1
|
||||
):
|
||||
with open(folder / "track.json", "w") as f:
|
||||
pts: list[tuple[float, ...]] = []
|
||||
|
||||
for i in range(n_sides):
|
||||
angle: float = radians(i / n_sides * 360)
|
||||
v: Vec = Vec(1, 0).rotate(angle)
|
||||
pos: Vec = center + v * radius
|
||||
normal: Vec = v
|
||||
pts.append((pos.x, pos.y, normal.x, normal.y, width))
|
||||
|
||||
for i, pt in enumerate(pts):
|
||||
pts[i] = tuple(round(v, 3) for v in pt)
|
||||
|
||||
json.dump([{"type": "road", "pts": pts}], f, indent=4)
|
||||
|
||||
with open(folder / "meta.json", "r") as f:
|
||||
meta: dict = json.load(f)
|
||||
|
||||
meta["start"] = {"pos": [radius, 0], "direction": [0, 1]}
|
||||
with open(folder / "meta.json", "w") as f:
|
||||
json.dump(meta, f, indent=4)
|
||||
|
||||
|
||||
def main():
|
||||
folder: Path = ROOT / "assets" / "tracks" / "simple"
|
||||
gen_circle(folder, Vec(0, 0), 30, 36)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user