@bendyline/molen-client 0.0.13 → 0.0.16

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.
@@ -0,0 +1,218 @@
1
+ import { resolveSnowCover } from "@bendyline/molen-schema";
2
+ import * as THREE from "three";
3
+ //#region src/weather/snow-cover.ts
4
+ /** Linear albedo of lying snow: bright, a little blue, short of white so sunlit slopes keep form. */
5
+ const SNOW_COVER_COLOR = [
6
+ .78,
7
+ .82,
8
+ .87
9
+ ];
10
+ /**
11
+ * Meters after which the snow line's wander repeats. A host passes world coordinates reduced by
12
+ * this period, which keeps float precision and survives floating-origin rebases; the terrain
13
+ * ground's own noise shares the period.
14
+ */
15
+ const SNOW_COVER_PERIOD = 4096;
16
+ /** Noise cells in meters that move the line, and how far each moves it, as shares of the band. */
17
+ const WANDER = [[
18
+ 512,
19
+ .5,
20
+ 401,
21
+ 59
22
+ ], [
23
+ 64,
24
+ .2,
25
+ 83,
26
+ 131
27
+ ]];
28
+ /** The most the wander can add to or take from a height, as a share of the transition band. */
29
+ const WANDER_REACH = WANDER.reduce((sum, [, share]) => sum + share / 2, 0);
30
+ /**
31
+ * World-normal up component across which a marked surface goes from bare to dusted, unless the
32
+ * material names its own range: walls stay clean and anything flatter than about 40 degrees is
33
+ * covered.
34
+ */
35
+ const SNOW_COVER_FACING = [.3, .75];
36
+ /** Most of a dusted surface's own color that snow hides. */
37
+ const SURFACE_COVER = .94;
38
+ function createSnowCoverUniforms() {
39
+ return {
40
+ molenSnowCover: { value: new THREE.Vector4(0, 150, 0, 0) },
41
+ molenSnowOrigin: { value: new THREE.Vector2() }
42
+ };
43
+ }
44
+ const wrap = (value) => (value % SNOW_COVER_PERIOD + SNOW_COVER_PERIOD) % SNOW_COVER_PERIOD;
45
+ /**
46
+ * Write a snow cover (or none) into a `vec4` uniform value: the line in rendered Y, which is
47
+ * world Y less the floating origin's, the transition band, and an amount of 1.
48
+ */
49
+ function writeSnowCoverValue(target, cover, worldOriginY = 0) {
50
+ if (cover === void 0) {
51
+ target.z = 0;
52
+ return;
53
+ }
54
+ const { level, transition } = resolveSnowCover(cover);
55
+ target.set(level - worldOriginY, transition, 1, 0);
56
+ }
57
+ /** Point a renderer's snow uniforms at a cover (or none) for a world origin. */
58
+ function writeSnowCover(uniforms, cover, worldOrigin) {
59
+ writeSnowCoverValue(uniforms.molenSnowCover.value, cover, worldOrigin[1]);
60
+ uniforms.molenSnowOrigin.value.set(wrap(worldOrigin[0]), wrap(worldOrigin[2]));
61
+ }
62
+ /**
63
+ * GLSL for the shared snow line. `molenSnowLine(p, height, snow)` is the share of ground covered
64
+ * at world XZ `p` (reduced by the period) and rendered height, for a `snow` uniform as
65
+ * `writeSnowCoverValue` fills it. Guarded, so a ground material that includes it and also takes
66
+ * the renderer's hook defines it once.
67
+ */
68
+ const SNOW_COVER_GLSL = `
69
+ #ifndef MOLEN_SNOW_LINE
70
+ #define MOLEN_SNOW_LINE
71
+ float molenSnowHash(vec2 c, float period) {
72
+ c -= period * floor(c / period);
73
+ vec3 p3 = fract(vec3(c.xyx) * 0.1031);
74
+ p3 += dot(p3, p3.yzx + 33.33);
75
+ return fract((p3.x + p3.y) * p3.z);
76
+ }
77
+ float molenSnowNoise(vec2 p, float cell) {
78
+ float period = ${SNOW_COVER_PERIOD.toFixed(1)} / cell;
79
+ vec2 q = p / cell;
80
+ vec2 i = floor(q);
81
+ vec2 f = q - i;
82
+ vec2 u = f * f * (3.0 - 2.0 * f);
83
+ return mix(
84
+ mix(molenSnowHash(i, period), molenSnowHash(i + vec2(1.0, 0.0), period), u.x),
85
+ mix(molenSnowHash(i + vec2(0.0, 1.0), period), molenSnowHash(i + vec2(1.0, 1.0), period), u.x),
86
+ u.y);
87
+ }
88
+ float molenSnowLine(vec2 p, float height, vec4 snow) {
89
+ if (snow.z <= 0.0) return 0.0;
90
+ float above = (height - snow.x) / max(snow.y, 1.0);
91
+ // Out of the wander's reach the answer is known: most of a scene skips the noise.
92
+ if (above <= -${WANDER_REACH.toFixed(2)}) return 0.0;
93
+ if (above >= ${(1 + WANDER_REACH).toFixed(2)}) return snow.z;
94
+ float wander = ${WANDER.map(([cell, share, x, z]) => `(molenSnowNoise(p + vec2(${x.toFixed(1)}, ${z.toFixed(1)}), ${cell.toFixed(1)}) - 0.5) * ${share.toFixed(2)}`).join(" +\n ")};
95
+ float t = clamp(above + wander, 0.0, 1.0);
96
+ return t * t * (3.0 - 2.0 * t) * snow.z;
97
+ }
98
+ #endif
99
+ `;
100
+ const SURFACE_GLSL = `
101
+ uniform vec4 molenSnowCover;
102
+ uniform vec2 molenSnowOrigin;
103
+ // This material's amount (0: takes no snow) and the facing range it dusts over.
104
+ uniform vec3 molenSnowSurface;
105
+ ${SNOW_COVER_GLSL}
106
+ `;
107
+ const SURFACE_INCLUDE = "#include <normal_fragment_maps>";
108
+ /** In every lit fragment shader, and only those: they declare the view position read below. */
109
+ const LIT_INCLUDE = "#include <lights_pars_begin>";
110
+ /**
111
+ * Add the snow dusting to a WebGL shader built from three's lit chunks; false if it has none.
112
+ * Every such shader carries the code, so materials keep sharing programs; `material` only sets
113
+ * its own amount and facing range (an unmarked material's amount is 0).
114
+ */
115
+ function injectSnowCover(shader, uniforms, material) {
116
+ if (!shader.fragmentShader.includes(SURFACE_INCLUDE) || !shader.fragmentShader.includes(LIT_INCLUDE)) return false;
117
+ shader.fragmentShader = `${SURFACE_GLSL}\n${shader.fragmentShader.replace(SURFACE_INCLUDE, `${SURFACE_INCLUDE}
118
+ if ( molenSnowSurface.x > 0.0 && molenSnowCover.z > 0.0 ) {
119
+ vec3 molenSnowWorld = cameraPosition + ( vec4( - vViewPosition, 0.0 ) * viewMatrix ).xyz;
120
+ float molenSnowUp = ( vec4( normal, 0.0 ) * viewMatrix ).y;
121
+ float molenSnow = molenSnowLine( molenSnowWorld.xz + molenSnowOrigin, molenSnowWorld.y, molenSnowCover ) *
122
+ smoothstep( molenSnowSurface.y, molenSnowSurface.z, molenSnowUp ) * ${SURFACE_COVER.toFixed(2)} * molenSnowSurface.x;
123
+ diffuseColor.rgb = mix( diffuseColor.rgb, vec3( ${SNOW_COVER_COLOR.map((c) => c.toFixed(3)).join(", ")} ), molenSnow );
124
+ #ifdef STANDARD
125
+ roughnessFactor = mix( roughnessFactor, 0.9, molenSnow );
126
+ metalnessFactor *= 1.0 - molenSnow;
127
+ #endif
128
+ }`)}`;
129
+ const [from, to] = snowCoverFacing(material);
130
+ Object.assign(shader.uniforms, uniforms, { molenSnowSurface: { value: new THREE.Vector3(snowCoverAmount(material), from, to) } });
131
+ return true;
132
+ }
133
+ const keyed = /* @__PURE__ */ new WeakSet();
134
+ /**
135
+ * How much of the weather's lying snow settles on a material: 0 unless `enableSnowCover` marked
136
+ * it (or the material it was cloned from).
137
+ */
138
+ function snowCoverAmount(material) {
139
+ const amount = material.userData.molenSnowCover;
140
+ return typeof amount === "number" && amount > 0 ? Math.min(1, amount) : 0;
141
+ }
142
+ /** The up-component range over which a material's surfaces go from bare to dusted. */
143
+ function snowCoverFacing(material) {
144
+ const facing = material.userData.molenSnowFacing;
145
+ return Array.isArray(facing) && facing.length === 2 ? facing : SNOW_COVER_FACING;
146
+ }
147
+ /**
148
+ * Let lying snow settle on a lit material: above the weather's snow line its up-facing surfaces
149
+ * whiten, on either backend, with no further calls. For roofs, ledges, crowns, props and parked
150
+ * cars; not for the ground (its materials draw their own snow), water, or anything that moves
151
+ * through the weather, such as an aircraft or a person. `amount` (0–1, default 1) thins the
152
+ * dusting: foliage holds less than a roof. `facing` is the range of the surface normal's up
153
+ * component over which it goes from bare to dusted (default `SNOW_COVER_FACING`: flat roofs
154
+ * white, walls clean); a lower range lets snow cling to steep sides, as on a conifer. A `clone()`
155
+ * stays marked, as does a `copy()` target marked again afterwards. Call it before the material
156
+ * first draws.
157
+ */
158
+ function enableSnowCover(material, amount = 1, facing) {
159
+ if (!(amount > 0 && amount <= 1)) throw new RangeError("Snow cover amount must be in (0, 1]");
160
+ if (facing !== void 0 && !(facing[0] < facing[1])) throw new RangeError("Snow cover facing must be an ascending range");
161
+ const data = material.userData;
162
+ data.molenSnowCover = amount;
163
+ if (facing === void 0) delete data.molenSnowFacing;
164
+ else data.molenSnowFacing = [...facing];
165
+ if (!keyed.has(material)) {
166
+ keyed.add(material);
167
+ const previous = material.customProgramCacheKey.bind(material);
168
+ material.customProgramCacheKey = () => `${previous()}|molen-snow-cover:${snowCoverAmount(material)}:${snowCoverFacing(material).join(",")}`;
169
+ }
170
+ material.needsUpdate = true;
171
+ return material;
172
+ }
173
+ /** `molenSnowLine` as TSL nodes; `tsl` is the caller's lazily loaded `three/tsl`. */
174
+ function snowLineNode(tsl, p, height, snow) {
175
+ const { clamp, dot, float, floor, Fn, fract, If, max, mix, vec2, vec3 } = tsl;
176
+ const hash = (cell, period) => {
177
+ const c = cell.sub(floor(cell.div(period)).mul(period));
178
+ const a = fract(vec3(c.x, c.y, c.x).mul(.1031));
179
+ const b = a.add(dot(a, a.yzx.add(33.33)));
180
+ return fract(b.x.add(b.y).mul(b.z));
181
+ };
182
+ const noise = (at, size) => {
183
+ const period = SNOW_COVER_PERIOD / size;
184
+ const q = at.div(size);
185
+ const i = floor(q).toVar();
186
+ const f = q.sub(i);
187
+ const u = f.mul(f).mul(f.mul(-2).add(3)).toVar();
188
+ return mix(mix(hash(i, period), hash(i.add(vec2(1, 0)), period), u.x), mix(hash(i.add(vec2(0, 1)), period), hash(i.add(vec2(1, 1)), period), u.x), u.y);
189
+ };
190
+ return Fn(([at, rendered, lying]) => {
191
+ const result = float(0).toVar();
192
+ If(lying.z.greaterThan(0), () => {
193
+ const above = rendered.sub(lying.x).div(max(lying.y, 1)).toVar();
194
+ If(above.greaterThanEqual(1 + WANDER_REACH), () => {
195
+ result.assign(lying.z);
196
+ }).ElseIf(above.greaterThan(-WANDER_REACH), () => {
197
+ let wander;
198
+ for (const [cell, share, x, z] of WANDER) {
199
+ const term = noise(at.add(vec2(x, z)), cell).sub(.5).mul(share);
200
+ wander = wander === void 0 ? term : wander.add(term);
201
+ }
202
+ const t = clamp(above.add(wander), 0, 1).toVar();
203
+ result.assign(t.mul(t).mul(t.mul(-2).add(3)).mul(lying.z));
204
+ });
205
+ });
206
+ return result;
207
+ })(p, height, snow);
208
+ }
209
+ /** The dusting on a marked surface, from its world position and normal, as TSL nodes. */
210
+ function snowSurfaceNode(tsl, p, height, up, snow, amount, facing = SNOW_COVER_FACING) {
211
+ const { smoothstep, vec3 } = tsl;
212
+ return {
213
+ cover: snowLineNode(tsl, p, height, snow).mul(smoothstep(facing[0], facing[1], up)).mul(SURFACE_COVER * amount),
214
+ color: vec3(...SNOW_COVER_COLOR)
215
+ };
216
+ }
217
+ //#endregion
218
+ export { createSnowCoverUniforms as a, snowCoverAmount as c, snowSurfaceNode as d, writeSnowCover as f, SNOW_COVER_PERIOD as i, snowCoverFacing as l, SNOW_COVER_FACING as n, enableSnowCover as o, writeSnowCoverValue as p, SNOW_COVER_GLSL as r, injectSnowCover as s, SNOW_COVER_COLOR as t, snowLineNode as u };
@@ -0,0 +1,67 @@
1
+ import { SnowCoverData } from "@bendyline/molen-schema";
2
+ import * as THREE from "three";
3
+ import { Node } from "three/webgpu";
4
+
5
+ //#region src/weather/snow-cover.d.ts
6
+ /** Linear albedo of lying snow: bright, a little blue, short of white so sunlit slopes keep form. */
7
+ declare const SNOW_COVER_COLOR: readonly [number, number, number];
8
+ /**
9
+ * Meters after which the snow line's wander repeats. A host passes world coordinates reduced by
10
+ * this period, which keeps float precision and survives floating-origin rebases; the terrain
11
+ * ground's own noise shares the period.
12
+ */
13
+ declare const SNOW_COVER_PERIOD = 4096;
14
+ /**
15
+ * World-normal up component across which a marked surface goes from bare to dusted, unless the
16
+ * material names its own range: walls stay clean and anything flatter than about 40 degrees is
17
+ * covered.
18
+ */
19
+ declare const SNOW_COVER_FACING: readonly [number, number];
20
+ interface SnowCoverUniforms {
21
+ /** Snow line (rendered Y), transition band in meters, amount (0 is none), unused. */
22
+ molenSnowCover: {
23
+ value: THREE.Vector4;
24
+ };
25
+ /** The renderer's world origin X and Z, wrapped to `SNOW_COVER_PERIOD`. */
26
+ molenSnowOrigin: {
27
+ value: THREE.Vector2;
28
+ };
29
+ }
30
+ /**
31
+ * Write a snow cover (or none) into a `vec4` uniform value: the line in rendered Y, which is
32
+ * world Y less the floating origin's, the transition band, and an amount of 1.
33
+ */
34
+ declare function writeSnowCoverValue(target: THREE.Vector4, cover: SnowCoverData | undefined, worldOriginY?: number): void;
35
+ /**
36
+ * GLSL for the shared snow line. `molenSnowLine(p, height, snow)` is the share of ground covered
37
+ * at world XZ `p` (reduced by the period) and rendered height, for a `snow` uniform as
38
+ * `writeSnowCoverValue` fills it. Guarded, so a ground material that includes it and also takes
39
+ * the renderer's hook defines it once.
40
+ */
41
+ declare const SNOW_COVER_GLSL: string;
42
+ /**
43
+ * How much of the weather's lying snow settles on a material: 0 unless `enableSnowCover` marked
44
+ * it (or the material it was cloned from).
45
+ */
46
+ declare function snowCoverAmount(material: THREE.Material): number;
47
+ /** The up-component range over which a material's surfaces go from bare to dusted. */
48
+ declare function snowCoverFacing(material: THREE.Material): readonly [number, number];
49
+ /**
50
+ * Let lying snow settle on a lit material: above the weather's snow line its up-facing surfaces
51
+ * whiten, on either backend, with no further calls. For roofs, ledges, crowns, props and parked
52
+ * cars; not for the ground (its materials draw their own snow), water, or anything that moves
53
+ * through the weather, such as an aircraft or a person. `amount` (0–1, default 1) thins the
54
+ * dusting: foliage holds less than a roof. `facing` is the range of the surface normal's up
55
+ * component over which it goes from bare to dusted (default `SNOW_COVER_FACING`: flat roofs
56
+ * white, walls clean); a lower range lets snow cling to steep sides, as on a conifer. A `clone()`
57
+ * stays marked, as does a `copy()` target marked again afterwards. Call it before the material
58
+ * first draws.
59
+ */
60
+ declare function enableSnowCover<T extends THREE.Material>(material: T, amount?: number, facing?: readonly [number, number]): T;
61
+ type Tsl = typeof import("three/tsl");
62
+ type F = Node<"float">;
63
+ type V2 = Node<"vec2">;
64
+ /** `molenSnowLine` as TSL nodes; `tsl` is the caller's lazily loaded `three/tsl`. */
65
+ declare function snowLineNode(tsl: Tsl, p: V2, height: F, snow: Node<"vec4">): F;
66
+ //#endregion
67
+ export { SnowCoverUniforms as a, snowCoverFacing as c, SNOW_COVER_PERIOD as i, snowLineNode as l, SNOW_COVER_FACING as n, enableSnowCover as o, SNOW_COVER_GLSL as r, snowCoverAmount as s, SNOW_COVER_COLOR as t, writeSnowCoverValue as u };
@@ -0,0 +1,2 @@
1
+ import { c as snowCoverFacing, i as SNOW_COVER_PERIOD, l as snowLineNode, n as SNOW_COVER_FACING, o as enableSnowCover, r as SNOW_COVER_GLSL, s as snowCoverAmount, t as SNOW_COVER_COLOR, u as writeSnowCoverValue } from "./snow-cover-tEG1uO98.mjs";
2
+ export { SNOW_COVER_COLOR, SNOW_COVER_FACING, SNOW_COVER_GLSL, SNOW_COVER_PERIOD, enableSnowCover, snowCoverAmount, snowCoverFacing, snowLineNode, writeSnowCoverValue };
package/dist/snow.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { c as snowCoverAmount, i as SNOW_COVER_PERIOD, l as snowCoverFacing, n as SNOW_COVER_FACING, o as enableSnowCover, p as writeSnowCoverValue, r as SNOW_COVER_GLSL, t as SNOW_COVER_COLOR, u as snowLineNode } from "./snow-cover-Bh0woabf.mjs";
2
+ export { SNOW_COVER_COLOR, SNOW_COVER_FACING, SNOW_COVER_GLSL, SNOW_COVER_PERIOD, enableSnowCover, snowCoverAmount, snowCoverFacing, snowLineNode, writeSnowCoverValue };
@@ -451,6 +451,14 @@ function aircraftObstacleContacts(probes, scene) {
451
451
  function drawGlassInOnePass(mesh) {
452
452
  for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) if (material.transparent && material.side === THREE.DoubleSide) material.forceSinglePass = true;
453
453
  }
