feat: add simple track generator

This commit is contained in:
2025-10-18 21:56:14 +02:00
parent f1ae12d0ec
commit dde690818b
3 changed files with 272 additions and 36 deletions

View File

@@ -2,12 +2,12 @@
"name": "Simple Track", "name": "Simple Track",
"start": { "start": {
"pos": [ "pos": [
0, 30,
-3 0
], ],
"direction": [ "direction": [
1, 0,
0 1
] ]
} }
} }

View File

@@ -3,59 +3,255 @@
"type": "road", "type": "road",
"pts": [ "pts": [
[ [
0, 30.0,
-3, 0.0,
0, 1.0,
-1, 0.0,
1 1
], ],
[ [
2, 29.544,
-2, 5.209,
1, 0.985,
-1, 0.174,
1 1
], ],
[ [
3, 28.191,
0, 10.261,
1, 0.94,
0, 0.342,
1 1
], ],
[ [
2, 25.981,
2, 15.0,
1, 0.866,
1, 0.5,
1 1
], ],
[ [
0, 22.981,
3, 19.284,
0, 0.766,
1, 0.643,
1 1
], ],
[ [
-2, 19.284,
2, 22.981,
-1, 0.643,
1, 0.766,
1 1
], ],
[ [
-3, 15.0,
0, 25.981,
-1, 0.5,
0, 0.866,
1 1
], ],
[ [
-2, 10.261,
-2, 28.191,
-1, 0.342,
-1, 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 1
] ]
] ]

40
scripts/track_gen.py Normal file
View 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()