@bendyline/molen-client 0.0.11 → 0.0.12
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/README.md +1 -0
- package/dist/aircraft.d.mts +3 -27
- package/dist/aircraft.mjs +229 -215
- package/dist/audio.d.mts +10 -1
- package/dist/audio.mjs +131 -6
- package/dist/camera-track.d.mts +1 -1
- package/dist/clouds-DmASLVoe.mjs +862 -0
- package/dist/glass.d.mts +19 -0
- package/dist/glass.mjs +249 -0
- package/dist/index.d.mts +14 -3
- package/dist/index.mjs +577 -147
- package/dist/{livery-C0abgthY.mjs → livery-qcDLzbU9.mjs} +7 -2
- package/dist/navigation.d.mts +19 -6
- package/dist/navigation.mjs +133 -83
- package/dist/{renderer-Dzus24ZF.d.mts → renderer-DAk7C8jH.d.mts} +234 -17
- package/dist/vehicle-interior-B8TpzTAx.d.mts +56 -0
- package/dist/vehicle-interior-CeyzF5El.mjs +455 -0
- package/dist/vehicles.d.mts +25 -20
- package/dist/vehicles.mjs +270 -66
- package/dist/webgpu-clouds-H03g7ID1.mjs +186 -0
- package/package.json +7 -3
- package/dist/vehicle-interior-BgcC750p.d.mts +0 -31
- package/dist/vehicle-interior-DfpZwWEh.mjs +0 -15
package/README.md
CHANGED
|
@@ -66,6 +66,7 @@ probe — a pinned backend is what makes a captured frame reproducible.
|
|
|
66
66
|
| `./camera-track` | `molen/cameratrack@1`: `registerCameraTrackSchema` + `evaluateCameraTrack` for scripted camera moves |
|
|
67
67
|
| `./vite` | `molenScripts()` — a Vite plugin that type-strips `*.ts?raw` scene scripts so the browser never sees TypeScript |
|
|
68
68
|
| `./vehicles` | `createVehicleVisual`, `createParkedVehicleBatch`, `vehicleCameraPose` — car visuals and cockpit/chase views, the render half of `@bendyline/molen-kernel/vehicles` |
|
|
69
|
+
| `./glass` | `createGlassVisual` — retained laminate cracks, released sheets and bounded glass fragments |
|
|
69
70
|
| `./aircraft` | `createAircraftVisual`, `aircraftCameraPose` — animated airframe and instrumented cockpit, the render half of `@bendyline/molen-kernel/aircraft` |
|
|
70
71
|
| `./instruments` | Named signal expressions and reusable wiring for calibrated dials, altimeters, attitude indicators, annunciators and seven-segment readouts; geometry stays in each model |
|
|
71
72
|
| `./navigation` | `OrbitController`, `FlyController`, `WalkController` + `WalkCollision`, `FollowController`, `NavigationInputSource` (keys, gamepad, pointer gestures) and `createTouchJoystick` — camera navigation for `createViewer` hosts |
|
package/dist/aircraft.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { a as VehicleCameraPose, c as aircraftObstacleContacts, i as VehicleCameraOptions, n as VehicleInteriorVisual, s as AircraftObstacleScene } from "./vehicle-interior-B8TpzTAx.mjs";
|
|
1
2
|
import { n as ModelSignals, t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { AircraftCollisionProbe, AircraftContact, AircraftInputData, AircraftSpec, AircraftStateData, LiveryData, VehicleSpec } from "@bendyline/molen-schema";
|
|
3
|
+
import { AircraftInputData, AircraftSpec, AircraftStateData, LiveryData } from "@bendyline/molen-schema";
|
|
4
4
|
import * as THREE from "three";
|
|
5
5
|
|
|
6
6
|
//#region src/aircraft-controls.d.ts
|
|
7
|
-
type AircraftControlAction = "power" | "mixture" | "propeller" | "stick" | "yaw" | "gear" | "flaps" | "engine" | "brake" | "thrustVector";
|
|
7
|
+
type AircraftControlAction = "speedBrake" | "tailHook" | "canopy" | "wipers" | "headlights" | "power" | "mixture" | "propeller" | "stick" | "yaw" | "gear" | "flaps" | "engine" | "brake" | "thrustVector";
|
|
8
8
|
interface AircraftCockpitControl {
|
|
9
9
|
id: string;
|
|
10
10
|
label: string;
|
|
@@ -79,30 +79,6 @@ interface AircraftCockpitPointerOptions {
|
|
|
79
79
|
}
|
|
80
80
|
declare function bindAircraftCockpitPointer(options: AircraftCockpitPointerOptions): AircraftCockpitPointer;
|
|
81
81
|
//#endregion
|
|
82
|
-
//#region src/aircraft-collision.d.ts
|
|
83
|
-
interface AircraftObstacleScene {
|
|
84
|
-
/** Collision tree origin and query, e.g. WalkCollision. */
|
|
85
|
-
origin: THREE.Vector3;
|
|
86
|
-
octree: {
|
|
87
|
-
sphereIntersect(sphere: THREE.Sphere): false | {
|
|
88
|
-
normal: THREE.Vector3;
|
|
89
|
-
depth: number;
|
|
90
|
-
};
|
|
91
|
-
getSphereTriangles?(sphere: THREE.Sphere, triangles: THREE.Triangle[]): unknown;
|
|
92
|
-
};
|
|
93
|
-
cars: ReadonlyArray<{
|
|
94
|
-
transform: {
|
|
95
|
-
pos: [number, number, number];
|
|
96
|
-
rot: [number, number, number, number];
|
|
97
|
-
};
|
|
98
|
-
spec: VehicleSpec;
|
|
99
|
-
}>;
|
|
100
|
-
/** Other aircraft body centers. The host excludes the queried aircraft. */
|
|
101
|
-
aircraft: ReadonlyArray<[number, number, number]>;
|
|
102
|
-
}
|
|
103
|
-
/** Contact normals from streamed geometry and nearby parked vehicles, in absolute coordinates. */
|
|
104
|
-
declare function aircraftObstacleContacts(probes: readonly AircraftCollisionProbe[], scene: AircraftObstacleScene): AircraftContact[];
|
|
105
|
-
//#endregion
|
|
106
82
|
//#region src/aircraft.d.ts
|
|
107
83
|
interface AircraftVisual {
|
|
108
84
|
setLivery(data: LiveryData | undefined): void;
|
package/dist/aircraft.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
2
|
-
import { t as applyLivery } from "./livery-
|
|
3
|
-
import { t as createVehicleInteriorVisual } from "./vehicle-interior-
|
|
2
|
+
import { t as applyLivery } from "./livery-qcDLzbU9.mjs";
|
|
3
|
+
import { n as aircraftObstacleContacts, r as createAircraftDamageVisual, t as createVehicleInteriorVisual } from "./vehicle-interior-CeyzF5El.mjs";
|
|
4
4
|
import * as THREE from "three";
|
|
5
5
|
//#region src/aircraft-controls.ts
|
|
6
6
|
/** Discover moving controls from their authored input bindings, never from instrument needles. */
|
|
@@ -54,7 +54,14 @@ function createAircraftCockpit(model, spec) {
|
|
|
54
54
|
else for (const engine of supported) add(action, `Engine ${engines.findIndex((e) => e.id === engine.id) + 1} ${label.toLowerCase()}`, bound(`engines.${engine.id}.${action}`, /mixture|prop|condition/i), engine.id);
|
|
55
55
|
}
|
|
56
56
|
if (engines.length > 1) for (const [index, engine] of engines.entries()) add("engine", `Engine ${index + 1}`, [], engine.id);
|
|
57
|
-
|
|
57
|
+
for (const [action, label] of [
|
|
58
|
+
["speedBrake", "Speed brake"],
|
|
59
|
+
["tailHook", "Tail hook"],
|
|
60
|
+
["canopy", "Canopy"],
|
|
61
|
+
["wipers", "Wipers"],
|
|
62
|
+
["headlights", "Lights"]
|
|
63
|
+
]) if (spec.actuators?.[action]) add(action, label, []);
|
|
64
|
+
if (spec.model === "airplane" && !spec.airplane?.fixedGear || spec.helicopter?.fixedGear === false) add("gear", "Landing gear", [...bound("gear", /handle|lever|selector/i), ...bound("gearPosition", /handle|lever|selector/i)]);
|
|
58
65
|
if (spec.model === "airplane" && (spec.airplane?.flapLift ?? 0) > 0) add("flaps", "Flaps", bound("flapPosition", /flap.*(?:handle|lever|selector|pump)|(?:lever|handle).*flap|Skylane-flap|ATR72-power-lever-4/i));
|
|
59
66
|
if (spec.model === "airplane") add("brake", "Parking brake", []);
|
|
60
67
|
if (spec.poweredLift) add("thrustVector", "Nozzle / nacelle angle", bound("thrustVector", /lever|thumb/i));
|
|
@@ -110,6 +117,13 @@ function createAircraftCockpit(model, spec) {
|
|
|
110
117
|
};
|
|
111
118
|
}
|
|
112
119
|
function aircraftControlValue(input, control) {
|
|
120
|
+
if ([
|
|
121
|
+
"speedBrake",
|
|
122
|
+
"tailHook",
|
|
123
|
+
"canopy",
|
|
124
|
+
"wipers",
|
|
125
|
+
"headlights"
|
|
126
|
+
].includes(control.action)) return Number(input.actuators?.[control.action] ?? 0);
|
|
113
127
|
if (control.action === "stick") return input.roll;
|
|
114
128
|
if (control.action === "power") return control.engine ? input.engines?.[control.engine]?.power ?? input.power : input.power;
|
|
115
129
|
if (control.action === "mixture" || control.action === "propeller") return (control.engine ? input.engines?.[control.engine]?.[control.action] : void 0) ?? input[control.action] ?? 1;
|
|
@@ -127,6 +141,19 @@ function applyAircraftControl(input, change, spec, state) {
|
|
|
127
141
|
if (control.engine && !bank.some((engine) => engine.id === control.engine)) return input;
|
|
128
142
|
const clamp = (v, low = 0) => Math.max(low, Math.min(1, v));
|
|
129
143
|
const next = { ...input };
|
|
144
|
+
if ([
|
|
145
|
+
"speedBrake",
|
|
146
|
+
"tailHook",
|
|
147
|
+
"canopy",
|
|
148
|
+
"wipers",
|
|
149
|
+
"headlights"
|
|
150
|
+
].includes(control.action)) return spec.actuators?.[control.action] ? {
|
|
151
|
+
...next,
|
|
152
|
+
actuators: {
|
|
153
|
+
...input.actuators,
|
|
154
|
+
[control.action]: clamp(value)
|
|
155
|
+
}
|
|
156
|
+
} : input;
|
|
130
157
|
switch (control.action) {
|
|
131
158
|
case "stick":
|
|
132
159
|
next.roll = clamp(value, -1);
|
|
@@ -177,7 +204,7 @@ function applyAircraftControl(input, change, spec, state) {
|
|
|
177
204
|
else next.engine = value > 0;
|
|
178
205
|
break;
|
|
179
206
|
case "gear":
|
|
180
|
-
if (spec.model
|
|
207
|
+
if ((spec.model === "airplane" ? spec.airplane?.fixedGear : spec.helicopter?.fixedGear !== false) || !state || state.grounded) return input;
|
|
181
208
|
next.gear = value > 0;
|
|
182
209
|
break;
|
|
183
210
|
case "flaps":
|
|
@@ -211,145 +238,205 @@ var AircraftPointerAxes = class {
|
|
|
211
238
|
}
|
|
212
239
|
};
|
|
213
240
|
//#endregion
|
|
214
|
-
//#region src/aircraft-
|
|
215
|
-
function
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
const shared = [];
|
|
232
|
-
const fragments = [];
|
|
233
|
-
model.traverse((node) => {
|
|
234
|
-
if (node instanceof THREE.Mesh && sections.some(({ part }) => part.fragments?.nodes.includes(node.userData.name ?? node.name))) shared.push(node);
|
|
235
|
-
});
|
|
236
|
-
const vertex = new THREE.Vector3(), centroid = new THREE.Vector3();
|
|
237
|
-
for (const mesh of shared) {
|
|
238
|
-
const matching = sections.filter(({ part }) => part.fragments?.nodes.includes(mesh.userData.name ?? mesh.name));
|
|
239
|
-
const matrix = new THREE.Matrix4().multiplyMatrices(modelInverse, mesh.matrixWorld);
|
|
240
|
-
const source = mesh.geometry, positions = source.getAttribute("position");
|
|
241
|
-
const count = source.index?.count ?? positions.count;
|
|
242
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
243
|
-
for (let i = 0; i < count; i += 3) {
|
|
244
|
-
centroid.set(0, 0, 0);
|
|
245
|
-
const indices = [
|
|
246
|
-
0,
|
|
247
|
-
1,
|
|
248
|
-
2
|
|
249
|
-
].map((j) => source.index?.getX(i + j) ?? i + j);
|
|
250
|
-
for (const index of indices) centroid.add(vertex.fromBufferAttribute(positions, index));
|
|
251
|
-
centroid.multiplyScalar(1 / 3).applyMatrix4(matrix);
|
|
252
|
-
const key = matching.find(({ part }) => {
|
|
253
|
-
const bounds = part.fragments;
|
|
254
|
-
return bounds && centroid.x >= bounds.min[0] && centroid.x <= bounds.max[0] && centroid.y >= bounds.min[1] && centroid.y <= bounds.max[1] && centroid.z >= bounds.min[2] && centroid.z <= bounds.max[2];
|
|
255
|
-
})?.part.id ?? "";
|
|
256
|
-
let bucket = buckets.get(key);
|
|
257
|
-
if (!bucket) {
|
|
258
|
-
bucket = {
|
|
259
|
-
indices: [],
|
|
260
|
-
groups: []
|
|
261
|
-
};
|
|
262
|
-
buckets.set(key, bucket);
|
|
263
|
-
}
|
|
264
|
-
const materialIndex = source.groups.find((group) => i >= group.start && i < group.start + group.count)?.materialIndex ?? 0;
|
|
265
|
-
const last = bucket.groups.at(-1);
|
|
266
|
-
if (last?.materialIndex === materialIndex) last.count += 3;
|
|
267
|
-
else bucket.groups.push({
|
|
268
|
-
start: bucket.indices.length,
|
|
269
|
-
count: 3,
|
|
270
|
-
materialIndex
|
|
271
|
-
});
|
|
272
|
-
bucket.indices.push(...indices);
|
|
273
|
-
}
|
|
274
|
-
for (const [key, bucket] of buckets) {
|
|
275
|
-
const fragment = mesh.clone(false);
|
|
276
|
-
fragment.name = `section:${key || "body"}:${mesh.name}`;
|
|
277
|
-
fragment.geometry = source.clone();
|
|
278
|
-
fragment.geometry.setIndex(bucket.indices);
|
|
279
|
-
fragment.geometry.clearGroups();
|
|
280
|
-
for (const group of bucket.groups) fragment.geometry.addGroup(group.start, group.count, group.materialIndex);
|
|
281
|
-
mesh.parent?.add(fragment);
|
|
282
|
-
fragments.push({
|
|
283
|
-
source: mesh,
|
|
284
|
-
fragment
|
|
241
|
+
//#region src/aircraft-propellers.ts
|
|
242
|
+
function createAircraftPropellers(model, spec) {
|
|
243
|
+
const propellers = [];
|
|
244
|
+
const engines = spec.engines ?? (spec.engine ? [{
|
|
245
|
+
...spec.engine,
|
|
246
|
+
id: "main"
|
|
247
|
+
}] : []);
|
|
248
|
+
if (spec.model === "airplane") {
|
|
249
|
+
model.updateWorldMatrix(true, true);
|
|
250
|
+
for (const binding of spec.visual.rotors) {
|
|
251
|
+
const engine = binding.engine === void 0 ? engines[0] : engines.find((e) => e.id === binding.engine);
|
|
252
|
+
if (!engine || engine.propulsion === "jet") continue;
|
|
253
|
+
const nodes = [];
|
|
254
|
+
model.traverse((node) => {
|
|
255
|
+
if (node.name === binding.node) nodes.push(node);
|
|
285
256
|
});
|
|
286
|
-
|
|
257
|
+
for (const node of nodes) {
|
|
258
|
+
if (ancestors(node).some((parent) => nodes.includes(parent))) continue;
|
|
259
|
+
const axis = binding.axis;
|
|
260
|
+
const u = axis === "x" ? "y" : "x";
|
|
261
|
+
const v = axis === "z" ? "y" : "z";
|
|
262
|
+
const inverse = node.matrixWorld.clone().invert();
|
|
263
|
+
const sources = [];
|
|
264
|
+
const markings = [];
|
|
265
|
+
let radius = 0;
|
|
266
|
+
node.traverse((mesh) => {
|
|
267
|
+
if (!(mesh instanceof THREE.Mesh)) return;
|
|
268
|
+
if (mesh.userData.liveryMarking) {
|
|
269
|
+
markings.push(mesh);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const transform = inverse.clone().multiply(mesh.matrixWorld);
|
|
273
|
+
const geometry = mesh.geometry;
|
|
274
|
+
const position = geometry.getAttribute("position");
|
|
275
|
+
if (!position) return;
|
|
276
|
+
const materials = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
|
|
277
|
+
const count = geometry.index?.count ?? position.count;
|
|
278
|
+
const groups = Array.isArray(mesh.material) ? geometry.groups : [{
|
|
279
|
+
start: 0,
|
|
280
|
+
count,
|
|
281
|
+
materialIndex: 0
|
|
282
|
+
}];
|
|
283
|
+
const bands = [];
|
|
284
|
+
for (const group of groups) {
|
|
285
|
+
const material = materials[group.materialIndex ?? 0];
|
|
286
|
+
if (!material?.visible || material.opacity <= 0) continue;
|
|
287
|
+
let inner = Infinity, outer = 0, area = 0, depth = 0, vertices = 0;
|
|
288
|
+
const points = [
|
|
289
|
+
new THREE.Vector3(),
|
|
290
|
+
new THREE.Vector3(),
|
|
291
|
+
new THREE.Vector3()
|
|
292
|
+
];
|
|
293
|
+
for (let i = group.start; i + 2 < Math.min(count, group.start + group.count); i += 3) {
|
|
294
|
+
for (const [j, p] of points.entries()) {
|
|
295
|
+
p.fromBufferAttribute(position, geometry.index?.getX(i + j) ?? i + j);
|
|
296
|
+
p.applyMatrix4(transform);
|
|
297
|
+
const r = Math.hypot(p[u], p[v]);
|
|
298
|
+
inner = Math.min(inner, r);
|
|
299
|
+
outer = Math.max(outer, r);
|
|
300
|
+
depth += p[axis];
|
|
301
|
+
vertices++;
|
|
302
|
+
}
|
|
303
|
+
const [a, b, c] = points;
|
|
304
|
+
area += Math.abs((b[u] - a[u]) * (c[v] - a[v]) - (b[v] - a[v]) * (c[u] - a[u])) / 4;
|
|
305
|
+
}
|
|
306
|
+
if (outer <= inner || !area) continue;
|
|
307
|
+
const color = material.color?.clone() ?? new THREE.Color(5592405);
|
|
308
|
+
bands.push({
|
|
309
|
+
inner,
|
|
310
|
+
outer,
|
|
311
|
+
area: area * material.opacity,
|
|
312
|
+
color,
|
|
313
|
+
depth: depth / vertices
|
|
314
|
+
});
|
|
315
|
+
radius = Math.max(radius, outer);
|
|
316
|
+
}
|
|
317
|
+
sources.push({
|
|
318
|
+
mesh,
|
|
319
|
+
bands
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
if (radius <= 0) continue;
|
|
323
|
+
const blades = sources.filter(({ bands }) => bands.some((b) => b.outer > radius * .35));
|
|
324
|
+
const bands = blades.flatMap((b) => b.bands);
|
|
325
|
+
if (!bands.length) continue;
|
|
326
|
+
for (const mesh of markings) if (ancestors(mesh).some((parent) => blades.some((blade) => blade.mesh === parent))) blades.push({
|
|
327
|
+
mesh,
|
|
328
|
+
bands: []
|
|
329
|
+
});
|
|
330
|
+
const disk = blurDisk(bands, radius, axis);
|
|
331
|
+
disk.name = `propeller-blur:${binding.node}`;
|
|
332
|
+
disk.userData.walkIgnore = true;
|
|
333
|
+
disk.userData.vehicleGeometry = true;
|
|
334
|
+
disk.raycast = () => {};
|
|
335
|
+
disk.visible = false;
|
|
336
|
+
node.add(disk);
|
|
337
|
+
const parents = [node, ...ancestors(node)];
|
|
338
|
+
propellers.push({
|
|
339
|
+
engine: engine.id,
|
|
340
|
+
speed: Math.abs(engine.rotorAngularSpeed * binding.multiplier),
|
|
341
|
+
parts: (spec.collisionParts ?? []).filter((part) => parents.some((p) => part.nodes.includes(p.userData.name ?? p.name))).map((part) => part.id),
|
|
342
|
+
disk,
|
|
343
|
+
blades: blades.map(({ mesh }) => {
|
|
344
|
+
const original = mesh.material;
|
|
345
|
+
return {
|
|
346
|
+
mesh,
|
|
347
|
+
original,
|
|
348
|
+
faded: (Array.isArray(original) ? original : [original]).map((m) => {
|
|
349
|
+
const clone = m.clone();
|
|
350
|
+
clone.transparent = true;
|
|
351
|
+
clone.depthWrite = false;
|
|
352
|
+
return clone;
|
|
353
|
+
}),
|
|
354
|
+
shadow: mesh.castShadow
|
|
355
|
+
};
|
|
356
|
+
})
|
|
357
|
+
});
|
|
358
|
+
}
|
|
287
359
|
}
|
|
288
|
-
mesh.visible = false;
|
|
289
360
|
}
|
|
290
|
-
const hidden = /* @__PURE__ */ new Map();
|
|
291
|
-
const pieces = /* @__PURE__ */ new Map();
|
|
292
|
-
const inverse = new THREE.Matrix4();
|
|
293
|
-
const pose = new THREE.Matrix4();
|
|
294
|
-
const position = new THREE.Vector3();
|
|
295
|
-
const rotation = new THREE.Quaternion();
|
|
296
|
-
const unit = new THREE.Vector3(1, 1, 1);
|
|
297
|
-
const reset = () => {
|
|
298
|
-
for (const [node, visible] of hidden) node.visible = visible;
|
|
299
|
-
hidden.clear();
|
|
300
|
-
for (const { source, fragment } of fragments) fragment.material = source.material;
|
|
301
|
-
for (const piece of pieces.values()) piece.removeFromParent();
|
|
302
|
-
pieces.clear();
|
|
303
|
-
};
|
|
304
361
|
return {
|
|
305
|
-
reset,
|
|
306
362
|
update(state) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
let group = pieces.get(part.id);
|
|
319
|
-
if (!debris && group) {
|
|
320
|
-
group.removeFromParent();
|
|
321
|
-
pieces.delete(part.id);
|
|
322
|
-
group = void 0;
|
|
323
|
-
}
|
|
324
|
-
if (debris && !group) {
|
|
325
|
-
group = new THREE.Group();
|
|
326
|
-
group.name = `debris:${part.id}`;
|
|
327
|
-
const local = new THREE.Matrix4().copy(model.matrixWorld).invert();
|
|
328
|
-
const offset = new THREE.Matrix4().makeTranslation(-part.center[0], -part.center[1], -part.center[2]);
|
|
329
|
-
for (const node of nodes) {
|
|
330
|
-
const clone = node.clone(true);
|
|
331
|
-
clone.matrixAutoUpdate = false;
|
|
332
|
-
clone.matrix.copy(offset).multiply(local).multiply(node.matrixWorld);
|
|
333
|
-
clone.visible = hidden.get(node) ?? node.visible;
|
|
334
|
-
group.add(clone);
|
|
363
|
+
for (const prop of propellers) {
|
|
364
|
+
const rpm = (prop.engine === void 0 ? void 0 : state.engines?.[prop.engine])?.rpm ?? state.rpm;
|
|
365
|
+
const blend = prop.parts.some((part) => state.damage?.[part]?.detached) || !Number.isFinite(rpm) ? 0 : THREE.MathUtils.smoothstep(Math.abs(rpm * prop.speed), 20, 60);
|
|
366
|
+
prop.disk.visible = blend > 0;
|
|
367
|
+
prop.disk.material.opacity = blend;
|
|
368
|
+
for (const { mesh, original, faded, shadow } of prop.blades) {
|
|
369
|
+
const originals = Array.isArray(original) ? original : [original];
|
|
370
|
+
for (const [i, material] of faded.entries()) {
|
|
371
|
+
const source = originals[i];
|
|
372
|
+
material.opacity = source.opacity * (1 - blend);
|
|
373
|
+
material.visible = source.visible && blend < 1;
|
|
335
374
|
}
|
|
336
|
-
|
|
337
|
-
|
|
375
|
+
mesh.material = blend === 0 ? original : Array.isArray(original) ? faded : faded[0];
|
|
376
|
+
mesh.castShadow = shadow && blend === 0;
|
|
338
377
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
node.visible = false;
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
dispose() {
|
|
381
|
+
for (const prop of propellers) {
|
|
382
|
+
for (const { mesh, original, faded, shadow } of prop.blades) {
|
|
383
|
+
mesh.material = original;
|
|
384
|
+
mesh.castShadow = shadow;
|
|
385
|
+
for (const material of faded) material.dispose();
|
|
348
386
|
}
|
|
387
|
+
prop.disk.removeFromParent();
|
|
388
|
+
prop.disk.geometry.dispose();
|
|
389
|
+
prop.disk.material.dispose();
|
|
349
390
|
}
|
|
391
|
+
propellers.length = 0;
|
|
350
392
|
}
|
|
351
393
|
};
|
|
352
394
|
}
|
|
395
|
+
function ancestors(node) {
|
|
396
|
+
const parents = [];
|
|
397
|
+
for (let parent = node.parent; parent; parent = parent.parent) parents.push(parent);
|
|
398
|
+
return parents;
|
|
399
|
+
}
|
|
400
|
+
function blurDisk(bands, radius, axis) {
|
|
401
|
+
const rings = 48, segments = 64;
|
|
402
|
+
const geometry = new THREE.RingGeometry(0, radius, segments, rings);
|
|
403
|
+
const position = geometry.getAttribute("position");
|
|
404
|
+
const colors = new Float32Array(position.count * 4);
|
|
405
|
+
const totalArea = bands.reduce((sum, b) => sum + b.area, 0);
|
|
406
|
+
const depth = bands.reduce((sum, b) => sum + b.depth * b.area, 0) / totalArea;
|
|
407
|
+
for (let ring = 0; ring <= rings; ring++) {
|
|
408
|
+
const r = ring / rings * radius;
|
|
409
|
+
const color = new THREE.Color(0, 0, 0);
|
|
410
|
+
let alpha = 0;
|
|
411
|
+
for (const band of bands) {
|
|
412
|
+
const feather = Math.min(radius / rings, (band.outer - band.inner) / 2);
|
|
413
|
+
const coverage = band.area / (Math.PI * (band.outer ** 2 - band.inner ** 2)) * THREE.MathUtils.smoothstep(r, band.inner, band.inner + feather) * (1 - THREE.MathUtils.smoothstep(r, band.outer - feather, band.outer));
|
|
414
|
+
color.add(band.color.clone().multiplyScalar(coverage));
|
|
415
|
+
alpha += coverage;
|
|
416
|
+
}
|
|
417
|
+
if (alpha > 0) color.multiplyScalar(1 / alpha);
|
|
418
|
+
for (let segment = 0; segment <= segments; segment++) {
|
|
419
|
+
const i = ring * 65 + segment;
|
|
420
|
+
colors.set([
|
|
421
|
+
color.r,
|
|
422
|
+
color.g,
|
|
423
|
+
color.b,
|
|
424
|
+
Math.min(.45, alpha)
|
|
425
|
+
], i * 4);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 4));
|
|
429
|
+
if (axis === "x") geometry.rotateY(Math.PI / 2);
|
|
430
|
+
else if (axis === "y") geometry.rotateX(-Math.PI / 2);
|
|
431
|
+
geometry.translate(axis === "x" ? depth : 0, axis === "y" ? depth : 0, axis === "z" ? depth : 0);
|
|
432
|
+
return new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({
|
|
433
|
+
vertexColors: true,
|
|
434
|
+
transparent: true,
|
|
435
|
+
depthWrite: false,
|
|
436
|
+
side: THREE.DoubleSide,
|
|
437
|
+
forceSinglePass: true
|
|
438
|
+
}));
|
|
439
|
+
}
|
|
353
440
|
//#endregion
|
|
354
441
|
//#region src/aircraft-cockpit-pointer.ts
|
|
355
442
|
function bindAircraftCockpitPointer(options) {
|
|
@@ -587,89 +674,6 @@ function bindActiveCockpitPointer(options) {
|
|
|
587
674
|
};
|
|
588
675
|
}
|
|
589
676
|
//#endregion
|
|
590
|
-
//#region src/aircraft-collision.ts
|
|
591
|
-
/** Contact normals from streamed geometry and nearby parked vehicles, in absolute coordinates. */
|
|
592
|
-
function aircraftObstacleContacts(probes, scene) {
|
|
593
|
-
const contacts = [];
|
|
594
|
-
for (const probe of probes) {
|
|
595
|
-
const point = probe.center;
|
|
596
|
-
const hit = (normal, depth) => {
|
|
597
|
-
contacts.push({
|
|
598
|
-
part: probe.part,
|
|
599
|
-
point: new THREE.Vector3().fromArray(point).addScaledVector(normal, -probe.radius).toArray(),
|
|
600
|
-
normal: normal.toArray(),
|
|
601
|
-
depth
|
|
602
|
-
});
|
|
603
|
-
};
|
|
604
|
-
const sphere = new THREE.Sphere(new THREE.Vector3().fromArray(point).sub(scene.origin), probe.radius);
|
|
605
|
-
if (scene.octree.getSphereTriangles) {
|
|
606
|
-
const triangles = [];
|
|
607
|
-
scene.octree.getSphereTriangles(sphere, triangles);
|
|
608
|
-
const faceNormal = new THREE.Vector3(), nearest = new THREE.Vector3();
|
|
609
|
-
const faces = [];
|
|
610
|
-
for (const triangle of triangles) {
|
|
611
|
-
triangle.getNormal(faceNormal);
|
|
612
|
-
if (faceNormal.dot(sphere.center.clone().sub(triangle.a)) < -1e-7) continue;
|
|
613
|
-
triangle.closestPointToPoint(sphere.center, nearest);
|
|
614
|
-
const offset = sphere.center.clone().sub(nearest);
|
|
615
|
-
const distance = offset.length();
|
|
616
|
-
if (distance >= probe.radius) continue;
|
|
617
|
-
const normal = distance > 1e-7 ? offset.multiplyScalar(1 / distance) : faceNormal.clone();
|
|
618
|
-
const depth = probe.radius - distance;
|
|
619
|
-
const same = faces.find((face) => face.normal.dot(normal) > .9999);
|
|
620
|
-
if (same) same.depth = Math.max(same.depth, depth);
|
|
621
|
-
else faces.push({
|
|
622
|
-
normal,
|
|
623
|
-
depth
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
faces.sort((a, b) => b.depth - a.depth || a.normal.x - b.normal.x || a.normal.y - b.normal.y || a.normal.z - b.normal.z);
|
|
627
|
-
const nearestFace = faces[0];
|
|
628
|
-
if (nearestFace) hit(nearestFace.normal, nearestFace.depth);
|
|
629
|
-
} else {
|
|
630
|
-
const obstacle = scene.octree.sphereIntersect(sphere);
|
|
631
|
-
if (obstacle) hit(obstacle.normal, obstacle.depth);
|
|
632
|
-
}
|
|
633
|
-
for (const { transform, spec } of scene.cars) {
|
|
634
|
-
if (Math.hypot(transform.pos[0] - point[0], transform.pos[2] - point[2]) > Math.max(spec.width, spec.length) + probe.radius) continue;
|
|
635
|
-
const orientation = new THREE.Quaternion().fromArray(transform.rot);
|
|
636
|
-
const local = new THREE.Vector3().fromArray(point).sub(new THREE.Vector3().fromArray(transform.pos)).applyQuaternion(orientation.clone().invert());
|
|
637
|
-
const bounds = new THREE.Box3(new THREE.Vector3(-spec.width / 2, 0, -spec.length / 2), new THREE.Vector3(spec.width / 2, spec.height, spec.length / 2));
|
|
638
|
-
const normal = local.clone().sub(bounds.clampPoint(local, new THREE.Vector3()));
|
|
639
|
-
const distance = normal.length();
|
|
640
|
-
if (distance >= probe.radius) continue;
|
|
641
|
-
let depth = probe.radius - distance;
|
|
642
|
-
if (distance > 1e-4) normal.multiplyScalar(1 / distance);
|
|
643
|
-
else {
|
|
644
|
-
const face = [
|
|
645
|
-
"x",
|
|
646
|
-
"y",
|
|
647
|
-
"z"
|
|
648
|
-
].flatMap((axis) => [{
|
|
649
|
-
axis,
|
|
650
|
-
sign: -1,
|
|
651
|
-
distance: local[axis] - bounds.min[axis]
|
|
652
|
-
}, {
|
|
653
|
-
axis,
|
|
654
|
-
sign: 1,
|
|
655
|
-
distance: bounds.max[axis] - local[axis]
|
|
656
|
-
}]).sort((a, b) => a.distance - b.distance)[0];
|
|
657
|
-
if (!face) continue;
|
|
658
|
-
normal.set(0, 0, 0);
|
|
659
|
-
normal[face.axis] = face.sign;
|
|
660
|
-
depth += face.distance;
|
|
661
|
-
}
|
|
662
|
-
hit(normal.applyQuaternion(orientation), depth);
|
|
663
|
-
}
|
|
664
|
-
for (const other of scene.aircraft) {
|
|
665
|
-
const normal = new THREE.Vector3().fromArray(point).sub(new THREE.Vector3().fromArray(other));
|
|
666
|
-
const distance = normal.length();
|
|
667
|
-
if (distance < 1.2 + probe.radius) hit(distance > 1e-4 ? normal.multiplyScalar(1 / distance) : new THREE.Vector3(0, 1, 0), 1.2 + probe.radius - distance);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return contacts;
|
|
671
|
-
}
|
|
672
|
-
//#endregion
|
|
673
677
|
//#region src/aircraft.ts
|
|
674
678
|
/**
|
|
675
679
|
* Takes ownership of a loaded library GLB. The named nodes remain editable in a DCC.
|
|
@@ -682,6 +686,7 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
682
686
|
const interior = cockpit.interior === void 0 ? void 0 : createVehicleInteriorVisual(model, cockpit.interior);
|
|
683
687
|
const animation = spec.visual.animation === void 0 ? void 0 : createModelSignalVisual(model, spec.visual.animation);
|
|
684
688
|
const moving = /* @__PURE__ */ new Map();
|
|
689
|
+
const articulatedGear = new Set((spec.visual.animation?.bindings ?? []).filter((binding) => binding.property === "rotation" || binding.property === "position").map((binding) => binding.node));
|
|
685
690
|
model.traverse((o) => {
|
|
686
691
|
o.userData.vehicleGeometry = true;
|
|
687
692
|
if (o instanceof THREE.Mesh) {
|
|
@@ -702,12 +707,15 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
702
707
|
});
|
|
703
708
|
const cabinRange = Math.max(60, 3 * Math.max(spec.length, spec.span));
|
|
704
709
|
const damage = createAircraftDamageVisual(model, spec);
|
|
710
|
+
let propellers = createAircraftPropellers(model, spec);
|
|
705
711
|
let cabinShown = true;
|
|
706
712
|
return {
|
|
707
713
|
setLivery(data) {
|
|
714
|
+
propellers.dispose();
|
|
708
715
|
appearance?.dispose();
|
|
709
716
|
damage.reset();
|
|
710
717
|
appearance = data === void 0 ? void 0 : applyLivery(model, data);
|
|
718
|
+
propellers = createAircraftPropellers(model, spec);
|
|
711
719
|
},
|
|
712
720
|
object: model,
|
|
713
721
|
cockpit,
|
|
@@ -720,7 +728,10 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
720
728
|
const engine = binding.engine === void 0 ? void 0 : state.engines?.[binding.engine];
|
|
721
729
|
turn(binding.node, binding.axis, (engine?.rotorAngle ?? state.rotorAngle) * binding.multiplier);
|
|
722
730
|
}
|
|
723
|
-
for (const name of spec.visual.gearNodes)
|
|
731
|
+
for (const name of spec.visual.gearNodes) {
|
|
732
|
+
if (articulatedGear.has(name)) continue;
|
|
733
|
+
for (const node of moving.get(name) ?? []) node.visible = gear > 0;
|
|
734
|
+
}
|
|
724
735
|
for (const binding of spec.visual.flaps) turn(binding.node, binding.axis, flaps * binding.multiplier);
|
|
725
736
|
for (const binding of spec.visual.ailerons) turn(binding.node, binding.axis, input.roll * binding.multiplier);
|
|
726
737
|
if (spec.visual.interior === void 0 && spec.visual.controlStick !== void 0) {
|
|
@@ -782,6 +793,7 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
782
793
|
engine: Number(input.engine),
|
|
783
794
|
brake: Number(input.brake),
|
|
784
795
|
grounded: Number(state.grounded),
|
|
796
|
+
...state.actuators,
|
|
785
797
|
...engineSignals,
|
|
786
798
|
...signals
|
|
787
799
|
};
|
|
@@ -801,6 +813,7 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
801
813
|
});
|
|
802
814
|
interior?.update(telemetry, timeSeconds);
|
|
803
815
|
animation?.update(telemetry, timeSeconds);
|
|
816
|
+
propellers.update(state);
|
|
804
817
|
damage.update(state);
|
|
805
818
|
},
|
|
806
819
|
updateView(camera) {
|
|
@@ -813,6 +826,7 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
813
826
|
},
|
|
814
827
|
dispose() {
|
|
815
828
|
damage.reset();
|
|
829
|
+
propellers.dispose();
|
|
816
830
|
appearance?.dispose();
|
|
817
831
|
const geometries = /* @__PURE__ */ new Set(), materials = /* @__PURE__ */ new Set();
|
|
818
832
|
model.traverse((o) => {
|
package/dist/audio.d.mts
CHANGED
|
@@ -68,6 +68,12 @@ interface VoiceSpatial {
|
|
|
68
68
|
rolloff: number;
|
|
69
69
|
model: "linear" | "inverse" | "exponential";
|
|
70
70
|
}
|
|
71
|
+
/** Optional rotor timbre and loading envelope; evaluated at audio rate by the backend. */
|
|
72
|
+
interface VoiceTone {
|
|
73
|
+
lowpassHz: number;
|
|
74
|
+
pulseHz: number;
|
|
75
|
+
pulseDepth: number;
|
|
76
|
+
}
|
|
71
77
|
/** The director's output: a diff the backend applies. */
|
|
72
78
|
type VoiceCommand = {
|
|
73
79
|
op: "start";
|
|
@@ -82,6 +88,7 @@ type VoiceCommand = {
|
|
|
82
88
|
bus: string;
|
|
83
89
|
spatial?: VoiceSpatial;
|
|
84
90
|
fadeInS?: number;
|
|
91
|
+
tone?: VoiceTone;
|
|
85
92
|
} | {
|
|
86
93
|
op: "set";
|
|
87
94
|
voice: string;
|
|
@@ -89,6 +96,7 @@ type VoiceCommand = {
|
|
|
89
96
|
pitch?: number;
|
|
90
97
|
position?: AudioVec3;
|
|
91
98
|
rampS?: number;
|
|
99
|
+
tone?: VoiceTone;
|
|
92
100
|
} | {
|
|
93
101
|
op: "stop";
|
|
94
102
|
voice: string;
|
|
@@ -527,9 +535,10 @@ declare class WebAudioBackend implements AudioBackend {
|
|
|
527
535
|
private trimBuffers;
|
|
528
536
|
private start;
|
|
529
537
|
private set;
|
|
538
|
+
private setTone;
|
|
530
539
|
private stop;
|
|
531
540
|
private cleanup;
|
|
532
541
|
private setListener;
|
|
533
542
|
}
|
|
534
543
|
//#endregion
|
|
535
|
-
export { type AudioBackend, type AudioBackendStats, type AudioCameraLike, type AudioClientLike, AudioDirector, type AudioDirectorOptions, type AudioEntitySource, type AudioEnvironmentSignals, type AudioLayer, type AudioLayerOptions, type AudioLayerStats, type AudioListenerState, type AudioPackSetLike, type AudioRendererLike, type AudioSkySignals, type AudioVec3, type AudioWorldLike, type DirectorInput, type EntityMotion, Gate, type RecordingBackend, type ResolvedSound, type SignalContext, type SignalValue, type SoundBank, type SoundbankInput, type Unlockable, type VoiceCommand, type VoiceSnapshot, type VoiceSpatial, WebAudioBackend, type WebAudioBackendOptions, attachAutoplayUnlock, createAudioLayer, createRecordingBackend, curve, entitySourceFromClient, entitySourceFromWorld, evalWhen, hash32, listenerFromCamera, loadPackSoundbanks, mergeSoundbanks, resolveSignal, unitRandom };
|
|
544
|
+
export { type AudioBackend, type AudioBackendStats, type AudioCameraLike, type AudioClientLike, AudioDirector, type AudioDirectorOptions, type AudioEntitySource, type AudioEnvironmentSignals, type AudioLayer, type AudioLayerOptions, type AudioLayerStats, type AudioListenerState, type AudioPackSetLike, type AudioRendererLike, type AudioSkySignals, type AudioVec3, type AudioWorldLike, type DirectorInput, type EntityMotion, Gate, type RecordingBackend, type ResolvedSound, type SignalContext, type SignalValue, type SoundBank, type SoundbankInput, type Unlockable, type VoiceCommand, type VoiceSnapshot, type VoiceSpatial, type VoiceTone, WebAudioBackend, type WebAudioBackendOptions, attachAutoplayUnlock, createAudioLayer, createRecordingBackend, curve, entitySourceFromClient, entitySourceFromWorld, evalWhen, hash32, listenerFromCamera, loadPackSoundbanks, mergeSoundbanks, resolveSignal, unitRandom };
|