454
+ /**
455
+ * Whether a mesh is see-through glass (every material blended at less than full opacity), which
456
+ * must not cast sun shadows: three's shadow pass draws a pane as solid, so a windscreen put its
457
+ * whole cockpit in shade. Lettering decals blend too, but at full opacity, and still cast.
458
+ */
459
+ function isGlass(mesh) {
460
+ return (Array.isArray(mesh.material) ? mesh.material : [mesh.material]).every((material) => material.transparent && material.opacity < 1);
461
+ }
454
462
  //#endregion
455
463
  //#region src/vehicle-interior.ts
456
464
  /** Vehicle convenience wrapper around the platform's model-signal binding system. */
@@ -465,4 +473,4 @@ function createVehicleInteriorVisual(model, spec) {
465
473
  };
466
474
  }
467
475
  //#endregion
468
- export { createAircraftDamageVisual as i, drawGlassInOnePass as n, aircraftObstacleContacts as r, createVehicleInteriorVisual as t };
476
+ export { createAircraftDamageVisual as a, aircraftObstacleContacts as i, drawGlassInOnePass as n, isGlass as r, createVehicleInteriorVisual as t };
@@ -0,0 +1,232 @@
1
+ import { n as ModelSignals, t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
2
+ import { AircraftCollisionProbe, AircraftContact, VehicleInteriorSpec, VehicleSpec } from "@bendyline/molen-schema";
3
+ import * as THREE from "three";
4
+ import { Object3D } from "three";
5
+
6
+ //#region src/aircraft-collision.d.ts
7
+ interface AircraftObstacleScene {
8
+ /** Collision tree origin and query, e.g. WalkCollision. */
9
+ origin: THREE.Vector3;
10
+ octree: {
11
+ sphereIntersect(sphere: THREE.Sphere): false | {
12
+ normal: THREE.Vector3;
13
+ depth: number;
14
+ };
15
+ getSphereTriangles?(sphere: THREE.Sphere, triangles: THREE.Triangle[]): unknown;
16
+ };
17
+ cars: ReadonlyArray<{
18
+ transform: {
19
+ pos: [number, number, number];
20
+ rot: [number, number, number, number];
21
+ };
22
+ spec: Pick<VehicleSpec, "width" | "height" | "length">;
23
+ }>;
24
+ /** Other aircraft body centers. The host excludes the queried aircraft. */
25
+ aircraft: ReadonlyArray<[number, number, number]>;
26
+ }
27
+ /** Contact normals from streamed geometry and nearby parked vehicles, in absolute coordinates. */
28
+ declare function aircraftObstacleContacts(probes: readonly AircraftCollisionProbe[], scene: AircraftObstacleScene): AircraftContact[];
29
+ //#endregion
30
+ //#region src/pilot-motion.d.ts
31
+ type Quat$1 = readonly [number, number, number, number];
32
+ /** One direction the seated body moves in, as a damped spring driven by the load along it. */
33
+ interface PilotMotionAxisTuning {
34
+ /** Eye travel per g of load along the axis, meters. The body moves against the load. */
35
+ travel: number;
36
+ /**
37
+ * Furthest travel in the negative and positive direction, meters, approached softly: the seat
38
+ * pan, seat back and harness. Axes are +X left, +Y up, +Z forward.
39
+ */
40
+ limit: readonly [negative: number, positive: number];
41
+ /** Natural frequency of the body on this axis, Hz: higher is tighter. */
42
+ frequency: number;
43
+ /** Damping ratio: 1 settles without overshoot, lower rebounds past rest first. */
44
+ damping: number;
45
+ /**
46
+ * Share of a sustained load the pilot braces against, 0..1. The body gives way at the onset,
47
+ * then recovers this much of the travel over `braceTime`, and is left leaning the other way
48
+ * for a moment when the load comes off.
49
+ */
50
+ brace: number;
51
+ }
52
+ /** The head on its neck: small rotations, each a damped spring. */
53
+ interface PilotMotionHeadTuning {
54
+ /** Chin drop per g above 1, radians: the head is heavy in a pull and light in a pushover. */
55
+ nod: number;
56
+ /**
57
+ * Chin drop per g of deceleration, radians: thrown forward, the head goes with the body.
58
+ * Pressed back under thrust it meets the headrest and does not tip.
59
+ */
60
+ surgeNod: number;
61
+ /** Head roll per g of sideways load, radians: toward the side the body is thrown. */
62
+ swayTilt: number;
63
+ /**
64
+ * How far the head is left behind when the airframe starts to turn, seconds squared: radians
65
+ * of lag per rad/s² of roll, pitch or yaw acceleration.
66
+ */
67
+ lag: number;
68
+ /**
69
+ * The head leveling toward the horizon in a bank, radians of tilt per radian of bank at small
70
+ * angles. It peaks at 45° of bank (half this value) and is gone at knife-edge and inverted.
71
+ */
72
+ horizonLean: number;
73
+ /** Largest rotation about any one axis, radians, approached softly. */
74
+ limit: number;
75
+ /** Height of the eyes above the neck's pivot, meters: a tilted head also moves the eye. */
76
+ neck: number;
77
+ /** Natural frequency of the head, Hz. */
78
+ frequency: number;
79
+ /** Damping ratio of the head. */
80
+ damping: number;
81
+ }
82
+ /** Every knob of {@link PilotMotion}. Defaults are {@link DEFAULT_PILOT_MOTION}. */
83
+ interface PilotMotionTuning {
84
+ /** The global switch: off, the eye stays at the authored eye point. */
85
+ enabled: boolean;
86
+ /** Scales every displacement and rotation before its limit. 1 is the tuned amount. */
87
+ intensity: number;
88
+ /** Loads beyond this many g on an axis are clipped: an impact jolts, it does not launch. */
89
+ maxLoad: number;
90
+ /** Seconds the pilot takes to brace against a sustained load (see the axes' `brace`). */
91
+ braceTime: number;
92
+ /** Vertical: sinking into the seat under positive g, rising against the straps unloaded. */
93
+ heave: PilotMotionAxisTuning;
94
+ /** Fore-aft: pressed into the seat back under thrust, thrown onto the straps by braking. */
95
+ surge: PilotMotionAxisTuning;
96
+ /** Sideways: thrown to the outside of a skid or a turn on the ground. */
97
+ sway: PilotMotionAxisTuning;
98
+ head: PilotMotionHeadTuning;
99
+ }
100
+ /** A partial {@link PilotMotionTuning}: unset fields keep their current value. */
101
+ type PilotMotionOverrides = { [K in keyof PilotMotionTuning]?: PilotMotionTuning[K] extends object ? Partial<PilotMotionTuning[K]> : PilotMotionTuning[K] };
102
+ /**
103
+ * The tuned defaults, sized to be felt more than seen. Flown through the kernel's flight model:
104
+ * a 6 g pull in the P-51 lowers the eye 3 cm, presses it over 1 cm back and drops the chin 1.5°,
105
+ * and on release the pilot comes up nearly 1 cm past rest before settling; 8.5 g in an F-16
106
+ * sinks 3.8 cm. Full brakes at 0.75 g throw the pilot nearly 3 cm forward, half of which they
107
+ * recover as they brace; full power presses them 1 cm back. A 60° bank tilts the head 3° toward
108
+ * the horizon.
109
+ */
110
+ declare const DEFAULT_PILOT_MOTION: Readonly<PilotMotionTuning>;
111
+ /** One reading of the seat the pilot is strapped to. */
112
+ interface PilotMotionSample {
113
+ /**
114
+ * Simulation time, seconds (`world.tick * world.dt`). The body moves in this time, so a paused
115
+ * simulation holds it still and asking twice in one tick gives the same pose.
116
+ */
117
+ time: number;
118
+ /** World position of the vehicle, to tell a teleport or a respawn from an acceleration. */
119
+ position: readonly [number, number, number];
120
+ /** Orientation of the vehicle: +X left, +Y up, +Z forward. */
121
+ rotation: Quat$1;
122
+ /** World velocity, m/s. */
123
+ velocity: readonly [number, number, number];
124
+ /** Factor by which `velocity` and travel are scaled up from the flown speed (boost mode). */
125
+ travelScale?: number;
126
+ }
127
+ /** Where the pilot's eyes are, relative to the authored eye point and the airframe. */
128
+ interface PilotMotionPose {
129
+ /** Eye displacement in the seat frame, meters: +X left, +Y up, +Z forward. */
130
+ offset: [number, number, number];
131
+ /** Head pitch, radians, chin up positive. */
132
+ pitch: number;
133
+ /** Head yaw, radians, to the left positive. */
134
+ yaw: number;
135
+ /** Head roll, radians, right ear down positive. */
136
+ roll: number;
137
+ }
138
+ /** A {@link PilotMotionSample} from a vehicle's transform and state. */
139
+ declare function pilotMotionSample(time: number, transform: {
140
+ pos: readonly [number, number, number];
141
+ rot: readonly [number, number, number, number];
142
+ }, state: {
143
+ velocity: readonly [number, number, number];
144
+ boosted?: boolean;
145
+ }): PilotMotionSample;
146
+ /**
147
+ * A complete tuning: `base` (the defaults when omitted) with `settings` over it. `true` and
148
+ * `false` only switch the effect; an object changes the fields it names.
149
+ */
150
+ declare function pilotMotionTuning(settings?: boolean | PilotMotionOverrides, base?: PilotMotionTuning): PilotMotionTuning;
151
+ /**
152
+ * The pilot's body in the seat. Feed it the vehicle's motion once a frame with {@link update}
153
+ * and pass the pose it returns to `aircraftCameraPose` as `motion`.
154
+ *
155
+ * What the pilot feels is the specific force in the seat frame: the vehicle's acceleration less
156
+ * gravity, 1 g straight up through the seat when parked or in level flight. The body is three
157
+ * damped springs driven by how far that is from 1 g up, and the head three more.
158
+ */
159
+ declare class PilotMotion {
160
+ /** Live tuning: change a field and the next {@link update} uses it. */
161
+ tuning: PilotMotionTuning;
162
+ /**
163
+ * The load last felt, in g, in the seat frame (+X left, +Y up, +Z forward): [0, 1, 0] parked
164
+ * or in level flight, [0, 4, 0] in a 4 g pull. For a HUD or for tuning.
165
+ */
166
+ readonly load: [number, number, number];
167
+ private readonly current;
168
+ private previous;
169
+ private readonly travel;
170
+ private readonly travelRate;
171
+ private readonly braced;
172
+ private readonly head;
173
+ private readonly headRate;
174
+ constructor(settings?: boolean | PilotMotionOverrides);
175
+ /** Change some of the tuning; `true` and `false` switch the whole effect. */
176
+ configure(settings: boolean | PilotMotionOverrides): void;
177
+ /** The pose as of the last {@link update}. */
178
+ get pose(): PilotMotionPose;
179
+ /** Forget the motion so far: for a new seat. The next sample starts settled in it. */
180
+ reset(): void;
181
+ /** Advance to `sample.time` and return where the pilot's eyes now are. */
182
+ update(sample: PilotMotionSample): PilotMotionPose;
183
+ /**
184
+ * Where the springs are heading: body travel per axis and the head's rotation vector, for a
185
+ * load `deviation` from 1 g up of which the pilot has `braced` against a share.
186
+ */
187
+ private targets;
188
+ private write;
189
+ }
190
+ //#endregion
191
+ //#region src/vehicle-camera.d.ts
192
+ interface VehicleCameraOptions {
193
+ view: "cockpit" | "chase";
194
+ lookYaw?: number;
195
+ lookPitch?: number;
196
+ /** Distance to the first static obstruction between two absolute world points. */
197
+ obstructionDistance?: (from: [number, number, number], to: [number, number, number]) => number | undefined;
198
+ /**
199
+ * Shake the seated view of an aircraft: `amount` 0–1 (its `aircraftState.buffet`) at `time`
200
+ * seconds on any steadily advancing clock. The eye moves about a centimeter and the view a
201
+ * few tenths of a degree, about ten times a second. Chase views stay steady.
202
+ */
203
+ shake?: {
204
+ amount: number;
205
+ time: number;
206
+ };
207
+ /**
208
+ * The pilot's body under load, from a `PilotMotion` (`@bendyline/molen-client/aircraft`): the
209
+ * eye moves off the authored eye point and the head turns a little with it. Aircraft cockpit
210
+ * views only; chase views stay steady.
211
+ */
212
+ motion?: PilotMotionPose;
213
+ }
214
+ interface VehicleCameraPose {
215
+ position: [number, number, number];
216
+ lookAt: [number, number, number];
217
+ yaw: number;
218
+ pitch: number;
219
+ }
220
+ /** Seat-space cockpit and collision-shortened chase views for any vehicle host. */
221
+ declare function vehicleCameraPose(transform: {
222
+ pos: [number, number, number];
223
+ rot: [number, number, number, number];
224
+ }, spec: Pick<VehicleSpec, "driverEye" | "length">, options: VehicleCameraOptions): VehicleCameraPose;
225
+ //#endregion
226
+ //#region src/vehicle-interior.d.ts
227
+ type VehicleInteriorSignals = ModelSignals;
228
+ type VehicleInteriorVisual = ModelSignalVisual;
229
+ /** Vehicle convenience wrapper around the platform's model-signal binding system. */
230
+ declare function createVehicleInteriorVisual(model: Object3D, spec: VehicleInteriorSpec): VehicleInteriorVisual;
231
+ //#endregion
232
+ export { AircraftObstacleScene as _, VehicleCameraPose as a, PilotMotion as c, PilotMotionOverrides as d, PilotMotionPose as f, pilotMotionTuning as g, pilotMotionSample as h, VehicleCameraOptions as i, PilotMotionAxisTuning as l, PilotMotionTuning as m, VehicleInteriorVisual as n, vehicleCameraPose as o, PilotMotionSample as p, createVehicleInteriorVisual as r, DEFAULT_PILOT_MOTION as s, VehicleInteriorSignals as t, PilotMotionHeadTuning as u, aircraftObstacleContacts as v };
@@ -1,9 +1,31 @@
1
- import { a as VehicleCameraPose, c as aircraftObstacleContacts, i as VehicleCameraOptions, n as VehicleInteriorVisual, o as vehicleCameraPose, r as createVehicleInteriorVisual, t as VehicleInteriorSignals } from "./vehicle-interior-B8TpzTAx.mjs";
1
+ import { a as VehicleCameraPose, i as VehicleCameraOptions, n as VehicleInteriorVisual, o as vehicleCameraPose, r as createVehicleInteriorVisual, t as VehicleInteriorSignals, v as aircraftObstacleContacts } from "./vehicle-interior-XC2tAySI.mjs";
2
2
  import { t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
3
3
  import { GlassVisual } from "./glass.mjs";
4
- import { GlassData, GlassStateData, LiveryData, VehicleCollisionPart, VehicleDamageState, VehicleData, VehiclePlacement } from "@bendyline/molen-schema";
4
+ import { GlassData, GlassStateData, LiveryData, RailVehicleProfile, VehicleCollisionPart, VehicleDamageState, VehicleData, VehiclePlacement } from "@bendyline/molen-schema";
5
5
  import * as THREE from "three";
6
6
 
7
+ //#region src/rail-proxy.d.ts
8
+ /** What a rail vehicle stand-in is built from (a rail `VehicleSpec` satisfies it). */
9
+ interface RailVehicleProxyDimensions {
10
+ width: number;
11
+ length: number;
12
+ height: number;
13
+ wheelRadius: number;
14
+ rail?: {
15
+ truckCenters: number;
16
+ profile?: RailVehicleProfile;
17
+ };
18
+ }
19
+ /**
20
+ * Low-detail stand-in for a rail vehicle seen from a distance: a parked cut of cars in a yard, or
21
+ * far traffic. One silhouette per `rail.profile` (boxcar, covered hopper, tank car, gondola,
22
+ * flatcar with a load, double-stack well car, autorack, road locomotive, bilevel coach, light-rail
23
+ * car) over two dark trucks. Front +Z, +X the left side, y = 0 the top of rail. The painted faces
24
+ * come first (`userData.bodyVertices`) so a batch tints the body and never the running gear.
25
+ * A few dozen triangles, one material, no textures. Never dispose the cached result.
26
+ */
27
+ declare function railVehicleProxyGeometry(spec: RailVehicleProxyDimensions): THREE.BufferGeometry;
28
+ //#endregion
7
29
  //#region src/vehicle-proxy.d.ts
8
30
  /** The dimensions a vehicle proxy is built from (a `VehicleSpec` satisfies it). */
9
31
  interface VehicleProxyDimensions {
@@ -15,6 +37,18 @@ interface VehicleProxyDimensions {
15
37
  wheelRadius: number;
16
38
  }
17
39
  /**
40
+ * Street-distance silhouette of a parked motorcycle, scooter or moped: two tyres in line, a
41
+ * painted body and front shield, seat and bars. About 110 triangles, one material, painted faces
42
+ * first. Never dispose the cached result.
43
+ */
44
+ declare function twoWheelerProxyGeometry(spec: VehicleProxyDimensions): THREE.BufferGeometry;
45
+ /**
46
+ * Street-distance silhouette of a parked auto-rickshaw: a body tapering to the nose under a
47
+ * canvas canopy on four posts, a windscreen, one front and two rear tyres. About 170 triangles,
48
+ * one material, painted faces first. Never dispose the cached result.
49
+ */
50
+ declare function threeWheelerProxyGeometry(spec: VehicleProxyDimensions): THREE.BufferGeometry;
51
+ /**
18
52
  * Shared street-distance silhouette for parked cars and instanced traffic. Painted faces come
19
53
  * first so a static batch can tint the body and roof without tinting the glass, tyres or lamps.
20
54
  * 148 triangles, one material, no textures or model downloads. Never dispose the cached result.
@@ -57,6 +91,12 @@ declare const vehicleProxyMaterial: THREE.MeshStandardMaterial;
57
91
  * hide and restore a car with `setParkedVehicleHidden`.
58
92
  */
59
93
  declare function createParkedVehicleBatch(placements: readonly VehiclePlacement[], origin?: [number, number]): THREE.Group;
94
+ /**
95
+ * Dormant cars as one instanced mesh per body size, for a car park of hundreds where a merged
96
+ * batch would cost more than the building. Each mesh keeps the batch's `vehicleIds` contract:
97
+ * instance `i` belongs to `userData.vehicleIds[i]`, and `setParkedVehicleHidden` hides it.
98
+ */
99
+ declare function createParkedVehicleInstances(placements: readonly VehiclePlacement[], origin?: [number, number]): THREE.Group;
60
100
  /** Whether `setParkedVehicleHidden` currently hides car `index` of a parked batch. */
61
101
  declare function isParkedVehicleHidden(batch: THREE.Mesh, index: number): boolean;
62
102
  /**
@@ -65,4 +105,4 @@ declare function isParkedVehicleHidden(batch: THREE.Mesh, index: number): boolea
65
105
  */
66
106
  declare function setParkedVehicleHidden(batch: THREE.Mesh, index: number, hidden: boolean): boolean;
67
107
  //#endregion
68
- export { type VehicleCameraOptions, type VehicleCameraPose, type VehicleInteriorSignals, type VehicleInteriorVisual, type VehicleProxyDimensions, VehicleVisual, createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose, aircraftObstacleContacts as vehicleObstacleContacts, vehicleProxyGeometry, vehicleProxyMaterial };
108
+ export { type RailVehicleProxyDimensions, type VehicleCameraOptions, type VehicleCameraPose, type VehicleInteriorSignals, type VehicleInteriorVisual, type VehicleProxyDimensions, VehicleVisual, createParkedVehicleBatch, createParkedVehicleInstances, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, railVehicleProxyGeometry, setParkedVehicleHidden, threeWheelerProxyGeometry, twoWheelerProxyGeometry, vehicleCameraPose, aircraftObstacleContacts as vehicleObstacleContacts, vehicleProxyGeometry, vehicleProxyMaterial };