@margoengine/road 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +205 -2
- package/dist/banking.d.ts +11 -0
- package/dist/banking.js +45 -0
- package/dist/design-mesh-DpZRXXz0.js +38 -0
- package/dist/design-mesh.d.ts +17 -0
- package/dist/drive-path.d.ts +49 -0
- package/dist/driving.d.ts +4 -0
- package/dist/driving.js +438 -0
- package/dist/errors-CsQwshHA.js +7 -0
- package/dist/frame-AjJIb-k3.js +9 -0
- package/dist/frame.d.ts +3 -0
- package/dist/geojson.d.ts +66 -0
- package/dist/geojson.js +375 -0
- package/dist/graph.d.ts +31 -0
- package/dist/graph.js +29 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +114 -0
- package/dist/intersections.d.ts +38 -0
- package/dist/intersections.js +100 -0
- package/dist/junctions.d.ts +33 -0
- package/dist/junctions.js +68 -0
- package/dist/lanes.d.ts +73 -0
- package/dist/lanes.js +100 -0
- package/dist/markings.d.ts +27 -0
- package/dist/markings.js +53 -0
- package/dist/repair.d.ts +11 -0
- package/dist/repair.js +23 -0
- package/dist/road-driver.d.ts +92 -0
- package/dist/road-surface.d.ts +36 -0
- package/dist/road-vehicle.d.ts +26 -0
- package/dist/shared/errors.d.ts +16 -0
- package/dist/structures.d.ts +91 -0
- package/dist/structures.js +229 -0
- package/dist/terrain.d.ts +16 -0
- package/dist/terrain.js +71 -0
- package/package.json +104 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { n as e, r as t, t as n } from "./design-mesh-DpZRXXz0.js";
|
|
2
|
+
//#region src/intersections.ts
|
|
3
|
+
function r(e, n, r) {
|
|
4
|
+
let i = e.map((t, r) => {
|
|
5
|
+
let i = e[(r + e.length - 1) % e.length], a = e[(r + 1) % e.length], o = Math.hypot(t[0] - i[0], t[1] - i[1]), s = Math.hypot(a[0] - t[0], a[1] - t[1]), c = [(t[0] - i[0]) / o, (t[1] - i[1]) / o], l = [(a[0] - t[0]) / s, (a[1] - t[1]) / s], u = Math.atan2(c[0] * l[1] - c[1] * l[0], c[0] * l[0] + c[1] * l[1]);
|
|
6
|
+
return {
|
|
7
|
+
b: t,
|
|
8
|
+
u: c,
|
|
9
|
+
v: l,
|
|
10
|
+
turn: u,
|
|
11
|
+
d: u < -1e-7 ? n * Math.tan(-u / 2) : 0,
|
|
12
|
+
l: o,
|
|
13
|
+
m: s
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
return i.flatMap(({ b: e, u: a, v: o, turn: s, d: c, l, m: u }, d) => {
|
|
17
|
+
if (!c) return [[...e]];
|
|
18
|
+
if (c + i[(d + i.length - 1) % i.length].d > l || c + i[(d + 1) % i.length].d > u) throw t("Turn radius does not fit adjacent edges; lengthen approaches or reduce turnRadius");
|
|
19
|
+
let f = [e[0] - a[0] * c, e[1] - a[1] * c], p = [f[0] + a[1] * n, f[1] - a[0] * n], m = Math.atan2(f[1] - p[1], f[0] - p[0]), h = Math.ceil(-s / (2 * Math.acos(Math.max(-1, 1 - r / n))));
|
|
20
|
+
if (h > 4096) throw t("Curb arc needs over 4096 segments; increase arcTolerance");
|
|
21
|
+
return Array.from({ length: Math.max(1, h) + 1 }, (t, r) => {
|
|
22
|
+
if (r === 0) return [f[0], f[1]];
|
|
23
|
+
if (r === Math.max(1, h)) return [e[0] + o[0] * c, e[1] + o[1] * c];
|
|
24
|
+
let i = m + s * r / Math.max(1, h);
|
|
25
|
+
return [p[0] + n * Math.cos(i), p[1] + n * Math.sin(i)];
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function i(i, a = {}) {
|
|
30
|
+
let { join: o = "round", cap: s = "round", miterLimit: c = 4, turnRadius: l = 2, arcTolerance: u = .02, elevation: d = 0, curbWidth: f = .2, curbHeight: p = .15, sidewalkWidth: m = 1.8, uvMeters: h = 1, signal: g } = a;
|
|
31
|
+
if (g?.throwIfAborted(), ![
|
|
32
|
+
"round",
|
|
33
|
+
"miter",
|
|
34
|
+
"bevel"
|
|
35
|
+
].includes(o) || ![
|
|
36
|
+
"round",
|
|
37
|
+
"butt",
|
|
38
|
+
"square"
|
|
39
|
+
].includes(s) || !e(c, 1, 100) || !e(l, 0, 1e3) || !e(u, 1e-6, 100) || !e(f, 0, 100) || !e(p, .001, 10) || !e(m, 0, 100) || !e(h, 1e-30, 1e6) || typeof d != "function" && !e(d, -1e6, 1e6) || !Array.isArray(i) || !i.length || i.length > 64) throw t("Invalid intersection options; use bounded metre dimensions and 1..64 roads");
|
|
40
|
+
let _ = 0, v = i.map((n) => {
|
|
41
|
+
let r = n?.width ?? 6;
|
|
42
|
+
if (!e(r, 1e-6, 1e3) || !Array.isArray(n?.points) || n.points.length < 2 || (_ += n.points.length) > 4096) throw t("Intersection roads need positive widths and 2..4096 points, 4096 total");
|
|
43
|
+
return {
|
|
44
|
+
points: n.points.map((r, i) => {
|
|
45
|
+
if (!Array.isArray(r) || r.length !== 2 || !r.every((t) => e(t, -1e6, 1e6)) || i > 0 && r[0] === n.points[i - 1][0] && r[1] === n.points[i - 1][1]) throw t("Intersection points need finite distinct neighbouring [x,z] pairs");
|
|
46
|
+
return [r[0], -r[1]];
|
|
47
|
+
}),
|
|
48
|
+
width: r
|
|
49
|
+
};
|
|
50
|
+
}), [{ polygonStroke: y, polygonUnion: b, polygonOffset: x, polygonDifference: S, polygonShapes: C, polygonArea: w }, { shapeGeometry: T }] = await Promise.all([import("@margoengine/geometry/polygon"), import("@margoengine/geometry/extrude")]);
|
|
51
|
+
g?.throwIfAborted();
|
|
52
|
+
let E = b(v.map((e) => y(e.points, e.width, {
|
|
53
|
+
join: o,
|
|
54
|
+
cap: s,
|
|
55
|
+
miterLimit: c,
|
|
56
|
+
arcTolerance: u
|
|
57
|
+
})));
|
|
58
|
+
if (l && (E = b(E.map((e) => ({
|
|
59
|
+
contour: r(e.contour, l, u),
|
|
60
|
+
holes: e.holes.map((e) => r(e, l, u))
|
|
61
|
+
})))), !E.length) throw t("Intersection footprint vanished; increase road width or use a local origin");
|
|
62
|
+
let D = (e) => e.map((e) => ({
|
|
63
|
+
contour: e.contour.map((e) => e.map(Math.fround)),
|
|
64
|
+
holes: e.holes.map((e) => e.map((e) => e.map(Math.fround)))
|
|
65
|
+
}));
|
|
66
|
+
E = D(E);
|
|
67
|
+
let O = (e, t, n) => [
|
|
68
|
+
e,
|
|
69
|
+
(typeof d == "function" ? d(e, t) : d) + n,
|
|
70
|
+
t
|
|
71
|
+
], k = (e, t, r = !1) => {
|
|
72
|
+
let i = new n(), a = D(e), o = T(C(a));
|
|
73
|
+
for (let e = 0; e < o.indices.length; e += 3) {
|
|
74
|
+
let n = Array.from(o.indices.subarray(e, e + 3), (e) => O(o.positions[e * 3], -o.positions[e * 3 + 1], t));
|
|
75
|
+
i.triangle(n[0], n[1], n[2]);
|
|
76
|
+
}
|
|
77
|
+
if (r) for (let e of E) for (let n of [e.contour, ...e.holes]) for (let e = 0; e < n.length; e++) {
|
|
78
|
+
let r = n[e], a = n[(e + 1) % n.length];
|
|
79
|
+
i.quad(O(r[0], -r[1], 0), O(r[0], -r[1], t), O(a[0], -a[1], t), O(a[0], -a[1], 0));
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
...i.finish(h),
|
|
83
|
+
area: w(a)
|
|
84
|
+
};
|
|
85
|
+
}, A = f ? x(E, f, {
|
|
86
|
+
join: "round",
|
|
87
|
+
arcTolerance: u
|
|
88
|
+
}) : E, j = {
|
|
89
|
+
...k(E, 0),
|
|
90
|
+
footprint: E,
|
|
91
|
+
curb: f ? k(S(A, E), p, !0) : null,
|
|
92
|
+
sidewalk: m ? k(S(x(E, f + m, {
|
|
93
|
+
join: "round",
|
|
94
|
+
arcTolerance: u
|
|
95
|
+
}), A), p) : null
|
|
96
|
+
};
|
|
97
|
+
return g?.throwIfAborted(), j;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { i as intersections };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Geometry } from '@margoengine/core';
|
|
2
|
+
/** One constant-width road centre line in the horizontal XZ plane, in metres. */
|
|
3
|
+
export interface JunctionRoad {
|
|
4
|
+
/** 2..4096 finite [x, z] points, each coordinate within 1,000,000 m. No repeated neighbours. */
|
|
5
|
+
points: readonly (readonly [number, number])[];
|
|
6
|
+
/** Full surface width in metres, above 0 and at most 1000. Default 6. */
|
|
7
|
+
width?: number;
|
|
8
|
+
}
|
|
9
|
+
/** Settings for an at-grade stitched road surface. */
|
|
10
|
+
export interface JunctionOptions {
|
|
11
|
+
/** Shared Y elevation in metres, within +/-1,000,000. Default 0. */
|
|
12
|
+
elevation?: number;
|
|
13
|
+
/** Metres per world-space UV repeat, above 0 and at most 1,000,000. Default 1. */
|
|
14
|
+
uvMeters?: number;
|
|
15
|
+
/** Cancels before and after lazy module loading. Synchronous polygon work runs to completion. */
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}
|
|
18
|
+
/** A single nonoverlapping surface containing every road and its crossings. */
|
|
19
|
+
export interface JunctionMesh {
|
|
20
|
+
/** Y-up triangles, suitable for a core mesh on WebGPU or WebGL2. Caller owns the CPU data. */
|
|
21
|
+
geometry: Geometry;
|
|
22
|
+
/** World-space [x, -z] texture coordinates, divided by uvMeters. */
|
|
23
|
+
uvs: Float32Array;
|
|
24
|
+
/** Filled area in square metres after overlapping surfaces have been united. */
|
|
25
|
+
area: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Stroke and unite 1..64 road centre lines, then triangulate once, including holes.
|
|
29
|
+
* Crossings, T junctions and overlapping bends share a surface instead of drawing overlapping sweeps.
|
|
30
|
+
* This is an at-grade surface: no curbs, grades, turn-radius design or bridge separation.
|
|
31
|
+
* Geometry's existing snap-rounded polygon and triangulation implementations do the geometric work.
|
|
32
|
+
*/
|
|
33
|
+
export declare function junctions(roads: readonly JunctionRoad[], { elevation, uvMeters, signal }?: JunctionOptions): Promise<JunctionMesh>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { t as e } from "./errors-CsQwshHA.js";
|
|
2
|
+
//#region src/junctions.ts
|
|
3
|
+
async function t(t, { elevation: n = 0, uvMeters: r = 1, signal: i } = {}) {
|
|
4
|
+
i?.throwIfAborted();
|
|
5
|
+
let a = () => e("failed", "Use 1..64 roads, at most 4096 total XZ points within +/-1000000, widths in (0,1000], a finite elevation within +/-1000000 and uvMeters in (0,1000000]", "geometry");
|
|
6
|
+
if (!Array.isArray(t) || !t.length || t.length > 64 || !Number.isFinite(n) || Math.abs(n) > 1e6 || !Number.isFinite(r) || r <= 0 || r > 1e6) throw a();
|
|
7
|
+
let o = 0, s = t.map((e) => {
|
|
8
|
+
let t = e?.width ?? 6;
|
|
9
|
+
if (!Number.isFinite(t) || t <= 0 || t > 1e3 || !Array.isArray(e?.points) || e.points.length < 2 || (o += e.points.length) > 4096) throw a();
|
|
10
|
+
return {
|
|
11
|
+
points: e.points.map((t, n) => {
|
|
12
|
+
if (!Array.isArray(t) || t.length !== 2 || !t.every((e) => Number.isFinite(e) && Math.abs(e) <= 1e6) || n && t[0] === e.points[n - 1][0] && t[1] === e.points[n - 1][1]) throw a();
|
|
13
|
+
return [t[0], -t[1]];
|
|
14
|
+
}),
|
|
15
|
+
width: t
|
|
16
|
+
};
|
|
17
|
+
}), [{ polygonStroke: c, polygonUnion: l, polygonArea: u, polygonShapes: d }, { shapeGeometry: f }, { applyMatrix4: p, toGeometry: m }] = await Promise.all([
|
|
18
|
+
import("@margoengine/geometry/polygon"),
|
|
19
|
+
import("@margoengine/geometry/extrude"),
|
|
20
|
+
import("@margoengine/geometry/utils")
|
|
21
|
+
]);
|
|
22
|
+
i?.throwIfAborted();
|
|
23
|
+
let h = l(s.map(({ points: e, width: t }) => c(e, t, {
|
|
24
|
+
join: "bevel",
|
|
25
|
+
cap: "butt"
|
|
26
|
+
})));
|
|
27
|
+
if (!h.length) throw e("failed", "Road footprint vanished at the polygon grid resolution; increase its width or reduce its coordinate span", "geometry");
|
|
28
|
+
let g = h.map(({ contour: e, holes: t }) => ({
|
|
29
|
+
contour: e.map(([e, t]) => [Math.fround(e), Math.fround(t)]),
|
|
30
|
+
holes: t.map((e) => e.map(([e, t]) => [Math.fround(e), Math.fround(t)]))
|
|
31
|
+
}));
|
|
32
|
+
if (g.some(({ contour: e, holes: t }) => [e, ...t].some((e) => !(u([{
|
|
33
|
+
contour: e,
|
|
34
|
+
holes: []
|
|
35
|
+
}]) > 0)))) throw e("failed", "Road boundary collapsed at float32 precision; move the roads closer to their local origin or increase their width", "geometry");
|
|
36
|
+
let _ = p(f(d(g)), [
|
|
37
|
+
1,
|
|
38
|
+
0,
|
|
39
|
+
0,
|
|
40
|
+
0,
|
|
41
|
+
0,
|
|
42
|
+
0,
|
|
43
|
+
-1,
|
|
44
|
+
0,
|
|
45
|
+
0,
|
|
46
|
+
1,
|
|
47
|
+
0,
|
|
48
|
+
0,
|
|
49
|
+
0,
|
|
50
|
+
n,
|
|
51
|
+
0,
|
|
52
|
+
1
|
|
53
|
+
]), v = _.positions;
|
|
54
|
+
for (let t = 0; t < _.indices.length; t += 3) {
|
|
55
|
+
let n = _.indices[t] * 3, r = _.indices[t + 1] * 3, i = _.indices[t + 2] * 3;
|
|
56
|
+
if (!((v[r + 2] - v[n + 2]) * (v[i] - v[n]) - (v[r] - v[n]) * (v[i + 2] - v[n + 2]) > 0)) throw e("failed", "Road triangles collapsed at float32 precision; move the roads closer to their local origin or increase their width", "geometry");
|
|
57
|
+
}
|
|
58
|
+
if (r !== 1) {
|
|
59
|
+
for (let t = 0; t < _.uvs.length; t++) if (_.uvs[t] /= r, !Number.isFinite(_.uvs[t])) throw e("failed", "Road UV coordinates overflowed float32; increase uvMeters or move the roads closer to their local origin", "geometry");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
geometry: m(_),
|
|
63
|
+
uvs: _.uvs,
|
|
64
|
+
area: u(g)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { t as junctions };
|
package/dist/lanes.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Spline } from '@margoengine/splines';
|
|
2
|
+
import type { Geometry } from '@margoengine/core';
|
|
3
|
+
/** Paint for one boundary, indexed left to right in the curve's direction. */
|
|
4
|
+
export interface LaneLine {
|
|
5
|
+
/** Default solid at outside edges and dashed inside. */
|
|
6
|
+
style?: 'solid' | 'dashed' | 'none';
|
|
7
|
+
/** Stroke width, metres. Default 0.15. */
|
|
8
|
+
width?: number;
|
|
9
|
+
/** Painted metres then unpainted metres. Default [3,6]. */
|
|
10
|
+
dash?: readonly [number, number];
|
|
11
|
+
/** Distance into the dash pattern at curve start. Default 0; use accumulated route distance at junctions. */
|
|
12
|
+
phase?: number;
|
|
13
|
+
/** Linear RGB, default white. */
|
|
14
|
+
color?: readonly [number, number, number];
|
|
15
|
+
}
|
|
16
|
+
/** An arrow authored in lane and arc-distance coordinates. */
|
|
17
|
+
export interface LaneArrow {
|
|
18
|
+
/** Zero-based lane index, left to right. */
|
|
19
|
+
lane: number;
|
|
20
|
+
/** Centre distance along the curve, metres. */
|
|
21
|
+
distance: number;
|
|
22
|
+
/** Direction in road coordinates. Default straight. */
|
|
23
|
+
turn?: 'straight' | 'left' | 'right' | 'straight-left' | 'straight-right';
|
|
24
|
+
/** Longitudinal length, metres. Default 4. */
|
|
25
|
+
length?: number;
|
|
26
|
+
/** Width, metres. Default min(1.5, lane width * 0.7). */
|
|
27
|
+
width?: number;
|
|
28
|
+
/** Face the opposite travel direction. Default false. */
|
|
29
|
+
reverse?: boolean;
|
|
30
|
+
/** Linear RGB, default white. */
|
|
31
|
+
color?: readonly [number, number, number];
|
|
32
|
+
}
|
|
33
|
+
/** Widths and paint placement, left to right looking along the curve. */
|
|
34
|
+
export interface LaneLayout {
|
|
35
|
+
/** 1..32 positive lane widths in metres. */
|
|
36
|
+
widths: readonly number[];
|
|
37
|
+
/** Exactly widths.length+1 boundary styles when specified; omitted entries use defaults. */
|
|
38
|
+
lines?: readonly LaneLine[];
|
|
39
|
+
/** Up to 4096 arrows. Default empty. */
|
|
40
|
+
arrows?: readonly LaneArrow[];
|
|
41
|
+
}
|
|
42
|
+
/** Arc-distance clipping and tessellation settings. */
|
|
43
|
+
export interface LaneOptions {
|
|
44
|
+
/** Maximum centreline arc-distance per chord, metres. Default 0.5. */
|
|
45
|
+
step?: number;
|
|
46
|
+
/** Start/end arc distances to paint. Default [0,curve.length]. */
|
|
47
|
+
range?: readonly [number, number];
|
|
48
|
+
/** Suppress paint across junction conflict areas; pairs of arc distances. Default empty. */
|
|
49
|
+
exclude?: readonly (readonly [number, number])[];
|
|
50
|
+
/** Vertical offset above road, metres. Default 0.01. */
|
|
51
|
+
lift?: number;
|
|
52
|
+
/** Shared ground height(x,z); default spline height at that distance. */
|
|
53
|
+
elevation?: (x: number, z: number) => number;
|
|
54
|
+
/** Checked before building and before return. Default none. */
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
}
|
|
57
|
+
/** Independent paint mesh, ready for an opaque material with the supplied linear colour. */
|
|
58
|
+
export interface LanePaint {
|
|
59
|
+
/** Line or arrow. */
|
|
60
|
+
kind: 'line' | 'arrow';
|
|
61
|
+
/** Boundary index for lines; lane index for arrows. */
|
|
62
|
+
index: number;
|
|
63
|
+
/** Owned finite CPU geometry. */
|
|
64
|
+
geometry: Geometry;
|
|
65
|
+
/** Owned planar UV coordinates in metres. */
|
|
66
|
+
uvs: Float32Array;
|
|
67
|
+
/** Owned linear RGB colour. */
|
|
68
|
+
color: [number, number, number];
|
|
69
|
+
/** Painted arc intervals, clipped to range/exclusions. */
|
|
70
|
+
intervals: [number, number][];
|
|
71
|
+
}
|
|
72
|
+
/** Build lane/edge lines and arrows that follow spline curvature and grade, including authored junction connectors. */
|
|
73
|
+
export declare function lanes(curve: Spline, layout: LaneLayout, options?: LaneOptions): LanePaint[];
|
package/dist/lanes.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { t as e } from "./frame-AjJIb-k3.js";
|
|
2
|
+
import { n as t, r as n, t as r } from "./design-mesh-DpZRXXz0.js";
|
|
3
|
+
//#region src/lanes.ts
|
|
4
|
+
function i(i, a, o = {}) {
|
|
5
|
+
let { step: s = .5, range: c = [0, i.length], exclude: l = [], lift: u = .01, elevation: d, signal: f } = o;
|
|
6
|
+
f?.throwIfAborted();
|
|
7
|
+
let p = () => n("Invalid lane design; use 1..32 positive widths, valid arc ranges, paint styles and bounded tessellation");
|
|
8
|
+
if (!t(i.length, 1e-6, 1e6) || !t(s, .001, 1e3) || !t(u, 0, 10) || !Array.isArray(a?.widths) || !a.widths.length || a.widths.length > 32 || !a.widths.every((e) => t(e, .1, 100)) || d !== void 0 && typeof d != "function" || !Array.isArray(l) || l.length > 4096) throw p();
|
|
9
|
+
let m = (e) => Array.isArray(e) && e.length === 2 && t(e[0], 0, i.length) && t(e[1], e[0], i.length);
|
|
10
|
+
if (!m(c) || !l.every(m)) throw p();
|
|
11
|
+
let h = [...a.widths], g = [h.reduce((e, t) => e + t, 0) / 2];
|
|
12
|
+
for (let e of h) g.push(g.at(-1) - e);
|
|
13
|
+
if (a.lines && (!Array.isArray(a.lines) || a.lines.length !== h.length + 1) || a.arrows && (!Array.isArray(a.arrows) || a.arrows.length > 4096)) throw p();
|
|
14
|
+
let _ = (e, t) => {
|
|
15
|
+
let n = [[Math.max(e, c[0]), Math.min(t, c[1])]].filter(([e, t]) => t > e);
|
|
16
|
+
for (let [e, t] of l) n = n.flatMap(([n, r]) => t <= n || e >= r ? [[n, r]] : [...e > n ? [[n, e]] : [], ...t < r ? [[t, r]] : []]);
|
|
17
|
+
return n;
|
|
18
|
+
}, v = /* @__PURE__ */ new Float64Array(3), y = /* @__PURE__ */ new Float64Array(3), b = /* @__PURE__ */ new Float64Array(3), x = (t, r) => {
|
|
19
|
+
e(i, t, Math.min(s * .01, i.length * 1e-5), v, y, b);
|
|
20
|
+
let a = b[0] - y[0], o = b[2] - y[2], c = Math.hypot(a, o);
|
|
21
|
+
if (!c) throw n("Lane curve has a vertical or zero tangent; use a nonvertical road");
|
|
22
|
+
let l = v[0] + o / c * r, f = v[2] - a / c * r;
|
|
23
|
+
return [
|
|
24
|
+
l,
|
|
25
|
+
(d ? d(l, f) : v[1]) + u,
|
|
26
|
+
f
|
|
27
|
+
];
|
|
28
|
+
}, S = (e = [
|
|
29
|
+
1,
|
|
30
|
+
1,
|
|
31
|
+
1
|
|
32
|
+
]) => {
|
|
33
|
+
if (!Array.isArray(e) || e.length !== 3 || !e.every((e) => t(e, 0, 1))) throw p();
|
|
34
|
+
return [...e];
|
|
35
|
+
}, C = 0, w = (e, t, r, i, a, o) => {
|
|
36
|
+
let c = Math.max(1, Math.ceil(Math.max(r - t, Math.abs(a - i)) / s));
|
|
37
|
+
if ((C += c) > 65536) throw n("Lane paint exceeds 65536 quads; increase step or reduce the painted distance");
|
|
38
|
+
let l = r - t, u = a - i, d = Math.hypot(l, u), f = -u / d * o / 2, m = l / d * o / 2;
|
|
39
|
+
if (!d) throw p();
|
|
40
|
+
let h = (e, n) => x(t + l * e + f * n, i + u * e + m * n);
|
|
41
|
+
for (let t = 0; t < c; t++) e.quad(h(t / c, -1), h((t + 1) / c, -1), h((t + 1) / c, 1), h(t / c, 1));
|
|
42
|
+
}, T = [];
|
|
43
|
+
for (let e = 0; e < g.length; e++) {
|
|
44
|
+
let n = a.lines?.[e] ?? {}, { style: o = e === 0 || e === h.length ? "solid" : "dashed", width: s = .15, dash: l = [3, 6], phase: u = 0 } = n;
|
|
45
|
+
if (![
|
|
46
|
+
"solid",
|
|
47
|
+
"dashed",
|
|
48
|
+
"none"
|
|
49
|
+
].includes(o) || !t(s, .001, 10) || !Number.isFinite(u) || !Array.isArray(l) || l.length !== 2 || !l.every((e) => t(e, .001, 1e4))) throw p();
|
|
50
|
+
let d = S(n.color);
|
|
51
|
+
if (o === "none") continue;
|
|
52
|
+
let f = [];
|
|
53
|
+
if (o === "solid") f.push(..._(0, i.length));
|
|
54
|
+
else {
|
|
55
|
+
let e = l[0] + l[1], t = (u % e + e) % e, n = Math.floor((c[0] + t) / e), r = Math.ceil((c[1] + t) / e);
|
|
56
|
+
if (r - n > 65536) throw p();
|
|
57
|
+
for (let i = n; i < r; i++) f.push(..._(i * e - t, i * e - t + l[0]));
|
|
58
|
+
}
|
|
59
|
+
if (!f.length) continue;
|
|
60
|
+
let m = new r();
|
|
61
|
+
for (let [t, n] of f) w(m, t, n, g[e], g[e], s);
|
|
62
|
+
T.push({
|
|
63
|
+
kind: "line",
|
|
64
|
+
index: e,
|
|
65
|
+
...m.finish(),
|
|
66
|
+
color: d,
|
|
67
|
+
intervals: f
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
for (let e of a.arrows ?? []) {
|
|
71
|
+
let { lane: n, distance: a, turn: o = "straight", length: s = 4, width: c = Math.min(1.5, h[n] * .7), reverse: l = !1 } = e;
|
|
72
|
+
if (!Number.isInteger(n) || n < 0 || n >= h.length || !t(s, .1, 100) || !t(c, .1, h[n] * .9) || !t(a, s / 2 + c / 2, i.length - s / 2 - c / 2) || typeof l != "boolean" || ![
|
|
73
|
+
"straight",
|
|
74
|
+
"left",
|
|
75
|
+
"right",
|
|
76
|
+
"straight-left",
|
|
77
|
+
"straight-right"
|
|
78
|
+
].includes(o)) throw p();
|
|
79
|
+
let u = S(e.color), d = a - s / 2, f = a + s / 2;
|
|
80
|
+
if (_(d - c / 2, f + c / 2).length !== 1 || _(d - c / 2, f + c / 2)[0][0] !== d - c / 2 || _(d - c / 2, f + c / 2)[0][1] !== f + c / 2) continue;
|
|
81
|
+
let m = new r(), v = (g[n] + g[n + 1]) / 2, y = l ? -1 : 1, b = (e, t, n, r) => {
|
|
82
|
+
let i = a + y * e, o = a + y * n, s = v + y * t, l = v + y * r;
|
|
83
|
+
i <= o ? w(m, i, o, s, l, c / 6) : w(m, o, i, l, s, c / 6);
|
|
84
|
+
};
|
|
85
|
+
if (b(-s / 2, 0, s * .1, 0), o.includes("straight") && (b(s * .1, 0, s / 2, 0), b(s * .25, -c / 2, s / 2, 0), b(s * .25, c / 2, s / 2, 0)), o !== "straight") {
|
|
86
|
+
let e = o.includes("left") ? 1 : -1;
|
|
87
|
+
b(s * .1, 0, s * .3, e * c / 2), b(s * .3, e * c / 2, s * .05, e * c * .3), b(s * .3, e * c / 2, s * .45, e * c * .25);
|
|
88
|
+
}
|
|
89
|
+
T.push({
|
|
90
|
+
kind: "arrow",
|
|
91
|
+
index: n,
|
|
92
|
+
...m.finish(),
|
|
93
|
+
color: u,
|
|
94
|
+
intervals: [[d, f]]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return f?.throwIfAborted(), T;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { i as lanes };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Decal } from '@margoengine/post/decals';
|
|
2
|
+
/** A projected solid/dashed line or stylized straight arrow, in world metres. */
|
|
3
|
+
export interface RoadMarking {
|
|
4
|
+
/** Line, or a shaft with two arrowhead strokes. */
|
|
5
|
+
kind: 'line' | 'arrow';
|
|
6
|
+
/** World-space centre, each coordinate within +/-1,000,000 m. */
|
|
7
|
+
position: readonly [number, number, number];
|
|
8
|
+
/** Radians about +Y from +Z toward +X (counterclockwise as viewed from above, the right-handed sense): 0 runs along +Z, pi/2 along +X. Default 0. */
|
|
9
|
+
angle?: number;
|
|
10
|
+
/** Full longitudinal extent, positive through 10000 m. Default 4. */
|
|
11
|
+
length?: number;
|
|
12
|
+
/** Line thickness or full arrowhead span, positive through 1000 m. Default 0.15 for lines, 1.5 for arrows. */
|
|
13
|
+
width?: number;
|
|
14
|
+
/** Line only: [painted length, gap], each positive through 10000 m. Starts painted at the line's negative end. Default solid. */
|
|
15
|
+
dash?: readonly [number, number];
|
|
16
|
+
}
|
|
17
|
+
/** Appearance and projection settings, shared by all returned decals. */
|
|
18
|
+
export interface RoadMarkingOptions {
|
|
19
|
+
/** Linear RGB channels, each 0..1. Default white [1,1,1]. Uses decal 'over' mode (unlit). */
|
|
20
|
+
color?: readonly [number, number, number];
|
|
21
|
+
/** Alpha in 0..1. Default 1. */
|
|
22
|
+
opacity?: number;
|
|
23
|
+
/** Downward projector depth, positive through 1000 m. Default 2. Road surface must lie inside this box. */
|
|
24
|
+
depth?: number;
|
|
25
|
+
}
|
|
26
|
+
/** Generate up to 4096 asset-free paint projectors for post/decals; [] clears all markings. All projector half-extents must be normal float32 values (at least 2^-126). No GPU allocation or import side effect. */
|
|
27
|
+
export declare function markings(items: readonly RoadMarking[], { color, opacity, depth }?: RoadMarkingOptions): Decal[];
|
package/dist/markings.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { t as e } from "./errors-CsQwshHA.js";
|
|
2
|
+
//#region src/markings.ts
|
|
3
|
+
function t(t, { color: n = [
|
|
4
|
+
1,
|
|
5
|
+
1,
|
|
6
|
+
1
|
|
7
|
+
], opacity: r = 1, depth: i = 2 } = {}) {
|
|
8
|
+
let a = () => e("failed", "Road markings need bounded finite positions, valid line/arrow settings and at most 4096 projectors; reduce the markings or fix their dimensions", "geometry");
|
|
9
|
+
if (!Array.isArray(t) || t.length > 4096 || n.length !== 3 || !n.every((e) => Number.isFinite(e) && e >= 0 && e <= 1) || !Number.isFinite(r) || r < 0 || r > 1 || !Number.isFinite(i) || i / 2 < 2 ** -126 || i > 1e3) throw a();
|
|
10
|
+
let o = [];
|
|
11
|
+
for (let e of t) {
|
|
12
|
+
if (!e || typeof e != "object") throw a();
|
|
13
|
+
let { kind: t, position: s, angle: c = 0, length: l = 4, width: u = t === "arrow" ? 1.5 : .15, dash: d } = e;
|
|
14
|
+
if (!["line", "arrow"].includes(t) || !Array.isArray(s) || s.length !== 3 || !s.every((e) => Number.isFinite(e) && Math.abs(e) <= 1e6) || !Number.isFinite(c) || !Number.isFinite(l) || l / 2 < 2 ** -126 || l > 1e4 || !Number.isFinite(u) || u / (t === "arrow" ? 10 : 2) < 2 ** -126 || u > 1e3 || d && (t !== "line" || d.length !== 2 || !d.every((e) => Number.isFinite(e) && e / 2 >= 2 ** -126 && e <= 1e4))) throw a();
|
|
15
|
+
let f = t === "arrow" ? 3 : d ? Math.ceil(l / (d[0] + d[1])) : 1;
|
|
16
|
+
if (o.length + f > 4096) throw a();
|
|
17
|
+
let p = Math.sin(c), m = Math.cos(c), h = (e, t, l, u, d) => {
|
|
18
|
+
let f = (e + l) / 2, h = (t + u) / 2, g = c + Math.atan2(l - e, u - t), _ = Math.hypot(l - e, u - t);
|
|
19
|
+
if (_ / 2 < 2 ** -126 || d / 2 < 2 ** -126) throw a();
|
|
20
|
+
o.push({
|
|
21
|
+
position: [
|
|
22
|
+
s[0] + m * f + p * h,
|
|
23
|
+
s[1],
|
|
24
|
+
s[2] - p * f + m * h
|
|
25
|
+
],
|
|
26
|
+
direction: [
|
|
27
|
+
0,
|
|
28
|
+
-1,
|
|
29
|
+
0
|
|
30
|
+
],
|
|
31
|
+
up: [
|
|
32
|
+
Math.sin(g),
|
|
33
|
+
0,
|
|
34
|
+
Math.cos(g)
|
|
35
|
+
],
|
|
36
|
+
width: d,
|
|
37
|
+
height: _,
|
|
38
|
+
depth: i,
|
|
39
|
+
color: [...n],
|
|
40
|
+
opacity: r,
|
|
41
|
+
mode: "over"
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
if (t === "arrow") h(0, -l / 2, 0, l / 2, u / 5), h(-u / 2, l * .15, 0, l / 2, u / 5), h(u / 2, l * .15, 0, l / 2, u / 5);
|
|
45
|
+
else for (let e = 0; e < f; e++) {
|
|
46
|
+
let t = d ? e * (d[0] + d[1]) : 0, n = d ? Math.min(d[0], l - t) : l;
|
|
47
|
+
h(0, t - l / 2, 0, t + n - l / 2, u);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return o;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { t as markings };
|
package/dist/repair.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Spline } from '@margoengine/splines';
|
|
2
|
+
import type { JunctionMesh, JunctionOptions } from '@margoengine/road/junctions';
|
|
3
|
+
/** Planar tight-bend repair settings. */
|
|
4
|
+
export interface RoadRepairOptions extends Omit<JunctionOptions, 'elevation'> {
|
|
5
|
+
/** Full surface width, above zero through 1000 m. Default 6. */
|
|
6
|
+
width?: number;
|
|
7
|
+
/** Arc-distance chords, integer 1..4095. Default 128. More chords improve the spline approximation. */
|
|
8
|
+
segments?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Replace a folding planar road sweep with the union of its stroked centre line, triangulated at renderer precision. */
|
|
11
|
+
export declare function repairRoad(curve: Spline, { width, segments, ...options }?: RoadRepairOptions): Promise<JunctionMesh>;
|
package/dist/repair.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { t as e } from "./errors-CsQwshHA.js";
|
|
2
|
+
//#region src/repair.ts
|
|
3
|
+
async function t(t, { width: n = 6, segments: r = 128, ...i } = {}) {
|
|
4
|
+
if (i.signal?.throwIfAborted(), !Number.isInteger(r) || r < 1 || r > 4095 || !Number.isFinite(t.length) || t.length <= 0) throw e("failed", "Road repair needs a nonzero spline and 1..4095 segments; pass valid planar road settings", "geometry");
|
|
5
|
+
let a = [], o = /* @__PURE__ */ new Float64Array(3);
|
|
6
|
+
t.atDistance(0, o);
|
|
7
|
+
let s = o[1], c = 128 * 2 ** -52 * Math.max(1, Math.abs(s)), l = t.points.length / 3, u = t.kind === "bezier" ? (l - 1) / 3 : t.closed ? l : l - 1;
|
|
8
|
+
for (let n = 0; n < u; n++) for (let r = 0; r <= 3; r++) if (t.at((n + r / 3) / u, o), !Number.isFinite(o[1]) || Math.abs(o[1] - s) > c) throw e("unsupported", "Road repair supports constant-elevation curves; split grades or use the root sweep without planar repair", "geometry");
|
|
9
|
+
for (let n = 0; n <= r; n++) {
|
|
10
|
+
if (t.atDistance(t.length * n / r, o), !Number.isFinite(o[1]) || Math.abs(o[1] - s) > c) throw e("unsupported", "Road repair supports constant-elevation curves; split grades or use the root sweep without planar repair", "geometry");
|
|
11
|
+
a.push([o[0], o[2]]);
|
|
12
|
+
}
|
|
13
|
+
let { junctions: d } = await import("@margoengine/road/junctions");
|
|
14
|
+
return i.signal?.throwIfAborted(), d([{
|
|
15
|
+
points: a,
|
|
16
|
+
width: n
|
|
17
|
+
}], {
|
|
18
|
+
...i,
|
|
19
|
+
elevation: s
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { t as repairRoad };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
2
|
+
import type { Physics, Vehicle, VehicleInput } from '@margoengine/physics';
|
|
3
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
4
|
+
import type { FieldDescriptor, Port, Region, Solver, SolverDescription, SolverHost, StepContext, PhysicsWorld } from '@margoengine/physics/world';
|
|
5
|
+
import { type DrivePoint, type RoadDrivePath } from './drive-path.js';
|
|
6
|
+
import { type RoadTraction } from './road-surface.js';
|
|
7
|
+
/** One fixed-stride row of normalized controls and navigation telemetry per configured vehicle. */
|
|
8
|
+
export declare const ROAD_DRIVER_WORDS = 8;
|
|
9
|
+
/** Command port layout. Each row is steer, throttle, brake, target/current speed, progress, wetness and segment index. */
|
|
10
|
+
export declare const ROAD_DRIVER_LAYOUT = 1;
|
|
11
|
+
/** A forward lane driver and the rigid body that follows its lane. */
|
|
12
|
+
export interface RoadDriverVehicle {
|
|
13
|
+
readonly body: number;
|
|
14
|
+
readonly path: RoadDrivePath;
|
|
15
|
+
readonly traction: RoadTraction;
|
|
16
|
+
/** Maximum approach speed on dry straight sections, m/s. Default 13.9. */
|
|
17
|
+
readonly maxSpeed?: number;
|
|
18
|
+
/** Wheelbase in metres, measured between front and rear axle. */
|
|
19
|
+
readonly wheelbase: number;
|
|
20
|
+
/** Offset of the tracking point from the chassis origin along its forward axis, m. Default 0. */
|
|
21
|
+
readonly rearOffset?: number;
|
|
22
|
+
/** Local units of chassis forward. Default +Z. */
|
|
23
|
+
readonly forward?: DrivePoint;
|
|
24
|
+
/** Full steering angle in radians, matching Vehicle; default 0.5. */
|
|
25
|
+
readonly maxSteer?: number;
|
|
26
|
+
/** Minimum look-ahead distance in metres. Default 2. */
|
|
27
|
+
readonly lookAhead?: number;
|
|
28
|
+
/** Extra look-ahead seconds applied to forward speed. Default 0.35. */
|
|
29
|
+
readonly lookAheadTime?: number;
|
|
30
|
+
/** Longitudinal acceleration for full throttle, m/s². Default 3. */
|
|
31
|
+
readonly acceleration?: number;
|
|
32
|
+
/** Comfort braking acceleration, m/s². Default 4, reduced by the available traction. */
|
|
33
|
+
readonly deceleration?: number;
|
|
34
|
+
/** Time constant for speed convergence, seconds. Default 0.75. */
|
|
35
|
+
readonly speedResponse?: number;
|
|
36
|
+
/** Relative wetness without a bound port. Default 0. */
|
|
37
|
+
readonly wetness?: number;
|
|
38
|
+
/** Index of the relative wetness in the bound layout-1 f64 port. Default 0. */
|
|
39
|
+
readonly wetnessWord?: number;
|
|
40
|
+
/** Optional existing vehicle attachment. Bind it after add() to retain its wheel and drivetrain state. */
|
|
41
|
+
readonly attachment?: Vehicle;
|
|
42
|
+
}
|
|
43
|
+
/** Drivers share one origin cell and the world's gravity and 60 Hz physics clock. */
|
|
44
|
+
export interface RoadDriverParams {
|
|
45
|
+
readonly vehicles: readonly RoadDriverVehicle[];
|
|
46
|
+
/** Required if rigid body positions and this lane are in different world cells. */
|
|
47
|
+
readonly cellSize?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for the road driver: its registry prefix (default 'road-driver') and an optional relative wetness
|
|
51
|
+
* field.
|
|
52
|
+
*/
|
|
53
|
+
export interface RoadDriverOptions {
|
|
54
|
+
/** Registry prefix. Default 'road-driver'. */
|
|
55
|
+
readonly id?: string;
|
|
56
|
+
/** ATMO-09 layout-1 f64 relative wetness, or another producer of the same declared quantity. */
|
|
57
|
+
readonly wetnessField?: FieldDescriptor;
|
|
58
|
+
}
|
|
59
|
+
/** Data copied from the live command port. */
|
|
60
|
+
export interface RoadDriveCommand extends Required<Pick<VehicleInput, 'steer' | 'throttle' | 'brake'>> {
|
|
61
|
+
readonly targetSpeed: number;
|
|
62
|
+
readonly speed: number;
|
|
63
|
+
readonly progress: number;
|
|
64
|
+
readonly wetness: number;
|
|
65
|
+
readonly segment: number;
|
|
66
|
+
}
|
|
67
|
+
/** Deterministic 60 Hz lane pursuit and traction-limited braking of actual rigid road vehicles. */
|
|
68
|
+
export declare class RoadDriver implements Solver<RoadDriverParams> {
|
|
69
|
+
private readonly port;
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly commandsField: FieldDescriptor;
|
|
72
|
+
private readonly rainfall;
|
|
73
|
+
private state;
|
|
74
|
+
private readonly bound;
|
|
75
|
+
/** Load the existing rigid body port only when constructing a clocked driver. */
|
|
76
|
+
static create(options?: RoadDriverOptions, signal?: AbortSignal): Promise<RoadDriver>;
|
|
77
|
+
private constructor();
|
|
78
|
+
describe(): SolverDescription;
|
|
79
|
+
init(host: SolverHost, params: RoadDriverParams): void;
|
|
80
|
+
step(context: StepContext): void;
|
|
81
|
+
exportPorts(tick: number): readonly Port[];
|
|
82
|
+
importPorts(_tick: number): void;
|
|
83
|
+
stateRegions(): readonly Region[];
|
|
84
|
+
extraState(): readonly Region[];
|
|
85
|
+
/** Copy the current command of one vehicle. */
|
|
86
|
+
read(index: number): RoadDriveCommand;
|
|
87
|
+
/** Drive the registered Vehicle at pre-step from the published world port. Returns an unbind function. */
|
|
88
|
+
bindVehicle(world: PhysicsWorld, physics: Physics, index: number): () => void;
|
|
89
|
+
private motion;
|
|
90
|
+
private driver;
|
|
91
|
+
private requireState;
|
|
92
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
2
|
+
import type { Physics, PhysicsBody, PhysicsCollider, WheelGroundContact, WheelGroundMaterial } from '@margoengine/physics';
|
|
3
|
+
import type { RoadMesh } from './index.js';
|
|
4
|
+
/** Measured limits at dry and fully wet endpoints on one road surface. */
|
|
5
|
+
export interface RoadTraction {
|
|
6
|
+
readonly dry: number;
|
|
7
|
+
readonly wet: number;
|
|
8
|
+
/** Yielding substrate, with the same measured footprint as the optional vehicle contact model. */
|
|
9
|
+
readonly soil?: WheelGroundMaterial['soil'];
|
|
10
|
+
}
|
|
11
|
+
/** Friction state of a physical collider, including a varying wetness service when supplied. */
|
|
12
|
+
export interface RoadSurfaceOptions {
|
|
13
|
+
readonly traction: RoadTraction;
|
|
14
|
+
/** 0 for dry and 1 for fully wet. Default 0. A callback can read the physics clock's held weather samples. */
|
|
15
|
+
readonly wetness?: number | ((point: WheelGroundContact['point']) => number);
|
|
16
|
+
}
|
|
17
|
+
/** Settings for a collider that uses exactly the triangles of a built road or banked road. */
|
|
18
|
+
export interface RoadColliderOptions extends RoadSurfaceOptions {
|
|
19
|
+
/** Offset from the physics world origin, m. Default [0, 0, 0]. */
|
|
20
|
+
readonly position?: WheelGroundContact['point'];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns the grip coefficient for a road given its dry and wet traction and a relative wetness from 0 to 1
|
|
24
|
+
* (default 0). Throws when the coefficients or the wetness are out of range.
|
|
25
|
+
*/
|
|
26
|
+
export declare function roadGrip(traction: RoadTraction, wetness?: number): number;
|
|
27
|
+
/** Per-collider measured tyre grip and soil response. Pass `sample` as a Vehicle's `groundMaterial`. */
|
|
28
|
+
export declare class RoadSurfaces {
|
|
29
|
+
private readonly materials;
|
|
30
|
+
/** Bind traction to an existing static road, moving deck, or terrain collider. */
|
|
31
|
+
register(collider: PhysicsCollider, options: RoadSurfaceOptions): this;
|
|
32
|
+
/** Add one fixed, edge-corrected collider using the visible road's original bank and curb geometry. */
|
|
33
|
+
add(physics: Physics, road: RoadMesh, options: RoadColliderOptions): PhysicsBody;
|
|
34
|
+
/** A sample is absent for other colliders, leaving their existing Vehicle behavior in place. */
|
|
35
|
+
readonly sample: (contact: WheelGroundContact) => WheelGroundMaterial | undefined;
|
|
36
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Mesh } from '@margoengine/core';
|
|
2
|
+
import type { Wind } from '@margoengine/math/fields';
|
|
3
|
+
// @ts-ignore optional peer: its types apply when it is installed
|
|
4
|
+
import type { Vehicle, WindForce, Physics, PhysicsBody, VehicleOptions } from '@margoengine/physics';
|
|
5
|
+
import { type DrivePoint } from './drive-path.js';
|
|
6
|
+
/** Body dimensions from an authored or procedural asset, a measured mass and the actual wheel mounts. */
|
|
7
|
+
export interface RoadVehicleOptions extends VehicleOptions {
|
|
8
|
+
/** Vehicle dimensions in the chassis's local X/Y/Z order, metres. */
|
|
9
|
+
readonly size: DrivePoint;
|
|
10
|
+
/** Chassis mass in kilograms. */
|
|
11
|
+
readonly mass: number;
|
|
12
|
+
/** Body origin, metres. Default origin. */
|
|
13
|
+
readonly position?: DrivePoint;
|
|
14
|
+
/** Offset of the chassis collider centre from the body origin, metres. Default zero. */
|
|
15
|
+
readonly colliderOffset?: DrivePoint;
|
|
16
|
+
/** Optional air field. Add an AirSolver when stepping the attachment on a PhysicsWorld clock. */
|
|
17
|
+
readonly wind?: Wind;
|
|
18
|
+
}
|
|
19
|
+
/** A road vehicle ready to step: its physics body, its vehicle and the optional wind force. */
|
|
20
|
+
export interface RoadVehicleAssembly {
|
|
21
|
+
readonly body: PhysicsBody;
|
|
22
|
+
readonly vehicle: Vehicle;
|
|
23
|
+
readonly wind?: WindForce;
|
|
24
|
+
}
|
|
25
|
+
/** Give a procedural vehicle a physical chassis, wheels and optional weather wind. Physics owns the result. */
|
|
26
|
+
export declare function addRoadVehicle(physics: Physics, mesh: Mesh | null, options: RoadVehicleOptions, signal?: AbortSignal): Promise<RoadVehicleAssembly>;
|