@bendyline/molen-client 0.0.11 → 0.0.13
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 +9 -31
- package/dist/aircraft.mjs +279 -219
- 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 +250 -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-DJ4cXTsQ.mjs +468 -0
- package/dist/vehicles.d.mts +25 -20
- package/dist/vehicles.mjs +271 -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/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 { i as createAircraftDamageVisual, n as drawGlassInOnePass, r as aircraftObstacleContacts, t as createVehicleInteriorVisual } from "./vehicle-interior-DJ4cXTsQ.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,209 @@ 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
|
+
const faded = (Array.isArray(original) ? original : [original]).map((m) => {
|
|
346
|
+
const clone = m.clone();
|
|
347
|
+
clone.transparent = true;
|
|
348
|
+
clone.depthWrite = false;
|
|
349
|
+
return clone;
|
|
350
|
+
});
|
|
351
|
+
mesh.userData.materialVariants = [...Array.isArray(original) ? original : [original], ...faded];
|
|
352
|
+
return {
|
|
353
|
+
mesh,
|
|
354
|
+
original,
|
|
355
|
+
faded,
|
|
356
|
+
shadow: mesh.castShadow
|
|
357
|
+
};
|
|
358
|
+
})
|
|
359
|
+
});
|
|
360
|
+
}
|
|
287
361
|
}
|
|
288
|
-
mesh.visible = false;
|
|
289
362
|
}
|
|
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
363
|
return {
|
|
305
|
-
reset,
|
|
306
364
|
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);
|
|
365
|
+
for (const prop of propellers) {
|
|
366
|
+
const rpm = (prop.engine === void 0 ? void 0 : state.engines?.[prop.engine])?.rpm ?? state.rpm;
|
|
367
|
+
const blend = prop.parts.some((part) => state.damage?.[part]?.detached) || !Number.isFinite(rpm) ? 0 : THREE.MathUtils.smoothstep(Math.abs(rpm * prop.speed), 20, 60);
|
|
368
|
+
prop.disk.visible = blend > 0;
|
|
369
|
+
prop.disk.material.opacity = blend;
|
|
370
|
+
for (const { mesh, original, faded, shadow } of prop.blades) {
|
|
371
|
+
const originals = Array.isArray(original) ? original : [original];
|
|
372
|
+
for (const [i, material] of faded.entries()) {
|
|
373
|
+
const source = originals[i];
|
|
374
|
+
material.opacity = source.opacity * (1 - blend);
|
|
375
|
+
material.visible = source.visible && blend < 1;
|
|
335
376
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
group.matrixAutoUpdate = false;
|
|
341
|
-
pose.compose(position.fromArray(debris.pos), rotation.fromArray(debris.rot), unit);
|
|
342
|
-
group.matrix.copy(inverse).multiply(pose);
|
|
343
|
-
group.matrixWorldNeedsUpdate = true;
|
|
377
|
+
const ready = mesh.userData.materialReady;
|
|
378
|
+
const fading = blend > 0 && (ready === void 0 || faded.filter((material) => !ready(material)).length === 0);
|
|
379
|
+
mesh.material = !fading ? original : Array.isArray(original) ? faded : faded[0];
|
|
380
|
+
mesh.castShadow = shadow && !fading;
|
|
344
381
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
dispose() {
|
|
385
|
+
for (const prop of propellers) {
|
|
386
|
+
for (const { mesh, original, faded, shadow } of prop.blades) {
|
|
387
|
+
mesh.material = original;
|
|
388
|
+
mesh.castShadow = shadow;
|
|
389
|
+
for (const material of faded) material.dispose();
|
|
348
390
|
}
|
|
391
|
+
prop.disk.removeFromParent();
|
|
392
|
+
prop.disk.geometry.dispose();
|
|
393
|
+
prop.disk.material.dispose();
|
|
349
394
|
}
|
|
395
|
+
propellers.length = 0;
|
|
350
396
|
}
|
|
351
397
|
};
|
|
352
398
|
}
|
|
399
|
+
function ancestors(node) {
|
|
400
|
+
const parents = [];
|
|
401
|
+
for (let parent = node.parent; parent; parent = parent.parent) parents.push(parent);
|
|
402
|
+
return parents;
|
|
403
|
+
}
|
|
404
|
+
function blurDisk(bands, radius, axis) {
|
|
405
|
+
const rings = 48, segments = 64;
|
|
406
|
+
const geometry = new THREE.RingGeometry(0, radius, segments, rings);
|
|
407
|
+
const position = geometry.getAttribute("position");
|
|
408
|
+
const colors = new Float32Array(position.count * 4);
|
|
409
|
+
const totalArea = bands.reduce((sum, b) => sum + b.area, 0);
|
|
410
|
+
const depth = bands.reduce((sum, b) => sum + b.depth * b.area, 0) / totalArea;
|
|
411
|
+
for (let ring = 0; ring <= rings; ring++) {
|
|
412
|
+
const r = ring / rings * radius;
|
|
413
|
+
const color = new THREE.Color(0, 0, 0);
|
|
414
|
+
let alpha = 0;
|
|
415
|
+
for (const band of bands) {
|
|
416
|
+
const feather = Math.min(radius / rings, (band.outer - band.inner) / 2);
|
|
417
|
+
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));
|
|
418
|
+
color.add(band.color.clone().multiplyScalar(coverage));
|
|
419
|
+
alpha += coverage;
|
|
420
|
+
}
|
|
421
|
+
if (alpha > 0) color.multiplyScalar(1 / alpha);
|
|
422
|
+
for (let segment = 0; segment <= segments; segment++) {
|
|
423
|
+
const i = ring * 65 + segment;
|
|
424
|
+
colors.set([
|
|
425
|
+
color.r,
|
|
426
|
+
color.g,
|
|
427
|
+
color.b,
|
|
428
|
+
Math.min(.45, alpha)
|
|
429
|
+
], i * 4);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 4));
|
|
433
|
+
if (axis === "x") geometry.rotateY(Math.PI / 2);
|
|
434
|
+
else if (axis === "y") geometry.rotateX(-Math.PI / 2);
|
|
435
|
+
geometry.translate(axis === "x" ? depth : 0, axis === "y" ? depth : 0, axis === "z" ? depth : 0);
|
|
436
|
+
return new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({
|
|
437
|
+
vertexColors: true,
|
|
438
|
+
transparent: true,
|
|
439
|
+
depthWrite: false,
|
|
440
|
+
side: THREE.DoubleSide,
|
|
441
|
+
forceSinglePass: true
|
|
442
|
+
}));
|
|
443
|
+
}
|
|
353
444
|
//#endregion
|
|
354
445
|
//#region src/aircraft-cockpit-pointer.ts
|
|
355
446
|
function bindAircraftCockpitPointer(options) {
|
|
@@ -587,90 +678,16 @@ function bindActiveCockpitPointer(options) {
|
|
|
587
678
|
};
|
|
588
679
|
}
|
|
589
680
|
//#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
681
|
//#region src/aircraft.ts
|
|
682
|
+
/** The group the cockpit-controls generator adds beside a model's cockpit: levers and legends. */
|
|
683
|
+
const FLIGHT_CONTROLS_NODE = "flight-controls";
|
|
684
|
+
/**
|
|
685
|
+
* Angular radius (radians) below which a cabin part is left out of the frame: under four pixels
|
|
686
|
+
* across in a 1080p view with a 60° field of view. From a chase camera fifteen meters back,
|
|
687
|
+
* gauges, needles and switches are each smaller than that behind the canopy, and each was a draw:
|
|
688
|
+
* the P-51's cockpit, 415 meshes, was a quarter of a takeoff's draws in chase view.
|
|
689
|
+
*/
|
|
690
|
+
const CABIN_DETAIL_ANGLE = .002;
|
|
674
691
|
/**
|
|
675
692
|
* Takes ownership of a loaded library GLB. The named nodes remain editable in a DCC.
|
|
676
693
|
*
|
|
@@ -682,11 +699,13 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
682
699
|
const interior = cockpit.interior === void 0 ? void 0 : createVehicleInteriorVisual(model, cockpit.interior);
|
|
683
700
|
const animation = spec.visual.animation === void 0 ? void 0 : createModelSignalVisual(model, spec.visual.animation);
|
|
684
701
|
const moving = /* @__PURE__ */ new Map();
|
|
702
|
+
const articulatedGear = new Set((spec.visual.animation?.bindings ?? []).filter((binding) => binding.property === "rotation" || binding.property === "position").map((binding) => binding.node));
|
|
685
703
|
model.traverse((o) => {
|
|
686
704
|
o.userData.vehicleGeometry = true;
|
|
687
705
|
if (o instanceof THREE.Mesh) {
|
|
688
706
|
o.castShadow = !o.name.includes("canopy") && !o.name.includes("bubble");
|
|
689
707
|
o.receiveShadow = true;
|
|
708
|
+
drawGlassInOnePass(o);
|
|
690
709
|
}
|
|
691
710
|
const list = moving.get(o.name) ?? [];
|
|
692
711
|
list.push(o);
|
|
@@ -696,18 +715,40 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
696
715
|
for (const node of moving.get(name) ?? []) node.rotation[axis] = angle;
|
|
697
716
|
};
|
|
698
717
|
let appearance = livery === void 0 ? void 0 : applyLivery(model, livery);
|
|
699
|
-
const cabin =
|
|
718
|
+
const cabin = [...spec.visual.interior?.nodes ?? [], FLIGHT_CONTROLS_NODE].flatMap((name) => moving.get(name) ?? []);
|
|
700
719
|
for (const node of cabin) node.traverse((object) => {
|
|
701
720
|
if (object.isMesh) object.userData.walkIgnore = true;
|
|
702
721
|
});
|
|
703
722
|
const cabinRange = Math.max(60, 3 * Math.max(spec.length, spec.span));
|
|
704
723
|
const damage = createAircraftDamageVisual(model, spec);
|
|
724
|
+
let propellers = createAircraftPropellers(model, spec);
|
|
705
725
|
let cabinShown = true;
|
|
726
|
+
model.updateMatrixWorld(true);
|
|
727
|
+
const modelScale = model.matrixWorld.getMaxScaleOnAxis();
|
|
728
|
+
const details = [];
|
|
729
|
+
const listed = /* @__PURE__ */ new Set();
|
|
730
|
+
for (const node of cabin) node.traverse((object) => {
|
|
731
|
+
const mesh = object;
|
|
732
|
+
if (!mesh.isMesh || listed.has(mesh)) return;
|
|
733
|
+
listed.add(mesh);
|
|
734
|
+
if (mesh.geometry.boundingSphere === null) mesh.geometry.computeBoundingSphere();
|
|
735
|
+
const radius = (mesh.geometry.boundingSphere?.radius ?? 0) * mesh.matrixWorld.getMaxScaleOnAxis() / modelScale;
|
|
736
|
+
details.push({
|
|
737
|
+
mesh,
|
|
738
|
+
reach: radius / CABIN_DETAIL_ANGLE,
|
|
739
|
+
layers: mesh.layers.mask
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
details.sort((a, b) => b.reach - a.reach);
|
|
743
|
+
let detailed = details.length;
|
|
744
|
+
const eye = new THREE.Vector3();
|
|
706
745
|
return {
|
|
707
746
|
setLivery(data) {
|
|
747
|
+
propellers.dispose();
|
|
708
748
|
appearance?.dispose();
|
|
709
749
|
damage.reset();
|
|
710
750
|
appearance = data === void 0 ? void 0 : applyLivery(model, data);
|
|
751
|
+
propellers = createAircraftPropellers(model, spec);
|
|
711
752
|
},
|
|
712
753
|
object: model,
|
|
713
754
|
cockpit,
|
|
@@ -720,7 +761,10 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
720
761
|
const engine = binding.engine === void 0 ? void 0 : state.engines?.[binding.engine];
|
|
721
762
|
turn(binding.node, binding.axis, (engine?.rotorAngle ?? state.rotorAngle) * binding.multiplier);
|
|
722
763
|
}
|
|
723
|
-
for (const name of spec.visual.gearNodes)
|
|
764
|
+
for (const name of spec.visual.gearNodes) {
|
|
765
|
+
if (articulatedGear.has(name)) continue;
|
|
766
|
+
for (const node of moving.get(name) ?? []) node.visible = gear > 0;
|
|
767
|
+
}
|
|
724
768
|
for (const binding of spec.visual.flaps) turn(binding.node, binding.axis, flaps * binding.multiplier);
|
|
725
769
|
for (const binding of spec.visual.ailerons) turn(binding.node, binding.axis, input.roll * binding.multiplier);
|
|
726
770
|
if (spec.visual.interior === void 0 && spec.visual.controlStick !== void 0) {
|
|
@@ -782,6 +826,7 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
782
826
|
engine: Number(input.engine),
|
|
783
827
|
brake: Number(input.brake),
|
|
784
828
|
grounded: Number(state.grounded),
|
|
829
|
+
...state.actuators,
|
|
785
830
|
...engineSignals,
|
|
786
831
|
...signals
|
|
787
832
|
};
|
|
@@ -801,18 +846,33 @@ function createAircraftVisual(model, spec, livery) {
|
|
|
801
846
|
});
|
|
802
847
|
interior?.update(telemetry, timeSeconds);
|
|
803
848
|
animation?.update(telemetry, timeSeconds);
|
|
849
|
+
propellers.update(state);
|
|
804
850
|
damage.update(state);
|
|
805
851
|
},
|
|
806
852
|
updateView(camera) {
|
|
807
853
|
if (cabin.length === 0) return;
|
|
808
854
|
const p = model.position;
|
|
809
855
|
const shown = Math.hypot(p.x - camera[0], p.y - camera[1], p.z - camera[2]) < cabinRange * (cabinShown ? 1.1 : 1);
|
|
810
|
-
if (shown
|
|
811
|
-
|
|
812
|
-
|
|
856
|
+
if (shown !== cabinShown) {
|
|
857
|
+
cabinShown = shown;
|
|
858
|
+
for (const node of cabin) node.visible = shown;
|
|
859
|
+
}
|
|
860
|
+
if (!shown) return;
|
|
861
|
+
eye.fromArray(spec.pilotEye).applyQuaternion(model.quaternion).add(p);
|
|
862
|
+
const near = Math.hypot(eye.x - camera[0], eye.y - camera[1], eye.z - camera[2]);
|
|
863
|
+
for (let next = details[detailed]; next !== void 0 && near < next.reach;) {
|
|
864
|
+
next.mesh.layers.mask = next.layers;
|
|
865
|
+
next = details[++detailed];
|
|
866
|
+
}
|
|
867
|
+
for (let last = details[detailed - 1]; last !== void 0 && near > last.reach * 1.1;) {
|
|
868
|
+
last.layers = last.mesh.layers.mask;
|
|
869
|
+
last.mesh.layers.mask = 0;
|
|
870
|
+
last = details[--detailed - 1];
|
|
871
|
+
}
|
|
813
872
|
},
|
|
814
873
|
dispose() {
|
|
815
874
|
damage.reset();
|
|
875
|
+
propellers.dispose();
|
|
816
876
|
appearance?.dispose();
|
|
817
877
|
const geometries = /* @__PURE__ */ new Set(), materials = /* @__PURE__ */ new Set();
|
|
818
878
|
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 };
|